From: Holger Schemel Date: Tue, 28 Mar 2017 21:55:13 +0000 (+0200) Subject: improved handling mouse actions (for MM engine) X-Git-Tag: 4.1.0.0~147 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=7e68d10c8f4c814e532cc30f6fc721c269a99cb6;p=rocksndiamonds.git improved handling mouse actions (for MM engine) --- diff --git a/src/events.c b/src/events.c index a43db7c6..b3015955 100644 --- a/src/events.c +++ b/src/events.c @@ -370,6 +370,13 @@ void ClearEventQueue() } } +void ClearPlayerMouseAction() +{ + local_player->mouse_action.lx = 0; + local_player->mouse_action.ly = 0; + local_player->mouse_action.button = 0; +} + void ClearPlayerAction() { int i; @@ -380,6 +387,22 @@ void ClearPlayerAction() stored_player[i].action = 0; ClearJoystickState(); + ClearPlayerMouseAction(); +} + +void SetPlayerMouseAction(int mx, int my, int button) +{ + int lx = getLevelFromScreenX(mx); + int ly = getLevelFromScreenY(my); + + ClearPlayerMouseAction(); + + if (!IN_GFX_FIELD_PLAY(mx, my) || !IN_LEV_FIELD(lx, ly)) + return; + + local_player->mouse_action.lx = lx; + local_player->mouse_action.ly = ly; + local_player->mouse_action.button = button; } void SleepWhileUnmapped() @@ -1325,11 +1348,10 @@ void HandleButton(int mx, int my, int button, int button_nr) break; case GAME_MODE_PLAYING: - if (level.game_engine_type == GAME_ENGINE_TYPE_MM && !tape.pausing) - ClickElement(mx, my, button); + SetPlayerMouseAction(mx, my, button); + #if defined(TARGET_SDL2) - else - HandleFollowFinger(mx, my, button); + HandleFollowFinger(mx, my, button); #endif #ifdef DEBUG diff --git a/src/game.c b/src/game.c index 14aac769..1bfe0100 100644 --- a/src/game.c +++ b/src/game.c @@ -3330,6 +3330,10 @@ void InitGame() player->effective_action = 0; player->programmed_action = 0; + player->mouse_action.lx = 0; + player->mouse_action.ly = 0; + player->mouse_action.button = 0; + player->score = 0; player->score_final = 0; @@ -11509,14 +11513,9 @@ void GameActions_SP_Main() void GameActions_MM_Main() { - byte effective_action[MAX_PLAYERS]; boolean warp_mode = (tape.playing && tape.warp_forward && !tape.pausing); - int i; - - for (i = 0; i < MAX_PLAYERS; i++) - effective_action[i] = stored_player[i].effective_action; - GameActions_MM(effective_action, warp_mode); + GameActions_MM(local_player->mouse_action, warp_mode); } void GameActions_RND_Main() diff --git a/src/game.h b/src/game.h index 5d5e887d..0e87912e 100644 --- a/src/game.h +++ b/src/game.h @@ -232,6 +232,8 @@ struct PlayerInfo byte programmed_action; /* action forced by game itself (like moving through doors); overrides other actions */ + struct MouseActionInfo mouse_action; /* (used by MM engine only) */ + int jx, jy, last_jx, last_jy; int MovDir, MovPos, GfxDir, GfxPos; int Frame, StepFrame; diff --git a/src/game_mm/export.h b/src/game_mm/export.h index ba805a2a..a46f89d5 100644 --- a/src/game_mm/export.h +++ b/src/game_mm/export.h @@ -200,7 +200,7 @@ extern void InitGfxBuffers_MM(); extern void InitGameEngine_MM(); extern void InitGameActions_MM(); -extern void GameActions_MM(byte *, boolean); +extern void GameActions_MM(struct MouseActionInfo, boolean); extern void ClickElement(int, int, int); diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index 9d8a8763..a649d233 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -2430,13 +2430,12 @@ static void ContinueMoving_MM(int x, int y) laser.redraw = TRUE; } -void ClickElement(int mx, int my, int button) +void ClickElement(int x, int y, int button) { static unsigned int click_delay = 0; static int click_delay_value = CLICK_DELAY_SHORT; static boolean new_button = TRUE; int element; - int x = (mx - SX) / TILEX, y = (my - SY) / TILEY; /* do not rotate objects hit by the laser after the game was solved */ if (game_mm.level_solved && Hit[x][y]) @@ -2459,7 +2458,7 @@ void ClickElement(int mx, int my, int button) if (button == MB_MIDDLEBUTTON) /* middle button has no function */ return; - if (!IN_PIX_FIELD(mx - SX, my - SY)) + if (!IN_LEV_FIELD(x, y)) return; if (Feld[x][y] == EL_EMPTY) @@ -2762,7 +2761,7 @@ void ColorCycling(void) } } -static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode) +static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) { static unsigned int action_delay = 0; static unsigned int pacman_delay = 0; @@ -3440,10 +3439,9 @@ static void GameActions_MM_Ext(byte action[MAX_PLAYERS], boolean warp_mode) return; } -void GameActions_MM(byte action[MAX_PLAYERS], boolean warp_mode) +void GameActions_MM(struct MouseActionInfo action, boolean warp_mode) { - if (!button_status) - ClickElement(0, 0, MB_NOT_PRESSED); + ClickElement(action.lx, action.ly, action.button); GameActions_MM_Ext(action, warp_mode); } diff --git a/src/libgame/system.h b/src/libgame/system.h index 2ca0021f..cc9e45d9 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1422,6 +1422,12 @@ struct TextPosInfo int style; /* needed for panel time/health graphics */ }; +struct MouseActionInfo +{ + int lx, ly; + int button; +}; + struct LevelStats { int played;