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

Fix glitch through celiing with Sneak Glitch #14332

Merged
merged 2 commits into from May 21, 2024

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Jan 31, 2024

  • Goal of the PR
    Fix jump-related bugs.
  • How does the PR work?
    Check if there is free space for a jump if sneak_glitch is applied and if the player is not in a collision when the normal jump will happen.
  • Does it resolve any reported issue?
    Fix Can glitch through ceiling with Sneak Glitch #11081

To do

This PR is a Ready for Review.

How to test

See #11081.

before:

simplescreenrecorder-2024-02-01_16.11.13.mp4

after;

simplescreenrecorder-2024-02-01_16.07.50.mp4

@Zughy Zughy added the Bugfix 🐛 PRs that fix a bug label Feb 1, 2024
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Show resolved Hide resolved
@grorp grorp added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Feb 4, 2024
@sfence sfence changed the title Fix #11081 and disallow jump if player is in collision Fix glitch through celiing with Sneak Glitch Feb 4, 2024
src/collision.cpp Outdated Show resolved Hide resolved
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Generally OK but there's too many lines that show up as modified even though they weren't.

src/client/localplayer.cpp Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Thank you for splitting the code. I like where this is going so far.

src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
@Zughy Zughy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Feb 27, 2024
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Sneak code performance measurement (code: see below)

master

  • sneak: 27.3 us
  • no sneak: 24.7 us

PR:

  • sneak: 73.5 us
  • no sneak: 25.9 us

Bug 1:

  1. hold sneak until further notice
  2. hold the forward key. collide horizontally with a node
  3. try to jump - at some chance you can't.
  4. release forward key. still cannot jump

This seems to work better when being further away from spawn (e.g. 10000,10,10000)


Code for the performance measurement:

diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index 1470d819a..7c122825b 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "client.h"
 #include "content_cao.h"
+#include "profiler.h"
 
 /*
        LocalPlayer
@@ -202,6 +203,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                return;
        }
 
+       TimeTaker tt("", nullptr, TimePrecision::PRECISION_MICRO);
+
        PlayerSettings &player_settings = getPlayerSettings();
 
        // Skip collision detection if noclip mode is used
@@ -494,6 +497,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
 
        // Autojump
        handleAutojump(dtime, env, result, initial_position, initial_speed, pos_max_d);
+       g_profiler->avg("Client: sneak [us]", tt.stop());
 }
 
 void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d)

@grorp grorp added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Mar 31, 2024
@sfence
Copy link
Contributor Author

sfence commented Apr 1, 2024

@grorp What kind of change is needed now?

@grorp
Copy link
Member

grorp commented Apr 1, 2024

SmallJoker reported a bug in #14332 (review) on Feb 28, which has not been fixed as far as I can see.

@sfence
Copy link
Contributor Author

sfence commented Apr 9, 2024

The bug reported by @SmallJoker should be fixed now.

I am not able to reproduce the original glitch. Hopefully due to the new collision detection logic.
But I removed the part of the code, the fix does not work without it before.

So, more testing that the glitch cannot be reproduced is welcome.

@sfence
Copy link
Contributor Author

sfence commented Apr 9, 2024

Windows build failed due to:

CMake Error at irr/src/CMakeLists.txt:267 (message):
SDL2 is too old, required is at least 2.0.10!

src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
@grorp
Copy link
Member

grorp commented Apr 11, 2024

Also, please take a look at the Code style guidelines and adjust newly written code accordingly. (The old code you've only moved can stay as is, that makes reviewing easier.)

@sfence
Copy link
Contributor Author

sfence commented May 1, 2024

Also, please take a look at the Code style guidelines and adjust newly written code accordingly. (The old code you've only moved can stay as is, that makes reviewing easier.)

Checked. Hopefully, I do not miss something.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Whereas this PR technically does what it promises, it does break the sneak glitch slightly.

  1. Stand in front of the pillar from the video in the main PR post
  2. Hold down forward key
  3. Hold down the sneak key
  4. Hold down the jump key and sneak-move up by a few steps
  5. Release the jump key
  • master: player stops at the ledge (minus the sideway movement due to still holding forward)
  • PR: falls down

Sometimes this also happens when not moving forward but I found it to be easiest to reproduce this way.

@sfence
Copy link
Contributor Author

sfence commented May 5, 2024

@SmallJoker
Should be fixed now.

Copy link
Member

@grorp grorp left a comment

Choose a reason for hiding this comment

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

IMO having header comments for obvious things in a small function like collision_check_intersection is unnecessary.

Also, please clean up the ScopeProfilers and TimeTakers you copied from collisionMoveSimple which have since been removed by 2e89529

Review is not comprehensive.

src/collision.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
@Zughy Zughy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label May 7, 2024
@grorp grorp self-assigned this May 7, 2024
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

The recently mentioned sneak issue is now solved
Collision still works properly. Tested by colliding with a mob_horse entity.

src/collision.cpp Outdated Show resolved Hide resolved
src/client/localplayer.cpp Outdated Show resolved Hide resolved
Copy link
Member

@grorp grorp left a comment

Choose a reason for hiding this comment

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

OK

@grorp
Copy link
Member

grorp commented May 21, 2024

(trivially rebased after #14654)

@grorp grorp merged commit df8a600 into minetest:master May 21, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can glitch through ceiling with Sneak Glitch
7 participants