From 8934226bb2412a53b6560b4f5dc5ebac0dfdf35e Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 25 Oct 2014 03:36:34 +0000 Subject: [PATCH] Another 5000 lines of pain and tears. DONT_BUILD. git-svn-id: https://svn.eduke32.com/eduke32@4680 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 36 +- polymer/eduke32/build/include/compat.h | 19 +- polymer/eduke32/build/include/hightile.h | 4 +- polymer/eduke32/build/include/libdivide.h | 18 +- polymer/eduke32/build/src/a-c.c | 2 +- polymer/eduke32/build/src/cache1d.c | 2 +- polymer/eduke32/build/src/defs.c | 130 +++--- polymer/eduke32/build/src/engine.c | 78 +++- polymer/eduke32/build/src/hightile.c | 4 +- polymer/eduke32/build/src/kplib.c | 1 + polymer/eduke32/build/src/mdsprite.c | 12 +- polymer/eduke32/build/src/polymer.c | 16 +- polymer/eduke32/build/src/polymost.c | 60 +-- polymer/eduke32/source/actors.c | 93 ++-- polymer/eduke32/source/astub.c | 4 +- polymer/eduke32/source/duke3d.h | 9 - polymer/eduke32/source/game.c | 46 +- polymer/eduke32/source/gamedef.c | 515 +++++++++++----------- polymer/eduke32/source/gameexec.c | 356 +++++++-------- polymer/eduke32/source/gameexec.h | 13 +- polymer/eduke32/source/gamestructures.c | 57 +-- polymer/eduke32/source/gamevars.c | 282 ++++++------ polymer/eduke32/source/gamevars.h | 8 +- polymer/eduke32/source/menus.c | 8 +- polymer/eduke32/source/osdcmds.c | 3 +- polymer/eduke32/source/player.c | 40 +- polymer/eduke32/source/premap.c | 3 +- polymer/eduke32/source/sector.c | 4 +- 28 files changed, 943 insertions(+), 880 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index f53c6f765..d42a124cf 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -622,7 +622,7 @@ typedef struct { uint32_t mdanimtims; int16_t mdanimcur; int16_t angoff, pitch, roll; - int32_t xoff, yoff, zoff; + vec3_t offset; uint8_t flags; uint8_t xpanning, ypanning; uint8_t filler; @@ -705,36 +705,44 @@ static inline void yax_setnextwall(int16_t wal, int16_t cf, int16_t thenextwall) static inline void sector_tracker_hook(uintptr_t address) { - address -= (uintptr_t)(sector); - address /= sizeof(sectortype); + uintptr_t const usector = (uintptr_t) sector; - if (address > MAXSECTORS + M32_FIXME_SECTORS) return; + if (EDUKE32_PREDICT_FALSE((address - usector) >= (MAXSECTORS+M32_FIXME_SECTORS * sizeof(sectortype)))) + return; + + address = (address - usector); + address /= sizeof(sectortype); sectorchanged[address]++; } static inline void wall_tracker_hook(uintptr_t address) { - address -= (uintptr_t)(wall); - address /= sizeof(walltype); + uintptr_t const uwall = (uintptr_t) wall; - if (address > MAXWALLS + M32_FIXME_WALLS) return; + if (EDUKE32_PREDICT_FALSE((address - uwall) >= (MAXWALLS+M32_FIXME_WALLS * sizeof(walltype)))) + return; + + address = (address - uwall); + address /= sizeof(walltype); wallchanged[address]++; } static inline void sprite_tracker_hook(uintptr_t address) { - if (address >= (uintptr_t)(sprite) && - address < (uintptr_t)(sprite) + MAXSPRITES * sizeof(spritetype)) - { - address -= (uintptr_t)(sprite); - address /= sizeof(spritetype); + uintptr_t const usprite = (uintptr_t)sprite; - spritechanged[address]++; - } + if (EDUKE32_PREDICT_FALSE((address - usprite) >= (MAXSPRITES * sizeof(spritetype)))) + return; + + address = (address - usprite); + address /= sizeof(spritetype); + + spritechanged[address]++; } + EXTERN int16_t maskwall[MAXWALLSB], maskwallcnt; EXTERN int16_t thewall[MAXWALLSB]; EXTERN spritetype *tspriteptr[MAXSPRITESONSCREEN + 1]; diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 2db4843b0..189da6cc5 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -37,6 +37,20 @@ # define ATTRIBUTE_OPTIMIZE(str) #endif +#if defined __GNUC__ || defined __clang__ +#define EDUKE32_PREDICT_TRUE(x) __builtin_expect(!!(x),1) +#define EDUKE32_PREDICT_FALSE(x) __builtin_expect(!!(x),0) +#define EDUKE32_UNREACHABLE_SECTION(...) __builtin_unreachable() +#elif _MSC_VER +#define EDUKE32_PREDICT_TRUE(x) (x) +#define EDUKE32_PREDICT_FALSE(x) (x) +#define EDUKE32_UNREACHABLE_SECTION(...) __assume(0) +#else +#define EDUKE32_PREDICT_TRUE(x) (x) +#define EDUKE32_PREDICT_FALSE(x) (x) +#define EDUKE32_UNREACHABLE_SECTION(...) __VA_ARGS__ +#endif + #ifndef min #define min(x,y) ((x) < (y) ? (x) : (y)) #endif @@ -150,11 +164,6 @@ #endif -#include -static inline long lround(double num) -{ - return (long) (num > 0 ? num + 0.5 : ceil(num - 0.5)); -} #else # define longlong(x) x##ll #endif diff --git a/polymer/eduke32/build/include/hightile.h b/polymer/eduke32/build/include/hightile.h index e9db8fed2..a7b3c8956 100644 --- a/polymer/eduke32/build/include/hightile.h +++ b/polymer/eduke32/build/include/hightile.h @@ -9,9 +9,9 @@ typedef struct hicreplc_t { struct hicreplc_t *next; char *filename; struct hicskybox_t *skybox; + vec2f_t scale; + float alphacut, specpower, specfactor; char palnum, flags; - short filler; - float alphacut, xscale, yscale, specpower, specfactor; } hicreplctyp; extern palette_t hictinting[MAXPALOOKUPS]; diff --git a/polymer/eduke32/build/include/libdivide.h b/polymer/eduke32/build/include/libdivide.h index 10683aa39..429904ce9 100644 --- a/polymer/eduke32/build/include/libdivide.h +++ b/polymer/eduke32/build/include/libdivide.h @@ -463,14 +463,14 @@ static uint64_t libdivide_128_div_64_to_64(uint64_t u1, uint64_t u0, uint64_t v, rhat; // A remainder. int s; // Shift amount for norm. - if (u1 >= v) { // If overflow, set rem. + if (EDUKE32_PREDICT_FALSE(u1 >= v)) { // If overflow, set rem. if (r != NULL) // to an impossible value, *r = (uint64_t)(-1); // and return the largest return (uint64_t)(-1);} // possible quotient. /* count leading zeros */ s = libdivide__count_leading_zeros64(v); // 0 <= s <= 63. - if (s > 0) { + if (EDUKE32_PREDICT_TRUE(s > 0)) { v = v << s; // Normalize divisor. un64 = (u1 << s) | ((u0 >> (64 - s)) & (-s >> 31)); un10 = u0 << s; // Shift dividend left. @@ -520,7 +520,7 @@ again2: libdivide_u32_t libdivide_u32_gen(uint32_t d) { libdivide_u32_t result; - if ((d & (d - 1)) == 0) { + if (EDUKE32_PREDICT_FALSE((d & (d - 1)) == 0)) { result.magic = 0; result.more = libdivide__count_trailing_zeros32(d) | LIBDIVIDE_U32_SHIFT_PATH; } @@ -555,7 +555,7 @@ libdivide_u32_t libdivide_u32_gen(uint32_t d) { uint32_t libdivide_u32_do(uint32_t numer, const libdivide_u32_t *denom) { uint8_t more = denom->more; - if (more & LIBDIVIDE_U32_SHIFT_PATH) { + if (EDUKE32_PREDICT_FALSE(more & LIBDIVIDE_U32_SHIFT_PATH)) { return numer >> (more & LIBDIVIDE_32_SHIFT_MASK); } else { @@ -640,7 +640,7 @@ __m128i libdivide_u32_do_vector_alg2(__m128i numers, const libdivide_u32_t *deno libdivide_u64_t libdivide_u64_gen(uint64_t d) { libdivide_u64_t result; - if ((d & (d - 1)) == 0) { + if (EDUKE32_PREDICT_FALSE((d & (d - 1)) == 0)) { result.more = libdivide__count_trailing_zeros64(d) | LIBDIVIDE_U64_SHIFT_PATH; result.magic = 0; } @@ -674,7 +674,7 @@ libdivide_u64_t libdivide_u64_gen(uint64_t d) { uint64_t libdivide_u64_do(uint64_t numer, const libdivide_u64_t *denom) { uint8_t more = denom->more; - if (more & LIBDIVIDE_U64_SHIFT_PATH) { + if (EDUKE32_PREDICT_FALSE(more & LIBDIVIDE_U64_SHIFT_PATH)) { return numer >> (more & LIBDIVIDE_64_SHIFT_MASK); } else { @@ -692,7 +692,7 @@ uint64_t libdivide_u64_do(uint64_t numer, const libdivide_u64_t *denom) { int libdivide_u64_get_algorithm(const libdivide_u64_t *denom) { uint8_t more = denom->more; - if (more & LIBDIVIDE_U64_SHIFT_PATH) return 0; + if (EDUKE32_PREDICT_FALSE(more & LIBDIVIDE_U64_SHIFT_PATH)) return 0; else if (! (more & LIBDIVIDE_ADD_MARKER)) return 1; else return 2; } @@ -765,7 +765,7 @@ libdivide_s32_t libdivide_s32_gen(int32_t d) { /* If d is a power of 2, or negative a power of 2, we have to use a shift. This is especially important because the magic algorithm fails for -1. To check if d is a power of 2 or its inverse, it suffices to check whether its absolute value has exactly one bit set. This works even for INT_MIN, because abs(INT_MIN) == INT_MIN, and INT_MIN has one bit set and is a power of 2. */ uint32_t absD = (uint32_t)(d < 0 ? -d : d); //gcc optimizes this to the fast abs trick - if ((absD & (absD - 1)) == 0) { //check if exactly one bit is set, don't care if absD is 0 since that's divide by zero + if (EDUKE32_PREDICT_FALSE((absD & (absD - 1)) == 0)) { //check if exactly one bit is set, don't care if absD is 0 since that's divide by zero result.magic = 0; result.more = libdivide__count_trailing_zeros32(absD) | (d < 0 ? LIBDIVIDE_NEGATIVE_DIVISOR : 0) | LIBDIVIDE_S32_SHIFT_PATH; } @@ -932,7 +932,7 @@ libdivide_s64_t libdivide_s64_gen(int64_t d) { /* If d is a power of 2, or negative a power of 2, we have to use a shift. This is especially important because the magic algorithm fails for -1. To check if d is a power of 2 or its inverse, it suffices to check whether its absolute value has exactly one bit set. This works even for INT_MIN, because abs(INT_MIN) == INT_MIN, and INT_MIN has one bit set and is a power of 2. */ const uint64_t absD = (uint64_t)(d < 0 ? -d : d); //gcc optimizes this to the fast abs trick - if ((absD & (absD - 1)) == 0) { //check if exactly one bit is set, don't care if absD is 0 since that's divide by zero + if (EDUKE32_PREDICT_FALSE((absD & (absD - 1)) == 0)) { //check if exactly one bit is set, don't care if absD is 0 since that's divide by zero result.more = libdivide__count_trailing_zeros64(absD) | (d < 0 ? LIBDIVIDE_NEGATIVE_DIVISOR : 0); result.magic = 0; } diff --git a/polymer/eduke32/build/src/a-c.c b/polymer/eduke32/build/src/a-c.c index 7a8ed3f8a..eceb6b120 100644 --- a/polymer/eduke32/build/src/a-c.c +++ b/polymer/eduke32/build/src/a-c.c @@ -265,7 +265,7 @@ void vlineasm4(int32_t cnt, char *p) #endif const int32_t logy = glogy, ourbpl = bpl; - if (!logy) // I had an assert on logy for quite a while that NEVER triggered... + if (EDUKE32_PREDICT_FALSE(!logy)) // I had an assert on logy for quite a while that NEVER triggered... { vlineasm4nlogy(cnt, p, pal, buf, vplc, vinc); return; diff --git a/polymer/eduke32/build/src/cache1d.c b/polymer/eduke32/build/src/cache1d.c index 364c4730d..89190c409 100644 --- a/polymer/eduke32/build/src/cache1d.c +++ b/polymer/eduke32/build/src/cache1d.c @@ -558,7 +558,7 @@ int32_t findfrompath(const char *fn, char **where) return -1; } -#ifdef _WIN32 +#if defined(_WIN32) && defined(DEBUGGINGAIDS) # define FILENAME_CASE_CHECK #endif diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index 2be14bb68..f5b8f38d0 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -115,7 +115,7 @@ static void defsparser_include(const char *fn, const scriptfile *script, const c scriptfile *included; included = scriptfile_fromfile(fn); - if (!included) + if (EDUKE32_PREDICT_FALSE(!included)) { if (!cmdtokptr) initprintf("Warning: Failed including %s as module\n", fn); @@ -141,14 +141,14 @@ static void defsparser_include(const char *fn, const scriptfile *script, const c static int32_t check_tile_range(const char *defcmd, int32_t *tilebeg, int32_t *tileend, const scriptfile *script, const char *cmdtokptr) { - if (*tileend < *tilebeg) + if (EDUKE32_PREDICT_FALSE(*tileend < *tilebeg)) { initprintf("Warning: %s: backwards tile range on line %s:%d\n", defcmd, script->filename, scriptfile_getlinum(script,cmdtokptr)); swaplong(tilebeg, tileend); } - if ((unsigned)*tilebeg >= MAXUSERTILES || (unsigned)*tileend >= MAXUSERTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)*tilebeg >= MAXUSERTILES || (unsigned)*tileend >= MAXUSERTILES)) { initprintf("Error: %s: Invalid tile range on line %s:%d\n", defcmd, script->filename, scriptfile_getlinum(script,cmdtokptr)); @@ -161,7 +161,7 @@ static int32_t check_tile_range(const char *defcmd, int32_t *tilebeg, int32_t *t static int32_t check_tile(const char *defcmd, int32_t tile, const scriptfile *script, const char *cmdtokptr) { - if ((unsigned)tile >= MAXUSERTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES)) { initprintf("Error: %s: Invalid tile number on line %s:%d\n", defcmd, script->filename, scriptfile_getlinum(script,cmdtokptr)); @@ -171,6 +171,8 @@ static int32_t check_tile(const char *defcmd, int32_t tile, const scriptfile *sc return 0; } +extern void getclosestcol_flush(void); + static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t alphacut) { const vec2_t siz = tilesiz[tile]; @@ -182,6 +184,8 @@ static void tile_from_truecolpic(int32_t tile, const palette_t *picptr, int32_t faketilebuffersiz = tsiz; } + getclosestcol_flush(); + faketiledata[tile] = (char *)Xmalloc(tsiz + 32); for (i=siz.x-1; i>=0; i--) @@ -315,7 +319,7 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getstring(script,&name)) break; if (scriptfile_getsymbol(script,&number)) break; - if (scriptfile_addsymbolvalue(name,number) < 0) + if (EDUKE32_PREDICT_FALSE(scriptfile_addsymbolvalue(name,number) < 0)) initprintf("Warning: Symbol %s was NOT redefined to %d on line %s:%d\n", name,number,script->filename,scriptfile_getlinum(script,cmdtokptr)); break; @@ -526,7 +530,7 @@ static int32_t defsparser(scriptfile *script) if (check_tile_range("animtilerange", &tile1, &tile2, script, cmdtokptr)) break; - if (tile2-tile1 > 255) + if (EDUKE32_PREDICT_FALSE(tile2-tile1 > 255)) { initprintf("Error: animtilerange: tile difference can be at most 255 on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); @@ -534,7 +538,7 @@ static int32_t defsparser(scriptfile *script) } spd = clamp(spd, 0, 15); - if (type&~3) + if (EDUKE32_PREDICT_FALSE(type&~3)) { initprintf("Error: animtilerange: animation type must be 0, 1, 2 or 3 on line %s:%d\n", script->filename, scriptfile_getlinum(script,cmdtokptr)); @@ -600,7 +604,7 @@ static int32_t defsparser(scriptfile *script) } } - if ((unsigned)tile >= MAXUSERTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES)) { initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,texturetokptr)); @@ -616,7 +620,7 @@ static int32_t defsparser(scriptfile *script) if (haveyoffset) picanm[tile].yofs = clamp(yoffset, -128, 127); - if (flags == 0 && !havexoffset && !haveyoffset) + if (EDUKE32_PREDICT_FALSE(flags == 0 && !havexoffset && !haveyoffset)) initprintf("\nError: missing 'file name' for tilefromtexture definition near line %s:%d", script->filename, scriptfile_getlinum(script,texturetokptr)); break; @@ -735,7 +739,7 @@ static int32_t defsparser(scriptfile *script) #ifdef USE_OPENGL lastmodelid = md_loadmodel(modelfn); - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { initprintf("Warning: Failed loading MD2/MD3 model \"%s\"\n", modelfn); break; @@ -766,7 +770,7 @@ static int32_t defsparser(scriptfile *script) if (check_tile_range("definemodelframe", &ftilenume, <ilenume, script, cmdtokptr)) break; - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { #ifdef USE_OPENGL initprintf("Warning: Ignoring frame definition.\n"); @@ -809,7 +813,7 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getdouble(script,&dfps)) break; //animation frame rate if (scriptfile_getnumber(script,&flags)) break; - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { #ifdef USE_OPENGL initprintf("Warning: Ignoring animation definition.\n"); @@ -899,13 +903,13 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getstring(script,&fn)) break; //voxel filename - if (nextvoxid == MAXVOXELS) + if (EDUKE32_PREDICT_FALSE(nextvoxid == MAXVOXELS)) { initprintf("Maximum number of voxels already defined.\n"); break; } - if (qloadkvx(nextvoxid, fn)) + if (EDUKE32_PREDICT_FALSE(qloadkvx(nextvoxid, fn))) { initprintf("Failure loading voxel file \"%s\"\n",fn); break; @@ -924,7 +928,7 @@ static int32_t defsparser(scriptfile *script) if (check_tile_range("definevoxeltiles", &ftilenume, <ilenume, script, cmdtokptr)) break; - if (lastvoxid < 0) + if (EDUKE32_PREDICT_FALSE(lastvoxid < 0)) { initprintf("Warning: Ignoring voxel tiles definition.\n"); break; @@ -971,7 +975,7 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getbraces(script,&modelend)) break; #ifdef USE_OPENGL lastmodelid = md_loadmodel(modelfn); - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { initprintf("Warning: Failed loading MD2/MD3 model \"%s\"\n", modelfn); script->textptr = modelend+1; @@ -1042,7 +1046,7 @@ static int32_t defsparser(scriptfile *script) break; } - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { #ifdef USE_OPENGL initprintf("Warning: Ignoring frame definition.\n"); @@ -1109,12 +1113,12 @@ static int32_t defsparser(scriptfile *script) } } - if (!startframe) initprintf("Error: missing 'start frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; - if (!endframe) initprintf("Error: missing 'end frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; + if (EDUKE32_PREDICT_FALSE(!startframe)) initprintf("Error: missing 'start frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; + if (EDUKE32_PREDICT_FALSE(!endframe)) initprintf("Error: missing 'end frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; model_ok &= happy; - if (!happy) break; + if (EDUKE32_PREDICT_FALSE(!happy)) break; - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { #ifdef USE_OPENGL initprintf("Warning: Ignoring animation definition.\n"); @@ -1187,7 +1191,7 @@ static int32_t defsparser(scriptfile *script) } } - if (!skinfn) + if (EDUKE32_PREDICT_FALSE(!skinfn)) { initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); model_ok = 0; @@ -1302,13 +1306,13 @@ static int32_t defsparser(scriptfile *script) } } - if (check_tile_range("hud", &ftilenume, <ilenume, script, hudtokptr)) + if (EDUKE32_PREDICT_FALSE(check_tile_range("hud", &ftilenume, <ilenume, script, hudtokptr))) { model_ok = 0; break; } - if (lastmodelid < 0) + if (EDUKE32_PREDICT_FALSE(lastmodelid < 0)) { #ifdef USE_OPENGL initprintf("Warning: Ignoring frame definition.\n"); @@ -1345,7 +1349,7 @@ static int32_t defsparser(scriptfile *script) } #ifdef USE_OPENGL - if (!model_ok) + if (EDUKE32_PREDICT_FALSE(!model_ok)) { if (lastmodelid >= 0) { @@ -1402,9 +1406,9 @@ static int32_t defsparser(scriptfile *script) { "scale", T_SCALE }, }; - if (scriptfile_getstring(script,&fn)) break; //voxel filename - if (nextvoxid == MAXVOXELS) { initprintf("Maximum number of voxels already defined.\n"); break; } - if (qloadkvx(nextvoxid, fn)) { initprintf("Failure loading voxel file \"%s\"\n",fn); break; } + if (EDUKE32_PREDICT_FALSE(scriptfile_getstring(script,&fn))) break; //voxel filename + if (EDUKE32_PREDICT_FALSE(nextvoxid == MAXVOXELS)) { initprintf("Maximum number of voxels already defined.\n"); break; } + if (EDUKE32_PREDICT_FALSE(qloadkvx(nextvoxid, fn))) { initprintf("Failure loading voxel file \"%s\"\n",fn); break; } lastvoxid = nextvoxid++; if (scriptfile_getbraces(script,&modelend)) break; @@ -1496,10 +1500,10 @@ static int32_t defsparser(scriptfile *script) } } - if (tile < 0) initprintf("Error: skybox: missing 'tile number' near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0; + if (EDUKE32_PREDICT_FALSE(tile < 0)) initprintf("Error: skybox: missing 'tile number' near line %s:%d\n", script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy=0; for (i=0; i<6; i++) { - if (!fn[i]) initprintf("Error: skybox: missing '%s filename' near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0; + if (EDUKE32_PREDICT_FALSE(!fn[i])) initprintf("Error: skybox: missing '%s filename' near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0; // FIXME? if (check_file_exist(fn[i])) happy = 0; @@ -1541,21 +1545,21 @@ static int32_t defsparser(scriptfile *script) scriptfile_getstring(script,&fn); break; } } - if ((unsigned)basepal >= ((unsigned)basepalcount)) + if (EDUKE32_PREDICT_FALSE((unsigned)basepal >= ((unsigned)basepalcount))) { initprintf("Error: missing or invalid 'base palette number' for highpalookup definition " "near line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr)); break; } - if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS) + if (EDUKE32_PREDICT_FALSE((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS)) { initprintf("Error: missing or invalid 'palette number' for highpalookup definition near " "line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr)); break; } - if (!fn) + if (EDUKE32_PREDICT_FALSE(!fn)) { initprintf("Error: missing 'file name' for highpalookup definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,highpaltokptr)); @@ -1586,7 +1590,7 @@ static int32_t defsparser(scriptfile *script) kclose(fd); kpgetdim(filebuf, filesize, &xsiz, &ysiz); - if (xsiz != PR_HIGHPALOOKUP_DIM*PR_HIGHPALOOKUP_DIM || ysiz != PR_HIGHPALOOKUP_DIM) + if (EDUKE32_PREDICT_FALSE(xsiz != PR_HIGHPALOOKUP_DIM*PR_HIGHPALOOKUP_DIM || ysiz != PR_HIGHPALOOKUP_DIM)) { initprintf("Error: image dimensions of \"%s\" must be %dx%d.\n", fn, PR_HIGHPALOOKUP_DIM*PR_HIGHPALOOKUP_DIM, PR_HIGHPALOOKUP_DIM); @@ -1596,7 +1600,7 @@ static int32_t defsparser(scriptfile *script) i = kprender(filebuf, filesize, (intptr_t)highpaldata, xsiz*sizeof(coltype), xsiz, ysiz); Bfree(filebuf); - if (i) + if (EDUKE32_PREDICT_FALSE(i)) { Bfree(highpaldata); initprintf("Error: failed rendering \"%s\".\n", fn); break; } } @@ -1639,7 +1643,7 @@ static int32_t defsparser(scriptfile *script) } } - if (pal < 0) + if (EDUKE32_PREDICT_FALSE(pal < 0)) { initprintf("Error: tint: missing 'palette number' near line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); @@ -1709,24 +1713,24 @@ static int32_t defsparser(scriptfile *script) Bsprintf(msgend, "for palookup definition near line %s:%d", script->filename, scriptfile_getlinum(script,starttokptr)); - if ((havepal&1)==0) + if (EDUKE32_PREDICT_FALSE((havepal&1)==0)) { initprintf("Error: missing 'palette number' %s\n", msgend); break; } - else if (pal==0 || (unsigned)pal >= MAXPALOOKUPS-RESERVEDPALS) + else if (EDUKE32_PREDICT_FALSE(pal==0 || (unsigned)pal >= MAXPALOOKUPS-RESERVEDPALS)) { initprintf("Error: 'palette number' out of range (1 .. %d) %s\n", MAXPALOOKUPS-RESERVEDPALS-1, msgend); break; } - else if (havepal&8) + else if (EDUKE32_PREDICT_FALSE(havepal&8)) { // will also disallow multiple remappals or remapselfs initprintf("Error: must have exactly one of either 'remappal' or 'remapself' %s\n", msgend); break; } - else if ((havepal&4) && (unsigned)remappal >= MAXPALOOKUPS-RESERVEDPALS) + else if (EDUKE32_PREDICT_FALSE((havepal&4) && (unsigned)remappal >= MAXPALOOKUPS-RESERVEDPALS)) { initprintf("Error: 'remap palette number' out of range (max=%d) %s\n", MAXPALOOKUPS-RESERVEDPALS-1, msgend); @@ -1821,21 +1825,21 @@ static int32_t defsparser(scriptfile *script) } } - if ((unsigned)tile >= MAXUSERTILES) break; // message is printed later - if ((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS) + if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES)) break; // message is printed later + if (EDUKE32_PREDICT_FALSE((unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS)) { initprintf("Error: missing or invalid 'palette number' for texture definition near " "line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr)); break; } - if (!fn) + if (EDUKE32_PREDICT_FALSE(!fn)) { initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr)); break; } - if (check_file_exist(fn)) + if (EDUKE32_PREDICT_FALSE(check_file_exist(fn))) break; if (xsiz > 0 && ysiz > 0) @@ -1874,7 +1878,7 @@ static int32_t defsparser(scriptfile *script) { "nodownsize", T_NODOWNSIZE }, }; - if (scriptfile_getbraces(script,&detailend)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&detailend))) break; while (script->textptr < detailend) { switch (getatoken(script,texturetokens_pal,ARRAY_SIZE(texturetokens_pal))) @@ -1900,15 +1904,15 @@ static int32_t defsparser(scriptfile *script) } } - if ((unsigned)tile >= MAXUSERTILES) break; // message is printed later - if (!fn) + if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES)) break; // message is printed later + if (EDUKE32_PREDICT_FALSE(!fn)) { initprintf("Error: missing 'file name' for texture definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,detailtokptr)); break; } - if (check_file_exist(fn)) + if (EDUKE32_PREDICT_FALSE(check_file_exist(fn))) break; #ifdef USE_OPENGL @@ -1937,7 +1941,7 @@ static int32_t defsparser(scriptfile *script) break; } } - if ((unsigned)tile >= MAXUSERTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)tile >= MAXUSERTILES)) { initprintf("Error: missing or invalid 'tile number' for texture definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,texturetokptr)); @@ -1951,7 +1955,7 @@ static int32_t defsparser(scriptfile *script) { int32_t r0,r1; - if (scriptfile_getsymbol(script,&r0)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getsymbol(script,&r0))) break; if (tokn == T_UNDEFMODELRANGE) { if (scriptfile_getsymbol(script,&r1)) break; @@ -1980,7 +1984,7 @@ static int32_t defsparser(scriptfile *script) int32_t mid; #endif - if (scriptfile_getsymbol(script,&r0)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getsymbol(script,&r0))) break; if (check_tile("undefmodelof", r0, script, cmdtokptr)) break; @@ -2006,19 +2010,19 @@ static int32_t defsparser(scriptfile *script) int32_t i; #endif - if (scriptfile_getsymbol(script,&r0)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getsymbol(script,&r0))) break; if (tokn == T_UNDEFTEXTURERANGE) { - if (scriptfile_getsymbol(script,&r1)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getsymbol(script,&r1))) break; - if (check_tile_range("undeftexturerange", &r0, &r1, script, cmdtokptr)) + if (EDUKE32_PREDICT_FALSE(check_tile_range("undeftexturerange", &r0, &r1, script, cmdtokptr))) break; } else { r1 = r0; - if (check_tile("undeftexture", r0, script, cmdtokptr)) + if (EDUKE32_PREDICT_FALSE(check_tile("undeftexture", r0, script, cmdtokptr))) break; } @@ -2036,8 +2040,8 @@ static int32_t defsparser(scriptfile *script) static const tokenlist dummytokens[] = { { "id", T_ID }, }; - if (scriptfile_getstring(script, &dummy)) break; - if (scriptfile_getbraces(script,&dummy)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getstring(script, &dummy))) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&dummy))) break; while (script->textptr < dummy) { // XXX? @@ -2050,8 +2054,8 @@ static int32_t defsparser(scriptfile *script) { int32_t b,e; - if (scriptfile_getnumber(script,&b)) break; - if (scriptfile_getnumber(script,&e)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getnumber(script,&b))) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getnumber(script,&e))) break; } break; @@ -2060,8 +2064,8 @@ static int32_t defsparser(scriptfile *script) { int32_t b,e, i; - if (scriptfile_getnumber(script,&b)) break; - if (scriptfile_getnumber(script,&e)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getnumber(script,&b))) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getnumber(script,&e))) break; b = max(b, 0); e = min(e, MAXUSERTILES-1); @@ -2082,7 +2086,7 @@ static int32_t defsparser(scriptfile *script) { "file", T_FILE }, }; - if (scriptfile_getbraces(script,&dummy)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&dummy))) break; while (script->textptr < dummy) { switch (getatoken(script,sound_musictokens,ARRAY_SIZE(sound_musictokens))) @@ -2109,7 +2113,7 @@ static int32_t defsparser(scriptfile *script) { "mhkfile", T_MHKFILE }, }; - if (scriptfile_getbraces(script,&dummy)) break; + if (EDUKE32_PREDICT_FALSE(scriptfile_getbraces(script,&dummy))) break; while (script->textptr < dummy) { switch (getatoken(script,mapinfotokens,ARRAY_SIZE(mapinfotokens))) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index d8351290d..bfd548a8c 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -2789,7 +2789,7 @@ static void maskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc) tweak_tsizes(&tsiz); - if (palookup[globalpal] == NULL) + if (EDUKE32_PREDICT_FALSE(palookup[globalpal] == NULL)) globalpal = 0; fpalookup = FP_OFF(palookup[globalpal]); @@ -5684,7 +5684,7 @@ draw_as_face_sprite: xsiz = mulscale30(siz,xv*xspan); ysiz = mulscale14(siz,tspr->yrepeat*yspan); - if ((tilesiz[tilenum].x>>11) >= xsiz || yspan >= (ysiz>>1)) + if (EDUKE32_PREDICT_FALSE((tilesiz[tilenum].x>>11) >= xsiz || yspan >= (ysiz>>1))) return; //Watch out for divscale overflow x1 = xb-(xsiz>>1); @@ -6966,11 +6966,11 @@ static inline int32_t addscaleclamp(int32_t a, int32_t b, int32_t s1, int32_t s2 // a + scale(b, s1, s1-s2), but without arithmetic exception when the // scale() expression overflows - int64_t tmp = (int64_t)a + ((int64_t)b*s1)/(s1-s2); + int64_t tmp = (int64_t)a + tabledivide64((int64_t)b*s1, s1-s2); - if (tmp <= INT32_MIN+1) + if (EDUKE32_PREDICT_FALSE(tmp <= INT32_MIN+1)) return INT32_MIN+1; - if (tmp >= INT32_MAX) + if (EDUKE32_PREDICT_FALSE(tmp >= INT32_MAX)) return INT32_MAX; return tmp; } @@ -8353,24 +8353,67 @@ void fillemptylookups(void) makepalookup(j, NULL, 0,0,0, 1); } +#define COLRESULTSIZ 4096 + +#define COLRESULT(x) do { } while (0) + +static uint32_t getclosestcol_results[COLRESULTSIZ]; +static int32_t numclosestcolresults; + +void getclosestcol_flush(void) +{ + Bmemset(getclosestcol_results, 0, COLRESULTSIZ * sizeof(uint32_t)); + numclosestcolresults = 0; +} + // Finds a color index in [0 .. lastokcol] closest to (r, g, b). // must be in [0 .. 255]. int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol) { int32_t i, k, retcol = -1; + int32_t mindist = -1; const int32_t j = (r>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ + (g>>3)*FASTPALGRIDSIZ + (b>>3) + FASTPALGRIDSIZ*FASTPALGRIDSIZ + FASTPALGRIDSIZ+1; - int32_t mindist = min(rdist[coldist[r&7]+64+8],gdist[coldist[g&7]+64+8]); - mindist = min(mindist,bdist[coldist[b&7]+64+8]); - mindist++; - + uint32_t col; + Bassert(lastokcol >= 0 && lastokcol <= 255); - r = 64-r; g = 64-g; b = 64-b; + r = 64-r, g = 64-g, b = 64-b; + + col = (r + (g<<8) + (b<<16)); + + if (!numclosestcolresults) goto skip; + + if (col == (getclosestcol_results[(numclosestcolresults-1) & (COLRESULTSIZ-1)] & 0x00ffffff)) + return getclosestcol_results[(numclosestcolresults-1) & (COLRESULTSIZ-1)]>>24; + + k = (numclosestcolresults > COLRESULTSIZ) ? (COLRESULTSIZ-4) : (numclosestcolresults-4); + + for (i = 0; i < k; i+=4) + { + if (col == (getclosestcol_results[i] & 0x00ffffff)) { mindist = i; break; } + if (col == (getclosestcol_results[i+1] & 0x00ffffff)) { mindist = i+1; break; } + if (col == (getclosestcol_results[i+2] & 0x00ffffff)) { mindist = i+2; break; } + if (col == (getclosestcol_results[i+3] & 0x00ffffff)) { mindist = i+3; break; } + } + + if (mindist == -1) + for (; i < k+4; i++) + if (col == (getclosestcol_results[i] & 0x00ffffff)) { mindist = i; break; } + + if (mindist != -1 && getclosestcol_results[mindist]>>24 < (unsigned)lastokcol) + return getclosestcol_results[mindist]>>24; + +skip: + getclosestcol_results[numclosestcolresults & (COLRESULTSIZ-1)] = col; + + mindist = min(rdist[coldist[r&7]+64+8], gdist[coldist[g&7]+64+8]); + mindist = min(mindist, bdist[coldist[b&7]+64+8]); + mindist++; for (k=26; k>=0; k--) { @@ -8401,7 +8444,11 @@ int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol) } if (retcol >= 0) + { + getclosestcol_results[numclosestcolresults & (COLRESULTSIZ-1)] |= retcol<<24; + numclosestcolresults++; return retcol; + } mindist = INT32_MAX; @@ -8416,6 +8463,8 @@ int32_t getclosestcol_lim(int32_t r, int32_t g, int32_t b, int32_t lastokcol) mindist = dist; retcol = i; } + getclosestcol_results[numclosestcolresults & (COLRESULTSIZ-1)] |= retcol<<24; + numclosestcolresults++; return retcol; } @@ -9591,6 +9640,8 @@ killsprite: swaplong(&spritesy[k],&spritesy[l]); swaplong(&spritesz[k],&spritesz[l]); } + + for (k=i+1; kstatnum < tspriteptr[l]->statnum) @@ -9599,6 +9650,7 @@ killsprite: swaplong(&spritesx[k],&spritesx[l]); swaplong(&spritesy[k],&spritesy[l]); } + } i = j; } @@ -10968,7 +11020,7 @@ int32_t loadmaphack(const char *filename) script->filename, scriptfile_getlinum(script,cmdtokptr)); break; } - spriteext[whichsprite].xoff = i; + spriteext[whichsprite].offset.x = i; } break; case T_MDYOFF: // mdyoff @@ -10983,7 +11035,7 @@ int32_t loadmaphack(const char *filename) script->filename, scriptfile_getlinum(script,cmdtokptr)); break; } - spriteext[whichsprite].yoff = i; + spriteext[whichsprite].offset.y = i; } break; case T_MDZOFF: // mdzoff @@ -10998,7 +11050,7 @@ int32_t loadmaphack(const char *filename) script->filename, scriptfile_getlinum(script,cmdtokptr)); break; } - spriteext[whichsprite].zoff = i; + spriteext[whichsprite].offset.z = i; } break; case T_AWAY1: // away1 diff --git a/polymer/eduke32/build/src/hightile.c b/polymer/eduke32/build/src/hightile.c index d1562da06..209d8e76d 100644 --- a/polymer/eduke32/build/src/hightile.c +++ b/polymer/eduke32/build/src/hightile.c @@ -164,8 +164,8 @@ int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float hrn->filename = Xstrdup(filen); hrn->alphacut = min(alphacut,1.0); - hrn->xscale = xscale; - hrn->yscale = yscale; + hrn->scale.x = xscale; + hrn->scale.y = yscale; hrn->specpower = specpower; hrn->specfactor = specfactor; hrn->flags = flags; diff --git a/polymer/eduke32/build/src/kplib.c b/polymer/eduke32/build/src/kplib.c index fce32ef6e..073a565a6 100644 --- a/polymer/eduke32/build/src/kplib.c +++ b/polymer/eduke32/build/src/kplib.c @@ -874,6 +874,7 @@ static int32_t kpngrend(const char *kfilebuf, int32_t kfilength, palcol[i] &= LSWAPIB((((int32_t)filptr[i])<<24)|0xffffff); break; default:; + EDUKE32_UNREACHABLE_SECTION(); } } else if (i == (int32_t)LSWAPIB(0x54414449)) { break; } //IDAT diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 94c7f2e97..05fadccf6 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -2114,14 +2114,14 @@ static int32_t polymost_md3draw(md3model_t *m, const spritetype *tspr) float f = 1.f/(fxdimen * fviewingrange) * (m0.x+m1.x) * (2560.f * (1.f/(65536.f*1280.f))); Bmemset(&a0, 0, sizeof(a0)); - if (sext->xoff) - a0.x = (float) sext->xoff * f; + if (sext->offset.x) + a0.x = (float) sext->offset.x * f; - if (sext->yoff) // Compare with SCREEN_FACTORS above - a0.y = (float) sext->yoff * f; + if (sext->offset.y) // Compare with SCREEN_FACTORS above + a0.y = (float) sext->offset.y * f; - if ((sext->zoff) && !(tspr->cstat&CSTAT_SPRITE_MDHACK)) // Compare with SCREEN_FACTORS above - a0.z = (float)sext->zoff / (655360.f * (m0.z+m1.z) * (gxyaspect*fxdimen*(1.f/1280.f))); + if ((sext->offset.z) && !(tspr->cstat&CSTAT_SPRITE_MDHACK)) // Compare with SCREEN_FACTORS above + a0.z = (float)sext->offset.z / (655360.f * (m0.z+m1.z) * (gxyaspect*fxdimen*(1.f/1280.f))); k0 = (float)sintable[(sext->pitch+512)&2047] * (1.f/16384.f); k1 = (float)sintable[sext->pitch&2047] * (1.f/16384.f); diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 9df3d43da..139e0a52a 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -4059,7 +4059,7 @@ static void polymer_drawmdsprite(spritetype *tspr) radplayerang = (globalang & 2047) * 2.0f * PI / 2048.0f; cosminusradplayerang = cos(-radplayerang); sinminusradplayerang = sin(-radplayerang); - hudzoom = 65536.0 / spriteext[tspr->owner].zoff; + hudzoom = 65536.0 / spriteext[tspr->owner].offset.z; bglTranslatef(spos[0], spos[1], spos[2]); bglRotatef(horizang, -cosminusradplayerang, 0.0f, sinminusradplayerang); @@ -4114,9 +4114,9 @@ static void polymer_drawmdsprite(spritetype *tspr) pitchang = (float)(spriteext[tspr->owner].pitch) / (2048.0f / 360.0f); rollang = (float)(spriteext[tspr->owner].roll) / (2048.0f / 360.0f); - offsets[0] = -spriteext[tspr->owner].xoff / (scale * tspr->xrepeat); - offsets[1] = -spriteext[tspr->owner].yoff / (scale * tspr->xrepeat); - offsets[2] = (float)(spriteext[tspr->owner].zoff) / 16.0f / (scale * tspr->yrepeat); + offsets[0] = -spriteext[tspr->owner].offset.x / (scale * tspr->xrepeat); + offsets[1] = -spriteext[tspr->owner].offset.y / (scale * tspr->xrepeat); + offsets[2] = (float)(spriteext[tspr->owner].offset.z) / 16.0f / (scale * tspr->yrepeat); bglTranslatef(-offsets[0], -offsets[1], -offsets[2]); @@ -4526,8 +4526,8 @@ static void polymer_getbuildmaterial(_prmaterial* material, int16_t tile if (pth->hicr) { - material->diffusescale[0] = pth->hicr->xscale; - material->diffusescale[1] = pth->hicr->yscale; + material->diffusescale[0] = pth->hicr->scale.x; + material->diffusescale[1] = pth->hicr->scale.y; } } @@ -4666,8 +4666,8 @@ static void polymer_getbuildmaterial(_prmaterial* material, int16_t tile pth->hicr && (pth->hicr->palnum == DETAILPAL)) { material->detailmap = pth->glpic; - material->detailscale[0] = pth->hicr->xscale; - material->detailscale[1] = pth->hicr->yscale; + material->detailscale[0] = pth->hicr->scale.x; + material->detailscale[1] = pth->hicr->scale.y; } // PR_BIT_GLOW_MAP diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 943821200..d28d33239 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -743,7 +743,7 @@ static void fixtransparency(coltype *dapic, vec2_t dasiz, vec2_t dasiz2, int32_t case 4: wpptr->r = ((r + 2)>>2); wpptr->g = ((g + 2)>>2); wpptr->b = ((b + 2)>>2); break; default: - break; + EDUKE32_UNREACHABLE_SECTION(break); } } } @@ -834,7 +834,7 @@ void uploadtexture(int32_t doalloc, int32_t xsiz, int32_t ysiz, int32_t intexfmt case 4: wpptr->r = ((r+2)>>2); wpptr->g = ((g+2)>>2); wpptr->b = ((b+2)>>2); wpptr->a = ((a+2)>>2); break; default: - break; + EDUKE32_UNREACHABLE_SECTION(break); } //if (wpptr->a) wpptr->a = 255; } @@ -1088,10 +1088,9 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp fn = hicr->filename; } - if ((filh = kopen4load(fn, 0)) < 0) + if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) < 0)) { OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic); - return -2; } @@ -1117,7 +1116,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp if ((filh = kopen4load(fn, 0)) < 0) return -1; picfil = (char *)Xmalloc(picfillen+1); - if (kread(filh, picfil, picfillen) != picfillen) + if (EDUKE32_PREDICT_FALSE(kread(filh, picfil, picfillen) != picfillen)) initprintf("warning: didn't fully read %s\n", fn); // prevent // Conditional jump or move depends on uninitialised value(s) @@ -1522,11 +1521,11 @@ static void drawpoly(vec2f_t *dpxy, int32_t n, int32_t method) } // texture scale by parkar request - if (pth && pth->hicr && !drawingskybox && ((pth->hicr->xscale != 1.0f) || (pth->hicr->yscale != 1.0f))) + if (pth && pth->hicr && !drawingskybox && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) { bglMatrixMode(GL_TEXTURE); bglLoadIdentity(); - bglScalef(pth->hicr->xscale, pth->hicr->yscale, 1.0f); + bglScalef(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); bglMatrixMode(GL_MODELVIEW); } @@ -1539,16 +1538,16 @@ static void drawpoly(vec2f_t *dpxy, int32_t n, int32_t method) { polymost_setupdetailtexture(++texunits, detailpth ? detailpth->glpic : 0); - f = detailpth ? detailpth->hicr->xscale : 1.f; + f = detailpth ? detailpth->hicr->scale.x : 1.f; bglMatrixMode(GL_TEXTURE); bglLoadIdentity(); - if (pth && pth->hicr && ((pth->hicr->xscale != 1.0f) || (pth->hicr->yscale != 1.0f))) - bglScalef(pth->hicr->xscale, pth->hicr->yscale, 1.0f); + if (pth && pth->hicr && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) + bglScalef(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); - if (detailpth && detailpth->hicr && ((detailpth->hicr->xscale != 1.0f) || (detailpth->hicr->yscale != 1.0f))) - bglScalef(detailpth->hicr->xscale, detailpth->hicr->yscale, 1.0f); + if (detailpth && detailpth->hicr && ((detailpth->hicr->scale.x != 1.0f) || (detailpth->hicr->scale.y != 1.0f))) + bglScalef(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); bglMatrixMode(GL_MODELVIEW); } @@ -3810,7 +3809,7 @@ void polymost_drawsprite(int32_t snum) spritetype *const tspr = tspriteptr[snum]; const sectortype *sec; - if (bad_tspr(tspr)) + if (EDUKE32_PREDICT_FALSE(bad_tspr(tspr))) return; spritenum = tspr->owner; @@ -3868,19 +3867,31 @@ void polymost_drawsprite(int32_t snum) break; } - if (tspr->cstat & (2|16) || gltexmayhavealpha(tspr->picnum,tspr->pal)) +// if (tspr->cstat & (2|16|32) || gltexmayhavealpha(tspr->picnum,tspr->pal)) { -#ifdef __arm__ // GL ES has a glDepthRangef and the loss of precision is OK there - float f = (tspr->cstat & (2|16)) ? (float)(spritenum + 1) * (FLT_EPSILON * 8.0) : 0.0; - if (f != 0.0) f *= 1.f/(float)(sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5); - bglDepthFunc(GL_LESS); + float f; + + if (tspr->cstat & 16) // push wall sprites away from wall + { + tspr->x += (sintable[(tspr->ang+512)&2047]>>13); + tspr->y += (sintable[tspr->ang&2047]>>13); + updatesector(tspr->x, tspr->y, &tspr->sectnum); + } + else if (tspr->cstat & 32) + { + if ((tspr->z - sec->ceilingz) < (sec->floorz - tspr->z)) + tspr->z += snum; + else tspr->z -= snum; + } + + f = (spritenum * (FLT_EPSILON * 1024.f))/(float)(sepldist(globalposx - tspr->x, globalposy - tspr->y)); + +#ifdef __arm__ glDepthRangef(0.f - f, 1.f - f); #else - double f = (tspr->cstat & (2|16)) ? (double)(spritenum + 1) * (FLT_EPSILON * 8.0) : 0.0; - if (f != 0.0) f *= 1.0/(double)(sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5); - bglDepthFunc(GL_LESS); bglDepthRange(0.0 - f, 1.0 - f); #endif + bglDepthFunc(GL_LESS); } #endif @@ -4160,9 +4171,6 @@ void polymost_drawsprite(int32_t snum) pxy[j].y = sx0*gcosang2 + sy0*gsinang2; } - if (tspr->z == sec->ceilingz) tspr->z++; - if (tspr->z == sec->floorz) tspr->z--; - if (tspr->z < globalposz) //if floor sprite is above you, reverse order of points { swapfloat(&pxy[0].x, &pxy[1].x); @@ -4465,7 +4473,7 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, bglEnable(GL_BLEND); spriteext[tspr.owner].roll = a; - spriteext[tspr.owner].zoff = z; + spriteext[tspr.owner].offset.z = z; fov = hudmem[(dastat&4)>>2][picnum].fov; @@ -4481,7 +4489,7 @@ void polymost_dorotatespritemodel(int32_t sx, int32_t sy, int32_t z, int16_t a, polymer_setaspect(pr_fov); - spriteext[tspr.owner].zoff = 0; + spriteext[tspr.owner].offset.z = 0; spriteext[tspr.owner].roll = 0; bglDisable(GL_BLEND); diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 9ed46ef1f..5850f9309 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -596,11 +596,11 @@ void A_DeleteSprite(int32_t s) return; } - if (G_HaveEvent(EVENT_KILLIT)) + if (VM_HaveEvent(EVENT_KILLIT)) { int32_t p, pl=A_FindPlayer(&sprite[s],&p); - if (VM_OnEvent(EVENT_KILLIT, s, pl, p, 0)) + if (VM_OnEvent_(EVENT_KILLIT, s, pl, p, 0)) return; } @@ -8295,31 +8295,32 @@ int32_t A_CheckSwitchTile(int32_t i) void G_MoveWorld(void) { extern double g_moveActorsTime; - int32_t k = MAXSTATUS-1; - do + if (EDUKE32_PREDICT_FALSE(VM_HaveEvent(EVENT_PREGAME))) { - int32_t i = headspritestat[k]; + int32_t i, j, k = 0, p, pl; - while (i >= 0) + do { - const int32_t j = nextspritestat[i]; + i = headspritestat[k++]; - if (!G_HaveEvent(EVENT_PREGAME) || A_CheckSpriteFlags(i, SFLAG_NOEVENTCODE)) + while (i >= 0) { + j = nextspritestat[i]; + + if (A_CheckSpriteFlags(i, SFLAG_NOEVENTCODE)) + { + i = j; + continue; + } + + pl = A_FindPlayer(&sprite[i], &p); + VM_OnEvent_(EVENT_PREGAME, i, pl, p, 0); + i = j; - continue; } - - { - int32_t p, pl = A_FindPlayer(&sprite[i], &p); - VM_OnEvent(EVENT_PREGAME, i, pl, p, 0); - } - - i = j; - } + } while (k < MAXSTATUS); } - while (k--); G_MoveZombieActors(); //ST 2 G_MoveWeapons(); //ST 4 @@ -8345,35 +8346,51 @@ void G_MoveWorld(void) G_MoveStandables(); //ST 6 - k = MAXSTATUS-1; - do + if (EDUKE32_PREDICT_FALSE(VM_HaveEvent(EVENT_GAME))) { - int32_t i = headspritestat[k]; + int32_t i, j, k = 0, p, pl; - while (i >= 0) + do { - const int32_t j = nextspritestat[i]; + i = headspritestat[k++]; + + while (i >= 0) + { + + if (A_CheckSpriteFlags(i, SFLAG_NOEVENTCODE)) + { + i = nextspritestat[i]; + continue; + } + + j = nextspritestat[i]; + + pl = A_FindPlayer(&sprite[i], &p); + VM_OnEvent_(EVENT_GAME, i, pl, p, 0); + + i = j; + } + } while (k < MAXSTATUS); + } #ifdef POLYMER - if (getrendermode() == REND_POLYMER) + if (getrendermode() == REND_POLYMER) + { + int32_t i, k = 0; + + do + { + i = headspritestat[k++]; + + while (i >= 0) + { A_DoLight(i); -#endif - if (!G_HaveEvent(EVENT_GAME) || A_CheckSpriteFlags(i, SFLAG_NOEVENTCODE)) - { - i = j; - continue; + i = nextspritestat[i]; } - - { - int32_t p, pl = A_FindPlayer(&sprite[i], &p); - VM_OnEvent(EVENT_GAME,i, pl, p, 0); - } - - i = j; - } + } while (k < MAXSTATUS); } - while (k--); +#endif G_DoSectorAnimations(); G_MoveFX(); //ST 11 diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 5471cce61..f089ca15e 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -8349,7 +8349,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) } #undef COPYARG -#ifdef _WIN32 +#if defined(_WIN32) && defined(DEBUGGINGAIDS) // See FILENAME_CASE_CHECK in cache1d.c static int32_t check_filename_casing(void) { @@ -8359,7 +8359,7 @@ static int32_t check_filename_casing(void) int32_t ExtPreInit(int32_t argc,const char **argv) { -#ifdef _WIN32 +#if defined(_WIN32) && defined(DEBUGGINGAIDS) { extern int32_t (*check_filename_casing_fn)(void); check_filename_casing_fn = check_filename_casing; diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index cb04dc1a8..55655d4e8 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -151,15 +151,6 @@ EDUKE32_STATIC_ASSERT(5 <= MAXTILES-MAXUSERTILES); # include "lunatic_game.h" #endif -static inline int32_t G_HaveEvent(int32_t iEventID) -{ -#ifdef LUNATIC - return El_HaveEvent(iEventID); -#else - return apScriptGameEvent[iEventID]!=NULL; -#endif -} - static inline int32_t G_HaveActor(int32_t actortile) { #ifdef LUNATIC diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index eef01a6ca..1c064bb55 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -3765,10 +3765,10 @@ void G_DisplayRest(int32_t smoothratio) } } - if (G_HaveEvent(EVENT_DISPLAYREST)) + if (VM_HaveEvent(EVENT_DISPLAYREST)) { int32_t vr=viewingrange, asp=yxaspect; - VM_OnEvent(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent_(EVENT_DISPLAYREST, g_player[screenpeek].ps->i, screenpeek, -1, 0); setaspect(vr, asp); } @@ -4044,8 +4044,7 @@ void G_DrawBackground(void) // when not rendering a game, fullscreen wipe // Gv_SetVar(g_iReturnVarID,tilesizx[MENUTILE]==320&&tilesizy[MENUTILE]==200?MENUTILE:BIGHOLE, -1, -1); - if (G_HaveEvent(EVENT_GETMENUTILE)) - bgtile = VM_OnEvent(EVENT_GETMENUTILE, -1, myconnectindex, -1, bgtile); + bgtile = VM_OnEvent(EVENT_GETMENUTILE, -1, myconnectindex, -1, bgtile); // MENU_TILE: is the menu tile tileable? #if !defined LUNATIC if (Gv_GetVarByLabel("MENU_TILE", !fstilep, -1, -1)) @@ -4705,8 +4704,7 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio) dont_draw = 0; // NOTE: might be rendering off-screen here, so CON commands that draw stuff // like showview must cope with that situation or bail out! - if (G_HaveEvent(EVENT_DISPLAYROOMS)) - dont_draw = VM_OnEvent(EVENT_DISPLAYROOMS, g_player[screenpeek].ps->i, screenpeek, -1, 0); + dont_draw = VM_OnEvent(EVENT_DISPLAYROOMS, g_player[screenpeek].ps->i, screenpeek, -1, 0); CAMERA(horiz) = clamp(CAMERA(horiz), HORIZ_MIN, HORIZ_MAX); @@ -5066,12 +5064,12 @@ int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s_z,int3 g_noResetVars = 0; #endif - if (G_HaveEvent(EVENT_EGS)) + if (VM_HaveEvent(EVENT_EGS)) { int32_t pl=A_FindPlayer(s, &p); block_deletesprite++; - VM_OnEvent(EVENT_EGS, i, pl, p, 0); + VM_OnEvent_(EVENT_EGS, i, pl, p, 0); block_deletesprite--; } @@ -7067,11 +7065,11 @@ int32_t A_Spawn(int32_t j, int32_t pn) } SPAWN_END: - if (G_HaveEvent(EVENT_SPAWN)) + if (VM_HaveEvent(EVENT_SPAWN)) { int32_t p; int32_t pl=A_FindPlayer(&sprite[i],&p); - VM_OnEvent(EVENT_SPAWN,i, pl, p, 0); + VM_OnEvent_(EVENT_SPAWN,i, pl, p, 0); } return i; @@ -7196,13 +7194,13 @@ static void G_DoEventAnimSprites(int32_t j) { const int32_t ow = tsprite[j].owner; - if (((unsigned)ow < MAXSPRITES && spriteext[ow].flags & SPREXT_TSPRACCESS) || tsprite[j].statnum == TSPR_TEMP) - { - spriteext[ow].tspr = &tsprite[j]; - // XXX: wouldn't screenpeek be more meaningful as current player? - VM_OnEvent(EVENT_ANIMATESPRITES, ow, myconnectindex, -1, 0); - spriteext[ow].tspr = NULL; - } + if (((unsigned) ow >= MAXSPRITES || (spriteext[ow].flags & SPREXT_TSPRACCESS) != SPREXT_TSPRACCESS) || tsprite[j].statnum != TSPR_TEMP) + return; + + spriteext[ow].tspr = &tsprite[j]; + // XXX: wouldn't screenpeek be more meaningful as current player? + VM_OnEvent_(EVENT_ANIMATESPRITES, ow, myconnectindex, -1, 0); + spriteext[ow].tspr = NULL; } void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t oura, int32_t smoothratio) @@ -7482,7 +7480,7 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t oura, int32_t smoo else if (g_curViewscreen >= 0 && OW != i && display_mirror != 3 && waloff[TILE_VIEWSCR] && walock[TILE_VIEWSCR] > 200 ) { // this exposes a sprite sorting issue which needs to be debugged further... -#if 0 +#if 0 if (spritesortcnt < MAXSPRITESONSCREEN) { spritetype *const newt = &tsprite[spritesortcnt++]; @@ -7501,10 +7499,11 @@ void G_DoSpriteAnimations(int32_t ourx, int32_t oury, int32_t oura, int32_t smoo t->yrepeat = t->yrepeat & 1 ? (t->yrepeat>>2) + 1 : t->yrepeat>>2; } +#if 0 // moved to polymost t->x += (sintable[(t->ang+512)&2047]>>13); t->y += (sintable[t->ang&2047]>>13); updatesector(t->x, t->y, &t->sectnum); - +#endif break; case SHRINKSPARK__STATIC: @@ -8051,15 +8050,14 @@ skip: */ } - if (G_HaveEvent(EVENT_ANIMATESPRITES)) + if (VM_HaveEvent(EVENT_ANIMATESPRITES)) { for (j = spritesortcnt-1; j>=0; j--) G_DoEventAnimSprites(j); } #ifdef LUNATIC - if (G_HaveEvent(EVENT_ANIMATEALLSPRITES)) - VM_OnEvent(EVENT_ANIMATEALLSPRITES, -1, -1, -1, 0); + VM_OnEvent(EVENT_ANIMATEALLSPRITES, -1, -1, -1, 0); #endif #ifdef DEBUGGINGAIDS g_spriteStat.numonscreen = spritesortcnt; @@ -11191,7 +11189,7 @@ void app_crashhandler(void) G_GameQuit(); } -#ifdef _WIN32 +#if defined(_WIN32) && defined(DEBUGGINGAIDS) // See FILENAME_CASE_CHECK in cache1d.c static int32_t check_filename_casing(void) { @@ -11252,10 +11250,12 @@ int32_t app_main(int32_t argc, const char **argv) backgroundidle = 0; +#ifdef DEBUGGINGAIDS { extern int32_t (*check_filename_casing_fn)(void); check_filename_casing_fn = check_filename_casing; } +#endif #endif G_ExtPreInit(argc, argv); diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 18fcf99f4..7f9fb1bb7 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1267,7 +1267,7 @@ static int32_t C_SetScriptSize(int32_t newsize) { if (bitptr[i>>3]&(BITPTR_POINTER<<(i&7))) { - if ((intptr_t)script[i] < (intptr_t)&script[0] || (intptr_t)script[i] >= (intptr_t)&script[g_scriptSize]) + if (EDUKE32_PREDICT_FALSE((intptr_t)script[i] < (intptr_t)&script[0] || (intptr_t)script[i] >= (intptr_t)&script[g_scriptSize])) { g_numCompilerErrors++; initprintf("Internal compiler error at %" PRIdPTR " (0x%" PRIxPTR ")\n",i,i); @@ -1375,7 +1375,7 @@ static int32_t C_SkipComments(void) } while (*textptr && (textptr[0] != '*' || textptr[1] != '/')); - if (!*textptr) + if (EDUKE32_PREDICT_FALSE(!*textptr)) { if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) initprintf("%s:%d: debug: EOF in comment!\n",g_szScriptFileName,g_lineNumber); @@ -1498,7 +1498,7 @@ static int32_t C_GetNextKeyword(void) //Returns its code # } tempbuf[l] = 0; - if ((i = hash_find(&h_keywords,tempbuf)) >= 0) + if (EDUKE32_PREDICT_TRUE((i = hash_find(&h_keywords,tempbuf)) >= 0)) { if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP) *g_scriptPtr = i + (IFELSE_MAGIC<<12); @@ -1516,7 +1516,7 @@ static int32_t C_GetNextKeyword(void) //Returns its code # textptr += l; g_numCompilerErrors++; - if ((tempbuf[0] == '{' || tempbuf[0] == '}') && tempbuf[1] != 0) + if (EDUKE32_PREDICT_FALSE((tempbuf[0] == '{' || tempbuf[0] == '}') && tempbuf[1] != 0)) { C_ReportError(-1); initprintf("%s:%d: error: expected whitespace between `%c' and `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf[0],tempbuf+1); @@ -1531,11 +1531,11 @@ static int32_t parse_decimal_number(void) // (textptr) // decimal constants -- this is finicky business int64_t num = strtoll(textptr, NULL, 10); // assume long long to be int64_t - if (num >= INT32_MIN && num <= INT32_MAX) + if (EDUKE32_PREDICT_TRUE(num >= INT32_MIN && num <= INT32_MAX)) { // all OK } - else if (num > INT32_MAX && num <= UINT32_MAX) + else if (EDUKE32_PREDICT_FALSE(num > INT32_MAX && num <= UINT32_MAX)) { // Number interpreted as uint32, but packed as int32 (on 32-bit archs) // (CON code in the wild exists that does this). Note that such conversion @@ -1563,7 +1563,7 @@ static int32_t parse_hex_constant(const char *hexnum) int64_t x; sscanf(hexnum, "%" PRIx64 "", &x); - if (x > UINT32_MAX) + if (EDUKE32_PREDICT_FALSE(x > UINT32_MAX)) { initprintf("%s:%d: warning: number 0x%" PRIx64 " truncated to 32 bits.\n", g_szScriptFileName,g_lineNumber, x); @@ -1605,13 +1605,7 @@ static void C_GetNextVarType(int32_t type) } else if ((*textptr == '-')/* && !isdigit(*(textptr+1))*/) { - if (!type) - { - if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) - initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber); //,Batol(textptr)); - f = (MAXGAMEVARS<<1); - } - else + if (EDUKE32_PREDICT_FALSE(type)) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -1619,12 +1613,16 @@ static void C_GetNextVarType(int32_t type) return; } + if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) + initprintf("%s:%d: debug: flagging gamevar as negative.\n", g_szScriptFileName, g_lineNumber); //,Batol(textptr)); + f = (MAXGAMEVARS<<1); + textptr++; } C_GetNextLabelName(); - if (!g_skipKeywordCheck && hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -1645,7 +1643,7 @@ static void C_GetNextVarType(int32_t type) if (i < g_iSpriteVarID || i > g_iActorVarID) i = -1; - if (i < 0) + if (EDUKE32_PREDICT_FALSE(i < 0)) { g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEARRAY); @@ -1660,7 +1658,7 @@ static void C_GetNextVarType(int32_t type) C_GetNextVarType(0); C_SkipComments(); - if (*textptr != ']') + if (EDUKE32_PREDICT_FALSE(*textptr != ']')) { g_numCompilerErrors++; C_ReportError(ERROR_GAMEARRAYBNC); @@ -1670,7 +1668,7 @@ static void C_GetNextVarType(int32_t type) //writing arrays in this way is not supported because it would require too many changes to other code - if (type) + if (EDUKE32_PREDICT_FALSE(type)) { g_numCompilerErrors++; C_ReportError(ERROR_INVALIDARRAYWRITE); @@ -1689,7 +1687,7 @@ static void C_GetNextVarType(int32_t type) textptr++; } - if (*textptr != '.') + if (EDUKE32_PREDICT_FALSE(*textptr != '.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -1712,7 +1710,7 @@ static void C_GetNextVarType(int32_t type) lLabelID=GetDefID(label+(g_numLabels<<6)); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -1765,9 +1763,9 @@ static void C_GetNextVarType(int32_t type) //try looking for a define instead Bstrcpy(tempbuf,label+(g_numLabels<<6)); i = hash_find(&h_labels,tempbuf); - if (i>=0) + if (EDUKE32_PREDICT_TRUE(i>=0)) { - if (labeltype[i] & LABEL_DEFINE) + if (EDUKE32_PREDICT_TRUE(labeltype[i] & LABEL_DEFINE)) { if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) initprintf("%s:%d: debug: accepted defined label `%s' instead of gamevar.\n",g_szScriptFileName,g_lineNumber,label+(i<<6)); @@ -1788,13 +1786,13 @@ static void C_GetNextVarType(int32_t type) return; } - if (type == GAMEVAR_READONLY && aGameVars[i].dwFlags & GAMEVAR_READONLY) + if (EDUKE32_PREDICT_FALSE(type == GAMEVAR_READONLY && aGameVars[i].dwFlags & GAMEVAR_READONLY)) { g_numCompilerErrors++; C_ReportError(ERROR_VARREADONLY); return; } - else if (aGameVars[i].dwFlags & type) + else if (EDUKE32_PREDICT_FALSE(aGameVars[i].dwFlags & type)) { g_numCompilerErrors++; C_ReportError(ERROR_VARTYPEMISMATCH); @@ -1842,7 +1840,7 @@ static int32_t C_GetNextValue(int32_t type) } tempbuf[l] = 0; - if (!g_skipKeywordCheck && hash_find(&h_keywords,tempbuf /*label+(g_numLabels<<6)*/)>=0) + if (EDUKE32_PREDICT_FALSE(!g_skipKeywordCheck && hash_find(&h_keywords,tempbuf /*label+(g_numLabels<<6)*/)>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -1854,7 +1852,7 @@ static int32_t C_GetNextValue(int32_t type) { char *el,*gl; - if (labeltype[i] & type) + if (EDUKE32_PREDICT_TRUE(labeltype[i] & type)) { if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) { @@ -1869,6 +1867,7 @@ static int32_t C_GetNextValue(int32_t type) textptr += l; return labeltype[i]; } + bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); *(g_scriptPtr++) = 0; textptr += l; @@ -1882,7 +1881,7 @@ static int32_t C_GetNextValue(int32_t type) return -1; // valid label name, but wrong type } - if (isdigit(*textptr) == 0 && *textptr != '-') + if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) == 0 && *textptr != '-')) { C_ReportError(ERROR_PARAMUNDEFINED); g_numCompilerErrors++; @@ -1893,7 +1892,7 @@ static int32_t C_GetNextValue(int32_t type) return -1; // error! } - if (isdigit(*textptr) && g_labelsOnly) + if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) && g_labelsOnly)) { C_ReportError(WARNING_LABELSONLY); g_numCompilerWarnings++; @@ -1904,7 +1903,7 @@ static int32_t C_GetNextValue(int32_t type) { // FIXME: check for 0-9 A-F for hex if (textptr[0] == '0' && textptr[1] == 'x') break; // kill the warning for hex - if (!isdigit(textptr[i--])) + if (EDUKE32_PREDICT_FALSE(!isdigit(textptr[i--]))) { C_ReportError(-1); initprintf("%s:%d: warning: invalid character `%c' in definition!\n",g_szScriptFileName,g_lineNumber,textptr[i+1]); @@ -1985,7 +1984,7 @@ static int32_t C_CheckEmptyBranch(int32_t tw, intptr_t lastScriptPtr) if ((*(g_scriptPtr) & 0xFFF) != CON_NULLOP || *(g_scriptPtr)>>12 != IFELSE_MAGIC) g_ifElseAborted = 0; - if (g_ifElseAborted) + if (EDUKE32_PREDICT_FALSE(g_ifElseAborted)) { C_ReportError(-1); g_numCompilerWarnings++; @@ -2037,7 +2036,7 @@ static void C_Include(const char *confile) int32_t fp; fp = kopen4loadfrommod(confile,g_loadFromGroupOnly); - if (fp < 0) + if (EDUKE32_PREDICT_FALSE(fp < 0)) { g_numCompilerErrors++; initprintf("%s:%d: error: could not find file `%s'.\n",g_szScriptFileName,g_lineNumber,confile); @@ -2519,17 +2518,17 @@ static int32_t C_ParseCommand(int32_t loop) do { - if (quitevent) + if (EDUKE32_PREDICT_FALSE(quitevent)) { initprintf("Aborted.\n"); G_Shutdown(); Bexit(0); } - if (g_numCompilerErrors > 63 || (*textptr == '\0') || (*(textptr+1) == '\0') || C_SkipComments()) + if (EDUKE32_PREDICT_FALSE(g_numCompilerErrors > 63 || (*textptr == '\0') || (*(textptr+1) == '\0') || C_SkipComments())) return 1; - if (g_scriptDebug) + if (EDUKE32_PREDICT_FALSE(g_scriptDebug)) C_ReportError(-1); tempscrptr = NULL; // temptextptr = NULL; @@ -2552,14 +2551,14 @@ static int32_t C_ParseCommand(int32_t loop) g_processingState = 1; Bsprintf(g_szCurrentBlockName,"%s",label+(g_numLabels<<6)); - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); continue; } - if (hash_find(&h_gamevars,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_gamevars,label+(g_numLabels<<6))>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); @@ -2572,43 +2571,39 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextLabelName(); - if ((j = hash_find(&h_labels,label+(g_numLabels<<6))) >= 0) - { - if (labeltype[j] & LABEL_STATE) - { - if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) - initprintf("%s:%d: debug: accepted state label `%s'.\n",g_szScriptFileName,g_lineNumber,label+(j<<6)); - *g_scriptPtr = (intptr_t)(script+labelcode[j]); - - // 'state' type labels are always script addresses, as far as I can see - bitptr[(g_scriptPtr-script)>>3] |= (BITPTR_POINTER<<((g_scriptPtr-script)&7)); - - g_scriptPtr++; - continue; - } - else - { - char *gl = (char *)C_GetLabelType(labeltype[j]); - C_ReportError(-1); - initprintf("%s:%d: warning: expected state, found %s.\n",g_szScriptFileName,g_lineNumber,gl); - g_numCompilerWarnings++; - Bfree(gl); - *(g_scriptPtr-1) = CON_NULLOP; // get rid of the state, leaving a nullop to satisfy if conditions - bitptr[(g_scriptPtr-script-1)>>3] &= ~(1<<((g_scriptPtr-script-1)&7)); - continue; // valid label name, but wrong type - } - } - else + if (EDUKE32_PREDICT_FALSE((j = hash_find(&h_labels,label+(g_numLabels<<6))) < 0)) { C_ReportError(-1); initprintf("%s:%d: error: state `%s' not found.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); g_numCompilerErrors++; + g_scriptPtr++; + continue; } + + if (EDUKE32_PREDICT_FALSE((labeltype[j] & LABEL_STATE) != LABEL_STATE)) + { + char *gl = (char *) C_GetLabelType(labeltype[j]); + C_ReportError(-1); + initprintf("%s:%d: warning: expected state, found %s.\n", g_szScriptFileName, g_lineNumber, gl); + g_numCompilerWarnings++; + Bfree(gl); + *(g_scriptPtr-1) = CON_NULLOP; // get rid of the state, leaving a nullop to satisfy if conditions + bitptr[(g_scriptPtr-script-1)>>3] &= ~(1<<((g_scriptPtr-script-1)&7)); + continue; // valid label name, but wrong type + } + + if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) + initprintf("%s:%d: debug: accepted state label `%s'.\n", g_szScriptFileName, g_lineNumber, label+(j<<6)); + *g_scriptPtr = (intptr_t) (script+labelcode[j]); + + // 'state' type labels are always script addresses, as far as I can see + bitptr[(g_scriptPtr-script)>>3] |= (BITPTR_POINTER<<((g_scriptPtr-script)&7)); + g_scriptPtr++; continue; case CON_ENDS: - if (g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_processingState == 0)) { C_ReportError(-1); initprintf("%s:%d: error: found `ends' without open `state'.\n",g_szScriptFileName,g_lineNumber); @@ -2616,17 +2611,18 @@ static int32_t C_ParseCommand(int32_t loop) } // else { - if (g_numBraces > 0) + if (EDUKE32_PREDICT_FALSE(g_numBraces > 0)) { C_ReportError(ERROR_OPENBRACKET); g_numCompilerErrors++; } - else if (g_numBraces < 0) + else if (EDUKE32_PREDICT_FALSE(g_numBraces < 0)) { C_ReportError(ERROR_CLOSEBRACKET); g_numCompilerErrors++; } - if (g_checkingSwitch > 0) + + if (EDUKE32_PREDICT_FALSE(g_checkingSwitch > 0)) { C_ReportError(ERROR_NOENDSWITCH); g_numCompilerErrors++; @@ -2672,7 +2668,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -2685,7 +2681,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameOffset(&projectileH,Bstrtolower(label+(g_numLabels<<6))); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -2720,7 +2716,7 @@ static int32_t C_ParseCommand(int32_t loop) // (see top of this files for flags) //printf("Got gamedef. Getting Label. '%.20s'\n",textptr); - if (isdigit(*textptr) || (*textptr == '-')) + if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) || (*textptr == '-'))) { C_GetNextLabelName(); g_numCompilerErrors++; @@ -2735,7 +2731,7 @@ static int32_t C_ParseCommand(int32_t loop) //printf("Got Label '%.20s'\n",textptr); // Check to see it's already defined - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -2750,7 +2746,7 @@ static int32_t C_ParseCommand(int32_t loop) //Bsprintf(g_szBuf,"Adding GameVar=\"%s\", val=%l, flags=%lX",label+(g_numLabels<<6), // *(g_scriptPtr-2), *(g_scriptPtr-1)); //AddLog(g_szBuf); - if ((*(g_scriptPtr-1)&GAMEVAR_USER_MASK)==3) + if (EDUKE32_PREDICT_FALSE((*(g_scriptPtr-1)&GAMEVAR_USER_MASK)==3)) { g_numCompilerWarnings++; *(g_scriptPtr-1)^=GAMEVAR_PERPLAYER; @@ -2766,7 +2762,7 @@ static int32_t C_ParseCommand(int32_t loop) continue; case CON_GAMEARRAY: - if (isdigit(*textptr) || (*textptr == '-')) + if (EDUKE32_PREDICT_FALSE(isdigit(*textptr) || (*textptr == '-'))) { C_GetNextLabelName(); g_numCompilerErrors++; @@ -2780,7 +2776,7 @@ static int32_t C_ParseCommand(int32_t loop) //printf("Got Label '%.20s'\n",textptr); // Check to see it's already defined - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -2788,7 +2784,7 @@ static int32_t C_ParseCommand(int32_t loop) } i = hash_find(&h_gamevars,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); @@ -2808,7 +2804,7 @@ static int32_t C_ParseCommand(int32_t loop) //printf("Got label. '%.20s'\n",textptr); // Check to see it's already defined - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -2816,7 +2812,7 @@ static int32_t C_ParseCommand(int32_t loop) } i = hash_find(&h_gamevars,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); @@ -2832,7 +2828,7 @@ static int32_t C_ParseCommand(int32_t loop) { // if (i >= g_numDefaultLabels) - if (labelcode[i] != *(g_scriptPtr-1)) + if (EDUKE32_PREDICT_FALSE(labelcode[i] != *(g_scriptPtr-1))) { g_numCompilerWarnings++; initprintf("%s:%d: warning: ignored redefinition of `%s' to %d (old: %d).\n",g_szScriptFileName, @@ -2872,7 +2868,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_MOVE: if (g_parsingActorPtr || g_processingState) { - if ((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)) + if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) { C_ReportError(-1); bitptr[(g_scriptPtr-script-1)>>3] &= ~(1<<((g_scriptPtr-script-1)&7)); @@ -2899,20 +2895,20 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextLabelName(); // Check to see it's already defined - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); continue; } - if (hash_find(&h_gamevars,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_gamevars,label+(g_numLabels<<6))>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); } - if ((i = hash_find(&h_labels,label+(g_numLabels<<6))) >= 0) + if (EDUKE32_PREDICT_FALSE((i = hash_find(&h_labels,label+(g_numLabels<<6))) >= 0)) { g_numCompilerWarnings++; initprintf("%s:%d: warning: duplicate move `%s' ignored.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); @@ -2953,40 +2949,39 @@ static int32_t C_ParseCommand(int32_t loop) if (k == -1) k = MAXVOLUMES; - if (k >= 0 && k < MAXVOLUMES+1) // if it's background or special music - { - i = 0; - // get the file name... - while (C_GetKeyword() == -1) - { - C_SkipComments(); - - j = 0; - tempbuf[j] = '/'; - while (isaltok(*(textptr+j))) - { - tempbuf[j+1] = textptr[j]; - j++; - } - tempbuf[j+1] = '\0'; - - C_DefineMusic(k, i, tempbuf); - - textptr += j; - - if (i >= MAXLEVELS) - break; - i++; - } - } - else + if (EDUKE32_PREDICT_FALSE((unsigned)k >= MAXVOLUMES+1)) // if it's not background or special music { g_numCompilerErrors++; C_ReportError(-1); initprintf("%s:%d: error: volume number must be between 0 and MAXVOLUMES+1=%d.\n", g_szScriptFileName, g_lineNumber, MAXVOLUMES+1); + continue; + } + i = 0; + // get the file name... + while (C_GetKeyword() == -1) + { + C_SkipComments(); + + j = 0; + tempbuf[j] = '/'; + while (isaltok(*(textptr+j))) + { + tempbuf[j+1] = textptr[j]; + j++; + } + tempbuf[j+1] = '\0'; + + C_DefineMusic(k, i, tempbuf); + + textptr += j; + + if (i >= MAXLEVELS) + break; + i++; + } } continue; @@ -3021,7 +3016,7 @@ static int32_t C_ParseCommand(int32_t loop) g_scriptPtr--; C_GetNextLabelName(); - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -3029,14 +3024,14 @@ static int32_t C_ParseCommand(int32_t loop) } i = hash_find(&h_gamevars,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); } i = hash_find(&h_labels,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; initprintf("%s:%d: warning: duplicate ai `%s' ignored.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); @@ -3055,7 +3050,8 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_ACTION); else if (j == 2) { - if ((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)) + if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && + (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) { C_ReportError(-1); bitptr[(g_scriptPtr-script-1)>>3] &= ~(1<<((g_scriptPtr-script-1)&7)); @@ -3101,7 +3097,7 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextLabelName(); // Check to see it's already defined - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -3109,14 +3105,14 @@ static int32_t C_ParseCommand(int32_t loop) } i = hash_find(&h_gamevars,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; C_ReportError(WARNING_NAMEMATCHESVAR); } i = hash_find(&h_labels,label+(g_numLabels<<6)); - if (i>=0) + if (EDUKE32_PREDICT_FALSE(i>=0)) { g_numCompilerWarnings++; initprintf("%s:%d: warning: duplicate action `%s' ignored.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); @@ -3145,7 +3141,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_ACTOR: case CON_USERACTOR: case CON_EVENTLOADACTOR: - if (g_processingState || g_parsingActorPtr) + if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr)) { C_ReportError(ERROR_FOUNDWITHIN); g_numCompilerErrors++; @@ -3175,7 +3171,7 @@ static int32_t C_ParseCommand(int32_t loop) { j = *g_scriptPtr; - if (j > 6 || (j&3)==3) + if (EDUKE32_PREDICT_FALSE(j > 6 || (j&3)==3)) { C_ReportError(-1); initprintf("%s:%d: warning: invalid useractor type. Must be 0, 1, 2" @@ -3189,7 +3185,7 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); g_scriptPtr--; - if ((unsigned)*g_scriptPtr >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)*g_scriptPtr >= MAXTILES)) { C_ReportError(ERROR_EXCEEDSMAXTILES); g_numCompilerErrors++; @@ -3256,7 +3252,8 @@ static int32_t C_ParseCommand(int32_t loop) break; case 2: // XXX: LABEL_MOVE|LABEL_DEFINE, what is this shit? compatibility? - if ((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)) + // yep, it sure is :( + if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) { C_ReportError(-1); bitptr[(g_scriptPtr-script-1)>>3] &= ~(1<<((g_scriptPtr-script-1)&7)); @@ -3276,7 +3273,7 @@ static int32_t C_ParseCommand(int32_t loop) continue; case CON_ONEVENT: - if (g_processingState || g_parsingActorPtr) + if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr)) { C_ReportError(ERROR_FOUNDWITHIN); g_numCompilerErrors++; @@ -3303,7 +3300,7 @@ static int32_t C_ParseCommand(int32_t loop) g_currentEvent = j; //Bsprintf(g_szBuf,"Adding Event for %d at %lX",j, g_parsingEventPtr); //AddLog(g_szBuf); - if (j > MAXGAMEEVENTS-1 || j < 0) + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXGAMEEVENTS-1)) { initprintf("%s:%d: error: invalid event ID.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; @@ -3369,14 +3366,14 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); if (tw == CON_CSTAT) { - if (*(g_scriptPtr-1) == 32767) + if (EDUKE32_PREDICT_FALSE(*(g_scriptPtr-1) == 32767)) { *(g_scriptPtr-1) = 32768; C_ReportError(-1); initprintf("%s:%d: warning: tried to set cstat 32767, using 32768 instead.\n",g_szScriptFileName,g_lineNumber); g_numCompilerWarnings++; } - else if ((*(g_scriptPtr-1) & 32) && (*(g_scriptPtr-1) & 16)) + else if (EDUKE32_PREDICT_FALSE((*(g_scriptPtr-1) & 32) && (*(g_scriptPtr-1) & 16))) { i = *(g_scriptPtr-1); *(g_scriptPtr-1) ^= 48; @@ -3406,7 +3403,29 @@ static int32_t C_ParseCommand(int32_t loop) continue; case CON_ELSE: - if (g_checkingIfElse) + if (EDUKE32_PREDICT_FALSE(!g_checkingIfElse)) + { + g_scriptPtr--; + tempscrptr = g_scriptPtr; + g_numCompilerWarnings++; + C_ReportError(-1); + + initprintf("%s:%d: warning: found `else' with no `if'.\n",g_szScriptFileName,g_lineNumber); + + if (C_GetKeyword() == CON_LEFTBRACE) + { + C_GetNextKeyword(); + g_numBraces++; + + C_ParseCommand(1); + } + else C_ParseCommand(0); + + g_scriptPtr = tempscrptr; + + continue; + } + { intptr_t offset; intptr_t lastScriptPtr = g_scriptPtr - &script[0] - 1; @@ -3429,26 +3448,7 @@ static int32_t C_ParseCommand(int32_t loop) *tempscrptr = (intptr_t) g_scriptPtr; bitptr[(tempscrptr-script)>>3] |= (BITPTR_POINTER<<((tempscrptr-script)&7)); } - else - { - g_scriptPtr--; - tempscrptr = g_scriptPtr; - g_numCompilerWarnings++; - C_ReportError(-1); - - initprintf("%s:%d: warning: found `else' with no `if'.\n",g_szScriptFileName,g_lineNumber); - - if (C_GetKeyword() == CON_LEFTBRACE) - { - C_GetNextKeyword(); - g_numBraces++; - - C_ParseCommand(1); - } - else C_ParseCommand(0); - - g_scriptPtr = tempscrptr; - } + continue; case CON_SETSECTOR: @@ -3481,7 +3481,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3494,7 +3494,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameID(SectorLabels,§orH,Bstrtolower(label+(g_numLabels<<6))); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -3611,7 +3611,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3624,7 +3624,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameID(WallLabels,&wallH,Bstrtolower(label+(g_numLabels<<6))); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -3673,7 +3673,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3686,7 +3686,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameOffset(&playerH,Bstrtolower(label+(g_numLabels<<6))); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -3749,7 +3749,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3762,7 +3762,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameOffset(&inputH,Bstrtolower(label+(g_numLabels<<6))); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -3800,7 +3800,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3813,7 +3813,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameID(UserdefsLabels,&userdefH,Bstrtolower(label+(g_numLabels<<6))); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -3862,7 +3862,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -3897,7 +3897,7 @@ static int32_t C_ParseCommand(int32_t loop) //printf("found label of \"%s\"\n", label+(g_numLabels<<6)); // Check to see if it's a keyword - if (hash_find(&h_keywords,label+(g_numLabels<<6))>=0) + if (EDUKE32_PREDICT_FALSE(hash_find(&h_keywords,label+(g_numLabels<<6))>=0)) { g_numCompilerErrors++; C_ReportError(ERROR_ISAKEYWORD); @@ -3906,14 +3906,14 @@ static int32_t C_ParseCommand(int32_t loop) i=GetDefID(label+(g_numLabels<<6)); //printf("Label \"%s\" ID is %d\n",label+(g_numLabels<<6), i); - if (i<0) + if (EDUKE32_PREDICT_FALSE(i<0)) { // not a defined DEF g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEVAR); continue; } - if (aGameVars[i].dwFlags & GAMEVAR_READONLY) + if (EDUKE32_PREDICT_FALSE(aGameVars[i].dwFlags & GAMEVAR_READONLY)) { g_numCompilerErrors++; C_ReportError(ERROR_VARREADONLY); @@ -3923,8 +3923,7 @@ static int32_t C_ParseCommand(int32_t loop) switch (tw) { case CON_SETACTORVAR: - { - if (!(aGameVars[i].dwFlags & GAMEVAR_PERACTOR)) + if (EDUKE32_PREDICT_FALSE(!(aGameVars[i].dwFlags & GAMEVAR_PERACTOR))) { g_numCompilerErrors++; C_ReportError(-1); @@ -3932,10 +3931,8 @@ static int32_t C_ParseCommand(int32_t loop) continue; } break; - } case CON_SETPLAYERVAR: - { - if (!(aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)) + if (EDUKE32_PREDICT_FALSE(!(aGameVars[i].dwFlags & GAMEVAR_PERPLAYER))) { g_numCompilerErrors++; C_ReportError(-1); @@ -3943,7 +3940,6 @@ static int32_t C_ParseCommand(int32_t loop) continue; } break; - } } bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); @@ -3993,7 +3989,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr != '.') + if (EDUKE32_PREDICT_FALSE(*textptr != '.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -4007,7 +4003,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameOffset(&actorH,Bstrtolower(label+(g_numLabels<<6))); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -4041,7 +4037,7 @@ static int32_t C_ParseCommand(int32_t loop) { int32_t lLabelID; #if 0 - if (g_currentEvent != EVENT_ANIMATESPRITES) + if (unlikely(g_currentEvent != EVENT_ANIMATESPRITES)) { C_ReportError(-1); initprintf("%s:%d: warning: found `%s' outside of EVENT_ANIMATESPRITES\n",g_szScriptFileName,g_lineNumber,tempbuf); @@ -4073,7 +4069,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; } - if (*textptr!='.') + if (EDUKE32_PREDICT_FALSE(*textptr!='.')) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -4086,7 +4082,7 @@ static int32_t C_ParseCommand(int32_t loop) lLabelID=C_GetLabelNameOffset(&tspriteH,Bstrtolower(label+(g_numLabels<<6))); //printf("LabelID is %d\n",lLabelID); - if (lLabelID == -1) + if (EDUKE32_PREDICT_FALSE(lLabelID == -1)) { g_numCompilerErrors++; C_ReportError(ERROR_SYMBOLNOTRECOGNIZED); @@ -4168,7 +4164,7 @@ static int32_t C_ParseCommand(int32_t loop) //printf("We are enhanced, baby...\n"); C_GetNextValue(LABEL_DEFINE); g_scriptPtr--; - if (*g_scriptPtr > BYTEVERSION_JF) + if (EDUKE32_PREDICT_FALSE(*g_scriptPtr > BYTEVERSION_JF)) { g_numCompilerWarnings++; initprintf("%s:%d: warning: need build %d, found build %d\n",g_szScriptFileName,g_lineNumber,k,BYTEVERSION_JF); @@ -4177,7 +4173,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_DYNAMICREMAP: g_scriptPtr--; - if (g_dynamicTileMapping) + if (EDUKE32_PREDICT_FALSE(g_dynamicTileMapping)) { initprintf("%s:%d: warning: duplicate dynamicremap statement\n",g_szScriptFileName,g_lineNumber); g_numCompilerWarnings++; @@ -4197,7 +4193,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_DYNAMICSOUNDREMAP: g_scriptPtr--; - if (g_dynamicSoundMapping) + if (EDUKE32_PREDICT_FALSE(g_dynamicSoundMapping)) { initprintf("%s:%d: warning: duplicate dynamicsoundremap statement\n",g_szScriptFileName,g_lineNumber); g_numCompilerWarnings++; @@ -4281,36 +4277,31 @@ static int32_t C_ParseCommand(int32_t loop) case CON_READARRAYFROMFILE: C_GetNextLabelName(); i=GetADefID(label+(g_numLabels<<6)); - if (i > (-1)) - { - bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); - *g_scriptPtr++=i; - } - else + if (EDUKE32_PREDICT_FALSE(i < 0)) { g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEARRAY); return 1; } + + bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); + *g_scriptPtr++=i; + C_GetNextValue(LABEL_DEFINE); continue; case CON_COPY: C_GetNextLabelName(); i=GetADefID(label+(g_numLabels<<6)); - if (i > (-1)) - { - bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); - *g_scriptPtr++=i; - } - else + if (EDUKE32_PREDICT_FALSE(i < 0)) { g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEARRAY); return 1; } + bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); + *g_scriptPtr++=i; C_SkipComments();// skip comments and whitespace - if (*textptr != '[') - + if (EDUKE32_PREDICT_FALSE(*textptr != '[')) { g_numCompilerErrors++; C_ReportError(ERROR_GAMEARRAYBNO); @@ -4319,7 +4310,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; C_GetNextVar(); C_SkipComments();// skip comments and whitespace - if (*textptr != ']') + if (EDUKE32_PREDICT_FALSE(*textptr != ']')) { g_numCompilerErrors++; C_ReportError(ERROR_GAMEARRAYBNC); @@ -4329,27 +4320,25 @@ static int32_t C_ParseCommand(int32_t loop) case CON_SETARRAY: C_GetNextLabelName(); i=GetADefID(label+(g_numLabels<<6)); - if (i > (-1)) - { - bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); - *g_scriptPtr++=i; - - if (aGameArrays[i].dwFlags & GAMEARRAY_READONLY) - { - C_ReportError(ERROR_ARRAYREADONLY); - g_numCompilerErrors++; - return 1; - } - } - else + if (EDUKE32_PREDICT_FALSE(i < 0)) { g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEARRAY); return 1; } + bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); + *g_scriptPtr++=i; + + if (EDUKE32_PREDICT_FALSE(aGameArrays[i].dwFlags & GAMEARRAY_READONLY)) + { + C_ReportError(ERROR_ARRAYREADONLY); + g_numCompilerErrors++; + return 1; + } + C_SkipComments();// skip comments and whitespace - if (*textptr != '[') + if (EDUKE32_PREDICT_FALSE(*textptr != '[')) { g_numCompilerErrors++; C_ReportError(ERROR_GAMEARRAYBNO); @@ -4358,7 +4347,7 @@ static int32_t C_ParseCommand(int32_t loop) textptr++; C_GetNextVar(); C_SkipComments();// skip comments and whitespace - if (*textptr != ']') + if (EDUKE32_PREDICT_FALSE(*textptr != ']')) { g_numCompilerErrors++; C_ReportError(ERROR_GAMEARRAYBNC); @@ -4371,24 +4360,22 @@ static int32_t C_ParseCommand(int32_t loop) case CON_RESIZEARRAY: C_GetNextLabelName(); i=GetADefID(label+(g_numLabels<<6)); - if (i >= 0) - { - bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); - *g_scriptPtr++ = i; - if (tw==CON_RESIZEARRAY && (aGameArrays[i].dwFlags & GAMEARRAY_TYPE_MASK)) - { - C_ReportError(-1); - initprintf("can't resize system array `%s'.", label+(g_numLabels<<6)); - return 1; - } - } - else + if (EDUKE32_PREDICT_FALSE(i < 0)) { g_numCompilerErrors++; C_ReportError(ERROR_NOTAGAMEARRAY); return 1; } + bitptr[(g_scriptPtr-script)>>3] &= ~(BITPTR_POINTER<<((g_scriptPtr-script)&7)); + *g_scriptPtr++ = i; + if (tw==CON_RESIZEARRAY && (aGameArrays[i].dwFlags & GAMEARRAY_TYPE_MASK)) + { + C_ReportError(-1); + initprintf("can't resize system array `%s'.", label+(g_numLabels<<6)); + return 1; + } + C_SkipComments(); C_GetNextVarType(tw==CON_GETARRAYSIZE ? GAMEVAR_READONLY : 0); continue; @@ -4462,7 +4449,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_LOADMAPSTATE: if (tw != CON_FLASH) { - if (g_currentEvent == EVENT_ANIMATESPRITES) + if (EDUKE32_PREDICT_FALSE(g_currentEvent == EVENT_ANIMATESPRITES)) { initprintf("%s:%d: warning: found `%s' inside EVENT_ANIMATESPRITES\n", g_szScriptFileName,g_lineNumber,tempbuf); @@ -4492,7 +4479,7 @@ static int32_t C_ParseCommand(int32_t loop) { int32_t y, z; - if (g_processingState || g_parsingActorPtr) + if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr)) { C_ReportError(ERROR_FOUNDWITHIN); g_numCompilerErrors++; @@ -4508,7 +4495,7 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); z = *(g_scriptPtr-1); - if ((unsigned)j >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXTILES)) { C_ReportError(ERROR_EXCEEDSMAXTILES); g_numCompilerErrors++; @@ -4531,7 +4518,7 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); g_scriptPtr--; - if ((unsigned)j >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXTILES)) { C_ReportError(ERROR_EXCEEDSMAXTILES); g_numCompilerErrors++; @@ -4550,7 +4537,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_SPRITENOSHADE: case CON_SPRITENOPAL: case CON_PRECACHE: - if (g_processingState || g_parsingActorPtr) + if (EDUKE32_PREDICT_FALSE(g_processingState || g_parsingActorPtr)) { C_ReportError(ERROR_FOUNDWITHIN); g_numCompilerErrors++; @@ -4562,7 +4549,7 @@ static int32_t C_ParseCommand(int32_t loop) g_scriptPtr--; j = *g_scriptPtr; - if ((unsigned)j >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXTILES)) { C_ReportError(ERROR_EXCEEDSMAXTILES); g_numCompilerErrors++; @@ -4587,7 +4574,7 @@ static int32_t C_ParseCommand(int32_t loop) C_GetNextValue(LABEL_DEFINE); g_scriptPtr--; i = *g_scriptPtr; - if ((unsigned)i >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXTILES)) { C_ReportError(ERROR_EXCEEDSMAXTILES); g_numCompilerErrors++; @@ -4711,7 +4698,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_ROTATESPRITE16: case CON_ROTATESPRITE: - if (g_parsingEventPtr == NULL && g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL && g_processingState == 0)) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; @@ -4727,7 +4714,7 @@ static int32_t C_ParseCommand(int32_t loop) continue; case CON_ROTATESPRITEA: - if (g_parsingEventPtr == NULL && g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL && g_processingState == 0)) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; @@ -4738,7 +4725,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_SHOWVIEW: case CON_SHOWVIEWUNBIASED: - if (g_parsingEventPtr == NULL && g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL && g_processingState == 0)) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; @@ -4824,7 +4811,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_DIGITALNUMBER: case CON_DIGITALNUMBERZ: case CON_SCREENTEXT: - if (g_parsingEventPtr == NULL && g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL && g_processingState == 0)) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; @@ -4858,7 +4845,7 @@ static int32_t C_ParseCommand(int32_t loop) case CON_MYOSPAL: case CON_MYOSX: case CON_MYOSPALX: - if (g_parsingEventPtr == NULL && g_processingState == 0) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL && g_processingState == 0)) { C_ReportError(ERROR_EVENTONLY); g_numCompilerErrors++; @@ -4997,7 +4984,7 @@ static int32_t C_ParseCommand(int32_t loop) intptr_t tempoffset = 0; //AddLog("Found Case"); - if (g_checkingSwitch < 1) + if (EDUKE32_PREDICT_FALSE(g_checkingSwitch < 1)) { g_numCompilerErrors++; C_ReportError(-1); @@ -5023,7 +5010,7 @@ repeatcase: if (g_caseScriptPtr) { for (i=(g_numCases/2)-1; i>=0; i--) - if (g_caseScriptPtr[i*2+1]==j) + if (EDUKE32_PREDICT_FALSE(g_caseScriptPtr[i*2+1]==j)) { g_numCompilerWarnings++; C_ReportError(WARNING_DUPLICATECASE); @@ -5072,14 +5059,14 @@ repeatcase: if (*textptr == ':') textptr++; - if (g_checkingSwitch<1) + if (EDUKE32_PREDICT_FALSE(g_checkingSwitch<1)) { g_numCompilerErrors++; C_ReportError(-1); initprintf("%s:%d: error: found `default' statement when not in switch\n",g_szScriptFileName,g_lineNumber); return 1; } - if (g_caseScriptPtr && g_caseScriptPtr[0]!=0) + if (EDUKE32_PREDICT_FALSE(g_caseScriptPtr && g_caseScriptPtr[0]!=0)) { // duplicate default statement g_numCompilerErrors++; @@ -5098,7 +5085,7 @@ repeatcase: case CON_ENDSWITCH: //AddLog("End Switch"); - if (--g_checkingSwitch < 0) + if (EDUKE32_PREDICT_FALSE(--g_checkingSwitch < 0)) { g_numCompilerErrors++; C_ReportError(-1); @@ -5201,7 +5188,7 @@ repeatcase: C_GetNextValue(LABEL_ACTION); break; case CON_IFMOVE: - if ((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1)) + if (EDUKE32_PREDICT_FALSE((C_GetNextValue(LABEL_MOVE|LABEL_DEFINE) == 0) && (*(g_scriptPtr-1) != 0) && (*(g_scriptPtr-1) != 1))) { C_ReportError(-1); *(g_scriptPtr-1) = 0; @@ -5311,7 +5298,7 @@ repeatcase: } case CON_LEFTBRACE: - if (!(g_processingState || g_parsingActorPtr || g_parsingEventPtr)) + if (EDUKE32_PREDICT_FALSE(!(g_processingState || g_parsingActorPtr || g_parsingEventPtr))) { g_numCompilerErrors++; C_ReportError(ERROR_SYNTAXERROR); @@ -5343,7 +5330,7 @@ repeatcase: return 1; } - if (g_numBraces < 0) + if (EDUKE32_PREDICT_FALSE(g_numBraces < 0)) { if (g_checkingSwitch) { @@ -5374,7 +5361,7 @@ repeatcase: j = *g_scriptPtr; C_SkipComments(); - if (j < 0 || j > MAXVOLUMES-1) + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXVOLUMES-1)) { initprintf("%s:%d: error: volume number exceeds maximum volume count.\n", g_szScriptFileName,g_lineNumber); @@ -5389,7 +5376,7 @@ repeatcase: { EpisodeNames[j][i] = *textptr; textptr++,i++; - if (i >= (signed)sizeof(EpisodeNames[j])-1) + if (EDUKE32_PREDICT_FALSE(i >= (signed)sizeof(EpisodeNames[j])-1)) { initprintf("%s:%d: warning: truncating volume name to %d characters.\n", g_szScriptFileName,g_lineNumber,(int32_t)sizeof(EpisodeNames[j])-1); @@ -5409,7 +5396,7 @@ repeatcase: j = *g_scriptPtr; C_SkipComments(); - if (j < 0 || j > NUMGAMEFUNCTIONS-1) + if (EDUKE32_PREDICT_FALSE((unsigned)j > NUMGAMEFUNCTIONS-1)) { initprintf("%s:%d: error: function number exceeds number of game functions.\n", g_szScriptFileName,g_lineNumber); @@ -5425,7 +5412,7 @@ repeatcase: gamefunctions[j][i] = *textptr; keydefaults[j*3][i] = *textptr; textptr++,i++; - if (*textptr != 0x0a && *textptr != 0x0d && ispecial(*textptr)) + if (EDUKE32_PREDICT_FALSE(*textptr != 0x0a && *textptr != 0x0d && ispecial(*textptr))) { initprintf("%s:%d: warning: invalid character in function name.\n", g_szScriptFileName,g_lineNumber); @@ -5433,7 +5420,7 @@ repeatcase: C_NextLine(); break; } - if (i >= MAXGAMEFUNCLEN-1) + if (EDUKE32_PREDICT_FALSE(i >= MAXGAMEFUNCLEN-1)) { initprintf("%s:%d: warning: truncating function name to %d characters.\n", g_szScriptFileName,g_lineNumber,MAXGAMEFUNCLEN); @@ -5461,7 +5448,7 @@ repeatcase: j = *g_scriptPtr; C_SkipComments(); - if (j < 0 || j >= MAXSKILLS) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSKILLS)) { initprintf("%s:%d: error: skill number exceeds maximum skill count %d.\n", g_szScriptFileName,g_lineNumber, MAXSKILLS); @@ -5476,7 +5463,7 @@ repeatcase: { SkillNames[j][i] = *textptr; textptr++,i++; - if (i >= (signed)sizeof(SkillNames[j])-1) + if (EDUKE32_PREDICT_FALSE(i >= (signed)sizeof(SkillNames[j])-1)) { initprintf("%s:%d: warning: truncating skill name to %d characters.\n", g_szScriptFileName,g_lineNumber,(int32_t)sizeof(SkillNames[j])-1); @@ -5508,7 +5495,7 @@ repeatcase: { gamename[i] = *textptr; textptr++,i++; - if (i >= (signed)sizeof(gamename)-1) + if (EDUKE32_PREDICT_FALSE(i >= (signed)sizeof(gamename)-1)) { initprintf("%s:%d: warning: truncating game name to %d characters.\n", g_szScriptFileName,g_lineNumber,(int32_t)sizeof(gamename)-1); @@ -5569,7 +5556,7 @@ repeatcase: C_SkipComments(); - if (j < 0 || j > MAXGAMETYPES-1) + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXGAMETYPES-1)) { initprintf("%s:%d: error: gametype number exceeds maximum gametype count.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; @@ -5584,7 +5571,7 @@ repeatcase: { GametypeNames[j][i] = *textptr; textptr++,i++; - if (i >= (signed)sizeof(GametypeNames[j])-1) + if (EDUKE32_PREDICT_FALSE(i >= (signed)sizeof(GametypeNames[j])-1)) { initprintf("%s:%d: warning: truncating gametype name to %d characters.\n", g_szScriptFileName,g_lineNumber,(int32_t)sizeof(GametypeNames[j])-1); @@ -5606,14 +5593,14 @@ repeatcase: k = *g_scriptPtr; C_SkipComments(); - if (j < 0 || j > MAXVOLUMES-1) + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXVOLUMES-1)) { initprintf("%s:%d: error: volume number exceeds maximum volume count.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; C_NextLine(); continue; } - if (k < 0 || k > MAXLEVELS-1) + if (EDUKE32_PREDICT_FALSE((unsigned)k > MAXLEVELS-1)) { initprintf("%s:%d: error: level number exceeds maximum number of levels per episode.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; @@ -5629,7 +5616,7 @@ repeatcase: { tempbuf[i+1] = *textptr; textptr++,i++; - if (i >= BMAX_PATH) + if (EDUKE32_PREDICT_FALSE(i >= BMAX_PATH)) { initprintf("%s:%d: error: level file name exceeds limit of %d characters.\n",g_szScriptFileName,g_lineNumber,BMAX_PATH); g_numCompilerErrors++; @@ -5675,7 +5662,7 @@ repeatcase: { tempbuf[i] = *textptr; textptr++,i++; - if (i >= 32) + if (EDUKE32_PREDICT_FALSE(i >= 32)) { initprintf("%s:%d: warning: truncating level name to %d characters.\n", g_szScriptFileName,g_lineNumber,32); @@ -5709,7 +5696,7 @@ repeatcase: k = *(g_scriptPtr-1); - if ((unsigned)k >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)k >= MAXQUOTES)) { initprintf("%s:%d: error: quote number exceeds limit of %d.\n",g_szScriptFileName,g_lineNumber,MAXQUOTES); g_numCompilerErrors++; @@ -5749,7 +5736,7 @@ repeatcase: else *(ScriptQuoteRedefinitions[g_numQuoteRedefinitions]+i) = *textptr; textptr++,i++; - if (i >= MAXQUOTELEN-1) + if (EDUKE32_PREDICT_FALSE(i >= MAXQUOTELEN-1)) { initprintf("%s:%d: warning: truncating quote text to %d characters.\n",g_szScriptFileName,g_lineNumber,MAXQUOTELEN-1); g_numCompilerWarnings++; @@ -5786,7 +5773,7 @@ repeatcase: C_GetNextValue(LABEL_DEFINE); k = *(g_scriptPtr-1); - if (k > 25) + if (EDUKE32_PREDICT_FALSE(k > 25)) { initprintf("%s:%d: error: cheat redefinition attempts to redefine nonexistent cheat.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; @@ -5801,7 +5788,7 @@ repeatcase: { CheatStrings[k][i] = *textptr; textptr++,i++; - if (i >= (signed)sizeof(CheatStrings[k])-1) + if (EDUKE32_PREDICT_FALSE(i >= (signed)sizeof(CheatStrings[k])-1)) { initprintf("%s:%d: warning: truncating cheat string to %d characters.\n", g_szScriptFileName,g_lineNumber,(signed)sizeof(CheatStrings[k])-1); @@ -5822,7 +5809,7 @@ repeatcase: j = hash_find(&h_labels,tempbuf); k = *(g_scriptPtr-1); - if ((unsigned)k >= MAXSOUNDS) + if (EDUKE32_PREDICT_FALSE((unsigned)k >= MAXSOUNDS)) { initprintf("%s:%d: error: exceeded sound limit of %d.\n",g_szScriptFileName,g_lineNumber,MAXSOUNDS); g_numCompilerErrors++; @@ -5840,7 +5827,7 @@ repeatcase: while (*textptr && *textptr != '\"') { g_sounds[k].filename[i++] = *textptr++; - if (i >= BMAX_PATH-1) + if (EDUKE32_PREDICT_FALSE(i >= BMAX_PATH-1)) { initprintf("%s:%d: error: sound filename exceeds limit of %d characters.\n",g_szScriptFileName,g_lineNumber,BMAX_PATH-1); g_numCompilerErrors++; @@ -5853,7 +5840,7 @@ repeatcase: else while (*textptr != ' ' && *textptr != '\t' && *textptr != '\r' && *textptr != '\n') { g_sounds[k].filename[i++] = *textptr++; - if (i >= BMAX_PATH-1) + if (EDUKE32_PREDICT_FALSE(i >= BMAX_PATH-1)) { initprintf("%s:%d: error: sound filename exceeds limit of %d characters.\n",g_szScriptFileName,g_lineNumber,BMAX_PATH-1); g_numCompilerErrors++; @@ -5890,24 +5877,24 @@ repeatcase: case CON_ENDEVENT: - if (g_parsingEventPtr == NULL) + if (EDUKE32_PREDICT_FALSE(g_parsingEventPtr == NULL)) { C_ReportError(-1); initprintf("%s:%d: error: found `endevent' without open `onevent'.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; } - if (g_numBraces > 0) + if (EDUKE32_PREDICT_FALSE(g_numBraces > 0)) { C_ReportError(ERROR_OPENBRACKET); g_numCompilerErrors++; } - if (g_numBraces < 0) + else if (EDUKE32_PREDICT_FALSE(g_numBraces < 0)) { C_ReportError(ERROR_CLOSEBRACKET); g_numCompilerErrors++; } // if event has already been declared then put a jump in instead - if (previous_event) + if (EDUKE32_PREDICT_FALSE((intptr_t)previous_event)) { g_scriptPtr--; *(g_scriptPtr++) = CON_JUMP; @@ -5922,13 +5909,13 @@ repeatcase: continue; case CON_ENDA: - if (g_parsingActorPtr == NULL) + if (EDUKE32_PREDICT_FALSE(g_parsingActorPtr == NULL)) { C_ReportError(-1); initprintf("%s:%d: error: found `enda' without open `actor'.\n",g_szScriptFileName,g_lineNumber); g_numCompilerErrors++; } - if (g_numBraces != 0) + if (EDUKE32_PREDICT_FALSE(g_numBraces != 0)) { C_ReportError(g_numBraces > 0 ? ERROR_OPENBRACKET : ERROR_CLOSEBRACKET); g_numCompilerErrors++; @@ -5941,7 +5928,7 @@ repeatcase: case CON_BREAK: if (g_checkingSwitch) { - if (otw == CON_BREAK) + if (EDUKE32_PREDICT_FALSE(otw == CON_BREAK)) { C_ReportError(-1); initprintf("%s:%d: warning: duplicate `break'.\n",g_szScriptFileName, g_lineNumber); @@ -5986,7 +5973,7 @@ repeatcase: case CON_NULLOP: if (tw == CON_NULLOP) { - if (C_GetKeyword() != CON_ELSE) + if (EDUKE32_PREDICT_FALSE(C_GetKeyword() != CON_ELSE)) { C_ReportError(-1); g_numCompilerWarnings++; diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 7d60d8ce4..82e179a1e 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -106,11 +106,11 @@ void VM_ScriptInfo(void) static void VM_KillIt(int32_t iActor, int32_t iPlayer) { - if ((unsigned) iActor >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned) iActor >= MAXSPRITES)) return; // if player was set to squish, first stop that... - if (iPlayer >= 0 && g_player[iPlayer].ps->actorsqu == iActor) + if (EDUKE32_PREDICT_FALSE(iPlayer >= 0 && g_player[iPlayer].ps->actorsqu == iActor)) g_player[iPlayer].ps->actorsqu = -1; A_DeleteSprite(iActor); @@ -165,11 +165,11 @@ int32_t VM_OnEvent_(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t l return iReturn; } -static inline int32_t VM_CheckSquished(void) +static int32_t VM_CheckSquished(void) { const sectortype *sc = §or[vm.g_sp->sectnum]; - if ((vm.g_sp->picnum == APLAYER && ud.noclip) || sc->lotag == ST_23_SWINGING_DOOR) + if (sc->lotag == ST_23_SWINGING_DOOR || EDUKE32_PREDICT_FALSE(vm.g_sp->picnum == APLAYER && ud.noclip)) return 0; { @@ -195,7 +195,7 @@ static inline int32_t VM_CheckSquished(void) if (A_CheckEnemySprite(vm.g_sp)) vm.g_sp->xvel = 0; - if (vm.g_sp->pal == 1) // frozen + if (EDUKE32_PREDICT_FALSE(vm.g_sp->pal == 1)) // frozen { actor[vm.g_i].picnum = SHOTSPARK1; actor[vm.g_i].extra = 1; @@ -328,51 +328,41 @@ void A_GetZLimits(int32_t iActor) { spritetype *s = &sprite[iActor]; -// if (s->statnum == STAT_PLAYER || s->statnum == STAT_STANDABLE || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_ACTOR || s->statnum == STAT_PROJECTILE) + int32_t hz,lz,zr = 127; + int32_t cstat = s->cstat; + + s->cstat = 0; + + if (s->statnum == STAT_PROJECTILE) + zr = 4; + + s->z -= ZOFFSET; + getzrange((vec3_t *)s,s->sectnum,&actor[iActor].ceilingz,&hz,&actor[iActor].floorz,&lz,zr,CLIPMASK0); + s->z += ZOFFSET; + + s->cstat = cstat; + + actor[iActor].flags &= ~SFLAG_NOFLOORSHADOW; + + if ((lz&49152) == 49152 && (sprite[lz&(MAXSPRITES-1)].cstat&48) == 0) { - int32_t hz,lz,zr = 127; - int32_t cstat = s->cstat; + const spritetype *hitspr = &sprite[lz&(MAXSPRITES-1)]; - s->cstat = 0; + lz &= (MAXSPRITES-1); - if (s->statnum == STAT_PROJECTILE) - zr = 4; - - s->z -= ZOFFSET; - getzrange((vec3_t *)s,s->sectnum,&actor[iActor].ceilingz,&hz,&actor[iActor].floorz,&lz,zr,CLIPMASK0); - s->z += ZOFFSET; - - s->cstat = cstat; - - actor[iActor].flags &= ~SFLAG_NOFLOORSHADOW; - - if ((lz&49152) == 49152 && (sprite[lz&(MAXSPRITES-1)].cstat&48) == 0) + if ((A_CheckEnemySprite(hitspr) && hitspr->pal != 1 && s->statnum != STAT_PROJECTILE) + || (hitspr->picnum == APLAYER && A_CheckEnemySprite(s))) { - const spritetype *hitspr = &sprite[lz&(MAXSPRITES-1)]; - - lz &= (MAXSPRITES-1); - - if ((A_CheckEnemySprite(hitspr) && hitspr->pal != 1 && s->statnum != STAT_PROJECTILE) - || (hitspr->picnum == APLAYER && A_CheckEnemySprite(s))) - { - actor[iActor].flags |= SFLAG_NOFLOORSHADOW; // No shadows on actors - s->xvel = -256; - A_SetSprite(iActor,CLIPMASK0); - } - else if (s->statnum == STAT_PROJECTILE && hitspr->picnum == APLAYER && s->owner==lz) - { - actor[iActor].ceilingz = sector[s->sectnum].ceilingz; - actor[iActor].floorz = sector[s->sectnum].floorz; - } + actor[iActor].flags |= SFLAG_NOFLOORSHADOW; // No shadows on actors + s->xvel = -256; + A_SetSprite(iActor,CLIPMASK0); } - } - /* - else + else if (s->statnum == STAT_PROJECTILE && hitspr->picnum == APLAYER && s->owner==lz) { actor[iActor].ceilingz = sector[s->sectnum].ceilingz; actor[iActor].floorz = sector[s->sectnum].floorz; } - */ + } } void A_Fall(int32_t iActor) @@ -382,13 +372,10 @@ void A_Fall(int32_t iActor) #ifdef YAX_ENABLE int16_t fbunch; #endif - if (G_CheckForSpaceFloor(s->sectnum)) + if (EDUKE32_PREDICT_FALSE(G_CheckForSpaceFloor(s->sectnum))) c = 0; - else - { - if (G_CheckForSpaceCeiling(s->sectnum) || sector[s->sectnum].lotag == ST_2_UNDERWATER) - c = g_spriteGravity/6; - } + else if (sector[s->sectnum].lotag == ST_2_UNDERWATER || EDUKE32_PREDICT_FALSE(G_CheckForSpaceCeiling(s->sectnum))) + c = g_spriteGravity/6; if (s->statnum == STAT_ACTOR || s->statnum == STAT_PLAYER || s->statnum == STAT_ZOMBIEACTOR || s->statnum == STAT_STANDABLE) { @@ -406,10 +393,7 @@ void A_Fall(int32_t iActor) } #ifdef YAX_ENABLE - if (sector[s->sectnum].floorstat&512) - fbunch = -1; - else - fbunch = yax_getbunch(s->sectnum, YAX_FLOOR); + fbunch = (sector[s->sectnum].floorstat&512) ? -1 : yax_getbunch(s->sectnum, YAX_FLOOR); #endif if (s->z < actor[iActor].floorz-ZOFFSET @@ -459,7 +443,7 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t movflags) #if !defined LUNATIC const intptr_t *moveptr; - if ((unsigned)AC_MOVE_ID(vm.g_t) >= (unsigned)g_scriptSize-1) + if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.g_t) >= (unsigned)g_scriptSize-1)) { AC_MOVE_ID(vm.g_t) = 0; @@ -533,7 +517,7 @@ GAMEEXEC_STATIC void VM_AlterAng(int32_t movflags) } } -static void VM_AddAngle(int32_t shr, int32_t goalang) +static inline void VM_AddAngle(int32_t shr, int32_t goalang) { int32_t angdif = G_GetAngleDelta(vm.g_sp->ang,goalang)>>shr; @@ -643,7 +627,7 @@ GAMEEXEC_STATIC void VM_Move(void) dead: #if !defined LUNATIC - if ((unsigned)AC_MOVE_ID(vm.g_t) >= (unsigned)g_scriptSize-1) + if (EDUKE32_PREDICT_FALSE((unsigned)AC_MOVE_ID(vm.g_t) >= (unsigned)g_scriptSize-1)) { AC_MOVE_ID(vm.g_t) = 0; OSD_Printf_nowarn(OSD_ERROR "clearing bad moveptr for actor %d (%d)\n", vm.g_i, TrackerCast(vm.g_sp->picnum)); @@ -869,9 +853,9 @@ static void VM_Fall(int32_t g_i, spritetype *g_sp) g_sp->xoffset = g_sp->yoffset = 0; - if (G_CheckForSpaceCeiling(g_sp->sectnum) || sector[g_sp->sectnum].lotag == ST_2_UNDERWATER) + if (sector[g_sp->sectnum].lotag == ST_2_UNDERWATER || EDUKE32_PREDICT_FALSE(G_CheckForSpaceCeiling(g_sp->sectnum))) grav = g_spriteGravity/6; - else if (G_CheckForSpaceFloor(g_sp->sectnum)) + else if (EDUKE32_PREDICT_FALSE(G_CheckForSpaceFloor(g_sp->sectnum))) grav = 0; if (!actor[g_i].cgg-- || (sector[g_sp->sectnum].floorstat&2)) @@ -1166,7 +1150,7 @@ skip_check: insptr++; { int32_t q = *insptr++, i = *insptr++; - if ((ScriptQuotes[q] == NULL || ScriptQuoteRedefinitions[i] == NULL)) + if (EDUKE32_PREDICT_FALSE((ScriptQuotes[q] == NULL || ScriptQuoteRedefinitions[i] == NULL))) { CON_ERRPRINTF("%d %d null quote\n", q,i); break; @@ -1447,7 +1431,7 @@ skip_check: case CON_MIKESND: insptr++; - if (((unsigned)vm.g_sp->yvel >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE(((unsigned)vm.g_sp->yvel >= MAXSOUNDS))) { CON_ERRPRINTF("Invalid sound %d\n", TrackerCast(vm.g_sp->yvel)); continue; @@ -1498,7 +1482,7 @@ skip_check: continue; case CON_SOUNDONCE: - if (((unsigned)*(++insptr) >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)*(++insptr) >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr++); continue; @@ -1512,7 +1496,7 @@ skip_check: { int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); - if (((unsigned)j >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", j); insptr++; @@ -1524,7 +1508,7 @@ skip_check: continue; case CON_IFSOUND: - if (((unsigned)*(++insptr) >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)*(++insptr) >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr); insptr++; @@ -1535,7 +1519,7 @@ skip_check: continue; case CON_STOPSOUND: - if (((unsigned)*(++insptr) >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)*(++insptr) >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr); insptr++; @@ -1551,7 +1535,7 @@ skip_check: { int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++); - if ((j<0 || j>=MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", j); continue; @@ -1568,7 +1552,7 @@ skip_check: { int32_t i = Gv_GetVarX(*insptr++), j = Gv_GetVarX(*insptr++), pitchoffset = Gv_GetVarX(*insptr++); - if ((j<0 || j>=MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", j); continue; @@ -1580,7 +1564,7 @@ skip_check: } case CON_GLOBALSOUND: - if (((unsigned)*(++insptr) >= MAXSOUNDS)) + if (EDUKE32_PREDICT_FALSE((unsigned)*(++insptr) >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr); insptr++; @@ -1596,7 +1580,7 @@ skip_check: continue; case CON_SOUND: - if ((unsigned)*(++insptr) >= MAXSOUNDS) + if (EDUKE32_PREDICT_FALSE((unsigned)*(++insptr) >= MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", (int32_t)*insptr); insptr++; @@ -1632,7 +1616,7 @@ skip_check: int32_t weap=*insptr++, amount=*insptr++; DukePlayer_t *ps = g_player[vm.g_p].ps; - if ((unsigned)weap >= MAX_WEAPONS) + if (EDUKE32_PREDICT_FALSE((unsigned)weap >= MAX_WEAPONS)) { CON_ERRPRINTF("Invalid weapon ID %d\n", weap); break; @@ -1815,22 +1799,38 @@ skip_check: switch (tw) { case CON_ACTIVATEBYSECTOR: - if ((unsigned)var1 >= (unsigned)numsectors) {CON_ERRPRINTF("Invalid sector %d\n", var1); break;} + if (EDUKE32_PREDICT_FALSE((unsigned)var1 >= (unsigned)numsectors)) + { + CON_ERRPRINTF("Invalid sector %d\n", var1); + break; + } G_ActivateBySector(var1, var2); break; case CON_OPERATESECTORS: - if ((unsigned)var1 >= (unsigned)numsectors) {CON_ERRPRINTF("Invalid sector %d\n", var1); break;} + if (EDUKE32_PREDICT_FALSE((unsigned)var1 >= (unsigned)numsectors)) + { + CON_ERRPRINTF("Invalid sector %d\n", var1); + break; + } G_OperateSectors(var1, var2); break; case CON_OPERATEACTIVATORS: - if ((unsigned)var2>=(unsigned)playerswhenstarted) {CON_ERRPRINTF("Invalid player %d\n", var2); break;} + if (EDUKE32_PREDICT_FALSE((unsigned)var2>=(unsigned)playerswhenstarted)) + { + CON_ERRPRINTF("Invalid player %d\n", var2); + break; + } G_OperateActivators(var1, var2); break; case CON_SETASPECT: setaspect(var1, var2); break; case CON_SSP: - if ((unsigned)var1 >= MAXSPRITES) { CON_ERRPRINTF("Invalid sprite %d\n", var1); break;} + if (EDUKE32_PREDICT_FALSE((unsigned)var1 >= MAXSPRITES)) + { + CON_ERRPRINTF("Invalid sprite %d\n", var1); + break; + } A_SetSprite(var1, var2); break; } @@ -1842,7 +1842,7 @@ skip_check: { int32_t lVar1 = Gv_GetVarX(*insptr++), lVar2 = Gv_GetVarX(*insptr++), res; - if ((unsigned)lVar1 >= MAXSPRITES || (unsigned)lVar2 >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)lVar1 >= MAXSPRITES || (unsigned)lVar2 >= MAXSPRITES)) { CON_ERRPRINTF("Invalid sprite %d\n", (unsigned)lVar1 >= MAXSPRITES ? lVar1 : lVar2); res=0; @@ -1879,7 +1879,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((ScriptQuotes[j] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[j] == NULL)) { CON_ERRPRINTF("null quote %d\n", j); Gv_SetVarX(i,-1); @@ -1910,11 +1910,11 @@ skip_check: orientation &= (ROTATESPRITE_MAX-1); - if (tilenum < 0 || tilenum+255 >= MAXTILES) + if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); - else if ((unsigned)q >= MAXQUOTES) + else if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES)) CON_ERRPRINTF("invalid quote ID %d\n", q); - else if ((ScriptQuotes[q] == NULL)) + else if (EDUKE32_PREDICT_FALSE((ScriptQuotes[q] == NULL))) CON_ERRPRINTF("null quote %d\n", q); else dim = G_ScreenTextSize(tilenum,x,y,z,blockangle,ScriptQuotes[q],2|orientation,xspace,yline,xbetween,ybetween,f,x1,y1,x2,y2); @@ -1929,7 +1929,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j > MAXSTATUS) + if (EDUKE32_PREDICT_FALSE((unsigned)j > MAXSTATUS)) { CON_ERRPRINTF("invalid status list %d\n", j); continue; @@ -1943,7 +1943,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; @@ -1957,7 +1957,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; @@ -1971,7 +1971,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= (unsigned)numsectors)) { CON_ERRPRINTF("invalid sector %d\n", j); continue; @@ -1985,7 +1985,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; @@ -1999,7 +1999,7 @@ skip_check: { int32_t i=*insptr++; int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", j); continue; @@ -2015,17 +2015,17 @@ skip_check: f = Gv_GetVarX(*insptr++); int32_t j = Gv_GetVarX(*insptr++); - if ((unsigned)i >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", i); continue; } - else if ((ScriptQuotes[i] == NULL)) + else if (EDUKE32_PREDICT_FALSE((ScriptQuotes[i] == NULL))) { CON_ERRPRINTF("null quote %d\n", i); continue; } - else if ((unsigned)f >= NUMGAMEFUNCTIONS) + else if (EDUKE32_PREDICT_FALSE((unsigned)f >= NUMGAMEFUNCTIONS)) { CON_ERRPRINTF("invalid function %d\n", f); continue; @@ -2057,34 +2057,34 @@ skip_check: int32_t st = Gv_GetVarX(*insptr++); int32_t ln = Gv_GetVarX(*insptr++); - if ((unsigned)q1>=MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)q1>=MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", q1); continue; } - if ((ScriptQuotes[q1] == NULL)) + if (EDUKE32_PREDICT_FALSE((ScriptQuotes[q1] == NULL))) { CON_ERRPRINTF("null quote %d\n", q1); continue; } - if ((unsigned)q2>=MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)q2>=MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", q2); continue; } - if ((ScriptQuotes[q2] == NULL)) + if (EDUKE32_PREDICT_FALSE((ScriptQuotes[q2] == NULL))) { CON_ERRPRINTF("null quote %d\n", q2); continue; } - if ((unsigned)st >= MAXQUOTELEN) + if (EDUKE32_PREDICT_FALSE((unsigned)st >= MAXQUOTELEN)) { CON_ERRPRINTF("invalid start position %d\n", st); continue; } - if (ln < 0) + if (EDUKE32_PREDICT_FALSE(ln < 0)) { CON_ERRPRINTF("invalid length %d\n", ln); continue; @@ -2124,7 +2124,7 @@ skip_check: switch (tw) { case CON_GETPNAME: - if ((ScriptQuotes[i] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL)) { CON_ERRPRINTF("null quote %d\n", i); break; @@ -2134,7 +2134,7 @@ skip_check: else Bsprintf(ScriptQuotes[i],"%d",j); break; case CON_QGETSYSSTR: - if ((ScriptQuotes[i] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL)) { CON_ERRPRINTF("null quote %d %d\n", i,j); break; @@ -2147,7 +2147,7 @@ skip_check: int32_t idx = ud.volume_number*MAXLEVELS + ud.level_number; const char *src; - if ((unsigned)idx >= ARRAY_SIZE(MapInfo)) + if (EDUKE32_PREDICT_FALSE((unsigned)idx >= ARRAY_SIZE(MapInfo))) { CON_ERRPRINTF("out of bounds map number (vol=%d, lev=%d)\n", ud.volume_number, ud.level_number); @@ -2155,7 +2155,7 @@ skip_check: } src = j==STR_MAPNAME ? MapInfo[idx].name : MapInfo[idx].filename; - if (src == NULL) + if (EDUKE32_PREDICT_FALSE(src == NULL)) { CON_ERRPRINTF("attempted access to %s of non-existent map (vol=%d, lev=%d)", j==STR_MAPNAME ? "name" : "file name", @@ -2167,7 +2167,7 @@ skip_check: break; } case STR_PLAYERNAME: - if ((unsigned)vm.g_p >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= (unsigned)playerswhenstarted)) { CON_ERRPRINTF("Invalid player ID %d\n", vm.g_p); break; @@ -2182,7 +2182,7 @@ skip_check: Bstrcpy(ScriptQuotes[i],GametypeNames[ud.coop]); break; case STR_VOLUMENAME: - if ((unsigned)ud.volume_number >= MAXVOLUMES) + if (EDUKE32_PREDICT_FALSE((unsigned)ud.volume_number >= MAXVOLUMES)) { CON_ERRPRINTF("invalid volume (%d)\n", ud.volume_number); break; @@ -2194,25 +2194,25 @@ skip_check: } break; case CON_QSTRCAT: - if ((ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; Bstrncat(ScriptQuotes[i],ScriptQuotes[j],(MAXQUOTELEN-1)-Bstrlen(ScriptQuotes[i])); break; case CON_QSTRNCAT: - if ((ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; Bstrncat(ScriptQuotes[i],ScriptQuotes[j],Gv_GetVarX(*insptr++)); break; case CON_QSTRCPY: - if ((ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL || ScriptQuotes[j] == NULL)) goto nullquote; if (i != j) Bstrcpy(ScriptQuotes[i],ScriptQuotes[j]); break; case CON_CHANGESPRITESECT: - if ((unsigned)i >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXSPRITES)) { CON_ERRPRINTF("Invalid sprite %d\n", i); break; } - if ((unsigned)j >= (unsigned)numsectors) + else if (EDUKE32_PREDICT_FALSE((unsigned)j >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", j); break; @@ -2233,12 +2233,12 @@ nullquote: int32_t i = Gv_GetVarX(*insptr++); int32_t j = Gv_GetVarX(*insptr++); - if ((unsigned)i >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXSPRITES)) { CON_ERRPRINTF("Invalid sprite: %d\n", i); continue; } - if ((unsigned)j >= MAXSTATUS) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXSTATUS)) { CON_ERRPRINTF("Invalid statnum: %d\n", j); continue; @@ -2284,13 +2284,13 @@ nullquote: // from 'level' cheat in game.c (about line 6250) int32_t volnume=Gv_GetVarX(*insptr++), levnume=Gv_GetVarX(*insptr++); - if ((volnume > MAXVOLUMES-1 || volnume < 0)) + if (EDUKE32_PREDICT_FALSE((volnume > MAXVOLUMES-1 || volnume < 0))) { CON_ERRPRINTF("invalid volume (%d)\n", volnume); continue; } - if ((levnume > MAXLEVELS-1 || levnume < 0)) + if (EDUKE32_PREDICT_FALSE((levnume > MAXLEVELS-1 || levnume < 0))) { CON_ERRPRINTF("invalid level (%d)\n", levnume); continue; @@ -2426,7 +2426,7 @@ nullquote: { int32_t wallnum = Gv_GetVarX(*insptr++), newx = Gv_GetVarX(*insptr++), newy = Gv_GetVarX(*insptr++); - if ((wallnum<0 || wallnum>=numwalls)) + if (EDUKE32_PREDICT_FALSE((wallnum<0 || wallnum>=numwalls))) { CON_ERRPRINTF("Invalid wall %d\n", wallnum); continue; @@ -2440,7 +2440,7 @@ nullquote: { int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); - if ((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite\n"); continue; @@ -2455,7 +2455,7 @@ nullquote: { int32_t distvar = *insptr++, xvar = Gv_GetVarX(*insptr++), yvar = Gv_GetVarX(*insptr++); - if ((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)xvar >= MAXSPRITES || (unsigned)yvar >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite\n"); continue; @@ -2513,7 +2513,7 @@ nullquote: { int32_t lIn=Gv_GetVarX(*insptr++); int32_t j; - if ((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); continue; @@ -2543,7 +2543,7 @@ nullquote: { int32_t j; - if ((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); insptr++; @@ -2579,7 +2579,7 @@ nullquote: const int32_t zvel = (tw == CON_ESHOOT) ? SHOOT_HARDCODED_ZVEL : (int16_t)Gv_GetVarX(*insptr++); - if ((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); insptr++; @@ -2599,7 +2599,7 @@ nullquote: { int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); continue; @@ -2618,7 +2618,7 @@ nullquote: const int32_t zvel = (int16_t)Gv_GetVarX(*insptr++); int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", TrackerCast(vm.g_sp->sectnum)); continue; @@ -2644,7 +2644,7 @@ nullquote: { int32_t j=Gv_GetVarX(*insptr++); - if (j<0 || j>=MAXSOUNDS) + if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAXSOUNDS)) { CON_ERRPRINTF("Invalid sound %d\n", j); continue; @@ -2677,10 +2677,10 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - if (j >= 0 && j < MAXUNIQHUDID-1) - guniqhudid = j; - else + if (EDUKE32_PREDICT_FALSE((unsigned) j >= MAXUNIQHUDID-1)) CON_ERRPRINTF("Invalid ID %d\n", j); + else guniqhudid = j; + continue; } @@ -2723,13 +2723,13 @@ nullquote: int32_t x2=Gv_GetVarX(*insptr++); int32_t y2=Gv_GetVarX(*insptr++); - if (x1 < 0 || y1 < 0 || x2 >= 320 || y2 >= 200) + if (EDUKE32_PREDICT_FALSE(x1 < 0 || y1 < 0 || x2 >= 320 || y2 >= 200)) { CON_ERRPRINTF("incorrect coordinates\n"); continue; } - if ((unsigned)sect >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sect >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sect); continue; @@ -2760,13 +2760,13 @@ nullquote: y<<=16; } - if ((unsigned)tilenum >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)tilenum >= MAXTILES)) { CON_ERRPRINTF("invalid tilenum %d\n", tilenum); continue; } - if (x < -(320<<16) || x >= (640<<16) || y < -(200<<16) || y >= (400<<16)) + if (EDUKE32_PREDICT_FALSE(x < -(320<<16) || x >= (640<<16) || y < -(200<<16) || y >= (400<<16))) { CON_ERRPRINTF("invalid coordinates: %d, %d\n", x, y); continue; @@ -2792,19 +2792,19 @@ nullquote: int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); int32_t z = (tw == CON_GAMETEXTZ) ? Gv_GetVarX(*insptr++) : 65536; - if (tilenum < 0 || tilenum+255 >= MAXTILES) + if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) { CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); continue; } - if ((unsigned)q >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", q); continue; } - if ((ScriptQuotes[q] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[q] == NULL)) { CON_ERRPRINTF("null quote %d\n", q); continue; @@ -2829,7 +2829,7 @@ nullquote: int32_t z = (tw == CON_DIGITALNUMBERZ) ? Gv_GetVarX(*insptr++) : 65536; // NOTE: '-' not taken into account, but we have rotatesprite() bound check now anyway - if (tilenum < 0 || tilenum+9 >= MAXTILES) + if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+9 >= MAXTILES)) { CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); continue; @@ -2845,13 +2845,13 @@ nullquote: int32_t x=Gv_GetVarX(*insptr++), y=Gv_GetVarX(*insptr++), q=Gv_GetVarX(*insptr++); int32_t shade=Gv_GetVarX(*insptr++), pal=Gv_GetVarX(*insptr++); - if ((unsigned)q >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", q); continue; } - if ((ScriptQuotes[q] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[q] == NULL)) { CON_ERRPRINTF("null quote %d\n", q); continue; @@ -2876,19 +2876,19 @@ nullquote: int32_t x1=Gv_GetVarX(*insptr++), y1=Gv_GetVarX(*insptr++); int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++); - if (tilenum < 0 || tilenum+255 >= MAXTILES) + if (EDUKE32_PREDICT_FALSE(tilenum < 0 || tilenum+255 >= MAXTILES)) { CON_ERRPRINTF("invalid base tilenum %d\n", tilenum); continue; } - if ((unsigned)q >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", q); continue; } - if ((ScriptQuotes[q] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[q] == NULL)) { CON_ERRPRINTF("null quote %d\n", q); continue; @@ -2921,7 +2921,7 @@ nullquote: int32_t ceilz, ceilhit, florz, florhit; - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); continue; @@ -2941,7 +2941,7 @@ nullquote: { int32_t sectnum = Gv_GetVarX(*insptr++); - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); continue; @@ -3012,7 +3012,7 @@ nullquote: vect.z = z; sectnum = Gv_GetVarX(sectnumvar); - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); Gv_SetVarX(retvar, 0); @@ -3044,7 +3044,7 @@ nullquote: int32_t hitsectvar=*insptr++, hitwallvar=*insptr++, hitspritevar=*insptr++; int32_t hitxvar=*insptr++, hityvar=*insptr++, hitzvar=*insptr++, cliptype=Gv_GetVarX(*insptr++); - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); continue; @@ -3068,7 +3068,7 @@ nullquote: int32_t x2=Gv_GetVarX(*insptr++), y2=Gv_GetVarX(*insptr++), z2=Gv_GetVarX(*insptr++); int32_t sect2=Gv_GetVarX(*insptr++), rvar=*insptr++; - if ((unsigned)sect1 >= (unsigned)numsectors || (unsigned)sect2 >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sect1 >= (unsigned)numsectors || (unsigned)sect2 >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector\n"); Gv_SetVarX(rvar, 0); @@ -3111,7 +3111,7 @@ nullquote: int16_t neartagsector, neartagwall, neartagsprite; int32_t neartaghitdist; - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); continue; @@ -3152,7 +3152,7 @@ nullquote: if (tw == CON_SETSPRITE) { - if ((unsigned)spritenum >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)spritenum >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", spritenum); continue; @@ -3164,7 +3164,7 @@ nullquote: { int32_t cliptype = Gv_GetVarX(*insptr++); - if ((unsigned)spritenum >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)spritenum >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", spritenum); insptr++; @@ -3180,7 +3180,7 @@ nullquote: insptr++; { int32_t sectnum = Gv_GetVarX(*insptr++), x = Gv_GetVarX(*insptr++), y = Gv_GetVarX(*insptr++); - if ((unsigned)sectnum >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) { CON_ERRPRINTF("Invalid sector %d\n", sectnum); insptr++; @@ -3546,7 +3546,7 @@ nullquote: insptr++; { int32_t j = Gv_GetVarX(*insptr++); - if ((unsigned)j >= MAXVOLUMES*MAXLEVELS) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= MAXVOLUMES*MAXLEVELS)) { CON_ERRPRINTF("Invalid map number: %d\n", j); continue; @@ -3651,7 +3651,7 @@ nullquote: case CON_PALFROM: insptr++; - if ((unsigned)vm.g_p >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= (unsigned)playerswhenstarted)) { CON_ERRPRINTF("invalid player ID %d\n", vm.g_p); insptr += 4; @@ -3677,7 +3677,7 @@ nullquote: insptr++; { int32_t dq = Gv_GetVarX(*insptr++), sq = Gv_GetVarX(*insptr++); - if ((ScriptQuotes[sq] == NULL || ScriptQuotes[dq] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[sq] == NULL || ScriptQuotes[dq] == NULL)) { CON_ERRPRINTF("null quote %d\n", ScriptQuotes[sq] ? dq : sq); @@ -3800,7 +3800,7 @@ finish_qsprintf: insptr++; index=Gv_GetVarX(*insptr++); - if (index>=0 && index < aGameArrays[lVarID].size) + if (EDUKE32_PREDICT_TRUE((unsigned)index < (unsigned)aGameArrays[lVarID].size)) { OSD_Printf(OSDTEXT_GREEN "%s: L=%d %s[%d] =%d\n", keyw[g_tw], g_errorLineNum, aGameArrays[lVarID].szLabel, index, @@ -3821,7 +3821,7 @@ finish_qsprintf: intptr_t *oinsptr = insptr++; int32_t index = Gv_GetVarX(*insptr++); insptr = oinsptr; - if ((unsigned)index >= MAXSPRITES-1) + if (EDUKE32_PREDICT_FALSE((unsigned)index >= MAXSPRITES-1)) { CON_ERRPRINTF("invalid array index\n"); Gv_GetVarX(*insptr++); @@ -3831,7 +3831,7 @@ finish_qsprintf: continue; } } - else if (*insptr&(MAXGAMEVARS<<1)) + else if (EDUKE32_PREDICT_TRUE(*insptr&(MAXGAMEVARS<<1))) { m = -m; lVarID ^= (MAXGAMEVARS<<1); @@ -4217,7 +4217,7 @@ finish_qsprintf: int32_t lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++; int32_t lVar2=*insptr++; - if ((unsigned)lSprite >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)lSprite >= MAXSPRITES)) { CON_ERRPRINTF("invalid sprite ID %d\n", lSprite); if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++; @@ -4247,7 +4247,7 @@ finish_qsprintf: { int32_t lVar1=*insptr++, lVar2=*insptr++; - if ((unsigned)iPlayer >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer >= (unsigned)playerswhenstarted)) { CON_ERRPRINTF("invalid player ID %d\n", iPlayer); if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++; @@ -4343,7 +4343,7 @@ finish_qsprintf: insptr++; - if ((unsigned)j >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= (unsigned)playerswhenstarted)) { CON_ERRPRINTF("Invalid player ID %d\n", j); continue; @@ -4396,13 +4396,13 @@ finish_qsprintf: int32_t index = Gv_GetVarX(*insptr++); int32_t value = Gv_GetVarX(*insptr++); - if (j<0 || j >= g_gameArrayCount || index >= aGameArrays[j].size || index < 0) + if (EDUKE32_PREDICT_FALSE((unsigned)j >= (unsigned)g_gameArrayCount || (unsigned)index >= (unsigned)aGameArrays[j].size)) { OSD_Printf_nowarn(OSD_ERROR "Gv_SetVar(): tried to set invalid array ID (%d) or index out of bounds from sprite %d (%d), player %d\n", j,vm.g_i,TrackerCast(sprite[vm.g_i].picnum),vm.g_p); continue; } - if (aGameArrays[j].dwFlags & GAMEARRAY_READONLY) + if (EDUKE32_PREDICT_FALSE(aGameArrays[j].dwFlags & GAMEARRAY_READONLY)) { OSD_Printf("Tried to set on read-only array `%s'", aGameArrays[j].szLabel); continue; @@ -4418,7 +4418,7 @@ finish_qsprintf: { int q = *insptr++; - if (ScriptQuotes[q] == NULL) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[q] == NULL)) { CON_ERRPRINTF("null quote %d\n", q); continue; @@ -4452,14 +4452,15 @@ finish_qsprintf: FILE *fil; char temp[BMAX_PATH]; - if (G_ModDirSnprintf(temp, sizeof(temp), "%s", ScriptQuotes[q])) + if (EDUKE32_PREDICT_FALSE(G_ModDirSnprintf(temp, sizeof(temp), "%s", ScriptQuotes[q]))) { CON_ERRPRINTF("file name too long\n"); continue; } fil = fopen(temp,"wb"); - if (fil == NULL) + + if (EDUKE32_PREDICT_FALSE(fil == NULL)) { CON_ERRPRINTF("couldn't open file"); continue; @@ -4506,29 +4507,29 @@ finish_qsprintf: int32_t didx = Gv_GetVarX(*insptr++); int32_t numelts = Gv_GetVarX(*insptr++); - if (si<0 || si>=g_gameArrayCount) + if (EDUKE32_PREDICT_FALSE((unsigned)si>=(unsigned)g_gameArrayCount)) { CON_ERRPRINTF("Invalid array %d!", si); dsiz = 1; } - if (di<0 || di>=g_gameArrayCount) + if (EDUKE32_PREDICT_FALSE((unsigned)di>=(unsigned)g_gameArrayCount)) { CON_ERRPRINTF("Invalid array %d!", di); dsiz = 1; } - if (aGameArrays[di].dwFlags & GAMEARRAY_READONLY) + if (EDUKE32_PREDICT_FALSE(aGameArrays[di].dwFlags & GAMEARRAY_READONLY)) { CON_ERRPRINTF("Array %d is read-only!", di); dsiz = 1; } - if (dsiz) continue; // dirty replacement for VMFLAG_ERROR + if (EDUKE32_PREDICT_FALSE(dsiz)) continue; // dirty replacement for VMFLAG_ERROR ssiz = (aGameArrays[si].dwFlags&GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[si].size) : aGameArrays[si].size; dsiz = (aGameArrays[di].dwFlags&GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[si].size) : aGameArrays[di].size; - if (sidx > ssiz || didx > dsiz) continue; + if (EDUKE32_PREDICT_FALSE(sidx > ssiz || didx > dsiz)) continue; if ((sidx+numelts) > ssiz) numelts = ssiz-sidx; if ((didx+numelts) > dsiz) numelts = dsiz-didx; @@ -4591,7 +4592,7 @@ finish_qsprintf: case CON_DIVVAR: insptr++; - if (*(insptr+1) == 0) + if (EDUKE32_PREDICT_FALSE(*(insptr+1) == 0)) { CON_ERRPRINTF("divide by zero!\n"); insptr += 2; @@ -4603,7 +4604,7 @@ finish_qsprintf: case CON_MODVAR: insptr++; - if (*(insptr+1) == 0) + if (EDUKE32_PREDICT_FALSE(*(insptr+1) == 0)) { CON_ERRPRINTF("mod by zero!\n"); insptr += 2; @@ -4666,7 +4667,7 @@ finish_qsprintf: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j>=MAX_WEAPONS) + if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAX_WEAPONS)) { CON_ERRPRINTF("Invalid weapon ID %d\n", j); insptr++; @@ -4680,7 +4681,7 @@ finish_qsprintf: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - if ((unsigned)j>=MAX_WEAPONS) + if (EDUKE32_PREDICT_FALSE((unsigned)j>=MAX_WEAPONS)) { CON_ERRPRINTF("Invalid weapon ID %d\n", j); insptr++; @@ -4705,7 +4706,7 @@ finish_qsprintf: int32_t j=*insptr++; int32_t l2=Gv_GetVarX(*insptr++); - if (!l2) + if (EDUKE32_PREDICT_FALSE(!l2)) { CON_ERRPRINTF("divide by zero!\n"); continue; @@ -4721,7 +4722,7 @@ finish_qsprintf: int32_t j=*insptr++; int32_t l2=Gv_GetVarX(*insptr++); - if (!l2) + if (EDUKE32_PREDICT_FALSE(!l2)) { CON_ERRPRINTF("mod by zero!\n"); continue; @@ -4852,7 +4853,7 @@ finish_qsprintf: int32_t level = (tw == CON_STARTTRACK) ? *(insptr++) : Gv_GetVarX(*(insptr++)); - if (G_StartTrack(level)) + if (EDUKE32_PREDICT_FALSE(G_StartTrack(level))) CON_ERRPRINTF("invalid level %d or null music for volume %d level %d\n", level, ud.volume_number, level); } @@ -4862,7 +4863,7 @@ finish_qsprintf: insptr++; { int32_t j=Gv_GetVarX(*(insptr++)); - if (numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME)) + if (EDUKE32_PREDICT_FALSE(numplayers != 1 || !(g_player[myconnectindex].ps->gm & MODE_GAME))) { CON_ERRPRINTF("not in a single-player game.\n"); continue; @@ -5172,21 +5173,21 @@ finish_qsprintf: case CON_QUOTE: insptr++; - if ((unsigned)(*insptr) >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)(*insptr) >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", (int32_t)(*insptr)); insptr++; continue; } - if ((ScriptQuotes[*insptr] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[*insptr] == NULL)) { CON_ERRPRINTF("null quote %d\n", (int32_t)*insptr); insptr++; continue; } - if ((unsigned)vm.g_p >= MAXPLAYERS) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p >= MAXPLAYERS)) { CON_ERRPRINTF("bad player for quote %d: (%d)\n", (int32_t)*insptr,vm.g_p); insptr++; @@ -5201,14 +5202,14 @@ finish_qsprintf: { int32_t i=Gv_GetVarX(*insptr++); - if ((unsigned)i >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", i); insptr++; continue; } - if ((ScriptQuotes[i] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL)) { CON_ERRPRINTF("null quote %d\n", i); continue; @@ -5222,14 +5223,14 @@ finish_qsprintf: { int32_t i=Gv_GetVarX(*insptr++); - if ((unsigned)i >= MAXQUOTES) + if (EDUKE32_PREDICT_FALSE((unsigned)i >= MAXQUOTES)) { CON_ERRPRINTF("invalid quote ID %d\n", i); insptr++; continue; } - if ((ScriptQuotes[i] == NULL)) + if (EDUKE32_PREDICT_FALSE(ScriptQuotes[i] == NULL)) { CON_ERRPRINTF("null quote %d\n", i); continue; @@ -5390,7 +5391,7 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) Bmemcpy(&vm, &tempvm, sizeof(vmstate_t)); - if ((unsigned)vm.g_sp->sectnum >= MAXSECTORS) + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_sp->sectnum >= MAXSECTORS)) { if (A_CheckEnemySprite(vm.g_sp)) g_player[vm.g_p].ps->actors_killed++; @@ -5499,7 +5500,7 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) if (vm.g_sp->xrepeat > 60) return; if (ud.respawn_monsters == 1 && vm.g_sp->extra <= 0) return; } - else if (ud.respawn_items == 1 && (vm.g_sp->cstat&32768)) return; + else if (EDUKE32_PREDICT_FALSE(ud.respawn_items == 1 && (vm.g_sp->cstat&32768))) return; if (A_CheckSpriteFlags(vm.g_i, SFLAG_USEACTIVATOR) && sector[vm.g_sp->sectnum].lotag & 16384) changespritestat(vm.g_i, STAT_ZOMBIEACTOR); @@ -5507,7 +5508,8 @@ void A_Execute(int32_t iActor, int32_t iPlayer, int32_t lDist) actor[vm.g_i].timetosleep--; else if (actor[vm.g_i].timetosleep == 1) { - if (g_scriptVersion == 13 && (vm.g_sp->picnum == FIRE || vm.g_sp->picnum == FIRE2)) + // hack for 1.3D fire sprites + if (EDUKE32_PREDICT_FALSE(g_scriptVersion == 13 && (vm.g_sp->picnum == FIRE || vm.g_sp->picnum == FIRE2))) return; changespritestat(vm.g_i, STAT_ZOMBIEACTOR); } diff --git a/polymer/eduke32/source/gameexec.h b/polymer/eduke32/source/gameexec.h index eeec48cfb..f82361cb0 100644 --- a/polymer/eduke32/source/gameexec.h +++ b/polymer/eduke32/source/gameexec.h @@ -155,17 +155,18 @@ void G_SaveMapState(); int32_t VM_OnEvent_(int32_t iEventID,int32_t iActor,int32_t iPlayer,int32_t lDist, int32_t iReturn); -static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) +static inline int32_t VM_HaveEvent(int32_t iEventID) { #ifdef LUNATIC - if (!L_IsInitialized(&g_ElState) || !El_HaveEvent(iEventID)) - return iReturn; + return L_IsInitialized(&g_ElState) && El_HaveEvent(iEventID) #else - if (!apScriptGameEvent[iEventID]) - return iReturn; + return apScriptGameEvent[iEventID]!=NULL; #endif +} - return VM_OnEvent_(iEventID, iActor, iPlayer, lDist, iReturn); +static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t iReturn) +{ + return VM_HaveEvent(iEventID) ? VM_OnEvent_(iEventID, iActor, iPlayer, lDist, iReturn) : iReturn; } void VM_ScriptInfo(void); diff --git a/polymer/eduke32/source/gamestructures.c b/polymer/eduke32/source/gamestructures.c index 4e8daf037..5c29792f6 100644 --- a/polymer/eduke32/source/gamestructures.c +++ b/polymer/eduke32/source/gamestructures.c @@ -33,7 +33,7 @@ static void __fastcall VM_AccessUserdef(int32_t iSet, int32_t lLabelID, int32_t { int32_t lValue=0; - if (vm.g_p != myconnectindex) + if (EDUKE32_PREDICT_FALSE(vm.g_p != myconnectindex)) { // if (lVar2 == MAXGAMEVARS) // insptr++; @@ -920,7 +920,7 @@ static void __fastcall VM_AccessActiveProjectile(int32_t iSet, int32_t lVar1, in if (lVar1 != g_iThisActorID) proj=Gv_GetVarX(lVar1); - if ((unsigned)proj >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)proj >= MAXSPRITES)) { // OSD_Printf("VM_AccessActiveProjectile(): invalid projectile (%d)\n",proj); CON_ERRPRINTF("tried to %s %s on invalid target projectile (%d) %d %d from %s\n", @@ -1218,10 +1218,10 @@ static void __fastcall VM_GetPlayer(register int32_t lVar1, register int32_t lLa if (lVar1 != g_iThisActorID) iPlayer=Gv_GetVarX(lVar1); - if ((unsigned)iPlayer >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer >= (unsigned)playerswhenstarted)) goto badplayer; - if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && ((unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2)) + if (EDUKE32_PREDICT_FALSE(PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && ((unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2))) goto badpos; ps = g_player[iPlayer].ps; @@ -1560,10 +1560,10 @@ static void __fastcall VM_SetPlayer(int32_t lVar1, int32_t lLabelID, int32_t lVa ps = g_player[iPlayer].ps; - if ((unsigned)iPlayer >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer >= (unsigned)playerswhenstarted)) goto badplayer; - if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2) + if (EDUKE32_PREDICT_FALSE(PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2)) goto badpos; lVar1=Gv_GetVarX(lVar2); @@ -1911,7 +1911,7 @@ static void __fastcall VM_AccessPlayerInput(int32_t iSet, int32_t lVar1, int32_t if (lVar1 != g_iThisActorID) iPlayer=Gv_GetVarX(lVar1); - if ((unsigned)iPlayer >= (unsigned)playerswhenstarted) + if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer >= (unsigned)playerswhenstarted)) goto badplayer; if (iSet) @@ -1987,7 +1987,7 @@ static void __fastcall VM_AccessWall(int32_t iSet, int32_t lVar1, int32_t lLabel int32_t lValue=0; int32_t iWall = Gv_GetVarX(lVar1); - if ((unsigned)iWall >= (unsigned)numwalls) + if (EDUKE32_PREDICT_FALSE((unsigned)iWall >= (unsigned)numwalls)) goto badwall; if (iSet) @@ -2183,7 +2183,7 @@ static void __fastcall VM_AccessSector(int32_t iSet, int32_t lVar1, int32_t lLab if (lVar1 != g_iThisActorID) iSector=Gv_GetVarX(lVar1); - if ((unsigned)iSector >= (unsigned)numsectors) + if (EDUKE32_PREDICT_FALSE((unsigned)iSector >= (unsigned)numsectors)) goto badsector; if (iSet) @@ -2445,10 +2445,10 @@ static void __fastcall VM_SetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVa if (lVar1 != g_iThisActorID) iActor=Gv_GetVarX(lVar1); - if ((unsigned)iActor >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)iActor >= MAXSPRITES)) goto badactor; - if (ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2) + if (EDUKE32_PREDICT_FALSE(ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2)) goto badpos; lVar1=Gv_GetVarX(lVar2); @@ -2640,15 +2640,15 @@ static void __fastcall VM_SetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVa return; case ACTOR_MDXOFF: - spriteext[iActor].xoff=lVar1; + spriteext[iActor].offset.x=lVar1; return; case ACTOR_MDYOFF: - spriteext[iActor].yoff=lVar1; + spriteext[iActor].offset.y=lVar1; return; case ACTOR_MDZOFF: - spriteext[iActor].zoff=lVar1; + spriteext[iActor].offset.z=lVar1; return; case ACTOR_MDFLAGS: @@ -2697,10 +2697,11 @@ static void __fastcall VM_GetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVa if (lVar1 != g_iThisActorID) iActor=Gv_GetVarX(lVar1); - if ((unsigned)iActor >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)iActor >= MAXSPRITES)) goto badactor; - if (ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2) + if (EDUKE32_PREDICT_FALSE(ActorLabels[lLabelID].flags & LABEL_HASPARM2 && + (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2)) goto badpos; switch (lLabelID) @@ -2890,15 +2891,15 @@ static void __fastcall VM_GetSprite(int32_t lVar1, int32_t lLabelID, int32_t lVa return; case ACTOR_MDXOFF: - Gv_SetVarX(lVar2,spriteext[iActor].xoff); + Gv_SetVarX(lVar2,spriteext[iActor].offset.x); return; case ACTOR_MDYOFF: - Gv_SetVarX(lVar2,spriteext[iActor].yoff); + Gv_SetVarX(lVar2,spriteext[iActor].offset.y); return; case ACTOR_MDZOFF: - Gv_SetVarX(lVar2,spriteext[iActor].zoff); + Gv_SetVarX(lVar2,spriteext[iActor].offset.z); return; case ACTOR_MDFLAGS: @@ -2952,13 +2953,13 @@ static void __fastcall VM_AccessTsprite(int32_t iSet, int32_t lVar1, int32_t lLa if (lVar1 != g_iThisActorID) iActor=Gv_GetVarX(lVar1); - if ((unsigned)iActor >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned)iActor >= MAXSPRITES)) goto badsprite; if (iSet) lValue=Gv_GetVarX(lVar2); - if (!spriteext[iActor].tspr) + if (EDUKE32_PREDICT_FALSE(!spriteext[iActor].tspr)) goto badtspr; switch (lLabelID) @@ -3208,7 +3209,7 @@ static void __fastcall VM_AccessProjectile(int32_t iSet, int32_t lVar1, int32_t { int32_t lValue=0; - if ((unsigned)lVar1 >= MAXTILES) + if (EDUKE32_PREDICT_FALSE((unsigned)lVar1 >= MAXTILES)) goto badtile; if (iSet) @@ -3498,7 +3499,8 @@ badtile: #else static int32_t __fastcall VM_AccessSpriteX(int32_t iActor, int32_t lLabelID, int32_t lParm2) { - if (ActorLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2) + if (EDUKE32_PREDICT_FALSE(ActorLabels[lLabelID].flags & LABEL_HASPARM2 && + (unsigned)lParm2 >= (unsigned)ActorLabels[lLabelID].maxParm2)) goto badpos; switch (lLabelID) @@ -3549,9 +3551,9 @@ static int32_t __fastcall VM_AccessSpriteX(int32_t iActor, int32_t lLabelID, int case ACTOR_ANGOFF: return spriteext[iActor].angoff; case ACTOR_PITCH: return spriteext[iActor].pitch; case ACTOR_ROLL: return spriteext[iActor].roll; - case ACTOR_MDXOFF: return spriteext[iActor].xoff; - case ACTOR_MDYOFF: return spriteext[iActor].yoff; - case ACTOR_MDZOFF: return spriteext[iActor].zoff; + case ACTOR_MDXOFF: return spriteext[iActor].offset.x; + case ACTOR_MDYOFF: return spriteext[iActor].offset.y; + case ACTOR_MDZOFF: return spriteext[iActor].offset.z; case ACTOR_MDFLAGS: return spriteext[iActor].flags; case ACTOR_XPANNING: return spriteext[iActor].xpanning; case ACTOR_YPANNING: return spriteext[iActor].ypanning; @@ -3611,7 +3613,8 @@ static int32_t __fastcall VM_AccessPlayerX(int32_t iPlayer, int32_t lLabelID, in { DukePlayer_t *const ps = g_player[iPlayer].ps; - if (PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && (unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2) + if (EDUKE32_PREDICT_FALSE(PlayerLabels[lLabelID].flags & LABEL_HASPARM2 && + (unsigned)lParm2 >= (unsigned)PlayerLabels[lLabelID].maxParm2)) goto badpos; switch (lLabelID) diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index d3ea38fae..058b96646 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -388,7 +388,7 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32 { int32_t i; - if (g_gameArrayCount >= MAXGAMEARRAYS) + if (EDUKE32_PREDICT_FALSE(g_gameArrayCount >= MAXGAMEARRAYS)) { g_numCompilerErrors++; C_ReportError(-1); @@ -396,7 +396,7 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32 return 0; } - if (Bstrlen(pszLabel) > (MAXARRAYLABEL-1)) + if (EDUKE32_PREDICT_FALSE(Bstrlen(pszLabel) > (MAXARRAYLABEL-1))) { g_numCompilerErrors++; C_ReportError(-1); @@ -404,7 +404,8 @@ int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32 return 0; } i = hash_find(&h_arrays,pszLabel); - if (i >=0 && !(aGameArrays[i].dwFlags & GAMEARRAY_RESET)) + + if (EDUKE32_PREDICT_FALSE(i >=0 && !(aGameArrays[i].dwFlags & GAMEARRAY_RESET))) { // found it it's a duplicate in error @@ -449,7 +450,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) //Bsprintf(g_szBuf,"Gv_NewVar(%s, %d, %X)",pszLabel, lValue, dwFlags); //AddLog(g_szBuf); - if (g_gameVarCount >= MAXGAMEVARS) + if (EDUKE32_PREDICT_FALSE(g_gameVarCount >= MAXGAMEVARS)) { g_numCompilerErrors++; C_ReportError(-1); @@ -457,7 +458,7 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) return 0; } - if (Bstrlen(pszLabel) > (MAXVARLABEL-1)) + if (EDUKE32_PREDICT_FALSE(Bstrlen(pszLabel) > (MAXVARLABEL-1))) { g_numCompilerErrors++; C_ReportError(-1); @@ -470,13 +471,13 @@ int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags) if (i >= 0 && !(aGameVars[i].dwFlags & GAMEVAR_RESET)) { // found it... - if (aGameVars[i].dwFlags & (GAMEVAR_PTR_MASK)) + if (EDUKE32_PREDICT_FALSE(aGameVars[i].dwFlags & (GAMEVAR_PTR_MASK))) { C_ReportError(-1); initprintf("%s:%d: warning: cannot redefine internal gamevar `%s'.\n",g_szScriptFileName,g_lineNumber,label+(g_numLabels<<6)); return 0; } - else if (!(aGameVars[i].dwFlags & GAMEVAR_SYSTEM)) + else if (EDUKE32_PREDICT_FALSE(!(aGameVars[i].dwFlags & GAMEVAR_SYSTEM))) { // it's a duplicate in error g_numCompilerWarnings++; @@ -552,138 +553,138 @@ void __fastcall A_ResetVars(int32_t iActor) static int32_t Gv_GetVarIndex(const char *szGameLabel) { int32_t i = hash_find(&h_gamevars,szGameLabel); - if (i == -1) + + if (EDUKE32_PREDICT_FALSE(i == -1)) { OSD_Printf(OSD_ERROR "Gv_GetVarIndex(): INTERNAL ERROR: couldn't find gamevar %s!\n",szGameLabel); return 0; } + return i; } int32_t __fastcall Gv_GetVar(int32_t id, int32_t iActor, int32_t iPlayer) { + int negateResult; + if (id == g_iThisActorID) return iActor; if (id == MAXGAMEVARS) return(*insptr++); + negateResult = id&(MAXGAMEVARS<<1); + + if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && !negateResult)) + goto nastyhacks; + + id &= (MAXGAMEVARS-1); + + switch (aGameVars[id].dwFlags & + (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) { - intptr_t negateResult = id&(MAXGAMEVARS<<1); + default: + return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); + case GAMEVAR_PERPLAYER: + if (EDUKE32_PREDICT_FALSE((unsigned) iPlayer >= MAXPLAYERS)) goto bad_id; + return ((aGameVars[id].val.plValues[iPlayer] ^ -negateResult) + negateResult); + case GAMEVAR_PERACTOR: + if (EDUKE32_PREDICT_FALSE((unsigned) iActor >= MAXSPRITES)) goto bad_id; + return ((aGameVars[id].val.plValues[iActor] ^ -negateResult) + negateResult); + case GAMEVAR_INTPTR: + return (((*((int32_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); + case GAMEVAR_SHORTPTR: + return (((*((int16_t *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); + case GAMEVAR_CHARPTR: + return (((*((char *) aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); + } - if (id >= g_gameVarCount) +nastyhacks: + if (id&(MAXGAMEVARS<<2)) // array + { + int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); + + id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= (unsigned) aGameArrays[id].size)) { - if (id&(MAXGAMEVARS<<2)) // array - { - int32_t index=Gv_GetVar(*insptr++,iActor,iPlayer); - - id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); - - if ((unsigned)index >= (unsigned)aGameArrays[id].size) - { - iActor = index; - goto badindex; - } - - return ((aGameArrays[id].plValues[index] ^ -negateResult) + negateResult); - } - - if (id&(MAXGAMEVARS<<3)) // struct shortcut vars - { - int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); - - switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) - { - case 0: //if (id == g_iSpriteVarID) - { - int32_t parm2 = 0, label = *insptr++; - - /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ - if (ActorLabels[label].flags & LABEL_HASPARM2) - parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); - - if ((unsigned)index >= MAXSPRITES) - { - iPlayer = index; - goto badsprite; - } - - return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult); - } - case 3: //else if (id == g_iPlayerVarID) - { - int32_t parm2 = 0, label = *insptr++; - - if (PlayerLabels[label].flags & LABEL_HASPARM2) - parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); - - if (index == vm.g_i) index = vm.g_p; - - if ((unsigned)index >= MAXPLAYERS) - { - iPlayer = index; - goto badplayer; - } - - return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult); - } - case 4: //else if (id == g_iActorVarID) - return ((Gv_GetVar(*insptr++, index, iPlayer) ^ -negateResult) + negateResult); - case 1: //else if (id == g_iSectorVarID) - if (index == vm.g_i) index = sprite[vm.g_i].sectnum; - if ((unsigned)index >= MAXSECTORS) - { - iPlayer = index; - insptr++; - goto badsector; - } - return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); - case 2: //else if (id == g_iWallVarID) - if ((unsigned)index >= MAXWALLS) - { - iPlayer = index; - insptr++; - goto badwall; - } - return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); - default: - goto wtf; - } - } - - id &= (MAXGAMEVARS-1); - - if (!negateResult) - goto badvarid; + iActor = index; + goto badindex; } - switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + return ((aGameArrays[id].plValues[index] ^ -negateResult) + negateResult); + } + + if (id&(MAXGAMEVARS<<3)) // struct shortcut vars + { + int32_t index=Gv_GetVar(*insptr++, iActor, iPlayer); + + switch ((id&(MAXGAMEVARS-1)) - g_iSpriteVarID) { + case 0: //if (id == g_iSpriteVarID) + { + int32_t parm2 = 0, label = *insptr++; + + /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ + if (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) + parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES)) + { + iPlayer = index; + goto badsprite; + } + + return ((VM_AccessSpriteX(index, label, parm2) ^ -negateResult) + negateResult); + } + case 3: //else if (id == g_iPlayerVarID) + { + int32_t parm2 = 0, label = *insptr++; + + if (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) + parm2 = Gv_GetVar(*insptr++, iActor, iPlayer); + + if (index == vm.g_i) index = vm.g_p; + + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS)) + { + iPlayer = index; + goto badplayer; + } + + return ((VM_AccessPlayerX(index, label, parm2) ^ -negateResult) + negateResult); + } + case 4: //else if (id == g_iActorVarID) + return ((Gv_GetVar(*insptr++, index, iPlayer) ^ -negateResult) + negateResult); + case 1: //else if (id == g_iSectorVarID) + if (index == vm.g_i) index = sprite[vm.g_i].sectnum; + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS)) + { + iPlayer = index; + insptr++; + goto badsector; + } + return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); + case 2: //else if (id == g_iWallVarID) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS)) + { + iPlayer = index; + insptr++; + goto badwall; + } + return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); default: - return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); - case GAMEVAR_PERPLAYER: - if ((unsigned)iPlayer >= MAXPLAYERS) goto bad_id; - return ((aGameVars[id].val.plValues[iPlayer] ^ -negateResult) + negateResult); - case GAMEVAR_PERACTOR: - if ((unsigned)iActor >= MAXSPRITES) goto bad_id; - return ((aGameVars[id].val.plValues[iActor] ^ -negateResult) + negateResult); - case GAMEVAR_INTPTR: - return (((*((int32_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); - case GAMEVAR_SHORTPTR: - return (((*((int16_t *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); - case GAMEVAR_CHARPTR: - return (((*((char *)aGameVars[id].val.lValue)) ^ -negateResult) + negateResult); + EDUKE32_UNREACHABLE_SECTION(return -1); } } + CON_ERRPRINTF("Gv_GetVar(): invalid gamevar ID (%d)\n", id); + return -1; + bad_id: CON_ERRPRINTF("Gv_GetVar(): invalid sprite/player ID %d/%d\n", iActor,iPlayer); return -1; -badvarid: - CON_ERRPRINTF("Gv_GetVar(): invalid gamevar ID (%d)\n", id); - return -1; badindex: CON_ERRPRINTF("Gv_GetVar(): invalid array index (%s[%d])\n", aGameArrays[id].szLabel,iActor); @@ -704,15 +705,11 @@ badsector: badwall: CON_ERRPRINTF("Gv_GetVar(): invalid wall ID %d\n", iPlayer); return -1; - -wtf: - CON_ERRPRINTF("Gv_GetVar(): WTF?\n"); - return -1; } void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iPlayer) { - if ((unsigned)id >= (unsigned)g_gameVarCount) goto badvarid; + if (EDUKE32_PREDICT_FALSE((unsigned)id >= (unsigned)g_gameVarCount)) goto badvarid; //Bsprintf(g_szBuf,"SGVI: %d (\"%s\") to %d for %d %d",id,aGameVars[id].szLabel,lValue,iActor,iPlayer); //AddLog(g_szBuf); @@ -723,12 +720,12 @@ void __fastcall Gv_SetVar(int32_t id, int32_t lValue, int32_t iActor, int32_t iP aGameVars[id].val.lValue=lValue; return; case GAMEVAR_PERPLAYER: - if ((unsigned)iPlayer > MAXPLAYERS-1) goto badindex; + if (EDUKE32_PREDICT_FALSE((unsigned)iPlayer > MAXPLAYERS-1)) goto badindex; // for the current player aGameVars[id].val.plValues[iPlayer]=lValue; return; case GAMEVAR_PERACTOR: - if ((unsigned)iActor > MAXSPRITES-1) goto badindex; + if (EDUKE32_PREDICT_FALSE((unsigned)iActor > MAXSPRITES-1)) goto badindex; aGameVars[id].val.plValues[iActor]=lValue; return; case GAMEVAR_INTPTR: @@ -761,8 +758,6 @@ enum { GVX_BADSECTOR, GVX_BADWALL, GVX_BADINDEX, - GVX_WTF, - GVX_ARRAYWTF } gvxerror_t; static const char *gvxerrs [] ={ "Gv_GetVarX(): invalid gamevar ID", @@ -771,8 +766,6 @@ static const char *gvxerrs [] ={ "Gv_GetVarX(): invalid gamevar ID", "Gv_GetVarX(): invalid sector ID", "Gv_GetVarX(): invalid wall ID", "Gv_GetVarX(): invalid array index", -"Gv_GetVarX(): WTF?", -"Gv_GetVarX() (array): WTF?" }; int32_t __fastcall Gv_GetVarX(int32_t id) @@ -785,7 +778,7 @@ int32_t __fastcall Gv_GetVarX(int32_t id) if (id == MAXGAMEVARS) return(*insptr++); - if (id >= g_gameVarCount && negateResult == 0) + if (EDUKE32_PREDICT_FALSE(id >= g_gameVarCount && negateResult == 0)) goto nastyhacks; id &= MAXGAMEVARS-1; @@ -795,7 +788,7 @@ int32_t __fastcall Gv_GetVarX(int32_t id) default: return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); case GAMEVAR_PERPLAYER: - if ((unsigned) vm.g_p >= MAXPLAYERS) + if (EDUKE32_PREDICT_FALSE((unsigned) vm.g_p >= MAXPLAYERS)) { id = vm.g_p; CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id); @@ -820,12 +813,9 @@ nastyhacks: id &= (MAXGAMEVARS-1);// ~((MAXGAMEVARS<<2)|(MAXGAMEVARS<<1)); - if (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) - siz = Gv_GetVarX(aGameArrays[id].size); - else - siz = aGameArrays[id].size; + siz = (aGameArrays[id].dwFlags & GAMEARRAY_VARSIZE) ? Gv_GetVarX(aGameArrays[id].size) : aGameArrays[id].size; - if (index < 0 || index >= siz) + if (EDUKE32_PREDICT_FALSE(index < 0 || index >= siz)) { negateResult = index; CON_ERRPRINTF("%s %s[%d]\n", gvxerrs[GVX_BADINDEX], aGameArrays[id].szLabel, index);; @@ -843,8 +833,7 @@ nastyhacks: case GAMEARRAY_OFCHAR: return (((uint8_t *) aGameArrays[id].plValues)[index] ^ -negateResult) + negateResult; default: - CON_ERRPRINTF("%s\n", gvxerrs[GVX_ARRAYWTF]); - return -1; + EDUKE32_UNREACHABLE_SECTION(return -1); } } @@ -859,10 +848,10 @@ nastyhacks: int32_t parm2 = 0, label = *insptr++; /*OSD_Printf("%d %d %d\n",__LINE__,index,label);*/ - if (ActorLabels[label].flags & LABEL_HASPARM2) + if (EDUKE32_PREDICT_FALSE(ActorLabels[label].flags & LABEL_HASPARM2)) parm2 = Gv_GetVarX(*insptr++); - if ((unsigned) index >= MAXSPRITES) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSPRITES)) { id = index; CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADSPRITE], id); @@ -875,12 +864,12 @@ nastyhacks: { int32_t parm2 = 0, label = *insptr++; - if (PlayerLabels[label].flags & LABEL_HASPARM2) + if (EDUKE32_PREDICT_FALSE(PlayerLabels[label].flags & LABEL_HASPARM2)) parm2 = Gv_GetVarX(*insptr++); if (index == vm.g_i) index = vm.g_p; - if ((unsigned) index >= MAXPLAYERS) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXPLAYERS)) { id = index; CON_ERRPRINTF("%s %d\n", gvxerrs[GVX_BADPLAYER], id); @@ -892,7 +881,7 @@ nastyhacks: return ((Gv_GetVar(*insptr++, index, vm.g_p) ^ -negateResult) + negateResult); case 1: //else if (id == g_iSectorVarID) if (index == vm.g_i) index = sprite[vm.g_i].sectnum; - if ((unsigned) index >= MAXSECTORS) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXSECTORS)) { id = index; insptr++; @@ -901,7 +890,7 @@ nastyhacks: } return ((VM_AccessSectorX(index, *insptr++) ^ -negateResult) + negateResult); case 2: //else if (id == g_iWallVarID) - if ((unsigned) index >= MAXWALLS) + if (EDUKE32_PREDICT_FALSE((unsigned) index >= MAXWALLS)) { id = index; insptr++; @@ -910,13 +899,11 @@ nastyhacks: } return ((VM_AccessWallX(index, *insptr++) ^ -negateResult) + negateResult); default: - CON_ERRPRINTF("Gv_GetVarX(): WTF?\n"); - return -1; + EDUKE32_UNREACHABLE_SECTION(return -1); } } - CON_ERRPRINTF("%s\n", gvxerrs[GVX_WTF]); - return -1; + EDUKE32_UNREACHABLE_SECTION(return -1); } void __fastcall Gv_SetVarX(int32_t id, int32_t lValue) @@ -927,11 +914,11 @@ void __fastcall Gv_SetVarX(int32_t id, int32_t lValue) aGameVars[id].val.lValue=lValue; return; case GAMEVAR_PERPLAYER: - if ((unsigned)vm.g_p > MAXPLAYERS-1) goto badindex; + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p > MAXPLAYERS-1)) goto badindex; aGameVars[id].val.plValues[vm.g_p]=lValue; return; case GAMEVAR_PERACTOR: - if ((unsigned)vm.g_i > MAXSPRITES-1) goto badindex; + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i > MAXSPRITES-1)) goto badindex; aGameVars[id].val.plValues[vm.g_i]=lValue; return; case GAMEVAR_INTPTR: @@ -956,22 +943,19 @@ int32_t Gv_GetVarByLabel(const char *szGameLabel, int32_t lDefault, int32_t iAct { int32_t i = hash_find(&h_gamevars,szGameLabel); - if (i < 0) - return lDefault; - - return Gv_GetVar(i, iActor, iPlayer); + return EDUKE32_PREDICT_FALSE(i < 0) ? lDefault : Gv_GetVar(i, iActor, iPlayer); } static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel) { int32_t i = hash_find(&h_gamevars,szGameLabel); - if (i < 0) + if (EDUKE32_PREDICT_FALSE(i < 0)) return NULL; if (aGameVars[i].dwFlags & (GAMEVAR_PERACTOR | GAMEVAR_PERPLAYER)) { - if (!aGameVars[i].val.plValues) + if (EDUKE32_PREDICT_FALSE(!aGameVars[i].val.plValues)) CON_ERRPRINTF("Gv_GetVarDataPtr(): INTERNAL ERROR: NULL array !!!\n"); return aGameVars[i].val.plValues; } @@ -983,7 +967,7 @@ static intptr_t *Gv_GetVarDataPtr(const char *szGameLabel) static void G_InitProjectileData(void) { int32_t i; - for (i=MAXTILES-1; i>=0; i--) + for (i=0; i<=MAXTILES-1; i++) Bmemcpy(&ProjectileData[i], &g_tile[i].defproj, sizeof(projectile_t)); } diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index 8cdec7111..98c23461e 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -129,11 +129,11 @@ void Gv_FinalizeWeaponDefaults(void); aGameVars[id].val.lValue operator lValue; \ break; \ case GAMEVAR_PERPLAYER: \ - if ((unsigned)vm.g_p > MAXPLAYERS-1) break; \ + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_p > MAXPLAYERS-1)) break; \ aGameVars[id].val.plValues[vm.g_p] operator lValue; \ break; \ case GAMEVAR_PERACTOR: \ - if ((unsigned)vm.g_i > MAXSPRITES-1) break; \ + if (EDUKE32_PREDICT_FALSE((unsigned)vm.g_i > MAXSPRITES-1)) break; \ aGameVars[id].val.plValues[vm.g_i] operator lValue; \ break; \ case GAMEVAR_INTPTR: \ @@ -158,8 +158,8 @@ static inline void __fastcall Gv_DivVar(int32_t id, int32_t lValue) libdivide_s32_t *dptr = &sdiv; intptr_t *iptr = &aGameVars[id].val.lValue; - if ((aGameVars[id].dwFlags & GAMEVAR_PERPLAYER && (unsigned) vm.g_p > MAXPLAYERS-1) || - (aGameVars[id].dwFlags & GAMEVAR_PERACTOR && (unsigned) vm.g_i > MAXSPRITES-1)) return; + if (EDUKE32_PREDICT_FALSE((aGameVars[id].dwFlags & GAMEVAR_PERPLAYER && (unsigned) vm.g_p > MAXPLAYERS-1) || + (aGameVars[id].dwFlags & GAMEVAR_PERACTOR && (unsigned) vm.g_i > MAXSPRITES-1))) return; if ((unsigned) lValue < DIVTABLESIZE) dptr = (libdivide_s32_t *)&divtable32[lValue]; diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 0c838cfed..cee81f7e6 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -3143,8 +3143,7 @@ void M_ChangeMenu(MenuID_t cm) Menu_t *search; int32_t i; - if (G_HaveEvent(EVENT_CHANGEMENU)) - cm = VM_OnEvent(EVENT_CHANGEMENU, g_player[myconnectindex].ps->i, myconnectindex, -1, cm); + cm = VM_OnEvent(EVENT_CHANGEMENU, g_player[myconnectindex].ps->i, myconnectindex, -1, cm); if (cm == MENU_PREVIOUS) { @@ -4816,8 +4815,7 @@ void M_DisplayMenus(void) return; } - if (G_HaveEvent(EVENT_DISPLAYMENU)) - VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, -1, 0); + VM_OnEvent(EVENT_DISPLAYMENU, g_player[screenpeek].ps->i, screenpeek, -1, 0); g_player[myconnectindex].ps->gm &= (0xff-MODE_TYPE); g_player[myconnectindex].ps->fta = 0; @@ -4847,7 +4845,7 @@ void M_DisplayMenus(void) gltexapplyprops(); #endif - if (G_HaveEvent(EVENT_DISPLAYMENUREST)) + if (VM_HaveEvent(EVENT_DISPLAYMENUREST)) VM_OnEvent(EVENT_DISPLAYMENUREST, g_player[screenpeek].ps->i, screenpeek, -1, 0); if ((g_player[myconnectindex].ps->gm&MODE_MENU) != MODE_MENU) diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 3c5b5fbee..99dfc0185 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -1403,8 +1403,7 @@ static int32_t osdcmd_cvar_set_game(const osdfuncparm_t *parm) } else if (!Bstrcasecmp(parm->name, "r_maxfps")) { - if (r_maxfps) g_frameDelay = (int32_t)lround(1000.f/(float)r_maxfps); - else g_frameDelay = 0; + g_frameDelay = r_maxfps ? Blrintf(1000.f/(float)r_maxfps) : 0; return r; } diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 4286742fb..ef04f0dfb 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -350,8 +350,7 @@ static int32_t GetAutoAimAngle(int32_t i, int32_t p, int32_t atwith, Gv_SetVar(g_iAimAngleVarID, g_player[p].ps->auto_aim == 3 ? AUTO_AIM_ANGLE<<1 : AUTO_AIM_ANGLE, i, p); #endif - if (G_HaveEvent(EVENT_GETAUTOAIMANGLE)) - VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1, 0); + VM_OnEvent(EVENT_GETAUTOAIMANGLE, i, p, -1, 0); { #ifdef LUNATIC @@ -473,8 +472,7 @@ static void P_PreFireHitscan(int32_t i, int32_t p, int32_t atwith, Gv_SetVar(g_iZRangeVarID,zRange,i,p); #endif - if (G_HaveEvent(EVENT_GETSHOTRANGE)) - VM_OnEvent(EVENT_GETSHOTRANGE, i,p, -1, 0); + VM_OnEvent(EVENT_GETSHOTRANGE, i, p, -1, 0); #ifdef LUNATIC angRange = ps->angrange; @@ -783,18 +781,20 @@ static int32_t A_PostFireHitscan(const hitdata_t *hit, int32_t i, int32_t atwith static int32_t Proj_CheckBlood(const vec3_t *srcvect, const hitdata_t *hit, int32_t projrange, int32_t minzdiff) { - if (hit->wall >= 0 && hit->sect >= 0) - { - const walltype *const hitwal = &wall[hit->wall]; + const walltype * hitwal; - if (FindDistance2D(srcvect->x-hit->pos.x, srcvect->y-hit->pos.y) < projrange) - if (hitwal->overpicnum != BIGFORCE && (hitwal->cstat&16) == 0) - if (sector[hit->sect].lotag == 0) - if (hitwal->nextsector < 0 || - (sector[hitwal->nextsector].lotag == 0 && sector[hit->sect].lotag == 0 && - sector[hit->sect].floorz-sector[hitwal->nextsector].floorz > minzdiff)) + if (hit->wall < 0 || hit->sect < 0) + return 0; + + hitwal = &wall[hit->wall]; + + if (FindDistance2D(srcvect->x-hit->pos.x, srcvect->y-hit->pos.y) < projrange) + if (hitwal->overpicnum != BIGFORCE && (hitwal->cstat&16) == 0) + if (sector[hit->sect].lotag == 0) + if (hitwal->nextsector < 0 || + (sector[hitwal->nextsector].lotag == 0 && sector[hit->sect].lotag == 0 && + sector[hit->sect].floorz-sector[hitwal->nextsector].floorz > minzdiff)) return 1; - } return 0; } @@ -868,7 +868,7 @@ static int32_t A_ShootCustom(const int32_t i, const int32_t atwith, int16_t sa, DukePlayer_t *const ps = p >= 0 ? g_player[p].ps : NULL; #ifdef POLYMER - if (proj->flashcolor) + if (getrendermode() == REND_POLYMER && proj->flashcolor) { int32_t x = ((sintable[(s->ang + 512) & 2047]) >> 7), y = ((sintable[(s->ang) & 2047]) >> 7); @@ -2928,10 +2928,10 @@ void P_GetInput(int32_t snum) loc.extbits |= (BUTTON(gamefunc_Strafe_Left) || (svel > 0))<<2; loc.extbits |= (BUTTON(gamefunc_Strafe_Right) || (svel < 0))<<3; - if (G_HaveEvent(EVENT_PROCESSINPUT) || G_HaveEvent(EVENT_TURNLEFT)) + if (VM_HaveEvent(EVENT_PROCESSINPUT) || VM_HaveEvent(EVENT_TURNLEFT)) loc.extbits |= BUTTON(gamefunc_Turn_Left)<<4; - if (G_HaveEvent(EVENT_PROCESSINPUT) || G_HaveEvent(EVENT_TURNRIGHT)) + if (VM_HaveEvent(EVENT_PROCESSINPUT) || VM_HaveEvent(EVENT_TURNRIGHT)) loc.extbits |= BUTTON(gamefunc_Turn_Right)<<5; // used for changing team @@ -3222,7 +3222,7 @@ static void P_ChangeWeapon(DukePlayer_t *p, int32_t weapon) if (p->reloading) return; - if (p->curr_weapon != weapon && G_HaveEvent(EVENT_CHANGEWEAPON)) + if (p->curr_weapon != weapon && VM_HaveEvent(EVENT_CHANGEWEAPON)) i = VM_OnEvent(EVENT_CHANGEWEAPON,p->i, snum, -1, weapon); if (i == -1) @@ -3754,8 +3754,8 @@ static void P_ProcessWeapon(int32_t snum) if (VM_OnEvent(EVENT_FIRE, p->i, snum, -1, 0) == 0) { - if (G_HaveEvent(EVENT_FIREWEAPON)) // this event is deprecated - VM_OnEvent(EVENT_FIREWEAPON, p->i, snum, -1, 0); + // this event is deprecated + VM_OnEvent(EVENT_FIREWEAPON, p->i, snum, -1, 0); switch (PWEAPON(snum, p->curr_weapon, WorksLike)) { diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index e5b77d37b..e7291504c 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -718,8 +718,7 @@ void P_ResetPlayer(int32_t snum) pl->movement_lock = 0; - if (G_HaveEvent(EVENT_RESETPLAYER)) - VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum, -1, 0); + VM_OnEvent(EVENT_RESETPLAYER, pl->i, snum, -1, 0); } void P_ResetStatus(int32_t snum) diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 9b32038af..93672e912 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -328,9 +328,9 @@ void G_DoSectorAnimations(void) int32_t GetAnimationGoal(const int32_t *animptr) { - int32_t i = g_animateCount-1; + int32_t i=0; - for (; i>=0; i--) + for (; i