Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce fast mouse polling for lower lag interpolation #1194

Merged
merged 13 commits into from
Aug 2, 2024
Merged

Conversation

mikeday0
Copy link
Collaborator

@mikeday0 mikeday0 commented Apr 2, 2024

This is my humble attempt to port to Crispy the fine work that @ceski-1 did for Woof. It's not ready yet but I thought it might be prudent to go ahead and get it out there for early review and testing.

EDIT: Calling this one complete. We are still missing vertical mouse and gamepad, but those can come later. The vertical mouse implementation in particular needs some careful study and refactoring across the four games.

This is not as sophisticated as the current implementation in Woof! but I think it stands on its own as a solid improvement to mousefeel for typical KB + M players.

mikeday0 and others added 2 commits April 2, 2024 14:47
Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
@ceski-1
Copy link
Collaborator

ceski-1 commented Apr 3, 2024

Nice starting point, I tested it briefly. Some issues I noticed:

  • Mouselook and mousevert feel off (compare capped and uncapped).
  • Combining keyboard turning and mouse turning at the same time has visual glitches (occasional "pops").
  • The "mouse threshold" concept in Chocolate/Crispy/Woof assumes each update is a tic in duration (1/35th of a second). So it doesn't work correctly with fast polling and the mouse will feel "slow" at higher fps. I sidestep the issue in Woof by ignoring threshold under certain conditions.
  • If you follow the mouse input calculations from start to finish, you'll notice that Crispy has rounding error in several stages. First there's AccelerateMouse() in I_ReadMouse(), then there's *(mouseSensitivity+5)/10 in G_Responder() or G_FastResponder(). By the time the error accumulator runs ("carrying" the error), it's too late and ineffective. I prevent this in Woof by doing the calculations as a single step and using doubles as working variables (see CalcMouseAngle() for example). The rounding only occurs once, in the carry function.

I'll try to give more feedback later, I know it's WIP right now.

@mikeday0
Copy link
Collaborator Author

mikeday0 commented Apr 3, 2024

  • Combining keyboard turning and mouse turning at the same time has visual glitches (occasional "pops").

I can repeat this. It appears to be fixed on my end by moving the fractionaltic update back to the end of I_FinishUpdate().

Diff
diff --git a/src/i_video.c b/src/i_video.c
index ab3c7bc9..b5f9f6f1 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -544,9 +544,6 @@ void I_StartDisplay(void) // [crispy]
 {
     SDL_PumpEvents();
 
-    // [AM] Figure out how far into the current tic we're in as a fixed_t.
-    fractionaltic = I_GetFracRealTime();
-
     if (usemouse && !nomouse && window_focused)
     {
         I_ReadMouseUncapped();
@@ -941,6 +938,9 @@ void I_FinishUpdate (void)
                 }
             }
         }
+        // [AM] Figure out how far into the current tic we're in as a fixed_t.
+        fractionaltic = I_GetFracRealTime();
+
     }
 
     // Restore background and undo the disk indicator, if it was drawn.

Does this fix the "pops" for you?

@ceski-1
Copy link
Collaborator

ceski-1 commented Apr 4, 2024

Does this fix the "pops" for you?

That seems to work fine, or like Woof:

Diff (Alt)
diff --git a/src/i_video.c b/src/i_video.c
index ab3c7bc9..328e6b1e 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -542,11 +542,11 @@ void I_StartTic (void)
 
 void I_StartDisplay(void) // [crispy]
 {
-    SDL_PumpEvents();
-
     // [AM] Figure out how far into the current tic we're in as a fixed_t.
     fractionaltic = I_GetFracRealTime();
 
+    SDL_PumpEvents();
+
     if (usemouse && !nomouse && window_focused)
     {
         I_ReadMouseUncapped();

mikeday0 and others added 9 commits April 13, 2024 09:01
Fixes random "pops" when turning using keyboard.

Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
When running uncapped, track last gametic's worth (28 ms) of mouse
movement to determine if acceleration should be applied.
* Apply mouse acceleration in g_game.
* Expand carry_t to include side and vertical movement.

Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
Co-authored-by: ceski <56656010+ceski-1@users.noreply.github.com>
@JNechaevsky
Copy link
Collaborator

Finally, tried it out on both 60 and 120 Hz monitors. It's a God's job. The difference is notable even on 120 Hz!

// Don't use localview if the player just teleported.
!player->mo->reactiontime &&
// Don't use localview if a demo is playing.
!demoplayback &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small thought: probably worth to check for !demorecording here as well. At the moment, while demo recording there is a small notable jiterring between frames while camera rotation, most likely brought by "short tics".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review Julia. I noticed this issue too. I have a fix for the jittering on my local pc that I will clean up and push when I return home this weekend.

@mikeday0 mikeday0 marked this pull request as ready for review June 28, 2024 21:02
@mikeday0 mikeday0 changed the title [WIP] Introduce fast mouse polling for lower lag interpolation Introduce fast mouse polling for lower lag interpolation Jun 28, 2024
@mikeday0
Copy link
Collaborator Author

mikeday0 commented Aug 1, 2024

@fabiangreffrath Kindly requesting a review of this PR for inclusion in the next release. Thanks!

Copy link
Owner

@fabiangreffrath fabiangreffrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this change is massive! I must have somehow missed that it was ready for review, sorry. Looks good to me, thank you. I cannot review every single line change, but I trust you enough to judge the change set just from the looks of it. 😉

@SoDOOManiac SoDOOManiac merged commit ae2fc6e into master Aug 2, 2024
5 checks passed
@mikeday0
Copy link
Collaborator Author

mikeday0 commented Aug 2, 2024

Just noticed this was a non-squashed merge. Should I revert and re-merge with squash?

@fabiangreffrath
Copy link
Owner

Just noticed this was a non-squashed merge. Should I revert and re-merge with squash?

Na, it's okay. Thanks!

@fabiangreffrath fabiangreffrath deleted the fastpoll branch August 2, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants