From: Holger Schemel Date: Tue, 21 Apr 2020 19:42:07 +0000 (+0200) Subject: replaced flag for game/tape mouse actions by bitmask X-Git-Tag: 4.2.0.0~41 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=6460301d715f72f7247b3070a5d98c0b56cfdb67;p=rocksndiamonds.git replaced flag for game/tape mouse actions by bitmask --- diff --git a/src/events.c b/src/events.c index 84449933..d48cf480 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.use_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.use_mouse_events && 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.use_mouse) + 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.use_mouse) + 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 2ca99766..d3885820 100644 --- a/src/files.c +++ b/src/files.c @@ -7623,7 +7623,7 @@ static int getTapePosSize(struct TapeInfo *tape) { int tape_pos_size = 0; - if (!tape->use_mouse) + if (tape->event_mask == GAME_EVENTS_KEYS) tape_pos_size += tape->num_participating_players; else tape_pos_size += 3; // x and y position and mouse button mask @@ -7633,6 +7633,42 @@ static int getTapePosSize(struct TapeInfo *tape) return tape_pos_size; } +static int getGameEventMaskFromTapeEventValue(int value) +{ + switch (value) + { + case TAPE_EVENTS_KEYS_ONLY: + return GAME_EVENTS_KEYS; + + case TAPE_EVENTS_MOUSE_ONLY: + return GAME_EVENTS_MOUSE; + + case TAPE_EVENTS_KEYS_AND_MOUSE: + return GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE; + + default: + return GAME_EVENTS_DEFAULT; + } +} + +static int getTapeEventValueFromGameEventMask(int mask) +{ + switch (mask) + { + case GAME_EVENTS_KEYS: + return TAPE_EVENTS_KEYS_ONLY; + + case GAME_EVENTS_MOUSE: + return TAPE_EVENTS_MOUSE_ONLY; + + case GAME_EVENTS_KEYS | GAME_EVENTS_MOUSE: + return TAPE_EVENTS_KEYS_AND_MOUSE; + + default: + return TAPE_EVENTS_DEFAULT; + } +} + static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) { tape->file_version = getFileVersion(file); @@ -7668,7 +7704,7 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) } } - tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE); + tape->event_mask = getGameEventMaskFromTapeEventValue(getFile8Bit(file)); ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -7728,7 +7764,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) break; } - if (tape->use_mouse) + 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); @@ -8070,7 +8106,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, store_participating_players); - putFile8Bit(file, (tape->use_mouse ? 1 : 0)); + putFile8Bit(file, getTapeEventValueFromGameEventMask(tape->event_mask)); // unused bytes not at the end here for 4-byte alignment of engine_version WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED); @@ -8097,7 +8133,7 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape) for (i = 0; i < tape->length; i++) { - if (tape->use_mouse) + 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]); diff --git a/src/game.c b/src/game.c index e4373903..36fc3b68 100644 --- a/src/game.c +++ b/src/game.c @@ -3280,21 +3280,28 @@ static void InitGameEngine(void) if (level.game_engine_type == GAME_ENGINE_TYPE_SP) level.time = 0; - // ----------initialize flag for handling mouse events --------------------- + // ---------- initialize mask for handling game action events --------------- - // set flag to default value: do not handle mouse events - game.use_mouse_events = FALSE; + // set game action events mask to default value + game.event_mask = GAME_EVENTS_DEFAULT; - // now check for custom elements which have mouse click events defined - for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) + // when using Mirror Magic game engine, handle mouse events only + if (level.game_engine_type == GAME_ENGINE_TYPE_MM) + game.event_mask = GAME_EVENTS_MOUSE; + + // check for custom elements with mouse click events + if (level.game_engine_type == GAME_ENGINE_TYPE_RND) { - int element = EL_CUSTOM_START + i; + for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) + { + int element = EL_CUSTOM_START + i; - if (HAS_CHANGE_EVENT(element, CE_CLICKED_BY_MOUSE) || - 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.use_mouse_events = TRUE; + if (HAS_CHANGE_EVENT(element, CE_CLICKED_BY_MOUSE) || + 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; + } } } @@ -3408,6 +3415,10 @@ void InitGame(void) InitGameEngine(); InitGameControlValues(); + // initialize tape action events from game when recording tape + if (tape.recording) + tape.event_mask = game.event_mask; + // don't play tapes over network network_playing = (network.enabled && !tape.playing); @@ -11165,7 +11176,7 @@ static byte PlayerActions(struct PlayerInfo *player, byte player_action) static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action, byte *tape_action) { - if (!tape.use_mouse) + if (tape.event_mask != GAME_EVENTS_MOUSE) return; mouse_action->lx = tape_action[TAPE_ACTION_LX]; @@ -11176,7 +11187,7 @@ static void SetMouseActionFromTapeAction(struct MouseActionInfo *mouse_action, static void SetTapeActionFromMouseAction(byte *tape_action, struct MouseActionInfo *mouse_action) { - if (!tape.use_mouse) + if (tape.event_mask != GAME_EVENTS_MOUSE) return; tape_action[TAPE_ACTION_LX] = mouse_action->lx; diff --git a/src/game.h b/src/game.h index 74625440..e20f50fa 100644 --- a/src/game.h +++ b/src/game.h @@ -42,6 +42,13 @@ #define SNAPSHOT_MODE_EVERY_COLLECT 3 #define SNAPSHOT_MODE_DEFAULT SNAPSHOT_MODE_OFF +// values for game action events handled by game engine +#define GAME_EVENTS_NONE 0 +#define GAME_EVENTS_KEYS (1 << 0) +#define GAME_EVENTS_MOUSE (1 << 1) + +#define GAME_EVENTS_DEFAULT GAME_EVENTS_KEYS + struct GamePanelInfo { @@ -178,8 +185,8 @@ struct GameInfo boolean max_num_changes_per_frame; boolean use_reverse_scan_direction; - // flag to indicate if mouse events are processed by game engine - boolean use_mouse_events; + // bit mask to indicate game action events handled by game engine + int event_mask; // variable within running game int yamyam_content_nr; diff --git a/src/tape.c b/src/tape.c index 61c0ec6e..2464832c 100644 --- a/src/tape.c +++ b/src/tape.c @@ -547,7 +547,7 @@ void TapeErase(void) tape.centered_player_nr_next = -1; tape.set_centered_player = FALSE; - tape.use_mouse = (level.game_engine_type == GAME_ENGINE_TYPE_MM); + tape.event_mask = GAME_EVENTS_DEFAULT; } static void TapeRewind(void) @@ -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.use_mouse && 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.use_mouse) + 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 c20fab41..eb0231b1 100644 --- a/src/tape.h +++ b/src/tape.h @@ -29,6 +29,13 @@ #define MAX_TAPE_ACTIONS 4 +// values for tape action events stored in tape file +#define TAPE_EVENTS_KEYS_ONLY 0 +#define TAPE_EVENTS_MOUSE_ONLY 1 +#define TAPE_EVENTS_KEYS_AND_MOUSE 2 + +#define TAPE_EVENTS_DEFAULT TAPE_EVENTS_KEYS_ONLY + // some positions in the video tape control window #define VIDEO_DISPLAY1_XPOS 5 #define VIDEO_DISPLAY1_YPOS 5 @@ -192,7 +199,7 @@ struct TapeInfo int centered_player_nr_next; boolean set_centered_player; - boolean use_mouse; + int event_mask; // game action events stored in tape actions struct {