From c405cf118d3d31c2b6e1fe935671ecdaeb031f8f Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 21 Aug 2004 16:51:43 +0200 Subject: [PATCH] rnd-20040821-3-src --- src/conftime.h | 2 +- src/game_em/game_em.h | 4 +- src/game_em/global.h | 11 +- src/game_em/init.c | 2 + src/game_em/input.c | 314 +++++++++++++++++++++++++++++------------- src/game_em/main.c | 23 ++-- src/init.c | 16 +-- src/screens.c | 30 +++- 8 files changed, 282 insertions(+), 120 deletions(-) diff --git a/src/conftime.h b/src/conftime.h index 8d2eb1b5..a65c4ad4 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2004-08-21 14:11]" +#define COMPILE_DATE_STRING "[2004-08-21 16:45]" diff --git a/src/game_em/game_em.h b/src/game_em/game_em.h index 80aae3ee..48012ab2 100644 --- a/src/game_em/game_em.h +++ b/src/game_em/game_em.h @@ -17,7 +17,9 @@ #define GAME_EM_VERSION_1_0_0 extern void em_open_all(); -extern void em_main(); extern void em_close_all(); +extern void em_main_init_game(); +extern int em_main_handle_game(byte); + #endif /* GAME_EM_H */ diff --git a/src/game_em/global.h b/src/game_em/global.h index 5f8b1821..c225dac4 100644 --- a/src/game_em/global.h +++ b/src/game_em/global.h @@ -20,6 +20,11 @@ extern int arg_silence; extern unsigned int frame; +#define EM_GAME_STATUS_MENU 1 +#define EM_GAME_STATUS_PLAY 2 + +extern int em_game_status; + extern short ulaw_to_linear[256]; extern unsigned char linear_to_ulaw[65536]; @@ -28,7 +33,7 @@ extern unsigned char linear_to_ulaw[65536]; int open_all(void); void close_all(void); -void readjoy(void); +void readjoy(byte); void input_eventloop(void); void blitscreen(void); @@ -45,7 +50,9 @@ void sound_play(void); int cave_convert(char *filename); -int game_start(void); +void game_init_vars(void); +int game_loop(byte); + void synchro_1(void); void synchro_2(void); void synchro_3(void); diff --git a/src/game_em/init.c b/src/game_em/init.c index 5622ca03..9011788e 100644 --- a/src/game_em/init.c +++ b/src/game_em/init.c @@ -967,7 +967,9 @@ void close_all(void) if(privateColourmap) XFreeColormap(display, privateColourmap); if(privateColours) free(privateColours); if(privateFlags) free(privateFlags); +#if 0 if(display) XCloseDisplay(display); +#endif } /* ---------------------------------------------------------------------- */ diff --git a/src/game_em/input.c b/src/game_em/input.c index ada3aba4..385588c5 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -110,13 +110,9 @@ static void drawmenu(int pos) } } -/* bring it all together */ -int game_start(void) +void game_init_vars(void) { - int x,y; - char name[MAXNAME+2]; - int temp; - int pos; + int x, y; Random = 1684108901; @@ -152,133 +148,256 @@ int game_start(void) player_level = 0; input_pause = 1 * 0; +} - while (1) +int game_play_init(int player_level) +{ + char name[MAXNAME+2]; + + name[MAXNAME] = 0; + snprintf(name, MAXNAME+2, "%s/lev%02d", EM_LVL_DIR, player_level); + + if (name[MAXNAME]) + snprintf_overflow("read a level in cave/"); + + if (cave_convert(name) != 0) + return 1; + + game_initscreen(); + game_blitscore(); + game_animscreen(); + + return 0; +} + +int game_menu_loop(boolean init, byte action) +{ + static int temp = -1; + static int pos = -1; + + if (init) { + temp = 1; pos = 4; - title_initscreen(); + return 0; + } + + input_eventloop(); - for (temp = 0; temp < 7; temp++) - drawmenu(temp); /* display all lines */ + if (input_die) + return 1; - title_blitants(4 + pos); + if (input_refresh) + blitscreen(); + if (!input_pause) + { + title_blitants(4 + pos); title_blitscore(); title_animscreen(); - temp = 1; - while (1) + ply1.joy_n = ply1.joy_e = ply1.joy_s = ply1.joy_w = 0; + + readjoy(action); + + if (temp == 0) { - input_eventloop(); - if (input_die) return(0); - if (input_refresh) blitscreen(); + if (ply1.joy_fire) + return 2; - if (!input_pause) + if (ply1.joy_e && player_level < 99) { + player_level++; + drawmenu(2); + } + + if (ply1.joy_w && player_level > 0) + { + player_level--; + drawmenu(2); + } + + if (ply1.joy_n && pos > 0) + { + drawmenu(pos); + pos--; + title_blitants(4 + pos); + } + + if (ply1.joy_s && pos < 4) + { + drawmenu(pos); + pos++; title_blitants(4 + pos); - title_blitscore(); - title_animscreen(); - - ply1.joy_n = ply1.joy_e = ply1.joy_s = ply1.joy_w = 0; - - readjoy(); - - if (temp == 0) - { - if (ply1.joy_fire) - break; - - if (ply1.joy_e && player_level < 99) - { - player_level++; - drawmenu(2); - } - - if (ply1.joy_w && player_level > 0) - { - player_level--; - drawmenu(2); - } - - if (ply1.joy_n && pos > 0) - { - drawmenu(pos); - pos--; - title_blitants(4 + pos); - } - - if (ply1.joy_s && pos < 4) - { - drawmenu(pos); - pos++; - title_blitants(4 + pos); - } - } - - temp = (ply1.joy_n || - ply1.joy_e || - ply1.joy_s || - ply1.joy_w || - ply1.joy_fire); } } - name[MAXNAME] = 0; - snprintf(name, MAXNAME+2, "%s/lev%02d", EM_LVL_DIR, player_level); + temp = (ply1.joy_n || ply1.joy_e || ply1.joy_s || ply1.joy_w || + ply1.joy_fire); + } + + return 0; +} + +int game_play_loop(byte action) +{ + input_eventloop(); - if (name[MAXNAME]) - snprintf_overflow("read a level in cave/"); + if (input_die || input_esc) + return 1; - if (cave_convert(name)) - continue; + if (input_refresh) + blitscreen(); - game_initscreen(); - game_blitscore(); + if (!input_pause) + { game_animscreen(); - while (1) + frame = (frame - 1) & 7; + + readjoy(action); + +#if 1 + if (input_esc) + return 1; +#endif + + if (frame == 7) { - input_eventloop(); + synchro_1(); + synchro_2(); + } - if (input_die || input_esc) - break; + if (frame == 6) + { + synchro_3(); + sound_play(); + game_blitscore(); + } + } - if (input_refresh) - blitscreen(); + return 0; +} - if (!input_pause) - { - game_animscreen(); +void game_menu_init(void) +{ + int pos = 4; + int i; - frame = (frame - 1) & 7; + title_initscreen(); - readjoy(); + for (i = 0; i < 7; i++) + drawmenu(i); /* display all lines */ - if (frame == 7) - { - synchro_1(); - synchro_2(); - } + title_blitants(4 + pos); + title_blitscore(); + title_animscreen(); - if (frame == 6) - { - synchro_3(); - sound_play(); - game_blitscore(); - } - } + game_menu_loop(1, 0); +} + +int game_loop(byte action) +{ +#if 1 + +#if 0 + printf("::: action == 0x%02x\n", action); +#endif + + if (em_game_status == EM_GAME_STATUS_MENU) + { + int result = game_menu_loop(0, action); + + if (result == 1) + { + /* exit program */ + + return 1; + } + + if (result == 2) + { + /* start playing */ + + if (game_play_init(player_level) == 0) + em_game_status = EM_GAME_STATUS_PLAY; + } + } + else if (em_game_status == EM_GAME_STATUS_PLAY) + { + if (game_play_loop(action) != 0) + { + /* stop playing */ + + game_menu_init(); + em_game_status = EM_GAME_STATUS_MENU; } } + + return 0; + +#else + + while (1) + { + int result = game_menu_loop(0); + + if (result == 1) + return 1; + + if (result == 2) + break; + } + + em_game_status = EM_GAME_STATUS_PLAY; + if (game_play_init(player_level) != 0) + return 0; + + while (1) + { + if (game_play_loop() != 0) + break; + } + + em_game_status = EM_GAME_STATUS_MENU; + game_menu_init(); + + return 0; + +#endif } /* read input device for players */ -void readjoy(void) +void readjoy(byte action) { - unsigned int i; unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0; +#if 1 + + if (action & JOY_LEFT) + west = 1; + + if (action & JOY_RIGHT) + east = 1; + + if (action & JOY_UP) + north = 1; + + if (action & JOY_DOWN) + south = 1; + + if (action & JOY_BUTTON_1) + fire = 1; + + if (action & JOY_BUTTON_2) + input_esc = 1; + +#else + + unsigned int i; + for (i = 0; i < 3; i++) if (keymatrix[northKeyCode[i] >> 3] & 1 << (northKeyCode[i] & 7)) north = 1; @@ -298,6 +417,7 @@ void readjoy(void) for (i = 0; i < 3; i++) if (keymatrix[fireKeyCode[i] >> 3] & 1 << (fireKeyCode[i] & 7)) fire = 1; +#endif ply1.joy_fire = fire; if (ply1.joy_stick || (north | east | south | west)) @@ -313,16 +433,20 @@ void readjoy(void) */ void input_eventloop(void) { +#if 0 XEvent event; +#endif unsigned int i; unsigned long count; if (input_pause) { +#if 0 XPeekEvent(display, &event); /* block until an event arrives */ if (gettimeofday(&tv1, 0) == -1) tv1.tv_usec = 0; +#endif } else { @@ -352,6 +476,7 @@ void input_eventloop(void) input_refresh = 0; lastKeySym = NoSymbol; +#if 0 while (XPending(display)) { /* drain the event queue */ @@ -387,6 +512,7 @@ void input_eventloop(void) } XQueryKeymap(display, keymatrix); /* read the keyboard */ +#endif input_esc = 0; for (i = 0; i < 1; i++) diff --git a/src/game_em/main.c b/src/game_em/main.c index a477d103..6f50f84a 100644 --- a/src/game_em/main.c +++ b/src/game_em/main.c @@ -25,9 +25,13 @@ char *arg_geometry; int arg_install; int arg_silence; +int em_game_status; + extern void tab_generate(); extern void ulaw_generate(); +extern void game_menu_init(); + void em_open_all() { /* pre-calculate some data */ @@ -38,6 +42,8 @@ void em_open_all() if (open_all() != 0) Error(ERR_EXIT, "em_open_all(): open_all() failed"); + + game_init_vars(); } void em_close_all() @@ -45,18 +51,15 @@ void em_close_all() close_all(); } -void em_main() +void em_main_init_game() { -#if 0 - em_open_all(); -#endif - - if (game_start() != 0) - Error(ERR_EXIT, "em_main(): game_start() failed"); + game_menu_init(); + em_game_status = EM_GAME_STATUS_MENU; +} -#if 0 - em_close_all(); -#endif +int em_main_handle_game(byte action) +{ + return game_loop(action); } /* massive kludge for buffer overflows diff --git a/src/init.c b/src/init.c index cdfac29b..20248885 100644 --- a/src/init.c +++ b/src/init.c @@ -4434,28 +4434,26 @@ void OpenAll() game_status = GAME_MODE_MAIN; - DrawMainMenu(); - - InitNetworkServer(); - #if 1 em_open_all(); #endif + DrawMainMenu(); + + InitNetworkServer(); } void CloseAllAndExit(int exit_value) { - -#if 1 - em_close_all(); -#endif - StopSounds(); FreeAllSounds(); FreeAllMusic(); CloseAudio(); /* called after freeing sounds (needed for SDL) */ +#if 1 + em_close_all(); +#endif + FreeAllImages(); FreeTileClipmasks(); diff --git a/src/screens.c b/src/screens.c index 9211c573..ddc28e8d 100644 --- a/src/screens.c +++ b/src/screens.c @@ -501,12 +501,16 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) else #endif { -#if 1 - em_main(); -#else game_status = GAME_MODE_PLAYING; StopAnimation(); + +#if 1 + + em_main_init_game(); + +#else InitGame(); + #endif } } @@ -2948,6 +2952,24 @@ void HandleGameActions() if (game_status != GAME_MODE_PLAYING) return; +#if 1 + + { + byte summarized_player_action = 0; + int i; + + for (i = 0; i < MAX_PLAYERS; i++) + summarized_player_action |= stored_player[i].action; + + if (em_main_handle_game(summarized_player_action) != 0) + { + game_status = GAME_MODE_MAIN; + DrawMainMenu(); + } + } + +#else + if (local_player->LevelSolved) GameWon(); @@ -2959,6 +2981,8 @@ void HandleGameActions() if (tape.auto_play && !tape.playing) AutoPlayTape(); /* continue automatically playing next tape */ + +#endif } /* ---------- new screen button stuff -------------------------------------- */ -- 2.34.1