diff --git a/.gitattributes b/.gitattributes index d45620912..77332e539 100644 --- a/.gitattributes +++ b/.gitattributes @@ -16,3 +16,5 @@ #Appveyor /appveyor.yml -crlf -whitespace # Other +*.c text=auto +*.h text=auto diff --git a/README.md b/README.md index c21b843de..d5a3d2b41 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ - Refactored Zone Memory Allocations (helps a bit with large maps) - Many many more crash fixes and other bugfixes to the basegame (too many too list all of them here; check the changelogs for more information) +- Crash Backtraces have been replaced by libbacktrace (except for 32bit Windows builds) +Crashlogs now contain alot more informations. and even more if your build has debug symbols +Also allows 64bit Windows builds to produce Crashlogs! + ## MISC - Bird's Camara Tilting feature is no longer turned on by default - Bird's warning on the title screen has been removed diff --git a/libs/DLL-README.txt b/libs/DLL-README.txt index c44558666..a88bf9938 100644 --- a/libs/DLL-README.txt +++ b/libs/DLL-README.txt @@ -23,10 +23,8 @@ and don't forget to build r_opengl.dll for srb2dd. ## srb2kart, 64-bit -* libs\dll-binaries\x86_64\exchndl.dll * libs\dll-binaries\x86_64\libgme.dll * libs\dll-binaries\x86_64\discord-rpc.dll -* libs\dll-binaries\x86_64\mgwhelp.dll (depend for exchndl.dll) * libs\SDL2\x86_64-w64-mingw32\bin\SDL2.dll * libs\SDL2_mixer\x86_64-w64-mingw32\bin\*.dll (get everything) -* libs\libopenmpt\x86_64\bin\mingw\libopenmpt.dll +* libs\libopenmpt\x86_64\bin\mingw\libopenmpt.dll \ No newline at end of file diff --git a/libs/dll-binaries/x86_64/exchndl.dll b/libs/dll-binaries/x86_64/exchndl.dll deleted file mode 100644 index 747d7a3d5..000000000 Binary files a/libs/dll-binaries/x86_64/exchndl.dll and /dev/null differ diff --git a/libs/dll-binaries/x86_64/mgwhelp.dll b/libs/dll-binaries/x86_64/mgwhelp.dll deleted file mode 100644 index 4e30e140e..000000000 Binary files a/libs/dll-binaries/x86_64/mgwhelp.dll and /dev/null differ diff --git a/libs/drmingw/lib/win64/libexchndl.a b/libs/drmingw/lib/win64/libexchndl.a deleted file mode 100644 index ff0bcf1a5..000000000 Binary files a/libs/drmingw/lib/win64/libexchndl.a and /dev/null differ diff --git a/libs/drmingw/lib/win64/libmgwhelp.a b/libs/drmingw/lib/win64/libmgwhelp.a deleted file mode 100644 index 6f5602905..000000000 Binary files a/libs/drmingw/lib/win64/libmgwhelp.a and /dev/null differ diff --git a/libs/libbacktrace/LICENSE.txt b/libs/libbacktrace/LICENSE.txt new file mode 100644 index 000000000..495411538 --- /dev/null +++ b/libs/libbacktrace/LICENSE.txt @@ -0,0 +1,29 @@ +# Copyright (C) 2012-2016 Free Software Foundation, Inc. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: + +# (1) Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. + +# (2) Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. + +# (3) The name of the author may not be used to +# endorse or promote products derived from this software without +# specific prior written permission. + +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/libs/libbacktrace/README.md b/libs/libbacktrace/README.md new file mode 100644 index 000000000..c82834d17 --- /dev/null +++ b/libs/libbacktrace/README.md @@ -0,0 +1,36 @@ +# libbacktrace +A C library that may be linked into a C/C++ program to produce symbolic backtraces + +Initially written by Ian Lance Taylor . + +This is version 1.0. +It is likely that this will always be version 1.0. + +The libbacktrace library may be linked into a program or library and +used to produce symbolic backtraces. +Sample uses would be to print a detailed backtrace when an error +occurs or to gather detailed profiling information. +In general the functions provided by this library are async-signal-safe, +meaning that they may be safely called from a signal handler. + +The libbacktrace library is provided under a BSD license. +See the source files for the exact license text. + +The public functions are declared and documented in the header file +backtrace.h, which should be #include'd by a user of the library. + +Building libbacktrace will generate a file backtrace-supported.h, +which a user of the library may use to determine whether backtraces +will work. +See the source file backtrace-supported.h.in for the macros that it +defines. + +As of October 2020, libbacktrace supports ELF, PE/COFF, Mach-O, and +XCOFF executables with DWARF debugging information. +In other words, it supports GNU/Linux, *BSD, macOS, Windows, and AIX. +The library is written to make it straightforward to add support for +other object file and debugging formats. + +The library relies on the C++ unwind API defined at +https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html +This API is provided by GCC and clang. diff --git a/libs/libbacktrace/include/backtrace.h b/libs/libbacktrace/include/backtrace.h new file mode 100644 index 000000000..777e1460b --- /dev/null +++ b/libs/libbacktrace/include/backtrace.h @@ -0,0 +1,188 @@ +/* backtrace.h -- Public header file for stack backtrace library. + Copyright (C) 2012-2020 Free Software Foundation, Inc. + Written by Ian Lance Taylor, Google. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + (1) Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + (2) Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + (3) The name of the author may not be used to + endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. */ + +#ifndef BACKTRACE_H +#define BACKTRACE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* The backtrace state. This struct is intentionally not defined in + the public interface. */ + +struct backtrace_state; + +/* The type of the error callback argument to backtrace functions. + This function, if not NULL, will be called for certain error cases. + The DATA argument is passed to the function that calls this one. + The MSG argument is an error message. The ERRNUM argument, if + greater than 0, holds an errno value. The MSG buffer may become + invalid after this function returns. + + As a special case, the ERRNUM argument will be passed as -1 if no + debug info can be found for the executable, but the function + requires debug info (e.g., backtrace_full, backtrace_pcinfo). The + MSG in this case will be something along the lines of "no debug + info". Similarly, ERRNUM will be passed as -1 if there is no + symbol table, but the function requires a symbol table (e.g., + backtrace_syminfo). This may be used as a signal that some other + approach should be tried. */ + +typedef void (*backtrace_error_callback) (void *data, const char *msg, + int errnum); + +/* Create state information for the backtrace routines. This must be + called before any of the other routines, and its return value must + be passed to all of the other routines. FILENAME is the path name + of the executable file; if it is NULL the library will try + system-specific path names. If not NULL, FILENAME must point to a + permanent buffer. If THREADED is non-zero the state may be + accessed by multiple threads simultaneously, and the library will + use appropriate atomic operations. If THREADED is zero the state + may only be accessed by one thread at a time. This returns a state + pointer on success, NULL on error. If an error occurs, this will + call the ERROR_CALLBACK routine. + + Calling this function allocates resources that cannot be freed. + There is no backtrace_free_state function. The state is used to + cache information that is expensive to recompute. Programs are + expected to call this function at most once and to save the return + value for all later calls to backtrace functions. */ + +extern struct backtrace_state *backtrace_create_state ( + const char *filename, int threaded, + backtrace_error_callback error_callback, void *data); + +/* The type of the callback argument to the backtrace_full function. + DATA is the argument passed to backtrace_full. PC is the program + counter. FILENAME is the name of the file containing PC, or NULL + if not available. LINENO is the line number in FILENAME containing + PC, or 0 if not available. FUNCTION is the name of the function + containing PC, or NULL if not available. This should return 0 to + continuing tracing. The FILENAME and FUNCTION buffers may become + invalid after this function returns. */ + +typedef int (*backtrace_full_callback) (void *data, uintptr_t pc, + const char *filename, int lineno, + const char *function); + +/* Get a full stack backtrace. SKIP is the number of frames to skip; + passing 0 will start the trace with the function calling + backtrace_full. DATA is passed to the callback routine. If any + call to CALLBACK returns a non-zero value, the stack backtrace + stops, and backtrace returns that value; this may be used to limit + the number of stack frames desired. If all calls to CALLBACK + return 0, backtrace returns 0. The backtrace_full function will + make at least one call to either CALLBACK or ERROR_CALLBACK. This + function requires debug info for the executable. */ + +extern int backtrace_full (struct backtrace_state *state, int skip, + backtrace_full_callback callback, + backtrace_error_callback error_callback, + void *data); + +/* The type of the callback argument to the backtrace_simple function. + DATA is the argument passed to simple_backtrace. PC is the program + counter. This should return 0 to continue tracing. */ + +typedef int (*backtrace_simple_callback) (void *data, uintptr_t pc); + +/* Get a simple backtrace. SKIP is the number of frames to skip, as + in backtrace. DATA is passed to the callback routine. If any call + to CALLBACK returns a non-zero value, the stack backtrace stops, + and backtrace_simple returns that value. Otherwise + backtrace_simple returns 0. The backtrace_simple function will + make at least one call to either CALLBACK or ERROR_CALLBACK. This + function does not require any debug info for the executable. */ + +extern int backtrace_simple (struct backtrace_state *state, int skip, + backtrace_simple_callback callback, + backtrace_error_callback error_callback, + void *data); + +/* Print the current backtrace in a user readable format to a FILE. + SKIP is the number of frames to skip, as in backtrace_full. Any + error messages are printed to stderr. This function requires debug + info for the executable. */ + +extern void backtrace_print (struct backtrace_state *state, int skip, FILE *); + +/* Given PC, a program counter in the current program, call the + callback function with filename, line number, and function name + information. This will normally call the callback function exactly + once. However, if the PC happens to describe an inlined call, and + the debugging information contains the necessary information, then + this may call the callback function multiple times. This will make + at least one call to either CALLBACK or ERROR_CALLBACK. This + returns the first non-zero value returned by CALLBACK, or 0. */ + +extern int backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc, + backtrace_full_callback callback, + backtrace_error_callback error_callback, + void *data); + +/* The type of the callback argument to backtrace_syminfo. DATA and + PC are the arguments passed to backtrace_syminfo. SYMNAME is the + name of the symbol for the corresponding code. SYMVAL is the + value and SYMSIZE is the size of the symbol. SYMNAME will be NULL + if no error occurred but the symbol could not be found. */ + +typedef void (*backtrace_syminfo_callback) (void *data, uintptr_t pc, + const char *symname, + uintptr_t symval, + uintptr_t symsize); + +/* Given ADDR, an address or program counter in the current program, + call the callback information with the symbol name and value + describing the function or variable in which ADDR may be found. + This will call either CALLBACK or ERROR_CALLBACK exactly once. + This returns 1 on success, 0 on failure. This function requires + the symbol table but does not require the debug info. Note that if + the symbol table is present but ADDR could not be found in the + table, CALLBACK will be called with a NULL SYMNAME argument. + Returns 1 on success, 0 on error. */ + +extern int backtrace_syminfo (struct backtrace_state *state, uintptr_t addr, + backtrace_syminfo_callback callback, + backtrace_error_callback error_callback, + void *data); + +#ifdef __cplusplus +} /* End extern "C". */ +#endif + +#endif diff --git a/libs/libbacktrace/lib/x86_64/libbacktrace.a b/libs/libbacktrace/lib/x86_64/libbacktrace.a new file mode 100644 index 000000000..891dd11d6 Binary files /dev/null and b/libs/libbacktrace/lib/x86_64/libbacktrace.a differ diff --git a/src/apng.h b/src/apng.h index aa7fac3df..0f22dca6d 100644 --- a/src/apng.h +++ b/src/apng.h @@ -24,12 +24,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define APNG_H #ifndef _MSC_VER -#ifndef _WII #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE #endif #endif -#endif #ifndef _LFS64_LARGEFILE #define _LFS64_LARGEFILE diff --git a/src/command.c b/src/command.c index 2a9c40227..165cbb584 100644 --- a/src/command.c +++ b/src/command.c @@ -49,6 +49,7 @@ static void COM_CEchoDuration_f(void); static void COM_Exec_f(void); static void COM_Wait_f(void); static void COM_Help_f(void); +static void COM_Find_f(void); static void COM_Toggle_f(void); static void COM_Add_f(void); @@ -299,6 +300,7 @@ void COM_Init(void) COM_AddCommand("exec", COM_Exec_f); COM_AddCommand("wait", COM_Wait_f); COM_AddCommand("help", COM_Help_f); + COM_AddCommand("find", COM_Find_f); COM_AddCommand("toggle", COM_Toggle_f); COM_AddCommand("add", COM_Add_f); RegisterNetXCmd(XD_NETVAR, Got_NetVar); @@ -820,7 +822,7 @@ static void COM_Help_f(void) if (cvar) { CONS_Printf("\x82""Variable %s:\n", cvar->name); - CONS_Printf(M_GetText(" flags :")); + CONS_Printf(M_GetText(" flags: ")); if (cvar->flags & CV_SAVE) CONS_Printf("AUTOSAVE "); if (cvar->flags & CV_FLOAT) @@ -874,30 +876,9 @@ static void COM_Help_f(void) return; } - CONS_Printf("No exact match, searching...\n"); - // commands - CONS_Printf("\x82""Commands:\n"); - for (cmd = com_commands; cmd; cmd = cmd->next) - { - if (!strstr(cmd->name, help)) - continue; - CONS_Printf("%s ",cmd->name); - i++; - } + CONS_Printf("No variable or command named %s", help); + CONS_Printf("\x82""\nCheck wiki.srb2.org for more or try typing help without arguments\n"); - // variables - CONS_Printf("\x82""\nVariables:\n"); - for (cvar = consvar_vars; cvar; cvar = cvar->next) - { - if ((cvar->flags & CV_NOSHOWHELP) || (!strstr(cvar->name, help))) - continue; - CONS_Printf("%s ", cvar->name); - i++; - } - - CONS_Printf("\x82""\nCheck wiki.srb2.org for more or type help \n"); - - CONS_Debug(DBG_GAMELOGIC, "\x87Total : %d\n", i); } return; } @@ -927,6 +908,78 @@ static void COM_Help_f(void) } } + +static void COM_Find_f(void) +{ + static char prefix[80]; + xcommand_t *cmd; + consvar_t *cvar; + cmdalias_t *alias; + const char *match; + const char *help; + size_t helplen; + boolean matchesany; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("find : Search for variables, commands and aliases containing \n")); + return; + } + + help = COM_Argv(1); + helplen = strlen(help); + CONS_Printf("\x82""Variables:\n"); + matchesany = false; + for (cvar = consvar_vars; cvar; cvar = cvar->next) + { + if (cvar->flags & CV_NOSHOWHELP) + continue; + match = strstr(cvar->name, help); + if (match != NULL) + { + memcpy(prefix, cvar->name, match - cvar->name); + prefix[match - cvar->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } + } + if (!matchesany) + CONS_Printf(" (none)\n"); + + CONS_Printf("\x82""Commands:\n"); + matchesany = false; + for (cmd = com_commands; cmd; cmd = cmd->next) + { + match = strstr(cmd->name, help); + if (match != NULL) + { + memcpy(prefix, cmd->name, match - cmd->name); + prefix[match - cmd->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } + } + if (!matchesany) + CONS_Printf(" (none)\n"); + + CONS_Printf("\x82""Aliases:\n"); + matchesany = false; + for (alias = com_alias; alias; alias = alias->next) + { + match = strstr(alias->name, help); + if (match != NULL) + { + memcpy(prefix, alias->name, match - alias->name); + prefix[match - alias->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } + } + if (!matchesany) + CONS_Printf(" (none)\n"); +} + + /** Toggles a console variable. Useful for on/off values. * * This works on on/off, yes/no values only diff --git a/src/console.c b/src/console.c index 21c9eb695..73eac9ff9 100644 --- a/src/console.c +++ b/src/console.c @@ -869,7 +869,9 @@ boolean CON_Responder(event_t *ev) static UINT8 consdown = false; // console is treated differently due to rare usage // sequential completions a la 4dos - static char completion[80]; + static char completioncmd[80 + sizeof("find ")] = "find "; + static char *completion = &completioncmd[sizeof("find ")-1]; + static INT32 comskips, varskips; const char *cmd = ""; @@ -948,7 +950,6 @@ boolean CON_Responder(event_t *ev) // show all cvars/commands that match what we have inputted if (key == KEY_TAB) { - size_t i, len; if (!completion[0]) { @@ -957,19 +958,8 @@ boolean CON_Responder(event_t *ev) strcpy(completion, inputlines[inputline]); comskips = varskips = 0; } - len = strlen(completion); - //first check commands - CONS_Printf("\nCommands:\n"); - for (i = 0, cmd = COM_CompleteCommand(completion, i); cmd; cmd = COM_CompleteCommand(completion, ++i)) - CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len); - if (i == 0) CONS_Printf(" (none)\n"); - - //now we move on to CVARs - CONS_Printf("Variables:\n"); - for (i = 0, cmd = CV_CompleteVar(completion, i); cmd; cmd = CV_CompleteVar(completion, ++i)) - CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len); - if (i == 0) CONS_Printf(" (none)\n"); + COM_BufInsertText(completioncmd); return true; } diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 6e56d3ac4..248afd2f9 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -47,6 +47,7 @@ #include "k_kart.h" #include "s_sound.h" // sfx_syfail #include "m_perfstats.h" +#include "d_main.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -171,6 +172,8 @@ static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; consvar_t cv_showjoinaddress = {"showjoinaddress", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shownodeip = {"showipinnodelist", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t playbackspeed_cons_t[] = {{1, "MIN"}, {10, "MAX"}, {0, NULL}}; consvar_t cv_playbackspeed = {"playbackspeed", "1", 0, playbackspeed_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1899,6 +1902,15 @@ static void CL_LoadReceivedSavegame(void) demo.title = false; automapactive = false; + if (!postautoloaded) + { + CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n"); + if (W_AddAutoloadedLocalFiles(autoloadwadfilespost) == 0) + CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n"); + D_CleanFile(autoloadwadfilespost); + postautoloaded = true; + } + // load a base level if (P_LoadNetGame()) { @@ -1939,12 +1951,13 @@ static void CL_LoadReceivedSavegame(void) static void SendAskInfo(INT32 node) { tic_t asktime; - + #ifdef HOLEPUNCH if (node != 0 && node != BROADCASTADDR && cv_rendezvousserver.string[0]) { I_NetRequestHolePunch(node); } + #endif asktime = I_GetTime(); @@ -3345,7 +3358,7 @@ static void Command_Nodes(void) { CONS_Printf("%.2u: %*s", i, (int)maxlen, player_names[i]); CONS_Printf(" - %.2d", playernode[i]); - if (I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) + if ((I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) && (cv_shownodeip.value)) CONS_Printf(" - %s", address); if (IsPlayerAdmin(i)) @@ -3359,6 +3372,94 @@ static void Command_Nodes(void) } } +//Screw the base game nodes lets replace with listplayers instead. +static void Command_Listplayers(void) +{ + const char *address; + int width = 0; + + boolean admin; + boolean spectator; + + /* + Mode of player status for an individual player (admin, spectator). + 1 for admin + 2 for spectator + 4 for both + */ + int mode = 0; + + INT32 totalplayers = 0; + + const char *cc; + const char *pcc; + + INT32 i; + int n; + + for (i = 0; i < MAXPLAYERS; ++i) + if (playeringame[i]) + { + n = strlen(player_names[i]); + if (n > width) + width = n; + + if (mode != 7) + { + admin = IsPlayerAdmin(i); + spectator = players[i].spectator; + + if (admin) + mode |= 1; + if (spectator) + mode |= 2; + if (admin && spectator) + mode |= 4; + } + } + + for (i = 0; i < MAXPLAYERS; ++i) + if (playeringame[i]) + { + admin = IsPlayerAdmin(i); + spectator = players[i].spectator; + + if (admin) + cc = "\x85";/* red */ + else if (spectator) + cc = "\x86";/* gray */ + else + cc = ""; + + pcc = HU_SkinColorToConsoleColor(players[i].skincolor); + + CONS_Printf("%.2d: ""%s""%-*s""\x80", i, pcc,width, player_names[i]); + + if ((I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) && (cv_shownodeip.value)) + CONS_Printf(" -- %s", address); + else/* print spacer */ + { + /* ...but not if there's a crammed status and were admin */ + if (mode != 7 || !admin) + CONS_Printf(" -- ");/* -- self */ + } + + if (admin) + CONS_Printf(M_GetText("%s"" (admin)"),cc); + if (spectator) + CONS_Printf(M_GetText("%s"" (spectator)"),cc); + + CONS_Printf("\n"); + + totalplayers++; + } + + if (totalplayers == 1) + CONS_Printf("\nThere is 1 player in the game.\n"); + else + CONS_Printf("\nThere are %d players in the game.\n", totalplayers); +} + static void Command_Ban(void) { if (COM_Argc() < 2) @@ -3924,6 +4025,7 @@ void D_ClientServerInit(void) COM_AddCommand("reloadbans", Command_ReloadBan); COM_AddCommand("connect", Command_connect); COM_AddCommand("nodes", Command_Nodes); + COM_AddCommand("listplayers", Command_Listplayers); #ifdef HAVE_CURL COM_AddCommand("set_http_login", Command_set_http_login); COM_AddCommand("list_http_logins", Command_list_http_logins); @@ -4215,6 +4317,13 @@ static void Got_RemovePlayer(UINT8 **p, INT32 playernum) pnum = READUINT8(*p); reason = READUINT8(*p); + if (pnum == serverplayer) + { + CONS_Alert(CONS_WARNING, "Attempt to remove server player\n"); + + return; + } + CL_RemovePlayer(pnum, reason); #ifdef HAVE_DISCORDRPC @@ -4981,36 +5090,26 @@ static void HandlePacketFromPlayer(SINT8 node) /// \todo Use a separate cvar for that kind of timeout? freezetimeout[node] = I_GetTime() + connectiontimeout; - //Ported this from 2.2 Prevent dropped ticcmds due to interp timing jutter - // If we've alredy received a ticcmd for this tic, just submit it for the next one. - tic_t faketic = maketic; - if ((!!(netcmds[maketic % TICQUEUE][netconsole].angleturn & TICCMD_RECEIVED)) - && (maketic - firstticstosend < TICQUEUE - 1)) - faketic++; - - - // Don't do anything for packets of type NODEKEEPALIVE? // Sryder 2018/07/01: Update the freezetimeout still! if (netbuffer->packettype == PT_NODEKEEPALIVE || netbuffer->packettype == PT_NODEKEEPALIVEMIS) break; - // Copy ticcmd Prevent dropped ticcmds due to interp timing jutter - G_MoveTiccmd(&netcmds[faketic%TICQUEUE][netconsole], &netbuffer->u.clientpak.cmd, 1); - + // Copy ticcmd + G_MoveTiccmd(&netcmds[maketic%TICQUEUE][netconsole], &netbuffer->u.clientpak.cmd, 1); // Check ticcmd for "speed hacks" if (CheckForSpeedHacks((UINT8)netconsole)) break; - // Splitscreen cmd Prevent dropped ticcmds due to interp timing jutter + // Splitscreen cmd if (((netbuffer->packettype == PT_CLIENT2CMD || netbuffer->packettype == PT_CLIENT2MIS) || (netbuffer->packettype == PT_CLIENT3CMD || netbuffer->packettype == PT_CLIENT3MIS) || (netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS)) && (nodetoplayer2[node] >= 0)) { - G_MoveTiccmd(&netcmds[faketic%TICQUEUE][(UINT8)nodetoplayer2[node]], + G_MoveTiccmd(&netcmds[maketic%TICQUEUE][(UINT8)nodetoplayer2[node]], &netbuffer->u.client2pak.cmd2, 1); if (CheckForSpeedHacks((UINT8)nodetoplayer2[node])) @@ -5021,7 +5120,7 @@ static void HandlePacketFromPlayer(SINT8 node) || (netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS)) && (nodetoplayer3[node] >= 0)) { - G_MoveTiccmd(&netcmds[faketic%TICQUEUE][(UINT8)nodetoplayer3[node]], + G_MoveTiccmd(&netcmds[maketic%TICQUEUE][(UINT8)nodetoplayer3[node]], &netbuffer->u.client3pak.cmd3, 1); if (CheckForSpeedHacks((UINT8)nodetoplayer3[node])) @@ -5031,7 +5130,7 @@ static void HandlePacketFromPlayer(SINT8 node) if ((netbuffer->packettype == PT_CLIENT4CMD || netbuffer->packettype == PT_CLIENT4MIS) && (nodetoplayer4[node] >= 0)) { - G_MoveTiccmd(&netcmds[faketic%TICQUEUE][(UINT8)nodetoplayer4[node]], + G_MoveTiccmd(&netcmds[maketic%TICQUEUE][(UINT8)nodetoplayer4[node]], &netbuffer->u.client4pak.cmd4, 1); if (CheckForSpeedHacks((UINT8)nodetoplayer4[node])) @@ -5299,7 +5398,7 @@ static void HandlePacketFromPlayer(SINT8 node) } else { - DEBFILE(va("frame not in bound: %u\n", neededtic)); + DEBFILE(va("frame not in bound: %u (bounds are from %u to %u)\n", neededtic, realstart, realend)); /*if (realend < neededtic - 2 * TICRATE || neededtic + 2 * TICRATE < realstart) I_Error("Received an out of order PT_SERVERTICS packet!\n" "Got tics %d-%d, needed tic %d\n\n" @@ -6153,6 +6252,7 @@ static void UpdatePingTable(void) } } +#ifdef HOLEPUNCH static void RenewHolePunch(void) { if (cv_rendezvousserver.string[0]) @@ -6168,6 +6268,7 @@ static void RenewHolePunch(void) } } } +#endif // Handle timeouts to prevent definitive freezes from happenning static void HandleNodeTimeouts(void) @@ -6201,11 +6302,14 @@ void NetKeepAlive(void) #ifdef MASTERSERVER MasterClient_Ticker(); #endif - + + #ifdef HOLEPUNCH if (netgame && serverrunning) { RenewHolePunch(); } + #endif + if (client) { @@ -6318,10 +6422,12 @@ void NetUpdate(void) MasterClient_Ticker(); // Acking the Master Server #endif + #ifdef HOLEPUNCH if (netgame && serverrunning) { RenewHolePunch(); } + #endif if (client) { diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 65fd3c9a9..b1bc9ffcc 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -515,6 +515,8 @@ extern consvar_t cv_kicktime; extern consvar_t cv_showjoinaddress; extern consvar_t cv_playbackspeed; +extern consvar_t cv_shownodeip; + #define BASEPACKETSIZE offsetof(doomdata_t, u) #define FILETXHEADER offsetof(filetx_pak, data) #define BASESERVERTICSSIZE offsetof(doomdata_t, u.serverpak.cmds[0]) diff --git a/src/d_main.c b/src/d_main.c index 3d946dd85..257402ed2 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -66,7 +66,7 @@ #include "fastcmp.h" #include "r_fps.h" // Frame interpolation/uncapped #include "keys.h" -#include "filesrch.h" // refreshdirmenu +#include "filesrch.h" // refreshdirmenu, pathisdirectory #include "d_protocol.h" #include "m_perfstats.h" @@ -94,8 +94,6 @@ // platform independant focus loss UINT8 window_notinfocus = false; -INT32 window_x; -INT32 window_y; // // DEMO LOOP @@ -105,6 +103,13 @@ static const char *pagename = "MAP1PIC"; static char *startupwadfiles[MAX_WADFILES]; static char *startuppwads[MAX_WADFILES]; +// autoloading +static char *autoloadwadfiles[MAX_WADFILES]; +char *autoloadwadfilespost[MAX_WADFILES]; +boolean autoloading; +boolean autoloaded; +boolean postautoloaded; + boolean devparm = false; // started game with -devparm boolean singletics = false; // timedemo @@ -885,7 +890,131 @@ static void D_AddFile(const char *file, char **filearray) filearray[pnumwadfiles] = newfile; } -static inline void D_CleanFile(char **filearray) +// Taken from TSoURDt3rd +// https://github.com/StarManiaKG/The-Story-of-Uncapped-Revengence-Discord-the-3rd/blob/main/src/STAR/star_functions.c +static INT32 D_DetectFileType(const char* filename) +{ + if (pathisdirectory(filename) == 1) + return 1; + else + { + if (!stricmp(&filename[strlen(filename) - 4], ".wad")) + return 2; + else if (!stricmp(&filename[strlen(filename) - 4], ".pk3")) + return 3; + else if (!stricmp(&filename[strlen(filename) - 5], ".kart")) + return 4; + + else if (!stricmp(&filename[strlen(filename) - 4], ".lua")) + return 5; + else if (!stricmp(&filename[strlen(filename) - 4], ".soc")) + return 6; + + else if (!stricmp(&filename[strlen(filename) - 4], ".cfg")) + return 7; + else if (!stricmp(&filename[strlen(filename) - 4], ".txt")) + return 8; + } + + return 0; +} + +// autoload that shit +static void D_AutoloadFile(const char *file, char **filearray) +{ + size_t pnumwadfiles; + char *newfile; + INT32 fileType = D_DetectFileType(file); + + for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) + ; + + newfile = malloc(strlen(file) + 1); + if (!newfile) + I_Error("No more free memory to AutoloadFile %s",file); + + if (!fileType) + { + CONS_Printf("D_AutoloadFile: File %s is unknown or invalid\n", file); + return; + } + + strcpy(newfile, file); + + if (fileType <= 6) + filearray[pnumwadfiles] = newfile; + else + COM_BufAddText(va("exec %s\n", newfile)); +} + +static char *strremove(char *str, const char *sub) { + char *p, *q, *r; + if (*sub && (q = r = strstr(str, sub)) != NULL) { + size_t len = strlen(sub); + while ((r = strstr(p = r + len, sub)) != NULL) { + while (p < r) + *q++ = *p++; + } + while ((*q++ = *p++) != '\0') + continue; + } + return str; +} + +// FIND THEM +static void D_FindAddonsToAutoload(void) +{ + FILE *autoloadconfigfile; + const char *autoloadpath; + boolean postload; + + INT32 i; + char wadsToAutoload[256] = "", renameAutoloadStrings[256] = ""; + + // does it exist tho + autoloadpath = va("%s"PATHSEP"%s",srb2home,AUTOLOADCONFIGFILENAME); + autoloadconfigfile = fopen(autoloadpath, "r"); + + // If the file is found, run our shit + if (!autoloadconfigfile) // nope outta here + return; + + while (fgets(wadsToAutoload, sizeof wadsToAutoload, autoloadconfigfile) != NULL) + { + postload = false; + // skip if commented or empty + if ((wadsToAutoload[1] == '\0' || wadsToAutoload[1] == '\n') + || (wadsToAutoload[0] == '#')) + continue; + // this marks it so that it loads after loading server addons + else if (fastncmp(wadsToAutoload, "postload ", 9)) { + strremove(wadsToAutoload, "postload "); + postload = true; + } + + // Remove Any Empty or Skipped Lines + for (i = 0; wadsToAutoload[i] != '\0'; i++) + { + if (wadsToAutoload[i] == '\n') + wadsToAutoload[i] = '\0'; + } + + // LOAD IT + if (!postload) + D_AutoloadFile(wadsToAutoload, autoloadwadfiles); + else + D_AutoloadFile(wadsToAutoload, autoloadwadfilespost); + + // end it here + for (i = 0; wadsToAutoload[i] != '\0'; i++) + wadsToAutoload[i] = '\0'; + } + + // we dont want memory leaks around here do we? + fclose(autoloadconfigfile); +} + +void D_CleanFile(char **filearray) { size_t pnumwadfiles; for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) @@ -921,6 +1050,8 @@ boolean snw_speedo; // snowy speedometer check boolean clr_hud; // colour hud check boolean big_lap; // bigger lap counter boolean big_lap_color; // bigger lap counter but colour +boolean kartzspeedo; // kartZ speedometer +boolean statdp; // New stat static void IdentifyVersion(void) { @@ -1186,6 +1317,9 @@ void D_SRB2Main(void) if (M_CheckParm("-password") && M_IsNextParm()) D_SetPassword(M_GetNextParm()); + // FIND THEM + D_FindAddonsToAutoload(); + // add any files specified on the command line with -file wadfile // to the wad list if (!(M_CheckParm("-connect") && !M_CheckParm("-server"))) @@ -1278,25 +1412,42 @@ void D_SRB2Main(void) mainwads++; if (found_extra2_kart) mainwads++; - + // now check for speedometer stuff if (W_CheckMultipleLumps("SP_SMSTC", "K_TRNULL", "SP_MKMH", "SP_MMPH", "SP_MFRAC", "SP_MPERC", NULL)) snw_speedo = true; - + // check for bigger lap count if (W_CheckMultipleLumps("K_STLAPB", "K_STLA2B", NULL)) big_lap = true; - + // now check for colour hud stuff if (W_CheckMultipleLumps("K_SCTIME", "K_SCTIMW", "K_SCLAPS", "K_SCLAPW", \ "K_SCBALN", "K_SCBALW", "K_SCKARM", "K_SCTOUT", "K_ISMULC", "K_ITMULC", "K_ITBC","K_ITBCD", "K_ISBC", "K_ISBCD", NULL)) clr_hud = true; - + // check for bigger lap count but color** its color bitch if (W_CheckMultipleLumps("K_SCLAPB", "K_SCLA2B", NULL)) big_lap_color = true; + + // kartzspeedo + if (W_CheckMultipleLumps("K_KZSP1", "K_KZSP2", "K_KZSP3", "K_KZSP4", "K_KZSP5", \ + "K_KZSP6", "K_KZSP7", "K_KZSP8", "K_KZSP9", "K_KZSP10", "K_KZSP11", "K_KZSP12", \ + "K_KZSP13", "K_KZSP14", "K_KZSP15", "K_KZSP16", "K_KZSP17", "K_KZSP18", "K_KZSP19", \ + "K_KZSP20", "K_KZSP21", "K_KZSP22", "K_KZSP23", "K_KZSP24", "K_KZSP25", NULL)) + kartzspeedo = true; + + // stat display for extended player setup + if (W_CheckMultipleLumps("K_STATNB", "K_STATN1", "K_STATN2", "K_STATN3", "K_STATN4", \ + "K_STATN5", "K_STATN6", NULL)) + statdp = true; } + CONS_Printf("D_AutoloadFile(): Loading autoloaded addons...\n"); + if (W_AddAutoloadedLocalFiles(autoloadwadfiles) == 0) + CONS_Printf("D_AutoloadFile(): Are you sure you put in valid files or what?\n"); + D_CleanFile(autoloadwadfiles); + // // search for maps // @@ -1491,6 +1642,7 @@ void D_SRB2Main(void) I_InitMusic(); S_InitSfxChannels(cv_soundvolume.value); S_InitMusicDefs(); + S_InitMTDefs(); } CONS_Printf("ST_Init(): Init status bar.\n"); diff --git a/src/d_main.h b/src/d_main.h index 8c91be487..4214e06a4 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -32,6 +32,14 @@ extern boolean snw_speedo; // snowy speedometer check extern boolean clr_hud; // colour hud check extern boolean big_lap; // bigger lap counter extern boolean big_lap_color; //bigger lap counter but colour +extern boolean kartzspeedo; //kartZ speedo +extern boolean statdp; //stat display for extended player setup + +extern boolean autoloading; +extern boolean autoloaded; +extern boolean postautoloaded; + +extern char *autoloadwadfilespost[MAX_WADFILES]; // the infinite loop of D_SRB2Loop() called from win_main for windows version void D_SRB2Loop(void) FUNCNORETURN; @@ -48,6 +56,8 @@ void D_PostEvent(const event_t *ev); void D_ProcessEvents(void); +void D_CleanFile(char **filearray); + const char *D_Home(void); // diff --git a/src/d_net.c b/src/d_net.c index 9c11d710b..b0bb637c4 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -51,7 +51,9 @@ doomcom_t *doomcom = NULL; /// \brief network packet data, points inside doomcom doomdata_t *netbuffer = NULL; /// \brief hole punching packet, also points inside doomcom +#ifdef HOLEPUNCH holepunch_t *holepunchpacket = NULL; +#endif #ifdef DEBUGFILE FILE *debugfile = NULL; // put some net info in a file during the game @@ -75,8 +77,10 @@ boolean (*I_NetCanGet)(void) = NULL; void (*I_NetCloseSocket)(void) = NULL; void (*I_NetFreeNodenum)(INT32 nodenum) = NULL; SINT8 (*I_NetMakeNodewPort)(const char *address, const char* port) = NULL; +#ifdef HOLEPUNCH void (*I_NetRequestHolePunch)(INT32 node) = NULL; void (*I_NetRegisterHolePunch)(void) = NULL; +#endif boolean (*I_NetOpenSocket)(void) = NULL; boolean (*I_Ban) (INT32 node) = NULL; void (*I_ClearBans)(void) = NULL; @@ -827,6 +831,10 @@ static const char *packettypename[NUMPACKETTYPE] = "CLIENTJOIN", "NODETIMEOUT", "RESYNCHING", + + "TELLFILESNEEDED", + "MOREFILESNEEDED", + "PING" }; @@ -1349,7 +1357,9 @@ boolean D_CheckNetGame(void) I_Error("Too many nodes (%d), max:%d", doomcom->numnodes, MAXNETNODES); netbuffer = (doomdata_t *)(void *)&doomcom->data; + #ifdef HOLEPUNCH holepunchpacket = (holepunch_t *)(void *)&doomcom->data; + #endif #ifdef DEBUGFILE if (M_CheckParm("-debugfile")) @@ -1458,7 +1468,7 @@ void Command_Ping_f(void) if (!server && playeringame[consoleplayer]) { - CONS_Printf("\nYour ping is %d frames (%d ms)\n", playerpingtable[consoleplayer], (INT32)(playerpingtable[i] * (1000.00f / TICRATE))); + CONS_Printf("\nYour ping is %d frames (%d ms)\n", playerpingtable[consoleplayer], (INT32)(playerpingtable[consoleplayer] * (1000.00f / TICRATE))); } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 27e3613ed..9753bf11a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -195,6 +195,8 @@ static void Command_Isgamemodified_f(void); static void Command_Cheats_f(void); static void Command_ListSkins(void); +static void Command_SkinSearch(void); + #ifdef _DEBUG static void Command_Togglemodified_f(void); @@ -295,12 +297,16 @@ 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_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; INT32 cv_debug; consvar_t cv_usemouse = {"use_mouse", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; +//WTF +consvar_t cv_mouseturn = {"mouseturn", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #if defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, @@ -412,7 +418,7 @@ consvar_t cv_kartdebugcheckpoint = {"kartdebugcheckpoint", "Off", CV_NOSHOWHELP, consvar_t cv_kartdebugnodes = {"kartdebugnodes", "Off", CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartdebugcolorize = {"kartdebugcolorize", "Off", CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t votetime_cons_t[] = {{10, "MIN"}, {3600, "MAX"}, {0, NULL}}; +static CV_PossibleValue_t votetime_cons_t[] = {{1, "MIN"}, {3600, "MAX"}, {0, NULL}}; consvar_t cv_votetime = {"votetime", "20", CV_NETVAR, votetime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ringslinger = {"ringslinger", "No", CV_NETVAR|CV_NOSHOWHELP|CV_CALL|CV_CHEAT, CV_YesNo, @@ -477,6 +483,7 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_minihead = {"smallminimapplayers", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -508,7 +515,7 @@ static CV_PossibleValue_t skinselectspin_cons_t[] = { consvar_t cv_skinselectspin = {"skinselectspin", "5", CV_SAVE, skinselectspin_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t perfstats_cons_t[] = { - {0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {0, NULL}}; + {0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {4, "PreThinkFrame"}, {5, "PostThinkFrame"}, {0, NULL}}; consvar_t cv_perfstats = {"perfstats", "Off", CV_CALL, perfstats_cons_t, PS_PerfStats_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ps_thinkframe_page = {"ps_thinkframe_page", "1", CV_CALL, CV_Natural, PS_ThinkFrame_Page_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -522,8 +529,8 @@ consvar_t cv_ps_descriptor = {"ps_descriptor", "Average", 0, ps_descriptor_cons_ consvar_t cv_showtrackaddon = {"showtrackaddon", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t skinselectmenu_t[] = {{SKINMENUTYPE_SCROLL, "Scroll"}, {SKINMENUTYPE_2D, "2d"}, {SKINMENUTYPE_GRID, "Grid"}, {0, NULL}}; -consvar_t cv_skinselectmenu = {"skinselectmenu", "Grid", CV_SAVE, skinselectmenu_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t skinselectmenu_t[] = {{SKINMENUTYPE_SCROLL, "Scroll"}, {SKINMENUTYPE_2D, "2d"}, {SKINMENUTYPE_GRID, "Grid"}, {SKINMENUTYPE_EXTENDED, "Extended"}, {0, NULL}}; +consvar_t cv_skinselectmenu = {"skinselectmenu", "Extended", CV_SAVE, skinselectmenu_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t skinselectgridsort_t[] ={ { SKINMENUSORT_REALNAME, "Real name" }, @@ -773,6 +780,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_joinnextround); #endif CV_RegisterVar(&cv_showjoinaddress); + CV_RegisterVar(&cv_shownodeip); CV_RegisterVar(&cv_blamecfail); #endif @@ -786,6 +794,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_pingtimeout); CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); + CV_RegisterVar(&cv_pingicon); #ifdef SEENAMES CV_RegisterVar(&cv_allowseenames); @@ -965,6 +974,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_luaimmersion); CV_RegisterVar(&cv_fakelocalskin); + + CV_RegisterVar(&cv_showlocalskinmenus); //CV_RegisterVar(&cv_crosshair); //CV_RegisterVar(&cv_crosshair2); @@ -1095,22 +1106,12 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_ps_thinkframe_page); CV_RegisterVar(&cv_ps_samplesize); CV_RegisterVar(&cv_ps_descriptor); - - CV_RegisterVar(&cv_invincmusicfade); - CV_RegisterVar(&cv_growmusicfade); - - CV_RegisterVar(&cv_respawnfademusicout); - CV_RegisterVar(&cv_respawnfademusicback); - - CV_RegisterVar(&cv_resetspecialmusic); - - CV_RegisterVar(&cv_resume); - CV_RegisterVar(&cv_fading); //Value used to store last server player has joined CV_RegisterVar(&cv_lastserver); CV_RegisterVar(&cv_showallmaps); + CV_RegisterVar(&cv_showmusicfilename); // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f); @@ -1156,6 +1157,7 @@ void D_RegisterClientCommands(void) #endif COM_AddCommand("listskins", Command_ListSkins); + COM_AddCommand("skinsearch", Command_SkinSearch); } /** @@ -3080,7 +3082,7 @@ static void Got_Pause(UINT8 **cp, INT32 playernum) if (paused) { - if (!menuactive || netgame) + if ((!menuactive || netgame) && (!cv_pausemusic.value)) S_PauseAudio(); } else @@ -6058,6 +6060,26 @@ static void Command_ListSkins(void) } } +static void Command_SkinSearch(void) +{ + size_t i; + UINT16 s; + UINT16 ic = 0; + //skin_t *skininput = &skins[s]; + for (i = 1; i < COM_Argc(); i++){ + for( s = 0 ; s < numallskins ; s++ ) + { + skin_t *skininput = &skins[s]; + if (strcasestr(skininput->realname,COM_Argv(i))) + { + ic++; + CONS_Printf("%d. %s%s:\x80 %s\n", ic,HU_SkinColorToConsoleColor(skininput->prefcolor),skininput->realname,skininput->name); + } + } + } + CONS_Printf("Total %d skins.\n", ic); +} + /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange * \author Graue diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 83f3cb5a1..0f44840d8 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -41,6 +41,8 @@ extern consvar_t cv_splitplayers; extern consvar_t cv_seenames, cv_allowseenames; #endif extern consvar_t cv_usemouse; +//WTF +extern consvar_t cv_mouseturn; extern consvar_t cv_usejoystick; extern consvar_t cv_usejoystick2; extern consvar_t cv_usejoystick3; @@ -153,6 +155,7 @@ extern consvar_t cv_maxping; extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; extern consvar_t cv_pingmeasurement; +extern consvar_t cv_pingicon; //extern consvar_t cv_smallpos; extern consvar_t cv_showminimapnames; @@ -163,6 +166,7 @@ extern consvar_t cv_showlapemblem; extern consvar_t cv_showviewpointtext; extern consvar_t cv_luaimmersion; extern consvar_t cv_fakelocalskin; +extern consvar_t cv_showlocalskinmenus; extern consvar_t cv_skipmapcheck; @@ -182,7 +186,8 @@ typedef enum { SKINMENUTYPE_SCROLL = 0, SKINMENUTYPE_2D, // 1 - SKINMENUTYPE_GRID // 2 + SKINMENUTYPE_GRID, // 2 + SKINMENUTYPE_EXTENDED // 3 } skinmenutype_t; typedef enum diff --git a/src/d_netfil.c b/src/d_netfil.c index 0f835ddd2..a51d44f80 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1342,7 +1342,7 @@ void CURLGetFile(void) if (easyres == CURLE_HTTP_RETURNED_ERROR) curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, &response_code); - easy_handle_error = (response_code) ? va("HTTP reponse code %ld", response_code) : curl_easy_strerror(easyres); + easy_handle_error = (response_code) ? va("HTTP response code %ld", response_code) : curl_easy_strerror(easyres); curl_curfile->status = FS_FALLBACK; curl_curfile->currentsize = curl_origfilesize; curl_curfile->totalsize = curl_origtotalfilesize; diff --git a/src/d_player.h b/src/d_player.h index c9329fe9c..4d61474fb 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -416,8 +416,8 @@ typedef struct player_s UINT8 skincolor; INT32 skin; - INT32 localskin; - boolean skinlocal; + INT32 localskin; // current localskin number + boolean skinlocal; // determines if localskin is a skin already loaded in the server UINT32 score; // player score fixed_t dashspeed; // dashing speed diff --git a/src/dehacked.c b/src/dehacked.c index 349b66e7c..c641887fa 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8277,6 +8277,7 @@ struct { // Frame settings {"FF_FRAMEMASK",FF_FRAMEMASK}, + {"FF_HORIZONTALFLIP",FF_HORIZONTALFLIP}, {"FF_PAPERSPRITE",FF_PAPERSPRITE}, {"FF_ANIMATE",FF_ANIMATE}, {"FF_FULLBRIGHT",FF_FULLBRIGHT}, diff --git a/src/discord.c b/src/discord.c index ea9bc66b9..3024943c0 100644 --- a/src/discord.c +++ b/src/discord.c @@ -480,14 +480,18 @@ void DRPC_UpdatePresence(void) // Server info if (netgame) { +#ifdef MASTERSERVER if (cv_advertise.value) { discordPresence.state = "Public"; } else { +#endif discordPresence.state = "Private"; +#ifdef MASTERSERVER } +#endif discordPresence.partyId = server_context; // Thanks, whoever gave us Mumble support, for implementing the EXACT thing Discord wanted for this field! discordPresence.partySize = D_NumPlayers(); // Players in server diff --git a/src/doomdef.h b/src/doomdef.h index f41a02782..b8faf6c62 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,8 +127,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v4 " -#define VERSIONSTRINGW L"Saturn v4" +#define VERSIONSTRING "Saturn v5 " +#define VERSIONSTRINGW L"Saturn v5" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! @@ -639,6 +639,7 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; #if defined (HAVE_CURL) && ! defined (NONET) #define MASTERSERVER +#define HOLEPUNCH #else #undef UPDATE_ALERT #endif diff --git a/src/doomstat.h b/src/doomstat.h index fc4c38733..3f90eb531 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -108,8 +108,6 @@ extern boolean digital_disabled; extern boolean menuactive; // Menu overlaid? extern UINT8 paused; // Game paused? extern UINT8 window_notinfocus; // are we in focus? (backend independant -- handles auto pausing and display of "focus lost" message) -extern INT32 window_x; -extern INT32 window_y; extern boolean nodrawers; extern boolean noblit; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index f09158e01..ff01bdff0 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -169,7 +169,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false; diff --git a/src/f_finale.c b/src/f_finale.c index 1b5310e01..2d9a45e8c 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -520,6 +520,19 @@ static const char *credits[] = { "Karol \"Fooruman\" D""\x1E""browski", // DÄ…browski, accents in srb2 :ytho: "\"Virt\"", "", + "\1Saturn", + "\"Alufolie91\" aka \"Alug\"", + "\"Indev\"", + "\"Haya\"", + "\"NepDisk\"", + "\"Xyzzy\"", + " ", + "\"Sunflower\" aka \"AnimeSonic\"", + "\"Yuz\" aka \"Yuzler\"", + "\"Democrab\"", + "\"Expand\" aka \"Maver\"", + "\"Nexit\"", + "", "\1Special Thanks", "SEGA", "Sonic Team", @@ -559,10 +572,11 @@ static struct { {224, 80+(216*13), "K_ITMINE", SKINCOLOR_BRONZE}, {224, 80+(216*14), "K_ITTHNS", SKINCOLOR_RASPBERRY}, {224, 80+(216*15), "K_ITINV1", SKINCOLOR_GREY}, + {224, 80+(216*16), "K_ITSINK", SKINCOLOR_PINETREE}, // This Tyler52 gag is troublesome // Alignment should be ((spaces+1 * 100) + (headers+1 * 38) + (lines * 15)) // Current max image spacing: (216*17) - {112, (16*100)+(19*38)+(103*15), "TYLER52", SKINCOLOR_NONE}, + {112, (17*100)+(20*38)+(114*15), "TYLER52", SKINCOLOR_NONE}, {0, 0, NULL, SKINCOLOR_NONE} }; @@ -596,6 +610,7 @@ void F_StartCredits(void) timetonext = 2*TICRATE; } + void F_CreditDrawer(void) { UINT16 i; @@ -925,7 +940,6 @@ void F_GameEndTicker(void) D_StartTitle(); } - // ============== // TITLE SCREEN // ============== @@ -988,7 +1002,7 @@ void F_TitleScreenDrawer(void) else { INT32 transval = 0; - + if (finalecount <= (50+(9<<1))) transval = (finalecount - 50)>>1; diff --git a/src/filesrch.c b/src/filesrch.c index d51ef9516..e2acdf324 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -337,6 +337,23 @@ size_t dir_on[menudepth]; UINT8 refreshdirmenu = 0; char *refreshdirname = NULL; +// Checks if the specified path is a directory. +// Returns 1 if so, 0 if not, and -1 if an error occurred. +// direrror is set if there was an error. +INT32 pathisdirectory(const char *path) +{ + struct stat fsstat; + + if (stat(path, &fsstat) < 0) + { + return -1; + } + else if (S_ISDIR(fsstat.st_mode)) + return 1; + + return 0; +} + filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *wantedmd5sum, boolean completepath, int maxsearchdepth) { filestatus_t retval = FS_NOTFOUND; @@ -396,9 +413,28 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want // okay, now we actually want searchpath to incorporate d_name strcpy(&searchpath[searchpathindex[depthleft]],dent->d_name); +#if defined(__linux__) || defined(__FreeBSD__) + if (dent->d_type == DT_UNKNOWN) + if (lstat(searchpath,&fsstat) == 0 && S_ISDIR(fsstat.st_mode)) + dent->d_type = DT_DIR; + else if (lstat(searchpath,&fsstat) == 0 && S_ISLNK(fsstat.st_mode)) + dent->d_type = DT_LNK; + + // Symlinks aren't always directory symlinks. Dunno if this would resolve recursive + // symlinks, but i think stat already does that + if (dent->d_type == DT_LNK && stat(searchpath,&fsstat) == 0 && !S_ISDIR(fsstat.st_mode)) + { + dent->d_type = DT_UNKNOWN; + } + + // Linux and FreeBSD has a special field for file type on dirent, so use that to speed up lookups. + // FIXME: should we also follow symlinks? + if ((dent->d_type == DT_DIR && depthleft) || (dent->d_type == DT_LNK && depthleft)) +#else if (stat(searchpath,&fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat ; // was the file (re)moved? can't stat it else if (S_ISDIR(fsstat.st_mode) && depthleft) +#endif { searchpathindex[--depthleft] = strlen(searchpath) + 1; dirhandle[depthleft] = opendir(searchpath); diff --git a/src/filesrch.h b/src/filesrch.h index 4cb92b238..b991e8b16 100644 --- a/src/filesrch.h +++ b/src/filesrch.h @@ -89,6 +89,7 @@ typedef enum REFRESHDIR_GAMEDATA = 64 } refreshdir_enum; +INT32 pathisdirectory(const char *path); void closefilemenu(boolean validsize); void searchfilemenu(char *tempname); boolean preparefilemenu(boolean samedepth, boolean replayhut); diff --git a/src/g_game.c b/src/g_game.c index 0e31ab4f5..55438cc83 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -496,8 +496,12 @@ consvar_t cv_ydeadzone4 = {"joy4_ydeadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_c 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}; -static CV_PossibleValue_t stretchfactor_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}}; -consvar_t cv_gravstretch = {"gravstretch", "0", CV_FLOAT | CV_SAVE, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t stretchfactor_t[] = { + {0, "Off"}, {FRACUNIT/8, "0.125"}, {FRACUNIT/4, "0.250"}, + {3*FRACUNIT/8, "0.375"}, {FRACUNIT/2, "0.500"}, {5*FRACUNIT/8, "0.625"}, + {3*FRACUNIT/4, "0.750"}, {7*FRACUNIT/8, "0.875"}, {FRACUNIT, "Max"}, {0, NULL}}; +consvar_t cv_gravstretch = {"gravstretch", "0", CV_SAVE, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_sloperoll = {"sloperoll", "Off", CV_SAVE|CV_CALL, CV_OnOff, PDistort_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; @@ -515,14 +519,6 @@ consvar_t cv_sloperolldist = {"sloperolldist", "Infinite", CV_SAVE, sloperolldis consvar_t cv_cechotoggle = {"show_cecho", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_respawnfademusicout = {"respawnfademusicout", "1000", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_respawnfademusicback = {"respawnfademusicback", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_resetspecialmusic = {"resetspecialmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_resume = {"resume", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_fading = {"fading", "Off", CV_SAVE|CV_CALL, CV_OnOff, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; - #if MAXPLAYERS > 16 #error "please update player_name table using the new value for MAXPLAYERS" #endif @@ -1423,9 +1419,9 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) side += ((axis * sidemove[0]) >> 10); } - // Specator mouse turning - if (player->spectator) + if (player->spectator || cv_mouseturn.value) { + //THIS WORKS WTF???????? cmd->angleturn = (INT16)(cmd->angleturn - ((mousex*(encoremode ? -1 : 1)*8))); cmd->driftturn = (INT16)(cmd->driftturn - ((mousex*(encoremode ? -1 : 1)*8))); } @@ -1961,7 +1957,7 @@ boolean G_Responder(event_t *ev) paused = true; S_PauseAudio(); } - else if (paused) + else if ((paused) && (!cv_pausemusic.value)) S_PauseAudio(); else S_ResumeAudio(); @@ -2828,7 +2824,7 @@ void G_PlayerReborn(INT32 player) /* I'm putting this here because lol */ - fade = ( cv_fading.value && P_IsLocalPlayer(p) ); + fade = (cv_fading.value && cv_birdmusic.value && P_IsLocalPlayer(p)); if (fade) { @@ -5036,16 +5032,29 @@ void G_FreeMapSearch(mapsearchfreq_t *freq, INT32 freqc) INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep) { boolean usemapcode = false; - INT32 newmapnum; - size_t mapnamelen; + size_t mapnamelen = strlen(mapname); char *p; - - mapnamelen = strlen(mapname); - - if (mapnamelen == 2)/* maybe two digit code */ + + if (mapnamelen == 1) + { + if (mapname[0] == '*') // current map + return gamemap; + else if (mapname[0] == '+' && mapheaderinfo[gamemap-1]) // next map + { + newmapnum = mapheaderinfo[gamemap-1]->nextlevel; + if (newmapnum < 1 || newmapnum > NUMMAPS) + { + CONS_Alert(CONS_ERROR, M_GetText("NextLevel (%d) is not a valid map.\n"), newmapnum); + return 0; + } + else + return newmapnum; + } + } + else if (mapnamelen == 2)/* maybe two digit code */ { if (( newmapnum = M_MapNumber(mapname[0], mapname[1]) )) usemapcode = true; @@ -8189,7 +8198,7 @@ void G_AddGhost(char *defdemoname) count = READUINT16(p); while (count--) { - SKIPSTRING(p); + p += 2; SKIPSTRING(p); p++; } diff --git a/src/g_game.h b/src/g_game.h index 8cebc088a..2f69070af 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -160,19 +160,8 @@ extern consvar_t cv_sliptideroll; extern consvar_t cv_slamsound; extern consvar_t cv_sloperolldist; -extern consvar_t cv_invincmusicfade; -extern consvar_t cv_growmusicfade; - -extern consvar_t cv_respawnfademusicout; -extern consvar_t cv_respawnfademusicback; - -extern consvar_t cv_resetspecialmusic; - extern consvar_t cv_cechotoggle; -extern consvar_t cv_resume; -extern consvar_t cv_fading; - #ifndef NONET extern consvar_t cv_chatlogsize; #endif diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 674ae876a..4c682b2eb 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -183,14 +183,15 @@ enum EPolyFlags PF_NoDepthTest = 0x00000200, // Disable the depth test mode PF_Invisible = 0x00000400, // Disable write to color buffer PF_Decal = 0x00000800, // Enable polygon offset - PF_Modulated = 0x00001000, // Modulation (multiply output with constant ARGB) + PF_Modulated = 0x00001000, // Modulation (multiply output with constant RGBA) // When set, pass the color constant into the FSurfaceInfo -> FlatColor PF_NoTexture = 0x00002000, // Disable texture - PF_Ripple = 0x00004000, // Water shader effect + PF_ColorMapped = 0x00008000, // Surface has "tint" and "fade" colors, which are sent as uniforms to a shader. // 0x00008000 PF_RemoveYWrap = 0x00010000, // Force clamp texture on Y PF_ForceWrapX = 0x00020000, // Force repeat texture on X - PF_ForceWrapY = 0x00040000, // Force repeat texture on Y + PF_ForceWrapY = 0x00040000, // Forces repeat texture on Y + PF_Ripple = 0x00100000 // Water ripple effect. The current backend doesn't use it for anything. // 0x20000000 // 0x40000000 // 0x80000000 @@ -208,7 +209,6 @@ enum ETextureFlags typedef struct GLMipmap_s FTextureInfo; -// jimita 14032019 struct FLightInfo { FUINT light_level; @@ -225,7 +225,7 @@ struct FSurfaceInfo RGBA_t TintColor; RGBA_t FadeColor; UINT32 LightTableId; - FLightInfo LightInfo; // jimita 14032019 + FLightInfo LightInfo; }; typedef struct FSurfaceInfo FSurfaceInfo; diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 8f94abbba..cfb9fae2c 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1138,10 +1138,13 @@ static inline boolean saveTGA(const char *file_name, void *buffer, UINT8 *HWR_GetScreenshot(void) { - UINT8 *buf = malloc(vid.width * vid.height * 3 * sizeof (*buf)); + static UINT8 *buf = NULL; + + buf = realloc(buf, vid.width * vid.height * 3); if (!buf) return NULL; + // returns 24bit 888 RGB HWD.pfnReadRect(0, 0, vid.width, vid.height, vid.width * 3, (void *)buf); return buf; diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index bcf627236..42183a015 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -28,6 +28,7 @@ // ========================================================================== EXPORT boolean HWRAPI(Init) (void); +EXPORT void HWRAPI(SetupGLInfo) (void); #if defined (PURESDL) || defined (macintosh) EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); #else @@ -49,7 +50,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); //Hurdler: added for new development -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface); +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); EXPORT void HWRAPI(CreateModelVBOs) (model_t *model); EXPORT void HWRAPI(SetTransform) (FTransform *stransform); @@ -63,6 +64,7 @@ EXPORT void HWRAPI(EndScreenWipe) (void); EXPORT void HWRAPI(DoScreenWipe) (void); EXPORT void HWRAPI(DrawIntermissionBG) (void); EXPORT void HWRAPI(MakeScreenTexture) (void); +EXPORT void HWRAPI(RenderVhsEffect) (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); EXPORT void HWRAPI(MakeScreenFinalTexture) (void); EXPORT void HWRAPI(DrawScreenFinalTexture) (int width, int height); @@ -94,6 +96,7 @@ EXPORT void HWRAPI(ClearLightTableCache) (void); struct hwdriver_s { Init pfnInit; + SetupGLInfo pfnSetupGLInfo; SetPalette pfnSetPalette; FinishUpdate pfnFinishUpdate; Draw2DLine pfnDraw2DLine; @@ -117,6 +120,7 @@ struct hwdriver_s DoScreenWipe pfnDoScreenWipe; DrawIntermissionBG pfnDrawIntermissionBG; MakeScreenTexture pfnMakeScreenTexture; + RenderVhsEffect pfnRenderVhsEffect; MakeScreenFinalTexture pfnMakeScreenFinalTexture; DrawScreenFinalTexture pfnDrawScreenFinalTexture; @@ -144,4 +148,4 @@ extern struct hwdriver_s hwdriver; #endif //not defined _CREATE_DLL_ -#endif //__HWR_DRV_H__ \ No newline at end of file +#endif //__HWR_DRV_H__ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e49cfaa8f..eece5e7fd 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -61,14 +61,11 @@ struct hwdriver_s hwdriver; // Commands and console variables // ========================================================================== -// keep the state here instead of in the cv var, so it always matches the state in r_opengl.c -int gr_use_palette_shader = 0; - static void CV_filtermode_ONChange(void); static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); -static void CV_grpaletteshader_OnChange(void); +static void CV_grshaders_OnChange(void); static void CV_Gammaxxx_ONChange(void); static CV_PossibleValue_t grgamma_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}}; @@ -102,6 +99,14 @@ consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grfofcut = {"gr_fofcut", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_fofzfightfix = {"fofzfightfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_splitwallfix = {"splitwallfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_slopepegfix = {"slopepegfix", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t grrenderdistance_cons_t[] = { {0, "Max"}, {1, "1024"}, {2, "2048"}, {3, "4096"}, {4, "6144"}, {5, "8192"}, {6, "12288"}, {7, "16384"}, {0, NULL}}; @@ -118,6 +123,8 @@ consvar_t cv_secbright = {"secbright", "0", CV_SAVE, secbright_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_grvhseffect = {"gr_vhseffect", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // values for the far clipping plane static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; @@ -134,15 +141,15 @@ static INT32 current_bsp_culling_distance = 0; // - water and heat wave effects // - intermission background // - full screen scaling (use native resolution or windowed mode to avoid this) -consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, +consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_screentextures_ONChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grshaders = {"gr_shaders", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grshaders = {"gr_shaders", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletteshader_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -150,6 +157,8 @@ consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, consvar_t cv_grshearing = {"gr_shearing", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfakecontrast = {"gr_fakecontrast", "Standard", CV_SAVE, grfakecontrast_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grslopecontrast = {"gr_slopecontrast", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static void CV_filtermode_ONChange(void) { @@ -169,25 +178,25 @@ static void CV_screentextures_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } -static void CV_useCustomShaders_ONChange(void) +static void CV_grshaders_OnChange(void) { - if (rendermode == render_opengl) + if (rendermode == render_opengl) { - if (cv_grshaders.value) - HWD.pfnInitCustomShaders(); + if (HWR_ShouldUsePaletteRendering()) + { + InitPalette(0, false); + } + + V_SetPalette(0); } } -static void CV_grpaletteshader_OnChange(void) +static void CV_useCustomShaders_ONChange(void) { - if (rendermode == render_opengl) + if (rendermode == render_opengl) { - if (cv_grshaders.value) - { - HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); - gr_use_palette_shader = cv_grpaletteshader.value; - V_SetPalette(0); - } + if (HWR_UseShader()) + HWD.pfnInitCustomShaders(); } } @@ -198,6 +207,7 @@ static void CV_Gammaxxx_ONChange(void) V_SetPalette(0); } + // ========================================================================== // Globals // ========================================================================== @@ -227,6 +237,8 @@ static line_t *gr_linedef; static sector_t *gr_frontsector; static sector_t *gr_backsector; +static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); + boolean gr_shadersavailable = true; // Performance stats @@ -457,6 +469,21 @@ static size_t gr_numportalcullsectors = 0; // Lighting // ========================================================================== +boolean HWR_UseShader(void) +{ + return (cv_grshaders.value && gr_shadersavailable); +} + +boolean HWR_ShouldUsePaletteRendering(void) +{ + return (cv_grpaletteshader.value && HWR_UseShader()); +} + +boolean HWR_PalRenderFlashpal(void) +{ + return (cv_grpaletteshader.value && HWR_UseShader() && cv_grflashpal.value); +} + void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { RGBA_t poly_color, tint_color, fade_color; @@ -467,7 +494,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GL_DEFAULTFOG; // Crappy backup coloring if you can't do shaders - if (!cv_grshaders.value || !gr_shadersavailable) + if (!HWR_UseShader()) { // be careful, this may get negative for high lightlevel values. float tint_alpha, fade_alpha; @@ -513,7 +540,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0; Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; - if (gr_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) { if (!colormap) { @@ -552,7 +579,7 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if realcolor.rgba = (colormap != NULL) ? colormap->rgba : GL_DEFAULTMIX; - if (cv_grshaders.value && gr_shadersavailable) + if (HWR_UseShader()) { surfcolor.s.alpha = (255 - light); } @@ -615,13 +642,57 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t return (FUINT)finallight; } +static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) +{ + INT16 finallight = lightnum; + + if (cv_grfakecontrast.value != 0 && cv_grslopecontrast.value != 0) + { + const UINT8 contrast = 8; + fixed_t extralight = 0; + + if (cv_grfakecontrast.value == 2) // Smooth setting + { + fixed_t dirmul = abs(FixedDiv(AngleFixed(dir) - (180<> FRACBITS; + } + else + { + dir = ((dir + ANGLE_45) / ANGLE_90) * ANGLE_90; + + if (dir == ANGLE_180) + extralight = -contrast; + else if (dir == 0) + extralight = contrast; + + if (delta >= FRACUNIT/2) + extralight *= 2; + } + + if (extralight != 0) + { + finallight += extralight; + + if (finallight < 0) + finallight = 0; + if (finallight > 255) + finallight = 255; + } + } + + return (FUINT)finallight; +} + // ========================================================================== // Floor and ceiling generation from subsectors // ========================================================================== // HWR_RenderPlane // Render a floor or ceiling convex polygon -void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap, subsector_t *subsector) +void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { polyvertex_t * pv; float height; //constant y for all points on the convex flat polygon @@ -776,8 +847,8 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei #define SETUP3DVERT(vert, vx, vy) {\ /* Hurdler: add scrolling texture on floor/ceiling */\ - vert->s = (float)(((vx) / fflatsize) - flatxref + scrollx);\ - vert->t = (float)(flatyref - ((vy) / fflatsize) + scrolly);\ + vert->s = (float)(((vx) / fflatsize) - flatxref + scrollx);\ + vert->t = (float)(flatyref - ((vy) / fflatsize) + scrolly);\ \ /* Need to rotate before translate */\ if (angle) /* Only needs to be done if there's an altered angle */\ @@ -801,6 +872,11 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei for (i = 0, v3d = planeVerts; i < nrPlaneVerts; i++,v3d++,pv++) SETUP3DVERT(v3d, pv->x, pv->y); +#ifdef ESLOPE + if (slope) + lightlevel = HWR_CalcSlopeLight(lightlevel, R_PointToAngle2(0, 0, slope->normal.x, slope->normal.y), abs(slope->zdelta)); +#endif + HWR_Lighting(&Surf, lightlevel, planecolormap); if (PolyFlags & (PF_Translucent|PF_Fog)) @@ -811,12 +887,17 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei else PolyFlags |= PF_Masked|PF_Modulated; - if (PolyFlags & PF_Fog) - HWD.pfnSetShader(6); // fog shader - else if (PolyFlags & PF_Ripple) - HWD.pfnSetShader(5); // water shader - else - HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader + if (HWR_UseShader()) + { + if (PolyFlags & PF_Fog) + HWD.pfnSetShader(6); // fog shader + else if (PolyFlags & PF_Ripple) + HWD.pfnSetShader(5); // water shader + else + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader + + PolyFlags |= PF_ColorMapped; + } HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, false); @@ -836,7 +917,7 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei for (i = 0; i < subsector->numlines; i++, line++) { - if (line->linedef->special == 41 && R_PointOnSegSide(dup_viewx, dup_viewy, line) == 0) + if (line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(dup_viewx, dup_viewy, line) == 0) { P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); @@ -970,7 +1051,11 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) break; } - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader + } + HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, false); } } @@ -1004,7 +1089,11 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend { HWR_Lighting(pSurf, lightlevel, wallcolormap); - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader + blendmode |= PF_ColorMapped; + } // don't draw to color buffer when drawing to stencil if (gl_drawing_stencil) @@ -1024,12 +1113,10 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // -void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags) +// SoM: split up and light walls according to the lightlist. +// This may also include leaving out parts of the wall that can't be seen +static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags) { - /* SoM: split up and light walls according to the - lightlist. This may also include leaving out parts - of the wall that can't be seen */ - float realtop, realbot, top, bot; float pegt, pegb, pegmul; float height = 0.0f, bheight = 0.0f; @@ -1038,67 +1125,82 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa float endrealtop, endrealbot, endtop, endbot; float endpegt, endpegb, endpegmul; float endheight = 0.0f, endbheight = 0.0f; + + float diff; - fixed_t v1x = FLOAT_TO_FIXED(wallVerts[0].x); - fixed_t v1y = FLOAT_TO_FIXED(wallVerts[0].z); // not a typo - fixed_t v2x = FLOAT_TO_FIXED(wallVerts[1].x); - fixed_t v2y = FLOAT_TO_FIXED(wallVerts[1].z); // not a typo - // compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly - // use this as a temp var to store P_GetZAt's return value each time - fixed_t temp; + fixed_t v1x = FloatToFixed(wallVerts[0].x); + fixed_t v1y = FloatToFixed(wallVerts[0].z); + fixed_t v2x = FloatToFixed(wallVerts[1].x); + fixed_t v2y = FloatToFixed(wallVerts[1].z); #endif - INT32 solid, i; - lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->PolyColor.s.alpha; FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; + + diff = top - bot; + pegt = wallVerts[3].t; pegb = wallVerts[0].t; - pegmul = (pegb - pegt) / (top - bot); - if (fpclassify(pegmul) == FP_NAN) + // Lactozilla: If both heights of a side lay on the same position, then this wall is a triangle. + // To avoid division by zero, which would result in a NaN, we check if the vertical difference + // between the two vertices is not zero. + if (fpclassify(diff) == FP_ZERO) pegmul = 0.0; + else + pegmul = (pegb - pegt) / diff; #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; - endrealbot = endbot = wallVerts[1].y; + endrealbot = endbot = wallVerts[1].y; endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif - if (fpclassify(endpegmul) == FP_NAN) - endpegmul = 0.0; - - for (i = 0; i < sector->numlights; i++) + for (INT32 i = 0; i < sector->numlights; i++) { #ifdef ESLOPE if (endtop < endrealbot) #endif if (top < realbot) return; + + lightlist_t *list = sector->lightlist; if (!(list[i].flags & FF_NOSHADE)) { if (pfloor && (pfloor->flags & FF_FOG)) { - colormap = pfloor->master->frontsector->extra_colormap; - lightnum = pfloor->master->frontsector->lightlevel; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); + if (HWR_ShouldUsePaletteRendering()) + { + colormap = pfloor->master->frontsector->extra_colormap; + lightnum = pfloor->master->frontsector->lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); + }else{ + lightnum = HWR_CalcWallLight(pfloor->master->frontsector->lightlevel, v1x, v1y, v2x, v2y); + colormap = pfloor->master->frontsector->extra_colormap; + } } else { - colormap = list[i].extra_colormap; - lightnum = *list[i].lightlevel; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); + if (HWR_ShouldUsePaletteRendering()) + { + colormap = list[i].extra_colormap; + lightnum = *list[i].lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); + }else{ + lightnum = HWR_CalcWallLight(*list[i].lightlevel, v1x, v1y, v2x, v2y); + colormap = list[i].extra_colormap; + } } } - solid = false; + boolean solid = false; if ((sector->lightlist[i].flags & FF_CUTSOLIDS) && !(cutflag & FF_EXTRA)) solid = true; @@ -1118,21 +1220,18 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #ifdef ESLOPE if (list[i].slope) { - temp = P_GetZAt(list[i].slope, v1x, v1y); - height = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(list[i].slope, v2x, v2y); - endheight = FIXED_TO_FLOAT(temp); + height = FixedToFloat(P_GetZAt(list[i].slope, v1x, v1y)); + endheight = FixedToFloat(P_GetZAt(list[i].slope, v2x, v2y)); } else height = endheight = FIXED_TO_FLOAT(list[i].height); + if (solid) { if (*list[i].caster->b_slope) { - temp = P_GetZAt(*list[i].caster->b_slope, v1x, v1y); - bheight = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(*list[i].caster->b_slope, v2x, v2y); - endbheight = FIXED_TO_FLOAT(temp); + bheight = FixedToFloat(P_GetZAt(*list[i].caster->b_slope, v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(*list[i].caster->b_slope, v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); @@ -1161,10 +1260,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (list[i+1].slope) { - temp = P_GetZAt(list[i+1].slope, v1x, v1y); - bheight = FIXED_TO_FLOAT(temp); - temp = P_GetZAt(list[i+1].slope, v2x, v2y); - endbheight = FIXED_TO_FLOAT(temp); + bheight = FixedToFloat(P_GetZAt(list[i+1].slope, v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(list[i+1].slope, v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(list[i+1].height); @@ -1185,6 +1282,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif + if (cv_splitwallfix.value) + { #ifdef ESLOPE if (endbheight > endtop) endbot = endtop; @@ -1201,6 +1300,27 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #ifdef ESLOPE endbot = min(max(endbheight, endrealbot), endtop); #endif + }else{ +#ifdef ESLOPE + if (endbheight >= endtop) +#endif + if (bheight >= top) + continue; + + //Found a break; + bot = bheight; + + if (bot < realbot) + bot = realbot; + +#ifdef ESLOPE + endbot = endbheight; + + if (endbot < endrealbot) + endbot = endrealbot; +#endif + } + Surf->PolyColor.s.alpha = alpha; @@ -1223,13 +1343,23 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa wallVerts[2].y = wallVerts[3].y = top; wallVerts[0].y = wallVerts[1].y = bot; #endif - - if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); - else - HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + if (cv_fofzfightfix.value) + { + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + }else{ + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + } + top = bot; #ifdef ESLOPE @@ -1267,12 +1397,22 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa wallVerts[0].y = wallVerts[1].y = bot; #endif - if (cutflag & FF_FOG) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); - else if (cutflag & FF_TRANSLUCENT) - HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); - else - HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + if (cv_fofzfightfix.value) + { + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture|polyflags, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent|polyflags, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked|polyflags, lightnum, colormap); + }else{ + if (cutflag & FF_FOG) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Fog|PF_NoTexture, true, lightnum, colormap); + else if (cutflag & FF_TRANSLUCENT) + HWR_AddTransparentWall(wallVerts, Surf, texnum, PF_Translucent, false, lightnum, colormap); + else + HWR_ProjectWall(wallVerts, Surf, PF_Masked, lightnum, colormap); + } } // skywall list system for fixing portal issues by postponing skywall rendering (and using stencil buffer for them) @@ -1510,10 +1650,16 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); } - colormap = gr_frontsector->extra_colormap; - lightnum = gr_frontsector->lightlevel; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - + if (HWR_ShouldUsePaletteRendering()) + { + colormap = gr_frontsector->extra_colormap; + lightnum = gr_frontsector->lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); + }else{ + lightnum = HWR_CalcWallLight(gr_frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); + colormap = gr_frontsector->extra_colormap; + } + if (gr_frontsector) Surf.PolyColor.s.alpha = 255; @@ -1877,6 +2023,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom popentopslope = min(worldtopslope, worldhighslope); popenbottomslope = max(worldbottomslope, worldlowslope); +#else + popentop = min(front->ceilingheight, back->ceilingheight); + popenbottom = max(front->floorheight, back->floorheight); +#endif } #ifdef ESLOPE @@ -1941,38 +2091,108 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = max(polybottom, lowcut); hS = min(highcutslope, polytopslope); lS = max(polybottomslope, lowcutslope); - + // PEGGING fixed_t texturevpeg, texturevpegslope; + + grTex = HWR_GetTexture(gr_midtexture); + + if (cv_slopepegfix.value) + { + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + { + texturevpeg = midtexheight - h + polybottom; + texturevpegslope = midtexheight - hS + polybottomslope; + } + else + { + texturevpeg = polytop - h; + texturevpegslope = polytopslope - hS; + } + + wallVerts[3].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[2].t = texturevpegslope * grTex->scaleY; + wallVerts[1].t = (hS - lS + texturevpegslope) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - { - texturevpeg = midtexheight - h + polybottom; - texturevpegslope = midtexheight - hS + polybottomslope; + // set top/bottom coords + // Take the texture peg into account, rather than changing the offsets past + // where the polygon might not be. + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[1].y = FIXED_TO_FLOAT(lS); } else { - texturevpeg = polytop - h; - texturevpegslope = polytopslope - hS; - } - - grTex = HWR_GetTexture(gr_midtexture); - - wallVerts[3].t = texturevpeg * grTex->scaleY; - wallVerts[0].t = (h - l + texturevpeg) * grTex->scaleY; - wallVerts[2].t = texturevpegslope * grTex->scaleY; - wallVerts[1].t = (hS - lS + texturevpegslope) * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; - wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; - - // set top/bottom coords - // Take the texture peg into account, rather than changing the offsets past - // where the polygon might not be. - wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[0].y = FIXED_TO_FLOAT(l); - wallVerts[2].y = FIXED_TO_FLOAT(hS); - wallVerts[1].y = FIXED_TO_FLOAT(lS); + // PEGGING +#ifdef ESLOPE + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) #endif + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + + wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + + // set top/bottom coords + // Take the texture peg into account, rather than changing the offsets past + // where the polygon might not be. + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); + +#ifdef ESLOPE + // Correct to account for slopes + { + fixed_t midtextureslant; + + if (gr_linedef->flags & ML_EFFECT2) + midtextureslant = 0; + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + midtextureslant = worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + else + midtextureslant = worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + + polytop += midtextureslant; + polybottom += midtextureslant; + + highcut += worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + lowcut += worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + + // Texture stuff + h = min(highcut, polytop); + l = max(polybottom, lowcut); + + { + // PEGGING + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + } + + wallVerts[2].y = FIXED_TO_FLOAT(h); + wallVerts[1].y = FIXED_TO_FLOAT(l); + } +#endif + } // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; @@ -2045,16 +2265,27 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Render midtextures on two-sided lines with a z-buffer offset. // This will cause the midtexture appear on top, if a FOF overlaps with it. - blendmode |= PF_Decal; + if (cv_fofzfightfix.value) + blendmode |= PF_Decal; if (!gl_drawing_stencil && gr_frontsector->numlights) { - if (!(blendmode & PF_Masked)) - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); - else + if (cv_fofzfightfix.value) { - HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); - } + if (!(blendmode & PF_Masked)) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, PF_Decal); + else + { + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, PF_Decal); + } + }else{ + if (!(blendmode & PF_Masked)) + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_TRANSLUCENT, NULL, 0); + else + { + HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTLEVEL, NULL, 0); + } + } } else if (!gl_drawing_stencil && !(blendmode & PF_Masked)) HWR_AddTransparentWall(wallVerts, &Surf, gr_midtexture, blendmode, false, lightnum, colormap); @@ -2066,7 +2297,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { // Single sided line... Deal only with the middletexture (if one exists) gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); - if (gr_midtexture && gr_linedef->special != 41) // (Ignore horizon line for OGL) + if (gr_midtexture && gr_linedef->special != HORIZONSPECIAL) // Ignore horizon line for OGL { { fixed_t texturevpeg; @@ -2191,10 +2422,21 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom INT32 texnum; line_t * newline = NULL; // Multi-Property FOF - lowcut = max(worldbottom, worldlow); - highcut = min(worldtop, worldhigh); - lowcutslope = max(worldbottomslope, worldlowslope); - highcutslope = min(worldtopslope, worldhighslope); + if (!cv_grfofcut.value) + { + ///TODO add slope support (fixing cutoffs, proper wall clipping) - maybe just disable highcut/lowcut if either sector or FOF has a slope + /// to allow fun plane intersecting in OGL? But then people would abuse that and make software look bad. :C + highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; + lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; + } + else + { + lowcut = max(worldbottom, worldlow); + highcut = min(worldtop, worldhigh); + lowcutslope = max(worldbottomslope, worldlowslope); + highcutslope = min(worldtopslope, worldhighslope); + } + if (gr_backsector->ffloors) { @@ -2203,17 +2445,26 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || (rover->flags & FF_INVERTSIDES)) continue; - SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) - SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + if (!cv_grfofcut.value) + { + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + } + else + { + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + + if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) + continue; + } - if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) - continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); if (rover->master->flags & ML_TFERLINE) { - size_t linenum = gr_curline->linedef-gr_backsector->lines[0]; + size_t linenum = min(gr_curline->linedef-gr_backsector->lines[0], rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2223,17 +2474,31 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; - // Adjust the heights so the FOF does not overlap with top and bottom textures. - if (h >= highcut && hS >= highcutslope) + + + if (!cv_grfofcut.value) { - h = highcut; - hS = highcutslope; + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; } - if (l <= lowcut && lS <= lowcutslope) + else { - l = lowcut; - lS = lowcutslope; + // Adjust the heights so the FOF does not overlap with top and bottom textures. + if (h >= highcut && hS >= highcutslope) + { + h = highcut; + hS = highcutslope; + } + if (l <= lowcut && lS <= lowcutslope) + { + l = lowcut; + lS = lowcutslope; + } } + + //Hurdler: HW code starts here //FIXME: check if peging is correct // set top/bottom coords @@ -2333,11 +2598,16 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - colormap = rover->master->frontsector->extra_colormap; - lightnum = rover->master->frontsector->lightlevel; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - - + if (HWR_ShouldUsePaletteRendering()) + { + colormap = rover->master->frontsector->extra_colormap; + lightnum = rover->master->frontsector->lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); + }else{ + lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); + colormap = rover->master->frontsector->extra_colormap; + } + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); if (gr_frontsector->numlights) @@ -2375,17 +2645,26 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_ALLSIDES)) continue; - SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) - SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + if (!cv_grfofcut.value) + { + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + } + else + { + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) + + if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) + continue; + } - if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) - continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); if (rover->master->flags & ML_TFERLINE) { - size_t linenum = gr_curline->linedef-gr_backsector->lines[0]; + size_t linenum = min(gr_curline->linedef-gr_backsector->lines[0], rover->master->frontsector->linecount); newline = rover->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2394,17 +2673,29 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; - // Adjust the heights so the FOF does not overlap with top and bottom textures. - if (h >= highcut && hS >= highcutslope) + + if (!cv_grfofcut.value) { - h = highcut; - hS = highcutslope; + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; } - if (l <= lowcut && lS <= lowcutslope) + else { - l = lowcut; - lS = lowcutslope; + // Adjust the heights so the FOF does not overlap with top and bottom textures. + if (h >= highcut && hS >= highcutslope) + { + h = highcut; + hS = highcutslope; + } + if (l <= lowcut && lS <= lowcutslope) + { + l = lowcut; + lS = lowcutslope; + } } + //Hurdler: HW code starts here //FIXME: check if peging is correct // set top/bottom coords @@ -2458,9 +2749,15 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - colormap = rover->master->frontsector->extra_colormap; - lightnum = rover->master->frontsector->lightlevel; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); + if (HWR_ShouldUsePaletteRendering()) + { + colormap = rover->master->frontsector->extra_colormap; + lightnum = rover->master->frontsector->lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); + }else{ + lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); + colormap = rover->master->frontsector->extra_colormap; + } Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); @@ -2695,8 +2992,8 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle64(v1x, v1y); - angle2 = R_PointToAngle64(v2x, v2y); + angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y); + angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y); // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -2991,8 +3288,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngle64(px1, py1); - angle2 = R_PointToAngle64(px2, py2); + angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1); + angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } @@ -3008,9 +3305,9 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) void HWR_AddPolyObjectSegs(void) { size_t i, j; - seg_t *gr_fakeline = Z_Calloc(sizeof(seg_t), PU_STATIC, NULL); - polyvertex_t *pv1 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); - polyvertex_t *pv2 = Z_Calloc(sizeof(polyvertex_t), PU_STATIC, NULL); + seg_t gr_fakeline; + polyvertex_t pv1; + polyvertex_t pv2; // Sort through all the polyobjects for (i = 0; i < numpolys; ++i) @@ -3019,25 +3316,20 @@ void HWR_AddPolyObjectSegs(void) for (j = 0; j < po_ptrs[i]->segCount; ++j) { // Copy the info of a polyobject's seg, then convert it to OpenGL floating point - M_Memcpy(gr_fakeline, po_ptrs[i]->segs[j], sizeof(seg_t)); + M_Memcpy(&gr_fakeline, po_ptrs[i]->segs[j], sizeof(seg_t)); // Now convert the line to float and add it to be rendered - pv1->x = FIXED_TO_FLOAT(gr_fakeline->v1->x); - pv1->y = FIXED_TO_FLOAT(gr_fakeline->v1->y); - pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x); - pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y); + pv1.x = FIXED_TO_FLOAT(gr_fakeline.v1->x); + pv1.y = FIXED_TO_FLOAT(gr_fakeline.v1->y); + pv2.x = FIXED_TO_FLOAT(gr_fakeline.v2->x); + pv2.y = FIXED_TO_FLOAT(gr_fakeline.v2->y); - gr_fakeline->pv1 = pv1; - gr_fakeline->pv2 = pv2; + gr_fakeline.pv1 = &pv1; + gr_fakeline.pv2 = &pv2; - HWR_AddLine(gr_fakeline); + HWR_AddLine(&gr_fakeline); } } - - // Free temporary data no longer needed - Z_Free(pv2); - Z_Free(pv1); - Z_Free(gr_fakeline); } #ifdef POLYOBJECTS_PLANES @@ -3201,7 +3493,12 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t else blendmode |= PF_Masked|PF_Modulated; - HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader + blendmode |= PF_ColorMapped; + } + HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, false); } @@ -3419,11 +3716,11 @@ void HWR_Subsector(size_t num) if (sub->validcount != validcount) { HWR_GetFlat(levelflats[gr_frontsector->floorpic].lumpnum, R_NoEncore(gr_frontsector, false)); - HWR_RenderPlane(&extrasubsectors[num], false, + HWR_RenderPlane(sub, &extrasubsectors[num], false, // Hack to make things continue to work around slopes. locFloorHeight == cullFloorHeight ? locFloorHeight : gr_frontsector->floorheight, // We now return you to your regularly scheduled rendering. - PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap, sub); + PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap); } } } @@ -3435,11 +3732,11 @@ void HWR_Subsector(size_t num) if (sub->validcount != validcount) { HWR_GetFlat(levelflats[gr_frontsector->ceilingpic].lumpnum, R_NoEncore(gr_frontsector, true)); - HWR_RenderPlane(&extrasubsectors[num], true, + HWR_RenderPlane(sub, &extrasubsectors[num], true, // Hack to make things continue to work around slopes. locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gr_frontsector->ceilingheight, // We now return you to your regularly scheduled rendering. - PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, ceilingcolormap, sub); + PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, ceilingcolormap); } } } @@ -3504,8 +3801,8 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gr_frontsector, false)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(&extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, - rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap, sub); + HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3556,8 +3853,8 @@ void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gr_frontsector, true)); light = R_GetPlaneLight(gr_frontsector, centerHeight, viewz < cullHeight ? true : false); - HWR_RenderPlane(&extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, - rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap, sub); + HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } } @@ -4012,7 +4309,12 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t if (sSurf.PolyColor.s.alpha > floorheight/4) { sSurf.PolyColor.s.alpha = (UINT8)(sSurf.PolyColor.s.alpha - floorheight/4); - HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader + + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader + } + HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, false); } } @@ -4223,6 +4525,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) } alpha = Surf.PolyColor.s.alpha; + // Start with the lightlevel and colormap from the top of the sprite lightlevel = *list[sector->numlights - 1].lightlevel; @@ -4378,8 +4681,13 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) HWR_Lighting(&Surf, lightlevel, colormap); Surf.PolyColor.s.alpha = alpha; - - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader + + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader + blend |= PF_ColorMapped; + } + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); top = bot; @@ -4419,7 +4727,12 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) Surf.PolyColor.s.alpha = alpha; - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader + blend |= PF_ColorMapped; + } + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } @@ -4572,7 +4885,12 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) blend = PF_Translucent|PF_Occlude; } - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader + blend |= PF_ColorMapped; + } + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } } @@ -4666,7 +4984,12 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) blend = PF_Translucent|PF_Occlude; } - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 3); // sprite shader + blend |= PF_ColorMapped; + } + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } @@ -4827,7 +5150,12 @@ void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean planeinfo->isceiling = isceiling; planeinfo->fixedheight = fixedheight; - planeinfo->lightlevel = lightlevel; + + if (HWR_ShouldUsePaletteRendering()) + planeinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; + else + planeinfo->lightlevel = lightlevel; + planeinfo->lumpnum = lumpnum; planeinfo->xsub = xsub; planeinfo->alpha = alpha; @@ -4845,7 +5173,12 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, polyplaneinfo->isceiling = isceiling; polyplaneinfo->fixedheight = fixedheight; - polyplaneinfo->lightlevel = lightlevel; + + if (HWR_ShouldUsePaletteRendering()) + polyplaneinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; + else + polyplaneinfo->lightlevel = lightlevel; + polyplaneinfo->lumpnum = lumpnum; polyplaneinfo->polysector = polysector; polyplaneinfo->alpha = alpha; @@ -4932,19 +5265,19 @@ void HWR_RenderDrawNodes(void) { planeinfo_t *plane = &drawnode->u.plane; - // We aren't traversing the BSP tree, so make gl_frontsector null to avoid crashes. + // We aren't traversing the BSP tree, so make gr_frontsector null to avoid crashes. gr_frontsector = NULL; if (!(plane->blend & PF_NoTexture)) HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling)); - HWR_RenderPlane(plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, - plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap, NULL); + HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, + plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); } else if (drawnode->type == DRAWNODE_POLYOBJECT_PLANE) { polyplaneinfo_t *polyplane = &drawnode->u.polyplane; - // We aren't traversing the BSP tree, so make gl_frontsector null to avoid crashes. + // We aren't traversing the BSP tree, so make gr_frontsector null to avoid crashes. gr_frontsector = NULL; if (!(polyplane->blend & PF_NoTexture)) @@ -5179,6 +5512,9 @@ void HWR_ProjectSprite(mobj_t *thing) size_t lumpoff; unsigned rot; UINT8 flip; + boolean mirrored = thing->mirrored; + boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + angle_t ang; const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; @@ -5242,11 +5578,11 @@ void HWR_ProjectSprite(mobj_t *thing) rot = thing->frame&FF_FRAMEMASK; //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if (thing->skin && thing->sprite == SPR_PLAY) + if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE - sprinfo = &spriteinfo[thing->sprite]; + sprinfo = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->sprinfo; #endif } else @@ -5280,6 +5616,8 @@ void HWR_ProjectSprite(mobj_t *thing) #endif ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + if (mirrored) + ang = InvAngle(ang); if (sprframe->rotate == SRF_SINGLE) { @@ -5384,6 +5722,8 @@ void HWR_ProjectSprite(mobj_t *thing) this_xscale = spritexscale * this_scale; this_yscale = spriteyscale * this_scale; + + flip = !flip != !hflip; if (flip) { @@ -5808,8 +6148,8 @@ void HWR_PortalClipping(portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); @@ -5940,8 +6280,16 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * if (!rootportal && portallist.base && !skybox)// if portals have been drawn in the main view, then render skywalls differently gr_collect_skywalls = true; + // 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. + int oldportal_state = gr_portal; + + if (gr_portal != GRPORTAL_OFF) // if we already haven't hit the recursion limit or we already ended our portal shenanigans + gr_portal = GRPORTAL_INSIDE; // TURN IT OFF // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); + // woo we back + gr_portal = oldportal_state; PS_STOP_TIMING(ps_bsptime); @@ -6210,13 +6558,20 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grsolvetjoin); CV_RegisterVar(&cv_grbatching); + CV_RegisterVar(&cv_grfofcut); + CV_RegisterVar(&cv_fofzfightfix); + CV_RegisterVar(&cv_splitwallfix); + CV_RegisterVar(&cv_slopepegfix); + CV_RegisterVar(&cv_grscreentextures); + CV_RegisterVar(&cv_grrenderdistance); CV_RegisterVar(&cv_grgammablue); CV_RegisterVar(&cv_grgammagreen); CV_RegisterVar(&cv_grgammared); CV_RegisterVar(&cv_grfakecontrast); + CV_RegisterVar(&cv_grslopecontrast); CV_RegisterVar(&cv_grfovchange); @@ -6239,6 +6594,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grflashpal); + + CV_RegisterVar(&cv_grvhseffect); } // -------------------------------------------------------------------------- @@ -6254,6 +6611,8 @@ void HWR_Startup(void) CONS_Printf("HWR_Startup()...\n"); HWR_InitTextureCache(); HWR_InitMD2(); + + HWD.pfnSetupGLInfo(); } if (rendermode == render_opengl) @@ -6308,7 +6667,14 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, blendmode |= PF_Modulated; // No PF_Occlude means overlapping (incorrect) transparency if (!fogwall) - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader + { + if (HWR_UseShader()) + { + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 10 : 2); // wall shader + blendmode |= PF_ColorMapped; + } + } + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode, false); #ifdef WALLSPLATS @@ -6340,7 +6706,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if ((player->flashcount && !cv_grpaletteshader.value) || (player->flashcount && cv_grpaletteshader.value && !cv_grflashpal.value)) + if ((player->flashcount) && (!HWR_PalRenderFlashpal())) { FOutVector v[4]; FSurfaceInfo Surf; @@ -6460,6 +6826,11 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) HWD.pfnDoScreenWipe(); } +void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize) +{ + HWD.pfnRenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); +} + void HWR_MakeScreenFinalTexture(void) { HWD.pfnMakeScreenFinalTexture(); @@ -6467,7 +6838,7 @@ void HWR_MakeScreenFinalTexture(void) void HWR_DrawScreenFinalTexture(int width, int height) { - if (gr_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) HWD.pfnSetShader(11); //post processing HWD.pfnDrawScreenFinalTexture(width, height); } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 5098c754e..1b259e5e7 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -89,6 +89,10 @@ void HWR_AddCommands(void); void HWR_SetTransform(float fpov, player_t *player); void HWR_ClearClipper(void); +boolean HWR_UseShader(void); +boolean HWR_ShouldUsePaletteRendering(void); +boolean HWR_PalRenderFlashpal(void); + // My original intention was to split hw_main.c // into files like hw_bsp.c, hw_sprites.c... @@ -107,11 +111,12 @@ void HWR_StartScreenWipe(void); void HWR_EndScreenWipe(void); void HWR_DrawIntermissionBG(void); void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum); +void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); void HWR_MakeScreenFinalTexture(void); void HWR_DrawScreenFinalTexture(int width, int height); // hw_main.c: Planes -void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap, subsector_t *subsector); +void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap); #ifdef POLYOBJECTS @@ -127,7 +132,7 @@ void HWR_ProcessSeg(void); // Sort of like GLWall::Process in GZDoom void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blendmode, INT32 lightlevel, extracolormap_t *wallcolormap); void HWR_AddTransparentWall(FOutVector *wallVerts, FSurfaceInfo * pSurf, INT32 texnum, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap); -void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); +// moved HWR_SplitWall to hw_main.c void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf); void HWR_DrawSkyBackground(float fpov); @@ -162,6 +167,10 @@ void HWR_CorrectSWTricks(void); // Console variables extern consvar_t cv_grshaders; +extern consvar_t cv_grfofcut; +extern consvar_t cv_fofzfightfix; +extern consvar_t cv_splitwallfix; +extern consvar_t cv_slopepegfix; extern consvar_t cv_grshearing; extern consvar_t cv_grfov; extern consvar_t cv_grmdls; @@ -177,15 +186,18 @@ extern consvar_t cv_grfovchange; extern consvar_t cv_grsolvetjoin; extern consvar_t cv_grspritebillboarding; extern consvar_t cv_grfakecontrast; +extern consvar_t cv_grslopecontrast; extern consvar_t cv_grfallbackplayermodel; extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletteshader; +extern consvar_t cv_grscreentextures; extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; +extern consvar_t cv_grvhseffect; extern CV_PossibleValue_t granisotropicmode_cons_t[]; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 140c42c1f..9cd077588 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1149,6 +1149,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) INT32 tics = spr->mobj->tics; //mdlframe_t *next = NULL; const UINT8 flip = (UINT8)((spr->mobj->eflags & MFE_VERTICALFLIP) == MFE_VERTICALFLIP); + const UINT8 hflip = (UINT8)(!(spr->mobj->mirrored) != !(spr->mobj->frame & FF_HORIZONTALFLIP)); spritedef_t *sprdef; spriteframe_t *sprframe; spriteinfo_t *sprinfo; @@ -1366,17 +1367,16 @@ void HWR_DrawMD2(gr_vissprite_t *spr) angle_t sliptideroll = 0; if (spr->mobj->player) - sliptideroll = ((cv_sloperoll.value) ? spr->mobj->player->sliproll : 0); + sliptideroll = ((cv_sloperoll.value && cv_sliptideroll.value) ? spr->mobj->player->sliproll : 0); - if ((spr->mobj->rollangle)||sliptideroll) + if ((spr->mobj->rollangle)||(sliptideroll && cv_sliptideroll.value)) { angle_t rollang = 0; rollfactor = ((spr->mobj->rollmodel == true) ? 1 : 0); - if (spr->mobj->player) - rollang = (spr->mobj->rollangle*rollfactor) + (sliptideroll*spr->mobj->player->sliptidemem); - else - rollang = (spr->mobj->rollangle*rollfactor); + rollang = (spr->mobj->player && sliptideroll && cv_sliptideroll.value) + ? (spr->mobj->rollangle * rollfactor) + (sliptideroll * spr->mobj->player->sliptidemem) + : (spr->mobj->rollangle * rollfactor); fixed_t anglef = AngleFixed(rollang); p.rollangle = FIXED_TO_FLOAT(anglef); @@ -1423,7 +1423,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) HWD.pfnSetShader(4); // model shader { - float this_scale = FIXED_TO_FLOAT(interp.scale); + float this_scale = FIXED_TO_FLOAT(interp.scale); float xs = this_scale * FIXED_TO_FLOAT(interp.spritexscale); float ys = this_scale * FIXED_TO_FLOAT(interp.spriteyscale); @@ -1436,7 +1436,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.y += ox * gr_viewcos; p.z += oy; - HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, &Surf); + HWD.pfnDrawModel(md2->model, frame, durs, tics, nextFrame, &p, md2->scale * xs, md2->scale * ys, flip, hflip, &Surf); } } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9f029ce01..9a1ec5941 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -166,6 +166,8 @@ static const GLfloat byte2float[256] = { 0.972549f, 0.976471f, 0.980392f, 0.984314f, 0.988235f, 0.992157f, 0.996078f, 1.000000f }; +// Loaded OpenGL version +static int majorGL = 0, minorGL = 0; // -----------------+ // GL_DBG_Printf : Output debug messages to debug log if DEBUG_TO_FILE is defined, @@ -453,6 +455,12 @@ static PFNglCopyTexSubImage2D pglCopyTexSubImage2D; typedef GLint (APIENTRY * PFNgluBuild2DMipmaps) (GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data); static PFNgluBuild2DMipmaps pgluBuild2DMipmaps; +/* 3.0 functions */ +#ifdef GL_VERSION_3_0 +typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); +static PFNglGenerateMipmap pglGenerateMipmap; +#endif + /* 1.3 functions for multitexturing */ typedef void (APIENTRY *PFNglActiveTexture) (GLenum); static PFNglActiveTexture pglActiveTexture; @@ -629,7 +637,6 @@ static boolean gl_shaderprogramchanged = true; static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; -static INT32 gl_use_palette_shader = 0; boolean gl_palette_initialized = false; static INT32 gl_enable_screen_textures = 1; @@ -1029,6 +1036,10 @@ void SetupGLFunc4(void) // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); + +#ifdef GL_VERSION_3_0 + pglGenerateMipmap = GetGLFunc("glGenerateMipmap"); +#endif } // jimita @@ -1251,7 +1262,7 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void) KillShaders(); return LoadShaders(); - if (gl_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) { InitPalette(0, false); } @@ -1340,6 +1351,20 @@ void InitPalette(int flashnum, boolean skiplut) if (!skiplut) { + GLenum internalFormat; + if (gl_version[0] == '1' || gl_version[0] == '2') + { + // if the OpenGL version is below 3.0, then the GL_R8 format may not be available. + // so use GL_LUMINANCE8 instead to get a single component 8-bit format + // (it is possible to have access to shaders even in some OpenGL 1.x systems, + // so palette rendering can still possibly be achieved there) + internalFormat = GL_LUMINANCE8; + } + else + { + internalFormat = GL_R8; + } + // init the palette conversion lookup texture GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); @@ -1361,9 +1386,14 @@ void InitPalette(int flashnum, boolean skiplut) pglBindTexture(GL_TEXTURE_3D, palette_tex_num); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - if (!pglTexImage3D) - I_Error("pglTexImage3D is NULL!"); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); + + if (!pglTexImage3D){ + GL_MSG_Error("pglTexImage3D is NULL!"); + CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it + return; + } + + pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); free(pal_lookup_tex); } #undef STEP_SIZE @@ -1561,6 +1591,17 @@ EXPORT boolean HWRAPI(Init) (void) } +// -----------------+ +// SetupGLInfo : Retreive and store currently loaded OpenGL version +// -----------------+ +EXPORT void HWRAPI(SetupGLInfo) (void) +{ + const GLubyte *versionGL = pglGetString(GL_VERSION); + CONS_Printf("Loaded OpenGL version %s\n", (const char*)versionGL); + sscanf((const char*)versionGL, "%d.%d", &majorGL, &minorGL); +} + + // -----------------+ // ClearMipMapCache : Flush OpenGL textures from memory // -----------------+ @@ -1582,13 +1623,31 @@ EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable) ltcachetail = cache_entry; } ltcachetail->next = NULL; + + GLenum internalFormat; + if (gl_version[0] == '1' || gl_version[0] == '2') + { + // if the OpenGL version is below 3.0, then the GL_R8 format may not be available. + // so use GL_LUMINANCE8 instead to get a single component 8-bit format + // (it is possible to have access to shaders even in some OpenGL 1.x systems, + // so palette rendering can still possibly be achieved there) + internalFormat = GL_LUMINANCE8; + } + else + { + internalFormat = GL_R8; + } + pglGenTextures(1, <cachetail->id); - if (!ltcachetail->id) - I_Error("hwr lighttable cache entry id is zero"); + if (!ltcachetail->id){ + GL_MSG_Error("HWR Lighttable cache entry id is zero"); + CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it + return; + } pglBindTexture(GL_TEXTURE_2D, ltcachetail->id); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable); + pglTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable); // restore previously bound texture if (!gl_batching) @@ -1721,7 +1780,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too - if (!gl_palette_initialized) + if ((!gl_palette_initialized) && (HWR_ShouldUsePaletteRendering())) InitPalette(0, false); // just gonna put this here for now } @@ -1923,6 +1982,7 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) const GLvoid *ptex = tex; INT32 w, h; GLuint texnum = 0; + if (!pTexInfo->downloaded) { @@ -2044,12 +2104,25 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) + pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } +#ifdef GL_VERSION_3_0 + else if (majorGL >= 3) + { + pglTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -2065,12 +2138,25 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) //pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) + pgluBuild2DMipmaps(GL_TEXTURE_2D, GL_ALPHA, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } +#ifdef GL_VERSION_3_0 + else if (majorGL >= 3) + { + pglTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); //pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_LINEAR_MIPMAP_LINEAR); } else @@ -2085,13 +2171,26 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) { if (MipMap) { - pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) + pgluBuild2DMipmaps(GL_TEXTURE_2D, textureformatGL, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + else if ((majorGL == 1 && minorGL >= 4) || (majorGL == 2)) + { + pglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + } +#ifdef GL_VERSION_3_0 + else if (majorGL >= 3) + { + pglTexImage2D(GL_TEXTURE_2D, 0, textureformatGL, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ptex); + pglGenerateMipmap(GL_TEXTURE_2D); + } +#endif // Control the mipmap level of detail pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, 0); // the lower the number, the higer the detail if (pTexInfo->flags & TF_TRANSPARENT) pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 0); // No mippmaps on transparent stuff else - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 16); } else { @@ -2304,10 +2403,10 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; - if (gl_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) { - diff = poly1->surf.LightTableId - poly2->surf.LightTableId; - if (diff != 0) return diff; + diff = poly1->surf.LightTableId - poly2->surf.LightTableId; + if (diff != 0) return diff; } diff = poly1->polyFlags - poly2->polyFlags; @@ -2447,7 +2546,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i if (gl_allowshaders) { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (gl_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); @@ -2564,7 +2663,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeState = true; changePolyFlags = true; } - if ((gl_allowshaders) && (gl_use_palette_shader)) + if ((gl_allowshaders) && (HWR_ShouldUsePaletteRendering())) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2578,7 +2677,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeSurfaceInfo = true; } } - else if ((gl_allowshaders) && (!gl_use_palette_shader)) + else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering())) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2709,7 +2808,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - if (gl_use_palette_shader) + if (HWR_ShouldUsePaletteRendering()) { pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); @@ -2793,37 +2892,40 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI // PolyColor if (pSurf) { - // If Modulated, mix the surface colour to the texture + // If modulated, mix the surface colour to the texture if (CurrentPolyFlags & PF_Modulated) - { - // Poly color - 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]; - pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); - } - // Tint color - 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]; + // 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]; + } - // Fade color - 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 (gl_use_palette_shader && gl_allowshaders) + // 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]; + + 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 (HWR_ShouldUsePaletteRendering() && gl_allowshaders) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); pglActiveTexture(GL_TEXTURE0); } - } + } Shader_Load(pSurf, &poly, &tint, &fade); } @@ -3165,10 +3267,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; } break; - - case HWD_SET_PALETTE_SHADER_ENABLED: - gl_use_palette_shader = Value; - break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -3205,11 +3303,25 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) mag_filter = GL_LINEAR; min_filter = GL_NEAREST; } - if (!pgluBuild2DMipmaps) + if (majorGL == 1 && minorGL >= 0 && minorGL < 4) { - MipMap = GL_FALSE; - min_filter = GL_LINEAR; + if (!pgluBuild2DMipmaps) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } } +#ifdef GL_VERSION_3_0 + else + { + if (!pglGenerateMipmap) + { + MipMap = GL_FALSE; + min_filter = GL_LINEAR; + } + } +#endif + Flush(); //??? if we want to change filter mode by texture, remove this break; @@ -3517,7 +3629,7 @@ EXPORT void HWRAPI(CreateModelVBOs) (model_t *model) #define BUFFER_OFFSET(i) ((char*)(i)) -static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface) +static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { static GLRGBAFloat poly = {0,0,0,0}; static GLRGBAFloat tint = {0,0,0,0}; @@ -3578,12 +3690,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglEnable(GL_NORMALIZE); #ifdef USE_FTRANSFORM_MIRROR - // flipped is if the object is flipped + // flipped is if the object is vertically flipped + // hflipped is if the object is horizontally flipped // pos->flip is if the screen is flipped vertically // pos->mirror is if the screen is flipped horizontally // XOR all the flips together to figure out what culling to use! { - boolean reversecull = (flipped ^ pos->flip ^ pos->mirror); + boolean reversecull = (flipped ^ hflipped ^ pos->flip ^ pos->mirror); if (reversecull) pglCullFace(GL_FRONT); else @@ -3591,7 +3704,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float } #else // pos->flip is if the screen is flipped too - if (flipped != pos->flip) // If either are active, but not both, invert the model's culling + if (flipped ^ hflipped ^ pos->flip) // If one or three of these are active, but not two, invert the model's culling pglCullFace(GL_FRONT); else pglCullFace(GL_BACK); @@ -3601,6 +3714,8 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float pglTranslatef(pos->x, pos->z, pos->y); if (flipped) scaley = -scaley; + if (hflipped) + scalez = -scalez; #ifdef USE_FTRANSFORM_ANGLEZ pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); // rotate by slope from Kart #endif @@ -3729,9 +3844,9 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, float duration, float // -----------------+ // HWRAPI DrawModel : Draw a model // -----------------+ -EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, FSurfaceInfo *Surface) +EXPORT void HWRAPI(DrawModel) (model_t *model, INT32 frameIndex, float duration, float tics, INT32 nextFrameIndex, FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) { - DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, Surface); + DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, pos, hscale, vscale, flipped, hflipped, Surface); } // -----------------+ @@ -4145,6 +4260,107 @@ EXPORT void HWRAPI(MakeScreenTexture) (void) tex_downloaded = screentexture; } +EXPORT void HWRAPI(RenderVhsEffect) (fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize) +{ + INT32 texsize = 512; + float xfix, yfix; + float fix[8]; + GLubyte color[4] = {255, 255, 255, 255}; + float i; + + float screenVerts[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 + }; + + // look for power of two that is large enough for the screen + while (texsize < screen_width || texsize < screen_height) + texsize <<= 1; + + xfix = 1/((float)(texsize)/((float)((screen_width)))); + yfix = 1/((float)(texsize)/((float)((screen_height)))); + + // Slight fuzziness + MakeScreenTexture(); + SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest); + pglBindTexture(GL_TEXTURE_2D, screentexture); + + for (i = 0; i < 1; i += 2.f/vid.height) + { + fix[2] = (float)(rand() % 128) / -22000 * xfix; + fix[0] = fix[2]; + fix[6] = fix[0] + xfix; + fix[4] = fix[2] + xfix; + fix[1] = fix[7] = i*yfix; + fix[3] = fix[5] = (i+0.015)*yfix; + + screenVerts[1] = screenVerts[10] = 2*i - 1.0f; + screenVerts[4] = screenVerts[7] = screenVerts[1] + 0.03; + + pglColor4ubv(color); + + pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + } + + // Upward bar + MakeScreenTexture(); + pglBindTexture(GL_TEXTURE_2D, screentexture); + color[0] = color[1] = color[2] = 190; + color[3] = 250; + pglColor4ubv(color); + + fix[0] = 0.0f; + fix[6] = xfix; + fix[2] = (float)updistort / screen_width * xfix; + fix[4] = fix[2] + fix[6]; + + screenVerts[1] = screenVerts[10] = 2.0f*upbary/screen_height - 1.0f; + screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/screen_height; + + fix[1] = fix[7] = (float)upbary/screen_height * yfix; + fix[3] = fix[5] = fix[1] + (float)barsize/2/screen_height * yfix; + + pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + fix[1] = fix[7] += (fix[3] - fix[7])*2; + screenVerts[1] = screenVerts[10] += (screenVerts[4] - screenVerts[1])*2; + pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + // Downward bar + MakeScreenTexture(); + pglBindTexture(GL_TEXTURE_2D, screentexture); + + fix[0] = 0.0f; + fix[6] = xfix; + fix[2] = (float)downdistort / screen_width * -xfix; + fix[4] = fix[2] + fix[6]; + + screenVerts[1] = screenVerts[10] = 2.0f*downbary/screen_height - 1.0f; + screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/screen_height; + + fix[1] = fix[7] = (float)downbary/screen_height * yfix; + fix[3] = fix[5] = fix[1] + (float)barsize/2/screen_height * yfix; + + pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + fix[1] = fix[7] += (fix[3] - fix[7])*2; + screenVerts[1] = screenVerts[10] += (screenVerts[4] - screenVerts[1])*2; + pglTexCoordPointer(2, GL_FLOAT, 0, fix); + pglVertexPointer(3, GL_FLOAT, 0, screenVerts); + pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); +} + EXPORT void HWRAPI(MakeScreenFinalTexture) (void) { INT32 texsize = 512; @@ -4241,7 +4457,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) // prepare shader, if it is enabled Shader_SetUniforms(NULL, NULL, NULL, NULL); - if (gl_use_palette_shader && cv_grshaders.value) + if (HWR_ShouldUsePaletteRendering()) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglActiveTexture(GL_TEXTURE1); @@ -4255,7 +4471,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (gl_use_palette_shader && cv_grshaders.value) + if (HWR_ShouldUsePaletteRendering()) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); diff --git a/src/hardware/s_fmod/s_fmod.c b/src/hardware/s_fmod/s_fmod.c index 9dd1cacbb..5d4422bb1 100644 --- a/src/hardware/s_fmod/s_fmod.c +++ b/src/hardware/s_fmod/s_fmod.c @@ -534,9 +534,6 @@ EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) case FSOUND_OUTPUT_A3D: DBG_Printf("FMOD driver: A3D driver.\n"); break; - case FSOUND_OUTPUT_XBOX: - DBG_Printf("FMOD driver: Xbox driver\n"); - break; case FSOUND_OUTPUT_OSS: DBG_Printf("FMOD driver: Linux/Unix OSS (Open Sound System) driver, i.e. the kernel sound drivers.\n"); break; @@ -549,12 +546,6 @@ EXPORT INT32 HWRAPI(Startup) (I_Error_t FatalErrorFunction, snddev_t *snd_dev) case FSOUND_OUTPUT_MAC: DBG_Printf("FMOD driver: Mac SoundManager driver\n"); break; - case FSOUND_OUTPUT_PS2: - DBG_Printf("FMOD driver: PlayStation 2 driver\n"); - break; - case FSOUND_OUTPUT_GC: - DBG_Printf("FMOD driver: Gamecube driver\n"); - break; case FSOUND_OUTPUT_NOSOUND_NONREALTIME: DBG_Printf("FMOD driver: This is the same as nosound, but the sound generation is driven by FSOUND_Update\n"); break; diff --git a/src/http-mserv.c b/src/http-mserv.c index 5b7928a8f..7ad84b71f 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -42,8 +42,9 @@ consvar_t cv_masterserver_timeout = { NULL, 0, NULL, NULL, 0, 0, NULL/* C90 moment */ }; +CV_PossibleValue_t masterserver_debug_cons_t[] = {{0, "Off"}, {1, "PrintOnly"}, {2, "On"}, {0, NULL}}; consvar_t cv_masterserver_debug = { - "masterserver_debug", "Off", CV_SAVE|CV_CALL, CV_OnOff, + "masterserver_debug", "Off", CV_SAVE|CV_CALL, masterserver_debug_cons_t, MasterServer_Debug_OnChange, 0, NULL, NULL, 0, 0, NULL/* C90 moment */ }; @@ -86,12 +87,17 @@ Printf_url (const char *url) { boolean startup; +#ifdef HAVE_THREADS I_lock_mutex(&con_mutex); startup = con_startup; I_unlock_mutex(con_mutex); +#else + startup = con_startup; +#endif - (startup ? I_OutputMsg : CONS_Printf)( - "HMS: connecting '%s'...\n", url); + if (cv_masterserver_debug.value) + (startup ? I_OutputMsg : CONS_Printf)( + "HMS: connecting '%s'...\n", url); } static size_t @@ -201,7 +207,7 @@ HMS_connect (const char *format, ...) buffer->buffer = malloc(buffer->end); buffer->needle = 0; - if (cv_masterserver_debug.value) + if (cv_masterserver_debug.value == 2) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_STDERR, logstream); @@ -385,7 +391,7 @@ HMS_list_servers (void) if (! hms) return; - if (HMS_do(hms)) + if (HMS_do(hms) && cv_masterserver_debug.value) { CONS_Printf("%s\n", hms->buffer); } @@ -579,7 +585,7 @@ MasterServer_Debug_OnChange (void) { #ifdef MASTERSERVER /* TODO: change to 'latest-log.txt' for log files revision. */ - if (cv_masterserver_debug.value) + if (cv_masterserver_debug.value == 2) CONS_Printf("Master server debug messages will appear in log.txt\n"); #endif } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f6e7a9caf..e63fceffb 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1142,6 +1142,10 @@ void HU_Ticker(void) } if (cechotimer > 0) --cechotimer; + + // Animate the desynch dots + if (hu_resynching) + resynch_ticker++; //tic tic tic tic tic HU_TickSongCredits(); } @@ -2579,8 +2583,24 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) gfxnum = Ping_gfx_num(lag); if (measureid == 1) - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + { + if (cv_ticrate.value == 2){ + V_DrawScaledPatch(x+12 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); + }else{ + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + } + } + + + if (cv_pingicon.value) + { + if (cv_ticrate.value == 2){ + V_DrawScaledPatch(x+2, y+13, flags, pinggfx[gfxnum]); + }else{ + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + } + } + if (servermaxping && lag > servermaxping && hu_tick < 4) { @@ -2592,11 +2612,21 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) { lag = (INT32)(lag * (1000.00f / TICRATE)); } + + if (cv_ticrate.value == 2){ + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+22, flags, lag, colormap); + }else{ + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + } - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); - - if (measureid == 0) - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + if (measureid == 0){ + if (cv_ticrate.value == 2){ + V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+22, flags, pingmeasure[measureid]); + }else{ + V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + } + } + } // @@ -2684,10 +2714,16 @@ static void HU_DrawRankings(void) hilicol = ((gametype == GT_RACE) ? V_SKYMAP : V_REDMAP); // draw the current gametype in the lower right - if (modeattacking) - V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, "Record Attack"); + //if (modeattacking) + //V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, "Record Attack"); + //else + //V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, gametype_cons_t[gametype].strvalue); + + // draw the current map in the lower right if theres none just say its unknown + if (!G_BuildMapTitle(gamemap)) + V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, "UNKNOWN"); else - V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, gametype_cons_t[gametype].strvalue); + V_DrawString(4, 188, hilicol|V_SNAPTOBOTTOM|V_SNAPTOLEFT, G_BuildMapTitle(gamemap)); if (G_GametypeHasTeams()) { diff --git a/src/i_net.h b/src/i_net.h index b9da94ec4..c3391a1ed 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -79,19 +79,24 @@ typedef struct char data[MAXPACKETLENGTH]; } ATTRPACK doomcom_t; +#ifdef HOLEPUNCH typedef struct { INT32 magic; INT32 addr; INT16 port; } ATTRPACK holepunch_t; +#endif #if defined(_MSC_VER) #pragma pack() #endif extern doomcom_t *doomcom; + +#ifdef HOLEPUNCH extern holepunch_t *holepunchpacket; +#endif /** \brief return packet in doomcom struct */ @@ -152,12 +157,14 @@ extern void (*I_NetCloseSocket)(void); /** \brief send a hole punching request */ +#ifdef HOLEPUNCH extern void (*I_NetRequestHolePunch)(INT32 node); - +#endif /** \brief register this machine on the hole punching server */ +#ifdef HOLEPUNCH extern void (*I_NetRegisterHolePunch)(void); - +#endif extern boolean (*I_Ban) (INT32 node); extern void (*I_ClearBans)(void); diff --git a/src/i_system.h b/src/i_system.h index 05826c79e..87198c923 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -369,6 +369,4 @@ const char *I_ClipboardPaste(void); void I_RegisterSysCommands(void); -void I_CursedWindowMovement(int xd, int yd); - #endif diff --git a/src/i_tcp.c b/src/i_tcp.c index 9162d61ae..1ebffc59b 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -201,8 +201,10 @@ static size_t broadcastaddresses = 0; static boolean nodeconnected[MAXNETNODES+1]; static banned_t *banned; /* See ../doc/Holepunch-Protocol.txt */ +#ifdef HOLEPUNCH static const INT32 hole_punch_magic = MSBF_LONG (0x52eb11); #endif +#endif static size_t numbans = 0; static size_t banned_size = 0; @@ -609,8 +611,10 @@ is_external_address (UINT32 p) } } +#ifdef HOLEPUNCH static boolean hole_punch(ssize_t c) { + /* See ../doc/Holepunch-Protocol.txt */ if (cv_rendezvousserver.string[0] && c == 10 && holepunchpacket->magic == hole_punch_magic && @@ -631,7 +635,9 @@ static boolean hole_punch(ssize_t c) { return false; } + } +#endif // Returns true if a packet was received from a new node, false in all other cases static boolean SOCK_Get(void) @@ -655,11 +661,12 @@ static boolean SOCK_Get(void) break; } #endif - +#ifdef HOLEPUNCH if (hole_punch(c)) { break; } +#endif // find remote node number for (j = 1; j <= MAXNETNODES; j++) //include LAN @@ -1363,7 +1370,7 @@ static SINT8 SOCK_NetMakeNodewPort(const char *address, const char *port) } /* See ../doc/Holepunch-Protocol.txt */ - +#ifdef HOLEPUNCH static void rendezvous(int size) { char *addrs = strdup(cv_rendezvousserver.string); @@ -1391,7 +1398,9 @@ static void rendezvous(int size) if (tic == refreshtic) { + #ifdef HOLEPUNCH holepunchpacket->magic = hole_punch_magic; + #endif sendto(mysockets[0], doomcom->data, size, 0, &rzv.any, sizeof rzv.ip4); } @@ -1417,6 +1426,8 @@ static void SOCK_RegisterHolePunch(void) } #endif +#endif + static boolean SOCK_OpenSocket(void) { #ifndef NONET @@ -1439,9 +1450,11 @@ static boolean SOCK_OpenSocket(void) I_NetCanSend = SOCK_CanSend; I_NetCanGet = SOCK_CanGet; #endif +#ifdef HOLEPUNCH I_NetRequestHolePunch = SOCK_RequestHolePunch; I_NetRegisterHolePunch = SOCK_RegisterHolePunch; +#endif // build the socket but close it first SOCK_CloseSocket(); diff --git a/src/i_time.c b/src/i_time.c index 292df0a66..a1ef580bd 100644 --- a/src/i_time.c +++ b/src/i_time.c @@ -30,12 +30,6 @@ static precise_t enterprecise, oldenterprecise; static fixed_t entertic, oldentertics; static double tictimer; -// A little more than the minimum sleep duration on Windows. -// May be incorrect for other platforms, but we don't currently have a way to -// query the scheduler granularity. SDL will do what's needed to make this as -// low as possible though. -#define MIN_SLEEP_DURATION_MS 2.1 - tic_t I_GetTime(void) { return g_time.time; @@ -86,38 +80,3 @@ void I_UpdateTime(fixed_t timescale) g_time.timefrac = FLOAT_TO_FIXED(fractional); } } - -void I_SleepDuration(precise_t duration) -{ - UINT64 precision = I_GetPrecisePrecision(); - INT32 sleepvalue = cv_sleep.value; - UINT64 delaygranularity; - precise_t cur; - precise_t dest; - - { - double gran = round(((double)(precision / 1000) * sleepvalue * MIN_SLEEP_DURATION_MS)); - delaygranularity = (UINT64)gran; - } - - cur = I_GetPreciseTime(); - dest = cur + duration; - - // the reason this is not dest > cur is because the precise counter may wrap - // two's complement arithmetic is our friend here, though! - // e.g. cur 0xFFFFFFFFFFFFFFFE = -2, dest 0x0000000000000001 = 1 - // 0x0000000000000001 - 0xFFFFFFFFFFFFFFFE = 3 - while ((INT64)(dest - cur) > 0) - { - // If our cv_sleep value exceeds the remaining sleep duration, use the - // hard sleep function. - if (sleepvalue > 0 && (dest - cur) > delaygranularity) - { - I_Sleep(sleepvalue); - } - - // Otherwise, this is a spinloop. - - cur = I_GetPreciseTime(); - } -} diff --git a/src/k_kart.c b/src/k_kart.c index 563f4aca9..a73656e3b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8,6 +8,7 @@ #include "hu_stuff.h" #include "g_game.h" #include "m_random.h" +#include "m_menu.h" // ffdhidshfuisduifigergho9igj89dgodhfih AAAAAAAAAA #include "p_local.h" #include "p_slopes.h" #include "r_draw.h" @@ -54,25 +55,33 @@ consvar_t cv_mini_yoffset = {"hud_minimap_yoffset", "0", CV_SAVE, NULL, NULL, 0, consvar_t cv_want_xoffset = {"hud_wanted_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_want_yoffset = {"hud_wanted_yoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_newspeedometer = {"newspeedometer", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_stat_xoffset = {"hud_stat_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_stat_yoffset = {"hud_stat_yoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +//extra hud things +consvar_t cv_showstats = {"showstats", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showinput = {"showinput", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t speedo_cons_t[] = {{1, "Default"}, {2, "Small"}, {3, "P-Meter"}, {0, NULL}}; +consvar_t cv_newspeedometer = {"newspeedometer", "Default", CV_SAVE, speedo_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +//hardcode saltyhop mhhm consvar_t cv_saltyhop = {"hardcodehop", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_saltyhopsfx = {"hardcodehopsfx", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_saltysquish = {"hardcodehopsquish", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //Colourized HUD -consvar_t cv_colorizedhud = {"colorizedhud", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_colorizedhud = {"colorizedhud", "Off", CV_SAVE|CV_CALL, CV_OnOff, Saturn_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_colorizeditembox = {"colorizeditembox", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t HudColor_cons_t[MAXSKINCOLORS+1]; consvar_t cv_colorizedhudcolor = {"colorizedhudcolor", "Skin Color", CV_SAVE, HudColor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_highresportrait = {"highresportrait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //make char potraits use their high-res version instead -consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // here for ppl who dont want to make 2 more patches for their custom hud +consvar_t cv_darkitembox = {"darkitembox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //itembox gets a dark box with specific items +consvar_t cv_biglaps = {"biglaphud", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //here for ppl who dont want to make 2 more patches for their custom hud // SOME IMPORTANT VARIABLES DEFINED IN DOOMDEF.H: // gamespeed is cc (0 for easy, 1 for normal, 2 for hard) @@ -553,7 +562,7 @@ void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, bo return; } - starttranscolor = (skinnum != TC_DEFAULT) ? ( (local) ? localskins : skins )[skinnum].starttranscolor : DEFAULT_STARTTRANSCOLOR; + starttranscolor = (skinnum != TC_DEFAULT) ? ((local) ? localskins : skins)[skinnum].starttranscolor : DEFAULT_STARTTRANSCOLOR; // Fill in the entries of the palette that are fixed for (i = 0; i < starttranscolor; i++) @@ -587,11 +596,18 @@ UINT8 K_GetKartColorByName(const char *name) return 0; } -UINT8 K_GetHudColor() +UINT8 K_GetHudColor(void) +{ + if (cv_colorizedhud.value){ + if (cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; + } + if (stplyr && P_IsLocalPlayer(stplyr) && gamestate == GS_LEVEL) return stplyr->skincolor; + return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); +} + +boolean K_UseColorHud(void) { - if (stplyr && players - stplyr != consoleplayer) return stplyr->skincolor; - if (cv_colorizedhudcolor.value) return cv_colorizedhudcolor.value; - return cv_playercolor.value; + return (cv_colorizedhud.value && clr_hud); } //} @@ -679,10 +695,14 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_mini_yoffset); CV_RegisterVar(&cv_want_xoffset); CV_RegisterVar(&cv_want_yoffset); + CV_RegisterVar(&cv_stat_xoffset); + CV_RegisterVar(&cv_stat_yoffset); + CV_RegisterVar(&cv_showstats); CV_RegisterVar(&cv_showinput); CV_RegisterVar(&cv_newspeedometer); + CV_RegisterVar(&cv_saltyhop); CV_RegisterVar(&cv_saltyhopsfx); CV_RegisterVar(&cv_saltysquish); @@ -696,6 +716,8 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_biglaps); + CV_RegisterVar(&cv_highresportrait); + CV_RegisterVar(&cv_slamsound); CV_RegisterVar(&cv_minihead); @@ -705,6 +727,9 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_stagetitle); CV_RegisterVar(&cv_lessflicker); + + CV_RegisterVar(&cv_mouseturn); + } //} @@ -3059,7 +3084,7 @@ static void K_SpawnAIZDust(player_t *player) static void K_StretchPlayerGravity(player_t *p) { - fixed_t mos = mapobjectscale; + fixed_t mos = FRACUNIT; fixed_t rzs = abs(p->mo->momz); fixed_t zspd = abs(rzs/mos); fixed_t stretchScaleFactor = 0; @@ -3087,7 +3112,7 @@ static void K_StretchPlayerGravity(player_t *p) if (p->mo->slamsoundtimer) p->mo->slamsoundtimer--; - if (cv_slamsound.value == 1 && (p->mo->eflags & MFE_JUSTHITFLOOR) && p->mo->stretchslam > 4*mos && !p->mo->slamsoundtimer) + if (cv_slamsound.value && (p->mo->eflags & MFE_JUSTHITFLOOR) && p->mo->stretchslam > 4*mos && !p->mo->slamsoundtimer) { S_StartSound(p->mo, sfx_s3k4c); p->mo->slamsoundtimer = TICRATE; @@ -3120,12 +3145,11 @@ static void K_StretchPlayerGravity(player_t *p) else slamDiv = FixedDiv(p->mo->stretchslam, stretchScaleFactor); p->mo->spritexscale = (dxs+(((slamDiv*2)/3)*2)); - p->mo->spriteyscale = ((dys-(slamDiv))); + p->mo->spriteyscale = (dys-(slamDiv)); if (p->mo->stretchslam > 0) p->mo->stretchslam -= (4*mos); else p->mo->stretchslam = 0; - } } @@ -3193,6 +3217,7 @@ static void K_QuiteSaltyHop(player_t *p) static INT32 K_FindPlayerNum(player_t *plyr) { INT32 i; + for(i = 0; i < 4; i++) { if (plyr == &players[displayplayers[i]]) @@ -3222,7 +3247,6 @@ static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useRes lookAngle = R_PointToAngle2(camera[pNum].x, camera[pNum].y, p->mo->x, p->mo->y); - if (!R_PointToDist(p->mo->x, p->mo->y)) lookAngle = p->mo->angle; @@ -3234,13 +3258,10 @@ static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useRes p->mo->reservezangle = zangle; p->mo->reservexydir = xydirection; } - else + else if (p->mo->reservezangle) { - if (p->mo->reservezangle) - { - zangle = p->mo->reservezangle; - xydirection = p->mo->reservexydir; - } + zangle = p->mo->reservezangle; + xydirection = p->mo->reservexydir; } if ((p->mo->eflags & MFE_VERTICALFLIP) && (!dontflip)) @@ -3248,12 +3269,10 @@ static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useRes an = (lookAngle - xydirection); final_slope = -(FixedMul(FINESINE(an>>ANGLETOFINESHIFT), zangle)); - an = (INT32)(final_slope - p->tilt_sprite) / 3; // instead of just a direct snap - - if (an) - p->tilt_sprite += an; - else - p->tilt_sprite = final_slope; + + an = (INT32)(final_slope - p->tilt_sprite) / (camspin[pNum] ? 1 : 3); + + p->tilt_sprite = an ? p->tilt_sprite + an : final_slope; return -p->tilt_sprite; } @@ -6007,7 +6026,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) P_SetScale(overlay, player->mo->scale); } player->kartstuff[k_invincibilitytimer] = itemtime+(2*TICRATE); // 10 seconds - if (P_IsLocalPlayer(player)) + if (P_IsLocalPlayer(player) && cv_supermusic.value && cv_birdmusic.value) S_ChangeMusicSpecial("kinvnc"); else S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmi : sfx_kinvnc)); @@ -6212,7 +6231,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if (cv_kartdebugshrink.value && !modeattacking && !player->bot) player->mo->destscale = (6*player->mo->destscale)/8; player->kartstuff[k_growshrinktimer] = itemtime+(4*TICRATE); // 12 seconds - if (P_IsLocalPlayer(player)) + if (P_IsLocalPlayer(player) && cv_growmusic.value && cv_birdmusic.value ) S_ChangeMusicSpecial("kgrow"); else S_StartSound(player->mo, (cv_kartinvinsfx.value ? sfx_alarmg : sfx_kgrow)); @@ -6881,21 +6900,15 @@ void K_UpdateSpectateGrief(void) INT32 i; if (nospectategrief) - { return; - } if (leveltime <= (starttime + 20*TICRATE)) - { return; - } for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i] || players[i].spectator) - { continue; - } numingame++; } @@ -6944,6 +6957,10 @@ static patch_t *skp_smallstickerclr; static patch_t *kp_itemmulstickerclr[2]; static patch_t *kp_itembgclr[4]; + +//Kartz speedo +static patch_t *kp_kartzspeedo[25]; + static patch_t *kp_startcountdown[16]; static patch_t *kp_racefinish[6]; @@ -7029,12 +7046,12 @@ void K_LoadKartHUDGraphics(void) kp_karmasticker = W_CachePatchName("K_STKARM", PU_HUDGFX); kp_splitkarmabomb = W_CachePatchName("K_SPTKRM", PU_HUDGFX); kp_timeoutsticker = W_CachePatchName("K_STTOUT", PU_HUDGFX); - + if (big_lap){ kp_lapstickerbig = W_CachePatchName("K_STLAPB", PU_HUDGFX); kp_lapstickerbig2 = W_CachePatchName("K_STLA2B", PU_HUDGFX); - } - + } + //Colourized hud if (clr_hud) { @@ -7056,12 +7073,41 @@ void K_LoadKartHUDGraphics(void) kp_lapstickerbigclr = W_CachePatchName("K_SCLAPB", PU_HUDGFX); kp_lapstickerbig2clr = W_CachePatchName("K_SCLA2B", PU_HUDGFX); } - - if (snw_speedo){ + + if (snw_speedo) skp_smallstickerclr = W_CachePatchName("SC_SMSTC", PU_HUDGFX); - } } + //KartZ speedo + if (kartzspeedo) + { + kp_kartzspeedo[0] = W_CachePatchName("K_KZSP1", PU_HUDGFX); + kp_kartzspeedo[1] = W_CachePatchName("K_KZSP2", PU_HUDGFX); + kp_kartzspeedo[2] = W_CachePatchName("K_KZSP3", PU_HUDGFX); + kp_kartzspeedo[3] = W_CachePatchName("K_KZSP4", PU_HUDGFX); + kp_kartzspeedo[4] = W_CachePatchName("K_KZSP5", PU_HUDGFX); + kp_kartzspeedo[5] = W_CachePatchName("K_KZSP6", PU_HUDGFX); + kp_kartzspeedo[6] = W_CachePatchName("K_KZSP7", PU_HUDGFX); + kp_kartzspeedo[7] = W_CachePatchName("K_KZSP8", PU_HUDGFX); + kp_kartzspeedo[8] = W_CachePatchName("K_KZSP9", PU_HUDGFX); + kp_kartzspeedo[9] = W_CachePatchName("K_KZSP10", PU_HUDGFX); + kp_kartzspeedo[10] = W_CachePatchName("K_KZSP11", PU_HUDGFX); + kp_kartzspeedo[11] = W_CachePatchName("K_KZSP12", PU_HUDGFX); + kp_kartzspeedo[12] = W_CachePatchName("K_KZSP13", PU_HUDGFX); + kp_kartzspeedo[13] = W_CachePatchName("K_KZSP14", PU_HUDGFX); + kp_kartzspeedo[14] = W_CachePatchName("K_KZSP15", PU_HUDGFX); + kp_kartzspeedo[15] = W_CachePatchName("K_KZSP16", PU_HUDGFX); + kp_kartzspeedo[16] = W_CachePatchName("K_KZSP17", PU_HUDGFX); + kp_kartzspeedo[17] = W_CachePatchName("K_KZSP18", PU_HUDGFX); + kp_kartzspeedo[18] = W_CachePatchName("K_KZSP19", PU_HUDGFX); + kp_kartzspeedo[19] = W_CachePatchName("K_KZSP20", PU_HUDGFX); + kp_kartzspeedo[20] = W_CachePatchName("K_KZSP21", PU_HUDGFX); + kp_kartzspeedo[21] = W_CachePatchName("K_KZSP22", PU_HUDGFX); + kp_kartzspeedo[22] = W_CachePatchName("K_KZSP23", PU_HUDGFX); + kp_kartzspeedo[23] = W_CachePatchName("K_KZSP24", PU_HUDGFX); + kp_kartzspeedo[24] = W_CachePatchName("K_KZSP25", PU_HUDGFX); + } + // Starting countdown kp_startcountdown[0] = W_CachePatchName("K_CNT3A", PU_HUDGFX); kp_startcountdown[1] = W_CachePatchName("K_CNT2A", PU_HUDGFX); @@ -7531,6 +7577,121 @@ INT32 K_calcSplitFlags(INT32 snapflags) return (splitflags|snapflags); } +static void K_drawKartStats(void) +{ + INT32 x, y, spdoffset, flags; + + // For 1-player display + x = 15; + y = 150; + spdoffset = 0; + flags = V_SNAPTOBOTTOM|V_SNAPTOLEFT; + + UINT8 splitnum = 0; + + for (; splitnum < MAXSPLITSCREENPLAYERS; ++splitnum) + { + if (stplyr == &players[displayplayers[splitnum]]) + break; + } + +#ifdef HAVE_BLUA + if (!LUA_HudEnabled(hud_statdisplay)) + return; +#endif + + + // I tried my best, but this is still mess :/ + if (splitscreen) + { + if (splitscreen == 1) + { + // If we are in 2-player splitscreen, for player 1 we move hud to up and remove snapping + // to bottom + if (splitnum == 0) + { + y /= 2; + flags = V_SNAPTOLEFT; + } + else + { + // Can move it down a bit + y += 20; + } + } + else + { + // In 4-player splitscreen... + flags = 0; + + // ...For players 2 and 4, which are at right side, we move x coordinate... + if (splitnum == 1 || splitnum == 3) + x += BASEVIDWIDTH/2; + // ...Else, for players on left side we can snap position to left... + else + flags |= V_SNAPTOLEFT; + + // ...For players 1 and 2, which are at top side, we move y coordinate... + if (splitnum == 0 || splitnum == 1) + y /= 2; + // ...Else, for players on bottom side we can snap position to bottom + else + { + flags |= V_SNAPTOBOTTOM; + // Can move it down a bit + y += 20; + } + } + } + + //Internal offset for speedometer + if (cv_kartspeedometer.value) + { + if (cv_newspeedometer.value == 2 && snw_speedo) + spdoffset = -10; + else + spdoffset = -14; + } + else + spdoffset = 0; + + // Customizations c: + x += 18 + cv_stat_xoffset.value; + y += cv_stat_yoffset.value + (G_BattleGametype() ? (stplyr->kartstuff[k_bumper] ? -5 : -8) : 0) + spdoffset; + flags |= V_HUDTRANS; + + skin_t *fakeskin; + fakeskin = &skins[stplyr->skin]; + + // local skinner + if (stplyr->localskin) + { + if (stplyr->skinlocal) + fakeskin = &localskins[stplyr->localskin - 1]; + else + fakeskin = &skins[stplyr->localskin - 1]; + } + + if (!splitscreen) + { + // Skin name + V_DrawSmallString(x+20, y+12, flags|V_ALLOWLOWERCASE, va("%c%s", V_GetSkincolorChar(stplyr->skincolor), fakeskin->realname)); + + // Icon and stats + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x, y, flags, R_GetSkinFaceWant(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); + else + V_DrawMappedPatch(x, y, flags, R_GetSkinFaceRank(stplyr), R_GetLocalTranslationColormap(fakeskin, fakeskin, stplyr->skincolor, GTC_CACHE, stplyr->skinlocal)); + V_DrawMappedPatch(x-3, y-2, flags, kp_facenum[min(9, max(1, stplyr->kartspeed))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BLUEBERRY, GTC_CACHE)); + V_DrawMappedPatch(x+10, y+10, flags, kp_facenum[min(9, max(1, stplyr->kartweight))], R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_BURGUNDY, GTC_CACHE)); + } + else + { + // In splitscreen, just draw a string with stats + V_DrawString(x, y+10, flags, va("\x84%dS \x87%dW", stplyr->kartspeed, stplyr->kartweight)); + } +} + static void K_drawKartItem(void) { // ITEM_X = BASEVIDWIDTH-50; // 270 @@ -7542,7 +7703,7 @@ static void K_drawKartItem(void) patch_t *localpatch = kp_nodraw; patch_t *localbg; - if (cv_colorizeditembox.value && cv_colorizedhud.value && clr_hud) + if (cv_colorizeditembox.value && K_UseColorHud()) localbg = ((offset) ? kp_itembgclr[2] : kp_itembgclr[0]); else localbg = ((offset) ? kp_itembg[2] : kp_itembg[0]); @@ -7706,12 +7867,8 @@ static void K_drawKartItem(void) break; case KITEM_INVINCIBILITY: localpatch = localinv; - if (cv_darkitembox.value){ - if (cv_colorizeditembox.value && cv_colorizedhud.value && clr_hud) - localbg = kp_itembgclr[offset+1]; - else - localbg = kp_itembg[offset+1]; - } + if (cv_darkitembox.value) + localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; break; case KITEM_BANANA: localpatch = kp_banana[offset]; @@ -7733,12 +7890,8 @@ static void K_drawKartItem(void) break; case KITEM_SPB: localpatch = kp_selfpropelledbomb[offset]; - if (cv_darkitembox.value){ - if (cv_colorizeditembox.value && cv_colorizedhud.value && clr_hud) - localbg = kp_itembgclr[offset+1]; - else - localbg = kp_itembg[offset+1]; - } + if (cv_darkitembox.value) + localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; break; case KITEM_GROW: localpatch = kp_grow[offset]; @@ -7748,12 +7901,8 @@ static void K_drawKartItem(void) break; case KITEM_THUNDERSHIELD: localpatch = kp_thundershield[offset]; - if (cv_darkitembox.value){ - if (cv_colorizeditembox.value && cv_colorizedhud.value && clr_hud) - localbg = kp_itembgclr[offset+1]; - else - localbg = kp_itembg[offset+1]; - } + if (cv_darkitembox.value) + localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; break; case KITEM_HYUDORO: localpatch = kp_hyudoro[offset]; @@ -7822,31 +7971,18 @@ static void K_drawKartItem(void) colmap = R_GetTranslationColormap(colormode, localcolor, GTC_CACHE); - if (cv_colorizeditembox.value && cv_colorizedhud.value && clr_hud) - { + if (cv_colorizeditembox.value && K_UseColorHud()) V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, localbg,colormap); - } else - { V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, localbg); - } - - - - // Then, the numbers: if (stplyr->kartstuff[k_itemamount] >= numberdisplaymin && !stplyr->kartstuff[k_itemroulette]) { - //Colourized hud - if (cv_colorizedhud.value && clr_hud) - { - V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulstickerclr[offset],colormap); // flip this graphic for p2 and p4 in split and shift it. - } - else - { - V_DrawScaledPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulsticker[offset]); // flip this graphic for p2 and p4 in split and shift it. - } + if (!K_UseColorHud()) + V_DrawScaledPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulsticker[offset]); + else //Colourized hud + V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulstickerclr[offset], colormap); // flip this graphic for p2 and p4 in split and shift it. V_DrawFixedPatch(fx<kartstuff[k_itemamount])); else { - V_DrawScaledPatch(fy+28, fy+41, V_HUDTRANS|fflags, kp_itemx); + V_DrawScaledPatch(fx+28, fy+41, V_HUDTRANS|fflags, kp_itemx); V_DrawKartString(fx+38, fy+36, V_HUDTRANS|fflags, va("%d", stplyr->kartstuff[k_itemamount])); } } @@ -7910,14 +8046,11 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI } } - - if (!cv_colorizedhud.value || !clr_hud) + if (!K_UseColorHud()) V_DrawScaledPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwide : kp_timestickerwide)); - else + else //Colourized hud { - //Colourized hud UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(TX, TY, splitflags, ((mode == 2) ? kp_lapstickerwideclr : kp_timestickerwideclr), colormap); } @@ -8078,9 +8211,8 @@ static void K_DrawKartPositionNum(INT32 num) scale *= 2; overtake = true; // this is used for splitscreen stuff in conjunction with flipdraw. } - if (splitscreen) - scale /= 2; - if (cv_showinput.value && !splitscreen) // anuther one. + + if (splitscreen || (cv_showinput.value && !splitscreen)) scale /= 2; W = FixedMul(W<>FRACBITS; @@ -8285,7 +8417,10 @@ static boolean K_drawKartPositionFaces(void) { player_t *p; p = &players[rankplayer[i]]; - V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, ( (p->skinlocal) ? localfacerankprefix : facerankprefix )[( (p->localskin) ? p->localskin-1 : p->skin )], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceWant(p), colormap); + else + V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, R_GetSkinFaceRank(p), colormap); } #ifdef HAVE_BLUA @@ -8375,7 +8510,10 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I { player_t *p; p = &players[tab[i].num]; - V_DrawMappedPatch(x, y-4, 0, ( (p->skinlocal) ? localfacerankprefix : facerankprefix )[( (p->localskin) ? p->localskin-1 : p->skin )], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x, y-4, 0, R_GetSkinFaceWant(p), colormap); + else + V_DrawMappedPatch(x, y-4, 0, R_GetSkinFaceRank(p), colormap); } /*if (G_BattleGametype() && players[tab[i].num].kartstuff[k_bumper] > 0) -- not enough space for this { @@ -8438,6 +8576,14 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I } } +static boolean K_BigLapSticker(void) +{ + if (K_UseColorHud()) + return ((cv_numlaps.value > 9) && (big_lap_color) && (cv_biglaps.value) && (!stplyr->exiting)); + else + return ((cv_numlaps.value > 9) && (big_lap) && (cv_biglaps.value) && (!stplyr->exiting)); +} + static void K_drawKartLaps(void) { INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); @@ -8447,7 +8593,6 @@ static void K_drawKartLaps(void) if (splitscreen > 1) { - // pain and suffering defined below if (splitscreen < 2) // don't change shit for THIS splitscreen. { @@ -8472,8 +8617,6 @@ static void K_drawKartLaps(void) } } - - if (stplyr->exiting) // draw stuff as god intended. { V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, kp_splitlapflag); @@ -8495,31 +8638,22 @@ static void K_drawKartLaps(void) } else { - - if (!cv_colorizedhud.value || !clr_hud){ - if ((cv_numlaps.value > 9) && (big_lap) && (cv_biglaps.value)){ - if (stplyr->laps+1 > 9) - V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerbig2); - else - V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerbig); - } + if (!K_UseColorHud()) + { + if (K_BigLapSticker()) + V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig)); else V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapsticker); } - else + else //Colourized hud { - //Colourized hud UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - if ((cv_numlaps.value > 9) && (big_lap_color) && (cv_biglaps.value)){ - if (stplyr->laps+1 > 9) - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerbig2clr, colormap); - else - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerbigclr, colormap); - } + if (K_BigLapSticker()) + V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr), colormap); else V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerclr, colormap); } - + if (stplyr->exiting) V_DrawKartString(LAPS_X+33, LAPS_Y+3, V_HUDTRANS|splitflags, "FIN"); else @@ -8534,6 +8668,11 @@ static void K_drawKartSpeedometer(void) return; fixed_t convSpeed = 0; + + //KartZ speedo + fixed_t fuspeed = 0; + INT32 spdpatch = 0; + INT32 speedtype = 0; INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); @@ -8562,7 +8701,7 @@ static void K_drawKartSpeedometer(void) } // man. - if ((!cv_newspeedometer.value) || (cv_newspeedometer.value && !snw_speedo)) + if ((cv_newspeedometer.value == 1) || (cv_newspeedometer.value == 2 && !snw_speedo) || (cv_newspeedometer.value == 3 && !kartzspeedo)) { switch (speedtype) { case 1: @@ -8581,21 +8720,86 @@ static void K_drawKartSpeedometer(void) V_DrawKartString(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, va("%4d %%", convSpeed)); } } - else if (cv_newspeedometer.value && snw_speedo) { // why bother if we dont? - if (!cv_colorizedhud.value || !clr_hud) + else if (cv_newspeedometer.value == 2 && snw_speedo) // why bother if we dont? + { + if (!K_UseColorHud()) V_DrawScaledPatch(SPDM_X + 1, SPDM_Y + 4, (V_HUDTRANS|splitflags), (skp_smallsticker)); - else + else //Colourized hud { - //Colourized hud UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - V_DrawMappedPatch(SPDM_X + 1, SPDM_Y + 4, (V_HUDTRANS|splitflags), (skp_smallstickerclr), colormap); } V_DrawRankNum(SPDM_X + 26, SPDM_Y + 4, V_HUDTRANS|splitflags, convSpeed, 3, NULL); V_DrawScaledPatch(SPDM_X + 31, SPDM_Y + 4, V_HUDTRANS|splitflags, skp_speedpatches[cv_kartspeedometer.value]); + } + + // Kart Z speedo bullshit... + // Draw the Speed counter. + // Warning large if statement below... + else if (cv_newspeedometer.value == 3 && kartzspeedo) + { + fuspeed = FixedDiv(stplyr->speed, mapobjectscale)/FRACUNIT; + + if (fuspeed < 2 && fuspeed > 0) + spdpatch = 0; + else if (fuspeed < 5 && fuspeed > 1) + spdpatch = 1; + else if (fuspeed < 7 && fuspeed > 4) + spdpatch = 2; + else if (fuspeed < 10 && fuspeed > 6) + spdpatch = 3; + else if (fuspeed < 12 && fuspeed > 9) + spdpatch = 4; + else if (fuspeed < 15 && fuspeed > 11) + spdpatch = 5; + else if (fuspeed < 17 && fuspeed > 14) + spdpatch = 6; + else if (fuspeed < 20 && fuspeed > 16) + spdpatch = 7; + else if (fuspeed < 22 && fuspeed > 19) + spdpatch = 8; + else if (fuspeed < 25 && fuspeed > 21) + spdpatch = 9; + else if (fuspeed < 27 && fuspeed > 24) + spdpatch = 10; + else if (fuspeed < 30 && fuspeed > 26) + spdpatch = 11; + else if (fuspeed < 32 && fuspeed > 29) + spdpatch = 12; + else if (fuspeed < 35 && fuspeed > 31) + spdpatch = 13; + else if (fuspeed < 37 && fuspeed > 34) + spdpatch = 14; + else if (fuspeed < 40 && fuspeed > 36) + spdpatch = 15; + else if (fuspeed < 42 && fuspeed > 39) + spdpatch = 16; + else if (fuspeed < 45 && fuspeed > 41) + spdpatch = 17; + else if (fuspeed < 47 && fuspeed > 44) + spdpatch = 18; + else if (fuspeed < 50 && fuspeed > 46) + spdpatch = 19; + else if (fuspeed < 52 && fuspeed > 49) + spdpatch = 20; + else if (fuspeed < 55 && fuspeed > 51) + spdpatch = 21; + else if (fuspeed < 57 && fuspeed > 54 && (leveltime&4)) + spdpatch = 24; + else if (fuspeed < 57 && fuspeed > 54 && !(leveltime&4)) + spdpatch = 23; + else if (fuspeed < 60 && fuspeed > 56 && (leveltime&4)) + spdpatch = 24; + else if (fuspeed < 60 && fuspeed > 56 && !(leveltime&4)) + spdpatch = 23; + else if (fuspeed > 59 && (leveltime&4)) + spdpatch = 24; + else if (fuspeed > 59 && !(leveltime&4)) + spdpatch = 23; + V_DrawScaledPatch(SPDM_X, SPDM_Y, V_HUDTRANS|splitflags, kp_kartzspeedo[spdpatch]); } } @@ -8609,7 +8813,6 @@ static void K_drawKartBumpersOrKarma(void) if (splitscreen > 1) { - // we will reuse lap coords here since it's essentially the same shit. if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3... @@ -8631,7 +8834,7 @@ static void K_drawKartBumpersOrKarma(void) V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_splitkarmabomb, colormap); V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, va("%d/2", stplyr->kartstuff[k_comebackpoints])); } - else // the above doesn't need to account for weird stuff since the max amount of karma necessary is always 2 ^^^^ + else // the above doesn't need to account for weird stuff since the max amount of karma necessary is always 2 ^^^^ { if (flipstring) // for p2 and p4, assume we can have more than 10 bumpers. It's retarded but who knows. { @@ -8640,7 +8843,7 @@ static void K_drawKartBumpersOrKarma(void) V_DrawMappedPatch(BASEVIDWIDTH-stringw-16, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); V_DrawRightAlignedString(BASEVIDWIDTH-3, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); } - else // draw bumpers normally. + else // draw bumpers normally. { V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); @@ -8651,39 +8854,15 @@ static void K_drawKartBumpersOrKarma(void) { if (stplyr->kartstuff[k_bumper] <= 0) { - //Colourized hud - if (cv_colorizedhud.value && clr_hud) - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_karmastickerclr, colormap); - } - else - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_karmasticker, colormap); - } + V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_karmastickerclr : kp_karmasticker), colormap); V_DrawKartString(LAPS_X+47, LAPS_Y+3, V_HUDTRANS|splitflags, va("%d/2", stplyr->kartstuff[k_comebackpoints])); } else { if (stplyr->kartstuff[k_bumper] > 9 && cv_kartbumpers.value > 9) - //Colourized hud - if (cv_colorizedhud.value && clr_hud) - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_bumperstickerwideclr, colormap); - } - else - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_bumperstickerwide, colormap); - } + V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_bumperstickerwideclr : kp_bumperstickerwide), colormap); else - //Colourized hud - if (cv_colorizedhud.value && clr_hud) - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_bumperstickerclr, colormap); - } - else - { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_bumpersticker, colormap); - } + V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_bumperstickerclr : kp_bumpersticker), colormap); V_DrawKartString(LAPS_X+47, LAPS_Y+3, V_HUDTRANS|splitflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); } @@ -8783,7 +8962,7 @@ static void K_drawKartWanted(void) if (players[battlewanted[i]].skincolor) { colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); - V_DrawFixedPatch(x<skinlocal) ? localfacewantprefix : facewantprefix )[( (p->localskin) ? p->localskin-1 : p->skin )] : ( (p->skinlocal) ? localfacerankprefix : facerankprefix )[( (p->localskin) ? p->localskin-1 : p->skin )]), colormap); + V_DrawFixedPatch(x<skin] : facerankprefix[p->skin]), colormap);*/ } @@ -8863,7 +9042,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat fixed_t xscale, yscale, zoom; if (mo->skin) - skin = ((skin_t*)( (mo->localskin) ? mo->localskin : mo->skin ))-( (skinlocal) ? localskins : skins ); + skin = ((skin_t*)((mo->localskin) ? mo->localskin : mo->skin))-((skinlocal) ? localskins : skins); maxx = maxy = INT32_MAX; minx = miny = INT32_MIN; @@ -8907,39 +9086,37 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((x + AutomapPic->width/2 - (( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin]->width/2))<height/2 - (( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin]->height/2))<width/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->width/2))<height/2 - (((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin]->height/2))<color) // 'default' color V_DrawSciencePatch(amxpos, amypos, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], FRACUNIT); else { - UINT8 *colormap = R_GetTranslationColormap((mo->colorized) ? TC_RAINBOW : skin, mo->color, GTC_CACHE); + UINT8 *colormap; + if (mo->colorized) + colormap = R_GetTranslationColormap(TC_RAINBOW, mo->color, GTC_CACHE); + else + colormap = R_GetLocalTranslationColormap(mo->skin, mo->localskin, mo->color, GTC_CACHE, skinlocal); - if (cv_minihead.value == 1) - { - colormap = R_GetLocalTranslationColormap(mo->skin, mo->localskin, mo->color, GTC_CACHE, skinlocal); - V_DrawFixedPatch(amxpos + (2 * FRACUNIT), amypos + (2 * FRACUNIT), FRACUNIT/2, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], colormap); - } - else if (cv_minihead.value == 0) - { - colormap = R_GetLocalTranslationColormap(mo->skin, mo->localskin, mo->color, GTC_CACHE, skinlocal); - V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], colormap); - } + if (cv_minihead.value) + V_DrawFixedPatch(amxpos + (2*FRACUNIT), amypos + (2*FRACUNIT), FRACUNIT/2, flags, ((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin], colormap); + else + V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, ((skinlocal) ? localfacemmapprefix : facemmapprefix)[skin], colormap); if (cv_showminimapnames.value && !(modeattacking || gamestate == GS_TIMEATTACK)) { const char *player_name = va("%c%s", V_GetSkincolorChar(mo->color), player_names[mo->player - players]); - V_DrawCenteredSmallStringAtFixed(amxpos + (4 * FRACUNIT), amypos - (3 * FRACUNIT), V_ALLOWLOWERCASE|flags, player_name); + V_DrawCenteredSmallStringAtFixed(amxpos + (4*FRACUNIT), amypos - (3*FRACUNIT), V_ALLOWLOWERCASE|flags, player_name); } if (mo->player && ((G_RaceGametype() && mo->player->kartstuff[k_position] == spbplace) || (G_BattleGametype() && K_IsPlayerWanted(mo->player)))) { - if (cv_minihead.value == 1) - V_DrawFixedPatch(amxpos, amypos, FRACUNIT / 2, flags, kp_wantedreticle, NULL); - else if (cv_minihead.value == 0) - V_DrawFixedPatch(amxpos - (4<kartstuff[k_comebacktimer]/TICRATE)); else { - if (!cv_colorizedhud.value || !clr_hud) + if (!K_UseColorHud()) V_DrawFixedPatch(x<kartstuff[k_lapanimation]; UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); @@ -9809,6 +9981,12 @@ void K_drawKartHUD(void) #endif K_drawInput(); + if (!demo.title && cv_showstats.value) +#ifdef HAVE_BLUA + if (LUA_HudEnabled(hud_statdisplay)) +#endif + K_drawKartStats(); + if (demo.title) // Draw title logo instead in demo.titles { INT32 x = BASEVIDWIDTH - 32, y = 128, offs; @@ -9900,7 +10078,7 @@ void K_drawKartHUD(void) { if (stplyr->exiting) K_drawKartFinish(); - else if (stplyr->kartstuff[k_lapanimation] && !splitscreen) + else if (stplyr->kartstuff[k_lapanimation] && !splitscreen && cv_showlapemblem.value) K_drawLapStartAnim(); } diff --git a/src/k_kart.h b/src/k_kart.h index 1b8e9c7ab..40353f5df 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -17,7 +17,7 @@ extern const UINT8 KartColor_Opposite[MAXSKINCOLORS*2]; void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor); void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local); UINT8 K_GetKartColorByName(const char *name); -UINT8 K_GetHudColor(); +UINT8 K_GetHudColor(void); void K_RegisterKartStuff(void); @@ -26,6 +26,10 @@ extern consvar_t cv_colorizeditembox; extern consvar_t cv_colorizedhudcolor; extern consvar_t cv_darkitembox; extern consvar_t cv_biglaps; +extern consvar_t cv_highresportrait; +extern consvar_t cv_stat_xoffset; +extern consvar_t cv_stat_yoffset; +extern consvar_t cv_showstats; boolean K_IsPlayerLosing(player_t *player); boolean K_IsPlayerWanted(player_t *player); diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d9344f65f..1e6a5cb29 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -430,6 +430,9 @@ void LUAh_PlayerJoin(int playernum) void LUAh_PreThinkFrame(void) { hook_p hookp; + // variables used by perf stats + int hook_index = 0; + precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8)))) return; @@ -437,19 +440,32 @@ void LUAh_PreThinkFrame(void) for (hookp = roothook; hookp; hookp = hookp->next) { - if (hookp->type != hook_PreThinkFrame) - continue; - - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); - if (lua_pcall(gL, 0, 0, 1)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; + if (hookp->type == hook_PreThinkFrame) + { + if (cv_perfstats.value == 4) + time_taken = I_GetPreciseTime(); + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + if (cv_perfstats.value == 4) + { + lua_Debug ar; + time_taken = I_GetPreciseTime() - time_taken; + // we need the function, let's just retrieve it again + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_getinfo(gL, ">S", &ar); + PS_SetPreThinkFrameHookInfo(hook_index, time_taken, ar.short_src); + hook_index++; + } } - } + } lua_pop(gL, 1); // Pop error handler } @@ -498,6 +514,9 @@ void LUAh_ThinkFrame(void) void LUAh_PostThinkFrame(void) { hook_p hookp; + // variables used by perf stats + int hook_index = 0; + precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_PostThinkFrame/8] & (1<<(hook_PostThinkFrame%8)))) return; @@ -505,19 +524,31 @@ void LUAh_PostThinkFrame(void) for (hookp = roothook; hookp; hookp = hookp->next) { - if (hookp->type != hook_PostThinkFrame) - continue; - - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); - if (lua_pcall(gL, 0, 0, 1)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; + if (hookp->type == hook_PostThinkFrame) + { + if (cv_perfstats.value == 5) + time_taken = I_GetPreciseTime(); + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + if (cv_perfstats.value == 5) + { + lua_Debug ar; + time_taken = I_GetPreciseTime() - time_taken; + // we need the function, let's just retrieve it again + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_getinfo(gL, ">S", &ar); + PS_SetPostThinkFrameHookInfo(hook_index, time_taken, ar.short_src); + hook_index++; + } } } - lua_pop(gL, 1); // Pop error handler } diff --git a/src/lua_hud.h b/src/lua_hud.h index 26b8cf0b0..db759bbfa 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -31,6 +31,7 @@ enum hud { hud_battlecomebacktimer, // comeback timer in battlefullscreen. separated for ease of use. hud_wanted, hud_speedometer, + hud_statdisplay, hud_freeplay, hud_rankings, // Tab rankings diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index f58d9ca72..04bbaa928 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -54,6 +54,7 @@ static const char *const hud_disable_options[] = { "battlecomebacktimer", // come back timer in battlefullscreen "wanted", "speedometer", + "statdisplay", "freeplay", "rankings", NULL}; @@ -595,6 +596,42 @@ static int libd_drawOnMinimap(lua_State *L) return 0; } +static int libd_drawStretched(lua_State *L) +{ + fixed_t x, y, hscale, vscale; + INT32 flags; + patch_t *patch; + UINT8 *colormap = NULL; + huddrawlist_h list; + + HUDONLY + x = luaL_checkinteger(L, 1); + y = luaL_checkinteger(L, 2); + hscale = luaL_checkinteger(L, 3); + if (hscale < 0) + return luaL_error(L, "negative horizontal scale"); + vscale = luaL_checkinteger(L, 4); + if (vscale < 0) + return luaL_error(L, "negative vertical scale"); + patch = *((patch_t **)luaL_checkudata(L, 5, META_PATCH)); + flags = luaL_optinteger(L, 6, 0); + if (!lua_isnoneornil(L, 7)) + colormap = *((UINT8 **)luaL_checkudata(L, 7, META_COLORMAP)); + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); + list = (huddrawlist_h) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (LUA_HUD_IsDrawListValid(list)) + LUA_HUD_AddDrawStretched(list, x, y, hscale, vscale, patch, flags, colormap); + else + V_DrawStretchyFixedPatch(x, y, hscale, vscale, flags, patch, colormap); + return 0; +} + + static int libd_drawNum(lua_State *L) { INT32 x, y, flags, num; @@ -912,6 +949,7 @@ static luaL_Reg lib_draw[] = { {"cachePatch", libd_cachePatch}, {"draw", libd_draw}, {"drawScaled", libd_drawScaled}, + {"drawStretched", libd_drawStretched}, {"drawNum", libd_drawNum}, {"drawPaddedNum", libd_drawPaddedNum}, {"drawPingNum", libd_drawPingNum}, diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index eedbff910..c543c15d8 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -20,6 +20,7 @@ enum drawitem_e { DI_Draw = 0, DI_DrawScaled, + DI_DrawStretched, DI_DrawNum, DI_DrawPaddedNum, DI_DrawPingNum, @@ -216,6 +217,29 @@ void LUA_HUD_AddDrawScaled( item->colormap = colormap; } +void LUA_HUD_AddDrawStretched( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t hscale, + fixed_t vscale, + patch_t *patch, + INT32 flags, + UINT8 *colormap +) +{ + size_t i = AllocateDrawItem(list); + drawitem_t *item = &list->items[i]; + item->type = DI_DrawStretched; + item->x = x; + item->y = y; + item->hscale = hscale; + item->vscale = vscale; + item->patch = patch; + item->flags = flags; + item->colormap = colormap; +} + void LUA_HUD_AddDrawNum( huddrawlist_h list, INT32 x, @@ -377,6 +401,9 @@ void LUA_HUD_DrawList(huddrawlist_h list) case DI_DrawScaled: V_DrawFixedPatch(item->x, item->y, item->scale, item->flags, item->patch, item->colormap); break; + case DI_DrawStretched: + V_DrawStretchyFixedPatch(item->x, item->y, item->hscale, item->vscale, item->flags, item->patch, item->colormap); + break; case DI_DrawNum: V_DrawTallNum(item->x, item->y, item->flags, item->num); break; diff --git a/src/lua_hudlib_drawlist.h b/src/lua_hudlib_drawlist.h index 992578778..4354b6f95 100644 --- a/src/lua_hudlib_drawlist.h +++ b/src/lua_hudlib_drawlist.h @@ -42,6 +42,16 @@ void LUA_HUD_AddDraw( INT32 flags, UINT8 *colormap ); +void LUA_HUD_AddDrawStretched( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t hscale, + fixed_t vscale, + patch_t *patch, + INT32 flags, + UINT8 *colormap +); void LUA_HUD_AddDrawScaled( huddrawlist_h list, fixed_t x, diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index cfc5c8e5f..52eda4554 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -143,6 +143,7 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, cvmem, udatalib_getter_int32, udatalib_setter_int32), FIELD(mobj_t, standingslope, udatalib_getter_slope, mobj_standingslope_noset), FIELD(mobj_t, colorized, udatalib_getter_boolean, udatalib_setter_boolean), + FIELD(mobj_t, mirrored, udatalib_getter_boolean, udatalib_setter_boolean), FIELD(mobj_t, rollmodel, udatalib_getter_boolean, udatalib_setter_boolean), { NULL }, }; @@ -217,7 +218,7 @@ UNIMPLEMENTED(mobjnum) // For some dumb reason it is valid to set sloperoll, even though it is read // only -int mobj_sloperoll_noop(lua_State *L) { return 0; } +int mobj_sloperoll_noop(lua_State *L) { (void)L; return 0; } // Now other getters/setters with arbitary logic @@ -415,13 +416,40 @@ int mobj_localskin_setter(lua_State *L) { mobj_t *mo = GETMO(); - // TODO - add ability to set localskin to non-player mobjs - // Will probably just need to reimplement SetLocalPlayerSkin as something - // like SetLocalObjectSkin - if (!mo->player) - return luaL_error(L, "mobj.localskin can't be set for non-player mobjs!"); + if (mo->player) + { + SetLocalPlayerSkin(mo->player - players, luaL_checkstring(L, 2), NULL); + } + else + { + INT32 i; + char skin[SKINNAMESIZE+1]; // all skin names are limited to this length + strlcpy(skin, luaL_checkstring(L, 2), sizeof skin); + strlwr(skin); // all skin names are lowercase + + // Try localskins + for (i = 0; i < numlocalskins; i++) + { + if (stricmp(localskins[i].name, skin) == 0) + { + mo->localskin = &localskins[i]; + mo->skinlocal = true; + return 0; + } + } + + // Try other skins + for (i = 0; i < numskins; i++) + { + if (fastcmp(skins[i].name, skin)) + { + mo->localskin = &skins[i]; + mo->skinlocal = false; + return 0; + } + } + } - SetLocalPlayerSkin(mo->player - players, luaL_checkstring(L, 2), NULL); return 0; } diff --git a/src/m_anigif.c b/src/m_anigif.c index 8071f030d..744651319 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -465,19 +465,23 @@ static size_t gifframe_size = 8192; static void GIF_rgbconvert(UINT8 *linear, UINT8 *scr) { UINT8 r, g, b; - size_t src = 0, dest = 0; - size_t size = (vid.width * vid.height * 3); + size_t src, dest; + int x, y; InitColorLUT(); - while (src < size) + for (x = 0; x < vid.width; x += scrbuf_downscaleamt) { - r = (UINT8)linear[src]; - g = (UINT8)linear[src + 1]; - b = (UINT8)linear[src + 2]; - scr[dest] = colorlookup[r >> SHIFTCOLORBITS][g >> SHIFTCOLORBITS][b >> SHIFTCOLORBITS]; - src += (3 * scrbuf_downscaleamt); - dest += scrbuf_downscaleamt; + for (y = 0; y < vid.height; y += scrbuf_downscaleamt) + { + dest = y*vid.width + x; + src = dest*3; + + r = (UINT8)linear[src]; + g = (UINT8)linear[src + 1]; + b = (UINT8)linear[src + 2]; + scr[dest] = colorlookup[r >> SHIFTCOLORBITS][g >> SHIFTCOLORBITS][b >> SHIFTCOLORBITS]; + } } } #endif @@ -514,7 +518,7 @@ static void GIF_framewrite(void) { UINT8 *linear = HWR_GetScreenshot(); GIF_rgbconvert(linear, movie_screen); - free(linear); + //free(linear); // Allocated 'statically', no need to free now } #endif } @@ -530,7 +534,7 @@ static void GIF_framewrite(void) { UINT8 *linear = HWR_GetScreenshot(); GIF_rgbconvert(linear, screens[0]); - free(linear); + //free(linear); // Allocated 'statically', no need to free now } #endif diff --git a/src/m_fixed.h b/src/m_fixed.h index e64c9e0d4..9d1ea399f 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -20,11 +20,6 @@ #include #endif -// Was this just for the #define USEASM? -//#ifdef _WIN32_WCE -//#include "sdl12/SRB2CE/cehelp.h" -//#endif - /*! \brief bits of the fraction */ @@ -43,6 +38,8 @@ typedef INT32 fixed_t; +typedef UINT32 ufixed_t; + /*! \brief convert fixed_t into floating number */ @@ -61,7 +58,6 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f) #define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT)) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) - /** \brief The FixedMul function \param a fixed_t number @@ -115,7 +111,7 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedInt(fixed_t a) */ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedDiv(fixed_t a, fixed_t b) { - if ((abs(a) >> (FRACBITS-2)) >= abs(b)) + if (((ufixed_t)abs(a) >> (FRACBITS-2)) >= (ufixed_t)abs(b)) return (a^b) < 0 ? INT32_MIN : INT32_MAX; return FixedDiv2(a, b); diff --git a/src/m_menu.c b/src/m_menu.c index b95bb4806..cae64b85b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -146,6 +146,8 @@ boolean browselocalskins = false; boolean menuactive = false; boolean fromlevelselect = false; +static INT32 coolalphatimer = 9; + typedef enum { LLM_CREATESERVER, @@ -222,6 +224,7 @@ static void M_GetAllEmeralds(INT32 choice); static void M_DestroyRobots(INT32 choice); //static void M_LevelSelectWarp(INT32 choice); static void M_Credits(INT32 choice); +static void M_MusicTest(INT32 choice); static void M_PandorasBox(INT32 choice); static void M_EmblemHints(INT32 choice); static char *M_GetConditionString(condition_t cond); @@ -271,12 +274,16 @@ static menu_t SP_TimeAttackDef, SP_ReplayDef, SP_GuestReplayDef, SP_GhostDef; // Multiplayer #ifndef NONET static void M_PreStartServerMenu(INT32 choice); +#ifdef MASTERSERVER static void M_PreStartServerMenuChoice(event_t *ev); static void M_PreConnectMenu(INT32 choice); static void M_PreConnectMenuChoice(event_t *ev); +#endif static void M_StartServerMenu(INT32 choice); +#ifdef MASTERSERVER static void M_ConnectMenu(INT32 choice); static void M_ConnectMenuModChecks(INT32 choice); +#endif static void M_Refresh(INT32 choice); static void M_Connect(INT32 choice); #endif @@ -310,14 +317,12 @@ static void M_ChangeControl(INT32 choice); static void M_ResetControls(INT32 choice); // Video & Sound -menu_t OP_VideoOptionsDef, OP_VideoModeDef; +menu_t OP_VideoOptionsDef, OP_VideoModeDef, OP_ExpOptionsDef; #ifdef HWRENDER menu_t OP_OpenGLOptionsDef, OP_OpenGLColorDef; #endif menu_t OP_SoundOptionsDef; -#ifdef HAVE_OPENMPT menu_t OP_SoundAdvancedDef; -#endif //static void M_RestartAudio(void); //Misc @@ -384,11 +389,12 @@ static UINT8 playback_enterheld = 0; // horrid hack to prevent holding the butto // Drawing functions static void M_DrawGenericMenu(void); static void M_DrawGenericBackgroundMenu(void); -//static void M_DrawGenericScrollMenu(void); +static void M_DrawGenericScrollMenu(void); static void M_DrawCenteredMenu(void); static void M_DrawAddons(void); static void M_DrawSkyRoom(void); static void M_DrawChecklist(void); +static void M_DrawMusicTest(void); static void M_DrawEmblemHints(void); static void M_DrawPauseMenu(void); static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade); @@ -423,6 +429,7 @@ static boolean M_ExitPandorasBox(void); static boolean M_QuitMultiPlayerMenu(void); static void M_HandleAddons(INT32 choice); static void M_HandleSoundTest(INT32 choice); +static void M_HandleMusicTest(INT32 choice); static void M_HandleImageDef(INT32 choice); //static void M_HandleLoadSave(INT32 choice); static void M_HandleLevelStats(INT32 choice); @@ -463,7 +470,9 @@ CV_PossibleValue_t gametype_cons_t[NUMGAMETYPES+1]; consvar_t cv_newgametype = {"newgametype", "Race", CV_HIDEN|CV_CALL, gametype_cons_t, Newgametype_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showallmaps = {"showallmaps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_showallmaps = {"showallmaps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_showmusicfilename = {"showmusicfilename", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t serversort_cons_t[] = { {0,"Ping"}, @@ -854,6 +863,12 @@ static menuitem_t SR_UnlockChecklistMenu[] = {IT_SUBMENU | IT_STRING, NULL, "NEXT", &MainDef, 192}, }; +static menuitem_t SR_MusicTestMenu[] = +{ + {IT_KEYHANDLER | IT_STRING, NULL, "", M_HandleMusicTest, 0}, +}; + + static menuitem_t SR_EmblemHintMenu[] = { {IT_STRING|IT_CVAR, NULL, "Medal Radar", &cv_itemfinder, 10}, @@ -1048,7 +1063,11 @@ static menuitem_t MP_MainMenu[] = {IT_HEADER, NULL, "Join a game", NULL, 132-24}, #ifndef NONET +#ifndef MASTERSERVER + {IT_GRAYEDOUT, NULL, "Internet server browser...",NULL, 142-24}, +#else {IT_STRING|IT_CALL, NULL, "Internet server browser...",M_PreConnectMenu, 142-24}, +#endif {IT_STRING|IT_CALL, NULL, "Join last server", M_ConnectLastServer, 150-24}, {IT_STRING|IT_KEYHANDLER, NULL, "Specify IPv4 address:", M_HandleConnectIP, 158-24}, #else @@ -1065,7 +1084,11 @@ static menuitem_t MP_MainMenu[] = static menuitem_t MP_ServerMenu[] = { {IT_STRING|IT_CVAR, NULL, "Max. Player Count", &cv_maxplayers, 10}, +#ifndef MASTERSERVER + {IT_GRAYEDOUT, NULL, "Advertise", NULL, 20}, +#else {IT_STRING|IT_CVAR, NULL, "Advertise", &cv_advertise, 20}, +#endif {IT_STRING|IT_CVAR|IT_CV_STRING, NULL, "Server Name", &cv_servername, 30}, {IT_STRING|IT_CVAR, NULL, "Game Type", &cv_newgametype, 68}, @@ -1084,7 +1107,7 @@ static menuitem_t MP_OfflineServerMenu[] = {IT_WHITESTRING|IT_CALL, NULL, "Start", M_StartServer, 130}, }; - +//Char select static menuitem_t MP_PlayerSetupMenu[] = { {IT_KEYHANDLER | IT_STRING, NULL, "Name", M_HandleSetupMultiPlayer, 0}, @@ -1092,6 +1115,9 @@ static menuitem_t MP_PlayerSetupMenu[] = {IT_KEYHANDLER | IT_STRING, NULL, "Color", M_HandleSetupMultiPlayer, 152}, }; + + + #ifndef NONET static menuitem_t MP_ConnectMenu[] = { @@ -1154,9 +1180,22 @@ static menuitem_t OP_ControlsMenu[] = {IT_CALL | IT_STRING, NULL, "Player 3 Controls...", &M_Setup3PControlsMenu, 30}, {IT_CALL | IT_STRING, NULL, "Player 4 Controls...", &M_Setup4PControlsMenu, 40}, + + {IT_SUBMENU | IT_STRING, NULL, "Mouse Options...", &OP_MouseOptionsDef, 60}, - {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 60}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth, 70}, + {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 80}, + {IT_STRING | IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth, 90}, +}; + +static const char* OP_ControlsTooltips[] = +{ + "Setup player 1 controls.", + "Setup player 2 controls.", + "Setup player 3 controls.", + "Setup player 4 controls.", + "Options for mouse control.", + "Allowed amount of controls per key.", + "Turn smoothing for non-analog turning.", }; static menuitem_t OP_AllControlsMenu[] = @@ -1273,22 +1312,32 @@ static menuitem_t OP_JoystickSetMenu[] = {IT_CALL | IT_NOTHING, "", NULL, M_AssignJoystick, (LINEHEIGHT*8)+5}, }; -/*static menuitem_t OP_MouseOptionsMenu[] = +//WTF +static menuitem_t OP_MouseOptionsMenu[] = { {IT_STRING | IT_CVAR, NULL, "Use Mouse", &cv_usemouse, 10}, - {IT_STRING | IT_CVAR, NULL, "First-Person MouseLook", &cv_alwaysfreelook, 30}, - {IT_STRING | IT_CVAR, NULL, "Third-Person MouseLook", &cv_chasefreelook, 40}, - {IT_STRING | IT_CVAR, NULL, "Mouse Move", &cv_mousemove, 50}, - {IT_STRING | IT_CVAR, NULL, "Invert Mouse", &cv_invertmouse, 60}, + //{IT_STRING | IT_CVAR, NULL, "First-Person MouseLook", &cv_alwaysfreelook, 30}, + //{IT_STRING | IT_CVAR, NULL, "Third-Person MouseLook", &cv_chasefreelook, 40}, + {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, 70}, + NULL, "Mouse X Speed", &cv_mousesens, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Mouse Y Speed", &cv_mouseysens, 80}, + NULL, "Mouse Y Speed", &cv_mouseysens, 50}, }; -static menuitem_t OP_Mouse2OptionsMenu[] = +static const char* OP_MouseTooltips[] = +{ + "Enable the use of the mouse.", + "Turn using the mouse.", + "Invert mouse movements.", + "Mouse horizontal sensitivity.", + "Mouse vertical sensitivity.", +}; + +/*static menuitem_t OP_Mouse2OptionsMenu[] = { {IT_STRING | IT_CVAR, NULL, "Use Mouse 2", &cv_usemouse2, 10}, {IT_STRING | IT_CVAR, NULL, "Second Mouse Serial Port", @@ -1322,15 +1371,39 @@ static menuitem_t OP_VideoOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Show FPS", &cv_ticrate, 90}, {IT_STRING | IT_CVAR, NULL, "Vertical Sync", &cv_vidwait, 100}, {IT_STRING | IT_CVAR, NULL, "FPS Cap", &cv_fpscap, 110}, - {IT_STRING | IT_CVAR, NULL, "Drift spark pulse size",&cv_driftsparkpulse, 125}, - {IT_STRING | IT_CVAR, NULL, "Uppercase Menu", &cv_menucaps, 135}, - + {IT_STRING | IT_CVAR, NULL, "Drift spark pulse size",&cv_driftsparkpulse, 120}, + {IT_STRING | IT_CVAR, NULL, "Uppercase Menu", &cv_menucaps, 130}, #ifdef HWRENDER - {IT_SUBMENU|IT_STRING, NULL, "OpenGL Options...", &OP_OpenGLOptionsDef, 145}, + {IT_SUBMENU|IT_STRING, NULL, "OpenGL Options...", &OP_OpenGLOptionsDef, 140}, #endif + {IT_SUBMENU|IT_STRING, NULL, "Experimental Options...", &OP_ExpOptionsDef, 150}, + }; +static const char* OP_VideoTooltips[] = +{ + "Resolution game runs at.", +#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) + "Enable fullscreen.", +#endif + "Gamma (brightness) of the game.", + "How far away objects are drawn.", + "How far away weather is drawn.", + "Toggle being able to see the sky.", + "Player field of view.", + "Show current game framerate.", + "Sync game framerate to refresh rate of monitor.", + "Set manual framerate cap.", + "Size of drift spark pulse.", + "Force menu to only use uppercase.", +#ifdef HWRENDER + "Options for OpenGL renderer.", +#endif + "Experimental graphical options.", +}; + + enum { op_video_res = 0, @@ -1351,6 +1424,7 @@ enum #ifdef HWRENDER op_video_ogl, #endif + op_video_exp, }; static menuitem_t OP_VideoModeMenu[] = @@ -1358,29 +1432,107 @@ static menuitem_t OP_VideoModeMenu[] = {IT_KEYHANDLER | IT_NOTHING, NULL, "", M_HandleVideoMode, '\0'}, // dummy menuitem for the control func }; +static menuitem_t OP_ExpOptionsMenu[] = +{ + {IT_HEADER, NULL, "Experimental Options", NULL, 10}, + {IT_STRING | IT_CVAR, NULL, "Weather Interpolation", &cv_precipinterp, 35}, + {IT_STRING | IT_CVAR, NULL, "Less Weather Effects", &cv_lessprecip, 45}, + + {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_vhseffect, 65}, + + {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 85}, + {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 95}, +#ifdef HWRENDER + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 65}, + {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_grvhseffect, 75}, + + {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 95}, + {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 105}, + {IT_STRING | IT_CVAR, NULL, "ZFighting fix for fofs", &cv_fofzfightfix, 115}, + {IT_STRING | IT_CVAR, NULL, "FOF wall cutoff for slopes", &cv_grfofcut, 125}, +#endif +}; + +static const char* OP_ExpTooltips[] = +{ + NULL, + "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", + "When weather is on this will cut the object amount used in half.", + "Show a VHS-like effect when the game is paused or youre rewinding replays.", + "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", + "Hides Sprites which are not visible\npotentially resulting in a performance boost.", +#ifdef HWRENDER + "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", + "Show a VHS-like effect when the game is paused or youre rewinding replays.", + "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", + "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", + "Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.", + "Toggle for FOF wall cutoff with slopes.", +#endif +}; + +enum +{ + op_exp_header, + op_exp_precipinter, + op_exp_lessprecip, + op_exp_vhs, + op_exp_ffclip, + op_exp_sprclip, +#ifdef HWRENDER + op_exp_grscrtx, + op_exp_grvhs, + op_exp_spltwal, + op_exp_pegging, + op_exp_fofzfight, + op_exp_fofcut, +#endif +}; + + #ifdef HWRENDER static menuitem_t OP_OpenGLOptionsMenu[] = { - {IT_STRING | IT_CVAR, NULL, "3D Models", &cv_grmdls, 5}, - {IT_STRING | IT_CVAR, NULL, "Fallback Player 3D Model", &cv_grfallbackplayermodel, 15}, + {IT_STRING | IT_CVAR, NULL, "3D Models", &cv_grmdls, 15}, + {IT_STRING | IT_CVAR, NULL, "Fallback Player 3D Model", &cv_grfallbackplayermodel, 20}, {IT_STRING | IT_CVAR, NULL, "Shaders", &cv_grshaders, 25}, //{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, - {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletteshader, 35}, - {IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 45}, - {IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 55}, + {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletteshader, 30}, + {IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35}, + {IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 40}, - {IT_STRING|IT_CVAR, NULL, "Texture Quality", &cv_scr_depth, 75}, - {IT_STRING|IT_CVAR, NULL, "Texture Filter", &cv_grfiltermode, 85}, - {IT_STRING|IT_CVAR, NULL, "Anisotropic", &cv_granisotropicmode, 95}, + {IT_STRING|IT_CVAR, NULL, "Texture Quality", &cv_scr_depth, 50}, + {IT_STRING|IT_CVAR, NULL, "Texture Filter", &cv_grfiltermode, 55}, + {IT_STRING|IT_CVAR, NULL, "Anisotropic", &cv_granisotropicmode, 60}, + {IT_STRING|IT_CVAR, NULL, "Visual Portals", &cv_grportals, 65}, - {IT_STRING|IT_CVAR, NULL, "Visual Portals", &cv_grportals, 105}, + {IT_STRING|IT_CVAR, NULL, "Wall Contrast Style", &cv_grfakecontrast, 75}, + {IT_STRING|IT_CVAR, NULL, "Slope Contrast", &cv_grslopecontrast, 80}, + {IT_STRING|IT_CVAR, NULL, "Sprite Billboarding", &cv_grspritebillboarding, 85}, + {IT_STRING|IT_CVAR, NULL, "Software Perspective", &cv_grshearing, 90}, + {IT_STRING|IT_CVAR, NULL, "Rendering Distance", &cv_grrenderdistance, 95}, - {IT_STRING|IT_CVAR, NULL, "Wall Contrast Style", &cv_grfakecontrast, 125}, - {IT_STRING|IT_CVAR, NULL, "Sprite Billboarding", &cv_grspritebillboarding, 135}, - {IT_STRING|IT_CVAR, NULL, "Software Perspective", &cv_grshearing, 145}, - {IT_STRING|IT_CVAR, NULL, "Rendering Distance", &cv_grrenderdistance, 155}, + {IT_SUBMENU|IT_STRING, NULL, "Gamma...", &OP_OpenGLColorDef, 105}, +}; - {IT_SUBMENU|IT_STRING, NULL, "Gamma...", &OP_OpenGLColorDef, 170}, +static const char* OP_OpenGLTooltips[] = +{ + "Use 3D models.", + "Fallback 3D model for characters that don't have any.", + "Graphical Shaders.", + "Recreates the look of software mode.", + "Flash palettes for palette rendering.", + "Minimum shader brightness. This is set in sector brightness values.", + "Bit-depth of textures.", + "Filter to use on textures.", + "Anisotropic filtering.", + "Recreates an effect from software mode that is used on some maps.", + "The look of the wall contrast effect.", + "Wall contrast but for slopes.", + "Should sprites always face the camera?", + "Recreates the look of software mode camera perspective.", + "How far the game world should be drawn.", + "Gamma (brightness) of colors.", }; static menuitem_t OP_OpenGLColorMenu[] = @@ -1418,14 +1570,34 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Chat Notifications", &cv_chatnotifications, 75}, {IT_STRING|IT_CVAR, NULL, "Character voices", &cv_kartvoices, 85}, {IT_STRING|IT_CVAR, NULL, "Powerup Warning", &cv_kartinvinsfx, 95}, - - {IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 110}, + + {IT_KEYHANDLER|IT_STRING, NULL, "Sound Test", M_HandleSoundTest, 105}, + {IT_STRING|IT_CALL, NULL, "Music Test", M_MusicTest, 115}, {IT_STRING|IT_CVAR, NULL, "Play Music While Unfocused", &cv_playmusicifunfocused, 125}, {IT_STRING|IT_CVAR, NULL, "Play SFX While Unfocused", &cv_playsoundifunfocused, 135}, {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 155} }; +static const char* OP_SoundTooltips[] = +{ + "Turn Sound effects on or off.", + "Volume of sound effects.", + "Turn Sound effects on or off.", + "Volume of music.", + "Reverse left and right channels of audio.", + "Surround Sound.", + "Chat notification sound.", + "Frequency of character voice lines.", + "Should the powerup warning be a sound effect or music?", + "Testing sounds...", + "Testing music...", + "Should the games music play while unfocused?", + "Should the games sound play while unfocused?", + "Options for advanced sound settings.", +}; + + static menuitem_t OP_SoundAdvancedMenu[] = { #ifdef HAVE_OPENMPT @@ -1437,13 +1609,31 @@ static menuitem_t OP_SoundAdvancedMenu[] = {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 62}, #endif {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 82}, -#endif +#endif {IT_HEADER, NULL, "Misc", NULL, 105}, - + {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 137}, }; +static const char* OP_SoundAdvancedTooltips[] = +{ +#ifdef HAVE_OPENMPT + NULL, + + "Filter used to resample tracker instruments.", + "Resample tracker modules to sound similar to Paula hardware.", +#if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR > 4 + "Which Amiga should be used for .mod playback?", +#endif + "How far should the four channels in .mod be panned?", +#endif + NULL, + "Should the Grow music be on or off?", + "Should the Invulnerability music be on or off?", + +}; + static menuitem_t OP_DataOptionsMenu[] = { @@ -1559,9 +1749,12 @@ static menuitem_t OP_HUDOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Console Text Size", &cv_constextsize, 120}, {IT_STRING | IT_CVAR, NULL, "Show Track Addon Name", &cv_showtrackaddon, 135}, - {IT_STRING | IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 145}, + + {IT_STRING | IT_CVAR, NULL, "Show All Maps", &cv_showallmaps, 145}, + + {IT_STRING | IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 155}, - {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 155}, + {IT_STRING | IT_CVAR, NULL, "2D character select", &cv_skinselectmenu, 165}, }; @@ -1582,6 +1775,25 @@ static menuitem_t OP_ChatOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. + {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 110}, + {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 120}, + + {IT_STRING | IT_CVAR, NULL, "Show IP addresses in playerlist", &cv_shownodeip, 140}, +}; + +static const char* OP_ChatOptionsTooltips[] = +{ + "Chat mode used for in-game chat.", + "Width of chat box.", + "Height of chat box.", + "Chatbox background.", + "Fadeout time for new chat message.", + "Spam protection for in-game chat.", + "Maxiumum amount of chat messages to look back at.", + "Show player ping.", + "Measurement used for ping.", + "Visibility of ping icon.", + "Should Player IP addresses be printed when using\nthe nodes or listplayers command?", }; static menuitem_t OP_GameOptionsMenu[] = @@ -1603,6 +1815,21 @@ static menuitem_t OP_GameOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Restrict Character Changes", &cv_restrictskinchange, 150}, }; +static const char* OP_GameTooltips[] = +{ + "Toggles for all in-game items.", + "Driving speed of game in race mode.", + "Crazier item rolls.", + "Mirror mode.", + "Number of laps.", + "Countdown for other players when people finish.", + "Time limit for battle mode.", + "Number of bumpers to start with in battle mode.", + "Allow players to come back via karma in battle mode.", + "Force everyone to use the same character.", + "Prevent character changes.", +}; + static menuitem_t OP_ServerOptionsMenu[] = { #ifndef NONET @@ -1626,12 +1853,37 @@ static menuitem_t OP_ServerOptionsMenu[] = #endif }; +static const char* OP_ServerOptionsTooltips[] = +{ +#ifndef NONET + "Name of server.", +#endif + "Length of intermission after races.", + "How the next map to be played is choosen.", + "How long map voting is.", + "How often should other gamemodes appear.", +#ifndef NONET + "Max amount of players allowed in this server.", + "Allow players to join this server.", + "Allow players to download addons.", + "Who has permission to pause the server?", + "Completely mute in game chat.", + "Options for advanced server settings.", +#endif +}; + #ifndef NONET static menuitem_t OP_AdvServerOptionsMenu[] = { - {IT_STRING | IT_CVAR | IT_CV_STRING, - NULL, "Server Browser Address", &cv_masterserver, 10}, +#ifndef MASTERSERVER + {IT_GRAYEDOUT, + NULL, "Server Browser Address", NULL, 10}, +#else + {IT_STRING | IT_CVAR | IT_CV_STRING, + + NULL, "Server Browser Address", &cv_masterserver, 10}, +#endif {IT_STRING | IT_CVAR, NULL, "Attempts to resynchronise", &cv_resynchattempts, 40}, {IT_STRING | IT_CVAR, NULL, "Delay limit (frames)", &cv_maxping, 50}, {IT_STRING | IT_CVAR, NULL, "Delay timeout (s)", &cv_pingtimeout, 60}, @@ -1647,6 +1899,24 @@ static menuitem_t OP_AdvServerOptionsMenu[] = }; #endif +#ifndef NONET +static const char* OP_AdvServerOptionsTooltips[] = +{ + + "Server used for master server.", + "Attempts to resynchronise player to server.", + "Maximum allowed delay.", + "Delay timeout in seconds.", + "Connection timeout in tics.", + "Join timeout in tics", + "Max file size sent in kilobytes.", + "Packet rate for file transfers.", + "Log ip addresses of players who join.", + "Log player resync attempts.", + "Log player file transfers.", +}; +#endif + /*static menuitem_t OP_NetgameOptionsMenu[] = { {IT_STRING | IT_CVAR, NULL, "Time Limit", &cv_timelimit, 10}, @@ -1716,22 +1986,47 @@ static menuitem_t OP_MonitorToggleMenu[] = static menuitem_t OP_SaturnMenu[] = { {IT_HEADER, NULL, "Saturn Options", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Serverqueue waittime", &cv_connectawaittime, 15}, - {IT_STRING | IT_CVAR, NULL, "Skin Select Spinning Speed", &cv_skinselectspin, 35}, - {IT_STRING | IT_CVAR, NULL, "Input Display outside of RA", &cv_showinput, 45}, - {IT_STRING | IT_CVAR, NULL, "Small Speedometer", &cv_newspeedometer, 55}, - {IT_STRING | IT_CVAR, NULL, "Colourized HUD", &cv_colorizedhud, 65}, - {IT_STRING | IT_CVAR, NULL, "Colourized Itembox", &cv_colorizeditembox, 75}, - {IT_STRING | IT_CVAR, NULL, "Colourized HUD Color", &cv_colorizedhudcolor, 85}, - {IT_STRING | IT_CVAR, NULL, "Show Lap Emblem", &cv_showlapemblem, 95}, - {IT_STRING | IT_CVAR, NULL, "Show Minimap Names", &cv_showminimapnames, 105}, - {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 115}, - {IT_STRING | IT_CVAR, NULL, "Less Midnight Channel Flicker", &cv_lessflicker, 125}, - {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 140}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 155}, + {IT_STRING | IT_CVAR, NULL, "Serverqueue waittime", &cv_connectawaittime, 10}, - {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 170}, // uwu + {IT_STRING | IT_CVAR, NULL, "Skin Select Spinning Speed", &cv_skinselectspin, 20}, + {IT_STRING | IT_CVAR, NULL, "Input Display outside of RA", &cv_showinput, 25}, + {IT_STRING | IT_CVAR, NULL, "Speedometer Style", &cv_newspeedometer, 30}, + {IT_STRING | IT_CVAR, NULL, "Stat Display", &cv_showstats, 35}, + {IT_STRING | IT_CVAR, NULL, "Higher Resolution Portraits", &cv_highresportrait, 40}, + {IT_STRING | IT_CVAR, NULL, "Colourized HUD", &cv_colorizedhud, 45}, + {IT_STRING | IT_CVAR, NULL, "Colourized Itembox", &cv_colorizeditembox, 50}, + {IT_STRING | IT_CVAR, NULL, "Colourized HUD Color", &cv_colorizedhudcolor, 55}, + {IT_STRING | IT_CVAR, NULL, "Show Lap Emblem", &cv_showlapemblem, 60}, + {IT_STRING | IT_CVAR, NULL, "Show Minimap Names", &cv_showminimapnames, 65}, + {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 70}, + {IT_STRING | IT_CVAR, NULL, "Less Midnight Channel Flicker", &cv_lessflicker, 75}, + + {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 85}, + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 90}, + + {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 105}, // uwu +}; + +static const char* OP_SaturnTooltips[] = +{ + NULL, + "How long can the game wait before it kicks you out from the server\nconnecting screen.", + "How much speen do you want?", + "Displays the input display outside of Record Attack. Also adjusts the\nposition scale to match.", + "Change what style the speedometer is.", + "Enable the stat display.", + "Enable the use of the higher resolution want icons instead of rank\nfor some places.", + "Enable colourized hud.", + "Enable the colourized itembox when colourized hud is enabled.", + "The color to use instead of the player color when colourized hud is enabled.", + "Show the big 'LAP' text on a lap change.", + "Show player names on the minimap.", + "Minimize the player icons on the minimap.", + "Disables the flicker effect on Midnight Channel.", + "Options for player distortion effects.", + "Move position of HUD elements.", + "See the people who helped make this project possible!", }; enum @@ -1741,7 +2036,10 @@ enum sm_skinselspeed, sm_input, sm_speedometer, + sm_statdisplay, + sm_highresport, sm_colorhud, + sm_coloritem, sm_colorhud_customcolor, sm_lapemblem, sm_mapnames, @@ -1766,6 +2064,19 @@ static menuitem_t OP_PlayerDistortMenu[] = {IT_STRING | IT_CVAR, NULL, "Saltyhop Squish", &cv_saltysquish, 140}, }; +static const char* OP_PlayerDistortTooltips[] = +{ + NULL, + "Player rotation on slopes.", + "Distance player rotation should be visable.", + "Player rotation when sliptiding.", + "Player squash and stretch.", + "Player landing sound effect.", + "Kart hopping while drifting. This is purely visual.", + "Player hop sound effect.", + "Player hop squash and stretch.", +}; + enum { sloperotate, @@ -1782,18 +2093,37 @@ static menuitem_t OP_HudOffsetMenu[] = { {IT_HEADER, NULL, "Kart Hud Offsets", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Itembox Horizontal Offset", &cv_item_xoffset, 20}, - {IT_STRING | IT_CVAR, NULL, "Itembox Vertical Offset", &cv_item_yoffset, 30}, - {IT_STRING | IT_CVAR, NULL, "Timer Horizontal Offset", &cv_time_xoffset, 45}, - {IT_STRING | IT_CVAR, NULL, "Timer Vertical Offset", &cv_time_yoffset, 55}, - {IT_STRING | IT_CVAR, NULL, "Lapcount Horizontal Offset", &cv_laps_xoffset, 70}, - {IT_STRING | IT_CVAR, NULL, "Lapcount Vertical Offset", &cv_laps_yoffset, 80}, - {IT_STRING | IT_CVAR, NULL, "Speedometer Horizontal Offset", &cv_spdm_xoffset, 95}, - {IT_STRING | IT_CVAR, NULL, "Speedometer Vertical Offset", &cv_spdm_yoffset, 105}, - {IT_STRING | IT_CVAR, NULL, "Miniranking Horizontal Offset", &cv_face_xoffset, 120}, - {IT_STRING | IT_CVAR, NULL, "Miniranking Vertical Offset", &cv_face_yoffset, 130}, - {IT_STRING | IT_CVAR, NULL, "Minimap Horizontal Offset", &cv_mini_xoffset, 145}, - {IT_STRING | IT_CVAR, NULL, "Minimap Vertical Offset", &cv_mini_yoffset, 155}, + {IT_HEADER, NULL, "Itembox", NULL, 10}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_item_xoffset, 15}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_item_yoffset, 20}, + + {IT_HEADER, NULL, "Timer", NULL, 30}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_time_xoffset, 35}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_time_yoffset, 40}, + + {IT_HEADER, NULL, "Lap Count", NULL, 50}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_laps_xoffset, 55}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_laps_yoffset, 60}, + + {IT_HEADER, NULL, "Speedometer", NULL, 70}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_spdm_xoffset, 75}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_spdm_yoffset, 80}, + + {IT_HEADER, NULL, "Mini Rankings", NULL, 90}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_face_xoffset, 95}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_face_yoffset, 100}, + + {IT_HEADER, NULL, "Minimap", NULL, 110}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_mini_xoffset, 115}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_mini_yoffset, 120}, + + {IT_HEADER, NULL, "Position / R.A. Wheel", NULL, 130}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_posi_xoffset, 135}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_posi_yoffset, 140}, + + {IT_HEADER, NULL, "Stat Display", NULL, 150}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_stat_xoffset, 155}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_stat_yoffset, 160}, }; static menuitem_t OP_SaturnCreditsMenu[] = @@ -1830,6 +2160,13 @@ static menuitem_t OP_SaturnCreditsMenu[] = {IT_STRING, NULL, "", NULL, 200}, // dummy text III }; +static const char* OP_CreditTooltips[] = +{ + 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[] = { {IT_HEADER, NULL, "Crazy", NULL, 0}, @@ -1844,10 +2181,42 @@ static menuitem_t OP_BirdMenu[] = //{IT_STRING | IT_CVAR, NULL, "Encore Choices", &cv_encorevotes, 90}, {IT_HEADER, NULL, "Music", NULL, 70}, - {IT_STRING | IT_CVAR, NULL, "Resume Level Music", &cv_resume, 80}, - {IT_STRING | IT_CVAR, NULL, "Restart Special Music", &cv_resetspecialmusic, 90}, + {IT_STRING | IT_CVAR, NULL, "Music Features", &cv_birdmusic, 80}, + {IT_STRING | IT_CVAR, NULL, "Resume Level Music", &cv_resume, 95}, + {IT_STRING | IT_CVAR, NULL, "Restart Special Music", &cv_resetspecialmusic, 105}, - {IT_STRING | IT_SUBMENU, NULL, "Advanced Music Options...", &OP_AdvancedBirdDef, 120}, + {IT_STRING | IT_SUBMENU, NULL, "Advanced Music Options...", &OP_AdvancedBirdDef, 130}, +}; + +static const char* OP_BirdTooltips[] = +{ + NULL, + "Options for screen tilting.", + NULL, + "Show player names in replay playback.", + "Show FREE PLAY text when in a empty server.", + //NULL, + //"Only show one battle choice in map vote", + //"Amount of encore choices in map vote.", + NULL, + "Global toggle for all bird music features.", + "Resume level music from last position after music change.", + "Restart Special music if item is used again.", + "Options for advanced music settings.", +}; + +enum +{ + headercrzy, + tiltmenu, + headerhud, + viewpointext, + freeplaytext, + headermusic, + birdmusic, + lvlresum, + spclresum, + advmusic, }; static menuitem_t OP_ForkedBirdMenu[] = @@ -1868,8 +2237,14 @@ static menuitem_t OP_TiltMenu[] = {IT_STRING | IT_CVAR, NULL, "Smoothing Divisor", &cv_tiltsmoothing, 20}, {IT_STRING | IT_CVAR, NULL, "Also Tilt During Quakes", &cv_actionmovie, 40}, +}; - {IT_STRING | IT_CVAR, NULL, "\x85" "Window Shaking During Quakes", &cv_windowquake, 60}, +static const char* OP_TiltTooltips[] = +{ + "Camera tilting during gameplay.", + "Tilt camera while turning.", + "Smoothing value used.", + "Tilt during screen quakes.", }; enum @@ -1893,6 +2268,17 @@ static menuitem_t OP_AdvancedBirdMenu[] = {IT_STRING | IT_CVAR, NULL, "Resync Special Music Only", &cv_music_resync_powerups_only, 70}, }; +static const char* OP_AdvancedBirdTooltips[] = +{ + "Music fading.", + "Fade in music after Invincibility.", + "Fade in music after Grow.", + "Fade out music before respawning.", + "Fade in music while respawning.", + "Threshold for syncing music.", + "Only sync special music.", +}; + enum { fading, @@ -1920,6 +2306,7 @@ menu_t MISC_AddonsDef = M_DrawAddons, 50, 28, 0, + NULL, NULL }; @@ -1932,7 +2319,8 @@ menu_t MISC_ReplayHutDef = M_DrawReplayHut, 30, 80, 0, - M_QuitReplayHut + M_QuitReplayHut, + NULL }; menu_t MISC_ReplayOptionsDef = @@ -1944,6 +2332,7 @@ menu_t MISC_ReplayOptionsDef = M_DrawGenericMenu, 27, 40, 0, + NULL, NULL }; @@ -1956,6 +2345,7 @@ menu_t MISC_ReplayStartDef = M_DrawReplayStartMenu, 30, 90, 0, + NULL, NULL }; @@ -1968,6 +2358,7 @@ menu_t PlaybackMenuDef = { //BASEVIDWIDTH/2 - 94, 2, BASEVIDWIDTH/2 - 88, 2, 0, + NULL, NULL }; @@ -2079,7 +2470,8 @@ menu_t SR_PandoraDef = M_DrawGenericMenu, 60, 40, 0, - M_ExitPandorasBox + M_ExitPandorasBox, + NULL }; menu_t SR_MainDef = CENTERMENUSTYLE(NULL, SR_MainMenu, &MainDef, 72); @@ -2094,8 +2486,23 @@ menu_t SR_UnlockChecklistDef = M_DrawChecklist, 280, 185, 0, + NULL, NULL }; + +menu_t SR_MusicTestDef = +{ + NULL, + sizeof (SR_MusicTestMenu)/sizeof (menuitem_t), + &OP_SoundOptionsDef, + SR_MusicTestMenu, + M_DrawMusicTest, + 60, 150, + 0, + NULL, + NULL +}; + menu_t SR_EmblemHintDef = { NULL, @@ -2105,6 +2512,7 @@ menu_t SR_EmblemHintDef = M_DrawEmblemHints, 60, 150, 0, + NULL, NULL }; @@ -2132,6 +2540,7 @@ menu_t SP_LevelStatsDef = M_DrawLevelStats, 280, 185, 0, + NULL, NULL }; @@ -2144,7 +2553,9 @@ static menu_t SP_TimeAttackDef = M_DrawTimeAttackMenu, 34, 40, 0, - M_QuitTimeAttackMenu + M_QuitTimeAttackMenu, + NULL, + NULL }; static menu_t SP_ReplayDef = { @@ -2155,6 +2566,8 @@ static menu_t SP_ReplayDef = M_DrawTimeAttackMenu, 34, 40, 0, + NULL, + NULL, NULL }; static menu_t SP_GuestReplayDef = @@ -2166,6 +2579,8 @@ static menu_t SP_GuestReplayDef = M_DrawTimeAttackMenu, 34, 40, 0, + NULL, + NULL, NULL }; static menu_t SP_GhostDef = @@ -2177,6 +2592,7 @@ static menu_t SP_GhostDef = M_DrawTimeAttackMenu, 34, 40, 0, + NULL, NULL }; @@ -2249,10 +2665,11 @@ menu_t MP_MainDef = 42, 30, 0, #ifndef NONET - M_CancelConnect + M_CancelConnect, #else - NULL + NULL, #endif + NULL }; menu_t MP_OfflineServerDef = MAPICONMENUSTYLE("M_MULTI", MP_OfflineServerMenu, &MP_MainDef); @@ -2269,7 +2686,8 @@ menu_t MP_ConnectDef = M_DrawConnectMenu, 27,24, 0, - M_CancelConnect + M_CancelConnect, + NULL }; #endif menu_t MP_PlayerSetupDef = @@ -2281,7 +2699,8 @@ menu_t MP_PlayerSetupDef = M_DrawSetupMultiPlayerMenu, 36, 14, 0, - M_QuitMultiPlayerMenu + M_QuitMultiPlayerMenu, + NULL }; // Options @@ -2294,10 +2713,13 @@ menu_t OP_MainDef = M_DrawGenericMenu, 60, 30, 0, + NULL, NULL }; menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 60, 30); +//WTF +menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30); menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); menu_t OP_Joystick1Def = DEFAULTMENUSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 60, 30); menu_t OP_Joystick2Def = DEFAULTMENUSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 60, 30); @@ -2312,6 +2734,7 @@ menu_t OP_JoystickSetDef = M_DrawJoystick, 50, 40, 0, + NULL, NULL }; @@ -2322,8 +2745,9 @@ menu_t OP_VideoOptionsDef = &OP_MainDef, OP_VideoOptionsMenu, M_DrawVideoMenu, - 30, 30, + 30, 20, 0, + NULL, NULL }; @@ -2336,6 +2760,7 @@ menu_t OP_VideoModeDef = M_DrawVideoMode, 48, 26, 0, + NULL, NULL }; @@ -2346,11 +2771,13 @@ menu_t OP_SoundOptionsDef = &OP_MainDef, OP_SoundOptionsMenu, M_DrawSkyRoom, - 30, 30, + 30, 20, 0, + NULL, NULL }; + menu_t OP_HUDOptionsDef = { "M_HUD", @@ -2360,19 +2787,19 @@ menu_t OP_HUDOptionsDef = M_DrawHUDOptions, 30, 20, 0, + NULL, NULL }; + menu_t OP_ChatOptionsDef = DEFAULTMENUSTYLE("M_HUD", OP_ChatOptionsMenu, &OP_HUDOptionsDef, 30, 30); -#ifdef HAVE_OPENMPT menu_t OP_SoundAdvancedDef = DEFAULTMENUSTYLE("M_SOUND", OP_SoundAdvancedMenu, &OP_SoundOptionsDef, 30, 30); -#endif -menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 30); -menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 30); +menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 20); +menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 20); #ifndef NONET -menu_t OP_AdvServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_AdvServerOptionsMenu, &OP_ServerOptionsDef, 24, 30); +menu_t OP_AdvServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_AdvServerOptionsMenu, &OP_ServerOptionsDef, 24, 20); #endif //menu_t OP_NetgameOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_NetgameOptionsMenu, &OP_ServerOptionsDef, 30, 30); @@ -2387,11 +2814,12 @@ menu_t OP_MonitorToggleDef = M_DrawMonitorToggles, 47, 30, 0, + NULL, NULL }; #ifdef HWRENDER -menu_t OP_OpenGLOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 20); +menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); menu_t OP_OpenGLColorDef = { @@ -2402,10 +2830,13 @@ menu_t OP_OpenGLColorDef = M_OGL_DrawColorMenu, 60, 40, 0, + NULL, NULL }; #endif +menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 30); + menu_t OP_DataOptionsDef = DEFAULTMENUSTYLE("M_DATA", OP_DataOptionsMenu, &OP_MainDef, 60, 30); menu_t OP_ScreenshotOptionsDef = DEFAULTMENUSTYLE("M_SCSHOT", OP_ScreenshotOptionsMenu, &OP_DataOptionsDef, 30, 30); menu_t OP_AddonsOptionsDef = DEFAULTMENUSTYLE("M_ADDONS", OP_AddonsOptionsMenu, &OP_DataOptionsDef, 30, 30); @@ -2415,9 +2846,9 @@ menu_t OP_DiscordOptionsDef = DEFAULTMENUSTYLE(NULL, OP_DiscordOptionsMenu, &OP_ #endif menu_t OP_EraseDataDef = DEFAULTMENUSTYLE("M_DATA", OP_EraseDataMenu, &OP_DataOptionsDef, 30, 30); -menu_t OP_SaturnDef = DEFAULTMENUSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 15); +menu_t OP_SaturnDef = DEFAULTSCROLLSTYLE(NULL, OP_SaturnMenu, &OP_MainDef, 30, 30); menu_t OP_PlayerDistortDef = DEFAULTMENUSTYLE("M_VIDEO", OP_PlayerDistortMenu, &OP_SaturnDef, 30, 30); -menu_t OP_HudOffsetDef = DEFAULTMENUSTYLE(NULL, OP_HudOffsetMenu, &OP_SaturnDef, 30, 20); +menu_t OP_HudOffsetDef = DEFAULTSCROLLSTYLE(NULL, OP_HudOffsetMenu, &OP_SaturnDef, 30, 30); menu_t OP_SaturnCreditsDef = DEFAULTMENUSTYLE(NULL, OP_SaturnCreditsMenu, &OP_SaturnDef, 30, 10); menu_t OP_BirdDef = DEFAULTMENUSTYLE(NULL, OP_BirdMenu, &OP_MainDef, 30, 30); @@ -2432,6 +2863,7 @@ menu_t OP_ForkedBirdDef = { M_DrawLocalSkinMenu, 30, 6, 0, + NULL, NULL }; @@ -2732,6 +3164,37 @@ void Bird_menu_Onchange(void) OP_AdvancedBirdMenu[fadegrow].status = status; OP_AdvancedBirdMenu[respawnfadeout].status = status; OP_AdvancedBirdMenu[respawnfadein].status = status; + + if (cv_birdmusic.value) + { + OP_BirdMenu[lvlresum].status = IT_STRING | IT_CVAR; + OP_BirdMenu[spclresum].status = IT_STRING | IT_CVAR; + OP_BirdMenu[advmusic].status = IT_STRING | IT_SUBMENU; + } + else + { + OP_BirdMenu[lvlresum].status = IT_GRAYEDOUT; + OP_BirdMenu[spclresum].status = IT_GRAYEDOUT; + OP_BirdMenu[advmusic].status = IT_GRAYEDOUT; + } +} + +//menu code is nice +void Saturn_menu_Onchange(void) +{ + UINT16 status; + + if (cv_colorizedhud.value) + { + status = IT_STRING | IT_CVAR; + } + else + { + status = IT_GRAYEDOUT; + } + + OP_SaturnMenu[sm_coloritem].status = status; + OP_SaturnMenu[sm_colorhud_customcolor].status = status; } // ========================================================================== @@ -3250,6 +3713,7 @@ boolean M_Responder(event_t *ev) case KEY_DOWNARROW: M_NextOpt(); S_StartSound(NULL, sfx_menu1); + coolalphatimer = 9; /*if (currentMenu == &SP_PlayerDef) { Z_Free(char_notes); @@ -3260,6 +3724,7 @@ boolean M_Responder(event_t *ev) case KEY_UPARROW: M_PrevOpt(); S_StartSound(NULL, sfx_menu1); + coolalphatimer = 9; /*if (currentMenu == &SP_PlayerDef) { Z_Free(char_notes); @@ -3646,10 +4111,13 @@ void M_StartControlPanel(void) MPauseMenu[mpause_psetup].status = IT_DISABLED; MISC_ChangeTeamMenu[0].status = IT_DISABLED; MISC_ChangeSpectateMenu[0].status = IT_DISABLED; + + MPauseMenu[mpause_addlocalskins].status = IT_STRING | IT_CALL; + MPauseMenu[mpause_localskin].status = IT_STRING | IT_CALL; // Reset these in case splitscreen messes things up MPauseMenu[mpause_addons].alphaKey = 8; - MPauseMenu[mpause_addlocalskins].alphaKey = 16; + MPauseMenu[mpause_addlocalskins].alphaKey = 24; MPauseMenu[mpause_scramble].alphaKey = 8; MPauseMenu[mpause_switchmap].alphaKey = 24; @@ -3666,9 +4134,21 @@ void M_StartControlPanel(void) { MPauseMenu[mpause_switchmap].status = IT_STRING | IT_CALL; MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; + if (G_GametypeHasTeams()) MPauseMenu[mpause_scramble].status = IT_STRING | IT_SUBMENU; } + + if (server || (!cv_showlocalskinmenus.value)) + { + MPauseMenu[mpause_addlocalskins].status = IT_DISABLED; + MPauseMenu[mpause_localskin].status = IT_DISABLED; + + MPauseMenu[mpause_options].alphaKey = 64; + MPauseMenu[mpause_title].alphaKey = 80; + MPauseMenu[mpause_quit].alphaKey = 88; + } + if (splitscreen) { @@ -3927,11 +4407,32 @@ void M_Init(void) #ifdef HWRENDER // Permanently hide some options based on render mode if (rendermode == render_soft) + { OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_grvhs].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_fofcut].status = IT_DISABLED; + } + + if (rendermode == render_opengl){ + OP_ExpOptionsMenu[op_exp_vhs].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; + } #endif - if (!snw_speedo) // why bother? + if (!snw_speedo && !kartzspeedo) // why bother? OP_SaturnMenu[sm_speedometer].status = IT_GRAYEDOUT; + + if (!snw_speedo && kartzspeedo) + OP_SaturnMenu[sm_speedometer].text = "Speedometer (No Small)"; + + if (snw_speedo && !kartzspeedo) + OP_SaturnMenu[sm_speedometer].text = "Speedometer (No PMeter)"; + if (!clr_hud){ // uhguauhauguuhee OP_SaturnMenu[sm_colorhud].status = IT_GRAYEDOUT; @@ -4261,6 +4762,58 @@ static void M_DrawMenuTitle(void) } } +// TODO: This is fucking terrible. +static void M_DrawSplitText(INT32 x, INT32 y, INT32 option, const char* str, INT32 box_x, INT32 alpha) +{ + const char* icopy = strdup(str); + const char** clines = NULL; + INT16 num_lines = 0; + + if (icopy == NULL) return; + + char* token = strtok(icopy, "\n"); + + while (token != NULL) + { + const char* line = strdup(token); + + if (line == NULL) return; + + clines = (const char**)realloc(clines, (num_lines + 1) * sizeof(const char*)); + clines[num_lines] = line; + num_lines++; + + token = strtok(NULL, "\n"); + } + + free(icopy); + + INT16 yoffset; + yoffset = (((5*10 - num_lines*10))); + + // Draw BG first,,, + for (int i = 0; i < num_lines; i++) + { + V_DrawFill(0, (y + yoffset - 6)+5, vid.width, 11, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); + yoffset += 11; + } + + yoffset = (((5*10 - num_lines*10))); + + // THEN the text + for (int i = 0; i < num_lines; i++) + { + V_DrawCenteredThinString(x, y + yoffset, option, clines[i]); + V_DrawCenteredThinString(x, y + yoffset, option|V_YELLOWMAP|((9 - alpha) << V_ALPHASHIFT), clines[i]); + yoffset += 10; + // Remember to free the memory for each line when you're done with it. + free((void*)clines[i]); + } + + free(clines); +} + + static void M_DrawGenericMenu(void) { INT32 x, y, w, i, cursory = 0; @@ -4403,6 +4956,172 @@ static void M_DrawGenericMenu(void) W_CachePatchName("M_CURSOR", PU_CACHE)); V_DrawString(currentMenu->x, cursory, lowercase|highlightflags, currentMenu->menuitems[itemOn].text); } + + + // dumb hack + // tooltips + + if (currentMenu == &OP_ControlsDef) + { + if (!(OP_ControlsTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_ControlsTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_MouseOptionsDef) + { + if (!(OP_MouseTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_MouseTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_VideoOptionsDef) + { + if (!(OP_VideoTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_VideoTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_SoundOptionsDef) + { + if (!(OP_SoundTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_SoundTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_SoundAdvancedDef) + { + if (!(OP_SoundAdvancedTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_SoundAdvancedTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_ExpOptionsDef) + { + if (!(OP_ExpTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_ExpTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_ChatOptionsDef) + { + if (!(OP_ChatOptionsTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_ChatOptionsTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + + + if (currentMenu == &OP_GameOptionsDef) + { + if (!(OP_GameTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_GameTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + + if (currentMenu == &OP_ServerOptionsDef) + { + if (!(OP_ServerOptionsTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_ServerOptionsTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + + if (currentMenu == &OP_AdvServerOptionsDef) + { + if (!(OP_AdvServerOptionsTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_AdvServerOptionsTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + + + + if (currentMenu == &OP_PlayerDistortDef) + { + if (!(OP_PlayerDistortTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_PlayerDistortTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + + + + if (currentMenu == &OP_SaturnCreditsDef) // C: + { + if (!(OP_CreditTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_CreditTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_BirdDef) + { + if (!(OP_BirdTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_BirdTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_TiltDef) + { + if (!(OP_TiltTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_TiltTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + if (currentMenu == &OP_AdvancedBirdDef) + { + if (!(OP_AdvancedBirdTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_AdvancedBirdTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } + + } static void M_DrawGenericBackgroundMenu(void) @@ -4413,8 +5132,10 @@ static void M_DrawGenericBackgroundMenu(void) #define scrollareaheight 72 + + // note that alphakey is multiplied by 2 for scrolling menus to allow greater usage in UINT8 range. -/*static void M_DrawGenericScrollMenu(void) +static void M_DrawGenericScrollMenu(void) { INT32 x, y, i, max, bottom, tempcentery, cursory = 0; @@ -4543,8 +5264,33 @@ static void M_DrawGenericBackgroundMenu(void) // DRAW THE SKULL CURSOR V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, W_CachePatchName("M_CURSOR", PU_CACHE)); -}*/ +#ifdef HWRENDER + // dumb hack + // tooltips + if (currentMenu == &OP_OpenGLOptionsDef) + { + if (!(OP_OpenGLTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_OpenGLTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } +#endif + + + + if (currentMenu == &OP_SaturnDef) + { + if (!(OP_SaturnTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_SaturnTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } +} static void M_DrawPauseMenu(void) { @@ -4933,24 +5679,23 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) //return false; // Should the map be hidden? <-- well imma wanna toggle it, its just annoying being unable to select hell maps in mapselect - if (cv_showallmaps.value) + if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) // map hell { - if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) - return true; // map hell - } - else if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) + if (cv_showallmaps.value) + return true; + else return false; + } // same goes here, just show every map if i want to - if (cv_showallmaps.value) + if (M_MapLocked(mapnum+1)) // not unlocked { - if (M_MapLocked(mapnum+1)) - return true; // not unlocked - } - else if (M_MapLocked(mapnum+1)) - return false; // not unlocked - - + if (cv_showallmaps.value) + return true; + else + return false; + } + /*if (gt == GT_COOP && (mapheaderinfo[mapnum]->typeoflevel & TOL_COOP)) return true; @@ -5494,6 +6239,8 @@ static void M_AddonsClearName(INT32 choice) M_StopMessage(choice); } +int errorshitspam = 0; // prevent the warning screen from crapping itself when errors get spammed lmao + // returns whether to do message draw static boolean M_AddonsRefresh(void) { @@ -5522,10 +6269,11 @@ static boolean M_AddonsRefresh(void) else message = va("%c%s\x80\nA file was not loaded.\nCheck the console log for more information.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname); } - else if (refreshdirmenu & (REFRESHDIR_WARNING|REFRESHDIR_ERROR)) + else if ((refreshdirmenu & (REFRESHDIR_WARNING | REFRESHDIR_ERROR)) && !errorshitspam) { S_StartSound(NULL, sfx_s224); message = va("%c%s\x80\nA file was loaded with %s.\nCheck the console log for more information.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname, ((refreshdirmenu & REFRESHDIR_ERROR) ? "errors" : "warnings")); + errorshitspam = 1; // you already said that shit } else if (majormods && !prevmajormods) { @@ -5700,6 +6448,64 @@ static void M_AddonExec(INT32 ch) COM_BufAddText(va("exec \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); } +// static void M_AddonAutoLoad(INT32 ch); +// exports mods to a file, which helps in autoloading that file +// +static void M_AddonAutoLoad(INT32 ch) +{ + // initalize these variables // + const char *path; + FILE *autoloadconfigfile; + + // check our controls // + if (ch != 'y' && ch != KEY_ENTER && ch != KEY_RSHIFT) + { + S_StartSound(NULL, sfx_s26d); + return; + } + + // first, find the file // + path = va("%s"PATHSEP"%s", srb2home, AUTOLOADCONFIGFILENAME); + autoloadconfigfile = fopen(path, "a"); + + // then, execute the addon and store it in our autoload.cfg // + switch (dirmenu[dir_on[menudepthleft]][DIR_TYPE]) + { + case EXT_FOLDER: + M_StartMessage(va("%c%s\x80\nAutoloading folders is not supported as of yet. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); + break; + case EXT_TXT: + case EXT_CFG: + CONS_Printf("Added the \x82%s\x80 console script to the autoload configuration list.\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING); + fprintf(autoloadconfigfile, "%s\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING); + + S_StartSound(NULL, sfx_s221); + break; + case EXT_LUA: + case EXT_SOC: + case EXT_WAD: + case EXT_KART: + case EXT_PK3: + default: + if (!(refreshdirmenu & REFRESHDIR_MAX)) + { + CONS_Printf("Added \x82%s\x80 to the autoload configuration list.\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING); + fprintf(autoloadconfigfile, "%s\n", dirmenu[dir_on[menudepthleft]]+DIR_STRING); + + S_StartSound(NULL, sfx_s221); + } + else + { + M_StartMessage(va("%c%s\x80\nToo many add-ons are loaded! \nYou need to restart the game to autoload more add-ons and folders. \nYou can still autoload console scripts though. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); + S_StartSound(NULL, sfx_s26d); + } + break; + } + + // lastly, do some last things and close the autoload config file // + fclose(autoloadconfigfile); +} + #define len menusearch[0] static boolean M_ChangeStringAddons(INT32 choice) { @@ -5868,12 +6674,16 @@ static void M_HandleAddons(INT32 choice) if (DumbStartsWith("KC_", dirmenu[dir_on[menudepthleft]]+DIR_STRING) || DumbStartsWith("kc_", dirmenu[dir_on[menudepthleft]]+DIR_STRING)) { M_StartMessage(va("%c%s\x80\nYou are loading a local skin.\nLocal skins will not be usable\nafter going back from\nthe title screen.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); COM_BufAddText(va("addskins \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + errorshitspam = 0; // reset it so it can show the warning screen again lmao } else S_StartSound(NULL, sfx_s26d); } else + { COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + errorshitspam = 0; // reset it so it can show the warning screen again lmao + } break; default: S_StartSound(NULL, sfx_s26d); @@ -5884,6 +6694,53 @@ static void M_HandleAddons(INT32 choice) } break; + case KEY_RSHIFT: + { + boolean refresh = true; + if (!dirmenu[dir_on[menudepthleft]]) + S_StartSound(NULL, sfx_s26d); + else + { + switch (dirmenu[dir_on[menudepthleft]][DIR_TYPE]) + { + case EXT_FOLDER: + M_StartMessage(va("%c%s%s\x80\nAutoloading a folder is not yet suppported. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), M_AddonsHeaderPath(), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); + S_StartSound(NULL, sfx_s26d); + break; + case EXT_UP: + S_StartSound(NULL, sfx_s224); + M_StartMessage(va("%c%s%s\x80\nNice try. \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), M_AddonsHeaderPath(), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); + break; + case EXT_TXT: + case EXT_CFG: + if ((strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, CONFIGFILENAME) == 0) + || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, AUTOLOADCONFIGFILENAME) == 0) + || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartserv.cfg") == 0) + || (strcmp(dirmenu[dir_on[menudepthleft]]+DIR_STRING, "kartexec.cfg") == 0)) + { + M_StartMessage(va("%c%s\x80\nYou can't autoload this builds' base console scripts, silly!\n They're already autoloaded on startup! \n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); + S_StartSound(NULL, sfx_s26d); + } + else + M_StartMessage(va("%c%s\x80\nYou're trying to autoload a console script. \nIgnore my warning anyways? \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO); + break; + case EXT_LUA: + case EXT_SOC: + case EXT_WAD: + case EXT_KART: + case EXT_PK3: + M_StartMessage(va("%c%s\x80\nYou are trying to mark an addon to autoload\nat startup. This will skip modifiedgame checks. \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO); + break; + default: + M_StartMessage(va("%c%s\x80\nIt may be dangerous to autoload this file. \nBut you're the boss, and I'm just hand-written code.\n Proceed? \n\n(Press 'Y' to confirm)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),M_AddonAutoLoad,MM_YESNO); + break; + } + } + if (refresh) + refreshdirmenu |= REFRESHDIR_NORMAL; + } + break; + case KEY_ESCAPE: exitmenu = true; break; @@ -6928,6 +7785,8 @@ static void M_Options(INT32 choice) OP_MainDef.prevMenu = currentMenu; M_SetupNextMenu(&OP_MainDef); + + OP_MainMenu[11].status = ((Playing() &&(server &&(!IsPlayerAdmin(consoleplayer)))) || (!cv_showlocalskinmenus.value)) ? (IT_DISABLED) : (IT_CALL|IT_STRING); } static void M_Manual(INT32 choice) @@ -7347,6 +8206,397 @@ static void M_HandleSoundTest(INT32 choice) } } +static musicdef_t *curplaying = NULL; +static INT32 st_sel = 0; +static tic_t st_time = 0; +static size_t st_namescroll = 0; +static size_t st_namescrollstate = 0; +//static patch_t* st_radio[9]; +//static patch_t* st_launchpad[4]; + +static void M_MusicTest(INT32 choice) +{ + INT32 ul = skyRoomMenuTranslations[choice-1]; + UINT8 i; + char buf[8]; + + if (!S_PrepareSoundTest()) + { + M_StartMessage(M_GetText("No selectable tracks found.\n"),NULL,MM_NOTHING); + return; + } + + /*STRBUFCPY(buf, "M_RADIOn"); + for (i = 0; i < 9; i++) + { + if (st_radio[i]) + W_UnlockCachedPatch(st_radio[i]); + buf[7] = (char)('0'+i); + st_radio[i] = W_CachePatchName(buf, PU_STATIC); + } + + STRBUFCPY(buf, "M_LPADn"); + for (i = 0; i < 4; i++) + { + if (st_launchpad[i]) + W_UnlockCachedPatch(st_launchpad[i]); + buf[6] = (char)('0'+i); + st_launchpad[i] = W_CachePatchName(buf, PU_STATIC); + }*/ + + curplaying = NULL; + st_time = 0; + + st_sel = 0; + + M_SetupNextMenu(&SR_MusicTestDef); +} + +static void M_DrawMusicTest(void) +{ + INT32 x, y, i; + char* title; + //fixed_t hscale = FRACUNIT/2, vscale = FRACUNIT/2, bounce = 0; + //UINT8 frame[4] = {0, 0, -1, SKINCOLOR_RUBY}; + + // let's handle the ticker first. ideally we'd tick this somewhere else, BUT... + if (curplaying) + { + { + fixed_t work; + //angle_t ang; + //bpm = FixedDiv((60*TICRATE)<= (FRACUNIT << (FRACBITS - 2))) // prevent overflow jump - takes about 15 minutes of loop on the same song to reach + st_time = work; + + //work = FixedDiv(work*180, bpm); + //frame[0] = 8-(work/(20<>ANGLETOFINESHIFT) & FINEMASK; + //bounce = (FINESINE(ang) - FRACUNIT/2); + //hscale -= bounce/16; + //vscale += bounce/16; + + st_time += renderdeltatics; + } + } + + x = 90<title[0] && curplaying->alttitle[0]) + titl = va("%s - %s - ", curplaying->title, curplaying->alttitle); + else if (curplaying->title[0]) + titl = va("%s - ", curplaying->title); + else + titl = va("%s - ", curplaying->source); + } + else + titl = "NONE - "; + + i = V_LevelNameWidth(titl); + + st_scroll += renderdeltatics; + + while (st_scroll >= (i << FRACBITS)) + st_scroll -= i << FRACBITS; + + x -= st_scroll >> FRACBITS; + + while (x < BASEVIDWIDTH-y) + x += i; + while (x > y) + { + x -= i; + V_DrawLevelTitle(x, 24, 0, titl); + } + + if (curplaying && curplaying->authors[0]) + V_DrawRightAlignedThinString(BASEVIDWIDTH-16, 46, V_ALLOWLOWERCASE, curplaying->authors); + + if (curplaying) + { + if (!curplaying->usage[0]) + V_DrawString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s", curplaying->name)); + else { + V_DrawSmallString(vid.dupx, vid.height - 5*vid.dupy, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s - %.255s\n", curplaying->name, curplaying->usage)); + } + + if (cv_showmusicfilename.value) + V_DrawSmallString(0, 0, V_SNAPTOTOP|V_SNAPTOLEFT|V_ALLOWLOWERCASE, curplaying->filename); + } + } + + V_DrawFill(20, 60, 280, 128, 239); + + { + INT32 t, b, q, m = 128; + + if (numsoundtestdefs <= 8) + { + t = 0; + b = numsoundtestdefs - 1; + i = 0; + } + else + { + q = m; + m = (5*m)/numsoundtestdefs; + if (st_sel < 3) + { + t = 0; + b = 7; + i = 0; + } + else if (st_sel >= numsoundtestdefs-4) + { + t = numsoundtestdefs - 8; + b = numsoundtestdefs - 1; + i = q-m; + } + else + { + t = st_sel - 3; + b = st_sel + 4; + i = (t * (q-m))/(numsoundtestdefs - 8); + } + } + + V_DrawFill(20+280-1, 60 + i, 1, m, 0); + + if (t != 0) + V_DrawString(20+280+4, 60+4 - (skullAnimCounter/5), V_YELLOWMAP, "\x1A"); + + if (b != numsoundtestdefs - 1) + V_DrawString(20+280+4, 60+128-12 + (skullAnimCounter/5), V_YELLOWMAP, "\x1B"); + + x = 24; + y = 64; + + if (renderisnewtic) ++st_namescroll; + + while (t <= b) + { + if (t == st_sel) + V_DrawFill(20, y-4, 280-1, 16, 237); + + { + const size_t MAXLENGTH = 34; + const tic_t SCROLLSPEED = TICRATE/5; // Number of tics for name being scrolled by 1 letter + size_t nameoffset = 0; + size_t namelength = strlen(soundtestdefs[t]->source); + if (soundtestdefs[t]->title[0]) + namelength = strlen(soundtestdefs[t]->title); + + char buf[MAXLENGTH+1]; + + if (t == st_sel && namelength > MAXLENGTH) + { + switch (st_namescrollstate) + { + case 0: + { + // Scroll forward + nameoffset = (st_namescroll/SCROLLSPEED) % (namelength - MAXLENGTH + 1); + + if (nameoffset == namelength - MAXLENGTH) + { + st_namescroll = 0; + st_namescrollstate++; + } + } + break; + + case 1: + { + nameoffset = namelength - MAXLENGTH; + + // Show name end for 1 second, then start scrolling back + if (st_namescroll == TICRATE) + { + st_namescroll = 0; + st_namescrollstate++; + } + } + break; + + case 2: + { + // Scroll back + nameoffset = (namelength - MAXLENGTH - 1) - (st_namescroll/SCROLLSPEED) % (namelength - MAXLENGTH); + + if (nameoffset == 0) + { + st_namescroll = 0; + st_namescrollstate++; + } + } + break; + + case 3: + { + nameoffset = 0; + + // Show name beginning for 1 second, then start scrolling forward again + if (st_namescroll == TICRATE) + { + st_namescroll = 0; + st_namescrollstate = 0; + } + } + break; + } + } + + if (soundtestdefs[t]->title[0]) + strncpy(buf, soundtestdefs[t]->title + nameoffset, MAXLENGTH); + else + strncpy(buf, soundtestdefs[t]->source + nameoffset, MAXLENGTH); + buf[MAXLENGTH] = 0; + + V_DrawString(x, y, (t == st_sel ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE|V_MONOSPACE, buf); + if (curplaying == soundtestdefs[t]) + { + V_DrawFill(20+280-9, y-4, 8, 16, 230); + //V_DrawCharacter(165+140-8, y, '\x19' | V_YELLOWMAP, false); + //V_DrawFixedPatch((165+140-9)<= numsoundtestdefs-1) + st_sel = 0; + { + S_StartSound(NULL, sfx_menu1); + } + st_namescroll = 0; + st_namescrollstate = 0; + break; + case KEY_UPARROW: + if (!st_sel--) + st_sel = numsoundtestdefs-1; + { + S_StartSound(NULL, sfx_menu1); + } + st_namescroll = 0; + st_namescrollstate = 0; + break; + case KEY_PGDN: + if (st_sel < numsoundtestdefs-1) + { + st_sel += 3; + if (st_sel >= numsoundtestdefs-1) + st_sel = numsoundtestdefs-1; + S_StartSound(NULL, sfx_menu1); + } + st_namescroll = 0; + st_namescrollstate = 0; + break; + case KEY_PGUP: + if (st_sel) + { + st_sel -= 3; + if (st_sel < 0) + st_sel = 0; + S_StartSound(NULL, sfx_menu1); + } + st_namescroll = 0; + st_namescrollstate = 0; + break; + case KEY_BACKSPACE: + if (curplaying) + { + S_StopSounds(); + S_StopMusic(); + curplaying = NULL; + st_time = 0; + S_StartSound(NULL, sfx_skid); + } + break; + case KEY_ESCAPE: + exitmenu = true; + st_namescroll = 0; + st_namescrollstate = 0; + break; + + case KEY_RIGHTARROW: + case KEY_LEFTARROW: + case KEY_ENTER: + S_StopSounds(); + S_StopMusic(); + st_time = 0; + curplaying = soundtestdefs[st_sel]; + S_ChangeMusicInternal(curplaying->name, true); + break; + + default: + break; + } + if (exitmenu) + { + Z_Free(soundtestdefs); + soundtestdefs = NULL; + + if (currentMenu->prevMenu) + M_SetupNextMenu(currentMenu->prevMenu); + else + M_ClearMenus(true); + } +} + // Entering secrets menu /*static void M_SecretsMenu(INT32 choice) { @@ -9238,6 +10488,7 @@ static void M_Refresh(INT32 choice) #endif/*MASTERSERVER*/ } +#ifdef MASTERSERVER static void M_DrawServerCountAndHorizontalBar(void) { const char *text; @@ -9280,6 +10531,7 @@ static void M_DrawServerCountAndHorizontalBar(void) V_DrawFill(1, currentMenu->y+32, center - radius - 2, 1, 0); V_DrawFill(center + radius + 2, currentMenu->y+32, BASEVIDWIDTH - 1, 1, 0); } +#endif static void M_DrawServerLines(INT32 x, INT32 page) { @@ -9342,6 +10594,7 @@ static void M_DrawConnectMenu(void) highlightflags, va("%u of %d", serverlistpage+1, numPages)); // Did you change the Server Browser address? Have a little reminder. + #ifdef MASTERSERVER if (CV_IsSetToDefault(&cv_masterserver)) mservflags = mservflags|highlightflags|V_30TRANS; else @@ -9350,6 +10603,7 @@ static void M_DrawConnectMenu(void) mservflags, va("MS: %s", cv_masterserver.string)); M_DrawServerCountAndHorizontalBar(); + #endif // When switching pages, slide the old page and the // new page across the screen @@ -9459,6 +10713,7 @@ void M_SortServerList(void) #ifndef NONET #ifdef UPDATE_ALERT +#ifdef MASTERSERVER static void M_CheckMODVersion(int id) { char updatestring[500]; @@ -9475,12 +10730,15 @@ static void M_CheckMODVersion(int id) #endif } } +#endif //MASTERSERVER #endif/*UPDATE_ALERT*/ #if defined (UPDATE_ALERT) && defined (HAVE_THREADS) +#ifdef MASTERSERVER static void Check_new_version_thread (int *id) { + M_SetWaitingMode(M_WAITING_VERSION); M_CheckMODVersion(*id); @@ -9493,9 +10751,12 @@ Check_new_version_thread (int *id) { free(id); } + } +#endif #endif/*defined (UPDATE_ALERT) && defined (HAVE_THREADS)*/ +#ifdef MASTERSERVER static void M_ConnectMenu(INT32 choice) { (void)choice; @@ -9540,12 +10801,13 @@ static void M_ConnectMenu(INT32 choice) #endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/ } + static void M_ConnectMenuModChecks(INT32 choice) { (void)choice; // okay never mind we want to COMMUNICATE to the player pre-emptively instead of letting them try and then get confused when it doesn't work - if (modifiedgame) + if (modifiedgame || autoloaded) { M_StartMessage(M_GetText("You have addons loaded.\nYou won't be able to join netgames!\n\nTo play online, restart the game\nand don't load any addons.\nSRB2Kart will automatically add\neverything you need when you join.\n\n(Press a key)\n"),M_ConnectMenu,MM_EVENTHANDLER); return; @@ -9553,9 +10815,10 @@ static void M_ConnectMenuModChecks(INT32 choice) M_ConnectMenu(-1); } +#endif boolean firstDismissedNagThisBoot = true; - +#ifdef MASTERSERVER static void M_HandleMasterServerResetChoice(event_t *ev) { INT32 choice = -1; @@ -9582,21 +10845,25 @@ static void M_HandleMasterServerResetChoice(event_t *ev) } } } + } +#endif static void M_PreStartServerMenu(INT32 choice) { - (void)choice; + (void)choice; +#ifdef MASTERSERVER if (!CV_IsSetToDefault(&cv_masterserver) && cv_masterserver_nagattempts.value > 0) { M_StartMessage(M_GetText("Hey! You've changed the Server Browser address.\n\nYou won't be able to host games on the official Server Browser.\nUnless you're from the future, this probably isn't what you want.\n\n\x83Press Accel\x80 to fix this and continue.\x80\nPress any other key to continue anyway.\n"),M_PreStartServerMenuChoice,MM_EVENTHANDLER); return; } - +#endif M_StartServerMenu(-1); -} +} +#ifdef MASTERSERVER static void M_PreConnectMenu(INT32 choice) { (void)choice; @@ -9621,6 +10888,7 @@ static void M_PreConnectMenuChoice(event_t *ev) M_HandleMasterServerResetChoice(ev); M_ConnectMenuModChecks(-1); } +#endif #endif //NONET //=========================================================================== @@ -9849,7 +11117,9 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) static void M_DrawServerMenu(void) { + M_DrawLevelSelectOnly(false, false); + #ifdef MASTERSERVER if (currentMenu == &MP_ServerDef && cv_advertise.value) // Remind players where they're hosting. { int mservflags = V_ALLOWLOWERCASE; @@ -9859,7 +11129,9 @@ static void M_DrawServerMenu(void) mservflags = mservflags|warningflags; V_DrawCenteredThinString(BASEVIDWIDTH/2, BASEVIDHEIGHT-12, mservflags, va("Master Server: %s", cv_masterserver.string)); } + #endif M_DrawGenericMenu(); + } static void M_MapChange(INT32 choice) @@ -10229,6 +11501,9 @@ static boolean setupm_skinlockedselect; #define SKINGRIDWIDTH 8 #define SKINGRIDHEIGHT 6 +#define SKINGRIDNEWWIDTH 8 +#define SKINGRIDNEWHEIGHT 9 + static char *sortNames[] = { "Name", "Internal name", @@ -10260,6 +11535,8 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 sltw, actw, hetw; UINT8 skintodisplay; INT32 nameboxaddy = 0; + int statoffset = 0; + int gridyoffset = 0; mx = MP_PlayerSetupDef.x; my = MP_PlayerSetupDef.y; @@ -10270,9 +11547,12 @@ static void M_DrawSetupMultiPlayerMenu(void) // use generic drawer for cursor, items and title M_DrawGenericMenu(); - // draw name string + // Offsets switch (cv_skinselectmenu.value) { + case SKINMENUTYPE_EXTENDED: + nameboxaddy = 6; + break; case SKINMENUTYPE_GRID: nameboxaddy = 6; break; @@ -10281,6 +11561,8 @@ static void M_DrawSetupMultiPlayerMenu(void) break; } + + M_DrawTextBox(mx + 32, my - 8 + nameboxaddy, MAXPLAYERNAME, 1); V_DrawString(mx + 40, my + nameboxaddy, V_ALLOWLOWERCASE, setupm_name); @@ -10292,6 +11574,32 @@ static void M_DrawSetupMultiPlayerMenu(void) st = V_StringWidth(skins[setupm_fakeskin].realname, 0); switch (cv_skinselectmenu.value) { + case SKINMENUTYPE_EXTENDED: +#define GETSELECTEDSKINNAME (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].realname : skins[setupm_fakeskin].realname) +#define GETSELECTEDSPEED (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartspeed : skins[setupm_fakeskin].kartspeed) +#define GETSELECTEDWEIGHT (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartweight : skins[setupm_fakeskin].kartweight) + + statoffset = 0; + tw = V_StringWidth("Character", 0);//V_StringWidth(GETSELECTEDSKINNAME, 0); + st = V_StringWidth(GETSELECTEDSKINNAME, 0); + + INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); + speed = skins[selectedskin].kartspeed; + weight = skins[selectedskin].kartweight; + + V_DrawString((mx+(tw/2)) - (st/2), my + 37, + ((MP_PlayerSetupMenu[2].status & IT_TYPE) == IT_SPACE ? V_TRANSLUCENT : 0) | highlightflags | V_ALLOWLOWERCASE, + GETSELECTEDSKINNAME); + if (statdp == true) + statoffset = 50; + else + statoffset = 113; + + V_DrawString(statx - statoffset, staty - 10, V_6WIDTHSPACE, va("\x84%dS \x87%dW", GETSELECTEDSPEED, GETSELECTEDWEIGHT)); +#undef GETSELECTEDSKINNAME +#undef GETSELECTEDSPEED +#undef GETSELECTEDWEIGHT + break; case SKINMENUTYPE_GRID: #define GETSELECTEDSKINNAME (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].realname : skins[setupm_fakeskin].realname) tw = V_StringWidth("Character", 0);//V_StringWidth(GETSELECTEDSKINNAME, 0); @@ -10342,6 +11650,16 @@ static void M_DrawSetupMultiPlayerMenu(void) st = V_StringWidth(KartColor_Names[setupm_fakecolor], 0); switch (cv_skinselectmenu.value) { + case SKINMENUTYPE_EXTENDED: + V_DrawString(mx, my + 164, highlightflags | V_ALLOWLOWERCASE, KartColor_Names[setupm_fakecolor]); // SRB2kart + if (itemOn == 2) + { + V_DrawCharacter(mx - 10/* - st*/ - (skullAnimCounter/5), my + 164, + '\x1C' | highlightflags, false); // left arrow + V_DrawCharacter(mx + 2 + st + (skullAnimCounter/5), my + 164, + '\x1D' | highlightflags, false); // right arrow + } + break; case SKINMENUTYPE_GRID: case SKINMENUTYPE_2D: V_DrawString(mx, my + 152, highlightflags | V_ALLOWLOWERCASE, KartColor_Names[setupm_fakecolor]); // SRB2kart @@ -10369,6 +11687,52 @@ static void M_DrawSetupMultiPlayerMenu(void) switch (cv_skinselectmenu.value) { + case SKINMENUTYPE_EXTENDED: + // SRB2Kart: draw the stat backer + //This is where stats and shit would go. + // gonna put the sorttype here as well + V_DrawSmallString(statx-3, staty-37, V_6WIDTHSPACE|highlightflags, "Sort:"); + V_DrawSmallString(statx+17, staty-37, V_6WIDTHSPACE|highlightflags, sortNames[cv_skinselectgridsort.value]); + if (itemOn == 1) + V_DrawSmallString(statx+101, staty-37, V_6WIDTHSPACE|highlightflags, "BS: change"); + +#define GETSELECTEDSPEED (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartspeed : skins[setupm_fakeskin].kartspeed) +#define GETSELECTEDWEIGHT (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartweight : skins[setupm_fakeskin].kartweight) + + if (statdp == true) + { + int i; + //Background + V_DrawScaledPatch(statx - 50, staty + 4, 0, W_CachePatchName("K_STATNB", PU_CACHE)); + + //Speed + for (i = 0; i < GETSELECTEDSPEED; i++) // draw the stat bars + { + if (i == 0) + V_DrawScaledPatch(statx - 45, staty + 63, 0, W_CachePatchName("K_STATN1", PU_CACHE)); + else if (i == GETSELECTEDSPEED -1 ) + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN3", PU_CACHE)); + else + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN2", PU_CACHE)); + } + + //Weight + for (i = 0; i < GETSELECTEDWEIGHT; i++) // draw the stat bars + { + + if (i == 0) + V_DrawScaledPatch(statx - 30, staty + 63, 0, W_CachePatchName("K_STATN4", PU_CACHE)); + else if (i == GETSELECTEDWEIGHT -1) + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN6", PU_CACHE)); + else + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN5", PU_CACHE)); + } + } +#undef GETSELECTEDSPEED +#undef GETSELECTEDWEIGHT + + + break; case SKINMENUTYPE_GRID: // SRB2Kart: draw the stat backer // labels @@ -10455,6 +11819,47 @@ static void M_DrawSetupMultiPlayerMenu(void) switch (cv_skinselectmenu.value) { + //Skin grid stuff + case SKINMENUTYPE_EXTENDED: + gridyoffset = 10; + for (s = 0; s < SKINGRIDNEWWIDTH*SKINGRIDNEWHEIGHT; s++) + { + INT32 x = ((s % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH) - 8) + 100 + SKINXSHIFT; //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + INT32 y = ((s / SKINGRIDNEWWIDTH) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2)) + gridyoffset); //BASEVIDWIDTH / 2 - ((icons + 1) * 24) - 4; + INT32 calcs = s + (setupm_skinypos * SKINGRIDNEWWIDTH); + INT32 skinn; + patch_t *face; + UINT8 *cmap; + + if (calcs < numskins) + skinn = skinsorted[calcs]; + else if (s % SKINGRIDNEWWIDTH == 0) + break; //really conveniant place to break out here + else + { + V_DrawFill(x, y, 16, 16, 239); + continue; + } + + face = facerankprefix[skinn]; + cmap = R_GetTranslationColormap(skinn, skins[skinn].prefcolor, GTC_MENUCACHE); + + V_DrawFixedPatch(x << FRACBITS, y << FRACBITS, FRACUNIT, 0, face, cmap); + } + + if (itemOn == 1) //has to be on skin select part + { + patch_t *cursor; + INT32 curx = (((setupm_skinselect % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH/2)) + SKINXSHIFT) + 20; + INT32 cury = (((setupm_skinselect / SKINGRIDNEWWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2))+ gridyoffset); + + UINT8 cursorframe = (I_GetTime() / 4) % 7; + + cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_CACHE); + V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); + } + + break; case SKINMENUTYPE_GRID: for (s = 0; s < SKINGRIDWIDTH*SKINGRIDHEIGHT; s++) { @@ -10589,7 +11994,11 @@ static void M_DrawSetupMultiPlayerMenu(void) #define charw 72 #define indexwidth 8 { - const INT32 colwidth = ((BASEVIDWIDTH-(2*mx))-charw)/(2*indexwidth); + INT32 colwidth = ((BASEVIDWIDTH-(2*mx))-charw)/(2*indexwidth); + + if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) + colwidth = colwidth - 10; + INT32 j = -colwidth; INT16 col = setupm_fakecolor - colwidth; INT32 x = mx; @@ -10692,6 +12101,13 @@ static void M_DrawSetupMultiPlayerMenu(void) else sprdef = &skins[0].spritedef; break; + case SKINMENUTYPE_EXTENDED: + skintodisplay = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); + if (R_SkinAvailable(skins[skintodisplay].name) != -1) + sprdef = &skins[R_SkinAvailable(skins[skintodisplay].name)].spritedef; + else + sprdef = &skins[0].spritedef; + break; case SKINMENUTYPE_GRID: skintodisplay = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); if (R_SkinAvailable(skins[skintodisplay].name) != -1) @@ -10729,7 +12145,7 @@ static void M_DrawSetupMultiPlayerMenu(void) patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_CACHE); // draw box around guy - V_DrawFill(mx + 43 - (charw/2), my+65, charw, 84, 239); + V_DrawFill(mx + 36 - (charw/2), my+65, charw, 84, 239); // draw player sprite if (setupm_fakecolor) // inverse should never happen @@ -10738,13 +12154,13 @@ static void M_DrawSetupMultiPlayerMenu(void) if (skins[skintodisplay].flags & SF_HIRES) { - V_DrawFixedPatch((mx+43)<= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT) - setupm_skinypos++; + + if (cv_skinselectmenu.value == SKINMENUTYPE_GRID){ + if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT) + setupm_skinypos++; + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED){ + if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8+24 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT+24) + setupm_skinypos++; + } } else { @@ -10827,7 +12250,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) S_StartSound(NULL,sfx_menu1); // Tails break; } - else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID) + else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) { if (itemOn == 1) { @@ -10846,8 +12269,16 @@ static void M_HandleSetupMultiPlayer(INT32 choice) else if (itemOn == 2) { setupm_skinselect = numskins - 1; - setupm_skinypos = (((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)) > 0 ? ((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)) : 0); - M_PrevOpt(); + if (cv_skinselectmenu.value == SKINMENUTYPE_GRID){ + setupm_skinypos = (((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)) > 0 ? ((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)) : 0); + M_PrevOpt(); + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED){ + setupm_skinypos = (((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)-2) > 0 ? ((numskins / SKINGRIDWIDTH) - (SKINGRIDHEIGHT-1)-2) : 0); + M_PrevOpt(); + + } + } else M_PrevOpt(); @@ -10879,7 +12310,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } break; } - else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID && itemOn == 1) + else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) && itemOn == 1) { if (setupm_skinselect > 0) { @@ -10891,7 +12322,10 @@ static void M_HandleSetupMultiPlayer(INT32 choice) { INT32 roundedskins = ROUNDSKINSUPTO8; setupm_skinselect = roundedskins-1; - setupm_skinypos = (((roundedskins/8) - SKINGRIDHEIGHT) > 0 ? (roundedskins/8) - SKINGRIDHEIGHT : 0); + if (cv_skinselectmenu.value == SKINMENUTYPE_GRID) + setupm_skinypos = (((roundedskins/8) - SKINGRIDHEIGHT) > 0 ? (roundedskins/8) - SKINGRIDHEIGHT : 0); + else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) + setupm_skinypos = (((roundedskins/8) - SKINGRIDHEIGHT-2) > 0 ? (roundedskins/8) - SKINGRIDHEIGHT-2 : 0); } S_StartSound(NULL, sfx_menu1); break; @@ -10929,13 +12363,19 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } break; } - else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID && itemOn == 1) + else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) && itemOn == 1) { if (setupm_skinselect < ROUNDSKINSUPTO8 - 1) { setupm_skinselect++; - if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT) - setupm_skinypos++; + if (cv_skinselectmenu.value == SKINMENUTYPE_GRID){ + if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT) + setupm_skinypos++; + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED){ + if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8+24 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT+24) + setupm_skinypos++; + } } else { @@ -10977,7 +12417,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) setupm_name[l-1] =0; } } - else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID && itemOn == 1) + else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) && itemOn == 1) { // change sort for select menu (damn now i have to add another cvar...) // now we have the cvar @@ -10996,7 +12436,6 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } } break; - case KEY_DEL: if (cv_skinselectmenu.value) BREAKWHENLOCKED @@ -11032,7 +12471,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) S_StartSound(NULL,sfx_menu1); } } - else if (cv_skinselectmenu.value == SKINMENUTYPE_GRID && itemOn == 1 && setupm_skinselect < numskins) + else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED ) && itemOn == 1 && setupm_skinselect < numskins) { setupm_fakeskin = skinsorted[setupm_skinselect]; S_StartSound(NULL, sfx_s221); @@ -11040,16 +12479,22 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; default: - if (choice < 32 || choice > 127 || itemOn != 0) + if (choice < 32 || choice > 127) break; - l = strlen(setupm_name); - if (l < MAXPLAYERNAME) - { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[l] =(char)choice; - setupm_name[l+1] =0; + if (itemOn == 0){ + l = strlen(setupm_name); + if (l < MAXPLAYERNAME) + { + S_StartSound(NULL,sfx_menu1); // Tails + setupm_name[l] =(char)choice; + setupm_name[l+1] =0; + } } break; + + + + } #undef BREAKWHENLOCKED @@ -11084,6 +12529,12 @@ case SKINMENUTYPE_2D:\ MP_PlayerSetupMenu[2].alphaKey = 164;\ MP_PlayerSetupDef.y = 6;\ break;\ +case SKINMENUTYPE_EXTENDED:\ + MP_PlayerSetupMenu[0].alphaKey = 6;\ + MP_PlayerSetupMenu[1].alphaKey = 25;\ + MP_PlayerSetupMenu[2].alphaKey = 152;\ + MP_PlayerSetupDef.y = 6;\ + break;\ case SKINMENUTYPE_GRID:\ MP_PlayerSetupMenu[0].alphaKey = 6;\ MP_PlayerSetupMenu[1].alphaKey = 25;\ @@ -11113,6 +12564,7 @@ static void M_SetupMultiPlayer(INT32 choice) setupm_cvskin = &cv_skin; setupm_cvcolor = &cv_playercolor; setupm_cvname = &cv_playername; + setupm_skinxpos = 4; setupm_skinypos = 0; setupm_skinlockedselect = false; @@ -11263,7 +12715,7 @@ static boolean M_QuitMultiPlayerMenu(void) } // 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 %d\n",setupm_cvcolor->name,setupm_fakecolor)); return true; } diff --git a/src/m_menu.h b/src/m_menu.h index a27f6c70b..e3b042294 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -147,6 +147,8 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt); #define MAXSTRINGLENGTH 32 +#define MAXTOOLTIPS 255 + typedef union { struct menu_s *submenu; // IT_SUBMENU @@ -184,6 +186,7 @@ typedef struct menu_s 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 + const char* tooltips[MAXTOOLTIPS]; // tooltips! give me that info bitch } menu_t; void M_SetupNextMenu(menu_t *menudef); @@ -242,6 +245,7 @@ extern description_t description[MAXSKINS]; extern consvar_t cv_showfocuslost; extern consvar_t cv_newgametype, cv_nextmap, cv_chooseskin, cv_serversort; extern consvar_t cv_showallmaps; +extern consvar_t cv_showmusicfilename; extern CV_PossibleValue_t gametype_cons_t[]; extern char dummystaffname[22]; @@ -269,6 +273,9 @@ void PDistort_menu_Onchange(void); // Bird menu updating void Bird_menu_Onchange(void); +// Saturn menu updating +void Saturn_menu_Onchange(void); + void M_ReplayHut(INT32 choice); void M_SetPlaybackMenuPointer(void); @@ -288,6 +295,20 @@ void M_PopupMasterServerRules(void); M_DrawGenericMenu,\ x, y,\ 0,\ + NULL,\ + NULL\ +} + +#define DEFAULTSCROLLSTYLE(header, source, prev, x, y)\ +{\ + header,\ + sizeof(source)/sizeof(menuitem_t),\ + prev,\ + source,\ + M_DrawGenericScrollMenu,\ + x, y,\ + 0,\ + NULL,\ NULL\ } @@ -300,6 +321,7 @@ void M_PopupMasterServerRules(void); M_DrawPauseMenu,\ x, y,\ 0,\ + NULL,\ NULL\ } @@ -312,6 +334,7 @@ void M_PopupMasterServerRules(void); M_DrawCenteredMenu,\ BASEVIDWIDTH/2, y,\ 0,\ + NULL,\ NULL\ } @@ -324,6 +347,7 @@ void M_PopupMasterServerRules(void); M_DrawServerMenu,\ 24,40,\ 0,\ + NULL,\ NULL\ } @@ -336,6 +360,7 @@ void M_PopupMasterServerRules(void); M_DrawControl,\ 26, 40,\ 0,\ + NULL,\ NULL\ } @@ -348,6 +373,7 @@ void M_PopupMasterServerRules(void); M_DrawImageDef,\ 0, 0,\ 0,\ + NULL,\ NULL\ } diff --git a/src/m_misc.c b/src/m_misc.c index 0601bb17d..db41f291a 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -193,7 +193,7 @@ INT32 M_MapNumber(char first, char second) // ========================================================================== // some libcs has no access function, make our own -#if defined (_WIN32_WCE) || defined (_WII) +#if 0 int access(const char *path, int amode) { int accesshandle = -1; diff --git a/src/m_misc.h b/src/m_misc.h index 0ce4aaf45..b79965b62 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -41,6 +41,8 @@ void M_StopMovie(void); // the file where game vars and settings are saved #define CONFIGFILENAME "kartconfig.cfg" +// autoload! +#define AUTOLOADCONFIGFILENAME "autoload.cfg" INT32 M_MapNumber(char first, char second); diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 11c0414b0..04e51a657 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -63,7 +63,10 @@ static ps_metric_t ps_removecount = {0}; ps_metric_t ps_checkposition_calls = {0}; +ps_metric_t ps_lua_prethinkframe_time = {0}; ps_metric_t ps_lua_thinkframe_time = {0}; +ps_metric_t ps_lua_postthinkframe_time = {0}; + ps_metric_t ps_lua_mobjhooks = {0}; ps_metric_t ps_otherlogictime = {0}; @@ -156,7 +159,9 @@ perfstatrow_t gamelogic_rows[] = { {" mobjs ", " Mobjs: ", &ps_thlist_times[THINK_MOBJ], PS_TIME|PS_LEVEL}, {" dynslop", " Dynamic slopes: ", &ps_thlist_times[THINK_DYNSLOPE], PS_TIME|PS_LEVEL}, {" precip ", " Precipitation: ", &ps_thlist_times[THINK_PRECIP], PS_TIME|PS_LEVEL},*/ + {" lprethinkf", " LUAh_PreThinkFrame:", &ps_lua_prethinkframe_time, PS_TIME|PS_LEVEL}, {" lthinkf", " LUAh_ThinkFrame:", &ps_lua_thinkframe_time, PS_TIME|PS_LEVEL}, + {" lpostthinkf", " LUAh_PostThinkFrame:", &ps_lua_postthinkframe_time, PS_TIME|PS_LEVEL}, {" other ", " Other: ", &ps_otherlogictime, PS_TIME|PS_LEVEL}, {0} }; @@ -189,10 +194,43 @@ int ps_frame_index = 0; int ps_tick_index = 0; // dynamically allocated resizeable array for thinkframe hook stats +ps_hookinfo_t *prethinkframe_hooks = NULL; +int prethinkframe_hooks_length = 0; +int prethinkframe_hooks_capacity = 16; + ps_hookinfo_t *thinkframe_hooks = NULL; int thinkframe_hooks_length = 0; int thinkframe_hooks_capacity = 16; +ps_hookinfo_t *postthinkframe_hooks = NULL; +int postthinkframe_hooks_length = 0; +int postthinkframe_hooks_capacity = 16; + +void PS_SetPreThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) +{ + if (!prethinkframe_hooks) + { + // array needs to be initialized + prethinkframe_hooks = Z_Calloc(sizeof(ps_hookinfo_t) * prethinkframe_hooks_capacity, PU_STATIC, NULL); + } + if (index >= prethinkframe_hooks_capacity) + { + // array needs more space, realloc with double size + int new_capacity = prethinkframe_hooks_capacity * 2; + prethinkframe_hooks = Z_Realloc(prethinkframe_hooks, + sizeof(ps_hookinfo_t) * new_capacity, PU_STATIC, NULL); + // initialize new memory with zeros so the pointers in the structs are null + memset(&prethinkframe_hooks[prethinkframe_hooks_capacity], 0, + sizeof(ps_hookinfo_t) * prethinkframe_hooks_capacity); + prethinkframe_hooks_capacity = new_capacity; + } + prethinkframe_hooks[index].time_taken.value.p = time_taken; + memcpy(prethinkframe_hooks[index].short_src, short_src, LUA_IDSIZE * sizeof(char)); + // since the values are set sequentially from begin to end, the last call should leave + // the correct value to this variable + prethinkframe_hooks_length = index + 1; +} + void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) { if (!thinkframe_hooks) @@ -218,6 +256,33 @@ void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) thinkframe_hooks_length = index + 1; } +void PS_SetPostThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) +{ + if (!postthinkframe_hooks) + { + // array needs to be initialized + postthinkframe_hooks = Z_Calloc(sizeof(ps_hookinfo_t) * postthinkframe_hooks_capacity, PU_STATIC, NULL); + } + if (index >= postthinkframe_hooks_capacity) + { + // array needs more space, realloc with double size + int new_capacity = postthinkframe_hooks_capacity * 2; + postthinkframe_hooks = Z_Realloc(postthinkframe_hooks, + sizeof(ps_hookinfo_t) * new_capacity, PU_STATIC, NULL); + // initialize new memory with zeros so the pointers in the structs are null + memset(&postthinkframe_hooks[postthinkframe_hooks_capacity], 0, + sizeof(ps_hookinfo_t) * postthinkframe_hooks_capacity); + postthinkframe_hooks_capacity = new_capacity; + } + postthinkframe_hooks[index].time_taken.value.p = time_taken; + memcpy(postthinkframe_hooks[index].short_src, short_src, LUA_IDSIZE * sizeof(char)); + // since the values are set sequentially from begin to end, the last call should leave + // the correct value to this variable + postthinkframe_hooks_length = index + 1; +} + + + static boolean PS_HighResolution(void) { return (vid.width >= 640 && vid.height >= 400); @@ -578,7 +643,11 @@ void PS_UpdateTickStats(void) ps_tictime.value.p - ps_playerthink_time.value.p - ps_thinkertime.value.p - - ps_lua_thinkframe_time.value.p; + ps_lua_prethinkframe_time.value.p - + ps_lua_thinkframe_time.value.p - + ps_lua_postthinkframe_time.value.p; + + PS_CountThinkers(); } @@ -590,21 +659,37 @@ void PS_UpdateTickStats(void) PS_UpdateRowHistories(misc_calls_rows, false); } } - if (cv_perfstats.value == 3 && cv_ps_samplesize.value > 1 && PS_IsLevelActive()) + if (cv_ps_samplesize.value > 1) { - int i; - for (i = 0; i < thinkframe_hooks_length; i++) + if(cv_perfstats.value >= 3 && PS_IsLevelActive()) { - PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + int i; + if (cv_perfstats.value == 3) + { + for (i = 0; i < thinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + } + else if (cv_perfstats.value == 4) + { + for (i = 0; i < prethinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false, false); + } + else if (cv_perfstats.value == 5) + { + for (i = 0; i < postthinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false, false); + } } - } - if (cv_perfstats.value && cv_ps_samplesize.value > 1) - { - ps_tick_index++; - if (ps_tick_index >= cv_ps_samplesize.value) - ps_tick_index = 0; - if (ps_tick_samples_left) - ps_tick_samples_left--; + if (cv_perfstats.value) + { + ps_tick_index++; + if (ps_tick_index >= cv_ps_samplesize.value) + ps_tick_index = 0; + if (ps_tick_samples_left) + ps_tick_samples_left--; + + } + } } @@ -624,7 +709,7 @@ static void PS_DrawDescriptorHeader(void) int samples_left = max(ps_frame_samples_left, ps_tick_samples_left); int x, y; - if (cv_perfstats.value == 3) + if (cv_perfstats.value >= 3) { x = 2; y = 0; @@ -717,21 +802,20 @@ static void PS_DrawGameLogicStats(void) #define WIDTH 106 #define HEIGHT 4 #define MAX_X 214 -#define MAX_Y 192 +#define MAX_Y 182 #define START_X 2 #define START_Y 4 #define PAGE_ENTRIES ((MAX_Y - START_Y) / HEIGHT) -static void PS_DrawThinkFrameStats(void) +static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) { char s[100]; int i; - int maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; - int page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); - - int pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); - int pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); + int maxpage = 0; + int page = 0; + int pagestart = 0; + int pageend = 0; // text writing position int x = START_X; int y = START_Y; @@ -741,19 +825,44 @@ static void PS_DrawThinkFrameStats(void) last_mod_name[0] = '\0'; INT32 total = 0; + //Decide page length based and drawn text on choosen thinker type + if (cv_perfstats.value == 3){ + maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); + pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); + + V_DrawSmallString(MAX_X-50, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "ThinkFrame"); + } + else if (cv_perfstats.value == 4){ + maxpage = prethinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); + pagestart = min((page - 1)*PAGE_ENTRIES, prethinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, prethinkframe_hooks_length); + V_DrawSmallString(MAX_X-60, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PreThinkFrame"); + } + else if (cv_perfstats.value == 5){ + maxpage = postthinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); + pagestart = min((page - 1)*PAGE_ENTRIES, postthinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, postthinkframe_hooks_length); + V_DrawSmallString(MAX_X-65, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PostThinkFrame"); + + } + PS_DrawDescriptorHeader(); - for (i = 0; i < thinkframe_hooks_length; i++) + for (i = 0; i < hook_length; i++) { #define NEXT_ROW() y += HEIGHT; - INT32 value = PS_GetMetricScreenValue(&thinkframe_hooks[i].time_taken, true); + INT32 value = PS_GetMetricScreenValue(&hook[i].time_taken, true); total += value; if (i < pagestart || i >= pageend) continue; - char* str = thinkframe_hooks[i].short_src; + char* str = hook[i].short_src; char* tempstr = tempbuffer; int len = (int)strlen(str); char* str_ptr; @@ -808,6 +917,8 @@ static void PS_DrawThinkFrameStats(void) snprintf(s, sizeof s - 1, "PAGE %d", page); V_DrawSmallString(START_X, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, s); } + + } void PS_ThinkFrame_Page_OnChange(void) @@ -828,6 +939,24 @@ void PS_ThinkFrame_Page_OnChange(void) #undef PAGE_ENTRIES + + +static void PS_DrawPreThinkFrameStats(void) +{ + draw_think_frame_stats(prethinkframe_hooks_length, prethinkframe_hooks); +} + +static void PS_DrawThinkFrameStats(void) +{ + draw_think_frame_stats(thinkframe_hooks_length, thinkframe_hooks); +} + +static void PS_DrawPostThinkFrameStats(void) +{ + draw_think_frame_stats(postthinkframe_hooks_length, postthinkframe_hooks); +} + + void M_DrawPerfStats(void) { if (cv_perfstats.value == 1) // rendering @@ -841,7 +970,7 @@ void M_DrawPerfStats(void) // tics when frame skips happen PS_DrawGameLogicStats(); } - else if (cv_perfstats.value == 3) // lua thinkframe + else if (cv_perfstats.value >= 3) // lua thinkframe { if (!PS_IsLevelActive()) return; @@ -850,13 +979,23 @@ void M_DrawPerfStats(void) // Low resolutions can't really use V_DrawSmallString that is used by thinkframe stats. // A low-res version using V_DrawThinString could be implemented, // but it would have much less space for information. - V_DrawThinString(80, 92, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "Perfstats 3 is not available"); + V_DrawThinString(80, 92, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "Lua Perfstats is not available"); V_DrawThinString(80, 100, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "for resolutions below 640x400."); + return; } - else + if (cv_perfstats.value == 3) { PS_DrawThinkFrameStats(); } + else if (cv_perfstats.value == 4) + { + PS_DrawPreThinkFrameStats(); + } + else if (cv_perfstats.value == 5) + { + PS_DrawPostThinkFrameStats(); + } + } } @@ -867,10 +1006,18 @@ static void PS_ClearHistory(void) Z_FreeTags(PU_PERFSTATS, PU_PERFSTATS); // thinkframe hook metric history pointers need to be cleared manually + for (i = 0; i < prethinkframe_hooks_length; i++) + { + prethinkframe_hooks[i].time_taken.history = NULL; + } for (i = 0; i < thinkframe_hooks_length; i++) { thinkframe_hooks[i].time_taken.history = NULL; } + for (i = 0; i < postthinkframe_hooks_length; i++) + { + postthinkframe_hooks[i].time_taken.history = NULL; + } ps_frame_index = ps_tick_index = 0; // PS_UpdateMetricHistory will set these correctly when it runs diff --git a/src/m_perfstats.h b/src/m_perfstats.h index d9ce6d171..ade7efd33 100644 --- a/src/m_perfstats.h +++ b/src/m_perfstats.h @@ -44,12 +44,17 @@ extern ps_metric_t ps_thlist_times[]; extern ps_metric_t ps_checkposition_calls; +extern ps_metric_t ps_lua_prethinkframe_time; extern ps_metric_t ps_lua_thinkframe_time; +extern ps_metric_t ps_lua_postthinkframe_time; extern ps_metric_t ps_lua_mobjhooks; extern ps_metric_t ps_otherlogictime; +void PS_SetPreThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); +void PS_SetPostThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); + void PS_UpdateTickStats(void); diff --git a/src/mserv.c b/src/mserv.c index 5c33cfe88..6945154c4 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -57,8 +57,12 @@ static void Command_Listserv_f(void); #endif/*MASTERSERVER*/ + + static void Update_parameters (void); +#ifdef MASTERSERVER + static void MasterServer_OnChange(void); static void Advertise_OnChange(void); @@ -69,16 +73,26 @@ static CV_PossibleValue_t masterserver_update_rate_cons_t[] = { {0, NULL} }; +#endif + +#ifdef MASTERSERVER consvar_t cv_masterserver = {"masterserver", "https://ms.kartkrew.org/ms/api", CV_SAVE|CV_CALL, NULL, MasterServer_OnChange, 0, NULL, NULL, 0, 0, NULL}; +#endif + +#ifdef HOLEPUNCH consvar_t cv_rendezvousserver = {"holepunchserver", "relay.kartkrew.org", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + consvar_t cv_servername = {"servername", "SRB2Kart server", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Update_parameters, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_server_contact = {"server_contact", "", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Update_parameters, 0, NULL, NULL, 0, 0, NULL}; - +#ifdef MASTERSERVER consvar_t cv_masterserver_update_rate = {"masterserver_update_rate", "15", CV_SAVE|CV_CALL|CV_NOINIT, masterserver_update_rate_cons_t, MasterClient_Ticker, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_advertise = {"advertise", "No", CV_NETVAR|CV_CALL|CV_NOINIT, CV_YesNo, Advertise_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_masterserver_nagattempts = {"masterserver_nagattempts", "5", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +#endif + #if defined (MASTERSERVER) && defined (HAVE_THREADS) int ms_QueryId; @@ -98,6 +112,7 @@ UINT16 current_port = 0; void AddMServCommands(void) { #ifndef NONET +#ifdef MASTERSERVER CV_RegisterVar(&cv_masterserver); CV_RegisterVar(&cv_masterserver_update_rate); CV_RegisterVar(&cv_masterserver_timeout); @@ -105,7 +120,11 @@ void AddMServCommands(void) CV_RegisterVar(&cv_masterserver_token); CV_RegisterVar(&cv_masterserver_nagattempts); CV_RegisterVar(&cv_advertise); +#endif +#ifdef HOLEPUNCH CV_RegisterVar(&cv_rendezvousserver); +#endif + CV_RegisterVar(&cv_servername); CV_RegisterVar(&cv_server_contact); #ifdef MASTERSERVER @@ -548,19 +567,20 @@ Update_parameters (void) } #endif/*MASTERSERVER*/ } - +#ifdef MASTERSERVER static void MasterServer_OnChange(void) { -#ifdef MASTERSERVER + UnregisterServer(); Set_api(cv_masterserver.string); if (Online()) RegisterServer(); -#endif/*MASTERSERVER*/ -} +} +#endif/*MASTERSERVER*/ +#ifdef MASTERSERVER static void Advertise_OnChange(void) { @@ -596,3 +616,4 @@ Advertise_OnChange(void) M_PopupMasterServerRules(); } } +#endif diff --git a/src/mserv.h b/src/mserv.h index c4c2d078f..5a74771a4 100644 --- a/src/mserv.h +++ b/src/mserv.h @@ -51,18 +51,25 @@ typedef struct #endif // ================================ GLOBALS =============================== - -extern consvar_t cv_masterserver, cv_servername; +#ifdef MASTERSERVER +extern consvar_t cv_masterserver; +#endif +extern consvar_t cv_servername; extern consvar_t cv_server_contact; +#ifdef MASTERSERVER extern consvar_t cv_masterserver_update_rate; extern consvar_t cv_masterserver_timeout; extern consvar_t cv_masterserver_debug; extern consvar_t cv_masterserver_token; -extern consvar_t cv_rendezvousserver; extern consvar_t cv_advertise; extern consvar_t cv_masterserver_nagattempts; +#endif + +#ifdef HOLEPUNCH +extern consvar_t cv_rendezvousserver; +#endif #ifdef HAVE_THREADS extern int ms_QueryId; @@ -71,7 +78,7 @@ extern I_mutex ms_QueryId_mutex; extern msg_server_t *ms_ServerList; extern I_mutex ms_ServerList_mutex; #endif - +#ifdef MASTERSERVER void RegisterServer(void); void UnregisterServer(void); @@ -97,3 +104,5 @@ int HMS_compare_mod_version (char *buffer, size_t size_of_buffer); const char * HMS_fetch_rules (char *buffer, size_t size_of_buffer); #endif + +#endif \ No newline at end of file diff --git a/src/p_inter.c b/src/p_inter.c index 07f4860e9..9e333ebe2 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2348,7 +2348,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) } target->player->playerstate = PST_DEAD; - if (cv_fading.value && P_IsLocalPlayer(target->player)) + if (cv_fading.value && cv_birdmusic.value && P_IsLocalPlayer(target->player)) { if (netgame || multiplayer) ms = cv_respawntime.value * 1000; diff --git a/src/p_local.h b/src/p_local.h index bb7c62046..df8df412e 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -142,7 +142,6 @@ extern consvar_t cv_quaketilt; extern consvar_t cv_tiltsmoothing; extern consvar_t cv_actionmovie; -extern consvar_t cv_windowquake; extern fixed_t t_cam_dist, t_cam_height, t_cam_rotate; extern fixed_t t_cam2_dist, t_cam2_height, t_cam2_rotate; diff --git a/src/p_mobj.c b/src/p_mobj.c index 12653d39d..c52bb05be 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6063,13 +6063,22 @@ static void P_AddOverlay(mobj_t *thing) static void P_RemoveOverlay(mobj_t *thing) { mobj_t *mo; + if (overlaycap == thing) + { + P_SetTarget(&overlaycap, thing->hnext); + P_SetTarget(&thing->hnext, NULL); + return; + } + for (mo = overlaycap; mo; mo = mo->hnext) - if (mo->hnext == thing) - { - P_SetTarget(&mo->hnext, thing->hnext); - P_SetTarget(&thing->hnext, NULL); - return; - } + { + if (mo->hnext != thing) + continue; + + P_SetTarget(&mo->hnext, thing->hnext); + P_SetTarget(&thing->hnext, NULL); + return; + } } void P_RunShadows(void) @@ -6175,12 +6184,14 @@ static void P_RemoveShadow(mobj_t *thing) } for (mo = shadowcap; mo; mo = mo->hnext) - if (mo->hnext == thing) - { - P_SetTarget(&mo->hnext, thing->hnext); - P_SetTarget(&thing->hnext, NULL); - return; - } + { + if (mo->hnext != thing) + continue; + + P_SetTarget(&mo->hnext, thing->hnext); + P_SetTarget(&thing->hnext, NULL); + return; + } } void A_BossDeath(mobj_t *mo); @@ -10359,7 +10370,7 @@ void P_SpawnPrecipitation(void) subsector_t *precipsector = NULL; precipmobj_t *rainmo = NULL; - if (dedicated || !(cv_drawdist_precip.value) || curWeather == PRECIP_NONE || curWeather == PRECIP_STORM_NORAIN) // SRB2Kart + if (dedicated || /*!cv_precipdensity*/!cv_drawdist_precip.value || curWeather == PRECIP_NONE) // SRB2Kart return; // Use the blockmap to narrow down our placing patterns @@ -10370,8 +10381,16 @@ void P_SpawnPrecipitation(void) //for (j = 0; j < cv_precipdensity.value; ++j) -- density is 1 for kart always { - x = basex + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); - y = basey + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); + if (cv_lessprecip.value) + { + x = basex*1.5 + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); + y = basey*1.5 + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); + } + else + { + x = basex + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); + y = basey + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3); + } precipsector = R_IsPointInSubsector(x, y); @@ -10402,13 +10421,22 @@ void P_SpawnPrecipitation(void) } else // everything else. rainmo = P_SpawnRainMobj(x, y, height, MT_RAIN); - if (curWeather == PRECIP_BLANK) - rainmo->precipflags |= PCF_INVISIBLE; // Randomly assign a height, now that floorz is set. rainmo->z = M_RandomRange(rainmo->floorz>>FRACBITS, rainmo->ceilingz>>FRACBITS)<thinker.function.acp1 = thinker; mobj->rollangle = 0; - mobj->spritexoffset = mobj->spriteyoffset = mobj->old_spritexoffset = mobj->old_spriteyoffset = FRACUNIT; - mobj->spritexscale = mobj->spriteyscale = mobj->old_spritexscale = mobj->old_spriteyscale = FRACUNIT; - mobj->realxscale = mobj->realyscale = FRACUNIT; + mobj->sloperoll = 0; + mobj->reservexydir = 0; + mobj->reservezangle = 0; + + mobj->spritexoffset = mobj->old_spritexoffset = 0; + mobj->spriteyoffset = mobj->old_spriteyoffset = 0; + mobj->spritexscale = mobj->old_spritexscale = FRACUNIT; + mobj->spriteyscale = mobj->old_spriteyscale = FRACUNIT; + mobj->realxscale = FRACUNIT; + mobj->realyscale = FRACUNIT; + mobj->stretchslam = 0; mobj->slamsoundtimer = 0; - mobj->sloperoll = mobj->reservezangle = mobj->reservexydir = 0; - + mobj->mirrored = 0; + mobj->z = z; mobj->floorz = floorz; mobj->ceilingz = ceilingz; diff --git a/src/p_setup.c b/src/p_setup.c index d8dcbb877..d85488c9f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3490,11 +3490,8 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (wadfiles[wadnum]->important) partadd_important = true; - - if (local) - wadfiles[wadnum]->localfile = true; - else - wadfiles[wadnum]->localfile = false; + + wadfiles[wadnum]->localfile = local; // // search for sound replacements @@ -3554,6 +3551,11 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // S_LoadMusicDefs(wadnum); + // + // edit music defs for stuff like musictest + // + S_LoadMTDefs(wadnum); + // // search for maps // @@ -3587,6 +3589,9 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!mapsadded) CONS_Printf(M_GetText("No maps added\n")); + // TODO: Experimental SPRTINFO support, test first + R_LoadSpriteInfoLumps(wadnum, wadfiles[wadnum]->numlumps); + refreshdirmenu &= ~REFRESHDIR_GAMEDATA; // Under usual circumstances we'd wait for REFRESHDIR_GAMEDATA to disappear the next frame, but it's a bit too dangerous for that... partadd_stage = 0; return wadnum; diff --git a/src/p_spec.c b/src/p_spec.c index 0ac38da01..bba01ed0e 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2002,14 +2002,53 @@ void P_LinedefExecute(INT16 tag, mobj_t *actor, sector_t *caller) // void P_SwitchWeather(INT32 weathernum) { - boolean purge = true; - boolean raintype = (PRECIP_SNOW || PRECIP_RAIN || PRECIP_STORM || PRECIP_STORM_NOSTRIKES || PRECIP_BLANK); + boolean purge = false; + INT32 swap = 0; - if (weathernum == curWeather) - return; - - if (weathernum == raintype && curWeather == raintype) - purge = false; + switch (weathernum) + { + case PRECIP_NONE: // None + if (curWeather == PRECIP_NONE) + return; // Nothing to do. + purge = true; + break; + case PRECIP_STORM: // Storm + case PRECIP_STORM_NOSTRIKES: // Storm w/ no lightning + case PRECIP_RAIN: // Rain + if (curWeather == PRECIP_SNOW || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + swap = PRECIP_RAIN; + break; + case PRECIP_SNOW: // Snow + if (curWeather == PRECIP_SNOW) + return; // Nothing to do. + if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES || curWeather == PRECIP_BLANK || curWeather == PRECIP_STORM_NORAIN) + swap = PRECIP_SNOW; // Need to delete the other precips. + break; + case PRECIP_STORM_NORAIN: // Storm w/o rain + if (curWeather == PRECIP_SNOW + || curWeather == PRECIP_STORM + || curWeather == PRECIP_STORM_NOSTRIKES + || curWeather == PRECIP_RAIN + || curWeather == PRECIP_BLANK) + swap = PRECIP_STORM_NORAIN; + else if (curWeather == PRECIP_STORM_NORAIN) + return; + break; + case PRECIP_BLANK: + if (curWeather == PRECIP_SNOW + || curWeather == PRECIP_STORM + || curWeather == PRECIP_STORM_NOSTRIKES + || curWeather == PRECIP_RAIN) + swap = PRECIP_BLANK; + else if (curWeather == PRECIP_STORM_NORAIN) + swap = PRECIP_BLANK; + else if (curWeather == PRECIP_BLANK) + return; + break; + default: + CONS_Debug(DBG_GAMELOGIC, "P_SwitchWeather: Unknown weather type %d.\n", weathernum); + break; + } if (purge) { @@ -2026,7 +2065,7 @@ void P_SwitchWeather(INT32 weathernum) P_RemovePrecipMobj(precipmobj); } } - else // Rather than respawn all that crap, reuse it! + else if (swap && !((swap == PRECIP_BLANK && curWeather == PRECIP_STORM_NORAIN) || (swap == PRECIP_STORM_NORAIN && curWeather == PRECIP_BLANK))) // Rather than respawn all that crap, reuse it! { thinker_t *think; precipmobj_t *precipmobj; @@ -2038,7 +2077,7 @@ void P_SwitchWeather(INT32 weathernum) continue; // not a precipmobj thinker precipmobj = (precipmobj_t *)think; - if (weathernum == PRECIP_RAIN || weathernum == PRECIP_STORM || weathernum == PRECIP_STORM_NOSTRIKES) // Snow To Rain + if (swap == PRECIP_RAIN) // Snow To Rain { precipmobj->flags = mobjinfo[MT_RAIN].flags; st = &states[mobjinfo[MT_RAIN].spawnstate]; @@ -2053,7 +2092,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->precipflags |= PCF_RAIN; //think->function.acp1 = (actionf_p1)P_RainThinker; } - else if (weathernum == PRECIP_SNOW) // Rain To Snow + else if (swap == PRECIP_SNOW) // Rain To Snow { INT32 z; @@ -2078,7 +2117,7 @@ void P_SwitchWeather(INT32 weathernum) //think->function.acp1 = (actionf_p1)P_SnowThinker; } - else // Remove precip, but keep it around for reuse. + else if (swap == PRECIP_BLANK || swap == PRECIP_STORM_NORAIN) // Remove precip, but keep it around for reuse. { //think->function.acp1 = (actionf_p1)P_NullPrecipThinker; @@ -2092,31 +2131,48 @@ void P_SwitchWeather(INT32 weathernum) case PRECIP_SNOW: // snow curWeather = PRECIP_SNOW; - if (purge) + if (!swap) P_SpawnPrecipitation(); break; case PRECIP_RAIN: // rain { + boolean dontspawn = false; + + if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) + dontspawn = true; + curWeather = PRECIP_RAIN; - if (purge) + if (!dontspawn && !swap) P_SpawnPrecipitation(); break; } case PRECIP_STORM: // storm { + boolean dontspawn = false; + + if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) + dontspawn = true; + curWeather = PRECIP_STORM; - if (purge) + if (!dontspawn && !swap) P_SpawnPrecipitation(); break; } case PRECIP_STORM_NOSTRIKES: // storm w/o lightning { - if (purge) + boolean dontspawn = false; + + if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) + dontspawn = true; + + curWeather = PRECIP_STORM_NOSTRIKES; + + if (!dontspawn && !swap) P_SpawnPrecipitation(); break; @@ -2124,11 +2180,14 @@ void P_SwitchWeather(INT32 weathernum) case PRECIP_STORM_NORAIN: // storm w/o rain curWeather = PRECIP_STORM_NORAIN; + if (!swap) + P_SpawnPrecipitation(); + break; - case PRECIP_BLANK: //preloaded + case PRECIP_BLANK: curWeather = PRECIP_BLANK; - if (purge) + if (!swap) P_SpawnPrecipitation(); break; diff --git a/src/p_tick.c b/src/p_tick.c index 38900db9f..6bad0f856 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -662,7 +662,10 @@ void P_Ticker(boolean run) ps_checkposition_calls.value.i = 0; #ifdef HAVE_BLUA + PS_START_TIMING(ps_lua_prethinkframe_time); LUAh_PreThinkFrame(); + PS_STOP_TIMING(ps_lua_prethinkframe_time); + #endif PS_START_TIMING(ps_playerthink_time); @@ -772,8 +775,6 @@ void P_Ticker(boolean run) quake.x = M_RandomRange(-ir,ir); quake.y = M_RandomRange(-ir,ir); quake.z = M_RandomRange(-ir,ir); - if (cv_windowquake.value) - I_CursedWindowMovement(FixedInt(quake.x), FixedInt(quake.y)); ir >>= 2; ir = M_RandomRange(-ir,ir); if (ir < 0) @@ -825,7 +826,11 @@ void P_Ticker(boolean run) D_MapChange(gamemap, gametype, encoremode, true, 0, false, false); #ifdef HAVE_BLUA + + PS_START_TIMING(ps_lua_postthinkframe_time); LUAh_PostThinkFrame(); + PS_STOP_TIMING(ps_lua_postthinkframe_time); + #endif } @@ -920,6 +925,8 @@ void P_PreTicker(INT32 frames) // Run shield positioning //P_RunShields(); P_RunOverlays(); + + P_RunShadows(); P_UpdateSpecials(); P_RespawnSpecials(); diff --git a/src/p_user.c b/src/p_user.c index 9a660b70e..fab59d28b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1281,13 +1281,17 @@ void P_RestoreMusic(player_t *player) if (wantedmus == 2 && cv_growmusic.value) { S_ChangeMusicInternal("kgrow", true); - S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); + + if (cv_birdmusic.value) + S_SetRestoreMusicFadeInCvar(&cv_growmusicfade); } // Item - Invincibility else if (wantedmus == 1 && cv_supermusic.value) { S_ChangeMusicInternal("kinvnc", true); - S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); + + if (cv_birdmusic.value) + S_SetRestoreMusicFadeInCvar(&cv_invincmusicfade); } else { @@ -1297,14 +1301,20 @@ void P_RestoreMusic(player_t *player) if (G_RaceGametype() && player->laps >= (UINT8)(cv_numlaps.value - 1)) S_SpeedMusic(1.2f); #endif - if (mapmusresume && cv_resume.value) - position = mapmusresume; - else - position = mapmusposition; + if (cv_birdmusic.value) + { + if (mapmusresume && cv_resume.value) + position = mapmusresume; + else + position = mapmusposition; - S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, - S_GetRestoreMusicFadeIn()); - S_ClearRestoreMusicFadeInCvar(); + S_ChangeMusicEx(mapmusname, mapmusflags, true, position, 0, + S_GetRestoreMusicFadeIn()); + S_ClearRestoreMusicFadeInCvar(); + } + else + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + mapmusresume = 0; } } @@ -7159,7 +7169,6 @@ consvar_t cv_quaketilt = {"quaketilt", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, consvar_t cv_tiltsmoothing = {"tiltsmoothing", "32", CV_SAVE, CV_Natural, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_actionmovie = {"actionmovie", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_windowquake = {"windowquake", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; fixed_t t_cam_dist = -42; fixed_t t_cam_height = -42; @@ -8063,7 +8072,7 @@ boolean P_SpectatorJoinGame(player_t *player) // Pressing fire assigns you to a team that needs players if allowed. // Partial code reproduction from p_tick.c autobalance code. else if (G_GametypeHasTeams()) - { + { INT32 changeto = 0; INT32 z, numplayersred = 0, numplayersblue = 0; @@ -8099,6 +8108,10 @@ boolean P_SpectatorJoinGame(player_t *player) player->kartstuff[k_spectatewait] = 0; player->ctfteam = changeto; player->playerstate = PST_REBORN; + + //center camera if its not already + if ((P_IsLocalPlayer(player)) && localaiming[0] != 0) + localaiming[0] = 0; //Reset away view if (P_IsLocalPlayer(player) && displayplayers[0] != consoleplayer) @@ -8113,7 +8126,7 @@ boolean P_SpectatorJoinGame(player_t *player) } // Joining in game from firing. else - { + { if (player->mo) { P_RemoveMobj(player->mo); @@ -8124,6 +8137,10 @@ boolean P_SpectatorJoinGame(player_t *player) player->kartstuff[k_spectatewait] = 0; player->playerstate = PST_REBORN; + //center camera if its not already + if ((P_IsLocalPlayer(player)) && localaiming[0] != 0) + localaiming[0] = 0; + //Reset away view if (P_IsLocalPlayer(player) && displayplayers[0] != consoleplayer) displayplayers[0] = consoleplayer; diff --git a/src/r_bsp.c b/src/r_bsp.c index 2de30d2ab..f0dcbd80e 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngle64(line->v1->x, line->v1->y); - angle2 = R_PointToAngle64(line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); curline = line; // Clip to view edges. @@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_data.c b/src/r_data.c index 4010aae0b..48a421170 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -39,11 +39,7 @@ #endif // Not sure if this is necessary, but it was in w_wad.c, so I'm putting it here too -Shadow Hog -#ifdef _WIN32_WCE -#define AVOID_ERRNO -#else #include -#endif // // Texture definition. @@ -1325,7 +1321,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) extra_colormaps[mapnum].fadeend = (UINT16)fadeend; extra_colormaps[mapnum].fog = fog; - if (rendermode == render_soft || rendermode == render_opengl) + if (rendermode != render_none) { double r, g, b, cbrightness; int p; diff --git a/src/r_defs.h b/src/r_defs.h index fa978ced2..8811d64e2 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -407,6 +407,8 @@ typedef enum ST_NEGATIVE } slopetype_t; +#define HORIZONSPECIAL 41 + typedef struct line_s { // Vertices, from v1 to v2. diff --git a/src/r_draw.c b/src/r_draw.c index ae30df6cc..b745c6d10 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -579,6 +579,33 @@ UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors return RGetTranslationColormap(( skin - skins ), color, flags, false); } +patch_t* R_GetSkinFaceRank(player_t* ply) +{ + if (ply->skinlocal && ply->localskin) + return localfacerankprefix[ply->localskin - 1]; + else if (ply->localskin) + 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) + 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) + return facemmapprefix[ply->localskin - 1]; + return facemmapprefix[ply->skin]; +} + /** \brief Flushes cache of translation colormaps. Flushes cache of translation colormaps, but doesn't actually free the diff --git a/src/r_draw.h b/src/r_draw.h index b4e3fb651..ddcf596fa 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -117,6 +117,9 @@ extern lumpnum_t viewborderlump[8]; void R_InitTranslationTables(void); 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); +patch_t* R_GetSkinFaceRank(player_t* ply); +patch_t* R_GetSkinFaceWant(player_t* ply); +patch_t* R_GetSkinFaceMini(player_t* ply); void R_FlushTranslationColormapCache(void); UINT8 R_GetColorByName(const char *name); diff --git a/src/r_draw8.c b/src/r_draw8.c index 7f1c0763c..c80ff2cbc 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -542,16 +542,19 @@ void R_DrawTranslatedColumn_8(void) */ void R_DrawSpan_8 (void) { - UINT32 xposition; - UINT32 yposition; - UINT32 xstep, ystep; + fixed_t xposition; + fixed_t yposition; + fixed_t xstep, ystep; UINT8 *source; UINT8 *colormap; UINT8 *dest; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; - size_t count; + size_t count = (ds_x2 - ds_x1 + 1); + + xposition = ds_xfrac; yposition = ds_yfrac; + xstep = ds_xstep; ystep = ds_ystep; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // can be used for the fraction part. This allows calculation of the memory address in the @@ -560,13 +563,12 @@ void R_DrawSpan_8 (void) // bit per power of two (obviously) // Ok, because I was able to eliminate the variable spot below, this function is now FASTER // than the original span renderer. Whodathunkit? - xposition = ds_xfrac << nflatshiftup; yposition = ds_yfrac << nflatshiftup; - xstep = ds_xstep << nflatshiftup; ystep = ds_ystep << nflatshiftup; + xposition <<= nflatshiftup; yposition <<= nflatshiftup; + xstep <<= nflatshiftup; ystep <<= nflatshiftup; source = ds_source; colormap = ds_colormap; dest = ylookup[ds_y] + columnofs[ds_x1]; - count = ds_x2 - ds_x1 + 1; if (dest+8 > deststop) return; @@ -576,35 +578,35 @@ void R_DrawSpan_8 (void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[0] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[1] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[1] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[2] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[2] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[3] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[3] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[4] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[4] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[5] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[5] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[6] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[6] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; - dest[7] = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + dest[7] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; @@ -613,7 +615,7 @@ void R_DrawSpan_8 (void) } while (count-- && dest <= deststop) { - *dest++ = colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]]; + *dest++ = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; xposition += xstep; yposition += ystep; } @@ -1281,15 +1283,20 @@ void R_DrawTranslucentSplat_8 (void) */ void R_DrawTranslucentSpan_8 (void) { - UINT32 xposition; - UINT32 yposition; - UINT32 xstep, ystep; + fixed_t xposition; + fixed_t yposition; + fixed_t xstep, ystep; UINT8 *source; UINT8 *colormap; UINT8 *dest; + const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; - size_t count; + size_t count = (ds_x2 - ds_x1 + 1); + UINT32 val; + + xposition = ds_xfrac; yposition = ds_yfrac; + xstep = ds_xstep; ystep = ds_ystep; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // can be used for the fraction part. This allows calculation of the memory address in the @@ -1298,57 +1305,57 @@ void R_DrawTranslucentSpan_8 (void) // bit per power of two (obviously) // Ok, because I was able to eliminate the variable spot below, this function is now FASTER // than the original span renderer. Whodathunkit? - xposition = ds_xfrac << nflatshiftup; yposition = ds_yfrac << nflatshiftup; - xstep = ds_xstep << nflatshiftup; ystep = ds_ystep << nflatshiftup; + xposition <<= nflatshiftup; yposition <<= nflatshiftup; + xstep <<= nflatshiftup; ystep <<= nflatshiftup; source = ds_source; colormap = ds_colormap; dest = ylookup[ds_y] + columnofs[ds_x1]; - count = ds_x2 - ds_x1 + 1; while (count >= 8) { // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[0]); + dest[0] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[0]); xposition += xstep; yposition += ystep; - dest[1] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[1]); + dest[1] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[1]); xposition += xstep; yposition += ystep; - dest[2] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[2]); + dest[2] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[2]); xposition += xstep; yposition += ystep; - dest[3] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[3]); + dest[3] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[3]); xposition += xstep; yposition += ystep; - dest[4] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[4]); + dest[4] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[4]); xposition += xstep; yposition += ystep; - dest[5] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[5]); + dest[5] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[5]); xposition += xstep; yposition += ystep; - dest[6] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[6]); + dest[6] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[6]); xposition += xstep; yposition += ystep; - dest[7] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[7]); + dest[7] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[7]); xposition += xstep; yposition += ystep; dest += 8; count -= 8; } - while (count--) + while (count-- && dest <= deststop) { - *dest = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + *dest); + val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); + *dest = *(ds_transmap + (colormap[source[val]] << 8) + *dest); dest++; xposition += xstep; yposition += ystep; diff --git a/src/r_main.c b/src/r_main.c index 1d3a6968c..63d1a7a59 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -37,16 +37,6 @@ #include "hardware/hw_main.h" #endif -//profile stuff --------------------------------------------------------- -//#define TIMING -#ifdef TIMING -#include "p5prof.h" -INT64 mycount; -INT64 mytotal = 0; -//unsigned long nombre = 100000; -#endif -//profile stuff --------------------------------------------------------- - // Fineangles in the SCREENWIDTH wide window. #define FIELDOFVIEW 2048 @@ -197,7 +187,8 @@ consvar_t cv_flipcam4 = {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, 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}; -consvar_t cv_ffloorclip = {"ffloorclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ffloorclip = {"r_ffloorclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_spriteclip = {"r_spriteclip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_soniccd = {"soniccd", "Off", CV_NETVAR|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowmlook = {"allowmlook", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_showhud = {"showhud", "Yes", CV_CALL, CV_YesNo, R_SetViewSize, 0, NULL, NULL, 0, 0, NULL}; @@ -207,6 +198,7 @@ consvar_t cv_translucency = {"translucency", "On", CV_SAVE, CV_OnOff, NULL, 0, N consvar_t cv_drawdist = {"drawdist", "Infinite", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_drawdist_nights = {"drawdist_nights", "2048", CV_SAVE, drawdist_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_drawdist_precip = {"drawdist_precip", "1024", CV_SAVE, drawdist_precip_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lessprecip = {"lessweathereffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; //consvar_t cv_precipdensity = {"precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // cap fov, fov too high tears software apart. @@ -352,7 +344,7 @@ INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *restrict node) } // killough 5/2/98: reformatted -INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *restrict line) +INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line) { fixed_t lx = line->v1->x; fixed_t ly = line->v1->y; @@ -369,10 +361,9 @@ INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *restrict line) y -= ly; // Try to quickly decide by looking at sign bits. - // also use a mask to avoid branch prediction - INT32 mask = (ldy ^ ldx ^ x ^ y) >> 31; - return (mask & ((ldy ^ x) < 0)) | // (left is negative) - (~mask & (FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x))); + if ((ldy ^ ldx ^ x ^ y) < 0) + return (ldy ^ x) < 0; // (left is negative) + return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x); } // @@ -404,22 +395,6 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } -angle_t R_PointToAngle64(INT64 x, INT64 y) -{ - return (y -= viewy, (x -= viewx) || y) ? - x >= 0 ? - y >= 0 ? - (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0 - ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1 - x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8 - ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7 - y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2 - (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4 - ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5 - 0; -} - angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -514,6 +489,32 @@ angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) 0; } +angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1) +{ + INT64 dx = x1 - x2; + INT64 dy = y1 - y2; + + // Check for potential overflow or underflow + if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX) + { + x1 = (INT64)(dx / 2 + x2); + y1 = (INT64)(dy / 2 + y2); + } + + return (y1 -= y2, (x1 -= x2) || y1) ? + x1 >= 0 ? + y1 >= 0 ? + (x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0 + ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1 + x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8 + ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7 + y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2 + (x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4 + ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5 + 0; +} + // // R_ScaleFromGlobalAngle // Returns the texture mapping scale for the current line (horizontal span) @@ -1811,26 +1812,15 @@ void R_RenderPlayerView(player_t *player) // The head node is the last node output. -//profile stuff --------------------------------------------------------- -#ifdef TIMING - mytotal = 0; - ProfZeroTimer(); -#endif ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0; PS_START_TIMING(ps_bsptime); R_RenderBSPNode((INT32)numnodes - 1); PS_STOP_TIMING(ps_bsptime); - ps_numsprites.value.i = visspritecount; PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(); PS_STOP_TIMING(ps_sw_spritecliptime); -#ifdef TIMING - RDMSR(0x10, &mycount); - mytotal += mycount; // 64bit add - - CONS_Debug(DBG_RENDER, "RenderBSPNode: 0x%d %d\n", *((INT32 *)&mytotal + 1), (INT32)mytotal); -#endif -//profile stuff --------------------------------------------------------- + + ps_numsprites.value.i = numvisiblesprites; // PORTAL RENDERING PS_START_TIMING(ps_sw_portaltime); @@ -1916,6 +1906,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_drawdist); //CV_RegisterVar(&cv_drawdist_nights); CV_RegisterVar(&cv_drawdist_precip); + CV_RegisterVar(&cv_lessprecip); CV_RegisterVar(&cv_fov); CV_RegisterVar(&cv_chasecam); @@ -1926,6 +1917,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_shadowoffs); CV_RegisterVar(&cv_skybox); CV_RegisterVar(&cv_ffloorclip); + CV_RegisterVar(&cv_spriteclip); CV_RegisterVar(&cv_cam_dist); CV_RegisterVar(&cv_cam_still); @@ -1959,7 +1951,6 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_quaketilt); CV_RegisterVar(&cv_tiltsmoothing); CV_RegisterVar(&cv_actionmovie); - CV_RegisterVar(&cv_windowquake); CV_RegisterVar(&cv_driftsparkpulse); CV_RegisterVar(&cv_gravstretch); diff --git a/src/r_main.h b/src/r_main.h index d6c966857..6a7ea7da6 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); -angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); +angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); @@ -111,9 +111,9 @@ extern consvar_t cv_homremoval; extern consvar_t cv_chasecam, cv_chasecam2, cv_chasecam3, cv_chasecam4; extern consvar_t cv_flipcam, cv_flipcam2, cv_flipcam3, cv_flipcam4; extern consvar_t cv_shadow, cv_shadowoffs; -extern consvar_t cv_ffloorclip; +extern consvar_t cv_ffloorclip, cv_spriteclip; extern consvar_t cv_translucency; -extern consvar_t /*cv_precipdensity,*/ cv_drawdist, /*cv_drawdist_nights,*/ cv_drawdist_precip; +extern consvar_t /*cv_precipdensity,*/ cv_drawdist, /*cv_drawdist_nights,*/ cv_drawdist_precip, cv_lessprecip; extern consvar_t cv_fov; extern consvar_t cv_skybox; extern consvar_t cv_tailspickup; diff --git a/src/r_patch.c b/src/r_patch.c index efd49f5e2..f69be9de3 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -1,1018 +1,1037 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1993-1996 by id Software, Inc. -// Copyright (C) 2005-2009 by Andrey "entryway" Budko. -// Copyright (C) 2018-2020 by Jaime "Lactozilla" Passos. -// Copyright (C) 2019-2020 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file r_patch.c -/// \brief Patch generation. - -#include "byteptr.h" -#include "dehacked.h" -#include "i_video.h" -#include "r_data.h" -#include "r_draw.h" -#include "r_patch.h" -#include "r_things.h" -#include "z_zone.h" -#include "w_wad.h" - -#ifdef HWRENDER -#include "hardware/hw_glob.h" -#endif - -static unsigned char imgbuf[1<<26]; - -// -// R_CheckIfPatch -// -// Returns true if the lump is a valid patch. -// -boolean R_CheckIfPatch(lumpnum_t lump) -{ - size_t size; - INT16 width, height; - patch_t *patch; - boolean result; - - size = W_LumpLength(lump); - - // minimum length of a valid Doom patch - if (size < 13) - return false; - - patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); - - width = patch->width; - height = patch->height; - - result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4)); - - if (result) - { - // The dimensions seem like they might be valid for a patch, so - // check the column directory for extra security. All columns - // must begin after the column directory, and none of them must - // point past the end of the patch. - INT16 x; - - for (x = 0; x < width; x++) - { - UINT32 ofs = LONG(patch->columnofs[x]); - - // Need one byte for an empty column (but there's patches that don't know that!) - if (ofs < (UINT32)width * 4 + 8 || ofs >= (UINT32)size) - { - result = false; - break; - } - } - } - - return result; -} - -// -// R_TextureToFlat -// -// Convert a texture to a flat. -// -void R_TextureToFlat(size_t tex, UINT8 *flat) -{ - texture_t *texture = textures[tex]; - - fixed_t col, ofs; - column_t *column; - UINT8 *desttop, *dest, *deststop; - UINT8 *source; - - // yea - R_CheckTextureCache(tex); - - desttop = flat; - deststop = desttop + (texture->width * texture->height); - - for (col = 0; col < texture->width; col++, desttop++) - { - // no post_t info - if (!texture->holes) - { - column = (column_t *)(R_GetColumn(tex, col)); - source = (UINT8 *)(column); - dest = desttop; - for (ofs = 0; dest < deststop && ofs < texture->height; ofs++) - { - if (source[ofs] != TRANSPARENTPIXEL) - *dest = source[ofs]; - dest += texture->width; - } - } - else - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)R_GetColumn(tex, col) - 3); - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - - dest = desttop + (topdelta * texture->width); - source = (UINT8 *)column + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - if (source[ofs] != TRANSPARENTPIXEL) - *dest = source[ofs]; - dest += texture->width; - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } - } -} - -// -// R_PatchToFlat -// -// Convert a patch to a flat. -// -void R_PatchToFlat(patch_t *patch, UINT8 *flat) -{ - fixed_t col, ofs; - column_t *column; - UINT8 *desttop, *dest, *deststop; - UINT8 *source; - - desttop = flat; - deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); - - for (col = 0; col < SHORT(patch->width); col++, desttop++) - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[col])); - - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - - dest = desttop + (topdelta * SHORT(patch->width)); - source = (UINT8 *)(column) + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - *dest = source[ofs]; - dest += SHORT(patch->width); - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } -} - -// -// R_PatchToMaskedFlat -// -// Convert a patch to a masked flat. -// Now, what is a "masked" flat anyway? -// It means the flat uses two bytes to store image data. -// The upper byte is used to store the transparent pixel, -// and the lower byte stores a palette index. -// -void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip) -{ - fixed_t col, ofs; - column_t *column; - UINT16 *desttop, *dest, *deststop; - UINT8 *source; - - desttop = raw; - deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); - - for (col = 0; col < SHORT(patch->width); col++, desttop++) - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-col) : col])); - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - dest = desttop + (topdelta * SHORT(patch->width)); - source = (UINT8 *)(column) + 3; - for (ofs = 0; dest < deststop && ofs < column->length; ofs++) - { - *dest = source[ofs]; - dest += SHORT(patch->width); - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } -} - -// -// R_FlatToPatch -// -// Convert a flat to a patch. -// -patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency) -{ - UINT32 x, y; - UINT8 *img; - UINT8 *imgptr = imgbuf; - UINT8 *colpointers, *startofspan; - size_t size = 0; - - if (!raw) - return NULL; - - // Write image size and offset - WRITEINT16(imgptr, width); - WRITEINT16(imgptr, height); - WRITEINT16(imgptr, leftoffset); - WRITEINT16(imgptr, topoffset); - - // Leave placeholder to column pointers - colpointers = imgptr; - imgptr += width*4; - - // Write columns - for (x = 0; x < width; x++) - { - int lastStartY = 0; - int spanSize = 0; - startofspan = NULL; - - // Write column pointer - WRITEINT32(colpointers, imgptr - imgbuf); - - // Write pixels - for (y = 0; y < height; y++) - { - UINT8 paletteIndex = raw[((y * width) + x)]; - boolean opaque = transparency ? (paletteIndex != TRANSPARENTPIXEL) : true; - - // End span if we have a transparent pixel - if (!opaque) - { - if (startofspan) - WRITEUINT8(imgptr, 0); - startofspan = NULL; - continue; - } - - // Start new column if we need to - if (!startofspan || spanSize == 255) - { - int writeY = y; - - // If we reached the span size limit, finish the previous span - if (startofspan) - WRITEUINT8(imgptr, 0); - - if (y > 254) - { - // Make sure we're aligned to 254 - if (lastStartY < 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - lastStartY = 254; - } - - // Write stopgap empty spans if needed - writeY = y - lastStartY; - - while (writeY > 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - writeY -= 254; - } - } - - startofspan = imgptr; - WRITEUINT8(imgptr, writeY); - imgptr += 2; - spanSize = 0; - - lastStartY = y; - } - - // Write the pixel - WRITEUINT8(imgptr, paletteIndex); - spanSize++; - startofspan[1] = spanSize; - } - - if (startofspan) - WRITEUINT8(imgptr, 0); - - WRITEUINT8(imgptr, 0xFF); - } - - size = imgptr-imgbuf; - img = Z_Malloc(size, PU_STATIC, NULL); - memcpy(img, imgbuf, size); - - Z_Free(raw); - - if (destsize != NULL) - *destsize = size; - return (patch_t *)img; -} - -// -// R_MaskedFlatToPatch -// -// Convert a masked flat to a patch. -// Explanation of "masked" flats in R_PatchToMaskedFlat. -// -patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize) -{ - UINT32 x, y; - UINT8 *img; - UINT8 *imgptr = imgbuf; - UINT8 *colpointers, *startofspan; - size_t size = 0; - - if (!raw) - return NULL; - - // Write image size and offset - WRITEINT16(imgptr, width); - WRITEINT16(imgptr, height); - WRITEINT16(imgptr, leftoffset); - WRITEINT16(imgptr, topoffset); - - // Leave placeholder to column pointers - colpointers = imgptr; - imgptr += width*4; - - // Write columns - for (x = 0; x < width; x++) - { - int lastStartY = 0; - int spanSize = 0; - startofspan = NULL; - - // Write column pointer - WRITEINT32(colpointers, imgptr - imgbuf); - - // Write pixels - for (y = 0; y < height; y++) - { - UINT16 pixel = raw[((y * width) + x)]; - UINT8 paletteIndex = (pixel & 0xFF); - UINT8 opaque = (pixel != 0xFF00); // If 1, we have a pixel - - // End span if we have a transparent pixel - if (!opaque) - { - if (startofspan) - WRITEUINT8(imgptr, 0); - startofspan = NULL; - continue; - } - - // Start new column if we need to - if (!startofspan || spanSize == 255) - { - int writeY = y; - - // If we reached the span size limit, finish the previous span - if (startofspan) - WRITEUINT8(imgptr, 0); - - if (y > 254) - { - // Make sure we're aligned to 254 - if (lastStartY < 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - lastStartY = 254; - } - - // Write stopgap empty spans if needed - writeY = y - lastStartY; - - while (writeY > 254) - { - WRITEUINT8(imgptr, 254); - WRITEUINT8(imgptr, 0); - imgptr += 2; - writeY -= 254; - } - } - - startofspan = imgptr; - WRITEUINT8(imgptr, writeY); - imgptr += 2; - spanSize = 0; - - lastStartY = y; - } - - // Write the pixel - WRITEUINT8(imgptr, paletteIndex); - spanSize++; - startofspan[1] = spanSize; - } - - if (startofspan) - WRITEUINT8(imgptr, 0); - - WRITEUINT8(imgptr, 0xFF); - } - - size = imgptr-imgbuf; - img = Z_Malloc(size, PU_STATIC, NULL); - memcpy(img, imgbuf, size); - - if (destsize != NULL) - *destsize = size; - return (patch_t *)img; -} - -// -// R_ParseSpriteInfoFrame -// -// Parse a SPRTINFO frame. -// -static void R_ParseSpriteInfoFrame(spriteinfo_t *info) -{ - char *sprinfoToken; - size_t sprinfoTokenLength; - char *frameChar = NULL; - UINT8 frameFrame = 0xFF; - INT16 frameXPivot = 0; - INT16 frameYPivot = 0; - rotaxis_t frameRotAxis = 0; - - // Sprite identifier - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite frame should be"); - } - sprinfoTokenLength = strlen(sprinfoToken); - if (sprinfoTokenLength != 1) - { - I_Error("Error parsing SPRTINFO lump: Invalid frame \"%s\"",sprinfoToken); - } - else - frameChar = sprinfoToken; - - frameFrame = R_Char2Frame(frameChar[0]); - Z_Free(sprinfoToken); - - // Left Curly Brace - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - I_Error("Error parsing SPRTINFO lump: Missing sprite info"); - else - { - if (strcmp(sprinfoToken,"{")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); - } - while (strcmp(sprinfoToken,"}")!=0) - { - if (stricmp(sprinfoToken, "XPIVOT")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - frameXPivot = atoi(sprinfoToken); - } - else if (stricmp(sprinfoToken, "YPIVOT")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - frameYPivot = atoi(sprinfoToken); - } - else if (stricmp(sprinfoToken, "ROTAXIS")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - if ((stricmp(sprinfoToken, "X")==0) || (stricmp(sprinfoToken, "XAXIS")==0) || (stricmp(sprinfoToken, "ROLL")==0)) - frameRotAxis = ROTAXIS_X; - else if ((stricmp(sprinfoToken, "Y")==0) || (stricmp(sprinfoToken, "YAXIS")==0) || (stricmp(sprinfoToken, "PITCH")==0)) - frameRotAxis = ROTAXIS_Y; - else if ((stricmp(sprinfoToken, "Z")==0) || (stricmp(sprinfoToken, "ZAXIS")==0) || (stricmp(sprinfoToken, "YAW")==0)) - frameRotAxis = ROTAXIS_Z; - } - Z_Free(sprinfoToken); - - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace should be"); - } - } - } - Z_Free(sprinfoToken); - } - - // set fields - info->pivot[frameFrame].x = frameXPivot; - info->pivot[frameFrame].y = frameYPivot; - info->pivot[frameFrame].rotaxis = frameRotAxis; -} - -// -// R_ParseSpriteInfo -// -// Parse a SPRTINFO lump. -// -static void R_ParseSpriteInfo(boolean spr2) -{ - spriteinfo_t *info; - char *sprinfoToken; - size_t sprinfoTokenLength; - char newSpriteName[5]; // no longer dynamically allocated - spritenum_t sprnum = NUMSPRITES; - //playersprite_t spr2num = NUMPLAYERSPRITES; - INT32 i; - INT32 skinnumbers[MAXSKINS]; // >variable 'skinnumbers' set but not used >compile error when commented out - INT32 foundskins = 0; - - // Sprite name - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite name should be"); - } - sprinfoTokenLength = strlen(sprinfoToken); - if (sprinfoTokenLength != 4) - { - I_Error("Error parsing SPRTINFO lump: Sprite name \"%s\" isn't 4 characters long",sprinfoToken); - } - else - { - memset(&newSpriteName, 0, 5); - M_Memcpy(newSpriteName, sprinfoToken, sprinfoTokenLength); - // ^^ we've confirmed that the token is == 4 characters so it will never overflow a 5 byte char buffer - strupr(newSpriteName); // Just do this now so we don't have to worry about it - } - Z_Free(sprinfoToken); - - if (!spr2) - { - for (i = 0; i <= NUMSPRITES; i++) - { - if (i == NUMSPRITES) - I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName); - if (!memcmp(newSpriteName,sprnames[i],4)) - { - sprnum = i; - break; - } - } - } - - // allocate a spriteinfo - info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL); - info->available = true; - - // Left Curly Brace - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where open curly brace for sprite \"%s\" should be",newSpriteName); - } - if (strcmp(sprinfoToken,"{")==0) - { - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where definition for sprite \"%s\" should be",newSpriteName); - } - while (strcmp(sprinfoToken,"}")!=0) - { - if (stricmp(sprinfoToken, "SKIN")==0) - { - INT32 skinnum; - char *skinName = NULL; - if (!spr2) - I_Error("Error parsing SPRTINFO lump: \"SKIN\" token found outside of a sprite2 definition"); - - Z_Free(sprinfoToken); - - // Skin name - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where skin frame should be"); - } - - // copy skin name yada yada - sprinfoTokenLength = strlen(sprinfoToken); - skinName = (char *)Z_Malloc((sprinfoTokenLength+1)*sizeof(char),PU_STATIC,NULL); - M_Memcpy(skinName,sprinfoToken,sprinfoTokenLength*sizeof(char)); - skinName[sprinfoTokenLength] = '\0'; - strlwr(skinName); - Z_Free(sprinfoToken); - - skinnum = R_SkinAvailable(skinName); - if (skinnum == -1) - I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName); - - skinnumbers[foundskins] = skinnum; - foundskins++; - } - else if (stricmp(sprinfoToken, "FRAME")==0) - { - R_ParseSpriteInfoFrame(info); - Z_Free(sprinfoToken); - M_Memcpy(&spriteinfo[sprnum], info, sizeof(spriteinfo_t)); - } - else - { - I_Error("Error parsing SPRTINFO lump: Unknown keyword \"%s\" in sprite %s",sprinfoToken,newSpriteName); - } - - sprinfoToken = M_GetToken(NULL); - if (sprinfoToken == NULL) - { - I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace for sprite \"%s\" should be",newSpriteName); - } - } - } - else - { - I_Error("Error parsing SPRTINFO lump: Expected \"{\" for sprite \"%s\", got \"%s\"",newSpriteName,sprinfoToken); - } - Z_Free(sprinfoToken); - Z_Free(info); -} - -// -// R_ParseSPRTINFOLump -// -// Read a SPRTINFO lump. -// -void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum) -{ - char *sprinfoLump; - size_t sprinfoLumpLength; - char *sprinfoText; - char *sprinfoToken; - - // Since lumps AREN'T \0-terminated like I'd assumed they should be, I'll - // need to make a space of memory where I can ensure that it will terminate - // correctly. Start by loading the relevant data from the WAD. - sprinfoLump = (char *)W_CacheLumpNumPwad(wadNum, lumpNum, PU_STATIC); - // If that didn't exist, we have nothing to do here. - if (sprinfoLump == NULL) return; - // If we're still here, then it DOES exist; figure out how long it is, and allot memory accordingly. - sprinfoLumpLength = W_LumpLengthPwad(wadNum, lumpNum); - sprinfoText = (char *)Z_Malloc((sprinfoLumpLength+1)*sizeof(char),PU_STATIC,NULL); - // Now move the contents of the lump into this new location. - memmove(sprinfoText,sprinfoLump,sprinfoLumpLength); - // Make damn well sure the last character in our new memory location is \0. - sprinfoText[sprinfoLumpLength] = '\0'; - // Finally, free up the memory from the first data load, because we really - // don't need it. - Z_Free(sprinfoLump); - - sprinfoToken = M_GetToken(sprinfoText); - while (sprinfoToken != NULL) - { - if (!stricmp(sprinfoToken, "SPRITE")) - R_ParseSpriteInfo(false); - else if (!stricmp(sprinfoToken, "SPRITE2")) - R_ParseSpriteInfo(true); - else - I_Error("Error parsing SPRTINFO lump: Unknown keyword \"%s\"", sprinfoToken); - Z_Free(sprinfoToken); - sprinfoToken = M_GetToken(NULL); - } - Z_Free((void *)sprinfoText); -} - -// -// R_LoadSpriteInfoLumps -// -// Load and read every SPRTINFO lump from the specified file. -// -void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps) -{ - lumpinfo_t *lumpinfo = wadfiles[wadnum]->lumpinfo; - UINT16 i; - char *name; - - for (i = 0; i < numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - // Load SPRTINFO and SPR_ lumps as SpriteInfo - if (!memcmp(name, "SPRTINFO", 8) || !memcmp(name, "SPR_", 4)) - R_ParseSPRTINFOLump(wadnum, i); - } -} - -static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) -{ - fixed_t ofs; - column_t *column; - UINT8 *source; - - if (x >= 0 && x < SHORT(patch->width)) - { - INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-x) : x])); - while (column->topdelta != 0xff) - { - topdelta = column->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - source = (UINT8 *)(column) + 3; - for (ofs = 0; ofs < column->length; ofs++) - { - if ((topdelta + ofs) == y) - return source[ofs]; - } - column = (column_t *)((UINT8 *)column + column->length + 4); - } - } - - return 0xFF00; -} - -#ifdef ROTSPRITE -// -// R_GetRollAngle -// -// Angles precalculated in R_InitSprites. -// -fixed_t rollcosang[ROTANGLES]; -fixed_t rollsinang[ROTANGLES]; - -INT32 R_GetRollAngle(angle_t rollangle) -{ - INT32 ra = AngleFixed(rollangle)>>FRACBITS; -#if (ROTANGDIFF > 1) - ra += (ROTANGDIFF/2); -#endif - ra /= ROTANGDIFF; - ra %= ROTANGLES; - return ra; -} - -patch_t *Patch_GetRotatedSprite( - spriteframe_t *sprite, - size_t frame, size_t spriteangle, - boolean flip, boolean adjustfeet, - void *info, INT32 rotationangle) -{ - rotsprite_t *rotsprite; - spriteinfo_t *sprinfo = (spriteinfo_t *)info; - INT32 idx = rotationangle; - UINT8 type = (adjustfeet ? 1 : 0); - - if (rotationangle < 1 || rotationangle >= ROTANGLES) - return NULL; - - rotsprite = sprite->rotated[type][spriteangle]; - - if (rotsprite == NULL) - { - rotsprite = RotatedPatch_Create(ROTANGLES); - sprite->rotated[type][spriteangle] = rotsprite; - } - - if (flip) - idx += rotsprite->angles; - - if (rotsprite->patches[idx] == NULL) - { - patch_t *patch; - INT32 xpivot = 0, ypivot = 0; - lumpnum_t lump = sprite->lumppat[spriteangle]; - - if (lump == LUMPERROR) - return NULL; - - patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); - - if (sprinfo->available) - { - xpivot = sprinfo->pivot[frame].x; - ypivot = sprinfo->pivot[frame].y; - } - else - { - xpivot = patch->leftoffset; - ypivot = patch->height / 2; - } - - RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); - - //BP: we cannot use special tric in hardware mode because feet in ground caused by z-buffer - if (adjustfeet) - ((patch_t *)rotsprite->patches[idx])->topoffset += FEETADJUST>>FRACBITS; - - // free image data - Z_Free(patch); - } - - return rotsprite->patches[idx]; -} - -rotsprite_t *RotatedPatch_Create(INT32 numangles) -{ - rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); - rotsprite->angles = numangles; - rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); - return rotsprite; -} - -static void RotatedPatch_CalculateDimensions( - INT32 width, INT32 height, - fixed_t ca, fixed_t sa, - INT32 *newwidth, INT32 *newheight) -{ - fixed_t fixedwidth = (width * FRACUNIT); - fixed_t fixedheight = (height * FRACUNIT); - - fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); - fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); - - w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); - w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); - h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); - h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); - - *newwidth = max(width, max(w1, w2)); - *newheight = max(height, max(h1, h2)); -} - -static patch_t *R_CreateHardwarePatch(patch_t *patch) -{ - GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); - grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); - grPatch->rawpatch = patch; - HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); - return (patch_t *)grPatch; -} - -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) -{ - UINT32 i; - patch_t *rotated, *hwpatch; - UINT16 *rawdst, *rawconv; - size_t size; - INT32 bflip = (flip != 0x00); - - INT32 width = patch->width; - INT32 height = patch->height; - INT32 leftoffset = patch->leftoffset; - INT32 newwidth, newheight; - - fixed_t ca = rollcosang[angle]; - fixed_t sa = rollsinang[angle]; - fixed_t xcenter, ycenter; - INT32 idx = angle; - INT32 x, y; - INT32 sx, sy; - INT32 dx, dy; - INT32 ox, oy; - INT32 minx, miny, maxx, maxy; - - // Don't cache angle = 0 - if (angle < 1 || angle >= ROTANGLES) - return; - - if (flip) - { - idx += rotsprite->angles; - xpivot = width - xpivot; - leftoffset = width - leftoffset; - } - - if (rotsprite->patches[idx]) - return; - - // Find the dimensions of the rotated patch. - RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); - - xcenter = (xpivot * FRACUNIT); - ycenter = (ypivot * FRACUNIT); - - if (xpivot != width / 2 || ypivot != height / 2) - { - newwidth *= 2; - newheight *= 2; - } - - minx = newwidth; - miny = newheight; - maxx = 0; - maxy = 0; - - // Draw the rotated sprite to a temporary buffer. - size = (newwidth * newheight); - if (!size) - size = (width * height); - rawdst = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); - - for (i = 0; i < size; i++) - rawdst[i] = 0xFF00; - - for (dy = 0; dy < newheight; dy++) - { - for (dx = 0; dx < newwidth; dx++) - { - x = (dx - (newwidth / 2)) * FRACUNIT; - y = (dy - (newheight / 2)) * FRACUNIT; - sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; - sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; - - sx >>= FRACBITS; - sy >>= FRACBITS; - - if (sx >= 0 && sy >= 0 && sx < width && sy < height) - rawdst[(dy*newwidth)+dx] = GetPatchPixel(patch, sx, sy, bflip); - } - } - - ox = (newwidth / 2) + (leftoffset - xpivot); - oy = (newheight / 2) + (patch->topoffset - ypivot); - width = (maxx - minx); - height = (maxy - miny); - - if ((unsigned)(width * height) > size) - { - UINT16 *src, *dest; - - size = (width * height); - rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); - - src = &rawdst[(miny * newwidth) + minx]; - dest = rawconv; - dy = height; - - while (dy--) - { - M_Memcpy(dest, src, width * sizeof(UINT16)); - dest += width; - src += newwidth; - } - - ox -= minx; - oy -= miny; - - Z_Free(rawdst); - } - else - { - rawconv = rawdst; - width = newwidth; - height = newheight; - } - - // make patch - rotated = R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - { - rotated->leftoffset = ox; - rotated->topoffset = oy; - } -#ifdef HWRENDER - if (rendermode == render_opengl) - { - hwpatch = R_CreateHardwarePatch(rotated); - } -#endif // HWRENDER - - //Z_ChangeTag(rotated, PU_PATCH_ROTATED); // important for memory clearing -#ifdef HWRENDER - if (rendermode == render_opengl) - Z_SetUser(hwpatch, (void **)(&rotsprite->patches[idx])); - else -#endif - Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); - - Z_Free(rawconv); - - rotated->leftoffset = ox; - rotated->topoffset = oy; -} -#endif +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 2005-2009 by Andrey "entryway" Budko. +// Copyright (C) 2018-2020 by Jaime "Lactozilla" Passos. +// Copyright (C) 2019-2020 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_patch.c +/// \brief Patch generation. + +#include "byteptr.h" +#include "dehacked.h" +#include "i_video.h" +#include "r_data.h" +#include "r_draw.h" +#include "r_patch.h" +#include "r_things.h" +#include "z_zone.h" +#include "w_wad.h" + +#ifdef HWRENDER +#include "hardware/hw_glob.h" +#endif + +static unsigned char imgbuf[1<<26]; + +// +// R_CheckIfPatch +// +// Returns true if the lump is a valid patch. +// +boolean R_CheckIfPatch(lumpnum_t lump) +{ + size_t size; + INT16 width, height; + patch_t *patch; + boolean result; + + size = W_LumpLength(lump); + + // minimum length of a valid Doom patch + if (size < 13) + return false; + + patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); + + width = patch->width; + height = patch->height; + + result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4)); + + if (result) + { + // The dimensions seem like they might be valid for a patch, so + // check the column directory for extra security. All columns + // must begin after the column directory, and none of them must + // point past the end of the patch. + INT16 x; + + for (x = 0; x < width; x++) + { + UINT32 ofs = LONG(patch->columnofs[x]); + + // Need one byte for an empty column (but there's patches that don't know that!) + if (ofs < (UINT32)width * 4 + 8 || ofs >= (UINT32)size) + { + result = false; + break; + } + } + } + + return result; +} + +// +// R_TextureToFlat +// +// Convert a texture to a flat. +// +void R_TextureToFlat(size_t tex, UINT8 *flat) +{ + texture_t *texture = textures[tex]; + + fixed_t col, ofs; + column_t *column; + UINT8 *desttop, *dest, *deststop; + UINT8 *source; + + // yea + R_CheckTextureCache(tex); + + desttop = flat; + deststop = desttop + (texture->width * texture->height); + + for (col = 0; col < texture->width; col++, desttop++) + { + // no post_t info + if (!texture->holes) + { + column = (column_t *)(R_GetColumn(tex, col)); + source = (UINT8 *)(column); + dest = desttop; + for (ofs = 0; dest < deststop && ofs < texture->height; ofs++) + { + if (source[ofs] != TRANSPARENTPIXEL) + *dest = source[ofs]; + dest += texture->width; + } + } + else + { + INT32 topdelta, prevdelta = -1; + column = (column_t *)((UINT8 *)R_GetColumn(tex, col) - 3); + while (column->topdelta != 0xff) + { + topdelta = column->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + + dest = desttop + (topdelta * texture->width); + source = (UINT8 *)column + 3; + for (ofs = 0; dest < deststop && ofs < column->length; ofs++) + { + if (source[ofs] != TRANSPARENTPIXEL) + *dest = source[ofs]; + dest += texture->width; + } + column = (column_t *)((UINT8 *)column + column->length + 4); + } + } + } +} + +// +// R_PatchToFlat +// +// Convert a patch to a flat. +// +void R_PatchToFlat(patch_t *patch, UINT8 *flat) +{ + fixed_t col, ofs; + column_t *column; + UINT8 *desttop, *dest, *deststop; + UINT8 *source; + + desttop = flat; + deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); + + for (col = 0; col < SHORT(patch->width); col++, desttop++) + { + INT32 topdelta, prevdelta = -1; + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[col])); + + while (column->topdelta != 0xff) + { + topdelta = column->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + + dest = desttop + (topdelta * SHORT(patch->width)); + source = (UINT8 *)(column) + 3; + for (ofs = 0; dest < deststop && ofs < column->length; ofs++) + { + *dest = source[ofs]; + dest += SHORT(patch->width); + } + column = (column_t *)((UINT8 *)column + column->length + 4); + } + } +} + +// +// R_PatchToMaskedFlat +// +// Convert a patch to a masked flat. +// Now, what is a "masked" flat anyway? +// It means the flat uses two bytes to store image data. +// The upper byte is used to store the transparent pixel, +// and the lower byte stores a palette index. +// +void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip) +{ + fixed_t col, ofs; + column_t *column; + UINT16 *desttop, *dest, *deststop; + UINT8 *source; + + desttop = raw; + deststop = desttop + (SHORT(patch->width) * SHORT(patch->height)); + + for (col = 0; col < SHORT(patch->width); col++, desttop++) + { + INT32 topdelta, prevdelta = -1; + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-col) : col])); + while (column->topdelta != 0xff) + { + topdelta = column->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + dest = desttop + (topdelta * SHORT(patch->width)); + source = (UINT8 *)(column) + 3; + for (ofs = 0; dest < deststop && ofs < column->length; ofs++) + { + *dest = source[ofs]; + dest += SHORT(patch->width); + } + column = (column_t *)((UINT8 *)column + column->length + 4); + } + } +} + +// +// R_FlatToPatch +// +// Convert a flat to a patch. +// +patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency) +{ + UINT32 x, y; + UINT8 *img; + UINT8 *imgptr = imgbuf; + UINT8 *colpointers, *startofspan; + size_t size = 0; + + if (!raw) + return NULL; + + // Write image size and offset + WRITEINT16(imgptr, width); + WRITEINT16(imgptr, height); + WRITEINT16(imgptr, leftoffset); + WRITEINT16(imgptr, topoffset); + + // Leave placeholder to column pointers + colpointers = imgptr; + imgptr += width*4; + + // Write columns + for (x = 0; x < width; x++) + { + int lastStartY = 0; + int spanSize = 0; + startofspan = NULL; + + // Write column pointer + WRITEINT32(colpointers, imgptr - imgbuf); + + // Write pixels + for (y = 0; y < height; y++) + { + UINT8 paletteIndex = raw[((y * width) + x)]; + boolean opaque = transparency ? (paletteIndex != TRANSPARENTPIXEL) : true; + + // End span if we have a transparent pixel + if (!opaque) + { + if (startofspan) + WRITEUINT8(imgptr, 0); + startofspan = NULL; + continue; + } + + // Start new column if we need to + if (!startofspan || spanSize == 255) + { + int writeY = y; + + // If we reached the span size limit, finish the previous span + if (startofspan) + WRITEUINT8(imgptr, 0); + + if (y > 254) + { + // Make sure we're aligned to 254 + if (lastStartY < 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + lastStartY = 254; + } + + // Write stopgap empty spans if needed + writeY = y - lastStartY; + + while (writeY > 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + writeY -= 254; + } + } + + startofspan = imgptr; + WRITEUINT8(imgptr, writeY); + imgptr += 2; + spanSize = 0; + + lastStartY = y; + } + + // Write the pixel + WRITEUINT8(imgptr, paletteIndex); + spanSize++; + startofspan[1] = spanSize; + } + + if (startofspan) + WRITEUINT8(imgptr, 0); + + WRITEUINT8(imgptr, 0xFF); + } + + size = imgptr-imgbuf; + img = Z_Malloc(size, PU_STATIC, NULL); + memcpy(img, imgbuf, size); + + Z_Free(raw); + + if (destsize != NULL) + *destsize = size; + return (patch_t *)img; +} + +// +// R_MaskedFlatToPatch +// +// Convert a masked flat to a patch. +// Explanation of "masked" flats in R_PatchToMaskedFlat. +// +patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize) +{ + UINT32 x, y; + UINT8 *img; + UINT8 *imgptr = imgbuf; + UINT8 *colpointers, *startofspan; + size_t size = 0; + + if (!raw) + return NULL; + + // Write image size and offset + WRITEINT16(imgptr, width); + WRITEINT16(imgptr, height); + WRITEINT16(imgptr, leftoffset); + WRITEINT16(imgptr, topoffset); + + // Leave placeholder to column pointers + colpointers = imgptr; + imgptr += width*4; + + // Write columns + for (x = 0; x < width; x++) + { + int lastStartY = 0; + int spanSize = 0; + startofspan = NULL; + + // Write column pointer + WRITEINT32(colpointers, imgptr - imgbuf); + + // Write pixels + for (y = 0; y < height; y++) + { + UINT16 pixel = raw[((y * width) + x)]; + UINT8 paletteIndex = (pixel & 0xFF); + UINT8 opaque = (pixel != 0xFF00); // If 1, we have a pixel + + // End span if we have a transparent pixel + if (!opaque) + { + if (startofspan) + WRITEUINT8(imgptr, 0); + startofspan = NULL; + continue; + } + + // Start new column if we need to + if (!startofspan || spanSize == 255) + { + int writeY = y; + + // If we reached the span size limit, finish the previous span + if (startofspan) + WRITEUINT8(imgptr, 0); + + if (y > 254) + { + // Make sure we're aligned to 254 + if (lastStartY < 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + lastStartY = 254; + } + + // Write stopgap empty spans if needed + writeY = y - lastStartY; + + while (writeY > 254) + { + WRITEUINT8(imgptr, 254); + WRITEUINT8(imgptr, 0); + imgptr += 2; + writeY -= 254; + } + } + + startofspan = imgptr; + WRITEUINT8(imgptr, writeY); + imgptr += 2; + spanSize = 0; + + lastStartY = y; + } + + // Write the pixel + WRITEUINT8(imgptr, paletteIndex); + spanSize++; + startofspan[1] = spanSize; + } + + if (startofspan) + WRITEUINT8(imgptr, 0); + + WRITEUINT8(imgptr, 0xFF); + } + + size = imgptr-imgbuf; + img = Z_Malloc(size, PU_STATIC, NULL); + memcpy(img, imgbuf, size); + + if (destsize != NULL) + *destsize = size; + return (patch_t *)img; +} + +// +// R_ParseSpriteInfoFrame +// +// Parse a SPRTINFO frame. +// +static void R_ParseSpriteInfoFrame(spriteinfo_t *info) +{ + char *sprinfoToken; + size_t sprinfoTokenLength; + char *frameChar = NULL; + UINT8 frameFrame = 0xFF; + INT16 frameXPivot = 0; + INT16 frameYPivot = 0; + rotaxis_t frameRotAxis = 0; + + // Sprite identifier + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite frame should be"); + } + sprinfoTokenLength = strlen(sprinfoToken); + if (sprinfoTokenLength != 1) + { + I_Error("Error parsing SPRTINFO lump: Invalid frame \"%s\"",sprinfoToken); + } + else + frameChar = sprinfoToken; + + frameFrame = R_Char2Frame(frameChar[0]); + Z_Free(sprinfoToken); + + // Left Curly Brace + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + I_Error("Error parsing SPRTINFO lump: Missing sprite info"); + else + { + if (strcmp(sprinfoToken,"{")==0) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info should be"); + } + while (strcmp(sprinfoToken,"}")!=0) + { + if (stricmp(sprinfoToken, "XPIVOT")==0) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + frameXPivot = atoi(sprinfoToken); + } + else if (stricmp(sprinfoToken, "YPIVOT")==0) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + frameYPivot = atoi(sprinfoToken); + } + else if (stricmp(sprinfoToken, "ROTAXIS")==0) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + if ((stricmp(sprinfoToken, "X")==0) || (stricmp(sprinfoToken, "XAXIS")==0) || (stricmp(sprinfoToken, "ROLL")==0)) + frameRotAxis = ROTAXIS_X; + else if ((stricmp(sprinfoToken, "Y")==0) || (stricmp(sprinfoToken, "YAXIS")==0) || (stricmp(sprinfoToken, "PITCH")==0)) + frameRotAxis = ROTAXIS_Y; + else if ((stricmp(sprinfoToken, "Z")==0) || (stricmp(sprinfoToken, "ZAXIS")==0) || (stricmp(sprinfoToken, "YAW")==0)) + frameRotAxis = ROTAXIS_Z; + } + Z_Free(sprinfoToken); + + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace should be"); + } + } + } + Z_Free(sprinfoToken); + } + + // set fields + info->pivot[frameFrame].x = frameXPivot; + info->pivot[frameFrame].y = frameYPivot; + info->pivot[frameFrame].rotaxis = frameRotAxis; +} + +// +// R_ParseSpriteInfo +// +// Parse a SPRTINFO lump. +// +static void R_ParseSpriteInfo(boolean spr2) +{ + spriteinfo_t *info; + char *sprinfoToken; + size_t sprinfoTokenLength; + char newSpriteName[5]; // no longer dynamically allocated + spritenum_t sprnum = NUMSPRITES; + //playersprite_t spr2num = NUMPLAYERSPRITES; + INT32 i; + INT32 skinnumbers[MAXSKINS]; // >variable 'skinnumbers' set but not used >compile error when commented out + INT32 foundskins = 0; + + // Sprite name + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite name should be"); + } + sprinfoTokenLength = strlen(sprinfoToken); + if (sprinfoTokenLength != 4) + { + I_Error("Error parsing SPRTINFO lump: Sprite name \"%s\" isn't 4 characters long",sprinfoToken); + } + else + { + memset(&newSpriteName, 0, 5); + M_Memcpy(newSpriteName, sprinfoToken, sprinfoTokenLength); + // ^^ we've confirmed that the token is == 4 characters so it will never overflow a 5 byte char buffer + strupr(newSpriteName); // Just do this now so we don't have to worry about it + } + Z_Free(sprinfoToken); + + if (!spr2) + { + for (i = 0; i <= NUMSPRITES; i++) + { + if (i == NUMSPRITES) + I_Error("Error parsing SPRTINFO lump: Unknown sprite name \"%s\"", newSpriteName); + if (!memcmp(newSpriteName,sprnames[i],4)) + { + sprnum = i; + break; + } + } + } + + // allocate a spriteinfo + info = Z_Calloc(sizeof(spriteinfo_t), PU_STATIC, NULL); + info->available = true; + + // Left Curly Brace + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where open curly brace for sprite \"%s\" should be",newSpriteName); + } + if (strcmp(sprinfoToken,"{")==0) + { + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where definition for sprite \"%s\" should be",newSpriteName); + } + while (strcmp(sprinfoToken,"}")!=0) + { + if (stricmp(sprinfoToken, "SKIN")==0) + { + INT32 skinnum; + char *skinName = NULL; + if (!spr2) + I_Error("Error parsing SPRTINFO lump: \"SKIN\" token found outside of a sprite2 definition"); + + Z_Free(sprinfoToken); + + // Skin name + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where skin frame should be"); + } + + // copy skin name yada yada + sprinfoTokenLength = strlen(sprinfoToken); + skinName = (char *)Z_Malloc((sprinfoTokenLength+1)*sizeof(char),PU_STATIC,NULL); + M_Memcpy(skinName,sprinfoToken,sprinfoTokenLength*sizeof(char)); + skinName[sprinfoTokenLength] = '\0'; + strlwr(skinName); + Z_Free(sprinfoToken); + + skinnum = R_AnySkinAvailable(skinName); + if (skinnum == -1) + I_Error("Error parsing SPRTINFO lump: Unknown skin \"%s\"", skinName); + + skinnumbers[foundskins] = skinnum; + foundskins++; + } + else if (stricmp(sprinfoToken, "FRAME")==0) + { + R_ParseSpriteInfoFrame(info); + Z_Free(sprinfoToken); + if (spr2) + { + if (!foundskins) + I_Error("Error parsing SPRTINFO lump: No skins specified in this sprite2 definition"); + for (i = 0; i < foundskins; i++) + { + size_t skinnum = skinnumbers[i]; + skin_t *skin; + if (allskins[skinnum].localskin) + skin = &localskins[allskins[skinnum].localnum]; + else + skin = &skins[allskins[skinnum].localnum]; + M_Memcpy(&skin->sprinfo, info, sizeof(spriteinfo_t)); + } + } + else + M_Memcpy(&spriteinfo[sprnum], info, sizeof(spriteinfo_t)); + } + else + { + I_Error("Error parsing SPRTINFO lump: Unknown keyword \"%s\" in sprite %s",sprinfoToken,newSpriteName); + } + + sprinfoToken = M_GetToken(NULL); + if (sprinfoToken == NULL) + { + I_Error("Error parsing SPRTINFO lump: Unexpected end of file where sprite info or right curly brace for sprite \"%s\" should be",newSpriteName); + } + } + } + else + { + I_Error("Error parsing SPRTINFO lump: Expected \"{\" for sprite \"%s\", got \"%s\"",newSpriteName,sprinfoToken); + } + Z_Free(sprinfoToken); + Z_Free(info); +} + +// +// R_ParseSPRTINFOLump +// +// Read a SPRTINFO lump. +// +void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum) +{ + char *sprinfoLump; + size_t sprinfoLumpLength; + char *sprinfoText; + char *sprinfoToken; + + // Since lumps AREN'T \0-terminated like I'd assumed they should be, I'll + // need to make a space of memory where I can ensure that it will terminate + // correctly. Start by loading the relevant data from the WAD. + sprinfoLump = (char *)W_CacheLumpNumPwad(wadNum, lumpNum, PU_STATIC); + // If that didn't exist, we have nothing to do here. + if (sprinfoLump == NULL) return; + // If we're still here, then it DOES exist; figure out how long it is, and allot memory accordingly. + sprinfoLumpLength = W_LumpLengthPwad(wadNum, lumpNum); + sprinfoText = (char *)Z_Malloc((sprinfoLumpLength+1)*sizeof(char),PU_STATIC,NULL); + // Now move the contents of the lump into this new location. + memmove(sprinfoText,sprinfoLump,sprinfoLumpLength); + // Make damn well sure the last character in our new memory location is \0. + sprinfoText[sprinfoLumpLength] = '\0'; + // Finally, free up the memory from the first data load, because we really + // don't need it. + Z_Free(sprinfoLump); + + sprinfoToken = M_GetToken(sprinfoText); + while (sprinfoToken != NULL) + { + CONS_Printf("Attempting to parse le SPRTINFO lump for ya..\n"); + if (!stricmp(sprinfoToken, "SPRITE")) + R_ParseSpriteInfo(false); + else if (!stricmp(sprinfoToken, "SPRITE2")) + R_ParseSpriteInfo(true); + else + I_Error("Error parsing SPRTINFO lump: Unknown keyword \"%s\"", sprinfoToken); + Z_Free(sprinfoToken); + sprinfoToken = M_GetToken(NULL); + } + Z_Free((void *)sprinfoText); +} + +// +// R_LoadSpriteInfoLumps +// +// Load and read every SPRTINFO lump from the specified file. +// +void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps) +{ + lumpinfo_t *lumpinfo = wadfiles[wadnum]->lumpinfo; + UINT16 i; + char *name; + + for (i = 0; i < numlumps; i++, lumpinfo++) + { + name = lumpinfo->name; + // Load SPRTINFO and SPR_ lumps as SpriteInfo + if (!memcmp(name, "SPRTINFO", 8) || !memcmp(name, "SPR_", 4)) + R_ParseSPRTINFOLump(wadnum, i); + } +} + +static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) +{ + fixed_t ofs; + column_t *column; + UINT8 *source; + + if (x >= 0 && x < SHORT(patch->width)) + { + INT32 topdelta, prevdelta = -1; + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[flip ? (patch->width-1-x) : x])); + while (column->topdelta != 0xff) + { + topdelta = column->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + source = (UINT8 *)(column) + 3; + for (ofs = 0; ofs < column->length; ofs++) + { + if ((topdelta + ofs) == y) + return source[ofs]; + } + column = (column_t *)((UINT8 *)column + column->length + 4); + } + } + + return 0xFF00; +} + +#ifdef ROTSPRITE +// +// R_GetRollAngle +// +// Angles precalculated in R_InitSprites. +// +fixed_t rollcosang[ROTANGLES]; +fixed_t rollsinang[ROTANGLES]; + +INT32 R_GetRollAngle(angle_t rollangle) +{ + INT32 ra = AngleFixed(rollangle)>>FRACBITS; +#if (ROTANGDIFF > 1) + ra += (ROTANGDIFF/2); +#endif + ra /= ROTANGDIFF; + ra %= ROTANGLES; + return ra; +} + +patch_t *Patch_GetRotatedSprite( + spriteframe_t *sprite, + size_t frame, size_t spriteangle, + boolean flip, boolean adjustfeet, + void *info, INT32 rotationangle) +{ + rotsprite_t *rotsprite; + spriteinfo_t *sprinfo = (spriteinfo_t *)info; + INT32 idx = rotationangle; + UINT8 type = (adjustfeet ? 1 : 0); + + if (rotationangle < 1 || rotationangle >= ROTANGLES) + return NULL; + + rotsprite = sprite->rotated[type][spriteangle]; + + if (rotsprite == NULL) + { + rotsprite = RotatedPatch_Create(ROTANGLES); + sprite->rotated[type][spriteangle] = rotsprite; + } + + if (flip) + idx += rotsprite->angles; + + if (rotsprite->patches[idx] == NULL) + { + patch_t *patch; + INT32 xpivot = 0, ypivot = 0; + lumpnum_t lump = sprite->lumppat[spriteangle]; + + if (lump == LUMPERROR) + return NULL; + + patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); + + if (sprinfo->available) + { + xpivot = sprinfo->pivot[frame].x; + ypivot = sprinfo->pivot[frame].y; + } + else + { + xpivot = patch->leftoffset; + ypivot = patch->height / 2; + } + + RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); + + //BP: we cannot use special tric in hardware mode because feet in ground caused by z-buffer + if (adjustfeet) + ((patch_t *)rotsprite->patches[idx])->topoffset += FEETADJUST>>FRACBITS; + + // free image data + Z_Free(patch); + } + + return rotsprite->patches[idx]; +} + +rotsprite_t *RotatedPatch_Create(INT32 numangles) +{ + rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); + rotsprite->angles = numangles; + rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); + return rotsprite; +} + +static void RotatedPatch_CalculateDimensions( + INT32 width, INT32 height, + fixed_t ca, fixed_t sa, + INT32 *newwidth, INT32 *newheight) +{ + fixed_t fixedwidth = (width * FRACUNIT); + fixed_t fixedheight = (height * FRACUNIT); + + fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); + fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); + + w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); + w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); + h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); + h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); + + *newwidth = max(width, max(w1, w2)); + *newheight = max(height, max(h1, h2)); +} + +#ifdef HWRENDER +static patch_t *R_CreateHardwarePatch(patch_t *patch) +{ + GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); + grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); + grPatch->rawpatch = patch; + HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); + return (patch_t *)grPatch; +} +#endif + +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) +{ + UINT32 i; + patch_t *rotated, *hwpatch; + UINT16 *rawdst, *rawconv; + size_t size; + INT32 bflip = (flip != 0x00); + + INT32 width = patch->width; + INT32 height = patch->height; + INT32 leftoffset = patch->leftoffset; + INT32 newwidth, newheight; + + fixed_t ca = rollcosang[angle]; + fixed_t sa = rollsinang[angle]; + fixed_t xcenter, ycenter; + INT32 idx = angle; + INT32 x, y; + INT32 sx, sy; + INT32 dx, dy; + INT32 ox, oy; + INT32 minx, miny, maxx, maxy; + + // Don't cache angle = 0 + if (angle < 1 || angle >= ROTANGLES) + return; + + if (flip) + { + idx += rotsprite->angles; + xpivot = width - xpivot; + leftoffset = width - leftoffset; + } + + if (rotsprite->patches[idx]) + return; + + // Find the dimensions of the rotated patch. + RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); + + xcenter = (xpivot * FRACUNIT); + ycenter = (ypivot * FRACUNIT); + + if (xpivot != width / 2 || ypivot != height / 2) + { + newwidth *= 2; + newheight *= 2; + } + + minx = newwidth; + miny = newheight; + maxx = 0; + maxy = 0; + + // Draw the rotated sprite to a temporary buffer. + size = (newwidth * newheight); + if (!size) + size = (width * height); + rawdst = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); + + for (i = 0; i < size; i++) + rawdst[i] = 0xFF00; + + for (dy = 0; dy < newheight; dy++) + { + for (dx = 0; dx < newwidth; dx++) + { + x = (dx - (newwidth / 2)) * FRACUNIT; + y = (dy - (newheight / 2)) * FRACUNIT; + sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; + sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; + + sx >>= FRACBITS; + sy >>= FRACBITS; + + if (sx >= 0 && sy >= 0 && sx < width && sy < height) + rawdst[(dy*newwidth)+dx] = GetPatchPixel(patch, sx, sy, bflip); + } + } + + ox = (newwidth / 2) + (leftoffset - xpivot); + oy = (newheight / 2) + (patch->topoffset - ypivot); + width = (maxx - minx); + height = (maxy - miny); + + if ((unsigned)(width * height) > size) + { + UINT16 *src, *dest; + + size = (width * height); + rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); + + src = &rawdst[(miny * newwidth) + minx]; + dest = rawconv; + dy = height; + + while (dy--) + { + M_Memcpy(dest, src, width * sizeof(UINT16)); + dest += width; + src += newwidth; + } + + ox -= minx; + oy -= miny; + + Z_Free(rawdst); + } + else + { + rawconv = rawdst; + width = newwidth; + height = newheight; + } + + // make patch + rotated = R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); + { + rotated->leftoffset = ox; + rotated->topoffset = oy; + } +#ifdef HWRENDER + if (rendermode == render_opengl) + { + hwpatch = R_CreateHardwarePatch(rotated); + } +#endif // HWRENDER + + //Z_ChangeTag(rotated, PU_PATCH_ROTATED); // important for memory clearing +#ifdef HWRENDER + if (rendermode == render_opengl) + Z_SetUser(hwpatch, (void **)(&rotsprite->patches[idx])); + else +#endif + Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); + + Z_Free(rawconv); + + rotated->leftoffset = ox; + rotated->topoffset = oy; +} +#endif diff --git a/src/r_segs.c b/src/r_segs.c index 53f12ecc6..0c4e1d763 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -755,7 +755,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->master->flags & ML_TFERLINE) { - size_t linenum = curline->linedef-backsector->lines[0]; + size_t linenum = min(curline->linedef-backsector->lines[0], pfloor->master->frontsector->linecount); newline = pfloor->master->frontsector->lines[0] + linenum; texnum = R_GetTextureNum(sides[newline->sidenum[0]].midtexture); } @@ -2653,8 +2653,22 @@ void R_StoreWallRange(INT32 start, INT32 stop) { ffloor[i].f_pos >>= 4; ffloor[i].f_pos_slope >>= 4; - ffloor[i].f_frac = (centeryfrac>>4) - FixedMul(ffloor[i].f_pos, rw_scale); - ffloor[i].f_step = ((centeryfrac>>4) - FixedMul(ffloor[i].f_pos_slope, ds_p->scale2) - ffloor[i].f_frac)/(range); + if (linedef->special == 41) // Horizon lines extend FOFs in contact with them too. + { + ffloor[i].f_step = 0; + ffloor[i].f_frac = (centeryfrac>>4); + topfrac++; // Prevent 1px HOM + } + else + { +#ifdef ESLOPE + ffloor[i].f_frac = (centeryfrac>>4) - FixedMul(ffloor[i].f_pos, rw_scale); + ffloor[i].f_step = ((centeryfrac>>4) - FixedMul(ffloor[i].f_pos_slope, ds_p->scale2) - ffloor[i].f_frac)/(range); +#else + ffloor[i].f_step = FixedMul(-rw_scalestep, ffloor[i].f_pos); + ffloor[i].f_frac = (centeryfrac>>4) - FixedMul(ffloor[i].f_pos, rw_scale); +#endif + } } } diff --git a/src/r_things.c b/src/r_things.c index 86588da82..d112c05f2 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -589,7 +589,8 @@ void R_DelSpriteDefs(UINT16 wadnum) // // GAME FUNCTIONS // -UINT32 visspritecount; +UINT32 visspritecount, numvisiblesprites; + static UINT32 clippedvissprites; static vissprite_t *visspritechunks[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {NULL}; @@ -642,9 +643,12 @@ void R_InitSprites(void) // it can be is do before loading config for skin cvar possible value R_InitSkins(); - for (i = 0; i < numwadfiles; i++) + for (i = 0; i < numwadfiles; i++) + { R_AddSkins((UINT16)i, false); - + R_LoadSpriteInfoLumps(i, wadfiles[i]->numlumps); + } + // // check if all sprites have frames // @@ -661,7 +665,7 @@ void R_InitSprites(void) // void R_ClearSprites(void) { - visspritecount = clippedvissprites = 0; + visspritecount = numvisiblesprites = clippedvissprites = 0; } // @@ -940,10 +944,10 @@ static void R_DrawVisSprite(vissprite_t *vis) { vis->scale = FixedMul(vis->scale, this_scale); vis->scalestep = FixedMul(vis->scalestep, this_scale); - vis->xiscale = FixedDiv(vis->xiscale,this_scale); + vis->xiscale = FixedDiv(vis->xiscale, this_scale); vis->isScaled = true; } - dc_texturemid = FixedDiv(dc_texturemid,this_scale); + dc_texturemid = FixedDiv(dc_texturemid, this_scale); } spryscale = vis->scale; @@ -1311,13 +1315,16 @@ static void R_ProjectSprite(mobj_t *thing) size_t rot; UINT8 flip; - /*boolean vflip = (!(thing->eflags & MFE_VERTICALFLIP) != !R_ThingVerticallyFlipped(thing)); + /*boolean vflip = (!(thing->eflags & MFE_VERTICALFLIP) != !R_ThingVerticallyFlipped(thing));*/ + boolean mirrored = thing->mirrored; - boolean hflip = (!R_ThingHorizontallyFlipped(thing) != !mirrored);*/ + boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); INT32 lindex; vissprite_t *vis; + + spritecut_e cut = SC_NONE; angle_t ang = 0; // gcc 4.6 and lower fix fixed_t iscale; @@ -1393,11 +1400,11 @@ static void R_ProjectSprite(mobj_t *thing) rot = thing->frame&FF_FRAMEMASK; //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if (thing->skin && thing->sprite == SPR_PLAY) + if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE - sprinfo = &spriteinfo[thing->sprite]; + sprinfo = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->sprinfo; #endif if (rot >= sprdef->numframes) @@ -1439,6 +1446,8 @@ static void R_ProjectSprite(mobj_t *thing) if (sprframe->rotate != SRF_SINGLE || papersprite) { ang = R_PointToAngle (interp.x, interp.y) - interp.angle; + if (mirrored) + ang = InvAngle(ang); if (papersprite) ang_scale = abs(FINESINE(ang>>ANGLETOFINESHIFT)); } @@ -1468,7 +1477,7 @@ static void R_ProjectSprite(mobj_t *thing) } I_Assert(lump < max_spritelumps); - + if (thing->localskin && ((skin_t *)thing->localskin)->flags & SF_HIRES) this_scale = FixedMul(this_scale, ((skin_t *)thing->localskin)->highresscale); else if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) @@ -1480,20 +1489,15 @@ static void R_ProjectSprite(mobj_t *thing) spr_topoffset = spritecachedinfo[lump].topoffset; #ifdef ROTSPRITE - - if (thing->player) - { - sliptiderollangle = FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), ((cv_sloperoll.value == 1) ? thing->player->sliproll*(thing->player->sliptidemem) : 0)); - } - else - sliptiderollangle = 0; - - if ((thing->rollangle)||(thing->sloperoll)||sliptiderollangle) + if ((thing->rollangle)||(thing->sloperoll)||(thing->player && thing->player->sliproll)) { if (thing->player) - rollsum = (thing->rollangle) + (thing->sloperoll) + sliptiderollangle; + { + sliptiderollangle = cv_sliptideroll.value ? thing->player->sliproll*(thing->player->sliptidemem) : 0; + rollsum = (thing->rollangle)+(thing->sloperoll)+FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), sliptiderollangle); + } else - rollsum = (thing->rollangle) + (thing->sloperoll); + rollsum = (thing->rollangle)+(thing->sloperoll); rollangle = R_GetRollAngle(rollsum); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); @@ -1515,6 +1519,7 @@ static void R_ProjectSprite(mobj_t *thing) // calculate edges of the shape spritexscale = interp.spritexscale; spriteyscale = interp.spriteyscale; + if (spritexscale < 1 || spriteyscale < 1) return; @@ -1533,6 +1538,8 @@ static void R_ProjectSprite(mobj_t *thing) spr_offset += interp.spritexoffset * flipoffset; spr_topoffset += interp.spriteyoffset * flipoffset; } + + flip = !flip != !hflip; if (flip) offset = spr_offset - spr_width; @@ -2193,6 +2200,14 @@ void R_SortVisSprites(void) bestscale = bestdispoffset = INT32_MAX; for (ds = unsorted.next; ds != &unsorted; ds = ds->next) { + // Remove this sprite if it was determined to not be visible + if (ds->cut & SC_NOTVISIBLE) + { + ds->next->prev = ds->prev; + ds->prev->next = ds->next; + continue; + } + if (ds->sortscale < bestscale) { bestscale = ds->sortscale; @@ -2206,12 +2221,15 @@ void R_SortVisSprites(void) best = ds; } } - best->next->prev = best->prev; - best->prev->next = best->next; - best->next = &vsprsortedhead; - best->prev = vsprsortedhead.prev; - vsprsortedhead.prev->next = best; - vsprsortedhead.prev = best; + if (best) + { + best->next->prev = best->prev; + best->prev->next = best->next; + best->next = &vsprsortedhead; + best->prev = vsprsortedhead.prev; + vsprsortedhead.prev->next = best; + vsprsortedhead.prev = best; + } } } @@ -2573,7 +2591,45 @@ static void R_DrawPrecipitationSprite(vissprite_t *spr) R_DrawPrecipitationVisSprite(spr); } -// R_ClipSprites +static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) +{ + INT16 sz = spr->sz; + INT16 szt = spr->szt; + + fixed_t texturemid, yscale, scalestep = spr->scalestep; + INT32 height; + + if (scalestep) + { + height = spr->patch->height; + yscale = spr->scale; + scalestep = FixedMul(scalestep, spr->spriteyscale); + + if (spr->thingscale != FRACUNIT) + texturemid = FixedDiv(spr->texturemid, max(spr->thingscale, 1)); + else + texturemid = spr->texturemid; + } + + for (INT32 x = x1; x <= x2; x++) + { + if (scalestep) + { + fixed_t top = centeryfrac - FixedMul(texturemid, yscale); + fixed_t bottom = top + (height * yscale); + szt = (INT16)(top >> FRACBITS); + sz = (INT16)(bottom >> FRACBITS); + yscale += scalestep; + } + + if (spr->cliptop[x] < spr->clipbot[x] && sz > spr->cliptop[x] && szt < spr->clipbot[x]) + return true; + } + + return false; +} + +// R_ClipVisSprite // Clips vissprites without drawing, so that portals can work. -Red void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) { @@ -2756,8 +2812,15 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) spr->clipbot[x] = (INT16)viewheight; if (spr->cliptop[x] == -2) - //Fab : 26-04-98: was -1, now clips against console bottom - spr->cliptop[x] = (INT16)con_clipviewtop; + spr->cliptop[x] = -1; + } + + // Check if it'll be visible + // Not done for floorsprites. + if (cv_spriteclip.value) + { + if (!R_CheckSpriteVisible(spr, x1, x2)) + spr->cut |= SC_NOTVISIBLE; } } @@ -2826,6 +2889,13 @@ void R_ClipSprites(void) for (; clippedvissprites < visspritecount; clippedvissprites++) { vissprite_t *spr = R_GetVisSprite(clippedvissprites); + + if (cv_spriteclip.value + && (spr->szt > vid.height || spr->sz < 0)) + { + spr->cut |= SC_NOTVISIBLE; + continue; + } if (spr->x2 < cx) { @@ -2844,6 +2914,9 @@ void R_ClipSprites(void) } R_ClipVisSprite(spr, spr->x1, spr->x2); + + if ((spr->cut & SC_NOTVISIBLE) == 0) + numvisiblesprites++; } } @@ -2923,6 +2996,7 @@ UINT8 skinstatscount[9][9] = { UINT8 skinsorted[MAXSKINS]; skin_t localskins[MAXSKINS]; skin_t allskins[MAXSKINS*2]; + // FIXTHIS: don't work because it must be inistilised before the config load //#define SKINVALUES #ifdef SKINVALUES @@ -3015,6 +3089,7 @@ void R_InitSkins(void) skin->spritedef.numframes = sprites[SPR_PLAY].numframes; skin->spritedef.spriteframes = sprites[SPR_PLAY].spriteframes; + skin->sprinfo = spriteinfo[SPR_PLAY]; ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, 0); // Set values for Sonic skin @@ -3539,6 +3614,7 @@ next_token: free(buf2); lump++; // if no sprite defined use spirte just after this one + INT32 sprnum; if (skin->sprite[0] == '\0') { const char *csprname = W_CheckNameForNumPwad(wadnum, lump); @@ -3549,6 +3625,9 @@ next_token: lastlump++; // allocate (or replace) sprite frames, and set spritedef R_AddSingleSpriteDef(csprname, &skin->spritedef, wadnum, lump, lastlump); + + // i feel like generally most skin authors just use PLAY here, so just assume PLAY + sprnum = SPR_PLAY; } else { @@ -3596,6 +3675,8 @@ next_token: R_AddSingleSpriteDef(sprname, &skin->spritedef, wadnum, lstart, lend); } + sprnum = numspritelumps - 1; + // I don't particularly care about skipping to the end of the used frames. // We could be using frames from ANYWHERE in the current WAD file, including // right before us, which is a terrible idea. diff --git a/src/r_things.h b/src/r_things.h index f20e34552..966ff3df1 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -79,6 +79,7 @@ typedef struct { char name[SKINNAMESIZE+1]; // INT16 descriptive name of the skin spritedef_t spritedef; + spriteinfo_t sprinfo; UINT16 wadnum; char sprite[4]; // Sprite name, if seperated from S_SKIN. skinflags_t flags; @@ -114,7 +115,10 @@ typedef enum SC_NONE = 0, SC_TOP = 1, SC_BOTTOM = 2, - SC_VFLIP = 3 + SC_VFLIP = 3, + SC_NOTVISIBLE = 4, + SC_CUTMASK = SC_TOP|SC_BOTTOM|SC_NOTVISIBLE, + SC_FLAGMASK = ~SC_CUTMASK } spritecut_e; // A vissprite_t is a thing that will be drawn during a refresh, @@ -175,7 +179,7 @@ typedef struct vissprite_s INT32 dispoffset; // copy of info->dispoffset, affects ordering but not drawing } vissprite_t; -extern UINT32 visspritecount; +extern UINT32 visspritecount, numvisiblesprites; void R_ClipSprites(void); void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2); diff --git a/src/s_sound.c b/src/s_sound.c index 30e40c7e0..ffe18d492 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -27,6 +27,8 @@ #include "r_sky.h" // skyflatnum #include "p_local.h" // camera info #include "m_misc.h" // for tunes command +#include "m_cond.h" // for conditionsets +#include "m_menu.h" // bird music stuff #ifdef HAVE_BLUA #include "lua_hook.h" // MusicChange hook @@ -96,6 +98,9 @@ consvar_t cv_gamesounds = {"sounds", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, consvar_t cv_playmusicifunfocused = {"playmusicifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_playsoundifunfocused = {"playsoundsifunfocused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pausemusic = {"playmusicifpaused", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +//bird music stuff static CV_PossibleValue_t music_resync_threshold_cons_t[] = { {0, "MIN"}, {1000, "MAX"}, @@ -106,6 +111,16 @@ consvar_t cv_music_resync_threshold = {"music_resync_threshold", "0", CV_SAVE|CV consvar_t cv_music_resync_powerups_only = {"music_resync_powerups_only", "No", CV_SAVE|CV_CALL, CV_YesNo, I_UpdateSongLagConditions, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_invincmusicfade = {"invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_growmusicfade = {"growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_respawnfademusicout = {"respawnfademusicout", "1000", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_respawnfademusicback = {"respawnfademusicback", "500", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_resetspecialmusic = {"resetspecialmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_resume = {"resume", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fading = {"fading", "Off", CV_SAVE|CV_CALL, CV_OnOff, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; + + #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -270,11 +285,25 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_gamemidimusic); #endif + //bird music stuff CV_RegisterVar(&cv_playmusicifunfocused); CV_RegisterVar(&cv_playsoundifunfocused); + CV_RegisterVar(&cv_pausemusic); CV_RegisterVar(&cv_music_resync_threshold); CV_RegisterVar(&cv_music_resync_powerups_only); + + CV_RegisterVar(&cv_invincmusicfade); + CV_RegisterVar(&cv_growmusicfade); + + CV_RegisterVar(&cv_respawnfademusicout); + CV_RegisterVar(&cv_respawnfademusicback); + + CV_RegisterVar(&cv_resetspecialmusic); + + CV_RegisterVar(&cv_resume); + CV_RegisterVar(&cv_fading); + CV_RegisterVar(&cv_birdmusic); COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); @@ -1294,6 +1323,19 @@ static UINT32 queue_fadeinms; musicdef_t *musicdefstart = NULL; // First music definition struct cursongcredit cursongcredit; // Currently displayed song credit info +musicdef_t soundtestsfx = { + "_STSFX", // prevents exactly one valid track name from being used on the sound test + "Sound Effects", + "", + "SEGA, Sonic Team Jr, other sources", + 1, // show on soundtest page 1 + 0, // with no conditions + 0, + 0, + false, + NULL +}; + // // search for music definition in wad // @@ -1400,6 +1442,8 @@ void S_LoadMusicDefs(UINT16 wadnum) //CONS_Printf("S_LoadMusicDefs: Added song '%s'\n", def->name); } } + + strncpy(def->filename, wadfiles[wadnum]->filename, 256); skip_lump: stoken = strtok(NULL, "\r\n "); @@ -1422,19 +1466,33 @@ skip_lump: free(buf2); return; } - + if (!stricmp(stoken, "usage")) { -#if 0 // Ignore for now STRBUFCPY(def->usage, value); for (value = def->usage; *value; value++) if (*value == '_') *value = ' '; // turn _ into spaces. //CONS_Printf("S_LoadMusicDefs: Set usage to '%s'\n", def->usage); -#endif } else if (!stricmp(stoken, "source")) { STRBUFCPY(def->source, value); for (value = def->source; *value; value++) if (*value == '_') *value = ' '; // turn _ into spaces. //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "title")) { + def->use_info = true; + STRBUFCPY(def->title, value); + for (value = def->title; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "alttitle")) { + STRBUFCPY(def->alttitle, value); + for (value = def->alttitle; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "authors")) { + STRBUFCPY(def->authors, value); + for (value = def->authors; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); } else { CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); } @@ -1461,7 +1519,168 @@ void S_InitMusicDefs(void) S_LoadMusicDefs(i); } +// +// search for music definition in wad +// +static UINT16 W_CheckForMusicInfoInPwad(UINT16 wadid) +{ + UINT16 i; + lumpinfo_t *lump_p; + lump_p = wadfiles[wadid]->lumpinfo; + for (i = 0; i < wadfiles[wadid]->numlumps; i++, lump_p++) + if (memcmp(lump_p->name, "MUSCINFO", 8) == 0) + return i; + + return INT16_MAX; // not found +} + +void S_LoadMTDefs(UINT16 wadnum) +{ + UINT16 lump; + char *buf; + char *buf2; + char *stoken; + char *value; + size_t size; + musicdef_t *def, *prev; + UINT16 line = 1; // for better error msgs + + lump = W_CheckForMusicInfoInPwad(wadnum); + if (lump == INT16_MAX) + return; + + buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); + size = W_LumpLengthPwad(wadnum, lump); + + // for strtok + buf2 = malloc(size+1); + if (!buf2) + I_Error("S_LoadMTDefs: No more free memory\n"); + M_Memcpy(buf2,buf,size); + buf2[size] = '\0'; + + def = prev = NULL; + + stoken = strtok (buf2, "\r\n "); + // Find music def + while (stoken) + { + /*if ((stoken[0] == '/' && stoken[1] == '/') + || (stoken[0] == '#')) // skip comments + { + stoken = strtok(NULL, "\r\n"); // skip end of line + if (def) + stoken = strtok(NULL, "\r\n= "); + else + stoken = strtok(NULL, "\r\n "); + line++; + } + else*/ if (!stricmp(stoken, "lump")) + { + value = strtok(NULL, "\r\n "); + + if (!value) + { + CONS_Alert(CONS_WARNING, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); + stoken = strtok(NULL, "\r\n"); // skip end of line + goto skip_lump; + } + + // No existing musicdefs + if (!musicdefstart) + { + musicdefstart = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); + STRBUFCPY(musicdefstart->name, value); + strlwr(musicdefstart->name); + def = musicdefstart; + //CONS_Printf("S_LoadMusicDefs: Initialized musicdef w/ song '%s'\n", def->name); + } + else + { + def = musicdefstart; + + // Search if this is a replacement + //CONS_Printf("S_LoadMusicDefs: Searching for song replacement...\n"); + while (def) + { + if (!stricmp(def->name, value)) + { + //CONS_Printf("S_LoadMusicDefs: Found song replacement '%s'\n", def->name); + break; + } + + prev = def; + def = def->next; + } + + // Nothing found, abort. + if (!def) + { + CONS_Alert(CONS_WARNING, "MUSCINFO: Music def for '%s' does not exist. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); + free(buf2); + return; + } + } + +skip_lump: + stoken = strtok(NULL, "\r\n "); + line++; + } + else + { + value = strtok(NULL, "\r\n= "); + + if (!value) + { + CONS_Alert(CONS_WARNING, "MUSCINFO: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); + stoken = strtok(NULL, "\r\n"); // skip end of line + goto skip_field; + } + + if (!def) + { + CONS_Alert(CONS_ERROR, "MUSCINFO: No music definition before field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); + free(buf2); + return; + } + + if (!stricmp(stoken, "title")) { + def->use_info = true; + STRBUFCPY(def->title, value); + for (value = def->title; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "alttitle")) { + STRBUFCPY(def->alttitle, value); + for (value = def->alttitle; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else if (!stricmp(stoken, "authors")) { + STRBUFCPY(def->authors, value); + for (value = def->authors; *value; value++) + if (*value == '_') *value = ' '; // turn _ into spaces. + //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + } else { + CONS_Alert(CONS_WARNING, "MUSCINFO: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); + } + +skip_field: + stoken = strtok(NULL, "\r\n= "); + line++; + } + } + + free(buf2); + return; +} + +void S_InitMTDefs(void) +{ + UINT16 i; + for (i = 0; i < numwadfiles; i++) + S_LoadMTDefs(i); +} // // S_FindMusicCredit // @@ -1522,6 +1741,42 @@ void S_ShowMusicCredit(void) S_ShowSpecifiedMusicCredit(music_name); } +musicdef_t **soundtestdefs = NULL; +INT32 numsoundtestdefs = 0; + +// +// S_PrepareSoundTest +// +// Prepare sound test. What am I, your butler? +// +boolean S_PrepareSoundTest(void) +{ + musicdef_t *def; + INT32 pos = numsoundtestdefs = 0; + + for (def = musicdefstart; def; def = def->next) + { + numsoundtestdefs++; + } + + if (!numsoundtestdefs) + return false; + + if (soundtestdefs) + Z_Free(soundtestdefs); + + if (!(soundtestdefs = Z_Malloc(numsoundtestdefs*sizeof(musicdef_t *), PU_STATIC, NULL))) + I_Error("S_PrepareSoundTest(): could not allocate soundtestdefs."); + + for (def = musicdefstart; def /*&& i < numsoundtestdefs*/; def = def->next) + { + soundtestdefs[pos++] = def; + } + + return true; +} + + /// ------------------------ /// Music Status /// ------------------------ @@ -1699,7 +1954,8 @@ static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) if (S_MusicDisabled()) return false; - I_UpdateSongLagConditions(); + if (cv_birdmusic.value) + I_UpdateSongLagConditions(); if ((!fadeinms && !I_PlaySong(looping)) || (fadeinms && !I_FadeInPlaySong(fadeinms, looping))) @@ -1823,7 +2079,7 @@ void S_StopMusic(void) || demo.title) // SRB2Kart: Demos don't interrupt title screen music return; - if (strcasecmp(music_name, mapmusname) == 0) + if ((cv_birdmusic.value) && (strcasecmp(music_name, mapmusname) == 0)) mapmusresume = I_GetSongPosition(); if (I_SongPaused()) diff --git a/src/s_sound.h b/src/s_sound.h index bc1a73563..5cfe937ea 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -42,6 +42,7 @@ extern consvar_t cv_gamemidimusic; extern consvar_t cv_gamesounds; extern consvar_t cv_playmusicifunfocused; extern consvar_t cv_playsoundifunfocused; +extern consvar_t cv_pausemusic; #ifdef HAVE_OPENMPT extern consvar_t cv_modfilter; @@ -52,9 +53,23 @@ extern consvar_t cv_amigatype; #endif #endif +//bird music stuff extern consvar_t cv_music_resync_threshold; extern consvar_t cv_music_resync_powerups_only; +extern consvar_t cv_invincmusicfade; +extern consvar_t cv_growmusicfade; + +extern consvar_t cv_respawnfademusicout; +extern consvar_t cv_respawnfademusicback; + +extern consvar_t cv_resetspecialmusic; + +extern consvar_t cv_resume; +extern consvar_t cv_fading; +extern consvar_t cv_birdmusic; + + extern CV_PossibleValue_t soundvolume_cons_t[]; typedef enum @@ -144,11 +159,25 @@ boolean S_SpeedMusic(float speed); typedef struct musicdef_s { char name[7]; - //char usage[256]; + char usage[256]; char source[256]; + char filename[256]; + // for the music test stuff + // generally if these are present on vanilla the game would throw up a warning + // a sacrifice i suppose + char title[256]; + char alttitle[256]; + char authors[256]; + boolean use_info; struct musicdef_s *next; } musicdef_t; +extern musicdef_t soundtestsfx; +extern musicdef_t *musicdefstart; +extern musicdef_t **soundtestdefs; +extern INT32 numsoundtestdefs; +extern UINT8 soundtestpage; + extern struct cursongcredit { musicdef_t *def; @@ -157,14 +186,17 @@ extern struct cursongcredit UINT8 trans; } cursongcredit; -extern musicdef_t *musicdefstart; void S_LoadMusicDefs(UINT16 wadnum); void S_InitMusicDefs(void); +void S_LoadMTDefs(UINT16 wadnum); +void S_InitMTDefs(void); musicdef_t *S_FindMusicCredit(const char *musname); void S_ShowSpecifiedMusicCredit(const char *musname); void S_ShowMusicCredit(void); +boolean S_PrepareSoundTest(void); + // // Music Seeking // diff --git a/src/screen.c b/src/screen.c index a7162c540..ee0c76e82 100644 --- a/src/screen.c +++ b/src/screen.c @@ -70,6 +70,8 @@ consvar_t cv_shittyscreen = {"televisionsignal", "Okay", CV_NOSHOWHELP, shittysc static void SCR_ChangeFullscreen (void); +static INT32 SCR_FPSflags(void); + consvar_t cv_fullscreen = {"fullscreen", "Yes", CV_SAVE|CV_CALL, CV_YesNo, SCR_ChangeFullscreen, 0, NULL, NULL, 0, 0, NULL}; // ========================================================================= @@ -411,6 +413,14 @@ void SCR_CalculateFPS(void) #endif } +// this is pretty dumb, but has to be done like this, otherwise the fps counter just disappears sometimes for no reason lol +static INT32 SCR_FPSflags(void) +{ + if (!cv_translucenthud.value) return V_SNAPTOBOTTOM|V_SNAPTORIGHT|V_HUDTRANS; // eee kinda works ig + + return (((10-cv_translucenthud.value)*V_10TRANS) & V_ALPHAMASK) | V_SNAPTOBOTTOM|V_SNAPTORIGHT; +} + void SCR_DisplayTicRate(void) { const UINT8 *ticcntcolor = NULL; @@ -418,10 +428,15 @@ void SCR_DisplayTicRate(void) UINT32 benchmark = (cap == 0) ? I_GetRefreshRate() : cap; INT32 x = 318; double fps = round(averageFPS); + INT32 fpsflags = SCR_FPSflags(); + + if (gamestate == GS_NULL) + return; // draw "FPS" - V_DrawFixedPatch(306< (benchmark - 5)) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); else if (fps < 20) @@ -439,15 +454,16 @@ void SCR_DisplayTicRate(void) } // draw total frame: - V_DrawPingNum(x, 190, V_SNAPTOBOTTOM|V_SNAPTORIGHT, cap, ticcntcolor); + V_DrawPingNum(x, 190, fpsflags, cap, ticcntcolor); + x -= digits * 4; - // draw "/" - V_DrawFixedPatch(x< servermaxping)) // only show 2 (warning) if our ping is at a bad level { INT32 dispy = cv_ticrate.value ? 160 : 181; - HU_drawPing(307, dispy, ping, V_SNAPTORIGHT | V_SNAPTOBOTTOM); + HU_drawPing(307, dispy, ping, fpsflags); } } diff --git a/src/screen.h b/src/screen.h index a4ddbfdb1..64c04dc15 100644 --- a/src/screen.h +++ b/src/screen.h @@ -39,13 +39,8 @@ // we try to re-allocate a minimum of buffers for stability of the memory, // so all the small-enough tables based on screen size, are allocated once // and for all at the maximum size. -#if defined (_WIN32_WCE) -#define MAXVIDWIDTH 320 -#define MAXVIDHEIGHT 200 -#else -#define MAXVIDWIDTH 2560 // don't set this too high because actually -#define MAXVIDHEIGHT 1440 // lots of tables are allocated with the MAX size. -#endif +#define MAXVIDWIDTH 3840 // don't set this too high because actually +#define MAXVIDHEIGHT 2160 // lots of tables are allocated with the MAX size. #define BASEVIDWIDTH 320 // NEVER CHANGE THIS! This is the original #define BASEVIDHEIGHT 200 // resolution of the graphics. diff --git a/src/sdl/MakeNIX.cfg b/src/sdl/MakeNIX.cfg index e1b1ceae3..81991793e 100644 --- a/src/sdl/MakeNIX.cfg +++ b/src/sdl/MakeNIX.cfg @@ -55,7 +55,7 @@ ifdef FREEBSD OPTS+=-DLINUX -DFREEBSD -I/usr/X11R6/include SDL_CONFIG?=sdl11-config LDFLAGS+=-L/usr/X11R6/lib - LIBS+=-lipx -lkvm + LIBS+=-lkvm -lexecinfo endif # diff --git a/src/sdl/Makefile.cfg b/src/sdl/Makefile.cfg index f733725af..72a94dca8 100644 --- a/src/sdl/Makefile.cfg +++ b/src/sdl/Makefile.cfg @@ -106,6 +106,15 @@ endif endif endif +ifndef NOLIBBACKTRACE + OPTS+=-DHAVE_LIBBACKTRACE +ifdef MINGW64 + CPPFLAGS+=-I../libs/libbacktrace/include + LDFLAGS+=-L../libs/libbacktrace/lib/x86_64 +endif + LIBS:=-lbacktrace $(LIBS) +endif + CFLAGS+=$(SDL_CFLAGS) LIBS:=$(SDL_LDFLAGS) $(LIBS) ifdef STATIC diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 4af37ee42..a64a11135 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -78,6 +78,7 @@ void *hwSym(const char *funcName,void *handle) funcPointer = &OglSdlSetPalette; GETFUNC(Init); + GETFUNC(SetupGLInfo); GETFUNC(Draw2DLine); GETFUNC(DrawPolygon); GETFUNC(SetBlend); @@ -99,6 +100,7 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(DoScreenWipe); GETFUNC(DrawIntermissionBG); GETFUNC(MakeScreenTexture); + GETFUNC(RenderVhsEffect); GETFUNC(MakeScreenFinalTexture); GETFUNC(DrawScreenFinalTexture); diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 49af2cf97..1d2e2395f 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -37,6 +37,12 @@ //#define SDLMAIN #endif +#ifdef HAVE_LIBBACKTRACE +#include + +struct backtrace_state *bt_state = NULL; +#endif + #ifdef SDLMAIN #include "SDL_main.h" #elif defined(FORCESDLMAIN) @@ -105,6 +111,19 @@ int main(int argc, char **argv) myargc = argc; myargv = argv; /// \todo pull out path to exe from this string +#ifdef HAVE_LIBBACKTRACE + bt_state = backtrace_create_state( + argv[0], +#ifdef HAVE_THREADS + 1, +#else + 0, +#endif + NULL, + NULL + ); +#endif + #ifdef HAVE_TTF #ifdef _WIN32 I_StartupTTF(FONTPOINTSIZE, SDL_INIT_VIDEO|SDL_INIT_AUDIO, SDL_SWSURFACE); diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 4b943c932..a3813767c 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -42,7 +42,16 @@ typedef UINT (WINAPI *p_timeEndPeriod) (UINT); typedef HANDLE (WINAPI *p_OpenFileMappingA) (DWORD, BOOL, LPCSTR); typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif + + +// A little more than the minimum sleep duration on Windows. +// May be incorrect for other platforms, but we don't currently have a way to +// query the scheduler granularity. SDL will do what's needed to make this as +// low as possible though. +#define MIN_SLEEP_DURATION_MS 2.1 + #include +#include #include #include #ifdef __GNUC__ @@ -90,7 +99,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif #include -#include +#include #endif #endif @@ -137,12 +146,6 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif -#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) -#include -#include -#define UNIXBACKTRACE -#endif - // Locations for searching the srb2.srb #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) #define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" @@ -197,6 +200,161 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif +#ifdef HAVE_LIBBACKTRACE +#include +// TODO - move this to some header file instead +extern struct backtrace_state *bt_state; + +static void printsignal(FILE *fp, INT32 num) +{ + switch (num) + { + case SIGILL: + fprintf(fp, "SIGILL - illegal instruction - invalid function image"); + break; + case SIGFPE: + fprintf(fp, "SIGFPE - mathematical exception"); + break; + case SIGSEGV: + fprintf(fp, "SIGSEGV - segment violation"); + break; + case SIGABRT: + fprintf(fp, "SIGABRT - abnormal termination triggered by abort call"); + break; + default: + fprintf(fp, "Signal number %d", num); + } +} + +typedef struct bt_out_buf_s { + boolean error; + char *pos; + size_t size; +} bt_out_buf_t; + +static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) +{ + (void)symval; + (void)symsize; + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!symname) + symname = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); + + if (n <= 0) + { + buf->size = 0; + return; + } + + buf->pos += n; + buf->size -= n; +} + +static int bt_simple_cb(void *data, uintptr_t pc) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); + + if (!buf->size) return 1; + + return 0; +} + +static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!filename) filename = "???"; + if (!function) function = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); + + if (n <= 0) return 1; + + buf->pos += n; + buf->size -= n; + + if (!buf->size) return 1; + + return 0; +} + +static void bt_error_cb(void *data, const char *msg, int errnum) +{ + (void)msg; // We don't need this + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + // No debug info + if (errnum == -1) + buf->error = true; +} + +static void write_backtrace(INT32 num) +{ + FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "srb2kart-crash-log.txt"), "a"); + + time_t rawtime; + struct tm *timeinfo; + + const size_t BUFSIZE = 8192; + char backtrace[BUFSIZE]; + + bt_out_buf_t buf; + buf.error = false; + buf.pos = backtrace; + buf.size = BUFSIZE; + + + if (!out) + { + fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); + out = stderr; + } + + // Get the current time as a string. + time(&rawtime); + timeinfo = localtime(&rawtime); + + fprintf(out, "------------------------\n\n"); + + fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); + + if (compdate && comptime && comprevision && compbranch) + fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); + + fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); + + fprintf(out, "Caused by: "); + printsignal(out, num); + + fprintf(out, "\nBacktrace:\n"); + + // Try to get full backtrace, it will print files and line numbers + backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); + + if (buf.error) + { + // Fall back to simple backtrace, only prints function names + backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); + } + + fputs(backtrace, out); + + if (out != stderr) + { + fclose(out); + fprintf(stderr, "Crash report created, find srb2kart-crash-log.txt in your SRB2Kart directory\n"); + } +} + +#endif + /** \brief The JoyReset function \param JoySet Joystick info to reset @@ -258,85 +416,6 @@ SDL_bool framebuffer = SDL_FALSE; UINT8 keyboard_started = false; -#ifdef UNIXBACKTRACE - -static void bt_write_file(int fd, const char *string) { - ssize_t written = 0; - ssize_t sourcelen = strlen(string); - - while (fd != -1 && (written != -1 && errno != EINTR) && written < sourcelen) - written = write(fd, string, sourcelen); -} - -static void bt_write_stderr(const char *string) { - bt_write_file(STDERR_FILENO, string); -} - -static void bt_write_all(int fd, const char *string) { - bt_write_file(fd, string); - bt_write_file(STDERR_FILENO, string); -} - -static void write_backtrace(INT32 signal) -{ - int fd = -1; - time_t rawtime; - struct tm timeinfo; - size_t bt_size; - - enum { BT_SIZE = 1024, STR_SIZE = 32 }; - void *funcptrs[BT_SIZE]; - char timestr[STR_SIZE]; - - const char *filename = va("%s" PATHSEP "%s", srb2home, "crash-log.txt"); - - fd = open(filename, O_CREAT|O_APPEND|O_RDWR, S_IRUSR|S_IWUSR); - - if (fd == -1) // File handle error - bt_write_stderr("\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); - - // Get the current time as a string. - time(&rawtime); - localtime_r(&rawtime, &timeinfo); - strftime(timestr, STR_SIZE, "%a, %d %b %Y %T %z", &timeinfo); - - bt_write_file(fd, "------------------------\n"); // Nice looking seperator - - bt_write_all(fd, "\n"); // Newline to look nice for both outputs. - bt_write_all(fd, "An error occurred within SRB2! Send this stack trace to someone who can help!\n"); - - if (fd != -1) // If the crash log exists, - bt_write_stderr("(Or find crash-log.txt in your SRB2 directory.)\n"); // tell the user where the crash log is. - - // Tell the log when we crashed. - bt_write_file(fd, "Time of crash: "); - bt_write_file(fd, timestr); - bt_write_file(fd, "\n"); - - // Give the crash log the cause and a nice 'Backtrace:' thing - // The signal is given to the user when the parent process sees we crashed. - bt_write_file(fd, "Cause: "); - bt_write_file(fd, strsignal(signal)); - bt_write_file(fd, "\n"); // Newline for the signal name - - bt_write_all(fd, "\nBacktrace:\n"); - - // Flood the output and log with the backtrace - bt_size = backtrace(funcptrs, BT_SIZE); - backtrace_symbols_fd(funcptrs, bt_size, fd); - backtrace_symbols_fd(funcptrs, bt_size, STDERR_FILENO); - - bt_write_file(fd, "\n"); // Write another newline to the log so it looks nice :) - - if (fd != -1) { - fsync(fd); // reaaaaally make sure we got that data written. - close(fd); - } -} - -#endif // UNIXBACKTRACE - - static void I_ReportSignal(int num, int coredumped) { //static char msg[] = "oh no! back to reality!\r\n"; @@ -395,9 +474,11 @@ static void I_ReportSignal(int num, int coredumped) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { D_QuitNetGame(); // Fix server freezes -#ifdef UNIXBACKTRACE + +#ifdef HAVE_LIBBACKTRACE write_backtrace(num); #endif + I_ReportSignal(num, 0); I_ShutdownSystem(); signal(num, SIG_DFL); //default signal action @@ -585,6 +666,7 @@ void I_GetConsoleEvents(void) return; ev.type = ev_console; + ev.data1 = 0; if (read(STDIN_FILENO, &key, 1) == -1 || !key) return; @@ -611,7 +693,7 @@ void I_GetConsoleEvents(void) } else return; } - else + else if (tty_con.cursor < sizeof (tty_con.buffer)) { // push regular character ev.data1 = tty_con.buffer[tty_con.cursor] = key; @@ -791,7 +873,8 @@ static void I_RegisterSignals (void) #ifdef NEWSIGNALHANDLER static void signal_handler_child(INT32 num) { -#ifdef UNIXBACKTRACE + +#ifdef HAVE_LIBBACKTRACE write_backtrace(num); #endif @@ -952,12 +1035,6 @@ INT32 I_GetKey (void) return rc; } -void -I_CursedWindowMovement (int xd, int yd) -{ - SDL_SetWindowPosition(window, window_x + xd, window_y + yd); -} - // // I_JoyScale // @@ -3146,6 +3223,52 @@ void I_Sleep(UINT32 ms) SDL_Delay(ms); } +void I_SleepDuration(precise_t duration) +{ +#if defined(__linux__) || defined(__FreeBSD__) + UINT64 precision = I_GetPrecisePrecision(); + struct timespec ts = { + .tv_sec = duration / precision, + .tv_nsec = duration * 1000000000 / precision % 1000000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); +#else + UINT64 precision = I_GetPrecisePrecision(); + INT32 sleepvalue = cv_sleep.value; + UINT64 delaygranularity; + precise_t cur; + precise_t dest; + + { + double gran = round(((double)(precision / 1000) * sleepvalue * MIN_SLEEP_DURATION_MS)); + delaygranularity = (UINT64)gran; + } + + cur = I_GetPreciseTime(); + dest = cur + duration; + + // the reason this is not dest > cur is because the precise counter may wrap + // two's complement arithmetic is our friend here, though! + // e.g. cur 0xFFFFFFFFFFFFFFFE = -2, dest 0x0000000000000001 = 1 + // 0x0000000000000001 - 0xFFFFFFFFFFFFFFFE = 3 + while ((INT64)(dest - cur) > 0) + { + // If our cv_sleep value exceeds the remaining sleep duration, use the + // hard sleep function. + if (sleepvalue > 0 && (dest - cur) > delaygranularity) + { + I_Sleep(sleepvalue); + } + + // Otherwise, this is a spinloop. + + cur = I_GetPreciseTime(); + } +#endif +} + #ifdef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) { @@ -3916,40 +4039,17 @@ static long get_entry(const char* name, const char* buf) size_t I_GetFreeMem(size_t *total) { #ifdef FREEBSD - struct vmmeter sum; - kvm_t *kd; - struct nlist namelist[] = - { -#define X_SUM 0 - {"_cnt"}, - {NULL} - }; - if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) - { - if (total) - *total = 0L; - return 0; - } - if (kvm_nlist(kd, namelist) != 0) - { - kvm_close (kd); - if (total) - *total = 0L; - return 0; - } - if (kvm_read(kd, namelist[X_SUM].n_value, &sum, - sizeof (sum)) != sizeof (sum)) - { - kvm_close(kd); - if (total) - *total = 0L; - return 0; - } - kvm_close(kd); + u_int v_free_count, v_page_size, v_page_count; + size_t size = sizeof(v_free_count); + sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, NULL, 0); + size = sizeof(v_page_size); + sysctlbyname("vm.stats.vm.v_page_size", &v_page_size, &size, NULL, 0); + size = sizeof(v_page_count); + sysctlbyname("vm.stats.vm.v_page_count", &v_page_count, &size, NULL, 0); if (total) - *total = sum.v_page_count * sum.v_page_size; - return sum.v_free_count * sum.v_page_size; + *total = v_page_count * v_page_size; + return v_free_count * v_page_size; #elif defined (SOLARIS) /* Just guess */ if (total) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8a5e37afb..5aa4b684c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -640,9 +640,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; - case SDL_WINDOWEVENT_MOVED: - window_x = evt.data1; - window_y = evt.data2; } if (mousefocus && kbfocus) @@ -1451,7 +1448,7 @@ void I_FinishUpdate(void) if (I_SkipFrame()) return; - if (cv_ticrate.value) + if (cv_ticrate.value && st_overlay) SCR_DisplayTicRate(); if (cv_showping.value && netgame && consoleplayer != serverplayer) @@ -1981,7 +1978,6 @@ void I_StartupGraphics(void) #ifdef HWRENDER else if (M_CheckParm("-opengl")) rendermode = render_opengl; -#endif msaa = 0; boolean msaa_set = false; a2c = false; boolean a2c_set = false; @@ -2011,7 +2007,6 @@ void I_StartupGraphics(void) FILE * file = OpenRendererFile("r"); if (file != NULL) { -#ifdef HWRENDER while (fgets(line, sizeof line, file) != NULL) { word = strtok(line, " \n"); @@ -2063,18 +2058,19 @@ void I_StartupGraphics(void) fclose(file); } -#endif - if (rendermode == render_none) - { -#ifdef HWRENDER - rendermode = render_opengl; - CONS_Printf("Defaulting to OpenGL renderer.\n"); -#else - rendermode = render_soft; - CONS_Printf("Using default software renderer.\n"); -#endif - } } +#endif + + if (rendermode == render_none) + { +#ifdef HWRENDER + rendermode = render_opengl; + CONS_Printf("Defaulting to OpenGL renderer.\n"); +#else + rendermode = render_soft; + CONS_Printf("Using default software renderer.\n"); +#endif + } { FILE * file = OpenRendererFile("w"); @@ -2089,10 +2085,12 @@ void I_StartupGraphics(void) fputs("opengl\n", file); } +#ifdef HWRENDER fprintf(file, "msaa %u\n", msaa); if (a2c) fputs("a2c\n", file); +#endif fclose(file); } @@ -2111,6 +2109,7 @@ void I_StartupGraphics(void) if (rendermode == render_opengl) { HWD.pfnInit = hwSym("Init",NULL); + HWD.pfnSetupGLInfo = hwSym("SetupGLInfo",NULL); HWD.pfnFinishUpdate = NULL; HWD.pfnDraw2DLine = hwSym("Draw2DLine",NULL); HWD.pfnDrawPolygon = hwSym("DrawPolygon",NULL); @@ -2134,6 +2133,7 @@ void I_StartupGraphics(void) HWD.pfnDoScreenWipe = hwSym("DoScreenWipe",NULL); HWD.pfnDrawIntermissionBG=hwSym("DrawIntermissionBG",NULL); HWD.pfnMakeScreenTexture= hwSym("MakeScreenTexture",NULL); + HWD.pfnRenderVhsEffect = hwSym("RenderVhsEffect",NULL); HWD.pfnMakeScreenFinalTexture=hwSym("MakeScreenFinalTexture",NULL); HWD.pfnDrawScreenFinalTexture=hwSym("DrawScreenFinalTexture",NULL); @@ -2150,7 +2150,7 @@ void I_StartupGraphics(void) HWD.pfnStartBatching = hwSym("StartBatching",NULL); HWD.pfnRenderBatches = hwSym("RenderBatches",NULL); - + HWD.pfnAddLightTable = hwSym("AddLightTable",NULL); HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 57072ee3c..b34ccb18a 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -624,7 +624,7 @@ static void count_music_bytes(int chan, void *stream, int len, void *udata) return; music_bytes += len; - if (gamestate == GS_LEVEL) + if ((gamestate == GS_LEVEL) && (cv_birdmusic.value)) Countstutter(len); } @@ -696,8 +696,8 @@ static void mix_gme(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif @@ -721,8 +721,8 @@ static void mix_openmpt(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif @@ -1375,7 +1375,7 @@ void I_SetMusicVolume(UINT8 volume) Mix_VolumeMusic(get_real_volume(music_volume)); } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { #ifdef HAVE_LIBGME diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 5c93642bd..2f8fa7b5d 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1476,7 +1476,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false; diff --git a/src/st_stuff.c b/src/st_stuff.c index 9bc182d17..17788d6a6 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -245,7 +245,7 @@ void ST_doPaletteStuff(void) palette = 0; #ifdef HWRENDER - if ((rendermode == render_opengl && !cv_grpaletteshader.value) || (rendermode == render_opengl && cv_grpaletteshader.value && !cv_grflashpal.value)) + if ((rendermode == render_opengl) && (!HWR_PalRenderFlashpal())) palette = 0; // No flashpals here in OpenGL #endif @@ -254,7 +254,7 @@ void ST_doPaletteStuff(void) st_palette = palette; #ifdef HWRENDER - if (rendermode == render_soft || (rendermode == render_opengl && cv_grpaletteshader.value && cv_grflashpal.value)) + if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) #else if (rendermode != render_none) #endif @@ -1971,8 +1971,8 @@ static void ST_overlayDrawer(void) strlcpy(name, player_names[stplyr-players], 13);*/ // Show name of player being displayed - V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-40, 0, M_GetText("VIEWPOINT:")); - V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-32, V_ALLOWLOWERCASE, player_names[stplyr-players]); + V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-40, V_HUDTRANS, M_GetText("VIEWPOINT:")); + V_DrawCenteredString((BASEVIDWIDTH/2), BASEVIDHEIGHT-32, V_HUDTRANS|V_ALLOWLOWERCASE, player_names[stplyr-players]); } } else if (!demo.title) @@ -2207,7 +2207,7 @@ void ST_Drawer(void) //25/08/99: Hurdler: palette changes is done for all players, // not only player1! That's why this part // of code is moved somewhere else. - if (rendermode == render_soft || (rendermode == render_opengl && cv_grpaletteshader.value && cv_grflashpal.value)) + if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) #endif if (rendermode != render_none) ST_doPaletteStuff(); diff --git a/src/stun.c b/src/stun.c index dbcfe58e8..1ff4dc960 100644 --- a/src/stun.c +++ b/src/stun.c @@ -11,7 +11,7 @@ /* https://tools.ietf.org/html/rfc5389 */ -#if defined (__linux__) +#if defined (__unix__) #include #elif defined (_WIN32) #define _CRT_RAND_S diff --git a/src/tmap.nas b/src/tmap.nas deleted file mode 100644 index 78840106f..000000000 --- a/src/tmap.nas +++ /dev/null @@ -1,957 +0,0 @@ -;; SONIC ROBO BLAST 2 -;;----------------------------------------------------------------------------- -;; Copyright (C) 1998-2000 by DooM Legacy Team. -;; Copyright (C) 1999-2018 by Sonic Team Junior. -;; -;; This program is free software distributed under the -;; terms of the GNU General Public License, version 2. -;; See the 'LICENSE' file for more details. -;;----------------------------------------------------------------------------- -;; FILE: -;; tmap.nas -;; DESCRIPTION: -;; Assembler optimised rendering code for software mode. -;; Draw wall columns. - - -[BITS 32] - -%define FRACBITS 16 -%define TRANSPARENTPIXEL 247 - -%ifdef LINUX -%macro cextern 1 -[extern %1] -%endmacro - -%macro cglobal 1 -[global %1] -%endmacro - -%else -%macro cextern 1 -%define %1 _%1 -[extern %1] -%endmacro - -%macro cglobal 1 -%define %1 _%1 -[global %1] -%endmacro - -%endif - - -; The viddef_s structure. We only need the width field. -struc viddef_s - resb 12 -.width: resb 4 - resb 44 -endstruc - -;; externs -;; columns -cextern dc_x -cextern dc_yl -cextern dc_yh -cextern ylookup -cextern columnofs -cextern dc_source -cextern dc_texturemid -cextern dc_texheight -cextern dc_iscale -cextern dc_hires -cextern centery -cextern centeryfrac -cextern dc_colormap -cextern dc_transmap -cextern colormaps -cextern vid -cextern topleft - -; DELME -cextern R_DrawColumn_8 - -; polygon edge rasterizer -cextern prastertab - -[SECTION .data] - -;;.align 4 -loopcount dd 0 -pixelcount dd 0 -tystep dd 0 - -[SECTION .text] - -;;---------------------------------------------------------------------- -;; -;; R_DrawColumn : 8bpp column drawer -;; -;; New optimised version 10-01-1998 by D.Fabrice and P.Boris -;; Revised by G. Dick July 2010 to support the intervening twelve years' -;; worth of changes to the renderer. Since I only vaguely know what I'm -;; doing, this is probably rather suboptimal. Help appreciated! -;; -;;---------------------------------------------------------------------- -;; fracstep, vid.width in memory -;; eax = accumulator -;; ebx = colormap -;; ecx = count -;; edx = heightmask -;; esi = source -;; edi = dest -;; ebp = frac -;;---------------------------------------------------------------------- - -cglobal R_DrawColumn_8_ASM -; align 16 -R_DrawColumn_8_ASM: - push ebp ;; preserve caller's stack frame pointer - push esi ;; preserve register variables - push edi - push ebx -;; -;; dest = ylookup[dc_yl] + columnofs[dc_x]; -;; - mov ebp,[dc_yl] - mov edi,[ylookup+ebp*4] - mov ebx,[dc_x] - add edi,[columnofs+ebx*4] ;; edi = dest -;; -;; pixelcount = yh - yl + 1 -;; - mov ecx,[dc_yh] - add ecx,1 - sub ecx,ebp ;; pixel count - jle near .done ;; nothing to scale -;; -;; fracstep = dc_iscale; // But we just use [dc_iscale] -;; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep)); -;; - mov eax,ebp ;; dc_yl - shl eax,FRACBITS - sub eax,[centeryfrac] - imul dword [dc_iscale] - shrd eax,edx,FRACBITS - add eax,[dc_texturemid] - mov ebp,eax ;; ebp = frac - - mov ebx,[dc_colormap] - - mov esi,[dc_source] -;; -;; if (dc_hires) frac = 0; -;; - test byte [dc_hires],0x01 - jz .texheightcheck - xor ebp,ebp - -;; -;; Check for power of two -;; -.texheightcheck: - mov edx,[dc_texheight] - sub edx,1 ;; edx = heightmask - test edx,[dc_texheight] - jnz .notpowertwo - - test ecx,0x01 ;; Test for odd no. pixels - jnz .odd - -;; -;; Texture height is a power of two, so we get modular arithmetic by -;; masking -;; -.powertwo: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part - and eax,edx ;; eax &= heightmask - movzx eax,byte [esi + eax] ;; eax = texel - add ebp,[dc_iscale] ;; frac += fracstep - movzx eax,byte [ebx+eax] ;; Map through colormap - mov [edi],al ;; Write pixel - ;; dest += vid.width - add edi,[vid + viddef_s.width] - -.odd: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part - and eax,edx ;; eax &= heightmask - movzx eax,byte [esi + eax] ;; eax = texel - add ebp,[dc_iscale] ;; frac += fracstep - movzx eax,byte [ebx+eax] ;; Map through colormap - mov [edi],al ;; Write pixel - ;; dest += vid.width - add edi,[vid + viddef_s.width] - - - sub ecx,2 ;; count -= 2 - jg .powertwo - - jmp .done - -.notpowertwo: - add edx,1 - shl edx,FRACBITS - test ebp,ebp - jns .notpowtwoloop - -.makefracpos: - add ebp,edx ;; frac is negative; make it positive - js .makefracpos - -.notpowtwoloop: - cmp ebp,edx ;; Reduce mod height - jl .writenonpowtwo - sub ebp,edx - jmp .notpowtwoloop - -.writenonpowtwo: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part. - mov bl,[esi + eax] ;; ebx = colormap + texel - add ebp,[dc_iscale] ;; frac += fracstep - movzx eax,byte [ebx] ;; Map through colormap - mov [edi],al ;; Write pixel - ;; dest += vid.width - add edi,[vid + viddef_s.width] - - sub ecx,1 - jnz .notpowtwoloop - -;; - -.done: - pop ebx ;; restore register variables - pop edi - pop esi - pop ebp ;; restore caller's stack frame pointer - ret - - -;;---------------------------------------------------------------------- -;; -;; R_Draw2sMultiPatchColumn : Like R_DrawColumn, but omits transparent -;; pixels. -;; -;; New optimised version 10-01-1998 by D.Fabrice and P.Boris -;; Revised by G. Dick July 2010 to support the intervening twelve years' -;; worth of changes to the renderer. Since I only vaguely know what I'm -;; doing, this is probably rather suboptimal. Help appreciated! -;; -;;---------------------------------------------------------------------- -;; fracstep, vid.width in memory -;; eax = accumulator -;; ebx = colormap -;; ecx = count -;; edx = heightmask -;; esi = source -;; edi = dest -;; ebp = frac -;;---------------------------------------------------------------------- - -cglobal R_Draw2sMultiPatchColumn_8_ASM -; align 16 -R_Draw2sMultiPatchColumn_8_ASM: - push ebp ;; preserve caller's stack frame pointer - push esi ;; preserve register variables - push edi - push ebx -;; -;; dest = ylookup[dc_yl] + columnofs[dc_x]; -;; - mov ebp,[dc_yl] - mov edi,[ylookup+ebp*4] - mov ebx,[dc_x] - add edi,[columnofs+ebx*4] ;; edi = dest -;; -;; pixelcount = yh - yl + 1 -;; - mov ecx,[dc_yh] - add ecx,1 - sub ecx,ebp ;; pixel count - jle near .done ;; nothing to scale -;; -;; fracstep = dc_iscale; // But we just use [dc_iscale] -;; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep)); -;; - mov eax,ebp ;; dc_yl - shl eax,FRACBITS - sub eax,[centeryfrac] - imul dword [dc_iscale] - shrd eax,edx,FRACBITS - add eax,[dc_texturemid] - mov ebp,eax ;; ebp = frac - - mov ebx,[dc_colormap] - - mov esi,[dc_source] -;; -;; if (dc_hires) frac = 0; -;; - test byte [dc_hires],0x01 - jz .texheightcheck - xor ebp,ebp - -;; -;; Check for power of two -;; -.texheightcheck: - mov edx,[dc_texheight] - sub edx,1 ;; edx = heightmask - test edx,[dc_texheight] - jnz .notpowertwo - - test ecx,0x01 ;; Test for odd no. pixels - jnz .odd - -;; -;; Texture height is a power of two, so we get modular arithmetic by -;; masking -;; -.powertwo: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part - and eax,edx ;; eax &= heightmask - movzx eax,byte [esi + eax] ;; eax = texel - add ebp,[dc_iscale] ;; frac += fracstep - cmp al,TRANSPARENTPIXEL ;; Is pixel transparent? - je .nextpowtwoeven ;; If so, advance. - movzx eax,byte [ebx+eax] ;; Map through colormap - mov [edi],al ;; Write pixel -.nextpowtwoeven: - ;; dest += vid.width - add edi,[vid + viddef_s.width] - -.odd: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part - and eax,edx ;; eax &= heightmask - movzx eax,byte [esi + eax] ;; eax = texel - add ebp,[dc_iscale] ;; frac += fracstep - cmp al,TRANSPARENTPIXEL ;; Is pixel transparent? - je .nextpowtwoodd ;; If so, advance. - movzx eax,byte [ebx+eax] ;; Map through colormap - mov [edi],al ;; Write pixel -.nextpowtwoodd: - ;; dest += vid.width - add edi,[vid + viddef_s.width] - - - sub ecx,2 ;; count -= 2 - jg .powertwo - - jmp .done - -.notpowertwo: - add edx,1 - shl edx,FRACBITS - test ebp,ebp - jns .notpowtwoloop - -.makefracpos: - add ebp,edx ;; frac is negative; make it positive - js .makefracpos - -.notpowtwoloop: - cmp ebp,edx ;; Reduce mod height - jl .writenonpowtwo - sub ebp,edx - jmp .notpowtwoloop - -.writenonpowtwo: - mov eax,ebp ;; eax = frac - sar eax,FRACBITS ;; Integer part. - mov bl,[esi + eax] ;; ebx = colormap + texel - add ebp,[dc_iscale] ;; frac += fracstep - cmp bl,TRANSPARENTPIXEL ;; Is pixel transparent? - je .nextnonpowtwo ;; If so, advance. - movzx eax,byte [ebx] ;; Map through colormap - mov [edi],al ;; Write pixel -.nextnonpowtwo: - ;; dest += vid.width - add edi,[vid + viddef_s.width] - - sub ecx,1 - jnz .notpowtwoloop - -;; - -.done: - pop ebx ;; restore register variables - pop edi - pop esi - pop ebp ;; restore caller's stack frame pointer - ret - -;;---------------------------------------------------------------------- -;; R_DrawTranslucentColumnA_8 -;; -;; Vertical column texture drawer, with transparency. Replaces Doom2's -;; 'fuzz' effect, which was not so beautiful. -;; Transparency is always impressive in some way, don't know why... -;;---------------------------------------------------------------------- - -cglobal R_DrawTranslucentColumn_8_ASM -R_DrawTranslucentColumn_8_ASM: - push ebp ;; preserve caller's stack frame pointer - push esi ;; preserve register variables - push edi - push ebx -;; -;; dest = ylookup[dc_yl] + columnofs[dc_x]; -;; - mov ebp,[dc_yl] - mov ebx,ebp - mov edi,[ylookup+ebx*4] - mov ebx,[dc_x] - add edi,[columnofs+ebx*4] ;; edi = dest -;; -;; pixelcount = yh - yl + 1 -;; - mov eax,[dc_yh] - inc eax - sub eax,ebp ;; pixel count - mov [pixelcount],eax ;; save for final pixel - jle near vtdone ;; nothing to scale -;; -;; frac = dc_texturemid - (centery-dc_yl)*fracstep; -;; - mov ecx,[dc_iscale] ;; fracstep - mov eax,[centery] - sub eax,ebp - imul eax,ecx - mov edx,[dc_texturemid] - sub edx,eax - mov ebx,edx - - shr ebx,16 ;; frac int. - and ebx,0x7f - shl edx,16 ;; y frac up - - mov ebp,ecx - shl ebp,16 ;; fracstep f. up - shr ecx,16 ;; fracstep i. ->cl - and cl,0x7f - push cx - mov ecx,edx - pop cx - mov edx,[dc_colormap] - mov esi,[dc_source] -;; -;; lets rock :) ! -;; - mov eax,[pixelcount] - shr eax,0x2 - test byte [pixelcount],0x3 - mov ch,al ;; quad count - mov eax,[dc_transmap] - je vt4quadloop -;; -;; do un-even pixel -;; - test byte [pixelcount],0x1 - je trf2 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add ecx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov dl,[edx] - mov [edi],dl -pf: add edi,0x12345678 -;; -;; do two non-quad-aligned pixels -;; -trf2: test byte [pixelcount],0x2 - je trf3 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add ecx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov dl,[edx] - mov [edi],dl -pg: add edi,0x12345678 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add ecx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov dl,[edx] - mov [edi],dl -ph: add edi,0x12345678 -;; -;; test if there was at least 4 pixels -;; -trf3: test ch,0xff ;; test quad count - je near vtdone - -;; -;; ebp : ystep frac. upper 24 bits -;; edx : y frac. upper 24 bits -;; ebx : y i. lower 7 bits, masked for index -;; ecx : ch = counter, cl = y step i. -;; eax : colormap aligned 256 -;; esi : source texture column -;; edi : dest screen -;; -vt4quadloop: - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [tystep],ebp -pi: add edi,0x12345678 - mov al,[edi] ;; fetch dest : index into colormap -pj: sub edi,0x12345678 - mov ebp,edi -pk: sub edi,0x12345678 - jmp short inloop -align 4 -vtquadloop: - add ecx,[tystep] - adc bl,cl -q1: add ebp,0x23456789 - and bl,0x7f - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov dl,[edx] - mov [edi],dl - mov al,[ebp] ;; fetch dest : index into colormap -inloop: - add ecx,[tystep] - adc bl,cl -q2: add edi,0x23456789 - and bl,0x7f - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov dl,[edx] - mov [ebp+0x0],dl - mov al,[edi] ;; fetch dest : index into colormap - - add ecx,[tystep] - adc bl,cl -q3: add ebp,0x23456789 - and bl,0x7f - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov dl,[edx] - mov [edi],dl - mov al,[ebp] ;; fetch dest : index into colormap - - add ecx,[tystep] - adc bl,cl -q4: add edi,0x23456789 - and bl,0x7f - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov dl,[edx] - mov [ebp],dl - mov al,[edi] ;; fetch dest : index into colormap - - dec ch - jne vtquadloop -vtdone: - pop ebx - pop edi - pop esi - pop ebp - ret - -;;---------------------------------------------------------------------- -;; R_DrawShadeColumn -;; -;; for smoke..etc.. test. -;;---------------------------------------------------------------------- -cglobal R_DrawShadeColumn_8_ASM -R_DrawShadeColumn_8_ASM: - push ebp ;; preserve caller's stack frame pointer - push esi ;; preserve register variables - push edi - push ebx - -;; -;; dest = ylookup[dc_yl] + columnofs[dc_x]; -;; - mov ebp,[dc_yl] - mov ebx,ebp - mov edi,[ylookup+ebx*4] - mov ebx,[dc_x] - add edi,[columnofs+ebx*4] ;; edi = dest -;; -;; pixelcount = yh - yl + 1 -;; - mov eax,[dc_yh] - inc eax - sub eax,ebp ;; pixel count - mov [pixelcount],eax ;; save for final pixel - jle near shdone ;; nothing to scale -;; -;; frac = dc_texturemid - (centery-dc_yl)*fracstep; -;; - mov ecx,[dc_iscale] ;; fracstep - mov eax,[centery] - sub eax,ebp - imul eax,ecx - mov edx,[dc_texturemid] - sub edx,eax - mov ebx,edx - shr ebx,16 ;; frac int. - and ebx,byte +0x7f - shl edx,16 ;; y frac up - - mov ebp,ecx - shl ebp,16 ;; fracstep f. up - shr ecx,16 ;; fracstep i. ->cl - and cl,0x7f - - mov esi,[dc_source] -;; -;; lets rock :) ! -;; - mov eax,[pixelcount] - mov dh,al - shr eax,2 - mov ch,al ;; quad count - mov eax,[colormaps] - test dh,3 - je sh4quadloop -;; -;; do un-even pixel -;; - test dh,0x1 - je shf2 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add edx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov [edi],dl -pl: add edi,0x12345678 -;; -;; do two non-quad-aligned pixels -;; -shf2: - test dh,0x2 - je shf3 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add edx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov [edi],dl -pm: add edi,0x12345678 - - mov ah,[esi+ebx] ;; fetch texel : colormap number - add edx,ebp - adc bl,cl - mov al,[edi] ;; fetch dest : index into colormap - and bl,0x7f - mov dl,[eax] - mov [edi],dl -pn: add edi,0x12345678 -;; -;; test if there was at least 4 pixels -;; -shf3: - test ch,0xff ;; test quad count - je near shdone - -;; -;; ebp : ystep frac. upper 24 bits -;; edx : y frac. upper 24 bits -;; ebx : y i. lower 7 bits, masked for index -;; ecx : ch = counter, cl = y step i. -;; eax : colormap aligned 256 -;; esi : source texture column -;; edi : dest screen -;; -sh4quadloop: - mov dh,0x7f ;; prep mask - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [tystep],ebp -po: add edi,0x12345678 - mov al,[edi] ;; fetch dest : index into colormap -pp: sub edi,0x12345678 - mov ebp,edi -pq: sub edi,0x12345678 - jmp short shinloop - -align 4 -shquadloop: - add edx,[tystep] - adc bl,cl - and bl,dh -q5: add ebp,0x12345678 - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [edi],dl - mov al,[ebp] ;; fetch dest : index into colormap -shinloop: - add edx,[tystep] - adc bl,cl - and bl,dh -q6: add edi,0x12345678 - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [ebp],dl - mov al,[edi] ;; fetch dest : index into colormap - - add edx,[tystep] - adc bl,cl - and bl,dh -q7: add ebp,0x12345678 - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [edi],dl - mov al,[ebp] ;; fetch dest : index into colormap - - add edx,[tystep] - adc bl,cl - and bl,dh -q8: add edi,0x12345678 - mov dl,[eax] - mov ah,[esi+ebx] ;; fetch texel : colormap number - mov [ebp],dl - mov al,[edi] ;; fetch dest : index into colormap - - dec ch - jne shquadloop - -shdone: - pop ebx ;; restore register variables - pop edi - pop esi - pop ebp ;; restore caller's stack frame pointer - ret - - -;; ======================================================================== -;; Rasterization of the segments of a LINEAR polygne textur of manire. -;; It is thus a question of interpolating coordinate them at the edges of texture in -;; the time that the X-coordinates minx/maxx for each line. -;; the argument ' dir' indicates which edges of texture are Interpol?: -;; 0: segments associs at edge TOP? and BOTTOM? (constant TY) -;; 1: segments associs at the LEFT and RIGHT edge (constant TX) -;; ======================================================================== -;; -;; void rasterize_segment_tex( LONG x1, LONG y1, LONG x2, LONG y2, LONG tv1, LONG tv2, LONG tc, LONG dir ); -;; ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 ARG7 ARG8 -;; -;; Pour dir = 0, (tv1,tv2) = (tX1,tX2), tc = tY, en effet TY est constant. -;; -;; Pour dir = 1, (tv1,tv2) = (tY1,tY2), tc = tX, en effet TX est constant. -;; -;; -;; Uses: extern struct rastery *_rastertab; -;; - -MINX EQU 0 -MAXX EQU 4 -TX1 EQU 8 -TY1 EQU 12 -TX2 EQU 16 -TY2 EQU 20 -RASTERY_SIZEOF EQU 24 - -cglobal rasterize_segment_tex -rasterize_segment_tex: - push ebp - mov ebp,esp - - sub esp,byte +0x8 ;; allocate the local variables - - push ebx - push esi - push edi - o16 mov ax,es - push eax - -;; #define DX [ebp-4] -;; #define TD [ebp-8] - - mov eax,[ebp+0xc] ;; y1 - mov ebx,[ebp+0x14] ;; y2 - cmp ebx,eax - je near .L_finished ;; special (y1==y2) segment horizontal, exit! - - jg near .L_rasterize_right - -;;rasterize_left: ;; one rasterize a segment LEFT of the polygne - - mov ecx,eax - sub ecx,ebx - inc ecx ;; y1-y2+1 - - mov eax,RASTERY_SIZEOF - mul ebx ;; * y2 - mov esi,[prastertab] - add esi,eax ;; point into rastertab[y2] - - mov eax,[ebp+0x8] ;; ARG1 - sub eax,[ebp+0x10] ;; ARG3 - shl eax,0x10 ;; ((x1-x2)< vid.height) downbary = -barsize; +#ifdef HWRENDER + if ((rendermode == render_opengl) && (cv_grvhseffect.value)) + { + HWR_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); + return; + } +#endif + for (y = 0; y < vid.height; y+=2) { thismapstart = normalmapstart; diff --git a/src/w_wad.c b/src/w_wad.c index 0914ec963..6739d7824 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -36,11 +36,7 @@ #define ZWAD #ifdef ZWAD -#ifdef _WIN32_WCE -#define AVOID_ERRNO -#else #include -#endif #include "lzf.h" #endif @@ -70,6 +66,7 @@ #include "p_setup.h" // P_ScanThings #endif #include "m_misc.h" // M_MapNumber +#include "p_setup.h" // P_PartialAddFile mayb #ifdef HWRENDER #include "r_data.h" @@ -145,7 +142,7 @@ static char filenamebuf[MAX_WADPATH]; // This #if is copied from filesrch.c, so not sure if it is 100% suitable for // this -#if defined (_WIN32) && !defined (_XBOX) +#if defined (_WIN32) //#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include @@ -202,7 +199,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors) // If findfile finds the file, the full path will be returned // in filenamebuf == *filename. - if (findfile(filenamebuf, NULL, true)) + if (findfile(filenamebuf, NULL, true) == FS_FOUND) { if ((handle = fopen_utf8(*filename, "rb")) == NULL) { @@ -943,6 +940,28 @@ INT32 W_InitMultipleFiles(char **filenames, boolean addons) return overallrc; } +INT32 W_AddAutoloadedLocalFiles(char **filenames) +{ + UINT16 rc = 1; + INT32 overallrc = 1; + + // will be realloced as lumps are added + for (; *filenames; filenames++) + { + rc = P_PartialAddWadFile(*filenames, true); + if (rc == UINT16_MAX) + CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), *filenames); + overallrc &= (rc != UINT16_MAX) ? 1 : 0; + } + + if (!numwadfiles) + I_Error("W_AddAutoloadedLocalFiles: no files found"); + + if (P_PartialAddGetStage() >= 0) + P_MultiSetupWadFiles(true); + return overallrc; +} + /** Make sure a lump number is valid. * Compiles away to nothing if PARANOIA is not defined. */ @@ -2137,6 +2156,10 @@ int W_VerifyNMUSlumps(const char *filename) {"MKFNT", 5}, // Kart font changes {"K_", 2}, // Kart graphic changes {"MUSICDEF", 8}, // Kart song definitions + {"SP_", 3}, // Speedometer changes do not count either. + {"SC_", 3}, // Colored speedometer stuff too. + {"SPRTINFO", 8}, // Sprite info + {"MUSCINFO", 8}, // Music test definitions #ifdef HWRENDER {"SHADERS", 7}, diff --git a/src/w_wad.h b/src/w_wad.h index 52e726d80..4b083ece6 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -145,6 +145,9 @@ void W_UnloadWadFile(UINT16 num); // so that it stops with a message if a file was not found, but not if all is okay. INT32 W_InitMultipleFiles(char **filenames, boolean addons); +// Used for autoload. Uses P_AddWadFileLocal instead of W_InitFiles. +INT32 W_AddAutoloadedLocalFiles(char **filenames); + #define W_FileHasFolders(wadfile) ((wadfile)->type == RET_PK3) const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump); diff --git a/src/win32/Makefile.cfg b/src/win32/Makefile.cfg index c31b07dcf..b713ff47b 100644 --- a/src/win32/Makefile.cfg +++ b/src/win32/Makefile.cfg @@ -62,18 +62,14 @@ else endif endif -ifdef MINGW64 - CPPFLAGS+=-I../libs/drmingw/include - LDFLAGS+=-L../libs/drmingw/lib/win64 - LIBS+=-lmgwhelp -lexchndl -else +ifndef MINGW64 CPPFLAGS+=-I../libs/drmingw/include LDFLAGS+=-L../libs/drmingw/lib/win32 LIBS+=-lmgwhelp -lexchndl endif # name of the exefile - EXENAME?=srb2kart.exe + EXENAME?=srb2kart-saturn.exe i_system_o+=$(OBJDIR)/SRB2.res #i_main_o+=$(OBJDIR)/win_dbg.o @@ -152,6 +148,10 @@ ifndef MINGW64 LDFLAGS+=-Wl,--large-address-aware endif +ifndef MINGW64 + NOLIBBACKTRACE=1 +endif + # disable dynamicbase if under msys2 ifdef MSYSTEM LDFLAGS+=-Wl,--disable-dynamicbase diff --git a/src/win32/srb2kart.exe.manifest b/src/win32/srb2kart.exe.manifest index f9ba6c814..c9ad725e5 100644 --- a/src/win32/srb2kart.exe.manifest +++ b/src/win32/srb2kart.exe.manifest @@ -22,7 +22,9 @@ - + + + diff --git a/src/y_inter.c b/src/y_inter.c index e23669951..ba5f89785 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -541,11 +541,20 @@ void Y_IntermissionDrawer(void) // i fucking hate this i fucking hate this i hate this so much if (!players[data.match.num[i]].skinlocal) { if (!players[data.match.num[i]].localskin) - V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[*data.match.character[i]], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x+16, y-4, 0, facewantprefix[*data.match.character[i]], colormap); + else + V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[*data.match.character[i]], colormap); else - V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[players[data.match.num[i]].localskin - 1], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x+16, y-4, 0, facewantprefix[players[data.match.num[i]].localskin - 1], colormap); + else + V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[players[data.match.num[i]].localskin - 1], colormap); } else { - V_DrawMappedPatch(x+16, y-4, 0, localfacerankprefix[players[data.match.num[i]].localskin - 1], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x+16, y-4, 0, localfacewantprefix[players[data.match.num[i]].localskin - 1], colormap); + else + V_DrawMappedPatch(x+16, y-4, 0, localfacerankprefix[players[data.match.num[i]].localskin - 1], colormap); } } @@ -1320,7 +1329,10 @@ void Y_VoteDrawer(void) if (players[i].skincolor) { UINT8 *colormap = R_GetTranslationColormap(players[i].skin, players[i].skincolor, GTC_CACHE); - V_DrawMappedPatch(x+24, y+9, V_SNAPTOLEFT, (players[i].skinlocal ? localfacerankprefix : facerankprefix)[((players[i].localskin) ? players[i].localskin-1 : players[i].skin)], colormap); + if (cv_highresportrait.value) + V_DrawSmallMappedPatch(x+24, y+9, V_SNAPTOLEFT, (players[i].skinlocal ? localfacewantprefix : facewantprefix)[((players[i].localskin) ? players[i].localskin-1 : players[i].skin)], colormap); + else + V_DrawMappedPatch(x+24, y+9, V_SNAPTOLEFT, (players[i].skinlocal ? localfacerankprefix : facerankprefix)[((players[i].localskin) ? players[i].localskin-1 : players[i].skin)], colormap); } if (!splitscreen && i == consoleplayer)