Open SiegeLord opened 1 month ago
Hello.
I've tested suggested changes and cannot confirm that mouse movement became better. On high resolutions (like 1920x1080) mouselook is still not smooth. I've tested both on mouse grab and mouse free modes.
I added some logging statements to the code:
diff --git a/ddio/lnxmouse.cpp b/ddio/lnxmouse.cpp
index 558d2519..61eeecde 100644
--- a/ddio/lnxmouse.cpp
+++ b/ddio/lnxmouse.cpp
@@ -399,6 +399,7 @@ int sdlMouseMotionFilter(SDL_Event const *event) {
DDIO_mouse_state.dy = event->motion.yrel;
DDIO_mouse_state.x += DDIO_mouse_state.dx;
DDIO_mouse_state.y += DDIO_mouse_state.dy;
+ LOG_WARNING.printf("event dx, dy: %d, %d", DDIO_mouse_state.dx, DDIO_mouse_state.dy);
} // if
else {
DDIO_mouse_state.dx = event->motion.x - DDIO_mouse_state.x;
@@ -435,6 +436,8 @@ int ddio_MouseGetState(int *x, int *y, int *dx, int *dy, int *z, int *dz) {
// update mouse timer.
int btn_mask = DDIO_mouse_state.btn_mask;
+ LOG_WARNING.printf("ddio_MouseGetState: dx=%d dy=%d", DDIO_mouse_state.dx, DDIO_mouse_state.dy);
+
// get return values.
if (x)
*x = DDIO_mouse_state.x;
diff --git a/ddio/sdlcontroller.cpp b/ddio/sdlcontroller.cpp
index 35eadbb0..9d394f3a 100644
--- a/ddio/sdlcontroller.cpp
+++ b/ddio/sdlcontroller.cpp
@@ -1237,6 +1237,7 @@ float sdlgameController::get_axis_value(int8_t controller, uint8_t axis, ct_form
if (invert)
val = -val;
+ LOG_WARNING.printf("mouselook x: %f", val);
vm_AnglesToMatrix(&orient, 0.0, val * (((float)(65535.0f / 20)) * .5), 0.0);
@@ -1260,6 +1261,7 @@ float sdlgameController::get_axis_value(int8_t controller, uint8_t axis, ct_form
if (invert)
val = -val;
+ LOG_WARNING.printf("mouselook y: %f", val);
vm_AnglesToMatrix(&orient, val * (((float)(65535.0f / 20)) * .5), 0.0, 0.0);
Then I launched the game and moved the mouse at various speeds. Here's the the logs with slow and fast mouse movement with unmodified mouse code:
2024-10-27 13:35:10.481 WARN [25028] [ddio_MouseGetState@439] ddio_MouseGetState: dx=-1 dy=0
2024-10-27 13:35:10.481 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:10.497 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.497 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.208334
2024-10-27 13:35:10.513 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.513 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:10.529 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.529 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.530 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.195313
2024-10-27 13:35:10.545 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.545 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 0, -1
2024-10-27 13:35:10.546 WARN [25028] [ddio_MouseGetState@439] ddio_MouseGetState: dx=0 dy=-1
2024-10-27 13:35:10.546 WARN [25028] [sdlgameController::get_axis_value@1264] mouselook y: -0.260417
2024-10-27 13:35:10.562 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.563 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.563 WARN [25028] [sdlgameController::get_axis_value@1264] mouselook y: -0.245098
2024-10-27 13:35:10.580 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.580 WARN [25028] [sdlgameController::get_axis_value@1264] mouselook y: -0.245098
2024-10-27 13:35:10.597 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 0, -1
2024-10-27 13:35:10.597 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:10.597 WARN [25028] [ddio_MouseGetState@439] ddio_MouseGetState: dx=-1 dy=0
2024-10-27 13:35:10.597 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:10.614 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:10.631 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:15.801 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.195313
2024-10-27 13:35:15.817 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 0
2024-10-27 13:35:15.817 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 1
2024-10-27 13:35:15.817 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 1
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -2, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:35:15.818 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.818 WARN [25028] [ddio_MouseGetState@439] ddio_MouseGetState: dx=-1 dy=0
2024-10-27 13:35:15.818 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:35:15.835 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:35:15.835 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:15.852 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 0, 1
2024-10-27 13:35:15.852 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:35:15.852 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:35:15.852 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.852 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 1
2024-10-27 13:35:15.852 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: -0.183824
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 1
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 1
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 1
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 3, 1
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 3, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:35:15.869 WARN [25028] [sdlMouseMotionFilter@402] event dx, dy: 3, 0
2024-10-27 13:35:15.869 WARN [25028] [ddio_MouseGetState@439] ddio_MouseGetState: dx=3 dy=0
2024-10-27 13:35:15.869 WARN [25028] [sdlgameController::get_axis_value@1240] mouselook x: 0.551471
My understanding of what's happening is that sdlMouseMotionFilter
is called asynchronously, and ddio_MouseGetState
is called regularly (but not every frame, there's some weird logic in the controller polling). The mouselook code is called every frame however, so it ends up reading the last value computed by ddio_MouseGetState
with some frame-time normalization of some sort. Anyway, the thing to look at here is, e.g., mouselook x
, which is roughly the same whether the mouse moves fast or slow.
Then, I implemented my changes, and turned down the mouse sensitivity. Here's the logs with slow + fast mouse movement:
2024-10-27 13:48:58.555 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.156251
2024-10-27 13:48:58.571 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:48:58.571 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -2, 1
2024-10-27 13:48:58.571 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -3, 1
2024-10-27 13:48:58.571 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.156251
2024-10-27 13:48:58.587 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -4, 1
2024-10-27 13:48:58.587 WARN [25160] [ddio_MouseGetState@439] ddio_MouseGetState: dx=-4 dy=1
2024-10-27 13:48:58.587 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.052084
2024-10-27 13:48:58.587 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.156251
2024-10-27 13:48:58.603 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:48:58.603 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -1, 1
2024-10-27 13:48:58.603 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -2, 1
2024-10-27 13:48:58.603 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.052084
2024-10-27 13:48:58.603 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.156251
2024-10-27 13:48:58.620 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -3, 1
2024-10-27 13:48:58.620 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -4, 1
2024-10-27 13:48:58.620 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.049020
2024-10-27 13:48:58.620 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.147060
2024-10-27 13:48:58.636 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -4, 2
2024-10-27 13:48:58.636 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -5, 2
2024-10-27 13:48:58.636 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.052084
2024-10-27 13:48:58.636 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.156251
2024-10-27 13:48:58.652 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -6, 2
2024-10-27 13:48:58.652 WARN [25160] [ddio_MouseGetState@439] ddio_MouseGetState: dx=-6 dy=2
2024-10-27 13:48:58.652 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.104167
2024-10-27 13:48:58.652 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.234376
2024-10-27 13:48:58.669 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.098040
2024-10-27 13:48:58.669 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.220589
2024-10-27 13:48:58.686 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: -1, 0
2024-10-27 13:48:58.686 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: 0.098040
2024-10-27 13:48:58.686 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: -0.220589
2024-10-27 13:49:00.141 WARN [25160] [ddio_MouseGetState@439] ddio_MouseGetState: dx=10 dy=0
2024-10-27 13:49:00.141 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.367649
2024-10-27 13:49:00.158 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:49:00.158 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 1, -1
2024-10-27 13:49:00.158 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 2, -1
2024-10-27 13:49:00.158 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 3, -1
2024-10-27 13:49:00.159 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.367649
2024-10-27 13:49:00.175 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 4, -1
2024-10-27 13:49:00.176 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 5, -1
2024-10-27 13:49:00.176 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 6, -1
2024-10-27 13:49:00.176 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 7, -1
2024-10-27 13:49:00.176 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 8, -1
2024-10-27 13:49:00.176 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.367649
2024-10-27 13:49:00.192 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 9, -1
2024-10-27 13:49:00.192 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 10, -1
2024-10-27 13:49:00.192 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 11, -2
2024-10-27 13:49:00.192 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 12, -2
2024-10-27 13:49:00.192 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 13, -2
2024-10-27 13:49:00.192 WARN [25160] [ddio_MouseGetState@439] ddio_MouseGetState: dx=13 dy=-2
2024-10-27 13:49:00.192 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: -0.098040
2024-10-27 13:49:00.192 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.477944
2024-10-27 13:49:00.208 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 1, 0
2024-10-27 13:49:00.208 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 2, 0
2024-10-27 13:49:00.208 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 3, 0
2024-10-27 13:49:00.208 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 4, 0
2024-10-27 13:49:00.208 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: -0.104167
2024-10-27 13:49:00.208 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.507815
2024-10-27 13:49:00.224 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 5, 0
2024-10-27 13:49:00.224 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 6, 0
2024-10-27 13:49:00.224 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 7, -1
2024-10-27 13:49:00.224 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 8, -1
2024-10-27 13:49:00.224 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 9, -1
2024-10-27 13:49:00.224 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: -0.104167
2024-10-27 13:49:00.224 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.507815
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 10, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 11, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 12, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 13, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 14, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 15, -1
2024-10-27 13:49:00.240 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: -0.104167
2024-10-27 13:49:00.240 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.507815
2024-10-27 13:49:00.257 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 16, -1
2024-10-27 13:49:00.257 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 17, -1
2024-10-27 13:49:00.257 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 18, -2
2024-10-27 13:49:00.257 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 19, -2
2024-10-27 13:49:00.257 WARN [25160] [sdlMouseMotionFilter@402] event dx, dy: 20, -2
2024-10-27 13:49:00.257 WARN [25160] [ddio_MouseGetState@439] ddio_MouseGetState: dx=20 dy=-2
2024-10-27 13:49:00.257 WARN [25160] [sdlgameController::get_axis_value@1264] mouselook y: -0.098040
2024-10-27 13:49:00.257 WARN [25160] [sdlgameController::get_axis_value@1240] mouselook x: 0.735298
Now the mouselook x
is small when mouse moves slowly, and large when it moves more quickly. The reason is seen from the logs: the base code takes the last value of event dx, dy
while the new code sums them up until they're reset by ddio_MouseGetState
.
I tried the changes and can confirm that the mouse movement is faster in the game. With a lower sensitivity setting (about 0.12) the jerkiness goes away and pixel perfect mouse aiming becomes possible. But for fast rotation the mouse has to be moved longer distances, which is a different play style that I had to get used to. But after a while I liked it a lot.
Without the changes I tried a mouse sensitivity of 0.2 which also allows pixel perfect mouse aiming. But fast rotation is impossible even with wide mouse gestures. That's likely because several successive mouse delta events get silently ignored. The game is barely playable that way because hunting down fast moving robots is impossible.
So far I believe
Build Version
398699e04588cf154a189f783e5cde308f78bc99
Operating System Environment
CPU Environment
Game Modes Affected
Game Environment
No response
Description
Mouselook is very jerky regardless of sensitivity settings. The issue is that the code in lnxmouse.cpp sets the dx/dy values based on the xrel/yrel values, which discards the xrel/yrel values coming from earlier mouse events in the same timestep. Here's how I fixed it:
Note that this makes the mouse move a lot faster than in the base game, necessitating rescaling the mouse sensitivity in some way. I opted to increase the resolution of the sensitivity range, and then turn down the sensitivity:
I don't know the implication of these changes, but I figured I'd share these rough versions of them in case they can help a well-thought-out solution. For me at least, this is an enormously impactful change, making mouselook actually a viable way to play.
Regression Status
No response
Steps to Reproduce