Changed build system to Automake. Split Glk code off into a GTK widget.
[rodin/chimara.git] / src / glk.c
1 #include <gtk/gtk.h>
2
3 #include "glk.h"
4 #include "abort.h"
5 #include "chimara-glk.h"
6 #include "chimara-glk-private.h"
7
8 ChimaraGlkPrivate *glk_data = NULL;
9
10 /**
11  * glk_exit:
12  * 
13  * Shuts down the Glk program. This function does not return.
14  *
15  * If you print some text to a window and then shut down your program, you can
16  * assume that the player will be able to read it.
17  *
18  * <note><para>
19  *  You should only shut down your program with glk_exit() or by returning from
20  *  your glk_main() function. If you call the ANSI <function>exit()</function> 
21  *  function, bad things may happen. This Glk library is designed for multiple 
22  *  sessions, for example, and you would be cutting off all the sessions instead
23  *  of just yours. You would also prevent final text from being visible to the 
24  *  player.
25  * </para></note>
26  */
27 void
28 glk_exit(void)
29 {
30         g_thread_exit(NULL);
31         glk_data = NULL;
32 }
33
34 /**
35  * glk_tick:
36  *
37  * Many platforms have some annoying thing that has to be done every so often,
38  * or the gnurrs come from the voodvork out and eat your computer.
39  * 
40  * Well, not really. But you should call glk_tick() every so often, just in
41  * case. It may be necessary to yield time to other applications in a
42  * cooperative-multitasking OS, or to check for player interrupts in an infinite
43  * loop.
44  * 
45  * This call is fast; in fact, on average, it does nothing at all. So you can
46  * call it often. (In a virtual machine interpreter, once per opcode is
47  * appropriate. In a program with lots of computation, pick a comparable rate.)
48  * 
49  * glk_tick() does not try to update the screen, or check for player input, or
50  * any other interface task. For that, you should call glk_select() or 
51  * glk_select_poll().
52  * 
53  * Basically, you must ensure there's some fixed upper bound on the amount of
54  * computation that can occur before a glk_tick() (or glk_select()) occurs. In a
55  * VM interpreter, where the VM code might contain an infinite loop, this is
56  * critical. In a C program, you can often eyeball it.
57  */
58 void
59 glk_tick()
60 {
61         check_for_abort();
62         
63         /* Do one iteration of the main loop if there are any events */
64         gdk_threads_enter();
65         if(gtk_events_pending())
66                 gtk_main_iteration();
67         gdk_threads_leave();
68 }