8 int mouse_x, mouse_y, mouse_state[3];
11 int win_width, win_height;
17 struct game_screen *cur_scr;
20 /* available screens */
21 extern struct game_screen scr_menu, scr_game, scr_map, scr_lvled;
23 static struct game_screen *screens[MAX_SCREENS];
24 static int num_screens;
27 int game_init(int argc, char **argv)
32 load_options(GAME_CFG_FILE);
33 if(parse_options(argc, argv) == -1) {
36 game_resize(opt.xres, opt.yres);
37 game_vsync(opt.vsync);
42 /* initialize screens */
43 screens[num_screens++] = &scr_menu;
44 screens[num_screens++] = &scr_game;
45 screens[num_screens++] = &scr_map;
46 screens[num_screens++] = &scr_lvled;
48 if((env = getenv("START_SCREEN"))) {
52 for(i=0; i<num_screens; i++) {
53 if(screens[i]->init() == -1) {
58 glClearColor(0.1, 0.1, 0.1, 1);
60 for(i=0; i<num_screens; i++) {
61 if(screens[i]->name && start_scr_name && strcmp(screens[i]->name, start_scr_name) == 0) {
62 game_chscr(screens[i]);
67 game_chscr(&scr_game); /* TODO: scr_menu */
72 void game_shutdown(void)
76 save_options(GAME_CFG_FILE);
78 for(i=0; i<num_screens; i++) {
79 if(screens[i]->destroy) {
80 screens[i]->destroy();
85 void game_display(void)
87 time_msec = game_getmsec();
96 void game_reshape(int x, int y)
100 win_aspect = (float)x / (float)y;
101 glViewport(0, 0, x, y);
103 if(cur_scr && cur_scr->reshape) {
104 cur_scr->reshape(x, y);
108 void game_keyboard(int key, int press)
118 if(modkeys & GKEY_MOD_ALT) {
127 if(cur_scr && cur_scr->keyboard) {
128 cur_scr->keyboard(key, press);
132 void game_mouse(int bn, int st, int x, int y)
137 mouse_state[bn] = st;
140 if(cur_scr && cur_scr->mouse) {
141 cur_scr->mouse(bn, st, x, y);
145 void game_motion(int x, int y)
147 if(cur_scr && cur_scr->motion) {
148 cur_scr->motion(x, y);
154 void game_chscr(struct game_screen *scr)
156 struct game_screen *prev = cur_scr;
160 if(scr->start && scr->start() == -1) {
164 scr->reshape(win_width, win_height);
167 if(prev && prev->stop) {