From 91601455766f1749465cd064b54b8158313c0d51 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 21 Apr 2020 22:13:13 +0200 Subject: [PATCH] added support for tapes with both keyboard/joystick and mouse actions --- src/events.c | 8 ++++---- src/files.c | 37 +++++++++++++++++++------------------ src/game.c | 10 +++++----- src/tape.c | 4 ++-- src/tape.h | 9 ++++----- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/events.c b/src/events.c index d48cf480..45da8607 100644 --- a/src/events.c +++ b/src/events.c @@ -464,7 +464,7 @@ static void SetPlayerMouseAction(int mx, int my, int button) local_player->mouse_action.ly = ly; local_player->mouse_action.button = button; - if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_MOUSE) + if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_MOUSE)) { // un-pause a paused game only if mouse button was newly pressed down if (new_button) @@ -1375,7 +1375,7 @@ static void HandleButtonOrFinger(int mx, int my, int button) { if (strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER)) HandleButtonOrFinger_FollowFinger(mx, my, button); - else if (game.event_mask == GAME_EVENTS_MOUSE && valid_mouse_event) + else if ((game.event_mask & GAME_EVENTS_MOUSE) && valid_mouse_event) SetPlayerMouseAction(mx, my, button); } } @@ -2098,7 +2098,7 @@ void HandleKey(Key key, int key_status) if (stored_player[pnr].snap_action) stored_player[pnr].action |= JOY_BUTTON_SNAP; - if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_KEYS) + if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_KEYS)) { if (tape.single_step) { @@ -2633,7 +2633,7 @@ void HandleJoystick(void) return; } - if (tape.recording && tape.pausing && tape.event_mask == GAME_EVENTS_KEYS) + if (tape.recording && tape.pausing && (tape.event_mask & GAME_EVENTS_KEYS)) { if (tape.single_step) { diff --git a/src/files.c b/src/files.c index d3885820..95256480 100644 --- a/src/files.c +++ b/src/files.c @@ -7623,9 +7623,10 @@ static int getTapePosSize(struct TapeInfo *tape) { int tape_pos_size = 0; - if (tape->event_mask == GAME_EVENTS_KEYS) + if (tape->event_mask & GAME_EVENTS_KEYS) tape_pos_size += tape->num_participating_players; - else + + if (tape->event_mask & GAME_EVENTS_MOUSE) tape_pos_size += 3; // x and y position and mouse button mask tape_pos_size += 1; // tape action delay value @@ -7764,15 +7765,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) break; } - if (tape->event_mask == GAME_EVENTS_MOUSE) - { - tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file); - tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file); - tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file); - - tape->pos[i].action[TAPE_ACTION_UNUSED] = 0; - } - else + if (tape->event_mask & GAME_EVENTS_KEYS) { for (j = 0; j < MAX_PLAYERS; j++) { @@ -7783,6 +7776,13 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) } } + if (tape->event_mask & GAME_EVENTS_MOUSE) + { + tape->pos[i].action[TAPE_ACTION_LX] = getFile8Bit(file); + tape->pos[i].action[TAPE_ACTION_LY] = getFile8Bit(file); + tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file); + } + tape->pos[i].delay = getFile8Bit(file); if (tape->file_version == FILE_VERSION_1_0) @@ -8133,19 +8133,20 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) for (i = 0; i < tape->length; i++) { - if (tape->event_mask == GAME_EVENTS_MOUSE) - { - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]); - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]); - putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]); - } - else + if (tape->event_mask & GAME_EVENTS_KEYS) { for (j = 0; j < MAX_PLAYERS; j++) if (tape->player_participates[j]) putFile8Bit(file, tape->pos[i].action[j]); } + if (tape->event_mask & GAME_EVENTS_MOUSE) + { + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]); + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]); + putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]); + } + putFile8Bit(file, tape->pos[i].delay); } } diff --git a/src/game.c b/src/game.c index 36fc3b68..9fe37cc5 100644 --- a/src/game.c +++ b/src/game.c @@ -3300,7 +3300,7 @@ static void InitGameEngine(void) HAS_CHANGE_EVENT(element, CE_PRESSED_BY_MOUSE) || HAS_CHANGE_EVENT(element, CE_MOUSE_CLICKED_ON_X) || HAS_CHANGE_EVENT(element, CE_MOUSE_PRESSED_ON_X)) - game.event_mask = GAME_EVENTS_MOUSE; + game.event_mask = GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE; } } } @@ -11176,7 +11176,7 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action, byte *tape_action) { - if (tape.event_mask != GAME_EVENTS_MOUSE) + if (!(tape.event_mask & GAME_EVENTS_MOUSE)) return; mouse_action->lx = tape_action[TAPE_ACTION_LX]; @@ -11187,7 +11187,7 @@ static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action, static void SetTapeActionFromMouseAction(byte *tape_action, struct MouseActionInfo *mouse_action) { - if (tape.event_mask != GAME_EVENTS_MOUSE) + if (!(tape.event_mask & GAME_EVENTS_MOUSE)) return; tape_action[TAPE_ACTION_LX] = mouse_action->lx; @@ -11910,8 +11910,8 @@ void GameActions_RND(void) { int new_button = (mouse_action.button && mouse_action_last.button == 0); - x = local_player->mouse_action.lx; - y = local_player->mouse_action.ly; + x = mouse_action.lx; + y = mouse_action.ly; element = Feld[x][y]; if (new_button) diff --git a/src/tape.c b/src/tape.c index 2464832c..09959763 100644 --- a/src/tape.c +++ b/src/tape.c @@ -706,7 +706,7 @@ void TapeRecordAction(byte action_raw[MAX_TAPE_ACTIONS]) for (i = 0; i < MAX_TAPE_ACTIONS; i++) action[i] = action_raw[i]; - if (tape.event_mask == GAME_EVENTS_KEYS && tape.set_centered_player) + if ((tape.event_mask & GAME_EVENTS_KEYS) && tape.set_centered_player) { for (i = 0; i < MAX_PLAYERS; i++) if (tape.centered_player_nr_next == i || @@ -887,7 +887,7 @@ byte *TapePlayAction(void) tape.set_centered_player = FALSE; tape.centered_player_nr_next = -999; - if (tape.event_mask == GAME_EVENTS_KEYS) + if (tape.event_mask & GAME_EVENTS_KEYS) { for (i = 0; i < MAX_PLAYERS; i++) { diff --git a/src/tape.h b/src/tape.h index eb0231b1..d2878581 100644 --- a/src/tape.h +++ b/src/tape.h @@ -22,12 +22,11 @@ #define MAX_TAPE_LEN (1000 * FRAMES_PER_SECOND) // max.time x fps // values for tape mouse actions -#define TAPE_ACTION_LX 0 -#define TAPE_ACTION_LY 1 -#define TAPE_ACTION_BUTTON 2 -#define TAPE_ACTION_UNUSED 3 +#define TAPE_ACTION_LX (MAX_PLAYERS + 0) +#define TAPE_ACTION_LY (MAX_PLAYERS + 1) +#define TAPE_ACTION_BUTTON (MAX_PLAYERS + 2) -#define MAX_TAPE_ACTIONS 4 +#define MAX_TAPE_ACTIONS (MAX_PLAYERS + 3) // values for tape action events stored in tape file #define TAPE_EVENTS_KEYS_ONLY 0 -- 2.34.1