bool Glulxe::init_dispatch() { int ix; /* Set up the game-ID hook. (This is ifdeffed because not all Glk libraries have this call.) */ #ifdef GI_DISPA_GAME_ID_AVAILABLE gidispatch_set_game_id_hook(&get_game_id); #endif /* GI_DISPA_GAME_ID_AVAILABLE */ /* Allocate the class hash tables. */ num_classes = gidispatch_count_classes(); classes = (classtable_t **)glulx_malloc(num_classes * sizeof(classtable_t *)); if (!classes) return false; for (ix = 0; ix < num_classes; ix++) { classes[ix] = new_classtable((glulx_random() % (uint)(101)) + 1); if (!classes[ix]) return false; } /* Set up the two callbacks. */ gidispatch_set_object_registry(&classtable_register, &classtable_unregister); gidispatch_set_retained_registry(&retained_register, &retained_unregister); /* If the library supports autorestore callbacks, set those up too. (These are only used in iosglk, currently.) */ #ifdef GIDISPATCH_AUTORESTORE_REGISTRY gidispatch_set_autorestore_registry(&glulxe_array_locate, &glulxe_array_restore); #endif /* GIDISPATCH_AUTORESTORE_REGISTRY */ return true; }
/* git_init_dispatch(): Set up the class hash tables and other startup-time stuff. */ int git_init_dispatch() { int ix; /* What with one thing and another, this *could* be called more than once. We only need to allocate the tables once. */ if (git_classes) return TRUE; /* Set up the game-ID hook. (This is ifdeffed because not all Glk libraries have this call.) */ #ifdef GI_DISPA_GAME_ID_AVAILABLE gidispatch_set_game_id_hook(&get_game_id); #endif /* GI_DISPA_GAME_ID_AVAILABLE */ /* Allocate the class hash tables. */ num_classes = gidispatch_count_classes(); git_classes = (classtable_t **)glulx_malloc(num_classes * sizeof(classtable_t *)); if (!git_classes) return FALSE; for (ix=0; ix<num_classes; ix++) { git_classes[ix] = new_classtable((glulx_random() % (glui32)(101)) + 1); if (!git_classes[ix]) return FALSE; } /* Set up the two callbacks. */ gidispatch_set_object_registry(&glulxe_classtable_register, &glulxe_classtable_unregister); gidispatch_set_retained_registry(&glulxe_retained_register, &glulxe_retained_unregister); return TRUE; }