diff --git a/README.md b/README.md index 9bf915be8..d5a3d2b41 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ - Sprites player rotation on slopes; going on hills, levitate, going down, and so on alters your sprites (configurable) - You can alter all the base kart HUD element offsets on the fly in the Saturn Options settings menu - `addfilelocal` Command, for those who want to use things like their custom hud in netgames (Same as addfile but completely client sided) +- Palette rendering, make the OpenGL renderer (almost) look like software mode! - OpenMPT for Tracker module playback instead of GME - Fixes looping and sounds better - Allows filter configuration +- Colourize your Kart HUD, to either your player color or whichever colour you like! (optional / requieres extra2.kart file) - The minimal brightness with Shaders can be configured, now you can seeeee in dark areas (0-255 , uses Sector brightness values) - Lua HUD hooks for Intermission (ex: You can make hostmod votes still visible during intermission!) - Lua HUD hooks for Vote Screen (ex: You can make hostmod votes still visible during map vote screen!) @@ -17,9 +19,12 @@ - Smaller Speedometer (optional / requieres extra.kart file) - Record Attack input display can now be used everywhere - Smaller minimap icons and also show player names on the minimap (toggable) +- Support for animated votescreens! - `showmusiccredit` command, shows you the current music track again - `listskins` show a list of all skins currently loaded - Visual Portals from Haya's HEP Client +- Horizonline effect in OpenGL (watch the endless bricks on SNES Bowsers Castle!) +- Localskins! use whatever skin you like! - Toggable lowercase menu's also from Haya's HEP client - Everything that Galaxy has @@ -39,6 +44,9 @@ - Toggable Lap animation - Main menu shows the current renderer being used - MSAA and A2C Antialiasing support (Configurable in renderer.txt file) +- A simple button to rejoin your last visited server +- Ability to show ALL maps in the mapselect screen, this includes hidden or hellmaps "showallmaps yes/no" +- Ability to toggle the Stagetitlecard "maptitles on/off" ## Performance / Debugging @@ -57,6 +65,15 @@ - The annoying depraction messages for `P_TeleportMove` and `P_AproxDistance` have been silenced - Silenced the annoying "cant find next map..." messages as theyre super useless and annoying anyways - Added a small cooldown on `map` command due to spamming causing a SIGSEGV +- Many bugfixes to the Software renderer, so its much less prone to crashing +- Many bugfixes to the OpenGL renderer (too many too list all of them here; check the changelogs for more information) +- Bugfixes to the soundsystem, mainly regarding Sound muting +- 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 @@ -67,12 +84,16 @@ - A2C antialiasing makes transparent surfaces even more transparent - You tell us! c: +## Note +Check the LUASTUFF file for more information on all the lua things Saturn has. + ## Dependencies - SDL2 (Linux/OS X only) - SDL2-Mixer (Linux/OS X only) - libupnp (Linux/OS X only) - libgme (Linux/OS X only) - libopenmpt (Linux/OS X only) +- libbacktrace (Linux/OS X only) ## Compiling 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/doomdef.h b/src/doomdef.h index b7b3d44bc..f41a02782 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 v3 " -#define VERSIONSTRINGW L"Saturn v3" +#define VERSIONSTRING "Saturn v4 " +#define VERSIONSTRINGW L"Saturn v4" // 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! diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f6e7a9caf..9243cca06 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2579,8 +2579,15 @@ 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]); + V_DrawScaledPatch(x+4, y+13, flags, pinggfx[gfxnum]); + }else{ + V_DrawScaledPatch(x+12 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + V_DrawScaledPatch(x+4, y+2, flags, pinggfx[gfxnum]); + } + } if (servermaxping && lag > servermaxping && hu_tick < 4) { @@ -2592,8 +2599,12 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 lag, INT32 flags) { lag = (INT32)(lag * (1000.00f / TICRATE)); } - - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, lag, colormap); + + 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); + } if (measureid == 0) V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); @@ -2676,19 +2687,21 @@ static void HU_DrawRankings(void) V_DrawFadeScreen(0xFF00, 16); // A little more readable, and prevents cheating the fades under other circumstances. - if (cons_menuhighlight.value) + //if (cons_menuhighlight.value) hilicol = cons_menuhighlight.value; - else if (modeattacking) + /*else if (modeattacking) hilicol = V_ORANGEMAP; else - hilicol = ((gametype == GT_RACE) ? V_SKYMAP : V_REDMAP); + hilicol = ((gametype == GT_RACE) ? V_SKYMAP : V_REDMAP);*/ // draw the current gametype in the lower right - if (modeattacking) + /*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); - + 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(cv_nextmap.value)); + if (G_GametypeHasTeams()) { if (gametype == GT_CTF) diff --git a/src/k_kart.c b/src/k_kart.c index 563f4aca9..1181acd18 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3059,7 +3059,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; diff --git a/src/screen.c b/src/screen.c index a7162c540..c3f87688d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -418,9 +418,13 @@ void SCR_DisplayTicRate(void) UINT32 benchmark = (cap == 0) ? I_GetRefreshRate() : cap; INT32 x = 318; double fps = round(averageFPS); + + if (gamestate == GS_NULL) + return; // draw "FPS" - V_DrawFixedPatch(306< (benchmark - 5)) ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); 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/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..c4e40c392 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -43,6 +43,7 @@ typedef HANDLE (WINAPI *p_OpenFileMappingA) (DWORD, BOOL, LPCSTR); typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif #include +#include #include #include #ifdef __GNUC__ @@ -90,7 +91,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #endif #include -#include +#include #endif #endif @@ -137,12 +138,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 +192,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 +408,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 +466,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 @@ -791,7 +864,8 @@ static void I_RegisterSignals (void) #ifdef NEWSIGNALHANDLER static void signal_handler_child(INT32 num) { -#ifdef UNIXBACKTRACE + +#ifdef HAVE_LIBBACKTRACE write_backtrace(num); #endif @@ -3916,40 +3990,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/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/v_video.c b/src/v_video.c index 8950fdf9d..3bcd9db50 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -42,7 +42,9 @@ UINT8 *screens[5]; static CV_PossibleValue_t gamma_cons_t[] = {{0, "MIN"}, {4, "MAX"}, {0, NULL}}; static void CV_usegamma_OnChange(void); -consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t fps_cons_t[] = {{0, "No"}, {1, "Normal"}, {2, "Compact"}, {0, NULL}}; +consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_usegamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_usegamma_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allcaps = {"allcaps", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/win32/Makefile.cfg b/src/win32/Makefile.cfg index c31b07dcf..c087703a1 100644 --- a/src/win32/Makefile.cfg +++ b/src/win32/Makefile.cfg @@ -62,11 +62,7 @@ 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 @@ -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 @@ - + + +