Another 5000 lines of pain and tears. DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4680 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-10-25 03:36:34 +00:00
parent 1c68e84e5a
commit 8934226bb2
28 changed files with 943 additions and 880 deletions

View File

@ -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];

View File

@ -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 <math.h>
static inline long lround(double num)
{
return (long) (num > 0 ? num + 0.5 : ceil(num - 0.5));
}
#else
# define longlong(x) x##ll
#endif

View File

@ -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];

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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, &ltilenume, 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, &ltilenume, 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, &ltilenume, script, hudtokptr))
if (EDUKE32_PREDICT_FALSE(check_tile_range("hud", &ftilenume, &ltilenume, 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)))

View File

@ -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).
// <lastokcol> 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; k<j; k++)
for (l=i; l<k; l++)
if (tspriteptr[k]->statnum < 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 <xx>
@ -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 <xx>
@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

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

View File

@ -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));
}

View File

@ -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];

View File

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

View File

@ -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;
}

View File

@ -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))
{

View File

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

View File

@ -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<g_animateCount; i++)
if (animptr == animateptr[i])
return i;
return -1;