]> git.lizzy.rs Git - minetest.git/commitdiff
Add tiny Y offset in collisionMoveSimple() to tweak performance
authorJens Rottmann <30634967+JRottm@users.noreply.github.com>
Fri, 4 Aug 2017 23:42:39 +0000 (01:42 +0200)
committersfan5 <sfan5@live.de>
Sat, 5 Aug 2017 10:38:11 +0000 (12:38 +0200)
Another small general problem: the player is always standing exactly on the
bondary between 2 nodes e.g. Y=1.5 is exactly between nodes Y=1 and Y=2.
floatToInt() and myround() will round +/-n.5 always 'outwards' to +/-(n+1),
which means they behave differently depending on where you are: they round
upwards above sea level and downwards when underground. This inconsistency
comes from the way the coordinates are calculated, independent of the
specific C++ code.

The result is a tiny bit of lost performance when moving underground,
because 1 node level more than necessary is checked for collisions. This can
be amended by adding a tiny offset to minpos_f.Y, like @paramat suggested.
This is not an elegant solution, but still better than wasting CPU.

src/collision.cpp

index 9bd75899530a7ba0d1f9950483fd34996015e3e0..9d0e8b361f78f38f2f4dea614a6d9e95233d0dd2 100644 (file)
@@ -260,7 +260,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
        v3f newpos_f = *pos_f + *speed_f * dtime;
        v3f minpos_f(
                MYMIN(pos_f->X, newpos_f.X),
-               MYMIN(pos_f->Y, newpos_f.Y),
+               MYMIN(pos_f->Y, newpos_f.Y) + 0.01 * BS, // bias rounding, player often at +/-n.5
                MYMIN(pos_f->Z, newpos_f.Z)
        );
        v3f maxpos_f(