Skip to content
Permalink
Browse files

Add tiny Y offset in collisionMoveSimple() to tweak performance

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.
  • Loading branch information
JRottm authored and sfan5 committed Aug 5, 2017
1 parent 0c893ea commit 248a1a8d65c483edcab328d898cc570071d6a182
Showing with 1 addition and 1 deletion.
  1. +1 −1 src/collision.cpp
@@ -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(

0 comments on commit 248a1a8

Please sign in to comment.