Verbeterd interrupt mechanisme en afbreken van het Glk programma
[projects/chimara/chimara.git] / src / glk.c
index dbec7596f581f478af528bc8473699e1b1820e5f..88ca873e10ea3c58e1eae636d980ac8dbcb8d0fc 100644 (file)
--- a/src/glk.c
+++ b/src/glk.c
@@ -2,6 +2,7 @@
 #include <gtk/gtk.h>
 
 #include "glk.h"
+#include "abort.h"
 
 /**
  * glk_exit:
 void
 glk_exit(void)
 {
+       cleanup();
        g_thread_exit(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_tick()
+{
+       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();
+}