Fix bug with high velocities in vents in 32bit builds, fix MingW build

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).

The Makefile now sets $CC to gcc for MingW builds, this should fix
https://github.com/yquake2/xatrix/issues/3

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:45:26 +02:00
parent e2b397d92c
commit 988afce481
3 changed files with 9 additions and 4 deletions

View File

@ -33,6 +33,8 @@ endif
ifeq ($(OSTYPE), Windows) ifeq ($(OSTYPE), Windows)
# At this time only i386 is supported on Windows # At this time only i386 is supported on Windows
ARCH := i386 ARCH := i386
# seems like mingw doesn't set CC by default
CC := gcc
else else
# Some platforms call it "amd64" and some "x86_64" # Some platforms call it "amd64" and some "x86_64"
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/amd64/x86_64/) ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/amd64/x86_64/)
@ -66,10 +68,10 @@ endif
# -MMD to generate header dependencies. # -MMD to generate header dependencies.
ifeq ($(OSTYPE), Darwin) ifeq ($(OSTYPE), Darwin)
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -arch i386 -arch x86_64 -Wall -pipe -g -fwrapv -arch i386 -arch x86_64
else else
CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -MMD -Wall -pipe -g -MMD -fwrapv
endif endif
# ---------- # ----------

View File

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

View File

@ -1620,7 +1620,10 @@ ClientThink(edict_t *ent, usercmd_t *ucmd)
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
pm.s.origin[i] = ent->s.origin[i] * 8; 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))) if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))