8 int mouse_x, mouse_y, mouse_state[3];
11 int win_width, win_height;
17 struct game_screen *cur_scr;
19 /* available screens */
20 extern struct game_screen scr_menu, scr_game, scr_map, scr_lvled;
22 static struct game_screen *screens[MAX_SCREENS];
23 static int num_screens;
26 int game_init(int argc, char **argv)
31 load_options(GAME_CFG_FILE);
32 if(parse_options(argc, argv) == -1) {
35 game_resize(opt.xres, opt.yres);
36 game_vsync(opt.vsync);
41 /* initialize screens */
42 screens[num_screens++] = &scr_menu;
43 screens[num_screens++] = &scr_game;
44 screens[num_screens++] = &scr_map;
45 screens[num_screens++] = &scr_lvled;
47 start_scr_name = getenv("START_SCREEN");
49 for(i=0; i<num_screens; i++) {
50 if(screens[i]->init() == -1) {
55 glClearColor(0.1, 0.1, 0.1, 1);
57 for(i=0; i<num_screens; i++) {
58 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
59 game_chscr(screens[i]);
64 game_chscr(&scr_game); /* TODO: scr_menu */
69 void game_shutdown(void)
73 save_options(GAME_CFG_FILE);
75 for(i=0; i<num_screens; i++) {
76 if(screens[i]->destroy) {
77 screens[i]->destroy();
82 void game_display(void)
84 time_msec = game_getmsec();
93 void game_reshape(int x, int y)
97 win_aspect = (float)x / (float)y;
98 glViewport(0, 0, x, y);
100 if(cur_scr && cur_scr->reshape) {
101 cur_scr->reshape(x, y);
105 void game_keyboard(int key, int press)
115 if(modkeys & GKEY_MOD_ALT) {
124 if(cur_scr && cur_scr->keyboard) {
125 cur_scr->keyboard(key, press);
129 void game_mouse(int bn, int st, int x, int y)
134 mouse_state[bn] = st;
137 if(cur_scr && cur_scr->mouse) {
138 cur_scr->mouse(bn, st, x, y);
142 void game_motion(int x, int y)
144 if(cur_scr && cur_scr->motion) {
145 cur_scr->motion(x, y);
151 void game_chscr(struct game_screen *scr)
153 struct game_screen *prev = cur_scr;
157 if(scr->start && scr->start() == -1) {
161 scr->reshape(win_width, win_height);
164 if(prev && prev->stop) {