Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 4bd5157

Browse files
committed
review changes
1 parent c6acbfc commit 4bd5157

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

Managers/UInputMan.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ namespace RTE {
100100
m_NetworkAccumulatedElementState[element][inputState] = false;
101101
}
102102
}
103+
104+
105+
#ifdef __unix__
106+
m_AllegroMousePreviousX = 0;
107+
m_AllegroMousePreviousY = 0;
108+
#endif
109+
103110
}
104111

105112
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1017,40 +1024,39 @@ namespace RTE {
10171024

10181025
#ifdef __unix__
10191026
void UInputMan::HandleAllegroMouseInput() {
1020-
if (_xwin.display == 0)
1027+
if (_xwin.display == 0) {
10211028
return;
1029+
}
10221030

1023-
int nEvents = XPending(_xwin.display);
10241031
std::vector<XEvent> events;
1025-
events.reserve(nEvents + 10);
1026-
for (int i = 0; i < XPending(_xwin.display); ++i) {
1032+
events.reserve(XPending(_xwin.display) + 10);
1033+
while(XPending(_xwin.display) > 0) {
10271034
XEvent e;
10281035
XNextEvent(_xwin.display, &e);
10291036
events.push_back(e);
10301037
}
10311038

1032-
static int mousePrevX = 0;
1033-
static int mousePrevY = 0;
1034-
mousePrevX = mouse_x;
1035-
mousePrevY = mouse_y;
1036-
int dx = 0;
1037-
int dy = 0;
1039+
g_UInputMan.m_AllegroMousePreviousX = mouse_x;
1040+
g_UInputMan.m_AllegroMousePreviousY = mouse_y;
1041+
int mouseDeltaX = 0;
1042+
int mouseDeltaY = 0;
10381043

10391044
int halfResX = _xwin.window_width / 2;
10401045
int halfResY = _xwin.window_height / 2;
1041-
for (auto event = events.rbegin(); event < events.rend(); ++event) {
1046+
for (std::vector<XEvent>::reverse_iterator event = events.rbegin(); event < events.rend(); ++event) {
10421047
switch (event->type) {
10431048
case MotionNotify: {
1044-
dx = event->xmotion.x - mousePrevX;
1045-
dy = event->xmotion.y - mousePrevY;
1046-
_xwin_mouse_interrupt(dx, dy, 0, 0, mouse_b);
1047-
_mouse_x = mousePrevX = !g_UInputMan.m_TrapMousePos ? event->xmotion.x : halfResX;
1048-
_mouse_y = mousePrevY = !g_UInputMan.m_TrapMousePos ? event->xmotion.y : halfResY;
1049+
mouseDeltaX = event->xmotion.x - g_UInputMan.m_AllegroMousePreviousX;
1050+
mouseDeltaY = event->xmotion.y - g_UInputMan.m_AllegroMousePreviousY;
1051+
_xwin_mouse_interrupt(mouseDeltaX, mouseDeltaY, 0, 0, mouse_b);
1052+
_mouse_x = g_UInputMan.m_AllegroMousePreviousX = !g_UInputMan.m_TrapMousePos ? event->xmotion.x : halfResX;
1053+
_mouse_y = g_UInputMan.m_AllegroMousePreviousY = !g_UInputMan.m_TrapMousePos ? event->xmotion.y : halfResY;
10491054

1050-
if (g_UInputMan.m_TrapMousePos && (dx != 0 || dy != 0)) {
1055+
if (g_UInputMan.m_TrapMousePos && (mouseDeltaX != 0 || mouseDeltaY != 0)) {
10511056
XWarpPointer(_xwin.display, _xwin.window, _xwin.window, 0, 0, 0, 0, halfResX, halfResY);
10521057
}
1053-
} break;
1058+
break;
1059+
}
10541060

10551061
default:
10561062
XPutBackEvent(_xwin.display, &(*event));

Managers/UInputMan.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,11 @@ namespace RTE {
797797
UInputMan & operator=(const UInputMan &rhs) = delete;
798798

799799
#ifdef __unix__
800+
private:
801+
802+
int m_AllegroMousePreviousX; //!< Stored mouse x position for the allegro event handler.
803+
int m_AllegroMousePreviousY; //!< Stored mouse y position for the allegro event handler.
804+
800805
/// <summary>
801806
/// Mouse input handler to circumvent the input drops that allegro does regularly, by replacing and disabling the default warping behaviour.
802807
/// Motion events that are generated while the handler is working are offset such that the allegro driver doesn't mess up the mickeys.
@@ -806,15 +811,11 @@ namespace RTE {
806811
static void HandleAllegroMouseInput(void);
807812

808813
/// <summary>
809-
/// Position the mouse on the screen in window coordinates. Generates MouseMotion events iff the requested position is different from the actual mouse position.
814+
/// Position the mouse on the screen in window coordinates. Generates MouseMotion events if the requested position is different from the actual mouse position.
810815
/// Replaces position_mouse and sets the allegro internal mouse position to the requested x,y.
811816
/// </summary>
812-
/// <param name="x">
813-
/// The x coordinate to warp to.
814-
/// </param>
815-
/// <param name="y">
816-
/// The y coordinate to warp to.
817-
/// </param>
817+
/// <param name="x"> The x coordinate to warp to. </param>
818+
/// <param name="y"> The y coordinate to warp to. </param>
818819
void WarpMouse(int x, int y) const;
819820
#endif
820821
};

0 commit comments

Comments
 (0)