diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index aad72ca41..e898e38d6 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -133,26 +133,26 @@ LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { - if (!lua_checkstack(L, space)) + if (l_unlikely(!lua_checkstack(L, space))) luaL_error(L, "stack overflow (%s)", mes); } LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { - if (lua_type(L, narg) != t) + if (l_unlikely(lua_type(L, narg) != t)) tag_error(L, narg, t); } LUALIB_API void luaL_checkany (lua_State *L, int narg) { - if (lua_type(L, narg) == LUA_TNONE) + if (l_unlikely(lua_type(L, narg) == LUA_TNONE)) luaL_argerror(L, narg, "value expected"); } LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { const char *s = lua_tolstring(L, narg, len); - if (!s) tag_error(L, narg, LUA_TSTRING); + if (l_unlikely(!s)) tag_error(L, narg, LUA_TSTRING); return s; } @@ -170,7 +170,7 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { lua_Number d = lua_tonumber(L, narg); - if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ + if (l_unlikely(d == 0 && !lua_isnumber(L, narg))) /* avoid extra test when d is not 0 */ tag_error(L, narg, LUA_TNUMBER); return d; } diff --git a/src/blua/lauxlib.h b/src/blua/lauxlib.h index 87c41ba61..c8555a557 100644 --- a/src/blua/lauxlib.h +++ b/src/blua/lauxlib.h @@ -102,7 +102,7 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, */ #define luaL_argcheck(L, cond,numarg,extramsg) \ - ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) + ((void)(l_likely(cond) || luaL_argerror(L, (numarg), (extramsg)))) #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) diff --git a/src/blua/lbaselib.c b/src/blua/lbaselib.c index 3c919cb64..8d2272d03 100644 --- a/src/blua/lbaselib.c +++ b/src/blua/lbaselib.c @@ -106,7 +106,7 @@ static int luaB_setmetatable (lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table expected"); - if (luaL_getmetafield(L, 1, "__metatable")) + if (l_unlikely(luaL_getmetafield(L, 1, "__metatable"))) luaL_error(L, "cannot change a protected metatable"); lua_settop(L, 2); lua_setmetatable(L, 1); @@ -120,10 +120,10 @@ static void getfunc (lua_State *L, int opt) { lua_Debug ar; int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); - if (lua_getstack(L, level, &ar) == 0) + if (l_unlikely(lua_getstack(L, level, &ar) == 0)) luaL_argerror(L, 1, "invalid level"); lua_getinfo(L, "f", &ar); - if (lua_isnil(L, -1)) + if (l_unlikely(lua_isnil(L, -1))) luaL_error(L, "no function environment for tail call at level %d", level); } @@ -151,7 +151,7 @@ static int luaB_setfenv (lua_State *L) { lua_setfenv(L, -2); return 0; } - else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) + else if (l_unlikely(lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0)) luaL_error(L, LUA_QL("setfenv") " cannot change environment of given object"); return 1; @@ -265,7 +265,7 @@ static int luaB_ipairs (lua_State *L) { static int luaB_assert (lua_State *L) { luaL_checkany(L, 1); - if (!lua_toboolean(L, 1)) + if (l_unlikely(!lua_toboolean(L, 1))) return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); return lua_gettop(L); } @@ -278,7 +278,7 @@ static int luaB_unpack (lua_State *L) { e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1)); if (i > e) return 0; /* empty range */ n = e - i + 1; /* number of elements */ - if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + if (l_unlikely(n <= 0 || !lua_checkstack(L, n))) /* n <= 0 means arith. overflow */ return luaL_error(L, "too many results to unpack"); lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ while (i++ < e) /* push arg[i + 1...e] */ @@ -445,9 +445,9 @@ static int luaB_costatus (lua_State *L) { static int auxresume (lua_State *L, lua_State *co, int narg) { int status = costatus(L, co); - if (!lua_checkstack(co, narg)) + if (l_unlikely(!lua_checkstack(co, narg))) luaL_error(L, "too many arguments to resume"); - if (status != CO_SUS) { + if (l_unlikely(status != CO_SUS)) { lua_pushfstring(L, "cannot resume %s coroutine", statnames[status]); return -1; /* error flag */ } @@ -456,7 +456,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) { status = lua_resume(co, narg); if (status == 0 || status == LUA_YIELD) { int nres = lua_gettop(co); - if (!lua_checkstack(L, nres + 1)) + if (l_unlikely(!lua_checkstack(L, nres + 1))) luaL_error(L, "too many results to resume"); lua_xmove(co, L, nres); /* move yielded values */ return nres; diff --git a/src/blua/ldblib.c b/src/blua/ldblib.c index 2eacef929..28f7c42bf 100644 --- a/src/blua/ldblib.c +++ b/src/blua/ldblib.c @@ -73,7 +73,7 @@ static int db_getinfo (lua_State *L) { } else return luaL_argerror(L, arg+1, "function or level expected"); - if (!lua_getinfo(L1, options, &ar)) + if (l_unlikely(!lua_getinfo(L1, options, &ar))) return luaL_argerror(L, arg+2, "invalid option"); lua_createtable(L, 0, 2); if (strchr(options, 'S')) { @@ -104,7 +104,7 @@ static int db_getlocal (lua_State *L) { lua_State *L1 = getthread(L, &arg); lua_Debug ar; const char *name; - if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ + if (l_unlikely(!lua_getstack(L1, luaL_checkint(L, arg+1), &ar))) /* out of range? */ return luaL_argerror(L, arg+1, "level out of range"); name = lua_getlocal(L1, &ar, luaL_checkint(L, arg+2)); if (name) { diff --git a/src/blua/ldo.c b/src/blua/ldo.c index 7470a79b7..ad8a32694 100644 --- a/src/blua/ldo.c +++ b/src/blua/ldo.c @@ -172,7 +172,7 @@ void luaD_reallocCI (lua_State *L, int newsize) { void luaD_growstack (lua_State *L, int n) { - if (n <= L->stacksize) /* double size is enough? */ + if (l_likely(n <= L->stacksize)) /* double size is enough? */ luaD_reallocstack(L, 2*L->stacksize); else luaD_reallocstack(L, L->stacksize + n); @@ -180,11 +180,11 @@ void luaD_growstack (lua_State *L, int n) { static CallInfo *growCI (lua_State *L) { - if (L->size_ci > LUAI_MAXCALLS) /* overflow while handling overflow? */ + if (l_unlikely(L->size_ci > LUAI_MAXCALLS)) /* overflow while handling overflow? */ luaD_throw(L, LUA_ERRERR); else { luaD_reallocCI(L, 2*L->size_ci); - if (L->size_ci > LUAI_MAXCALLS) + if (l_unlikely(L->size_ci > LUAI_MAXCALLS)) luaG_runerror(L, "stack overflow"); } return ++L->ci; @@ -257,7 +257,7 @@ static StkId tryfuncTM (lua_State *L, StkId func) { const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); StkId p; ptrdiff_t funcr = savestack(L, func); - if (!ttisfunction(tm)) + if (l_unlikely(!ttisfunction(tm))) luaG_typeerror(L, func, "call"); /* Open a hole inside the stack at `func' */ for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); @@ -356,7 +356,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) { StkId res; int wanted, i; CallInfo *ci; - if (L->hookmask & LUA_MASKRET) + if (l_unlikely(L->hookmask) & LUA_MASKRET) firstResult = callrethooks(L, firstResult); ci = L->ci--; res = ci->func; /* res == final position of 1st result */ @@ -380,7 +380,7 @@ int luaD_poscall (lua_State *L, StkId firstResult) { ** function position. */ void luaD_call (lua_State *L, StkId func, int nResults) { - if (++L->nCcalls >= LUAI_MAXCCALLS) { + if (l_unlikely(++L->nCcalls >= LUAI_MAXCCALLS)) { if (L->nCcalls == LUAI_MAXCCALLS) luaG_runerror(L, "C stack overflow"); else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) @@ -430,15 +430,15 @@ static int resume_error (lua_State *L, const char *msg) { LUA_API int lua_resume (lua_State *L, int nargs) { int status; lua_lock(L); - if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) + if (l_unlikely(L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci))) return resume_error(L, "cannot resume non-suspended coroutine"); - if (L->nCcalls >= LUAI_MAXCCALLS) + if (l_unlikely(L->nCcalls >= LUAI_MAXCCALLS)) return resume_error(L, "C stack overflow"); luai_userstateresume(L, nargs); lua_assert(L->errfunc == 0); L->baseCcalls = ++L->nCcalls; status = luaD_rawrunprotected(L, resume, L->top - nargs); - if (status != 0) { /* error? */ + if (l_unlikely(status != 0)) { /* error? */ L->status = cast_byte(status); /* mark thread as `dead' */ luaD_seterrorobj(L, status, L->top); L->ci->top = L->top; @@ -456,7 +456,7 @@ LUA_API int lua_resume (lua_State *L, int nargs) { LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); - if (L->nCcalls > L->baseCcalls) + if (l_unlikely(L->nCcalls > L->baseCcalls)) luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); L->base = L->top - nresults; /* protect stack slots below */ L->status = LUA_YIELD; @@ -474,7 +474,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_errfunc = L->errfunc; L->errfunc = ef; status = luaD_rawrunprotected(L, func, u); - if (status != 0) { /* an error occurred? */ + if (l_unlikely(status != 0)) { /* an error occurred? */ StkId oldtop = restorestack(L, old_top); luaF_close(L, oldtop); /* close eventual pending closures */ luaD_seterrorobj(L, status, oldtop); @@ -511,8 +511,8 @@ static void f_parser (lua_State *L, void *ud) { tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, &p->buff, p->name); #else - if (c == LUA_SIGNATURE[0]) - luaG_runerror(L, "invalid format, cannot load bytecode scripts"); + if (l_unlikely(c == LUA_SIGNATURE[0])) + luaG_runerror(L, "invalid format, cannot load bytecode scripts"); tf = luaY_parser(L, p->z, &p->buff, p->name); #endif cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); diff --git a/src/blua/ldo.h b/src/blua/ldo.h index 29364965f..baaa1301c 100644 --- a/src/blua/ldo.h +++ b/src/blua/ldo.h @@ -14,7 +14,7 @@ #define luaD_checkstack(L,n) \ - if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ + if (l_unlikely((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue))) \ luaD_growstack(L, n); \ else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); diff --git a/src/blua/liolib.c b/src/blua/liolib.c index 2d69f45cd..40e3e4582 100644 --- a/src/blua/liolib.c +++ b/src/blua/liolib.c @@ -84,7 +84,7 @@ static int io_type (lua_State *L) { static FILE *tofile (lua_State *L) { FILE **f = tofilep(L); - if (*f == NULL) + if (l_unlikely(*f == NULL)) luaL_error(L, "attempt to use a closed file"); return *f; } @@ -184,8 +184,8 @@ static int io_open (lua_State *L) { break; } } - if (strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\") - || StartsWith(filename, "/") || !pass) + if (l_unlikely(strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\") + || StartsWith(filename, "/") || !pass)) { luaL_error(L,"access denied to %s", filename); return pushresult(L,0,filename); @@ -202,7 +202,7 @@ static int io_open (lua_State *L) { { *splitter = 0; I_mkdir(destFilename, 0755); - *splitter = '/'; + *splitter = '/'; splitter++; forward = strchr(splitter, '/'); @@ -226,7 +226,7 @@ static FILE *getiofile (lua_State *L, int findex) { FILE *f; lua_rawgeti(L, LUA_ENVIRONINDEX, findex); f = *(FILE **)lua_touserdata(L, -1); - if (f == NULL) + if (l_unlikely(f == NULL)) luaL_error(L, "standard %s file is closed", fnames[findex - 1]); return f; } @@ -238,7 +238,7 @@ static int g_iofile (lua_State *L, int f, const char *mode) { if (filename) { FILE **pf = newfile(L); *pf = fopen(filename, mode); - if (*pf == NULL) + if (l_unlikely(*pf == NULL)) fileerror(L, 1, filename); } else { @@ -290,7 +290,7 @@ static int io_lines (lua_State *L) { const char *filename = luaL_checkstring(L, 1); FILE **pf = newfile(L); *pf = fopen(filename, "r"); - if (*pf == NULL) + if (l_unlikely(*pf == NULL)) fileerror(L, 1, filename); aux_lines(L, lua_gettop(L), 1); return 1; @@ -307,7 +307,7 @@ static int io_lines (lua_State *L) { static int read_number (lua_State *L, FILE *f) { lua_Number d; - if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) { + if (l_likely(fscanf(f, LUA_NUMBER_SCAN, &d) == 1)) { lua_pushnumber(L, d); return 1; } @@ -454,7 +454,7 @@ static int g_write (lua_State *L, FILE *f, int arg) { else { size_t l; const char *s = luaL_checklstring(L, arg, &l); - if (ftell(f) + l > FILELIMIT) + if (l_unlikely(ftell(f) + l > FILELIMIT)) { luaL_error(L,"write limit bypassed in file. Changes have been discarded."); break; @@ -483,7 +483,7 @@ static int f_seek (lua_State *L) { int op = luaL_checkoption(L, 2, "cur", modenames); long offset = luaL_optlong(L, 3, 0); op = fseek(f, offset, mode[op]); - if (op) + if (l_unlikely(op)) return pushresult(L, 0, NULL); /* error */ else { lua_pushinteger(L, ftell(f)); diff --git a/src/blua/lmem.c b/src/blua/lmem.c index 1b9bed658..a49d3dce1 100644 --- a/src/blua/lmem.c +++ b/src/blua/lmem.c @@ -48,7 +48,7 @@ void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, void *newblock; int newsize; if (*size >= limit/2) { /* cannot double it? */ - if (*size >= limit) /* cannot grow even a little? */ + if (l_unlikely(*size >= limit)) /* cannot grow even a little? */ luaG_runerror(L, errormsg); newsize = limit; /* still have at least one free place */ } @@ -77,7 +77,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { global_State *g = G(L); lua_assert((osize == 0) == (block == NULL)); block = (*g->frealloc)(g->ud, block, osize, nsize); - if (block == NULL && nsize > 0) + if (l_unlikely(block == NULL && nsize > 0)) luaD_throw(L, LUA_ERRMEM); lua_assert((nsize == 0) == (block == NULL)); g->totalbytes = (g->totalbytes - osize) + nsize; diff --git a/src/blua/lparser.c b/src/blua/lparser.c index 3f392ae7b..871c9730d 100644 --- a/src/blua/lparser.c +++ b/src/blua/lparser.c @@ -103,7 +103,7 @@ static void checknext (LexState *ls, int c) { static void check_match (LexState *ls, int what, int who, int where) { - if (!testnext(ls, what)) { + if (l_unlikely(!testnext(ls, what))) { if (where == ls->linenumber) error_expected(ls, what); else { @@ -275,7 +275,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) { static void enterlevel (LexState *ls) { - if (++ls->L->nCcalls > LUAI_MAXCCALLS) + if (l_unlikely(++ls->L->nCcalls > LUAI_MAXCCALLS)) luaX_lexerror(ls, "chunk has too many syntax levels", 0); } @@ -643,7 +643,7 @@ static void funcargs (LexState *ls, expdesc *f) { int line = ls->linenumber; switch (ls->t.token) { case '(': { /* funcargs -> `(' [ explist1 ] `)' */ - if (line != ls->lastline) + if (l_unlikely(line != ls->lastline)) luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); luaX_next(ls); if (ls->t.token == ')') /* arg list is empty? */ @@ -712,7 +712,7 @@ static void prefixexp (LexState *ls, expdesc *v) { case '$': { lua_Number i = ls->t.seminfo.r; if (i == 0) i = ls->fs->nrhs; - if (i <= 0 || i > ls->fs->nlhs) + if (l_unlikely(i <= 0 || i > ls->fs->nlhs)) luaX_syntaxerror(ls, "pseudo-variable out of range or not in assignment"); else { expdesc_list *lhs = ls->fs->lhs; @@ -1105,7 +1105,7 @@ static void breakstat (LexState *ls, lua_Number n) { upval |= bl->upval; bl = bl->previous; } - if (!bl) + if (l_unlikely(!bl)) luaX_syntaxerror(ls, "no loop to break"); if (upval) luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); @@ -1124,7 +1124,7 @@ static void continuestat (LexState *ls) { //upval |= bl->upval; // AK: ADDITION (would this fix forbody probs?) bl = bl->previous; } - if (!bl) + if (l_unlikely(!bl)) luaX_syntaxerror(ls, "no loop to continue"); //if (upval) //AK: experimental diff --git a/src/blua/lstring.c b/src/blua/lstring.c index afc851d0c..0bcc30877 100644 --- a/src/blua/lstring.c +++ b/src/blua/lstring.c @@ -83,7 +83,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { o != NULL; o = o->gch.next) { TString *ts = rawgco2ts(o); - if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { + if (l_unlikely(ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0))) { /* string may be dead */ if (isdead(G(L), o)) changewhite(o); return ts; @@ -95,7 +95,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { Udata *u; - if (s > MAX_SIZET - sizeof(Udata)) + if (l_unlikely(s > MAX_SIZET - sizeof(Udata))) luaM_toobig(L); u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); u->uv.marked = luaC_white(G(L)); /* is not finalized */ diff --git a/src/blua/lstrlib.c b/src/blua/lstrlib.c index 297504e95..e2fd23604 100644 --- a/src/blua/lstrlib.c +++ b/src/blua/lstrlib.c @@ -113,7 +113,7 @@ static int str_byte (lua_State *L) { if ((size_t)pose > l) pose = l; if (posi > pose) return 0; /* empty interval; return no values */ n = (int)(pose - posi + 1); - if (posi + n <= pose) /* overflow? */ + if (l_unlikely(posi + n <= pose)) /* overflow? */ luaL_error(L, "string slice too long"); luaL_checkstack(L, n, "string slice too long"); for (i=0; i= ms->level || ms->capture[l].len == CAP_UNFINISHED) + if (l_unlikely(l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)) return luaL_error(ms->L, "invalid capture index"); return l; } @@ -204,14 +204,14 @@ static int capture_to_close (MatchState *ms) { static const char *classend (MatchState *ms, const char *p) { switch (*p++) { case L_ESC: { - if (*p == '\0') + if (l_unlikely(*p == '\0')) luaL_error(ms->L, "malformed pattern (ends with " LUA_QL("%%") ")"); return p+1; } case '[': { if (*p == '^') p++; do { /* look for a `]' */ - if (*p == '\0') + if (l_unlikely(*p == '\0')) luaL_error(ms->L, "malformed pattern (missing " LUA_QL("]") ")"); if (*(p++) == L_ESC && *p != '\0') p++; /* skip escapes (e.g. `%]') */ @@ -282,7 +282,7 @@ static const char *match (MatchState *ms, const char *s, const char *p); static const char *matchbalance (MatchState *ms, const char *s, const char *p) { - if (*p == 0 || *(p+1) == 0) + if (l_unlikely(*p == 0 || *(p+1) == 0)) luaL_error(ms->L, "unbalanced pattern"); if (*s != *p) return NULL; else { @@ -332,7 +332,8 @@ static const char *start_capture (MatchState *ms, const char *s, const char *p, int what) { const char *res; int level = ms->level; - if (level >= LUA_MAXCAPTURES) luaL_error(ms->L, "too many captures"); + if (l_unlikely(level >= LUA_MAXCAPTURES)) + luaL_error(ms->L, "too many captures"); ms->capture[level].init = s; ms->capture[level].len = what; ms->level = level+1; @@ -386,7 +387,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { case 'f': { /* frontier? */ const char *ep; char previous; p += 2; - if (*p != '[') + if (l_unlikely(*p != '[')) luaL_error(ms->L, "missing " LUA_QL("[") " after " LUA_QL("%%f") " in pattern"); ep = classend(ms, p); /* points to what is next */ @@ -468,14 +469,15 @@ static const char *lmemfind (const char *s1, size_t l1, static void push_onecapture (MatchState *ms, int i, const char *s, const char *e) { if (i >= ms->level) { - if (i == 0) /* ms->level == 0, too */ + if (l_likely(i == 0)) /* ms->level == 0, too */ lua_pushlstring(ms->L, s, e - s); /* add whole match */ else luaL_error(ms->L, "invalid capture index"); } else { ptrdiff_t l = ms->capture[i].len; - if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); + if (l_unlikely(l == CAP_UNFINISHED)) + luaL_error(ms->L, "unfinished capture"); if (l == CAP_POSITION) lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); else @@ -637,7 +639,7 @@ static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, lua_pop(L, 1); lua_pushlstring(L, s, e - s); /* keep original text */ } - else if (!lua_isstring(L, -1)) + else if (l_unlikely(!lua_isstring(L, -1))) luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1)); luaL_addvalue(b); /* add result to accumulator */ } @@ -727,7 +729,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { const char *p = strfrmt; while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */ - if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) + if (l_unlikely((size_t)(p - strfrmt) >= sizeof(FLAGS))) luaL_error(L, "invalid format (repeated flags)"); if (isdigit(uchar(*p))) p++; /* skip width */ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ @@ -736,7 +738,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { if (isdigit(uchar(*p))) p++; /* skip precision */ if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ } - if (isdigit(uchar(*p))) + if (l_unlikely(isdigit(uchar(*p)))) luaL_error(L, "invalid format (width or precision too long)"); *(form++) = '%'; strncpy(form, strfrmt, p - strfrmt + 1); diff --git a/src/blua/ltable.c b/src/blua/ltable.c index 0ddd9ef4f..b21bc4bfa 100644 --- a/src/blua/ltable.c +++ b/src/blua/ltable.c @@ -278,7 +278,7 @@ static void setnodevector (lua_State *L, Table *t, int size) { else { int i; lsize = ceillog2(size); - if (lsize > MAXBITS) + if (l_unlikely(lsize > MAXBITS)) luaG_runerror(L, "table overflow"); size = twoto(lsize); t->node = luaM_newvector(L, size, Node); @@ -498,8 +498,9 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) { if (p != luaO_nilobject) return cast(TValue *, p); else { - if (ttisnil(key)) luaG_runerror(L, "table index is nil"); - else if (ttisnumber(key) && luai_numisnan(nvalue(key))) + if (l_unlikely(ttisnil(key))) + luaG_runerror(L, "table index is nil"); + else if (l_unlikely(ttisnumber(key) && luai_numisnan(nvalue(key)))) luaG_runerror(L, "table index is NaN"); return newkey(L, t, key); } diff --git a/src/blua/ltablib.c b/src/blua/ltablib.c index 2dd157155..5f4ead74a 100644 --- a/src/blua/ltablib.c +++ b/src/blua/ltablib.c @@ -134,7 +134,7 @@ static int tremove (lua_State *L) { static void addfield (lua_State *L, luaL_Buffer *b, int i) { lua_rawgeti(L, 1, i); - if (!lua_isstring(L, -1)) + if (l_unlikely(!lua_isstring(L, -1))) luaL_error(L, "invalid value (%s) at index %d in table for " LUA_QL("concat"), luaL_typename(L, -1), i); luaL_addvalue(b); @@ -224,12 +224,14 @@ static void auxsort (lua_State *L, int l, int u) { for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ /* repeat ++i until a[i] >= P */ while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { - if (i>u) luaL_error(L, "invalid order function for sorting"); + if (l_unlikely(i>u)) + luaL_error(L, "invalid order function for sorting"); lua_pop(L, 1); /* remove a[i] */ } /* repeat --j until a[j] <= P */ while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { - if (j +#if defined(__GNUC__) +#define l_likely(x) (__builtin_expect(((x) != 0), 1)) +#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#else +#define l_likely(x) (x) +#define l_unlikely(x) (x) +#endif + +#endif + /* ** Local configuration. You can use this space to add your redefinitions ** without modifying the main part of the file. diff --git a/src/blua/lvm.c b/src/blua/lvm.c index c6269966c..02d2265c1 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -119,7 +119,7 @@ void luaV_gettable (lua_State *L, TValue *t, TValue *key, StkId val) { } /* else will try the tag method */ } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) + else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))) luaG_typeerror(L, t, "index"); if (ttisfunction(tm)) { callTMres(L, val, tm, t, key); @@ -147,7 +147,7 @@ void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val) { } /* else will try the tag method */ } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) + else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))) luaG_typeerror(L, t, "index"); if (ttisfunction(tm)) { callTM(L, tm, t, key, val); @@ -293,7 +293,8 @@ void luaV_concat (lua_State *L, int total, int last) { /* collect total length */ for (n = 1; n < total && tostring(L, top-n-1); n++) { size_t l = tsvalue(top-n-1)->len; - if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); + if (l_unlikely(l >= MAX_SIZET - tl)) + luaG_runerror(L, "string length overflow"); tl += l; } buffer = luaZ_openspace(L, &G(L)->buff, tl); @@ -322,8 +323,8 @@ static void Arith (lua_State *L, StkId ra, TValue *rb, case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break; case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; - case TM_DIV: if (nc == 0) { luaG_runerror(L, "divide by zero error"); } else setnvalue(ra, luai_numdiv(nb, nc)); break; - case TM_MOD: if (nc == 0) { luaG_runerror(L, "modulo by zero error"); } else setnvalue(ra, luai_nummod(nb, nc)); break; + case TM_DIV: if (l_unlikely(nc == 0)) { luaG_runerror(L, "divide by zero error"); } else setnvalue(ra, luai_numdiv(nb, nc)); break; + case TM_MOD: if (l_unlikely(nc == 0)) { luaG_runerror(L, "modulo by zero error"); } else setnvalue(ra, luai_nummod(nb, nc)); break; case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; case TM_AND: setnvalue(ra, luai_numand(nb, nc)); break; @@ -491,7 +492,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { TValue *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { lua_Number nb = nvalue(rb), nc = nvalue(rc); - if (nc == 0) { + if (l_unlikely(nc == 0)) { luaG_runerror(L, "divide by zero error"); } else @@ -506,7 +507,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { TValue *rc = RKC(i); if (ttisnumber(rb) && ttisnumber(rc)) { lua_Number nb = nvalue(rb), nc = nvalue(rc); - if (nc == 0) { + if (l_unlikely(nc == 0)) { luaG_runerror(L, "modulo by zero error"); } else @@ -580,7 +581,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { } default: { /* try metamethod */ Protect( - if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN)) + if (l_unlikely(!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))) luaG_typeerror(L, rb, "get length of"); ) } @@ -724,11 +725,11 @@ void luaV_execute (lua_State *L, int nexeccalls) { const TValue *plimit = ra+1; const TValue *pstep = ra+2; L->savedpc = pc; /* next steps may throw errors */ - if (!tonumber(init, ra)) + if (l_unlikely(!tonumber(init, ra))) luaG_runerror(L, LUA_QL("for") " initial value must be a number"); - else if (!tonumber(plimit, ra+1)) + else if (l_unlikely(!tonumber(plimit, ra+1))) luaG_runerror(L, LUA_QL("for") " limit must be a number"); - else if (!tonumber(pstep, ra+2)) + else if (l_unlikely(!tonumber(pstep, ra+2))) luaG_runerror(L, LUA_QL("for") " step must be a number"); if (ra && pstep) setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep))); diff --git a/src/d_main.c b/src/d_main.c index db0be8bb9..654cfc7af 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1479,7 +1479,7 @@ static void D_CheckSaturnExtraFiles(void) } // extra round joystick inputdisplay sprites - if (W_CheckMultipleLumps("JOYBCK","JOYKNB","JOYSHD", NULL)) + if (W_CheckMultipleLumps("JOYBCK", "JOYKNB", "JOYSHD", NULL)) { joystickicon = true; PUSHCONS(inputdisplay_cons_temp, last_inputdisplay_i, 3, "StickGFX"); diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e6f574951..e2e295cb5 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -746,7 +746,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool for (i = 0; i < subsector->numlines; i++, line++) { - if (line->linedef->special != HORIZONSPECIAL) + // this check sucks and is a hotspot lel + if (LIKELY(line->linedef->special != HORIZONSPECIAL)) continue; if (R_PointOnSegSide(viewx, viewy, line) != 0) @@ -762,8 +763,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool } else { - x1 = FixedToFloat(line->v1->x); - y1 = FixedToFloat(line->v1->x); + x1 = y1 = FixedToFloat(line->v1->x); } if (line->pv2) @@ -3891,11 +3891,13 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) INT32 shader = SHADER_NONE; - if (!spr->mobj || !spr->mobj->subsector) + const mobj_t *sprmo = spr->mobj; + + if (UNLIKELY(!sprmo || !sprmo->subsector)) return; - const boolean papersprite = (spr->mobj->frame & FF_PAPERSPRITE); - const sector_t *sector = spr->mobj->subsector->sector; + const boolean papersprite = (sprmo->frame & FF_PAPERSPRITE); + const sector_t *sector = sprmo->subsector->sector; if (sector->numlights) { @@ -3961,9 +3963,9 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // Draw shadow BEFORE sprite if (UNLIKELY(cv_shadow.value // Shadows enabled - && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. - && !(spr->mobj->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. - && (spr->mobj->z >= spr->mobj->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. + && (sprmo->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. + && !(sprmo->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. + && (sprmo->z >= sprmo->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. { //////////////////// // SHADOW SPRITE! // @@ -3993,24 +3995,24 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !fullbright); INT32 blendmode; - if (spr->mobj->frame & FF_BLENDMASK) - blendmode = ((spr->mobj->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; + if (sprmo->frame & FF_BLENDMASK) + blendmode = ((sprmo->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; else - blendmode = spr->mobj->blendmode; + blendmode = sprmo->blendmode; if (UNLIKELY(!cv_translucency.value)) // translucency disabled { Surf.PolyColor.s.alpha = 0xFF; blend = PF_Translucent|PF_Occlude; } - else if (spr->mobj->flags2 & MF2_SHADOW) + else if (sprmo->flags2 & MF2_SHADOW) { Surf.PolyColor.s.alpha = 0x40; blend = HWR_GetBlendModeFlag(blendmode); } - else if (spr->mobj->frame & FF_TRANSMASK) + else if (sprmo->frame & FF_TRANSMASK) { - INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + INT32 trans = (sprmo->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; blend = HWR_SurfaceBlend(blendmode, trans, &Surf); } else @@ -4023,7 +4025,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && spr->mobj->player) + if (cv_playerfade.value && sprmo->player) Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); if (HWR_UseShader()) @@ -4046,7 +4048,9 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) INT32 shader = SHADER_NONE; - if (!spr->mobj || !spr->mobj->subsector) + const mobj_t *sprmo = spr->mobj; + + if (UNLIKELY(!sprmo || !sprmo->subsector)) return; // cache sprite graphics @@ -4084,7 +4088,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; // colormap test - sector_t *sector = spr->mobj->subsector->sector; + sector_t *sector = sprmo->subsector->sector; UINT8 lightlevel = 255; extracolormap_t *colormap = sector->extra_colormap; @@ -4092,9 +4096,9 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) { INT32 light; - light = R_GetPlaneLight(sector, spr->mobj->z + spr->mobj->height, false); // Always use the light at the top instead of whatever I was doing before + light = R_GetPlaneLight(sector, sprmo->z + sprmo->height, false); // Always use the light at the top instead of whatever I was doing before - if (!(spr->mobj->frame & FF_FULLBRIGHT)) + if (!(sprmo->frame & FF_FULLBRIGHT)) lightlevel = static_cast(CLAMP(*sector->lightlist[light].lightlevel, 0, 255)); if (sector->lightlist[light].extra_colormap) @@ -4102,7 +4106,7 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) } else { - if (!(spr->mobj->frame & FF_FULLBRIGHT)) + if (!(sprmo->frame & FF_FULLBRIGHT)) lightlevel = static_cast(CLAMP(sector->lightlevel, 0, 255)); if (sector->extra_colormap) @@ -4111,9 +4115,9 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector)); - if (spr->mobj->frame & FF_TRANSMASK) + if (sprmo->frame & FF_TRANSMASK) { - INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + INT32 trans = (sprmo->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; blend = HWR_SurfaceBlend(AST_TRANSLUCENT, trans, &Surf); } else diff --git a/src/k_kart.c b/src/k_kart.c index dfc30c177..65460201d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6090,32 +6090,47 @@ void K_KartUpdatePosition(player_t *player) // This checks every thing on the map, and looks for MT_BOSS3WAYPOINT (the thing we're using for checkpoint wp's, for now) for (mo = waypointcap; mo != NULL; mo = mo->tracer) { - pmo = P_AproxDistance(P_AproxDistance( mo->x - player->mo->x, - mo->y - player->mo->y), - mo->z - player->mo->z) / FRACUNIT; - imo = P_AproxDistance(P_AproxDistance( mo->x - players[i].mo->x, - mo->y - players[i].mo->y), - mo->z - players[i].mo->z) / FRACUNIT; + const boolean isprevcheckpointp = mo->health == player->starpostnum; + const boolean isnextcheckpointp = mo->health == (player->starpostnum + 1); - if (mo->health == player->starpostnum && (!mo->movecount || mo->movecount == player->laps+1)) + if ((isprevcheckpointp || isnextcheckpointp) && (!mo->movecount || mo->movecount == player->laps+1)) { - player->kartstuff[k_prevcheck] += pmo; - ppcd++; + pmo = P_AproxDistance(P_AproxDistance( mo->x - player->mo->x, + mo->y - player->mo->y), + mo->z - player->mo->z) / FRACUNIT; + + if (isprevcheckpointp) + { + player->kartstuff[k_prevcheck] += pmo; + ppcd++; + } + + if (isnextcheckpointp) + { + player->kartstuff[k_nextcheck] += pmo; + pncd++; + } } - if (mo->health == (player->starpostnum + 1) && (!mo->movecount || mo->movecount == player->laps+1)) + + const boolean isprevcheckpointi = mo->health == players[i].starpostnum; + const boolean isnextcheckpointi = mo->health == (players[i].starpostnum + 1); + + if ((isprevcheckpointi || isnextcheckpointi) && (!mo->movecount || mo->movecount == players[i].laps+1)) { - player->kartstuff[k_nextcheck] += pmo; - pncd++; - } - if (mo->health == players[i].starpostnum && (!mo->movecount || mo->movecount == players[i].laps+1)) - { - players[i].kartstuff[k_prevcheck] += imo; - ipcd++; - } - if (mo->health == (players[i].starpostnum + 1) && (!mo->movecount || mo->movecount == players[i].laps+1)) - { - players[i].kartstuff[k_nextcheck] += imo; - incd++; + imo = P_AproxDistance(P_AproxDistance( mo->x - players[i].mo->x, + mo->y - players[i].mo->y), + mo->z - players[i].mo->z) / FRACUNIT; + + if (isprevcheckpointi) + { + players[i].kartstuff[k_prevcheck] += imo; + ipcd++; + } + if (isnextcheckpointi ) + { + players[i].kartstuff[k_nextcheck] += imo; + incd++; + } } } diff --git a/src/m_menu.c b/src/m_menu.c index baa13716d..8f26c7e87 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2701,8 +2701,16 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) { case LLM_CREATESERVER: // Should the map be hidden? <-- well imma wanna toggle it, its just annoying being unable to select hell maps in mapselect - if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) // map hell - return cv_showallmaps.value; + + if (mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) + { + if (cv_showallmaps.value && + ((gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE)) || // race map hell + ((gt == GT_MATCH || gt == GT_TEAMMATCH) && (mapheaderinfo[mapnum]->typeoflevel & TOL_MATCH)))) // battle map hell + return true; + else + return false; + } // same goes here, just show every map if i want to if (M_MapLocked(mapnum+1)) // not unlocked @@ -3282,6 +3290,8 @@ static boolean M_AddonsRefresh(void) return false; } +static tic_t addons_scrolltic = 0; // maybe not the best place but e + static void M_DrawAddons(void) { INT32 x, y; @@ -3289,6 +3299,8 @@ static void M_DrawAddons(void) const UINT8 *flashcol = NULL; UINT8 hilicol; + if (renderisnewtic) addons_scrolltic++; + // hack - need to refresh at end of frame to handle addfile... if (refreshdirmenu & M_AddonsRefresh()) { @@ -3372,6 +3384,9 @@ static void M_DrawAddons(void) for (; i < m; i++) { UINT32 flags = V_ALLOWLOWERCASE; +#define MAXADDONNAME 31 + char scrollbuf[MAXADDONNAME+1] = {0}; + if (y > BASEVIDHEIGHT) break; if (dirmenu[i]) #define type (UINT8)(dirmenu[i][DIR_TYPE]) @@ -3392,11 +3407,22 @@ static void M_DrawAddons(void) } #define charsonside 14 - if (dirmenu[i][DIR_LEN] > (charsonside*2 + 3)) - V_DrawString(x, y+4, flags, va("%.*s...%s", charsonside, dirmenu[i]+DIR_STRING, dirmenu[i]+DIR_STRING+dirmenu[i][DIR_LEN]-(charsonside+1))); + if (dirmenu[i][DIR_LEN] > MAXADDONNAME) + { + if ((size_t)i == dir_on[menudepthleft]) + { + M_ScrollString(dirmenu[i]+DIR_STRING, dirmenu[i][DIR_LEN]-1, scrollbuf, MAXADDONNAME, addons_scrolltic); + } + else + strncpy(scrollbuf, va("%.*s...%s", charsonside, dirmenu[i]+DIR_STRING, dirmenu[i]+DIR_STRING+dirmenu[i][DIR_LEN]-(charsonside+1)), MAXADDONNAME); + + V_DrawString(x, y+4, flags, scrollbuf); + } #undef charsonside else V_DrawString(x, y+4, flags, dirmenu[i]+DIR_STRING); + +#undef MAXADDONNAME } #undef type y += 16; @@ -3521,11 +3547,13 @@ static void M_HandleAddons(INT32 choice) case KEY_DOWNARROW: if (dir_on[menudepthleft] < sizedirmenu-1) dir_on[menudepthleft]++; + addons_scrolltic = 0; S_StartSound(NULL, sfx_menu1); break; case KEY_UPARROW: if (dir_on[menudepthleft]) dir_on[menudepthleft]--; + addons_scrolltic = 0; S_StartSound(NULL, sfx_menu1); break; case KEY_PGDN: @@ -3534,6 +3562,7 @@ static void M_HandleAddons(INT32 choice) for (i = numaddonsshown; i && (dir_on[menudepthleft] < sizedirmenu-1); i--) dir_on[menudepthleft]++; } + addons_scrolltic = 0; S_StartSound(NULL, sfx_menu1); break; case KEY_PGUP: @@ -3542,6 +3571,7 @@ static void M_HandleAddons(INT32 choice) for (i = numaddonsshown; i && (dir_on[menudepthleft]); i--) dir_on[menudepthleft]--; } + addons_scrolltic = 0; S_StartSound(NULL, sfx_menu1); break; case KEY_ENTER: @@ -3681,6 +3711,7 @@ static void M_HandleAddons(INT32 choice) case KEY_ESCAPE: exitmenu = true; + addons_scrolltic = 0; break; default: @@ -5337,51 +5368,6 @@ static musicdef_t *curplaying = NULL; static INT32 st_sel = 0; static tic_t st_musictime = 0; -static void scrollMusicName(const char name[], size_t len, size_t maxlen, char result[]) -{ - // How much should we scroll. Not sure why +1 is needed, but without it this function skips 2 - // characters at once sometimes - const size_t amount = len - maxlen + 1; - - // Note: anything above 17 will cause zero division - const size_t MAXSPEED = 6; - const size_t t = st_musictime / (35/min(amount, MAXSPEED)); - - const size_t state = (t / amount) % 4; - - switch (state) - { - // Show beginning of the name - case 0: - memcpy(result, name, maxlen-1); - break; - - // Scroll towards end of the name - case 1: - { - const size_t advance = t % amount; - memcpy(result, name+advance, maxlen-1); - } - break; - - // Show end of the name - case 2: - memcpy(result, name+len+1-maxlen, maxlen-1); - break; - - // Scroll towards start of the name - case 3: - { - const size_t advance = t % amount; - memcpy(result, name+len+1-maxlen-advance, maxlen-1); - } - break; - } - - // Technically not necessary, since it gets set again after function call, but just in case - result[maxlen] = 0; -} - static void M_MusicTest(INT32 choice) { (void)choice; @@ -5523,7 +5509,7 @@ static void M_DrawMusicTest(void) char buf[MAXLENGTH+1]; if (t == st_sel && namelength > MAXLENGTH) - scrollMusicName(songname, namelength, MAXLENGTH, buf); + M_ScrollString(songname, namelength, buf, MAXLENGTH, st_musictime); else strncpy(buf, songname, MAXLENGTH); buf[MAXLENGTH] = 0; @@ -7184,17 +7170,28 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if (cv_nextmap.value && cv_showtrackaddon.value) { + static tic_t namescroll = 0; + static INT32 namescrollmap = 0; + char namescrollbuf[64]= {0}; + + if (cv_nextmap.value != namescrollmap) + { + namescrollmap = cv_nextmap.value; + namescroll = 0; + } + + if (renderisnewtic) namescroll++; + char *addonname = wadfiles[mapwads[cv_nextmap.value-1]]->filename; INT32 len; - INT32 charlimit = 21 + (dupadjust/5); + INT32 charlimit = min((size_t)(21 + (dupadjust/5)), sizeof(namescrollbuf)-1); nameonly(addonname); len = strlen(addonname); -#define charsonside 14 if (len > charlimit) - V_DrawThinString(x+w+5, y+i-8, V_TRANSLUCENT|MENUCAPS, va("%.*s...%s", charsonside, addonname, addonname+((len-charlimit) + charsonside))); // variable reuse... -#undef charsonside + M_ScrollString(addonname, len, namescrollbuf, charlimit, namescroll); else - V_DrawThinString(x+w+5, y+i-8, V_TRANSLUCENT|MENUCAPS, addonname); // variable reuse... + strncpy(namescrollbuf, addonname, sizeof(namescrollbuf)); + V_DrawThinString(x+w+5, y+i-8, V_TRANSLUCENT|MENUCAPS, namescrollbuf); // variable reuse... } if (!cv_kartencore.value || gamestate == GS_TIMEATTACK || cv_newgametype.value != GT_RACE) diff --git a/src/m_misc.c b/src/m_misc.c index 8dd7bf9b5..dace68e72 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1604,6 +1604,52 @@ boolean M_ScreenshotResponder(event_t *ev) return true; } + +void M_ScrollString(const char name[], size_t len, char result[], size_t maxlen, tic_t timer) +{ + // How much should we scroll. Not sure why +1 is needed, but without it this function skips 2 + // characters at once sometimes + const size_t amount = len - maxlen + 1; + + // Note: anything above 17 will cause zero division + const size_t MAXSPEED = 6; + const tic_t t = timer / (35/min(amount, MAXSPEED)); + + const size_t state = (t / amount) % 4; + + switch (state) + { + // Show beginning of the name + case 0: + memcpy(result, name, maxlen-1); + break; + + // Scroll towards end of the name + case 1: + { + const size_t advance = t % amount; + memcpy(result, name+advance, maxlen-1); + } + break; + + // Show end of the name + case 2: + memcpy(result, name+len+1-maxlen, maxlen-1); + break; + + // Scroll towards start of the name + case 3: + { + const size_t advance = t % amount; + memcpy(result, name+len+1-maxlen-advance, maxlen-1); + } + break; + } + + // Technically not necessary, since it gets set again after function call, but just in case + result[maxlen] = 0; +} + void M_MinimapGenerate(void) { #ifdef USE_PNG diff --git a/src/m_misc.h b/src/m_misc.h index 17ec9823a..2cdad977a 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -73,6 +73,8 @@ void M_ScreenShot(void); void M_DoScreenShot(void); boolean M_ScreenshotResponder(event_t *ev); +void M_ScrollString(const char name[], size_t len, char result[], size_t maxlen, tic_t timer); + void M_MinimapGenerate(void); void Command_SaveConfig_f(void); diff --git a/src/p_inter.c b/src/p_inter.c index 2dc644332..b559c6cc1 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1542,15 +1542,17 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) { if (target->target->hnext) K_KillBananaChain(target->target->hnext, inflictor, source); + target->target->player->kartstuff[k_itemamount] = 0; } - else if (target->target->player->kartstuff[k_itemamount]) + else target->target->player->kartstuff[k_itemamount]--; } else if ((target->type == MT_ORBINAUT_SHIELD && target->target->player->kartstuff[k_itemtype] == KITEM_ORBINAUT) // orbit items || (target->type == MT_JAWZ_SHIELD && target->target->player->kartstuff[k_itemtype] == KITEM_JAWZ)) { target->target->player->kartstuff[k_itemamount]--; + if (target->lastlook != 0) { K_RepairOrbitChain(target); diff --git a/src/p_local.h b/src/p_local.h index 50e8f6df3..de62c86a1 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -158,6 +158,8 @@ extern consvar_t cv_tiltsmoothing; extern consvar_t cv_actionmovie; +extern consvar_t cv_screenquake; + extern consvar_t cv_lookbackmom[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_verticallook[MAXSPLITSCREENPLAYERS]; diff --git a/src/p_map.c b/src/p_map.c index 656dec34b..3dc6a8498 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1691,7 +1691,7 @@ static boolean PIT_CheckLine(line_t *ld) boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) { INT32 xl, xh, yl, yh, bx, by; - subsector_t *newsubsec; + sector_t *newsec; boolean blockval = true; ps_checkposition_calls.value.i++; @@ -1714,9 +1714,9 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) tmbbox[BOXLEFT] = x - tmthing->radius; if (thing->x != x || thing->y != y || thing->subsector == NULL) - newsubsec = R_PointInSubsector(x, y); + newsec = R_PointInSubsector(x, y)->sector; else - newsubsec = thing->subsector; + newsec = thing->subsector->sector; ceilingline = blockingline = NULL; @@ -1724,33 +1724,34 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) // that contains the point. // Any contacted lines the step closer together // will adjust them. - tmfloorz = tmdropoffz = P_GetFloorZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->floorheight; - tmceilingz = P_GetCeilingZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->ceilingheight; - tmfloorslope = newsubsec->sector->f_slope; - tmceilingslope = newsubsec->sector->c_slope; + tmfloorz = tmdropoffz = P_GetFloorZ(thing, newsec, x, y, NULL); //newsec->floorheight; + tmceilingz = P_GetCeilingZ(thing, newsec, x, y, NULL); //newsec->ceilingheight; + tmfloorslope = newsec->f_slope; + tmceilingslope = newsec->c_slope; // Check list of fake floors and see if tmfloorz/tmceilingz need to be altered. - if (newsubsec->sector->ffloors) + if (newsec->ffloors) { ffloor_t *rover; fixed_t delta1, delta2; INT32 thingtop = thing->z + thing->height; - for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) + for (rover = newsec->ffloors; rover; rover = rover->next) { fixed_t topheight, bottomheight, midheight; if (!(rover->flags & FF_EXISTS)) continue; - topheight = P_GetFOFTopZ(thing, newsubsec->sector, rover, x, y, NULL); - bottomheight = P_GetFOFBottomZ(thing, newsubsec->sector, rover, x, y, NULL); + topheight = P_GetFOFTopZ(thing, newsec, rover, x, y, NULL); + bottomheight = P_GetFOFBottomZ(thing, newsec, rover, x, y, NULL); if ((rover->flags & (FF_SWIMMABLE|FF_GOOWATER)) == (FF_SWIMMABLE|FF_GOOWATER) && !(thing->flags & MF_NOGRAVITY)) { // If you're inside goowater and slowing down fixed_t sinklevel = FixedMul(thing->info->height/6, thing->scale); fixed_t minspeed = FixedMul(thing->info->height/9, thing->scale); + if (thing->z < topheight && bottomheight < thingtop && abs(thing->momz) < minspeed) { @@ -1984,7 +1985,7 @@ void P_CheckHoopPosition(mobj_t *hoopthing, fixed_t x, fixed_t y, fixed_t z, fix boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) { INT32 xl, xh, yl, yh, bx, by; - subsector_t *newsubsec; + sector_t *newsec; tmx = x; tmy = y; @@ -1995,15 +1996,15 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) tmbbox[BOXLEFT] = x - thiscam->radius; if (thiscam->x != x || thiscam->y != y || thiscam->subsector == NULL) - newsubsec = R_PointInSubsectorFast(x, y); + newsec = R_PointInSubsectorFast(x, y)->sector; else - newsubsec = thiscam->subsector; + newsec = thiscam->subsector->sector; ceilingline = blockingline = NULL; mapcampointer = thiscam; - if (GETSECSPECIAL(newsubsec->sector->special, 4) == 12) + if (GETSECSPECIAL(newsec->special, 4) == 12) { // Camera noclip on entire sector. tmfloorz = tmdropoffz = thiscam->z; tmceilingz = tmdrpoffceilz = thiscam->z + thiscam->height; @@ -2014,45 +2015,47 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) // that contains the point. // Any contacted lines the step closer together // will adjust them. - tmfloorz = tmdropoffz = P_CameraGetFloorZ(thiscam, newsubsec->sector, x, y, NULL); + tmfloorz = tmdropoffz = P_CameraGetFloorZ(thiscam, newsec, x, y, NULL); - tmceilingz = P_CameraGetCeilingZ(thiscam, newsubsec->sector, x, y, NULL); + tmceilingz = P_CameraGetCeilingZ(thiscam, newsec, x, y, NULL); // Cameras use the heightsec's heights rather then the actual sector heights. // If you can see through it, why not move the camera through it too? - if (newsubsec->sector->heightsec >= 0) + if (newsec->heightsec >= 0) { - tmfloorz = tmdropoffz = sectors[newsubsec->sector->heightsec].floorheight; - tmceilingz = tmdrpoffceilz = sectors[newsubsec->sector->heightsec].ceilingheight; + tmfloorz = tmdropoffz = sectors[newsec->heightsec].floorheight; + tmceilingz = tmdrpoffceilz = sectors[newsec->heightsec].ceilingheight; } // Use preset camera clipping heights if set with Sector Special Parameters whose control sector has Camera Intangible special -Red - if (newsubsec->sector->camsec >= 0) + if (newsec->camsec >= 0) { - tmfloorz = tmdropoffz = sectors[newsubsec->sector->camsec].floorheight; - tmceilingz = tmdrpoffceilz = sectors[newsubsec->sector->camsec].ceilingheight; + tmfloorz = tmdropoffz = sectors[newsec->camsec].floorheight; + tmceilingz = tmdrpoffceilz = sectors[newsec->camsec].ceilingheight; } // Check list of fake floors and see if tmfloorz/tmceilingz need to be altered. - if (newsubsec->sector->ffloors) + if (newsec->ffloors) { ffloor_t *rover; fixed_t delta1, delta2; INT32 thingtop = thiscam->z + thiscam->height; - for (rover = newsubsec->sector->ffloors; rover; rover = rover->next) + for (rover = newsec->ffloors; rover; rover = rover->next) { fixed_t topheight, bottomheight; + if (!(rover->flags & FF_BLOCKOTHERS) || !(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERALL) || GETSECSPECIAL(rover->master->frontsector->special, 4) == 12) continue; - topheight = P_CameraGetFOFTopZ(thiscam, newsubsec->sector, rover, x, y, NULL); - bottomheight = P_CameraGetFOFBottomZ(thiscam, newsubsec->sector, rover, x, y, NULL); + topheight = P_CameraGetFOFTopZ(thiscam, newsec, rover, x, y, NULL); + bottomheight = P_CameraGetFOFBottomZ(thiscam, newsec, rover, x, y, NULL); delta1 = thiscam->z - (bottomheight + ((topheight - bottomheight)/2)); delta2 = thingtop - (bottomheight + ((topheight - bottomheight)/2)); + if (topheight > tmfloorz && abs(delta1) < abs(delta2)) { tmfloorz = tmdropoffz = topheight; @@ -2171,8 +2174,6 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) { subsector_t *s; - - boolean retval = true; UINT8 i; floatok = false; @@ -2222,12 +2223,12 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) else tryy = y; - if (!P_CheckCameraPosition(tryx, tryy, thiscam)) - return false; // solid wall or thing - if (tmceilingz - tmfloorz < thiscam->height) return false; // doesn't fit + if (!P_CheckCameraPosition(tryx, tryy, thiscam)) + return false; // solid wall or thing + floatok = true; if (tmceilingz - thiscam->z < thiscam->height) @@ -2248,7 +2249,8 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) if ((tmfloorz - thiscam->z > MAXCAMERASTEPMOVE)) return false; // too big a step up - } while(tryx != x || tryy != y); + + } while (tryx != x || tryy != y); } else { @@ -2265,7 +2267,7 @@ boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam) thiscam->y = y; thiscam->subsector = s; - return retval; + return true; } // diff --git a/src/p_mobj.c b/src/p_mobj.c index a7a00e355..2ae818350 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -178,7 +178,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) // Set animation state // The pflags version of this was just as convoluted. // Rewriten for SRB2kart ... though I don't know what this is. - switch(state) + switch (state) { case S_KART_STND1...S_KART_STND2_R: case S_KART_SQUISH: @@ -203,7 +203,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) do { - if (state == S_NULL) + if (UNLIKELY(state == S_NULL)) { // Bad SOC! CONS_Alert(CONS_ERROR, "Cannot remove player mobj by setting its state to S_NULL.\n"); //P_RemoveMobj(mobj); @@ -239,7 +239,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) state = st->nextstate; } while (!mobj->tics && !seenstate[state]); - if (!mobj->tics) + if (UNLIKELY(!mobj->tics)) CONS_Alert(CONS_WARNING, M_GetText("State cycle detected, exiting.\n")); if (!--recursion) @@ -306,7 +306,7 @@ boolean P_SetMobjState(mobj_t *mobj, statenum_t state) state = st->nextstate; } while (!mobj->tics && !seenstate[state]); - if (!mobj->tics) + if (UNLIKELY(!mobj->tics)) CONS_Alert(CONS_WARNING, M_GetText("State cycle detected, exiting.\n")); if (!--recursion) @@ -1894,11 +1894,9 @@ boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover) I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); - fixed_t topheight = P_GetFFloorTopZAt(rover, mo->x, mo->y); - if (rover->flags & FF_SWIMMABLE && GETSECSPECIAL(rover->master->frontsector->special, 1) == 3 && !(rover->master->flags & ML_BLOCKMONSTERS) - && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > topheight - FixedMul(16*FRACUNIT, mo->scale))) + && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > P_GetFFloorTopZAt(rover, mo->x, mo->y) - FixedMul(16*FRACUNIT, mo->scale))) return true; return false; @@ -3348,6 +3346,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled thiscam->ceilingz = thiscam->z + thiscam->height; thiscam->floorz = thiscam->z; } + return false; } @@ -3373,7 +3372,7 @@ static void P_PlayerMobjThinker(mobj_t *mobj) mobj->eflags &= ~MFE_JUSTSTEPPEDDOWN; // Zoom tube - if (mobj->tracer && mobj->tracer->type == MT_TUBEWAYPOINT) + if (UNLIKELY(mobj->tracer && mobj->tracer->type == MT_TUBEWAYPOINT)) { P_UnsetThingPosition(mobj); mobj->x += mobj->momx; @@ -3383,7 +3382,7 @@ static void P_PlayerMobjThinker(mobj_t *mobj) P_CheckPosition(mobj, mobj->x, mobj->y); goto animonly; } - else if (mobj->player->pflags & PF_MACESPIN && mobj->tracer) + else if (UNLIKELY(mobj->player->pflags & PF_MACESPIN && mobj->tracer)) { P_CheckPosition(mobj, mobj->x, mobj->y); goto animonly; @@ -3402,7 +3401,7 @@ static void P_PlayerMobjThinker(mobj_t *mobj) else P_TryMove(mobj, mobj->x, mobj->y, true); - if (!(netgame && mobj->player->spectator)) + if (LIKELY(!(netgame && mobj->player->spectator))) { // Crumbling platforms for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next) @@ -3449,6 +3448,7 @@ static void P_PlayerMobjThinker(mobj_t *mobj) } } } + if (thereiswater) { for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next) @@ -5981,7 +5981,8 @@ angle_t P_MobjPitchAndRoll(mobj_t *mobj) return 0; // if mobj doesent have any of those, no need to do the rest - if (mobj->roll == 0 && mobj->pitch == 0 && mobj->sloperoll == 0 && mobj->slopepitch == 0) + if (mobj->roll == 0 && mobj->pitch == 0 + && mobj->sloperoll == 0 && mobj->slopepitch == 0) return 0; size_t rot = (mobj->frame & FF_FRAMEMASK); @@ -6007,7 +6008,8 @@ angle_t P_MobjPitchAndRoll(mobj_t *mobj) sprframe = &sprdef->spriteframes[rot]; // No sprite frame? I guess it is possible - if (!sprframe) return 0; + if (!sprframe) + return 0; if (sprframe->rotate != SRF_SINGLE || (mobj->frame & FF_PAPERSPRITE)) { @@ -6016,9 +6018,9 @@ angle_t P_MobjPitchAndRoll(mobj_t *mobj) } return_angle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mobj->roll) - + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), mobj->pitch) - + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), mobj->sloperoll) - + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), mobj->slopepitch); + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), mobj->pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), mobj->sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), mobj->slopepitch); return return_angle; } @@ -9096,7 +9098,7 @@ void P_MobjThinker(mobj_t *mobj) mobj->eflags &= ~MFE_JUSTHITFLOOR; } - if (mobj->type == MT_FLINGRING + if (UNLIKELY(mobj->type == MT_FLINGRING || mobj->type == MT_FLINGCOIN || P_WeaponOrPanel(mobj->type) || mobj->type == MT_FLINGEMERALD @@ -9109,8 +9111,8 @@ void P_MobjThinker(mobj_t *mobj) P_ButteredSlope(mobj); } - if (mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->health - && P_CheckDeathPitCollide(mobj)) // extra pit check in case these didn't have momz + if (UNLIKELY(mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->health + && P_CheckDeathPitCollide(mobj))) // extra pit check in case these didn't have momz { P_KillMobj(mobj, NULL, NULL); return; @@ -9119,10 +9121,10 @@ void P_MobjThinker(mobj_t *mobj) // Crush enemies! if (mobj->ceilingz - mobj->floorz < mobj->height) { - if (( + if (UNLIKELY(( (mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->flags & MF_SHOOTABLE) - || mobj->type == MT_EGGSHIELD) + || mobj->type == MT_EGGSHIELD)) && !(mobj->flags & MF_NOCLIPHEIGHT) && mobj->health > 0) { @@ -9140,7 +9142,7 @@ void P_MobjThinker(mobj_t *mobj) if (P_MobjWasRemoved(mobj)) return; - switch (mobj->type) + if (UNLIKELY(P_WeaponOrPanel(mobj->type))) { case MT_BOUNCEPICKUP ... MT_GRENADEPICKUP: if (mobj->health == 0) // Fading tile @@ -9150,15 +9152,12 @@ void P_MobjThinker(mobj_t *mobj) value = 10-value; value--; - if (value <= 0) - value = 1; + if (value <= 0) + value = 1; - mobj->frame &= ~FF_TRANSMASK; - mobj->frame |= value << FF_TRANSSHIFT; - } - break; - default: - break; + mobj->frame &= ~FF_TRANSMASK; + mobj->frame |= value << FF_TRANSSHIFT; + } } } @@ -9983,8 +9982,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->precipflags |= PCF_FOF; else { - INT32 special = GETSECSPECIAL(mobj->subsector->sector->special, 1); - + const INT32 special = GETSECSPECIAL(mobj->subsector->sector->special, 1); if (special == 7 || special == 6 || mobj->subsector->sector->floorpic == skyflatnum) mobj->precipflags |= PCF_PIT; } @@ -10016,14 +10014,14 @@ void P_RemoveMobj(mobj_t *mobj) mobj->thinker.function = (actionf_p1)P_MobjThinker; // needed for P_UnsetThingPosition, etc. to work. // Rings only, please! - if (mobj->spawnpoint && + if (UNLIKELY(mobj->spawnpoint && (mobj->type == MT_RING || mobj->type == MT_COIN || mobj->type == MT_BLUEBALL || mobj->type == MT_REDTEAMRING || mobj->type == MT_BLUETEAMRING || P_WeaponOrPanel(mobj->type)) - && !(mobj->flags2 & MF2_DONTRESPAWN)) + && !(mobj->flags2 & MF2_DONTRESPAWN))) { itemrespawnque[iquehead] = mobj->spawnpoint; itemrespawntime[iquehead] = leveltime; @@ -10045,13 +10043,13 @@ void P_RemoveMobj(mobj_t *mobj) } } - if (mobj->type == MT_OVERLAY) + if (UNLIKELY(mobj->type == MT_OVERLAY)) P_RemoveOverlay(mobj); - if (mobj->type == MT_SHADOW) + if (UNLIKELY(mobj->type == MT_SHADOW)) P_RemoveShadow(mobj); - if (mobj->type == MT_SPB) + if (UNLIKELY(mobj->type == MT_SPB)) spbplace = -1; mobj->health = 0; // Just because @@ -10063,6 +10061,7 @@ void P_RemoveMobj(mobj_t *mobj) P_DelSeclist(sector_list); sector_list = NULL; } + mobj->flags |= MF_NOSECTOR|MF_NOBLOCKMAP; mobj->subsector = NULL; mobj->state = NULL; @@ -10098,46 +10097,33 @@ void P_RemoveMobj(mobj_t *mobj) R_RemoveMobjInterpolator(mobj); // free block - // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. if (mobj->flags & MF_NOTHINK && !mobj->thinker.next) { // Uh-oh, the mobj doesn't think, P_RemoveThinker would never go through! if (!mobj->thinker.references) { -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset(mobj, 0xff, sizeof(mobj_t)); -#endif // no references, dump it directly in the mobj cache mobj->hnext = mobjcache; mobjcache = mobj; + return; } - else - { // Add thinker just to delay removing it until refrences are gone. - mobj->flags &= ~MF_NOTHINK; - P_AddThinker((thinker_t *)mobj); -#ifdef PARANOIA - // Saved to avoid being scrambled like below... - mobj->thinker.debug_mobjtype = mobj->type; -#endif -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); -#endif - P_RemoveThinker((thinker_t *)mobj); - } + + // Add thinker just to delay removing it until refrences are gone. + mobj->flags &= ~MF_NOTHINK; + P_AddThinker((thinker_t *)mobj); } - else - { + + P_RemoveThinker((thinker_t *)mobj); + #ifdef PARANOIA - // Saved to avoid being scrambled like below... - mobj->thinker.debug_mobjtype = mobj->type; + // Saved to avoid being scrambled like below... + mobj->thinker.debug_mobjtype = mobj->type; #endif + + // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. #ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); + // Invalidate mobj_t data to cause crashes if accessed! + memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); #endif - P_RemoveThinker((thinker_t *)mobj); - } } void P_FreePrecipMobj(precipmobj_t *mobj) diff --git a/src/p_tick.c b/src/p_tick.c index 437ebd402..8cf354c8a 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -573,7 +573,7 @@ static void P_RunQuakes(void) { fixed_t ir; - if (quake.time <= 0) + if (!cv_screenquake.value || quake.time <= 0) { quake.x = quake.y = quake.z = quake.roll = 0; return; @@ -618,8 +618,8 @@ static inline void P_ResetSpriteStuff(void) if (!mo || (mo->sprite == SPR_NULL) || (mo->flags2 & MF2_DONTDRAW) || (mo->type == MT_SHADOW)) continue; - mo->spritexscale = mo->realxscale; - mo->spriteyscale = mo->realyscale; + mo->spritexscale = mo->realxscale; + mo->spriteyscale = mo->realyscale; mo->spritexoffset = mo->realxoffset; mo->spriteyoffset = mo->realyoffset; } diff --git a/src/p_user.c b/src/p_user.c index dd2f4cd2b..7ea0e84c4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3048,6 +3048,8 @@ consvar_t cv_tiltsmoothing = {"tiltsmoothing", "32", CV_SAVE, CV_Natural, NULL, consvar_t cv_actionmovie = {"actionmovie", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_screenquake = {"quakescreenshake", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t lookbackmom_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Double"}, {0, NULL}}; consvar_t cv_lookbackmom[MAXSPLITSCREENPLAYERS] = { diff --git a/src/r_main.cpp b/src/r_main.cpp index fa4425f19..cef57ad2e 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1578,6 +1578,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_tiltsmoothing); CV_RegisterVar(&cv_actionmovie); + CV_RegisterVar(&cv_screenquake); + CV_RegisterVar(&cv_driftsparkpulse); CV_RegisterVar(&cv_gravstretch); CV_RegisterVar(&cv_sloperoll);