Fix bug with high velocities in vents in 32bit builds, fix #71

See https://github.com/yquake2/yquake2/issues/71
and https://github.com/yquake2/xatrix/issues/4

In ClientThink(), the float value ent->velocity[i]*8 is saved into
a short and if the value is too big for a short, in 32bit gcc builds
the short is set to SHRT_MIN, resulting in the player being pressed
down instead of up.
Now we put the result in a 32bit int first (which should be big enough)
and assign the int to the short. This still overflows, but with -fwrapv
at least in a defined way (most probably the same way the original
binaries did).

And while I was at it, when the game lib is loaded, it prints the date
it was built, this is especially interesting for our Win32 binaries.
This commit is contained in:
Daniel Gibson 2015-05-17 18:52:18 +02:00
parent 4e547feb2c
commit 41ea8879e7
3 changed files with 7 additions and 4 deletions

View file

@ -155,12 +155,12 @@ endif
# generated if building universal binaries on OSX)
ifeq ($(OSTYPE), Darwin)
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g
-Wall -pipe -g -fwrapv
#-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.5.sdk
CFLAGS += $(OSX_ARCH)
else
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -ggdb -MMD
-Wall -pipe -g -ggdb -MMD -fwrapv
endif
# ----------

View file

@ -2266,7 +2266,10 @@ ClientThink(edict_t *ent, usercmd_t *ucmd)
for (i = 0; i < 3; i++)
{
pm.s.origin[i] = ent->s.origin[i] * 8;
pm.s.velocity[i] = ent->velocity[i] * 8;
/* save to an int first, in case the short overflows
* so we get defined behavior (at least with -fwrapv) */
int tmpVel = ent->velocity[i] * 8;
pm.s.velocity[i] = tmpVel;
}
if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))

View file

@ -201,7 +201,7 @@ void
InitGame(void)
{
gi.dprintf("Game is starting up.\n");
gi.dprintf("Game is %s.\n", GAMEVERSION);
gi.dprintf("Game is %s built on %s.\n", GAMEVERSION, __DATE__);
gun_x = gi.cvar("gun_x", "0", 0);
gun_y = gi.cvar("gun_y", "0", 0);