X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=src%2Fglk.c;h=47c28cb521a89b9a003922c00527b4e948873a07;hb=82db17cf44e29708bb971b1da2e1e6d4d747fa9b;hp=fc22682676d383f7f2aed2be6fdb435b77eeeed9;hpb=49eca40060b04105343874714fa67976b9430def;p=rodin%2Fchimara.git diff --git a/src/glk.c b/src/glk.c index fc22682..47c28cb 100644 --- a/src/glk.c +++ b/src/glk.c @@ -1,26 +1,68 @@ -#include #include #include "glk.h" +#include "abort.h" +#include "chimara-glk.h" +#include "chimara-glk-private.h" + +ChimaraGlkPrivate *glk_data = NULL; /** * glk_exit: * - * End the Glk program. As far as the client program is concerned, this - * function does not return. + * Shuts down the Glk program. This function does not return. + * + * If you print some text to a window and then shut down your program, you can + * assume that the player will be able to read it. + * + * + * You should only shut down your program with glk_exit() or by returning from + * your glk_main() function. If you call the ANSI exit() + * function, bad things may happen. This Glk library is designed for multiple + * sessions, for example, and you would be cutting off all the sessions instead + * of just yours. You would also prevent final text from being visible to the + * player. + * */ void glk_exit(void) { g_thread_exit(NULL); + glk_data = NULL; } -/* +/** + * glk_tick: + * + * Many platforms have some annoying thing that has to be done every so often, + * or the gnurrs come from the voodvork out and eat your computer. + * + * Well, not really. But you should call glk_tick() every so often, just in + * case. It may be necessary to yield time to other applications in a + * cooperative-multitasking OS, or to check for player interrupts in an infinite + * loop. + * + * This call is fast; in fact, on average, it does nothing at all. So you can + * call it often. (In a virtual machine interpreter, once per opcode is + * appropriate. In a program with lots of computation, pick a comparable rate.) + * + * glk_tick() does not try to update the screen, or check for player input, or + * any other interface task. For that, you should call glk_select() or + * glk_select_poll(). + * + * Basically, you must ensure there's some fixed upper bound on the amount of + * computation that can occur before a glk_tick() (or glk_select()) occurs. In a + * VM interpreter, where the VM code might contain an infinite loop, this is + * critical. In a C program, you can often eyeball it. + */ void -glk_select(event_t *event) +glk_tick() { - gtk_main_iteration(); + check_for_abort(); + + /* Do one iteration of the main loop if there are any events */ + gdk_threads_enter(); + if(gtk_events_pending()) + gtk_main_iteration(); + gdk_threads_leave(); } -*/ - -