improved handling mouse actions (for MM engine)
authorHolger Schemel <info@artsoft.org>
Tue, 28 Mar 2017 21:55:13 +0000 (23:55 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 23 Mar 2018 22:21:11 +0000 (23:21 +0100)
src/events.c
src/game.c
src/game.h
src/game_mm/export.h
src/game_mm/mm_game.c
src/libgame/system.h

index a43db7c6510eaa59ea666d62baee3686480755e5..b30159555f124225f1526a46778befe0bf8c6a47 100644 (file)
@@ -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
index 14aac76926d268836c040e861edd09cf2e20d261..1bfe0100d1084c4214ad9cbaff4026f1456bf450 100644 (file)
@@ -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()
index 5d5e887d4857270541ce491bd39c2e3a88128102..0e87912e25e4c6e42c76b7c975818709fe790ded 100644 (file)
@@ -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;
index ba805a2a47b5553cfcfbcb43fd8007b16e722e4b..a46f89d5ee757bd79f36b4d000f2fe3ef98cfbe7 100644 (file)
@@ -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);
 
index 9d8a8763f5d77de1f3e407485c844008ca8b3c59..a649d2333583832d335f48dd8a0d6e59669907ea 100644 (file)
@@ -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);
 }
index 2ca0021fb6d224ad9bbe5a7466fef9d1304daea2..cc9e45d930fd280de9d59457533e48272c71824b 100644 (file)
@@ -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;