writing a mesh abstraction
[vrtris] / src / screen.c
1 #include <string.h>
2 #include "screen.h"
3 #include "opt.h"
4
5 /* defined in their respective screen source files */
6 struct game_screen main_menu_screen;
7 struct game_screen game_screen;
8
9 static struct game_screen *screens[16];
10 static int num_screens;
11
12 static struct game_screen *stack;
13
14 int init_screens(void)
15 {
16         int i = 0;
17
18         /* populate the screens */
19         screens[i++] = &main_menu_screen;
20         screens[i++] = &game_screen;
21         num_screens = i;
22
23         stack = screens[0];
24
25         for(i=0; i<num_screens; i++) {
26                 if(screens[i]->init() == -1) {
27                         return -1;
28                 }
29                 if(opt.start_scr && strcmp(screens[i]->name, opt.start_scr) == 0) {
30                         stack = screens[i];
31                 }
32         }
33         return 0;
34 }
35
36 void cleanup_screens(void)
37 {
38         int i;
39
40         for(i=0; i<num_screens; i++) {
41                 screens[i]->cleanup();
42         }
43 }
44
45 void reshape_screens(int x, int y)
46 {
47         struct game_screen *s = stack;
48         while(s) {
49                 s->reshape(x, y);
50                 s = s->next;
51         }
52 }
53
54 void push_screen(struct game_screen *s)
55 {
56         s->next = stack;
57         stack = s;
58         s->start();
59 }
60
61 int pop_screen(void)
62 {
63         struct game_screen *s;
64
65         if(!stack->next) return -1;
66         s = stack;
67         stack = stack->next;
68         s->stop();
69         return 0;
70 }