From d48b08856e43ccadd779c54f3da863c697fd6051 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 31 Aug 2023 10:42:43 +0200 Subject: [PATCH 01/16] Support for Animated Votingscreens i hate the interpolation i hate it no idea honestly if those play correctly atm but atleast they dont freak out with uncapped https://gitlab.com/blondedradio/srb-2-k-cep/-/commit/776a547087cdef46b2bdbfc3ddc9d4d963bbea4b --- src/y_inter.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 115 insertions(+), 8 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index 3fb2d3aa3..16a5dae72 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -116,6 +116,18 @@ static INT32 intertic; static INT32 endtic = -1; static INT32 sorttic = -1; +patch_t *animVoteFramesPatches = NULL; +// VEXTRN - Vote (V) Extra (EXT) Race (R) Normal (N - Normal sized patch) +// VEXTBN - Vote (V) Extra (EXT) Battle (B) Normal (N - Normal sized patch) +// VEXTBW - Vote (V) Extra (EXT) Battle (B) Normal (W - Wide patch used in software) +// VEXTRW - Vote (V) Extra (EXT) Race (R) Normal (W - Wide patch used in software) +char animPrefix[] = "INTSC"; +char animWidePrefix[] = "INTSW"; + +INT32 currentAnimFrame = 0; +static INT32 foundAnimVoteFrames = 0; +static INT32 foundAnimVoteWideFrames = 0; + intertype_t intertype = int_none; @@ -325,6 +337,44 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) } } +// +// Y_AnimatedVoteScreenCheck +// +// Check if the lumps exist (checking for VEXTR(N|W)xx for race and VEXTRB(N|W)xx for battle) +void Y_AnimatedVoteScreenCheck(void) +{ + char tmpPrefix[] = "INTS"; + if(G_BattleGametype()) { + strcpy(animPrefix, "BTLSC"); + strcpy(animWidePrefix, "BTLSW"); + + strcpy(tmpPrefix, "BTLS"); + } + boolean stopSearching = false; + + foundAnimVoteFrames = 0; + foundAnimVoteWideFrames = 0; + currentAnimFrame = 0; + + INT32 i = 1; + while(!stopSearching){ + boolean normalLumpExists = W_LumpExists(va("%sC%d", tmpPrefix, i)); + boolean wideLumpExists = W_LumpExists(va("%sW%d", tmpPrefix, i)); + + if(normalLumpExists || wideLumpExists){ + if(normalLumpExists){ + foundAnimVoteFrames++; + } + if(wideLumpExists){ + foundAnimVoteWideFrames++; + } + } else { // If we don't find at least frame 1 (e.g VEXTRN1), let's just stop looking + stopSearching = true; + } + i++; + } +} + // // Y_IntermissionDrawer // @@ -978,6 +1028,41 @@ static void Y_UnloadData(void) // SRB2Kart: Voting! +// Y_DrawAnimatedVoteScreenPatch +// +// Draw animated patch based on frame counter on vote screen +// +void Y_DrawAnimatedVoteScreenPatch(boolean widePatch){ + char tempAnimPrefix[7]; + (widePatch) ? strcpy(tempAnimPrefix, animWidePrefix) : strcpy(tempAnimPrefix, animPrefix); + INT32 tempFoundAnimVoteFrames = (widePatch) ? foundAnimVoteWideFrames : foundAnimVoteFrames; + INT32 flags = V_SNAPTOBOTTOM | V_SNAPTOTOP; + UINT8 patchframe = (votetic / 4) % 16; + + // Just in case someone provides LESS widescreen frames than normal frames or vice versa, reset the frame counter to 0 + if(widePatch) { + if(currentAnimFrame > foundAnimVoteWideFrames-1){ + currentAnimFrame = 0; + } + } else { + if(currentAnimFrame > foundAnimVoteFrames-1){ + currentAnimFrame = 0; + } + } + + /*patch_t *currPatch = W_CachePatchName(va("%s%d", tempAnimPrefix, currentAnimFrame+1), PU_CACHE); + V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(currPatch->width)/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) + (vid.height / vid.dupy) - SHORT(currPatch->height), + V_SNAPTOTOP|V_SNAPTOLEFT, currPatch); + if(votetic % 3 == 0 && !paused){*/ + + { + currentAnimFrame = (currentAnimFrame+1 > tempFoundAnimVoteFrames-1) ? 0 : currentAnimFrame + 1; // jeez no fucking idea how to make this shit not go nuts with interpolation + patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, patchframe + 1), PU_CACHE); + V_DrawScaledPatch(160 - (background->width / 2), (200 - (background->height)), flags, background); + } +} + // // Y_VoteDrawer // @@ -1006,14 +1091,34 @@ void Y_VoteDrawer(void) V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); - if (widebgpatch && rendermode == render_soft && vid.width / vid.dupx > 320) - V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(widebgpatch->width)/2), - (vid.height / vid.dupy) - SHORT(widebgpatch->height), - V_SNAPTOTOP|V_SNAPTOLEFT, widebgpatch); - else - V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(bgpatch->width)/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) - (vid.height / vid.dupy) - SHORT(bgpatch->height), - V_SNAPTOTOP|V_SNAPTOLEFT, bgpatch); + if (widebgpatch && rendermode == render_soft && vid.width / vid.dupx > 320) { + + if(foundAnimVoteWideFrames == 0){ + V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(widebgpatch->width)/2), + (vid.height / vid.dupy) - SHORT(widebgpatch->height), + V_SNAPTOTOP|V_SNAPTOLEFT, widebgpatch); + } else { + // patch_t *currPatch = W_CachePatchName(va("%s%d", animPrefix, currentAnimFrame+1), PU_CACHE); + // V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(currPatch->width)/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) + // (vid.height / vid.dupy) - SHORT(currPatch->height), + // V_SNAPTOTOP|V_SNAPTOLEFT, currPatch); + // if(votetic % 4 == 0 && !paused){ + // currentAnimFrame = (currentAnimFrame+1 > foundAnimVoteFrames-1) ? 0 : currentAnimFrame + 1; + // } + Y_DrawAnimatedVoteScreenPatch(true); + } + } else { + if(foundAnimVoteFrames == 0) { + V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(bgpatch->width)/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) + (vid.height / vid.dupy) - SHORT(bgpatch->height), + V_SNAPTOTOP|V_SNAPTOLEFT, bgpatch); + } else { + Y_DrawAnimatedVoteScreenPatch(false); + } + + + } + for (i = 0; i < 4; i++) // First, we need to figure out the height of this thing... { @@ -1487,6 +1592,8 @@ void Y_StartVote(void) I_Error("voteendtic is dirty"); #endif + Y_AnimatedVoteScreenCheck(); + widebgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCW" : "INTERSCW"), PU_STATIC); bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_STATIC); cursor = W_CachePatchName("M_CURSOR", PU_STATIC); -- 2.54.0 From ca9277366cdb9eeff329d5e72a259e9c42be8bfb Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 1 Sep 2023 19:43:24 +0200 Subject: [PATCH 02/16] anim screen stuff --- src/y_inter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/y_inter.c b/src/y_inter.c index 16a5dae72..41c96c9ce 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -171,6 +171,7 @@ typedef struct static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; static INT32 votetic; +static INT32 lastvotetic; static INT32 voteendtic = -1; static patch_t *cursor = NULL; static patch_t *cursor1 = NULL; @@ -1037,7 +1038,6 @@ void Y_DrawAnimatedVoteScreenPatch(boolean widePatch){ (widePatch) ? strcpy(tempAnimPrefix, animWidePrefix) : strcpy(tempAnimPrefix, animPrefix); INT32 tempFoundAnimVoteFrames = (widePatch) ? foundAnimVoteWideFrames : foundAnimVoteFrames; INT32 flags = V_SNAPTOBOTTOM | V_SNAPTOTOP; - UINT8 patchframe = (votetic / 4) % 16; // Just in case someone provides LESS widescreen frames than normal frames or vice versa, reset the frame counter to 0 if(widePatch) { @@ -1057,10 +1057,12 @@ void Y_DrawAnimatedVoteScreenPatch(boolean widePatch){ if(votetic % 3 == 0 && !paused){*/ { - currentAnimFrame = (currentAnimFrame+1 > tempFoundAnimVoteFrames-1) ? 0 : currentAnimFrame + 1; // jeez no fucking idea how to make this shit not go nuts with interpolation - patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, patchframe + 1), PU_CACHE); + patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, currentAnimFrame + 1), PU_CACHE); V_DrawScaledPatch(160 - (background->width / 2), (200 - (background->height)), flags, background); } + if (lastvotetic != votetic && lastvotetic % 2 == 0) { + currentAnimFrame = (currentAnimFrame+1 > tempFoundAnimVoteFrames-1) ? 0 : currentAnimFrame + 1; // jeez no fucking idea how to make this shit not go nuts with interpolation + } } // @@ -1336,6 +1338,8 @@ void Y_VoteDrawer(void) V_DrawCenteredString(BASEVIDWIDTH/2, 188, hilicol, va("Vote ends in %d", tickdown)); } + + lastvotetic = votetic; #ifdef HAVE_BLUA if (renderisnewtic) -- 2.54.0 From 90cc5a6cb0cf0f210d2a8c3518dbe73c429b29ff Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 15:30:21 +0200 Subject: [PATCH 03/16] Fix a possible crash in R_RenderMaskedSegRange https://git.do.srb2.org/STJr/SRB2/-/commit/55b4458001b2ffe76774ff07a11b56ebf1f70de9 --- src/r_segs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r_segs.c b/src/r_segs.c index 594024b75..53f12ecc6 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1769,6 +1769,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) while (need > maxopenings); openings = Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL); lastopening = openings + pos; + + if (oldopenings == NULL) + return; // borrowed fix from *cough* zdoom *cough* // [RH] We also need to adjust the openings pointers that -- 2.54.0 From 7da590df94863e0d18451f194923849e49d384ab Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 15:30:42 +0200 Subject: [PATCH 04/16] Fix sprite scale column iteration crash https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2130 --- src/r_things.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/r_things.c b/src/r_things.c index 26dad2f0b..b1c4c3851 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -851,6 +851,15 @@ static void R_DrawVisSprite(vissprite_t *vis) if (overflow_test < 0) overflow_test = -overflow_test; if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; // ditto } + + // TODO This check should not be necessary. But Papersprites near to the camera will sometimes create invalid values + // for the vissprite's startfrac. This happens because they are not depth culled like other sprites. + // Someone who is more familiar with papersprites pls check and try to fix <3 + if (vis->startfrac < 0 || vis->startfrac > (patch->width << FRACBITS)) + { + // never draw vissprites with startfrac out of patch range + return; + } colfunc = basecolfunc; // hack: this isn't resetting properly somewhere. dc_colormap = vis->colormap; -- 2.54.0 From 98dfe528d8b46662c57ed910544d5308345058f8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 16:37:11 +0200 Subject: [PATCH 05/16] remove this --- src/r_things.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/r_things.h b/src/r_things.h index ab4688f91..7e38dbf47 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -152,8 +152,6 @@ typedef struct vissprite_s extracolormap_t *extra_colormap; // global colormaps - //fixed_t xscale; - // Precalculated top and bottom screen coords for the sprite. fixed_t thingheight; // The actual height of the thing (for 3D floors) sector_t *sector; // The sector containing the thing. -- 2.54.0 From 7f05d27f42a437e28f293829e849c5fbdfc7dfb6 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 5 Sep 2023 12:47:49 +0300 Subject: [PATCH 06/16] Allow lua to change vote background via hud.setVoteBackground --- src/lua_hudlib.c | 36 ++++++++++++++++++++++++++++++++++++ src/y_inter.c | 23 +++++++++++++++++------ src/y_inter.h | 1 + 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 470fad9b7..bd3fb19c8 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -15,6 +15,7 @@ #include "r_defs.h" #include "r_local.h" #include "st_stuff.h" // hudinfo[] +#include "y_inter.h" #include "g_game.h" #include "i_video.h" // rendermode #include "p_local.h" // camera_t @@ -966,11 +967,46 @@ static int lib_hudadd(lua_State *L) return 0; } +static int lib_hudsetvotebackground(lua_State *L) +{ + if (lua_isnoneornil(L, 1)) + { + if (luaVoteScreen) + { + free(luaVoteScreen); + } + + luaVoteScreen = NULL; + + return 0; + } + + const char *prefix = luaL_checkstring(L, 1); + + if (strlen(prefix) != 4) + { + return luaL_argerror(L, 1, "prefix should 4 characters wide"); + } + + if (!luaVoteScreen) + { + luaVoteScreen = (char*)malloc(5); + luaVoteScreen[4] = 0; + } + + strncpy(luaVoteScreen, prefix, 4); + + strupr(luaVoteScreen); + + return 0; +} + static luaL_Reg lib_hud[] = { {"enable", lib_hudenable}, {"disable", lib_huddisable}, {"enabled", lib_hudenabled}, {"add", lib_hudadd}, + {"setVoteBackground", lib_hudsetvotebackground}, {NULL, NULL} }; diff --git a/src/y_inter.c b/src/y_inter.c index 41c96c9ce..bda60dde2 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -123,6 +123,7 @@ patch_t *animVoteFramesPatches = NULL; // VEXTRW - Vote (V) Extra (EXT) Race (R) Normal (W - Wide patch used in software) char animPrefix[] = "INTSC"; char animWidePrefix[] = "INTSW"; +char *luaVoteScreen = NULL; INT32 currentAnimFrame = 0; static INT32 foundAnimVoteFrames = 0; @@ -345,14 +346,24 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) void Y_AnimatedVoteScreenCheck(void) { char tmpPrefix[] = "INTS"; - if(G_BattleGametype()) { - strcpy(animPrefix, "BTLSC"); - strcpy(animWidePrefix, "BTLSW"); - - strcpy(tmpPrefix, "BTLS"); - } boolean stopSearching = false; + if (luaVoteScreen) + { + strncpy(tmpPrefix, luaVoteScreen, 4); + } + else + { + if(G_BattleGametype()) { + strcpy(tmpPrefix, "BTLS"); + } + } + + strncpy(animPrefix, tmpPrefix, 4); + animPrefix[4] = 'C'; + strncpy(animWidePrefix, tmpPrefix, 4); + animWidePrefix[4] = 'W'; + foundAnimVoteFrames = 0; foundAnimVoteWideFrames = 0; currentAnimFrame = 0; diff --git a/src/y_inter.h b/src/y_inter.h index 6162dc282..ee320d474 100644 --- a/src/y_inter.h +++ b/src/y_inter.h @@ -10,6 +10,7 @@ /// \brief Tally screens, or "Intermissions" as they were formally called in Doom extern boolean usebuffer; +extern char *luaVoteScreen; void Y_IntermissionDrawer(void); void Y_Ticker(void); -- 2.54.0 From cdedf1349cd4e797a8e8ffcac3a9032d3278e888 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 11:47:19 +0300 Subject: [PATCH 07/16] Attempt to fix non-ansii filenames on windows --- src/w_wad.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 31977bea8..6f16b3477 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -148,6 +148,38 @@ void W_Shutdown(void) 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) +//#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H +#include + +// Windows can't open utf-8 path so it must be converted to utf-16 +FILE* fopen_utf8(const char* filename, const char* mode) +{ + static const int MY_PATH_MAX = 2048; + WCHAR nameW[MY_PATH_MAX] = { 0 }; + WCHAR modeW[16] = { 0 }; + // the following function converts the UTF-8 filename to UTF-16 (WCHAR) nameW + int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, nameW, MY_PATH_MAX); + if(len > 0 && MultiByteToWideChar(CP_UTF8, 0, mode, -1, modeW, 16) > 0) + { + // using _wfopen_s() shuts up MSVC's complaints + // about _wfopen() being unsafe.. + FILE* ret = NULL; + if(_wfopen_s(&ret, nameW, modeW) == 0) + return ret; + } + return NULL; +} + +#else + +#define fopen_utf8 fopen + +#endif + // W_OpenWadFile // Helper function for opening the WAD file. // Returns the FILE * handle for the file, or NULL if not found or could not be opened @@ -165,7 +197,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors) *filename = filenamebuf; // open wad file - if ((handle = fopen(*filename, "rb")) == NULL) + if ((handle = fopen_utf8(*filename, "rb")) == NULL) { // If we failed to load the file with the path as specified by // the user, strip the directories and search for the file. @@ -175,7 +207,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors) // in filenamebuf == *filename. if (findfile(filenamebuf, NULL, true)) { - if ((handle = fopen(*filename, "rb")) == NULL) + if ((handle = fopen_utf8(*filename, "rb")) == NULL) { if (useerrors) CONS_Alert(CONS_ERROR, M_GetText("Can't open %s\n"), *filename); -- 2.54.0 From 9cd0e6c38512e56ca2e0c4c34e886b7e5db49cca Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 12:00:10 +0300 Subject: [PATCH 08/16] Why is this 'variable-sized' and can't be initialized like that??? --- src/w_wad.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 6f16b3477..f715c26cb 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -159,8 +159,10 @@ static char filenamebuf[MAX_WADPATH]; FILE* fopen_utf8(const char* filename, const char* mode) { static const int MY_PATH_MAX = 2048; - WCHAR nameW[MY_PATH_MAX] = { 0 }; - WCHAR modeW[16] = { 0 }; + WCHAR nameW[MY_PATH_MAX]; + memset(nameW, 0, sizeof(WCHAR)*MY_PATH_MAX); + WCHAR modeW[16]; + memset(modeW, 0, sizeof(WCHAR)*16); // the following function converts the UTF-8 filename to UTF-16 (WCHAR) nameW int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, nameW, MY_PATH_MAX); if(len > 0 && MultiByteToWideChar(CP_UTF8, 0, mode, -1, modeW, 16) > 0) -- 2.54.0 From 16a7e69292ae7629b0f37d35b1f4b368ea5960ac Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 11 Sep 2023 13:01:29 +0300 Subject: [PATCH 09/16] Don't init discord rich presence untill discordrp is set to On Haven't tested this since i'm on linux and the feature looks like it is windows only --- src/discord.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/discord.c b/src/discord.c index 6926b4e1c..a845b6104 100644 --- a/src/discord.c +++ b/src/discord.c @@ -47,6 +47,8 @@ discordRequest_t *discordRequestList = NULL; static char self_ip[IP_SIZE]; +boolean drpc_init = false; + /*-------------------------------------------------- static char *DRPC_XORIPString(const char *input) @@ -315,6 +317,9 @@ void DRPC_RemoveRequest(discordRequest_t *removeRequest) --------------------------------------------------*/ void DRPC_Init(void) { + if (drpc_init || !cv_discordrp.value) return; + + drpc_init = true; DiscordEventHandlers handlers; memset(&handlers, 0, sizeof(handlers)); @@ -402,6 +407,10 @@ static void DRPC_EmptyRequests(void) --------------------------------------------------*/ void DRPC_UpdatePresence(void) { + if (!cv_discordrp.value) return; + + if (!drpc_init) DRPC_Init(); + char detailstr[48+1]; char mapimg[8+1]; -- 2.54.0 From 346433d248987d6f3ca4708150681a4bc38cbcd2 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 11 Sep 2023 13:17:12 +0300 Subject: [PATCH 10/16] Shutdown DiscordRPC when discordrp cvar is set to Off --- src/discord.c | 32 ++++++++++++++++++++++++++++++-- src/discord.h | 7 +++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/discord.c b/src/discord.c index a845b6104..ea9bc66b9 100644 --- a/src/discord.c +++ b/src/discord.c @@ -37,7 +37,9 @@ // length of IP strings #define IP_SIZE 21 -consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL}; +static void Discordrp_OnChange(void); + +consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, Discordrp_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_discordstreamer = {"discordstreamer", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_discordasks = {"discordasks", "Yes", CV_SAVE|CV_CALL, CV_YesNo, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL}; @@ -330,10 +332,36 @@ void DRPC_Init(void) handlers.joinRequest = DRPC_HandleJoinRequest; Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL); - I_AddExitFunc(Discord_Shutdown); + I_AddExitFunc(DRPC_Shutdown); DRPC_UpdatePresence(); } +void DRPC_Shutdown(void) +{ + if (!drpc_init) + { + CONS_Printf("DiscordRPC never started\n"); + return; + } + + CONS_Printf("Shutting down DiscordRPC\n"); + + Discord_Shutdown(); + drpc_init = false; +} + +static void Discordrp_OnChange(void) +{ + if (cv_discordrp.value) + { + DRPC_UpdatePresence(); + } + else + { + DRPC_Shutdown(); + } +} + /*-------------------------------------------------- static void DRPC_GotServerIP(UINT32 address) diff --git a/src/discord.h b/src/discord.h index a6bb1134a..131dc05f9 100644 --- a/src/discord.h +++ b/src/discord.h @@ -64,6 +64,13 @@ void DRPC_RemoveRequest(discordRequest_t *removeRequest); void DRPC_Init(void); +/*-------------------------------------------------- + void DRPC_Shutdown(void); + + Shutdown Discord Rich Presence if it was started at all. +--------------------------------------------------*/ +void DRPC_Shutdown(void); + /*-------------------------------------------------- void DRPC_UpdatePresence(void); -- 2.54.0 From 35cfdea9e71209e1987435a6c1284295035232e2 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 11 Sep 2023 15:55:59 +0200 Subject: [PATCH 11/16] allow opengl to also use widescreen backgrounds for votes thanks kk for locking this to software mode only despite this working without issues in opengl aswell --- src/y_inter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/y_inter.c b/src/y_inter.c index bda60dde2..c20ef30e3 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1104,7 +1104,7 @@ void Y_VoteDrawer(void) V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); - if (widebgpatch && rendermode == render_soft && vid.width / vid.dupx > 320) { + if (widebgpatch && vid.width / vid.dupx > 320) { if(foundAnimVoteWideFrames == 0){ V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(widebgpatch->width)/2), -- 2.54.0 From 4455ebe58f08fdeb95da06efe639986c9e8eeafd Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sat, 2 Sep 2023 13:07:13 +0800 Subject: [PATCH 12/16] Fix issue with upside-down salty hop --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 7878a19b5..1ff3f031d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3100,7 +3100,7 @@ static void K_QuiteSaltyHop(player_t *p) p->mo->spriteyscale += (mos/8); p->mo->spritexscale -= (mos/8); } - p->mo->spriteyoffset = p->mo->salty_zoffset*P_MobjFlip(p->mo); + p->mo->spriteyoffset = p->mo->salty_zoffset; if (S_SoundPlaying(p->mo, sfx_screec)) S_StopSoundByID(p->mo, sfx_screec); if (S_SoundPlaying(p->mo, sfx_drift)) -- 2.54.0 From f91687209ba243be16db2aed532ed8ec3941f9dc Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Fri, 8 Sep 2023 10:15:57 +0800 Subject: [PATCH 13/16] fix horizon lines on batching somewhat --- src/hardware/hw_draw.c | 22 ++++---- src/hardware/hw_drv.h | 3 +- src/hardware/hw_main.c | 97 ++++++++++++++++++++++++++++---- src/hardware/r_opengl/r_opengl.c | 35 ++++++++---- 4 files changed, 123 insertions(+), 34 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 68aba1be0..8f94abbba 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -122,7 +122,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) flags |= PF_ForceWrapY; // clip it since it is used for bunny scroll in doom I - HWD.pfnDrawPolygon(NULL, v, 4, flags); + HWD.pfnDrawPolygon(NULL, v, 4, flags, false); } void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap) @@ -300,10 +300,10 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + HWD.pfnDrawPolygon(&Surf, v, 4, flags, false); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + HWD.pfnDrawPolygon(NULL, v, 4, flags, false); } void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) @@ -454,10 +454,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[cv_translucenthud.value]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; flags |= PF_Modulated; - HWD.pfnDrawPolygon(&Surf, v, 4, flags); + HWD.pfnDrawPolygon(&Surf, v, 4, flags, false); } else - HWD.pfnDrawPolygon(NULL, v, 4, flags); + HWD.pfnDrawPolygon(NULL, v, 4, flags, false); } // ========================================================================== @@ -533,7 +533,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum // BTW, I see we put 0 for PFs, and If I'm right, that // means we take the previous PFs as default // how can we be sure they are ok? - HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest); //PF_Translucent); + HWD.pfnDrawPolygon(NULL, v, 4, PF_NoDepthTest, false); //PF_Translucent); } @@ -570,7 +570,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) Surf.PolyColor.rgba = pLocalPalette[color].rgba; Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); } - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } // Draw the console background with translucency support @@ -597,7 +597,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } @@ -846,7 +846,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) Surf.PolyColor = V_GetColor(color); HWD.pfnDrawPolygon(&Surf, v, 4, - PF_Modulated|PF_NoTexture|PF_NoDepthTest); + PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); } // -------------------+ @@ -954,7 +954,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 Surf.PolyColor.rgba = UINT2RGBA(color); Surf.PolyColor.s.alpha = 0x80; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest); + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } // -----------------+ @@ -1062,7 +1062,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) Surf.PolyColor = V_GetColor(color); HWD.pfnDrawPolygon(&Surf, v, 4, - PF_Modulated|PF_NoTexture|PF_NoDepthTest); + PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); } #ifdef HAVE_PNG diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index c7786670a..204c79dc1 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -21,6 +21,7 @@ #include "hw_md2.h" #include "hw_dll.h" +#include "../doomdef.h" // ========================================================================== // STANDARD DLL EXPORTS @@ -34,7 +35,7 @@ EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal, RGBA_t *pgamma); #endif EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl); EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags); +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial); EXPORT void HWRAPI(SetBlend) (FBITFIELD PolyFlags); EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, FBOOLEAN DepthMask, FBOOLEAN StencilMask, FRGBAFloat *ClearColor); EXPORT void HWRAPI(SetTexture) (FTextureInfo *TexInfo); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index aa9a921e2..07f74f6a5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -725,7 +725,80 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei else HWD.pfnSetShader(1); // floor shader - HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags); + HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, false); + + if (subsector) + { + // Horizon lines + FOutVector horizonpts[6]; + float dist, vx, vy; + float x1, y1, xd, yd; + UINT8 numplanes, j; + vertex_t v; // For determining the closest distance from the line to the camera, to split render planes for minimum distortion; + + const float renderdist = 27000.0f; // How far out to properly render the plane + const float farrenderdist = 32768.0f; // From here, raise plane to horizon level to fill in the line with some texture distortion + + seg_t *line = &segs[subsector->firstline]; + + for (i = 0; i < subsector->numlines; i++, line++) + { + if (line->linedef->special == 41 && 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)); + + x1 = ((polyvertex_t *)line->pv1)->x; + y1 = ((polyvertex_t *)line->pv1)->y; + xd = ((polyvertex_t *)line->pv2)->x - x1; + yd = ((polyvertex_t *)line->pv2)->y - y1; + + // Based on the seg length and the distance from the line, split horizon into multiple poly sets to reduce distortion + dist = sqrtf((xd*xd) + (yd*yd)) / dist / 16.0f; + if (dist > 100.0f) + numplanes = 100; + else + numplanes = (UINT8)dist + 1; + + for (j = 0; j < numplanes; j++) + { + // Left side + vx = x1 + xd * j / numplanes; + vy = y1 + yd * j / numplanes; + SETUP3DVERT((&horizonpts[1]), vx, vy); + + dist = sqrtf(powf(vx - gr_viewx, 2) + powf(vy - gr_viewy, 2)); + vx = (vx - gr_viewx) * renderdist / dist + gr_viewx; + vy = (vy - gr_viewy) * renderdist / dist + gr_viewy; + SETUP3DVERT((&horizonpts[0]), vx, vy); + + // Right side + vx = x1 + xd * (j+1) / numplanes; + vy = y1 + yd * (j+1) / numplanes; + SETUP3DVERT((&horizonpts[2]), vx, vy); + + dist = sqrtf(powf(vx - gr_viewx, 2) + powf(vy - gr_viewy, 2)); + vx = (vx - gr_viewx) * renderdist / dist + gr_viewx; + vy = (vy - gr_viewy) * renderdist / dist + gr_viewy; + SETUP3DVERT((&horizonpts[3]), vx, vy); + + // Horizon fills + vx = (horizonpts[0].x - gr_viewx) * farrenderdist / renderdist + gr_viewx; + vy = (horizonpts[0].z - gr_viewy) * farrenderdist / renderdist + gr_viewy; + SETUP3DVERT((&horizonpts[5]), vx, vy); + horizonpts[5].y = gr_viewz; + + vx = (horizonpts[3].x - gr_viewx) * farrenderdist / renderdist + gr_viewx; + vy = (horizonpts[3].z - gr_viewy) * farrenderdist / renderdist + gr_viewy; + SETUP3DVERT((&horizonpts[4]), vx, vy); + horizonpts[4].y = gr_viewz; + + // Draw + HWD.pfnDrawPolygon(&Surf, horizonpts, 6, PolyFlags, true); + } + } + } + } } #ifdef WALLSPLATS @@ -789,7 +862,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) } HWD.pfnSetShader(2); // wall shader - HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal); + HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal, false); } } #endif @@ -831,7 +904,7 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend blendmode &= ~PF_Masked; } - HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude); + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude, false); #ifdef WALLSPLATS if (gr_curline->linedef->splats && cv_splats.value) @@ -1125,7 +1198,7 @@ void HWR_DrawSkyWallList() HWD.pfnUnSetShader(); for (i = 0; i < skyWallVertexArraySize; i++) { - HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture); + HWD.pfnDrawPolygon(&surf, skyWallVertexArray + i * 4, 4, PF_Occlude|PF_Invisible|PF_NoTexture, false); } } @@ -2951,7 +3024,7 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t blendmode |= PF_Masked|PF_Modulated; HWD.pfnSetShader(1); // floor shader - HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode); + HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode, false); } void HWR_AddPolyObjectPlanes(void) @@ -3750,7 +3823,7 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t { sSurf.PolyColor.s.alpha = (UINT8)(sSurf.PolyColor.s.alpha - floorheight/4); HWD.pfnSetShader(1); // floor shader - HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated); + HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, false); } } @@ -4117,7 +4190,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) Surf.PolyColor.s.alpha = alpha; HWD.pfnSetShader(3); // sprite shader - HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); top = bot; #ifdef ESLOPE @@ -4157,7 +4230,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) Surf.PolyColor.s.alpha = alpha; HWD.pfnSetShader(3); // sprite shader - HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } // -----------------+ @@ -4310,7 +4383,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) } HWD.pfnSetShader(3); // sprite shader - HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } } @@ -4404,7 +4477,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) } HWD.pfnSetShader(3); // sprite shader - HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); + HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated, false); } // -------------------------------------------------------------------------- @@ -6027,7 +6100,7 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, blendmode |= PF_Modulated; // No PF_Occlude means overlapping (incorrect) transparency - HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode); + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode, false); #ifdef WALLSPLATS if (gr_curline->linedef->splats && cv_splats.value) @@ -6078,7 +6151,7 @@ void HWR_DoPostProcessor(player_t *player) Surf.PolyColor.s.alpha = 0xc0; // match software mode - HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); + HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest, false); } if (!cv_grscreentextures.value) // screen textures are needed for the rest of the effects diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d1690e9ee..8f740dd1b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1822,6 +1822,8 @@ typedef struct FBITFIELD polyFlags; GLuint texNum; GLuint shader; + // this tells batching that the plane belongs to a horizon line and must be drawn in correct order with the skywalls + boolean horizonSpecial; } PolygonArrayEntry; FOutVector* finalVertexArray = NULL;// contains subset of sorted vertices and texture coordinates to be sent to gpu @@ -1861,21 +1863,27 @@ EXPORT void HWRAPI(StartBatching) (void) static int comparePolygons(const void *p1, const void *p2) { - PolygonArrayEntry* poly1 = &polygonArray[*(const unsigned int*)p1]; - PolygonArrayEntry* poly2 = &polygonArray[*(const unsigned int*)p2]; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; int shader1 = poly1->shader; int shader2 = poly2->shader; - // make skywalls first in order - if (poly1->polyFlags & PF_NoTexture) + // make skywalls and horizon lines first in order + if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) shader1 = -1; - if (poly2->polyFlags & PF_NoTexture) + if (poly2->polyFlags & PF_NoTexture || poly1->horizonSpecial) shader2 = -1; diff = shader1 - shader2; if (diff != 0) return diff; + // skywalls and horizon lines must retain their order for horizon lines to work + if (shader1 == -1 && shader2 == -1) + return index1 - index2; + diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; @@ -1899,20 +1907,26 @@ static int comparePolygons(const void *p1, const void *p2) static int comparePolygonsNoShaders(const void *p1, const void *p2) { - PolygonArrayEntry* poly1 = &polygonArray[*(const unsigned int*)p1]; - PolygonArrayEntry* poly2 = &polygonArray[*(const unsigned int*)p2]; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; GLuint texNum1 = poly1->texNum; GLuint texNum2 = poly2->texNum; - if (poly1->polyFlags & PF_NoTexture) + if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) texNum1 = 0; - if (poly2->polyFlags & PF_NoTexture) + if (poly2->polyFlags & PF_NoTexture || poly1->horizonSpecial) texNum2 = 0; diff = texNum1 - texNum2; if (diff != 0) return diff; + // skywalls and horizon lines must retain their order for horizon lines to work + if (texNum1 == 0 && texNum2 == 0) + return index1 - index2; + diff = poly1->polyFlags - poly2->polyFlags; if (diff != 0) return diff; @@ -2269,7 +2283,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i // -----------------+ // DrawPolygon : Render a polygon, set the texture, set render mode // -----------------+ -EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags) +EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial) { if (gl_batching) { @@ -2309,6 +2323,7 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI polygonArray[polygonArraySize].polyFlags = PolyFlags; polygonArray[polygonArraySize].texNum = tex_downloaded; polygonArray[polygonArraySize].shader = gl_currentshaderprogram; + polygonArray[polygonArraySize].horizonSpecial = horizonSpecial; polygonArraySize++; memcpy(&unsortedVertexArray[unsortedVertexArraySize], pOutVerts, iNumPts * sizeof(FOutVector)); -- 2.54.0 From dd4a9ae8909df63cc538e9f701728dd489ec000f Mon Sep 17 00:00:00 2001 From: haya <126386046+hayaunderscore@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:24:37 +0800 Subject: [PATCH 14/16] i may be stupid --- src/hardware/r_opengl/r_opengl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8f740dd1b..b0c6ec8f6 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1875,7 +1875,7 @@ static int comparePolygons(const void *p1, const void *p2) // make skywalls and horizon lines first in order if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) shader1 = -1; - if (poly2->polyFlags & PF_NoTexture || poly1->horizonSpecial) + if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) shader2 = -1; diff = shader1 - shader2; if (diff != 0) return diff; @@ -1918,7 +1918,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) GLuint texNum2 = poly2->texNum; if (poly1->polyFlags & PF_NoTexture || poly1->horizonSpecial) texNum1 = 0; - if (poly2->polyFlags & PF_NoTexture || poly1->horizonSpecial) + if (poly2->polyFlags & PF_NoTexture || poly2->horizonSpecial) texNum2 = 0; diff = texNum1 - texNum2; if (diff != 0) return diff; -- 2.54.0 From b6ef6eb8018a383fe27189755fcc2836ea4d7df9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 21:03:58 +0200 Subject: [PATCH 15/16] revert sloped midtexture fix for now huge performance regression on some maps ill look into it in the future again maybe --- src/hardware/hw_main.c | 148 +++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 58 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..66adf3522 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -951,9 +951,6 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); - if (fpclassify(pegmul) == FP_NAN) - pegmul = 0.0; - #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; @@ -962,8 +959,6 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif - if (fpclassify(endpegmul) == FP_NAN) - endpegmul = 0.0; for (i = 0; i < sector->numlights; i++) { @@ -1074,10 +1069,24 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif - // Found a break - bot = min(max(bheight, realbot), top); - endbot = min(max(endbheight, endrealbot), endtop); +#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; #ifdef ESLOPE @@ -1671,7 +1680,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil) { + FBITFIELD blendmode; sector_t *front, *back; + fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; + fixed_t texturevpeg = 0; INT32 repeats; if (gr_linedef->frontsector->heightsec != -1) @@ -1707,10 +1719,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else repeats = 1; - fixed_t midtexheight = textureheight[gr_midtexture] * repeats; - fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; - fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; - // SoM: a little note: This code re-arranging will // fix the bug in Nimrod map02. popentop and popenbottom // record the limits the texture can be displayed in. @@ -1724,8 +1732,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // From CB if (gr_curline->polyseg) { - popentop = popentopslope = back->ceilingheight; - popenbottom = popenbottomslope = back->floorheight; + popentop = back->ceilingheight; + popenbottom = back->floorheight; } else #endif @@ -1733,9 +1741,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); - - popentopslope = min(worldtopslope, worldhighslope); - popenbottomslope = max(worldbottomslope, worldlowslope); +#else + popentop = min(front->ceilingheight, back->ceilingheight); + popenbottom = max(front->floorheight, back->floorheight); +#endif } #ifdef ESLOPE @@ -1744,16 +1753,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) { polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; - polybottomslope = polybottom; - polytop = polybottom + midtexheight; - polytopslope = polytop; + polytop = polybottom + textureheight[gr_midtexture]*repeats; } else { polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polytopslope = polytop; - polybottom = polytop - midtexheight; - polybottomslope = polybottom; + polybottom = polytop - textureheight[gr_midtexture]*repeats; } } else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -1762,17 +1767,12 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif { polybottom = popenbottom + gr_sidedef->rowoffset; - polytop = polybottom + midtexheight; - polybottomslope = popenbottomslope + gr_sidedef->rowoffset; - polytopslope = polybottomslope + midtexheight; + polytop = polybottom + textureheight[gr_midtexture]*repeats; } else { polytop = popentop + gr_sidedef->rowoffset; polybottom = polytop - textureheight[gr_midtexture]*repeats; - polybottom = polytop - midtexheight; - polytopslope = popentopslope + gr_sidedef->rowoffset; - polybottomslope = polytopslope - midtexheight; } // CB @@ -1783,8 +1783,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { lowcut = polybottom; highcut = polytop; - lowcutslope = polybottomslope; - highcutslope = polytopslope; } #endif else @@ -1792,49 +1790,83 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector lowcut = popenbottom; highcut = popentop; - lowcutslope = popenbottomslope; - highcutslope = popentopslope; } h = min(highcut, polytop); l = max(polybottom, lowcut); - hS = min(highcutslope, polytopslope); - lS = max(polybottomslope, lowcutslope); - // PEGGING - fixed_t texturevpeg, texturevpegslope; - - 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; - } + // 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; 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; + 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[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); + 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; + // ooops ! this do not work at all because render order we should render it in backtofront order switch (gr_linedef->special) { -- 2.54.0 From 538de7d2d2b439331949320a31a99bc8ca37b041 Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 13 Sep 2023 04:42:35 +0200 Subject: [PATCH 16/16] fix memfree command on 64bit --- src/android/i_system.c | 2 +- src/dummy/i_system.c | 2 +- src/i_system.h | 2 +- src/sdl/i_system.c | 13 ++++++------- src/z_zone.c | 10 +++++----- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/android/i_system.c b/src/android/i_system.c index 51a96d93a..c0b49a886 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -24,7 +24,7 @@ static INT64 start_time; // as microseconds since the epoch // I should probably return how much memory is remaining // for this process, considering Android's process memory limit. -UINT32 I_GetFreeMem(UINT32 *total) +size_t I_GetFreeMem(size_t *total) { // what the heck? sysinfo() is partially missing in bionic? /* struct sysinfo si; */ diff --git a/src/dummy/i_system.c b/src/dummy/i_system.c index 1696672b8..cf8144b90 100644 --- a/src/dummy/i_system.c +++ b/src/dummy/i_system.c @@ -5,7 +5,7 @@ UINT8 graphics_started = 0; UINT8 keyboard_started = 0; -UINT32 I_GetFreeMem(UINT32 *total) +size_t I_GetFreeMem(size_t *total) { *total = 0; return 0; diff --git a/src/i_system.h b/src/i_system.h index 89ea1ae2d..05826c79e 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -40,7 +40,7 @@ extern UINT8 keyboard_started; \return free memory in the system */ -UINT32 I_GetFreeMem(UINT32 *total); +size_t I_GetFreeMem(size_t *total); /** \brief Returns precise time value for performance measurement. The precise time should be a monotonically increasing counter, and will wrap. diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 5b76edddf..d1add12b4 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3806,8 +3806,7 @@ static long get_entry(const char* name, const char* buf) } #endif -// quick fix for compil -UINT32 I_GetFreeMem(UINT32 *total) +size_t I_GetFreeMem(size_t *total) { #ifdef FREEBSD struct vmmeter sum; @@ -3855,8 +3854,8 @@ UINT32 I_GetFreeMem(UINT32 *total) info.dwLength = sizeof (MEMORYSTATUS); GlobalMemoryStatus( &info ); if (total) - *total = (UINT32)info.dwTotalPhys; - return (UINT32)info.dwAvailPhys; + *total = (size_t)info.dwTotalPhys; + return (size_t)info.dwAvailPhys; #elif defined (__OS2__) UINT32 pr_arena; @@ -3871,8 +3870,8 @@ UINT32 I_GetFreeMem(UINT32 *total) /* Linux */ char buf[1024]; char *memTag; - UINT32 freeKBytes; - UINT32 totalKBytes; + size_t freeKBytes; + size_t totalKBytes; INT32 n; INT32 meminfo_fd = -1; long Cached; @@ -3903,7 +3902,7 @@ UINT32 I_GetFreeMem(UINT32 *total) } memTag += sizeof (MEMTOTAL); - totalKBytes = atoi(memTag); + totalKBytes = (size_t)atoi(memTag); if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) { diff --git a/src/z_zone.c b/src/z_zone.c index 199eefd08..1eb9ba42e 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -140,14 +140,14 @@ static void Command_Memdump_f(void); void Z_Init(void) { - UINT32 total, memfree; + size_t total, memfree; memset(&head, 0x00, sizeof(head)); head.next = head.prev = &head; memfree = I_GetFreeMem(&total)>>20; - CONS_Printf("System memory: %uMB - Free: %uMB\n", total>>20, memfree); + CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree)); // Note: This allocates memory. Watch out. COM_AddCommand("memfree", Command_Memfree_f); @@ -616,7 +616,7 @@ size_t Z_TagUsage(INT32 tagnum) void Command_Memfree_f(void) { - UINT32 freebytes, totalbytes; + size_t freebytes, totalbytes; Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); @@ -644,8 +644,8 @@ void Command_Memfree_f(void) CONS_Printf("\x82%s", M_GetText("System Memory Info\n")); freebytes = I_GetFreeMem(&totalbytes); - CONS_Printf(M_GetText(" Total physical memory: %7u KB\n"), totalbytes>>10); - CONS_Printf(M_GetText("Available physical memory: %7u KB\n"), freebytes>>10); + CONS_Printf(M_GetText(" Total physical memory: %s KB\n"), sizeu1(totalbytes>>10)); + CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10)); } #ifdef ZDEBUG -- 2.54.0