diff --git a/LUASTUFF.md b/LUASTUFF.md index 28e77bed8..fcc9f313a 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -13,10 +13,12 @@ Mainly for use in visual-only addons like secondcolor. **Not netsafe**. Returns player's current sliptide roll angle, taking sliptideroll cvar value into account. -## hud.setVoteBackground(name) +## hud.setVoteBackground(name[, time\_per\_frame]) Changes vote background texture prefix (game looks for PREFIX + "W" or "C" (depends on resolution) + FRAME\_NUMBER). +If time\_per\_frame is set, each frame will last this amount of tics, default value is 2 + ## hud.add(fn, "vote") and hud.add(fn, "intermission") Hud hooks for vote screen and intermission screen. They only get drawer (`v`) as argument. @@ -120,6 +122,11 @@ v.interpLatch(false) ``` When using a custom string drawer, enable this mode to avoid interpolation artifacting when the string changes. +## cameras[] global array + +Local player cameras that can be accessed outside of hud hooks. +`#cameras` will return amount of available cameras. (0 on dedicated server, 1 with 1 player, 4 with 4p splitscreen, etc) + ## mobj.spritexscale, mobj.spriteyscale, mobj.spritexoffset, mobj.spriteyoffset, mobj.rollangle, mobj.sloperoll, mobj.rollmodel fields Same fields as in SRB2 2.2 diff --git a/libs/SDL2/SRB2NOTE.txt b/libs/SDL2/SRB2NOTE.txt index 70d80a6e7..aa5950c29 100644 --- a/libs/SDL2/SRB2NOTE.txt +++ b/libs/SDL2/SRB2NOTE.txt @@ -1,20 +1,15 @@ -# SDL Development Libaries - -Download both the VC and MinGW packages and extract them here. - -https://www.libsdl.org/download-2.0.php - -## VC Package - -* include -* lib - -## MinGW Package - -* i686-w64-mingw32 -* x86_64-w64-mingw32 - -# SRB2Kart Saturn note: -Due to a good amount of issues with newer SDL releases, we decided to ship our own Version of the library. -This version is just the 2.28.5 release with a fix backported for non US keyboard layouts that prevented the right ALT GR key from working properly. -It can be found under: https://github.com/alufolie91/SDL/tree/backportaltgrfix +# SDL Development Libaries + +Download both the VC and MinGW packages and extract them here. + +https://www.libsdl.org/download-2.0.php + +## VC Package + +* include +* lib + +## MinGW Package + +* i686-w64-mingw32 +* x86_64-w64-mingw32 diff --git a/libs/SDL2/i686-w64-mingw32/bin/SDL2.dll b/libs/SDL2/i686-w64-mingw32/bin/SDL2.dll index 17a86d671..573225cab 100644 Binary files a/libs/SDL2/i686-w64-mingw32/bin/SDL2.dll and b/libs/SDL2/i686-w64-mingw32/bin/SDL2.dll differ diff --git a/libs/SDL2/i686-w64-mingw32/bin/sdl2-config b/libs/SDL2/i686-w64-mingw32/bin/sdl2-config index aa99b065a..8352f5564 100644 --- a/libs/SDL2/i686-w64-mingw32/bin/sdl2-config +++ b/libs/SDL2/i686-w64-mingw32/bin/sdl2-config @@ -1,65 +1,65 @@ -#!/bin/sh - -# Get the canonical path of the folder containing this script -bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)") - -# Calculate the canonical path of the prefix, relative to the folder of this script -prefix=$(cd -P -- "$bindir/.." && printf '%s\n' "$(pwd -P)") -exec_prefix=${prefix} -exec_prefix_set=no -libdir=${exec_prefix}/lib - -#usage="\ -#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]" -usage="\ -Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]" - -if test $# -eq 0; then - echo "${usage}" 1>&2 - exit 1 -fi - -while test $# -gt 0; do - case "$1" in - -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - if test $exec_prefix_set = no ; then - exec_prefix=$optarg - fi - ;; - --prefix) - echo $prefix - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - ;; - --exec-prefix) - echo $exec_prefix - ;; - --version) - echo 2.28.5 - ;; - --cflags) - echo -I${prefix}/include/SDL2 -Dmain=SDL_main - ;; - --libs) - echo -L${exec_prefix}/lib -lmingw32 -lSDL2main -lSDL2 -mwindows - ;; - --static-libs) -# --libs|--static-libs) - sdl_static_libs=$(echo "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g") - echo -L${exec_prefix}/lib $sdl_static_libs - ;; - *) - echo "${usage}" 1>&2 - exit 1 - ;; - esac - shift -done +#!/bin/sh + +# Get the canonical path of the folder containing this script +bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)") + +# Calculate the canonical path of the prefix, relative to the folder of this script +prefix=$(cd -P -- "$bindir/.." && printf '%s\n' "$(pwd -P)") +exec_prefix=${prefix} +exec_prefix_set=no +libdir=${exec_prefix}/lib + +#usage="\ +#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]" +usage="\ +Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]" + +if test $# -eq 0; then + echo "${usage}" 1>&2 + exit 1 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case $1 in + --prefix=*) + prefix=$optarg + if test $exec_prefix_set = no ; then + exec_prefix=$optarg + fi + ;; + --prefix) + echo $prefix + ;; + --exec-prefix=*) + exec_prefix=$optarg + exec_prefix_set=yes + ;; + --exec-prefix) + echo $exec_prefix + ;; + --version) + echo 2.28.5 + ;; + --cflags) + echo -I${prefix}/include/SDL2 -Dmain=SDL_main + ;; + --libs) + echo -L${exec_prefix}/lib -lmingw32 -lSDL2main -lSDL2 -mwindows + ;; + --static-libs) +# --libs|--static-libs) + sdl_static_libs=$(echo "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g") + echo -L${exec_prefix}/lib $sdl_static_libs + ;; + *) + echo "${usage}" 1>&2 + exit 1 + ;; + esac + shift +done diff --git a/libs/SDL2/x86_64-w64-mingw32/bin/SDL2.dll b/libs/SDL2/x86_64-w64-mingw32/bin/SDL2.dll index 9b8adc0ff..e26bcb1c3 100644 Binary files a/libs/SDL2/x86_64-w64-mingw32/bin/SDL2.dll and b/libs/SDL2/x86_64-w64-mingw32/bin/SDL2.dll differ diff --git a/libs/SDL2/x86_64-w64-mingw32/bin/sdl2-config b/libs/SDL2/x86_64-w64-mingw32/bin/sdl2-config index 65b2fd199..a48f6792d 100644 --- a/libs/SDL2/x86_64-w64-mingw32/bin/sdl2-config +++ b/libs/SDL2/x86_64-w64-mingw32/bin/sdl2-config @@ -1,65 +1,65 @@ -#!/bin/sh - -# Get the canonical path of the folder containing this script -bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)") - -# Calculate the canonical path of the prefix, relative to the folder of this script -prefix=$(cd -P -- "$bindir/.." && printf '%s\n' "$(pwd -P)") -exec_prefix=${prefix} -exec_prefix_set=no -libdir=${exec_prefix}/lib - -#usage="\ -#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]" -usage="\ -Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]" - -if test $# -eq 0; then - echo "${usage}" 1>&2 - exit 1 -fi - -while test $# -gt 0; do - case "$1" in - -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - if test $exec_prefix_set = no ; then - exec_prefix=$optarg - fi - ;; - --prefix) - echo $prefix - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - ;; - --exec-prefix) - echo $exec_prefix - ;; - --version) - echo 2.28.5 - ;; - --cflags) - echo -I${prefix}/include/SDL2 -Dmain=SDL_main - ;; - --libs) - echo -L${exec_prefix}/lib -lmingw32 -lSDL2main -lSDL2 -mwindows - ;; - --static-libs) -# --libs|--static-libs) - sdl_static_libs=$(echo "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g") - echo -L${exec_prefix}/lib $sdl_static_libs - ;; - *) - echo "${usage}" 1>&2 - exit 1 - ;; - esac - shift -done +#!/bin/sh + +# Get the canonical path of the folder containing this script +bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)") + +# Calculate the canonical path of the prefix, relative to the folder of this script +prefix=$(cd -P -- "$bindir/.." && printf '%s\n' "$(pwd -P)") +exec_prefix=${prefix} +exec_prefix_set=no +libdir=${exec_prefix}/lib + +#usage="\ +#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]" +usage="\ +Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]" + +if test $# -eq 0; then + echo "${usage}" 1>&2 + exit 1 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) optarg= ;; + esac + + case $1 in + --prefix=*) + prefix=$optarg + if test $exec_prefix_set = no ; then + exec_prefix=$optarg + fi + ;; + --prefix) + echo $prefix + ;; + --exec-prefix=*) + exec_prefix=$optarg + exec_prefix_set=yes + ;; + --exec-prefix) + echo $exec_prefix + ;; + --version) + echo 2.28.5 + ;; + --cflags) + echo -I${prefix}/include/SDL2 -Dmain=SDL_main + ;; + --libs) + echo -L${exec_prefix}/lib -lmingw32 -lSDL2main -lSDL2 -mwindows + ;; + --static-libs) +# --libs|--static-libs) + sdl_static_libs=$(echo "-lmingw32 -lSDL2main -lSDL2 -mwindows -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid" | sed -E "s#-lSDL2[ $]#$libdir/libSDL2.a #g") + echo -L${exec_prefix}/lib $sdl_static_libs + ;; + *) + echo "${usage}" 1>&2 + exit 1 + ;; + esac + shift +done diff --git a/libs/dll-binaries/i686/SDL2.dll b/libs/dll-binaries/i686/SDL2.dll index 17a86d671..573225cab 100644 Binary files a/libs/dll-binaries/i686/SDL2.dll and b/libs/dll-binaries/i686/SDL2.dll differ diff --git a/libs/dll-binaries/x86_64/SDL2.dll b/libs/dll-binaries/x86_64/SDL2.dll index 9b8adc0ff..e26bcb1c3 100644 Binary files a/libs/dll-binaries/x86_64/SDL2.dll and b/libs/dll-binaries/x86_64/SDL2.dll differ diff --git a/src/.gitignore b/src/.gitignore index 156f6f65f..b1b48e2a2 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,4 @@ /cscope.out *.json *.idx +*.gdb_history diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk index dd31d2f3e..7ff978397 100644 --- a/src/Makefile.d/detect.mk +++ b/src/Makefile.d/detect.mk @@ -64,7 +64,7 @@ endif # This must have high to low order. gcc_versions:=\ - 151 150 15\ + 152 151 150 15\ 142 141 140 14\ 132 131 130 13\ 123 122 121 120 12\ @@ -77,7 +77,7 @@ gcc_versions:=\ 55 54 53 52 51 50\ 49 48 47 46 45 44 43 42 41 40 -latest_gcc_version:=15.1.1 +latest_gcc_version:=15.2 # Automatically set version flag, but not if one was # manually set. And don't bother if this is a clean only diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 451ff72e7..2a80cfa39 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/Sourcefile b/src/Sourcefile index 761806e6b..08c18ebf0 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -1,3 +1,4 @@ +string.c am_map.c b_bot.c command.c @@ -42,7 +43,6 @@ s_sound.c screen.c sounds.c st_stuff.c -string.c tables.c v_video.c w_wad.c diff --git a/src/android/i_system.c b/src/android/i_system.c index 102bff461..ef10df5b5 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -226,10 +226,6 @@ const char *I_LocateWad(void) return "/sdcard/srb2"; } -void I_GetJoystickEvents(void){} - -void I_GetJoystick2Events(void){} - char *I_GetEnv(const char *name) { LOGW("I_GetEnv() called?!"); diff --git a/src/android/i_video.c b/src/android/i_video.c index f3054038e..bdd128895 100644 --- a/src/android/i_video.c +++ b/src/android/i_video.c @@ -50,25 +50,15 @@ const char *VID_GetModeName(INT32 modenum) return "A320x240"; } -void I_UpdateNoBlit(void){} - -void I_FinishUpdate(void) { +void I_FinishUpdate(void) +{ LOGD("FRAME!"); (*jni_env)->CallVoidMethod(jni_env, androidVideo, videoFrameCB); } void I_UpdateNoVsync(void) {} -void I_WaitVBL(INT32 count) -{ - (void)count; -} - void I_ReadScreen(UINT8 * restrict scr, INT32 scale) { (void)scr; } - -void I_BeginRead(void){} - -void I_EndRead(void){} diff --git a/src/b_bot.c b/src/b_bot.c index 8100fc414..fa1508917 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -47,7 +47,7 @@ static inline void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cm if (sonic->player->pflags & (PF_MACESPIN|PF_ITEMHANG)) { cmd->forwardmove = sonic->player->cmd.forwardmove; - cmd->angleturn = abs((signed)(tails->angle - sonic->angle))>>16; + cmd->angleturn = abs((signed)(tails->angle - sonic->angle)) >> TICCMD_REDUCE; if (sonic->angle < tails->angle) cmd->angleturn = -cmd->angleturn; } else if (dist > FixedMul(512*FRACUNIT, tails->scale)) @@ -139,13 +139,13 @@ void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward // Don't mess with bot inputs during these unhandled movement conditions. // The normal AI doesn't use abilities, so custom AI should be sending us exactly what it wants anyway. if (forward) - cmd->forwardmove += MAXPLMOVE<>16; + cmd->forwardmove += MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (backward) - cmd->forwardmove -= MAXPLMOVE<>16; + cmd->forwardmove -= MAXPLMOVE<> TICCMD_REDUCE; if (left || strafeleft) - cmd->sidemove -= MAXPLMOVE<>16; + cmd->sidemove -= MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (right || straferight) - cmd->sidemove += MAXPLMOVE<>16; + cmd->sidemove += MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; } else { // In standard 2D mode, interpret "forward" as "the way you're facing" and everything else as "the way you're not facing" if (left || right) @@ -163,23 +163,23 @@ void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward right = true; } if (left || strafeleft) - cmd->sidemove -= MAXPLMOVE<>16; + cmd->sidemove -= MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (right || straferight) - cmd->sidemove += MAXPLMOVE<>16; + cmd->sidemove += MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; } } else { if (forward) - cmd->forwardmove += MAXPLMOVE<>16; + cmd->forwardmove += MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (backward) - cmd->forwardmove -= MAXPLMOVE<>16; + cmd->forwardmove -= MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (left) cmd->angleturn += 1280; if (right) cmd->angleturn -= 1280; if (strafeleft) - cmd->sidemove -= MAXPLMOVE<>16; + cmd->sidemove -= MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; if (straferight) - cmd->sidemove += MAXPLMOVE<>16; + cmd->sidemove += MAXPLMOVE << FRACBITS >> TICCMD_REDUCE; } if (jump) cmd->buttons |= BT_DRIFT; diff --git a/src/blua/lauxlib.c b/src/blua/lauxlib.c index e91faa182..5fb454d5e 100644 --- a/src/blua/lauxlib.c +++ b/src/blua/lauxlib.c @@ -93,6 +93,57 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { /* }====================================================== */ +/* +** {====================================================== +** 'luaL_resourcetryagain' +** This function uses 'errno' to check whether the last error was +** related to lack of resources (e.g., not enough memory or too many +** open files). If so, the function performs a full garbage collection +** to try to release resources, and then it returns 1 to signal to +** the caller that it is worth trying again the failed operation. +** Otherwise, it returns 0. Because error codes are not ANSI C, the +** code must handle any combination of error codes that are defined. +** ======================================================= +*/ + +LUALIB_API int luaL_resourcetryagain (lua_State *L) { + +/* these are the resource-related errors in Linux */ +#if defined(EMFILE) || defined(ENFILE) || defined(ENOMEM) + +#if !defined(EMFILE) /* too many open files in the process */ +#define EMFILE -1 /* if not defined, use an impossible value */ +#endif + +#if !defined(ENFILE) /* too many open files in the system */ +#define ENFILE -1 +#endif + +#if !defined(ENOMEM) /* not enough memory */ +#define ENOMEM -1 +#endif + + if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) { + CONS_Alert(CONS_WARNING, "%s, force calling lua garbage collector\n", strerror(errno)); + lua_gc(L, LUA_GCCOLLECT, 0); /* try to release resources with a full GC */ + return 1; /* signal to try again the creation */ + } + +#endif + + return 0; /* else, asume errors are not due to lack of resources */ + +} + +/* }====================================================== */ + + +/* +** {====================================================== +** Userdata's metatable manipulation +** ======================================================= +*/ + LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, const char *const lst[]) { const char *name = (def) ? luaL_optstring(L, narg, def) : diff --git a/src/blua/lauxlib.h b/src/blua/lauxlib.h index befdae303..c5de212c8 100644 --- a/src/blua/lauxlib.h +++ b/src/blua/lauxlib.h @@ -95,6 +95,8 @@ LUALIB_API FUNCREPORT int (luaL_error) (lua_State *L, const char *fmt, ...); LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, const char *const lst[]); +LUALIB_API int (luaL_resourcetryagain) (lua_State *L); + LUALIB_API int (luaL_ref) (lua_State *L, int t); LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); diff --git a/src/blua/liolib.c b/src/blua/liolib.c index 929937e2e..2cd8dd481 100644 --- a/src/blua/liolib.c +++ b/src/blua/liolib.c @@ -58,12 +58,6 @@ static int pushresult (lua_State *L, int i, const char *filename) { } -static void fileerror (lua_State *L, int arg, const char *filename) { - lua_pushfstring(L, "%s: %s", filename, strerror(errno)); - luaL_argerror(L, arg, lua_tostring(L, -1)); -} - - #define tofilep(L) ((FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE)) @@ -165,6 +159,24 @@ static int StartsWith(const char *a, const char *b) // this is wolfs being lazy return 0; } +/* +** Equivalent to 'fopen', but if it fails due to a lack of resources +** (see 'luaL_resourcetryagain'), do an "emergency" garbage collection to try +** to close some files and then tries to open the file again. +*/ +static FILE *trytoopen (lua_State *L, const char *path, const char *mode) { + FILE *f = fopen(path, mode); + if (f == NULL && luaL_resourcetryagain(L)) /* resource failure? */ + f = fopen(path, mode); /* try to open again */ + return f; +} + +static void opencheck (lua_State *L, const char *fname, const char *mode) { + FILE **p = newfile(L); + *p = trytoopen(L, fname, mode); + if (l_unlikely(*p == NULL)) + luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); +} static int io_open(lua_State *L) { @@ -212,7 +224,7 @@ static int io_open(lua_State *L) } pf = newfile(L); - *pf = fopen(destFilename, mode); + *pf = trytoopen(L, destFilename, mode); return (*pf == NULL) ? pushresult(L, 0, filename) : 1; } @@ -220,6 +232,8 @@ static int io_open(lua_State *L) static int io_tmpfile (lua_State *L) { FILE **pf = newfile(L); *pf = tmpfile(); + if (*pf == NULL && luaL_resourcetryagain(L)) /* resource failure? */ + *pf = tmpfile(); /* try to open again */ return (*pf == NULL) ? pushresult(L, 0, NULL) : 1; } @@ -238,10 +252,7 @@ static int g_iofile (lua_State *L, int f, const char *mode) { if (!lua_isnoneornil(L, 1)) { const char *filename = lua_tostring(L, 1); if (filename) { - FILE **pf = newfile(L); - *pf = fopen(filename, mode); - if (l_unlikely(*pf == NULL)) - fileerror(L, 1, filename); + opencheck(L, filename, mode); } else { tofile(L); /* check that it's a valid file handle */ @@ -290,10 +301,7 @@ static int io_lines (lua_State *L) { } else { const char *filename = luaL_checkstring(L, 1); - FILE **pf = newfile(L); - *pf = fopen(filename, "r"); - if (l_unlikely(*pf == NULL)) - fileerror(L, 1, filename); + opencheck(L, filename, "r"); aux_lines(L, lua_gettop(L), 1); return 1; } diff --git a/src/command.c b/src/command.c index d12ae5d49..6b71dce73 100644 --- a/src/command.c +++ b/src/command.c @@ -57,7 +57,6 @@ static void CV_EnforceExecVersion(void); static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr); static boolean CV_Command(void); -consvar_t *CV_FindVar(const char *name); static const char *CV_StringValue(const char *var_name); static consvar_t *consvar_vars; // list of registered console variables @@ -238,10 +237,13 @@ void COM_ImmedExecute(const char *ptext) char line[1024] = ""; INT32 quotes; - while (i < strlen(ptext)) + const size_t txtlength = strlen(ptext); + + while (i < txtlength) { quotes = 0; - for (j = 0; i < strlen(ptext); i++,j++) + + for (j = 0; i < txtlength; i++,j++) { if (ptext[i] == '\"' && !quotes && i > 0 && ptext[i-1] != ' ') // Malformed command return; @@ -653,7 +655,7 @@ static void COM_Alias_f(void) CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); int count = 0; - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { if (strncmp(begin, head->name, szBegin) == 0) { @@ -674,7 +676,7 @@ static void COM_Alias_f(void) /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { CONS_Printf(alias_format, head->name, head->value); } diff --git a/src/console.c b/src/console.c index 2757b22e7..88fe25000 100644 --- a/src/console.c +++ b/src/console.c @@ -33,6 +33,8 @@ #include "d_main.h" #include "m_menu.h" #include "m_textinput.h" +#include "m_emotes.h" +#include "i_time.h" #include "filesrch.h" #ifdef HWRENDER @@ -167,6 +169,8 @@ static CV_PossibleValue_t menuhighlight_cons_t[] = }; consvar_t cons_menuhighlight = {"menuhighlight", "Gametype Default", CV_SAVE, menuhighlight_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cons_consoleprintinmenu = {"consoleprintinmenu", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static void CON_Print(char *msg); // @@ -424,6 +428,7 @@ void CON_Init(void) CV_RegisterVar(&cons_backpic); CV_RegisterVar(&cons_backcolor); CV_RegisterVar(&cons_menuhighlight); + CV_RegisterVar(&cons_consoleprintinmenu); COM_AddCommand("bind", CONS_Bind_f); } else @@ -584,12 +589,18 @@ static void CON_ChangeHeight(void) // Handles Console moves in/out of screen (per frame) // -static void CON_MoveConsole(void) +void CON_MoveConsole(void) { static fixed_t fracmovement = 0; Lock_state(); + if (con_curlines == con_destlines) + { + Unlock_state(); + return; + } + // instant if (!cons_speed.value) { @@ -1453,7 +1464,18 @@ static void CON_DrawHudlines(void) } if (c >= con_width) break; - if (*p < HU_FONTSTART) + + int emotelen; + emote_t *emote; + + if ((emote = M_VerifyEmote((const char *)p, &emotelen))) + { + M_DrawScaledEmote(x<= con_width) break; + + int emotelen; + emote_t *emote; + + if ((emote = M_VerifyEmote((const char *)p, &emotelen))) + { + M_DrawScaledEmote(x< 0) CON_DrawConsole(); else if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_CUTSCENE || gamestate == GS_CREDITS - || gamestate == GS_VOTING || gamestate == GS_EVALUATION || gamestate == GS_WAITINGPLAYERS) + || gamestate == GS_VOTING || gamestate == GS_EVALUATION || gamestate == GS_WAITINGPLAYERS || (cons_consoleprintinmenu.value && gamestate == GS_TITLESCREEN)) CON_DrawHudlines(); Unlock_state(); diff --git a/src/console.h b/src/console.h index 79af2e48f..a16ef47b6 100644 --- a/src/console.h +++ b/src/console.h @@ -36,6 +36,7 @@ extern INT32 con_destlines; extern UINT32 con_scalefactor; // console text scale factor extern consvar_t cons_backcolor, cons_menuhighlight; +extern consvar_t cons_consoleprintinmenu; extern UINT8 *yellowmap, *purplemap, *greenmap, *bluemap, *graymap, *redmap, *orangemap,\ *skymap, *goldmap, *lavendermap, *teamap, *steelmap, *pinkmap, *brownmap, *peachmap; @@ -51,6 +52,7 @@ void CON_ClearHUD(void); // clear heads up messages void CON_Ticker(void); void CON_Drawer(void); +void CON_MoveConsole(void); void CONS_Error(const char *msg); // print out error msg, and wait a key // force console to move out diff --git a/src/d_clisrv.c b/src/d_clisrv.c index b7ea0f472..6cf50a4d3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -53,6 +53,8 @@ #include "m_perfstats.h" #include "d_main.h" #include "r_fps.h" +#include "filesrch.h" // refreshdirmenu + // cl loading screen #include "v_video.h" @@ -121,7 +123,7 @@ UINT32 realpingtable[MAXPLAYERS] = {}; //the base table of ping where an average UINT32 playerpingtable[MAXPLAYERS] = {}; //table of player latency values. #define GENTLEMANSMOOTHING (TICRATE) -static tic_t reference_lag; +static tic_t reference_lag = 0; static UINT8 spike_time; tic_t lowest_lag = 0; tic_t simulated_lag = 0; @@ -505,10 +507,12 @@ static void ExtraDataTicker(void) } // If you are a client, you can safely forget the net commands for this tic - // If you are the server, you need to remember them until every client has been aknowledged, - // because if you need to resend a PT_SERVERTICS packet, you need to put the commands in it + // If you are the server, you need to remember them until every client has been acknowledged, + // because if you need to resend a PT_SERVERTICS packet, you will need to put the commands in it if (client) + { D_FreeTextcmd(gametic); + } } static void D_Clearticcmd(tic_t tic) @@ -1367,10 +1371,19 @@ static inline void CL_DrawConnectionStatus(void) V_DrawThinString(12 + 80, 58, V_ALLOWLOWERCASE|V_YELLOWMAP, "Vanilla"); } - if (serverlist[joinnode].info.cheatsenabled) + const UINT8 serverkartspeed = (serverlist[joinnode].info.kartvars & SV_SPEEDMASK); + + if (serverkartspeed == 2) + V_DrawRightAlignedThinString(BASEVIDWIDTH - 12, 58, V_ALLOWLOWERCASE|V_REDMAP, "Hard Speed"); + else if (serverkartspeed == 1) + V_DrawRightAlignedThinString(BASEVIDWIDTH - 12, 58, V_ALLOWLOWERCASE|V_BLUEMAP, "Normal Speed"); + else + V_DrawRightAlignedThinString(BASEVIDWIDTH - 12, 58, V_ALLOWLOWERCASE|V_GREENMAP, "Easy Speed"); + + /*if (serverlist[joinnode].info.cheatsenabled) { V_DrawRightAlignedThinString(BASEVIDWIDTH - 12, 58, V_ALLOWLOWERCASE|V_GREENMAP, "Cheats"); - } + }*/ V_DrawFill(8, 72, BASEVIDWIDTH - 16, 112, 239); @@ -1390,10 +1403,16 @@ static inline void CL_DrawConnectionStatus(void) if (playerinfo[i].node < 255) { strncpy(player_name, playerinfo[i].name, MAXPLAYERNAME); - V_DrawThinString(x + 10, y, V_ALLOWLOWERCASE|V_6WIDTHSPACE, player_name); + + // if we get a skin color + // try to colourize the player name + if (playerinfo[i].data > 0 && playerinfo[i].data < MAXSKINCOLORS) + V_DrawThinString(x + 10, y, V_ALLOWLOWERCASE|V_6WIDTHSPACE, va("%s%s ", HU_SkinColorToConsoleColor(playerinfo[i].data), player_name)); + else + V_DrawThinString(x + 10, y, V_ALLOWLOWERCASE|V_6WIDTHSPACE, player_name); if (playerinfo[i].team == 0) { statuscolor = 184; } // playing - if (playerinfo[i].data & 0x20) { statuscolor = 86; } // tag IT + //if (playerinfo[i].data & 0x20) { statuscolor = 86; } // tag IT if (playerinfo[i].team == 1) { statuscolor = 128; } // ctf red team if (playerinfo[i].team == 2) { statuscolor = 232; } // ctf blue team if (playerinfo[i].team == 255) { statuscolor = 16; } // spectator or non-team @@ -1438,12 +1457,14 @@ static inline void CL_DrawConnectionStatus(void) V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, dldlength, 8, 160); memset(tempname, 0, sizeof(tempname)); + // offset filename to just the name only part filename += strlen(filename) - nameonlylength(filename); + const size_t filenamelength = strlen(filename); - if (strlen(filename) > sizeof(tempname)-1) // too long to display fully + if (filenamelength > sizeof(tempname)-1) // too long to display fully { - size_t endhalfpos = strlen(filename)-10; + size_t endhalfpos = filenamelength-10; // display as first 14 chars + ... + last 10 chars // which should add up to 27 if our math(s) is correct snprintf(tempname, sizeof(tempname), "%.14s...%.10s", filename, filename+endhalfpos); @@ -1736,16 +1757,19 @@ static void SV_SendPlayerInfo(INT32 node) // Extra data // Kart has extra skincolors, so we can't use this - netbuffer->u.playerinfo[i].data = 0; //netbuffer->u.playerinfo[i].data = players[i].skincolor; + //netbuffer->u.playerinfo[i].data = 0; //netbuffer->u.playerinfo[i].data = players[i].skincolor; - if (players[i].pflags & PF_TAGIT) - netbuffer->u.playerinfo[i].data |= 0x20; + // well why not, we only got like 100 of these? + netbuffer->u.playerinfo[i].data = players[i].skincolor; - if (players[i].gotflag) - netbuffer->u.playerinfo[i].data |= 0x40; + //if (players[i].pflags & PF_TAGIT) + //netbuffer->u.playerinfo[i].data |= 0x20; - if (players[i].powers[pw_super]) - netbuffer->u.playerinfo[i].data |= 0x80; + //if (players[i].gotflag) + //netbuffer->u.playerinfo[i].data |= 0x40; + + //if (players[i].powers[pw_super]) + //netbuffer->u.playerinfo[i].data |= 0x80; } HSendPacket(node, false, 0, sizeof(plrinfo) * MSCOMPAT_MAXPLAYERS); @@ -1753,6 +1777,9 @@ static void SV_SendPlayerInfo(INT32 node) static void SV_SendMapIcon(INT32 node) { + if (node == 0) + return; + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); const char *map = va("%sP", G_BuildMapName(gamemap)); @@ -1928,7 +1955,7 @@ static boolean SV_ResendingSavegameToAnyone(void) static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; - savebuffer_t save; + savebuffer_t save = {0}; UINT8 *compressedsave; UINT8 *buffertosend; @@ -1998,7 +2025,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O static void SV_SavedGame(void) { size_t length; - savebuffer_t save; + savebuffer_t save = {0}; char tmpsave[264]; if (!cv_dumpconsistency.value) @@ -2038,7 +2065,7 @@ static void SV_SavedGame(void) static void CL_LoadReceivedSavegame(boolean reloading) { - savebuffer_t save; + savebuffer_t save = {0}; size_t length, decompressedlen; char tmpsave[264]; @@ -2047,6 +2074,7 @@ static void CL_LoadReceivedSavegame(boolean reloading) length = FIL_ReadFile(tmpsave, &save.buffer); CONS_Printf(M_GetText("Loading savegame length %s\n"), sizeu1(length)); + if (!length) { I_Error("Can't read savegame sent"); @@ -2130,7 +2158,7 @@ static void CL_ReloadReceivedSavegame(void) // we dont have P_ForceLocalAngle so were setting it manually here for (i = 0; i <= splitscreen; i++) { - localangle[i] = (angle_t)(players[displayplayers[i]].cmd.angleturn << 16); + P_ForceLocalAngle(&players[displayplayers[i]], (angle_t)(players[displayplayers[i]].cmd.angleturn << TICCMD_REDUCE)); } for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) @@ -2169,12 +2197,8 @@ static void SendAskInfo(INT32 node) HSendPacket(node, false, 0, sizeof (askinfo_pak)); } -serverelem_t serverlist[MAXSERVERLIST]; +serverelem_t serverlist[MAXSERVERLIST] = {}; UINT32 serverlistcount = 0; -UINT32 serverlistultimatecount = 0; - -static boolean resendserverlistnode[MAXNETNODES]; -static tic_t serverlistepoch; static void SL_ClearServerList(INT32 connectedserver) { @@ -2187,8 +2211,7 @@ static void SL_ClearServerList(INT32 connectedserver) serverlist[i].node = 0; } serverlistcount = 0; - - memset(resendserverlistnode, 0, sizeof resendserverlistnode); + //memset(serverlist, 0, sizeof(serverlist)); } static UINT32 SL_SearchServer(INT32 node) @@ -2205,8 +2228,6 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) { UINT32 i; - resendserverlistnode[node] = false; - // search if not already on it i = SL_SearchServer(node); if (i == UINT32_MAX) @@ -2240,7 +2261,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) M_SortServerList(); } -void CL_UpdateServerList (void) +void CL_UpdateServerList(void) { SL_ClearServerList(0); @@ -2258,14 +2279,12 @@ void CL_UpdateServerList (void) SendAskInfo(BROADCASTADDR); } -void CL_QueryServerList (msg_server_t *server_list) +void CL_QueryServerList(msg_server_t *server_list) { INT32 i; CL_UpdateServerList(); - serverlistepoch = I_GetTime(); - for (i = 0; server_list[i].header.buffer[0]; i++) { // Make sure MS version matches our own, to @@ -2278,42 +2297,20 @@ void CL_QueryServerList (msg_server_t *server_list) if (node == -1) continue; // no more node free, or resolution failure SendAskInfo(node); - resendserverlistnode[node] = true; - // Leave this node open. It'll be closed if the - // request times out (CL_TimeoutServerList). - } - } - serverlistultimatecount = i; -} - -#define SERVERLISTRESENDRATE NEWTICRATE - -void CL_TimeoutServerList(void) -{ - if (netgame && serverlistultimatecount > serverlistcount) - { - const tic_t timediff = I_GetTime() - serverlistepoch; - const tic_t timetoresend = timediff % SERVERLISTRESENDRATE; - const boolean timedout = timediff > connectiontimeout; - - if (timedout || (timediff > 0 && timetoresend == 0)) - { - INT32 node; - - for (node = 1; node < MAXNETNODES; ++node) - { - if (resendserverlistnode[node]) - { - if (timedout) - Net_CloseConnection(node|FORCECLOSE); - else - SendAskInfo(node); - } - } - - if (timedout) - serverlistultimatecount = serverlistcount; + // Force close the connection so that servers can't eat + // up nodes forever if we never get a reply back from them + // (usually when they've not forwarded their ports). + // + // Don't worry, we'll get in contact with the working + // servers again when they send SERVERINFO to us later! + // + // (Note: as a side effect this probably means every + // server in the list will probably be using the same node (e.g. node 1), + // not that it matters which nodes they use when + // the connections are closed afterwards anyway) + // -- Monster Iestyn 12/11/18 + Net_CloseConnection(node|FORCECLOSE); } } } @@ -3480,6 +3477,9 @@ void CL_Reset(void) memset(player_muted, 0, sizeof(player_muted)); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + // D_StartTitle should get done now, but the calling function will handle it } @@ -4268,6 +4268,9 @@ void D_ClientServerInit(void) #endif D_LoadBan(false); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + gametic = 0; localgametic = 0; @@ -4503,6 +4506,8 @@ static void Got_AddPlayer(const UINT8 **p, INT32 playernum) DEBFILE("spawning me\n"); } + P_ForceLocalAngle(&players[newplayernum], (angle_t)(players[newplayernum].cmd.angleturn << TICCMD_REDUCE)); + D_SendPlayerConfig(); addedtogame = true; } @@ -6448,6 +6453,7 @@ static void SV_SendTics(void) continue; DEBFILE(va("Sent %d anyway\n", realfirsttic)); } + realfirsttic = max(realfirsttic, firstticstosend); // compute the length of the packet and cut it if too large @@ -6593,7 +6599,8 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) // -- Monster Iestyn 16/01/18 break; } - netcmds[tic%BACKUPTICS][playernum].angleturn = (INT16)((angle>>16) | TICCMD_RECEIVED); + + netcmds[tic%BACKUPTICS][playernum].angleturn = (INT16)((angle >> TICCMD_REDUCE) | TICCMD_RECEIVED); if (!tic) // failsafe for gametic == 0 -- Monster Iestyn 16/01/18 break; @@ -7175,6 +7182,7 @@ void NetUpdate(void) I_lock_mutex(&m_menu_mutex); #endif M_Ticker(); + refreshdirmenu = 0; #ifdef HAVE_THREADS I_unlock_mutex(m_menu_mutex); #endif @@ -7221,7 +7229,7 @@ void CL_ClearRewinds(void) rewind_t *CL_SaveRewindPoint(size_t demopos) { - savebuffer_t save; + savebuffer_t save = {0}; rewind_t *rewind; if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) @@ -7244,7 +7252,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) rewind_t *CL_RewindToTime(tic_t time) { - savebuffer_t save; + savebuffer_t save = {0}; rewind_t *rewind; while (rewindhead && rewindhead->leveltime > time) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 5919b54ce..430729bc2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -516,7 +516,6 @@ typedef struct extern serverelem_t serverlist[MAXSERVERLIST]; extern UINT32 serverlistcount; -extern UINT32 serverlistultimatecount; extern INT32 mapchangepending; // Points inside doomcom @@ -627,7 +626,6 @@ void CL_ClearPlayer(INT32 playernum); void CL_RemovePlayer(INT32 playernum, INT32 reason); void CL_QueryServerList(msg_server_t *list); void CL_UpdateServerList(void); -void CL_TimeoutServerList(void); void CL_AbortConnection(void); diff --git a/src/d_main.c b/src/d_main.c index ba34eb66e..c46ef0c44 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -46,6 +46,7 @@ #include "i_time.h" #include "i_threads.h" #include "i_video.h" +#include "hu_stuff.h" #include "m_argv.h" #include "m_menu.h" #include "m_misc.h" @@ -69,7 +70,7 @@ #include "fastcmp.h" #include "r_fps.h" // Frame interpolation/uncapped #include "keys.h" -#include "filesrch.h" // refreshdirmenu, pathisdirectory +#include "filesrch.h" // pathisdirectory #include "d_protocol.h" #include "m_perfstats.h" #include "k_kart.h" @@ -166,38 +167,6 @@ UINT8 ctrldown = 0; // 0x1 left, 0x2 right UINT8 altdown = 0; // 0x1 left, 0x2 right boolean capslock = 0; // gee i wonder what this does. -static UINT16 curcolor[MAXSPLITSCREENPLAYERS] = {}; - -static void D_DeviceLEDTick(void) -{ - UINT8 i; - static UINT16 color[MAXSPLITSCREENPLAYERS] = {}; - - if (numcontrollers == 0) - { - return; - } - - for (i = 0; i <= splitscreen; i++) - { - if (!cv_usejoystick[i].value || !cv_gamepadled[i].value) - continue; - - color[i] = G_GetSkinColor(i); - - if (curcolor[i] == color[i]) // dont update if same colour - continue; - - G_SetPlayerGamepadIndicatorColor(i, color[i]); - curcolor[i] = color[i]; - } -} - -void D_ResetDeviceLED(void) -{ - memset(curcolor, 0, sizeof(curcolor)); -} - // // D_ProcessEvents // Send all the events of the given timestamp down the responder chain @@ -359,13 +328,12 @@ static void D_Renderview(void) if (splitscreen == 2) { // V_DrawPatchFill, but for the fourth screen only - patch_t *pat = W_CachePatchName("SRB2BACK", PU_PATCH); - INT32 x, y, pw = SHORT(pat->width) * vid.dup, ph = SHORT(pat->height) * vid.dup; + INT32 x, y, pw = SHORT(srb2back->width) * vid.dup, ph = SHORT(srb2back->height) * vid.dup; for (x = vid.width>>1; x < vid.width; x += pw) { for (y = vid.height>>1; y < vid.height; y += ph) - V_DrawScaledPatch(x, y, V_NOSCALESTART, pat); + V_DrawScaledPatch(x, y, V_NOSCALESTART, srb2back); } } @@ -407,10 +375,6 @@ static boolean D_Display(void) R_ExecuteSetViewSize(); forcerefresh = true; // force background redraw } - - // draw buffered stuff to screen - // Used only by linux GGI version - I_UpdateNoBlit(); } // save the current screen if about to wipe @@ -708,7 +672,7 @@ void D_SRB2Loop(void) COM_ImmedExecute("cls;version"); if (rendermode == render_soft) - V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_PATCH_LOWPRIORITY), NULL); + V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_PATCH), NULL); I_FinishUpdate(); // page flip or blit buffer precision = I_GetPrecisePrecision(); @@ -761,8 +725,6 @@ void D_SRB2Loop(void) renderisnewtic = (realtics > 0 || singletics); - refreshdirmenu = 0; // not sure where to put this, here as good as any? - if (renderisnewtic) { // don't skip more than 10 frames at a time @@ -799,7 +761,7 @@ void D_SRB2Loop(void) if (!dedicated) { - D_DeviceLEDTick(); + G_DeviceLEDTick(); } } @@ -830,9 +792,9 @@ void D_SRB2Loop(void) } else if (!dedicated) { - // always update console and hud - // otherwise it may take minutes to open it - CON_Drawer(); + // always update console movement + // otherwise it will takes literal ages to open + CON_MoveConsole(); } } @@ -923,7 +885,6 @@ void D_ClearState(void) CURLAbortFile(); SV_StopServer(); SV_ResetServer(); - serverlistultimatecount = 0; for (i = 0; i < MAXPLAYERS; i++) CL_ClearPlayer(i); @@ -977,7 +938,7 @@ void D_ClearState(void) M_ClearMenus(true); // map palettes affect this - D_ResetDeviceLED(); + G_ResetDeviceLED(); } // @@ -1218,8 +1179,10 @@ static void IdentifyVersion(void) const char *srb2waddir = NULL; #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) + CLEANUP(pfree) const char *allocwaddir = NULL; // here so we dont potentially free stack memory // change to the directory where 'srb2.srb' is found - srb2waddir = I_LocateWad(); + allocwaddir = I_LocateWad(); + srb2waddir = allocwaddir; #endif char tempsrb2path[256] = "."; diff --git a/src/d_main.h b/src/d_main.h index d9954a5b0..8f1475706 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -80,8 +80,6 @@ void D_ProcessEvents(void); const char *D_Home(void); -void D_ResetDeviceLED(void); - // // BASE LEVEL // diff --git a/src/d_net.c b/src/d_net.c index ba70cb7c1..59b31a1fb 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -492,6 +492,7 @@ void Net_AckTicker(void) ackpak[i].acknum = 0; continue; } + DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, NODETIMEOUT, I_GetTime())); memcpy(netbuffer, ackpak[i].pak.raw, ackpak[i].length); @@ -1224,7 +1225,7 @@ void D_SetDoomcom(void) if (doomcom) return; - doomcom = Z_Calloc(sizeof (doomcom_t), PU_STATIC, NULL); + doomcom = Z_Calloc(sizeof(doomcom_t), PU_STATIC, NULL); doomcom->id = DOOMCOM_ID; doomcom->numslots = doomcom->numnodes = 1; } @@ -1266,6 +1267,7 @@ boolean D_CheckNetGame(void) ret = true; if (client && netgame) netgame = false; + server = true; // WTF? server always true??? // no! The deault mode is server. Client is set elsewhere // when the client executes connect command. @@ -1301,6 +1303,7 @@ boolean D_CheckNetGame(void) if (doomcom->id != DOOMCOM_ID) I_Error("Doomcom buffer invalid!"); + if (doomcom->numnodes > MAXNETNODES) I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES); @@ -1309,14 +1312,17 @@ boolean D_CheckNetGame(void) { char filename[21]; INT32 k = doomcom->consoleplayer - 1; + if (M_IsNextParm()) k = atoi(M_GetNextParm()) - 1; + while (!debugfile && k < MAXPLAYERS) { k++; sprintf(filename, "debug%d.txt", k); debugfile = fopen(va("%s" PATHSEP "%s", srb2home, filename), "w"); } + if (debugfile) CONS_Printf(M_GetText("debug output to: %s\n"), va("%s" PATHSEP "%s", srb2home, filename)); else diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 6d90e4d4e..c669da59b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -144,6 +144,7 @@ static void Command_Addfile(void); static void Command_Addskins(void); static void Command_GLocalSkin(void); static void Command_ListWADS_f(void); +static void Command_LocateLump_f(void); static void Command_ListDoomednums_f(void); static void Command_ListUnusedSprites_f(void); static void Command_RunSOC(void); @@ -270,11 +271,11 @@ consvar_t cv_skin4 = {"skin4", DEFAULTSKIN4, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Sk // haha I've beaten you now, ONLINE consvar_t cv_localskin = {"internal___localskin", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showlocalskinmenus = {"showlocalskinmenus", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showlocalskinmenus = {"showlocalskinmenus", "Yes", CV_SAVE|CV_CALL, CV_YesNo, ShowLocalskinMenu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -INT32 cv_debug; +INT32 cv_debug = 0; static void UseMouse_OnChange(void); consvar_t cv_usemouse = {"use_mouse", "Off", CV_SAVE|CV_CALL, usemouse_cons_t, UseMouse_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -531,7 +532,7 @@ boolean forceresetplayers = false; boolean deferencoremode = false; UINT8 splitscreen = 0; boolean circuitmap = true; // SRB2kart -INT32 adminplayers[MAXPLAYERS]; +INT32 adminplayers[MAXPLAYERS] = {}; /// \warning Keep this up-to-date if you add/remove/rename net text commands const char *netxcmdnames[MAXNETXCMD - 1] = @@ -638,6 +639,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("addfile", Command_Addfile); COM_AddCommand("addskins", Command_Addskins); COM_AddCommand("listwad", Command_ListWADS_f); + COM_AddCommand("locatelump", Command_LocateLump_f); COM_AddCommand("listmapthings", Command_ListDoomednums_f); COM_AddCommand("listunusedsprites", Command_ListUnusedSprites_f); @@ -937,6 +939,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_chatbacktint); CV_RegisterVar(&cv_chatcentertext); CV_RegisterVar(&cv_songcredits); + CV_RegisterVar(&cv_pausesongcredits); CV_RegisterVar(&cv_showfreeplay); CV_RegisterVar(&cv_skinselectspin); CV_RegisterVar(&cv_showallmaps); @@ -994,15 +997,18 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_litesteer[i]); + CV_RegisterVar(&cv_autoaccel[i]); + CV_RegisterVar(&cv_usejoystick[i]); CV_RegisterVar(&cv_joyscale[i]); CV_RegisterVar(&cv_rumble[i]); + CV_RegisterVar(&cv_rumblestrength[i]); CV_RegisterVar(&cv_gamepadled[i]); } CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_invertmouse); - CV_RegisterVar(&cv_mousesens); + CV_RegisterVar(&cv_mousexsens); CV_RegisterVar(&cv_mouseysens); CV_RegisterVar(&cv_mousevisible); @@ -2588,8 +2594,7 @@ void D_PickVote(void) SendNetXCmd(XD_PICKVOTE, &buf, 2); } -static char * -ConcatCommandArgv (int start, int end) +static char *ConcatCommandArgv(int start, int end) { char *final; @@ -2647,7 +2652,6 @@ static void Command_Map_f(void) return; } - M_ClearMenus(true); last_map_cmd = I_GetTime(); @@ -2662,8 +2666,8 @@ static void Command_Map_f(void) INT32 newmapnum; - char * mapname; - char *realmapname = NULL; + CLEANUP(Z_Pfree) char * mapname = NULL; + CLEANUP(Z_Pfree) char *realmapname = NULL; INT32 newgametype = gametype; boolean newencoremode = cv_kartencore.value; @@ -2732,7 +2736,6 @@ static void Command_Map_f(void) if (newmapnum == 0) { CONS_Alert(CONS_ERROR, M_GetText("Could not find any map described as '%s'.\n"), mapname); - Z_Free(mapname); return; } @@ -2764,8 +2767,6 @@ static void Command_Map_f(void) " 0 and %d inclusive. ...Or just use the name. :v\n", d, NUMGAMETYPES-1); - Z_Free(realmapname); - Z_Free(mapname); return; } } @@ -2774,8 +2775,6 @@ static void Command_Map_f(void) CONS_Alert(CONS_ERROR, "'%s' is not a gametype.\n", gametypename); - Z_Free(realmapname); - Z_Free(mapname); return; } } @@ -2793,8 +2792,6 @@ static void Command_Map_f(void) if (!mapheaderinfo[newmapnum-1]) { CONS_Alert(CONS_WARNING, M_GetText("Invalid mapheaderinfo for Course %s (%s)\n"), realmapname, G_BuildMapName(newmapnum)); - Z_Free(realmapname); - Z_Free(mapname); return; } @@ -2802,8 +2799,6 @@ static void Command_Map_f(void) { CONS_Alert(CONS_WARNING, M_GetText("Course %s (%s) doesn't support %s mode!\n(Use -force to override)\n"), realmapname, G_BuildMapName(newmapnum), (multiplayer ? gametype_cons_t[newgametype].strvalue : "Single Player")); - Z_Free(realmapname); - Z_Free(mapname); return; } } @@ -2815,8 +2810,6 @@ static void Command_Map_f(void) if (!dedicated && M_MapLocked(newmapnum)) { CONS_Alert(CONS_NOTICE, M_GetText("You need to unlock this level before you can warp to it!\n")); - Z_Free(realmapname); - Z_Free(mapname); return; } @@ -2841,9 +2834,9 @@ static void Command_Map_f(void) fromlevelselect = false; - D_MapChange(newmapnum, newgametype, newencoremode, newresetplayers, 0, false, false); + M_ClearMenus(true); - Z_Free(realmapname); + D_MapChange(newmapnum, newgametype, newencoremode, newresetplayers, 0, false, false); } /** Receives a map command and changes the map. @@ -3911,6 +3904,7 @@ static void Got_Teamchange(const UINT8 **cp, INT32 playernum) if (G_BattleGametype()) // SRB2kart { players[playernum].marescore = 0; + if (K_IsPlayerWanted(&players[playernum])) K_CalculateBattleWanted(); } @@ -4508,7 +4502,7 @@ static void Command_Addskins(void) CONS_Printf("addskins has been deprecated\nuse addfilelocal instead!\n"); } -static void Command_GLocalSkin (void) +static void Command_GLocalSkin(void) { size_t first_option; size_t option_display; @@ -4519,7 +4513,7 @@ static void Command_GLocalSkin (void) option_display = COM_CheckPartialParm("-d"); option_all = COM_CheckPartialParm("-a"); - char* fuck; // local skin name + CLEANUP(Z_Pfree) char* fuck = NULL; // local skin name if (!(first_option = COM_FirstOption())) first_option = COM_Argc(); @@ -4560,7 +4554,6 @@ static void Command_GLocalSkin (void) CONS_Printf("Successfully applied localskin to displayed player.\n"); - Z_Free(fuck); return; } else if (option_all) // -all @@ -4575,7 +4568,6 @@ static void Command_GLocalSkin (void) } CONS_Printf("Successfully applied localskin to all players.\n"); - Z_Free(fuck); return; } else // -player or no other arguments @@ -4592,7 +4584,6 @@ static void Command_GLocalSkin (void) } CONS_Printf("Successfully applied localskin to specified player.\n"); - Z_Free(fuck); return; } else @@ -4600,13 +4591,11 @@ static void Command_GLocalSkin (void) SetLocalPlayerSkin(consoleplayer, fuck, &cv_localskin); CONS_Printf("Successfully applied localskin.\n"); - Z_Free(fuck); return; } CONS_Printf("Could not apply localskin.\n"); - Z_Free(fuck); return; } } @@ -4737,7 +4726,30 @@ static void Command_ListWADS_f(void) } } -#define MAXDOOMEDNUM 4095 +static void Command_LocateLump_f(void) +{ + if (COM_Argc() == 1) + { + CONS_Printf("Usage: locatelump [ [ ...]]\n"); + return; + } + + for (size_t i = 1; i < COM_Argc(); ++i) + { + const char *name = COM_Argv(i); + + lumpnum_t num = W_CheckNumForName(name); + + const char *wadname = "(not found)"; + + if (num != LUMPERROR) + { + wadname = wadfiles[WADFILENUM(num)]->filename; + } + + CONS_Printf("%s - %s\n", name, wadname); + } +} static void Command_ListDoomednums_f(void) { @@ -5689,7 +5701,7 @@ static void Command_Togglemodified_f(void) static void Command_Archivetest_f(void) { - savebuffer_t save; + savebuffer_t save = {0}; UINT32 i, wrote; thinker_t *th; if (gamestate != GS_LEVEL) diff --git a/src/d_netfil.c b/src/d_netfil.c index d80ae7b79..a4478fcc9 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -64,7 +64,6 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid); #ifdef HAVE_CURL -size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream); #if (LIBCURL_VERSION_MAJOR <= 7) && (LIBCURL_VERSION_MINOR < 35) static int curlprogress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); #else @@ -1080,12 +1079,14 @@ void CloseNetFile(void) // Receiving a file? for (i = 0; i < MAX_WADFILES; i++) + { if (fileneeded[i].status == FS_DOWNLOADING && fileneeded[i].file) { fclose(fileneeded[i].file); // File is not complete delete it remove(fileneeded[i].filename); } + } // Remove PT_FILEFRAGMENT from acknowledge list Net_AbortPacketType(PT_FILEFRAGMENT); @@ -1099,17 +1100,16 @@ void nameonly(char *s) void *ns; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { ns = &(s[j+1]); len = strlen(ns); -#if 0 - memcpy(s, ns, len+1); -#else - memmove(s, ns, len+1); -#endif + memmove(s, ns, len+1); + return; } + } } // Returns the length in characters of the last element of a path. @@ -1163,8 +1163,12 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet filestatus_t homecheck; // store result of last file search boolean badmd5 = false; // store whether md5 was bad from either of the first two searches (if nothing was found in the third) - // skip for startup, our mainwads wont be in there - if (loaded_config) + // see IdentifyVersion + // Iwads skip findfile due to passing fullpath to W_OpenWadFile +#if 0 + // skip for Iwads, as they wont be in there + if (!startupiwadcount) +#endif { if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0') { diff --git a/src/d_ticcmd.h b/src/d_ticcmd.h index 98e4891e3..df26aa882 100644 --- a/src/d_ticcmd.h +++ b/src/d_ticcmd.h @@ -46,15 +46,20 @@ typedef enum // Mainly movements/button commands per game tick, // plus a checksum for internal state consistency. +// ticcmd turning bits +#define TICCMD_REDUCE 16 + +// ticcmd latency mask +#define TICCMD_LATENCYMASK 0xFF + // bits in angleturn -#define TICCMD_RECEIVED 1 -#define TICCMD_XY 2 +#define TICCMD_RECEIVED (0x01) /* Actual tic recieved from client */ typedef struct { SINT8 forwardmove; // -MAXPLMOVE to MAXPLMOVE (50) SINT8 sidemove; // -MAXPLMOVE to MAXPLMOVE (50) - INT16 angleturn; // <<16 for angle delta - saved as 1 byte into demos + INT16 angleturn; // << TICCMD_REDUCE for angle delta - saved as 1 byte into demos INT16 aiming; // vertical aiming, see G_BuildTicCmd UINT16 buttons; INT16 driftturn; // SRB2Kart: Used for getting drift turn speed diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index fe8889405..4d52ffa70 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -127,16 +127,32 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include -// Locations for searching the srb2.srb +/// Locations to directly check for srb2.srb in +const char *wadDefaultPaths[] = { #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) -#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" -#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2Kart" -#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2Kart" -#define DEFAULTWADLOCATION4 "/usr/games/SRB2Kart" -#define DEFAULTSEARCHPATH1 "/usr/local/games" -#define DEFAULTSEARCHPATH2 "/usr/games" -#define DEFAULTSEARCHPATH3 "/usr/local" + "/usr/local/share/games/SRB2Kart", + "/usr/local/games/SRB2Kart", + "/usr/share/games/SRB2Kart", + "/usr/games/SRB2Kart", +#elif defined (_WIN32) + "c:\\games\\srb2kart", + "\\games\\srb2kart", #endif + NULL +}; + +// Folders to recurse through looking for srb2.srb +const char *wadSearchPaths[] = { +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + "/usr/local/games", + "/usr/games", + "/usr/local", +#elif defined (_WIN32) + "c:\\games", + "\\games", +#endif + NULL +}; /** \brief WAD file to look for */ @@ -151,6 +167,8 @@ static char returnWadPath[256]; #include "../i_video.h" #include "../i_sound.h" #include "../i_system.h" +#include "../i_time.h" +#include "../i_net.h" #include "../screen.h" //vid.WndParent #include "../d_net.h" #include "../g_game.h" @@ -180,8 +198,6 @@ UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -boolean stdin_active = true; - typedef struct { size_t cursor; @@ -683,11 +699,7 @@ void I_JoyScale4(void) */ -void I_ShutdownJoystick(void) -{ -} - -void I_GetJoystickEvents(UINT8 index) +void I_ShutdownJoystick(UINT8 index) { (void)index; } @@ -1423,20 +1435,6 @@ death: exit(0); } -void I_WaitVBL(INT32 count) -{ - count = 1; - I_Sleep(count); -} - -void I_BeginRead(void) -{ -} - -void I_EndRead(void) -{ -} - // // I_Error // @@ -1827,16 +1825,23 @@ static const char *searchWad(const char *searchDir) return tempsw; } - strcpy(tempsw, WADKEYWORD2); - fstemp = filesearch(tempsw, searchDir, NULL, true, 20); - if (fstemp == FS_FOUND) - { - pathonly(tempsw); - return tempsw; - } return NULL; } +#define CHECKWADPATH(ret) \ +do { \ + I_OutputMsg(",%s", ret); \ + if (isWadPathOk(ret)) \ + return ret; \ +} while (0) + +#define SEARCHWAD(str) \ +do { \ + WadPath = searchWad(str); \ + if (WadPath) \ + return WadPath; \ +} while (0) + /** \brief go through all possible paths and look for srb2.srb \return path to srb2.srb if any @@ -1845,6 +1850,7 @@ static const char *locateWad(void) { const char *envstr; const char *WadPath; + int i; I_OutputMsg("SRB2WADDIR"); // does SRB2WADDIR exist? @@ -1852,132 +1858,51 @@ static const char *locateWad(void) return envstr; #ifndef NOCWD - I_OutputMsg(",."); // examine current dir strcpy(returnWadPath, "."); + I_OutputMsg(",%s", returnWadPath); if (isWadPathOk(returnWadPath)) return NULL; #endif - +#ifndef NOHOME #ifdef DEFAULTDIR I_OutputMsg(",HOME/" DEFAULTDIR); // examine user jart directory if ((envstr = I_GetEnv("HOME")) != NULL) { sprintf(returnWadPath, "%s" PATHSEP DEFAULTDIR, envstr); - if (isWadPathOk(returnWadPath)) - return returnWadPath; - } -#endif - - -#ifdef CMAKECONFIG -#ifndef NDEBUG - I_OutputMsg(","CMAKE_ASSETS_DIR); - strcpy(returnWadPath, CMAKE_ASSETS_DIR); - if (isWadPathOk(returnWadPath)) - { - return returnWadPath; + CHECKWADPATH(returnWadPath); } #endif #endif #ifdef __APPLE__ OSX_GetResourcesPath(returnWadPath); - I_OutputMsg(",%s", returnWadPath); - if (isWadPathOk(returnWadPath)) - { - return returnWadPath; - } + CHECKWADPATH(returnWadPath); #endif // examine default dirs -#ifdef DEFAULTWADLOCATION1 - I_OutputMsg(","DEFAULTWADLOCATION1); - strcpy(returnWadPath, DEFAULTWADLOCATION1); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION2 - I_OutputMsg(","DEFAULTWADLOCATION2); - strcpy(returnWadPath, DEFAULTWADLOCATION2); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION3 - I_OutputMsg(","DEFAULTWADLOCATION3); - strcpy(returnWadPath, DEFAULTWADLOCATION3); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION4 - I_OutputMsg(","DEFAULTWADLOCATION4); - strcpy(returnWadPath, DEFAULTWADLOCATION4); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION5 - I_OutputMsg(","DEFAULTWADLOCATION5); - strcpy(returnWadPath, DEFAULTWADLOCATION5); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION6 - I_OutputMsg(","DEFAULTWADLOCATION6); - strcpy(returnWadPath, DEFAULTWADLOCATION6); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifdef DEFAULTWADLOCATION7 - I_OutputMsg(","DEFAULTWADLOCATION7); - strcpy(returnWadPath, DEFAULTWADLOCATION7); - if (isWadPathOk(returnWadPath)) - return returnWadPath; -#endif -#ifndef NOHOME - // find in $HOME - I_OutputMsg(",HOME/" DEFAULTDIR); - if ((envstr = I_GetEnv("HOME")) != NULL) + for (i = 0; wadDefaultPaths[i]; i++) { - char *tmp = malloc(strlen(envstr) + sizeof(PATHSEP) + sizeof(DEFAULTDIR)); - strcpy(tmp, envstr); - strcat(tmp, PATHSEP); - strcat(tmp, DEFAULTDIR); - WadPath = searchWad(tmp); - free(tmp); - if (WadPath) - return WadPath; + strcpy(returnWadPath, wadDefaultPaths[i]); + CHECKWADPATH(returnWadPath); } -#endif -#ifdef DEFAULTSEARCHPATH1 - // find in /usr/local - I_OutputMsg(", in:"DEFAULTSEARCHPATH1); - WadPath = searchWad(DEFAULTSEARCHPATH1); - if (WadPath) - return WadPath; -#endif -#ifdef DEFAULTSEARCHPATH2 - // find in /usr/games - I_OutputMsg(", in:"DEFAULTSEARCHPATH2); - WadPath = searchWad(DEFAULTSEARCHPATH2); - if (WadPath) - return WadPath; -#endif -#ifdef DEFAULTSEARCHPATH3 - // find in ??? - I_OutputMsg(", in:"DEFAULTSEARCHPATH3); - WadPath = searchWad(DEFAULTSEARCHPATH3); - if (WadPath) - return WadPath; -#endif + + // search paths + for (i = 0; wadSearchPaths[i]; i++) + { + I_OutputMsg(", in:%s", wadSearchPaths[i]); + SEARCHWAD(wadSearchPaths[i]); + } + // if nothing was found return NULL; } const char *I_LocateWad(void) { - const char *waddir; + const char *waddir = NULL; I_OutputMsg("Looking for WADs in: "); waddir = locateWad(); @@ -1987,12 +1912,15 @@ const char *I_LocateWad(void) { // change to the directory where we found srb2.srb #if defined (_WIN32) + waddir = _fullpath(NULL, waddir, MAX_PATH); SetCurrentDirectoryA(waddir); #else + waddir = realpath(waddir, NULL); if (waddir == NULL || chdir(waddir) == -1) I_OutputMsg("Couldn't change working directory\n"); #endif } + return waddir; } diff --git a/src/dedicated/i_video.c b/src/dedicated/i_video.c index 4ade52c5f..d253a7572 100644 --- a/src/dedicated/i_video.c +++ b/src/dedicated/i_video.c @@ -65,13 +65,6 @@ void I_OsPolling(void) I_GetConsoleEvents(); } -// -// I_UpdateNoBlit -// -void I_UpdateNoBlit(void) -{ -} - // // I_FinishUpdate // diff --git a/src/doomdef.h b/src/doomdef.h index 87a7d936d..492fa1185 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -107,8 +107,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v9.1" -#define VERSIONSTRINGW L"Saturn v9.1" +#define VERSIONSTRING "Saturn v9.2" +#define VERSIONSTRINGW L"Saturn v9.2" #define SATURN_TESTING // comment out for saturn release builds! @@ -477,7 +477,7 @@ extern INT32 cv_debug; // Misc stuff for later... // ======================= -#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) +#define ANG2RAD(angle) ((float)((angle)*M_PIf) / (float)ANGLE_180) // Modifier key variables, accessible anywhere extern UINT8 shiftdown, ctrldown, altdown; @@ -526,6 +526,10 @@ UINT32 quickncasehash (const char *p, size_t n) #define M_PIl 3.1415926535897932384626433832795029L #endif +#ifndef M_PIf +#define M_PIf 3.14159265f +#endif + // Floating point comparison epsilons from float.h #ifndef FLT_EPSILON #define FLT_EPSILON 1.1920928955078125e-7f diff --git a/src/doomstat.h b/src/doomstat.h index a9bd9bbac..80f86b974 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -542,7 +542,7 @@ extern mapthing_t *redctfstarts[MAXPLAYERS]; // CTF #else #define DEBUGFILE #ifdef DEBUGFILE -#define DEBFILE(msg) { if (debugfile) { fputs(msg, debugfile); fflush(debugfile); } } +#define DEBFILE(msg) { if (UNLIKELY(debugfile)) { fputs(msg, debugfile); fflush(debugfile); } } #else #define DEBFILE(msg) {} #endif diff --git a/src/doomtype.h b/src/doomtype.h index 8043b7285..ed6248129 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,11 +68,13 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif -#ifndef __cplusplus -char *strcasestr(const char *in, const char *what); -#define stristr strcasestr +char *nongnu_strcasestr(const char *in, const char *what); +#ifndef _GNU_SOURCE +#define strcasestr nongnu_strcasestr #endif +#define stristr strcasestr + #if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap #define true 1 #define false 0 diff --git a/src/f_finale.c b/src/f_finale.c index 450910021..801af8ab5 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -166,8 +166,8 @@ static void F_SkyScroll(INT32 scrollspeed) patch_t *pat, *pat2; INT32 anim2 = 0; - pat = W_CachePatchName("TITLEBG1", PU_PATCH_LOWPRIORITY); - pat2 = W_CachePatchName("TITLEBG2", PU_PATCH_LOWPRIORITY); + pat = W_CachePatchName("TITLEBG1", PU_PATCH); + pat2 = W_CachePatchName("TITLEBG2", PU_PATCH); w = (vid.scaledwidth << FRACBITS); @@ -215,9 +215,6 @@ static tic_t introscenetime[NUMINTROSCENES] = 4*TICRATE, // KART KR(eW }; -// custom intros -void F_StartCustomCutscene(INT32 cutscenenum, boolean precutscene, boolean resetplayer); - void F_StartIntro(void) { if (gamestate) @@ -257,26 +254,21 @@ void F_StartIntro(void) // void F_IntroDrawer(void) { - boolean highres = false; INT32 cx = 8, cy = 128; patch_t *background = NULL; INT32 bgxoffs = 0; + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 120); + // DRAW A FULL PIC INSTEAD OF FLAT! if (intro_scenenum == 0) { - background = W_CachePatchName("KARTKREW", PU_PATCH_LOWPRIORITY); - highres = true; - } + background = W_CachePatchName("KARTKREW", PU_PATCH); - V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 120); - - if (background) - { - if (highres) + if (background) + { V_DrawSmallScaledPatch(bgxoffs, 0, 0, background); - else - V_DrawScaledPatch(bgxoffs, 0, 0, background); + } } W_UnlockCachedPatch(background); @@ -324,6 +316,7 @@ void F_IntroTicker(void) D_StartTitle(); return; } + if (finalecount == 8) S_StartSound(NULL, sfx_vroom); else if (finalecount == 47) @@ -626,7 +619,6 @@ void F_StartCredits(void) timetonext = 2*TICRATE; } - void F_CreditDrawer(void) { UINT16 i; @@ -661,22 +653,23 @@ void F_CreditDrawer(void) // Draw credits text on top for (i = 0; credits[i]; i++) { - switch(credits[i][0]) + switch (credits[i][0]) { - case 0: - y += 80<>FRACBITS > -20) - V_DrawCreditString((160 - (V_CreditStringWidth(&credits[i][1])>>1))<>FRACBITS > -10) - V_DrawStringAtFixed(32<>FRACBITS > -20) + V_DrawCreditString((160 - (V_CreditStringWidth(&credits[i][1])>>1))<>FRACBITS > -10) + V_DrawStringAtFixed(32<>FRACBITS) * vid.dup) > vid.height) break; } @@ -701,7 +694,7 @@ void F_CreditTicker(void) // Draw credits text on top for (i = 0; credits[i]; i++) { - switch(credits[i][0]) + switch (credits[i][0]) { case 0: y += 80< + #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -246,10 +248,12 @@ void G_ReadDemoExtraData(void) { extradata = READUINT8(demobuf.p); + player_t *player = &players[p]; + if (extradata & DXD_RESPAWN) { - if (players[p].mo) - P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); // Is this how this should work..? + if (player->mo) + P_DamageMobj(player->mo, NULL, NULL, DMG_INSTAKILL); // Is this how this should work..? } if (extradata & DXD_SKIN) @@ -264,11 +268,11 @@ void G_ReadDemoExtraData(void) kartspeed = READUINT8(demobuf.p); kartweight = READUINT8(demobuf.p); - if (!fasticmp(skins[players[p].skin].name, name)) + if (!fasticmp(skins[player->skin].name, name)) FindClosestSkinForStats(p, kartspeed, kartweight); - players[p].kartspeed = kartspeed; - players[p].kartweight = kartweight; + player->kartspeed = kartspeed; + player->kartweight = kartweight; } if (extradata & DXD_COLOR) @@ -279,9 +283,9 @@ void G_ReadDemoExtraData(void) for (i = 0; i < MAXSKINCOLORS; i++) if (fasticmp(KartColor_Names[i], name)) // SRB2kart { - players[p].skincolor = i; - if (players[p].mo) - players[p].mo->color = i; + player->skincolor = i; + if (player->mo) + player->mo->color = i; break; } } @@ -300,17 +304,17 @@ void G_ReadDemoExtraData(void) switch (extradata) { case DXD_PST_PLAYING: - players[p].pflags |= PF_WANTSTOJOIN; // fuck you + player->pflags |= PF_WANTSTOJOIN; // fuck you break; case DXD_PST_SPECTATING: - players[p].pflags &= ~PF_WANTSTOJOIN; // double-fuck you + player->pflags &= ~PF_WANTSTOJOIN; // double-fuck you if (!playeringame[p]) { CL_ClearPlayer(p); playeringame[p] = true; G_AddPlayer(p); - players[p].spectator = true; + player->spectator = true; // There's likely an off-by-one error in timing recording or playback of joins. This hacks around it so I don't have to find out where that is. \o/ if (oldcmd[p].forwardmove) @@ -318,11 +322,11 @@ void G_ReadDemoExtraData(void) } else { - players[p].spectator = true; - if (players[p].mo) - P_DamageMobj(players[p].mo, NULL, NULL, DMG_INSTAKILL); + player->spectator = true; + if (player->mo) + P_DamageMobj(player->mo, NULL, NULL, DMG_INSTAKILL); else - players[p].playerstate = PST_REBORN; + player->playerstate = PST_REBORN; } break; case DXD_PST_LEFT: @@ -330,7 +334,7 @@ void G_ReadDemoExtraData(void) break; } - G_ResetViews(); + G_ResetViews(false); // dont reset our freecam pls thx! // maybe these are necessary? if (G_BattleGametype()) @@ -484,6 +488,7 @@ void G_ReadDemoTiccmd(ticcmd_t *cmd, INT32 playernum) G_CopyTiccmd(cmd, &oldcmd[playernum], 1); + // what in the actual fuck is this??? // SRB2kart: Copy-pasted from ticcmd building, removes that crappy demo cam if (((players[displayplayers[0]].mo && players[displayplayers[0]].speed > 0) // Moving || (leveltime > starttime && (cmd->buttons & BT_ACCELERATE && cmd->buttons & BT_BRAKE)) // Rubber-burn turn @@ -1131,7 +1136,29 @@ void G_GhostTicker(void) for (g = ghosts, p = NULL; g; g = g->next) { // Skip normal demo data. - UINT8 ziptic = READUINT8(g->p); + UINT8 ziptic; + + if (g->done) + { + continue; + } + + ziptic = READUINT8(g->p); + +fadeghost: + // Demo ends after ghost data. + if (ziptic == DEMOMARKER) + { + g->mo->momx = g->mo->momy = g->mo->momz = 0; + + g->done = true; + if (p) + { + p->next = g->next; + } + + continue; + } #ifdef DEMO_COMPAT_100 if (g->version != 0x0001) @@ -1139,8 +1166,14 @@ void G_GhostTicker(void) #endif while (ziptic != DW_END) // Get rid of extradata stuff { - if (ziptic == 0) // Only support player 0 info for now + if (ziptic < MAXPLAYERS) { +#ifdef DEVELOP + UINT8 playerid = ziptic; +#endif + // We want to skip *any* player extradata because some demos have extradata for bogus players, + // but if there is tic data later for those players *then* we'll consider it invalid. + ziptic = READUINT8(g->p); if (ziptic & DXD_SKIN) @@ -1152,13 +1185,26 @@ void G_GhostTicker(void) if (ziptic & DXD_NAME) g->p += 16; // yea - if (ziptic & DXD_PLAYSTATE && READUINT8(g->p) != DXD_PST_PLAYING) - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + if (ziptic & DXD_PLAYSTATE) + { + UINT8 playstate = READUINT8(g->p); + if (playstate != DXD_PST_PLAYING) + { +#ifdef DEVELOP + CONS_Alert(CONS_WARNING, "Ghost demo has non-playing playstate for player %d\n", playerid + 1); +#endif + ; + } + } } else if (ziptic == DW_RNG) + { g->p += 4; // RNG seed + } else - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + { + I_Error("Ghost is not a record attack ghost DXD (ziptic = %u)", ziptic); //@TODO lmao don't blow up like this + } ziptic = READUINT8(g->p); } @@ -1181,7 +1227,7 @@ void G_GhostTicker(void) if (ziptic & ZT_DRIFT) g->p += 2; if (ziptic & ZT_LATENCY) - g->p += 1; + g->p++; // Grab ghost data. ziptic = READUINT8(g->p); @@ -1190,10 +1236,12 @@ void G_GhostTicker(void) if (g->version != 0x0001) { #endif + if (ziptic == DEMOMARKER) // Had to end early for some reason + goto fadeghost; if (ziptic == 0xFF) goto skippedghosttic; // Didn't write ghost info this frame - else if (ziptic != 0) - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + if (ziptic != 0) + I_Error("Ghost is not a record attack ghost ZIPTIC"); //@TODO lmao don't blow up like this ziptic = READUINT8(g->p); #ifdef DEMO_COMPAT_100 } @@ -1364,7 +1412,7 @@ void G_GhostTicker(void) { #endif if (READUINT8(g->p) != 0xFF) // Make sure there isn't other ghost data here. - I_Error("Ghost is not a record attack ghost"); //@TODO lmao don't blow up like this + I_Error("Ghost is not a record attack ghost GHOSTEND"); //@TODO lmao don't blow up like this #ifdef DEMO_COMPAT_100 } #endif @@ -1384,20 +1432,6 @@ skippedghosttic: break; } - // Demo ends after ghost data. - if (*g->p == DEMOMARKER) - { - g->mo->momx = g->mo->momy = g->mo->momz = 0; - - if (p) - p->next = g->next; - else - ghosts = g->next; - - Z_Free(g); - continue; - } - p = g; } } @@ -1592,7 +1626,7 @@ void G_ConfirmRewind(tic_t rewindtime) displayplayers[2] = olddp3; displayplayers[3] = olddp4; R_ExecuteSetViewSize(); - G_ResetViews(); + G_ResetViews(true); for (i = splitscreen; i >= 0; i--) P_ResetCamera(&players[displayplayers[i]], &camera[i]); @@ -2369,49 +2403,69 @@ static long G_GetCreationTime(char *filepath) static char *G_GetDemoDate(menudemo_t *pdemo) { - char *datetime; - datetime = malloc(sizeof(pdemo->date)); // mallocma balls - - // no mallocma balls... :c - if (!datetime) - { - return NULL; - } - + char *endPos = NULL; + static char datetime[11]; time_t file_time = 0; + const char *format = NULL; + struct tm *tm_buf = NULL; + CLEANUP(pfree) char *filename = NULL; // get le filepath - char *filename; filename = strdup(pdemo->filepath); -#if defined (_WIN32) if (!filename) { - // if we cant get a filename try just getting the file create time +#if defined (_WIN32) + // if we cant get a filename try just getting the file creation time file_time = G_GetCreationTime(pdemo->filepath); goto skipfilenametime; - } #else - if (!filename) - { - free(datetime); return NULL; - } #endif + } // get the actual filename Zzz... nameonly(filename); - // convert it to long Zzz.... - file_time = strtol(filename, NULL, 10); - free(filename); // dont need this anymore a + // the first 10 characters of a replay name usually is a unix timestamp + + // not long enough to contain a valid timestamp + if (strlen(filename) < 10) + { +#if defined (_WIN32) + // try to get file creation time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; +#else + return NULL; +#endif + } + +#ifndef AVOID_ERRNO + errno = 0; +#endif + // get the timestamp as actual numbers lul + file_time = strtol(filename, &endPos, 10); + + if (endPos == filename // Empty string +#ifndef AVOID_ERRNO + || errno == ERANGE // Number out-of-range +#endif + || file_time < 0) // Number is not positive + { +#if defined (_WIN32) + // just try and get the creation time then + file_time = G_GetCreationTime(pdemo->filepath); +#else + return NULL; +#endif + } #if defined (_WIN32) skipfilenametime: #endif // then throw it into localtime to get an actual human readable format lmao - struct tm *tm_buf = NULL; tm_buf = localtime(&file_time); // cant believe we ended up in 1970 @@ -2424,14 +2478,10 @@ skipfilenametime: tm_buf = localtime(&file_time); if (tm_buf == NULL || tm_buf->tm_year <= 110) - { - free(datetime); return NULL; - } goto gotcreationtime; #else - free(datetime); return NULL; #endif } @@ -2440,17 +2490,27 @@ skipfilenametime: gotcreationtime: #endif - const char *format; - // US ppl are special (: if (cv_demodateformat.value == 2) format = "%m.%d.%Y"; else if (cv_demodateformat.value == 1) format = "%d.%m.%Y"; else - format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; + { + const char *locale = setlocale(LC_TIME, NULL); - strftime(datetime, sizeof(pdemo->date), format, tm_buf); + if (locale == NULL) + format = "%d.%m.%Y"; // fallback to non US format + else if (strstr(locale, "en_US")) + format = "%m.%d.%Y"; + else + format = "%d.%m.%Y"; + } + + if (strftime(datetime, sizeof(datetime), format, tm_buf) == 0) + { + return NULL; + } return datetime; } @@ -2459,6 +2519,7 @@ void G_LoadDemoTitle(menudemo_t *pdemo) { UINT8 infobuffer[96], *info_p; UINT16 pdemoversion; + char *demodate = NULL; size_t count; FILE *handle = fopen(pdemo->filepath, "rb"); @@ -2497,13 +2558,13 @@ void G_LoadDemoTitle(menudemo_t *pdemo) memcpy(pdemo->title, info_p, 64); // demo date - char *demodate; demodate = G_GetDemoDate(pdemo); if (demodate) - strncpy(pdemo->date, demodate, sizeof(pdemo->date)); + { + strlcpy(pdemo->date, demodate, sizeof(pdemo->date)); + } - free(demodate); break; #ifdef DEMO_COMPAT_100 case 0x0001: @@ -2580,7 +2641,7 @@ void G_DoPlayDemo(char *defdemoname) snprintf(msg, 1024, M_GetText("Failed to read file '%s'.\n"), defdemoname); CONS_Alert(CONS_ERROR, "%s", msg); gameaction = ga_nothing; - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); return; } @@ -2592,7 +2653,7 @@ void G_DoPlayDemo(char *defdemoname) snprintf(msg, 1024, M_GetText("Failed to read lump '%s'.\n"), defdemoname); CONS_Alert(CONS_ERROR, "%s", msg); gameaction = ga_nothing; - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); return; } else // it's an internal demo @@ -2612,7 +2673,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2638,7 +2699,7 @@ void G_DoPlayDemo(char *defdemoname) default: snprintf(msg, 1024, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2649,7 +2710,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s is the wrong type of recording and cannot be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2666,7 +2727,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s is an alpha multiplayer replay and cannot be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2724,7 +2785,7 @@ void G_DoPlayDemo(char *defdemoname) CONS_Alert(CONS_ERROR, "%s", msg); if (!CON_Ready()) // In the console they'll just see the notice there! No point pulling them out. - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; @@ -2762,6 +2823,16 @@ void G_DoPlayDemo(char *defdemoname) #endif demobuf.p += 4; // Extrainfo location + // ...*map* not loaded? + if (!gamemap || (gamemap > NUMMAPS) || (W_CheckNumForName(G_BuildMapName(gamemap)) == LUMPERROR)) + { + snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); + G_ResetDemoPlayback(); + return; + } + #ifdef DEMO_COMPAT_100 if (demo.version == 0x0001) { @@ -2789,7 +2860,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s features a character that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2799,7 +2870,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2822,7 +2893,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2860,7 +2931,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s contains no data to be played.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2909,7 +2980,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with spectators, and is thus invalid.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -2921,7 +2992,7 @@ void G_DoPlayDemo(char *defdemoname) { snprintf(msg, 1024, M_GetText("%s is a Record Attack replay with multiple players, and is thus invalid.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); - M_StartMessage(msg, NULL, MM_NOTHING); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); G_ResetDemoPlayback(); return; } @@ -3531,7 +3602,6 @@ void G_FreeGhosts(void) ghosts = NULL; } - boolean G_CheckDemoStatus(void) { G_FreeGhosts(); diff --git a/src/g_demo.h b/src/g_demo.h index 3ce32c054..5e430a2e8 100644 --- a/src/g_demo.h +++ b/src/g_demo.h @@ -149,6 +149,7 @@ typedef struct demoghost { UINT8 checksum[16]; UINT8 *buffer, *p, color; UINT16 version; + boolean done; mobj_t oldmo, *mo; struct demoghost *next; } demoghost; diff --git a/src/g_game.c b/src/g_game.c index bafd63f3c..2d2a49461 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -276,12 +276,6 @@ UINT32 timesBeatenWithEmeralds = 0; INT16 prevmap = 0, nextmap = 0; -// Analog Control -void SendWeaponPref(void); -void SendWeaponPref2(void); -void SendWeaponPref3(void); -void SendWeaponPref4(void); - // don't mind me putting these here, I was lazy to figure out where else I could put those without blowing up the compiler. // chat timer thingy @@ -318,6 +312,8 @@ consvar_t cv_pauseifunfocused = {"pauseifunfocused", "Yes", CV_SAVE, CV_YesNo, N static CV_PossibleValue_t songcredits_cons_t[] = {{0, "Off"}, {1, "Default"}, {2, "Box"}, {0, NULL}}; consvar_t cv_songcredits = {"songcredits", "Default", CV_SAVE, songcredits_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pausesongcredits = {"pausesongcredits", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // Show "FREE PLAY" when you're alone. :( consvar_t cv_showfreeplay = { "showfreeplay", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -458,6 +454,14 @@ consvar_t cv_litesteer[MAXSPLITSCREENPLAYERS] = { {"litesteer4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} }; +//static CV_PossibleValue_t autoaccelcons_t[] = {{0, "Off"}, {1, "Manual"}, {2, "Automatic"}, {0, NULL}}; +consvar_t cv_autoaccel[MAXSPLITSCREENPLAYERS] = { + {"autoaccel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel3", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"autoaccel4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} +}; + static CV_PossibleValue_t driftsparkpulse_t[] = {{0, "MIN"}, {FRACUNIT*3, "MAX"}, {0, NULL}}; consvar_t cv_driftsparkpulse = {"driftsparkpulse", "1.4", CV_FLOAT | CV_SAVE, driftsparkpulse_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -668,7 +672,7 @@ INT16 G_ClipAimingPitch(INT32 *aiming) else if (*aiming < -limitangle) *aiming = -limitangle; - return (INT16)((*aiming)>>16); + return (INT16)((*aiming) >> TICCMD_REDUCE); } INT16 G_SoftwareClipAimingPitch(INT32 *aiming) @@ -681,7 +685,7 @@ INT16 G_SoftwareClipAimingPitch(INT32 *aiming) else if (*aiming < -limitangle) *aiming = -limitangle; - return (INT16)((*aiming)>>16); + return (INT16)((*aiming) >> TICCMD_REDUCE); } INT32 JoyAxis(axis_input_e axissel, UINT8 player) @@ -804,6 +808,10 @@ static fixed_t forwardmove[2] = {25<>16, 50<>16}; static fixed_t sidemove[2] = {2<>16, 4<>16}; static fixed_t angleturn[3] = {KART_FULLTURN/2, KART_FULLTURN, KART_FULLTURN/4}; // + slow turn +// +// G_HandleLocalDriftturn +// Hack for Lua menus that check directional inputs with driftturn +// static void G_HandleLocalDriftturn(ticcmd_t *cmd, UINT8 ssplayer) { INT32 axis = 0; @@ -866,9 +874,8 @@ static void G_HandleLocalDriftturn(ticcmd_t *cmd, UINT8 ssplayer) // static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) { - boolean moveinput = false; INT32 axis = 0; - const boolean usejoystick = (cv_usejoystick[(ssplayer-1)].value); + const boolean usejoystick = cv_usejoystick[(ssplayer-1)].value; // check for inputs and return button commands // for stuff like joining with item button, saltyhop, honking, etc. @@ -903,15 +910,11 @@ static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) #undef CHECKINPUT - moveinput = (InputDown(gc_turnleft, ssplayer) || InputDown(gc_turnright, ssplayer) - || InputDown(gc_aimforward, ssplayer) || InputDown(gc_aimbackward, ssplayer) || - (usejoystick && JoyAxis(AXISAIM, ssplayer) != 0) || (usejoystick && JoyAxis(AXISTURN, ssplayer) != 0)); - axis = JoyAxis(AXISLOOKBACK, ssplayer); camspin[ssplayer-1] = (InputDown(gc_lookback, ssplayer) || (usejoystick && axis > 0)); // Reset to our spec player if we watch someone else. - if ((moveinput || cmd->buttons) + if ((cmd->driftturn || cmd->buttons) && displayplayers[0] != consoleplayer && ssplayer == 1) { if (cv_director.value) @@ -923,6 +926,63 @@ static void G_BuildLocalTiccmd(ticcmd_t *cmd, UINT8 ssplayer, boolean freecam) } } +// +// G_HandleAutoAcceleration +// +static void G_HandleAutoAcceleration(ticcmd_t *cmd, player_t *player, UINT8 forplayer) +{ + if (!cv_autoaccel[forplayer].value) + return; + + if (gamestate != GS_LEVEL) + return; + + // dont accel before and during countdown + if (leveltime <= starttime) + return; + + // dont do this in menus or when console is onscreen + if (menuactive || CON_Ready()) + return; + + // gotta have a player that aint respawning + if (!player->mo || player->kartstuff[k_respawn]) + return; + + // dont need for "finished" players + if (player->exiting || (player->pflags & PF_TIMEOVER)) + return; + + // dont do during spinout + if (player->kartstuff[k_spinouttimer]) + return; + + // spectators and freecam dont need special handling, see G_BuildTiccmd + + if (cmd->buttons & BT_BRAKE) + { + if (cmd->buttons & BT_DRIFT || + player->kartstuff[k_sneakertimer] || + player->kartstuff[k_squishedtimer]) + { + cmd->forwardmove = (SINT8)forwardmove[0]; + cmd->buttons |= BT_ACCELERATE; + } + else + { + // allows us to drive backwards if we need to + if (cmd->forwardmove > 0) + cmd->forwardmove = 0; + cmd->buttons &= ~BT_ACCELERATE; + } + } + else + { + cmd->forwardmove = (SINT8)forwardmove[1]; + cmd->buttons |= BT_ACCELERATE; + } +} + // // G_BuildTiccmd // Builds a ticcmd from all of the available inputs @@ -965,7 +1025,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) // Kart, don't build a ticcmd if someone is resynching or the server is stopped too so we don't fly off course in bad conditions if (paused || P_AutoPause() || (gamestate == GS_LEVEL && player->playerstate == PST_REBORN) || hu_resynching) { - cmd->angleturn = (INT16)(lang >> 16); + cmd->angleturn = (INT16)(lang >> TICCMD_REDUCE); cmd->aiming = G_ClipAimingPitch(&laim); return; } @@ -973,7 +1033,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) // dumbass thing so we can use a few buttons but dont accidentally drive away if (player->spectator || freecam) { - cmd->angleturn = (INT16)(lang >> 16); + cmd->angleturn = (INT16)(lang >> TICCMD_REDUCE); G_BuildLocalTiccmd(cmd, ssplayer, freecam); // let lua override everything @@ -1070,7 +1130,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) if (InputDown(gc_accelerate, ssplayer) || (gamepadjoystickmove && axis > 0) || player->kartstuff[k_sneakertimer]) { cmd->buttons |= BT_ACCELERATE; - forward = forwardmove[1]; // 50 + forward = forwardmove[1]; // 50 } else if (analogjoystickmove && axis > 0) { @@ -1133,7 +1193,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) cmd->aiming = G_ClipAimingPitch(&laim); - mousex = mousey = mlooky = 0; + mousex = mousey = 0; if (forward > MAXPLMOVE) forward = MAXPLMOVE; @@ -1151,6 +1211,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) cmd->sidemove = (SINT8)(cmd->sidemove + side); } + G_HandleAutoAcceleration(cmd, player, forplayer); + //{ SRB2kart - Drift support // Not grouped with the rest of turn stuff because it needs to know what buttons you're pressing for rubber-burn turn // limit turning to angleturn[1] to stop mouselook letting you look too fast @@ -1172,10 +1234,10 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) || (leveltime > starttime && (cmd->buttons & BT_ACCELERATE && cmd->buttons & BT_BRAKE)) // Rubber-burn turn || (player->kartstuff[k_respawn]) // Respawning || (player->spectator || objectplacing))) // Not a physical player - lang += (cmd->angleturn<<16); + lang += (cmd->angleturn << TICCMD_REDUCE); - cmd->angleturn = (INT16)(lang >> 16); - cmd->latency = modeattacking ? 0 : (leveltime & 0xFF); // Send leveltime when this tic was generated to the server for control lag calculations + cmd->angleturn = (INT16)(lang >> TICCMD_REDUCE); + cmd->latency = modeattacking ? 0 : (leveltime & TICCMD_LATENCYMASK); // Send leveltime when this tic was generated to the server for control lag calculations if (!hu_stopped) { @@ -1756,14 +1818,15 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) // Increment a viewpoint by offset from the current player. A negative value // decrements. // -void G_AdjustView(UINT8 viewnum, INT32 offset, boolean onlyactive) +void G_AdjustViewEx(UINT8 viewnum, INT32 offset, boolean onlyactive, boolean resetfreecam) { INT32 *displayplayerp, oldview; displayplayerp = &displayplayers[viewnum-1]; oldview = (*displayplayerp); // turn off the freecam - camera[viewnum-1].freecam = false; + if (resetfreecam) + camera[viewnum-1].freecam = false; G_ResetView(viewnum, ( (*displayplayerp) + offset ), onlyactive); @@ -1777,7 +1840,7 @@ void G_AdjustView(UINT8 viewnum, INT32 offset, boolean onlyactive) // Ensures all viewpoints are valid // Also demotes splitscreen down to one player. // -void G_ResetViews(void) +void G_ResetViews(boolean resetfreecam) { UINT8 splits; UINT8 viewd; @@ -1801,7 +1864,7 @@ void G_ResetViews(void) */ for (viewd = 1; viewd <= splits; ++viewd) { - G_AdjustView(viewd, 0, false); + G_AdjustViewEx(viewd, 0, false, resetfreecam); } } @@ -1882,7 +1945,7 @@ void G_Ticker(boolean run) G_CopyTiccmd(cmd, &netcmds[buf][i], 1); // Use the leveltime sent in the player's ticcmd to determine control lag - cmd->latency = modeattacking ? 0 : min(((leveltime & 0xFF) - cmd->latency) & 0xFF, MAXPREDICTTICS-1); //@TODO add a cvar to allow setting this max + cmd->latency = modeattacking ? 0 : min(((leveltime & TICCMD_LATENCYMASK) - cmd->latency) & TICCMD_LATENCYMASK, MAXPREDICTTICS-1); //@TODO add a cvar to allow setting this max } } @@ -1890,7 +1953,6 @@ void G_Ticker(boolean run) switch (gamestate) { case GS_LEVEL: - for (; ra_timeskip < starttime - TICRATE*4; ra_timeskip++) // this looks weird but this is done to not break compability with older demos for now. { if (demo.title) @@ -3025,7 +3087,8 @@ tryagain: void G_AddMapToBuffer(INT16 map) { - INT16 bufx, refreshnum = max(0, TOLMaps(G_TOLFlag(gametype))-3); + const INT32 tolmaps = TOLMaps(G_TOLFlag(gametype)); + INT16 bufx, refreshnum = max(0, tolmaps-3); // Add the map to the buffer. for (bufx = NUMMAPS-1; bufx > 0; bufx--) @@ -3438,7 +3501,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; - savebuffer_t save; + savebuffer_t save = {0}; //For records tic_t rectime; @@ -3571,7 +3634,7 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - savebuffer_t save; + savebuffer_t save = {0}; (void)force; char backupfile[MAX_WADPATH+4]; @@ -3742,7 +3805,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; - savebuffer_t save; + savebuffer_t save = {0}; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -3828,7 +3891,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; - savebuffer_t save; + savebuffer_t save = {0}; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -4012,6 +4075,12 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool automapactive = false; imcontinuing = false; + // HACK: this doesent reset if you change the map from within a replay and may cause crashes or the replayhut to be non functional + if (!demo.playback && demo.inreplayhut) + { + M_ResetDemoList(); + } + if (!skipprecutscene && mapheaderinfo[gamemap-1]->precutscenenum && !modeattacking) // Start a custom cutscene. F_StartCustomCutscene(mapheaderinfo[gamemap-1]->precutscenenum-1, true, resetplayer); else diff --git a/src/g_game.h b/src/g_game.h index 249ecbff1..509749c5f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -50,7 +50,7 @@ extern INT16 rw_maximums[NUM_WEAPONS]; // used in game menu extern consvar_t cv_chatwidth, cv_chatnotifications, cv_chatheight, cv_chattime, cv_consolechat, cv_chatbacktint, cv_chatspamprotection, cv_chatcentertext/*, cv_compactscoreboard*/; -extern consvar_t cv_songcredits; +extern consvar_t cv_songcredits, cv_pausesongcredits; extern consvar_t cv_showfreeplay; extern consvar_t cv_growmusic, cv_supermusic; extern consvar_t cv_pauseifunfocused; @@ -74,6 +74,8 @@ extern consvar_t cv_ydeadzone[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_litesteer[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_autoaccel[MAXSPLITSCREENPLAYERS]; + extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_guest, cv_ghost_staff; // Hud offsets @@ -160,7 +162,7 @@ typedef enum const char *G_BuildMapName(INT32 map); void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer); -// copy ticcmd_t to and fro the normal way +// copy ticcmd_t to and from the normal way ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n); // copy ticcmd_t to and fro network packets ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n); @@ -262,9 +264,10 @@ boolean G_CanView(INT32 playernum, UINT8 viewnum, boolean onlyactive); INT32 G_FindView(INT32 startview, UINT8 viewnum, boolean onlyactive, boolean reverse); INT32 G_CountPlayersPotentiallyViewable(boolean active); -void G_ResetViews(void); +void G_ResetViews(boolean resetfreecam); void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive); -void G_AdjustView(UINT8 viewnum, INT32 offset, boolean onlyactive); +void G_AdjustViewEx(UINT8 viewnum, INT32 offset, boolean onlyactive, boolean resetfreecam); +#define G_AdjustView(v,o,oa) G_AdjustViewEx(v,o,oa, true) void G_AddPlayer(INT32 playernum); diff --git a/src/g_input.c b/src/g_input.c index 6596d1e72..0082df273 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -34,7 +34,7 @@ static CV_PossibleValue_t onecontrolperkey_cons_t[] = {{1, "One"}, {2, "Several" static CV_PossibleValue_t turnsmooth_cons_t[] = {{2, "Slow"}, {1, "Fast"}, {0, "Off"}, {0, NULL}}; // mouse values are used once -consvar_t cv_mousesens = {"mousesens", "20", CV_SAVE, mousesens_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_mousexsens = {"mousexsens", "20", CV_SAVE, mousesens_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_mouseysens = {"mouseysens", "20", CV_SAVE, mousesens_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_controlperkey = {"controlperkey", "One", CV_SAVE, onecontrolperkey_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -58,12 +58,21 @@ static void led_off_handle3(void); static void led_off_handle4(void); consvar_t cv_rumble[MAXSPLITSCREENPLAYERS] = { - {"rumble", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, rumble_off_handle, 0, NULL, NULL, 0, 0, NULL}, + {"rumble", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, rumble_off_handle, 0, NULL, NULL, 0, 0, NULL}, {"rumble2", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, rumble_off_handle2, 0, NULL, NULL, 0, 0, NULL}, {"rumble3", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, rumble_off_handle3, 0, NULL, NULL, 0, 0, NULL}, {"rumble4", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, rumble_off_handle4, 0, NULL, NULL, 0, 0, NULL} }; +static CV_PossibleValue_t rumblestrength_cons_t[] = {{FRACUNIT/4, "MIN"}, {FRACUNIT*4, "MAX"}, {0, NULL}}; + +consvar_t cv_rumblestrength[MAXSPLITSCREENPLAYERS] = { + {"rumblestrength", "1.0", CV_SAVE|CV_FLOAT, rumblestrength_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"rumblestrength2", "1.0", CV_SAVE|CV_FLOAT, rumblestrength_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"rumblestrength3", "1.0", CV_SAVE|CV_FLOAT, rumblestrength_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"rumblestrength4", "1.0", CV_SAVE|CV_FLOAT, rumblestrength_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL} +}; + static CV_PossibleValue_t gamepadled_cons_t[] = {{0, "Off"}, {1, "Skincolor"}, {2, "Mobjcolor"}, {0, NULL}}; consvar_t cv_gamepadled[MAXSPLITSCREENPLAYERS] = { {"gamepadled", "Skincolor", CV_SAVE|CV_CALL|CV_NOINIT, gamepadled_cons_t, led_off_handle, 0, NULL, NULL, 0, 0, NULL}, @@ -116,17 +125,17 @@ static void led_off_handle4(void) G_ResetPlayerGamepadIndicatorColor(3); } -INT32 mousex, mousey; -INT32 mlooky; // like mousey but with a custom sensitivity for mlook +INT32 mousex = 0, mousey = 0; // joystick values are repeated -INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET], joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET]; +INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET] = {}; +INT32 joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET] = {}; // current state of the keys: true if pushed -UINT8 gamekeydown[NUMINPUTS]; +UINT8 gamekeydown[NUMINPUTS] = {}; // two key codes (or virtual key) per game control -INT32 gamecontrol[MAXSPLITSCREENPLAYERS][num_gamecontrols][2]; +INT32 gamecontrol[MAXSPLITSCREENPLAYERS][num_gamecontrols][2] = {}; typedef struct { @@ -183,9 +192,8 @@ void G_MapEventsToControls(event_t *ev) case ev_mouse: // buttons are virtual keys if (menuactive || CON_Ready() || chat_on) break; - mousex = (INT32)(ev->data2*((cv_mousesens.value*cv_mousesens.value)/110.0f + 0.1f)); - mousey = (INT32)(ev->data3*((cv_mousesens.value*cv_mousesens.value)/110.0f + 0.1f)); - mlooky = (INT32)(ev->data3*((cv_mouseysens.value*cv_mousesens.value)/110.0f + 0.1f)); + mousex = (INT32)(ev->data2*((cv_mousexsens.value*cv_mousexsens.value)/110.0f + 0.1f)); + mousey = (INT32)(ev->data3*((cv_mouseysens.value*cv_mouseysens.value)/110.0f + 0.1f)); break; case ev_joystick: // buttons are virtual keys @@ -206,7 +214,7 @@ void G_MapEventsToControls(event_t *ev) case ev_joystick3: i = ev->data1; - if (i >= JOYAXISSET) + if (i >= JOYAXISSET || menuactive) break; if (ev->data2 != INT32_MAX) joyxmove[2][i] = ev->data2; if (ev->data3 != INT32_MAX) joyymove[2][i] = ev->data3; @@ -214,7 +222,7 @@ void G_MapEventsToControls(event_t *ev) case ev_joystick4: i = ev->data1; - if (i >= JOYAXISSET) + if (i >= JOYAXISSET || menuactive) break; if (ev->data2 != INT32_MAX) joyxmove[3][i] = ev->data2; if (ev->data3 != INT32_MAX) joyymove[3][i] = ev->data3; @@ -875,11 +883,13 @@ static const char *gamecontrolname[num_gamecontrols] = #include "k_kart.h" -UINT16 G_GetSkinColor(INT32 playernum) +UINT8 G_GetSkinColorForGamepad(INT32 playernum) { + I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); + if (gamestate == GS_LEVEL) { - player_t *player = &players[displayplayers[playernum]]; + const player_t *player = &players[displayplayers[playernum]]; if (player) { @@ -897,13 +907,13 @@ UINT16 G_GetSkinColor(INT32 playernum) switch (playernum) { case 0: - return cv_playercolor.value; + return (UINT8)cv_playercolor.value; case 1: - return cv_playercolor2.value; + return (UINT8)cv_playercolor2.value; case 2: - return cv_playercolor3.value; + return (UINT8)cv_playercolor3.value; case 3: - return cv_playercolor4.value; + return (UINT8)cv_playercolor4.value; default: return 0; } @@ -911,19 +921,23 @@ UINT16 G_GetSkinColor(INT32 playernum) return 0; } -void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color) +// Sets the Indicator LED on supported gamepads to a desired skincolor +// pass SKINCOLOR_NONE/0 to set the players skin color +void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color) { - UINT16 skincolor; + UINT8 skincolor; byteColor_t byte_color; I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); - if (cv_gamepadled[playernum].value == 0) + if (cv_gamepadled[playernum].value == 0 + || color >= MAXTRANSLATIONS) { return; } - skincolor = color ? color : G_GetSkinColor(playernum); + // so we can override this + skincolor = color ? color : G_GetSkinColorForGamepad(playernum); byte_color = V_GetColor(colortranslations[skincolor][8]).s; I_SetGamepadIndicatorColor(playernum, byte_color.red, byte_color.green, byte_color.blue); @@ -936,7 +950,46 @@ static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum) I_SetGamepadIndicatorColor(playernum, 0, 0, 255); } else + { G_SetPlayerGamepadIndicatorColor(playernum, 0); + } +} + +static UINT8 curcolor[MAXSPLITSCREENPLAYERS] = {}; + +void G_DeviceLEDTick(void) +{ + UINT8 i, newcolor; + + if (numcontrollers == 0) + { + return; + } + + for (i = 0; i <= splitscreen; i++) + { + if (!cv_usejoystick[i].value || !cv_gamepadled[i].value) + continue; + + newcolor = G_GetSkinColorForGamepad(i); + + // compiler be absolutely tripping + // delet this if this gets fixed within gcc +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + if (curcolor[i] == newcolor) // dont update if same colour + continue; +#pragma GCC diagnostic pop + + G_SetPlayerGamepadIndicatorColor(i, newcolor); + curcolor[i] = newcolor; + } +} + +// ensures next call to G_DeviceLEDTick will refresh the gamepad led +void G_ResetDeviceLED(void) +{ + memset(curcolor, 0, sizeof(curcolor)); } static void G_ResetPlayerDeviceRumble(INT32 playernum) @@ -963,9 +1016,135 @@ void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_stre return; } + // doesent need to be super precise + // but ensure this is within range (0-65535) + // placed here so it applies to lua aswell + low_strength = (UINT16)min(FixedMul(low_strength, cv_rumblestrength[playernum].value), UINT16_MAX); + high_strength = (UINT16)min(FixedMul(high_strength, cv_rumblestrength[playernum].value), UINT16_MAX); + I_GamepadRumble(playernum, low_strength, high_strength, duration); } +// rumble strengths +enum +{ + RUMBLE_VERYSTRONG = FRACUNIT / 4, // 16384 + RUMBLE_STRONG = FRACUNIT / 8, // 8192 + RUMBLE_MODERATE = FRACUNIT / 64, // 1024 + RUMBLE_WEAK = FRACUNIT / 128, // 512 + RUMBLE_VERYWEAK = FRACUNIT / 256, // 256 +}; + +// Controller rumble! +// this keeps track of a bunch of things +// and makes your controller rumble accordingly +void G_DeviceRumbleTick(void) +{ + UINT8 i; + + if (dedicated || numcontrollers == 0 || gamestate != GS_LEVEL) + { + return; + } + + for (i = 0; i <= splitscreen; i++) + { + if (!cv_usejoystick[i].value || !cv_rumble[i].value) + { + continue; + } + + if (camera[i].freecam) + { + continue; + } + + // SDL rumble strength goes from a range or 0-65535 respectively + // the higher, the stronger it is + UINT16 low = 0, high = 0; + // for how long the action should rumble, in ms + UINT16 lenght = 57; // 57ms is a short pulse, matches super well with this updating once per tic + + const player_t *player = P_GetLocalPlayerForNum(i); + + // allow lua to do some crap for spectators + if (player->spectator || !player->mo) + { + continue; + } + + // reset the rumble if you exit or are ded lel + if (player->exiting || + player->playerstate == PST_DEAD || + player->kartstuff[k_respawn] > 1) + { + G_PlayerDeviceRumble(i, low, high, 0); + continue; + } + + if (player->kartstuff[k_spinouttimer]) + { + //low = high = FRACUNIT / 6; + low = high = FixedMul((RUMBLE_VERYSTRONG), (FixedDiv(player->kartstuff[k_spinouttimer], (3*TICRATE / 2)))); // try do some some kinda fadeout, 3*TICRATE / 2 is the "default" spinout time + } + else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) + { + low = high = RUMBLE_STRONG; + } + else if ((player->kartstuff[k_offroad]) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + // weaken this depending on if you got hyu or invinc + if (player->kartstuff[k_hyudorotimer]) + { + high = RUMBLE_WEAK; + } + else if (player->kartstuff[k_invincibilitytimer]) + { + high = RUMBLE_MODERATE; + } + else + { + low = high = RUMBLE_MODERATE; + } + } + else if ((player->kartstuff[k_bananadrag] > TICRATE) + && player->speed != 0 + && P_IsObjectOnGround(player->mo)) + { + if (leveltime & 1) // this is actually funny lel + high = RUMBLE_MODERATE; + } + + if (player->kartstuff[k_brakedrift]) + { + high = CLAMP((high + RUMBLE_VERYWEAK), 0, UINT16_MAX); + } + + // pulse when gettin new driftlevel + // let this come last + if (player->kartstuff[k_driftcharge] + && player->driftlevel) + { + high = CLAMP((high + RUMBLE_VERYWEAK), 0, UINT16_MAX); + + if (player->driftlevel == 2) + lenght = 114; + else if (player->driftlevel == 3) + lenght = 174; + } + + // hack alert! i just dont want this thing constantly resetting the rumble lol + if (low == 0 && high == 0) + { + continue; + } + + G_PlayerDeviceRumble(i, low, high, lenght); + } +} + // // Detach any keys associated to the given game control // - pass the pointer to the gamecontrol table for the player being edited diff --git a/src/g_input.h b/src/g_input.h index c430fe7bc..9831e6d8f 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -109,14 +109,14 @@ typedef enum } gamecontrols_e; // mouse values are used once -extern consvar_t cv_mousesens, cv_mouseysens; +extern consvar_t cv_mousexsens, cv_mouseysens; extern consvar_t cv_controlperkey; extern consvar_t cv_turnsmooth[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_rumblestrength[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_gamepadled[MAXSPLITSCREENPLAYERS]; extern INT32 mousex, mousey; -extern INT32 mlooky; //mousey with mlookSensitivity extern INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET], joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET]; @@ -131,13 +131,17 @@ extern INT32 gamecontrol[MAXSPLITSCREENPLAYERS][num_gamecontrols][2]; #define PLAYER3INPUTDOWN(gc) (gamekeydown[gamecontrol[2][gc][0]] || gamekeydown[gamecontrol[2][gc][1]]) #define PLAYER4INPUTDOWN(gc) (gamekeydown[gamecontrol[3][gc][0]] || gamekeydown[gamecontrol[3][gc][1]]) -// peace to my little coder fingers! -// check a gamecontrol being active or not +UINT8 G_GetSkinColorForGamepad(INT32 playernum); +void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color); +void G_DeviceLEDTick(void); +void G_ResetDeviceLED(void); -UINT16 G_GetSkinColor(INT32 playernum); -void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT16 color); void G_ResetAllDeviceRumbles(void); void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration); +void G_DeviceRumbleTick(void); + +// peace to my little coder fingers! +// check a gamecontrol being active or not // remaps the input event to a game control. void G_MapEventsToControls(event_t *ev); diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 3e0c2320b..4d6b1ea6e 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -21,28 +21,28 @@ // The texture for the next polygon given to HWR_ProcessPolygon. // Set with HWR_SetCurrentTexture. -GLMipmap_t *current_texture = NULL; +static GLMipmap_t *current_texture = NULL; -boolean currently_batching = false; +static boolean currently_batching = false; -FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu -UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion +static FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu +static UINT32* finalVertexIndexArray = NULL;// contains indexes for glDrawElements, taking into account fan->triangles conversion // NOTE have this alloced as 3x finalVertexArray size -int finalVertexArrayAllocSize = 65536; +static int finalVertexArrayAllocSize = 65536; //GLubyte* colorArray = NULL;// contains color data to be sent to gpu, if needed //int colorArrayAllocSize = 65536; // not gonna use this for now, just sort by color and change state when it changes // later maybe when using vertex attributes if it's needed -PolygonArrayEntry* polygonArray = NULL ;// contains the polygon data from DrawPolygon, waiting to be processed -PolygonArrayEntry **polygonArraySorted = NULL; // contains sorted pointers to polygonArray -int polygonArraySize = 0; -int polygonArrayAllocSize = 65536; +static PolygonArrayEntry* polygonArray = NULL ;// contains the polygon data from DrawPolygon, waiting to be processed +static PolygonArrayEntry **polygonArraySorted = NULL; // contains sorted pointers to polygonArray +static int polygonArraySize = 0; +static int polygonArrayAllocSize = 65536; -FOutVector* unsortedVertexArray = NULL; // contains unsorted vertices and texture coordinates from DrawPolygon -int unsortedVertexArraySize = 0; -int unsortedVertexArrayAllocSize = 65536; +static FOutVector* unsortedVertexArray = NULL; // contains unsorted vertices and texture coordinates from DrawPolygon +static int unsortedVertexArraySize = 0; +static int unsortedVertexArrayAllocSize = 65536; // Enables batching mode. HWR_ProcessPolygon will collect polygons instead of passing them directly to the rendering backend. // Call HWR_RenderBatches to render all the collected geometry. @@ -126,8 +126,9 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt if (!(PolyFlags & PF_NoTexture) && !horizonSpecial) { // use FNV-1a to hash polygons for later sorting. - INT32 hash = 0x811c9dc5; -#define DIGEST(h, x) h ^= (x); h *= 0x01000193 + UINT32 hash = 0x811c9dc5; + UINT32 prime = 0x1000193; +#define DIGEST(h, x) h ^= ((UINT32)(x)); h *= prime if (current_texture) { DIGEST(hash, current_texture->downloaded); @@ -148,7 +149,7 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt } #undef DIGEST // remove the sign bit to ensure that skybox and horizon line comes first. - polygonArray[polygonArraySize-1].hash = (hash & INT32_MAX); + polygonArray[polygonArraySize-1].hash = (INT32)(hash & INT32_MAX); } memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector)); @@ -168,8 +169,10 @@ static int comparePolygons(const void *p1, const void *p2) const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; - const int shader1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? -1 : poly1->shader; - const int shader2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? -1 : poly2->shader; + // special case with signedness to prevent overflowing + // FIXME: check for prediction slowdowns! + const int shader1 = poly1->hash & 0x80000000 ? -1 : poly1->shader; + const int shader2 = poly2->hash & 0x80000000 ? -1 : poly2->shader; // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) @@ -210,8 +213,8 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) const PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; const PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; - const GLMipmap_t *texture1 = (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) ? NULL : poly1->texture; - const GLMipmap_t *texture2 = (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) ? NULL : poly2->texture; + const GLMipmap_t *texture1 = poly1->hash & 0x80000000 ? NULL : poly1->texture; + const GLMipmap_t *texture2 = poly2->hash & 0x80000000 ? NULL : poly2->texture; // skywalls and horizon lines must retain their order for horizon lines to work if (!texture1 && !texture2) @@ -219,6 +222,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) UINT32 downloaded1 = texture1 ? texture1->downloaded : 0; // there should be a opengl texture name here, usable for comparisons UINT32 downloaded2 = texture2 ? texture2->downloaded : 0; + diff64 = downloaded1 - downloaded2; if (diff64 != 0) return diff64; @@ -260,7 +264,7 @@ void HWR_RenderBatches(void) nextSurfaceInfo.LightInfo.light_level = 0; nextSurfaceInfo.LightInfo.directional = false; - currently_batching = false;// no longer collecting batches + currently_batching = false; // no longer collecting batches if (!polygonArraySize) { @@ -270,6 +274,8 @@ void HWR_RenderBatches(void) return;// nothing to draw } + const boolean useshader = HWR_UseShader(); + // init stats vars ps_hw_numpolys.value.i = polygonArraySize; ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0; @@ -284,7 +290,7 @@ void HWR_RenderBatches(void) // sort polygons PS_START_TIMING(ps_hw_batchsorttime); - qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (HWR_UseShader() ? comparePolygons : comparePolygonsNoShaders)); + qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (useshader ? comparePolygons : comparePolygonsNoShaders)); PS_STOP_TIMING(ps_hw_batchsorttime); // sort order @@ -305,7 +311,7 @@ void HWR_RenderBatches(void) // set state for first batch - if (HWR_UseShader()) + if (useshader) { GL_SetShader(currentShader); } @@ -387,7 +393,7 @@ void HWR_RenderBatches(void) if (nextPolyFlags & PF_NoTexture) nextTexture = 0; - if (currentShader != nextShader && HWR_UseShader()) + if (useshader && currentShader != nextShader) { changeState = true; changeShader = true; @@ -405,7 +411,7 @@ void HWR_RenderBatches(void) changePolyFlags = true; } - if (HWR_UseShader()) + if (useshader) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 3b154f916..79069857c 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -538,7 +538,7 @@ static void loading_status(void) x = BASEVIDWIDTH/2; y = BASEVIDHEIGHT/2; V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // Black background to match fade in effect - //V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); // SRB2 background, ehhh too bright. + //V_DrawPatchFill(srb2back); // SRB2 background, ehhh too bright. M_DrawTextBox(x-58, y-8, 13, 1); V_DrawString(x-50, y, V_YELLOWMAP, "Loading..."); V_DrawRightAlignedString(x+50, y, V_YELLOWMAP, s); diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.cpp similarity index 90% rename from src/hardware/hw_cache.c rename to src/hardware/hw_cache.cpp index b4bc067be..09f4f1a7b 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.cpp @@ -15,6 +15,8 @@ #ifdef HWRENDER +#include + #include "hw_main.h" #include "hw_glob.h" #include "hw_gl.h" @@ -36,7 +38,7 @@ INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes INT32 textureformat = GL_TEXFMT_P_8; // use chromakey for hole -RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. +RGBA_t mapPalette[256] = {}; // the palette for the currently loaded level or menu etc. static void HWR_FreeTextureColormaps(patch_t *patch); @@ -98,7 +100,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm position = 0; } - position = max(((position * scale_y) + (FRACUNIT/2)) >> FRACBITS, 0); + position = std::max(((position * scale_y) + (FRACUNIT/2)) >> FRACBITS, 0); if (position + count >= pblockheight) count = pblockheight - position; @@ -162,7 +164,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = static_cast(mipmap->data); INT32 bpp; INT32 blockmodulo; RGBA_t *palette; @@ -212,7 +214,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, fixed_t xfrac, xfracstep; fixed_t yfracstep, scale_y; const column_t *patchcol; - UINT8 *block = mipmap->data; + UINT8 *block = static_cast(mipmap->data); INT32 bpp; INT32 blockmodulo; INT32 width, height; @@ -287,8 +289,8 @@ static UINT8 *MakeBlock(GLMipmap_t *glMipmap) UINT16 bu16 = ((0x00 <<8) | HWR_PATCHES_CHROMAKEY_COLORINDEX); INT32 blocksize = (glMipmap->width * glMipmap->height); - bpp = format2bpp(glMipmap->format); - block = Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data)); + bpp = format2bpp(glMipmap->format); + block = static_cast(Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data))); switch (bpp) { @@ -325,7 +327,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture = textures[texnum]; gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; - gltex->mipmap.format = textureformat; + gltex->mipmap.format = static_cast(textureformat); // hack the Legacy skies.. if (UNLIKELY(memcmp(texture->name, "SKY", 3) == 0 && @@ -344,7 +346,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe colormap += COLORMAP_REMAPOFFSET; #endif - gltex->mipmap.colormap = Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + gltex->mipmap.colormap = static_cast(Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL)); gltex->mipmap.colormap->source = colormap; memcpy(gltex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); @@ -377,7 +379,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + pdata = static_cast(W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL)); realpatch = (softwarepatch_t *)pdata; HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); @@ -413,7 +415,7 @@ void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipma glMipmap->flags = 0; // setup the texture info - glMipmap->format = patchformat; + glMipmap->format = static_cast(patchformat); glPatch->max_s = (float)patch->width / (float)glMipmap->width; glPatch->max_t = (float)patch->height / (float)glMipmap->height; @@ -455,12 +457,13 @@ static void HWR_FreeTextureData(patch_t *patch) if (!patch || !patch->hardware) return; - glPatch = patch->hardware; + glPatch = static_cast(patch->hardware); if (vid.glstate == VID_GL_LIBRARY_LOADED) GL_DeleteTexture(glPatch->mipmap); Z_Free(glPatch->mipmap->data); + glPatch->mipmap->data = NULL; } void HWR_FreeTexture(patch_t *patch) @@ -470,7 +473,7 @@ void HWR_FreeTexture(patch_t *patch) if (patch->hardware) { - GLPatch_t *glPatch = patch->hardware; + GLPatch_t *glPatch = static_cast(patch->hardware); HWR_FreeTextureColormaps(patch); @@ -478,6 +481,7 @@ void HWR_FreeTexture(patch_t *patch) { HWR_FreeTextureData(patch); Z_Free(glPatch->mipmap); + glPatch->mipmap = NULL; } Z_Free(patch->hardware); @@ -495,7 +499,7 @@ static void HWR_FreeTextureColormaps(patch_t *patch) if (!patch) return; - pat = patch->hardware; + pat = static_cast(patch->hardware); if (!pat) return; @@ -577,6 +581,9 @@ void HWR_InitMapTextures(void) static void FreeMapTexture(GLMapTexture_t *tex) { + if (!tex) + return; + GL_DeleteTexture(&tex->mipmap); Z_Free(tex->mipmap.data); tex->mipmap.data = NULL; @@ -586,6 +593,12 @@ void HWR_FreeMapTextures(void) { size_t i; + if (!gl_textures) + { + gl_numtextures = 0; + return; + } + for (i = 0; i < gl_numtextures; i++) { FreeMapTexture(&gl_textures[i].normal); @@ -596,18 +609,29 @@ void HWR_FreeMapTextures(void) // now the heap don't have any 'user' pointing to our // texturecache info, we can free it - if (gl_textures) - free(gl_textures); + free(gl_textures); gl_textures = NULL; gl_numtextures = 0; } static void HWR_PrecacheLevelFlats(void) { - lumpnum_t lump; + // lookup for flats that may´ve been already loaded + // too lazy to make a hashtable or smth so unordered set will do :carbuncle: + std::unordered_set flatpresent; size_t i, j; INT32 k; + auto load_flat = [&](lumpnum_t lump, boolean noencoremap) + { + // flat already loaded? + if (flatpresent.count(lump) == 0) + { + HWR_GetFlat(lump, noencoremap); + flatpresent.insert(lump); + } + }; + // special case for encore #ifdef GLENCORE if (encoremap) @@ -625,15 +649,14 @@ static void HWR_PrecacheLevelFlats(void) const levelflat_t *levelflat = &levelflats[pic]; - lump = levelflat->lumpnum; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); + load_flat(levelflat->lumpnum, R_NoEncore(sec, ceiling)); - if (levelflat->speed) // it is an animated flat + if (levelflat->speed) // is it an animated flat ? { - for (k = 1; k < levelflat->numpics; k++) + // start from 0, occasionally basenumlump != flat->lumpnum + for (k = 0; k < levelflat->numpics; k++) { - lump = levelflat->baselumpnum + k; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); + load_flat(levelflat->baselumpnum + k, R_NoEncore(sec, ceiling)); } } } @@ -647,17 +670,16 @@ static void HWR_PrecacheLevelFlats(void) for (i = 0; i < numlevelflats; i++) { const levelflat_t *levelflat = &levelflats[i]; - lump = levelflat->lumpnum; - HWR_GetFlat(lump, false); + load_flat(levelflat->lumpnum, false); - if (!levelflat->speed) // is it an animated flat ? - continue; - - for (k = 1; k < levelflat->numpics; k++) + if (levelflat->speed) // is it an animated flat ? { - lump = levelflat->baselumpnum + k; - HWR_GetFlat(lump, false); + // start from 0, occasionally basenumlump != flat->lumpnum + for (k = 0; k < levelflat->numpics; k++) + { + load_flat(levelflat->baselumpnum + k, false); + } } } } @@ -670,7 +692,7 @@ static void HWR_PrecacheLevelTextures(void) size_t i, j, f; INT32 h; - texturepresent = calloc(numtextures, sizeof (*texturepresent)); + texturepresent = static_cast(calloc(gl_numtextures, sizeof(*texturepresent))); if (texturepresent == NULL) I_Error("%s: Out of memory looking up textures", "HWR_PrecacheLevel"); @@ -701,7 +723,10 @@ static void HWR_PrecacheLevelTextures(void) { const INT32 texnum = sidetex[f]; - if (texnum < 0 || texnum >= numtextures || texturepresent[texnum]) + if (texnum < 0 || texnum >= (signed)gl_numtextures) + continue; + + if (texturepresent[texnum]) continue; #ifdef GLENCORE texturepresent[texnum] = 1|noencoremap; @@ -729,14 +754,16 @@ static void HWR_PrecacheLevelTextures(void) for (h = 1; h < anim->numpics; h++) { + const INT32 animtexnum = anim->basepic+h; + if (texpresent & 1) { - HWR_GetTexture(anim->basepic+h, false); + HWR_GetTexture(animtexnum, false); } #ifdef GLENCORE if (texpresent & 2) { - HWR_GetTexture(anim->basepic+h, true); + HWR_GetTexture(animtexnum, true); } #endif } @@ -840,7 +867,7 @@ void HWR_LoadMapTextures(size_t pnumtextures) HWR_FreeMapTextures(); gl_numtextures = pnumtextures; - gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t + gl_textures = static_cast(calloc(gl_numtextures, sizeof(*gl_textures))); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t if (gl_textures == NULL) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); @@ -852,6 +879,7 @@ void HWR_LoadMapTextures(size_t pnumtextures) GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) { GLMapTexture_t *gltex; + GLMipmap_t *glMipmap; if (tex < 0 || tex >= (signed)gl_numtextures) { @@ -870,19 +898,22 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) gltex = &gl_textures[tex]; #endif + glMipmap = &gltex->mipmap; + // Generate texture if missing from the cache - if (!gltex->mipmap.downloaded) + if (!glMipmap->downloaded) { if (!gltex->mipmap.data) HWR_GenerateTexture(tex, gltex, noencore); // If hardware does not have the texture, then call GL_SetTexture to upload it - GL_SetTexture(&gltex->mipmap); + GL_SetTexture(glMipmap); } - HWR_SetCurrentTexture(&gltex->mipmap); + + HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. - Z_ChangeTag(gltex->mipmap.data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); return gltex; } @@ -933,7 +964,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) W_ReadLump(flatlumpnum, Z_Malloc(size, PU_HWRCACHE, &glMipmap->data)); #ifdef GLENCORE - flat = glMipmap->data; + flat = static_cast(glMipmap->data); for (steppy = 0; steppy < size; steppy++) { if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX) @@ -977,7 +1008,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) if (!noencoremap && encoremap) colormap += COLORMAP_REMAPOFFSET; #endif - glMipmap->colormap = Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + glMipmap->colormap = static_cast(Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); glMipmap->colormap->source = colormap; memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); } @@ -1001,7 +1032,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) // --------------------+ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) { - GLPatch_t *glPatch = patch->hardware; + GLPatch_t *glPatch = static_cast(patch->hardware); if (!glMipmap->downloaded) { @@ -1022,8 +1053,8 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) // ----------------------+ static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) { - GLPatch_t *grPatch = patch->hardware; - HWR_MakePatch(patch, grPatch, glMipmap, true); + GLPatch_t *glPatch = static_cast(patch->hardware); + HWR_MakePatch(patch, glPatch, glMipmap, true); // If hardware does not have the texture, then call GL_SetTexture to upload it // If it does have the texture, then call GL_UpdateTexture to update it @@ -1031,6 +1062,7 @@ static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) GL_SetTexture(glMipmap); else GL_UpdateTexture(glMipmap); + HWR_SetCurrentTexture(glMipmap); // The system-memory data can be purged now. @@ -1057,7 +1089,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) if (!patch->hardware) Patch_CreateGL(patch); - glPatch = patch->hardware; + glPatch = static_cast(patch->hardware); // Blatant hack for encore colormapping aside... if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) @@ -1093,12 +1125,12 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) // (it have a liste of mipmap) // this malloc is cleared in HWR_FreeColormapCache // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better - newMipmap = calloc(1, sizeof (*newMipmap)); + newMipmap = static_cast(calloc(1, sizeof (*newMipmap))); if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap = static_cast(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); newMipmap->colormap->source = colormap; memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); @@ -1121,7 +1153,7 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) { void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); Patch_Create(NULL, 0, ptr); - Patch_AllocateHardwarePatch(ptr); + Patch_AllocateHardwarePatch(static_cast(ptr)); } return (patch_t *)(lumpcache[lumpnum]); @@ -1138,7 +1170,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 { INT32 i,j; fixed_t posx, posy, stepx, stepy; - UINT8 *block = mipmap->data; // places the data directly into here + UINT8 *block = static_cast(mipmap->data); // places the data directly into here UINT8 *flat; UINT8 *dest, *src, texel; RGBA_t col; @@ -1294,9 +1326,9 @@ void HWR_SetPalette(RGBA_t *palette) static void HWR_SetPaletteLookup(RGBA_t *palette) { int r, g, b; - UINT8 *lut = Z_Malloc( + UINT8 *lut = static_cast(Z_Malloc( HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8), - PU_STATIC, NULL); + PU_STATIC, NULL)); #define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE) for (b = 0; b < HWR_PALETTE_LUT_SIZE; b++) { @@ -1339,7 +1371,7 @@ void HWR_SetMapPalette(void) if (palsize < 768) // 256 * 3 I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n"); - RGB_data = W_CacheLumpNum(lumpnum, PU_CACHE); + RGB_data = static_cast(W_CacheLumpNum(lumpnum, PU_CACHE)); // we got the RGB palette now, but we need it in RGBA format. for (i = 0; i < 256; i++) { @@ -1374,7 +1406,7 @@ static UINT32 HWR_CreateLightTable(UINT8 *lighttable) { UINT32 i, id; RGBA_t *palette = HWR_GetTexturePalette(); - RGBA_t *hw_lighttable = Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL); + RGBA_t *hw_lighttable = static_cast(Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL)); // To make the palette index -> RGBA mapping easier for the shader, // the hardware lighttable is composed of RGBA colors instead of palette indices. diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 624dc4234..3f9536436 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -166,6 +166,7 @@ static void gld_clipper_RemoveRange(clipnode_t *range) { range->prev->next = range->next; } + if (range->next) { range->next->prev = range->prev; @@ -177,7 +178,7 @@ static void gld_clipper_RemoveRange(clipnode_t *range) void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) { - if(startangle > endangle) + if (startangle > endangle) { // The range has to added in two parts. gld_clipper_AddClipRange(startangle, ANGLE_MAX); @@ -319,7 +320,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle) double floatangle; angle_t a1; - float tilt = (float)fabs(((double)(int)tiltangle) / ANG1); + float tilt = fabsf(((float)(int)tiltangle) / (float)ANG1); if (tilt > 90.0f) tilt = 90.0f; @@ -330,7 +331,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle) // ok, this is a gross hack that barely works... // but at least it doesn't overestimate too much... - clipfov = atan(1 / (GLdouble)projMatrix[0]) * 360.0 / M_PIl; + clipfov = atan(1 / (GLdouble)projMatrix[0]) * 360.0 / M_PI; floatangle = 2.0 + (45.0 + ((double)tilt / 1.9)) * clipfov / 90.0; if (floatangle >= 180.0) return 0xffffffff; @@ -348,33 +349,32 @@ angle_t gld_FrustumAngle(angle_t tiltangle) // gld_FrustumSetup // -static GLdouble viewMatrix[16]; -static GLdouble projMatrix[16]; -float frustum[6][4]; +static float frustum[6][4]; #define CALCMATRIX(a, b, c, d, e, f, g, h)\ -(float)(viewMatrix[a] * projMatrix[b] + \ -viewMatrix[c] * projMatrix[d] + \ -viewMatrix[e] * projMatrix[f] + \ -viewMatrix[g] * projMatrix[h]) + (modelMatrix[a] * projMatrix[b] + \ + modelMatrix[c] * projMatrix[d] + \ + modelMatrix[e] * projMatrix[f] + \ + modelMatrix[g] * projMatrix[h]) #define NORMALIZE_PLANE(i)\ -t = (float)sqrt(\ -frustum[i][0] * frustum[i][0] + \ -frustum[i][1] * frustum[i][1] + \ -frustum[i][2] * frustum[i][2]); \ -frustum[i][0] /= t; \ -frustum[i][1] /= t; \ -frustum[i][2] /= t; \ -frustum[i][3] /= t + t = sqrtf(\ + frustum[i][0] * frustum[i][0] + \ + frustum[i][1] * frustum[i][1] + \ + frustum[i][2] * frustum[i][2]); \ + frustum[i][0] /= t; \ + frustum[i][1] /= t; \ + frustum[i][2] /= t; \ + frustum[i][3] /= t void gld_FrustumSetup(void) { float t; float clip[16]; - pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); - pglGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix); + // HWR_SetTransform will take care of this! + //pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); + //pglGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix); clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index 4299fbaea..232d09c06 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -16,7 +16,7 @@ extern "C" { #include "../tables.h" #include "../doomtype.h" -//#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code +#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index 45d072c28..bb174b205 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -65,7 +65,7 @@ typedef struct GLMipmap_s GLMipmap_t; struct GLMapTexture_s { GLMipmap_t mipmap; - float scaleX; //used for scaling textures on walls + float scaleX; // used for scaling textures on walls float scaleY; }; typedef struct GLMapTexture_s GLMapTexture_t; @@ -74,7 +74,7 @@ typedef struct GLMapTexture_s GLMapTexture_t; struct GLPatch_s { GLMipmap_t *mipmap; - float max_s,max_t; + float max_s, max_t; }; typedef struct GLPatch_s GLPatch_t; diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index ce903c82d..6a8649099 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -79,7 +79,7 @@ typedef struct FColorARGB FColorARGB; // Simple 2D coordinate typedef struct { - FLOAT x,y; + FLOAT x, y; } F2DCoord, v2d_t; // ====================== @@ -142,8 +142,8 @@ enum // Transformed vector, as passed to HWR API typedef struct { - FLOAT x,y,z; - FLOAT s,t; + FLOAT x, y, z; + FLOAT s, t; } FOutVector; typedef struct vbo_vertex_s @@ -173,7 +173,7 @@ typedef struct int rows, columns; int loopcount; - int detail, vertex_count; + int vertex_count; int texture, width, height; boolean rebuild; // VBO needs to be rebuilt diff --git a/src/hardware/hw_dll.h b/src/hardware/hw_dll.h deleted file mode 100644 index 8ee6da2fc..000000000 --- a/src/hardware/hw_dll.h +++ /dev/null @@ -1,67 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 2005 by SRB2 Jr. Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Win32 DLL and Shared Objects API definitions - -#ifndef __HWR_DLL_H__ -#define __HWR_DLL_H__ - -// Function declaration for exports from the DLL : -// EXPORT HWRAPI() (); -// If _CREATE_DLL_ is defined the above declaration translates to : -// __declspec(dllexport) WINAPI (); -// If _CREATE_DLL_ is NOT DEFINED the above declaration translates to : -// __declspec(dllexport) type> (WINAPI *) (); - -#ifdef _CREATE_DLL_ - #ifdef __cplusplus - #define EXPORT extern "C" - #else - #define EXPORT - #endif - #ifdef _WIN32 - #define HWRAPI(fn) WINAPI fn - #else - #define HWRAPI(fn) fn - #endif -#else // _CREATE_DLL_ - #define EXPORT typedef - #ifdef _WIN32 - #define HWRAPI(fn) (WINAPI *fn) - #else - #define HWRAPI(fn) (*fn) - #endif -#endif - -// ========================================================================== -// MATHS -// ========================================================================== - -// Constants -#define DEGREE (0.017453292519943295769236907684883l) // 2*PI/360 - -void GL_DBG_Printf(const char *format, ...) /*FUNCPRINTF*/; -#define DBG_Printf GL_DBG_Printf - -#if defined (__CYGWIN__) -void _init() __attribute__((constructor)); -void _fini() __attribute__((destructor)); -#else -void _init(); -void _fini(); -#endif - -#endif diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 498c7042a..70a5a3a8d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -14,6 +14,7 @@ #ifdef HWRENDER #include +#include #include "../doomstat.h" #include "../doomdef.h" @@ -83,6 +84,13 @@ float gl_viewsin = 0.0f, gl_viewcos = 0.0f; static float gl_viewludsin, gl_viewludcos; static angle_t gl_aimingangle; +static float yaw = 0.0f; +static float inv_yaw = 0.0f; +static float cos_inv_yaw = 0.0f; +static float sin_inv_yaw = 0.0f; + +static constexpr float deg2radians = (M_PIf / 180.0f); + seg_t *gl_curline = NULL; side_t *gl_sidedef = NULL; line_t *gl_linedef = NULL; @@ -138,7 +146,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing); static void HWR_SetTransformAiming(FTransform *trans); static void HWR_RollTransform(FTransform *tr, angle_t roll); -static void HWR_DoPostProcessor(player_t *player); +static void HWR_DoPostProcessor(void); static void HWR_SetShaderState(void); static void HWR_TogglePaletteRendering(void); @@ -260,7 +268,8 @@ static void CV_screentextures_OnChange(void) static void CV_glframebuffer_OnChange(void) { ONLY_IF_GL_LOADED - if ((cv_glframebuffer.value != 0 && cv_glscreentextures.value != 2) || (!supportFBO && cv_glframebuffer.value != 0)) // screen FBO needs screen textures + if ((cv_glframebuffer.value != 0 && cv_glscreentextures.value != 2) + || (!supportFBO && cv_glframebuffer.value != 0)) // screen FBO needs screen textures CV_SetValue(&cv_glframebuffer, 0); I_DownSample(); @@ -379,7 +388,7 @@ void HWR_ObjectLightLevelPost(gl_vissprite_t *spr, const sector_t *sector, INT32 extralight = FixedMul(extralight, std::min(std::max(0, *lightlevel), 255) * FRACUNIT / 255); // simple OGL approximation - fixed_t tr = R_QuickCamDist(spr->mobj->x, spr->mobj->y) << FRACBITS; + fixed_t tr = R_QuickCamDist(spr->mobj->x, spr->mobj->y); fixed_t xscale = FixedDiv((vid.width / 2) << FRACBITS, tr); // Less change in contrast at further distances, to counteract DOOM diminished light @@ -634,8 +643,8 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool pv = planepoly->pts; // reference point for flat texture coord for each vertex around the polygon - flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); - flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); + flatxref = static_cast(static_cast(pv->x) & (~flatflag)) / fflatsize; + flatyref = static_cast(static_cast(pv->y) & (~flatflag)) / fflatsize; if (!isceiling) // it's a floor { @@ -652,9 +661,13 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool if (angle) // Only needs to be done if there's an altered angle { + // This needs to be done so that it scrolls in a different direction after rotation like software tempxsow = flatxref; tempytow = flatyref; anglef = ANG2RAD(InvAngle(angle)); + + // This needs to be done so everything aligns after rotation + // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does cosangf = cosf(anglef); sinangf = sinf(anglef); flatxref = (tempxsow * cosangf) - (tempytow * sinangf); @@ -798,6 +811,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool } } } +#undef SETUP3DVERT } #ifdef WALLSPLATS @@ -1233,6 +1247,9 @@ static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) if (LIKELY(!gl_curline->polyseg)) { + // check if linedef alpha is within range + const boolean linealpha = (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT); + // set alpha for transparent walls switch (gl_linedef->special) { @@ -1247,19 +1264,23 @@ static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) case 221: case 253: case 256: - if (gl_linedef->blendmode) + if (gl_linedef->blendmode && linealpha) blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Translucent; break; default: if (gl_linedef->blendmode) { - if (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT) + if (linealpha) blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); else blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); } - else if (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT) + else if (linealpha) blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Masked; break; } } @@ -1350,8 +1371,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // x offset the texture const fixed_t texturehpeg = gl_sidedef->textureoffset + gl_curline->offset; - const float cliplow = (float)texturehpeg; - const float cliphigh = (float)(texturehpeg + gl_curline->length); + const float cliplow = static_cast(texturehpeg); + const float cliphigh = static_cast(texturehpeg) + static_cast(gl_curline->length); FUINT lightnum = gl_frontsector->lightlevel; extracolormap_t *colormap = gl_frontsector->extra_colormap; @@ -1365,8 +1386,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom const INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); GLMapTexture_t *glTex = NULL; - static constexpr float FLOATMAX = INT32_MAX / (float)FRACUNIT; - static constexpr float FLOATMIN = INT32_MIN / (float)FRACUNIT; + static constexpr float FLOATMAX = static_cast(INT32_MAX) / static_cast(FRACUNIT); + static constexpr float FLOATMIN = static_cast(INT32_MIN) / static_cast(FRACUNIT); // two sided line if (gl_backsector) @@ -1479,8 +1500,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom glTex = HWR_GetTexture(gl_toptexture, noencore); - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpeg + gl_frontsector->ceilingheight - gl_backsector->ceilingheight) * glTex->scaleY; + wallVerts[3].t = wallVerts[2].t = static_cast(texturevpeg) * glTex->scaleY; + wallVerts[0].t = wallVerts[1].t = static_cast(texturevpeg + gl_frontsector->ceilingheight - gl_backsector->ceilingheight) * glTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * glTex->scaleX; @@ -1488,23 +1509,23 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(gl_linedef->flags & ML_EFFECT1)) { // Unskewed - wallVerts[3].t -= (worldtop - gl_frontsector->ceilingheight) * glTex->scaleY; - wallVerts[2].t -= (worldtopslope - gl_frontsector->ceilingheight) * glTex->scaleY; - wallVerts[0].t -= (worldhigh - gl_backsector->ceilingheight) * glTex->scaleY; - wallVerts[1].t -= (worldhighslope - gl_backsector->ceilingheight) * glTex->scaleY; + wallVerts[3].t -= static_cast(worldtop - gl_frontsector->ceilingheight) * glTex->scaleY; + wallVerts[2].t -= static_cast(worldtopslope - gl_frontsector->ceilingheight) * glTex->scaleY; + wallVerts[0].t -= static_cast(worldhigh - gl_backsector->ceilingheight) * glTex->scaleY; + wallVerts[1].t -= static_cast(worldhighslope - gl_backsector->ceilingheight) * glTex->scaleY; } else if (gl_linedef->flags & ML_DONTPEGTOP) { // Skewed by top - wallVerts[0].t = (texturevpeg + (worldtop - worldhigh)) * glTex->scaleY; - wallVerts[1].t = (texturevpeg + (worldtopslope - worldhighslope)) * glTex->scaleY; + wallVerts[0].t = static_cast(texturevpeg + (worldtop - worldhigh)) * glTex->scaleY; + wallVerts[1].t = static_cast(texturevpeg + (worldtopslope - worldhighslope)) * glTex->scaleY; } else { // Skewed by bottom - wallVerts[0].t = wallVerts[1].t = (texturevpeg + (worldtop - worldhigh)) * glTex->scaleY; - wallVerts[3].t = wallVerts[0].t - (worldtop - worldhigh) * glTex->scaleY; - wallVerts[2].t = wallVerts[1].t - (worldtopslope - worldhighslope) * glTex->scaleY; + wallVerts[0].t = wallVerts[1].t = static_cast(texturevpeg + (worldtop - worldhigh)) * glTex->scaleY; + wallVerts[3].t = wallVerts[0].t - static_cast(worldtop - worldhigh) * glTex->scaleY; + wallVerts[2].t = wallVerts[1].t - static_cast(worldtopslope - worldhighslope) * glTex->scaleY; } // set top/bottom coords @@ -1541,8 +1562,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom glTex = HWR_GetTexture(gl_bottomtexture, noencore); - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpeg + (gl_backsector->floorheight - gl_frontsector->floorheight)) * glTex->scaleY; + wallVerts[3].t = wallVerts[2].t = static_cast(texturevpeg * glTex->scaleY); + wallVerts[0].t = wallVerts[1].t = static_cast(texturevpeg + (gl_backsector->floorheight - gl_frontsector->floorheight)) * glTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * glTex->scaleX; @@ -1550,22 +1571,22 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(gl_linedef->flags & ML_EFFECT1)) { // Unskewed - wallVerts[0].t -= (worldbottom - gl_frontsector->floorheight) * glTex->scaleY; - wallVerts[1].t -= (worldbottomslope - gl_frontsector->floorheight) * glTex->scaleY; - wallVerts[3].t -= (worldlow - gl_backsector->floorheight) * glTex->scaleY; - wallVerts[2].t -= (worldlowslope - gl_backsector->floorheight) * glTex->scaleY; + wallVerts[0].t -= static_cast(worldbottom - gl_frontsector->floorheight) * glTex->scaleY; + wallVerts[1].t -= static_cast(worldbottomslope - gl_frontsector->floorheight) * glTex->scaleY; + wallVerts[3].t -= static_cast(worldlow - gl_backsector->floorheight) * glTex->scaleY; + wallVerts[2].t -= static_cast(worldlowslope - gl_backsector->floorheight) * glTex->scaleY; } else if (gl_linedef->flags & ML_DONTPEGBOTTOM) { // Skewed by bottom - wallVerts[0].t = wallVerts[1].t = (texturevpeg + (worldlow - worldbottom)) * glTex->scaleY; - wallVerts[2].t = wallVerts[1].t - (worldlowslope - worldbottomslope) * glTex->scaleY; + wallVerts[0].t = wallVerts[1].t = static_cast(texturevpeg + (worldlow - worldbottom)) * glTex->scaleY; + wallVerts[2].t = wallVerts[1].t - static_cast(worldlowslope - worldbottomslope) * glTex->scaleY; } else { // Skewed by top - wallVerts[0].t = (texturevpeg + (worldlow - worldbottom)) * glTex->scaleY; - wallVerts[1].t = (texturevpeg + (worldlowslope - worldbottomslope)) * glTex->scaleY; + wallVerts[0].t = static_cast(texturevpeg + (worldlow - worldbottom)) * glTex->scaleY; + wallVerts[1].t = static_cast(texturevpeg + (worldlowslope - worldbottomslope)) * glTex->scaleY; } // set top/bottom coords @@ -1727,13 +1748,13 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom glTex = HWR_GetTexture(gl_midtexture, noencore); // Left side - wallVerts[3].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = (h - l + texturevpeg) * glTex->scaleY; + wallVerts[3].t = static_cast(texturevpeg * glTex->scaleY); + wallVerts[0].t = static_cast(h - l + texturevpeg) * glTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; // Right side wallVerts[2].t = texturevpegslope * glTex->scaleY; - wallVerts[1].t = (hS - lS + texturevpegslope) * glTex->scaleY; + wallVerts[1].t = static_cast(hS - lS + texturevpegslope) * glTex->scaleY; wallVerts[2].s = wallVerts[1].s = cliphigh * glTex->scaleX; // set top/bottom coords @@ -1776,28 +1797,28 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else texturevpeg = gl_sidedef->rowoffset; // top of texture at top - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpeg + gl_frontsector->ceilingheight - gl_frontsector->floorheight) * glTex->scaleY; + wallVerts[3].t = wallVerts[2].t = (static_cast(texturevpeg) * glTex->scaleY); + wallVerts[0].t = wallVerts[1].t = static_cast(texturevpeg + gl_frontsector->ceilingheight - gl_frontsector->floorheight) * glTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * glTex->scaleX; // Texture correction for slopes if (gl_linedef->flags & ML_EFFECT2) { - wallVerts[3].t += (gl_frontsector->ceilingheight - worldtop) * glTex->scaleY; - wallVerts[2].t += (gl_frontsector->ceilingheight - worldtopslope) * glTex->scaleY; - wallVerts[0].t += (gl_frontsector->floorheight - worldbottom) * glTex->scaleY; - wallVerts[1].t += (gl_frontsector->floorheight - worldbottomslope) * glTex->scaleY; + wallVerts[3].t += static_cast(gl_frontsector->ceilingheight - worldtop) * glTex->scaleY; + wallVerts[2].t += static_cast(gl_frontsector->ceilingheight - worldtopslope) * glTex->scaleY; + wallVerts[0].t += static_cast(gl_frontsector->floorheight - worldbottom) * glTex->scaleY; + wallVerts[1].t += static_cast(gl_frontsector->floorheight - worldbottomslope) * glTex->scaleY; } else if (gl_linedef->flags & ML_DONTPEGBOTTOM) { - wallVerts[3].t = wallVerts[0].t + (worldbottom - worldtop) * glTex->scaleY; - wallVerts[2].t = wallVerts[1].t + ((worldbottomslope - worldtopslope)) * glTex->scaleY; + wallVerts[3].t = wallVerts[0].t + static_cast(worldbottom - worldtop) * glTex->scaleY; + wallVerts[2].t = wallVerts[1].t + static_cast((worldbottomslope - worldtopslope)) * glTex->scaleY; } else { - wallVerts[0].t = wallVerts[3].t - (worldbottom - worldtop) * glTex->scaleY; - wallVerts[1].t = wallVerts[2].t - (worldbottomslope - worldtopslope) * glTex->scaleY; + wallVerts[0].t = wallVerts[3].t - static_cast(worldbottom - worldtop) * glTex->scaleY; + wallVerts[1].t = wallVerts[2].t - static_cast(worldbottomslope - worldtopslope) * glTex->scaleY; } //Set textures properly on single sided walls that are sloped @@ -1860,6 +1881,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1; + fixed_t high2, highslope2, low2, lowslope2; INT32 texnum; @@ -1872,19 +1894,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_backsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || (roverflags & FF_INVERTSIDES)) @@ -1896,6 +1905,45 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; @@ -1962,24 +2010,24 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (dont_peg_bottom) texturevpeg -= (*rover->topheight - *rover->bottomheight); - wallVerts[3].t = ((*rover->topheight - h) + texturevpeg) * glTex->scaleY; - wallVerts[2].t = ((*rover->topheight - hS) + texturevpeg) * glTex->scaleY; - wallVerts[0].t = ((*rover->topheight - l) + texturevpeg) * glTex->scaleY; - wallVerts[1].t = ((*rover->topheight - lS) + texturevpeg) * glTex->scaleY; + wallVerts[3].t = static_cast((*rover->topheight - h) + texturevpeg) * glTex->scaleY; + wallVerts[2].t = static_cast((*rover->topheight - hS) + texturevpeg) * glTex->scaleY; + wallVerts[0].t = static_cast((*rover->topheight - l) + texturevpeg) * glTex->scaleY; + wallVerts[1].t = static_cast((*rover->topheight - lS) + texturevpeg) * glTex->scaleY; } else { if (!dont_peg_bottom) // skew by top { - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = ((h - l) + texturevpeg) * glTex->scaleY; - wallVerts[1].t = ((hS - lS) + texturevpeg) * glTex->scaleY; + wallVerts[3].t = wallVerts[2].t = (static_cast(texturevpeg) * glTex->scaleY); + wallVerts[0].t = static_cast((h - l) + texturevpeg) * glTex->scaleY; + wallVerts[1].t = static_cast((hS - lS) + texturevpeg) * glTex->scaleY; } else // skew by bottom { - wallVerts[0].t = wallVerts[1].t = texturevpeg * glTex->scaleY; - wallVerts[3].t = wallVerts[0].t - (h - l) * glTex->scaleY; - wallVerts[2].t = wallVerts[1].t - (hS - lS) * glTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (static_cast(texturevpeg) * glTex->scaleY); + wallVerts[3].t = wallVerts[0].t - static_cast(h - l) * glTex->scaleY; + wallVerts[2].t = wallVerts[1].t - static_cast(hS - lS) * glTex->scaleY; } } @@ -2032,19 +2080,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_frontsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || !(roverflags & FF_ALLSIDES)) @@ -2056,6 +2091,44 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; @@ -2122,24 +2195,24 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (dont_peg_bottom) texturevpeg -= (*rover->topheight - *rover->bottomheight); - wallVerts[3].t = ((*rover->topheight - h) + texturevpeg) * glTex->scaleY; - wallVerts[2].t = ((*rover->topheight - hS) + texturevpeg) * glTex->scaleY; - wallVerts[0].t = ((*rover->topheight - l) + texturevpeg) * glTex->scaleY; - wallVerts[1].t = ((*rover->topheight - lS) + texturevpeg) * glTex->scaleY; + wallVerts[3].t = static_cast((*rover->topheight - h) + texturevpeg) * glTex->scaleY; + wallVerts[2].t = static_cast((*rover->topheight - hS) + texturevpeg) * glTex->scaleY; + wallVerts[0].t = static_cast((*rover->topheight - l) + texturevpeg) * glTex->scaleY; + wallVerts[1].t = static_cast((*rover->topheight - lS) + texturevpeg) * glTex->scaleY; } else { if (!dont_peg_bottom) // skew by top { - wallVerts[3].t = wallVerts[2].t = texturevpeg * glTex->scaleY; - wallVerts[0].t = ((h - l) + texturevpeg) * glTex->scaleY; - wallVerts[1].t = ((hS - lS) + texturevpeg) * glTex->scaleY; + wallVerts[3].t = wallVerts[2].t = (static_cast(texturevpeg) * glTex->scaleY); + wallVerts[0].t = static_cast((h - l) + texturevpeg) * glTex->scaleY; + wallVerts[1].t = static_cast((hS - lS) + texturevpeg) * glTex->scaleY; } else // skew by bottom { - wallVerts[0].t = wallVerts[1].t = texturevpeg * glTex->scaleY; - wallVerts[3].t = wallVerts[0].t - (h - l) * glTex->scaleY; - wallVerts[2].t = wallVerts[1].t - (hS - lS) * glTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (static_cast(texturevpeg) * glTex->scaleY); + wallVerts[3].t = wallVerts[0].t - static_cast(h - l) * glTex->scaleY; + wallVerts[2].t = wallVerts[1].t - static_cast(hS - lS) * glTex->scaleY; } } @@ -2339,12 +2412,22 @@ static inline void DoAddLine(seg_t* line, angle_t angle1, angle_t angle2) static sector_t tempsec; auto do_addline = [&](bool dontdraw) { + // Single sided line? if (!line->backsector) { gld_clipper_SafeAddClipRange(angle2, angle1); } else { + if (line->frontsector == line->backsector) + { + if (R_GetTextureNum(line->sidedef->midtexture) == 0) + { + //e6y: nothing to do here! + return; + } + } + gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); if (CheckClip(gl_frontsector, gl_backsector)) @@ -2470,8 +2553,10 @@ static boolean HWR_CheckBBox(const fixed_t *bspcoord) // Find the corners of the box // that define the edges from current viewpoint. - const INT32 boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT] ? 1 : 2) + - (viewy >= bspcoord[BOXTOP] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8); + const INT32 boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : + viewx < bspcoord[BOXRIGHT] ? 1 : 2) + + (viewy >= bspcoord[BOXTOP] ? 0 : + viewy > bspcoord[BOXBOTTOM] ? 4 : 8); if (boxpos == 5) return true; @@ -2511,25 +2596,25 @@ static boolean HWR_CheckBBox(const fixed_t *bspcoord) // one if statement will split the space in two for one coordinate // for example: // x < BOXLEFT || BOXLEFT || !(x < BOXLEFT) <-- (same as x >= BOXLEFT) - fixed_t mindist;// = min(min(mindist1, mindist2), min(mindist3, mindist4)); + fixed_t mindist = 0;// = min(min(mindist1, mindist2), min(mindist3, mindist4)); // new thing // calculate distance to axis aligned bounding box. if (viewx < bspcoord[BOXLEFT]) // 1,4,6 { if (viewy > bspcoord[BOXTOP]) // 1 - mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXTOP]) << FRACBITS; + mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXTOP]); else if (viewy < bspcoord[BOXBOTTOM]) // 6 - mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM]) << FRACBITS; + mindist = R_QuickCamDist(bspcoord[BOXLEFT], bspcoord[BOXBOTTOM]); else // 4 mindist = bspcoord[BOXLEFT] - viewx; } else if (viewx > bspcoord[BOXRIGHT]) // 3,5,8 { if (viewy > bspcoord[BOXTOP]) // 3 - mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXTOP]) << FRACBITS; + mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXTOP]); else if (viewy < bspcoord[BOXBOTTOM]) // 8 - mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXBOTTOM]) << FRACBITS; + mindist = R_QuickCamDist(bspcoord[BOXRIGHT], bspcoord[BOXBOTTOM]); else // 5 mindist = viewx - bspcoord[BOXRIGHT]; } @@ -2591,6 +2676,7 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, INT32 flatflag; size_t len; float scrollx = 0.0f, scrolly = 0.0f; + float anglef = 0.0f, cosangf = 0.0f, sinangf = 0.0f; angle_t angle = 0; FSurfaceInfo Surf; fixed_t tempxsow, tempytow; @@ -2612,12 +2698,14 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, return; } + const sector_t *sec = FOFsector ? FOFsector : gl_frontsector; + // Allocate plane-vertex buffer if we need to if (!planeVerts || nrPlaneVerts > numAllocedPlaneVerts) { numAllocedPlaneVerts = (UINT16)nrPlaneVerts; Z_Free(planeVerts); - Z_Malloc(numAllocedPlaneVerts * sizeof (FOutVector), PU_LEVEL, &planeVerts); + Z_Malloc(numAllocedPlaneVerts * sizeof(FOutVector), PU_LEVEL, &planeVerts); } height = FixedToFloat(fixedheight); @@ -2660,72 +2748,51 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, flatxref = FixedToFloat(polysector->origVerts[0].x); flatyref = FixedToFloat(polysector->origVerts[0].y); - flatxref = (float)(((fixed_t)flatxref & (~flatflag)) / fflatsize); - flatyref = (float)(((fixed_t)flatyref & (~flatflag)) / fflatsize); + flatxref = static_cast(static_cast(flatxref) & (~flatflag)) / fflatsize; + flatyref = static_cast(static_cast(flatyref) & (~flatflag)) / fflatsize; - // transform - v3d = planeVerts; - - if (FOFsector != NULL) + if (!isceiling) // it's a floor { - if (!isceiling) // it's a floor - { - scrollx = FixedToFloat(FOFsector->floor_xoffs)/fflatsize; - scrolly = FixedToFloat(FOFsector->floor_yoffs)/fflatsize; - angle = FOFsector->floorpic_angle>>ANGLETOFINESHIFT; - } - else // it's a ceiling - { - scrollx = FixedToFloat(FOFsector->ceiling_xoffs)/fflatsize; - scrolly = FixedToFloat(FOFsector->ceiling_yoffs)/fflatsize; - angle = FOFsector->ceilingpic_angle>>ANGLETOFINESHIFT; - } + scrollx = FixedToFloat(sec->floor_xoffs)/fflatsize; + scrolly = FixedToFloat(sec->floor_yoffs)/fflatsize; + angle = sec->floorpic_angle; } - else if (gl_frontsector) + else // it's a ceiling { - if (!isceiling) // it's a floor - { - scrollx = FixedToFloat(gl_frontsector->floor_xoffs)/fflatsize; - scrolly = FixedToFloat(gl_frontsector->floor_yoffs)/fflatsize; - angle = gl_frontsector->floorpic_angle>>ANGLETOFINESHIFT; - } - else // it's a ceiling - { - scrollx = FixedToFloat(gl_frontsector->ceiling_xoffs)/fflatsize; - scrolly = FixedToFloat(gl_frontsector->ceiling_yoffs)/fflatsize; - angle = gl_frontsector->ceilingpic_angle>>ANGLETOFINESHIFT; - } + scrollx = FixedToFloat(sec->ceiling_xoffs)/fflatsize; + scrolly = FixedToFloat(sec->ceiling_yoffs)/fflatsize; + angle = sec->ceilingpic_angle; } if (angle) // Only needs to be done if there's an altered angle { // This needs to be done so that it scrolls in a different direction after rotation like software - tempxsow = FloatToFixed(scrollx); - tempytow = FloatToFixed(scrolly); - scrollx = (FixedToFloat(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - scrolly = (FixedToFloat(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + tempxsow = flatxref; + tempytow = flatyref; + anglef = ANG2RAD(InvAngle(angle)); // This needs to be done so everything aligns after rotation // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does - tempxsow = FloatToFixed(flatxref); - tempytow = FloatToFixed(flatyref); - flatxref = (FixedToFloat(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - flatyref = (FixedToFloat(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + cosangf = cosf(anglef); + sinangf = sinf(anglef); + flatxref = (tempxsow * cosangf) - (tempytow * sinangf); + flatyref = (tempxsow * sinangf) + (tempytow * cosangf); } - for (i = 0; i < (INT32)nrPlaneVerts; i++,v3d++) + for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++, v3d++) { - // Hurdler: add scrolling texture on floor/ceiling - v3d->s = (float)((FixedToFloat(polysector->origVerts[i].x) / fflatsize) - flatxref + scrollx); // Go from the polysector's original vertex locations - v3d->t = (float)(flatyref - (FixedToFloat(polysector->origVerts[i].y) / fflatsize) + scrolly); // Means the flat is offset based on the original vertex locations + // Go from the polysector's original vertex locations + // Means the flat is offset based on the original vertex locations + v3d->s = ((FixedToFloat(polysector->origVerts[i].x) / fflatsize) - flatxref + scrollx); + v3d->t = (flatyref - (FixedToFloat(polysector->origVerts[i].y) / fflatsize) + scrolly); // Need to rotate before translate if (angle) // Only needs to be done if there's an altered angle { - tempxsow = FloatToFixed(v3d->s); - tempytow = FloatToFixed(v3d->t); - v3d->s = (FixedToFloat(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - v3d->t = (FixedToFloat(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); + tempxsow = v3d->s; + tempytow = v3d->t; + v3d->s = (tempxsow * cosangf) - (tempytow * sinangf); + v3d->t = (tempxsow * sinangf) + (tempytow * cosangf); } v3d->x = FixedToFloat(polysector->vertices[i]->x); @@ -2956,7 +3023,7 @@ static void HWR_Subsector(size_t num) if (anyMoved == true) { gl_frontsector->numlights = sub->sector->numlights = 0; - R_Prep3DFloors(gl_frontsector); + R_Prep3DFloors(gl_frontsector, locCeilingHeight); sub->sector->lightlist = gl_frontsector->lightlist; sub->sector->numlights = gl_frontsector->numlights; sub->sector->moved = gl_frontsector->moved = false; @@ -3004,7 +3071,7 @@ static void HWR_Subsector(size_t num) // Hack to make things continue to work around slopes. locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gl_frontsector->ceilingheight, // We now return you to your regularly scheduled rendering. - PF_Occlude, ceilinglightlevel, levelflats[gl_frontsector->ceilingpic].lumpnum,NULL, 255, ceilingcolormap); + PF_Occlude, ceilinglightlevel, levelflats[gl_frontsector->ceilingpic].lumpnum, NULL, 255, ceilingcolormap); } } } @@ -3036,8 +3103,8 @@ static void HWR_Subsector(size_t num) centerHeight = P_GetFFloorBottomZAt(rover, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); if (centerHeight <= locCeilingHeight && centerHeight >= locFloorHeight && - ((viewz < bottomCullHeight && !(rover->flags & FF_INVERTPLANES)) || - (viewz > bottomCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + ((viewz < bottomCullHeight && !(rover->flags & FF_INVERTPLANES)) || + (viewz > bottomCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) { @@ -3081,9 +3148,9 @@ static void HWR_Subsector(size_t num) centerHeight = P_GetFFloorTopZAt(rover, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); if (centerHeight >= locFloorHeight && - centerHeight <= locCeilingHeight && - ((viewz > topCullHeight && !(rover->flags & FF_INVERTPLANES)) || - (viewz < topCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + centerHeight <= locCeilingHeight && + ((viewz > topCullHeight && !(rover->flags & FF_INVERTPLANES)) || + (viewz < topCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) { @@ -3162,12 +3229,15 @@ doaddline: // hurdler: false: we only add the sprites, the walls are drawn first if (line) { - // draw sprites first, coz they are clipped to the solidsegs of - // subsectors more 'in front' - if (cv_drawdist.value || current_bsp_culling_distance) - HWR_AddSprites(gl_frontsector); - else - HWR_AddSprites(gl_frontsector); + if (sub->sector->validcount != validcount) + { + // draw sprites first, coz they are clipped to the solidsegs of + // subsectors more 'in front' + if (cv_drawdist.value || current_bsp_culling_distance) + HWR_AddSprites(gl_frontsector); + else + HWR_AddSprites(gl_frontsector); + } //Hurdler: at this point validcount must be the same, but is not because // gl_frontsector doesn't point anymore to sub->sector due to @@ -3429,13 +3499,13 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t if (spr->mobj && fabsf(this_scale - 1.0f) > 1.0E-36f) { // Always a pixel above the floor, perfectly flat. - swallVerts[0].y = swallVerts[1].y = swallVerts[2].y = swallVerts[3].y = spr->gzt - gpatch->topoffset * this_scale - (floorheight+3); + swallVerts[0].y = swallVerts[1].y = swallVerts[2].y = swallVerts[3].y = spr->gzt - static_cast(gpatch->topoffset) * this_scale - static_cast(floorheight+3); // Now transform the TOP vertices along the floor in the direction of the camera - swallVerts[3].x = spr->x1 + ((gpatch->height * this_scale) + offset) * gl_viewcos; - swallVerts[2].x = spr->x2 + ((gpatch->height * this_scale) + offset) * gl_viewcos; - swallVerts[3].z = spr->z1 + ((gpatch->height * this_scale) + offset) * gl_viewsin; - swallVerts[2].z = spr->z2 + ((gpatch->height * this_scale) + offset) * gl_viewsin; + swallVerts[3].x = spr->x1 + ((static_cast(gpatch->height) * this_scale) + offset) * gl_viewcos; + swallVerts[2].x = spr->x2 + ((static_cast(gpatch->height) * this_scale) + offset) * gl_viewcos; + swallVerts[3].z = spr->z1 + ((static_cast(gpatch->height) * this_scale) + offset) * gl_viewsin; + swallVerts[2].z = spr->z2 + ((static_cast(gpatch->height) * this_scale) + offset) * gl_viewsin; } else { @@ -3443,10 +3513,10 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t swallVerts[0].y = swallVerts[1].y = swallVerts[2].y = swallVerts[3].y = spr->gzt - gpatch->topoffset - (floorheight+3); // Now transform the TOP vertices along the floor in the direction of the camera - swallVerts[3].x = spr->x1 + (gpatch->height + offset) * gl_viewcos; - swallVerts[2].x = spr->x2 + (gpatch->height + offset) * gl_viewcos; - swallVerts[3].z = spr->z1 + (gpatch->height + offset) * gl_viewsin; - swallVerts[2].z = spr->z2 + (gpatch->height + offset) * gl_viewsin; + swallVerts[3].x = spr->x1 + (static_cast(gpatch->height) + offset) * gl_viewcos; + swallVerts[2].x = spr->x2 + (static_cast(gpatch->height) + offset) * gl_viewcos; + swallVerts[3].z = spr->z1 + (static_cast(gpatch->height) + offset) * gl_viewsin; + swallVerts[2].z = spr->z2 + (static_cast(gpatch->height) + offset) * gl_viewsin; } // We also need to move the bottom ones away when shadowoffs is on @@ -4157,6 +4227,7 @@ static int CompareVisSprites(const void *p1, const void *p2) static void HWR_SortVisSprites(void) { UINT32 i; + for (i = 0; i < gl_visspritecount; i++) { gl_vsprorder[i] = HWR_GetVisSprite(i); @@ -4225,38 +4296,29 @@ typedef struct // initial size of drawnode array #define DRAWNODES_INIT_SIZE 64 -gl_drawnode_t *drawnodes = NULL; -INT32 numdrawnodes = 0; -INT32 alloceddrawnodes = 0; +// no reason to waste all the allocations since every map will have atleast one translucent thing +static std::vector drawnodes; static void *HWR_CreateDrawNode(gl_drawnode_type_t type) { - gl_drawnode_t *drawnode; + // if we didnt alloc anything yet, reserve atleast 64 nodes + // dont declare with it as we want our size to be 0! + drawnodes.reserve(DRAWNODES_INIT_SIZE); - if (!drawnodes) - { - alloceddrawnodes = DRAWNODES_INIT_SIZE; - drawnodes = static_cast(Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes)); - } - else if (numdrawnodes >= alloceddrawnodes) - { - alloceddrawnodes *= 2; - Z_Realloc(drawnodes, alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes); - } - - drawnode = &drawnodes[numdrawnodes++]; - drawnode->type = type; + drawnodes.emplace_back(); + drawnodes.back().type = type; // not sure if returning different pointers to a union is necessary switch (type) { case DRAWNODE_PLANE: - return &drawnode->u.plane; + return &drawnodes.back().u.plane; case DRAWNODE_POLYOBJECT_PLANE: - return &drawnode->u.polyplane; + return &drawnodes.back().u.polyplane; case DRAWNODE_WALL: - return &drawnode->u.wall; + return &drawnodes.back().u.wall; } + return NULL; } @@ -4320,11 +4382,15 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) // Sorts and renders the list of drawnodes for the scene being rendered. static void HWR_RenderDrawNodes(void) { - INT32 i = 0, run_start = 0; + size_t i = 0, run_start = 0; + static std::vector sortindex; + + sortindex.reserve(DRAWNODES_INIT_SIZE); // Array for storing the rendering order. // A list of indices into the drawnodes array. - INT32 *sortindex; + + const size_t numdrawnodes = drawnodes.size(); if (!numdrawnodes) return; @@ -4333,7 +4399,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodesorttime); - sortindex = static_cast(Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL)); + sortindex.resize(numdrawnodes); // Reversed order for (i = 0; i < numdrawnodes; i++) @@ -4349,7 +4415,7 @@ static void HWR_RenderDrawNodes(void) if (drawnodes[sortindex[run_start]].type == DRAWNODE_PLANE) { // found it, now look for run end - INT32 run_end; // (inclusive) + size_t run_end; // (inclusive) for (i = run_start+1; i < numdrawnodes; i++) { @@ -4362,7 +4428,7 @@ static void HWR_RenderDrawNodes(void) if (run_end > run_start) // if there are multiple consecutive planes, not just one { // consecutive run of planes found, now sort it - qs22j(sortindex + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); + qs22j(sortindex.data() + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); } run_start = run_end + 1; // continue looking for runs coming right after this one @@ -4434,9 +4500,7 @@ static void HWR_RenderDrawNodes(void) PS_STOP_TIMING(ps_hw_nodedrawtime); - numdrawnodes = 0; - - Z_Free(sortindex); + drawnodes.clear(); // clear so our size is 0 again! } @@ -4624,9 +4688,10 @@ static void HWR_ProjectSprite(mobj_t *thing) float tr_x, tr_y; float tz; float x1, x2; + float y1, y2; float z1, z2; float rightsin, rightcos; - float this_scale; + float thing_scale; float spritexscale, spriteyscale; float gz, gzt; spritedef_t *sprdef; @@ -4695,10 +4760,6 @@ static void HWR_ProjectSprite(mobj_t *thing) const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); - this_scale = FixedToFloat(interp.scale); - spritexscale = FixedToFloat(interp.spritexscale); - spriteyscale = FixedToFloat(interp.spriteyscale); - // decide which patch to use for sprite relative to player #ifdef RANGECHECK if ((unsigned)thing->sprite >= numsprites) @@ -4799,9 +4860,6 @@ static void HWR_ProjectSprite(mobj_t *thing) flip ^= (1<flags & SF_HIRES)) - this_scale *= FixedToFloat(sprskin->highresscale); - spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; spr_offset = spritecachedinfo[lumpoff].offset; @@ -4846,19 +4904,13 @@ static void HWR_ProjectSprite(mobj_t *thing) spr_offset += interp.spritexoffset; spr_topoffset += interp.spriteyoffset; - if (papersprite) - { - rightsin = FixedToFloat(FINESINE(interp.angle >> ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE(interp.angle >> ANGLETOFINESHIFT)); - } - else - { - rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - } + thing_scale = FixedToFloat(interp.scale); - spritexscale *= this_scale; - spriteyscale *= this_scale; + if (sprskin && (sprskin->flags & SF_HIRES)) + thing_scale *= FixedToFloat(sprskin->highresscale); + + spritexscale = FixedToFloat(interp.spritexscale) * thing_scale; + spriteyscale = FixedToFloat(interp.spriteyscale) * thing_scale; flip = !flip != !hflip; @@ -4873,19 +4925,17 @@ static void HWR_ProjectSprite(mobj_t *thing) x2 = (FixedToFloat(spr_width - spr_offset) * spritexscale); } - z1 = tr_y + x1 * rightsin; - z2 = tr_y - x2 * rightsin; - x1 = tr_x + x1 * rightcos; - x2 = tr_x - x2 * rightcos; + y1 = (FixedToFloat(spr_topoffset) * spriteyscale); + y2 = (FixedToFloat(spr_height - spr_topoffset) * spriteyscale); if (vflip) { - gz = FixedToFloat(interp.z + thing->height) - (FixedToFloat(spr_topoffset) * spriteyscale); + gz = FixedToFloat(interp.z + thing->height) - y1; gzt = gz + (FixedToFloat(spr_height) * spriteyscale); } else { - gzt = FixedToFloat(interp.z) + (FixedToFloat(spr_topoffset) * spriteyscale); + gzt = FixedToFloat(interp.z) + y1; gz = gzt - (FixedToFloat(spr_height) * spriteyscale); } @@ -4895,6 +4945,18 @@ static void HWR_ProjectSprite(mobj_t *thing) return; } + // if the sprite is out of our view, dont need to draw it X) + if (!gld_SphereInFrustum( + (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.z) + (y1 + y2) / 2.0f, + FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + //1.5 == sqrt(2) + small delta for MF_FOREGROUND + std::max(FixedToFloat(spr_width) * spritexscale, + FixedToFloat(spr_height) * spriteyscale) / 2.0f * 1.5f)) + { + return; + } + heightsec = thing->subsector->sector->heightsec; if (viewplayer && viewplayer->mo && viewplayer->mo->subsector) phs = viewplayer->mo->subsector->sector->heightsec; @@ -4903,16 +4965,39 @@ static void HWR_ProjectSprite(mobj_t *thing) if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { - if (gl_viewz < FixedToFloat(sectors[phs].floorheight) ? - FixedToFloat(interp.z) >= FixedToFloat(sectors[heightsec].floorheight) : - gzt < FixedToFloat(sectors[heightsec].floorheight)) + fixed_t secheight; + + secheight = P_GetSectorFloorZAt(§ors[heightsec], viewx, viewy); + if (viewz < P_GetSectorFloorZAt(§ors[phs], interp.x, interp.y) ? + interp.z >= secheight : + FloatToFixed(gzt) < secheight) return; - if (gl_viewz > FixedToFloat(sectors[phs].ceilingheight) ? - gzt < FixedToFloat(sectors[heightsec].ceilingheight) && gl_viewz >= FixedToFloat(sectors[heightsec].ceilingheight) : - FixedToFloat(interp.z) >= FixedToFloat(sectors[heightsec].ceilingheight)) + + secheight = P_GetSectorCeilingZAt(§ors[heightsec], viewx, viewy); + if (viewz > P_GetSectorCeilingZAt(§ors[phs], interp.x, interp.y) ? + FloatToFixed(gzt) < secheight && viewz >= secheight : + interp.z >= secheight) return; } + if (papersprite) + { + rightsin = FixedToFloat(FINESINE(interp.angle >> ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE(interp.angle >> ANGLETOFINESHIFT)); + } + else + { + rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + } + + z1 = tr_y + x1 * rightsin; + z2 = tr_y - x2 * rightsin; + x1 = tr_x + x1 * rightcos; + x2 = tr_x - x2 * rightcos; + //y1 = tr_y + y1 * rightcos; + //y2 = tr_y - y2 * rightcos; + // store information in a vissprite vis = HWR_NewVisSprite(); vis->x1 = x1; @@ -4925,7 +5010,7 @@ static void HWR_ProjectSprite(mobj_t *thing) vis->dispoffset = thing->info->dispoffset; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST vis->flip = flip; - vis->scale = this_scale; + vis->scale = thing_scale; vis->spritexscale = spritexscale; vis->spriteyscale = spriteyscale; vis->spritexoffset = FixedToFloat(spr_offset); @@ -4933,10 +5018,10 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE if (rotsprite != NULL) - vis->gpatch = (patch_t *)rotsprite; + vis->gpatch = static_cast(rotsprite); else #endif - vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); + vis->gpatch = static_cast(W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE)); vis->mobj = thing; @@ -4988,12 +5073,16 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) float tr_x, tr_y; float tz; float x1, x2; + float y1, y2; float z1, z2; + float gz, gzt; float rightsin, rightcos; - float this_scale; + float thing_scale; spritedef_t *sprdef; spriteframe_t *sprframe; size_t lumpoff; + fixed_t spr_width, spr_height; + fixed_t spr_offset, spr_topoffset; unsigned rot = 0; UINT8 flip; @@ -5024,7 +5113,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) return; // decide which patch to use for sprite relative to player - if ((unsigned)thing->sprite >= numsprites) + if (static_cast(thing->sprite) >= numsprites) { #ifdef RANGECHECK I_Error("HWR_ProjectPrecipitationSprite: invalid sprite number %i ", @@ -5036,7 +5125,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) sprdef = &sprites[thing->sprite]; - if ((size_t)(thing->frame&FF_FRAMEMASK) >= sprdef->numframes) + if (static_cast((thing->frame&FF_FRAMEMASK)) >= sprdef->numframes) { #ifdef RANGECHECK I_Error("HWR_ProjectPrecipitationSprite: invalid sprite frame %i : %i for %s", @@ -5046,7 +5135,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif } - this_scale = FixedToFloat(interp.scale); + thing_scale = FixedToFloat(interp.scale); sprframe = &sprdef->spriteframes[thing->frame & FF_FRAMEMASK]; @@ -5054,27 +5143,53 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) lumpoff = sprframe->lumpid[0]; flip = sprframe->flip; // Will only be 0x00 or 0xFF - rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); - rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + spr_width = spritecachedinfo[lumpoff].width; + spr_height = spritecachedinfo[lumpoff].height; + spr_offset = spritecachedinfo[lumpoff].offset; + spr_topoffset = spritecachedinfo[lumpoff].topoffset; if (flip) { - x1 = FixedToFloat(spritecachedinfo[lumpoff].width - spritecachedinfo[lumpoff].offset); - x2 = FixedToFloat(spritecachedinfo[lumpoff].offset); + x1 = FixedToFloat(spr_width - spr_offset); + x2 = FixedToFloat(spr_offset); } else { - x1 = FixedToFloat(spritecachedinfo[lumpoff].offset); - x2 = FixedToFloat(spritecachedinfo[lumpoff].width - spritecachedinfo[lumpoff].offset); + x1 = x2 = FixedToFloat(spr_offset); } - x1 *= this_scale; - x2 *= this_scale; + y1 = (FixedToFloat(spr_topoffset)); + y2 = (FixedToFloat(spr_height - spr_topoffset)); + + x1 *= thing_scale; + x2 *= thing_scale; + y1 *= thing_scale; + y2 *= thing_scale; + + if (!gld_SphereInFrustum( + (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.z) + (y1 + y2) / 2.0f, + FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + //1.5 == sqrt(2) + small delta for MF_FOREGROUND + std::max(FixedToFloat(spr_width) * thing_scale, + FixedToFloat(spr_height) * thing_scale) / 2.0f * 1.5f)) + { + return; + } + + // set top/bottom coords + gzt = FixedToFloat(interp.z) + y1; + gz = gzt - (FixedToFloat(spr_height) * thing_scale); + + rightsin = FixedToFloat(FINESINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); + rightcos = FixedToFloat(FINECOSINE((viewangle + ANGLE_90)>>ANGLETOFINESHIFT)); z1 = tr_y + x1 * rightsin; z2 = tr_y - x2 * rightsin; x1 = tr_x + x1 * rightcos; x2 = tr_x - x2 * rightcos; + //y1 = tr_y + y1 * rightcos; + //y2 = tr_y - y2 * rightcos; // // store information in a vissprite @@ -5086,7 +5201,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->z2 = z2; vis->tz = tz; vis->dispoffset = 0; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST - vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); + vis->gpatch = static_cast(W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE)); vis->flip = flip; vis->mobj = NULL; @@ -5098,8 +5213,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #endif // set top/bottom coords - vis->gzt = FixedToFloat(interp.z) + (FixedToFloat(spritecachedinfo[lumpoff].topoffset) * this_scale); - vis->gz = vis->gzt - (FixedToFloat(spritecachedinfo[lumpoff].height) * this_scale); + vis->gzt = gzt; + vis->gz = gz; vis->precip = thing; } @@ -5113,11 +5228,10 @@ static gl_sky_t gl_sky; static void HWR_SkyDomeVertex(gl_sky_t *sky, gl_skyvertex_t *vbo, int r, int c, signed char yflip, float delta, boolean foglayer) { - static constexpr float radians = (float)(M_PIl / 180.0f); static constexpr float scale = 10000.0f; - static constexpr float maxSideAngle = 60.0f * radians; + static constexpr float maxSideAngle = 60.0f * deg2radians; - float topAngle = ((float)c / (float)sky->columns * 360.0f) * radians; + float topAngle = ((float)c / (float)sky->columns * 360.0f) * deg2radians; float sideAngle = (maxSideAngle * (float)(sky->rows - r) / (float)sky->rows); float height = sinf(sideAngle); float realRadius = (scale * cosf(sideAngle)); @@ -5175,7 +5289,6 @@ void HWR_ClearSkyDome(void) sky->rows = sky->columns = 0; sky->loopcount = 0; - sky->detail = 0; sky->texture = -1; sky->width = sky->height = 0; @@ -5194,8 +5307,7 @@ void HWR_BuildSkyDome(void) gl_skyvertex_t *vertex_p; const texture_t *texture = textures[texturetranslation[skytexture]]; - sky->detail = 16; - col_count *= sky->detail; + col_count *= 16; if ((sky->columns != col_count) || (sky->rows != row_count)) HWR_ClearSkyDome(); @@ -5255,16 +5367,14 @@ void HWR_BuildSkyDome(void) } } -static boolean drewsky = false; - // precompute to save a bit of division -static constexpr float FINEDEGREE = (360.0f/(float)FINEANGLES); +static constexpr float FINEDEGREE = (360.0f/static_cast(FINEANGLES)); static void HWR_DrawSkyBackground(void) { FTransform dometransform; - if (drewsky || HWR_IsWireframeMode()) + if (HWR_IsWireframeMode()) return; GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); @@ -5276,7 +5386,7 @@ static void HWR_DrawSkyBackground(void) //04/01/2000: Hurdler: added for T&L // It should replace all other gl_viewxxx when finished HWR_SetTransformAiming(&dometransform); - dometransform.angley = (float)((viewangle-ANGLE_270)>>ANGLETOFINESHIFT)*(FINEDEGREE); + dometransform.angley = static_cast((viewangle-ANGLE_270) >> ANGLETOFINESHIFT)*(FINEDEGREE); HWR_GetTexture(texturetranslation[skytexture], false); @@ -5321,7 +5431,7 @@ static void HWR_SetTransformAiming(FTransform *trans) if (cv_glshearing.value) { fixed_t fixedaiming = AIMINGTODY(aimingangle); - trans->viewaiming = FixedToFloat(fixedaiming) * ((float)vid.width / vid.height) / ((float)BASEVIDWIDTH / BASEVIDHEIGHT); + trans->viewaiming = FixedToFloat(fixedaiming) * (static_cast(vid.width) / static_cast(vid.height)) / (static_cast(BASEVIDWIDTH) / static_cast(BASEVIDHEIGHT)); if (splitscreen == 1) // only for 2 player splitscreen trans->viewaiming *= 2.125; // splitscreen adjusts fov with 0.8, so compensate (but only halfway, since splitscreen means only half the screen is used) trans->shearing = true; @@ -5333,7 +5443,7 @@ static void HWR_SetTransformAiming(FTransform *trans) gl_aimingangle = aimingangle; } - trans->anglex = (float)(gl_aimingangle>>ANGLETOFINESHIFT)*(FINEDEGREE); + trans->anglex = static_cast(gl_aimingangle >> ANGLETOFINESHIFT)*(FINEDEGREE); } void HWR_SetTransform(float fpov) @@ -5352,17 +5462,23 @@ void HWR_SetTransform(float fpov) atransform.z = gl_viewz; atransform.scalex = 1; - atransform.scaley = (float)vid.width/vid.height; + atransform.scaley = static_cast(vid.width) / static_cast(vid.height); atransform.scalez = 1; HWR_SetTransformAiming(&atransform); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(FINEDEGREE); + atransform.angley = static_cast(viewangle >> ANGLETOFINESHIFT)*(FINEDEGREE); + + yaw = 270.0f - atransform.angley; + inv_yaw = 180.0f - yaw; + const float inv_yaw_radians = inv_yaw * deg2radians; + cos_inv_yaw = cosf(inv_yaw_radians); + sin_inv_yaw = sinf(inv_yaw_radians); // only needed for sprite billboarding if (cv_glspritebillboarding.value && !cv_glshearing.value) { - gl_viewludsin = FixedToFloat(FINECOSINE(gl_aimingangle>>ANGLETOFINESHIFT)); - gl_viewludcos = FixedToFloat(-FINESINE(gl_aimingangle>>ANGLETOFINESHIFT)); + gl_viewludsin = FixedToFloat(FINECOSINE(gl_aimingangle >> ANGLETOFINESHIFT)); + gl_viewludcos = FixedToFloat(-FINESINE(gl_aimingangle >> ANGLETOFINESHIFT)); } atransform.fovangle = fpov; // Tails @@ -5415,15 +5531,22 @@ namespace }; template -void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) +static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; - const float fpov = FixedToFloat(R_GetPlayerFov(player)); - const boolean skybox = (skyboxmo[0] && cv_skybox.value); + player_t *viewplayer = &players[displayplayers[viewssnum]]; + const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); + + auto reset_viewstate = [&]() + { + HWR_SetTransform(fpov); + HWR_ClearSprites(); + HWR_ClearClipper(); + }; portallist.base = portallist.cap = NULL; - HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls + HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regular walls if constexpr (Type == RenderViewpointType::kPortal) { @@ -5435,10 +5558,12 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ currentportallist = &portallist; HWR_SetPortalState(GLPORTAL_SEARCH); - HWR_ClearClipper(); + reset_viewstate(); if (rootportal) + { HWR_PortalClipping(rootportal); + } validcount++; @@ -5449,7 +5574,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ // note: if necessary, could sort the portals here? for (portal = portallist.base; portal; portal = portal->next) { - HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); + HWR_RenderPortal(portal, rootportal, fpov, stencil_level); } HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn @@ -5459,10 +5584,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); - HWR_SetTransform(fpov); - - HWR_ClearSprites(); - HWR_ClearClipper(); + reset_viewstate(); if constexpr (Type == RenderViewpointType::kPortal) { @@ -5476,6 +5598,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); + // FIXME: perfstats does not account for portal rendering! ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); @@ -5487,8 +5610,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if constexpr (Type == RenderViewpointType::kPortal) { - if (allow_portals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently - gl_collect_skywalls = true; + gl_collect_skywalls = (allow_portals && !rootportal && portallist.base && (!skyboxmo[0] || !cv_skybox.value)); // if portals have been drawn in the main view, then render skywalls differently // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. // This fixes specific effects not working, such as horizon lines. @@ -5520,6 +5642,9 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if (LIKELY(cv_glbatching.value)) HWR_RenderBatches(); + // Check for new console commands. + NetUpdate(); + if constexpr (Type == RenderViewpointType::kPortal) { if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method @@ -5528,13 +5653,13 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ HWR_DrawSkyWallList(); HWR_SkyWallList_Clear(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); - drewsky = false; HWR_DrawSkyBackground(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - GL_ClearBuffer(false, false, true, NULL);// clear skywall markings from the stencil buffer - HWR_SetTransform(fpov);// restore transform + GL_ClearBuffer(false, false, true, NULL); // clear skywall markings from the stencil buffer + HWR_SetTransform(fpov); // restore transform } } + gl_collect_skywalls = false; ps_numsprites.value.i = gl_visspritecount; @@ -5551,6 +5676,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ ps_numdrawnodes.value.i = 0; ps_hw_nodesorttime.value.p = 0; ps_hw_nodedrawtime.value.p = 0; + HWR_RenderDrawNodes(); if (HWR_IsWireframeMode()) @@ -5561,26 +5687,22 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ }; extern "C" { - void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) { - HWR_RenderViewpoint(rootportal, player, stencil_level, allow_portals); + void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals) { + HWR_RenderViewpoint(rootportal, stencil_level, allow_portals); } } // ========================================================================== // Render the current frame. // ========================================================================== -static void HWR_RenderFrame(player_t *player, boolean skybox) +static void HWR_RenderFrame(boolean skybox, boolean drawsky) { - // check for new console commands. - NetUpdate(); - // Clear view, set viewport (glViewport), set perspective... HWR_ClearView(); // Draw the sky background. - HWR_DrawSkyBackground(); - if (skybox) - drewsky = true; + if (drawsky) + HWR_DrawSkyBackground(); current_bsp_culling_distance = 0; @@ -5596,26 +5718,17 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) current_bsp_culling_distance = bsp_culling_distances[renderdist- 1]; } - portalclipline = NULL; - if (UNLIKELY(HWR_UsePortals())) - HWR_RenderViewpoint(NULL, player, 0, !skybox); - else - HWR_RenderViewpoint(NULL, player, 0, !skybox); - - // Unset transform and shader - GL_SetTransform(NULL); - GL_UnSetShader(); - - // Run post processor effects - if (!skybox) - HWR_DoPostProcessor(player); - // Check for new console commands. NetUpdate(); - // added by Hurdler for correct splitscreen - // moved here by hurdler so it works with the new near clipping plane - GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + portalclipline = NULL; + if (UNLIKELY(HWR_UsePortals())) + HWR_RenderViewpoint(NULL, 0, !skybox); + else + HWR_RenderViewpoint(NULL, 0, !skybox); + + // Check for new console commands. + NetUpdate(); } // ========================================================================== @@ -5626,7 +5739,7 @@ static void HWR_RollTransform(FTransform *tr, angle_t roll) { if (roll != 0) { - tr->rollangle = roll / (float)ANG1; + tr->rollangle = static_cast(roll) / static_cast(ANG1); tr->roll = true; tr->rollx = 1.0f; tr->rollz = 0.0f; @@ -5665,22 +5778,31 @@ void HWR_RenderPlayerView(void) if (viewssnum > 3) return; - player_t * player = &players[displayplayers[viewssnum]]; const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on // Render the skybox if there is one. PS_START_TIMING(ps_skyboxtime); - drewsky = false; if (skybox) { R_SkyboxFrame(viewssnum); - HWR_RenderFrame(player, true); + HWR_RenderFrame(true, true); } PS_STOP_TIMING(ps_skyboxtime); R_SetupFrame(viewssnum, false); // This can stay false because it is only used to set viewsky in r_main.c, which isn't used here framecount++; // for timedemo - HWR_RenderFrame(player, false); + HWR_RenderFrame(false, !skybox); + + // Unset transform and shader + GL_SetTransform(NULL); + GL_UnSetShader(); + + // Run post processor effects + HWR_DoPostProcessor(); + + // added by Hurdler for correct splitscreen + // moved here by hurdler so it works with the new near clipping plane + GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } void HWR_LoadLevel(void) @@ -5891,6 +6013,7 @@ void HWR_Shutdown(void) HWR_FreeExtraSubsectors(); HWR_FreeMapTextures(); GL_FlushScreenTextures(); + HWR_ClearAllTextures(); #ifdef USE_FBO_OGL GL_Framebuffer_Disable(); #endif @@ -5933,35 +6056,40 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD #endif } -static void HWR_DoPostProcessor(player_t *player) +static void HWR_DoPostProcessor(void) { - GL_UnSetShader(); - // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (!HWR_PalRenderFlashpal() && player->flashcount) + if (!HWR_PalRenderFlashpal()) { - FOutVector v[4]; - FSurfaceInfo Surf; + const player_t *player = &players[displayplayers[viewssnum]]; - v[0].x = v[2].y = v[3].x = v[3].y = -4.0f; - v[0].y = v[1].x = v[1].y = v[2].x = 4.0f; - v[0].z = v[1].z = v[2].z = v[3].z = 4.0f; // 4.0 because of the same reason as with the sky, just after the screen is cleared so near clipping plane is 3.99 - - // This won't change if the flash palettes are changed unfortunately, but it works for its purpose - if (player->flashpal == PAL_NUKE) + if (player->flashcount) { - Surf.PolyColor.s.red = 0xff; - Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0x7F; // The nuke palette is kind of pink-ish + static FOutVector v[4] = { + {-4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, + { 4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, // 4.0 because of the same reason as with the sky, just after the screen is cleared so near clipping plane is 3.99 + { 4.0f, -4.0f, 4.0f, 0.0f, 0.0f}, + {-4.0f, -4.0f, 4.0f, 0.0f, 0.0f} + }; + + FSurfaceInfo Surf; + + // This won't change if the flash palettes are changed unfortunately, but it works for its purpose + if (player->flashpal == PAL_NUKE) + { + Surf.PolyColor.s.red = 0xff; + Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0x7F; // The nuke palette is kind of pink-ish + } + else + Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; + + Surf.PolyColor.s.alpha = 0xc0; // match software mode + + V_CubeApply(&Surf.PolyColor); + + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } - else - Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; - - Surf.PolyColor.s.alpha = 0xc0; // match software mode - - V_CubeApply(&Surf.PolyColor); - - GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } if (cv_glscreentextures.value != 2) // screen textures are needed for the rest of the effects @@ -6011,7 +6139,7 @@ static void HWR_DoPostProcessor(player_t *player) for (y = 0; y < SCREENVERTS; y++) { // Change X position based on its Y position. - v[x][y][0] = x-4.5f + sinf(((disStart+((float)y * WAVELENGTH)) / FREQUENCY)) / AMPLITUDE; // (x / scale) + v[x][y][0] = x-4.5f + sinf(((disStart+(static_cast(y) * WAVELENGTH)) / FREQUENCY)) / AMPLITUDE; // (x / scale) v[x][y][1] = y-4.5f; // (y / scale) } } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 30906b611..8b5284acb 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -102,8 +102,7 @@ void HWR_SetViewSize(void); void HWR_AddCommands(void); void HWR_RenderPlayerView(void); -void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals); -void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals); +void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals); void HWR_ClearSkyDome(void); void HWR_BuildSkyDome(void); diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index d8ad87354..e588adea1 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -38,7 +38,7 @@ void HWR_PortalClipping(gl_portal_t *portal) gld_clipper_SafeAddClipRange(portal->angle1, portal->angle2); } -static gl_portal_t* HWR_Portal_Add (seg_t *seg) +static gl_portal_t* HWR_Portal_Add(seg_t *seg) { gl_portal_t *portal = Z_Malloc(sizeof(gl_portal_t), PU_STATIC, NULL); @@ -120,8 +120,8 @@ void HWR_PortalFrame(gl_portal_t* portal) viewz = portal->viewz; viewangle = portal->viewangle; - //viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); - //viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); + viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); + viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); if (portal->clipline != -1) { @@ -157,7 +157,7 @@ static void HWR_RenderPortalSeg(gl_portal_t* portal, SINT8 state) } // Renders a single portal from the current viewpoint. -void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level) +void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, int stencil_level) { // draw portal seg to stencil buffer with increment HWR_SetTransform(fpov); @@ -170,7 +170,7 @@ void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float HWR_PortalFrame(portal); // call HWR_RenderViewpoint - HWR_RenderPortalViewpoint(portal, player, stencil_level + 1, true); + HWR_RenderPortalViewpoint(portal, stencil_level + 1, true); // return to current frame if (rootportal) diff --git a/src/hardware/hw_portal.h b/src/hardware/hw_portal.h index 494110d79..db494e5f3 100644 --- a/src/hardware/hw_portal.h +++ b/src/hardware/hw_portal.h @@ -65,7 +65,7 @@ extern SINT8 gl_portal_state; // new thing extern gl_portallist_t *currentportallist; -static inline void HWR_SetPortalState (SINT8 state) +static inline void HWR_SetPortalState(SINT8 state) { gl_portal_state = state; } @@ -75,7 +75,7 @@ void HWR_PortalClipping(gl_portal_t *portal); void HWR_Portal_Add2Lines(const INT32 line1, const INT32 line2, seg_t *seg); void HWR_PortalFrame(gl_portal_t* portal); -void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level); +void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, int stencil_level); void HWR_FreePortalList(gl_portallist_t portallist); boolean HWR_PortalCheckPointSide(fixed_t x, fixed_t y); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 024dd2629..94656e843 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -127,7 +127,7 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -static GLfloat modelMatrix[16]; +GLfloat modelMatrix[16] = {0}; GLfloat projMatrix[16] = {0}; static GLint viewport[4]; @@ -173,41 +173,7 @@ boolean supportstencil = false; // can know when the textures aren't there, as textures are always considered resident in their virtual memory static GLuint screenTextures[NUMSCREENTEXTURES] = {0}; -// shortcut for ((float)1/i) -static const GLfloat byte2float[256] = { - 0.000000f, 0.003922f, 0.007843f, 0.011765f, 0.015686f, 0.019608f, 0.023529f, 0.027451f, - 0.031373f, 0.035294f, 0.039216f, 0.043137f, 0.047059f, 0.050980f, 0.054902f, 0.058824f, - 0.062745f, 0.066667f, 0.070588f, 0.074510f, 0.078431f, 0.082353f, 0.086275f, 0.090196f, - 0.094118f, 0.098039f, 0.101961f, 0.105882f, 0.109804f, 0.113725f, 0.117647f, 0.121569f, - 0.125490f, 0.129412f, 0.133333f, 0.137255f, 0.141176f, 0.145098f, 0.149020f, 0.152941f, - 0.156863f, 0.160784f, 0.164706f, 0.168627f, 0.172549f, 0.176471f, 0.180392f, 0.184314f, - 0.188235f, 0.192157f, 0.196078f, 0.200000f, 0.203922f, 0.207843f, 0.211765f, 0.215686f, - 0.219608f, 0.223529f, 0.227451f, 0.231373f, 0.235294f, 0.239216f, 0.243137f, 0.247059f, - 0.250980f, 0.254902f, 0.258824f, 0.262745f, 0.266667f, 0.270588f, 0.274510f, 0.278431f, - 0.282353f, 0.286275f, 0.290196f, 0.294118f, 0.298039f, 0.301961f, 0.305882f, 0.309804f, - 0.313726f, 0.317647f, 0.321569f, 0.325490f, 0.329412f, 0.333333f, 0.337255f, 0.341176f, - 0.345098f, 0.349020f, 0.352941f, 0.356863f, 0.360784f, 0.364706f, 0.368627f, 0.372549f, - 0.376471f, 0.380392f, 0.384314f, 0.388235f, 0.392157f, 0.396078f, 0.400000f, 0.403922f, - 0.407843f, 0.411765f, 0.415686f, 0.419608f, 0.423529f, 0.427451f, 0.431373f, 0.435294f, - 0.439216f, 0.443137f, 0.447059f, 0.450980f, 0.454902f, 0.458824f, 0.462745f, 0.466667f, - 0.470588f, 0.474510f, 0.478431f, 0.482353f, 0.486275f, 0.490196f, 0.494118f, 0.498039f, - 0.501961f, 0.505882f, 0.509804f, 0.513726f, 0.517647f, 0.521569f, 0.525490f, 0.529412f, - 0.533333f, 0.537255f, 0.541177f, 0.545098f, 0.549020f, 0.552941f, 0.556863f, 0.560784f, - 0.564706f, 0.568627f, 0.572549f, 0.576471f, 0.580392f, 0.584314f, 0.588235f, 0.592157f, - 0.596078f, 0.600000f, 0.603922f, 0.607843f, 0.611765f, 0.615686f, 0.619608f, 0.623529f, - 0.627451f, 0.631373f, 0.635294f, 0.639216f, 0.643137f, 0.647059f, 0.650980f, 0.654902f, - 0.658824f, 0.662745f, 0.666667f, 0.670588f, 0.674510f, 0.678431f, 0.682353f, 0.686275f, - 0.690196f, 0.694118f, 0.698039f, 0.701961f, 0.705882f, 0.709804f, 0.713726f, 0.717647f, - 0.721569f, 0.725490f, 0.729412f, 0.733333f, 0.737255f, 0.741177f, 0.745098f, 0.749020f, - 0.752941f, 0.756863f, 0.760784f, 0.764706f, 0.768627f, 0.772549f, 0.776471f, 0.780392f, - 0.784314f, 0.788235f, 0.792157f, 0.796078f, 0.800000f, 0.803922f, 0.807843f, 0.811765f, - 0.815686f, 0.819608f, 0.823529f, 0.827451f, 0.831373f, 0.835294f, 0.839216f, 0.843137f, - 0.847059f, 0.850980f, 0.854902f, 0.858824f, 0.862745f, 0.866667f, 0.870588f, 0.874510f, - 0.878431f, 0.882353f, 0.886275f, 0.890196f, 0.894118f, 0.898039f, 0.901961f, 0.905882f, - 0.909804f, 0.913726f, 0.917647f, 0.921569f, 0.925490f, 0.929412f, 0.933333f, 0.937255f, - 0.941177f, 0.945098f, 0.949020f, 0.952941f, 0.956863f, 0.960784f, 0.964706f, 0.968628f, - 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f -}; +#define byte2float(byte) (GLfloat)(byte / 255.0f) // -----------------+ // GL_DBG_Printf : Output debug messages to debug log if DEBUG_TO_FILE is defined, @@ -1023,11 +989,9 @@ boolean GL_CompileShader(int slot) { return true; } - else - { - gl_shaders[slot].program = 0; - return false; - } + + gl_shaders[slot].program = 0; + return false; } // @@ -1069,6 +1033,7 @@ void GL_SetShader(int slot) GL_UnSetShader(); return; } + if (gl_allowshaders) { gl_shader_t *next_shader = &gl_shaders[slot]; // the gl_shader_t we are going to switch to @@ -1130,7 +1095,7 @@ static void GL_SetNoTexture(void) // -----------------+ static void GL_Perspective(GLfloat fovy, GLfloat aspect) { - GLfloat m[4][4] = + static GLfloat m[4][4] = { { 1.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f}, @@ -1145,7 +1110,7 @@ static void GL_Perspective(GLfloat fovy, GLfloat aspect) return; } - const GLfloat focallength = (GLfloat)(1.0f / (GLfloat)tan(fovy * (GLfloat)M_PIl / 360.0f)); + const GLfloat focallength = (1.0f / tanf(fovy * M_PIf / 360.0f)); m[0][0] = focallength / aspect; m[1][1] = focallength; @@ -1160,7 +1125,7 @@ static void GL_Perspective(GLfloat fovy, GLfloat aspect) // -----------------+ void GL_SetModelView(GLint w, GLint h) { - GLint maxtexsize = 0; + static GLint maxtexsize = 0; //GL_DBG_Printf("SetModelView(): %dx%d\n", (int)w, (int)h); // The screen textures need to be flushed if the width or height change so that they be remade for the correct size @@ -1193,7 +1158,9 @@ void GL_SetModelView(GLint w, GLint h) screen_texsizeh <<= 1; } - pglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize); // Get the maximum supported texture size + if (!maxtexsize) + pglGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtexsize); // Get the maximum supported texture size + if ((screen_texsizew > maxtexsize || screen_texsizeh > maxtexsize) && maxtexsize > 0) { // The desired screen texture resolution is too big for the player's GPU! @@ -1339,7 +1306,8 @@ void GL_DeleteTexture(GLMipmap_t *pTexInfo) if (!pTexInfo) return; - else if (pTexInfo->downloaded) + + if (pTexInfo->downloaded) pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); while (head) @@ -1393,7 +1361,8 @@ void GL_Flush(void) TexCacheTail = TexCacheHead = NULL; //Hurdler: well, TexCacheHead is already NULL tex_downloaded = 0; - free(textureBuffer); + if (textureBuffer) + free(textureBuffer); textureBuffer = NULL; textureBufferSize = 0; } @@ -1547,6 +1516,7 @@ void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask ClearMask |= GL_COLOR_BUFFER_BIT; } + if (DepthMask) { pglClearDepth(1.0f); //Hurdler: all that are permanen states @@ -1558,7 +1528,7 @@ void GL_ClearBuffer(FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask GL_SetBlend(DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude); if (StencilMask) - ClearMask |= GL_STENCIL_BUFFER_BIT;// looks like sometimes stencil buffer needs clearing? had a problem with random black screens + ClearMask |= GL_STENCIL_BUFFER_BIT; // looks like sometimes stencil buffer needs clearing? had a problem with random black screens pglClear(ClearMask); pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one @@ -1602,18 +1572,21 @@ void GL_Draw2DLine(F2DCoord * v1, F2DCoord * v2, RGBA_t Color) pglEnableClientState(GL_TEXTURE_COORD_ARRAY); pglEnable(GL_TEXTURE_2D); } + +static inline void Clamp2D(GLenum pname) +{ +#ifdef GL_CLAMP_TO_EDGE + pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP_TO_EDGE); +#else + pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP); // fallback clamp +#endif +} + // -----------------+ // SetBlend : Set render mode // -----------------+ // PF_Masked - we could use an ALPHA_TEST of GL_EQUAL, and alpha ref of 0, // is it faster when pixels are discarded ? -static void Clamp2D(GLenum pname) -{ - pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP); // fallback clamp -#ifdef GL_CLAMP_TO_EDGE - pglTexParameteri(GL_TEXTURE_2D, pname, GL_CLAMP_TO_EDGE); -#endif -} static void GL_SetBlendEquation(GLenum mode) { @@ -1762,14 +1735,6 @@ void GL_SetBlend(FBITFIELD PolyFlags) if (Xor & PF_Modulated) { -#if defined (__unix__) || defined (UNIXCOMMON) - if (oglflags & GLF_NOTEXENV) - { - if (!(PolyFlags & PF_Modulated)) - pglColor4ubv(white); - } - else -#endif if (PolyFlags & PF_Modulated) { // mix texture colour with Surface->PolyColor pglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -2143,7 +2108,8 @@ void GL_SetTexture(GLMipmap_t *pTexInfo) GL_SetNoTexture(); return; } - else if (pTexInfo->downloaded) + + if (pTexInfo->downloaded) { if (pTexInfo->downloaded != tex_downloaded) { @@ -2243,16 +2209,10 @@ static void GL_Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRG UNIFORM_1(shader->uniforms[gluniform_light_contrast], shader_light_contrast, pglUniform1f); UNIFORM_1(shader->uniforms[gluniform_light_backlight], shader_light_backlight, pglUniform1f); } - else - { - UNIFORM_3(shader->uniforms[gluniform_light_dir], 0, 0, 0, pglUniform3f); - UNIFORM_1(shader->uniforms[gluniform_light_contrast], 0, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_light_backlight], 0, pglUniform1f); - } UNIFORM_1(shader->uniforms[gluniform_leveltime], shader_leveltime, pglUniform1f); - UNIFORM_2(shader->uniforms[gluniform_scr_resolution], vid.width, vid.height, pglUniform2f); + UNIFORM_2(shader->uniforms[gluniform_scr_resolution], (GLfloat)vid.width, (GLfloat)vid.height, pglUniform2f); #undef UNIFORM_1 #undef UNIFORM_2 @@ -2419,38 +2379,38 @@ static void GL_PreparePolygon(FSurfaceInfo *pSurf, FBITFIELD PolyFlags) if (pSurf) { - // If modulated, mix the surface colour to the texture - if (CurrentPolyFlags & PF_Modulated) - pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); - // If the surface is either modulated or colormapped, or both if (CurrentPolyFlags & (PF_Modulated | PF_ColorMapped)) { - poly.red = byte2float[pSurf->PolyColor.s.red]; - poly.green = byte2float[pSurf->PolyColor.s.green]; - poly.blue = byte2float[pSurf->PolyColor.s.blue]; - poly.alpha = byte2float[pSurf->PolyColor.s.alpha]; - } + // If modulated, mix the surface colour to the texture + if (CurrentPolyFlags & PF_Modulated) + pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); - // Only if the surface is colormapped - if (CurrentPolyFlags & PF_ColorMapped) - { - tint.red = byte2float[pSurf->TintColor.s.red]; - tint.green = byte2float[pSurf->TintColor.s.green]; - tint.blue = byte2float[pSurf->TintColor.s.blue]; - tint.alpha = byte2float[pSurf->TintColor.s.alpha]; + poly.red = byte2float(pSurf->PolyColor.s.red); + poly.green = byte2float(pSurf->PolyColor.s.green); + poly.blue = byte2float(pSurf->PolyColor.s.blue); + poly.alpha = byte2float(pSurf->PolyColor.s.alpha); - fade.red = byte2float[pSurf->FadeColor.s.red]; - fade.green = byte2float[pSurf->FadeColor.s.green]; - fade.blue = byte2float[pSurf->FadeColor.s.blue]; - fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - - if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) + // Only if the surface is colormapped + if (CurrentPolyFlags & PF_ColorMapped) { - pglActiveTexture(GL_TEXTURE2); - pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); - pglActiveTexture(GL_TEXTURE0); - lt_downloaded = pSurf->LightTableId; + tint.red = byte2float(pSurf->TintColor.s.red); + tint.green = byte2float(pSurf->TintColor.s.green); + tint.blue = byte2float(pSurf->TintColor.s.blue); + tint.alpha = byte2float(pSurf->TintColor.s.alpha); + + fade.red = byte2float(pSurf->FadeColor.s.red); + fade.green = byte2float(pSurf->FadeColor.s.green); + fade.blue = byte2float(pSurf->FadeColor.s.blue); + fade.alpha = byte2float(pSurf->FadeColor.s.alpha); + + if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) + { + pglActiveTexture(GL_TEXTURE2); + pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); + pglActiveTexture(GL_TEXTURE0); + lt_downloaded = pSurf->LightTableId; + } } } } @@ -2962,24 +2922,24 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics pol = 0.0f; } - poly.red = byte2float[Surface->PolyColor.s.red]; - poly.green = byte2float[Surface->PolyColor.s.green]; - poly.blue = byte2float[Surface->PolyColor.s.blue]; - poly.alpha = byte2float[Surface->PolyColor.s.alpha]; + poly.red = byte2float(Surface->PolyColor.s.red); + poly.green = byte2float(Surface->PolyColor.s.green); + poly.blue = byte2float(Surface->PolyColor.s.blue); + poly.alpha = byte2float(Surface->PolyColor.s.alpha); pglColor4ubv((GLubyte*)&Surface->PolyColor.s); GL_SetBlend(((poly.alpha < 1) ? Surface->PolyFlags : (PF_Masked|PF_Occlude))|PF_Modulated); - tint.red = byte2float[Surface->TintColor.s.red]; - tint.green = byte2float[Surface->TintColor.s.green]; - tint.blue = byte2float[Surface->TintColor.s.blue]; - tint.alpha = byte2float[Surface->TintColor.s.alpha]; + tint.red = byte2float(Surface->TintColor.s.red); + tint.green = byte2float(Surface->TintColor.s.green); + tint.blue = byte2float(Surface->TintColor.s.blue); + tint.alpha = byte2float(Surface->TintColor.s.alpha); - fade.red = byte2float[Surface->FadeColor.s.red]; - fade.green = byte2float[Surface->FadeColor.s.green]; - fade.blue = byte2float[Surface->FadeColor.s.blue]; - fade.alpha = byte2float[Surface->FadeColor.s.alpha]; + fade.red = byte2float(Surface->FadeColor.s.red); + fade.green = byte2float(Surface->FadeColor.s.green); + fade.blue = byte2float(Surface->FadeColor.s.blue); + fade.alpha = byte2float(Surface->FadeColor.s.alpha); if (Surface->LightTableId && Surface->LightTableId != lt_downloaded) { @@ -3196,11 +3156,13 @@ void GL_SetTransform(FTransform *stransform) if (special_splitscreen) { - used_fov = (atanf(tanf(used_fov * (float)M_PI / 360.0f) * 0.8f) * 360.0f / (float)M_PI); + used_fov = (atanf(tanf(used_fov * M_PIf / 360.0f) * 0.8f) * 360.0f / M_PIf); GL_Perspective(used_fov, 2*ASPECT_RATIO); } else + { GL_Perspective(used_fov, ASPECT_RATIO); + } pglGetFloatv(GL_PROJECTION_MATRIX, projMatrix); // added for new coronas' code (without depth buffer) pglMatrixMode(GL_MODELVIEW); @@ -3334,8 +3296,8 @@ void GL_Framebuffer_Disable(void) // delet our fbo if (framebufferobject.fboobj) pglDeleteFramebuffers(1, &framebufferobject.fboobj); - framebufferobject.fboobj = 0; + GL_Framebuffer_DeleteAttachments(); } #endif @@ -3465,7 +3427,7 @@ void GL_FlushScreenTextures(void) void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) { - float fix[8]; + static float fix[8]; float xfix, yfix; if (gl_enable_screen_textures != 2) @@ -3474,14 +3436,8 @@ void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) xfix = 1/((float)screen_texsizew/(float)screen_width); yfix = 1/((float)screen_texsizeh/(float)screen_height); - fix[0] = 0.0f; - fix[1] = 0.0f; - fix[2] = 0.0f; - fix[3] = yfix; - fix[4] = xfix; - fix[5] = yfix; - fix[6] = xfix; - fix[7] = 0.0f; + fix[3] = fix[5] = yfix; + fix[4] = fix[6] = xfix; pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); @@ -3715,7 +3671,13 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh float origaspect, newaspect; float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen - static float off[12]; + static float off[12] = + { + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f + }; + static float fix[8]; if (gl_enable_screen_textures != 2) @@ -3739,28 +3701,14 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh } // float off[12]; - off[0] = -xoff; - off[1] = -yoff; - off[2] = 1.0f; - off[3] = -xoff; - off[4] = yoff; - off[5] = 1.0f; - off[6] = xoff; - off[7] = yoff; - off[8] = 1.0f; - off[9] = xoff; - off[10] = -yoff; - off[11] = 1.0f; + off[0] = off[3] = -xoff; + off[1] = off[10] = -yoff; + off[4] = off[7] = yoff; + off[6] = off[9] = xoff; // float fix[8]; - fix[0] = 0.0f; - fix[1] = 0.0f; - fix[2] = 0.0f; - fix[3] = yfix; - fix[4] = xfix; - fix[5] = yfix; - fix[6] = xfix; - fix[7] = 0.0f; + fix[3] = fix[5] = yfix; + fix[4] = fix[6] = xfix; pglViewport(0, 0, width, height); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 34d4b9da3..13ba9f6f5 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -38,8 +38,6 @@ extern "C" { #endif #endif -#define _CREATE_DLL_ // necessary for Unix AND Windows - #include "../../doomdef.h" #include "../hw_gl.h" #include "../../z_zone.h" @@ -69,7 +67,6 @@ extern boolean supportstencil; void *GetGLFunc(const char *proc); boolean SetupGLfunc(void); void SetupGLFunc4(void); -void GL_Flush(void); INT32 GL_isExtAvailable(const char *extension, const GLubyte *start); void GL_SetModelView(GLint w, GLint h); void GL_SetStates(void); @@ -127,18 +124,9 @@ extern GLint maximumAnisotropy; extern boolean supportNPO2tex; extern boolean supportMipMap; -/** \brief OpenGL flags for video driver -*/ -extern INT32 oglflags; - +extern GLfloat modelMatrix[16]; extern GLfloat projMatrix[16]; -typedef enum -{ - GLF_NOZBUFREAD = 0x01, - GLF_NOTEXENV = 0x02, -} oglflags_t; - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 8819d63b4..6cca391e9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -88,6 +88,8 @@ patch_t *ranknum[10] = {}; // rank numbers patch_t *framecounter = NULL; patch_t *frameslash = NULL; // framerate stuff. Used in screen.c +patch_t *srb2back = NULL; + static player_t *plr = NULL; boolean chat_on = false; // entering a chat message? static char w_chat_buf[HU_MAXMSGLEN + 1]; @@ -96,10 +98,9 @@ static boolean headsupactive = false; boolean hu_showscores = false; // draw rankings static char hu_tick; static tic_t hu_emoteanim = 0; -#define MAXEMOTESUGGESTIONS 8 -static emote_t *emote_suggestions[MAXEMOTESUGGESTIONS] = {0}; +emote_autocomplete_t emote_autocomplete = {0}; -static huddrawlist_h luahuddrawlist_scores; +static huddrawlist_h luahuddrawlist_scores = NULL; patch_t *rflagico = NULL; patch_t *bflagico = NULL; @@ -291,6 +292,7 @@ void HU_LoadGraphics(void) return; j = HU_FONTSTART; + for (i = 0; i < HU_FONTSIZE; i++, j++) { // cache the heads-up font for entire game execution @@ -361,21 +363,21 @@ void HU_LoadGraphics(void) cred_font[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - //cache numbers too! + // cache numbers too! for (i = 0; i < 10; i++) { sprintf(buffer, "STTNUM%d", i); tallnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); sprintf(buffer, "PINGN%d", i); - pingnum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + pingnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); sprintf(buffer, "OPPRNK0%d", i); - ranknum[i] = (patch_t *) W_CachePatchName(buffer, PU_HUDGFX); + ranknum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } // minus for negative tallnums tallminus = (patch_t *)W_CachePatchName("STTMINUS", PU_HUDGFX); - songcreditbg = W_CachePatchName("K_SONGCR", PU_HUDGFX); + songcreditbg = (patch_t *)W_CachePatchName("K_SONGCR", PU_HUDGFX); // cache ping gfx: for (i = 0; i < 5; i++) @@ -384,12 +386,15 @@ void HU_LoadGraphics(void) pinggfx[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX); } - pingmeasure[0] = W_CachePatchName("PINGD", PU_HUDGFX); - pingmeasure[1] = W_CachePatchName("PINGMS", PU_HUDGFX); + pingmeasure[0] = (patch_t *)W_CachePatchName("PINGD", PU_HUDGFX); + pingmeasure[1] = (patch_t *)W_CachePatchName("PINGMS", PU_HUDGFX); // fps stuff - framecounter = W_CachePatchName("FRAMER", PU_HUDGFX); - frameslash = W_CachePatchName("FRAMESL", PU_HUDGFX);; + framecounter = (patch_t *)W_CachePatchName("FRAMER", PU_HUDGFX); + frameslash = (patch_t *)W_CachePatchName("FRAMESL", PU_HUDGFX); + + // idk where else to put this lul + srb2back = (patch_t *)W_CachePatchName("SRB2BACK", PU_HUDGFX); } // Initialise Heads up @@ -406,8 +411,10 @@ void HU_Init(void) // set shift translation table shiftxform = english_shiftxform; - luahuddrawlist_scores = LUA_HUD_CreateDrawList(); + if (dedicated || rendermode == render_none) + return; + luahuddrawlist_scores = LUA_HUD_CreateDrawList(); HU_LoadGraphics(); } @@ -589,12 +596,12 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) } // Only servers/admins can CSAY. - if(!server && !(IsPlayerAdmin(consoleplayer))) + if (!server && !(IsPlayerAdmin(consoleplayer))) flags &= ~HU_CSAY; // We handle HU_SERVER_SAY, not the caller. flags &= ~HU_SERVER_SAY; - if(dedicated && !(flags & HU_CSAY)) + if (dedicated && !(flags & HU_CSAY)) flags |= HU_SERVER_SAY; buf[0] = target; @@ -608,17 +615,20 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) strlcat(msg, COM_Argv(ix + usedargs), msgspace); } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + const size_t msglength = strlen(msg); + + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: const char *newmsg; INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); + CLEANUP(pfree) char *nodenum = (char*) malloc(3); memcpy(nodenum, msg+3, 2); nodenum[2] = '\0'; + // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) + if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { // check if nodenum[1] is a space if (nodenum[1] == ' ') @@ -627,23 +637,21 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } + // I'm very bad at C, I swear I am, additional checks eww! if (spc != 0) { if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -654,12 +662,13 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same return; } + buf[0] = target; newmsg = msg+5+spc; strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); + SendNetXCmd(XD_SAY, buf, msglength + 1 + msg-buf); } /** Send a message to everyone. @@ -910,10 +919,12 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) return; } + const size_t msglength = strlen(msg); + //check for invalid characters (0x80 or above) { size_t i; - const size_t j = strlen(msg); + const size_t j = msglength; for (i = 0; i < j; i++) { if (msg[i] & 0x80) @@ -960,7 +971,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) } // Handle "/me" actions, but only in messages to everyone. - if (target == 0 && strlen(msg) > 4 && strnicmp(msg, "/me ", 4) == 0) + if (target == 0 && msglength > 4 && strnicmp(msg, "/me ", 4) == 0) { msg += 4; action = true; @@ -1142,10 +1153,12 @@ static boolean HU_clearChatSpaces(void) size_t i = 0; // Used to just check our message char c; // current character we're iterating. boolean nothingbutspaces = true; + const size_t chatlength = strlen(w_chat_buf); - for (; i < strlen(w_chat_buf); i++) // iterate through message and eradicate all spaces that don't belong. + for (; i < chatlength; i++) // iterate through message and eradicate all spaces that don't belong. { c = w_chat_buf[i]; + if (!c) break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. @@ -1154,6 +1167,7 @@ static boolean HU_clearChatSpaces(void) nothingbutspaces = false; } } + return nothingbutspaces; } @@ -1200,11 +1214,11 @@ static void HU_SendChatMessage(void) return; } - size_t len = strlen(msg); + const size_t msglength = strlen(msg); - if (len >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute + if (msglength >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute { - if (len > 6) + if (msglength > 6) DoMute(msg+6); else HU_AddChatText("\x82NOTICE: \x80Usage: /mute ", false); @@ -1212,7 +1226,7 @@ static void HU_SendChatMessage(void) return; } - if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. const char *newmsg; @@ -1334,6 +1348,7 @@ boolean HU_Responder(event_t *ev) chat_on = true; w_chat_buf[0] = 0; M_TextInputInit(&w_chat, w_chat_buf, sizeof w_chat_buf); + memset(&emote_autocomplete, 0, sizeof(emote_autocomplete)); teamtalk = false; chat_scrollmedown = true; typelines = 1; @@ -1346,6 +1361,7 @@ boolean HU_Responder(event_t *ev) chat_on = true; w_chat_buf[0] = 0; M_TextInputInit(&w_chat, w_chat_buf, sizeof w_chat_buf); + memset(&emote_autocomplete, 0, sizeof(emote_autocomplete)); teamtalk = G_GametypeHasTeams(); // Don't teamtalk if we don't have teams. chat_scrollmedown = true; typelines = 1; @@ -1371,9 +1387,9 @@ boolean HU_Responder(event_t *ev) && ev->data1 != gamecontrol[0][gc_talkkey][1])) return false; - M_TextInputHandleEmotes(&w_chat, c, emote_suggestions, MAXEMOTESUGGESTIONS); - - if (c == KEY_ENTER) + if (M_TextInputHandleEmotes(&w_chat, c, &emote_autocomplete)) + ; // Do nothing + else if (c == KEY_ENTER) { chat_on = false; chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) @@ -1410,8 +1426,6 @@ boolean HU_Responder(event_t *ev) // HEADS UP DRAWING //====================================================================== -#define HU_DrawEmote(x, y, emote, flags) M_DrawEmote((x), (y), (emote), hu_emoteanim, (flags)) - // Precompile a wordwrapped string to any given width. // This is a muuuch better method than V_WORDWRAP. // again stolen and modified a bit from video.c, don't mind me, will need to rearrange this one day. @@ -1614,7 +1628,7 @@ static void HU_drawMiniChat(void) if (cv_chatbacktint.value) // on request of wolfy V_DrawFillConsoleMap(x + dx + 2, y+dy, EMOTEWIDTH, charheight, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); - HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag); + M_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|transflag); dx += EMOTEWIDTH - charwidth; j += emotelen; @@ -1724,7 +1738,7 @@ static void HU_drawChatLog(INT32 offset) { if ((y+dy+2 >= chat_topy) && (y+dy < (chat_bottomy))) { - HU_DrawEmote(x+dx+2, y+dy, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT); + M_DrawEmote(x+dx+2, y+dy+1, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT); dx += EMOTEWIDTH - charwidth; } j += emotelen; @@ -1864,7 +1878,7 @@ static void HU_DrawChat(void) if ((emote = M_VerifyEmote(w_chat_buf+i, &emotelen))) { - HU_DrawEmote(chatx + c + 2, y-1, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|t); + M_DrawEmote(chatx + c + 2, y-1, emote, V_SNAPTOBOTTOM|V_SNAPTOLEFT|t); c += EMOTEWIDTH - charwidth; i += emotelen-1; drawwidth = EMOTEWIDTH; @@ -1901,17 +1915,37 @@ static void HU_DrawChat(void) } } - if (emote_suggestions[0]) + if (emote_autocomplete.emotestart != -1 && (emote_autocomplete.complete[0] || (w_chat.cursor - emote_autocomplete.emotestart) > 1)) { + emote_t *suggest; + int skip = 0; + + const char *complete; + int complete_len; + + if (emote_autocomplete.complete[0]) + { + complete = emote_autocomplete.complete; + complete_len = strlen(complete); + } + else + { + complete = &w_chat_buf[emote_autocomplete.emotestart]; + complete_len = w_chat.cursor - emote_autocomplete.emotestart; + } + // A bit of copy-paste from /pm code :p INT32 suggesty = chaty - charheight - 1; size_t longest_suggestion_length = 0; - for (i = 0; i < MAXEMOTESUGGESTIONS && emote_suggestions[i]; ++i) + while ((suggest = M_FindEmote(complete, complete_len, skip)) != NULL) { - longest_suggestion_length = max(longest_suggestion_length, strlen(emote_suggestions[i]->name)); + longest_suggestion_length = max(longest_suggestion_length, strlen(suggest->name)); + ++skip; } + skip = 0; + #ifdef NETSPLITSCREEN if (splitscreen) { @@ -1923,11 +1957,19 @@ static void HU_DrawChat(void) #endif suggesty -= (cv_kartspeedometer.value ? 16 : 0); - for (i = 0; i < MAXEMOTESUGGESTIONS && emote_suggestions[i]; ++i) + while ((suggest = M_FindEmote(complete, complete_len, skip)) != NULL) { - V_DrawFillConsoleMap(chatx + boxw + 2, suggesty - (7*i), (longest_suggestion_length+2)*4 + EMOTEWIDTH, 6, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); - V_DrawSmallString(chatx + boxw + 4 + EMOTEWIDTH, suggesty - (7*i), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, va(":%s:", emote_suggestions[i]->name)); - HU_DrawEmote(chatx + boxw + 2, suggesty - i*7, emote_suggestions[i], V_SNAPTOBOTTOM|V_SNAPTOLEFT); + V_DrawFillConsoleMap(chatx + boxw + 2, suggesty - (7*skip), (longest_suggestion_length+2)*4 + EMOTEWIDTH, 6, V_SNAPTOBOTTOM|V_SNAPTOLEFT); + + // Highlight currently suggested emote + int hlflag = 0; + if (skip == emote_autocomplete.skip && emote_autocomplete.complete[0]) + hlflag = V_YELLOWMAP; + + V_DrawSmallString(chatx + boxw + 4 + EMOTEWIDTH, suggesty - (7*skip), hlflag|V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, va(":%s:", suggest->name)); + M_DrawEmote(chatx + boxw + 2, suggesty - skip*7, suggest, V_SNAPTOBOTTOM|V_SNAPTOLEFT); + + ++skip; } } @@ -1956,7 +1998,7 @@ static void HU_DrawChat(void) longest_name_length = max(longest_name_length, strlen(player_names[i])); } - for(i = 0; i < MAXPLAYERS; i++) + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i]) continue; @@ -2062,15 +2104,15 @@ static void HU_DrawChat_Old(void) i = 0; while (w_chat_buf[i]) { - if (w_chat.cursor == (i+1) && hu_tick < 4) - { - INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. - INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); - V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); - } + int emotelen; + emote_t *emote; - //Hurdler: isn't it better like that? - if (w_chat_buf[i] >= HU_FONTSTART) + if ((emote = M_VerifyEmote(w_chat_buf+i, &emotelen))) + { + M_DrawScaledEmote((HU_INPUTX + c)<= HU_FONTSTART) //Hurdler: isn't it better like that? { //charwidth = hu_font[w_chat[i]-HU_FONTSTART]->width * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, w_chat_buf[i] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); @@ -2082,6 +2124,13 @@ static void HU_DrawChat_Old(void) ++i; + if (w_chat.cursor == i && hu_tick < 4) + { + INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. + INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); + V_DrawCharacter(cursorx, cursory+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); + } + c += charwidth; if (c >= vid.width) { diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 64d369a33..85ff630f5 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -90,6 +90,7 @@ extern patch_t *pinggfx[5]; extern patch_t *ranknum[10]; extern patch_t *framecounter; extern patch_t *frameslash; +extern patch_t *srb2back; extern patch_t *lt_font[LT_FONTSIZE]; extern patch_t *cred_font[CRED_FONTSIZE]; extern patch_t *rflagico; diff --git a/src/i_net.h b/src/i_net.h index e811908f2..112fd706e 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -80,6 +80,8 @@ typedef struct #define DOOMCOM_DATA(d) (doomdata_t *)&(d)->data +extern doomcom_t *doomcom; + #ifdef HOLEPUNCH typedef struct { @@ -91,8 +93,6 @@ typedef struct #define HOLEPUNCH_DATA(d) (holepunch_t *)&(d)->data #endif -extern doomcom_t *doomcom; - /** \brief return packet in doomcom struct */ extern boolean (*I_NetGet)(void); diff --git a/src/i_system.h b/src/i_system.h index 7084c655f..97dfae9a1 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,6 +29,10 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 +void I_GetConsoleEvents(void); + +extern boolean consolevent; +extern boolean framebuffer; /** \brief Graphic system had started up */ diff --git a/src/i_tcp.c b/src/i_tcp.c index 98a03f841..982b327d0 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -568,13 +568,12 @@ void Command_Numnodes(void) #ifdef HOLEPUNCH /* not one of the reserved "local" addresses */ -static boolean -is_external_address (UINT32 p) +static boolean is_external_address(UINT32 p) { UINT8 a = (p & 255); UINT8 b = ((p >> 8) & 255); - if (p == (UINT32)~0)/* 255.255.255.255 */ + if (p == (UINT32)~0) /* 255.255.255.255 */ return 0; switch (a) @@ -584,7 +583,7 @@ is_external_address (UINT32 p) case 127: return false; case 172: - return (b & ~15) != 16;/* 16 - 31 */ + return (b & ~15) != 16; /* 16 - 31 */ case 192: return b != 168; default: @@ -763,6 +762,7 @@ static void SOCK_Send(void) if (myfamily[i] == broadcastaddress[j].any.sa_family) { c = SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]); + if (c == ERRSOCKET) { e = errno; @@ -780,6 +780,7 @@ static void SOCK_Send(void) if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family) { c = SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]); + if (c == ERRSOCKET) { e = errno; @@ -792,6 +793,7 @@ static void SOCK_Send(void) else { c = SOCK_SendToAddr(nodesocket[doomcom->remotenode], &clientaddress[doomcom->remotenode]); + if (c == ERRSOCKET) { e = errno; @@ -1060,7 +1062,6 @@ static boolean UDP_Socket(void) #endif const char *serv; - for (s = 0; s < mysocketses; s++) mysockets[s] = ERRSOCKET; for (s = 0; s < MAXNETNODES+1; s++) diff --git a/src/i_video.h b/src/i_video.h index f8c3a5c97..d4bb659ee 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -102,10 +102,6 @@ void VID_PrepareModeList(void); */ extern boolean allow_fullscreen; -/** \brief Update video system without updating frame -*/ -void I_UpdateNoBlit(void); - /** \brief Update video system with updating frame */ void I_FinishUpdate(void); @@ -114,13 +110,6 @@ void I_FinishUpdate(void); */ void I_UpdateNoVsync(void); -/** \brief Wait for vertical retrace or pause a bit. - - \param count max wait - - \return void -*/ -void I_WaitVBL(INT32 count); /** \brief The I_ReadScreen function @@ -130,13 +119,6 @@ void I_WaitVBL(INT32 count); */ void I_ReadScreen(UINT8 * restrict scr, INT32 scale); -/** \brief Start disk icon -*/ -void I_BeginRead(void); - -/** \brief Stop disk icon -*/ -void I_EndRead(void); UINT32 I_GetRefreshRate(void); @@ -145,8 +127,6 @@ boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); -void I_HandleControllerHatRepeat(void); - #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); @@ -155,6 +135,15 @@ boolean UseScreenFBO(void); extern boolean downsample; #endif +// So we can call this from i_video event loop +void I_ShutdownJoystick(UINT8 index); + +// Quick thing to make SDL_JOYDEVICEADDED events less of an abomination +void I_UpdateJoystickDeviceIndex(UINT8 player); +void I_UpdateJoystickDeviceIndices(UINT8 excludePlayer); + +void I_HandleControllerHatRepeat(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/info.h b/src/info.h index 4ee851cee..c84d63214 100644 --- a/src/info.h +++ b/src/info.h @@ -19,6 +19,8 @@ #include "sounds.h" #include "m_fixed.h" +#define MAXDOOMEDNUM 4095 + // dehacked.c now has lists for the more named enums! PLEASE keep them up to date! // For great modding!! diff --git a/src/k_hud.c b/src/k_hud.c index 54b81a0f4..1d9b7fe5b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -568,7 +568,7 @@ static patch_t *kp_racefinish[6]; static patch_t *kp_positionnum[NUMPOSNUMS][NUMPOSFRAMES]; static patch_t *kp_winnernum[NUMPOSFRAMES]; -static patch_t *kp_facenum[MAXPLAYERS+1]; +patch_t *kp_facenum[MAXPLAYERS+1]; static patch_t *kp_facehighlight[8]; static patch_t *kp_rankbumper; @@ -1076,6 +1076,49 @@ static void K_initKartHUD(void) R_InterpolateView(R_GetTimeFrac(RTF_CAMERA), !cv_uncappedhud.value); } +void K_KartPlayerHUDUpdate(player_t *player) +{ + if (player->kartstuff[k_lapanimation]) + player->kartstuff[k_lapanimation]--; + + if (player->kartstuff[k_yougotem]) + player->kartstuff[k_yougotem]--; + + if (G_BattleGametype() && (player->exiting || player->kartstuff[k_comebacktimer])) + { + if (player->exiting) + { + if (player->exiting < 6*TICRATE) + player->kartstuff[k_cardanimation] += ((164-player->kartstuff[k_cardanimation])/8)+1; + else if (player->exiting == 6*TICRATE) + player->kartstuff[k_cardanimation] = 0; + else if (player->kartstuff[k_cardanimation] < 2*TICRATE) + player->kartstuff[k_cardanimation]++; + } + else + { + if (player->kartstuff[k_comebacktimer] < 6*TICRATE) + player->kartstuff[k_cardanimation] -= ((164-player->kartstuff[k_cardanimation])/8)+1; + else if (player->kartstuff[k_comebacktimer] < 9*TICRATE) + player->kartstuff[k_cardanimation] += ((164-player->kartstuff[k_cardanimation])/8)+1; + } + + if (player->kartstuff[k_cardanimation] > 164) + player->kartstuff[k_cardanimation] = 164; + if (player->kartstuff[k_cardanimation] < 0) + player->kartstuff[k_cardanimation] = 0; + } + else if (G_RaceGametype() && player->exiting) + { + if (player->kartstuff[k_cardanimation] < 2*TICRATE) + player->kartstuff[k_cardanimation]++; + } + else + { + player->kartstuff[k_cardanimation] = 0; + } +} + UINT8 K_GetHudColor(void) { if (cv_colorizedhud.value && cv_colorizedhudcolor.value) @@ -2860,7 +2903,7 @@ static boolean K_GetScreenCoords(vector2_t *vec, player_t *player, mobj_t *targe // X coordinate // get difference between camangle and angle towards target - x = (INT32)viewangle - (INT32)R_PointToAngle(targx, targy); + x = (fixed_t)(viewangle - R_PointToAngle(targx, targy)); distfact = FINECOSINE((x>>ANGLETOFINESHIFT) & FINEMASK); if (!distfact) distfact = 1; @@ -4387,8 +4430,10 @@ static void K_drawLapStartAnim(void) UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); INT32 vflags = V_SNAPTOTOP|V_HUDTRANS; - fixed_t slideout = max(0, 32*(((progress - 76)*FRACUNIT) + R_GetTimeFrac(RTF_LEVEL))); - fixed_t slidein = max(0, 32*(((stplyr->kartstuff[k_lapanimation] - 76)*FRACUNIT) - R_GetTimeFrac(RTF_LEVEL))); + fixed_t slideout = 32*(((progress - 76)*FRACUNIT) + R_GetTimeFrac(RTF_LEVEL)); + slideout = max(0, slideout); + fixed_t slidein = 32*(((stplyr->kartstuff[k_lapanimation] - 76)*FRACUNIT) - R_GetTimeFrac(RTF_LEVEL)); + slidein = max(0, slidein); // First, draw the emblem and hand INT32 emblemx = (BASEVIDWIDTH << (FRACBITS - 1)) + slidein; @@ -4423,7 +4468,9 @@ static void K_drawLapStartAnim(void) V_DrawFixedPatch(leftx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2, 6)], NULL); char *lapnum = va("%02d", stplyr->laps + 1); - for (int i = 0; i < (int)strlen(lapnum); i++) + const size_t laplength = strlen(lapnum); + + for (int i = 0; i < (int)laplength; i++) { int digit = lapnum[i] - '0'; int frame = min(2, progress/2 - 8 - (i*2)); diff --git a/src/k_hud.h b/src/k_hud.h index 3d2e478a7..c42996a4e 100644 --- a/src/k_hud.h +++ b/src/k_hud.h @@ -24,7 +24,6 @@ extern "C" { UINT8 K_GetHudColor(void); boolean K_UseColorHud(void); boolean K_UseHighResPortraits(void); -patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); void K_RegisterKartHudStuff(void); @@ -35,7 +34,6 @@ extern consvar_t cv_colorizedhud, extern consvar_t cv_darkitembox; extern consvar_t cv_biglaps; extern consvar_t cv_highresportrait; -extern consvar_t cv_stat_xoffset, cv_stat_yoffset; extern consvar_t cv_showstats; extern consvar_t cv_fancyroulette; extern consvar_t cv_showlaptimes; @@ -43,6 +41,9 @@ extern consvar_t cv_battlespeedo; extern consvar_t cv_multiitemicon; extern consvar_t cv_huditemamount; +// for use in timeattack menu +extern patch_t *kp_facenum[MAXPLAYERS+1]; + #define NUMSPEEDOSTUFF 8 extern CV_PossibleValue_t speedo_cons_t[NUMSPEEDOSTUFF]; #define NUMDGAUGESTUFF 6 @@ -52,6 +53,8 @@ extern CV_PossibleValue_t inputdisplay_cons_t[NUMINPUTDISPLAYSTUFF]; #define NUMMINIMAPDOTSTUFF 5 extern CV_PossibleValue_t minimapdot_cons_t[NUMMINIMAPDOTSTUFF]; +void K_KartPlayerHUDUpdate(player_t *player); + const char *K_GetItemPatch(UINT8 item, boolean tiny); INT32 K_calcSplitFlags(INT32 snapflags); void K_LoadKartHUDGraphics(void); diff --git a/src/k_kart.c b/src/k_kart.c index c40529b5e..767e041a1 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -98,8 +98,6 @@ static void saltyhop_onchange(void) } } -static boolean K_SpeedLinesShouldBlend(player_t *player); - // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) // franticitems is Frantic Mode items, bool @@ -811,8 +809,10 @@ boolean K_IsPlayerLosing(player_t *player) boolean K_IsPlayerWanted(player_t *player) { UINT8 i; - if (!(G_BattleGametype())) + + if (!G_BattleGametype()) return false; + for (i = 0; i < 4; i++) { if (battlewanted[i] == -1) @@ -820,6 +820,7 @@ boolean K_IsPlayerWanted(player_t *player) if (player == &players[battlewanted[i]]) return true; } + return false; } @@ -1244,7 +1245,9 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) { if (!playeringame[i] || players[i].spectator) continue; + pingame++; + if (players[i].exiting) dontforcespb = true; if (players[i].kartstuff[k_bumper] > bestbumper) @@ -1258,13 +1261,11 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) // This makes the roulette produce the random noises. if ((player->kartstuff[k_itemroulette] % 3) == 1 && P_IsDisplayPlayer(player)) { -#define PLAYROULETTESND S_StartSound(NULL, sfx_itrol1 + ((player->kartstuff[k_itemroulette] / 3) % 8)) for (i = 0; i <= splitscreen; i++) { if (player == &players[displayplayers[i]] && players[displayplayers[i]].kartstuff[k_itemroulette]) - PLAYROULETTESND; + S_StartSound(NULL, sfx_itrol1 + ((player->kartstuff[k_itemroulette] / 3) % 8)); } -#undef PLAYROULETTESND } roulettestop = TICRATE + (3*(pingame - player->kartstuff[k_position])); @@ -1363,8 +1364,9 @@ static fixed_t K_GetMobjWeight(mobj_t *mobj, mobj_t *against) else { weight = (mobj->player->kartweight)<player->speed > K_GetKartSpeed(mobj->player, false)) - weight += (mobj->player->speed - K_GetKartSpeed(mobj->player, false))/8; + const fixed_t kartspeed = K_GetKartSpeed(mobj->player, false); + if (mobj->player->speed > kartspeed) + weight += (mobj->player->speed - kartspeed)/8; } break; case MT_FALLINGROCK: @@ -1486,9 +1488,9 @@ void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce, boolean solid) } // if the speed difference is less than this let's assume they're going proportionately faster from each other - if (P_AproxDistance(momdifx, momdify) < (25*mapobjectscale)) + const fixed_t momdiflength = P_AproxDistance(momdifx, momdify); + if (momdiflength < (25*mapobjectscale)) { - fixed_t momdiflength = P_AproxDistance(momdifx, momdify); fixed_t normalisedx = FixedDiv(momdifx, momdiflength); fixed_t normalisedy = FixedDiv(momdify, momdiflength); momdifx = FixedMul((25*mapobjectscale), normalisedx); @@ -1652,7 +1654,7 @@ static void K_UpdateOffroad(player_t *player) // If you are in offroad, a timer starts. if (offroadstrength) { - if (/*K_CheckOffroadCollide(player->mo) &&*/ player->kartstuff[k_offroad] == 0) // With the way offroad is detected now that first check is no longer necessary. -Lat' + if (/*K_CheckOffroadCollide(player->mo) &&*/ player->kartstuff[k_offroad] == 0) // With the way offroad is detected now that first check is no longer necessary. -Lat' player->kartstuff[k_offroad] = (TICRATE/2); if (player->kartstuff[k_offroad] > 0) @@ -2396,7 +2398,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto || player->kartstuff[k_invincibilitytimer] > 0 || player->kartstuff[k_growshrinktimer] > 0 || player->kartstuff[k_hyudorotimer] > 0 || (G_BattleGametype() && ((player->kartstuff[k_bumper] <= 0 && player->kartstuff[k_comebacktimer]) || player->kartstuff[k_comebackmode] == 1))) { - if (!force) // if shoulddamage force, we go THROUGH that. + if (!force) // if shoulddamage force, we go THROUGH that. { K_DoInstashield(player); return; @@ -2441,6 +2443,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto P_SetScale(karmahitbox, player->mo->scale); CONS_Printf(M_GetText("%s lost all of their bumpers!\n"), player_names[player-players]); } + player->kartstuff[k_bumper]--; if (K_IsPlayerWanted(player)) K_CalculateBattleWanted(); @@ -2575,6 +2578,7 @@ void K_SquishPlayer(player_t *player, mobj_t *source, mobj_t *inflictor) P_SetScale(karmahitbox, player->mo->scale); CONS_Printf(M_GetText("%s lost all of their bumpers!\n"), player_names[player-players]); } + player->kartstuff[k_bumper]--; if (K_IsPlayerWanted(player)) K_CalculateBattleWanted(); @@ -2694,6 +2698,7 @@ void K_ExplodePlayer(player_t *player, mobj_t *source, mobj_t *inflictor) // A b P_SetScale(karmahitbox, player->mo->scale); CONS_Printf(M_GetText("%s lost all of their bumpers!\n"), player_names[player-players]); } + player->kartstuff[k_bumper]--; if (K_IsPlayerWanted(player)) K_CalculateBattleWanted(); @@ -2854,9 +2859,9 @@ void K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 for (i = 0; i < number; i++) { fa = (i*degrees); - v[0] = FixedMul(FINECOSINE(fa),radius); + v[0] = FixedMul(FINECOSINE(fa), radius); v[1] = 0; - v[2] = FixedMul(FINESINE(fa),radius); + v[2] = FixedMul(FINESINE(fa), radius); v[3] = FRACUNIT; res = VectorMatrixMultiply(v, *RotateXMatrix(rotangle)); @@ -3425,7 +3430,7 @@ boolean K_CheckSlopeRollDist(mobj_t *mobj) return true; const fixed_t rolldist = (cv_sloperolldist.value * mapobjectscale); - const fixed_t m_dist = (R_QuickCamDist(mobj->x, mobj->y) << FRACBITS); + const fixed_t m_dist = R_QuickCamDist(mobj->x, mobj->y); return (m_dist <= rolldist); } @@ -3606,7 +3611,7 @@ void K_SpawnSparkleTrail(mobj_t *mo) sparkle->color = mo->color; - if (cv_playerblendeffects.value && mo->player && K_SpeedLinesShouldBlend(mo->player)) + if (mo->player && K_PlayerEffectsShouldBlend(mo->player)) sparkle->blendmode = AST_ADD; } @@ -3980,15 +3985,19 @@ void K_PuntMine(mobj_t *thismine, mobj_t *punter) mine->floorz = thismine->floorz; mine->ceilingz = thismine->ceilingz; - //Since we aren't using P_KillMobj, we need to clean up the hnext reference - { - P_SetTarget(&thismine->target->hnext, NULL); //target is the player who owns the mine - thismine->target->player->kartstuff[k_bananadrag] = 0; - thismine->target->player->kartstuff[k_itemheld] = 0; + // Copy interp data + mine->old_angle = thismine->old_angle; + mine->old_x = thismine->old_x; + mine->old_y = thismine->old_y; + mine->old_z = thismine->old_z; - if (--thismine->target->player->kartstuff[k_itemamount] <= 0) - thismine->target->player->kartstuff[k_itemtype] = KITEM_NONE; - } + // Since we aren't using P_KillMobj, we need to clean up the hnext reference + P_SetTarget(&thismine->target->hnext, NULL); // target is the player who owns the mine + thismine->target->player->kartstuff[k_bananadrag] = 0; + thismine->target->player->kartstuff[k_itemheld] = 0; + + if (--thismine->target->player->kartstuff[k_itemamount] <= 0) + thismine->target->player->kartstuff[k_itemtype] = KITEM_NONE; P_RemoveMobj(thismine); @@ -4424,6 +4433,12 @@ void K_DropHnextList(player_t *player) dropwork->floorz = work->floorz; dropwork->ceilingz = work->ceilingz; + // Copy interp data + dropwork->old_angle = work->old_angle; + dropwork->old_x = work->old_x; + dropwork->old_y = work->old_y; + dropwork->old_z = work->old_z; + if (ponground) { // floorz and ceilingz aren't properly set to account for FOFs and Polyobjects on spawn @@ -4506,7 +4521,7 @@ void K_DropItems(player_t *player) { mobj_t *drop = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z + player->mo->height/2, MT_FLOATINGITEM); P_SetScale(drop, drop->scale>>4); - drop->destscale = (3*drop->destscale)/2;; + drop->destscale = (3*drop->destscale)/2; drop->angle = player->mo->angle + ANGLE_90; P_Thrust(drop, @@ -5164,6 +5179,24 @@ player_t *K_FindJawzTarget(mobj_t *actor, player_t *source) return wtarg; } +static INT32 K_GetEngineClass(const player_t *player) +{ + INT32 speed, weight; + + speed = (player->kartspeed - 1) / 3; + weight = (player->kartweight - 1) / 3; + +#define LOCKSTAT(stat) \ + if (stat < 0) { stat = 0; } \ + if (stat > 2) { stat = 2; } + LOCKSTAT(speed); + LOCKSTAT(weight); +#undef LOCKSTAT + + return (speed + (3*weight)); +} + + // Engine Sounds. static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) { @@ -5174,7 +5207,7 @@ static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) static const UINT8 dampenval = 48; // 255 * 48 = close enough to FRACUNIT/6 - INT32 class, s, w; // engine class number + INT32 class; // engine class number UINT8 volume = 255; fixed_t volumedampen = FRACUNIT; @@ -5210,7 +5243,7 @@ static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) targetsnd = (((6 * cmd->forwardmove) / 25) + ((player->speed / mapobjectscale) / 5)) / 2; } - if (targetsnd < 0) { targetsnd = 0; } + if (targetsnd < 0) { targetsnd = 0; } if (targetsnd > 12) { targetsnd = 12; } if (player->kartstuff[k_enginesnd] < targetsnd) { player->kartstuff[k_enginesnd]++; } @@ -5287,17 +5320,7 @@ static void K_UpdateEngineSounds(player_t *player, ticcmd_t *cmd) return; } - s = (player->kartspeed - 1) / 3; - w = (player->kartweight - 1) / 3; - -#define LOCKSTAT(stat) \ - if (stat < 0) { stat = 0; } \ - if (stat > 2) { stat = 2; } - LOCKSTAT(s); - LOCKSTAT(w); -#undef LOCKSTAT - - class = s + (3*w); + class = K_GetEngineClass(player); S_StartSoundAtVolume(player->mo, (sfx_krta00 + player->kartstuff[k_enginesnd]) + (class * numsnds), volume); } @@ -5329,53 +5352,13 @@ static void K_UpdateInvincibilitySounds(player_t *player) #undef STOPTHIS } -void K_KartPlayerHUDUpdate(player_t *player) -{ - if (player->kartstuff[k_lapanimation]) - player->kartstuff[k_lapanimation]--; - - if (player->kartstuff[k_yougotem]) - player->kartstuff[k_yougotem]--; - - if (G_BattleGametype() && (player->exiting || player->kartstuff[k_comebacktimer])) - { - if (player->exiting) - { - if (player->exiting < 6*TICRATE) - player->kartstuff[k_cardanimation] += ((164-player->kartstuff[k_cardanimation])/8)+1; - else if (player->exiting == 6*TICRATE) - player->kartstuff[k_cardanimation] = 0; - else if (player->kartstuff[k_cardanimation] < 2*TICRATE) - player->kartstuff[k_cardanimation]++; - } - else - { - if (player->kartstuff[k_comebacktimer] < 6*TICRATE) - player->kartstuff[k_cardanimation] -= ((164-player->kartstuff[k_cardanimation])/8)+1; - else if (player->kartstuff[k_comebacktimer] < 9*TICRATE) - player->kartstuff[k_cardanimation] += ((164-player->kartstuff[k_cardanimation])/8)+1; - } - - if (player->kartstuff[k_cardanimation] > 164) - player->kartstuff[k_cardanimation] = 164; - if (player->kartstuff[k_cardanimation] < 0) - player->kartstuff[k_cardanimation] = 0; - } - else if (G_RaceGametype() && player->exiting) - { - if (player->kartstuff[k_cardanimation] < 2*TICRATE) - player->kartstuff[k_cardanimation]++; - } - else - player->kartstuff[k_cardanimation] = 0; -} - -static boolean K_SpeedLinesShouldBlend(player_t *player) +boolean K_PlayerEffectsShouldBlend(player_t *player) { if (!cv_playerblendeffects.value || !player->mo) return false; - if (player->kartstuff[k_sneakertimer]) + if (player->kartstuff[k_sneakertimer] || + player->kartstuff[k_invincibilitytimer]) return true; // this is how the percentage speedometer calcs, i suck at maths so this was the easiest thing to do lmao @@ -5460,7 +5443,7 @@ FUNCINLINE static ATTRINLINE void K_SpawnNormalSpeedLines(player_t *player, bool fast->colorized = true; } - if (colorSpeed && K_SpeedLinesShouldBlend(player)) + if (colorSpeed && K_PlayerEffectsShouldBlend(player)) fast->blendmode = AST_ADD; } } @@ -5756,7 +5739,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) K_UpdateInvincibilitySounds(player); // Also thanks, VAda! // Plays the music during and after the starting countdown. - if (P_IsLocalPlayer(player)) + if ((leveltime <= MUSICSTARTTIME) && P_IsLocalPlayer(player)) S_StartMapMusic(); } @@ -5936,45 +5919,33 @@ static void K_KartDrift(player_t *player, boolean onground) // Holding the Jump button will enable drifting. // Drift Release (Moved here so you can't "chain" drifts) - if ((player->kartstuff[k_drift] != -5 && player->kartstuff[k_drift] != 5) - // || (player->kartstuff[k_drift] >= 1 && player->kartstuff[k_turndir] != 1) || (player->kartstuff[k_drift] <= -1 && player->kartstuff[k_turndir] != -1)) - && player->kartstuff[k_driftcharge] < dsone - && onground) + if (onground && player->kartstuff[k_drift] != -5 && player->kartstuff[k_drift] != 5) { - player->kartstuff[k_driftcharge] = 0; - } - else if ((player->kartstuff[k_drift] != -5 && player->kartstuff[k_drift] != 5) - // || (player->kartstuff[k_drift] >= 1 && player->kartstuff[k_turndir] != 1) || (player->kartstuff[k_drift] <= -1 && player->kartstuff[k_turndir] != -1)) - && (player->kartstuff[k_driftcharge] >= dsone && player->kartstuff[k_driftcharge] < dstwo) - && onground) - { - if (player->kartstuff[k_driftboost] < 20) - player->kartstuff[k_driftboost] = 20; - S_StartSound(player->mo, sfx_s23c); - //K_SpawnDashDustRelease(player); - player->kartstuff[k_driftcharge] = 0; - } - else if ((player->kartstuff[k_drift] != -5 && player->kartstuff[k_drift] != 5) - // || (player->kartstuff[k_drift] >= 1 && player->kartstuff[k_turndir] != 1) || (player->kartstuff[k_drift] <= -1 && player->kartstuff[k_turndir] != -1)) - && player->kartstuff[k_driftcharge] < dsthree - && onground) - { - if (player->kartstuff[k_driftboost] < 50) - player->kartstuff[k_driftboost] = 50; - S_StartSound(player->mo, sfx_s23c); - //K_SpawnDashDustRelease(player); - player->kartstuff[k_driftcharge] = 0; - } - else if ((player->kartstuff[k_drift] != -5 && player->kartstuff[k_drift] != 5) - // || (player->kartstuff[k_drift] >= 1 && player->kartstuff[k_turndir] != 1) || (player->kartstuff[k_drift] <= -1 && player->kartstuff[k_turndir] != -1)) - && player->kartstuff[k_driftcharge] >= dsthree - && onground) - { - if (player->kartstuff[k_driftboost] < 125) - player->kartstuff[k_driftboost] = 125; - S_StartSound(player->mo, sfx_s23c); - //K_SpawnDashDustRelease(player); - player->kartstuff[k_driftcharge] = 0; + if (player->kartstuff[k_driftcharge] < dsone) + { + player->kartstuff[k_driftcharge] = 0; + } + else if (player->kartstuff[k_driftcharge] >= dsone && player->kartstuff[k_driftcharge] < dstwo) + { + if (player->kartstuff[k_driftboost] < 20) + player->kartstuff[k_driftboost] = 20; + S_StartSound(player->mo, sfx_s23c); + player->kartstuff[k_driftcharge] = 0; + } + else if (player->kartstuff[k_driftcharge] < dsthree) + { + if (player->kartstuff[k_driftboost] < 50) + player->kartstuff[k_driftboost] = 50; + S_StartSound(player->mo, sfx_s23c); + player->kartstuff[k_driftcharge] = 0; + } + else if (player->kartstuff[k_driftcharge] >= dsthree) + { + if (player->kartstuff[k_driftboost] < 125) + player->kartstuff[k_driftboost] = 125; + S_StartSound(player->mo, sfx_s23c); + player->kartstuff[k_driftcharge] = 0; + } } // Drifting: left or right? @@ -6052,8 +6023,8 @@ static void K_KartDrift(player_t *player, boolean onground) // Sound whenever you get a different tier of sparks if (driftblue - || driftred - || driftrainbow) + || driftred + || driftrainbow) { //S_StartSound(player->mo, sfx_s3ka2); if (P_IsLocalPlayer(player)) // UGHGHGH... @@ -6128,6 +6099,7 @@ static void K_KartDrift(player_t *player, boolean onground) else player->kartstuff[k_brakedrift] = 0; } + // // K_KartUpdatePosition // @@ -6316,7 +6288,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) K_KartUpdatePosition(player); - if (LIKELY(!player->exiting)) + if (!player->exiting) { if (player->kartstuff[k_oldposition] < player->kartstuff[k_position]) // But first, if you lost a place, { diff --git a/src/k_kart.h b/src/k_kart.h index 1dda3d960..ab0d8bd14 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -41,7 +41,7 @@ void K_FlipFromObject(mobj_t *mo, mobj_t *master); void K_MatchGenericExtraFlags(mobj_t *mo, mobj_t *master); void K_RespawnChecker(player_t *player); void K_KartMoveAnimation(player_t *player); -void K_KartPlayerHUDUpdate(player_t *player); +boolean K_PlayerEffectsShouldBlend(player_t *player); void K_KartPlayerThink(player_t *player, ticcmd_t *cmd); void K_KartPlayerAfterThink(player_t *player); void K_DoInstashield(player_t *player); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 9ab63ce52..0da8abfae 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -385,7 +385,7 @@ static int lib_pSpawnMobj(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnMobj(x, y, z, type); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -413,7 +413,7 @@ static int lib_pSpawnMissile(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnMissile(source, dest, type); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -432,7 +432,7 @@ static int lib_pSpawnXYZMissile(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnXYZMissile(source, dest, type, x, y, z); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -453,7 +453,7 @@ static int lib_pSpawnPointMissile(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnPointMissile(source, xa, ya, za, type, x, y, z); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -472,7 +472,7 @@ static int lib_pSpawnAlteredDirectionMissile(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnAlteredDirectionMissile(source, type, x, y, z, shiftingAngle); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -503,7 +503,7 @@ static int lib_pSPMAngle(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SPMAngle(source, type, angle, allowaim, flags2); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -519,7 +519,7 @@ static int lib_pSpawnPlayerMissile(lua_State *L) if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); mobj_t *th = P_SpawnPlayerMissile(source, type, flags2); - th->islocal = !hook_important; + if (!P_MobjWasRemoved(th)) th->islocal = !hook_important; LUA_PushUserdata(L, th, META_MOBJ); return 1; } @@ -3056,7 +3056,13 @@ static int lib_gSetPlayerGamepadIndicatorColor(lua_State *L) { INT32 player = -1; player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); // retrieve player - UINT16 color = (UINT16)luaL_checkinteger(L, 2); // skincolor + UINT8 color = (UINT8)luaL_checkinteger(L, 2); // skincolor + + if (!plr) + return LUA_ErrInvalid(L, "player_t"); + + if (color >= MAXTRANSLATIONS) + return luaL_error(L, "color %d out of range (0 - %d).", color, MAXTRANSLATIONS-1); for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) { @@ -3084,6 +3090,9 @@ static int lib_gPlayerDeviceRumble(lua_State *L) UINT16 high_strength = (UINT16)luaL_checkinteger(L, 3); // high frequency rumble motor strenght UINT32 duration = (UINT32)luaL_optinteger(L, 4, 84); // duration of rumble in ms + if (!plr) + return LUA_ErrInvalid(L, "player_t"); + for (int i = 0; i < MAXSPLITSCREENPLAYERS; ++i) { if (plr - players == displayplayers[i]) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 251a1013c..538463117 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -149,7 +149,8 @@ enum cameraf { camera_momx, camera_momy, camera_momz, - camera_pnum + camera_pnum, + camera_freecam, }; @@ -169,6 +170,7 @@ static const char *const camera_opt[] = { "momy", "momz", "pnum", + "freecam", NULL}; enum hudpatch { @@ -387,10 +389,43 @@ static int camera_get(lua_State *L) case camera_pnum: lua_pushinteger(L, camnum); break; + case camera_freecam: + lua_pushboolean(L, cam->freecam); + break; } return 1; } +static int lib_getCamera(lua_State *L) +{ + // No cameras on dedicated + if (dedicated) + return 0; + + if (lua_type(L, 2) == LUA_TNUMBER) + { + int i = lua_tonumber(L, 2); + + if (i < 0 || i > splitscreen) + return 0; + + LUA_PushUserdata(L, &camera[i], META_CAMERA); + return 1; + } + + return 0; +} + +static int lib_lenCamera(lua_State *L) +{ + if (dedicated) + lua_pushinteger(L, 0); + else + lua_pushinteger(L, splitscreen+1); // splitscreen == 0 -> 1 active camera, splitscreen == 1 -> 2 cameras and so on + + return 1; +} + // // lib_draw // @@ -1252,22 +1287,32 @@ extern int lib_hudadd(lua_State *L); static int lib_hudsetvotebackground(lua_State *L) { + // Reset to default memset(VoteScreen.luaPrefix, 0, sizeof(VoteScreen.luaPrefix)); + VoteScreen.timePerAnimFrame = 2; - if (lua_isnoneornil(L, 1)) + if (!lua_isnoneornil(L, 1)) { - return 0; + const char *prefix = luaL_checkstring(L, 1); + + if (strlen(prefix) != 4) + { + return luaL_argerror(L, 1, "prefix should 4 characters wide"); + } + + strncpy(VoteScreen.luaPrefix, prefix, 4); + strupr(VoteScreen.luaPrefix); } - const char *prefix = luaL_checkstring(L, 1); - - if (strlen(prefix) != 4) + if (!lua_isnoneornil(L, 2)) { - return luaL_argerror(L, 1, "prefix should 4 characters wide"); - } + INT32 time_per_frame = luaL_checkinteger(L, 2); - strncpy(VoteScreen.luaPrefix, prefix, 4); - strupr(VoteScreen.luaPrefix); + if (time_per_frame <= 0) + return luaL_argerror(L, 2, "time per frame should be 1 or more"); + + VoteScreen.timePerAnimFrame = time_per_frame; + } // Update background if we're already on vote screen if (gamestate == GS_VOTING) @@ -1371,6 +1416,16 @@ int LUA_HudLib(lua_State *L) lua_setfield(L, -2, "__index"); lua_pop(L,1); + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getCamera); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_lenCamera); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_setglobal(L, "cameras"); + camera_fields_ref = Lua_CreateFieldTable(L, camera_opt); luaL_register(L, "hud", lib_hud); diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index fef27f563..45c3a9f19 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -251,14 +251,8 @@ int mobj_angle_setter(lua_State *L) mobj_t *mo = GETMO(); mo->angle = luaL_checkangle(L, 2); - for (UINT8 i = 0; i <= splitscreen; i++) - { - if (mo->player == P_GetLocalPlayerForNum(i)) - { - localangle[i] = mo->angle; - break; - } - } + if (mo->player) + P_ForceLocalAngle(mo->player, mo->angle); return 0; } diff --git a/src/lua_script.c b/src/lua_script.c index 96ce94a22..2aa88cd52 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1064,9 +1064,13 @@ static void ArchiveTables(UINT8 **p) { // Write key e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + if (e == 1) + n++; // the table contained a new table we'll have to archive. :( + else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i); + lua_pop(gL, 1); + continue; } else if (e == 3) // nil key due to invalid userdata. NOT an error. { @@ -1077,15 +1081,12 @@ static void ArchiveTables(UINT8 **p) // Write value e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) - { n++; // the table contained a new table we'll have to archive. :( - } else if (e == 2) // invalid value type - { CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -2), luaL_typename(gL, -1)); - } lua_pop(gL, 1); + } lua_pop(gL, 1); WRITEUINT8(*p, ARCH_TEND); @@ -1276,13 +1277,21 @@ static void UnArchiveTables(UINT8 **p, boolean network) UINT8 ret; ret = UnArchiveValue(p, TABLESINDEX, network); - if (ret == 3) + if (ret == 1) // End of table + break; + else if (ret == 2) // Key contains a new table + n++; + else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 1) // read key - break; + + if (lua_isnil(gL, -1)) // If key is nil, skip this entry + { + lua_pop(gL, 1); + continue; + } ret = UnArchiveValue(p, TABLESINDEX, network); if (ret == 1) @@ -1291,21 +1300,15 @@ static void UnArchiveTables(UINT8 **p, boolean network) lua_pop(gL, 1); // Pop key break; } + else if (ret == 2) // read value + n++; else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); + lua_rawset(gL, -3); } lua_pop(gL, 1); diff --git a/src/m_aatree.c b/src/m_aatree.c index f78355eaf..7fb847aab 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -49,17 +49,19 @@ aatree_t *M_AATreeAlloc(UINT32 flags) return aatree; } -static void M_AATreeFree_Node(aatree_node_t *node) +static void M_AATreeFree_Node(aatree_node_t *node, bool is_string) { - if (node->left) M_AATreeFree_Node(node->left); - if (node->right) M_AATreeFree_Node(node->right); + if (node->left) M_AATreeFree_Node(node->left, is_string); + if (node->right) M_AATreeFree_Node(node->right, is_string); + if (is_string) + Z_Free(node->value); Z_Free(node); } void M_AATreeFree(aatree_t *aatree) { if (aatree->root) - M_AATreeFree_Node(aatree->root); + M_AATreeFree_Node(aatree->root, (aatree->flags & AATREE_STRING) == AATREE_STRING); Z_Free(aatree); } diff --git a/src/m_cheat.c b/src/m_cheat.c index 85caaa234..2890c7196 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -908,7 +908,7 @@ void OP_ObjectplaceMovement(player_t *player) ticcmd_t *cmd = &player->cmd; if (!player->climbing && (netgame || (player->pflags & PF_SPINNING))) - player->mo->angle = (cmd->angleturn<<16 /* not FRACBITS */); + player->mo->angle = (cmd->angleturn << TICCMD_REDUCE); ticruned++; if (!(cmd->angleturn & TICCMD_RECEIVED)) diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index 45fd78804..515799af3 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -10,20 +10,25 @@ /// \brief Chat emotes handling #include +#include #include #include #include #include "m_emotes.h" +#include "i_time.h" // I_GetTime extern "C" { #include "w_wad.h" #include "z_zone.h" #include "hu_stuff.h" #include "v_video.h" +#include "command.h" } -consvar_t cv_emotes = {"emotes", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};; +static void Command_ListEmotes_f(void); + +consvar_t cv_emotes = {"emotes", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static std::map emotes; @@ -117,12 +122,6 @@ void M_LoadEmotes(UINT16 wadnum) UINT8 numframes = 0; auto copy_frame = [&] { - if (numframes == MAXEMOTEFRAMES) - { - CONS_Alert(CONS_WARNING, "EMOTES: Too many frames. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); - return false; - } - size_t list_split = value.find(','); std::string framelumpname = value.substr(0, list_split); trim(framelumpname); @@ -136,9 +135,16 @@ void M_LoadEmotes(UINT16 wadnum) if (framelumpname.size() == 0) return false; + // Only print this warning if we actually got new frame + if (numframes == MAXEMOTEFRAMES) + { + CONS_Alert(CONS_WARNING, "EMOTES: Too many frames. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); + return false; + } + if (framelumpname.size() > 8) { - CONS_Alert(CONS_WARNING, "EMOTES: Frame %d name is too long. (file %s, line %d)", numframes, wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Frame %d name is too long. (file %s, line %d)\n", numframes, wadfiles[wadnum]->filename, linenum); framelumpname.resize(8); } @@ -153,7 +159,7 @@ void M_LoadEmotes(UINT16 wadnum) if (numframes == 0) { - CONS_Alert(CONS_WARNING, "EMOTES: Expected list of frames. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Expected list of frames. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); } emote->numframes = numframes; @@ -165,12 +171,12 @@ void M_LoadEmotes(UINT16 wadnum) if (emote->timeperframe <= 0) { emote->timeperframe = 1; - CONS_Alert(CONS_WARNING, "EMOTES: Bad value for 'timeperframe'. (file %s, line %d)", wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Bad value for 'timeperframe'. (file %s, line %d)\n", wadfiles[wadnum]->filename, linenum); } } else { - CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)", field.c_str(), wadfiles[wadnum]->filename, linenum); + CONS_Alert(CONS_WARNING, "EMOTES: Unrecognized field '%s'. (file %s, line %d)\n", field.c_str(), wadfiles[wadnum]->filename, linenum); } } else @@ -187,6 +193,8 @@ void M_InitEmotes(void) UINT16 i; for (i = 0; i < numwadfiles; i++) M_LoadEmotes(i); + + COM_AddCommand("listemotes", Command_ListEmotes_f); } emote_t *M_FindEmote(const char *name, int len, int skip) @@ -199,7 +207,7 @@ emote_t *M_FindEmote(const char *name, int len, int skip) for (auto &pair: emotes) { - if (pair.first.rfind(query, 0, std::min(len, MAXEMOTENAME)) != 0) + if (strcasestr(pair.first.c_str(), query) == NULL) continue; if (skip > 0) @@ -247,23 +255,18 @@ emote_t *M_VerifyEmote(const char *name, int *emotelen) return match; } -void M_DrawEmote(INT32 x, INT32 y, emote_t *emote, tic_t anim, INT32 flags) +void M_DrawScaledEmote(fixed_t x, fixed_t y, fixed_t scale, emote_t *emote, INT32 flags) { if (emote->numframes == 0) return; - const char *lumpname = emote->frames[(anim/emote->timeperframe) % emote->numframes]; + const char *lumpname = emote->frames[(I_GetTime()/emote->timeperframe) % emote->numframes]; patch_t *emotepatch = (patch_t*)W_CachePatchName(lumpname, PU_CACHE); const int CHARHEIGHT = 6; - fixed_t scale = FRACUNIT; - - x *= FRACUNIT; - y *= FRACUNIT; - if (emotepatch->width > EMOTEWIDTH) - scale = (FRACUNIT/emotepatch->width)*EMOTEWIDTH; + scale = FixedMul(scale, (FRACUNIT/emotepatch->width)*EMOTEWIDTH); else if (emotepatch->width < EMOTEWIDTH) x += (EMOTEWIDTH-emotepatch->width)*FRACUNIT/2; @@ -271,3 +274,37 @@ void M_DrawEmote(INT32 x, INT32 y, emote_t *emote, tic_t anim, INT32 flags) V_DrawFixedPatch(x, y, scale, flags, emotepatch, NULL); } + +static void Command_ListEmotes_f(void) +{ + const int EMOTES_PER_PAGE = 24; + const int NUMPAGES = std::max(emotes.size()/EMOTES_PER_PAGE, 1); + int page = 1; + + if (COM_Argc() > 1) + page = std::atoi(COM_Argv(1)); + + if (page <= 0 || page > NUMPAGES) + { + if (NUMPAGES > 1) + CONS_Printf("Enter page number between 1 and %d\n", NUMPAGES); + else + CONS_Printf("Bad page number, try using this command without arguments\n"); + return; + } + + int i = 0; + for (auto &pair: emotes) + { + ++i; + + if (i <= (page-1)*EMOTES_PER_PAGE) + continue; + if (i > page*EMOTES_PER_PAGE) + break; + + CONS_Printf("%s - :%s:\n", pair.first.c_str(), pair.first.c_str()); + } + + CONS_Printf("Page %d/%d\n", page, NUMPAGES); +} diff --git a/src/m_emotes.h b/src/m_emotes.h index 9921e4444..594e219f8 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -17,6 +17,7 @@ extern "C" { #endif #include "doomdef.h" +#include "m_fixed.h" #include "command.h" extern consvar_t cv_emotes; @@ -48,9 +49,9 @@ emote_t *M_FindEmote(const char *name, int len, int skips); // needs to be skipped to get past emote name emote_t *M_VerifyEmote(const char *name, int *emotelen); -// Draw the emote, anim should be some kind of timer ticking every game tic -// for animated emotes -void M_DrawEmote(INT32 x, INT32 y, emote_t *emote, tic_t anim, INT32 flags); +// Draw the emote, animation for animated emotes is done via I_GetTime +#define M_DrawEmote(x, y, emote, flags) M_DrawScaledEmote((x)<lastOn = itemOn; + itemOn = tastart; + } + + if (mapheaderinfo[cv_nextmap.value-1] && mapheaderinfo[cv_nextmap.value-1]->forcecharacter[0] != '\0') + CV_Set(&cv_chooseskin, mapheaderinfo[cv_nextmap.value-1]->forcecharacter); + + free(gpath); + } +} + +static void Dummymenuplayer_OnChange(void) +{ + if (cv_dummymenuplayer.value < 1) + CV_StealthSetValue(&cv_dummymenuplayer, splitscreen+1); + else if (cv_dummymenuplayer.value > splitscreen+1) + CV_StealthSetValue(&cv_dummymenuplayer, 1); +} + +char dummystaffname[22]; + +static void Dummystaff_OnChange(void) +{ + lumpnum_t l; + + dummystaffname[0] = '\0'; + + if ((l = W_CheckNumForName(va("%sS01",G_BuildMapName(cv_nextmap.value)))) == LUMPERROR) + { + CV_StealthSetValue(&cv_dummystaff, 0); + return; + } + else + { + char *temp = dummystaffname; + UINT8 numstaff = 1; + while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value),numstaff+1))) != LUMPERROR) + numstaff++; + + if (cv_dummystaff.value < 1) + CV_StealthSetValue(&cv_dummystaff, numstaff); + else if (cv_dummystaff.value > numstaff) + CV_StealthSetValue(&cv_dummystaff, 1); + + if ((l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value), cv_dummystaff.value))) == LUMPERROR) + return; // shouldn't happen but might as well check... + + G_UpdateStaffGhostName(l); + + while (*temp) + temp++; + + sprintf(temp, " - %d", cv_dummystaff.value); + } +} + +// Newgametype. Used for gametype changes. +static void Newgametype_OnChange(void) +{ + if (cv_nextmap.value && menuactive) + { + if (!mapheaderinfo[cv_nextmap.value-1]) + P_AllocMapHeader((INT16)(cv_nextmap.value-1)); + + if ((cv_newgametype.value == GT_RACE && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_RACE)) || // SRB2kart + ((cv_newgametype.value == GT_MATCH || cv_newgametype.value == GT_TEAMMATCH) && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_MATCH))) + { + INT32 value = 0; + + switch (cv_newgametype.value) + { + case GT_COOP: + value = TOL_RACE; // SRB2kart + break; + case GT_COMPETITION: + value = TOL_COMPETITION; + break; + case GT_RACE: + value = TOL_RACE; + break; + case GT_MATCH: + case GT_TEAMMATCH: + value = TOL_MATCH; + break; + case GT_TAG: + case GT_HIDEANDSEEK: + value = TOL_TAG; + break; + case GT_CTF: + value = TOL_CTF; + break; + } + + CV_SetValue(&cv_nextmap, M_FindFirstMap(value)); + } + } +} + +static void Splitplayers_OnChange(void) +{ + if (cv_splitplayers.value < setupm_pselect) + setupm_pselect = 1; +} + +void ShowLocalskinMenu_Onchange(void) +{ + OP_MainMenu[localskin].status = (!cv_showlocalskinmenus.value) ? (IT_DISABLED) : (IT_CALL|IT_STRING); +} + // current menudef menu_t *currentMenu = &MainDef; @@ -640,7 +871,7 @@ static boolean M_ChangeStringCvar(INT32 choice) if (M_TextInputHandle(&menuinput, choice)) { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails CV_Set(cv, menuinput.buffer); return true; @@ -699,7 +930,7 @@ static void M_CheckStringItem(void) // special case: name input, cap it to prevent writing outside the textbox // kinda ugly but itll work - if (cv == &cv_playername) + if (cv == setupm_cvname) M_TextInputInit(&menuinput, menu_text_input_buf, MAXPLAYERNAME +1); else M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); @@ -810,18 +1041,6 @@ boolean M_Responder(event_t *ev) ch = KEY_RIGHTARROW; break; } - - if (menuactive) - { - if (currentMenu == &MISC_ChangeLevelDef || currentMenu == &MP_OfflineServerDef || currentMenu == &MP_ServerDef) - { - if (ch == gamecontrol[0][gc_fire][0] - || ch == gamecontrol[0][gc_fire][1]) - { - COM_ImmedExecute("add kartencore 1"); - } - } - } } else if (menuactive) { @@ -1013,6 +1232,19 @@ boolean M_Responder(event_t *ev) if ((ch == gamecontrol[0][gc_brake][0] || ch == gamecontrol[0][gc_brake][1]) && ch >= KEY_MOUSE1) // do this here, otherwise brake opens the menu mid-game ch = KEY_ESCAPE; + if (currentMenu == &MISC_ChangeLevelDef || + currentMenu == &MP_OfflineServerDef || + currentMenu == &MP_ServerDef) + { + if (ch == gamecontrol[0][gc_fire][0] + || ch == gamecontrol[0][gc_fire][1]) + { + if (M_SecretUnlocked(SECRET_ENCORE)) + COM_ImmedExecute("add kartencore 1"); + return true; + } + } + routine = currentMenu->menuitems[itemOn].itemaction; // Handle menuitems which need a specific key handling @@ -1701,6 +1933,9 @@ void M_Ticker(void) if (dedicated) return; + if (currentMenu->tickroutine) + currentMenu->tickroutine(); + if (menuactive) I_HandleControllerHatRepeat(); @@ -1740,8 +1975,6 @@ void M_Ticker(void) } I_unlock_mutex(ms_ServerList_mutex); #endif - - CL_TimeoutServerList(); } // @@ -2349,7 +2582,7 @@ static void M_DrawGenericMenu(void) static void M_DrawGenericBackgroundMenu(void) { - V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill(srb2back); M_DrawGenericMenu(); } @@ -2498,6 +2731,12 @@ static void M_DrawPauseMenu(void) } #endif + musicdef_t *def; + if (cv_pausesongcredits.value && (def = S_FindMusicCredit(S_MusicName())) != NULL) + { + V_DrawThinString(2, 2, V_SNAPTOTOP|V_SNAPTOLEFT|V_ALLOWLOWERCASE, va("\x1F"" %s", def->source)); + } + M_DrawGenericMenu(); } @@ -2628,8 +2867,9 @@ static void M_DrawCenteredMenu(void) static inline size_t M_StringHeight(const char *string) { size_t h = 8, i; + const size_t strlength = strlen(string); - for (i = 0; i < strlen(string); i++) + for (i = 0; i < strlength; i++) if (string[i] == '\n') h += 8; @@ -2798,6 +3038,7 @@ menu_t MessageDef = NULL, // previous menu (TO HACK) MessageMenu, // menuitem_t -> M_DrawMessageMenu, // drawing routine -> + NULL, // ticker routine 0, 0, // x, y (TO HACK) 0, // lastOn, flags (TO HACK) NULL, @@ -2922,7 +3163,7 @@ static void M_DrawMessageMenu(void) // hack: draw RA background in RA menus if (gamestate == GS_TIMEATTACK) - V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill(srb2back); M_DrawTextBox(currentMenu->x, y - 8, (max+7)>>3, mlines); @@ -2989,6 +3230,7 @@ static void M_StopMessage(INT32 choice) static void M_DrawImageDef(void) { patch_t *patch = (patch_t *)W_CachePatchName(currentMenu->menuitems[itemOn].text, PU_PATCH); + if (patch->width <= BASEVIDWIDTH) V_DrawScaledPatch(0,0,0,patch); else @@ -3159,8 +3401,6 @@ static void M_DrawTemperature(INT32 x, fixed_t t) // bounds check if (t > FRACUNIT) t = FRACUNIT; - /*else if (t < 0) -- not needed - t = 0;*/ // scale if (t > 1) @@ -3232,8 +3472,8 @@ static void M_AddonsClearName(INT32 choice) M_StopMessage(choice); } -// returns whether to do message draw -static boolean M_AddonsRefresh(void) +// Handles messages for addon errors. +static void M_AddonsRefresh(void) { if ((refreshdirmenu & REFRESHDIR_NORMAL) && !preparefilemenu(true, false)) { @@ -3242,7 +3482,7 @@ static boolean M_AddonsRefresh(void) { CLEARNAME; } - return true; + return; } if (!majormods && prevmajormods) @@ -3291,14 +3531,14 @@ static boolean M_AddonsRefresh(void) if (message) { M_StartMessage(message, M_AddonsClearName, MM_EVENTHANDLER); - return true; + return; } S_StartSound(NULL, sfx_s221); CLEARNAME; } - return false; + return; } static tic_t addons_scrolltic = 0; // maybe not the best place but e @@ -3306,19 +3546,13 @@ static tic_t addons_scrolltic = 0; // maybe not the best place but e static void M_DrawAddons(void) { INT32 x, y; - ssize_t i, m; + size_t i, m; + size_t t, b; // top and bottom item #s to draw in directory 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()) - { - M_DrawMessageMenu(); - return; - } - if (Playing()) { if (browselocalskins) @@ -3348,57 +3582,73 @@ static void M_DrawAddons(void) hilicol = V_GetStringColormap(highlightflags)[120]; +#define boxwidth (MAXSTRINGLENGTH*8+6) + + // draw the file path and the top white + black lines of the box V_DrawString(x-21, (y - 16) + (lsheadingheight - 12), highlightflags|V_ALLOWLOWERCASE, M_AddonsHeaderPath()); - V_DrawFill(x-21, (y - 16) + (lsheadingheight - 3), MAXSTRINGLENGTH*8+6, 1, hilicol); - V_DrawFill(x-21, (y - 16) + (lsheadingheight - 2), MAXSTRINGLENGTH*8+6, 1, 30); + V_DrawFill(x-21, (y - 16) + (lsheadingheight - 3), boxwidth, 1, hilicol); + V_DrawFill(x-21, (y - 16) + (lsheadingheight - 2), boxwidth, 1, 30); m = (BASEVIDHEIGHT - currentMenu->y + 2) - (y - 1); - V_DrawFill(x - 21, y - 1, MAXSTRINGLENGTH*8+6, m, 239); + V_DrawFill(x-21, y - 1, boxwidth, m, 239); - // scrollbar! - if (sizedirmenu <= (2*numaddonsshown + 1)) - i = 0; + // The directory is too small for a scrollbar, so just draw a tall white line + if (sizedirmenu <= addonmenusize) + { + t = 0; // first item + b = sizedirmenu - 1; // last item + i = 0; // "scrollbar" at "top" position + } else { - ssize_t q = m; - m = ((2*numaddonsshown + 1) * m)/sizedirmenu; + size_t q = m; + m = (addonmenusize * m)/sizedirmenu; // height of scroll bar + if (dir_on[menudepthleft] <= numaddonsshown) // all the way up - i = 0; - else if (sizedirmenu <= (dir_on[menudepthleft] + numaddonsshown + 1)) // all the way down - i = q-m; - else - i = ((dir_on[menudepthleft] - numaddonsshown) * (q-m))/(sizedirmenu - (2*numaddonsshown + 1)); + { + t = 0; // first item + b = addonmenusize - 1; //9th item + i = 0; // scrollbar at top position + } + else if (dir_on[menudepthleft] >= sizedirmenu - (numaddonsshown + 1)) // all the way down + { + t = sizedirmenu - addonmenusize; // # 9th last + b = sizedirmenu - 1; // last item + i = q-m; // scrollbar at bottom position + } + else // somewhere in the middle + { + t = dir_on[menudepthleft] - numaddonsshown; // 4 items above + b = dir_on[menudepthleft] + numaddonsshown; // 4 items below + i = (t * (q-m))/(sizedirmenu - addonmenusize); // calculate position of scrollbar + } } - V_DrawFill(x + MAXSTRINGLENGTH*8+5 - 21, (y - 1) + i, 1, m, hilicol); + // draw the scrollbar! + V_DrawFill((x-21) + boxwidth-1, (y - 1) + i, 1, m, hilicol); - // get bottom... - m = dir_on[menudepthleft] + numaddonsshown + 1; - if (m > (ssize_t)sizedirmenu) - m = sizedirmenu; +#undef boxwidth - // then compute top and adjust bottom if needed! - if (m < (2*numaddonsshown + 1)) - { - m = min(sizedirmenu, 2*numaddonsshown + 1); - i = 0; - } - else - i = m - (2*numaddonsshown + 1); - - if (i != 0) + // draw up arrow that bobs up and down + if (t != 0) V_DrawString(19, y+4 - (skullAnimCounter/5), highlightflags, "\x1A"); + // make the selection box flash yellow if (skullAnimCounter < 4) flashcol = V_GetStringColormap(highlightflags); - for (; i < m; i++) + // draw icons and item names + for (i = t; i <= b; i++) { UINT32 flags = V_ALLOWLOWERCASE; -#define MAXADDONNAME 31 - char scrollbuf[MAXADDONNAME+1] = {0}; - if (y > BASEVIDHEIGHT) break; +#define charsonside 14 +#define MAXADDONNAME (charsonside*2 + 3) + char scrollbuf[MAXADDONNAME+1] = {0}; + + if (y > BASEVIDHEIGHT) + break; + if (dirmenu[i]) #define type (UINT8)(dirmenu[i][DIR_TYPE]) { @@ -3411,13 +3661,15 @@ static void M_DrawAddons(void) else V_DrawSmallScaledPatch(x-(16+4), y, 0, addonsp[(type & ~EXT_LOADED)]); - if ((size_t)i == dir_on[menudepthleft]) + // draw selection box for the item currently selected + if (i == dir_on[menudepthleft]) { V_DrawFixedPatch((x-(16+4))< MAXADDONNAME) { if ((size_t)i == dir_on[menudepthleft]) @@ -3430,18 +3682,19 @@ static void M_DrawAddons(void) V_DrawString(x, y+4, flags, scrollbuf); } #undef charsonside +#undef MAXADDONNAME else V_DrawString(x, y+4, flags, dirmenu[i]+DIR_STRING); - -#undef MAXADDONNAME } #undef type y += 16; } - if (m != (ssize_t)sizedirmenu) + // draw down arrow that bobs down and up + if (b != sizedirmenu) V_DrawString(19, y-12 + (skullAnimCounter/5), highlightflags, "\x1B"); + // draw search box y = BASEVIDHEIGHT - currentMenu->y + 1; M_DrawTextBox(x - (21 + 5), y, MAXSTRINGLENGTH, 1); @@ -3451,15 +3704,21 @@ static void M_DrawAddons(void) else V_DrawString(x - 18, y + 8, V_ALLOWLOWERCASE|V_TRANSLUCENT, "Type to search..."); + // draw search icon x -= (21 + 5 + 16); V_DrawSmallScaledPatch(x, y + 4, (menusearch.length ? 0 : V_TRANSLUCENT), addonsp[NUM_EXT+3]); + // draw save icon x = BASEVIDWIDTH - x - 16; V_DrawSmallScaledPatch(x, y + 4, ((!majormods) ? 0 : V_TRANSLUCENT), addonsp[NUM_EXT+4]); if (modifiedgame) V_DrawSmallScaledPatch(x, y + 4, 0, addonsp[NUM_EXT+2]); + // no space on alot of resolutions + //m = numwadfiles-(mainwads+2+1); + //V_DrawCenteredString(BASEVIDWIDTH/2, y+24, (majormods ? highlightflags : V_TRANSLUCENT), va("%d ADD-ON%s LOADED", (int)m, (m == 1) ? "" : "S")); //+2 for music, sounds, +1 for main.kart + V_DrawThinString(0, BASEVIDHEIGHT-10, V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_TRANSLUCENT|V_ALLOWLOWERCASE, ("END Key - Add addon to autoload")); } @@ -3544,7 +3803,7 @@ static void M_HandleAddons(INT32 choice) if (M_TextInputHandle(&menusearch, choice)) { - S_StartSound(NULL,sfx_menu1); + S_StartSound(NULL, sfx_menu1); char *tempname = NULL; if (dirmenu && dirmenu[dir_on[menudepthleft]]) @@ -3744,10 +4003,11 @@ static void M_HandleAddons(INT32 choice) } // ---- REPLAY HUT ----- -menudemo_t *demolist; // Replays that that have been checked to match with query +menudemo_t *demolist = NULL; // Replays that that have been checked to match with query // Locked behind Lock_search_state -menudemo_t *demolist_all; // All replays +menudemo_t *demolist_all = NULL; // All replays +size_t demolist_all_size = 0; boolean replaynamesloaded = false; #ifdef HAVE_THREADS @@ -3780,14 +4040,14 @@ static void ReplayNamesLoadThread(void* userdata) { Lock_search_state(); - size_t demolist_all_size = sizedirmenu; - menudemo_t *demolist_all_local = (menudemo_t*)malloc(sizeof(menudemo_t)*sizedirmenu); - memcpy(demolist_all_local, demolist_all, sizeof(menudemo_t)*sizedirmenu); + size_t demolist_all_size_local = demolist_all_size; + menudemo_t *demolist_all_local = (menudemo_t*)malloc(sizeof(menudemo_t)*demolist_all_size_local); + memcpy(demolist_all_local, demolist_all, sizeof(menudemo_t)*demolist_all_size_local); char *replaydirpath = (char*)userdata; Unlock_search_state(); - for (size_t i = 0; i < demolist_all_size; ++i) + for (size_t i = 0; i < demolist_all_size_local; ++i) { if (demolist_all_local[i].type != MD_SUBDIR) { @@ -3803,9 +4063,9 @@ static void ReplayNamesLoadThread(void* userdata) Lock_search_state(); - if (fastcmp(menupath, replaydirpath)) + if (fastcmp(menupath, replaydirpath) && demolist_all) { - memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*sizedirmenu); + memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*demolist_all_size); replaynamesloaded = true; } @@ -3939,6 +4199,7 @@ static void PrepReplayList(boolean reset) Z_Free(demolist_all); demolist_all = Z_Calloc(sizeof(menudemo_t) * sizedirmenu, PU_STATIC, NULL); + demolist_all_size = sizedirmenu; for (i = 0; i < sizedirmenu; i++) { @@ -3987,6 +4248,7 @@ void M_ReplayHut(INT32 choice) } else if (!demo.inreplayhut) dir_on[menudepthleft] = 0; + demo.inreplayhut = true; replayScrollTitle = 0; replayScrollDelay = TICRATE; replayScrollDir = 1; @@ -4011,7 +4273,7 @@ static boolean M_HandleReplayHutQuery(INT32 choice) if (M_TextInputHandle(&replayqueryinput, choice)) { - S_StartSound(NULL,sfx_menu1); + S_StartSound(NULL, sfx_menu1); // Restart search only if we actually modified input and not just moved in it if (memcmp(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1)) @@ -4078,6 +4340,9 @@ static void M_HandleReplayHutList(INT32 choice) if (!replaynamesloaded) return; + if (replayqueryfound == 0) + return; + switch (dirmenu[dir_on[menudepthleft]][DIR_TYPE]) { case EXT_FOLDER: @@ -4176,136 +4441,140 @@ static void DrawReplayHutReplayInfo(void) UINT8 *colormap; INT32 x, y, w, h; - switch (demolist[dir_on[menudepthleft]].type) + const menudemo_t *replaydemolist = &demolist[dir_on[menudepthleft]]; + + switch (replaydemolist->type) { - case MD_NOTLOADED: - V_DrawCenteredString(160, 40, V_SNAPTOTOP|MENUCAPS, "Loading replay information..."); - break; - - case MD_INVALID: - V_DrawCenteredString(160, 40, V_SNAPTOTOP|warningflags|MENUCAPS, "This replay cannot be played."); - break; - - case MD_SUBDIR: - break; // Can't think of anything to draw here right now - - case MD_OUTDATED: - V_DrawThinString(17, 64, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT|highlightflags, va("Recorded on an outdated version. %s", demolist[dir_on[menudepthleft]].version)); - /* FALLTHRU */ - default: - // Draw level stuff - x = 15; y = 15; - - // A 160x100 image of the level as entry MAPxxP - //CONS_Printf("%d %s\n", demolist[dir_on[menudepthleft]].map, G_BuildMapName(demolist[dir_on[menudepthleft]].map)); - lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(demolist[dir_on[menudepthleft]].map))); - if (lumpnum != LUMPERROR) - patch = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH); - else - patch = (patch_t *)W_CachePatchName("M_NOLVL", PU_PATCH); - - if (!(demolist[dir_on[menudepthleft]].kartspeed & DF_ENCORE)) - V_DrawSmallScaledPatch(x, y, V_SNAPTOTOP, patch); - else - { - w = patch->width; - h = patch->height; - V_DrawSmallScaledPatch(x+(w>>1), y, V_SNAPTOTOP|V_FLIP, patch); - - { - static angle_t rubyfloattime = 0; - const fixed_t rubyheight = FINESINE(rubyfloattime>>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+(w>>2))<>2))<version)); + /* FALLTHRU */ + default: + // Draw level stuff + x = 15; y = 15; - // Character face! - if (demolist[dir_on[menudepthleft]].standings[0].skin < numskins && W_CheckNumForName(skins[demolist[dir_on[menudepthleft]].standings[0].skin].facewant) != LUMPERROR) - { - patch = facewantprefix[demolist[dir_on[menudepthleft]].standings[0].skin]; - colormap = R_GetTranslationColormap( - demolist[dir_on[menudepthleft]].standings[0].skin, - demolist[dir_on[menudepthleft]].standings[0].color, - GTC_MENUCACHE); - } - else - { - patch = (patch_t *)W_CachePatchName("M_NOWANT", PU_PATCH); - colormap = R_GetTranslationColormap( - TC_RAINBOW, - demolist[dir_on[menudepthleft]].standings[0].color, - GTC_MENUCACHE); - } + // A 160x100 image of the level as entry MAPxxP + //CONS_Printf("%d %s\n", replaydemolist->map, G_BuildMapName(replaydemolist->map)); + lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(replaydemolist->map))); + if (lumpnum != LUMPERROR) + patch = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH); + else + patch = (patch_t *)W_CachePatchName("M_NOLVL", PU_PATCH); - V_DrawMappedPatch(BASEVIDWIDTH-15 - patch->width, y+20, V_SNAPTOTOP, patch, colormap); + if (!(replaydemolist->kartspeed & DF_ENCORE)) + V_DrawSmallScaledPatch(x, y, V_SNAPTOTOP, patch); + else + { + w = patch->width; + h = patch->height; + V_DrawSmallScaledPatch(x+(w>>1), y, V_SNAPTOTOP|V_FLIP, patch); - break; + { + static angle_t rubyfloattime = 0; + const fixed_t rubyheight = FINESINE(rubyfloattime>>ANGLETOFINESHIFT); + V_DrawFixedPatch((x+(w>>2))<>2))<map-1]) + { + char *title = G_BuildMapTitle(replaydemolist->map); + if (title) + { + V_DrawString(x, y, V_SNAPTOTOP|MENUCAPS, title); + Z_Free(title); + } + } + else + V_DrawString(x, y, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "Level is not loaded."); + + INT32 datew = 0; + + if (replaydemolist->date[0] != '\0') + { + datew = V_StringWidth(replaydemolist->date, 0); + V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("%s", replaydemolist->date)); + } + + if (replaydemolist->numlaps) + V_DrawThinString(x+datew, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("(%d laps)", replaydemolist->numlaps)); + + V_DrawString(x, y+20, V_SNAPTOTOP|V_ALLOWLOWERCASE, replaydemolist->gametype == GT_RACE ? + va("Race (%s speed)", kartspeed_cons_t[replaydemolist->kartspeed & ~DF_ENCORE].strvalue) : + "Battle Mode"); + + if (!replaydemolist->standings[0].ranking) + { + // No standings were loaded! + V_DrawString(x, y+39, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "No standings available."); + break; + } + + V_DrawThinString(x, y+29, V_SNAPTOTOP|highlightflags|MENUCAPS, "Winner"); + V_DrawString(x+38, y+30, V_SNAPTOTOP|V_ALLOWLOWERCASE, replaydemolist->standings[0].name); + + if (replaydemolist->gametype == GT_RACE) + { + V_DrawThinString(x, y+39, V_SNAPTOTOP|highlightflags|MENUCAPS, "Time"); + } + else + { + V_DrawThinString(x, y+39, V_SNAPTOTOP|highlightflags|MENUCAPS, "Score"); + } + + const UINT32 timeorscore = replaydemolist->standings[0].timeorscore; + + if (timeorscore == (UINT32_MAX-1)) + { + V_DrawThinString(x+32, y+40-1, V_SNAPTOTOP|MENUCAPS, "No Contest"); + } + else if (replaydemolist->gametype == GT_RACE) + { + V_DrawRightAlignedString(x+84, y+40, V_SNAPTOTOP, va("%d'%02d\"%02d", + G_TicsToMinutes(timeorscore, true), + G_TicsToSeconds(timeorscore), + G_TicsToCentiseconds(timeorscore) + )); + } + else + { + V_DrawString(x+32, y+40, V_SNAPTOTOP, va("%d", timeorscore)); + } + + // Character face! + if (replaydemolist->standings[0].skin < numskins && W_CheckNumForName(skins[replaydemolist->standings[0].skin].facewant) != LUMPERROR) + { + patch = facewantprefix[replaydemolist->standings[0].skin]; + colormap = R_GetTranslationColormap( + replaydemolist->standings[0].skin, + replaydemolist->standings[0].color, + GTC_MENUCACHE); + } + else + { + patch = (patch_t *)W_CachePatchName("M_NOWANT", PU_PATCH); + colormap = R_GetTranslationColormap( + TC_RAINBOW, + replaydemolist->standings[0].color, + GTC_MENUCACHE); + } + + V_DrawMappedPatch(BASEVIDWIDTH-15 - patch->width, y+20, V_SNAPTOTOP, patch, colormap); + + break; } } @@ -4319,7 +4588,7 @@ static void M_DrawReplayHut(void) static UINT16 replayhutmenuy = 0; - V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill(srb2back); if (cv_vhseffect.value) V_DrawVhsEffect(false); @@ -4371,7 +4640,7 @@ static void M_DrawReplayHut(void) if (i == itemOn) cursory = localy; - if ((currentMenu->menuitems[i].status & IT_DISPLAY)==IT_STRING) + if ((currentMenu->menuitems[i].status & IT_DISPLAY) == IT_STRING) V_DrawString(x, localy, V_SNAPTOTOP|V_SNAPTOLEFT, currentMenu->menuitems[i].text); else V_DrawString(x, localy, V_SNAPTOTOP|V_SNAPTOLEFT|highlightflags, currentMenu->menuitems[i].text); @@ -4451,8 +4720,7 @@ static void M_DrawReplayHut(void) } // Draw the cursor - V_DrawScaledPatch(currentMenu->x - 24, cursory, V_SNAPTOTOP|V_SNAPTOLEFT, - (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); + V_DrawScaledPatch(currentMenu->x - 24, cursory, V_SNAPTOTOP|V_SNAPTOLEFT, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(currentMenu->x, cursory, V_SNAPTOTOP|V_SNAPTOLEFT|highlightflags, currentMenu->menuitems[itemOn].text); // Now draw some replay info! @@ -4484,34 +4752,38 @@ static void M_DrawReplayStartMenu(void) M_DrawGenericBackgroundMenu(); + const menudemo_t *replaydemolist = &demolist[dir_on[menudepthleft]]; + #define STARTY 62-(replayScrollTitle>>1) // Draw rankings beyond first - for (i = 1; i < MAXPLAYERS && demolist[dir_on[menudepthleft]].standings[i].ranking; i++) + for (i = 1; i < MAXPLAYERS && replaydemolist->standings[i].ranking; i++) { patch_t *patch; UINT8 *colormap; - V_DrawRightAlignedString(BASEVIDWIDTH-100, STARTY + i*20, V_SNAPTOTOP|highlightflags, va("%2d", demolist[dir_on[menudepthleft]].standings[i].ranking)); - V_DrawThinString(BASEVIDWIDTH-96, STARTY + i*20, V_SNAPTOTOP|V_ALLOWLOWERCASE, demolist[dir_on[menudepthleft]].standings[i].name); + V_DrawRightAlignedString(BASEVIDWIDTH-100, STARTY + i*20, V_SNAPTOTOP|highlightflags, va("%2d", replaydemolist->standings[i].ranking)); + V_DrawThinString(BASEVIDWIDTH-96, STARTY + i*20, V_SNAPTOTOP|V_ALLOWLOWERCASE, replaydemolist->standings[i].name); - if (demolist[dir_on[menudepthleft]].standings[i].timeorscore == UINT32_MAX-1) + const UINT32 timeorscore = replaydemolist->standings[i].timeorscore; + + if (timeorscore == UINT32_MAX-1) V_DrawThinString(BASEVIDWIDTH-92, STARTY + i*20 + 9, V_SNAPTOTOP, "NO CONTEST"); - else if (demolist[dir_on[menudepthleft]].gametype == GT_RACE) + else if (replaydemolist->gametype == GT_RACE) V_DrawRightAlignedString(BASEVIDWIDTH-40, STARTY + i*20 + 9, V_SNAPTOTOP, va("%d'%02d\"%02d", - G_TicsToMinutes(demolist[dir_on[menudepthleft]].standings[i].timeorscore, true), - G_TicsToSeconds(demolist[dir_on[menudepthleft]].standings[i].timeorscore), - G_TicsToCentiseconds(demolist[dir_on[menudepthleft]].standings[i].timeorscore) + G_TicsToMinutes(timeorscore, true), + G_TicsToSeconds(timeorscore), + G_TicsToCentiseconds(timeorscore) )); else - V_DrawString(BASEVIDWIDTH-92, STARTY + i*20 + 9, V_SNAPTOTOP, va("%d", demolist[dir_on[menudepthleft]].standings[i].timeorscore)); + V_DrawString(BASEVIDWIDTH-92, STARTY + i*20 + 9, V_SNAPTOTOP, va("%d", timeorscore)); // Character face! - if (demolist[dir_on[menudepthleft]].standings[i].skin < numskins && W_CheckNumForName(skins[demolist[dir_on[menudepthleft]].standings[i].skin].facerank) != LUMPERROR) + if (replaydemolist->standings[i].skin < numskins && W_CheckNumForName(skins[replaydemolist->standings[i].skin].facerank) != LUMPERROR) { - patch = facerankprefix[demolist[dir_on[menudepthleft]].standings[i].skin]; + patch = facerankprefix[replaydemolist->standings[i].skin]; colormap = R_GetTranslationColormap( - demolist[dir_on[menudepthleft]].standings[i].skin, - demolist[dir_on[menudepthleft]].standings[i].color, + replaydemolist->standings[i].skin, + replaydemolist->standings[i].color, GTC_MENUCACHE); } else @@ -4519,7 +4791,7 @@ static void M_DrawReplayStartMenu(void) patch = (patch_t *)W_CachePatchName("M_NORANK", PU_PATCH); colormap = R_GetTranslationColormap( TC_RAINBOW, - demolist[dir_on[menudepthleft]].standings[i].color, + replaydemolist->standings[i].color, GTC_MENUCACHE); } @@ -4556,10 +4828,10 @@ static void M_DrawReplayStartMenu(void) V_DrawFill(10, 10, 300, 60, V_SNAPTOTOP|239); DrawReplayHutReplayInfo(); - V_DrawString(10, 72, V_SNAPTOTOP|highlightflags|V_ALLOWLOWERCASE, demolist[dir_on[menudepthleft]].title); + V_DrawString(10, 72, V_SNAPTOTOP|highlightflags|V_ALLOWLOWERCASE, replaydemolist->title); // Draw a warning prompt if needed - switch (demolist[dir_on[menudepthleft]].addonstatus) + switch (replaydemolist->addonstatus) { case DFILE_ERROR_CANNOTLOAD: warning = "Some addons in this replay cannot be loaded.\nYou can watch anyway, but desyncs may occur."; @@ -4588,6 +4860,9 @@ static void M_DrawReplayStartMenu(void) void M_ResetDemoList(void) { + Lock_search_state(); + replaynamesloaded = false; + Z_Free(demolist_all); demolist_all = NULL; @@ -4595,6 +4870,8 @@ void M_ResetDemoList(void) demolist = NULL; demo.inreplayhut = false; + + Unlock_search_state(); } static boolean M_QuitReplayHut(void) @@ -4607,6 +4884,16 @@ static boolean M_QuitReplayHut(void) return true; } +// same as M_QuitReplayHut, but calls M_StopMessage +void M_ReturnToTitleFromError(void) +{ + M_StopMessage(0); + // D_StartTitle does its own wipe, since GS_TIMEATTACK is now a complete gamestate. + menuactive = false; + D_StartTitle(); + M_ResetDemoList(); +} + static void M_HutStartReplay(INT32 choice) { (void)choice; @@ -5079,7 +5366,7 @@ void M_PopupMasterServerRules(void) UINT16 ccvaralphakey = 4; INT16 ccvarlaststheader = 0; -INT32 CVARSETUP; +INT32 CVARSETUP = 0; void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* name) { @@ -5124,7 +5411,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na // SKY ROOM // ======== -UINT8 skyRoomMenuTranslations[MAXUNLOCKABLES]; +UINT8 skyRoomMenuTranslations[MAXUNLOCKABLES] = {}; static char *M_GetConditionString(condition_t cond) { @@ -5958,7 +6245,7 @@ void M_DrawTimeAttackMenu(void) //S_ChangeMusicInternal("racent", true); // Eww, but needed for when user hits escape during demo playback - V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill(srb2back); M_DrawMenuTitle(); if (currentMenu == &SP_TimeAttackDef) @@ -5971,11 +6258,27 @@ void M_DrawTimeAttackMenu(void) SHOWMODDEDGAME + const INT32 skinnum = max(cv_chooseskin.value-1, 0); // dont think its needed but better safe than sorry! + const skin_t *skin = &skins[skinnum]; + // Character face! - if (W_CheckNumForName(skins[cv_chooseskin.value-1].facewant) != LUMPERROR) + if (W_CheckNumForName(skin->facewant) != LUMPERROR) { - UINT8 *colormap = R_GetTranslationColormap(cv_chooseskin.value-1, cv_playercolor.value, GTC_MENUCACHE); - V_DrawMappedPatch(BASEVIDWIDTH-x - facewantprefix[cv_chooseskin.value-1]->width, y, 0, facewantprefix[cv_chooseskin.value-1], colormap); + const INT32 charx = (BASEVIDWIDTH-x - facewantprefix[skinnum]->width); + + UINT8 *colormap = NULL; + + colormap = R_GetTranslationColormap(skinnum, cv_playercolor.value, GTC_MENUCACHE); + V_DrawMappedPatch(charx, y, 0, facewantprefix[skinnum], colormap); + + // draw stats + // speed + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BLUEBERRY, GTC_CACHE); + V_DrawFixedPatch((charx-6) << FRACBITS, (y-5) << FRACBITS, 3*FRACUNIT/2, 0, kp_facenum[min(9, max(1, skin->kartspeed))], colormap); + // weight + colormap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BURGUNDY, GTC_CACHE); + V_DrawFixedPatch((charx+25) << FRACBITS, (y+25) << FRACBITS, 3*FRACUNIT/2, 0, kp_facenum[min(9, max(1, skin->kartweight))], colormap); + // idk if kp_facenum are the best numbers for this case? but works with some scaling lul } for (i = 0; i < currentMenu->numitems; ++i) @@ -6005,7 +6308,7 @@ void M_DrawTimeAttackMenu(void) } else { - const char *str = ((cv == &cv_chooseskin) ? skins[cv_chooseskin.value-1].realname : cv->string); + const char *str = ((cv == &cv_chooseskin) ? skin->realname : cv->string); INT32 soffset = 40, strw = V_StringWidth(str, 0); // hack to keep the menu from overlapping the level icon @@ -6050,10 +6353,12 @@ void M_DrawTimeAttackMenu(void) { tic_t lap = 0, time = 0; - if (mainrecords[cv_nextmap.value-1]) + const recorddata_t *currecord = mainrecords[cv_nextmap.value-1]; + + if (currecord) { - lap = mainrecords[cv_nextmap.value-1]->lap; - time = mainrecords[cv_nextmap.value-1]->time; + lap = currecord->lap; + time = currecord->time; } V_DrawFill((BASEVIDWIDTH - vid.scaledwidth)>>1, 78, vid.scaledwidth, 36, 239); @@ -6075,6 +6380,7 @@ void M_DrawTimeAttackMenu(void) y = currentMenu->y+SP_TimeAttackMenu[i].alphaKey; V_DrawString(x, y, V_TRANSLUCENT|MENUCAPS, SP_TimeAttackMenu[i].text); ncv = (consvar_t *)SP_TimeAttackMenu[i].itemaction; + if (SP_TimeAttackMenu[i].status & IT_CV_STRING) { M_DrawTextBox(x + 32, y - 8, MAXPLAYERNAME, 1); @@ -6082,7 +6388,7 @@ void M_DrawTimeAttackMenu(void) } else { - const char *str = ((ncv == &cv_chooseskin) ? skins[cv_chooseskin.value-1].realname : ncv->string); + const char *str = ((ncv == &cv_chooseskin) ? skin->realname : ncv->string); INT32 soffset = 40, strw = V_StringWidth(str, 0); // hack to keep the menu from overlapping the level icon @@ -6245,8 +6551,7 @@ static void M_EraseGuest(INT32 choice) remove(rguest); M_SetupNextMenu(&SP_TimeAttackDef); - CV_AddValue(&cv_nextmap, -1); - CV_AddValue(&cv_nextmap, 1); + Nextmap_OnChange(); M_StartMessage(M_GetText("Guest replay data erased.\n"),NULL,MM_NOTHING); } @@ -6267,8 +6572,7 @@ static void M_OverwriteGuest(const char *which) Z_Free(rguest); M_SetupNextMenu(&SP_TimeAttackDef); - CV_AddValue(&cv_nextmap, -1); - CV_AddValue(&cv_nextmap, 1); + Nextmap_OnChange(); M_StartMessage(M_GetText("Guest replay data saved.\n"),NULL,MM_NOTHING); } @@ -6338,8 +6642,7 @@ static void M_ModeAttackEndGame(INT32 choice) modeattacking = ATTACKING_NONE; S_ChangeMusicInternal("racent", true); // Update replay availability. - CV_AddValue(&cv_nextmap, 1); - CV_AddValue(&cv_nextmap, -1); + Nextmap_OnChange(); } // ======== @@ -6478,6 +6781,10 @@ static void M_SearchServerList(void) char servername[MAXSERVERNAME+1] = {0}; serverlistsearchedcount = 0; +#ifdef HAVE_THREADS + I_lock_mutex(&ms_ServerList_mutex); +#endif + for (UINT32 i = 0; i < serverlistcount; ++i) { StripColors(servername, serverlist[i].info.servername, MAXSERVERNAME); @@ -6485,6 +6792,10 @@ static void M_SearchServerList(void) serverlistsearched[serverlistsearchedcount++] = i; } +#ifdef HAVE_THREADS + I_unlock_mutex(ms_ServerList_mutex); +#endif + if (menuinput.length > 0) serverlistpage = 0; } @@ -6582,12 +6893,22 @@ static void M_Connect(INT32 choice) COM_BufAddText(va("connect node %d\n", serverlist[serverlistsearched[choice-FIRSTSERVERLINE + serverlistpage * SERVERS_PER_PAGE]].node)); } +static void M_ResetServerList(void) +{ + serverlistpage = 0; + oldserverlistpage = 0; + + serverlistslidex = 0.0f; + memset(serverlistsearched, 0, sizeof(serverlistsearched)); + serverlistsearchedcount = 0; +} + static void M_Refresh(INT32 choice) { (void)choice; // first page of servers - serverlistpage = 0; + M_ResetServerList(); CL_UpdateServerList(); @@ -6618,14 +6939,7 @@ static void M_DrawServerCountAndHorizontalBar(void) break; default: - if (serverlistultimatecount > serverlistcount) - { - text = va("%d/%d servers found%.*s", - serverlistcount, - serverlistultimatecount, - I_GetTime() / NEWTICRATE % 4, "..."); - } - else if (serverlistcount > 0) + if (serverlistcount > 0) { text = va("%d servers found", serverlistcount); } @@ -6809,7 +7123,7 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en void M_SortServerList(void) { - switch(cv_serversort.value) + switch (cv_serversort.value) { case 0: // Ping. qs22j(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_time); @@ -6884,7 +7198,7 @@ static void M_ConnectMenu(INT32 choice) // we don't request a restart unless the filelist differs // first page of servers - serverlistpage = 0; + M_ResetServerList(); CL_UpdateServerList(); @@ -7102,7 +7416,8 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) patch_t *PictureOfLevel; INT32 x, y, w, i, oldval, trans, dupadjust = (vid.scaledwidth - BASEVIDWIDTH)>>1; - if (levellistmode != LLM_RECORDATTACK) // so it doesent show in record attack menu + // so it doesent show in record attack menu + if (levellistmode != LLM_RECORDATTACK && M_SecretUnlocked(SECRET_ENCORE)) // gotta have it unlocked first ofc { char encoretoggle[32] = {0}; const char *item1 = gamecontrol[0][gc_fire][0] != 0 ? G_KeynumToString(gamecontrol[0][gc_fire][0]) : NULL; @@ -7323,10 +7638,6 @@ static void M_StartServerMenu(INT32 choice) // CONNECT VIA IP // ============== -#define SETUPM_IP_MAXSIZE ((28-1)*8) -static char setupm_ip[64]; -static textinput_t setupm_input_ip; - void M_Multiplayer(INT32 choice) { (void)choice; @@ -7335,8 +7646,6 @@ void M_Multiplayer(INT32 choice) M_SetupNextMenu(&MP_MainDef); } -static UINT8 setupm_pselect = 1; - // Draw the funky Connect IP menu. Tails 11-19-2002 // So much work for such a little thing! static void M_DrawMPMainMenu(void) @@ -7431,12 +7740,6 @@ Update the maxplayers label... } } -static void Splitplayers_OnChange(void) -{ - if (cv_splitplayers.value < setupm_pselect) - setupm_pselect = 1; -} - static void M_SetupMultiHandler(INT32 choice) { boolean exitmenu = false; // exit to previous menu and send name change @@ -7448,7 +7751,7 @@ static void M_SetupMultiHandler(INT32 choice) { if (--setupm_pselect < 1) setupm_pselect = cv_splitplayers.value; - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } break; @@ -7457,23 +7760,23 @@ static void M_SetupMultiHandler(INT32 choice) { if (++setupm_pselect > cv_splitplayers.value) setupm_pselect = 1; - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } break; case KEY_DOWNARROW: M_NextOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_UPARROW: M_PrevOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_ENTER: { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails currentMenu->lastOn = itemOn; switch (setupm_pselect) { @@ -7527,7 +7830,6 @@ static void M_ConnectIP(INT32 choice) M_DrawTextBox(56, BASEVIDHEIGHT/2-12, 24, 2); V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, "Connecting to server..."); I_OsPolling(); - I_UpdateNoBlit(); if (rendermode == render_soft) I_FinishUpdate(); // page flip or blit buffer } @@ -7556,16 +7858,16 @@ static void M_HandleConnectIP(INT32 choice) { case KEY_DOWNARROW: M_NextOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_UPARROW: M_PrevOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_ENTER: - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails currentMenu->lastOn = itemOn; M_ConnectIP(1); break; @@ -7579,7 +7881,7 @@ static void M_HandleConnectIP(INT32 choice) case KEY_BACKSPACE: case KEY_DEL: if (M_TextInputHandle(&setupm_input_ip, choice)) - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; default: @@ -7589,7 +7891,7 @@ static void M_HandleConnectIP(INT32 choice) || (choice >= 199 && choice <= 211 && choice != 202 && choice != 206))*/ //numpad too! { if (M_TextInputHandle(&setupm_input_ip, choice)) - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } break; } @@ -7608,28 +7910,6 @@ static void M_HandleConnectIP(INT32 choice) // ======================== // Tails 03-02-2002 -static fixed_t multi_tics; -static state_t *multi_state; - -// this is set before entering the MultiPlayer setup menu, -// for either player 1 or 2 -static char setupm_name[MAXPLAYERNAME+1]; -static textinput_t setupm_input; -static player_t *setupm_player; -static consvar_t *setupm_cvskin; -static consvar_t *setupm_cvcolor; -static consvar_t *setupm_cvname; -static UINT8 setupm_skinxpos; -static INT32 setupm_fakeskin; -static INT32 setupm_fakecolor; - -//variables used for other skin select menus -static UINT8 setupm_skinypos; -static INT32 setupm_skinselect; -static boolean setupm_skinlockedselect; - -static UINT8 setupm_playernum; //brap - #define SELECTEDSTATSCOUNT skinstatscount[setupm_skinxpos][setupm_skinypos] #define LASTSELECTEDSTAT skinstats[setupm_skinxpos][setupm_skinypos][skinstatscount[setupm_skinxpos][setupm_skinypos]] @@ -8315,7 +8595,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else M_NextOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; } else if (gridselect) //grid skin select menu @@ -8355,7 +8635,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; } M_NextOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_UPARROW: @@ -8371,7 +8651,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else M_PrevOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; } else if (gridselect) @@ -8408,18 +8688,18 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else M_PrevOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; } M_PrevOpt(); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails break; case KEY_LEFTARROW: if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { @@ -8433,7 +8713,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else //player skin { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails if (setupm_skinxpos > 0) setupm_skinxpos--; @@ -8466,14 +8746,14 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } if (itemOn == 1) //player skin { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails setupm_fakeskin--; } else if (itemOn == 2) // player color { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails setupm_fakecolor--; - G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, (UINT8)setupm_fakecolor); } break; @@ -8481,7 +8761,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { @@ -8491,11 +8771,11 @@ static void M_HandleSetupMultiPlayer(INT32 choice) setupm_skinselect++; else setupm_skinselect = 0; - S_StartSound(NULL,sfx_menu1); + S_StartSound(NULL, sfx_menu1); } else //player skin { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails if (setupm_skinxpos < MAXSTAT - 1) setupm_skinxpos++; else @@ -8530,14 +8810,14 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } if (itemOn == 1) //player skin { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails setupm_fakeskin++; } else if (itemOn == 2) // player color { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails setupm_fakecolor++; - G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, (UINT8)setupm_fakecolor); } break; @@ -8556,7 +8836,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } else if (gridselect && itemOn == 1) { @@ -8572,9 +8852,9 @@ static void M_HandleSetupMultiPlayer(INT32 choice) UINT8 col = skins[setupm_fakeskin].prefcolor; if (setupm_fakecolor != col) { - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails setupm_fakecolor = col; - G_SetPlayerGamepadIndicatorColor(setupm_playernum, setupm_fakecolor); + G_SetPlayerGamepadIndicatorColor(setupm_playernum, (UINT8)setupm_fakecolor); } } break; @@ -8585,7 +8865,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) if (itemOn == 0) { M_TextInputHandle(&setupm_input, choice); - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } break; @@ -8608,7 +8888,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { setupm_skinlockedselect = true; setupm_skinselect = 0; - S_StartSound(NULL,sfx_menu1); + S_StartSound(NULL, sfx_menu1); } } else if (gridselect && itemOn == 1 && setupm_skinselect < numskins) @@ -8622,7 +8902,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) if (itemOn == 0) { if (M_TextInputHandle(&setupm_input, choice)) - S_StartSound(NULL,sfx_menu1); // Tails + S_StartSound(NULL, sfx_menu1); // Tails } break; } @@ -8687,9 +8967,6 @@ static void M_DoSetupMultiPlayer(UINT8 pnum) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); - M_TextInputSetString(&setupm_input, cv_playername.string); - switch (pnum) { case 1: @@ -8718,6 +8995,9 @@ static void M_DoSetupMultiPlayer(UINT8 pnum) break; } + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, setupm_cvname->string); + setupm_skinxpos = 4; setupm_skinypos = 0; setupm_skinlockedselect = false; @@ -8784,15 +9064,15 @@ static boolean M_QuitMultiPlayerMenu(void) if (!fastcmp(setupm_name, setupm_cvname->string)) { // remove trailing whitespaces - for (l= strlen(setupm_name)-1; + for (l = strlen(setupm_name)-1; (signed)l >= 0 && setupm_name[l] ==' '; l--) setupm_name[l] =0; - COM_BufAddText (va("%s \"%s\"\n",setupm_cvname->name,setupm_name)); + COM_BufAddText(va("%s \"%s\"\n",setupm_cvname->name,setupm_name)); } // you know what? always putting these in the buffer won't hurt anything. - COM_BufAddText (va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); - COM_BufAddText (va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); + COM_BufAddText(va("%s \"%s\"\n",setupm_cvskin->name,skins[setupm_fakeskin].name)); + COM_BufAddText(va("%s %d\n",setupm_cvcolor->name,setupm_fakecolor)); return true; } @@ -8879,24 +9159,20 @@ static void M_DrawJoystick(void) //M_DrawSaveLoadBorder(OP_JoystickSetDef.x, OP_JoystickSetDef.y+LINEHEIGHT*i); #ifdef JOYSTICK_HOTPLUG - if (atoi(cv_usejoystick[3].string) > I_NumJoys()) - compareval4 = atoi(cv_usejoystick[3].string); - else + compareval4 = atoi(cv_usejoystick[3].string); + if (compareval4 <= numcontrollers) compareval4 = cv_usejoystick[3].value; - if (atoi(cv_usejoystick[2].string) > I_NumJoys()) - compareval3 = atoi(cv_usejoystick[2].string); - else + compareval3 = atoi(cv_usejoystick[2].string); + if (compareval3 <= numcontrollers) compareval3 = cv_usejoystick[2].value; - if (atoi(cv_usejoystick[1].string) > I_NumJoys()) - compareval2 = atoi(cv_usejoystick[1].string); - else + compareval2 = atoi(cv_usejoystick[1].string); + if (compareval2 <= numcontrollers) compareval2 = cv_usejoystick[1].value; - if (atoi(cv_usejoystick[0].string) > I_NumJoys()) - compareval = atoi(cv_usejoystick[0].string); - else + compareval = atoi(cv_usejoystick[0].string); + if (compareval <= numcontrollers) compareval = cv_usejoystick[0].value; #else compareval4 = cv_usejoystick[3].value; @@ -8919,15 +9195,16 @@ void M_SetupJoystickMenu(INT32 choice) { INT32 i = 0; const char *joyNA = "Unavailable"; - INT32 n = I_NumJoys(); (void)choice; strcpy(joystickInfo[i], "None"); for (i = 1; i < 8; i++) { - if (i <= n && (I_GetJoyName(i)) != NULL) - strncpy(joystickInfo[i], I_GetJoyName(i), 28); + const char *joyname = I_GetJoyName(i); + + if (i <= numcontrollers && joyname != NULL) + strncpy(joystickInfo[i], joyname, 28); else strcpy(joystickInfo[i], joyNA); @@ -8986,28 +9263,28 @@ static void M_Setup4PJoystickMenu(INT32 choice) static void M_DoAssignJoystick(UINT8 pnum, INT32 choice) { INT32 oldchoice, oldstringchoice; - const INT32 numjoys = I_NumJoys(); + const int joynum = atoi(cv_usejoystick[pnum].string); - oldchoice = oldstringchoice = atoi(cv_usejoystick[pnum].string) > numjoys ? atoi(cv_usejoystick[pnum].string) : cv_usejoystick[pnum].value; + oldchoice = oldstringchoice = joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value; CV_SetValue(&cv_usejoystick[pnum], choice); // Just in case last-minute changes were made to cv_usejoystick.value, // update the string too // But don't do this if we're intentionally setting higher than numjoys - if (choice <= numjoys) + if (choice <= numcontrollers) { CV_SetValue(&cv_usejoystick[pnum], cv_usejoystick[pnum].value); - if (oldchoice > numjoys) /* reset this so the comparison is valid*/ + if (oldchoice > numcontrollers) /* reset this so the comparison is valid*/ oldchoice = cv_usejoystick[pnum].value; if (oldchoice != choice) { - if (choice && oldstringchoice > numjoys) // if we did not select "None", we likely selected a used device - CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numjoys ? oldstringchoice : oldchoice)); + if (choice && oldstringchoice > numcontrollers) // if we did not select "None", we likely selected a used device + CV_SetValue(&cv_usejoystick[pnum], (oldstringchoice > numcontrollers ? oldstringchoice : oldchoice)); if (oldstringchoice == - (atoi(cv_usejoystick[pnum].string) > numjoys ? atoi(cv_usejoystick[pnum].string) : cv_usejoystick[pnum].value)) + (joynum > numcontrollers ? joynum : cv_usejoystick[pnum].value)) M_StartMessage("This joystick is used by another\n" "player. Reset the joystick\n" "for that player first.\n\n" @@ -9036,7 +9313,6 @@ static void M_AssignJoystick(INT32 choice) break; } #else - switch (setupcontrolplayer) { case 4: @@ -9082,29 +9358,32 @@ static void M_SetupControlsMenu(UINT8 pnum) break; } + OP_AllControlsMenu[4].itemaction = &cv_litesteer[pnum]; + OP_AllControlsMenu[5].itemaction = &cv_turnsmooth[pnum]; + if (pnum > 0) { // Hide P1-only controls - OP_AllControlsMenu[15].status = IT_GRAYEDOUT2; // Chat - OP_AllControlsMenu[16].status = IT_GRAYEDOUT2; // Rankings - OP_AllControlsMenu[17].status = IT_GRAYEDOUT2; // Pause - OP_AllControlsMenu[18].status = IT_GRAYEDOUT2; // Screenshot - OP_AllControlsMenu[19].status = IT_GRAYEDOUT2; // GIF - OP_AllControlsMenu[20].status = IT_GRAYEDOUT2; // System Menu - OP_AllControlsMenu[21].status = IT_GRAYEDOUT2; // Console - OP_AllControlsMenu[37].status = IT_GRAYEDOUT2; // Director + OP_AllControlsMenu[19].status = IT_GRAYEDOUT2; // Chat + OP_AllControlsMenu[10].status = IT_GRAYEDOUT2; // Rankings + OP_AllControlsMenu[21].status = IT_GRAYEDOUT2; // Pause + OP_AllControlsMenu[22].status = IT_GRAYEDOUT2; // Screenshot + OP_AllControlsMenu[23].status = IT_GRAYEDOUT2; // GIF + OP_AllControlsMenu[24].status = IT_GRAYEDOUT2; // System Menu + OP_AllControlsMenu[25].status = IT_GRAYEDOUT2; // Console + OP_AllControlsMenu[41].status = IT_GRAYEDOUT2; // Director } else { // Unhide P1-only controls - OP_AllControlsMenu[15].status = IT_CONTROL; // Chat - OP_AllControlsMenu[16].status = IT_CONTROL; // Rankings - OP_AllControlsMenu[17].status = IT_CONTROL; // Pause - OP_AllControlsMenu[18].status = IT_CONTROL; // Screenshot - OP_AllControlsMenu[19].status = IT_CONTROL; // GIF - OP_AllControlsMenu[20].status = IT_CONTROL; // System Menu - OP_AllControlsMenu[21].status = IT_CONTROL; // Console - OP_AllControlsMenu[37].status = IT_CONTROL; // Director + OP_AllControlsMenu[19].status = IT_CONTROL; // Chat + OP_AllControlsMenu[10].status = IT_CONTROL; // Rankings + OP_AllControlsMenu[21].status = IT_CONTROL; // Pause + OP_AllControlsMenu[22].status = IT_CONTROL; // Screenshot + OP_AllControlsMenu[23].status = IT_CONTROL; // GIF + OP_AllControlsMenu[24].status = IT_CONTROL; // System Menu + OP_AllControlsMenu[25].status = IT_CONTROL; // Console + OP_AllControlsMenu[41].status = IT_CONTROL; // Director } M_SetupNextMenu(&OP_AllControlsDef); @@ -9218,12 +9497,36 @@ static void M_DrawControl(void) else if ((currentMenu->menuitems[i].status == IT_HEADER) && (i != max-1)) V_DrawString(19, y+6, highlightflags|V_ALLOWLOWERCASE, currentMenu->menuitems[i].text); else if (currentMenu->menuitems[i].status & IT_STRING) + { V_DrawString(x, y, ((i == itemOn) ? highlightflags|V_ALLOWLOWERCASE : V_ALLOWLOWERCASE), currentMenu->menuitems[i].text); + if (currentMenu->menuitems[i].status & IT_CVAR) + { + consvar_t *cv = (consvar_t *)currentMenu->menuitems[i].itemaction; + + // IT_HEADER matches IT_CVAR, for some reason... + if (cv) + { + INT32 w = V_StringWidth(cv->string, 0); + V_DrawString(BASEVIDWIDTH - x - w, y, + ((cv->flags & CV_CHEAT) && !CV_IsSetToDefault(cv) ? warningflags : highlightflags)|MENUCAPS, cv->string); + if (i == itemOn) + { + V_DrawCharacter(BASEVIDWIDTH - x - 10 - w - (skullAnimCounter/5), y, + '\x1C' | highlightflags, false); // left arrow + V_DrawCharacter(BASEVIDWIDTH - x + 2 + (skullAnimCounter/5), y, + '\x1D' | highlightflags, false); // right arrow + } + } + } + } + y += SMALLLINEHEIGHT; } V_DrawScaledPatch(currentMenu->x - 20, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); + + M_DoToolTips(currentMenu); } #undef controlheight @@ -9489,6 +9792,13 @@ static void M_DrawHUDOptions(void) V_DrawRightAlignedString(x, y, highlightflags, "("); } +static void M_CameraMenu(INT32 choice) +{ + (void)choice; + OP_CamOptionsDef.prevMenu = currentMenu; + M_SetupNextMenu(&OP_CamOptionsDef); +} + static void M_LocalSkinMenu(INT32 choice) { (void)choice; @@ -10242,6 +10552,7 @@ void M_QuitResponse(INT32 ch) if (ch != 'y' && ch != KEY_ENTER) return; + if (!(netgame || cv_debug)) { mrand = M_RandomKey(sizeof(quitsounds)/sizeof(INT32)); @@ -10258,6 +10569,7 @@ void M_QuitResponse(INT32 ch) I_UpdateTime(cv_timescale.value); } } + I_Quit(); } diff --git a/src/m_menu.h b/src/m_menu.h index 5bc957541..d94df99f6 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -204,6 +204,7 @@ typedef struct menu_s struct menu_s *prevMenu; // previous menu menuitem_t *menuitems; // menu items void (*drawroutine)(void); // draw routine + void (*tickroutine)(void); // ticker routine INT16 x, y; // x, y of menu INT16 lastOn; // last item user was on in menu boolean (*quitroutine)(void); // called before quit a menu return true if we can @@ -305,14 +306,19 @@ void SaturnHud_menu_Onchange(void); void GameFocus_menu_Onchange (void); +void ShowLocalskinMenu_Onchange(void); + #ifdef HWRENDER void M_UpdateOGLMenu(void); #endif void M_ResetDemoList(void); void M_ReplayHut(INT32 choice); +void M_ReturnToTitleFromError(void); void M_SetPlaybackMenuPointer(void); +void Nextmap_OnChange(void); + void M_RefreshPauseMenu(void); INT32 HU_GetHighlightColor(void); @@ -333,6 +339,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na prev,\ source,\ M_DrawGenericMenu,\ + NULL,\ x, y,\ 0,\ NULL,\ @@ -346,6 +353,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na prev,\ source,\ M_DrawGenericScrollMenu,\ + NULL,\ x, y,\ 0,\ NULL,\ @@ -360,6 +368,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na NULL,\ source,\ M_DrawPauseMenu,\ + NULL,\ x, y,\ 0,\ NULL,\ @@ -373,6 +382,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na prev,\ source,\ M_DrawCenteredMenu,\ + NULL,\ BASEVIDWIDTH/2, y,\ 0,\ NULL,\ @@ -386,23 +396,25 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na prev,\ source,\ M_DrawServerMenu,\ + NULL,\ 24,40,\ 0,\ NULL,\ NULL\ } -#define CONTROLMENUSTYLE(source, prev)\ +#define CONTROLMENUSTYLE(source, prev, tooltip)\ {\ "M_CONTRO",\ sizeof (source)/sizeof (menuitem_t),\ prev,\ source,\ M_DrawControl,\ + NULL,\ 26, 40,\ 0,\ NULL,\ - NULL\ + tooltip\ } #define IMAGEDEF(source)\ @@ -412,6 +424,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na NULL,\ source,\ M_DrawImageDef,\ + NULL,\ 0, 0,\ 0,\ NULL,\ diff --git a/src/m_menudefs.c b/src/m_menudefs.c index fc1d7679d..e6129d2d8 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -600,7 +600,7 @@ static menuitem_t OP_MainMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Game Focus Options...", &OP_FocusOptionsDef, 33}, {IT_SUBMENU|IT_STRING, NULL, "HUD Options...", &OP_HUDOptionsDef, 46}, - {IT_SUBMENU|IT_STRING, NULL, "Camera Options...", &OP_CamOptionsDef, 56}, + {IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 56}, {IT_SUBMENU|IT_STRING, NULL, "Gameplay Options...", &OP_GameOptionsDef, 66}, {IT_SUBMENU|IT_STRING, NULL, "Server Options...", &OP_ServerOptionsDef, 76}, @@ -610,7 +610,7 @@ static menuitem_t OP_MainMenu[] = {IT_CALL|IT_STRING, NULL, "Tricks & Secrets (F1)", M_Manual, 109}, {IT_CALL|IT_STRING, NULL, "Play Credits", M_Credits, 119}, - {IT_SUBMENU|IT_STRING, NULL, "Accessibility Options...",&OP_AccessibilityDef, 132}, + {IT_SUBMENU|IT_STRING, NULL, "Accessibility Options...", &OP_AccessibilityDef, 132}, {IT_SUBMENU|IT_STRING, NULL, "Saturn Options...", &OP_SaturnDef, 142}, {IT_SUBMENU|IT_STRING, NULL, "Bird...", &OP_BirdDef, 152}, @@ -648,17 +648,6 @@ static menuitem_t OP_ControlsMenu[] = {IT_SUBMENU | IT_STRING, NULL, "Mouse Options...", &OP_MouseOptionsDef, 55}, {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 75}, - - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P1)", &cv_turnsmooth[0], 85}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P2)", &cv_turnsmooth[1], 95}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P3)", &cv_turnsmooth[2], 105}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing (P4)", &cv_turnsmooth[3], 115}, - - // i hate our menus sincerly - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P1)", &cv_litesteer[0], 135}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P2)", &cv_litesteer[1], 145}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P3)", &cv_litesteer[2], 155}, - {IT_STRING | IT_CVAR, NULL, "Lite Steer (P4)", &cv_litesteer[3], 165}, }; static const char* OP_ControlsTooltips[] = @@ -669,15 +658,6 @@ static const char* OP_ControlsTooltips[] = "Setup player 4 controls.", "Options for mouse control.", "Allowed amount of controls per key.", - "Turn smoothing for non-analog turning (Player 1).", - "Turn smoothing for non-analog turning (Player 2).", - "Turn smoothing for non-analog turning (Player 3).", - "Turn smoothing for non-analog turning (Player 4).", - - "Hold DOWN on d-pad/keyboard for shallow turns (Player 1).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 2).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 3).", - "Hold DOWN on d-pad/keyboard for shallow turns (Player 4).", }; static menuitem_t OP_AllControlsMenu[] = @@ -685,6 +665,13 @@ static menuitem_t OP_AllControlsMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Gamepad Options...", &OP_Joystick1Def, 0}, {IT_CALL|IT_STRING, NULL, "Reset to defaults", M_ResetControls, 8}, + {IT_HEADER, NULL, "Control Options", NULL, 0}, + {IT_SPACE, NULL, NULL, NULL, 0}, + + // Cvars are set in M_SetupControlsMenu + {IT_STRING|IT_CVAR, NULL, "Lite Steer", &cv_litesteer[0], 18}, + {IT_STRING|IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth[0], 26}, + //{IT_SPACE, NULL, NULL, NULL, 0}, {IT_HEADER, NULL, "Gameplay Controls", NULL, 0}, {IT_SPACE, NULL, NULL, NULL, 0}, @@ -733,28 +720,40 @@ static menuitem_t OP_AllControlsMenu[] = {IT_CONTROL, NULL, "Custom Action 3", M_ChangeControl, gc_custom3 }, }; +// Has to be same length as OP_AllControlsMenu, but otherwise its mostly empty +static const char* OP_AllControlsTooltips[sizeof(OP_AllControlsMenu)/sizeof(OP_AllControlsMenu[0])] = { + NULL, + NULL, + NULL, + NULL, + "Hold DOWN on d-pad/keyboard for shallow turns.", + "Turn smoothing for non-analog turning.", + // The rest is null, for now +}; + #define OP_JOYMENU(pnum) \ {IT_HEADER, NULL, "Gameplay Controls", NULL, 7}, \ - {IT_STRING | IT_CVAR, NULL, "Aim Forward/Back" , &cv_aimaxis[pnum] , 15}, \ - {IT_STRING | IT_CVAR, NULL, "Turn Left/Right" , &cv_turnaxis[pnum] , 20}, \ - {IT_STRING | IT_CVAR, NULL, "Accelerate" , &cv_moveaxis[pnum] , 25}, \ - {IT_STRING | IT_CVAR, NULL, "Brake" , &cv_brakeaxis[pnum] , 30}, \ - {IT_STRING | IT_CVAR, NULL, "Drift" , &cv_driftaxis[pnum] , 35}, \ - {IT_STRING | IT_CVAR, NULL, "Use Item" , &cv_fireaxis[pnum] , 40}, \ - {IT_STRING | IT_CVAR, NULL, "Look Backward" , &cv_lookbackaxis[pnum] , 45}, \ - {IT_STRING | IT_CVAR, NULL, "Custom Button 1" , &cv_custom1axis[pnum] , 50}, \ - {IT_STRING | IT_CVAR, NULL, "Custom Button 2" , &cv_custom2axis[pnum] , 55}, \ - {IT_STRING | IT_CVAR, NULL, "Custom Button 3" , &cv_custom3axis[pnum] , 60}, \ + {IT_STRING | IT_CVAR, NULL, "Aim Forward/Back" , &cv_aimaxis[pnum] , 15}, \ + {IT_STRING | IT_CVAR, NULL, "Turn Left/Right" , &cv_turnaxis[pnum] , 20}, \ + {IT_STRING | IT_CVAR, NULL, "Accelerate" , &cv_moveaxis[pnum] , 25}, \ + {IT_STRING | IT_CVAR, NULL, "Brake" , &cv_brakeaxis[pnum] , 30}, \ + {IT_STRING | IT_CVAR, NULL, "Drift" , &cv_driftaxis[pnum] , 35}, \ + {IT_STRING | IT_CVAR, NULL, "Use Item" , &cv_fireaxis[pnum] , 40}, \ + {IT_STRING | IT_CVAR, NULL, "Look Backward" , &cv_lookbackaxis[pnum] , 45}, \ + {IT_STRING | IT_CVAR, NULL, "Custom Button 1" , &cv_custom1axis[pnum] , 50}, \ + {IT_STRING | IT_CVAR, NULL, "Custom Button 2" , &cv_custom2axis[pnum] , 55}, \ + {IT_STRING | IT_CVAR, NULL, "Custom Button 3" , &cv_custom3axis[pnum] , 60}, \ {IT_HEADER, NULL, "Camera Controls", NULL, 67}, \ - {IT_STRING | IT_CVAR, NULL, "Look Up/Down" , &cv_lookaxis[pnum] , 75}, \ - {IT_STRING | IT_CVAR, NULL, "Turn Left/Right" , &cv_camturnaxis[pnum] , 80}, \ - {IT_STRING | IT_CVAR, NULL, "Strafe Left/Right" , &cv_camstrafeaxis[pnum] , 85}, \ + {IT_STRING | IT_CVAR, NULL, "Look Up/Down" , &cv_lookaxis[pnum] , 75}, \ + {IT_STRING | IT_CVAR, NULL, "Turn Left/Right" , &cv_camturnaxis[pnum] , 80}, \ + {IT_STRING | IT_CVAR, NULL, "Strafe Left/Right" , &cv_camstrafeaxis[pnum] , 85}, \ {IT_HEADER, NULL, "Deadzones", NULL, 92}, \ - {IT_STRING | IT_CVAR, NULL, "X deadzone" , &cv_xdeadzone[pnum] , 100}, \ - {IT_STRING | IT_CVAR, NULL, "Y deadzone" , &cv_ydeadzone[pnum] , 105}, \ + {IT_STRING | IT_CVAR, NULL, "X deadzone" , &cv_xdeadzone[pnum] , 100}, \ + {IT_STRING | IT_CVAR, NULL, "Y deadzone" , &cv_ydeadzone[pnum] , 105}, \ {IT_HEADER, NULL, "Miscellaneous", NULL, 112}, \ - {IT_STRING | IT_CVAR, NULL, "Controller Rumble" , &cv_rumble[pnum] , 120}, \ - {IT_STRING | IT_CVAR, NULL, "Set LED to Player color", &cv_gamepadled[pnum] , 125}, + {IT_STRING | IT_CVAR, NULL, "Controller Rumble" , &cv_rumble[pnum] , 120}, \ + {IT_STRING | IT_CVAR, NULL, "Controller Rumble Strength" , &cv_rumblestrength[pnum] , 125}, \ + {IT_STRING | IT_CVAR, NULL, "Set LED to Player color" , &cv_gamepadled[pnum] , 130}, static menuitem_t OP_Joystick1Menu[] = { @@ -799,7 +798,7 @@ static menuitem_t OP_MouseOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Mouse Turning", &cv_mouseturn, 20}, {IT_STRING | IT_CVAR, NULL, "Invert Mouse", &cv_invertmouse, 30}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Mouse X Speed", &cv_mousesens, 40}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Mouse X Speed", &cv_mousexsens, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Mouse Y Speed", &cv_mouseysens, 50}, }; @@ -1324,13 +1323,14 @@ static menuitem_t OP_HUDOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Menu Highlights", &cons_menuhighlight, 95}, // highlight info - (GOOD HIGHLIGHT, WARNING HIGHLIGHT) - 110 (see M_DrawHUDOptions) - {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, + {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, + {IT_STRING | IT_CVAR, NULL, "Show Console Prints in Menu",&cons_consoleprintinmenu, 130}, - {IT_STRING | IT_CVAR, NULL, "Show Track Addon Name", &cv_showtrackaddon, 135}, + {IT_STRING | IT_CVAR, NULL, "Show Track Addon Name", &cv_showtrackaddon, 145}, - {IT_STRING | IT_CVAR, NULL, "Show All Maps", &cv_showallmaps, 145}, + {IT_STRING | IT_CVAR, NULL, "Show All Maps", &cv_showallmaps, 155}, - {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 155}, + {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 165}, }; static menuitem_t OP_CamOptionsMenu[] = @@ -1339,16 +1339,19 @@ static menuitem_t OP_CamOptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_BIGFLOAT, NULL, "Field of View",&cv_fov, 30}, - {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 50}, - {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 60}, - {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 70}, - {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 80}, + {IT_STRING | IT_CVAR, NULL, "Flipcam Mode", &cv_flipcammode, 40}, + + {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 60}, + {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 70}, + {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 80}, + {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 90}, }; static const char* OP_CamOptionsTooltips[] = { NULL, "Player field of view.", + "Change flipcam mode.\nDisplayplayer - use currently viewed player option.\nLocal - use local flipcam toggle option.", NULL, NULL, NULL, @@ -1644,12 +1647,19 @@ static menuitem_t OP_AccessibilityMenu[] = {IT_STRING|IT_CVAR, NULL, "Quake Screenshakes", &cv_screenquake, 60}, - {IT_SUBMENU|IT_STRING, NULL, "Camera Options...", &OP_CamOptionsDef, 65}, + {IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 65}, {IT_HEADER, NULL, "Audio", NULL, 75}, {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 85}, {IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 90}, + + {IT_HEADER, NULL, "Controls", NULL, 100}, + + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 110}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 115}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 120}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 125}, }; static const char* OP_AccessibilityTooltips[] = @@ -1671,6 +1681,11 @@ static const char* OP_AccessibilityTooltips[] = NULL, "Reverse left and right channels of audio.", "Change how often the same Sound is allowed to play at once.", + NULL, + "Automatically hold acceleration button (Player 1).", + "Automatically hold acceleration button (Player 2).", + "Automatically hold acceleration button (Player 3).", + "Automatically hold acceleration button (Player 4).", }; static menuitem_t OP_SaturnMenu[] = @@ -1847,15 +1862,16 @@ static menuitem_t OP_SaturnHudMenu[] = {IT_STRING|IT_CVAR, NULL, "Player Angle Visual", &cv_showminimapangle, 150}, {IT_STRING|IT_CVAR, NULL, "Music Credits", &cv_songcredits, 160}, + {IT_STRING|IT_CVAR, NULL, "Music Credits on Pause", &cv_pausesongcredits, 165}, - {IT_STRING|IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 170}, + {IT_STRING|IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 175}, - {IT_STRING|IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 180}, + {IT_STRING|IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 185}, - {IT_STRING|IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 190}, - {IT_STRING|IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 195}, + {IT_STRING|IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 195}, + {IT_STRING|IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 200}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 205}, + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 210}, }; static const char* OP_SaturnHudTooltips[] = @@ -1873,7 +1889,7 @@ static const char* OP_SaturnHudTooltips[] = "Disable the animation of the Positionnumber\nwhen overtaking someone.", "Flash current Lap Time when doing a Lap on the Timer.", "Use extra graphics for multiple sneakers, bananas and jawz.", - "Change when the item amount is to be displayed\nMultiple will always display the number.\nwhen you have multiple of the same Item.\nAlways will always display the number regardless of Item amount.", + "Change when the item amount is to be displayed.\nMultiple will always display the number.\nWhen you have multiple of the same Item.\nAlways will always display the number regardless of Item amount.", "Enables an animation while the roulette is active.", "Show the big 'LAP' text on a lap change.", "Show the big Cecho Messages.", @@ -1882,6 +1898,7 @@ static const char* OP_SaturnHudTooltips[] = "Erratically rotate player icons during spinouts.", "Visualize the player facing angle.", "Show the Music Credits and which style.", + "Show the Music Credits while in pause menu.", "Make the Intermission screen look like in beta versions of Kart!\nEither with background or just the rest.", "Show the Director Toggle prompt when spectating.", "Nametag Options.", @@ -1969,47 +1986,46 @@ static menuitem_t OP_HudOffsetMenu[] = // absolutely crazy how many people put work into this at this point <3 static menuitem_t OP_SaturnCreditsMenu[] = { + // in no particular order besides me and indev <3 {IT_HEADER, NULL, "Thanks to all contributers <3", NULL, 0}, - {IT_STRING2+IT_SPACE, NULL, "Alug", NULL, 10}, - {IT_STRING2+IT_SPACE, NULL, "Indev", NULL, 20}, - {IT_STRING2+IT_SPACE, NULL, "Haya", NULL, 30}, - {IT_STRING2+IT_SPACE, NULL, "Nepdisk", NULL, 40}, - {IT_STRING2+IT_SPACE, NULL, "GenericHeroGuy", NULL, 50}, - {IT_STRING2+IT_SPACE, NULL, "xyzzy", NULL, 60}, - {IT_STRING2+IT_SPACE, NULL, "Chearii", NULL, 70}, - {IT_STRING2+IT_SPACE, NULL, "riomccloud", NULL, 80}, - {IT_STRING2+IT_SPACE, NULL, "chromaticpipe", NULL, 90}, - {IT_STRING2+IT_SPACE, NULL, "PAS", NULL, 100}, - {IT_STRING2+IT_SPACE, NULL, "$HOME", NULL, 110}, - {IT_STRING2+IT_SPACE, NULL, "Achii", NULL, 120}, - {IT_STRING2+IT_SPACE, NULL, "Anonimus", NULL, 130}, - {IT_STRING2+IT_SPACE, NULL, "scizor300", NULL, 140}, - {IT_STRING2+IT_SPACE, NULL, "Lugent", NULL, 150}, + {IT_STRING2+IT_SPACE, NULL, "Alug Indev", NULL, 10}, + {IT_STRING2+IT_SPACE, NULL, "Haya Nepdisk", NULL, 20}, + {IT_STRING2+IT_SPACE, NULL, "GenericHeroGuy xyzzy", NULL, 30}, + {IT_STRING2+IT_SPACE, NULL, "Chearii riomccloud", NULL, 40}, + {IT_STRING2+IT_SPACE, NULL, "chromaticpipe PAS", NULL, 50}, + {IT_STRING2+IT_SPACE, NULL, "$HOME yama", NULL, 60}, + {IT_STRING2+IT_SPACE, NULL, "Achii scizor300", NULL, 70}, + {IT_STRING2+IT_SPACE, NULL, "Superjustinbros Lugent", NULL, 80}, - {IT_HEADER, NULL, "", NULL, 124}, + {IT_HEADER, NULL, "", NULL, 74}, - {IT_STRING2+IT_SPACE, NULL, "Sunflower Yuz", NULL, 180}, - {IT_STRING2+IT_SPACE, NULL, "Democrab EXpand", NULL, 190}, - {IT_STRING2+IT_SPACE, NULL, "Nexit Spee", NULL, 200}, - {IT_STRING2+IT_SPACE, NULL, "jin", NULL, 210}, + {IT_STRING2+IT_SPACE, NULL, "Sunflower Yuz", NULL, 110}, + {IT_STRING2+IT_SPACE, NULL, "Democrab EXpand", NULL, 120}, + {IT_STRING2+IT_SPACE, NULL, "Nexit Spee", NULL, 130}, + {IT_STRING2+IT_SPACE, NULL, "jin Mompi", NULL, 140}, + {IT_STRING2+IT_SPACE, NULL, "Phoenix", NULL, 150}, - {IT_HEADER, NULL, "Special Thanks <3", NULL, 168}, + {IT_HEADER, NULL, "Special Thanks <3", NULL, 130}, - {IT_STRING2+IT_SPACE, NULL, "All of Sunflower's Garden", NULL, 178}, - {IT_STRING2+IT_SPACE, NULL, "The Moe Mansion and Birdhouse Team", NULL, 188}, - {IT_STRING2+IT_SPACE, NULL, "Galactice for Galaxy", NULL, 198}, + {IT_STRING2+IT_SPACE, NULL, "All of Sunflower's Garden", NULL, 140}, + {IT_STRING2+IT_SPACE, NULL, "Blankart", NULL, 150}, + {IT_STRING2+IT_SPACE, NULL, "SRB2 Legacy", NULL, 160}, + {IT_STRING2+IT_SPACE, NULL, "SRB2 Classic", NULL, 170}, + {IT_STRING2+IT_SPACE, NULL, "The Moe Mansion and Birdhouse Team", NULL, 180}, + {IT_STRING2+IT_SPACE, NULL, "Galactice for Galaxy", NULL, 190}, - {IT_STRING+IT_SPACE, NULL, "", NULL, 198}, // dummy text I - {IT_STRING, NULL, "", NULL, 258}, // dummy text II + {IT_STRING+IT_SPACE, NULL, "", NULL, 228}, // dummy text I + {IT_STRING, NULL, "", NULL, 278}, // dummy text II }; -// sry we dont have space for this anymore :c -/*static const char* OP_CreditTooltips[] = +// sry we dont have space for this anymore :c < now we have again, for now..... TODO: finally stop being a lazy ass and make a cool credits screen +static const char* OP_CreditTooltips[] = { - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + // this sucks lol note to self: we need as many NULLs as we have entries in OP_SaturnCreditsMenu - 1 + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, "Thanks everyone! <3" -};*/ +}; static menuitem_t OP_BirdMenu[] = @@ -2222,6 +2238,7 @@ menu_t MISC_AddonsDef = &OP_DataOptionsDef, MISC_AddonsMenu, M_DrawAddons, + M_AddonsRefresh, 50, 28, 0, NULL, @@ -2235,6 +2252,7 @@ menu_t MISC_ReplayHutDef = NULL, MISC_ReplayHutMenu, M_DrawReplayHut, + NULL, 30, 80, 0, M_QuitReplayHut, @@ -2248,6 +2266,7 @@ menu_t MISC_ReplayOptionsDef = &OP_DataOptionsDef, MISC_ReplayOptionsMenu, M_DrawGenericMenu, + NULL, 27, 40, 0, NULL, @@ -2261,6 +2280,7 @@ menu_t MISC_ReplayStartDef = &MISC_ReplayHutDef, MISC_ReplayStartMenu, M_DrawReplayStartMenu, + NULL, 30, 90, 0, NULL, @@ -2273,6 +2293,7 @@ menu_t PlaybackMenuDef = { NULL, PlaybackMenu, M_DrawPlaybackMenu, + NULL, //BASEVIDWIDTH/2 - 94, 2, BASEVIDWIDTH/2 - 88, 2, 0, @@ -2291,6 +2312,7 @@ menu_t MISC_DiscordRequestsDef = { &MPauseDef, MISC_DiscordRequestsMenu, M_DrawDiscordRequests, + NULL, 0, 0, 0, NULL, @@ -2315,6 +2337,7 @@ menu_t SR_UnlockChecklistDef = &SR_MainDef, SR_UnlockChecklistMenu, M_DrawChecklist, + NULL, 280, 185, 0, NULL, @@ -2328,6 +2351,7 @@ menu_t SR_MusicTestDef = &OP_SoundOptionsDef, SR_MusicTestMenu, M_DrawMusicTest, + NULL, 60, 150, 0, NULL, @@ -2344,6 +2368,7 @@ menu_t SP_LevelStatsDef = &SR_MainDef, SP_LevelStatsMenu, M_DrawLevelStats, + NULL, 280, 185, 0, NULL, @@ -2357,6 +2382,7 @@ static menu_t SP_TimeAttackDef = &MainDef, // Doesn't matter. SP_TimeAttackMenu, M_DrawTimeAttackMenu, + NULL, 34, 40, 0, M_QuitTimeAttackMenu, @@ -2369,6 +2395,7 @@ static menu_t SP_ReplayDef = &SP_TimeAttackDef, SP_ReplayMenu, M_DrawTimeAttackMenu, + NULL, 34, 40, 0, NULL, @@ -2381,6 +2408,7 @@ static menu_t SP_GuestReplayDef = &SP_TimeAttackDef, SP_GuestReplayMenu, M_DrawTimeAttackMenu, + NULL, 34, 40, 0, NULL, @@ -2393,6 +2421,7 @@ static menu_t SP_GhostDef = &SP_TimeAttackDef, SP_GhostMenu, M_DrawTimeAttackMenu, + NULL, 34, 40, 0, NULL, @@ -2407,6 +2436,7 @@ menu_t MP_MainDef = &MainDef, MP_MainMenu, M_DrawMPMainMenu, + NULL, 42, 30, 0, M_CancelConnect, @@ -2424,6 +2454,7 @@ menu_t MP_ConnectDef = &MP_MainDef, MP_ConnectMenu, M_DrawConnectMenu, + NULL, 27,24, 0, M_CancelConnect, @@ -2437,6 +2468,7 @@ menu_t MP_PlayerSetupDef = &MP_MainDef, MP_PlayerSetupMenu, M_DrawSetupMultiPlayerMenu, + NULL, 36, 14, 0, M_QuitMultiPlayerMenu, @@ -2451,6 +2483,7 @@ menu_t OP_MainDef = &MainDef, OP_MainMenu, M_DrawGenericMenu, + NULL, 60, 25, 0, NULL, @@ -2460,7 +2493,7 @@ menu_t OP_MainDef = menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 40, 15, OP_ControlsTooltips); //WTF menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30, OP_MouseTooltips); -menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); +menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef, OP_AllControlsTooltips); menu_t OP_Joystick1Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 30, 36, NULL); menu_t OP_Joystick2Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 30, 36, NULL); menu_t OP_Joystick3Def = DEFAULTSCROLLSTYLE("M_CONTRO", OP_Joystick3Menu, &OP_AllControlsDef, 30, 36, NULL); @@ -2473,6 +2506,7 @@ menu_t OP_JoystickSetDef = &OP_Joystick1Def, OP_JoystickSetMenu, M_DrawJoystick, + NULL, 50, 40, 0, NULL, @@ -2486,6 +2520,7 @@ menu_t OP_VideoOptionsDef = &OP_MainDef, OP_VideoOptionsMenu, M_DrawVideoMenu, + NULL, 30, 15, 0, NULL, @@ -2499,6 +2534,7 @@ menu_t OP_VideoModeDef = &OP_VideoOptionsDef, OP_VideoModeMenu, M_DrawVideoMode, + NULL, 48, 26, 0, NULL, @@ -2512,6 +2548,7 @@ menu_t OP_ColorOptionsDef = &OP_VideoOptionsDef, OP_ColorOptionsMenu, M_DrawColorMenu, + NULL, 30, 30, 0, NULL, @@ -2525,6 +2562,7 @@ menu_t OP_SoundOptionsDef = &OP_MainDef, OP_SoundOptionsMenu, M_DrawSkyRoom, + NULL, 30, 20, 0, NULL, @@ -2539,6 +2577,7 @@ menu_t OP_HUDOptionsDef = &OP_MainDef, OP_HUDOptionsMenu, M_DrawHUDOptions, + NULL, 30, 20, 0, NULL, @@ -2568,6 +2607,7 @@ menu_t OP_MonitorToggleDef = &OP_GameOptionsDef, OP_MonitorToggleMenu, M_DrawMonitorToggles, + NULL, 47, 30, 0, NULL, @@ -2592,7 +2632,7 @@ menu_t OP_EraseDataDef = DEFAULTMENUSTYLE("M_DATA", OP_EraseDataMenu, &O menu_t OP_AccessibilityDef = DEFAULTSCROLLSTYLE(NULL, OP_AccessibilityMenu, &OP_MainDef, 30, 30, OP_AccessibilityTooltips); menu_t OP_SaturnDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 30, OP_SaturnTooltips); -menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 0, NULL); // OP_CreditTooltips no space :c +menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 2, OP_CreditTooltips); // OP_CreditTooltips no space :c menu_t OP_SaturnHudDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnHudMenu, &OP_SaturnDef, 30, 30, OP_SaturnHudTooltips); menu_t OP_PlayerDistortDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 30, OP_PlayerDistortTooltips); @@ -2615,6 +2655,7 @@ menu_t OP_ForkedBirdDef = { &OP_MainDef, OP_ForkedBirdMenu, M_DrawLocalSkinMenu, + NULL, 30, 6, 0, NULL, @@ -2623,191 +2664,7 @@ menu_t OP_ForkedBirdDef = { menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60, NULL); - -// ========================================================================== -// CVAR ONCHANGE EVENTS GO HERE -// ========================================================================== -// (there's only a couple anyway) - -// Nextmap. Used for Time Attack. -static void Nextmap_OnChange(void) -{ - char *leveltitle; - UINT8 active; - - // Update the string in the consvar. - Z_Free(cv_nextmap.zstring); - leveltitle = G_BuildMapTitle(cv_nextmap.value); - cv_nextmap.string = cv_nextmap.zstring = leveltitle ? leveltitle : Z_StrDup(G_BuildMapName(cv_nextmap.value)); - - if (currentMenu == &SP_TimeAttackDef) - { - // see also p_setup.c's P_LoadRecordGhosts - const size_t glen = strlen(srb2home)+1+strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; - char *gpath = malloc(glen); - INT32 i; - - if (!gpath) - return; - - sprintf(gpath,"%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value)); - - CV_StealthSetValue(&cv_dummystaff, 0); - - active = false; - SP_TimeAttackMenu[taguest].status = IT_DISABLED; - SP_TimeAttackMenu[tareplay].status = IT_DISABLED; - - // Check if file exists, if not, disable REPLAY option - for (i = 0; i < 4; i++) - { - SP_ReplayMenu[i].status = IT_DISABLED; - SP_GuestReplayMenu[i].status = IT_DISABLED; - } - SP_ReplayMenu[4].status = IT_DISABLED; - - SP_GhostMenu[3].status = IT_DISABLED; - SP_GhostMenu[4].status = IT_DISABLED; - - if (FIL_FileExists(va("%s-%s-time-best.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[0].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[0].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - if (FIL_FileExists(va("%s-%s-lap-best.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[1].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[1].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - if (FIL_FileExists(va("%s-%s-last.lmp", gpath, cv_chooseskin.string))) { - SP_ReplayMenu[2].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[2].status = IT_WHITESTRING|IT_CALL; - active |= 3; - } - - if (FIL_FileExists(va("%s-guest.lmp", gpath))) - { - SP_ReplayMenu[3].status = IT_WHITESTRING|IT_CALL; - SP_GuestReplayMenu[3].status = IT_WHITESTRING|IT_CALL; - SP_GhostMenu[3].status = IT_STRING|IT_CVAR; - active |= 3; - } - - CV_SetValue(&cv_dummystaff, 1); - if (cv_dummystaff.value) - { - SP_ReplayMenu[4].status = IT_WHITESTRING|IT_KEYHANDLER; - SP_GhostMenu[4].status = IT_STRING|IT_CVAR; - CV_StealthSetValue(&cv_dummystaff, 1); - active |= 1; - } - - if (active) { - if (active & 1) - SP_TimeAttackMenu[tareplay].status = IT_WHITESTRING|IT_SUBMENU; - if (active & 2) - SP_TimeAttackMenu[taguest].status = IT_WHITESTRING|IT_SUBMENU; - } - else if (itemOn == tareplay) // Reset lastOn so replay isn't still selected when not available. - { - currentMenu->lastOn = itemOn; - itemOn = tastart; - } - - if (mapheaderinfo[cv_nextmap.value-1] && mapheaderinfo[cv_nextmap.value-1]->forcecharacter[0] != '\0') - CV_Set(&cv_chooseskin, mapheaderinfo[cv_nextmap.value-1]->forcecharacter); - - free(gpath); - } -} - -static void Dummymenuplayer_OnChange(void) -{ - if (cv_dummymenuplayer.value < 1) - CV_StealthSetValue(&cv_dummymenuplayer, splitscreen+1); - else if (cv_dummymenuplayer.value > splitscreen+1) - CV_StealthSetValue(&cv_dummymenuplayer, 1); -} - -char dummystaffname[22]; - -static void Dummystaff_OnChange(void) -{ - lumpnum_t l; - - dummystaffname[0] = '\0'; - - if ((l = W_CheckNumForName(va("%sS01",G_BuildMapName(cv_nextmap.value)))) == LUMPERROR) - { - CV_StealthSetValue(&cv_dummystaff, 0); - return; - } - else - { - char *temp = dummystaffname; - UINT8 numstaff = 1; - while (numstaff < 99 && (l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value),numstaff+1))) != LUMPERROR) - numstaff++; - - if (cv_dummystaff.value < 1) - CV_StealthSetValue(&cv_dummystaff, numstaff); - else if (cv_dummystaff.value > numstaff) - CV_StealthSetValue(&cv_dummystaff, 1); - - if ((l = W_CheckNumForName(va("%sS%02u",G_BuildMapName(cv_nextmap.value), cv_dummystaff.value))) == LUMPERROR) - return; // shouldn't happen but might as well check... - - G_UpdateStaffGhostName(l); - - while (*temp) - temp++; - - sprintf(temp, " - %d", cv_dummystaff.value); - } -} - -// Newgametype. Used for gametype changes. -static void Newgametype_OnChange(void) -{ - if (cv_nextmap.value && menuactive) - { - if (!mapheaderinfo[cv_nextmap.value-1]) - P_AllocMapHeader((INT16)(cv_nextmap.value-1)); - - if ((cv_newgametype.value == GT_RACE && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_RACE)) || // SRB2kart - ((cv_newgametype.value == GT_MATCH || cv_newgametype.value == GT_TEAMMATCH) && !(mapheaderinfo[cv_nextmap.value-1]->typeoflevel & TOL_MATCH))) - { - INT32 value = 0; - - switch (cv_newgametype.value) - { - case GT_COOP: - value = TOL_RACE; // SRB2kart - break; - case GT_COMPETITION: - value = TOL_COMPETITION; - break; - case GT_RACE: - value = TOL_RACE; - break; - case GT_MATCH: - case GT_TEAMMATCH: - value = TOL_MATCH; - break; - case GT_TAG: - case GT_HIDEANDSEEK: - value = TOL_TAG; - break; - case GT_CTF: - value = TOL_CTF; - break; - } - - CV_SetValue(&cv_nextmap, M_FindFirstMap(value)); - } - } -} - +// Onchange functions to show/hide/move things in menus void Screenshot_option_Onchange(void) { OP_ScreenshotOptionsMenu[op_screenshot_folder].status = @@ -2884,7 +2741,7 @@ void Bird_menu_Onchange(void) OP_AdvancedBirdMenu[respawnfadein].status = status; } -//menu code is nice +// menu code is nice void SaturnHud_menu_Onchange(void) { UINT16 status; diff --git a/src/m_misc.c b/src/m_misc.c index 655a28a24..8c7b34163 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1346,14 +1346,15 @@ void M_MinimapGenerate(void) minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) - goto failure; + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create %s\n"), filepath); + return; + } M_CreateScreenShotPalette(); ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); -failure: - if (minigen->buf != NULL) - free(minigen->buf); + free(minigen->buf); if (ret) { @@ -1693,22 +1694,23 @@ char *M_GetToken(const char *inputString) } -const char * M_Ftrim (double f) +const char * M_Ftrim(double f) { static char dig[9];/* "0." + 6 digits (6 is printf's default) */ int i; + /* I know I said it's the default, but just in case... */ sprintf(dig, "%.6f", fabs(modf(f, &f))); + /* trim trailing zeroes */ for (i = strlen(dig)-1; dig[i] == '0'; --i) ; + if (dig[i] == '.')/* :NOTHING: */ return ""; - else - { - dig[i + 1] = '\0'; - return &dig[1];/* skip the 0 */ - } + + dig[i + 1] = '\0'; + return &dig[1];/* skip the 0 */ } /** Count bits in a number. diff --git a/src/m_textinput.c b/src/m_textinput.c index 049222701..7d050dfc7 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -411,21 +411,13 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) return M_TextInputHandleBase(input, key, false); } -boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_t *suggestions[], int maxsuggestions) +static int M_TextInputEmoteStart(textinput_t *input) { - boolean ret = M_TextInputHandleBase(input, key, true); + if (input->cursor == 0) + return -1; - // After this handled key we ended up inside an emote, lets fix that - if (M_TextInputCheckEmote(input)) - M_TextInputToWordEnd(input, !shiftdown); + int emotestart = -1; - // Always clear the first entry - suggestions[0] = NULL; - - // For autocomplete - int emotestart = 0; - - // Try find suggestions for emote names for (int i = input->cursor-1; i >= 0 && input->cursor-i <= MAXEMOTENAME; --i) { // Space can't be part of emote name @@ -436,62 +428,93 @@ boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_t *suggesti if (input->buffer[i] == ':') { emotestart = i+1; - // ...But only if we typed at least something - if ((int)input->cursor-(i-1) < 3) - break; - - for (int skip = 0; skip < maxsuggestions; ++skip) - { - suggestions[skip] = M_FindEmote(input->buffer+i+1, input->cursor-i-1, skip); - - // No more suggestions - if (!suggestions[skip]) - break; - } - - // In any case, we found what we wanted, can exit the loop now break; } } - // If we suggest emotes, try autocomplete - if (key == '\t' && suggestions[0]) + return emotestart; +} + +static boolean M_TextInputCompleteEmote(textinput_t *input, emote_autocomplete_t *autocomplete) +{ + if (input->cursor == 0) + return false; + + // If we're in "autocomplete" state, delete ':' for latest autocompleted emote + if (autocomplete->complete[0]) { - int pos = (input->cursor-emotestart); - boolean autocomplete = true; - - while (autocomplete) + if (input->buffer[input->cursor-1] == ':') { - // Check if current character matches for all suggestions - char c = suggestions[0]->name[pos]; - - // End of string reached - if (!c) - break; - - for (int i = 1; i < maxsuggestions && suggestions[i]; ++i) - { - if (suggestions[i]->name[pos] != c) - { - autocomplete = false; - break; - } - } - - ++pos; - - if (autocomplete) - M_TextInputAddChar(input, c); + M_TextInputDelChar(input); } - // This was the only suggestion, finish autocomplete with a ':' and clear suggestions - if (maxsuggestions == 1 || !suggestions[1]) + autocomplete->skip++; + } + else + { + // Try to find emote to autocomplete + + int emotestart = autocomplete->emotestart; + + // No emote - no autocomplete + if (emotestart == -1 || input->cursor - emotestart < 2) + return false; + + strlcpy(autocomplete->complete, &input->buffer[emotestart], input->cursor-emotestart+1); + } + + emote_t *completed = M_FindEmote(autocomplete->complete, strlen(autocomplete->complete), autocomplete->skip); + + // We hit end of list of suggested emotes + if (completed == NULL) + { + autocomplete->skip = 0; + completed = M_FindEmote(autocomplete->complete, strlen(autocomplete->complete), autocomplete->skip); + + // NULL again, list was empty to begin with + if (completed == NULL) { - M_TextInputAddChar(input, ':'); - suggestions[0] = NULL; + // Clear autocompletion state + autocomplete->complete[0] = 0; + return false; } } + // Erase previously typed emote. Not really efficent but too lazy to count chars and do M_TextInputDel() + while (input->buffer[input->cursor-1] != ':') + { + M_TextInputDelChar(input); + } + + M_TextInputAddString(input, completed->name); + M_TextInputAddChar(input, ':'); + + return true; +} + +boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_autocomplete_t *autocomplete) +{ + boolean ret = M_TextInputHandleBase(input, key, true); + + // After this handled key we ended up inside an emote, lets fix that + if (M_TextInputCheckEmote(input)) + M_TextInputToWordEnd(input, !shiftdown); + + // Always update it + autocomplete->emotestart = M_TextInputEmoteStart(input); + + if (key == '\t' || (autocomplete->complete[0] == 0 && key == KEY_ENTER)) + { + if (M_TextInputCompleteEmote(input, autocomplete) && key == KEY_ENTER) // Don't send message if we've autocompleted an emote + ret = true; + } + else + { + // Reset state just in case + autocomplete->complete[0] = 0; + autocomplete->skip = 0; + } + return ret; } diff --git a/src/m_textinput.h b/src/m_textinput.h index 512a47b7c..ce296ffde 100644 --- a/src/m_textinput.h +++ b/src/m_textinput.h @@ -26,6 +26,12 @@ typedef struct textinput_s { unsigned skull; } textinput_t; +typedef struct emote_autocomplete_s { + char complete[MAXEMOTENAME+1]; + int skip; + int emotestart; +} emote_autocomplete_t; + void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size); void M_TextInputClear(textinput_t *input); @@ -36,7 +42,7 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key); // Does everything same as M_TextInputHandle, but also handles emotes in input string // If currently typing something that looks like an existing emote, return suggestions for it -boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_t *suggestions[], int maxsuggestions); +boolean M_TextInputHandleEmotes(textinput_t *input, INT32 key, emote_autocomplete_t *autocomplete); #define M_DrawTextInput(x, y, input, flags) M_DrawTextInputScroll((x), (y), (input), (flags), ((input)->buffer_size-1)*8) void M_DrawTextInputScroll(INT32 x, INT32 y, textinput_t *input, INT32 flags, INT32 MAXINPUTWIDTH); diff --git a/src/p_ceilng.c b/src/p_ceilng.c index a00d78008..1ec076325 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -33,7 +33,6 @@ void T_MoveCeiling(ceiling_t *ceiling) { result_e res; - boolean dontupdate = false; if (ceiling->delaytimer) { @@ -69,9 +68,7 @@ void T_MoveCeiling(ceiling_t *ceiling) case instantMoveCeilingByFrontSector: ceiling->sector->ceilingpic = ceiling->texture; ceiling->sector->ceilingdata = NULL; - ceiling->sector->ceilspeed = 0; P_RemoveThinker(&ceiling->thinker); - dontupdate = true; break; case moveCeilingByFrontSector: if (ceiling->texture < -1) // chained linedef executing @@ -83,9 +80,7 @@ void T_MoveCeiling(ceiling_t *ceiling) // case raiseCeilingByLine: case moveCeilingByFrontTexture: ceiling->sector->ceilingdata = NULL; - ceiling->sector->ceilspeed = 0; P_RemoveThinker(&ceiling->thinker); - dontupdate = true; break; case fastCrushAndRaise: @@ -189,9 +184,7 @@ void T_MoveCeiling(ceiling_t *ceiling) case instantMoveCeilingByFrontSector: ceiling->sector->ceilingpic = ceiling->texture; ceiling->sector->ceilingdata = NULL; - ceiling->sector->ceilspeed = 0; P_RemoveThinker(&ceiling->thinker); - dontupdate = true; break; case moveCeilingByFrontSector: @@ -209,9 +202,7 @@ void T_MoveCeiling(ceiling_t *ceiling) // case lowerCeilingByLine: case moveCeilingByFrontTexture: ceiling->sector->ceilingdata = NULL; - ceiling->sector->ceilspeed = 0; P_RemoveThinker(&ceiling->thinker); - dontupdate = true; break; case bounceCeiling: { @@ -290,10 +281,6 @@ void T_MoveCeiling(ceiling_t *ceiling) } break; } - if (!dontupdate) - ceiling->sector->ceilspeed = ceiling->speed*ceiling->direction; - else - ceiling->sector->ceilspeed = 0; } /** Moves a ceiling crusher. @@ -335,12 +322,9 @@ void T_CrushCeiling(ceiling_t *ceiling) switch(ceiling->type) { case crushCeilOnce: - ceiling->sector->ceilspeed = 0; ceiling->sector->ceilingdata = NULL; break; case crushBothOnce: - ceiling->sector->floorspeed = 0; - ceiling->sector->ceilspeed = 0; ceiling->sector->ceilingdata = NULL; break; default: @@ -377,11 +361,6 @@ void T_CrushCeiling(ceiling_t *ceiling) } break; } - - if (ceiling->type == crushBothOnce) - ceiling->sector->floorspeed = ceiling->speed*(-ceiling->direction); - - ceiling->sector->ceilspeed = ceiling->speed*ceiling->direction; } /** Starts a ceiling mover. diff --git a/src/p_enemy.c b/src/p_enemy.c index 880f110cd..76f1af9a0 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -8176,13 +8176,16 @@ void A_SPBChase(void *thing) // Smoothly rotate horz angle angle_t input = hang - actor->angle; boolean invert = (input > ANGLE_180); + fixed_t fixedinput; if (invert) input = InvAngle(input); + fixedinput = AngleFixed(input); // Slow down when turning; it looks better and makes U-turns not unfair - xyspeed = FixedMul(actor->cvmem, max(0, (((180<cvmem, max(0, xyspeed)); - input = FixedAngle(AngleFixed(input)/4); + input = FixedAngle(fixedinput/4); if (invert) input = InvAngle(input); @@ -8193,11 +8196,13 @@ void A_SPBChase(void *thing) invert = (input > ANGLE_180); if (invert) input = InvAngle(input); + fixedinput = AngleFixed(input); // Slow down when turning; might as well do it for momz, since we do it above too - zspeed = FixedMul(actor->cvmem, max(0, (((180<cvmem, max(0, zspeed)); - input = FixedAngle(AngleFixed(input)/4); + input = FixedAngle(fixedinput/4); if (invert) input = InvAngle(input); @@ -8301,13 +8306,17 @@ void A_SPBChase(void *thing) // Smoothly rotate horz angle angle_t input = hang - actor->angle; boolean invert = (input > ANGLE_180); + fixed_t fixedinput; + if (invert) input = InvAngle(input); + fixedinput = AngleFixed(input); // Slow down when turning; it looks better and makes U-turns not unfair - xyspeed = FixedMul(wspeed, max(0, (((180< ANGLE_180); if (invert) input = InvAngle(input); + fixedinput = AngleFixed(input); // Slow down when turning; might as well do it for momz, since we do it above too - zspeed = FixedMul(wspeed, max(0, (((180<delaytimer) { @@ -325,7 +324,6 @@ void T_MoveFloor(floormove_t *movefloor) else movefloor->floordestheight = lines[movefloor->texture].frontsector->floorheight; movefloor->direction = (movefloor->floordestheight < movefloor->sector->floorheight) ? -1 : 1; - movefloor->sector->floorspeed = movefloor->speed * movefloor->direction; movefloor->delaytimer = movefloor->delay; movefloor->sector->moved = true; return; // not break, why did this work? Graue 04-03-2004 @@ -341,7 +339,6 @@ void T_MoveFloor(floormove_t *movefloor) movefloor->speed = movefloor->origspeed = FixedDiv(abs(lines[movefloor->texture].dx),4*FRACUNIT); // forward again, use dx } movefloor->direction = (movefloor->floordestheight < movefloor->sector->floorheight) ? -1 : 1; - movefloor->sector->floorspeed = movefloor->speed * movefloor->direction; movefloor->delaytimer = movefloor->delay; movefloor->sector->moved = true; return; // not break, why did this work? Graue 04-03-2004 @@ -374,7 +371,6 @@ void T_MoveFloor(floormove_t *movefloor) else movefloor->floordestheight = lines[movefloor->texture].frontsector->floorheight; movefloor->direction = (movefloor->floordestheight < movefloor->sector->floorheight) ? -1 : 1; - movefloor->sector->floorspeed = movefloor->speed * movefloor->direction; movefloor->delaytimer = movefloor->delay; movefloor->sector->moved = true; return; // not break, why did this work? Graue 04-03-2004 @@ -390,14 +386,12 @@ void T_MoveFloor(floormove_t *movefloor) movefloor->speed = movefloor->origspeed = FixedDiv(abs(lines[movefloor->texture].dx),4*FRACUNIT); // forward again, use dx } movefloor->direction = (movefloor->floordestheight < movefloor->sector->floorheight) ? -1 : 1; - movefloor->sector->floorspeed = movefloor->speed * movefloor->direction; movefloor->delaytimer = movefloor->delay; movefloor->sector->moved = true; return; // not break, why did this work? Graue 04-03-2004 case crushFloorOnce: movefloor->sector->floordata = NULL; // Clear up the thinker so others can use it P_RemoveThinker(&movefloor->thinker); - movefloor->sector->floorspeed = 0; movefloor->sector->moved = true; return; default: @@ -406,14 +400,8 @@ void T_MoveFloor(floormove_t *movefloor) } movefloor->sector->floordata = NULL; // Clear up the thinker so others can use it - movefloor->sector->floorspeed = 0; P_RemoveThinker(&movefloor->thinker); - dontupdate = true; } - if (!dontupdate) - movefloor->sector->floorspeed = movefloor->speed*movefloor->direction; - else - movefloor->sector->floorspeed = 0; movefloor->sector->moved = true; } @@ -623,22 +611,13 @@ void T_MoveElevator(elevator_t *elevator) { elevator->sector->floordata = NULL; //jff 2/22/98 elevator->sector->ceilingdata = NULL; //jff 2/22/98 - elevator->sector->ceilspeed = 0; - elevator->sector->floorspeed = 0; P_RemoveThinker(&elevator->thinker); // remove elevator from actives dontupdate = true; } } - if (!dontupdate) + if (dontupdate) { - elevator->sector->floorspeed = elevator->speed*elevator->direction; - elevator->sector->ceilspeed = 42; - } - else - { - elevator->sector->floorspeed = 0; - elevator->sector->ceilspeed = 0; elevator->sector->floordata = NULL; elevator->sector->ceilingdata = NULL; } @@ -695,8 +674,6 @@ void T_ContinuousFalling(levelspecthink_t *faller) } } - faller->sector->floorspeed = faller->speed*faller->direction; - faller->sector->ceilspeed = 42; faller->sector->moved = true; #undef speed #undef direction @@ -710,8 +687,7 @@ void T_ContinuousFalling(levelspecthink_t *faller) // P_SectorCheckWater // // Like P_MobjCheckWater, but takes a sector instead of a mobj. -static fixed_t P_SectorCheckWater(sector_t *analyzesector, - sector_t *elevatorsec) +static fixed_t P_SectorCheckWater(sector_t *analyzesector, sector_t *elevatorsec) { fixed_t watertop; @@ -767,9 +743,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) { bouncer->sector->crumblestate = 1; bouncer->sector->ceilingdata = NULL; - bouncer->sector->ceilspeed = 0; bouncer->sector->floordata = NULL; - bouncer->sector->floorspeed = 0; P_RemoveThinker(&bouncer->thinker); // remove bouncer from actives return; } @@ -795,8 +769,6 @@ void T_BounceCheese(levelspecthink_t *bouncer) T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, 0, 0, -1); // update things on floor bouncer->sector->ceilingdata = NULL; bouncer->sector->floordata = NULL; - bouncer->sector->floorspeed = 0; - bouncer->sector->ceilspeed = 0; bouncer->sector->moved = true; P_RemoveThinker(&bouncer->thinker); // remove bouncer from actives return; @@ -810,8 +782,6 @@ void T_BounceCheese(levelspecthink_t *bouncer) T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, 0, 0, -1); // update things on floor bouncer->sector->ceilingdata = NULL; bouncer->sector->floordata = NULL; - bouncer->sector->floorspeed = 0; - bouncer->sector->ceilspeed = 0; bouncer->sector->moved = true; P_RemoveThinker(&bouncer->thinker); // remove bouncer from actives return; @@ -827,9 +797,6 @@ void T_BounceCheese(levelspecthink_t *bouncer) T_MovePlane(bouncer->sector, bouncer->speed/2, bouncer->sector->floorheight - 70*FRACUNIT, 0, 0, -1); // move floor - bouncer->sector->floorspeed = -bouncer->speed/2; - bouncer->sector->ceilspeed = 42; - if (bouncer->sector->ceilingheight < bouncer->ceilingwasheight && bouncer->low == 0) // Down { if (abs(bouncer->speed) < 6*FRACUNIT) @@ -878,9 +845,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) T_MovePlane(bouncer->sector, 0, bouncer->sector->ceilingheight, 0, 1, -1); // update things on ceiling T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, 0, 0, -1); // update things on floor bouncer->sector->ceilingdata = NULL; - bouncer->sector->floordata = NULL; - bouncer->sector->floorspeed = 0; - bouncer->sector->ceilspeed = 0; + bouncer->sector->floordata = NULL;; bouncer->sector->moved = true; P_RemoveThinker(&bouncer->thinker); // remove bouncer from actives } @@ -920,8 +885,6 @@ void T_StartCrumble(elevator_t *elevator) || (elevator->floordestheight == 0 && elevator->direction == 1)) && elevator->type == elevateContinuous) // No return crumbler { - elevator->sector->ceilspeed = 0; - elevator->sector->floorspeed = 0; return; } @@ -934,9 +897,6 @@ void T_StartCrumble(elevator_t *elevator) elevator->distance = -15*TICRATE; // Timer until platform returns to original position. else { - // Timer isn't up yet, so just keep waiting. - elevator->sector->ceilspeed = 0; - elevator->sector->floorspeed = 0; return; } } @@ -965,8 +925,6 @@ void T_StartCrumble(elevator_t *elevator) else elevator->direction = 1; - elevator->sector->ceilspeed = 0; - elevator->sector->floorspeed = 0; return; } @@ -1050,9 +1008,6 @@ void T_StartCrumble(elevator_t *elevator) 0, // move ceiling elevator->direction ); - - elevator->sector->ceilspeed = 42; - elevator->sector->floorspeed = elevator->speed*elevator->direction; } } } @@ -1063,8 +1018,6 @@ void T_StartCrumble(elevator_t *elevator) elevator->sector->floorheight = elevator->floorwasheight; elevator->sector->floordata = NULL; elevator->sector->ceilingdata = NULL; - elevator->sector->ceilspeed = 0; - elevator->sector->floorspeed = 0; elevator->sector->moved = true; P_RemoveThinker(&elevator->thinker); } @@ -1121,8 +1074,6 @@ void T_MarioBlock(levelspecthink_t *block) P_RemoveThinker(&block->thinker); block->sector->floordata = NULL; block->sector->ceilingdata = NULL; - block->sector->floorspeed = 0; - block->sector->ceilspeed = 0; } for (i = -1; (i = P_FindSectorFromTag((INT16)block->vars[0], i)) >= 0 ;) @@ -1365,8 +1316,6 @@ wegotit: { bridge->sector->floorheight = LOWCEILINGHEIGHT - (bridge->sector->ceilingheight - bridge->sector->floorheight); bridge->sector->ceilingheight = LOWCEILINGHEIGHT; - bridge->sector->ceilspeed = 0; - bridge->sector->floorspeed = 0; goto dorest; } @@ -1422,9 +1371,6 @@ wegotit: DIRECTION // direction ); - bridge->sector->ceilspeed = 42; - bridge->sector->floorspeed = CURSPEED*DIRECTION; - dorest: // Adjust joined sector heights { @@ -1463,8 +1409,6 @@ wegotit: { bridge->sector->floorheight = ORIGCEILINGHEIGHT - (bridge->sector->ceilingheight - bridge->sector->floorheight); bridge->sector->ceilingheight = ORIGCEILINGHEIGHT; - bridge->sector->ceilspeed = 0; - bridge->sector->floorspeed = 0; continue; } @@ -1519,9 +1463,6 @@ wegotit: 0, // floor or ceiling (0 for floor) DIRECTION // direction ); - - bridge->sector->ceilspeed = 42; - bridge->sector->floorspeed = CURSPEED*DIRECTION; } } } @@ -1558,8 +1499,6 @@ wegotit: { bridge->sector->floorheight = ORIGCEILINGHEIGHT - (bridge->sector->ceilingheight - bridge->sector->floorheight); bridge->sector->ceilingheight = ORIGCEILINGHEIGHT; - bridge->sector->ceilspeed = 0; - bridge->sector->floorspeed = 0; continue; } @@ -1614,9 +1553,6 @@ wegotit: 0, // floor or ceiling (0 for floor) DIRECTION // direction ); - - bridge->sector->ceilspeed = 42; - bridge->sector->floorspeed = CURSPEED*DIRECTION; } } } @@ -1642,8 +1578,6 @@ wegotit: { bridge->sector->floorheight = ORIGCEILINGHEIGHT - (bridge->sector->ceilingheight - bridge->sector->floorheight); bridge->sector->ceilingheight = ORIGCEILINGHEIGHT; - bridge->sector->ceilspeed = 0; - bridge->sector->floorspeed = 0; continue; } @@ -1698,9 +1632,6 @@ wegotit: 0, // floor or ceiling (0 for floor) DIRECTION // direction ); - - bridge->sector->ceilspeed = 42; - bridge->sector->floorspeed = CURSPEED*DIRECTION; } } // Update precip @@ -1875,9 +1806,6 @@ void T_ThwompSector(levelspecthink_t *thwomp) if (res == pastdest) thwomp->direction = 0; // stop moving - - thwomp->sector->ceilspeed = 42; - thwomp->sector->floorspeed = thwomp->speed*thwomp->direction; } else if (thwomp->direction < 0) // Crashing down! { @@ -1932,16 +1860,10 @@ void T_ThwompSector(levelspecthink_t *thwomp) thwomp->direction = 1; // start heading back up thwomp->distance = TICRATE; // but only after a small delay } - - thwomp->sector->ceilspeed = 42; - thwomp->sector->floorspeed = thwomp->speed*thwomp->direction; } else // Not going anywhere, so look for players. { thwomp->direction = -1; - - thwomp->sector->ceilspeed = 0; - thwomp->sector->floorspeed = 0; } actionsector->moved = true; @@ -2355,8 +2277,6 @@ void T_RaiseSector(levelspecthink_t *raise) { raise->sector->floorheight = raise->vars[7] - (raise->sector->ceilingheight - raise->sector->floorheight); raise->sector->ceilingheight = raise->vars[7]; - raise->sector->ceilspeed = 0; - raise->sector->floorspeed = 0; return; } @@ -2370,8 +2290,6 @@ void T_RaiseSector(levelspecthink_t *raise) { raise->sector->floorheight = raise->vars[5] - (raise->sector->ceilingheight - raise->sector->floorheight); raise->sector->ceilingheight = raise->vars[5]; - raise->sector->ceilspeed = 0; - raise->sector->floorspeed = 0; return; } @@ -2390,8 +2308,6 @@ void T_RaiseSector(levelspecthink_t *raise) { raise->sector->floorheight = raise->vars[5] - (raise->sector->ceilingheight - raise->sector->floorheight); raise->sector->ceilingheight = raise->vars[5]; - raise->sector->ceilspeed = 0; - raise->sector->floorspeed = 0; return; } raise->vars[8] = 1; @@ -2404,8 +2320,6 @@ void T_RaiseSector(levelspecthink_t *raise) { raise->sector->floorheight = raise->vars[7] - (raise->sector->ceilingheight - raise->sector->floorheight); raise->sector->ceilingheight = raise->vars[7]; - raise->sector->ceilspeed = 0; - raise->sector->floorspeed = 0; return; } raise->vars[8] = -1; @@ -2460,9 +2374,6 @@ void T_RaiseSector(levelspecthink_t *raise) raise->vars[8] // direction ); - raise->sector->ceilspeed = 42; - raise->sector->floorspeed = raise->vars[3]*raise->vars[8]; - for (i = -1; (i = P_FindSectorFromTag(raise->sourceline->tag, i)) >= 0 ;) sectors[i].moved = true; } diff --git a/src/p_inter.c b/src/p_inter.c index 876ffa4b5..c95735506 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -869,14 +869,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) toucher->angle = special->angle; - for (i = 0; i <= splitscreen; i++) - { - if (player == P_GetLocalPlayerForNum(i)) - { - localangle[i] = toucher->angle; - break; - } - } + P_ForceLocalAngle(player, toucher->angle); P_ResetPlayer(player); @@ -2171,7 +2164,9 @@ static void P_KillPlayer(player_t *player, mobj_t *source) P_SetScale(karmahitbox, player->mo->scale); CONS_Printf(M_GetText("%s lost all of their bumpers!\n"), player_names[player-players]); } + player->kartstuff[k_bumper]--; + if (K_IsPlayerWanted(player)) K_CalculateBattleWanted(); } diff --git a/src/p_local.h b/src/p_local.h index 6977cc4b1..3c16b5c62 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -192,6 +192,7 @@ void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor); void P_ResetPlayer(player_t *player); player_t *P_GetLocalPlayerForNum(UINT8 pnum); INT32 P_GetLocalPlayerNumForNum(UINT8 pnum); +INT32 P_GetLocalPlayerNumForPlayer(const player_t *player); boolean P_IsLocalPlayer(const player_t *player); boolean P_IsLocalPlayerNum(UINT8 pnum); boolean P_IsDisplayPlayer(const player_t *player); @@ -226,7 +227,9 @@ void P_PlayerThink(player_t *player); void P_PlayerAfterThink(player_t *player); void P_DoPlayerExit(player_t *player); void P_DoTimeOver(player_t *player); -//void P_NightserizePlayer(player_t *player, INT32 ptime); + +angle_t P_GetLocalAngle(player_t *player); +void P_ForceLocalAngle(player_t *player, angle_t angle); void P_InstaThrust(mobj_t *mo, angle_t angle, fixed_t move); fixed_t P_ReturnThrustX(mobj_t *mo, angle_t angle, fixed_t move); @@ -269,6 +272,9 @@ extern consvar_t cv_gravity; void P_RespawnSpecials(void); +extern mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1]; +void CalculateDoomednumToMobjtype(void); + mobj_t *P_AllocateMobj(void); mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); diff --git a/src/p_map.c b/src/p_map.c index f9d828b98..e51930bef 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -223,14 +223,7 @@ boolean P_DoSpring(mobj_t *spring, mobj_t *object) if (!demo.playback || P_AnalogMove(object->player)) { - for (UINT8 j = 0; j <= splitscreen; ++j) - { - if (object->player == P_GetLocalPlayerForNum(j)) - { - localangle[j] = spring->angle; - break; - } - } + P_ForceLocalAngle(object->player, spring->angle); } } diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index 3209f6f51..37b31c4ac 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -230,8 +230,8 @@ PUREFUNC fixed_t P_InterceptVector(divline_t *v2, divline_t *v1) // Sets opentop and openbottom to the window through a two sided line. // OPTIMIZE: keep this precalculated // -fixed_t opentop, openbottom, openrange, lowfloor, highceiling; -pslope_t *opentopslope, *openbottomslope; +fixed_t opentop = 0, openbottom = 0, openrange = 0, lowfloor = 0, highceiling = 0; +pslope_t *opentopslope = NULL, *openbottomslope = NULL; // P_CameraLineOpening // P_LineOpening, but for camera @@ -985,7 +985,7 @@ boolean P_BlockThingsIterator(INT32 x, INT32 y, boolean (*func)(mobj_t *)) static intercept_t *intercepts = NULL; static intercept_t *intercept_p = NULL; -divline_t trace; +divline_t trace = {}; static boolean earlyout; //SoM: 4/6/2000: Remove limit on intercepts. diff --git a/src/p_mobj.c b/src/p_mobj.c index 9b60e565d..ad7982d87 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1041,6 +1041,27 @@ fixed_t P_GetMobjGravity(mobj_t *mo) { switch (mo->type) { + case MT_BANANA: + case MT_EGGMANITEM: + case MT_SSMINE: + case MT_SINK: + if (mo->extravalue2 > 0) + gravityadd *= mo->extravalue2; + /* FALLTHRU */ + case MT_ORBINAUT: + case MT_JAWZ: + case MT_JAWZ_DUD: + gravityadd = (5*gravityadd)/2; + break; + case MT_SIGN: + gravityadd /= 8; + break; + case MT_KARMAFIREWORK: + gravityadd /= 3; + break; + case MT_WATERDROP: + gravityadd >>= 1; + break; case MT_FLINGRING: case MT_FLINGCOIN: case MT_FLINGEMERALD: @@ -1069,27 +1090,6 @@ fixed_t P_GetMobjGravity(mobj_t *mo) } } break; - case MT_WATERDROP: - gravityadd >>= 1; - break; - case MT_BANANA: - case MT_EGGMANITEM: - case MT_SSMINE: - case MT_SINK: - if (mo->extravalue2 > 0) - gravityadd *= mo->extravalue2; - /* FALLTHRU */ - case MT_ORBINAUT: - case MT_JAWZ: - case MT_JAWZ_DUD: - gravityadd = (5*gravityadd)/2; - break; - case MT_SIGN: - gravityadd /= 8; - break; - case MT_KARMAFIREWORK: - gravityadd /= 3; - break; default: break; } @@ -1969,6 +1969,35 @@ static boolean P_ZMovement(mobj_t *mo) switch (mo->type) { + // SRB2kart stuff that should die in pits + // Shouldn't stop moving along the Z if there's no speed though! + case MT_EGGMANITEM: + case MT_BANANA: + case MT_ORBINAUT: + case MT_JAWZ: + case MT_JAWZ_DUD: + case MT_BALLHOG: + case MT_SSMINE: + // + case MT_FALLINGROCK: + case MT_BIGTUMBLEWEED: + case MT_LITTLETUMBLEWEED: + case MT_SHELL: + // Remove stuff from death pits. + if (P_CheckDeathPitCollide(mo)) + { + P_RemoveMobj(mo); + return false; + } + break; + case MT_SPIKE: + // Dead spike particles disappear upon ground contact + if ((mo->z <= mo->floorz || mo->z + mo->height >= mo->ceilingz) && mo->health <= 0) + { + P_RemoveMobj(mo); + return false; + } + break; case MT_THROWNBOUNCE: if ((mo->flags & MF_BOUNCE) && (mo->z <= mo->floorz || mo->z+mo->height >= mo->ceilingz)) { @@ -2007,26 +2036,6 @@ static boolean P_ZMovement(mobj_t *mo) S_StartSound(mo, mo->info->painsound); } break; - case MT_FALLINGROCK: - case MT_BIGTUMBLEWEED: - case MT_LITTLETUMBLEWEED: - case MT_SHELL: - // SRB2kart stuff that should die in pits - // Shouldn't stop moving along the Z if there's no speed though! - case MT_EGGMANITEM: - case MT_BANANA: - case MT_ORBINAUT: - case MT_JAWZ: - case MT_JAWZ_DUD: - case MT_BALLHOG: - case MT_SSMINE: - // Remove stuff from death pits. - if (P_CheckDeathPitCollide(mo)) - { - P_RemoveMobj(mo); - return false; - } - break; case MT_REDFLAG: case MT_BLUEFLAG: // Remove from death pits. DON'T FUCKING DESPAWN IT DAMMIT @@ -2036,7 +2045,6 @@ static boolean P_ZMovement(mobj_t *mo) return false; } break; - case MT_RING: // Ignore still rings case MT_COIN: case MT_BLUEBALL: @@ -2085,14 +2093,6 @@ static boolean P_ZMovement(mobj_t *mo) if (!(mo->flags & MF_BOUNCE)) return true; break; - case MT_SPIKE: - // Dead spike particles disappear upon ground contact - if ((mo->z <= mo->floorz || mo->z + mo->height >= mo->ceilingz) && mo->health <= 0) - { - P_RemoveMobj(mo); - return false; - } - break; default: break; } @@ -3237,7 +3237,22 @@ void P_DestroyRobots(void) // the below is chasecam only, if you're curious. check out P_CalcPostImg in p_user.c for first person void P_CalcChasePostImg(player_t *player, camera_t *thiscam) { - const boolean flipcam = (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); + boolean player_flipcam = false; + + if (cv_flipcammode.value == 0) + player_flipcam = player->pflags & PF_FLIPCAM; + else + { + INT32 pnum = P_GetLocalPlayerNumForPlayer(player); + + // Shouldn't happen but just in case + if (pnum == -1) + pnum = 0; + + player_flipcam = cv_flipcam[pnum].value; + } + + const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); UINT8 postimgtype = 0; if (encoremode) @@ -3577,7 +3592,7 @@ static void P_CalculatePrecipFloor(precipmobj_t *mobj) if (!(rover->flags & FF_BLOCKOTHERS) && !(rover->flags & FF_SWIMMABLE)) continue; - topheight = P_GetFFloorTopZAt(rover, mobj->x, mobj->y);; + topheight = P_GetFFloorTopZAt(rover, mobj->x, mobj->y); if (topheight > mobj->floorz) mobj->floorz = topheight; @@ -4847,8 +4862,6 @@ static void P_Boss7Thinker(mobj_t *mobj) mobj->momx = FixedMul(horizontal, FINECOSINE(an)); mobj->momy = FixedMul(horizontal, FINESINE(an)); mobj->momz = vertical; - -// mobj->momz = 10*FRACUNIT; } else if (mobj->state == &states[S_BLACKEGG_JUMP2] && mobj->z <= mobj->floorz) { @@ -4904,7 +4917,6 @@ static void P_Boss7Thinker(mobj_t *mobj) } else if (mobj->state == &states[mobj->info->deathstate] && mobj->tics == mobj->state->tics) S_StartSound(0, sfx_bedie1 + (P_RandomFixed() & 1)); - } // Metal Sonic battle boss @@ -5936,7 +5948,6 @@ static void P_RemoveShadow(mobj_t *thing) } } -void A_BossDeath(void *thing); // AI for the Koopa boss. static void P_KoopaThinker(mobj_t *koopa) { @@ -6102,51 +6113,17 @@ static void P_MobjSceneryThink(mobj_t *mobj) switch (mobj->type) { - case MT_HOOP: - if (mobj->fuse > 1) - P_MoveHoop(mobj); - else if (mobj->fuse == 1) - mobj->movecount = 1; - - if (mobj->movecount) + case MT_SHADOW: + if (!mobj->target) { - mobj->fuse++; - - if (mobj->fuse > 32) - { - // Don't kill the hoop center. For the sake of respawning. - //if (mobj->target) - // P_RemoveMobj(mobj->target); - - P_RemoveMobj(mobj); - } - } - else - mobj->fuse--; - return; - case MT_NIGHTSPARKLE: - if (mobj->tics != -1) - { - mobj->tics--; - - // you can cycle through multiple states in a tic - if (!mobj->tics) - if (!P_SetMobjState(mobj, mobj->state->nextstate)) - return; // freed itself - } - - P_UnsetThingPosition(mobj); - mobj->x += mobj->momx; - mobj->y += mobj->momy; - mobj->z += mobj->momz; - P_SetThingPosition(mobj); - return; - case MT_NIGHTSLOOPHELPER: - if (--mobj->tics <= 0) P_RemoveMobj(mobj); + return; + } - // Don't touch my fuse! - return; + K_RollMobjBySlopes(mobj, mobj->target->standingslope); + + P_AddShadow(mobj); + break; case MT_OVERLAY: if (!mobj->target) { @@ -6162,17 +6139,6 @@ static void P_MobjSceneryThink(mobj_t *mobj) P_AddOverlay(mobj); break; - case MT_SHADOW: - if (!mobj->target) - { - P_RemoveMobj(mobj); - return; - } - - K_RollMobjBySlopes(mobj, mobj->target->standingslope); - - P_AddShadow(mobj); - break; //{ SRB2kart mobs case MT_ORBINAUT_SHIELD: // Kart orbit/trail items case MT_JAWZ_SHIELD: @@ -6604,6 +6570,7 @@ static void P_MobjSceneryThink(mobj_t *mobj) } break; //} + case MT_WATERDROP: P_SceneryCheckWater(mobj); if ((mobj->z <= mobj->floorz || mobj->z <= mobj->watertop) @@ -6635,6 +6602,59 @@ static void P_MobjSceneryThink(mobj_t *mobj) return; } break; + case MT_ROCKCRUMBLE1 ... MT_ROCKCRUMBLE16: + if (mobj->z <= P_FloorzAtPos(mobj->x, mobj->y, mobj->z, mobj->height) + && mobj->state != &states[mobj->info->deathstate]) + { + P_SetMobjState(mobj, mobj->info->deathstate); + return; + } + break; + case MT_HOOP: + if (mobj->fuse > 1) + P_MoveHoop(mobj); + else if (mobj->fuse == 1) + mobj->movecount = 1; + + if (mobj->movecount) + { + mobj->fuse++; + + if (mobj->fuse > 32) + { + // Don't kill the hoop center. For the sake of respawning. + //if (mobj->target) + // P_RemoveMobj(mobj->target); + + P_RemoveMobj(mobj); + } + } + else + mobj->fuse--; + return; + case MT_NIGHTSPARKLE: + if (mobj->tics != -1) + { + mobj->tics--; + + // you can cycle through multiple states in a tic + if (!mobj->tics) + if (!P_SetMobjState(mobj, mobj->state->nextstate)) + return; // freed itself + } + + P_UnsetThingPosition(mobj); + mobj->x += mobj->momx; + mobj->y += mobj->momy; + mobj->z += mobj->momz; + P_SetThingPosition(mobj); + return; + case MT_NIGHTSLOOPHELPER: + if (--mobj->tics <= 0) + P_RemoveMobj(mobj); + + // Don't touch my fuse! + return; case MT_DROWNNUMBERS: if (!mobj->target) { @@ -6739,14 +6759,6 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_SEED: mobj->momz = mobj->info->speed; break; - case MT_ROCKCRUMBLE1 ... MT_ROCKCRUMBLE16: - if (mobj->z <= P_FloorzAtPos(mobj->x, mobj->y, mobj->z, mobj->height) - && mobj->state != &states[mobj->info->deathstate]) - { - P_SetMobjState(mobj, mobj->info->deathstate); - return; - } - break; case MT_FIREDITEM: if (!P_MobjWasRemoved(mobj->target)) { @@ -6839,63 +6851,6 @@ static boolean P_MobjDeadThink(mobj_t *mobj) { switch (mobj->type) { - case MT_BLUEBALL: - if ((mobj->tics>>2)+1 > 0 && (mobj->tics>>2)+1 <= tr_trans60) // tr_trans50 through tr_trans90, shifting once every second frame - mobj->frame = (NUMTRANSMAPS-((mobj->tics>>2)+1))<frame = tr_trans60<z <= mobj->floorz) - { - P_RemoveMobj(mobj); - return false; - } - break; - case MT_EGGTRAP: // Egg Capsule animal release - if (mobj->fuse > 0 && mobj->fuse < 2*TICRATE-(TICRATE/7) - && (mobj->fuse & 3)) - { - INT32 i,j; - fixed_t x,y,z; - fixed_t ns; - mobj_t *mo2; - - i = P_RandomByte(); - z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT); - - for (j = 0; j < 2; j++) - { - const angle_t fa = (P_RandomByte()*FINEANGLES/16) & FINEMASK; - ns = 64 * FRACUNIT; - x = mobj->x + FixedMul(FINESINE(fa),ns); - y = mobj->y + FixedMul(FINECOSINE(fa),ns); - - mo2 = P_SpawnMobj(x, y, z, MT_EXPLODE); - ns = 4 * FRACUNIT; - mo2->momx = FixedMul(FINESINE(fa),ns); - mo2->momy = FixedMul(FINECOSINE(fa),ns); - - i = P_RandomByte(); - - if (i % 5 == 0) - P_SpawnMobj(x, y, z, MT_CHICKEN); - else if (i % 4 == 0) - P_SpawnMobj(x, y, z, MT_COW); - else if (i % 3 == 0) - { - P_SpawnMobj(x, y, z, MT_BIRD); - S_StartSound(mo2, mobj->info->deathsound); - } - else if ((i & 1) == 0) - P_SpawnMobj(x, y, z, MT_BUNNY); - else - P_SpawnMobj(x, y, z, MT_MOUSE); - } - - mobj->fuse--; - } - break; case MT_PLAYER: /// \todo Have the player's dead body completely finish its animation even if they've already respawned. if (!(mobj->flags2 & MF2_DONTDRAW)) @@ -7009,6 +6964,63 @@ static boolean P_MobjDeadThink(mobj_t *mobj) } break; //} + case MT_BLUEBALL: + if ((mobj->tics>>2)+1 > 0 && (mobj->tics>>2)+1 <= tr_trans60) // tr_trans50 through tr_trans90, shifting once every second frame + mobj->frame = (NUMTRANSMAPS-((mobj->tics>>2)+1))<frame = tr_trans60<z <= mobj->floorz) + { + P_RemoveMobj(mobj); + return false; + } + break; + case MT_EGGTRAP: // Egg Capsule animal release + if (mobj->fuse > 0 && mobj->fuse < 2*TICRATE-(TICRATE/7) + && (mobj->fuse & 3)) + { + INT32 i,j; + fixed_t x,y,z; + fixed_t ns; + mobj_t *mo2; + + i = P_RandomByte(); + z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT); + + for (j = 0; j < 2; j++) + { + const angle_t fa = (P_RandomByte()*FINEANGLES/16) & FINEMASK; + ns = 64 * FRACUNIT; + x = mobj->x + FixedMul(FINESINE(fa),ns); + y = mobj->y + FixedMul(FINECOSINE(fa),ns); + + mo2 = P_SpawnMobj(x, y, z, MT_EXPLODE); + ns = 4 * FRACUNIT; + mo2->momx = FixedMul(FINESINE(fa),ns); + mo2->momy = FixedMul(FINECOSINE(fa),ns); + + i = P_RandomByte(); + + if (i % 5 == 0) + P_SpawnMobj(x, y, z, MT_CHICKEN); + else if (i % 4 == 0) + P_SpawnMobj(x, y, z, MT_COW); + else if (i % 3 == 0) + { + P_SpawnMobj(x, y, z, MT_BIRD); + S_StartSound(mo2, mobj->info->deathsound); + } + else if ((i & 1) == 0) + P_SpawnMobj(x, y, z, MT_BUNNY); + else + P_SpawnMobj(x, y, z, MT_MOUSE); + } + + mobj->fuse--; + } + break; default: break; } @@ -7020,472 +7032,11 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { switch (mobj->type) { - case MT_FALLINGROCK: - // Despawn rocks here in case zmovement code can't do so (blame slopes) - if (!mobj->fuse && !mobj->momx && !mobj->momy && !mobj->momz - && ((mobj->eflags & MFE_VERTICALFLIP) ? - mobj->z + mobj->height >= mobj->ceilingz - : mobj->z <= mobj->floorz)) - { - mobj->fuse = TICRATE; - } - P_MobjCheckWater(mobj); - break; - case MT_EMERALDSPAWN: - if (mobj->threshold) - { - mobj->threshold--; - - if (!mobj->threshold && !mobj->target && mobj->reactiontime) - { - mobj_t *emerald = P_SpawnMobj(mobj->x, mobj->y, mobj->z, mobj->reactiontime); - emerald->threshold = 42; - P_SetTarget(&mobj->target, emerald); - P_SetTarget(&emerald->target, mobj); - } - } - break; - case MT_AQUABUZZ: - case MT_BIGAIRMINE: - { - if (mobj->tracer && mobj->tracer->player && mobj->tracer->health > 0 - && P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius * 16) - { - // Home in on the target. - P_HomingAttack(mobj, mobj->tracer); - - if (mobj->z < mobj->floorz) - mobj->z = mobj->floorz; - - if (leveltime % mobj->info->painchance == 0) - S_StartSound(mobj, mobj->info->activesound); - } - else - { - // Try to find a player - P_LookForPlayers(mobj, true, true, mobj->radius * 16); - mobj->momx >>= 1; - mobj->momy >>= 1; - mobj->momz >>= 1; - } - } - break; - case MT_BIGMINE: - { - if (mobj->tracer && mobj->tracer->player && mobj->tracer->health > 0 - && P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius * 16) - { - P_MobjCheckWater(mobj); - - // Home in on the target. - P_HomingAttack(mobj, mobj->tracer); - - // Don't let it go out of water - if (mobj->z + mobj->height > mobj->watertop) - mobj->z = mobj->watertop - mobj->height; - - if (mobj->z < mobj->floorz) - mobj->z = mobj->floorz; - - if (leveltime % mobj->info->painchance == 0) - S_StartSound(mobj, mobj->info->activesound); - } - else - { - // Try to find a player - P_LookForPlayers(mobj, true, true, mobj->radius * 16); - mobj->momx >>= 1; - mobj->momy >>= 1; - mobj->momz >>= 1; - } - } - break; - case MT_SPINMACEPOINT: - if (leveltime & 1) - { - if (mobj->lastlook > mobj->movecount) - mobj->lastlook--; - } - break; - case MT_EGGCAPSULE: - if (!mobj->reactiontime) - { - // Target nearest player on your mare. - // (You can make it float up/down by adding MF_FLOAT, - // but beware level design pitfalls.) - fixed_t shortest = 1024*FRACUNIT; - INT32 i; - P_SetTarget(&mobj->target, NULL); - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i] || !players[i].mo) - continue; - - if ((players[i].mare != mobj->threshold) || (players[i].health <= 1)) - continue; - - fixed_t dist = P_AproxDistance(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y); - - if (!(dist < shortest)) - continue; - - P_SetTarget(&mobj->target, players[i].mo); - shortest = dist; - } - } - break; - case MT_EGGMOBILE2_POGO: - if (!mobj->target - || !mobj->target->health - || mobj->target->state == &states[mobj->target->info->spawnstate] - || mobj->target->state == &states[mobj->target->info->raisestate]) - { - P_RemoveMobj(mobj); - return false; - } - P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z - mobj->height); - break; - case MT_HAMMER: - if (mobj->z <= mobj->floorz) - { - P_RemoveMobj(mobj); - return false; - } - break; - case MT_KOOPA: - P_KoopaThinker(mobj); - break; - case MT_REDRING: - if (((mobj->z < mobj->floorz) || (mobj->z + mobj->height > mobj->ceilingz)) - && mobj->flags & MF_MISSILE) - { - P_ExplodeMissile(mobj); - return false; - } - break; - case MT_BOSSFLYPOINT: - return false; - case MT_NIGHTSCORE: - mobj->color = (UINT8)(leveltime % SKINCOLOR_WHITE); - break; - case MT_JETFUME1: - { - fixed_t jetx, jety; - - if (!mobj->target // if you have no target - || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now - { - P_RemoveMobj(mobj); // then remove yourself as well! - return false; - } - - jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, FixedMul(-64*FRACUNIT, mobj->target->scale)); - jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, FixedMul(-64*FRACUNIT, mobj->target->scale)); - - switch (mobj->fuse) - { - case 56: // First one - { - P_UnsetThingPosition(mobj); - mobj->x = jetx; - mobj->y = jety; - if (mobj->target->eflags & MFE_VERTICALFLIP) - mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(38*FRACUNIT, mobj->target->scale); - else - mobj->z = mobj->target->z + FixedMul(38*FRACUNIT, mobj->target->scale); - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - case 57: - { - P_UnsetThingPosition(mobj); - mobj->x = jetx + P_ReturnThrustX(mobj->target, mobj->target->angle-ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); - mobj->y = jety + P_ReturnThrustY(mobj->target, mobj->target->angle-ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); - if (mobj->target->eflags & MFE_VERTICALFLIP) - mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(12*FRACUNIT, mobj->target->scale); - else - mobj->z = mobj->target->z + FixedMul(12*FRACUNIT, mobj->target->scale); - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - case 58: - { - P_UnsetThingPosition(mobj); - mobj->x = jetx + P_ReturnThrustX(mobj->target, mobj->target->angle+ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); - mobj->y = jety + P_ReturnThrustY(mobj->target, mobj->target->angle+ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); - if (mobj->target->eflags & MFE_VERTICALFLIP) - mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(12*FRACUNIT, mobj->target->scale); - else - mobj->z = mobj->target->z + FixedMul(12*FRACUNIT, mobj->target->scale); - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - case 59: - { - jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, -mobj->target->radius); - jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, -mobj->target->radius); - P_UnsetThingPosition(mobj); - mobj->x = jetx; - mobj->y = jety; - if (mobj->target->eflags & MFE_VERTICALFLIP) - mobj->z = mobj->target->z + mobj->target->height/2 + mobj->height/2; - else - mobj->z = mobj->target->z + mobj->target->height/2 - mobj->height/2; - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - default: - break; - } - mobj->fuse++; - } - break; - case MT_PROPELLER: - { - fixed_t jetx, jety; - - if (!mobj->target // if you have no target - || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now - { // then remove yourself as well! - P_RemoveMobj(mobj); - return false; - } - - jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, FixedMul(-60*FRACUNIT, mobj->target->scale)); - jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, FixedMul(-60*FRACUNIT, mobj->target->scale)); - - P_UnsetThingPosition(mobj); - mobj->x = jetx; - mobj->y = jety; - mobj->z = mobj->target->z + FixedMul(17*FRACUNIT, mobj->target->scale); - mobj->angle = mobj->target->angle - ANGLE_180; - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - case MT_JETFLAME: - { - if (!mobj->target // if you have no target - || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now - { // then remove yourself as well! - P_RemoveMobj(mobj); - return false; - } - - P_UnsetThingPosition(mobj); - mobj->x = mobj->target->x; - mobj->y = mobj->target->y; - mobj->z = mobj->target->z - FixedMul(50*FRACUNIT, mobj->target->scale); - mobj->floorz = mobj->z; - mobj->ceilingz = mobj->z+mobj->height; - P_SetThingPosition(mobj); - } - break; - case MT_NIGHTSDRONE: - if (mobj->state >= &states[S_NIGHTSDRONE_SPARKLING1] && mobj->state <= &states[S_NIGHTSDRONE_SPARKLING16]) - { - mobj->flags2 &= ~MF2_DONTDRAW; - mobj->z = mobj->floorz + mobj->height + (mobj->spawnpoint->options >> ZSHIFT) * FRACUNIT; - mobj->angle = 0; - - if (!mobj->target) - { - mobj_t *goalpost = P_SpawnMobj(mobj->x, mobj->y, mobj->z + FRACUNIT, MT_NIGHTSGOAL); - CONS_Debug(DBG_NIGHTSBASIC, "Adding goal post\n"); - goalpost->angle = mobj->angle; - P_SetTarget(&mobj->target, goalpost); - } - - if (mobj->tracer && mobj->tracer->player) - { - if (!(mobj->tracer->player->pflags & PF_NIGHTSMODE)) - { - mobj->flags &= ~MF_NOGRAVITY; - mobj->flags2 &= ~MF2_DONTDRAW; - P_SetMobjState(mobj, S_NIGHTSDRONE1); - } - else if (!mobj->tracer->player->bonustime) - { - mobj->flags &= ~MF_NOGRAVITY; - P_SetMobjState(mobj, S_NIGHTSDRONE1); - } - } - } - else - { - if (mobj->tracer && mobj->tracer->player) - { - if (mobj->target) - { - CONS_Debug(DBG_NIGHTSBASIC, "Removing goal post\n"); - P_RemoveMobj(mobj->target); - P_SetTarget(&mobj->target, NULL); - } - - if (mobj->tracer->player->pflags & PF_NIGHTSMODE) - { - if (mobj->tracer->player->bonustime) - { - P_SetMobjState(mobj, S_NIGHTSDRONE_SPARKLING1); - mobj->flags |= MF_NOGRAVITY; - } - else - mobj->flags2 |= MF2_DONTDRAW; - } - else // Not NiGHTS - mobj->flags2 &= ~MF2_DONTDRAW; - } - - mobj->angle += ANG10; - - if (mobj->z <= mobj->floorz) - mobj->momz = 5*FRACUNIT; - } - break; case MT_PLAYER: if (mobj->player) P_PlayerMobjThinker(mobj); return false; - case MT_SKIM: - // check mobj against possible water content, before movement code - P_MobjCheckWater(mobj); - - // Keep Skim at water surface - if (mobj->z <= mobj->watertop) - { - mobj->flags |= MF_NOGRAVITY; - if (mobj->z < mobj->watertop) - { - if (mobj->watertop - mobj->z <= FixedMul(mobj->info->speed*FRACUNIT, mobj->scale)) - mobj->z = mobj->watertop; - else - mobj->momz = FixedMul(mobj->info->speed*FRACUNIT, mobj->scale); - } - } - else - { - mobj->flags &= ~MF_NOGRAVITY; - if (mobj->z > mobj->watertop && mobj->z - mobj->watertop < FixedMul(MAXSTEPMOVE, mapobjectscale)) - mobj->z = mobj->watertop; - } - break; - case MT_RING: - case MT_COIN: - case MT_BLUEBALL: - case MT_REDTEAMRING: - case MT_BLUETEAMRING: - // No need to check water. Who cares? - P_RingThinker(mobj); - if (mobj->flags2 & MF2_NIGHTSPULL) - P_NightsItemChase(mobj); - else - A_AttractChase(mobj); - return false; - // Flung items - case MT_FLINGRING: - case MT_FLINGCOIN: - if (mobj->flags2 & MF2_NIGHTSPULL) - P_NightsItemChase(mobj); - else - A_AttractChase(mobj); - break; - case MT_NIGHTSWING: - if (mobj->flags2 & MF2_NIGHTSPULL) - P_NightsItemChase(mobj); - break; - case MT_SMALLMACE: - case MT_BIGMACE: - { - mobj_t *ghostmo = P_SpawnGhostMobj(mobj); - ghostmo->fuse = 4; - } - break; - case MT_SHELL: - if (mobj->threshold > TICRATE) - mobj->threshold--; - - if (mobj->state != &states[S_SHELL]) - { - mobj->angle = R_PointToAngle2(0, 0, mobj->momx, mobj->momy); - P_InstaThrust(mobj, mobj->angle, FixedMul(mobj->info->speed, mobj->scale)); - } - break; //{ SRB2kart Items - case MT_FLOATINGITEM: - { - if (mobj->flags & MF_NOCLIPTHING) - { - if (P_CheckDeathPitCollide(mobj)) - { - P_RemoveMobj(mobj); - return false; - } - else if (P_IsObjectOnGround(mobj)) - { - mobj->momx = 1; - mobj->momy = 0; - mobj->flags &= ~MF_NOCLIPTHING; - mobj->flags |= MF_NOGRAVITY; - } - } - else - { - mobj->angle += 2*ANG2; - if (mobj->flags2 & MF2_NIGHTSPULL) - { - if (!mobj->tracer || !mobj->tracer->health - || mobj->scale <= mapobjectscale>>4) - { - P_RemoveMobj(mobj); - return false; - } - P_Attract(mobj, mobj->tracer, true); - } - else - { - fixed_t adj = FixedMul(FRACUNIT - FINECOSINE((mobj->movedir>>ANGLETOFINESHIFT) & FINEMASK), (mapobjectscale<<3)); - mobj->movedir += 2*ANG2; - if (mobj->eflags & MFE_VERTICALFLIP) - mobj->z = mobj->ceilingz - mobj->height - adj; - else - mobj->z = mobj->floorz + adj; - } - } - - switch (mobj->threshold) - { - case KITEM_ORBINAUT: - mobj->sprite = SPR_ITMO; - mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|(min(mobj->movecount-1, 3)); - break; - case KITEM_INVINCIBILITY: - mobj->sprite = SPR_ITMI; - mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|((leveltime % (7*3)) / 3); - break; - case KITEM_SAD: - mobj->sprite = SPR_ITEM; - mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE; - break; - case KITEM_SPB: - case KITEM_SHRINK: - indirectitemcooldown = 20*TICRATE; - /* FALLTHRU */ - default: - mobj->sprite = SPR_ITEM; - mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|(mobj->threshold); - break; - } - break; - } case MT_ORBINAUT: { boolean grounded = P_IsObjectOnGround(mobj); @@ -7856,49 +7407,6 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->flags2 |= MF2_DONTDRAW; } break; - case MT_PLAYERRETICULE: - if (!mobj->target || !mobj->target->health) - { - P_RemoveMobj(mobj); - return false; - } - P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z); - break; - case MT_INSTASHIELDB: - mobj->flags2 ^= MF2_DONTDRAW; - /* FALLTHRU */ - case MT_INSTASHIELDA: - if (!mobj->target || !mobj->target->health || (mobj->target->player && !mobj->target->player->kartstuff[k_instashield])) - { - P_RemoveMobj(mobj); - return false; - } - - K_MatchGenericExtraFlags(mobj, mobj->target); - P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z); - break; - case MT_BATTLEPOINT: - if (P_MobjWasRemoved(mobj->target)) - { - P_RemoveMobj(mobj); - return false; - } - - if (mobj->movefactor < 48*mobj->target->scale) - { - mobj->movefactor += (48*mobj->target->scale)/6; - if (mobj->movefactor > mobj->target->height) - mobj->movefactor = mobj->target->height; - } - else if (mobj->movefactor > 48*mobj->target->scale) - { - mobj->movefactor -= (48*mobj->target->scale)/6; - if (mobj->movefactor < mobj->target->height) - mobj->movefactor = mobj->target->height; - } - K_MatchGenericExtraFlags(mobj, mobj->target); - P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z + (mobj->target->height/2) + mobj->movefactor); - break; case MT_THUNDERSHIELD: { fixed_t destx, desty; @@ -7959,6 +7467,115 @@ static boolean P_MobjRegularThink(mobj_t *mobj) } } break; + case MT_FLOATINGITEM: + { + if (mobj->flags & MF_NOCLIPTHING) + { + if (P_CheckDeathPitCollide(mobj)) + { + P_RemoveMobj(mobj); + return false; + } + else if (P_IsObjectOnGround(mobj)) + { + mobj->momx = 1; + mobj->momy = 0; + mobj->flags &= ~MF_NOCLIPTHING; + mobj->flags |= MF_NOGRAVITY; + } + } + else + { + mobj->angle += 2*ANG2; + if (mobj->flags2 & MF2_NIGHTSPULL) + { + if (!mobj->tracer || !mobj->tracer->health + || mobj->scale <= mapobjectscale>>4) + { + P_RemoveMobj(mobj); + return false; + } + P_Attract(mobj, mobj->tracer, true); + } + else + { + fixed_t adj = FixedMul(FRACUNIT - FINECOSINE((mobj->movedir>>ANGLETOFINESHIFT) & FINEMASK), (mapobjectscale<<3)); + mobj->movedir += 2*ANG2; + if (mobj->eflags & MFE_VERTICALFLIP) + mobj->z = mobj->ceilingz - mobj->height - adj; + else + mobj->z = mobj->floorz + adj; + } + } + + switch (mobj->threshold) + { + case KITEM_ORBINAUT: + mobj->sprite = SPR_ITMO; + mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|(min(mobj->movecount-1, 3)); + break; + case KITEM_INVINCIBILITY: + mobj->sprite = SPR_ITMI; + mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|((leveltime % (7*3)) / 3); + break; + case KITEM_SAD: + mobj->sprite = SPR_ITEM; + mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE; + break; + case KITEM_SPB: + case KITEM_SHRINK: + indirectitemcooldown = 20*TICRATE; + /* FALLTHRU */ + default: + mobj->sprite = SPR_ITEM; + mobj->frame = FF_FULLBRIGHT|FF_PAPERSPRITE|(mobj->threshold); + break; + } + break; + } + case MT_PLAYERRETICULE: + if (!mobj->target || !mobj->target->health) + { + P_RemoveMobj(mobj); + return false; + } + P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z); + break; + case MT_INSTASHIELDB: + mobj->flags2 ^= MF2_DONTDRAW; + /* FALLTHRU */ + case MT_INSTASHIELDA: + if (!mobj->target || !mobj->target->health || (mobj->target->player && !mobj->target->player->kartstuff[k_instashield])) + { + P_RemoveMobj(mobj); + return false; + } + + K_MatchGenericExtraFlags(mobj, mobj->target); + P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z); + break; + case MT_BATTLEPOINT: + if (P_MobjWasRemoved(mobj->target)) + { + P_RemoveMobj(mobj); + return false; + } + + if (mobj->movefactor < 48*mobj->target->scale) + { + mobj->movefactor += (48*mobj->target->scale)/6; + if (mobj->movefactor > mobj->target->height) + mobj->movefactor = mobj->target->height; + } + else if (mobj->movefactor > 48*mobj->target->scale) + { + mobj->movefactor -= (48*mobj->target->scale)/6; + if (mobj->movefactor < mobj->target->height) + mobj->movefactor = mobj->target->height; + } + K_MatchGenericExtraFlags(mobj, mobj->target); + P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z + (mobj->target->height/2) + mobj->movefactor); + break; case MT_KARMAHITBOX: { statenum_t state = (mobj->state-states); @@ -8050,44 +7667,45 @@ static boolean P_MobjRegularThink(mobj_t *mobj) } break; case MT_SIGN: // Kart's unique sign behavior - if (mobj->movecount) { - if (mobj->z <= mobj->movefactor) + if (mobj->movecount) { - P_SetMobjState(mobj, S_SIGN_END); - if (mobj->info->attacksound) - S_StartSound(mobj, mobj->info->attacksound); - mobj->flags |= MF_NOGRAVITY; // ? - mobj->flags &= ~MF_NOCLIPHEIGHT; - mobj->z = mobj->movefactor; - mobj->movecount = 0; - } - else - { - fixed_t rand_x; - fixed_t rand_y; - fixed_t rand_z; - - rand_z = mobj->z + (24*mobj->scale) + (P_RandomRange(-8,8)*mobj->scale); - rand_y = mobj->y + (P_RandomRange(-48,48)*mobj->scale); - rand_x = mobj->x + (P_RandomRange(-48,48)*mobj->scale); - - P_SpawnMobj(rand_x, rand_y, rand_z, MT_SIGNSPARKLE); - - mobj->flags &= ~MF_NOGRAVITY; - - if (abs(mobj->z - mobj->movefactor) <= (512*mobj->scale) && !mobj->cvmem) + if (mobj->z <= mobj->movefactor) { - if (mobj->info->seesound) - S_StartSound(mobj, mobj->info->seesound); - mobj->cvmem = 1; + P_SetMobjState(mobj, S_SIGN_END); + if (mobj->info->attacksound) + S_StartSound(mobj, mobj->info->attacksound); + mobj->flags |= MF_NOGRAVITY; // ? + mobj->flags &= ~MF_NOCLIPHEIGHT; + mobj->z = mobj->movefactor; + mobj->movecount = 0; + } + else + { + fixed_t rand_x; + fixed_t rand_y; + fixed_t rand_z; + + rand_z = mobj->z + (24*mobj->scale) + (P_RandomRange(-8,8)*mobj->scale); + rand_y = mobj->y + (P_RandomRange(-48,48)*mobj->scale); + rand_x = mobj->x + (P_RandomRange(-48,48)*mobj->scale); + + P_SpawnMobj(rand_x, rand_y, rand_z, MT_SIGNSPARKLE); + + mobj->flags &= ~MF_NOGRAVITY; + + if (abs(mobj->z - mobj->movefactor) <= (512*mobj->scale) && !mobj->cvmem) + { + if (mobj->info->seesound) + S_StartSound(mobj, mobj->info->seesound); + mobj->cvmem = 1; + } } } + + // fancy sign rotation + P_RollPitchMobj(mobj); } - - // fancy sign rotation - P_RollPitchMobj(mobj); - break; case MT_CDUFO: if (!mobj->spawnpoint || mobj->fuse) @@ -8648,6 +8266,401 @@ static boolean P_MobjRegularThink(mobj_t *mobj) } break; //} + case MT_FALLINGROCK: + // Despawn rocks here in case zmovement code can't do so (blame slopes) + if (!mobj->fuse && !mobj->momx && !mobj->momy && !mobj->momz + && ((mobj->eflags & MFE_VERTICALFLIP) ? + mobj->z + mobj->height >= mobj->ceilingz + : mobj->z <= mobj->floorz)) + { + mobj->fuse = TICRATE; + } + P_MobjCheckWater(mobj); + break; + case MT_EMERALDSPAWN: + if (mobj->threshold) + { + mobj->threshold--; + + if (!mobj->threshold && !mobj->target && mobj->reactiontime) + { + mobj_t *emerald = P_SpawnMobj(mobj->x, mobj->y, mobj->z, mobj->reactiontime); + emerald->threshold = 42; + P_SetTarget(&mobj->target, emerald); + P_SetTarget(&emerald->target, mobj); + } + } + break; + case MT_AQUABUZZ: + case MT_BIGAIRMINE: + { + if (mobj->tracer && mobj->tracer->player && mobj->tracer->health > 0 + && P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius * 16) + { + // Home in on the target. + P_HomingAttack(mobj, mobj->tracer); + + if (mobj->z < mobj->floorz) + mobj->z = mobj->floorz; + + if (leveltime % mobj->info->painchance == 0) + S_StartSound(mobj, mobj->info->activesound); + } + else + { + // Try to find a player + P_LookForPlayers(mobj, true, true, mobj->radius * 16); + mobj->momx >>= 1; + mobj->momy >>= 1; + mobj->momz >>= 1; + } + } + break; + case MT_BIGMINE: + { + if (mobj->tracer && mobj->tracer->player && mobj->tracer->health > 0 + && P_AproxDistance(P_AproxDistance(mobj->tracer->x - mobj->x, mobj->tracer->y - mobj->y), mobj->tracer->z - mobj->z) <= mobj->radius * 16) + { + P_MobjCheckWater(mobj); + + // Home in on the target. + P_HomingAttack(mobj, mobj->tracer); + + // Don't let it go out of water + if (mobj->z + mobj->height > mobj->watertop) + mobj->z = mobj->watertop - mobj->height; + + if (mobj->z < mobj->floorz) + mobj->z = mobj->floorz; + + if (leveltime % mobj->info->painchance == 0) + S_StartSound(mobj, mobj->info->activesound); + } + else + { + // Try to find a player + P_LookForPlayers(mobj, true, true, mobj->radius * 16); + mobj->momx >>= 1; + mobj->momy >>= 1; + mobj->momz >>= 1; + } + } + break; + case MT_SPINMACEPOINT: + if (leveltime & 1) + { + if (mobj->lastlook > mobj->movecount) + mobj->lastlook--; + } + break; + case MT_EGGCAPSULE: + if (!mobj->reactiontime) + { + // Target nearest player on your mare. + // (You can make it float up/down by adding MF_FLOAT, + // but beware level design pitfalls.) + fixed_t shortest = 1024*FRACUNIT; + INT32 i; + P_SetTarget(&mobj->target, NULL); + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || !players[i].mo) + continue; + + if ((players[i].mare != mobj->threshold) || (players[i].health <= 1)) + continue; + + fixed_t dist = P_AproxDistance(players[i].mo->x - mobj->x, players[i].mo->y - mobj->y); + + if (!(dist < shortest)) + continue; + + P_SetTarget(&mobj->target, players[i].mo); + shortest = dist; + } + } + break; + case MT_EGGMOBILE2_POGO: + if (!mobj->target + || !mobj->target->health + || mobj->target->state == &states[mobj->target->info->spawnstate] + || mobj->target->state == &states[mobj->target->info->raisestate]) + { + P_RemoveMobj(mobj); + return false; + } + P_MoveOrigin(mobj, mobj->target->x, mobj->target->y, mobj->target->z - mobj->height); + break; + case MT_HAMMER: + if (mobj->z <= mobj->floorz) + { + P_RemoveMobj(mobj); + return false; + } + break; + case MT_KOOPA: + P_KoopaThinker(mobj); + break; + case MT_REDRING: + if (((mobj->z < mobj->floorz) || (mobj->z + mobj->height > mobj->ceilingz)) + && mobj->flags & MF_MISSILE) + { + P_ExplodeMissile(mobj); + return false; + } + break; + case MT_BOSSFLYPOINT: + return false; + case MT_NIGHTSCORE: + mobj->color = (UINT8)(leveltime % SKINCOLOR_WHITE); + break; + case MT_JETFUME1: + { + fixed_t jetx, jety; + + if (!mobj->target // if you have no target + || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now + { + P_RemoveMobj(mobj); // then remove yourself as well! + return false; + } + + jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, FixedMul(-64*FRACUNIT, mobj->target->scale)); + jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, FixedMul(-64*FRACUNIT, mobj->target->scale)); + + switch (mobj->fuse) + { + case 56: // First one + { + P_UnsetThingPosition(mobj); + mobj->x = jetx; + mobj->y = jety; + if (mobj->target->eflags & MFE_VERTICALFLIP) + mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(38*FRACUNIT, mobj->target->scale); + else + mobj->z = mobj->target->z + FixedMul(38*FRACUNIT, mobj->target->scale); + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + case 57: + { + P_UnsetThingPosition(mobj); + mobj->x = jetx + P_ReturnThrustX(mobj->target, mobj->target->angle-ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); + mobj->y = jety + P_ReturnThrustY(mobj->target, mobj->target->angle-ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); + if (mobj->target->eflags & MFE_VERTICALFLIP) + mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(12*FRACUNIT, mobj->target->scale); + else + mobj->z = mobj->target->z + FixedMul(12*FRACUNIT, mobj->target->scale); + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + case 58: + { + P_UnsetThingPosition(mobj); + mobj->x = jetx + P_ReturnThrustX(mobj->target, mobj->target->angle+ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); + mobj->y = jety + P_ReturnThrustY(mobj->target, mobj->target->angle+ANGLE_90, FixedMul(24*FRACUNIT, mobj->target->scale)); + if (mobj->target->eflags & MFE_VERTICALFLIP) + mobj->z = mobj->target->z + mobj->target->height - mobj->height - FixedMul(12*FRACUNIT, mobj->target->scale); + else + mobj->z = mobj->target->z + FixedMul(12*FRACUNIT, mobj->target->scale); + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + case 59: + { + jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, -mobj->target->radius); + jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, -mobj->target->radius); + P_UnsetThingPosition(mobj); + mobj->x = jetx; + mobj->y = jety; + if (mobj->target->eflags & MFE_VERTICALFLIP) + mobj->z = mobj->target->z + mobj->target->height/2 + mobj->height/2; + else + mobj->z = mobj->target->z + mobj->target->height/2 - mobj->height/2; + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + default: + break; + } + mobj->fuse++; + } + break; + case MT_PROPELLER: + { + fixed_t jetx, jety; + + if (!mobj->target // if you have no target + || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now + { // then remove yourself as well! + P_RemoveMobj(mobj); + return false; + } + + jetx = mobj->target->x + P_ReturnThrustX(mobj->target, mobj->target->angle, FixedMul(-60*FRACUNIT, mobj->target->scale)); + jety = mobj->target->y + P_ReturnThrustY(mobj->target, mobj->target->angle, FixedMul(-60*FRACUNIT, mobj->target->scale)); + + P_UnsetThingPosition(mobj); + mobj->x = jetx; + mobj->y = jety; + mobj->z = mobj->target->z + FixedMul(17*FRACUNIT, mobj->target->scale); + mobj->angle = mobj->target->angle - ANGLE_180; + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + case MT_JETFLAME: + { + if (!mobj->target // if you have no target + || (!(mobj->target->flags & MF_BOSS) && mobj->target->health <= 0)) // or your target isn't a boss and it's popped now + { // then remove yourself as well! + P_RemoveMobj(mobj); + return false; + } + + P_UnsetThingPosition(mobj); + mobj->x = mobj->target->x; + mobj->y = mobj->target->y; + mobj->z = mobj->target->z - FixedMul(50*FRACUNIT, mobj->target->scale); + mobj->floorz = mobj->z; + mobj->ceilingz = mobj->z+mobj->height; + P_SetThingPosition(mobj); + } + break; + case MT_NIGHTSDRONE: + if (mobj->state >= &states[S_NIGHTSDRONE_SPARKLING1] && mobj->state <= &states[S_NIGHTSDRONE_SPARKLING16]) + { + mobj->flags2 &= ~MF2_DONTDRAW; + mobj->z = mobj->floorz + mobj->height + (mobj->spawnpoint->options >> ZSHIFT) * FRACUNIT; + mobj->angle = 0; + + if (!mobj->target) + { + mobj_t *goalpost = P_SpawnMobj(mobj->x, mobj->y, mobj->z + FRACUNIT, MT_NIGHTSGOAL); + CONS_Debug(DBG_NIGHTSBASIC, "Adding goal post\n"); + goalpost->angle = mobj->angle; + P_SetTarget(&mobj->target, goalpost); + } + + if (mobj->tracer && mobj->tracer->player) + { + if (!(mobj->tracer->player->pflags & PF_NIGHTSMODE)) + { + mobj->flags &= ~MF_NOGRAVITY; + mobj->flags2 &= ~MF2_DONTDRAW; + P_SetMobjState(mobj, S_NIGHTSDRONE1); + } + else if (!mobj->tracer->player->bonustime) + { + mobj->flags &= ~MF_NOGRAVITY; + P_SetMobjState(mobj, S_NIGHTSDRONE1); + } + } + } + else + { + if (mobj->tracer && mobj->tracer->player) + { + if (mobj->target) + { + CONS_Debug(DBG_NIGHTSBASIC, "Removing goal post\n"); + P_RemoveMobj(mobj->target); + P_SetTarget(&mobj->target, NULL); + } + + if (mobj->tracer->player->pflags & PF_NIGHTSMODE) + { + if (mobj->tracer->player->bonustime) + { + P_SetMobjState(mobj, S_NIGHTSDRONE_SPARKLING1); + mobj->flags |= MF_NOGRAVITY; + } + else + mobj->flags2 |= MF2_DONTDRAW; + } + else // Not NiGHTS + mobj->flags2 &= ~MF2_DONTDRAW; + } + + mobj->angle += ANG10; + + if (mobj->z <= mobj->floorz) + mobj->momz = 5*FRACUNIT; + } + break; + case MT_SKIM: + // check mobj against possible water content, before movement code + P_MobjCheckWater(mobj); + + // Keep Skim at water surface + if (mobj->z <= mobj->watertop) + { + mobj->flags |= MF_NOGRAVITY; + if (mobj->z < mobj->watertop) + { + if (mobj->watertop - mobj->z <= FixedMul(mobj->info->speed*FRACUNIT, mobj->scale)) + mobj->z = mobj->watertop; + else + mobj->momz = FixedMul(mobj->info->speed*FRACUNIT, mobj->scale); + } + } + else + { + mobj->flags &= ~MF_NOGRAVITY; + if (mobj->z > mobj->watertop && mobj->z - mobj->watertop < FixedMul(MAXSTEPMOVE, mapobjectscale)) + mobj->z = mobj->watertop; + } + break; + case MT_RING: + case MT_COIN: + case MT_BLUEBALL: + case MT_REDTEAMRING: + case MT_BLUETEAMRING: + // No need to check water. Who cares? + P_RingThinker(mobj); + if (mobj->flags2 & MF2_NIGHTSPULL) + P_NightsItemChase(mobj); + else + A_AttractChase(mobj); + return false; + // Flung items + case MT_FLINGRING: + case MT_FLINGCOIN: + if (mobj->flags2 & MF2_NIGHTSPULL) + P_NightsItemChase(mobj); + else + A_AttractChase(mobj); + break; + case MT_NIGHTSWING: + if (mobj->flags2 & MF2_NIGHTSPULL) + P_NightsItemChase(mobj); + break; + case MT_SMALLMACE: + case MT_BIGMACE: + { + mobj_t *ghostmo = P_SpawnGhostMobj(mobj); + ghostmo->fuse = 4; + } + break; + case MT_SHELL: + if (mobj->threshold > TICRATE) + mobj->threshold--; + + if (mobj->state != &states[S_SHELL]) + { + mobj->angle = R_PointToAngle2(0, 0, mobj->momx, mobj->momy); + P_InstaThrust(mobj, mobj->angle, FixedMul(mobj->info->speed, mobj->scale)); + } + break; case MT_TURRET: P_MobjCheckWater(mobj); P_CheckPosition(mobj, mobj->x, mobj->y); @@ -8900,7 +8913,10 @@ static boolean P_FuseThink(mobj_t *mobj) if (mobj->fuse) { - if (((mobj->type == MT_RANDOMITEM && mobj->threshold == 69) || mobj->type == MT_EGGMANITEM || mobj->type == MT_FALLINGROCK) && mobj->fuse <= TICRATE) + if ((( mobj->type == MT_RANDOMITEM && mobj->threshold == 69) + || mobj->type == MT_EGGMANITEM + || mobj->type == MT_FALLINGROCK) + && mobj->fuse <= TICRATE) mobj->flags2 ^= MF2_DONTDRAW; return true; @@ -8908,62 +8924,63 @@ static boolean P_FuseThink(mobj_t *mobj) if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjFuse)) || P_MobjWasRemoved(mobj)) ; - else switch (mobj->type) - { - // gargoyle and snowman handled in P_PushableThinker, not here - case MT_THROWNGRENADE: - case MT_CYBRAKDEMON_NAPALM_BOMB_LARGE: - P_SetMobjState(mobj, mobj->info->deathstate); - break; - case MT_BLUEFLAG: - case MT_REDFLAG: - P_FlagFuseThink(mobj); - return false; - case MT_YELLOWTV: // Ring shield box - case MT_BLUETV: // Force shield box - case MT_GREENTV: // Water shield box - case MT_BLACKTV: // Bomb shield box - case MT_WHITETV: // Jump shield box - case MT_SNEAKERTV: // Super Sneaker box - case MT_SUPERRINGBOX: // 10-Ring box - case MT_REDRINGBOX: // Red Team 10-Ring box - case MT_BLUERINGBOX: // Blue Team 10-Ring box - case MT_INV: // Invincibility box - case MT_MIXUPBOX: // Teleporter Mixup box - case MT_RECYCLETV: // Recycler box - case MT_SCORETVSMALL: - case MT_SCORETVLARGE: - case MT_PRUP: // 1up! - case MT_EGGMANBOX: // Eggman box - case MT_GRAVITYBOX: // Gravity box - case MT_QUESTIONBOX: - P_MonitorFuseThink(mobj); - return false; - case MT_RANDOMITEM: - if (!P_RandomItemFuseThink(mobj)) + else + switch (mobj->type) + { + case MT_PLAYER: + break; // don't remove + case MT_RANDOMITEM: + if (!P_RandomItemFuseThink(mobj)) + break; + P_RemoveMobj(mobj); // make sure they disappear + return false; + case MT_SMK_ICEBLOCK: + P_IceBlockFuseThink(mobj); + return false; + case MT_SPIKE: + P_SetMobjState(mobj, mobj->state->nextstate); + mobj->fuse = mobj->info->speed; + if (mobj->spawnpoint) + mobj->fuse += mobj->spawnpoint->angle; break; - P_RemoveMobj(mobj); // make sure they disappear - return false; - case MT_METALSONIC_BATTLE: - break; // don't remove - case MT_SPIKE: - P_SetMobjState(mobj, mobj->state->nextstate); - mobj->fuse = mobj->info->speed; - if (mobj->spawnpoint) - mobj->fuse += mobj->spawnpoint->angle; - break; - case MT_NIGHTSCORE: - P_RemoveMobj(mobj); - return false; - case MT_PLAYER: - break; // don't remove - case MT_SMK_ICEBLOCK: - P_IceBlockFuseThink(mobj); - return false; - default: - P_SetMobjState(mobj, mobj->info->xdeathstate); // will remove the mobj if S_NULL. - break; - } + case MT_METALSONIC_BATTLE: + break; // don't remove + case MT_NIGHTSCORE: + P_RemoveMobj(mobj); + return false; + // gargoyle and snowman handled in P_PushableThinker, not here + case MT_THROWNGRENADE: + case MT_CYBRAKDEMON_NAPALM_BOMB_LARGE: + P_SetMobjState(mobj, mobj->info->deathstate); + break; + case MT_BLUEFLAG: + case MT_REDFLAG: + P_FlagFuseThink(mobj); + return false; + case MT_YELLOWTV: // Ring shield box + case MT_BLUETV: // Force shield box + case MT_GREENTV: // Water shield box + case MT_BLACKTV: // Bomb shield box + case MT_WHITETV: // Jump shield box + case MT_SNEAKERTV: // Super Sneaker box + case MT_SUPERRINGBOX: // 10-Ring box + case MT_REDRINGBOX: // Red Team 10-Ring box + case MT_BLUERINGBOX: // Blue Team 10-Ring box + case MT_INV: // Invincibility box + case MT_MIXUPBOX: // Teleporter Mixup box + case MT_RECYCLETV: // Recycler box + case MT_SCORETVSMALL: + case MT_SCORETVLARGE: + case MT_PRUP: // 1up! + case MT_EGGMANBOX: // Eggman box + case MT_GRAVITYBOX: // Gravity box + case MT_QUESTIONBOX: + P_MonitorFuseThink(mobj); + return false; + default: + P_SetMobjState(mobj, mobj->info->xdeathstate); // will remove the mobj if S_NULL. + break; + } return !P_MobjWasRemoved(mobj); } @@ -9168,14 +9185,14 @@ void P_MobjThinker(mobj_t *mobj) mobj->eflags &= ~MFE_JUSTHITFLOOR; } - if (UNLIKELY(mobj->type == MT_FLINGRING - || mobj->type == MT_FLINGCOIN - || P_WeaponOrPanel(mobj->type) - || mobj->type == MT_FLINGEMERALD - || mobj->type == MT_BIGTUMBLEWEED + if (mobj->type == MT_FALLINGROCK || mobj->type == MT_LITTLETUMBLEWEED - || mobj->type == MT_CANNONBALLDECOR) - || mobj->type == MT_FALLINGROCK) + || mobj->type == MT_BIGTUMBLEWEED + || mobj->type == MT_FLINGRING + || mobj->type == MT_FLINGCOIN + || mobj->type == MT_FLINGEMERALD + || mobj->type == MT_CANNONBALLDECOR + || P_WeaponOrPanel(mobj->type)) { P_TryMove(mobj, mobj->x, mobj->y, true); // Sets mo->standingslope correctly P_ButteredSlope(mobj); @@ -9541,285 +9558,287 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) else if (P_MobjWasRemoved(mobj)) return NULL; else - switch (mobj->type) { - case MT_CYBRAKDEMON_NAPALM_BOMB_LARGE: - mobj->fuse = mobj->info->mass; - break; - case MT_BLACKEGGMAN: - { - mobj_t *spawn = P_SpawnMobj(mobj->x, mobj->z, mobj->z+mobj->height-16*FRACUNIT, MT_BLACKEGGMAN_HELPER); - spawn->destscale = mobj->scale; - P_SetScale(spawn, mobj->scale); - P_SetTarget(&spawn->target, mobj); - } - break; - case MT_BLACKEGGMAN_HELPER: - // Collision helper can be stood on but not pushed - mobj->flags2 |= MF2_STANDONME; - break; - case MT_SPIKE: - mobj->flags2 |= MF2_STANDONME; - break; - case MT_DETON: - mobj->movedir = 0; - break; - case MT_EGGGUARD: - { - mobj_t *spawn = P_SpawnMobj(x, y, z, MT_EGGSHIELD); - spawn->destscale = mobj->scale; - P_SetScale(spawn, mobj->scale); - P_SetTarget(&mobj->tracer, spawn); - P_SetTarget(&spawn->target, mobj); - } - break; - case MT_UNIDUS: + switch (mobj->type) { - INT32 i; - mobj_t *ball; - // Spawn "damage" number of "painchance" spikeball mobjs - // threshold is the distance they should keep from the MT_UNIDUS (touching radius + ball painchance) - for (i = 0; i < mobj->info->damage; i++) - { - ball = P_SpawnMobj(x, y, z, mobj->info->painchance); - ball->destscale = mobj->scale; - P_SetScale(ball, mobj->scale); - P_SetTarget(&ball->target, mobj); - ball->movedir = FixedAngle(FixedMul(FixedDiv(i<info->damage<threshold = ball->radius + mobj->radius + FixedMul(ball->info->painchance, ball->scale); - - var1 = ball->state->var1, var2 = ball->state->var2; - ball->state->action(ball); - } - break; - } - case MT_POINTY: - { - INT32 q; - mobj_t *ball, *lastball = mobj; - - for (q = 0; q < mobj->info->painchance; q++) - { - ball = P_SpawnMobj(x, y, z, mobj->info->mass); - ball->destscale = mobj->scale; - P_SetScale(ball, mobj->scale); - P_SetTarget(&lastball->tracer, ball); - P_SetTarget(&ball->target, mobj); - lastball = ball; - } - break; - } - case MT_EGGMOBILE2: - // Special condition for the 2nd boss. - mobj->watertop = mobj->info->speed; - break; - case MT_BIRD: - case MT_BUNNY: - case MT_MOUSE: - case MT_CHICKEN: - case MT_COW: - case MT_REDBIRD: - mobj->fuse = P_RandomRange(300, 350); - break; - case MT_REDRING: // Make MT_REDRING red by default - mobj->color = skincolor_redring; - break; - case MT_SMALLBUBBLE: // Bubbles eventually dissipate, in case they get caught somewhere. - case MT_MEDIUMBUBBLE: - case MT_EXTRALARGEBUBBLE: - mobj->fuse += 30 * TICRATE; - break; - case MT_EGGCAPSULE: - mobj->extravalue1 = -1; // timer for how long a player has been at the capsule - break; - case MT_REDTEAMRING: - mobj->color = skincolor_redteam; - break; - case MT_BLUETEAMRING: - mobj->color = skincolor_blueteam; - break; - case MT_RING: - case MT_COIN: - case MT_BLUEBALL: - nummaprings++; - break; - // SRB2Kart - case MT_KARMAHITBOX: - { - const fixed_t rad = FixedMul(mobjinfo[MT_PLAYER].radius, mobj->scale); - mobj_t *cur, *prev = mobj; - INT32 i; - - for (i = 0; i < 4; i++) + // SRB2Kart + case MT_RANDOMAUDIENCE: { - fixed_t offx = rad; - fixed_t offy = rad; + fixed_t randu = P_RandomFixed(); + P_SetScale(mobj, (mobj->destscale <<= 1)); + if (randu < (FRACUNIT/9)) // a fan of someone? + { + UINT8 i, pcount = 0; + UINT8 pnum[MAXPLAYERS]; - if (i == 1 || i == 3) - offx *= -1; - if (i == 2 || i == 3) - offy *= -1; + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i]) + continue; - cur = P_SpawnMobj(mobj->x + offx, mobj->y + offy, mobj->z, MT_KARMAWHEEL); - cur->destscale = mobj->scale; - P_SetScale(cur, mobj->scale); + pnum[pcount] = i; + pcount++; + } - cur->lastlook = i; + if (pcount) + { + mobj->threshold = pnum[P_RandomKey(pcount)]; + mobj->color = players[mobj->threshold].skincolor; + mobj->colorized = true; + break; + } + } - P_SetTarget(&cur->hprev, prev); - P_SetTarget(&prev->hnext, cur); + if (randu > (FRACUNIT/2)) + { + mobj->color = P_RandomKey(MAXSKINCOLORS-1)+1; + break; + } - prev = cur; + mobj->color = SKINCOLOR_AQUA; } - } - break; - case MT_BIGRING: - P_SetScale(mobj, (mobj->destscale = 3*FRACUNIT)); - break; - case MT_RANDOMAUDIENCE: - { - fixed_t randu = P_RandomFixed(); - P_SetScale(mobj, (mobj->destscale <<= 1)); - if (randu < (FRACUNIT/9)) // a fan of someone? - { - UINT8 i, pcount = 0; - UINT8 pnum[MAXPLAYERS]; - - for (i = 0; i < MAXPLAYERS; i++) - { - if (!playeringame[i]) - continue; - - pnum[pcount] = i; - pcount++; - } - - if (pcount) - { - mobj->threshold = pnum[P_RandomKey(pcount)]; - mobj->color = players[mobj->threshold].skincolor; - mobj->colorized = true; - break; - } - } - - if (randu > (FRACUNIT/2)) - { - mobj->color = P_RandomKey(MAXSKINCOLORS-1)+1; break; - } + case MT_KARMAHITBOX: + { + const fixed_t rad = FixedMul(mobjinfo[MT_PLAYER].radius, mobj->scale); + mobj_t *cur, *prev = mobj; + INT32 i; - mobj->color = SKINCOLOR_AQUA; - break; - } - case MT_MARBLETORCH: - P_SpawnMobj(mobj->x, mobj->y, mobj->z + (29*mobj->scale), MT_MARBLELIGHT); - break; - case MT_RUSTYLAMP_ORANGE: - P_SpawnMobj(mobj->x, mobj->y, mobj->z + (69*mobj->scale), MT_MARBLELIGHT); - break; - case MT_PINETREE: - { - angle_t diff = FixedAngle((360/mobj->info->mass)*FRACUNIT); - UINT8 i; + for (i = 0; i < 4; i++) + { + fixed_t offx = rad; + fixed_t offy = rad; - for (i = 0; i < mobj->info->mass; i++) + if (i == 1 || i == 3) + offx *= -1; + if (i == 2 || i == 3) + offy *= -1; + + cur = P_SpawnMobj(mobj->x + offx, mobj->y + offy, mobj->z, MT_KARMAWHEEL); + cur->destscale = mobj->scale; + P_SetScale(cur, mobj->scale); + + cur->lastlook = i; + + P_SetTarget(&cur->hprev, prev); + P_SetTarget(&prev->hnext, cur); + + prev = cur; + } + } + break; + case MT_TUMBLEGEM: + mobj->color = P_RandomKey(MAXSKINCOLORS - 1) + 1; + break; + case MT_BIGRING: + P_SetScale(mobj, (mobj->destscale = 3*FRACUNIT)); + break; + case MT_MARBLETORCH: + P_SpawnMobj(mobj->x, mobj->y, mobj->z + (29*mobj->scale), MT_MARBLELIGHT); + break; + case MT_RUSTYLAMP_ORANGE: + P_SpawnMobj(mobj->x, mobj->y, mobj->z + (69*mobj->scale), MT_MARBLELIGHT); + break; + case MT_PINETREE: { - angle_t ang = i * diff; - mobj_t *side = P_SpawnMobj(mobj->x + FINECOSINE((ang>>ANGLETOFINESHIFT) & FINEMASK), - mobj->y + FINESINE((ang>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_PINETREE_SIDE); - side->angle = ang; - P_SetTarget(&side->target, mobj); - side->threshold = i; - } - break; - } - case MT_EZZPROPELLER: - { - mobj_t *cur, *prev = mobj; - UINT8 i; + angle_t diff = FixedAngle((360/mobj->info->mass)*FRACUNIT); + UINT8 i; - for (i = 0; i < mobj->info->mass; i++) - { - mobj->angle = FixedAngle((i * (360/mobj->info->mass))<x + FINECOSINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), - mobj->y + FINESINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_EZZPROPELLER_BLADE); - cur->angle = mobj->angle; - - P_SetTarget(&cur->hprev, prev); - P_SetTarget(&prev->hnext, cur); - - prev = cur; - } - break; - } - case MT_ROBRA: - case MT_BLUEROBRA: - P_SetScale(mobj, (mobj->destscale = 1)); - break; - case MT_ROBRA_HEAD: - { - mobj_t *shell; - - shell = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_OVERLAY); - P_SetTarget(&shell->target, mobj); - P_SetMobjState(shell, S_ROBRASHELL_INSIDE); - - shell = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_OVERLAY); - P_SetTarget(&shell->target, mobj); - P_SetMobjState(shell, S_ROBRASHELL_OUTSIDE); - } - break; - case MT_EERIEFOGGEN: - { - UINT16 i; for (i = 0; i < mobj->info->mass; i++) { - fixed_t newx = mobj->x + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<z, 8<z) - P_SpawnMobj(newx, newy, mobj->z, MT_EERIEFOG); + angle_t ang = i * diff; + mobj_t *side = P_SpawnMobj(mobj->x + FINECOSINE((ang>>ANGLETOFINESHIFT) & FINEMASK), + mobj->y + FINESINE((ang>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_PINETREE_SIDE); + side->angle = ang; + P_SetTarget(&side->target, mobj); + side->threshold = i; } + break; } - break; - case MT_SMK_MOLE: - mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime/2); // Random delay on start of level - break; - case MT_SMK_THWOMP: - mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime); // Random delay on start of level - if (mobj->z == mobj->floorz) - mobj->z += (256<movefactor = mobj->z + (256<flags2 |= MF2_STANDONME; + case MT_EZZPROPELLER: { mobj_t *cur, *prev = mobj; UINT8 i; - for (i = 0; i < 4; i++) + for (i = 0; i < mobj->info->mass; i++) { - cur = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_SMK_ICEBLOCK_SIDE); - P_SetTarget(&cur->target, mobj); - cur->threshold = i; - P_MoveOrigin(cur, cur->x + ((cur->radius>>FRACBITS) * FINECOSINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), - cur->y + ((cur->radius>>FRACBITS) * FINESINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), cur->z); - cur->angle = ANGLE_90*(cur->threshold+1); + mobj->angle = FixedAngle((i * (360/mobj->info->mass))<x + FINECOSINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), + mobj->y + FINESINE(((mobj->angle*8)>>ANGLETOFINESHIFT) & FINEMASK), mobj->z, MT_EZZPROPELLER_BLADE); + cur->angle = mobj->angle; P_SetTarget(&cur->hprev, prev); P_SetTarget(&prev->hnext, cur); prev = cur; } + break; } - break; - case MT_TUMBLEGEM: - mobj->color = P_RandomKey(MAXSKINCOLORS - 1) + 1; - break; - default: - break; + case MT_ROBRA: + case MT_BLUEROBRA: + P_SetScale(mobj, (mobj->destscale = 1)); + break; + case MT_ROBRA_HEAD: + { + mobj_t *shell; + + shell = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_OVERLAY); + P_SetTarget(&shell->target, mobj); + P_SetMobjState(shell, S_ROBRASHELL_INSIDE); + + shell = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_OVERLAY); + P_SetTarget(&shell->target, mobj); + P_SetMobjState(shell, S_ROBRASHELL_OUTSIDE); + } + break; + case MT_EERIEFOGGEN: + { + UINT16 i; + for (i = 0; i < mobj->info->mass; i++) + { + fixed_t newx = mobj->x + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<z, 8<z) + P_SpawnMobj(newx, newy, mobj->z, MT_EERIEFOG); + } + } + break; + case MT_SMK_MOLE: + mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime/2); // Random delay on start of level + break; + case MT_SMK_THWOMP: + mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime); // Random delay on start of level + if (mobj->z == mobj->floorz) + mobj->z += (256<movefactor = mobj->z + (256<flags2 |= MF2_STANDONME; + { + mobj_t *cur, *prev = mobj; + UINT8 i; + + for (i = 0; i < 4; i++) + { + cur = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_SMK_ICEBLOCK_SIDE); + P_SetTarget(&cur->target, mobj); + cur->threshold = i; + P_MoveOrigin(cur, cur->x + ((cur->radius>>FRACBITS) * FINECOSINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), + cur->y + ((cur->radius>>FRACBITS) * FINESINE((FixedAngle((90*cur->threshold)<>ANGLETOFINESHIFT) & FINEMASK)), cur->z); + cur->angle = ANGLE_90*(cur->threshold+1); + + P_SetTarget(&cur->hprev, prev); + P_SetTarget(&prev->hnext, cur); + + prev = cur; + } + } + break; + case MT_SMALLBUBBLE: // Bubbles eventually dissipate, in case they get caught somewhere. + case MT_MEDIUMBUBBLE: + case MT_EXTRALARGEBUBBLE: + mobj->fuse += 30 * TICRATE; + break; + case MT_SPIKE: + mobj->flags2 |= MF2_STANDONME; + break; + case MT_CYBRAKDEMON_NAPALM_BOMB_LARGE: + mobj->fuse = mobj->info->mass; + break; + case MT_BLACKEGGMAN: + { + mobj_t *spawn = P_SpawnMobj(mobj->x, mobj->z, mobj->z+mobj->height-16*FRACUNIT, MT_BLACKEGGMAN_HELPER); + spawn->destscale = mobj->scale; + P_SetScale(spawn, mobj->scale); + P_SetTarget(&spawn->target, mobj); + } + break; + case MT_BLACKEGGMAN_HELPER: + // Collision helper can be stood on but not pushed + mobj->flags2 |= MF2_STANDONME; + break; + case MT_DETON: + mobj->movedir = 0; + break; + case MT_EGGGUARD: + { + mobj_t *spawn = P_SpawnMobj(x, y, z, MT_EGGSHIELD); + spawn->destscale = mobj->scale; + P_SetScale(spawn, mobj->scale); + P_SetTarget(&mobj->tracer, spawn); + P_SetTarget(&spawn->target, mobj); + } + break; + case MT_UNIDUS: + { + INT32 i; + mobj_t *ball; + // Spawn "damage" number of "painchance" spikeball mobjs + // threshold is the distance they should keep from the MT_UNIDUS (touching radius + ball painchance) + for (i = 0; i < mobj->info->damage; i++) + { + ball = P_SpawnMobj(x, y, z, mobj->info->painchance); + ball->destscale = mobj->scale; + P_SetScale(ball, mobj->scale); + P_SetTarget(&ball->target, mobj); + ball->movedir = FixedAngle(FixedMul(FixedDiv(i<info->damage<threshold = ball->radius + mobj->radius + FixedMul(ball->info->painchance, ball->scale); + + var1 = ball->state->var1, var2 = ball->state->var2; + ball->state->action(ball); + } + break; + } + case MT_POINTY: + { + INT32 q; + mobj_t *ball, *lastball = mobj; + + for (q = 0; q < mobj->info->painchance; q++) + { + ball = P_SpawnMobj(x, y, z, mobj->info->mass); + ball->destscale = mobj->scale; + P_SetScale(ball, mobj->scale); + P_SetTarget(&lastball->tracer, ball); + P_SetTarget(&ball->target, mobj); + lastball = ball; + } + break; + } + case MT_EGGMOBILE2: + // Special condition for the 2nd boss. + mobj->watertop = mobj->info->speed; + break; + case MT_BIRD: + case MT_BUNNY: + case MT_MOUSE: + case MT_CHICKEN: + case MT_COW: + case MT_REDBIRD: + mobj->fuse = P_RandomRange(300, 350); + break; + case MT_REDRING: // Make MT_REDRING red by default + mobj->color = skincolor_redring; + break; + case MT_EGGCAPSULE: + mobj->extravalue1 = -1; // timer for how long a player has been at the capsule + break; + case MT_REDTEAMRING: + mobj->color = skincolor_redteam; + break; + case MT_BLUETEAMRING: + mobj->color = skincolor_blueteam; + break; + case MT_RING: + case MT_COIN: + case MT_BLUEBALL: + nummaprings++; + break; + default: + break; + } } if (!(mobj->flags & MF_NOTHINK)) @@ -9828,13 +9847,6 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) switch (mobj->type) { case MT_PLAYER: - case MT_SMALLMACE: case MT_BIGMACE: - case MT_PUMA: case MT_BIGPUMA: - case MT_FALLINGROCK: - case MT_SMK_MOLE: case MT_SMK_THWOMP: - //case MT_RANDOMITEM: - case MT_FLOATINGITEM: - case MT_BATTLEBUMPER: case MT_BANANA: case MT_BANANA_SHIELD: //case MT_EGGMANITEM: case MT_EGGMANITEM_SHIELD: case MT_ORBINAUT: case MT_ORBINAUT_SHIELD: @@ -9843,6 +9855,13 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) case MT_BALLHOG: case MT_SINK: case MT_THUNDERSHIELD: case MT_ROCKETSNEAKER: case MT_SPB: + //case MT_RANDOMITEM: + case MT_FLOATINGITEM: + case MT_BATTLEBUMPER: + case MT_SMALLMACE: case MT_BIGMACE: + case MT_PUMA: case MT_BIGPUMA: + case MT_FALLINGROCK: + case MT_SMK_MOLE: case MT_SMK_THWOMP: P_SpawnShadowMobj(mobj); default: break; @@ -10059,9 +10078,9 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype // // P_RemoveMobj // -mapthing_t *itemrespawnque[ITEMQUESIZE]; -tic_t itemrespawntime[ITEMQUESIZE]; -size_t iquehead, iquetail; +mapthing_t *itemrespawnque[ITEMQUESIZE] = {}; +tic_t itemrespawntime[ITEMQUESIZE] = {}; +size_t iquehead = 0, iquetail = 0; #ifdef PARANOIA #define SCRAMBLE_REMOVED // Force debug build to crash when Removed mobj is accessed @@ -10077,25 +10096,13 @@ void P_RemoveMobj(mobj_t *mobj) LUA_HookMobj(mobj, MOBJ_HOOK(MobjRemoved)); mobj->thinker.function = (actionf_p1)P_MobjThinker; // needed for P_UnsetThingPosition, etc. to work. - // Rings only, please! - 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))) - { - itemrespawnque[iquehead] = mobj->spawnpoint; - itemrespawntime[iquehead] = leveltime; - iquehead = (iquehead+1)&(ITEMQUESIZE-1); - // lose one off the end? - if (iquehead == iquetail) - iquetail = (iquetail+1)&(ITEMQUESIZE-1); - } - - if (mobj->type == MT_KARMAHITBOX) // Remove linked list objects for certain types + if (mobj->type == MT_SHADOW) + P_RemoveShadow(mobj); + else if (mobj->type == MT_SPB) + spbplace = -1; + else if (mobj->type == MT_OVERLAY) + P_RemoveOverlay(mobj); + else if (mobj->type == MT_KARMAHITBOX) // Remove linked list objects for certain types { mobj_t *cur = mobj->hnext; @@ -10106,15 +10113,23 @@ void P_RemoveMobj(mobj_t *mobj) P_RemoveMobj(prev); } } - - if (UNLIKELY(mobj->type == MT_OVERLAY)) - P_RemoveOverlay(mobj); - - if (UNLIKELY(mobj->type == MT_SHADOW)) - P_RemoveShadow(mobj); - - if (UNLIKELY(mobj->type == MT_SPB)) - spbplace = -1; + // Rings only, please! + else if (UNLIKELY(mobj->spawnpoint && + !(mobj->flags2 & MF2_DONTRESPAWN) && + (mobj->type == MT_RING + || mobj->type == MT_COIN + || mobj->type == MT_BLUEBALL + || mobj->type == MT_REDTEAMRING + || mobj->type == MT_BLUETEAMRING + || P_WeaponOrPanel(mobj->type)))) + { + itemrespawnque[iquehead] = mobj->spawnpoint; + itemrespawntime[iquehead] = leveltime; + iquehead = (iquehead+1)&(ITEMQUESIZE-1); + // lose one off the end? + if (iquehead == iquetail) + iquetail = (iquetail+1)&(ITEMQUESIZE-1); + } mobj->health = 0; // Just because @@ -10448,6 +10463,24 @@ void P_PrecipitationEffects(void) } } +mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1] = {}; + +void CalculateDoomednumToMobjtype(void) +{ + memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); + + for (size_t i = 0; i < NUMMOBJTYPES; i++) + { + const INT32 doomednum = mobjinfo[i].doomednum; + + if (doomednum > 0 && doomednum <= MAXDOOMEDNUM) + { + if (g_doomednum_to_mobjtype[doomednum] == MT_NULL) + g_doomednum_to_mobjtype[doomednum] = (mobjtype_t)i; + } + } +} + // // P_RespawnSpecials // @@ -10521,17 +10554,15 @@ void P_RespawnSpecials(void) if (mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; ss = R_PointInSubsector(x, y); // find which type to spawn - for (i = 0; i < NUMMOBJTYPES; i++) - if (mthing->type == mobjinfo[i].doomednum) - break; + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) // prevent creation of objects with this type -- Monster Iestyn 17/12/17 + if (i <= MT_NULL || i >= NUMMOBJTYPES) // prevent creation of objects with this type -- Monster Iestyn 17/12/17 { // 3D Mode start Thing is unlikely to be added to the que, // so don't bother checking for that specific type @@ -10668,8 +10699,9 @@ void P_SpawnPlayer(INT32 playernum) mobj = P_SpawnMobj(0, 0, 0, MT_PLAYER); I_Assert(mobj != NULL); (mobj->player = p)->mo = mobj; + //P_SetTarget(&p->mo, mobj); - mobj->angle = 0; + mobj->angle = mobj->old_angle = 0; // set color translations for player sprites mobj->color = p->skincolor; @@ -10776,14 +10808,13 @@ void P_AfterPlayerSpawn(INT32 playernum) mobj_t *mobj = p->mo; UINT8 i; - for (i = 0; i <= splitscreen; i++) - { - if (playernum == P_GetLocalPlayerNumForNum(i)) - { - localangle[i] = mobj->angle; - break; - } - } + // Update interpolation + mobj->old_x = mobj->x; + mobj->old_y = mobj->y; + mobj->old_z = mobj->z; + mobj->old_angle = mobj->angle; + + P_ForceLocalAngle(p, mobj->angle); p->viewheight = 32<type == mobjinfo[i].doomednum) - break; + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) + if (i <= MT_NULL || i >= NUMMOBJTYPES) { if (mthing->type == 3328) // 3D Mode start Thing return; @@ -11044,13 +11073,9 @@ void P_SpawnMapThing(mapthing_t *mthing) } // find which type to spawn - for (i = 0; i < NUMMOBJTYPES; i++) - { - if (mthing->type == mobjinfo[i].doomednum) - break; - } + i = g_doomednum_to_mobjtype[mthing->type]; - if (i == NUMMOBJTYPES) + if (i <= MT_NULL || i >= NUMMOBJTYPES) { if (mthing->type == 3328) // 3D Mode start Thing return; @@ -11743,32 +11768,32 @@ ML_NOCLIMB : Direction not controllable if (mobj->flags & MF_MONITOR) { // flag for strong/weak random boxes - if (mthing->type == mobjinfo[MT_SUPERRINGBOX].doomednum || mthing->type == mobjinfo[MT_PRUP].doomednum || - mthing->type == mobjinfo[MT_SNEAKERTV].doomednum || mthing->type == mobjinfo[MT_INV].doomednum || - mthing->type == mobjinfo[MT_WHITETV].doomednum || mthing->type == mobjinfo[MT_GREENTV].doomednum || - mthing->type == mobjinfo[MT_YELLOWTV].doomednum || mthing->type == mobjinfo[MT_BLUETV].doomednum || - mthing->type == mobjinfo[MT_BLACKTV].doomednum || mthing->type == mobjinfo[MT_PITYTV].doomednum || - mthing->type == mobjinfo[MT_RECYCLETV].doomednum || mthing->type == mobjinfo[MT_MIXUPBOX].doomednum) + if (i == MT_SUPERRINGBOX || i == MT_PRUP || + i == MT_SNEAKERTV || i == MT_INV || + i == MT_WHITETV || i == MT_GREENTV || + i == MT_YELLOWTV || i == MT_BLUETV || + i == MT_BLACKTV || i == MT_PITYTV || + i == MT_RECYCLETV || i == MT_MIXUPBOX) mobj->flags2 |= MF2_AMBUSH; } - - else if (mthing->type != mobjinfo[MT_AXIS].doomednum && - mthing->type != mobjinfo[MT_AXISTRANSFER].doomednum && - mthing->type != mobjinfo[MT_AXISTRANSFERLINE].doomednum && - mthing->type != mobjinfo[MT_NIGHTSBUMPER].doomednum && - mthing->type != mobjinfo[MT_STARPOST].doomednum) + else if ( + i != MT_AXIS && + i != MT_AXISTRANSFER && + i != MT_AXISTRANSFERLINE && + i != MT_NIGHTSBUMPER && + i != MT_STARPOST) mobj->flags2 |= MF2_AMBUSH; } if (mthing->options & MTF_OBJECTSPECIAL) { // flag for strong/weak random boxes - if (mthing->type == mobjinfo[MT_SUPERRINGBOX].doomednum || mthing->type == mobjinfo[MT_PRUP].doomednum || - mthing->type == mobjinfo[MT_SNEAKERTV].doomednum || mthing->type == mobjinfo[MT_INV].doomednum || - mthing->type == mobjinfo[MT_WHITETV].doomednum || mthing->type == mobjinfo[MT_GREENTV].doomednum || - mthing->type == mobjinfo[MT_YELLOWTV].doomednum || mthing->type == mobjinfo[MT_BLUETV].doomednum || - mthing->type == mobjinfo[MT_BLACKTV].doomednum || mthing->type == mobjinfo[MT_PITYTV].doomednum || - mthing->type == mobjinfo[MT_RECYCLETV].doomednum || mthing->type == mobjinfo[MT_MIXUPBOX].doomednum) + if (i == MT_SUPERRINGBOX || i == MT_PRUP || + i == MT_SNEAKERTV || i == MT_INV || + i == MT_WHITETV || i == MT_GREENTV || + i == MT_YELLOWTV || i == MT_BLUETV || + i == MT_BLACKTV || i == MT_PITYTV || + i == MT_RECYCLETV || i == MT_MIXUPBOX) mobj->flags2 |= MF2_STRONGBOX; // Requires you to be in bonus time to activate diff --git a/src/p_mobj.h b/src/p_mobj.h index 781b86390..38bbe2e37 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -285,7 +285,7 @@ typedef struct mobj_s // Info for drawing: position. fixed_t x, y, z; fixed_t old_x, old_y, old_z; // position interpolation - fixed_t old_x2, old_y2, old_z2; + fixed_t old_z2; // ok guess we need that... // More list: links in sector (if needed) struct mobj_s *bnext; @@ -297,7 +297,6 @@ typedef struct mobj_s // More drawing info: to determine current sprite. angle_t angle, pitch, roll; // orientation angle_t old_angle, old_pitch, old_roll; // orientation interpolation - angle_t old_angle2, old_pitch2, old_roll2; angle_t rollangle; spritenum_t sprite; // used to find patch_t and flip value UINT32 frame; // frame number, plus bits see p_pspr.h @@ -307,9 +306,7 @@ typedef struct mobj_s fixed_t spritexscale, spriteyscale; fixed_t spritexoffset, spriteyoffset; fixed_t old_spritexscale, old_spriteyscale; - fixed_t old_spritexscale2, old_spriteyscale2; fixed_t old_spritexoffset, old_spriteyoffset; - fixed_t old_spritexoffset2, old_spriteyoffset2; INT16 lightlevel; // Add to sector lightlevel, -255 - 255 fixed_t realxscale, realyscale; // funn-E streeetch @@ -320,7 +317,6 @@ typedef struct mobj_s //sloperollangle angle_t sloperoll, slopepitch; angle_t old_sloperoll, old_slopepitch; - angle_t old_sloperoll2, old_slopepitch2; angle_t pitch_sprite, roll_sprite; struct msecnode_s *touching_sectorlist; // a linked list of sectors where this object appears @@ -395,7 +391,6 @@ typedef struct mobj_s fixed_t scale; fixed_t old_scale; // interpolation - fixed_t old_scale2; fixed_t destscale; fixed_t scalespeed; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 15090a7ea..94c808b22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1383,13 +1383,9 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, { mo->angle += delta; - for (UINT8 i = 0; i <= splitscreen; i++) + if (mo->player) { - if (mo->player == P_GetLocalPlayerForNum(i)) - { - localangle[i] += delta; - break; - } + P_ForceLocalAngle(mo->player, P_GetLocalAngle(mo->player) + delta); } } } diff --git a/src/p_saveg.c b/src/p_saveg.c index 7c2bd9e95..64686dfd4 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -339,7 +339,7 @@ static void P_NetUnArchivePlayers(savebuffer_t *save, boolean reloading) for (j = 0; j < NUMKARTSTUFF; j++) player->kartstuff[j] = READINT32(save->p); - player->frameangle = READANGLE(save->p); + player->frameangle = player->old_frameangle = READANGLE(save->p); player->playerstate = READUINT8(save->p); player->pflags = READUINT32(save->p); @@ -1965,21 +1965,6 @@ FUNCINLINE static ATTRINLINE player_t *LoadPlayer(UINT32 player) // Loads a mobj_t from a save game // -static mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; - -static void CalculateDoomednumToMobjtype(void) -{ - memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); - - for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) - { - if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) - { - g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; - } - } -} - static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) { mobj_t *mobj; @@ -2052,15 +2037,15 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) if (diff & MD_POS) { - mobj->x = READFIXED(save->p); - mobj->y = READFIXED(save->p); - mobj->angle = READANGLE(save->p); + mobj->x = mobj->old_x = READFIXED(save->p); + mobj->y = mobj->old_y = READFIXED(save->p); + mobj->angle = mobj->old_angle = READANGLE(save->p); } else { - mobj->x = mobj->spawnpoint->x << FRACBITS; - mobj->y = mobj->spawnpoint->y << FRACBITS; - mobj->angle = FixedAngle(mobj->spawnpoint->angle*FRACUNIT); + mobj->x = mobj->old_x = mobj->spawnpoint->x << FRACBITS; + mobj->y = mobj->old_y = mobj->spawnpoint->y << FRACBITS; + mobj->angle = mobj->old_angle = FixedAngle(mobj->spawnpoint->angle*FRACUNIT); } if (diff & MD_MOM) @@ -2122,12 +2107,6 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) i = READUINT8(save->p); mobj->player = &players[i]; mobj->player->mo = mobj; - - // added for angle prediction - if (i == P_GetLocalPlayerNumForNum(i)) - { - localangle[i] = mobj->angle; - } } if (diff & MD_MOVEDIR) mobj->movedir = READANGLE(save->p); @@ -2885,10 +2864,6 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) if (READUINT32(save->p) != ARCHIVEBLOCK_THINKERS) I_Error("Bad $$$.sav at archive block Thinkers"); - // Pre-calculate this lookup, because it was wasting - // a shit ton of time loading mobj thinkers. - CalculateDoomednumToMobjtype(); - // remove all the current thinkers for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = next) { diff --git a/src/p_setup.c b/src/p_setup.c index 6491a4099..bf40afe9d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -15,6 +15,7 @@ #include "d_main.h" #include "byteptr.h" #include "g_game.h" +#include "g_input.h" #include "p_local.h" #include "p_setup.h" @@ -596,8 +597,8 @@ FUNCINLINE static ATTRINLINE void P_LoadSubsectors(void *data) // #define MAXLEVELFLATS 256 -size_t numlevelflats; -levelflat_t *levelflats; +size_t numlevelflats = 0; +levelflat_t *levelflats = NULL; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) @@ -679,11 +680,11 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat) if (i == numlevelflats) { // store the name - strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); + strlcpy(levelflat->name, flatname, sizeof(levelflat->name)); strupr(levelflat->name); // store the flat lump number - levelflat->lumpnum = R_GetFlatNumForName(flatname); + levelflat->lumpnum = R_GetFlatNumForName(levelflat->name); levelflat->baselumpnum = LUMPERROR; P_CheckCyanFlat(levelflat); @@ -726,11 +727,11 @@ INT32 P_AddLevelFlatRuntime(const char *flatname) levelflat = levelflats+i; // store the name - strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); + strlcpy(levelflat->name, flatname, sizeof(levelflat->name)); strupr(levelflat->name); // store the flat lump number - levelflat->lumpnum = R_GetFlatNumForName(flatname); + levelflat->lumpnum = R_GetFlatNumForName(levelflat->name); levelflat->baselumpnum = LUMPERROR; P_CheckCyanFlat(levelflat); @@ -1021,7 +1022,7 @@ void P_WriteThings(lumpnum_t lumpnum) size_t i, length; mapthing_t *mt; UINT8 *data; - savebuffer_t save; + savebuffer_t save = {0}; INT16 temp; data = W_CacheLumpNum(lumpnum, PU_LEVEL); @@ -2029,8 +2030,8 @@ void P_SetupLevelSky(INT32 skynum, boolean global) R_SetupSkyDraw(); } -static const char *maplumpname; -lumpnum_t lastloadedmaplumpnum; // for comparative savegame +static const char *maplumpname = NULL; +lumpnum_t lastloadedmaplumpnum = LUMPERROR; // for comparative savegame // // P_LevelInitStuff @@ -2414,7 +2415,7 @@ static void P_InitCamera(void) displayplayers[0] = consoleplayer; // Start with your OWN view, please! } -struct minimapinfo minimapinfo; +struct minimapinfo minimapinfo = {}; static void P_InitMinimapInfo(void) { lumpnum_t lumpnum; @@ -2708,8 +2709,12 @@ void P_FreeLevelState(void) G_FreeGhosts(); // ghosts are allocated with PU_LEVEL - Patch_FreeTag(PU_PATCH_LOWPRIORITY); - //Patch_FreeTag(PU_PATCH_ROTATED); // we keep those ty! + if (rendermode != render_none) + { + Patch_FreeTag(PU_PATCH_LOWPRIORITY); + //Patch_FreeTag(PU_PATCH_ROTATED); // we keep those ty! + } + Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1); Y_VoteClear(); @@ -2718,6 +2723,9 @@ void P_FreeLevelState(void) // clear the splats from previous level R_ClearLevelSplats(); #endif + + R_InitMobjInterpolators(); + R_InitializeLevelInterpolators(); } /** Loads a level from a lump or external wad. @@ -2735,13 +2743,8 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) lumpnum_t encoreLump = LUMPERROR; UINT8 levelfadecol; - // HACK: this doesent reset if you change the map from within a replay and may cause crashes or the replayhut to be non functional - if (!demo.playback && demo.inreplayhut) - { - M_ResetDemoList(); - } - midgamejoin = fromnetsave; // makes dynslopes run in P_Ticker/P_PreTicker to avoid synch issues and other stuff + midgamejoin = fromnetsave; // makes dynslopes run in P_Ticker to avoid synch issues and other stuff levelloading = true; @@ -2827,10 +2830,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) P_FreeLevelState(); - R_InitializeLevelInterpolators(); - P_InitThinkers(); - R_InitMobjInterpolators(); P_InitCachedActions(); // internal game map @@ -2861,6 +2861,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) P_ResetDynamicSlopes(); + // Pre-calculate this lookup, because it was wasting + // a shit ton of time loading mobj thinkers. + CalculateDoomednumToMobjtype(); + P_SpawnMapThings(); P_SpawnEmblems(!fromnetsave); @@ -2979,7 +2983,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) G_AddMapToBuffer(gamemap-1); - D_ResetDeviceLED(); + G_ResetDeviceLED(); return true; } diff --git a/src/p_slopes.c b/src/p_slopes.c index 2ec2898b9..b3f4592d6 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -338,19 +338,12 @@ void P_SpawnSlope_Line(int linenum) vector3_t origin, point; vector2_t direction; fixed_t nx, ny, dz, extent; - - boolean frontfloor = (special == 700 || special == 702 || special == 703); - boolean backfloor = (special == 710 || special == 712 || special == 713); - boolean frontceil = (special == 701 || special == 702 || special == 713); - boolean backceil = (special == 711 || special == 712 || special == 703); - UINT8 flags = 0; // Slope flags - if (line->flags & ML_NOSONIC) - flags |= SL_NOPHYSICS; - if (!(line->flags & ML_NOTAILS)) - flags |= SL_NODYNAMIC; - if (line->flags & ML_NOKNUX) - flags |= SL_ANCHORVERTEX; + + const boolean frontfloor = (special == 700 || special == 702 || special == 703); + const boolean backfloor = (special == 710 || special == 712 || special == 713); + const boolean frontceil = (special == 701 || special == 702 || special == 713); + const boolean backceil = (special == 711 || special == 712 || special == 703); if (!frontfloor && !backfloor && !frontceil && !backceil) { @@ -364,6 +357,13 @@ void P_SpawnSlope_Line(int linenum) return; } + if (line->flags & ML_NOSONIC) + flags |= SL_NOPHYSICS; + if (!(line->flags & ML_NOTAILS)) + flags |= SL_NODYNAMIC; + if (line->flags & ML_NOKNUX) + flags |= SL_ANCHORVERTEX; + fixed_t len = R_PointToDist2(0, 0, line->dx, line->dy); nx = FixedDiv(line->dy, len); ny = -FixedDiv(line->dx, len); @@ -809,7 +809,7 @@ void P_ResetDynamicSlopes(void) if (lines[i].flags & ML_NOKNUX) *slopetoset = P_NewVertexSlope(lines[i].tag, sides[lines[i].sidenum[which]].textureoffset >> FRACBITS, - sides[lines[i].sidenum[which]].rowoffset >> FRACBITS, flags); + sides[lines[i].sidenum[which]].rowoffset >> FRACBITS, flags); else *slopetoset = P_NewVertexSlope(lines[i].tag, lines[i].tag, lines[i].tag, flags); diff --git a/src/p_spec.c b/src/p_spec.c index cf8f76503..66901d234 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -53,7 +53,7 @@ mobj_t *skyboxmo[2] = {}; #define MAXFLATSIZE (2048<speed = animdefs[i].speed; - else - lastanim->speed = LONG(animdefs[i].speed); + lastanim->speed = LONG(animdefs[i].speed); lastanim++; } @@ -330,8 +226,7 @@ void P_InitPicAnims(void) // Clear animdefs now that we're done with it. // We'll only be using anims from now on. - if (animdefs != harddefs) - Z_Free(animdefs); + Z_Free(animdefs); animdefs = NULL; } @@ -1978,13 +1873,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { P_RemoveThinker(&((elevator_t *)sectors[secnum].floordata)->thinker); sectors[secnum].floordata = sectors[secnum].ceilingdata = NULL; - sectors[secnum].floorspeed = sectors[secnum].ceilspeed = 0; } else // floormove { P_RemoveThinker(&((floormove_t *)sectors[secnum].floordata)->thinker); sectors[secnum].floordata = NULL; - sectors[secnum].floorspeed = 0; } } @@ -1992,7 +1885,6 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { P_RemoveThinker(&((ceiling_t *)sectors[secnum].ceilingdata)->thinker); sectors[secnum].ceilingdata = NULL; - sectors[secnum].ceilspeed = 0; } } break; @@ -2087,13 +1979,17 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Seek offset from current song position if (line->flags & ML_EFFECT1) { + const UINT32 muslength = S_GetMusicLength(); + const UINT32 muspos = S_GetMusicPosition(); + const UINT32 muslooppoint = S_GetMusicLoopPoint(); + // adjust for loop point if subtracting - if (position < 0 && S_GetMusicLength() && - S_GetMusicPosition() > S_GetMusicLoopPoint() && - S_GetMusicPosition() + position < S_GetMusicLoopPoint()) - position = max(S_GetMusicLength() - (S_GetMusicLoopPoint() - (S_GetMusicPosition() + position)), 0); + if (position < 0 && muslength && + muspos > muslooppoint && + muspos + position < muslooppoint) + position = max(muslength - (muslooppoint - (muspos + position)), 0); else - position = max(S_GetMusicPosition() + position, 0); + position = max(muspos + position, 0); } // Fade current music to target volume (if music won't be changed) @@ -2160,11 +2056,13 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (sfxnum == sfx_None) return; // Do nothing! + if (sfxnum < sfx_None || sfxnum >= NUMSFX) { CONS_Debug(DBG_GAMELOGIC, "Line type 414 Executor: sfx number %d is invalid!\n", sfxnum); return; } + if (line->tag != 0) // Do special stuff only if a non-zero linedef tag is set { if (line->flags & ML_EFFECT5) // Repeat Midtexture @@ -3553,14 +3451,7 @@ DoneSection2: if (!demo.playback || P_AnalogMove(player)) { - for (UINT8 j = 0; j <= splitscreen; ++j) - { - if (player == P_GetLocalPlayerForNum(j)) - { - localangle[j] = player->mo->angle; - break; - } - } + P_ForceLocalAngle(player, player->mo->angle); } if (!(lines[i].flags & ML_EFFECT4)) @@ -7511,22 +7402,16 @@ void T_Pusher(pusher_t *p) thing->player->pflags |= PF_JUMPED; thing->player->pflags |= PF_SLIDING; - thing->angle = R_PointToAngle2 (0, 0, xspeed<<(FRACBITS-PUSH_FACTOR), yspeed<<(FRACBITS-PUSH_FACTOR)); + thing->angle = R_PointToAngle2(0, 0, xspeed<<(FRACBITS-PUSH_FACTOR), yspeed<<(FRACBITS-PUSH_FACTOR)); if (!demo.playback || P_AnalogMove(thing->player)) { - for (UINT8 i = 0; i <= splitscreen; ++i) - { - if (thing->player == P_GetLocalPlayerForNum(i)) - { - if (thing->angle - localangle[i] > ANGLE_180) - localangle[i] -= (localangle[i] - thing->angle) / 8; - else - localangle[i] += (thing->angle - localangle[i]) / 8; + angle_t angle = P_GetLocalAngle(thing->player); - break; - } - } + if (thing->angle - angle > ANGLE_180) + P_ForceLocalAngle(thing->player, angle - (angle - thing->angle) / 8); + else + P_ForceLocalAngle(thing->player, angle + (thing->angle - angle) / 8); } } diff --git a/src/p_telept.c b/src/p_telept.c index 539e0050b..20f53d396 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -65,14 +65,7 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, thing->reactiontime = TICRATE/2; // don't move for about half a second // absolute angle position - for (i = 0; i <= splitscreen; i++) - { - if (thing == P_GetLocalPlayerForNum(i)->mo) - { - localangle[i] = angle; - break; - } - } + P_ForceLocalAngle(thing->player, angle); // move chasecam at new player location for (i = 0; i <= splitscreen; i++) @@ -106,6 +99,7 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, P_FlashPal(thing->player, PAL_MIXUP, 10); } + thing->old_angle += (angle-thing->angle); thing->angle = angle; thing->momx = thing->momy = thing->momz = 0; @@ -150,18 +144,18 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle thing->reactiontime = TICRATE/2; // don't move for about half a second // absolute angle position + P_ForceLocalAngle(thing->player, angle); + // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { if (thing->player != &players[displayplayers[i]]) continue; - localangle[i] = angle; if (camera[i].chase) P_ResetCamera(thing->player, &camera[i]); R_ResetViewInterpolation(i + 1); - break; } // don't run in place after a teleport diff --git a/src/p_tick.c b/src/p_tick.c index d8b21aa86..88e8fb2fd 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -457,113 +457,6 @@ static inline void P_RunThinkers(void) } } -// Controller rumble! -// this keeps track of a bunch of things -// and makes your controller rumble accordingly -static void P_DeviceRumbleTick(void) -{ - UINT8 i; - - if (dedicated || numcontrollers == 0 || gamestate != GS_LEVEL) - { - return; - } - - for (i = 0; i <= splitscreen; i++) - { - if (!cv_usejoystick[i].value || !cv_rumble[i].value) - { - continue; - } - - if (camera[i].freecam) - { - continue; - } - - UINT16 low = 0, high = 0; - UINT16 lenght = 57; // in ms - - const player_t *player = P_GetLocalPlayerForNum(i); - - // allow lua to do some crap for spectators - if (player->spectator || !player->mo) - { - continue; - } - - // reset the rumble if you exit or are ded lel - if (player->exiting || - player->playerstate == PST_DEAD || - player->kartstuff[k_respawn] > 1) - { - G_PlayerDeviceRumble(i, low, high, 0); - continue; - } - - if (player->kartstuff[k_spinouttimer]) - { - //low = high = FRACUNIT / 6; - low = high = FixedMul((FRACUNIT / 4), (FixedDiv(player->kartstuff[k_spinouttimer], (3*TICRATE / 2)))); // try do some some kinda fadeout - } - else if (player->kartstuff[k_sneakertimer] > (sneakertime-(TICRATE/2))) - { - low = high = FRACUNIT / 8; - } - else if ((player->kartstuff[k_offroad]) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - // weaken this depending on if you got hyu or invinc - if (player->kartstuff[k_hyudorotimer]) - { - high = FRACUNIT / 128; - } - else if (player->kartstuff[k_invincibilitytimer]) - { - high = FRACUNIT / 64; - } - else - { - low = high = FRACUNIT / 64; - } - } - else if ((player->kartstuff[k_bananadrag] > TICRATE) - && player->speed != 0 - && P_IsObjectOnGround(player->mo)) - { - if (leveltime & 1) // this is actually funny lel - high = FRACUNIT / 64; - } - - if (player->kartstuff[k_brakedrift]) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - } - - // pulse when gettin new driftlevel - // let this come last - if (player->kartstuff[k_driftcharge] - && player->driftlevel) - { - high = CLAMP((high + FRACUNIT / 256), 0, UINT16_MAX); - - if (player->driftlevel == 2) - lenght = 114; - else if (player->driftlevel == 3) - lenght = 174; - } - - // hack alert! i just dont want this thing constantly resetting the rumble lol - if (low == 0 && high == 0) - { - continue; - } - - G_PlayerDeviceRumble(i, low, high, lenght); - } -} - void P_RunChaseCameras(void) { UINT8 i; @@ -763,7 +656,7 @@ void P_Ticker(boolean run) // Apply rumble to local players if (!demo.playback) { - P_DeviceRumbleTick(); + G_DeviceRumbleTick(); } PS_START_TIMING(ps_lua_thinkframe_time); @@ -943,10 +836,6 @@ void P_PreTicker(INT32 frames) } } - // Dynamic slopeness - if (midgamejoin) - P_RunDynamicSlopes(); - P_RunThinkers(); // Run any "after all the other thinkers" stuff diff --git a/src/p_user.c b/src/p_user.c index d0967c5b6..2a3ccc300 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -47,6 +47,7 @@ // SRB2kart #include "m_cond.h" // M_UpdateUnlockablesAndExtraEmblems #include "k_kart.h" +#include "k_hud.h" #include "console.h" // CON_LogMessage #include "m_menu.h" @@ -77,7 +78,6 @@ void P_Thrust(mobj_t *mo, angle_t angle, fixed_t move) mo->momy += FixedMul(move, FINESINE(angle)); } - // // P_InstaThrust // Moves the given origin along a given angle instantly. @@ -213,12 +213,11 @@ UINT8 P_GetNextEmerald(void) if (!(emeralds & EMERALD6)) return 5; return 6; } - else // Depends on stage - { - if (gamemap < sstage_start || gamemap > sstage_end) - return 0; - return (UINT8)(gamemap - sstage_start); - } + + // Depends on stage + if (gamemap < sstage_start || gamemap > sstage_end) + return 0; + return (UINT8)(gamemap - sstage_start); } // @@ -239,10 +238,11 @@ void P_GiveEmerald(boolean spawnObj) if (spawnObj) { for (i = 0; i < MAXPLAYERS; i++) + { if (playeringame[i]) P_SetMobjState(P_SpawnMobj(players[i].mo->x, players[i].mo->y, players[i].mo->z + players[i].mo->info->height, MT_GOTEMERALD), mobjinfo[MT_GOTEMERALD].spawnstate + em); - + } } } @@ -352,9 +352,9 @@ void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor) player->mo->z++; if (player->mo->eflags & MFE_UNDERWATER) - P_SetObjectMomZ(player->mo, FixedDiv(10511*FRACUNIT,2600*FRACUNIT), false); + P_SetObjectMomZ(player->mo, FixedDiv(10511*FRACUNIT, 2600*FRACUNIT), false); else - P_SetObjectMomZ(player->mo, FixedDiv(69*FRACUNIT,10*FRACUNIT), false); + P_SetObjectMomZ(player->mo, FixedDiv(69*FRACUNIT, 10*FRACUNIT), false); } ang = R_PointToAngle2(inflictor->x, inflictor->y, player->mo->x, player->mo->y); // SRB2kart @@ -434,8 +434,8 @@ void P_GivePlayerRings(player_t *player, INT32 num_rings) if (!player->mo) return; - player->mo->health += num_rings; - player->health += num_rings; + //player->mo->health += num_rings; + //player->health += num_rings; player->totalring += num_rings; //{ SRB2kart - rings don't really do anything, but we don't want the player spilling them later. @@ -581,7 +581,8 @@ static boolean isPlayerLosing(player_t *player) if (players[i].marescore > player->marescore) ++pos; - maxpos = max(getPlayerPos(&players[i]), maxpos); + const UINT8 playerpos = getPlayerPos(&players[i]); + maxpos = max(playerpos, maxpos); } if (maxpos == 1) @@ -618,11 +619,11 @@ boolean P_EndingMusic(player_t *player) // Check for if this is valid or not if (splitscreen) { - if (!((players[displayplayers[0]].exiting || (players[displayplayers[0]].pflags & PF_TIMEOVER)) - || (players[displayplayers[1]].exiting || (players[displayplayers[1]].pflags & PF_TIMEOVER)) - || ((splitscreen < 2) && (players[displayplayers[2]].exiting || (players[displayplayers[2]].pflags & PF_TIMEOVER))) - || ((splitscreen < 3) && (players[displayplayers[3]].exiting || (players[displayplayers[3]].pflags & PF_TIMEOVER))))) - return false; + for (UINT8 i = 0; i <= splitscreen; i++) + { + if (!(players[displayplayers[i]].exiting || (players[displayplayers[i]].pflags & PF_TIMEOVER))) + return false; + } bestlocalplayer = &players[displayplayers[0]]; bestlocalpos = ((players[displayplayers[0]].pflags & PF_TIMEOVER) ? MAXPLAYERS+1 : getPlayerPos(&players[displayplayers[0]])); @@ -702,71 +703,74 @@ void P_RestoreMusic(player_t *player) // Event - Level Start if (leveltime < MUSICSTARTTIME) - S_StartMapMusic(); - else // see also where time overs are handled - search for "lives = 2" in this file { - INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow + S_StartMapMusic(); + return; + } - if (splitscreen) - { - INT32 bestlocaltimer = 1; + // see also where time overs are handled - search for "lives = 2" in this file + INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow + + if (splitscreen) + { + INT32 bestlocaltimer = 1; #define setbests(p) \ - if (players[p].playerstate == PST_LIVE) \ - { \ - if (players[p].kartstuff[k_growshrinktimer] > bestlocaltimer) \ - { wantedmus = 2; bestlocaltimer = players[p].kartstuff[k_growshrinktimer]; } \ - else if (players[p].kartstuff[k_invincibilitytimer] > bestlocaltimer) \ - { wantedmus = 1; bestlocaltimer = players[p].kartstuff[k_invincibilitytimer]; } \ - } - setbests(displayplayers[0]); - setbests(displayplayers[1]); - if (splitscreen > 1) - setbests(displayplayers[2]); - if (splitscreen > 2) - setbests(displayplayers[3]); + if (players[p].playerstate == PST_LIVE) \ + { \ + if (players[p].kartstuff[k_growshrinktimer] > bestlocaltimer) \ + { wantedmus = 2; bestlocaltimer = players[p].kartstuff[k_growshrinktimer]; } \ + else if (players[p].kartstuff[k_invincibilitytimer] > bestlocaltimer) \ + { wantedmus = 1; bestlocaltimer = players[p].kartstuff[k_invincibilitytimer]; } \ + } + + setbests(displayplayers[0]); + setbests(displayplayers[1]); + if (splitscreen > 1) + setbests(displayplayers[2]); + if (splitscreen > 2) + setbests(displayplayers[3]); #undef setbests - } - else + } + else + { + if (player->playerstate == PST_LIVE) { - if (player->playerstate == PST_LIVE) - { - if (player->kartstuff[k_growshrinktimer] > 1) - wantedmus = 2; - else if (player->kartstuff[k_invincibilitytimer] > 1) - wantedmus = 1; - } + if (player->kartstuff[k_growshrinktimer] > 1) + wantedmus = 2; + else if (player->kartstuff[k_invincibilitytimer] > 1) + wantedmus = 1; } + } - // Item - Grow - if (wantedmus == 2 && cv_growmusic.value == 1) - { - S_ChangeMusicInternal("kgrow", true); - S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); - } - // Item - Invincibility - else if (wantedmus == 1 && cv_supermusic.value == 1) - { - S_ChangeMusicInternal("kinvnc", true); - S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); - } - else - { + // Item - Grow + if (wantedmus == 2 && cv_growmusic.value == 1) + { + S_ChangeMusicInternal("kgrow", true); + S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); + } + // Item - Invincibility + else if (wantedmus == 1 && cv_supermusic.value == 1) + { + S_ChangeMusicInternal("kinvnc", true); + S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); + } + else + { #if 0 - // Event - Final Lap - // Still works for GME, but disabled for consistency - if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) - S_SpeedMusic(1.2f); + // Event - Final Lap + // Still works for GME, but disabled for consistency + if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) + S_SpeedMusic(1.2f); #endif - if (mapmusic.resume && cv_resume.value) // mapmusresume will be 0 anyways when birdmusic stuff is disabled - position = mapmusic.resume; - else - position = mapmusic.position; + if (mapmusic.resume && cv_resume.value) // mapmusresume will be 0 anyways when birdmusic stuff is disabled + position = mapmusic.resume; + else + position = mapmusic.position; - S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, position, 0, S_GetRestoreMusicFadeIn()); - S_ClearRestoreMusicFadeInCvar(); - mapmusic.resume = 0; - } + S_ChangeMusicEx(mapmusic.name, mapmusic.flags, true, position, 0, S_GetRestoreMusicFadeIn()); + S_ClearRestoreMusicFadeInCvar(); + mapmusic.resume = 0; } } @@ -970,7 +974,18 @@ fixed_t P_GetPlayerHeight(player_t *player) // fixed_t P_GetPlayerSpinHeight(player_t *player) { - return FixedMul(FixedMul(player->mo->info->height, player->mo->scale),2*FRACUNIT/3); + return FixedMul(FixedMul(player->mo->info->height, player->mo->scale), 2*FRACUNIT/3); +} + +// +// P_GetLocalPlayerNumForNum +// +// Returns the player number +// on the local machine for given number. +// +INT32 P_GetLocalPlayerNumForNum(UINT8 pnum) +{ + return (pnum == 0 ? consoleplayer : displayplayers[pnum]); } // @@ -984,15 +999,17 @@ player_t *P_GetLocalPlayerForNum(UINT8 pnum) return (&players[P_GetLocalPlayerNumForNum(pnum)]); } -// -// P_GetLocalPlayerNumForNum -// -// Returns the player number -// on the local machine for given number. -// -INT32 P_GetLocalPlayerNumForNum(UINT8 pnum) +INT32 P_GetLocalPlayerNumForPlayer(const player_t *player) { - return (pnum == 0 ? consoleplayer : displayplayers[pnum]); + for (UINT8 i = 0; i <= splitscreen; i++) + { + if (player == P_GetLocalPlayerForNum(i)) + { + return i; + } + } + + return -1; } // @@ -1008,7 +1025,9 @@ boolean P_IsLocalPlayer(const player_t *player) for (i = 0; i <= splitscreen; i++) { if (player == P_GetLocalPlayerForNum(i)) + { return true; + } } return false; @@ -1027,7 +1046,9 @@ boolean P_IsLocalPlayerNum(UINT8 pnum) for (i = 0; i <= splitscreen; i++) { if (pnum == P_GetLocalPlayerNumForNum(i)) + { return true; + } } return false; @@ -1055,7 +1076,9 @@ boolean P_IsDisplayPlayer(const player_t *player) } if (player == &players[displayplayers[i]]) + { return true; + } } return false; @@ -1161,6 +1184,9 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_GHOST); + // not sure if this is safe to do........... + //P_SetTarget(&ghost->target, mobj); + P_SetScale(ghost, mobj->scale); ghost->scalespeed = mobj->scalespeed; ghost->destscale = mobj->scale; @@ -1174,10 +1200,7 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost->color = mobj->color; ghost->colorized = mobj->colorized; // Kart: they should also be colorized if their origin is - if (mobj->player) - ghost->angle = mobj->player->frameangle; - else - ghost->angle = mobj->angle; + ghost->angle = (mobj->player ? mobj->player->frameangle : mobj->angle); ghost->sprite = mobj->sprite; ghost->frame = mobj->frame; @@ -1190,11 +1213,17 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost->localskin = mobj->localskin; ghost->skinlocal = mobj->skinlocal; + // same deal... + //ghost->standingslope = mobj->standingslope; + ghost->spritexscale = mobj->spritexscale; ghost->spriteyscale = mobj->spriteyscale; ghost->spritexoffset = mobj->spritexoffset; ghost->spriteyoffset = mobj->spriteyoffset; + if (mobj->player && K_PlayerEffectsShouldBlend(mobj->player)) + ghost->blendmode = AST_ADD; + ghost->pitch = mobj->pitch; ghost->roll = mobj->roll; ghost->sloperoll = mobj->sloperoll; @@ -1209,19 +1238,20 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) mobj->flags &= ~MF_DONTENCOREMAP; // Copy interpolation data :) - ghost->old_x = mobj->old_x2; - ghost->old_y = mobj->old_y2; - ghost->old_z = mobj->old_z2; - ghost->old_angle = (mobj->player ? mobj->player->old_frameangle2 : mobj->old_angle2); - ghost->old_pitch = mobj->old_pitch2; - ghost->old_roll = mobj->old_roll2; - ghost->old_sloperoll = mobj->old_sloperoll2; - ghost->old_slopepitch = mobj->old_slopepitch2; - ghost->old_scale = mobj->old_scale2; - ghost->old_spritexscale = mobj->old_spritexscale2; - ghost->old_spriteyscale = mobj->old_spriteyscale2; - ghost->old_spritexoffset = mobj->old_spritexoffset2; - ghost->old_spriteyoffset = mobj->old_spriteyoffset2; + // old_x - mobj->momx - hack to preserve vanilla look + ghost->old_x = mobj->old_x - mobj->momx; + ghost->old_y = mobj->old_y - mobj->momy; + ghost->old_z = mobj->old_z2; // Slopes..... + ghost->old_angle = (mobj->player ? mobj->player->old_frameangle : mobj->old_angle); + ghost->old_pitch = mobj->old_pitch; + ghost->old_roll = mobj->old_roll; + ghost->old_sloperoll = mobj->old_sloperoll; + ghost->old_slopepitch = mobj->old_slopepitch; + ghost->old_scale = mobj->old_scale; + ghost->old_spritexscale = mobj->old_spritexscale; + ghost->old_spriteyscale = mobj->old_spriteyscale; + ghost->old_spritexoffset = mobj->old_spritexoffset; + ghost->old_spriteyoffset = mobj->old_spriteyoffset; return ghost; } @@ -1235,7 +1265,9 @@ void P_DoPlayerExit(player_t *player) if (player->exiting || mapreset) return; - if (P_IsLocalPlayer(player) && (!player->spectator && !demo.playback)) + const boolean islocalplayer = P_IsLocalPlayer(player); + + if (islocalplayer && (!player->spectator && !demo.playback)) legitimateexit = true; if (player->griefstrikes > 0) @@ -1250,7 +1282,7 @@ void P_DoPlayerExit(player_t *player) { const int soundid = K_IsPlayerLosing(player) ? sfx_klose: sfx_kwin; // fix godjjsa win sounds - if (P_IsLocalPlayer(player)) + if (islocalplayer) { sfxenum_t sfx_id = K_GetMobjSkin(player->mo)->soundsid[S_sfx[soundid].skinsound]; S_StartSound(NULL, sfx_id); @@ -1304,12 +1336,13 @@ boolean P_InSpaceSector(mobj_t *mo) // Returns true if you are in space if (GETSECSPECIAL(rover->master->frontsector->special, 1) != SPACESPECIAL) continue; - topheight = P_GetFFloorTopZAt(rover, mo->x, mo->y); - bottomheight = P_GetFFloorBottomZAt(rover, mo->x, mo->y); + topheight = P_GetFFloorTopZAt(rover, mo->x, mo->y); if (mo->z + (mo->height/2) > topheight) continue; + bottomheight = P_GetFFloorBottomZAt(rover, mo->x, mo->y); + if (mo->z + (mo->height/2) < bottomheight) continue; @@ -1340,12 +1373,13 @@ boolean P_InQuicksand(mobj_t *mo) // Returns true if you are in quicksand if (!(rover->flags & FF_QUICKSAND)) continue; - topheight = P_GetFFloorTopZAt(rover, mo->x, mo->y); - bottomheight = P_GetFFloorBottomZAt(rover, mo->x, mo->y); + topheight = P_GetFFloorTopZAt(rover, mo->x, mo->y); if (mo->z + flipoffset > topheight) continue; + bottomheight = P_GetFFloorBottomZAt(rover, mo->x, mo->y); + if (mo->z + (mo->height/2) + flipoffset < bottomheight) continue; @@ -1527,13 +1561,12 @@ static void P_CheckBouncySectors(player_t *player) if (top) { fixed_t newmom; - pslope_t *slope; - if (abs(oldz - topheight) < abs(oldz + player->mo->height - bottomheight)) { // Hit top + + if (abs(oldz - topheight) < abs(oldz + player->mo->height - bottomheight)) // Hit top slope = *rover->t_slope; - } else { // Hit bottom + else // Hit bottom slope = *rover->b_slope; - } momentum.x = player->mo->momx; momentum.y = player->mo->momy; @@ -1624,7 +1657,8 @@ static void P_CheckQuicksand(player_t *player) for (rover = player->mo->subsector->sector->ffloors; rover; rover = rover->next) { - if (!(rover->flags & FF_EXISTS)) continue; + if (!(rover->flags & FF_EXISTS)) + continue; if (!(rover->flags & FF_QUICKSAND)) continue; @@ -1682,10 +1716,8 @@ static void P_CheckInvincibilityTimer(player_t *player) { if (!player->powers[pw_super]) { - { - player->mo->color = player->skincolor; - G_GhostAddColor((INT32) (player - players), GHC_NORMAL); - } + player->mo->color = player->skincolor; + G_GhostAddColor((INT32)(player - players), GHC_NORMAL); // If you had a shield, restore its visual significance P_SpawnShieldOrb(player); @@ -1710,7 +1742,7 @@ static void P_DoBubbleBreath(player_t *player) else zh = player->mo->z + FixedDiv(player->mo->height,5*(FRACUNIT/4)); - if (!(player->mo->eflags & MFE_UNDERWATER) || ((player->powers[pw_shield] & SH_NOSTACK) == SH_ELEMENTAL && !(player->pflags & PF_NIGHTSMODE)) || player->spectator) + if (!(player->mo->eflags & MFE_UNDERWATER) || player->spectator || ((player->powers[pw_shield] & SH_NOSTACK) == SH_ELEMENTAL && !(player->pflags & PF_NIGHTSMODE))) return; if (P_RandomChance(FRACUNIT/16)) @@ -1724,9 +1756,6 @@ static void P_DoBubbleBreath(player_t *player) bubble->destscale = player->mo->scale; P_SetScale(bubble, bubble->destscale); } - - //if (player->pflags & PF_NIGHTSMODE) // NiGHTS Super doesn't spawn flight bubbles - //return; } // @@ -1839,10 +1868,10 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) if (!P_CheckSight(player->mo, mo2)) continue; // if your psychic powers can't "see" it don't bother - an = R_PointToAngle2(player->mo->x, player->mo->y, mo2->x, mo2->y); - if (mo2->health > 0) { + an = R_PointToAngle2(player->mo->x, player->mo->y, mo2->x, mo2->y); + P_Thrust(mo2, an, thrust); if (mo2->type == MT_GOLDBUZZ || mo2->type == MT_REDBUZZ) @@ -1859,7 +1888,6 @@ boolean P_AnalogMove(player_t *player) return player->pflags & PF_ANALOGMODE; } - //#define OLD_MOVEMENT_CODE 1 static void P_3dMovement(player_t *player) { @@ -1893,7 +1921,7 @@ static void P_3dMovement(player_t *player) if (analogmove) { - movepushangle = (cmd->angleturn<<16 /* not FRACBITS */); + movepushangle = (cmd->angleturn << TICCMD_REDUCE); } else { @@ -1993,12 +2021,17 @@ static void P_3dMovement(player_t *player) // The rest is unaffected. angle_t thrustangle = R_PointToAngle2(0, 0, totalthrust.x, totalthrust.y)-player->mo->standingslope->xydirection; - if (player->mo->standingslope->zdelta < 0) { // Direction goes down, so thrustangle needs to face toward - if (thrustangle < ANGLE_90 || thrustangle > ANGLE_270) { + if (player->mo->standingslope->zdelta < 0) // Direction goes down, so thrustangle needs to face toward + { + if (thrustangle < ANGLE_90 || thrustangle > ANGLE_270) + { P_QuantizeMomentumToSlope(&totalthrust, player->mo->standingslope); } - } else { // Direction goes up, so thrustangle needs to face away - if (thrustangle > ANGLE_90 && thrustangle < ANGLE_270) { + } + else // Direction goes up, so thrustangle needs to face away + { + if (thrustangle > ANGLE_90 && thrustangle < ANGLE_270) + { P_QuantizeMomentumToSlope(&totalthrust, player->mo->standingslope); } } @@ -2053,7 +2086,7 @@ static void P_SpectatorMovement(player_t *player) { ticcmd_t *cmd = &player->cmd; - player->mo->angle = (angle_t)(cmd->angleturn<<16 /* not FRACBITS */); + player->mo->angle = (angle_t)(cmd->angleturn << TICCMD_REDUCE); ticruned++; if (!(cmd->angleturn & TICCMD_RECEIVED)) @@ -2081,10 +2114,6 @@ static void P_SpectatorMovement(player_t *player) // Quake-style flying spectators :D player->mo->momz += FixedMul(cmd->forwardmove*mapobjectscale, AIMINGTOSLOPE(player->aiming)); } - /*if (cmd->sidemove != 0) -- was disabled in practice anyways, since sidemove was suppressed - { - P_Thrust(player->mo, player->mo->angle-ANGLE_90, cmd->sidemove*mapobjectscale); - }*/ } void P_BlackOw(player_t *player) @@ -2259,7 +2288,7 @@ static void P_MovePlayer(player_t *player) { // KART: Don't directly apply angleturn! It may have been either A) forged by a malicious client, or B) not be a smooth turn due to a player dropping frames. // Instead, turn the player only up to the amount they're supposed to turn accounting for latency. Allow exactly 1 extra turn unit to try to keep old replays synced. - angle_diff = cmd->angleturn - (player->mo->angle>>16); + angle_diff = cmd->angleturn - (player->mo->angle >> TICCMD_REDUCE); max_left_turn = player->lturn_max[(leveltime + MAXPREDICTTICS - cmd->latency) % MAXPREDICTTICS]; max_right_turn = player->rturn_max[(leveltime + MAXPREDICTTICS - cmd->latency) % MAXPREDICTTICS]; @@ -2272,18 +2301,18 @@ static void P_MovePlayer(player_t *player) else { // Try to keep normal turning as accurate to 1.0.1 as possible to reduce replay desyncs. - player->mo->angle = cmd->angleturn<<16; + player->mo->angle = cmd->angleturn << TICCMD_REDUCE; add_delta = false; } //CONS_Printf("applied turn: %d\n", angle_diff); if (add_delta) { - player->mo->angle += angle_diff<<16; + player->mo->angle += angle_diff << TICCMD_REDUCE; player->mo->angle &= ~0xFFFF; // Try to keep the turning somewhat similar to how it was before? //CONS_Printf("leftover turn (%s): %5d or %4d%%\n", // player_names[player-players], - // (INT16) (cmd->angleturn - (player->mo->angle>>16)), - // (INT16) (cmd->angleturn - (player->mo->angle>>16)) * 100 / (angle_diff ? angle_diff : 1)); + // (INT16) (cmd->angleturn - (player->mo->angle >> TICCMD_REDUCE)), + // (INT16) (cmd->angleturn - (player->mo->angle >> TICCMD_REDUCE)) * 100 / (angle_diff ? angle_diff : 1)); } } @@ -2597,15 +2626,7 @@ static void P_DoZoomTube(player_t *player) if (player->mo->tracer) { player->mo->angle = R_PointToAngle2(player->mo->x, player->mo->y, player->mo->tracer->x, player->mo->tracer->y); - - for (UINT8 i = 0; i <= splitscreen; i++) - { - if (player == P_GetLocalPlayerForNum(i)) - { - localangle[i] = player->mo->angle; - break; - } - } + P_ForceLocalAngle(player, player->mo->angle); } } @@ -2721,6 +2742,9 @@ boolean P_LookForEnemies(player_t *player) if (!(mo->flags & (MF_ENEMY|MF_BOSS|MF_MONITOR|MF_SPRING))) continue; // not a valid enemy + if (mo->type == MT_PLAYER) // Don't chase after other players! + continue; + if (mo->health <= 0) // dead continue; @@ -2748,9 +2772,6 @@ boolean P_LookForEnemies(player_t *player) && abs(player->mo->y-mo->y) > player->mo->radius)) continue; // not in your 2d plane - if (mo->type == MT_PLAYER) // Don't chase after other players! - continue; - if (closestmo && P_AproxDistance(P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y), player->mo->z-mo->z) > P_AproxDistance(P_AproxDistance(player->mo->x-closestmo->x, player->mo->y-closestmo->y), player->mo->z-closestmo->z)) @@ -2791,14 +2812,7 @@ void P_HomingAttack(mobj_t *source, mobj_t *enemy) // Home in on your target if (source->player) { - for (UINT8 i = 0; i <= splitscreen; i++) - { - if (source->player == P_GetLocalPlayerForNum(i)) - { - localangle[i] = source->angle; - break; - } - } + P_ForceLocalAngle(source->player, source->angle); } // change slope @@ -2927,7 +2941,7 @@ notrealplayer: // P_MoveCamera: make sure the camera is not outside the world and looks at the player avatar // -camera_t camera[MAXSPLITSCREENPLAYERS]; // Four cameras, three for splitscreen +camera_t camera[MAXSPLITSCREENPLAYERS] = {}; // Four cameras, three for splitscreen static void CV_CamRotate_OnChange(void) { @@ -3163,7 +3177,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam, UINT8 num) lang = cam->localangle; laim = cam->localaiming; - cmd->angleturn = (INT16)(lang >> 16); + cmd->angleturn = (INT16)(lang >> TICCMD_REDUCE); cmd->aiming = G_ClipAimingPitch(&laim); const boolean analogjoystickmove = cv_usejoystick[num].value && !Joystick[num].bGamepadStyle; @@ -3259,7 +3273,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam, UINT8 num) axis = JoyAxis(AXISLOOK, forplayer); - laim += (mlooky<<19)*player_invert; + laim += (mousey<<19)*player_invert; if (InputDown(gc_lookup, forplayer) || (usejoystick && axis < 0)) { @@ -3298,7 +3312,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam, UINT8 num) cmd->aiming = G_ClipAimingPitch(&laim); } - mousex = mousey = mlooky = 0; + mousex = mousey = 0; if (forward > MAXPLMOVE) forward = MAXPLMOVE; @@ -3316,7 +3330,7 @@ static ticcmd_t *P_CameraCmd(camera_t *cam, UINT8 num) cmd->sidemove = (SINT8)(cmd->sidemove + side); } - lang += (cmd->angleturn << 16); + lang += (cmd->angleturn << TICCMD_REDUCE); cam->localangle = lang; if (!cam->reset_aiming) @@ -3346,7 +3360,7 @@ static void P_DemoCameraMovement(camera_t *cam, UINT8 num) cam->aiming = cmd->aiming << FRACBITS; } - cam->angle = cmd->angleturn << 16; + cam->angle = cmd->angleturn << TICCMD_REDUCE; // camera movement: if (!cam->button_a_held) @@ -3826,7 +3840,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall // Sometimes stale ticcmds send a weird angle at the start of the race. // P_UpdatePlayerAngle knows to ignore cmd angle when you literally can't turn, so we do the same here. if (cv_demoangturn.value && leveltime > starttime) - focusangle = player->cmd.angleturn << 16; + focusangle = player->cmd.angleturn << TICCMD_REDUCE; else focusangle = mo->angle; // Just use something known sane. focusaiming = 0; @@ -5194,14 +5208,8 @@ void P_PlayerAfterThink(player_t *player) player->mo->tracer->target->health += cmd->sidemove; player->mo->angle += cmd->sidemove << ANGLETOFINESHIFT; // 2048 --> ANGLE_MAX - for (i = 0; i <= splitscreen; i++) - { - if (player == P_GetLocalPlayerForNum(i)) - { - localangle[i] = player->mo->angle; // Adjust the local control angle. - break; - } - } + // Adjust the local control angle. + P_ForceLocalAngle(player, player->mo->angle); } } @@ -5240,3 +5248,34 @@ void P_PlayerAfterThink(player_t *player) K_KartPlayerAfterThink(player); } + +angle_t P_GetLocalAngle(player_t *player) +{ + // this function is from vanilla srb2. can you tell? + // (hint: they have separate variables for all of this shit instead of arrays) + UINT8 i; + + for (i = 0; i <= splitscreen; i++) + { + if (player == &players[displayplayers[i]]) + return localangle[i]; + } + + return 0; +} + +void P_ForceLocalAngle(player_t *player, angle_t angle) +{ + UINT8 i; + + angle = angle & ~UINT16_MAX; + + for (i = 0; i <= splitscreen; i++) + { + if (player == &players[displayplayers[i]]) + { + localangle[i] = angle; + } + } +} + diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 5a0a21d76..55a475c9d 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -322,9 +322,6 @@ static void R_AddLine(seg_t *line) g_portal = NULL; - if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) - return; - // big room fix angle1 = R_PointToAngle64(line->v1->x, line->v1->y); angle2 = R_PointToAngle64(line->v2->x, line->v2->y); @@ -500,7 +497,7 @@ clipsolid: // 0 | 0 | 1 | 2 // 1 | 4 | 5 | 6 // 2 | 8 | 9 | A -INT32 checkcoord[12][4] = +const INT32 checkcoord[12][4] = { {3, 0, 2, 1}, {3, 0, 2, 0}, @@ -518,13 +515,15 @@ INT32 checkcoord[12][4] = static boolean R_CheckBBox(const fixed_t *bspcoord) { angle_t angle1, angle2; - INT32 sx1, sx2, boxpos; + INT32 sx1, sx2; const INT32* check; // Find the corners of the box // that define the edges from current viewpoint. - boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT ] ? 1 : 2) + - (viewy >= bspcoord[BOXTOP ] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8); + const INT32 boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : + viewx < bspcoord[BOXRIGHT] ? 1 : 2) + + (viewy >= bspcoord[BOXTOP] ? 0 : + viewy > bspcoord[BOXBOTTOM] ? 4 : 8); if (boxpos == 5) return true; @@ -722,6 +721,8 @@ static void R_AddPolyObjects(subsector_t *sub) po = (polyobj_t *)(po->link.next); } + g_portal = NULL; + // for render stats ps_numpolyobjects.value.i += numpolys; @@ -732,8 +733,16 @@ static void R_AddPolyObjects(subsector_t *sub) for (i = 0; i < numpolys; ++i) { qs22j(po_ptrs[i]->segs, po_ptrs[i]->segCount, sizeof(seg_t *), R_PolysegCompare); + for (j = 0; j < po_ptrs[i]->segCount; ++j) - R_AddLine(po_ptrs[i]->segs[j]); + { + seg_t *seg = po_ptrs[i]->segs[j]; + + if (!(seg->polyseg->flags & POF_RENDERSIDES)) + continue; + + R_AddLine(seg); + } } } @@ -805,7 +814,7 @@ static void R_Subsector(size_t num) if (anyMoved == true) { frontsector->numlights = sub->sector->numlights = 0; - R_Prep3DFloors(frontsector); + R_Prep3DFloors(frontsector, ceilingcenterz); sub->sector->lightlist = frontsector->lightlist; sub->sector->numlights = frontsector->numlights; sub->sector->moved = frontsector->moved = false; @@ -1055,7 +1064,7 @@ static void R_Subsector(size_t num) // // This function creates the lightlists that the given sector uses to light // floors/ceilings/walls according to the 3D floors. -void R_Prep3DFloors(sector_t *sector) +void R_Prep3DFloors(sector_t *sector, fixed_t secceilz) { ffloor_t *rover; ffloor_t *best; @@ -1081,13 +1090,13 @@ void R_Prep3DFloors(sector_t *sector) if (count != sector->numlights) { Z_Free(sector->lightlist); - sector->lightlist = static_cast(Z_Calloc(sizeof (*sector->lightlist) * count, PU_LEVEL, NULL)); + sector->lightlist = static_cast(Z_Malloc(sizeof(*sector->lightlist) * count, PU_LEVEL, NULL)); sector->numlights = count; } - else - memset(sector->lightlist, 0, sizeof (lightlist_t) * count); - heighttest = P_GetSectorCeilingZAt(sector, sector->soundorg.x, sector->soundorg.y); + memset(sector->lightlist, 0, sizeof(lightlist_t) * count); + + heighttest = secceilz; // sector ceiling z sector->lightlist[0].height = heighttest + 1; sector->lightlist[0].slope = sector->c_slope; @@ -1117,6 +1126,7 @@ void R_Prep3DFloors(sector_t *sector) bestslope = *rover->t_slope; continue; } + if (rover->flags & FF_DOUBLESHADOW) { heighttest = P_GetFFloorBottomZAt(rover, sector->soundorg.x, sector->soundorg.y); diff --git a/src/r_bsp.h b/src/r_bsp.h index b9e4e291d..5f208f015 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -34,7 +34,7 @@ extern portal_t *g_portal; // is curline a portal seg? // drawsegs are allocated on the fly... see r_segs.c -extern INT32 checkcoord[12][4]; +extern const INT32 checkcoord[12][4]; extern drawseg_t *curdrawsegs; extern drawseg_t *drawsegs; @@ -65,7 +65,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, boolean R_IsEmptyLine(seg_t *line, const sector_t *front, const sector_t *back); INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside); -void R_Prep3DFloors(sector_t *sector); +void R_Prep3DFloors(sector_t *sector, fixed_t secceilz); #ifdef __cplusplus } // extern "C" diff --git a/src/r_data.c b/src/r_data.c index da5a81dac..386f0e700 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -307,10 +307,10 @@ static boolean R_CheckTextureLumpLength(texture_t *texture, size_t patch) CONS_Alert( CONS_ERROR, "%.8s: texture lump data is too small. Expected %s bytes, got %s. (%s)\n", - texture->name, - sizeu1(offsetof(softwarepatch_t, columnofs)), - sizeu2(lumplength), - wadfiles[wadnum]->lumpinfo[lumpnum].fullname + texture->name, + sizeu1(offsetof(softwarepatch_t, columnofs)), + sizeu2(lumplength), + wadfiles[wadnum]->lumpinfo[lumpnum].fullname ); return false; @@ -717,38 +717,25 @@ static INT32 R_CountTextures(UINT16 wadnum) return count; } -static void -recallocuser -( void * user, - size_t old, - size_t new) -{ - char *p = Z_Realloc(*(void**)user, - new, PU_STATIC, user); - - if (new > old) - memset(&p[old], 0, (new - old)); -} - static void R_AllocateTextures(INT32 add) { const INT32 newtextures = (numtextures + add); const size_t newsize = newtextures * sizeof (void*); - const size_t oldsize = numtextures * sizeof (void*); + //const size_t oldsize = numtextures * sizeof (void*); INT32 i; // Allocate memory and initialize to 0 for all the textures we are initialising. - recallocuser(&textures, oldsize, newsize); + Z_Realloc(textures, newsize, PU_STATIC, &textures); // Allocate texture column offset table. - recallocuser(&texturecolumnofs, oldsize, newsize); + Z_Realloc(texturecolumnofs, newsize, PU_STATIC, &texturecolumnofs); // Allocate texture referencing cache. - recallocuser(&texturecache, oldsize, newsize); + Z_Realloc(texturecache, newsize, PU_STATIC, &texturecache); // Allocate texture width table. - recallocuser(&texturewidth, oldsize, newsize); + Z_Realloc(texturewidth, newsize, PU_STATIC, &texturewidth); // Allocate texture height table. - recallocuser(&textureheight, oldsize, newsize); + Z_Realloc(textureheight, newsize, PU_STATIC, &textureheight); // Create translation table for global animation. Z_Realloc(texturetranslation, (newtextures + 1) * sizeof(*texturetranslation), PU_STATIC, &texturetranslation); @@ -853,6 +840,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch) { Z_Free(patchName); } + patchName = (char *)Z_Malloc((texturesTokenLength+1)*sizeof(char),PU_STATIC,NULL); memcpy(patchName,texturesToken,texturesTokenLength*sizeof(char)); patchName[texturesTokenLength] = '\0'; @@ -1249,60 +1237,6 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) Z_Free((void *)texturesText); } -/* -static inline lumpnum_t R_CheckNumForNameList(const char *name, lumplist_t *list, size_t listsize) // SRB2kart - unused. -{ - size_t i; - UINT16 lump; - - for (i = listsize - 1; i < INT16_MAX; i--) - { - lump = W_CheckNumForNamePwad(name, list[i].wadfile, list[i].firstlump); - if (lump == INT16_MAX || lump > (list[i].firstlump + list[i].numlumps)) - continue; - else - return (list[i].wadfile<<16)+lump; - } - return LUMPERROR; -} -*/ - -/*static lumplist_t *colormaplumps = NULL; ///\todo free leak -static size_t numcolormaplumps = 0; - -static void R_InitExtraColormaps(void) -{ - lumpnum_t startnum, endnum; - UINT16 cfile, clump; - static size_t maxcolormaplumps = 16; - - for (cfile = clump = 0; cfile < numwadfiles; cfile++, clump = 0) - { - startnum = W_CheckNumForNamePwad("C_START", cfile, clump); - if (startnum == INT16_MAX) - continue; - - endnum = W_CheckNumForNamePwad("C_END", cfile, clump); - - if (endnum == INT16_MAX) - I_Error("R_InitExtraColormaps: C_START without C_END\n"); - - // This shouldn't be possible when you use the Pwad function, silly - //if (WADFILENUM(startnum) != WADFILENUM(endnum)) - //I_Error("R_InitExtraColormaps: C_START and C_END in different wad files!\n"); - - if (numcolormaplumps >= maxcolormaplumps) - maxcolormaplumps *= 2; - colormaplumps = Z_Realloc(colormaplumps, - sizeof (*colormaplumps) * maxcolormaplumps, PU_STATIC, NULL); - colormaplumps[numcolormaplumps].wadfile = cfile; - colormaplumps[numcolormaplumps].firstlump = startnum+1; - colormaplumps[numcolormaplumps].numlumps = endnum - (startnum + 1); - numcolormaplumps++; - } - CONS_Printf(M_GetText("Number of Extra Colormaps: %s\n"), sizeu1(numcolormaplumps)); -}*/ - // Search for flat name. lumpnum_t R_GetFlatNumForName(const char *name) { @@ -1430,7 +1364,7 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) encoremap = Z_Malloc(256 + 10, PU_LEVEL, NULL); W_ReadLump(newencoremap, encoremap); colormap_p = colormap_p2 = colormaps; - colormap_p += (256 * 32); + colormap_p += COLORMAP_REMAPOFFSET; for (p = 0; p < 32; p++) { @@ -1439,6 +1373,7 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) *colormap_p = colormap_p2[encoremap[i]]; colormap_p++; } + colormap_p2 += 256; } } @@ -1465,43 +1400,9 @@ void R_ClearColormaps(void) for (i = 0; i < MAXCOLORMAPS; i++) foundcolormaps[i] = LUMPERROR; - memset(extra_colormaps, 0, sizeof (extra_colormaps)); + memset(extra_colormaps, 0, sizeof(extra_colormaps)); } -/*INT32 R_ColormapNumForName(char *name) -{ - lumpnum_t lump, i; - - if (num_extra_colormaps == MAXCOLORMAPS) - I_Error("R_ColormapNumForName: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - - lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps); - if (lump == LUMPERROR) - I_Error("R_ColormapNumForName: Cannot find colormap lump %.8s\n", name); - - for (i = 0; i < num_extra_colormaps; i++) - if (lump == foundcolormaps[i]) - return i; - - foundcolormaps[num_extra_colormaps] = lump; - - // aligned on 8 bit for asm code - extra_colormaps[num_extra_colormaps].colormap = Z_Malloc(W_LumpLength(lump), PU_LEVEL, NULL); - W_ReadLump(lump, extra_colormaps[num_extra_colormaps].colormap); - - // We set all params of the colormap to normal because there - // is no real way to tell how GL should handle a colormap lump anyway.. - extra_colormaps[num_extra_colormaps].maskcolor = 0xffff; - extra_colormaps[num_extra_colormaps].fadecolor = 0x0; - extra_colormaps[num_extra_colormaps].maskamt = 0x0; - extra_colormaps[num_extra_colormaps].fadestart = 0; - extra_colormaps[num_extra_colormaps].fadeend = 31; - extra_colormaps[num_extra_colormaps].fog = 0; - - num_extra_colormaps++; - return (INT32)num_extra_colormaps - 1; -}*/ - // // R_CreateColormap // diff --git a/src/r_defs.h b/src/r_defs.h index 876c63485..e6c5866c6 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -397,9 +397,6 @@ typedef struct sector_s // Sprite culling feature struct line_s *cullheight; - // Current speed of ceiling/floor. For Knuckles to hold onto stuff. - fixed_t floorspeed, ceilspeed; - // Eternity engine slope boolean hasslope; // The sector, or one of its visible FOFs, contains a slope } sector_t; @@ -549,12 +546,10 @@ typedef struct seg_s sector_t *backsector; fixed_t length; // precalculated seg length - #ifdef HWRENDER - floatvertex_t fv1; - floatvertex_t fv2; + floatvertex_t fv1; // v1 in floats - precalculated + floatvertex_t fv2; // v2 in floats - precalculated #endif - polyobj_t *polyseg; // Fake contrast calculated on level load diff --git a/src/r_draw.cpp b/src/r_draw.cpp index f27b0023c..639107daa 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -355,13 +355,14 @@ UINT8 *R_GetBlendTable(int style, INT32 alphalevel) // Return a normal translucency table if (--alphalevel >= 0) return transtables + (ClipTransLevel(alphalevel) << FF_TRANSSHIFT); - else - return NULL; + + return NULL; } boolean R_BlendLevelVisible(INT32 blendmode, INT32 alphalevel) { - if (blendmode <= AST_COPY || blendmode == AST_SUBTRACT || blendmode == AST_MODULATE || blendmode >= AST_OVERLAY) + if (blendmode <= AST_COPY || blendmode == AST_SUBTRACT || + blendmode == AST_MODULATE || blendmode >= AST_OVERLAY) return true; return (alphalevel < BlendTab_Count[BlendTab_FromStyle[blendmode]]); @@ -412,7 +413,8 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f // Get colormap ret = tt[skintableindex][color]; } - else ret = NULL; + else + ret = NULL; // Generate the colormap if necessary if (!ret) @@ -435,36 +437,46 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags) UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local) { - if (localskin) - return RGetTranslationColormap(localskin - K_GetSkinArray(local), color, flags, local); - else - return RGetTranslationColormap((skin - skins), color, flags, false); + const INT32 skinnum = localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins); + return RGetTranslationColormap(skinnum, color, flags, (localskin && local)); } patch_t* R_GetSkinFaceRank(player_t* ply) { - if (ply->skinlocal && ply->localskin) - return localfacerankprefix[ply->localskin - 1]; - else if (ply->localskin) + if (ply->localskin) + { + if (ply->skinlocal) + return localfacerankprefix[ply->localskin - 1]; + return facerankprefix[ply->localskin - 1]; + } + return facerankprefix[ply->skin]; } patch_t* R_GetSkinFaceWant(player_t* ply) { - if (ply->skinlocal && ply->localskin) - return localfacewantprefix[ply->localskin - 1]; - else if (ply->localskin) + if (ply->localskin) + { + if (ply->skinlocal) + return localfacewantprefix[ply->localskin - 1]; + return facewantprefix[ply->localskin - 1]; + } + return facewantprefix[ply->skin]; } patch_t* R_GetSkinFaceMini(player_t* ply) { - if (ply->skinlocal && ply->localskin) - return localfacemmapprefix[ply->localskin - 1]; - else if (ply->localskin) + if (ply->localskin) + { + if (ply->skinlocal) + return localfacemmapprefix[ply->localskin - 1]; + return facemmapprefix[ply->localskin - 1]; + } + return facemmapprefix[ply->skin]; } diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index e5ee15463..806cee954 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -14,13 +14,7 @@ /// \note no includes because this is included as part of r_draw.cpp #ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif +#define local_for_thread static thread_local #else #define local_for_thread static #endif @@ -221,11 +215,7 @@ static void R_GetTiltedLighting(std::vector& tiltlighting, const drawspan const float planelightfloat = PLANELIGHTFLOAT; const fixed_t lightstart = FloatToFixed(iz * planelightfloat); const fixed_t lightend = FloatToFixed((iz + ds->szp.x * width) * planelightfloat); - - if (tiltlighting.size() != (size_t)viewwidth) - { - tiltlighting.resize(viewwidth); - } + tiltlighting.resize((size_t)viewwidth); R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, lightstart, lightend); //CONS_Printf("tilted lighting %f to %f (foc %f)\n", FixedToFloat(lightstart), FixedToFloat(lightend), focallengthf); diff --git a/src/r_fps.cpp b/src/r_fps.cpp index 98bfaf68b..7ccebf8e5 100644 --- a/src/r_fps.cpp +++ b/src/r_fps.cpp @@ -722,6 +722,10 @@ void R_AddMobjInterpolator(mobj_t *mobj) interpolated_mobjs.push_back(mobj); + // Maybe not the best place for it, but for first tic this old_z is 0, + // so when R_ResetMobjInterpolationState is called old_z2 will be set to 0 + mobj->old_z = mobj->z; + R_ResetMobjInterpolationState(mobj); mobj->resetinterp = true; } @@ -763,22 +767,7 @@ void R_ResetMobjInterpolationState(mobj_t *mobj) if (rendermode == render_none) return; - mobj->old_x2 = mobj->old_x; - mobj->old_y2 = mobj->old_y; mobj->old_z2 = mobj->old_z; - mobj->old_angle2 = mobj->old_angle; - mobj->old_scale2 = mobj->old_scale; - - // rotation humor - mobj->old_pitch2 = mobj->old_pitch; - mobj->old_roll2 = mobj->old_roll; - mobj->old_slopepitch2 = mobj->old_slopepitch; - mobj->old_sloperoll2 = mobj->old_sloperoll; - - mobj->old_spritexscale2 = mobj->old_spritexscale; - mobj->old_spriteyscale2 = mobj->old_spriteyscale; - mobj->old_spritexoffset2 = mobj->old_spritexoffset; - mobj->old_spriteyoffset2 = mobj->old_spriteyoffset; mobj->old_x = mobj->x; mobj->old_y = mobj->y; diff --git a/src/r_fps.h b/src/r_fps.h index 7ad5e9f16..89efc6cfb 100644 --- a/src/r_fps.h +++ b/src/r_fps.h @@ -75,15 +75,11 @@ typedef struct { fixed_t y; fixed_t z; boolean sky; - sector_t *sector; player_t *player; angle_t angle; angle_t aim; angle_t roll; - fixed_t cos; - fixed_t sin; - mobj_t *mobj; } viewvars_t; extern viewvars_t *newview; @@ -142,12 +138,12 @@ typedef struct levelinterpolator_s { fixed_t oldcx, oldcy, bakcx, bakcy; angle_t oldangle, bakangle; } polyobj; - struct { + /*struct { pslope_t *slope; vector3_t oldo, bako; vector2_t oldd, bakd; fixed_t oldzdelta, bakzdelta; - } dynslope; + } dynslope;*/ }; } levelinterpolator_t; diff --git a/src/r_main.cpp b/src/r_main.cpp index 06c595809..fecfba580 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -182,6 +182,9 @@ consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS] = { {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam4_OnChange, 0, NULL, NULL, 0, 0, NULL} }; +static CV_PossibleValue_t flipcammode_cons_t[] = {{0, "Displayplayer"}, {1, "Local"}, {0, NULL}}; +consvar_t cv_flipcammode = {"flipcammode", "Displayplayer", CV_SAVE, flipcammode_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -433,10 +436,7 @@ fixed_t R_ScaleFromGlobalAngle(angle_t visangle) if (den > num>>16) { num = FixedDiv(num, den); - if (num > 64*FRACUNIT) - return 64*FRACUNIT; - if (num < 256) - return 256; + num = CLAMP(num, 256, 64*FRACUNIT); return num; } return 64*FRACUNIT; @@ -449,8 +449,8 @@ line_t *R_GetFFloorLine(const line_t *line, const ffloor_t *pfloor, const sector size_t linenum = std::min((size_t)(line - sector->lines[0]), pfloor->master->frontsector->linecount); return pfloor->master->frontsector->lines[0] + linenum; } - else - return pfloor->master; + + return pfloor->master; } side_t *R_GetFFloorSide(const line_t *line, const ffloor_t *pfloor, const sector_t *sector) @@ -460,8 +460,8 @@ side_t *R_GetFFloorSide(const line_t *line, const ffloor_t *pfloor, const sector line_t *newline = R_GetFFloorLine(line, pfloor, sector); return &sides[newline->sidenum[0]]; } - else - return &sides[pfloor->master->sidenum[0]]; + + return &sides[pfloor->master->sidenum[0]]; } // @@ -570,6 +570,7 @@ static void R_InitTextureMapping(void) else if (t > viewwidth+1) t = viewwidth+1; } + viewangletox[i] = t; } @@ -1095,9 +1096,9 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) // R_SetupFrame // -mobj_t *viewmobj; +mobj_t *viewmobj = NULL; -static void R_SetupCommonFrame(player_t * player, sector_t * sector) +static void R_SetupCommonFrame(player_t * player) { newview->player = player; @@ -1107,17 +1108,13 @@ static void R_SetupCommonFrame(player_t * player, sector_t * sector) newview->roll = R_ViewRollAngle(player); - if (sector != NULL) - newview->sector = sector; - else - newview->sector = R_PointInSubsectorFast(newview->x, newview->y)->sector; - R_InterpolateView(R_GetTimeFrac(RTF_CAMERA), false); } static void R_SetupAimingFrame(player_t *player, camera_t *thiscam) { - if (player->awayviewtics && player->awayviewmobj) + if (player->awayviewtics && player->awayviewmobj + && !(thiscam && thiscam->freecam)) // dont force this if we wanna freecam! { newview->aim = player->awayviewaiming; newview->angle = player->awayviewmobj->angle; @@ -1210,7 +1207,6 @@ void R_SkyboxFrame(UINT8 pnum) { player_t *player = &players[displayplayers[pnum]]; camera_t *thiscam = &camera[pnum]; - sector_t *viewsec = NULL; mapheader_t *mh = mapheaderinfo[gamemap-1]; R_SetViewContext(static_cast(VIEWCONTEXT_SKY1 + pnum)); @@ -1236,9 +1232,6 @@ void R_SkyboxFrame(UINT8 pnum) newview->x = viewmobj->x; newview->y = viewmobj->y; newview->z = (viewmobj->spawnpoint) ? (((fixed_t)viewmobj->spawnpoint->angle) << FRACBITS) : 0; - - if (viewmobj->subsector) - viewsec = viewmobj->subsector->sector; } if (mh) @@ -1246,7 +1239,7 @@ void R_SkyboxFrame(UINT8 pnum) R_SetupSkyScale(player, thiscam, mh); } - R_SetupCommonFrame(player, viewsec); + R_SetupCommonFrame(player); } void R_SetupFrame(UINT8 pnum, boolean skybox) @@ -1254,17 +1247,10 @@ void R_SetupFrame(UINT8 pnum, boolean skybox) player_t *player = &players[displayplayers[pnum]]; camera_t *thiscam = &camera[pnum]; boolean chasecam = (cv_chasecam[pnum].value); - sector_t *viewsec = NULL; R_SetViewContext(static_cast(VIEWCONTEXT_PLAYER1 + pnum)); - if (thiscam->reset) - { - R_ResetViewInterpolation(pnum); - thiscam->reset = false; - } - - if (player->spectator || thiscam->freecam) + if (player->spectator || (thiscam && thiscam->freecam)) { // Free flying spectator uses demo freecam. This // requires chasecam to be enabled. @@ -1274,31 +1260,38 @@ void R_SetupFrame(UINT8 pnum, boolean skybox) if (player->playerstate == PST_DEAD || player->exiting) chasecam = true; // force chasecam on - if (chasecam && (thiscam && !thiscam->chase)) + if (thiscam) { - P_ResetCamera(player, thiscam); - thiscam->chase = true; + if (thiscam->reset) + { + R_ResetViewInterpolation(pnum); + thiscam->reset = false; + } + + if (chasecam && !thiscam->chase) + { + P_ResetCamera(player, thiscam); + thiscam->chase = true; + } + else if (!chasecam) + thiscam->chase = false; } - else if (thiscam && !chasecam) - thiscam->chase = false; newview->sky = !skybox; R_SetupAimingFrame(player, thiscam); - if (player->awayviewtics && player->awayviewmobj) // cut-away view stuff + if (player->awayviewtics && player->awayviewmobj // cut-away view stuff + && !(thiscam && thiscam->freecam)) // dont force this when we wanna freecam! { - viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN + viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN whos altview man? I_Assert(viewmobj != NULL); newview->x = viewmobj->x; newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; - if (viewmobj->subsector) - viewsec = viewmobj->subsector->sector; - - R_SetupCommonFrame(player, viewsec); + R_SetupCommonFrame(player); } else if (thiscam && chasecam) // use outside cam view { @@ -1309,10 +1302,7 @@ void R_SetupFrame(UINT8 pnum, boolean skybox) newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); - if (thiscam->subsector) - viewsec = thiscam->subsector->sector; - - R_SetupCommonFrame(player, viewsec); + R_SetupCommonFrame(player); } else if (player->mo) // use the player's eyes view { @@ -1323,10 +1313,7 @@ void R_SetupFrame(UINT8 pnum, boolean skybox) newview->y = viewmobj->y; newview->z = player->viewz; - if (viewmobj->subsector) - viewsec = viewmobj->subsector->sector; - - R_SetupCommonFrame(player, viewsec); + R_SetupCommonFrame(player); } } @@ -1337,8 +1324,8 @@ static void R_PortalFrame(portal_t *portal) viewz = portal->viewz; viewangle = portal->viewangle; - //viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); - //viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); + viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); + viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); portalclipstart = portal->start; portalclipend = portal->end; @@ -1356,7 +1343,7 @@ static void R_PortalFrame(portal_t *portal) } } -static void Mask_Pre (maskcount_t* m) +static void Mask_Pre(maskcount_t* m) { m->drawsegs[0] = ds_p - drawsegs; m->vissprites[0] = visspritecount; @@ -1366,7 +1353,7 @@ static void Mask_Pre (maskcount_t* m) m->viewsector = viewsector; } -static void Mask_Post (maskcount_t* m) +static void Mask_Post(maskcount_t* m) { m->drawsegs[1] = ds_p - drawsegs; m->vissprites[1] = visspritecount; @@ -1448,6 +1435,7 @@ void R_RenderPlayerView(player_t *player) // Clear buffers. R_ClearPlanes(); + if (viewmorph.use) { portalclipstart = viewmorph.x1; @@ -1561,6 +1549,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_flipcam[i]); } + CV_RegisterVar(&cv_flipcammode); + // Enough for dedicated server if (dedicated) return; diff --git a/src/r_main.h b/src/r_main.h index 04c996365..d33d67606 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -150,6 +150,26 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y); #define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) #define R_PointToDist2(px2, py2, px1, py1) FixedHypot((px1) - (px2), (py1) - (py2)) +FUNCMATH FUNCINLINE static ATTRINLINE fixed_t R_QuickDist(fixed_t x1, fixed_t y1, fixed_t x, fixed_t y) +{ + const fixed_t absx = abs(x - x1); + const fixed_t absy = abs(y - y1); +#ifdef __cplusplus + return std::max(absx, absy); +#else + return max(absx, absy); +#endif +} + +// Takes 2 fixed-point coordinates, returns "distance" between them and camera, +// as an fixed-point integer. +// It is very rough, tho it is used only for optimizing out unnecessary +// interpolation, so it is kinda ok on big distances. +FUNCINLINE static ATTRINLINE PUREFUNC fixed_t R_QuickCamDist(fixed_t x, fixed_t y) +{ + return R_QuickDist(viewx, viewy, x, y); +} + line_t *R_GetFFloorLine(const line_t *line, const ffloor_t *pfloor, const sector_t *sector); side_t *R_GetFFloorSide(const line_t *line, const ffloor_t *pfloor, const sector_t *sector); @@ -185,6 +205,7 @@ extern consvar_t cv_showhud, cv_translucenthud, cv_uncappedhud; extern consvar_t cv_homremoval; extern consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_flipcammode; extern consvar_t cv_shadow, cv_shadowoffs; extern consvar_t cv_ffloorclip, cv_spriteclip; extern consvar_t cv_softcyancut; diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 515f5ea38..60d4acb98 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -487,11 +487,8 @@ void *R_PixelsToPatch(UINT8 *raw, INT16 width, INT16 height, INT16 leftoffset, I size_t maxoutsize = maxcolumnsize * width + (8 + 4 * width); // so, a 512x512 flat should maximally need 393,760 (384.53 KiB) bytes. // quite a bit smaller than 64 megabytes, and much less annoying to the windows debug allocator! - while (imgbuf.size() < maxoutsize) - { - imgbuf.resize(imgbuf.size() * 2); - } + imgbuf.resize(maxoutsize); imgptr = imgbuf.data(); // Write image size and offset @@ -621,11 +618,8 @@ void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffs size_t maxoutsize = maxcolumnsize * width + (8 + 4 * width); // so, a 512x512 flat should maximally need 393,760 (384.53 KiB) bytes. // quite a bit smaller than 64 megabytes, and much less annoying to the windows debug allocator! - while (imgbuf.size() < maxoutsize) - { - imgbuf.resize(imgbuf.size() * 2); - } + imgbuf.resize(maxoutsize); imgptr = imgbuf.data(); // Write image size and offset diff --git a/src/r_patchrotation.cpp b/src/r_patchrotation.cpp index 485a8b9f1..9fdda001b 100644 --- a/src/r_patchrotation.cpp +++ b/src/r_patchrotation.cpp @@ -128,7 +128,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle UINT32 i; patch_t *rotated; - static std::vector rawdst(1024 * 1024), rawconv(1024 * 1024); // 1 MB should be enough for most cases + static std::vector rawdst(512 * 1024), rawconv(512 * 1024); // 1 MB should be enough for most cases UINT16 *rawout; size_t size; @@ -185,10 +185,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle if (!size) size = (width * height); - while (rawdst.size() < size) - { - rawdst.resize(rawdst.size() * 2); - } + rawdst.resize(size); for (i = 0; i < size; i++) rawdst[i] = 0xFF00; diff --git a/src/r_portal.c b/src/r_portal.c index 1a5c7c4a8..661034a3f 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -220,21 +220,20 @@ static void Portal_ClipVisplane (const visplane_t* plane, portal_t* portal) for (i = 0; i < end - start; i++) { // Invalid column. - if (plane->top[i + start] == 65535) + if (plane->top[i + start] == UINT16_MAX) { portal->ceilingclip[i] = -1; portal->floorclip[i] = -1; continue; } + portal->ceilingclip[i] = plane->top[i + start] - 1; portal->floorclip[i] = plane->bottom[i + start] + 1; portal->frontscale[i] = INT32_MAX; } } -extern INT32 viewwidth; - -static boolean TrimVisplaneBounds (const visplane_t* plane, INT16* start, INT16* end) +static boolean TrimVisplaneBounds(const visplane_t* plane, INT16* start, INT16* end) { *start = plane->minx; *end = plane->maxx + 1; @@ -255,13 +254,13 @@ static boolean TrimVisplaneBounds (const visplane_t* plane, INT16* start, INT16* * valid area. */ - while (plane->bottom[*start] == 0 && plane->top[*start] == 65535 && *start < *end) + while (plane->bottom[*start] == 0 && plane->top[*start] == UINT16_MAX && *start < *end) { (*start)++; } - while (plane->bottom[*end - 1] == 0 && plane->top[*start] == 65535 && *end > *start) + while (plane->bottom[*end - 1] == 0 && plane->top[*start] == UINT16_MAX && *end > *start) { (*end)--; } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c0aab2bfc..3fe8042ae 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2229,12 +2229,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) lowcutslope = std::max(worldbottomslope, worldlowslope) + viewz; highcutslope = std::min(worldtopslope, worldhighslope) + viewz; - auto check_fof_offscreen = [&](ffloor_t* rover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) + auto check_fof_offscreen = [&](ffloor_t* rrover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) { - return ((P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= bottom + viewz - && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= bottomslope + viewz) - || ( P_GetFFloorBottomZAt (rover, segleft .x, segleft .y) >= top + viewz - && P_GetFFloorBottomZAt (rover, segright.x, segright.y) >= topslope + viewz)); + return ((P_GetFFloorTopZAt (rrover, segleft .x, segleft .y) <= bottom + viewz + && P_GetFFloorTopZAt (rrover, segright.x, segright.y) <= bottomslope + viewz) + || ( P_GetFFloorBottomZAt (rrover, segleft .x, segleft .y) >= top + viewz + && P_GetFFloorBottomZAt (rrover, segright.x, segright.y) >= topslope + viewz)); }; if (frontsector->ffloors && backsector->ffloors) diff --git a/src/r_things.cpp b/src/r_things.cpp index 3cf92381e..b62d9e5d7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1577,7 +1577,7 @@ static void R_ProjectSprite(mobj_t *thing) else blendmode = thing->blendmode; - if (thing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) + if (thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK else if (thing->frame & FF_TRANSMASK) { @@ -1612,6 +1612,47 @@ static void R_ProjectSprite(mobj_t *thing) return; } + if (!papersprite) + { + // killough 4/9/98: clip things which are out of view due to height + // e6y: fix of hanging decoration disappearing in Batman Doom MAP02 + // centeryfrac -> viewheightfrac + // [kb] add +1 so sprites are shown even with the extended freelook + // lug: attempt to account for freelook properly + if (interp.z > viewz + FixedMul(FixedDiv(centeryfrac, projectiony), tz) || + gzt < viewz + FixedMul(FixedDiv(centeryfrac - (viewheight << FRACBITS), projectiony), tz)) + { + return; + } + } + + // killough 3/27/98: exclude things totally separated + // from the viewer, by either water or fake ceilings + // killough 4/11/98: improve sprite clipping for underwater/fake ceilings + + heightsec = thing->subsector->sector->heightsec; + if (viewplayer && viewplayer->mo && viewplayer->mo->subsector) + phs = viewplayer->mo->subsector->sector->heightsec; + else + phs = -1; + + if (heightsec != -1 && phs != -1) // only clip things which are in special sectors + { + fixed_t secheight; + + secheight = P_GetSectorFloorZAt(§ors[heightsec], viewx, viewy); + if (viewz < P_GetSectorFloorZAt(§ors[phs], interp.x, interp.y) ? + interp.z >= secheight : + gzt < secheight) + return; + + secheight = P_GetSectorCeilingZAt(§ors[heightsec], viewx, viewy); + if (viewz > P_GetSectorCeilingZAt(§ors[phs], interp.x, interp.y) ? + gzt < secheight && viewz >= secheight : + interp.z >= secheight) + return; + } + if (thing->frame & FF_ABSOLUTELIGHTLEVEL) { const UINT8 n = R_ThingLightLevel(thing); @@ -1689,24 +1730,6 @@ static void R_ProjectSprite(mobj_t *thing) lights_array = scalelight[lightnum]; } - heightsec = thing->subsector->sector->heightsec; - if (viewplayer && viewplayer->mo && viewplayer->mo->subsector) - phs = viewplayer->mo->subsector->sector->heightsec; - else - phs = -1; - - if (heightsec != -1 && phs != -1) // only clip things which are in special sectors - { - if (viewz < sectors[phs].floorheight ? - interp.z >= sectors[heightsec].floorheight : - gzt < sectors[heightsec].floorheight) - return; - if (viewz > sectors[phs].ceilingheight ? - gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : - interp.z >= sectors[heightsec].ceilingheight) - return; - } - // store information in a vissprite vis = R_NewVisSprite(); vis->heightsec = heightsec; //SoM: 3/17/2000 @@ -1952,6 +1975,17 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; } + // killough 4/9/98: clip things which are out of view due to height + // e6y: fix of hanging decoration disappearing in Batman Doom MAP02 + // centeryfrac -> viewheightfrac + // [kb] add +1 so sprites are shown even with the extended freelook + // lug: attempt to account for freelook properly + if (interp.z > viewz + FixedMul(FixedDiv(centeryfrac, projectiony), tz) || + gzt < viewz + FixedMul(FixedDiv(centeryfrac - (viewheight << FRACBITS), projectiony), tz)) + { + return; + } + // aspect ratio stuff : yscale = FixedDiv(projectiony, tz); @@ -2908,7 +2942,7 @@ boolean R_ThingWithinDist(mobj_t *thing, INT32 limit_dist) { if (limit_dist) { - if ((R_QuickCamDist(thing->x, thing->y) << FRACBITS)/mapobjectscale > limit_dist) + if (R_QuickCamDist(thing->x, thing->y)/mapobjectscale > limit_dist) { return false; } @@ -2952,7 +2986,7 @@ static boolean R_CheckInterpDist(T *thing) if (!R_UsingFrameInterpolation()) return false; - const INT32 dist = R_QuickCamDist(thing->x, thing->y); + const INT32 dist = R_QuickCamDist(thing->x, thing->y) >> FRACBITS; return (dist < cv_maxinterpdist.value); } diff --git a/src/r_things.h b/src/r_things.h index fd03a6611..c8195891a 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -35,19 +35,6 @@ extern "C" { #define FEETADJUST (4<>FRACBITS) - (viewx>>FRACBITS)), std::abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) -#define R_QuickDist(x1, y1, x, y) std::max(std::abs(((x)>>FRACBITS) - (x1>>FRACBITS)), std::abs(((y)>>FRACBITS) - (y1>>FRACBITS))) -#else -#define R_QuickCamDist(x, y) max(abs(((x)>>FRACBITS) - (viewx>>FRACBITS)), abs(((y)>>FRACBITS) - (viewy>>FRACBITS))) -#define R_QuickDist(x1, y1, x, y) max(abs(((x)>>FRACBITS) - (x1>>FRACBITS)), abs(((y)>>FRACBITS) - (y1>>FRACBITS))) -#endif - // Constant arrays used for psprite clipping // and initializing clipping. extern INT16 *negonearray; @@ -67,6 +54,7 @@ FUNCINLINE static ATTRINLINE INT32 R_ThingLightLevel(mobj_t* thing) { return (INT32)thing->lightlevel; } + fixed_t R_GetSpriteDirectionalLighting(angle_t angle); fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope); diff --git a/src/s_sound.c b/src/s_sound.c index 3bc48eba6..e8075469c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -97,7 +97,6 @@ consvar_t cv_pausemusic = {"playmusicifpaused", "No", CV_SAVE, CV_YesNo, NULL, static CV_PossibleValue_t music_resync_threshold_cons_t[] = { {0, "MIN"}, {1000, "MAX"}, - {0} }; consvar_t cv_music_resync_threshold = {"music_resync_threshold", "0", CV_SAVE|CV_CALL, music_resync_threshold_cons_t, I_UpdateSongLagThreshold, 0, NULL, NULL, 0, 0, NULL}; @@ -1492,6 +1491,9 @@ musicdef_t *S_FindMusicCredit(const char *musname) { def = S_GetMusicCredit(i); + if (!def) + continue; + if (hash != def->hash) continue; @@ -1951,13 +1953,13 @@ static const char *musicexception_list[] = { // check if the current music is smth we dont want to keep (vote music, etc) static boolean S_CheckMusicException(void) { - if (!fasticmp(music.name, mapmusic.name)) - return true; - // dumb hack but dont keepmusic music that is supposed to reset if (music.flags & MUSIC_RELOADRESET) return true; + if (!fasticmp(music.name, mapmusic.name)) + return true; + // in case somehow the mapmusic was replaced with smth we dont want to keep for (size_t i = 0; i < sizeof(musicexception_list)/sizeof(musicexception_list[0]); i++) { @@ -2050,16 +2052,13 @@ static boolean S_SkipIntroMusic(void) if (fasticmp(music.name, "titles")) return false; - char *maptitle = G_BuildMapTitle(gamemap); // Zzz... + CLEANUP(Z_Pfree) char *maptitle = G_BuildMapTitle(gamemap); // Zzz... if (maptitle && fasticmp(maptitle, "Wandering Falls")) // wandering balls changes its song when the race starts Zzz... { - Z_Free(maptitle); return false; } - Z_Free(maptitle); - return true; } diff --git a/src/screen.c b/src/screen.c index 2d5ea4db8..5f52b8d97 100644 --- a/src/screen.c +++ b/src/screen.c @@ -343,8 +343,6 @@ boolean SCR_IsAspectCorrect(INT32 width, INT32 height) return (width % BASEVIDWIDTH == 0 && height % BASEVIDHEIGHT == 0 && width / BASEVIDWIDTH == height / BASEVIDHEIGHT); } -double averageFPS = 0.0f; - #define USE_FPS_SAMPLES #ifdef USE_FPS_SAMPLES @@ -352,16 +350,16 @@ double averageFPS = 0.0f; #define NUM_FPS_SAMPLES (32) // Number of samples to store static double total_frame_time = 0.0; -static int frame_index; - static double fps_samples[NUM_FPS_SAMPLES]; #endif -static boolean fps_init = false; -static precise_t fps_enter = 0; +static double averageFPS = 0.0f; void SCR_CalculateFPS(void) { + static boolean fps_init = false; + static int frame_index = 0; + static precise_t fps_enter = 0; precise_t fps_finish = 0; double frameElapsed = 0.0; diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 96c22061f..66d8e4bb4 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -139,7 +139,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif -// Locations to directly check for srb2.pk3 in +// Locations to directly check for srb2.srb in const char *wadDefaultPaths[] = { #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) "/usr/local/share/games/SRB2Kart", @@ -153,7 +153,7 @@ const char *wadDefaultPaths[] = { NULL }; -// Folders to recurse through looking for srb2.pk3 +// Folders to recurse through looking for srb2.srb const char *wadSearchPaths[] = { #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) "/usr/local/games", @@ -213,14 +213,12 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -SDL_bool consolevent = SDL_FALSE; -SDL_bool framebuffer = SDL_FALSE; +boolean consolevent = false; +boolean framebuffer = false; UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -SDL_bool stdin_active = SDL_TRUE; - typedef struct { size_t cursor; @@ -282,8 +280,8 @@ static void I_ShutdownConsole(void) if (consolevent) { I_OutputMsg("Shutdown tty console\n"); - consolevent = SDL_FALSE; - tcsetattr (STDIN_FILENO, TCSADRAIN, &tty_tc); + consolevent = false; + tcsetattr(STDIN_FILENO, TCSADRAIN, &tty_tc); } } @@ -301,16 +299,18 @@ static void I_StartupConsole(void) framebuffer = static_cast( M_CheckParm("-framebuffer")); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; - if (!consolevent) return; + if (!consolevent) + return; if (isatty(STDIN_FILENO)!=1) { I_OutputMsg("stdin is not a tty, tty console mode failed\n"); - consolevent = SDL_FALSE; + consolevent = false; return; } + memset(&tty_con, 0x00, sizeof(tty_con)); tcgetattr (0, &tty_tc); tty_erase = tty_tc.c_cc[VERASE]; @@ -372,6 +372,7 @@ void I_GetConsoleEvents(void) tty_con.buffer[tty_con.cursor] = '\0'; tty_Back(); } + ev.data1 = KEY_BACKSPACE; } else if (key < ' ') // check if this is a control char @@ -387,7 +388,8 @@ void I_GetConsoleEvents(void) // shut down, most unix programs behave this way I_Quit(); } - else continue; + else + continue; } else if (tty_con.cursor < sizeof(tty_con.buffer)) { @@ -397,7 +399,9 @@ void I_GetConsoleEvents(void) // print the current line (this is differential) write(STDOUT_FILENO, &key, 1); } - if (ev.data1) D_PostEvent(&ev); + + if (ev.data1) + D_PostEvent(&ev); //tty_FlushIn(); } } @@ -505,7 +509,7 @@ static void I_StartupConsole(void) if (gotConsole) { SetConsoleTitleA("SRB2Kart Console"); - consolevent = SDL_TRUE; + consolevent = true; } //Let get the real console HANDLE, because Mingw's Bash is bad! @@ -538,7 +542,7 @@ static inline void I_StartupConsole(void) framebuffer = M_CheckParm("-framebuffer"); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; } static inline void I_ShutdownConsole(void){} #endif @@ -759,7 +763,7 @@ void I_JoyScale4(void) } // Cheat to get the device index for a joystick handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) +static INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) { SDL_Joystick *joystick = NULL; @@ -1845,17 +1849,20 @@ INT32 I_StartupSystem(void) return 0; } +boolean is_quitting = false; + // // I_Quit // FUNCNORETURN void ATTRNORETURN I_Quit(void) { - static SDL_bool quiting = SDL_FALSE; - /* prevent recursive I_Quit() */ - if (quiting) goto death; + if (is_quitting) + abort(); + + is_quitting = true; SDL_ShowCursor(SDL_TRUE); - quiting = SDL_FALSE; + I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. D_SaveBan(); // save the ban list @@ -1882,25 +1889,11 @@ FUNCNORETURN void ATTRNORETURN I_Quit(void) } if (myargmalloc) free(myargv); // Deallocate allocated memory -death: + W_Shutdown(); exit(0); } -void I_WaitVBL(INT32 count) -{ - count = 1; - SDL_Delay(count); -} - -void I_BeginRead(void) -{ -} - -void I_EndRead(void) -{ -} - // // I_Error // @@ -2322,12 +2315,17 @@ static void pathonly(char *s) size_t j; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { - if (s[j] == ':') s[j+1] = 0; - else s[j] = 0; + if (s[j] == ':') + s[j+1] = 0; + else + s[j] = 0; + return; } + } } /** \brief search for srb2.srb in the given path @@ -2340,7 +2338,7 @@ static void pathonly(char *s) */ static const char *searchWad(const char *searchDir) { - static char tempsw[MAX_WADPATH] = ""; + static char tempsw[255] = ""; filestatus_t fstemp; strcpy(tempsw, WADKEYWORD1); @@ -2391,6 +2389,18 @@ static const char *locateWad(void) return NULL; #endif +#ifndef NOHOME +#ifdef DEFAULTDIR + I_OutputMsg(",HOME/" DEFAULTDIR); + // examine user jart directory + if ((envstr = I_GetEnv("HOME")) != NULL) + { + sprintf(returnWadPath, "%s" PATHSEP DEFAULTDIR, envstr); + CHECKWADPATH(returnWadPath); + } +#endif +#endif + #ifdef __APPLE__ OSX_GetResourcesPath(returnWadPath); CHECKWADPATH(returnWadPath); @@ -2403,20 +2413,6 @@ static const char *locateWad(void) CHECKWADPATH(returnWadPath); } -#ifndef NOHOME - // find in $HOME - I_OutputMsg(",HOME/" DEFAULTDIR); - if ((envstr = I_GetEnv("HOME")) != NULL) - { - char *tmp = static_cast(malloc(strlen(envstr) + sizeof(PATHSEP) + sizeof(DEFAULTDIR))); - strcpy(tmp, envstr); - strcat(tmp, PATHSEP); - strcat(tmp, DEFAULTDIR); - CHECKWADPATH(tmp); - free(tmp); - } -#endif - // search paths for (i = 0; wadSearchPaths[i]; i++) { @@ -2430,7 +2426,7 @@ static const char *locateWad(void) const char *I_LocateWad(void) { - const char *waddir; + const char *waddir = NULL; I_OutputMsg("Looking for WADs in: "); waddir = locateWad(); @@ -2448,6 +2444,7 @@ const char *I_LocateWad(void) I_OutputMsg("Couldn't change working directory\n"); #endif } + return waddir; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ef7f439b0..1dcf028fb 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -153,14 +153,16 @@ static UINT32 localPalette[256]; Uint16 realwidth = BASEVIDWIDTH; Uint16 realheight = BASEVIDHEIGHT; #define HalfWarpMouse(x,y) if (wrapmouseok) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) -static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; // SDL2 vars -SDL_Window *window = NULL; -SDL_Renderer *renderer = NULL; +static SDL_Window *window = NULL; +static SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; +#ifdef HWRENDER +static SDL_GLContext sdlglcontext = NULL; +#endif static SDL_bool havefocus = SDL_TRUE; static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); @@ -987,7 +989,7 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { I_InitJoystick(i); - G_SetPlayerGamepadIndicatorColor(i, G_GetSkinColor(i)); // gotta update the controller led again on reconnect + G_SetPlayerGamepadIndicatorColor(i, 0); // gotta update the controller led again on reconnect } //////////////////////////////////////////////////////////// @@ -995,12 +997,12 @@ static void Impl_HandleControllerAddedEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + numcontrollers = I_NumJoys(); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); - numcontrollers = I_NumJoys(); - for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { if (JoyInfo[i].dev == newcontroller) @@ -1057,11 +1059,11 @@ static void Impl_HandleControllerRemovedEvent(void) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) CONS_Debug(DBG_GAMELOGIC, "Joystick%d device index: %d\n", i+1, JoyInfo[i].oldjoy); + numcontrollers = I_NumJoys(); + // update the menu if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); - - numcontrollers = I_NumJoys(); } void I_GetEvent(void) @@ -1380,31 +1382,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) } } -// -// I_UpdateNoBlit -// -void I_UpdateNoBlit(void) -{ - if (rendermode == render_none) - return; - - if (exposevideo) - { -#ifdef HWRENDER - if (rendermode == render_opengl) - { - OglSdlFinishUpdate(cv_vidwait.value); - return; - } - -#endif - SDL_RenderCopy(renderer, texture, NULL, NULL); - SDL_RenderPresent(renderer); - } - - exposevideo = SDL_FALSE; -} - // // I_FinishUpdate // @@ -1437,7 +1414,7 @@ void I_FinishUpdate(void) #ifdef HWRENDER if (rendermode == render_opengl) { - OglSdlFinishUpdate(cv_vidwait.value); + OglSdlFinishUpdate(window); return; } #endif @@ -1464,8 +1441,6 @@ void I_FinishUpdate(void) SDL_RenderCopy(renderer, texture, &src_rect, NULL); SDL_RenderPresent(renderer); } - - exposevideo = SDL_FALSE; } // @@ -2195,13 +2170,20 @@ void I_ShutdownGraphics(void) graphics_started = false; I_OutputMsg("shut down\n"); - #ifdef HWRENDER if (sdlglcontext) - { SDL_GL_DeleteContext(sdlglcontext); - } + sdlglcontext = NULL; #endif + if (texture) + SDL_DestroyTexture(texture); + texture = NULL; + if (renderer) + SDL_DestroyRenderer(renderer); + renderer = NULL; + if (window) + SDL_DestroyWindow(window); + window = NULL; SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; @@ -2219,17 +2201,17 @@ UINT32 I_GetRefreshRate(void) static void Impl_SetVsync(void) { -#if SDL_VERSION_ATLEAST(2,0,18) - if (renderer) - SDL_RenderSetVSync(renderer, cv_vidwait.value); -#endif #ifdef HWRENDER - if (!renderer && rendermode == render_opengl && - sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) + if (rendermode == render_opengl && + sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) { SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); } #endif +#if SDL_VERSION_ATLEAST(2,0,18) + if (renderer) + SDL_RenderSetVSync(renderer, cv_vidwait.value); +#endif } void I_SetBorderlessWindow(void) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 529b47399..272e48a1b 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -461,7 +461,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, 0); + mem = Z_Malloc(len, PU_SOUND, NULL); gme_play(emu, len >> 1, mem); gme_free_info(info); @@ -499,7 +499,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, 0); + mem = Z_Malloc(len, PU_SOUND, NULL); gme_play(emu, len >> 1, mem); gme_free_info(info); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 98a8424ce..d50cdbe93 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -63,25 +63,15 @@ PFNglGetString pglGetString; #endif #ifdef USE_FBO_OGL - -#if defined (__unix__) -static boolean xwaylandcrap = false; -#endif - boolean UseScreenFBO(void) { - return ((supportFBO && cv_glframebuffer.value && downsample) -#if defined (__unix__) - || (supportFBO && xwaylandcrap) -#endif - ); + return (supportFBO && cv_glframebuffer.value && downsample); } #endif /** \brief SDL video display surface */ INT32 oglflags = 0; -SDL_GLContext sdlglcontext = 0; void *GetGLFunc(const char *proc) { @@ -201,17 +191,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) supportNPO2tex = true; glanisotropicmode_cons_t[1].value = maximumAnisotropy; - -#if defined (__unix__) -#ifdef USE_FBO_OGL - // TODO: delet this since nvidia fixed their shit on 575 - char videodriver[4] = {'S','D','L',0}; - if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") - && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') - && (strncasecmp("x11", videodriver, 4) == 0)) - xwaylandcrap = true; -#endif -#endif } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -241,22 +220,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) \return void */ -void OglSdlFinishUpdate(boolean waitvbl) +void OglSdlFinishUpdate(SDL_Window *window) { - static boolean oldwaitvbl = false; int sdlw, sdlh; #ifdef USE_FBO_OGL const boolean usefbo = UseScreenFBO(); #endif - if (oldwaitvbl != waitvbl) - { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); - } - - oldwaitvbl = waitvbl; - SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); @@ -289,13 +260,6 @@ void OglSdlFinishUpdate(boolean waitvbl) if (!I_CheckNativeRes() || WipeInAction) #endif HWR_DrawScreenFinalTexture(realwidth, realheight, false); - -#if defined (__unix__) -#ifdef USE_FBO_OGL - if (loaded_config) - xwaylandcrap = false; -#endif -#endif } #endif //HWRENDER diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 6d614cd22..9bdebc715 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -20,11 +20,9 @@ boolean OglSdlSurface(INT32 w, INT32 h); -void OglSdlFinishUpdate(boolean vidwait); +void OglSdlFinishUpdate(SDL_Window *window); boolean VID_LoadOGLAPI(void); -extern SDL_Renderer *renderer; -extern SDL_GLContext sdlglcontext; extern Uint16 realwidth; extern Uint16 realheight; diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 0fe93953a..e5bdca395 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -23,9 +23,6 @@ extern "C" { #endif -extern SDL_bool consolevent; -extern SDL_bool framebuffer; - #include "../m_fixed.h" // SDL2 stub macro @@ -67,23 +64,6 @@ extern SDLJoyInfo_t JoyInfo[4]; //MAXSPLITSCREENPLAYERS #define SDL_JDEADZONE 153 #undef SDL_JDEADZONE -void I_GetConsoleEvents(void); - -// So we can call this from i_video event loop -void I_ShutdownJoystick(UINT8 index); - -// Cheat to get the device index for a game controller handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev); - -// Quick thing to make SDL_JOYDEVICEADDED events less of an abomination -void I_UpdateJoystickDeviceIndex(UINT8 player); -void I_UpdateJoystickDeviceIndices(UINT8 excludePlayer); - -void I_GetConsoleEvents(void); - -// Needed for some WIN32 functions -extern SDL_Window *window; - #ifdef __cplusplus } // extern "C" #endif diff --git a/src/strcasestr.c b/src/strcasestr.c index 4ff778bf1..d24a36e54 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -51,7 +51,7 @@ swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) } char * -strcasestr (const char *s, const char *q) +nongnu_strcasestr (const char *s, const char *q) { size_t qn; diff --git a/src/v_video.c b/src/v_video.c index fd7dab9fb..ac85715ef 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -546,7 +546,8 @@ void V_SetPalette(INT32 palettenum) V_ReloadPalette(); #ifdef HWRENDER - if (rendermode == render_soft || (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) // opengl without paletterendering hates subpalettes + if (rendermode == render_soft || + (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) // opengl without paletterendering hates subpalettes #endif { if (palettenum == 0) @@ -2991,7 +2992,9 @@ INT32 V_CreditStringWidth(const char *string) if (!string) return 0; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - CRED_FONTSTART; if (c < 0 || c >= CRED_FONTSIZE) @@ -3069,7 +3072,9 @@ INT32 V_LevelNameWidth(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) @@ -3088,7 +3093,9 @@ INT32 V_LevelNameHeight(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) diff --git a/src/w_wad.c b/src/w_wad.c index 640ee0367..524bd97de 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1997,11 +1997,16 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); + if (rspr == NULL) + return W_CachePatchNum(num, tag); + if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH); + if (ptr == NULL) + return W_CachePatchNum(num, tag); // >y pivot centered // >x pivot not centered @@ -2612,6 +2617,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); + if (wadData == NULL) + I_Error("vres_GetMap: Invalid WadData!\n"); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); i = LONG(((wadinfo_t *)wadData)->numlumps); @@ -2628,6 +2636,8 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) } vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) @@ -2663,7 +2673,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) lumpnum_t lumppos = lumpnum + 1; for (i = LUMPNUM(lumppos); i < wadfiles[WADFILENUM(lumpnum)]->numlumps; i++, lumppos++, numlumps++) { - if (memcmp(W_CheckNameForNum(lumppos), "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) + const char *name = W_CheckNameForNum(lumppos); + if (name == NULL) + continue; + + if (memcmp(name, "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) { break; } @@ -2671,10 +2685,15 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + for (i = 0; i < numlumps; i++, lumpnum++) { // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere const char *name = W_CheckNameForNum(lumpnum); + if (name == NULL) + continue; if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) { diff --git a/src/y_inter.c b/src/y_inter.c index c1bdafd32..d35fa7825 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -61,8 +61,6 @@ typedef struct static y_data_t data; // graphics -static patch_t *bgtile = NULL; // SPECTILE/SRB2BACK - static INT32 timer; static INT32 intertic; @@ -354,7 +352,7 @@ static void Y_PlayerStandingsDrawer(y_data_t *standings, INT32 x, INT32 hilicol) if (pnum == whiteplayer) { UINT8 cursorframe = (intertic / 4) % 8; - V_DrawScaledPatch(x+16, y-4, 0, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); + V_DrawScaledPatch(x+16, y-4, 0, (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); } STRBUFCPY(strtime, standings->name[i]); @@ -446,7 +444,7 @@ void Y_IntermissionDrawer(void) || (rendermode == render_opengl && cv_glscreentextures.value != 2) // use the neato kart bg for intermission on disabled screen textures #endif ) - V_DrawPatchFill(bgtile); // use the neato kart bg for intermission on disabled screen textures + V_DrawPatchFill(srb2back); // use the neato kart bg for intermission on disabled screen textures else { if (rendermode == render_soft) @@ -703,8 +701,7 @@ static void Y_UpdateRecordReplays(void) G_SaveGameData(false); // Update timeattack menu's replay availability. - CV_AddValue(&cv_nextmap, 1); - CV_AddValue(&cv_nextmap, -1); + Nextmap_OnChange(); } // @@ -753,7 +750,7 @@ void Y_StartIntermission(void) } // This should always exist, but just in case... - if(!mapheaderinfo[prevmap]) + if (!mapheaderinfo[prevmap]) P_AllocMapHeader(prevmap); switch (intertype) @@ -782,16 +779,16 @@ void Y_StartIntermission(void) Y_CalculateMatchData(0, Y_CompareRace); break; } - case int_none: default: break; } - bgtile = W_CachePatchName("SRB2BACK", PU_PATCH_LOWPRIORITY); - - LUA_HUD_DestroyDrawList(luahuddrawlist_intermission); - luahuddrawlist_intermission = LUA_HUD_CreateDrawList(); + if (rendermode != render_none) + { + LUA_HUD_DestroyDrawList(luahuddrawlist_intermission); + luahuddrawlist_intermission = LUA_HUD_CreateDrawList(); + } } // ====== @@ -834,6 +831,9 @@ void Y_VoteScreenCheck(void) VoteScreen.foundLuaVoteFrames = VoteScreen.foundLuaVoteWideFrames = 0; VoteScreen.currentAnimFrame = 0; + if (VoteScreen.timePerAnimFrame == 0) + VoteScreen.timePerAnimFrame = 2; + INT32 i = 1; // check for lua vote background replacements @@ -859,8 +859,8 @@ void Y_VoteScreenCheck(void) // non lua vote background handling boolean prefbattletype = ((votelevels[0][1] & ~0x80) == GT_MATCH); - VoteScreen.widebgpatch = W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH_LOWPRIORITY); - VoteScreen.bgpatch = W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH_LOWPRIORITY); + VoteScreen.widebgpatch = (patch_t *)W_CachePatchName((prefbattletype ? "BATTLSCW" : "INTERSCW"), PU_PATCH_LOWPRIORITY); + VoteScreen.bgpatch = (patch_t *)W_CachePatchName((prefbattletype ? "BATTLSCR" : "INTERSCR"), PU_PATCH_LOWPRIORITY); } // @@ -908,7 +908,7 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch) // Draw non animated patch if (!tempfoundAnimLuaVoteFrames) { - votebg = W_CachePatchName(va("%s1", tempPrefix), PU_PATCH_LOWPRIORITY); + votebg = (patch_t *)W_CachePatchName(va("%s1", tempPrefix), PU_PATCH_LOWPRIORITY); Y_VoteBackgroundDrawer(votebg); return; } @@ -921,11 +921,11 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch) nextframe = (VoteScreen.currentAnimFrame + 1); - votebg = W_CachePatchName(va("%s%d", tempPrefix, nextframe), PU_PATCH_LOWPRIORITY); + votebg = (patch_t *)W_CachePatchName(va("%s%d", tempPrefix, nextframe), PU_PATCH_LOWPRIORITY); Y_VoteBackgroundDrawer(votebg); - if (renderisnewtic && (votetic % 2 == 0) && !paused) + if (renderisnewtic && (votetic % VoteScreen.timePerAnimFrame == 0) && !paused) VoteScreen.currentAnimFrame = (nextframe > tempfoundAnimLuaVoteFrames) ? 0 : nextframe; } @@ -1189,7 +1189,7 @@ void Y_VoteDrawer(void) if (!splitscreen && i == consoleplayer) { UINT8 cursorframe = (votetic / 4) % 8; - V_DrawScaledPatch(x+24, y+9, V_SNAPTOLEFT, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); + V_DrawScaledPatch(x+24, y+9, V_SNAPTOLEFT, (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); } } @@ -1449,14 +1449,14 @@ static void Y_InitVoteDrawing(void) // setup the background patches Y_VoteScreenCheck(); - VoteScreen.cursor[0] = W_CachePatchName("M_CURSOR", PU_PATCH_LOWPRIORITY); - VoteScreen.cursor[1] = W_CachePatchName("P1CURSOR", PU_PATCH_LOWPRIORITY); - VoteScreen.cursor[2] = W_CachePatchName("P2CURSOR", PU_PATCH_LOWPRIORITY); - VoteScreen.cursor[3] = W_CachePatchName("P3CURSOR", PU_PATCH_LOWPRIORITY); - VoteScreen.cursor[4] = W_CachePatchName("P4CURSOR", PU_PATCH_LOWPRIORITY); + VoteScreen.cursor[0] = (patch_t*)W_CachePatchName("M_CURSOR", PU_PATCH); + VoteScreen.cursor[1] = (patch_t*)W_CachePatchName("P1CURSOR", PU_PATCH_LOWPRIORITY); + VoteScreen.cursor[2] = (patch_t*)W_CachePatchName("P2CURSOR", PU_PATCH_LOWPRIORITY); + VoteScreen.cursor[3] = (patch_t*)W_CachePatchName("P3CURSOR", PU_PATCH_LOWPRIORITY); + VoteScreen.cursor[4] = (patch_t*)W_CachePatchName("P4CURSOR", PU_PATCH_LOWPRIORITY); - VoteScreen.randomlvl = W_CachePatchName("RANDOMLV", PU_PATCH_LOWPRIORITY); - VoteScreen.rubyicon = W_CachePatchName("RUBYICON", PU_PATCH_LOWPRIORITY); + VoteScreen.randomlvl = (patch_t*)W_CachePatchName("RANDOMLV", PU_PATCH); + VoteScreen.rubyicon = (patch_t*)W_CachePatchName("RUBYICON", PU_PATCH); } void Y_StartVote(void) @@ -1537,13 +1537,13 @@ void Y_StartVote(void) levelinfo[i].gts = NULL; // set up the pic - if (!dedicated) + if (rendermode != render_none) { lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(votelevels[i][0]+1))); if (lumpnum != LUMPERROR) - levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_PATCH_LOWPRIORITY); + levelinfo[i].pic = (patch_t *)W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_PATCH); else - levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_PATCH_LOWPRIORITY); + levelinfo[i].pic = (patch_t *)W_CachePatchName("BLANKLVL", PU_PATCH); } } diff --git a/src/y_inter.h b/src/y_inter.h index e749f0c28..29422e7b9 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -79,6 +79,7 @@ typedef struct char luaPrefix[5]; // prefix for lua votescreens INT32 currentAnimFrame; // current animated background frame + INT32 timePerAnimFrame; // time for 1 frame in ticks, 2 by default INT32 foundLuaVoteFrames; // normal lua patch frames INT32 foundLuaVoteWideFrames; // widescreen lua patch frames diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 549696bd7..9e5b4f41e 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -651,9 +651,6 @@ void Z_ChangeTag(void *ptr, INT32 tag) I_Error("Internal memory management error: " "tried to make block purgable but it has no owner"); - // No, please, don't make my PU_STATIC patch NULL! It supposed to be always valid! - if (block->tag < 10) return; - block->tag = tag; }