X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_em%2Finput.c;h=6eadbbdf0d2ca4aec9d50b6442e9270659aab066;hb=739004ae2f6fa8b334b040760486b9689d8f59da;hp=f550494ceeaac64d6d30ca5a2010df304f2705bd;hpb=da8f8eaa9d466f33d94ff884230a613b3f239700;p=rocksndiamonds.git diff --git a/src/game_em/input.c b/src/game_em/input.c index f550494c..6eadbbdf 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -3,364 +3,114 @@ * handle input from x11 and keyboard and joystick */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "main_em.h" -#include "global.h" -#include "display.h" -#include "level.h" +struct CAVE cav; +struct LOGIC lev; +struct PLAYER ply[MAX_PLAYERS]; -#if defined(TARGET_X11) +struct EngineSnapshotInfo_EM engine_snapshot_em; -unsigned long Random; - -struct PLAYER ply1; -struct PLAYER ply2; -struct LEVEL lev; - -struct LevelInfo_EM native_em_level; - -unsigned short **Boom; -unsigned short **Cave; -unsigned short **Next; -unsigned short **Draw; - -static unsigned short *Index[4][HEIGHT]; -static unsigned short Array[4][HEIGHT][WIDTH]; - -static int input_die; -static int input_pause; -static int input_refresh; -static int input_esc; - -static struct timeval tv1; -static struct timeval tv2; - -static int player_mode; -static char player_name[32]; -static int player_level; - -static void drawmenu(int pos) +void game_init_random(void) { - char buffer[256]; - - switch(pos) - { - case 0: - switch(player_mode) - { - case 0: - strcpy(buffer, "quit emerald mine"); - break; - - case 1: - strcpy(buffer, "single player"); - break; - - case 2: - strcpy(buffer, "teamwork"); - break; - } - - title_string(4, 0, 40, buffer); - break; - - case 1: - sprintf(buffer, "name: %s", player_name); - title_string(5, 0, 40, buffer); - break; - - case 2: - sprintf(buffer, "level: %d", player_level); - title_string(6, 0, 40, buffer); - break; - - case 3: - title_string(7, 0, 40, "highscores"); - break; - - case 4: - title_string(8, 0, 40, "start"); - break; - - case 5: - title_string(10, 3, 13, "played"); - title_string(10, 14, 26, "score"); - title_string(10, 27, 37, "won"); - break; - - case 6: - sprintf(buffer, "%d", 0); - title_string(11, 3, 13, buffer); - sprintf(buffer, "%d", 0); - title_string(11, 14, 26, buffer); - sprintf(buffer, "%d", 0); - title_string(11, 27, 37, buffer); - break; - } + game_em.random = 1684108901; } -void game_init_vars(void) +void game_init_cave_buffers(void) { int x, y; - Random = 1684108901; - - for (y = 0; y < HEIGHT; y++) - for (x = 0; x < WIDTH; x++) - Array[0][y][x] = ZBORDER; - for (y = 0; y < HEIGHT; y++) - for (x = 0; x < WIDTH; x++) - Array[1][y][x] = ZBORDER; - for (y = 0; y < HEIGHT; y++) - for (x = 0; x < WIDTH; x++) - Array[2][y][x] = ZBORDER; - for (y = 0; y < HEIGHT; y++) - for (x = 0; x < WIDTH; x++) - Array[3][y][x] = Xblank; - - for (y = 0; y < HEIGHT; y++) - Index[0][y] = Array[0][y]; - for (y = 0; y < HEIGHT; y++) - Index[1][y] = Array[1][y]; - for (y = 0; y < HEIGHT; y++) - Index[2][y] = Array[2][y]; - for (y = 0; y < HEIGHT; y++) - Index[3][y] = Array[3][y]; - - Cave = Index[0]; - Next = Index[1]; - Draw = Index[2]; - Boom = Index[3]; - - player_mode = 1; /* start off as single player */ - strcpy(player_name, "dave"); - player_level = 0; - - input_pause = 1 * 0; + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.cavebuf[x][y] = Zborder; + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.nextbuf[x][y] = Zborder; + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.drawbuf[x][y] = Zborder; + for (y = 0; y < CAVE_BUFFER_HEIGHT; y++) + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.boombuf[x][y] = Xblank; + + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.cavecol[x] = lev.cavebuf[x]; + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.nextcol[x] = lev.nextbuf[x]; + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.drawcol[x] = lev.drawbuf[x]; + for (x = 0; x < CAVE_BUFFER_WIDTH; x++) + lev.boomcol[x] = lev.boombuf[x]; + + lev.cave = lev.cavecol; + lev.next = lev.nextcol; + lev.draw = lev.drawcol; + lev.boom = lev.boomcol; } -int game_play_init(int level_nr, char *filename) +void InitGameEngine_EM(void) { -#if 0 - if (filename != NULL) - { -#endif - - player_level = level_nr; - -#if 1 - prepare_em_level(); -#else - if (!LoadNativeLevel_EM(filename)) - return 1; -#endif - -#if 0 - } - else /* !!! SOON OBSOLETE !!! */ - { - 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; - } -#endif + prepare_em_level(); 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; - - return 0; - } - - input_eventloop(); - - if (input_die) - return 1; - - if (input_refresh) - blitscreen(); - - if (!input_pause) - { - title_blitscore(); - title_animscreen(); - - ply1.joy_n = ply1.joy_e = ply1.joy_s = ply1.joy_w = 0; - - readjoy(action); - - if (temp == 0) - { - if (ply1.joy_fire) - return 2; - - 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--; - } - - if (ply1.joy_s && pos < 4) - { - drawmenu(pos); - pos++; - } - } - - temp = (ply1.joy_n || ply1.joy_e || ply1.joy_s || ply1.joy_w || - ply1.joy_fire); - } - return 0; + RedrawPlayfield_EM(FALSE); } -int game_play_loop(byte action) +static void UpdateGameDoorValues_EM(void) { - input_eventloop(); - - if (input_die || input_esc) - return 1; - - if (input_refresh) - blitscreen(); - - if (!input_pause) - { - game_animscreen(); - - frame = (frame - 1) & 7; - - readjoy(action); - -#if 1 - if (input_esc) - return 1; -#endif - - if (frame == 7) - { - synchro_1(); - synchro_2(); - } - - if (frame == 6) - { - synchro_3(); - sound_play(); - game_blitscore(); - } - } - - return 0; } -void game_menu_init(void) +void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode) { int i; + boolean any_player_dropping = FALSE; - title_initscreen(); + game_em.random = game_em.random * 129 + 1; - for (i = 0; i < 7; i++) - drawmenu(i); /* display all lines */ + frame = (frame - 1) & 7; - title_blitscore(); - title_animscreen(); + for (i = 0; i < MAX_PLAYERS; i++) + readjoy(action[i], &ply[i]); - game_menu_loop(1, 0); -} - -int game_loop(byte action) -{ -#if 0 - printf("::: action == 0x%02x\n", action); -#endif + UpdateEngineValues(screen_x / TILEX, screen_y / TILEY, ply[0].x, ply[0].y); - if (em_game_status == EM_GAME_STATUS_MENU) + if (frame == 7) { - int result = game_menu_loop(0, action); - - if (result == 1) - { - /* exit program */ - - return 1; - } + logic_players(); + logic_objects(); + } - if (result == 2) - { - /* start playing */ + if (frame == 6) + { + logic_globals(); - em_game_status = EM_GAME_STATUS_PLAY; - if (game_play_init(player_level, NULL) != 0) - em_game_status = EM_GAME_STATUS_MENU; - } + UpdateGameDoorValues_EM(); } - else if (em_game_status == EM_GAME_STATUS_PLAY) - { - if (game_play_loop(action) != 0) - { - /* stop playing */ - if (skip_menu) - return 1; + for (i = 0; i < MAX_PLAYERS; i++) + if (ply[i].joy_drop && + ply[i].dynamite && + ply[i].dynamite_cnt > 0 && + ply[i].dynamite_cnt < 5) + any_player_dropping = TRUE; - em_game_status = EM_GAME_STATUS_MENU; - game_menu_init(); - } - } + CheckSingleStepMode_EM(action, frame, game_em.any_player_moving, + game_em.any_player_snapping, any_player_dropping); - return 0; + RedrawPlayfield_EM(FALSE); } - /* read input device for players */ -void readjoy(byte action) +void readjoy(byte action, struct PLAYER *ply) { - unsigned int north = 0, east = 0, south = 0, west = 0, fire = 0; + int north = 0, east = 0, south = 0, west = 0; + int snap = 0, drop = 0; + + if (game_em.use_single_button && action & (JOY_BUTTON_1 | JOY_BUTTON_2)) + action |= JOY_BUTTON_1 | JOY_BUTTON_2; if (action & JOY_LEFT) west = 1; @@ -375,57 +125,64 @@ void readjoy(byte action) south = 1; if (action & JOY_BUTTON_1) - fire = 1; + snap = 1; -#if 0 if (action & JOY_BUTTON_2) - input_esc = 1; -#endif + drop = 1; + + /* always update drop action */ + ply->joy_drop = drop; - ply1.joy_fire = fire; - if (ply1.joy_stick || (north | east | south | west)) + if (ply->joy_stick || (north | east | south | west)) /* (no "| snap"!) */ { - ply1.joy_n = north; - ply1.joy_e = east; - ply1.joy_s = south; - ply1.joy_w = west; + ply->joy_n = north; + ply->joy_e = east; + ply->joy_s = south; + ply->joy_w = west; + + /* when storing last action, only update snap action with direction */ + /* (prevents clearing direction if snapping stopped before frame 7) */ + ply->joy_snap = snap; } -} + /* if no direction was stored before, allow setting snap to current state */ + if (!ply->joy_n && + !ply->joy_e && + !ply->joy_s && + !ply->joy_w) + ply->joy_snap = snap; -/* handle events from x windows and block until the next frame */ + /* use bug with snap key (mainly TAS keys) sometimes moving the player */ + if (game_em.use_snap_key_bug) + ply->joy_snap = snap; +} -void input_eventloop(void) +void SaveEngineSnapshotValues_EM(void) { - unsigned long count; + int i; - if (!input_pause) - { - XSync(display, False); /* block until all graphics are drawn */ - - if (gettimeofday(&tv2, 0) == -1) - tv2.tv_usec = 0; - - count = tv2.tv_usec + 1000000 - tv1.tv_usec; - if (count >= 1000000) - count -= 1000000; - - tv1.tv_usec = tv2.tv_usec; - if (count < 25000) - { - tv2.tv_sec = 0; - tv2.tv_usec = 25000 - count; -#if 1 - select(0, 0, 0, 0, &tv2); /* sleep a bit */ -#else - usleep(tv2.tv_usec); -#endif - } - } + engine_snapshot_em.game_em = game_em; + engine_snapshot_em.lev = lev; + + engine_snapshot_em.frame = frame; + engine_snapshot_em.screen_x = screen_x; + engine_snapshot_em.screen_y = screen_y; - input_esc = 0; - input_die = 0; - input_refresh = 0; + for (i = 0; i < 4; i++) + engine_snapshot_em.ply[i] = ply[i]; } -#endif +void LoadEngineSnapshotValues_EM(void) +{ + int i; + + game_em = engine_snapshot_em.game_em; + lev = engine_snapshot_em.lev; + + frame = engine_snapshot_em.frame; + screen_x = engine_snapshot_em.screen_x; + screen_y = engine_snapshot_em.screen_y; + + for (i = 0; i < 4; i++) + ply[i] = engine_snapshot_em.ply[i]; +}