From c499a8387e1daf9519d443251444beafbdeacea2 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 3 Aug 2023 16:39:17 -0700 Subject: [PATCH 001/239] Fix glibc 2.38 compile glibc 2.38 added strlcpy and strlcat. --- src/doomtype.h | 7 ++++++- src/string.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 4660e876d..f4f32edc8 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -164,6 +164,11 @@ char *strcasestr(const char *in, const char *what); #define HAVE_DOSSTR_FUNCS #endif +// glibc 2.38: added strlcpy and strlcat to _DEFAULT_SOURCE +#if defined (__APPLE__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) +#define HAVE_STRLCPY +#endif + #ifndef HAVE_DOSSTR_FUNCS int strupr(char *n); // from dosstr.c int strlwr(char *n); // from dosstr.c @@ -171,7 +176,7 @@ int strlwr(char *n); // from dosstr.c #include // for size_t -#ifndef __APPLE__ +#ifndef HAVE_STRLCPY size_t strlcat(char *dst, const char *src, size_t siz); size_t strlcpy(char *dst, const char *src, size_t siz); #endif diff --git a/src/string.c b/src/string.c index c415e5245..34c5e71aa 100644 --- a/src/string.c +++ b/src/string.c @@ -16,7 +16,7 @@ #include #include "doomdef.h" -#if !defined (__APPLE__) +#ifndef HAVE_STRLCPY // Like the OpenBSD version, but it doesn't check for src not being a valid // C string. From f9880e84137505001b0447fa3f7f66cfe8a8bc8a Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 5 Aug 2023 14:50:12 +0300 Subject: [PATCH 002/239] Fix ban.txt crashing game --- src/d_clisrv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 727eba4ab..2656d9978 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2905,6 +2905,12 @@ void D_LoadBan(boolean warning) address = strtok(buffer, " /\t\r\n"); mask = strtok(NULL, " \t\r\n"); + if (!address) + { + malformed = true; + continue; + } + if (i == 0 && !strncmp(address, "BANFORMAT", 9)) { if (mask) From 0b55e8df7bca2510275be4c7ad1123625e867fff Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 6 Aug 2023 19:34:50 -0700 Subject: [PATCH 003/239] Rename HAVE_STRLCPY to SRB2_HAVE_STRLCPY, fix non-glibc compile - Fix compile with msvcrt - Fix compile with SDL 2.28.2 --- src/doomtype.h | 12 ++++++++---- src/string.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index f4f32edc8..27278f0cf 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -164,9 +164,13 @@ char *strcasestr(const char *in, const char *what); #define HAVE_DOSSTR_FUNCS #endif -// glibc 2.38: added strlcpy and strlcat to _DEFAULT_SOURCE -#if defined (__APPLE__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 38) -#define HAVE_STRLCPY +#if defined (__APPLE__) + #define SRB2_HAVE_STRLCPY +#elif defined (__GLIBC_PREREQ) + // glibc 2.38: added strlcpy and strlcat to _DEFAULT_SOURCE + #if __GLIBC_PREREQ(2, 38) + #define SRB2_HAVE_STRLCPY + #endif #endif #ifndef HAVE_DOSSTR_FUNCS @@ -176,7 +180,7 @@ int strlwr(char *n); // from dosstr.c #include // for size_t -#ifndef HAVE_STRLCPY +#ifndef SRB2_HAVE_STRLCPY size_t strlcat(char *dst, const char *src, size_t siz); size_t strlcpy(char *dst, const char *src, size_t siz); #endif diff --git a/src/string.c b/src/string.c index 34c5e71aa..c919ec804 100644 --- a/src/string.c +++ b/src/string.c @@ -16,7 +16,7 @@ #include #include "doomdef.h" -#ifndef HAVE_STRLCPY +#ifndef SRB2_HAVE_STRLCPY // Like the OpenBSD version, but it doesn't check for src not being a valid // C string. From 97f0ea1b0fa57f23189740523ee1f52640bea381 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 16:59:23 +0200 Subject: [PATCH 004/239] initial support https://git.do.srb2.org/haya_/Kart-Public/-/commit/a464df2165d62528af46d7ef0a6cbdbf29c3d07c --- src/d_netcmd.c | 64 ++++++++++++++++++- src/d_netcmd.h | 4 ++ src/d_player.h | 2 + src/g_game.c | 6 ++ src/hardware/hw_main.c | 32 ++++++---- src/hardware/hw_md2.c | 60 +++++++++++++----- src/hardware/hw_md2.h | 3 +- src/p_enemy.c | 1 + src/p_mobj.c | 10 +++ src/p_mobj.h | 2 + src/p_setup.c | 8 +-- src/p_setup.h | 2 +- src/r_draw.c | 55 ++++++++++++---- src/r_draw.h | 2 + src/r_things.c | 140 ++++++++++++++++++++++++++++++++--------- src/r_things.h | 6 +- src/st_stuff.c | 19 ++++++ src/st_stuff.h | 1 + 18 files changed, 338 insertions(+), 79 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index cb2123e45..007d62949 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -110,6 +110,10 @@ static void Skin_OnChange(void); static void Skin2_OnChange(void); static void Skin3_OnChange(void); static void Skin4_OnChange(void); +static void Localskin_OnChange(void); +static void Localskin2_OnChange(void); +static void Localskin3_OnChange(void); +static void Localskin4_OnChange(void); static void Color_OnChange(void); static void Color2_OnChange(void); static void Color3_OnChange(void); @@ -141,6 +145,7 @@ static void Command_SetViews_f(void); static void Command_Addfilelocal(void); static void Command_Addfile(void); +static void Command_Addskins(void); static void Command_ListWADS_f(void); #ifdef DELFILE static void Command_Delfile(void); @@ -289,6 +294,11 @@ consvar_t cv_skin = {"skin", DEFAULTSKIN, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin_ consvar_t cv_skin2 = {"skin2", DEFAULTSKIN2, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin2_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skin3 = {"skin3", DEFAULTSKIN3, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin3_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skin4 = {"skin4", DEFAULTSKIN4, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin4_OnChange, 0, NULL, NULL, 0, 0, NULL}; +// haha I've beaten you now, ONLINE +consvar_t cv_localskin = {"localskin", "none", CV_CALL|CV_NOINIT, NULL, Localskin_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin2 = {"localskin2", "none", CV_CALL|CV_NOINIT, NULL, Localskin2_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin3 = {"localskin3", "none", CV_CALL|CV_NOINIT, NULL, Localskin3_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin4 = {"localskin4", "none", CV_CALL|CV_NOINIT, NULL, Localskin4_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -643,6 +653,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("addfilelocal", Command_Addfilelocal); COM_AddCommand("addfile", Command_Addfile); + COM_AddCommand("addskins", Command_Addskins); COM_AddCommand("listwad", Command_ListWADS_f); #ifdef DELFILE @@ -885,18 +896,22 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_playername); CV_RegisterVar(&cv_playercolor); CV_RegisterVar(&cv_skin); // r_things.c (skin NAME) + CV_RegisterVar(&cv_localskin); // secondary player (splitscreen) CV_RegisterVar(&cv_playername2); CV_RegisterVar(&cv_playercolor2); CV_RegisterVar(&cv_skin2); + CV_RegisterVar(&cv_localskin2); // third player CV_RegisterVar(&cv_playername3); CV_RegisterVar(&cv_playercolor3); CV_RegisterVar(&cv_skin3); + CV_RegisterVar(&cv_localskin3); // fourth player CV_RegisterVar(&cv_playername4); CV_RegisterVar(&cv_playercolor4); CV_RegisterVar(&cv_skin4); + CV_RegisterVar(&cv_localskin4); // preferred number of players CV_RegisterVar(&cv_splitplayers); @@ -4564,7 +4579,7 @@ static void Command_Addfile(void) // Add file on your client directly if it is trivial, or you aren't in a netgame. if (!(netgame || multiplayer) || musiconly) { - P_AddWadFile(fn); + P_AddWadFile(fn, false); return; } @@ -4613,6 +4628,20 @@ static void Command_Addfile(void) SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); } +/** Adds something at runtime. + */ +static void +Command_Addskins (void) +{ + if (COM_Argc() != 2) + { + CONS_Printf( + "addskins : load skins bro\n"); + return; + } + P_AddWadFile(COM_Argv(1), true); +} + #ifdef DELFILE /** removes the last added pwad at runtime. * Searches for sounds, maps, music and images to remove @@ -4769,7 +4798,7 @@ static void Got_Addfilecmd(UINT8 **cp, INT32 playernum) ncs = findfile(filename,md5sum,true); - if (ncs != FS_FOUND || !P_AddWadFile(filename)) + if (ncs != FS_FOUND || !P_AddWadFile(filename, false)) { Command_ExitGame_f(); if (ncs == FS_FOUND) @@ -5925,6 +5954,37 @@ static void Command_ListSkins(void) } } +/** bruh + */ +static void Localskin_OnChange(void) +{ + if (!Playing()) + return; // do whatever you want + SetLocalPlayerSkin(consoleplayer, cv_localskin.string, &cv_localskin); +} + +/** two bruh machine gun + */ +static void Localskin2_OnChange(void) +{ + if (!Playing()) + return; // do whatever you want + SetLocalPlayerSkin(displayplayers[1], cv_localskin2.string, &cv_localskin2); +} + +static void Localskin3_OnChange(void) +{ + if (!Playing()) + return; // do whatever you want + SetLocalPlayerSkin(displayplayers[2], cv_localskin3.string, &cv_localskin3); +} + +static void Localskin4_OnChange(void) +{ + if (!Playing()) + return; // do whatever you want + SetLocalPlayerSkin(displayplayers[3], cv_localskin4.string, &cv_localskin4); +} /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange diff --git a/src/d_netcmd.h b/src/d_netcmd.h index e999a202e..9cf7c2e5d 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -21,18 +21,22 @@ extern consvar_t cv_playername; extern consvar_t cv_playercolor; extern consvar_t cv_skin; +extern consvar_t cv_localskin; // secondary splitscreen player extern consvar_t cv_playername2; extern consvar_t cv_playercolor2; extern consvar_t cv_skin2; +extern consvar_t cv_localskin2; // third splitscreen player extern consvar_t cv_playername3; extern consvar_t cv_playercolor3; extern consvar_t cv_skin3; +extern consvar_t cv_localskin3; // fourth splitscreen player extern consvar_t cv_playername4; extern consvar_t cv_playercolor4; extern consvar_t cv_skin4; +extern consvar_t cv_localskin4; // preferred number of players extern consvar_t cv_splitplayers; diff --git a/src/d_player.h b/src/d_player.h index d7bfb80eb..1479b3a9f 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -415,6 +415,8 @@ typedef struct player_s UINT8 skincolor; INT32 skin; + INT32 localskin; + boolean skinlocal; UINT32 score; // player score fixed_t dashspeed; // dashing speed diff --git a/src/g_game.c b/src/g_game.c index 0cb897b52..d17434f4e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2702,6 +2702,8 @@ void G_PlayerReborn(INT32 player) UINT8 mare; UINT8 skincolor; INT32 skin; + int localskin; + boolean skinlocal; tic_t jointime; UINT8 splitscreenindex; boolean spectator; @@ -2748,6 +2750,8 @@ void G_PlayerReborn(INT32 player) skincolor = players[player].skincolor; skin = players[player].skin; + localskin = players[player].localskin; + skinlocal = players[player].skinlocal; // SRB2kart kartspeed = players[player].kartspeed; kartweight = players[player].kartweight; @@ -2837,6 +2841,8 @@ void G_PlayerReborn(INT32 player) // save player config truth reborn p->skincolor = skincolor; p->skin = skin; + p->localskin = localskin; + p->skinlocal = skinlocal; // SRB2kart p->kartspeed = kartspeed; p->kartweight = kartweight; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 834f617bf..adfd08cff 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3825,7 +3825,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) FOutVector baseWallVerts[4]; // This is what the verts should end up as GLPatch_t *gpatch; FSurfaceInfo Surf; - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)spr->mobj->skin)->flags & SF_HIRES); + const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); extracolormap_t *colormap; FUINT lightlevel; FBITFIELD blend = 0; @@ -3849,7 +3849,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) this_scale = FIXED_TO_FLOAT(spr->mobj->scale); if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)spr->mobj->skin)->highresscale); + this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); @@ -4171,11 +4171,11 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) FOutVector wallVerts[4]; GLPatch_t *gpatch; // sprite patch converted to hardware FSurfaceInfo Surf; - const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)spr->mobj->skin)->flags & SF_HIRES); + const boolean hires = (spr->mobj && spr->mobj->skin && ((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->flags & SF_HIRES); if (spr->mobj) this_scale = FIXED_TO_FLOAT(spr->mobj->scale); if (hires) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)spr->mobj->skin)->highresscale); + this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->highresscale); if (!spr->mobj) return; @@ -4722,8 +4722,19 @@ void HWR_DrawSprites(void) else if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { + md2_t *md2; + if (spr->mobj->localskin) + { + if (spr->mobj->skinlocal) + md2 = &md2_localplayermodels[(skin_t *)spr->mobj->localskin - localskins]; + else + md2 = &md2_playermodels [(skin_t *)spr->mobj->localskin - skins]; + } + else + md2 = &md2_playermodels[(skin_t *)spr->mobj->skin - skins]; + // 8/1/19: Only don't display player models if no default SPR_PLAY is found. - if (!cv_grmdls.value || ((md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound || md2_playermodels[(skin_t*)spr->mobj->skin-skins].scale < 0.0f) && ((!cv_grfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) + if (!cv_grmdls.value || ((md2->notfound || md2->scale < 0.0f) && ((!cv_grfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) HWR_DrawSprite(spr); else HWR_DrawMD2(spr); @@ -4970,7 +4981,7 @@ void HWR_ProjectSprite(mobj_t *thing) //Fab : 02-08-98: 'skin' override spritedef currently used for skin if (thing->skin && thing->sprite == SPR_PLAY) { - sprdef = &((skin_t *)thing->skin)->spritedef; + sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE sprinfo = &spriteinfo[thing->sprite]; #endif @@ -5045,8 +5056,8 @@ void HWR_ProjectSprite(mobj_t *thing) } } - if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) - this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)thing->skin)->highresscale); + if (thing->skin && ((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->flags & SF_HIRES) + this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->highresscale); spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; @@ -5205,10 +5216,7 @@ void HWR_ProjectSprite(mobj_t *thing) if (thing->colorized) vis->colormap = R_GetTranslationColormap(TC_RAINBOW, thing->color, GTC_CACHE); else if (thing->skin && thing->sprite == SPR_PLAY) // This thing is a player! - { - size_t skinnum = (skin_t*)thing->skin-skins; - vis->colormap = R_GetTranslationColormap((INT32)skinnum, thing->color, GTC_CACHE); - } + vis->colormap = R_GetLocalTranslationColormap(thing->skin, thing->localskin, thing->color, GTC_CACHE, thing->skinlocal); else vis->colormap = R_GetTranslationColormap(TC_DEFAULT, thing->color, GTC_CACHE); } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index ce7ee8d9f..140c42c1f 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -75,6 +75,7 @@ md2_t md2_models[NUMSPRITES]; md2_t md2_playermodels[MAXSKINS]; +md2_t md2_localplayermodels[MAXSKINS]; /* @@ -487,6 +488,13 @@ void HWR_InitMD2(void) md2_playermodels[s].skin = -1; md2_playermodels[s].notfound = true; md2_playermodels[s].error = false; + + md2_localplayermodels[s].scale = -1.0f; + md2_localplayermodels[s].model = NULL; + md2_localplayermodels[s].grpatch = NULL; + md2_localplayermodels[s].skin = -1; + md2_localplayermodels[s].notfound = true; + md2_localplayermodels[s].error = false; } for (i = 0; i < NUMSPRITES; i++) { @@ -559,11 +567,12 @@ md2found: fclose(f); } -void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup +void HWR_AddPlayerMD2(int skin, boolean local) // For MD2's that were added after startup { FILE *f; char name[20], filename[32]; float scale, offset; + md2_t *md2s; if (nomd2s) return; @@ -585,22 +594,23 @@ void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup } } - // Check for any MD2s that match the names of sprite names! + md2s = ( (local) ? md2_localplayermodels : md2_playermodels ); + // Check for any MD2s that match the names of player skins! while (fscanf(f, "%19s %31s %f %f", name, filename, &scale, &offset) == 4) { - if (stricmp(name, skins[skin].name) == 0) + if (stricmp(name, ( (local) ? localskins : skins )[skin].name) == 0) { - md2_playermodels[skin].skin = skin; - md2_playermodels[skin].scale = scale; - md2_playermodels[skin].offset = offset; - md2_playermodels[skin].notfound = false; - strcpy(md2_playermodels[skin].filename, filename); + md2s[skin].skin = skin; + md2s[skin].scale = scale; + md2s[skin].offset = offset; + md2s[skin].notfound = false; + strcpy(md2s[skin].filename, filename); goto playermd2found; } } //CONS_Printf("MD2 for player skin %s not found\n", skins[skin].name); - md2_playermodels[skin].notfound = true; + md2s[skin].notfound = true; playermd2found: fclose(f); } @@ -1154,6 +1164,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) { R_InterpolateMobjState(spr->mobj, FRACUNIT, &interp); } + md2_t *md2s; + int skinnum; // Apparently people don't like jump frames like that, so back it goes //if (tics > durs) @@ -1168,13 +1180,33 @@ void HWR_DrawMD2(gr_vissprite_t *spr) // dont forget to enabled the depth test because we can't do this like // before: polygons models are not sorted + + /* fuck you */ + if (spr->mobj->localskin) + { + if (spr->mobj->skinlocal) + { + md2s = md2_localplayermodels; + skinnum = (skin_t *)spr->mobj->localskin - localskins; + } + else + { + md2s = md2_playermodels; + skinnum = (skin_t *)spr->mobj->localskin - skins; + } + } + else + { + md2s = md2_playermodels; + skinnum = (skin_t *)spr->mobj->skin - skins; + } // 1. load model+texture if not already loaded // 2. draw model with correct position, rotation,... - if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY && !md2_playermodels[(skin_t*)spr->mobj->skin-skins].notfound) // Use the player MD2 list if the mobj has a skin and is using the player sprites + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY && !md2s[skinnum].notfound) // Use the player MD2 list if the mobj has a skin and is using the player sprites { - md2 = &md2_playermodels[(skin_t*)spr->mobj->skin-skins]; - md2->skin = (skin_t*)spr->mobj->skin-skins; + md2 = &md2s[skinnum]; + md2->skin = skinnum; sprinfo = &spriteinfo[spr->mobj->sprite]; } else @@ -1239,7 +1271,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) skinnum = TC_RAINBOW; else { - skinnum = (INT32)((skin_t*)spr->mobj->skin-skins); + skinnum = (INT32)((skin_t*)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ) - ( (spr->mobj->skinlocal) ? localskins : skins )); } } else skinnum = TC_DEFAULT; @@ -1306,7 +1338,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) p.z = FIXED_TO_FLOAT(interp.z); if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) - sprdef = &((skin_t *)spr->mobj->skin)->spritedef; + sprdef = &((skin_t *)( (spr->mobj->localskin) ? spr->mobj->localskin : spr->mobj->skin ))->spritedef; else sprdef = &sprites[spr->mobj->sprite]; diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index fab8e6ad9..a6f06428e 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -37,10 +37,11 @@ typedef struct extern md2_t md2_models[NUMSPRITES]; extern md2_t md2_playermodels[MAXSKINS]; +extern md2_t md2_localplayermodels[MAXSKINS]; void HWR_InitMD2(void); void HWR_DrawMD2(gr_vissprite_t *spr); -void HWR_AddPlayerMD2(INT32 skin); +void HWR_AddPlayerMD2(INT32 skin, boolean local); void HWR_AddSpriteMD2(size_t spritenum); #endif // _HW_MD2_H_ diff --git a/src/p_enemy.c b/src/p_enemy.c index 01b1e8f56..a25999f1f 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2608,6 +2608,7 @@ void A_MonitorPop(mobj_t *actor) remains->fuse = actor->fuse; // Transfer respawn timer remains->threshold = 68; remains->skin = NULL; + remains->localskin = NULL; P_SetTarget(&tmthing, remains); diff --git a/src/p_mobj.c b/src/p_mobj.c index 8aa726870..204532ea2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10772,6 +10772,16 @@ void P_SpawnPlayer(INT32 playernum) // (usefulness: when body mobj is detached from player (who respawns), // the dead body mobj retains the skin through the 'spritedef' override). mobj->skin = &skins[p->skin]; + if (p->localskin > 0) + { + if (p->skinlocal) + mobj->localskin = &localskins[p->localskin - 1]; + else + mobj->localskin = & skins[p->localskin - 1]; + } + else + mobj->localskin = 0; + mobj->skinlocal = p->skinlocal; mobj->health = p->health; p->playerstate = PST_LIVE; diff --git a/src/p_mobj.h b/src/p_mobj.h index 004a437c4..67a579c11 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -327,6 +327,8 @@ typedef struct mobj_s UINT16 eflags; // extra flags void *skin; // overrides 'sprite' when non-NULL (for player bodies to 'remember' the skin) + void *localskin; + boolean skinlocal; // Player and mobj sprites in multiplayer modes are modified // using an internal color lookup table for re-indexing. UINT8 color; // This replaces MF_TRANSLATION. Use 0 for default (no translation). diff --git a/src/p_setup.c b/src/p_setup.c index f0bf34c9f..978df4066 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3433,7 +3433,7 @@ boolean P_RunSOC(const char *socfilename) lumpnum_t lump; if (strstr(socfilename, ".soc") != NULL) - return P_AddWadFile(socfilename); + return P_AddWadFile(socfilename, false); lump = W_CheckNumForName(socfilename); if (lump == LUMPERROR) @@ -3449,11 +3449,11 @@ boolean P_RunSOC(const char *socfilename) // Add a wadfile to the active wad files, // replace sounds, musics, patches, textures, sprites and maps // -boolean P_AddWadFile(const char *wadfilename) +boolean P_AddWadFile(const char *wadfilename, boolean local) { UINT16 wadnum; - if ((wadnum = P_PartialAddWadFile(wadfilename, false)) == UINT16_MAX) + if ((wadnum = P_PartialAddWadFile(wadfilename, local)) == UINT16_MAX) return false; P_MultiSetupWadFiles(true); @@ -3545,7 +3545,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // // look for skins // - R_AddSkins(wadnum); // faB: wadfile index in wadfiles[] + R_AddSkins(wadnum, local); // faB: wadfile index in wadfiles[] // // edit music defs diff --git a/src/p_setup.h b/src/p_setup.h index 99269da00..728549943 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -60,7 +60,7 @@ void P_ScanThings(INT16 mapnum, INT16 wadnum, INT16 lumpnum); #endif void P_LoadThingsOnly(void); boolean P_SetupLevel(boolean skipprecip); -boolean P_AddWadFile(const char *wadfilename); +boolean P_AddWadFile(const char *wadfilename, boolean local); boolean P_AddWadFileLocal(const char *wadfilename); #ifdef DELFILE boolean P_DelWadFile(void); diff --git a/src/r_draw.c b/src/r_draw.c index a29c26a3c..88fa75e7f 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -18,6 +18,7 @@ #include "doomdef.h" #include "doomstat.h" #include "r_local.h" +#include "r_things.h" #include "st_stuff.h" // need ST_HEIGHT #include "i_video.h" #include "v_video.h" @@ -141,6 +142,7 @@ UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask; #define NUM_PALETTE_ENTRIES 256 static UINT8** translationtablecache[TT_CACHE_SIZE] = {NULL}; +static UINT8** localtranslationtablecache[MAXSKINS] = {NULL}; // See also the enum skincolors_t @@ -519,29 +521,39 @@ static void R_GenerateTranslationColormap(UINT8 *dest_colormap, INT32 skinnum, U \return Colormap. If not cached, caller should Z_Free. */ -UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags) +static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags, boolean local) { + UINT8 ***tt; UINT8* ret; INT32 skintableindex; - // Adjust if we want the default colormap - if (skinnum == TC_DEFAULT) skintableindex = DEFAULT_TT_CACHE_INDEX; - else if (skinnum == TC_BOSS) skintableindex = BOSS_TT_CACHE_INDEX; - else if (skinnum == TC_METALSONIC) skintableindex = METALSONIC_TT_CACHE_INDEX; - else if (skinnum == TC_ALLWHITE) skintableindex = ALLWHITE_TT_CACHE_INDEX; - else if (skinnum == TC_RAINBOW) skintableindex = RAINBOW_TT_CACHE_INDEX; - else if (skinnum == TC_BLINK) skintableindex = BLINK_TT_CACHE_INDEX; - else skintableindex = skinnum; + if (local) + { + tt = localtranslationtablecache; + skintableindex = skinnum; + } + else + { + tt = translationtablecache; + // Adjust if we want the default colormap + if (skinnum == TC_DEFAULT) skintableindex = DEFAULT_TT_CACHE_INDEX; + else if (skinnum == TC_BOSS) skintableindex = BOSS_TT_CACHE_INDEX; + else if (skinnum == TC_METALSONIC) skintableindex = METALSONIC_TT_CACHE_INDEX; + else if (skinnum == TC_ALLWHITE) skintableindex = ALLWHITE_TT_CACHE_INDEX; + else if (skinnum == TC_RAINBOW) skintableindex = RAINBOW_TT_CACHE_INDEX; + else if (skinnum == TC_BLINK) skintableindex = BLINK_TT_CACHE_INDEX; + else skintableindex = skinnum; + } if (flags & GTC_CACHE) { // Allocate table for skin if necessary - if (!translationtablecache[skintableindex]) - translationtablecache[skintableindex] = Z_Calloc(MAXTRANSLATIONS * sizeof(UINT8**), PU_STATIC, NULL); + if (!tt[skintableindex]) + tt[skintableindex] = Z_Calloc(MAXTRANSLATIONS * sizeof(UINT8**), PU_STATIC, NULL); // Get colormap - ret = translationtablecache[skintableindex][color]; + ret = tt[skintableindex][color]; } else ret = NULL; @@ -553,12 +565,25 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags) // Cache the colormap if desired if (flags & GTC_CACHE) - translationtablecache[skintableindex][color] = ret; + tt[skintableindex][color] = ret; } return ret; } +UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags) +{ + return RGetTranslationColormap(skinnum, color, flags, false); +} + +UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local) +{ + if (localskin) + return RGetTranslationColormap(( localskin - ( (local) ? localskins : skins ) ), color, flags, local); + else + return RGetTranslationColormap(( skin - skins ), color, flags, false); +} + /** \brief Flushes cache of translation colormaps. Flushes cache of translation colormaps, but doesn't actually free the @@ -574,6 +599,10 @@ void R_FlushTranslationColormapCache(void) for (i = 0; i < (INT32)(sizeof(translationtablecache) / sizeof(translationtablecache[0])); i++) if (translationtablecache[i]) memset(translationtablecache[i], 0, MAXTRANSLATIONS * sizeof(UINT8**)); + + for (i = 0; i < (INT32)(sizeof(localtranslationtablecache) / sizeof(localtranslationtablecache[0])); i++) + if (localtranslationtablecache[i]) + memset(localtranslationtablecache[i], 0, MAXTRANSLATIONS * sizeof(UINT8**)); } /* diff --git a/src/r_draw.h b/src/r_draw.h index b6d72fe71..c35c95ea4 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -15,6 +15,7 @@ #define __R_DRAW__ #include "r_defs.h" +#include "r_things.h" // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp @@ -115,6 +116,7 @@ extern lumpnum_t viewborderlump[8]; // Initialize color translation tables, for player rendering etc. 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); void R_FlushTranslationColormapCache(void); UINT8 R_GetColorByName(const char *name); diff --git a/src/r_things.c b/src/r_things.c index 26dad2f0b..0a2644c06 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -643,7 +643,7 @@ 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++) - R_AddSkins((UINT16)i); + R_AddSkins((UINT16)i, false); // // check if all sprites have frames @@ -872,10 +872,7 @@ static void R_DrawVisSprite(vissprite_t *vis) if (vis->mobj->colorized) dc_translation = R_GetTranslationColormap(TC_RAINBOW, vis->mobj->color, GTC_CACHE); else if (vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // MT_GHOST LOOKS LIKE A PLAYER SO USE THE PLAYER TRANSLATION TABLES. >_> - { - size_t skinnum = (skin_t*)vis->mobj->skin-skins; - dc_translation = R_GetTranslationColormap((INT32)skinnum, vis->mobj->color, GTC_CACHE); - } + dc_translation = R_GetLocalTranslationColormap(vis->mobj->skin, vis->mobj->localskin, vis->mobj->color, GTC_CACHE, vis->mobj->skinlocal); else // Use the defaults dc_translation = R_GetTranslationColormap(TC_DEFAULT, vis->mobj->color, GTC_CACHE); } @@ -893,10 +890,7 @@ static void R_DrawVisSprite(vissprite_t *vis) if (vis->mobj->colorized) dc_translation = R_GetTranslationColormap(TC_RAINBOW, vis->mobj->color, GTC_CACHE); else if (vis->mobj->skin && vis->mobj->sprite == SPR_PLAY) // This thing is a player! - { - size_t skinnum = (skin_t*)vis->mobj->skin-skins; - dc_translation = R_GetTranslationColormap((INT32)skinnum, vis->mobj->color, GTC_CACHE); - } + dc_translation = R_GetLocalTranslationColormap(vis->mobj->skin, vis->mobj->localskin, vis->mobj->color, GTC_CACHE, vis->mobj->skinlocal); else // Use the defaults dc_translation = R_GetTranslationColormap(TC_DEFAULT, vis->mobj->color, GTC_CACHE); } @@ -925,7 +919,9 @@ static void R_DrawVisSprite(vissprite_t *vis) frac = vis->startfrac; windowtop = windowbottom = sprbotscreen = INT32_MAX; - if (vis->mobj->skin && ((skin_t *)vis->mobj->skin)->flags & SF_HIRES) + if (vis->mobj->localskin && ((skin_t *)vis->mobj->localskin)->flags & SF_HIRES) + this_scale = FixedMul(this_scale, ((skin_t *)vis->mobj->localskin)->highresscale); + else if (vis->mobj->skin && ((skin_t *)vis->mobj->skin)->flags & SF_HIRES) this_scale = FixedMul(this_scale, ((skin_t *)vis->mobj->skin)->highresscale); if (this_scale <= 0) this_scale = 1; @@ -1274,7 +1270,7 @@ static void R_ProjectSprite(mobj_t *thing) //Fab : 02-08-98: 'skin' override spritedef currently used for skin if (thing->skin && thing->sprite == SPR_PLAY) { - sprdef = &((skin_t *)thing->skin)->spritedef; + sprdef = &((skin_t *)( (thing->localskin) ? thing->localskin : thing->skin ))->spritedef; #ifdef ROTSPRITE sprinfo = &spriteinfo[thing->sprite]; #endif @@ -1348,7 +1344,9 @@ static void R_ProjectSprite(mobj_t *thing) I_Assert(lump < max_spritelumps); - if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) + 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) this_scale = FixedMul(this_scale, ((skin_t *)thing->skin)->highresscale); spr_width = spritecachedinfo[lump].width; @@ -2784,6 +2782,7 @@ void R_DrawMasked(void) // ========================================================================== INT32 numskins = 0; +INT32 numlocalskins = 0; skin_t skins[MAXSKINS]; UINT8 skinstats[9][9][MAXSKINS]; UINT8 skinstatscount[9][9] = { @@ -2798,13 +2797,15 @@ UINT8 skinstatscount[9][9] = { {0, 0, 0, 0, 0, 0, 0, 0, 0} }; UINT8 skinsorted[MAXSKINS]; +skin_t localskins[MAXSKINS]; // FIXTHIS: don't work because it must be inistilised before the config load //#define SKINVALUES #ifdef SKINVALUES CV_PossibleValue_t skin_cons_t[MAXSKINS+1]; +CV_PossibleValue_t localskin_cons_t[MAXSKINS+1]; #endif -static void Sk_SetDefaultValue(skin_t *skin) +static void Sk_SetDefaultValue(skin_t *skin, boolean local) { INT32 i; // @@ -2812,7 +2813,7 @@ static void Sk_SetDefaultValue(skin_t *skin) // memset(skin, 0, sizeof (skin_t)); snprintf(skin->name, - sizeof skin->name, "skin %u", (UINT32)(skin-skins)); + sizeof skin->name, "skin %u", (UINT32)(skin-( (local) ? localskins : skins ))); skin->name[sizeof skin->name - 1] = '\0'; skin->wadnum = INT16_MAX; strcpy(skin->sprite, ""); @@ -2853,13 +2854,15 @@ void R_InitSkins(void) { skin_cons_t[i].value = 0; skin_cons_t[i].strvalue = NULL; + localskin_cons_t[i].value = 0; + localskin_cons_t[i].strvalue = NULL; } #endif // skin[0] = Sonic skin skin = &skins[0]; numskins = 1; - Sk_SetDefaultValue(skin); + Sk_SetDefaultValue(skin, false); memset(skinstats, 0, sizeof(skinstats)); memset(skinsorted, 0, sizeof(skinsorted)); @@ -2893,7 +2896,7 @@ void R_InitSkins(void) //MD2 for sonic doesn't want to load in Linux. #ifdef HWRENDER if (rendermode == render_opengl) - HWR_AddPlayerMD2(0); + HWR_AddPlayerMD2(0, false); #endif } @@ -2911,6 +2914,23 @@ INT32 R_SkinAvailable(const char *name) return -1; } +INT32 R_LocalSkinAvailable(const char *name, boolean local) +{ + INT32 i; + + if (local) + { + for (i = 0; i < numlocalskins; i++) + { + if (stricmp(localskins[i].name,name)==0) + return i; + } + return -1; + } + else + return R_SkinAvailable(name); +} + // network code calls this when a 'skin change' is received boolean SetPlayerSkin(INT32 playernum, const char *skinname) { @@ -2936,6 +2956,61 @@ boolean SetPlayerSkin(INT32 playernum, const char *skinname) return false; } +void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) +{ + player_t *player = &players[playernum]; + INT32 i; + + if (strcasecmp(skinname, "none")) + { + for (i = 0; i < numlocalskins; i++) + { + // search in the skin list + if (stricmp(localskins[i].name, skinname) == 0) + { + player->localskin = 1 + i; + player->skinlocal = true; + if (player->mo) + { + player->mo->localskin = &localskins[i]; + player->mo->skinlocal = true; + } + break; + } + } + for (i = 0; i < numskins; i++) + { + // search in the skin list + if (stricmp(skins[i].name, skinname) == 0) + { + player->localskin = 1 + i; + player->skinlocal = false; + if (player->mo) + { + player->mo->localskin = &skins[i]; + player->mo->skinlocal = false; + } + break; + } + } + } + else + { + player->localskin = 0; + player->skinlocal = false; + if (player->mo) + { + player->mo->localskin = 0; + player->mo->skinlocal = false; + } + } + + if (player->localskin > 0) + CV_StealthSet(cvar, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name); + else + CV_StealthSet(cvar, "none"); +} + // Same as SetPlayerSkin, but uses the skin #. // network code calls this when a 'skin change' is received void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum) @@ -3120,7 +3195,7 @@ void sortSkinGrid(void) // // Find skin sprites, sounds & optional status bar face, & add them // -void R_AddSkins(UINT16 wadnum) +void R_AddSkins(UINT16 wadnum, boolean local) { UINT16 lump, lastlump = 0; char *buf; @@ -3140,7 +3215,7 @@ void R_AddSkins(UINT16 wadnum) // advance by default lastlump = lump + 1; - if (numskins >= MAXSKINS) + if (( (local) ? numlocalskins : numskins ) >= MAXSKINS) { CONS_Alert(CONS_WARNING, M_GetText("Unable to add skin, too many characters are loaded (%d maximum)\n"), MAXSKINS); continue; // so we know how many skins couldn't be added @@ -3156,8 +3231,8 @@ void R_AddSkins(UINT16 wadnum) buf2[size] = '\0'; // set defaults - skin = &skins[numskins]; - Sk_SetDefaultValue(skin); + skin = &( (local) ? localskins : skins )[( (local) ? numlocalskins : numskins )]; + Sk_SetDefaultValue(skin, local); skin->wadnum = wadnum; hudname = realname = false; // parse @@ -3181,7 +3256,7 @@ void R_AddSkins(UINT16 wadnum) // the skin name must uniquely identify a single skin // I'm lazy so if name is already used I leave the 'skin x' // default skin name set in Sk_SetDefaultValue - if (R_SkinAvailable(value) == -1) + if (R_LocalSkinAvailable(value, local) == -1) { STRBUFCPY(skin->name, value); strlwr(skin->name); @@ -3191,12 +3266,12 @@ void R_AddSkins(UINT16 wadnum) else { const size_t stringspace = - strlen(value) + sizeof (numskins) + 1; + strlen(value) + sizeof (( (local) ? numlocalskins : numskins )) + 1; char *value2 = Z_Malloc(stringspace, PU_STATIC, NULL); snprintf(value2, stringspace, - "%s%d", value, numskins); + "%s%d", value, ( (local) ? numlocalskins : numskins )); value2[stringspace - 1] = '\0'; - if (R_SkinAvailable(value2) == -1) + if (R_LocalSkinAvailable(value2, local) == -1) { STRBUFCPY(skin->name, value2); @@ -3379,20 +3454,23 @@ next_token: CONS_Printf(M_GetText("Added skin '%s'\n"), skin->name); #ifdef SKINVALUES - skin_cons_t[numskins].value = numskins; - skin_cons_t[numskins].strvalue = skin->name; + ( (local) ? localskin_cons_t : skin_cons_t )[( (local) ? numlocalskins : numskins )].value = ( (local) ? numlocalskins : numskins ); + ( (local) ? localskin_cons_t : skin_cons_t )[( (local) ? numlocalskins : numskins )].strvalue = skin->name; #endif // Update the forceskin possiblevalues - Forceskin_cons_t[numskins+1].value = numskins; - Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; + if (! local) + { + Forceskin_cons_t[numskins+1].value = numskins; + Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; + } // add face graphics - ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins); + ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins, local); #ifdef HWRENDER if (rendermode == render_opengl) - HWR_AddPlayerMD2(numskins); + HWR_AddPlayerMD2(( (local) ? numlocalskins : numskins ), local); #endif skinstats[skin->kartspeed-1][skin->kartweight-1][skinstatscount[skin->kartspeed-1][skin->kartweight-1]] = numskins; CONS_Debug(DBG_SETUP, M_GetText("Added %d to %d, %d\n"), numskins, skin->kartweight, skin->kartweight); @@ -3401,7 +3479,7 @@ next_token: skinsorted[numskins] = numskins; - numskins++; + ( (local) ? numlocalskins++ : numskins++ ); } sortSkinGrid(); diff --git a/src/r_things.h b/src/r_things.h index ab4688f91..5d7076f10 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -201,17 +201,21 @@ typedef struct drawnode_s } drawnode_t; extern INT32 numskins; +extern INT32 numlocalskins; extern skin_t skins[MAXSKINS]; extern UINT8 skinstats[9][9][MAXSKINS]; extern UINT8 skinstatscount[9][9]; extern UINT8 skinsorted[MAXSKINS]; void sortSkinGrid(void); +extern skin_t localskins[MAXSKINS]; boolean SetPlayerSkin(INT32 playernum,const char *skinname); void SetPlayerSkinByNum(INT32 playernum,INT32 skinnum); // Tails 03-16-2002 +void SetLocalPlayerSkin(INT32 playernum,const char *skinname, consvar_t *cvar); INT32 R_SkinAvailable(const char *name); -void R_AddSkins(UINT16 wadnum); +INT32 R_LocalSkinAvailable(const char *name, boolean local); +void R_AddSkins(UINT16 wadnum, boolean local); #ifdef DELFILE void R_DelSkins(UINT16 wadnum); diff --git a/src/st_stuff.c b/src/st_stuff.c index 966a0c9c6..949ff4bac 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -58,6 +58,10 @@ patch_t *facerankprefix[MAXSKINS]; // ranking patch_t *facewantprefix[MAXSKINS]; // wanted patch_t *facemmapprefix[MAXSKINS]; // minimap +patch_t *localfacerankprefix[MAXSKINS]; // ranking +patch_t *localfacewantprefix[MAXSKINS]; // wanted +patch_t *localfacemmapprefix[MAXSKINS]; // minimap + // ------------------------------------------ // status bar overlay // ------------------------------------------ @@ -380,12 +384,27 @@ void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skin facemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); } +void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skinnum, boolean local) +{ + if (local) + { + localfacerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); + localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); + localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); + } + else + ST_LoadFaceGraphics(rankstr, wantstr, mmapstr, skinnum); +} + void ST_ReloadSkinFaceGraphics(void) { INT32 i; for (i = 0; i < numskins; i++) ST_LoadFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); + + for (i = 0; i < numlocalskins; i++) + ST_LoadLocalFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i, true); } static inline void ST_InitData(void) diff --git a/src/st_stuff.h b/src/st_stuff.h index 0f8722720..1478655ca 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -51,6 +51,7 @@ void ST_LoadGraphics(void); // face load graphics, called when skin changes void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 playernum); +void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 playernum, boolean local); void ST_ReloadSkinFaceGraphics(void); #ifdef DELFILE void ST_UnLoadFaceGraphics(INT32 skinnum); From 6e55d8881614638877d5ed89b488876bcf8292c9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:02:05 +0200 Subject: [PATCH 005/239] more shit https://git.do.srb2.org/haya_/Kart-Public/-/commit/28fa3039c147d7b479b8d4ddfca50918c620aa2f --- src/k_kart.c | 4 ++-- src/k_kart.h | 2 +- src/r_draw.c | 2 +- src/r_things.c | 2 +- src/st_stuff.h | 3 +++ 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 36bb9a57a..9eb3defe5 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -504,7 +504,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor) \return void */ -void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color) +void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local) { INT32 i; INT32 starttranscolor; @@ -540,7 +540,7 @@ void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color) return; } - starttranscolor = (skinnum != TC_DEFAULT) ? 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++) diff --git a/src/k_kart.h b/src/k_kart.h index b664f9c33..a7dc591f8 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -15,7 +15,7 @@ extern UINT8 colortranslations[MAXTRANSLATIONS][16]; extern const char *KartColor_Names[MAXSKINCOLORS]; 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); +void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local); UINT8 K_GetKartColorByName(const char *name); void K_RegisterKartStuff(void); diff --git a/src/r_draw.c b/src/r_draw.c index 88fa75e7f..536b478b9 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -561,7 +561,7 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f if (!ret) { ret = Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8); - K_GenerateKartColormap(ret, skinnum, color); //R_GenerateTranslationColormap(ret, skinnum, color); // SRB2kart + K_GenerateKartColormap(ret, skinnum, color, local); //R_GenerateTranslationColormap(ret, skinnum, color); // SRB2kart // Cache the colormap if desired if (flags & GTC_CACHE) diff --git a/src/r_things.c b/src/r_things.c index 0a2644c06..1eca172a7 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3466,7 +3466,7 @@ next_token: } // add face graphics - ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins, local); + ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, ( (local) ? numlocalskins : numskins ), local); #ifdef HWRENDER if (rendermode == render_opengl) diff --git a/src/st_stuff.h b/src/st_stuff.h index 1478655ca..5b3f611d9 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -79,6 +79,9 @@ extern patch_t *sboperiod; extern patch_t *facerankprefix[MAXSKINS]; // ranking extern patch_t *facewantprefix[MAXSKINS]; // wanted extern patch_t *facemmapprefix[MAXSKINS]; // minimap +extern patch_t *localfacerankprefix[MAXSKINS]; // ranking +extern patch_t *localfacewantprefix[MAXSKINS]; // wanted +extern patch_t *localfacemmapprefix[MAXSKINS]; // minimap extern patch_t *livesback; extern patch_t *ngradeletters[7]; From bc7ce5c983efe34d610e4628f25df8c201e8cbaf Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:04:40 +0200 Subject: [PATCH 006/239] "immersion" https://git.do.srb2.org/haya_/Kart-Public/-/commit/4547347e219158c1d11a6f373c9c94a7bd2ee789 --- src/k_kart.c | 26 ++++++++++++++++++-------- src/s_sound.c | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 9eb3defe5..5fc7a1bd0 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8090,7 +8090,11 @@ static boolean K_drawKartPositionFaces(void) else colormap = R_GetTranslationColormap(players[rankplayer[i]].skin, players[rankplayer[i]].mo->color, GTC_CACHE); - V_DrawMappedPatch(FACE_X, Y, V_HUDTRANS|V_SNAPTOLEFT, facerankprefix[players[rankplayer[i]].skin], colormap); + { + 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); + } #ifdef HAVE_BLUA if (LUA_HudEnabled(hud_battlebumpers)) @@ -8176,7 +8180,11 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I else colormap = R_GetTranslationColormap(players[tab[i].num].skin, players[tab[i].num].mo->color, GTC_CACHE); - V_DrawMappedPatch(x, y-4, 0, facerankprefix[players[tab[i].num].skin], colormap); + { + 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 (G_BattleGametype() && players[tab[i].num].kartstuff[k_bumper] > 0) -- not enough space for this { INT32 bumperx = x+19; @@ -8523,7 +8531,7 @@ static void K_drawKartWanted(void) if (players[battlewanted[i]].skincolor) { colormap = R_GetTranslationColormap(TC_RAINBOW, p->skincolor, GTC_CACHE); - V_DrawFixedPatch(x<skin] : facerankprefix[p->skin]), colormap); + 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); /*if (basey2) // again with 4p stuff V_DrawFixedPatch(x<skin] : facerankprefix[p->skin]), colormap);*/ } @@ -8590,6 +8598,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat // it, they wouldn't 'spawn' on the top-right side of the HUD. UINT8 skin = 0; + boolean skinlocal = mo->skinlocal; fixed_t amnumxpos, amnumypos; INT32 amxpos, amypos; @@ -8602,7 +8611,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->skin)-skins; + skin = ((skin_t*)( (mo->localskin) ? mo->localskin : mo->skin ))-( (skinlocal) ? localskins : skins ); maxx = maxy = INT32_MAX; minx = miny = INT32_MIN; @@ -8646,11 +8655,11 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((x + AutomapPic->width/2 - (facemmapprefix[skin]->width/2))<height/2 - (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, facemmapprefix[skin], FRACUNIT); + V_DrawSciencePatch(amxpos, amypos, flags, ( (skinlocal) ? localfacemmapprefix : facemmapprefix )[skin], FRACUNIT); else { UINT8 *colormap = R_GetTranslationColormap((mo->colorized) ? TC_RAINBOW : skin, mo->color, GTC_CACHE); @@ -8658,7 +8667,8 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat if (cv_minihead.value == 1) V_DrawFixedPatch(amxpos + (2 * FRACUNIT), amypos + (2 * FRACUNIT), FRACUNIT/2, flags, facemmapprefix[skin], colormap); else if (cv_minihead.value == 0) - V_DrawFixedPatch(amxpos, amypos, FRACUNIT, flags, facemmapprefix[skin], colormap); + 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_showminimapnames.value && !(modeattacking || gamestate == GS_TIMEATTACK)) { diff --git a/src/s_sound.c b/src/s_sound.c index 977d3be55..9afea7bf5 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -578,7 +578,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) if (sfx->skinsound != -1 && origin && origin->skin) { // redirect player sound to the sound in the skin table - sfx_id = ((skin_t *)origin->skin)->soundsid[sfx->skinsound]; + sfx_id = ((skin_t *)( (origin->localskin) ? origin->localskin : origin->skin ))->soundsid[sfx->skinsound]; sfx = &S_sfx[sfx_id]; } From 7ab0a808a9db885f9dad11a589f82c27447be1b0 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:05:21 +0200 Subject: [PATCH 007/239] Show which skin is the real one --- src/m_menu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 3c67d86ce..7bcde32f5 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10452,6 +10452,13 @@ static void M_DrawSetupMultiPlayerMenu(void) // draw box around guy V_DrawFill(mx + 43 - (charw/2), my+65, charw, 84, 239); + + if (setupm_skinlocal) + { + UINT8 *colmap; + colmap = R_GetTranslationColormap(setupm_fakeskin, setupm_fakecolor, GTC_MENUCACHE); + V_DrawFixedPatch(( mx + 43 - (charw/2) + 1 )< Date: Wed, 30 Aug 2023 17:08:50 +0200 Subject: [PATCH 008/239] Ghost and signpost support https://git.do.srb2.org/haya_/Kart-Public/-/commit/f07179589414b15605da14901f742342ab53de66 --- src/p_user.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 700671ef6..5130c8f55 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1696,6 +1696,8 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) ghost->fuse = ghost->info->damage; ghost->skin = mobj->skin; + ghost->localskin = mobj->localskin; + ghost->skinlocal = mobj->skinlocal; if (mobj->flags2 & MF2_OBJECTFLIP) ghost->flags |= MF2_OBJECTFLIP; @@ -1737,10 +1739,19 @@ void P_DoPlayerExit(player_t *player) if (P_IsLocalPlayer(player)) { sfxenum_t sfx_id; - if (K_IsPlayerLosing(player)) - sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_klose].skinsound]; - else - sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_kwin].skinsound]; + // fix godjjsa win sounds + if (K_IsPlayerLosing(player)) { + if (player->mo->skinlocal) + sfx_id = ((skin_t *)player->mo->localskin)->soundsid[S_sfx[sfx_klose].skinsound]; + else + sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_klose].skinsound]; + } + else { + if (player->mo->skinlocal) + sfx_id = ((skin_t *)player->mo->localskin)->soundsid[S_sfx[sfx_kwin].skinsound]; + else + sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_kwin].skinsound]; + } S_StartSound(NULL, sfx_id); } else From 65fadcf7094c44f34ce3a9243da428169aa5eb80 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:09:40 +0200 Subject: [PATCH 009/239] fix https://git.do.srb2.org/haya_/Kart-Public/-/commit/b6b3dcb3f08b470d6075c2949b2dee364afb5c99 --- src/p_enemy.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/p_enemy.c b/src/p_enemy.c index a25999f1f..1812ede5d 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4168,6 +4168,12 @@ void A_SignPlayer(mobj_t *actor) P_SetTarget(&ov->target, actor); ov->color = actor->target->player->skincolor; ov->skin = &skins[actor->target->player->skin]; + if (actor->target->skinlocal) { + // needs - 1 or else it pukes an error out + // same thing happens on p_mobj.c + ov->localskin = &localskins[actor->target->player->localskin - 1]; + ov->skinlocal = actor->target->skinlocal; + } P_SetMobjState(ov, actor->info->seestate); // S_PLAY_SIGN } From c011d09e33ce76854e69c2122eadc9695ecf4610 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:11:38 +0200 Subject: [PATCH 010/239] fix for localskins not properly saving when returning back into the titlescreen https://git.do.srb2.org/haya_/Kart-Public/-/commit/e679dfe0aa059cca68bc67da5a45c12c26dfd9ac --- src/p_setup.c | 2 +- src/w_wad.c | 15 +++++++++------ src/w_wad.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 978df4066..f47417b04 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3483,7 +3483,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) boolean mapsadded = false; lumpinfo_t *lumpinfo; - if ((numlumps = W_InitFile(wadfilename, local)) == INT16_MAX) + if ((numlumps = W_InitFile(wadfilename, 0, &wadnum, local)) == INT16_MAX) { refreshdirmenu |= REFRESHDIR_NOTLOADED; CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), wadfilename); diff --git a/src/w_wad.c b/src/w_wad.c index 31977bea8..630947fad 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -690,7 +690,7 @@ static void W_ReadFileShaders(wadfile_t *wadfile) // // Can now load dehacked files (.soc) // -UINT16 W_InitFile(const char *filename, boolean local) +UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, boolean local) { FILE *handle; lumpinfo_t *lumpinfo = NULL; @@ -743,10 +743,13 @@ UINT16 W_InitFile(const char *filename, boolean local) { if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { - CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); - if (handle) - fclose(handle); - return INT16_MAX; + if (!local) { + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); + if (handle) + fclose(handle); + return INT16_MAX; + } + CONS_Alert(CONS_WARNING, M_GetText("%s is a local skin that is already loaded\n"), filename); } } #endif @@ -898,7 +901,7 @@ INT32 W_InitMultipleFiles(char **filenames, boolean addons) G_SetGameModified(true, false); //CONS_Debug(DBG_SETUP, "Loading %s\n", *filenames); - rc = W_InitFile(*filenames, false); + rc = W_InitFile(*filenames, 0, 0, false); if (rc == INT16_MAX) CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), *filenames); overallrc &= (rc != INT16_MAX) ? 1 : 0; diff --git a/src/w_wad.h b/src/w_wad.h index 1c6e86c49..32c843580 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -132,7 +132,7 @@ FILE *W_OpenWadFile(const char **filename, boolean useerrors); // // if local is true, it wouldn't check if file adds complex things, therefore // allowing to still join server without the "you have wrong addons loaded" error -UINT16 W_InitFile(const char *filename, boolean local); +UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, boolean local); #ifdef DELFILE void W_UnloadWadFile(UINT16 num); #endif From 46c7bf8b031a0498affdcc5a5115b0aa6ee15720 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:24:50 +0200 Subject: [PATCH 011/239] fix shit https://git.do.srb2.org/haya_/Kart-Public/-/commit/e4ba8b9a753fe741f1e5a65490ae0d2d645baa97 --- src/d_netcmd.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++--- src/k_kart.c | 2 +- src/m_menu.c | 22 +++++++++++++-- src/r_things.c | 8 ++++-- src/st_stuff.c | 19 +++++++------ src/st_stuff.h | 2 +- 6 files changed, 105 insertions(+), 20 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 007d62949..41287dcbb 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -146,6 +146,10 @@ static void Command_SetViews_f(void); static void Command_Addfilelocal(void); static void Command_Addfile(void); static void Command_Addskins(void); +static void Command_Localskin1(void); +static void Command_Localskin2(void); +static void Command_Localskin3(void); +static void Command_Localskin4(void); static void Command_ListWADS_f(void); #ifdef DELFILE static void Command_Delfile(void); @@ -295,10 +299,10 @@ consvar_t cv_skin2 = {"skin2", DEFAULTSKIN2, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Sk consvar_t cv_skin3 = {"skin3", DEFAULTSKIN3, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin3_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skin4 = {"skin4", DEFAULTSKIN4, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin4_OnChange, 0, NULL, NULL, 0, 0, NULL}; // haha I've beaten you now, ONLINE -consvar_t cv_localskin = {"localskin", "none", CV_CALL|CV_NOINIT, NULL, Localskin_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskin2 = {"localskin2", "none", CV_CALL|CV_NOINIT, NULL, Localskin2_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskin3 = {"localskin3", "none", CV_CALL|CV_NOINIT, NULL, Localskin3_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskin4 = {"localskin4", "none", CV_CALL|CV_NOINIT, NULL, Localskin4_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin = {"internal___localskin", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin2 = {"internal___localskin2", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin3 = {"internal___localskin3", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskin4 = {"internal___localskin4", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -654,6 +658,10 @@ void D_RegisterServerCommands(void) COM_AddCommand("addfilelocal", Command_Addfilelocal); COM_AddCommand("addfile", Command_Addfile); COM_AddCommand("addskins", Command_Addskins); + COM_AddCommand("localskin", Command_Localskin1); + COM_AddCommand("localskin2", Command_Localskin2); + COM_AddCommand("localskin3", Command_Localskin3); + COM_AddCommand("localskin4", Command_Localskin4); COM_AddCommand("listwad", Command_ListWADS_f); #ifdef DELFILE @@ -4642,6 +4650,62 @@ Command_Addskins (void) P_AddWadFile(COM_Argv(1), true); } +static void Command_Localskin1 (void) { + if (!Playing() && !demo.playback) + { + CONS_Printf("You can only use this command in gameplay.\n"); + return; + } + if (COM_Argc() != 2) + { + CONS_Printf("localskin : Set a localskin.\n"); + return; + } + SetLocalPlayerSkin(consoleplayer, COM_Argv(1), &cv_localskin); +} + +static void Command_Localskin2 (void) { + if (!Playing() && !demo.playback) + { + CONS_Printf("You can only use this command in gameplay.\n"); + return; + } + if (COM_Argc() != 2) + { + CONS_Printf("localskin2 : Set a localskin.\n"); + return; + } + SetLocalPlayerSkin(displayplayers[1], COM_Argv(1), &cv_localskin2); +} + +static void Command_Localskin3 (void) { + if (!Playing() && !demo.playback) + { + CONS_Printf("You can only use this command in gameplay.\n"); + return; + } + if (COM_Argc() != 2) + { + CONS_Printf("localskin3 : Set a localskin.\n"); + return; + } + SetLocalPlayerSkin(displayplayers[2], COM_Argv(1), &cv_localskin3); +} + +static void Command_Localskin4 (void) { + if (!Playing() && !demo.playback) + { + CONS_Printf("You can only use this command in gameplay.\n"); + return; + } + if (COM_Argc() != 2) + { + CONS_Printf("localskin4 : Set a localskin.\n"); + return; + } + SetLocalPlayerSkin(displayplayers[3], COM_Argv(1), &cv_localskin4); +} + #ifdef DELFILE /** removes the last added pwad at runtime. * Searches for sounds, maps, music and images to remove diff --git a/src/k_kart.c b/src/k_kart.c index 5fc7a1bd0..a2c2699d6 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8598,7 +8598,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat // it, they wouldn't 'spawn' on the top-right side of the HUD. UINT8 skin = 0; - boolean skinlocal = mo->skinlocal; + boolean skinlocal = mo->player->localskin > 0; fixed_t amnumxpos, amnumypos; INT32 amxpos, amypos; diff --git a/src/m_menu.c b/src/m_menu.c index 7bcde32f5..a4941bdb2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3571,7 +3571,7 @@ void M_StartControlPanel(void) else // multiplayer { MPauseMenu[mpause_switchmap].status = IT_DISABLED; - MPauseMenu[mpause_addons].status = IT_DISABLED; + //MPauseMenu[mpause_addons].status = IT_DISABLED; MPauseMenu[mpause_scramble].status = IT_DISABLED; MPauseMenu[mpause_psetupsplit].status = IT_DISABLED; MPauseMenu[mpause_psetupsplit2].status = IT_DISABLED; @@ -5499,6 +5499,14 @@ static boolean M_ChangeStringAddons(INT32 choice) } #undef len +// i hate myself +static boolean DumbStartsWith(const char *pre, const char *str) +{ + size_t lenpre = strlen(pre), + lenstr = strlen(str); + return lenstr < lenpre ? false : memcmp(pre, str, lenpre) == 0; +} + static void M_HandleAddons(INT32 choice) { boolean exitmenu = false; // exit to previous menu @@ -5617,7 +5625,17 @@ static void M_HandleAddons(INT32 choice) case EXT_KART: #endif case EXT_PK3: - COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + if (netgame || multiplayer) { + // no characters? + if (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)); + } + else + S_StartSound(NULL, sfx_s26d); + } + else + COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); break; default: S_StartSound(NULL, sfx_s26d); diff --git a/src/r_things.c b/src/r_things.c index 1eca172a7..adf602251 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3459,14 +3459,18 @@ next_token: #endif // Update the forceskin possiblevalues - if (! local) + if (!local) { Forceskin_cons_t[numskins+1].value = numskins; Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; } // add face graphics - ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, ( (local) ? numlocalskins : numskins ), local); + if (local) { + ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numlocalskins); + } else { + ST_LoadFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numskins); + } #ifdef HWRENDER if (rendermode == render_opengl) diff --git a/src/st_stuff.c b/src/st_stuff.c index 949ff4bac..1c469507c 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -384,16 +384,15 @@ void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skin facemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); } -void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skinnum, boolean local) +void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skinnum) { - if (local) - { - localfacerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); - localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); - localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); - } - else - ST_LoadFaceGraphics(rankstr, wantstr, mmapstr, skinnum); + localfacerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); + localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); + localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); + + //CONS_Printf("Added rank prefix %s\n", rankstr); + //CONS_Printf("Added want prefix %s\n", wantstr); + //CONS_Printf("Added mmap prefix %s\n", mmapstr); } void ST_ReloadSkinFaceGraphics(void) @@ -404,7 +403,7 @@ void ST_ReloadSkinFaceGraphics(void) ST_LoadFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); for (i = 0; i < numlocalskins; i++) - ST_LoadLocalFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i, true); + ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); } static inline void ST_InitData(void) diff --git a/src/st_stuff.h b/src/st_stuff.h index 5b3f611d9..0a047d8ce 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -51,7 +51,7 @@ void ST_LoadGraphics(void); // face load graphics, called when skin changes void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 playernum); -void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 playernum, boolean local); +void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 playernum); void ST_ReloadSkinFaceGraphics(void); #ifdef DELFILE void ST_UnLoadFaceGraphics(INT32 skinnum); From 58c58e9542f9dd4997feb02220ea19b21dab873f Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:31:57 +0200 Subject: [PATCH 012/239] fix shit even more https://git.do.srb2.org/haya_/Kart-Public/-/commit/37d72b4680bbb1ecb68aaa817f2afc8b34deab96 --- src/k_kart.c | 2 +- src/lua_mobjlib.c | 5 ++++- src/lua_skinlib.c | 18 +++++++++--------- src/r_things.c | 9 +++++++++ src/r_things.h | 2 ++ src/st_stuff.c | 26 ++++++++++++++++++++++++-- src/st_stuff.h | 6 ++++++ src/w_wad.c | 14 +++++++++++++- src/y_inter.c | 11 +++++++++-- 9 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index a2c2699d6..5fc7a1bd0 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8598,7 +8598,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat // it, they wouldn't 'spawn' on the top-right side of the HUD. UINT8 skin = 0; - boolean skinlocal = mo->player->localskin > 0; + boolean skinlocal = mo->skinlocal; fixed_t amnumxpos, amnumypos; INT32 amxpos, amypos; diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 91c2158e8..ca7825601 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -350,7 +350,10 @@ int mobj_skin_getter(lua_State *L) if (!mo->skin) return 0; - lua_pushstring(L, ((skin_t *)mo->skin)->name); + if (mo->localskin) // only do this for demos + lua_pushstring(L, ((skin_t *)mo->localskin)->name); + else + lua_pushstring(L, ((skin_t *)mo->skin)->name); return 1; } diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index f44e97afe..e86cd55af 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -166,14 +166,14 @@ static int lib_iterateSkins(lua_State *L) lua_remove(L, 1); // state is unused. if (!lua_isnil(L, 1)) - i = (INT32)(*((skin_t **)luaL_checkudata(L, 1, META_SKIN)) - skins) + 1; + i = (INT32)(*((skin_t **)luaL_checkudata(L, 1, META_SKIN)) - allskins) + 1; else i = 0; // skins are always valid, only added, never removed - if (i < numskins) + if (i < numallskins) { - LUA_PushUserdata(L, &skins[i], META_SKIN); + LUA_PushUserdata(L, &allskins[i], META_SKIN); return 1; } @@ -191,9 +191,9 @@ static int lib_getSkin(lua_State *L) i = luaL_checkinteger(L, 2); if (i < 0 || i >= MAXSKINS) return luaL_error(L, "skins[] index %d out of range (0 - %d)", i, MAXSKINS-1); - if (i >= numskins) + if (i >= numallskins) return 0; - LUA_PushUserdata(L, &skins[i], META_SKIN); + LUA_PushUserdata(L, &allskins[i], META_SKIN); return 1; } @@ -207,10 +207,10 @@ static int lib_getSkin(lua_State *L) } // find skin by name - for (i = 0; i < numskins; i++) - if (fastcmp(skins[i].name, field)) + for (i = 0; i < numallskins; i++) + if (fastcmp(allskins[i].name, field)) { - LUA_PushUserdata(L, &skins[i], META_SKIN); + LUA_PushUserdata(L, &allskins[i], META_SKIN); return 1; } @@ -219,7 +219,7 @@ static int lib_getSkin(lua_State *L) static int lib_numSkins(lua_State *L) { - lua_pushinteger(L, numskins); + lua_pushinteger(L, numallskins); return 1; } diff --git a/src/r_things.c b/src/r_things.c index adf602251..653aa3930 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2782,6 +2782,7 @@ void R_DrawMasked(void) // ========================================================================== INT32 numskins = 0; +INT32 numallskins = 0; INT32 numlocalskins = 0; skin_t skins[MAXSKINS]; UINT8 skinstats[9][9][MAXSKINS]; @@ -2798,6 +2799,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 @@ -2898,6 +2900,10 @@ void R_InitSkins(void) if (rendermode == render_opengl) HWR_AddPlayerMD2(0, false); #endif + + // lets set it + allskins[0] = skins[0]; + numallskins = 1; } // returns true if the skin name is found (loaded from pwad) @@ -3482,8 +3488,11 @@ next_token: CONS_Debug(DBG_SETUP, M_GetText("Incremented %d, %d to %d\n"), skin->kartspeed, skin->kartweight, skinstatscount[skin->kartspeed - 1][skin->kartweight - 1]); skinsorted[numskins] = numskins; + + allskins[numallskins] = ( (local) ? localskins : skins )[( (local) ? numlocalskins : numskins )]; ( (local) ? numlocalskins++ : numskins++ ); + numallskins++; } sortSkinGrid(); diff --git a/src/r_things.h b/src/r_things.h index 5d7076f10..2d9e7a47f 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -202,6 +202,7 @@ typedef struct drawnode_s extern INT32 numskins; extern INT32 numlocalskins; +extern INT32 numallskins; extern skin_t skins[MAXSKINS]; extern UINT8 skinstats[9][9][MAXSKINS]; extern UINT8 skinstatscount[9][9]; @@ -209,6 +210,7 @@ extern UINT8 skinsorted[MAXSKINS]; void sortSkinGrid(void); extern skin_t localskins[MAXSKINS]; +extern skin_t allskins[MAXSKINS*2]; boolean SetPlayerSkin(INT32 playernum,const char *skinname); void SetPlayerSkinByNum(INT32 playernum,INT32 skinnum); // Tails 03-16-2002 diff --git a/src/st_stuff.c b/src/st_stuff.c index 1c469507c..2b5355abc 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -62,6 +62,14 @@ patch_t *localfacerankprefix[MAXSKINS]; // ranking patch_t *localfacewantprefix[MAXSKINS]; // wanted patch_t *localfacemmapprefix[MAXSKINS]; // minimap +char *facerankprefix_name[MAXSKINS]; // ranking +char *facewantprefix_name[MAXSKINS]; // wanted +char *facemmapprefix_name[MAXSKINS]; // minimap + +char *localfacerankprefix_name[MAXSKINS]; // ranking +char *localfacewantprefix_name[MAXSKINS]; // wanted +char *localfacemmapprefix_name[MAXSKINS]; // minimap + // ------------------------------------------ // status bar overlay // ------------------------------------------ @@ -382,6 +390,10 @@ void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skin facerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); facewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); facemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); + + facerankprefix_name[skinnum] = rankstr; + facewantprefix_name[skinnum] = wantstr; + facemmapprefix_name[skinnum] = mmapstr; } void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skinnum) @@ -389,6 +401,10 @@ void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 localfacerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); + + localfacerankprefix_name[skinnum] = rankstr; + localfacewantprefix_name[skinnum] = wantstr; + localfacemmapprefix_name[skinnum] = mmapstr; //CONS_Printf("Added rank prefix %s\n", rankstr); //CONS_Printf("Added want prefix %s\n", wantstr); @@ -402,8 +418,14 @@ void ST_ReloadSkinFaceGraphics(void) for (i = 0; i < numskins; i++) ST_LoadFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); - for (i = 0; i < numlocalskins; i++) - ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); + if (players[consoleplayer].skinlocal) { + for (i = 0; i < numlocalskins; i++) { + ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); + } + } else { + for (i = 0; i < numskins; i++) + ST_LoadLocalFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); + } } static inline void ST_InitData(void) diff --git a/src/st_stuff.h b/src/st_stuff.h index 0a047d8ce..281b87fb5 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -82,6 +82,12 @@ extern patch_t *facemmapprefix[MAXSKINS]; // minimap extern patch_t *localfacerankprefix[MAXSKINS]; // ranking extern patch_t *localfacewantprefix[MAXSKINS]; // wanted extern patch_t *localfacemmapprefix[MAXSKINS]; // minimap +extern char *facerankprefix_name[MAXSKINS]; // ranking +extern char *facewantprefix_name[MAXSKINS]; // wanted +extern char *facemmapprefix_name[MAXSKINS]; // minimap +extern char *localfacerankprefix_name[MAXSKINS]; // ranking +extern char *localfacewantprefix_name[MAXSKINS]; // wanted +extern char *localfacemmapprefix_name[MAXSKINS]; // minimap extern patch_t *livesback; extern patch_t *ngradeletters[7]; diff --git a/src/w_wad.c b/src/w_wad.c index 630947fad..d2bbf0bdc 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -65,6 +65,7 @@ #include "i_system.h" #include "md5.h" #include "lua_script.h" +#include "st_stuff.h" #ifdef SCANTHINGS #include "p_setup.h" // P_ScanThings #endif @@ -1730,7 +1731,18 @@ void *W_CachePatchName(const char *name, INT32 tag) { lumpnum_t num; - num = W_CheckNumForName(name); + const char *finalname = name; + + // bogus fix by haya + // i really dont want to bother rn + if (finalname == facerankprefix_name[players[consoleplayer].skin] && players[consoleplayer].skinlocal) + finalname = localfacerankprefix_name[players[consoleplayer].localskin - 1]; + else if (finalname == facemmapprefix_name[players[consoleplayer].skin] && players[consoleplayer].skinlocal) + finalname = localfacemmapprefix_name[players[consoleplayer].localskin - 1]; + else if (finalname == facewantprefix_name[players[consoleplayer].skin] && players[consoleplayer].skinlocal) + finalname = localfacewantprefix_name[players[consoleplayer].localskin - 1]; + + num = W_CheckNumForName(finalname); if (num == LUMPERROR) return W_CachePatchNum(W_GetNumForName("MISSING"), tag); diff --git a/src/y_inter.c b/src/y_inter.c index 3fb2d3aa3..71011ed60 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -482,7 +482,14 @@ void Y_IntermissionDrawer(void) if (data.match.color[i]) { UINT8 *colormap = R_GetTranslationColormap(*data.match.character[i], *data.match.color[i], GTC_CACHE); - V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[*data.match.character[i]], colormap); + if (!players[i].skinlocal) { + if (!players[i].localskin) + V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[*data.match.character[i]], colormap); + else + V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[players[i].localskin - 1], colormap); + } else { + V_DrawMappedPatch(x+16, y-4, 0, localfacerankprefix[players[i].localskin - 1], colormap); + } } if (data.match.num[i] == whiteplayer) @@ -1200,7 +1207,7 @@ 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, facerankprefix[players[i].skin], colormap); + 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) From ceae12baba2b70e1e909b10957021eea3fc442c8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:34:28 +0200 Subject: [PATCH 013/239] fix an issue with desynchs https://git.do.srb2.org/haya_/Kart-Public/-/commit/a47d965b82e45bcf600217899a2cd6951024093b --- src/lua_mobjlib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index ca7825601..ff4a024ac 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -19,6 +19,7 @@ #include "p_local.h" #include "g_game.h" #include "p_setup.h" +#include "doomdef.h" #include "lua_script.h" #include "lua_libs.h" @@ -350,7 +351,7 @@ int mobj_skin_getter(lua_State *L) if (!mo->skin) return 0; - if (mo->localskin) // only do this for demos + if (mo->localskin) // pretty cool, but also destructive lua_pushstring(L, ((skin_t *)mo->localskin)->name); else lua_pushstring(L, ((skin_t *)mo->skin)->name); @@ -366,7 +367,7 @@ int mobj_skin_setter(lua_State *L) 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 - for (i = 0; i < numskins; i++) + for (i = 0; i < numskins; i++) { { if (fastcmp(skins[i].name, skin)) { @@ -375,7 +376,10 @@ int mobj_skin_setter(lua_State *L) } } - return luaL_error(L, "mobj.skin '%s' not found!", skin); + } + + mo->skin = &skins[players[consoleplayer].skin]; // we dont want to use our local skin for this!!!!!!!!! + return 0; } int mobj_color_setter(lua_State *L) From 9dc2ad4f32ff0a2cc7e1ed5acca8361f3f0fb3c1 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 17:39:41 +0200 Subject: [PATCH 014/239] add localskinall command https://git.do.srb2.org/haya_/Kart-Public/-/commit/958fe796eb070b6678cd45ea835a998d8dc6d2c9 --- src/d_netcmd.c | 75 ++++++++++++++++++++++++----------------------- src/d_netcmd.h | 1 + src/lua_mobjlib.c | 9 ++++-- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 41287dcbb..7d88cb466 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -110,10 +110,6 @@ static void Skin_OnChange(void); static void Skin2_OnChange(void); static void Skin3_OnChange(void); static void Skin4_OnChange(void); -static void Localskin_OnChange(void); -static void Localskin2_OnChange(void); -static void Localskin3_OnChange(void); -static void Localskin4_OnChange(void); static void Color_OnChange(void); static void Color2_OnChange(void); static void Color3_OnChange(void); @@ -150,6 +146,7 @@ static void Command_Localskin1(void); static void Command_Localskin2(void); static void Command_Localskin3(void); static void Command_Localskin4(void); +static void Command_LocalskinAll(void); static void Command_ListWADS_f(void); #ifdef DELFILE static void Command_Delfile(void); @@ -303,6 +300,7 @@ consvar_t cv_localskin = {"internal___localskin", "none", CV_HIDEN, NULL, NULL, consvar_t cv_localskin2 = {"internal___localskin2", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_localskin3 = {"internal___localskin3", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_localskin4 = {"internal___localskin4", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_localskinall = {"internal___localskinall", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -662,6 +660,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("localskin2", Command_Localskin2); COM_AddCommand("localskin3", Command_Localskin3); COM_AddCommand("localskin4", Command_Localskin4); + COM_AddCommand("localskinall", Command_LocalskinAll); COM_AddCommand("listwad", Command_ListWADS_f); #ifdef DELFILE @@ -920,6 +919,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_playercolor4); CV_RegisterVar(&cv_skin4); CV_RegisterVar(&cv_localskin4); + CV_RegisterVar(&cv_localskinall); // preferred number of players CV_RegisterVar(&cv_splitplayers); @@ -4636,6 +4636,14 @@ static void Command_Addfile(void) SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); } +// i hate myself +static boolean DumbStartsWith(const char *pre, const char *str) +{ + size_t lenpre = strlen(pre), + lenstr = strlen(str); + return lenstr < lenpre ? false : memcmp(pre, str, lenpre) == 0; +} + /** Adds something at runtime. */ static void @@ -4647,7 +4655,15 @@ Command_Addskins (void) "addskins : load skins bro\n"); return; } - P_AddWadFile(COM_Argv(1), true); + // we dont want anything that aint a skin + if (DumbStartsWith("KC_", COM_Argv(1))) + P_AddWadFile(COM_Argv(1), true); + else if (DumbStartsWith("KCL_", COM_Argv(1)) && demo.playback) // KCL only for demos + P_AddWadFile(COM_Argv(1), true); + else if (DumbStartsWith("KCL_", COM_Argv(1)) && !demo.playback) + CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is a skin with lua."), COM_Argv(1)); + else + CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is not a skin."), COM_Argv(1)); } static void Command_Localskin1 (void) { @@ -4706,6 +4722,23 @@ static void Command_Localskin4 (void) { SetLocalPlayerSkin(displayplayers[3], COM_Argv(1), &cv_localskin4); } +static void Command_LocalskinAll (void) { + if (!Playing() && !demo.playback) + { + CONS_Printf("You can only use this command in gameplay.\n"); + return; + } + if (COM_Argc() != 2) + { + CONS_Printf("localskinall : Set a localskin to all players.\n"); + return; + } + INT32 i; + for (i; i < MAXPLAYERS; i++) { + SetLocalPlayerSkin(i, COM_Argv(1), &cv_localskinall); + } +} + #ifdef DELFILE /** removes the last added pwad at runtime. * Searches for sounds, maps, music and images to remove @@ -6018,38 +6051,6 @@ static void Command_ListSkins(void) } } -/** bruh - */ -static void Localskin_OnChange(void) -{ - if (!Playing()) - return; // do whatever you want - SetLocalPlayerSkin(consoleplayer, cv_localskin.string, &cv_localskin); -} - -/** two bruh machine gun - */ -static void Localskin2_OnChange(void) -{ - if (!Playing()) - return; // do whatever you want - SetLocalPlayerSkin(displayplayers[1], cv_localskin2.string, &cv_localskin2); -} - -static void Localskin3_OnChange(void) -{ - if (!Playing()) - return; // do whatever you want - SetLocalPlayerSkin(displayplayers[2], cv_localskin3.string, &cv_localskin3); -} - -static void Localskin4_OnChange(void) -{ - if (!Playing()) - return; // do whatever you want - SetLocalPlayerSkin(displayplayers[3], cv_localskin4.string, &cv_localskin4); -} - /** 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 9cf7c2e5d..80c7078a0 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -37,6 +37,7 @@ extern consvar_t cv_playername4; extern consvar_t cv_playercolor4; extern consvar_t cv_skin4; extern consvar_t cv_localskin4; +extern consvar_t cv_localskinall; // preferred number of players extern consvar_t cv_splitplayers; diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index ff4a024ac..a7f3d8580 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -367,6 +367,12 @@ int mobj_skin_setter(lua_State *L) 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 + // nope, not this time chief. + if (fastcmp(localskins[players[consoleplayer].localskin - 1].name, skin)) + { + mo->skin = &skins[players[consoleplayer].skin]; // we dont want to use our local skin for this!!!!!!!!! + return 0; + } for (i = 0; i < numskins; i++) { { if (fastcmp(skins[i].name, skin)) @@ -378,8 +384,7 @@ int mobj_skin_setter(lua_State *L) } - mo->skin = &skins[players[consoleplayer].skin]; // we dont want to use our local skin for this!!!!!!!!! - return 0; + return luaL_error(L, "mobj.skin '%s' not found!", skin); } int mobj_color_setter(lua_State *L) From faeb4d22ed6153eea4fd965f2b32a11946263442 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 18:43:55 +0200 Subject: [PATCH 015/239] Add a -force parameter to addskins, fix localskin not playing the right sounds https://git.do.srb2.org/haya_/Kart-Public/-/commit/932e9b92c3551dc4910157ea8d3eea1145ccfc40 --- src/d_netcmd.c | 33 ++++++++++++++++++++++----------- src/m_menu.c | 2 +- src/p_user.c | 4 ++-- src/y_inter.c | 9 +++++---- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 7d88cb466..235cde3a2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -49,6 +49,7 @@ #include "m_anigif.h" #include "k_kart.h" // SRB2kart #include "y_inter.h" +#include "fastcmp.h" #include "m_perfstats.h" #ifdef NETGAME_DEVMODE @@ -4649,21 +4650,31 @@ static boolean DumbStartsWith(const char *pre, const char *str) static void Command_Addskins (void) { - if (COM_Argc() != 2) + if (COM_Argc() > 3) { CONS_Printf( - "addskins : load skins bro\n"); + "addskins : Load a skin file.\n"); return; } - // we dont want anything that aint a skin - if (DumbStartsWith("KC_", COM_Argv(1))) - P_AddWadFile(COM_Argv(1), true); - else if (DumbStartsWith("KCL_", COM_Argv(1)) && demo.playback) // KCL only for demos - P_AddWadFile(COM_Argv(1), true); - else if (DumbStartsWith("KCL_", COM_Argv(1)) && !demo.playback) - CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is a skin with lua."), COM_Argv(1)); - else - CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is not a skin."), COM_Argv(1)); + // no forcing? + if (fasticmp(COM_Argv(2), "-force") || fasticmp(COM_Argv(2), "-f")) { + CONS_Alert(CONS_NOTICE, M_GetText("Adding file %s. May or may not be a skin.\n"), COM_Argv(1)); + P_AddWadFile(COM_Argv(1), 0, true); + } else { + if (DumbStartsWith("KC_", COM_Argv(1))) { + P_AddWadFile(COM_Argv(1), 0, true); + } else if (DumbStartsWith("KCL_", COM_Argv(1))) { + if (!demo.playback) { + CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is a skin with lua. Include -force or -f to force it to load.\n"), COM_Argv(1)); + return; + } else { + P_AddWadFile(COM_Argv(1), 0, true); + } + } else { + CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is not a skin.\n"), COM_Argv(1)); + return; + } + } } static void Command_Localskin1 (void) { diff --git a/src/m_menu.c b/src/m_menu.c index a4941bdb2..872af2530 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5629,7 +5629,7 @@ static void M_HandleAddons(INT32 choice) // no characters? if (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)); + COM_BufAddText(va("addskins \"%s%s\" -force", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); } else S_StartSound(NULL, sfx_s26d); diff --git a/src/p_user.c b/src/p_user.c index 5130c8f55..c625e5fcc 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1741,13 +1741,13 @@ void P_DoPlayerExit(player_t *player) sfxenum_t sfx_id; // fix godjjsa win sounds if (K_IsPlayerLosing(player)) { - if (player->mo->skinlocal) + if (player->mo->localskin) sfx_id = ((skin_t *)player->mo->localskin)->soundsid[S_sfx[sfx_klose].skinsound]; else sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_klose].skinsound]; } else { - if (player->mo->skinlocal) + if (player->mo->localskin) sfx_id = ((skin_t *)player->mo->localskin)->soundsid[S_sfx[sfx_kwin].skinsound]; else sfx_id = ((skin_t *)player->mo->skin)->soundsid[S_sfx[sfx_kwin].skinsound]; diff --git a/src/y_inter.c b/src/y_inter.c index 71011ed60..02b88f834 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -482,13 +482,14 @@ void Y_IntermissionDrawer(void) if (data.match.color[i]) { UINT8 *colormap = R_GetTranslationColormap(*data.match.character[i], *data.match.color[i], GTC_CACHE); - if (!players[i].skinlocal) { - if (!players[i].localskin) + // 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); else - V_DrawMappedPatch(x+16, y-4, 0, facerankprefix[players[i].localskin - 1], colormap); + 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[i].localskin - 1], colormap); + V_DrawMappedPatch(x+16, y-4, 0, localfacerankprefix[players[data.match.num[i]].localskin - 1], colormap); } } From 487cbc495a278ea23a638a8a3fc745018248dc4e Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 18:47:57 +0200 Subject: [PATCH 016/239] more changes https://git.do.srb2.org/haya_/Kart-Public/-/commit/9e3919195d143956e31bf092f6822cab61d1ee81 --- src/d_netcmd.c | 7 +++++-- src/g_game.c | 10 ++++++++++ src/g_game.h | 1 + src/lua_script.c | 2 +- src/r_things.c | 19 +++++++++++++++++++ src/st_stuff.c | 9 ++------- src/w_wad.c | 1 + src/w_wad.h | 1 + 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 235cde3a2..71dd814d9 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4683,12 +4683,15 @@ static void Command_Localskin1 (void) { CONS_Printf("You can only use this command in gameplay.\n"); return; } - if (COM_Argc() != 2) + if (COM_Argc() > 3) { CONS_Printf("localskin : Set a localskin.\n"); return; } - SetLocalPlayerSkin(consoleplayer, COM_Argv(1), &cv_localskin); + if (fasticmp(COM_Argv(2), "-display") || fasticmp(COM_Argv(2), "-d")) + SetLocalPlayerSkin(displayplayers[0], COM_Argv(1), &cv_localskin); + else + SetLocalPlayerSkin(consoleplayer, COM_Argv(1), &cv_localskin); } static void Command_Localskin2 (void) { diff --git a/src/g_game.c b/src/g_game.c index d17434f4e..1a5e0c067 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -846,6 +846,16 @@ void G_SetGameModified(boolean silent, boolean major) M_EndModeAttackRun(); } +void G_SetWadModified(boolean silent, boolean major, UINT16 wadnum) +{ + // now that we have a wad that is actually well, a gameplay changing mod + // (for later) + wadfiles[wadnum]->majormod = true; + + // set our game to be marked as modified. + G_SetGameModified(silent, major); +} + /** Builds an original game map name from a map number. * The complexity is due to MAPA0-MAPZZ. * diff --git a/src/g_game.h b/src/g_game.h index 67618296f..d7163b4ed 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -402,6 +402,7 @@ boolean G_GetRetryFlag(void); void G_LoadGameData(void); void G_LoadGameSettings(void); +void G_SetWadModified(boolean silent, boolean major, UINT16 wadnum); void G_SetGameModified(boolean silent, boolean major); void G_SetGamestate(gamestate_t newstate); diff --git a/src/lua_script.c b/src/lua_script.c index 8f4438732..e0da24b40 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -280,7 +280,7 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump) LUA_LoadFile(&f, name); // actually load file! // Okay, we've modified the game beyond the point of no return. - G_SetGameModified(multiplayer, true); + G_SetWadModified(multiplayer, true, wad); free(name); Z_Free(f.data); diff --git a/src/r_things.c b/src/r_things.c index 653aa3930..4d21ed574 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2966,6 +2966,13 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) { player_t *player = &players[playernum]; INT32 i; + + // this is where we're gonna use major mod for. + if (wadfiles[skins[player->skin].wadnum]->majormod && !demo.playback) + { + CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the player's skin is modifying the game.\n"), skinname); + return; + } if (strcasecmp(skinname, "none")) { @@ -2975,6 +2982,12 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (stricmp(localskins[i].name, skinname) == 0) { player->localskin = 1 + i; + if (wadfiles[localskins[player->localskin - 1].wadnum]->majormod && !demo.playback) + { + CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the localskin is a gameplay-modifying addon.\n"), skinname); + player->localskin = 0; + return; + } player->skinlocal = true; if (player->mo) { @@ -2990,6 +3003,12 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (stricmp(skins[i].name, skinname) == 0) { player->localskin = 1 + i; + if (wadfiles[skins[player->localskin - 1].wadnum]->majormod && !demo.playback) + { + CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the skin is a gameplay-modifying addon.\n"), skinname); + player->localskin = 0; + return; + } player->skinlocal = false; if (player->mo) { diff --git a/src/st_stuff.c b/src/st_stuff.c index 2b5355abc..19567b42d 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -418,13 +418,8 @@ void ST_ReloadSkinFaceGraphics(void) for (i = 0; i < numskins; i++) ST_LoadFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); - if (players[consoleplayer].skinlocal) { - for (i = 0; i < numlocalskins; i++) { - ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); - } - } else { - for (i = 0; i < numskins; i++) - ST_LoadLocalFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); + for (i = 0; i < numlocalskins; i++) { + ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); } } diff --git a/src/w_wad.c b/src/w_wad.c index d2bbf0bdc..1e0cd96ae 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -793,6 +793,7 @@ UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, b fseek(handle, 0, SEEK_END); wadfile->filesize = (unsigned)ftell(handle); wadfile->type = type; + wadfile->majormod = false; // already generated, just copy it over M_Memcpy(&wadfile->md5sum, &md5sum, 16); diff --git a/src/w_wad.h b/src/w_wad.h index 32c843580..230d69a72 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -114,6 +114,7 @@ typedef struct wadfile_s UINT32 filesize; // for network UINT8 md5sum[16]; boolean important; + boolean majormod; } wadfile_t; #define WADFILENUM(lumpnum) (UINT16)((lumpnum)>>16) // wad flumpnum>>16) // wad file number in upper word From 23ba3d493be814e3a4f82b01e4be6639820a54cc Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 18:50:00 +0200 Subject: [PATCH 017/239] issues fixing --- src/d_netcmd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 71dd814d9..dfd5e5615 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4657,6 +4657,7 @@ Command_Addskins (void) return; } // no forcing? + /* if (fasticmp(COM_Argv(2), "-force") || fasticmp(COM_Argv(2), "-f")) { CONS_Alert(CONS_NOTICE, M_GetText("Adding file %s. May or may not be a skin.\n"), COM_Argv(1)); P_AddWadFile(COM_Argv(1), 0, true); @@ -4668,13 +4669,16 @@ Command_Addskins (void) CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is a skin with lua. Include -force or -f to force it to load.\n"), COM_Argv(1)); return; } else { + */ P_AddWadFile(COM_Argv(1), 0, true); + /* } } else { CONS_Alert(CONS_ERROR, M_GetText("Cannot add file %s as it is not a skin.\n"), COM_Argv(1)); return; } } + */ } static void Command_Localskin1 (void) { From 43e133159496b7d3f20c03b0aca092e440e493ac Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 18:51:10 +0200 Subject: [PATCH 018/239] another localfile thingie https://git.do.srb2.org/haya_/Kart-Public/-/commit/4a60babf75ce6362d32a1633b12a718d65bcd18c --- src/d_netfil.c | 2 +- src/p_setup.c | 5 +++++ src/w_wad.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 0436f05d3..dbf4e6281 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -513,7 +513,7 @@ INT32 CL_CheckFiles(void) for (i = 0, j = mainwads+1; i < fileneedednum || j < numwadfiles;) { - if (j < numwadfiles && !wadfiles[j]->important) + if (j < numwadfiles && (!wadfiles[j]->important || wadfiles[j]->localfile)) { // Unimportant on our side. still don't care. ++j; diff --git a/src/p_setup.c b/src/p_setup.c index f47417b04..ca15e44ba 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3493,6 +3493,11 @@ 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; // // search for sound replacements diff --git a/src/w_wad.h b/src/w_wad.h index 230d69a72..b2b518793 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -115,6 +115,7 @@ typedef struct wadfile_s UINT8 md5sum[16]; boolean important; boolean majormod; + boolean localfile; // only for skins } wadfile_t; #define WADFILENUM(lumpnum) (UINT16)((lumpnum)>>16) // wad flumpnum>>16) // wad file number in upper word From 76b66b41b63cfbfd1a073585373da476959b3b7c Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 18:58:26 +0200 Subject: [PATCH 019/239] Argh! https://git.do.srb2.org/haya_/Kart-Public/-/commit/217f15452c1fda9ea3c0d00650d470e13e14e0f5 --- src/CMakeLists.txt | 2 + src/args.c | 48 ++++++++--------- src/args.h | 20 +++---- src/command.c | 12 ++++- src/command.h | 4 ++ src/d_netcmd.c | 126 +++++++++++++++++---------------------------- src/p_enemy.c | 6 +++ src/r_things.c | 6 +++ src/r_things.h | 2 + 9 files changed, 112 insertions(+), 114 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88231fc03..099e9f1ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ # Core sources set(SRB2_CORE_SOURCES am_map.c + args.c b_bot.c command.c comptime.c @@ -52,6 +53,7 @@ set(SRB2_CORE_SOURCES set(SRB2_CORE_HEADERS am_map.h + args.h b_bot.h byteptr.h command.h diff --git a/src/args.c b/src/args.c index 88eec9092..465208e47 100644 --- a/src/args.c +++ b/src/args.c @@ -1,4 +1,4 @@ -#include "doomtype.h" +#include #include #include #include @@ -106,7 +106,7 @@ static void vec_free(Vec* vec) { } -static boolean vec_add(Vec* vec, void* entry) { +static bool vec_add(Vec* vec, void* entry) { if (vec->count + 1 > vec->capacity) { int new_capacity = vec->capacity < 8 ? 8 : vec->capacity * 2; void** new_array = realloc(vec->entries, sizeof(void*) * new_capacity); @@ -191,7 +191,7 @@ static MapEntry* map_find(Map* map, const char* key, uint32_t key_hash) { } -static boolean map_grow(Map* map) { +static bool map_grow(Map* map) { MapEntry* old_entries = map->entries; int old_capacity = map->capacity; int new_capacity = old_capacity < 8 ? 8 : old_capacity * 2; @@ -227,7 +227,7 @@ static boolean map_grow(Map* map) { // Returns true if the key was found. -static boolean map_get(Map* map, const char* key, void** value) { +static bool map_get(Map* map, const char* key, void** value) { if (map->count == 0) return false; uint32_t key_hash = str_hash(key); @@ -241,7 +241,7 @@ static boolean map_get(Map* map, const char* key, void** value) { // Adds a new entry to the map or updates the value of an existing entry. // (Note that the map stores its own internal copy of the key string.) -static boolean map_set(Map* map, const char* key, void* value) { +static bool map_set(Map* map, const char* key, void* value) { if (map->count == map->max_load_threshold) { if (!map_grow(map)) { return false; @@ -269,7 +269,7 @@ static boolean map_set(Map* map, const char* key, void* value) { // Convenience wrapper for map_set(). This splits the key string into space- // separated words and adds a separate entry to the map for each word. -static boolean map_set_splitkey(Map* map, const char* key_string, void* value) { +static bool map_set_splitkey(Map* map, const char* key_string, void* value) { char *copy_of_key_string = str_dup(key_string); if (!copy_of_key_string) { return false; @@ -343,7 +343,7 @@ static void option_free(Option* opt) { } -static boolean option_append_value(Option* opt, OptionValue value) { +static bool option_append_value(Option* opt, OptionValue value) { if (opt->count + 1 > opt->capacity) { int new_capacity = opt->capacity < 4 ? 4 : opt->capacity * 2; OptionValue* new_array = realloc(opt->values, sizeof(OptionValue) * new_capacity); @@ -359,7 +359,7 @@ static boolean option_append_value(Option* opt, OptionValue value) { } -static boolean option_try_set(Option* opt, char* arg) { +static bool option_try_set(Option* opt, char* arg) { if (opt->type == OPT_STR) { return option_append_value(opt, (OptionValue){.str_val = arg}); } @@ -579,7 +579,7 @@ static char* argstream_next(ArgStream* stream) { } -static boolean argstream_has_next(ArgStream* stream) { +static bool argstream_has_next(ArgStream* stream) { return stream->index < stream->count; } @@ -600,10 +600,10 @@ struct ArgParser { ap_callback_t callback; char* cmd_name; struct ArgParser* cmd_parser; - boolean enable_help_command; - boolean had_memory_error; + bool enable_help_command; + bool had_memory_error; struct ArgParser* parent; - boolean first_positional_arg_ends_options; + bool first_positional_arg_ends_options; }; @@ -748,7 +748,7 @@ char* ap_get_version(ArgParser* parser) { } -void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable) { +void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable) { parser->first_positional_arg_ends_options = enable; } @@ -832,7 +832,7 @@ int ap_count(ArgParser* parser, const char* name) { // Returns true if the specified flag or option was found. -boolean ap_found(ArgParser* parser, const char* name) { +bool ap_found(ArgParser* parser, const char* name) { Option* opt = ap_get_opt(parser, name); return opt->count > 0; } @@ -913,7 +913,7 @@ double* ap_dbl_values(ArgParser* parser, const char* name) { // Returns true if the parser has found one or more positional arguments. -boolean ap_has_args(ArgParser* parser) { +bool ap_has_args(ArgParser* parser) { return parser->positional_args->count > 0; } @@ -1016,7 +1016,7 @@ void ap_callback(ArgParser* parser, ap_callback_t function) { // Returns true if the parser has found a command. -boolean ap_has_cmd(ArgParser* parser) { +bool ap_has_cmd(ArgParser* parser) { return parser->cmd_name != NULL; } @@ -1034,7 +1034,7 @@ ArgParser* ap_cmd_parser(ArgParser* parser) { // Toggles support for the automatic 'help' command. -void ap_enable_help_command(ArgParser* parser, boolean enable) { +void ap_enable_help_command(ArgParser* parser, bool enable) { parser->enable_help_command = enable; } @@ -1056,7 +1056,7 @@ static void ap_handle_equals_opt(ArgParser* parser, const char* prefix, const ch char *value = strchr(arg, '=') + 1; Option* option; - boolean found = map_get(parser->option_map, name, (void**)&option); + bool found = map_get(parser->option_map, name, (void**)&option); if (!found || option->type == OPT_FLAG) { err(va("%s%s is not a recognised option name", prefix, name)); @@ -1101,7 +1101,7 @@ static void ap_handle_short_opt(ArgParser* parser, const char* arg, ArgStream* s for (size_t i = 0; i < strlen(arg); i++) { char keystr[] = {arg[i], 0}; Option* option; - boolean found = map_get(parser->option_map, keystr, (void**)&option); + bool found = map_get(parser->option_map, keystr, (void**)&option); if (!found) { if (arg[i] == 'h' && parser->helptext != NULL) { CONS_Printf("%s\n", parser->helptext); @@ -1134,7 +1134,7 @@ static void ap_parse_stream(ArgParser* parser, ArgStream* stream) { } ArgParser* cmd_parser; - boolean is_first_arg = true; + bool is_first_arg = true; while (argstream_has_next(stream)) { char* arg = argstream_next(stream); @@ -1216,7 +1216,7 @@ static void ap_parse_stream(ArgParser* parser, ArgStream* stream) { // Parse an array of string arguments. -static boolean ap_parse_array(ArgParser* parser, int count, char* args[]) { +static bool ap_parse_array(ArgParser* parser, int count, char* args[]) { if (parser->had_memory_error) { return false; } @@ -1237,7 +1237,7 @@ static boolean ap_parse_array(ArgParser* parser, int count, char* args[]) { // are the arguments passed to main(), i.e. that the first element in [argv] is the program's name // and should be ignored when parsing the actual *arguments*. In some situations [argv] can be // empty, i.e. [argc == 0], which can lead to security vulnerabilities if not explicitly handled. -boolean ap_parse(ArgParser* parser, int argc, char* argv[]) { +bool ap_parse(ArgParser* parser, int argc, char* argv[]) { if (argc > 1) { return ap_parse_array(parser, argc - 1, argv + 1); } @@ -1250,7 +1250,7 @@ boolean ap_parse(ArgParser* parser, int argc, char* argv[]) { /* --------------------- */ -boolean ap_had_memory_error(ArgParser* parser) { +bool ap_had_memory_error(ArgParser* parser) { return parser->had_memory_error; } @@ -1294,7 +1294,7 @@ void ap_print(ArgParser* parser) { /* --------------------- */ -void ap_cmd_help(ArgParser* parser, boolean enable) { +void ap_cmd_help(ArgParser* parser, bool enable) { ap_enable_help_command(parser, enable); } diff --git a/src/args.h b/src/args.h index e2db1e501..39cd57b5c 100644 --- a/src/args.h +++ b/src/args.h @@ -8,7 +8,7 @@ #ifndef args_h #define args_h -#include "doomtype.h" +#include // ----------------------------------------------------------------------------- // Types. @@ -51,7 +51,7 @@ char* ap_get_version(ArgParser* parser); // If toggled to true, the first positional argument ends option parsing; all // subsequent arguments will be treated as positionals. Defaults to false. -void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable); +void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable); // Parses the application's command line arguments. The parameters are assumed // to be [argc] and [argv] as supplied to main(), i.e. the first element of the @@ -59,7 +59,7 @@ void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable); // if the arguments were successfully parsed. Returns false if parsing failed // due to a memory allocation error. (This memory allocation error may have // occured during set-up rather than during parsing.) -boolean ap_parse(ArgParser* parser, int argc, char** argv); +bool ap_parse(ArgParser* parser, int argc, char** argv); // Frees the memory associated with the parser and any subparsers. void ap_free(ArgParser* parser); @@ -88,7 +88,7 @@ void ap_dbl_opt(ArgParser* parser, const char* name, double fallback); int ap_count(ArgParser* parser, const char* name); // Returns true if the specified flag or option was found. -boolean ap_found(ArgParser* parser, const char* name); +bool ap_found(ArgParser* parser, const char* name); // Returns the value of a string option. char* ap_str_value(ArgParser* parser, const char* name); @@ -128,7 +128,7 @@ double* ap_dbl_values(ArgParser* parser, const char* name); // ----------------------------------------------------------------------------- // Returns true if the parser has found one or more positional arguments. -boolean ap_has_args(ArgParser* parser); +bool ap_has_args(ArgParser* parser); // Returns the number of positional arguments. int ap_count_args(ArgParser* parser); @@ -166,7 +166,7 @@ ArgParser* ap_cmd(ArgParser* parser, const char* name); void ap_callback(ArgParser* parser, ap_callback_t function); // Returns true if the parser has found a command. -boolean ap_has_cmd(ArgParser* parser); +bool ap_has_cmd(ArgParser* parser); // Returns the command name, if the parser has found a command. char* ap_cmd_name(ArgParser* parser); @@ -174,11 +174,11 @@ char* ap_cmd_name(ArgParser* parser); // Returns the command's parser instance, if the parser has found a command. ArgParser* ap_cmd_parser(ArgParser* parser); -// This booleanean switch toggles support for an automatic 'help' command that +// This boolean switch toggles support for an automatic 'help' command that // prints subcommand helptext. The value defaults to false but gets toggled // automatically to true whenever a command is registered. You can use this // function to disable the feature if required. -void ap_enable_help_command(ArgParser* parser, boolean enable); +void ap_enable_help_command(ArgParser* parser, bool enable); // ----------------------------------------------------------------------------- // Debugging utilities. @@ -188,14 +188,14 @@ void ap_enable_help_command(ArgParser* parser, boolean enable); void ap_print(ArgParser* parser); // True if an attempt to allocate memory failed. -boolean ap_had_memory_error(ArgParser* parser); +bool ap_had_memory_error(ArgParser* parser); // ----------------------------------------------------------------------------- // Deprecated. // ----------------------------------------------------------------------------- // Replaced by ap_enable_help_command(). -void ap_cmd_help(ArgParser* parser, boolean enable); +void ap_cmd_help(ArgParser* parser, bool enable); // Replaced by ap_set_helptext(). void ap_helptext(ArgParser* parser, const char* helptext); diff --git a/src/command.c b/src/command.c index 46709fc67..0af4b9fb2 100644 --- a/src/command.c +++ b/src/command.c @@ -277,7 +277,7 @@ static xcommand_t *com_commands = NULL; // current commands #define MAX_ARGS 80 static size_t com_argc; -static char *com_argv[MAX_ARGS]; +char *com_argv[MAX_ARGS]; static const char *com_null_string = ""; static char *com_args = NULL; // current command args or NULL @@ -327,6 +327,16 @@ const char *COM_Argv(size_t arg) return com_argv[arg]; } +/** Returns all of the console command arguments + * + * \return String pointer to the argv table. + * \sa COM_ArgvList + */ +char **COM_ArgvList(void) +{ + return com_argv; +} + /** Gets all console command arguments. * * \return String pointer to all arguments for the last command. diff --git a/src/command.h b/src/command.h index 3fc39c84a..2276a0ae2 100644 --- a/src/command.h +++ b/src/command.h @@ -33,8 +33,12 @@ typedef void (*com_func_t)(void); void COM_AddCommand(const char *name, com_func_t func); int COM_AddLuaCommand(const char *name); +#define MAX_ARGS 80 +extern char *com_argv[MAX_ARGS]; + size_t COM_Argc(void); const char *COM_Argv(size_t arg); // if argv > argc, returns empty string +char **COM_ArgvList(void); char *COM_Args(void); size_t COM_CheckParm(const char *check); // like M_CheckParm :) size_t COM_CheckPartialParm(const char *check); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index dfd5e5615..f7e13dc92 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -143,11 +143,7 @@ static void Command_SetViews_f(void); static void Command_Addfilelocal(void); static void Command_Addfile(void); static void Command_Addskins(void); -static void Command_Localskin1(void); -static void Command_Localskin2(void); -static void Command_Localskin3(void); -static void Command_Localskin4(void); -static void Command_LocalskinAll(void); +static void Command_GLocalSkin(void); static void Command_ListWADS_f(void); #ifdef DELFILE static void Command_Delfile(void); @@ -657,11 +653,7 @@ void D_RegisterServerCommands(void) COM_AddCommand("addfilelocal", Command_Addfilelocal); COM_AddCommand("addfile", Command_Addfile); COM_AddCommand("addskins", Command_Addskins); - COM_AddCommand("localskin", Command_Localskin1); - COM_AddCommand("localskin2", Command_Localskin2); - COM_AddCommand("localskin3", Command_Localskin3); - COM_AddCommand("localskin4", Command_Localskin4); - COM_AddCommand("localskinall", Command_LocalskinAll); + COM_AddCommand("localskin", Command_GLocalSkin); COM_AddCommand("listwad", Command_ListWADS_f); #ifdef DELFILE @@ -4681,80 +4673,56 @@ Command_Addskins (void) */ } -static void Command_Localskin1 (void) { - if (!Playing() && !demo.playback) - { - CONS_Printf("You can only use this command in gameplay.\n"); - return; - } - if (COM_Argc() > 3) - { - CONS_Printf("localskin : Set a localskin.\n"); - return; - } - if (fasticmp(COM_Argv(2), "-display") || fasticmp(COM_Argv(2), "-d")) - SetLocalPlayerSkin(displayplayers[0], COM_Argv(1), &cv_localskin); - else - SetLocalPlayerSkin(consoleplayer, COM_Argv(1), &cv_localskin); -} +// args n stuff +#include "args.h" -static void Command_Localskin2 (void) { - if (!Playing() && !demo.playback) - { - CONS_Printf("You can only use this command in gameplay.\n"); - return; - } - if (COM_Argc() != 2) - { - CONS_Printf("localskin2 : Set a localskin.\n"); - return; - } - SetLocalPlayerSkin(displayplayers[1], COM_Argv(1), &cv_localskin2); -} +static void Command_GLocalSkin (void) { + ArgParser* parser = ap_new(); + ap_set_helptext(parser, "Usage: localskin [options] \n\nOptions: \n\ + -d, --display: Use the first displaying player instead of yourself.\n\ + Has no effect on replays. Omits any player related\n\ + options.\n\ + -a, --all: Set a localskin to all players. Omits any player related\n\ + options.\n\ + -p, --player: Set a localskin to a specific player name.\n\ + If omitted, defaults to the client player, unless -d \n\ + or --display is added."); + ap_set_version(parser, ""); + ap_str_opt(parser, "player p", player_names[consoleplayer]); + ap_flag(parser, "display d"); + ap_flag(parser, "all a"); -static void Command_Localskin3 (void) { - if (!Playing() && !demo.playback) - { - CONS_Printf("You can only use this command in gameplay.\n"); - return; - } - if (COM_Argc() != 2) - { - CONS_Printf("localskin3 : Set a localskin.\n"); - return; - } - SetLocalPlayerSkin(displayplayers[2], COM_Argv(1), &cv_localskin3); -} + ap_parse(parser, COM_Argc(), COM_ArgvList()); -static void Command_Localskin4 (void) { - if (!Playing() && !demo.playback) - { - CONS_Printf("You can only use this command in gameplay.\n"); - return; - } - if (COM_Argc() != 2) - { - CONS_Printf("localskin4 : Set a localskin.\n"); - return; - } - SetLocalPlayerSkin(displayplayers[3], COM_Argv(1), &cv_localskin4); -} + boolean disply; + boolean allp; -static void Command_LocalskinAll (void) { - if (!Playing() && !demo.playback) - { - CONS_Printf("You can only use this command in gameplay.\n"); - return; - } - if (COM_Argc() != 2) - { - CONS_Printf("localskinall : Set a localskin to all players.\n"); - return; - } - INT32 i; - for (i; i < MAXPLAYERS; i++) { - SetLocalPlayerSkin(i, COM_Argv(1), &cv_localskinall); + if (ap_found(parser, "display")) disply = true; else disply = false; + if (ap_found(parser, "all")) allp = true; else allp = false; + + INT32 i, idx; + i = 0; + idx = 0; + + for (idx = 0; idx < ap_count_args(parser); idx++) { + if (disply) { + SetLocalPlayerSkin(displayplayers[0], ap_arg(parser, idx), &cv_localskin); + return; + } else { + for (i = 0; i < MAXPLAYERS; i++) { + if (allp) { + SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskinall); + } else { + if (fasticmp(player_names[i], ap_str_value(parser, "player"))) { + SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskin); + break; + } + } + } + } } + + ap_free(parser); } #ifdef DELFILE diff --git a/src/p_enemy.c b/src/p_enemy.c index 1812ede5d..ecdb8c376 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4173,6 +4173,12 @@ void A_SignPlayer(mobj_t *actor) // same thing happens on p_mobj.c ov->localskin = &localskins[actor->target->player->localskin - 1]; ov->skinlocal = actor->target->skinlocal; + } else { + // needs - 1 or else it pukes an error out + // same thing happens on p_mobj.c + if (actor->target->player->localskin) + ov->localskin = &skins[actor->target->player->localskin - 1]; + ov->skinlocal = actor->target->skinlocal; } P_SetMobjState(ov, actor->info->seestate); // S_PLAY_SIGN } diff --git a/src/r_things.c b/src/r_things.c index 4d21ed574..0f99661c6 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2880,7 +2880,9 @@ void R_InitSkins(void) strncpy(skin->facerank, "PLAYRANK", 9); strncpy(skin->facewant, "PLAYWANT", 9); strncpy(skin->facemmap, "PLAYMMAP", 9); + skin->wadnum = 0; // god what have you brought to this world skin->prefcolor = SKINCOLOR_BLUE; + skin->localskin = false; // SRB2kart skin->kartspeed = 8; @@ -3030,10 +3032,12 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) } } + /* if (player->localskin > 0) CV_StealthSet(cvar, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name); else CV_StealthSet(cvar, "none"); + */ } // Same as SetPlayerSkin, but uses the skin #. @@ -3489,6 +3493,8 @@ next_token: Forceskin_cons_t[numskins+1].value = numskins; Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name; } + + skin->localskin = local; // add face graphics if (local) { diff --git a/src/r_things.h b/src/r_things.h index 2d9e7a47f..af4b98e6b 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -97,6 +97,8 @@ typedef struct // specific sounds per skin sfxenum_t soundsid[NUMSKINSOUNDS]; // sound # in S_sfx table + + boolean localskin; } skin_t; extern CV_PossibleValue_t Forceskin_cons_t[]; From 71e4005226874ca6dc333873284f07d5cd65c7e8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 19:12:56 +0200 Subject: [PATCH 020/239] add menu n shit https://git.do.srb2.org/haya_/Kart-Public/-/commit/b85a55137cfef0a18b297c59e62018586323a2e9 --- src/d_netcmd.c | 22 ++++++------- src/d_netcmd.h | 6 ++-- src/lua_mobjlib.c | 18 +++++------ src/m_menu.c | 82 ++++++++++++++++++++++++++++++++++++++--------- src/r_things.c | 69 +++++++++++++++++++++------------------ src/r_things.h | 2 ++ 6 files changed, 128 insertions(+), 71 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f7e13dc92..756d5607f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -294,10 +294,6 @@ consvar_t cv_skin3 = {"skin3", DEFAULTSKIN3, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Sk consvar_t cv_skin4 = {"skin4", DEFAULTSKIN4, CV_SAVE|CV_CALL|CV_NOINIT, NULL, Skin4_OnChange, 0, NULL, NULL, 0, 0, NULL}; // 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_localskin2 = {"internal___localskin2", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskin3 = {"internal___localskin3", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskin4 = {"internal___localskin4", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_localskinall = {"internal___localskinall", "none", CV_HIDEN, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipmapcheck = {"skipmapcheck", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -456,6 +452,7 @@ static CV_PossibleValue_t basenumlaps_cons_t[] = {{1, "MIN"}, {50, "MAX"}, {0, " consvar_t cv_basenumlaps = {"basenumlaps", "Map default", CV_NETVAR|CV_CALL|CV_CHEAT, basenumlaps_cons_t, BaseNumLaps_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_forceskin = {"forceskin", "Off", CV_NETVAR|CV_CALL|CV_CHEAT, Forceskin_cons_t, ForceSkin_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fakelocalskin = {"fakelocalskin", "None", CV_SAVE, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_downloading = {"downloading", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowexitlevel = {"allowexitlevel", "No", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -477,6 +474,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_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}; @@ -788,6 +786,9 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_showping); CV_RegisterVar(&cv_pingmeasurement); + CV_RegisterVar(&cv_luaimmersion); + CV_RegisterVar(&cv_fakelocalskin); + CV_RegisterVar(&cv_minihead); CV_RegisterVar(&cv_showminimapnames); @@ -901,18 +902,14 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_playername2); CV_RegisterVar(&cv_playercolor2); CV_RegisterVar(&cv_skin2); - CV_RegisterVar(&cv_localskin2); // third player CV_RegisterVar(&cv_playername3); CV_RegisterVar(&cv_playercolor3); CV_RegisterVar(&cv_skin3); - CV_RegisterVar(&cv_localskin3); // fourth player CV_RegisterVar(&cv_playername4); CV_RegisterVar(&cv_playercolor4); CV_RegisterVar(&cv_skin4); - CV_RegisterVar(&cv_localskin4); - CV_RegisterVar(&cv_localskinall); // preferred number of players CV_RegisterVar(&cv_splitplayers); @@ -4706,15 +4703,18 @@ static void Command_GLocalSkin (void) { for (idx = 0; idx < ap_count_args(parser); idx++) { if (disply) { - SetLocalPlayerSkin(displayplayers[0], ap_arg(parser, idx), &cv_localskin); + SetLocalPlayerSkin(displayplayers[0], ap_arg(parser, idx), NULL); return; } else { for (i = 0; i < MAXPLAYERS; i++) { if (allp) { - SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskinall); + SetLocalPlayerSkin(i, ap_arg(parser, idx), NULL); } else { if (fasticmp(player_names[i], ap_str_value(parser, "player"))) { - SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskin); + if (fasticmp(player_names[i], cv_playername.string)) + SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskin); + else + SetLocalPlayerSkin(i, ap_arg(parser, idx), NULL); break; } } diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 80c7078a0..e2c084e0d 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -26,18 +26,14 @@ extern consvar_t cv_localskin; extern consvar_t cv_playername2; extern consvar_t cv_playercolor2; extern consvar_t cv_skin2; -extern consvar_t cv_localskin2; // third splitscreen player extern consvar_t cv_playername3; extern consvar_t cv_playercolor3; extern consvar_t cv_skin3; -extern consvar_t cv_localskin3; // fourth splitscreen player extern consvar_t cv_playername4; extern consvar_t cv_playercolor4; extern consvar_t cv_skin4; -extern consvar_t cv_localskin4; -extern consvar_t cv_localskinall; // preferred number of players extern consvar_t cv_splitplayers; @@ -162,6 +158,8 @@ extern consvar_t cv_minihead; extern consvar_t cv_showlapemblem; extern consvar_t cv_showviewpointtext; +extern consvar_t cv_luaimmersion; +extern consvar_t cv_fakelocalskin; extern consvar_t cv_skipmapcheck; diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index a7f3d8580..39f9ab0bc 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -20,6 +20,7 @@ #include "g_game.h" #include "p_setup.h" #include "doomdef.h" +#include "d_netcmd.h" #include "lua_script.h" #include "lua_libs.h" @@ -351,11 +352,14 @@ int mobj_skin_getter(lua_State *L) if (!mo->skin) return 0; - if (mo->localskin) // pretty cool, but also destructive - lua_pushstring(L, ((skin_t *)mo->localskin)->name); - else + if (hud_running && cv_luaimmersion.value) { + if (mo->localskin) // HUD ONLY!!!!!!!!!! + lua_pushstring(L, ((skin_t *)mo->localskin)->name); + else + lua_pushstring(L, ((skin_t *)mo->skin)->name); + } else { lua_pushstring(L, ((skin_t *)mo->skin)->name); - + } return 1; } @@ -367,12 +371,6 @@ int mobj_skin_setter(lua_State *L) 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 - // nope, not this time chief. - if (fastcmp(localskins[players[consoleplayer].localskin - 1].name, skin)) - { - mo->skin = &skins[players[consoleplayer].skin]; // we dont want to use our local skin for this!!!!!!!!! - return 0; - } for (i = 0; i < numskins; i++) { { if (fastcmp(skins[i].name, skin)) diff --git a/src/m_menu.c b/src/m_menu.c index 872af2530..5189cd2e6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -234,6 +234,8 @@ menu_t SR_MainDef, SR_UnlockChecklistDef; static void M_SinglePlayerMenu(INT32 choice); #endif static void M_Options(INT32 choice); +static void M_LocalSkinMenu(INT32 choice); +static void M_LocalSkinChange(INT32 choice); static void M_Manual(INT32 choice); static void M_SelectableClearMenus(INT32 choice); static void M_Retry(INT32 choice); @@ -350,6 +352,9 @@ menu_t OP_SaturnCreditsDef; // Bird menu_t OP_BirdDef; +// Stuff, yknow. +menu_t OP_ForkedBirdDef; +menu_t OP_LocalSkinDef; menu_t OP_TiltDef; menu_t OP_AdvancedBirdDef; @@ -407,6 +412,7 @@ static void M_DrawConnectMenu(void); #endif static void M_DrawJoystick(void); static void M_DrawSetupMultiPlayerMenu(void); +static void M_DrawLocalSkinMenu(void); // Handling functions #ifndef NONET @@ -647,10 +653,11 @@ static menuitem_t MPauseMenu[] = {IT_STRING | IT_SUBMENU, NULL, "Switch Team...", &MISC_ChangeTeamDef, 48}, {IT_STRING | IT_SUBMENU, NULL, "Enter/Spectate...", &MISC_ChangeSpectateDef,48}, {IT_CALL | IT_STRING, NULL, "Player Setup...", M_SetupMultiPlayer, 56}, // alone - {IT_CALL | IT_STRING, NULL, "Options", M_Options, 64}, + {IT_CALL | IT_STRING, NULL, "Local Skin...", M_LocalSkinMenu, 64}, // alone + {IT_CALL | IT_STRING, NULL, "Options", M_Options, 72}, - {IT_CALL | IT_STRING, NULL, "Return to Title", M_EndGame, 80}, - {IT_CALL | IT_STRING, NULL, "Quit Game", M_QuitSRB2, 88}, + {IT_CALL | IT_STRING, NULL, "Return to Title", M_EndGame, 88}, + {IT_CALL | IT_STRING, NULL, "Quit Game", M_QuitSRB2, 96}, }; typedef enum @@ -674,6 +681,7 @@ typedef enum mpause_switchteam, mpause_switchspectate, mpause_psetup, + mpause_localskin, mpause_options, mpause_title, @@ -1128,6 +1136,7 @@ static menuitem_t OP_MainMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Saturn Options...", &OP_SaturnDef, 140}, {IT_SUBMENU|IT_STRING, NULL, "Bird", &OP_BirdDef, 150}, + {IT_CALL|IT_STRING, NULL, "Fork Options...", M_LocalSkinMenu, 160}, }; static menuitem_t OP_ControlsMenu[] = @@ -1812,6 +1821,17 @@ static menuitem_t OP_BirdMenu[] = {IT_STRING | IT_SUBMENU, NULL, "Advanced Music Options...", &OP_AdvancedBirdDef, 120}, }; +static menuitem_t OP_ForkedBirdMenu[] = +{ + {IT_HEADER, NULL, "Local Skins", NULL, 0}, + {IT_STRING | IT_CVAR | IT_CV_STRING, NULL, "Local Skin Name", &cv_fakelocalskin, 10}, + {IT_STRING2 | IT_SPACE, NULL, "Set to None for no Local Skin", NULL, 50}, + {IT_STRING | IT_CALL, NULL, "Apply to All Players", M_LocalSkinChange, 50}, + {IT_STRING | IT_CALL, NULL, "Apply to Displaying Player", M_LocalSkinChange, 60}, + {IT_STRING | IT_CALL, NULL, "Apply to Yourself", M_LocalSkinChange, 70}, + {IT_STRING | IT_CVAR, NULL, "Lua Immersion", &cv_luaimmersion, 90}, +}; + static menuitem_t OP_TiltMenu[] = { {IT_STRING | IT_CVAR, NULL, "Camera Tilting", &cv_tilting, 0}, @@ -2375,6 +2395,10 @@ menu_t OP_BirdDef = DEFAULTMENUSTYLE(NULL, OP_BirdMenu, &OP_MainDef, 30, 30); menu_t OP_TiltDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_BirdDef, 30, 60); menu_t OP_AdvancedBirdDef = DEFAULTMENUSTYLE(NULL, OP_AdvancedBirdMenu, &OP_BirdDef, 30, 60); +menu_t OP_ForkedBirdDef = DEFAULTMENUSTYLE(NULL, OP_ForkedBirdMenu, &OP_MainDef, 30, 30); +menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60); + + // ========================================================================== // CVAR ONCHANGE EVENTS GO HERE // ========================================================================== @@ -3571,7 +3595,7 @@ void M_StartControlPanel(void) else // multiplayer { MPauseMenu[mpause_switchmap].status = IT_DISABLED; - //MPauseMenu[mpause_addons].status = IT_DISABLED; + MPauseMenu[mpause_addons].status = IT_DISABLED; MPauseMenu[mpause_scramble].status = IT_DISABLED; MPauseMenu[mpause_psetupsplit].status = IT_DISABLED; MPauseMenu[mpause_psetupsplit2].status = IT_DISABLED; @@ -3593,9 +3617,10 @@ void M_StartControlPanel(void) MPauseMenu[mpause_switchteam].alphaKey = 48; MPauseMenu[mpause_switchspectate].alphaKey = 48; - MPauseMenu[mpause_options].alphaKey = 64; - MPauseMenu[mpause_title].alphaKey = 80; - MPauseMenu[mpause_quit].alphaKey = 88; + MPauseMenu[mpause_localskin].alphaKey = 64; + MPauseMenu[mpause_options].alphaKey = 72; + MPauseMenu[mpause_title].alphaKey = 88; + MPauseMenu[mpause_quit].alphaKey = 96; Dummymenuplayer_OnChange(); @@ -3605,6 +3630,9 @@ void M_StartControlPanel(void) MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; if (G_GametypeHasTeams()) MPauseMenu[mpause_scramble].status = IT_STRING | IT_SUBMENU; + } else { + MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; + MPauseMenu[mpause_addons].alphaKey += 8; } if (splitscreen) @@ -3618,6 +3646,7 @@ void M_StartControlPanel(void) { MPauseMenu[mpause_switchteam].status = IT_STRING | IT_SUBMENU; MPauseMenu[mpause_switchteam].alphaKey += ((splitscreen+1) * 8); + MPauseMenu[mpause_localskin].alphaKey += 8; MPauseMenu[mpause_options].alphaKey += 8; MPauseMenu[mpause_title].alphaKey += 8; MPauseMenu[mpause_quit].alphaKey += 8; @@ -3626,6 +3655,7 @@ void M_StartControlPanel(void) { MPauseMenu[mpause_switchspectate].status = IT_STRING | IT_SUBMENU; MPauseMenu[mpause_switchspectate].alphaKey += ((splitscreen+1) * 8); + MPauseMenu[mpause_localskin].alphaKey += 8; MPauseMenu[mpause_options].alphaKey += 8; MPauseMenu[mpause_title].alphaKey += 8; MPauseMenu[mpause_quit].alphaKey += 8; @@ -3636,6 +3666,7 @@ void M_StartControlPanel(void) { MPauseMenu[mpause_psetupsplit3].status = IT_STRING | IT_CALL; + MPauseMenu[mpause_localskin].alphaKey += 8; MPauseMenu[mpause_options].alphaKey += 8; MPauseMenu[mpause_title].alphaKey += 8; MPauseMenu[mpause_quit].alphaKey += 8; @@ -3643,6 +3674,7 @@ void M_StartControlPanel(void) if (splitscreen > 2) { MPauseMenu[mpause_psetupsplit4].status = IT_STRING | IT_CALL; + MPauseMenu[mpause_localskin].alphaKey += 8; MPauseMenu[mpause_options].alphaKey += 8; MPauseMenu[mpause_title].alphaKey += 8; MPauseMenu[mpause_quit].alphaKey += 8; @@ -4283,7 +4315,7 @@ static void M_DrawGenericMenu(void) y += STRINGHEIGHT; break; case IT_STRING2: - V_DrawString(x, y, lowercase, currentMenu->menuitems[i].text); + V_DrawString(((BASEVIDWIDTH - V_StringWidth(currentMenu->menuitems[i].text, 0))>>1), y, 0, currentMenu->menuitems[i].text); /* FALLTHRU */ case IT_DYLITLSPACE: y += SMALLLINEHEIGHT; @@ -6691,6 +6723,33 @@ static void M_Options(INT32 choice) OP_MainDef.prevMenu = currentMenu; M_SetupNextMenu(&OP_MainDef); } +static void M_LocalSkinMenu(INT32 choice) +{ + (void)choice; + + OP_ForkedBirdDef.prevMenu = currentMenu; + M_SetupNextMenu(&OP_ForkedBirdDef); +} + +static void M_LocalSkinChange(INT32 choice) +{ + (void)choice; + + switch (itemOn) { + case 3: + COM_BufAddText(va("localskin -a %s", cv_fakelocalskin.string)); + break; + case 4: + COM_BufAddText(va("localskin -d %s", cv_fakelocalskin.string)); + break; + case 5: + COM_BufAddText(va("localskin %s", cv_fakelocalskin.string)); + break; + default: + break; + } + S_StartSound(NULL, sfx_s221); +} static void M_Manual(INT32 choice) { @@ -10470,13 +10529,6 @@ static void M_DrawSetupMultiPlayerMenu(void) // draw box around guy V_DrawFill(mx + 43 - (charw/2), my+65, charw, 84, 239); - - if (setupm_skinlocal) - { - UINT8 *colmap; - colmap = R_GetTranslationColormap(setupm_fakeskin, setupm_fakecolor, GTC_MENUCACHE); - V_DrawFixedPatch(( mx + 43 - (charw/2) + 1 )<wadnum = 0; // god what have you brought to this world skin->prefcolor = SKINCOLOR_BLUE; skin->localskin = false; + skin->localnum = 0; // SRB2kart skin->kartspeed = 8; @@ -2922,6 +2923,20 @@ INT32 R_SkinAvailable(const char *name) return -1; } +// returns true if the skin name is found (loaded from pwad) +// warning return -1 if not found +INT32 R_AnySkinAvailable(const char *name) +{ + INT32 i; + + for (i = 0; i < numallskins; i++) + { + if (stricmp(allskins[i].name,name)==0) + return i; + } + return -1; +} + INT32 R_LocalSkinAvailable(const char *name, boolean local) { INT32 i; @@ -2968,13 +2983,6 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) { player_t *player = &players[playernum]; INT32 i; - - // this is where we're gonna use major mod for. - if (wadfiles[skins[player->skin].wadnum]->majormod && !demo.playback) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the player's skin is modifying the game.\n"), skinname); - return; - } if (strcasecmp(skinname, "none")) { @@ -2984,12 +2992,6 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (stricmp(localskins[i].name, skinname) == 0) { player->localskin = 1 + i; - if (wadfiles[localskins[player->localskin - 1].wadnum]->majormod && !demo.playback) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the localskin is a gameplay-modifying addon.\n"), skinname); - player->localskin = 0; - return; - } player->skinlocal = true; if (player->mo) { @@ -3005,12 +3007,6 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (stricmp(skins[i].name, skinname) == 0) { player->localskin = 1 + i; - if (wadfiles[skins[player->localskin - 1].wadnum]->majormod && !demo.playback) - { - CONS_Alert(CONS_ERROR, M_GetText("Cannot set localskin to %s because the skin is a gameplay-modifying addon.\n"), skinname); - player->localskin = 0; - return; - } player->skinlocal = false; if (player->mo) { @@ -3032,12 +3028,16 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) } } - /* - if (player->localskin > 0) - CV_StealthSet(cvar, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name); - else - CV_StealthSet(cvar, "none"); - */ + if (cvar != NULL) { + if (player->localskin > 0) { + CV_StealthSet(&cv_fakelocalskin, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name); + CV_StealthSet(cvar, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name); + } + else { + CV_StealthSet(&cv_fakelocalskin, "none"); + CV_StealthSet(cvar, "none"); + } + } } // Same as SetPlayerSkin, but uses the skin #. @@ -3495,6 +3495,11 @@ next_token: } skin->localskin = local; + // so we dont have to guess + if (local) + skin->localnum = numlocalskins; + else + skin->localnum = numskins; // add face graphics if (local) { @@ -3507,12 +3512,14 @@ next_token: if (rendermode == render_opengl) HWR_AddPlayerMD2(( (local) ? numlocalskins : numskins ), local); #endif - skinstats[skin->kartspeed-1][skin->kartweight-1][skinstatscount[skin->kartspeed-1][skin->kartweight-1]] = numskins; - CONS_Debug(DBG_SETUP, M_GetText("Added %d to %d, %d\n"), numskins, skin->kartweight, skin->kartweight); - skinstatscount[skin->kartspeed-1][skin->kartweight-1]++; - CONS_Debug(DBG_SETUP, M_GetText("Incremented %d, %d to %d\n"), skin->kartspeed, skin->kartweight, skinstatscount[skin->kartspeed - 1][skin->kartweight - 1]); - - skinsorted[numskins] = numskins; + if (!local) { + skinstats[skin->kartspeed-1][skin->kartweight-1][skinstatscount[skin->kartspeed-1][skin->kartweight-1]] = numskins; + CONS_Debug(DBG_SETUP, M_GetText("Added %d to %d, %d\n"), numskins, skin->kartweight, skin->kartweight); + skinstatscount[skin->kartspeed-1][skin->kartweight-1]++; + CONS_Debug(DBG_SETUP, M_GetText("Incremented %d, %d to %d\n"), skin->kartspeed, skin->kartweight, skinstatscount[skin->kartspeed - 1][skin->kartweight - 1]); + + skinsorted[numskins] = numskins; + } allskins[numallskins] = ( (local) ? localskins : skins )[( (local) ? numlocalskins : numskins )]; diff --git a/src/r_things.h b/src/r_things.h index af4b98e6b..833edd5fd 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -99,6 +99,7 @@ typedef struct sfxenum_t soundsid[NUMSKINSOUNDS]; // sound # in S_sfx table boolean localskin; + INT32 localnum; } skin_t; extern CV_PossibleValue_t Forceskin_cons_t[]; @@ -218,6 +219,7 @@ boolean SetPlayerSkin(INT32 playernum,const char *skinname); void SetPlayerSkinByNum(INT32 playernum,INT32 skinnum); // Tails 03-16-2002 void SetLocalPlayerSkin(INT32 playernum,const char *skinname, consvar_t *cvar); INT32 R_SkinAvailable(const char *name); +INT32 R_AnySkinAvailable(const char *name); INT32 R_LocalSkinAvailable(const char *name, boolean local); void R_AddSkins(UINT16 wadnum, boolean local); From 71056064754e4c2b22c3959984484b3edc7ad2db Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 19:14:41 +0200 Subject: [PATCH 021/239] more menu shit - Youll now get a preview of what skin is going to be used. - Removed redundant code https://git.do.srb2.org/haya_/Kart-Public/-/commit/a6728c26f76bfc94f7bc07aa076c8979c9bef5c9 --- src/m_menu.c | 176 +++++++++++++++++++++++++++++++++++++++++---------- src/w_wad.c | 9 --- 2 files changed, 143 insertions(+), 42 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 5189cd2e6..c5a2798f6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1825,11 +1825,11 @@ static menuitem_t OP_ForkedBirdMenu[] = { {IT_HEADER, NULL, "Local Skins", NULL, 0}, {IT_STRING | IT_CVAR | IT_CV_STRING, NULL, "Local Skin Name", &cv_fakelocalskin, 10}, - {IT_STRING2 | IT_SPACE, NULL, "Set to None for no Local Skin", NULL, 50}, - {IT_STRING | IT_CALL, NULL, "Apply to All Players", M_LocalSkinChange, 50}, - {IT_STRING | IT_CALL, NULL, "Apply to Displaying Player", M_LocalSkinChange, 60}, - {IT_STRING | IT_CALL, NULL, "Apply to Yourself", M_LocalSkinChange, 70}, - {IT_STRING | IT_CVAR, NULL, "Lua Immersion", &cv_luaimmersion, 90}, + {IT_STRING2 | IT_SPACE, NULL, "Set to None for no Local Skin", NULL, 20}, + {IT_STRING | IT_CALL, NULL, "Apply to All Players", M_LocalSkinChange, 140}, + {IT_STRING | IT_CALL, NULL, "Apply to Displaying Player", M_LocalSkinChange, 150}, + {IT_STRING | IT_CALL, NULL, "Apply to Yourself", M_LocalSkinChange, 160}, + {IT_STRING | IT_CVAR, NULL, "Lua Immersion", &cv_luaimmersion, 170}, }; static menuitem_t OP_TiltMenu[] = @@ -2395,7 +2395,17 @@ menu_t OP_BirdDef = DEFAULTMENUSTYLE(NULL, OP_BirdMenu, &OP_MainDef, 30, 30); menu_t OP_TiltDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_BirdDef, 30, 60); menu_t OP_AdvancedBirdDef = DEFAULTMENUSTYLE(NULL, OP_AdvancedBirdMenu, &OP_BirdDef, 30, 60); -menu_t OP_ForkedBirdDef = DEFAULTMENUSTYLE(NULL, OP_ForkedBirdMenu, &OP_MainDef, 30, 30); +menu_t OP_ForkedBirdDef = { + NULL, + sizeof(OP_ForkedBirdMenu)/sizeof(menuitem_t), + &OP_MainDef, + OP_ForkedBirdMenu, + M_DrawLocalSkinMenu, + 30, 6, + 0, + NULL +}; + menu_t OP_LocalSkinDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_ForkedBirdDef, 30, 60); @@ -6723,33 +6733,6 @@ static void M_Options(INT32 choice) OP_MainDef.prevMenu = currentMenu; M_SetupNextMenu(&OP_MainDef); } -static void M_LocalSkinMenu(INT32 choice) -{ - (void)choice; - - OP_ForkedBirdDef.prevMenu = currentMenu; - M_SetupNextMenu(&OP_ForkedBirdDef); -} - -static void M_LocalSkinChange(INT32 choice) -{ - (void)choice; - - switch (itemOn) { - case 3: - COM_BufAddText(va("localskin -a %s", cv_fakelocalskin.string)); - break; - case 4: - COM_BufAddText(va("localskin -d %s", cv_fakelocalskin.string)); - break; - case 5: - COM_BufAddText(va("localskin %s", cv_fakelocalskin.string)); - break; - default: - break; - } - S_StartSound(NULL, sfx_s221); -} static void M_Manual(INT32 choice) { @@ -11972,6 +11955,133 @@ static void M_DrawHUDOptions(void) V_DrawRightAlignedString(x, y, highlightflags, "("); } +static void M_LocalSkinMenu(INT32 choice) +{ + (void)choice; + + multi_state = &states[mobjinfo[MT_PLAYER].seestate]; + multi_tics = multi_state->tics; + + OP_ForkedBirdDef.prevMenu = currentMenu; + M_SetupNextMenu(&OP_ForkedBirdDef); +} + +static void M_LocalSkinChange(INT32 choice) +{ + (void)choice; + + switch (itemOn) { + case 3: + COM_BufAddText(va("localskin -a %s", cv_fakelocalskin.string)); + break; + case 4: + COM_BufAddText(va("localskin -d %s", cv_fakelocalskin.string)); + break; + case 5: + COM_BufAddText(va("localskin %s", cv_fakelocalskin.string)); + break; + default: + break; + } + S_StartSound(NULL, sfx_s221); +} + +// Display our localskin in our goofy ahhhh local skin menu +static void M_DrawLocalSkinMenu(void) +{ + INT32 mx, my, st, flags = 0; + spritedef_t *sprdef; + spriteframe_t *sprframe; + patch_t *patch; + UINT8 frame; + UINT8 skintodisplay; + UINT32 speenframe; + + mx = OP_ForkedBirdDef.x; + my = OP_ForkedBirdDef.y; + + // use generic drawer for cursor, items and title + M_DrawGenericMenu(); + + #define charw 72 + + // anim the player in the box + if (--multi_tics <= 0) + { + st = multi_state->nextstate; + if (st != S_NULL) + multi_state = &states[st]; + multi_tics = multi_state->tics; + if (multi_tics == -1) + multi_tics = 15; + } + + // skin 0 is default player sprite + if (R_AnySkinAvailable(cv_fakelocalskin.string) != -1) + { + sprdef = &allskins[R_AnySkinAvailable(cv_fakelocalskin.string)].spritedef; + skintodisplay = R_AnySkinAvailable(cv_fakelocalskin.string); + } + else + { + // ATTEMPT TO FIND REAL SKIN + if (R_AnySkinAvailable(cv_skin.string) != -1) + { + sprdef = &allskins[R_AnySkinAvailable(cv_skin.string)].spritedef; + skintodisplay = R_AnySkinAvailable(cv_skin.string); + } else { // STILL NOTHIN? use sonic instead + sprdef = &allskins[0].spritedef; + skintodisplay = 0; + } + } + + if (!sprdef->numframes) // No frames ?? + return; // Can't render! + + frame = multi_state->frame & FF_FRAMEMASK; + if (frame >= sprdef->numframes) // Walking animation missing + frame = 0; // Try to use standing frame + + sprframe = &sprdef->spriteframes[frame]; + + //minenice's speen css, it's a piece of shit but hey + //patch = W_CachePatchNum(sprframe->lumppat[1], PU_CACHE); + speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; + + //this is a very shitty solution for checking if a sprite needs flipping + //but it works + if ((sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe]) && (speenframe > 4)) { + flags = V_FLIP; // This sprite is left/right flipped! + } + patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_CACHE); + + // draw box around guy + V_DrawFill(mx + 220 - (charw/2), my+54, charw, 84, 239); + + // draw player sprite + UINT8 *colormap = R_GetTranslationColormap(skintodisplay, cv_playercolor.value, GTC_MENUCACHE); + colormap = R_GetLocalTranslationColormap(&skins[allskins[skintodisplay].localnum], (allskins[skintodisplay].localskin ? &localskins[allskins[skintodisplay].localnum] : NULL), cv_playercolor.value, GTC_MENUCACHE, allskins[skintodisplay].localskin); + + V_DrawMappedPatch(mx, my+50, 0, W_CachePatchName(allskins[skintodisplay].facewant, PU_CACHE), colormap); + V_DrawMappedPatch(mx+8, my+85, 0, W_CachePatchName(allskins[skintodisplay].facerank, PU_CACHE), colormap); + V_DrawString(mx, my+108, V_ALLOWLOWERCASE, "Character"); + if (strlen(allskins[skintodisplay].realname) > 10) + V_DrawThinString(mx+20, my+118, V_ALLOWLOWERCASE|highlightflags, allskins[skintodisplay].realname); + else + V_DrawString(mx+20, my+118, V_ALLOWLOWERCASE|highlightflags, allskins[skintodisplay].realname); + + if (allskins[skintodisplay].flags & SF_HIRES) + { + V_DrawFixedPatch((mx+220)< Date: Wed, 30 Aug 2023 19:15:22 +0200 Subject: [PATCH 022/239] smol fix --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index c5a2798f6..ea58fec96 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12046,7 +12046,7 @@ static void M_DrawLocalSkinMenu(void) //minenice's speen css, it's a piece of shit but hey //patch = W_CachePatchNum(sprframe->lumppat[1], PU_CACHE); - speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; + speenframe = (I_GetTime()*4/TICRATE + 1)%8; //this is a very shitty solution for checking if a sprite needs flipping //but it works From 002c5502637a78e189afdd2bf7972c0c231c3e37 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 19:17:51 +0200 Subject: [PATCH 023/239] more fixes ugh --- src/d_netcmd.c | 2 +- src/m_menu.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 756d5607f..6460b7c62 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4659,7 +4659,7 @@ Command_Addskins (void) return; } else { */ - P_AddWadFile(COM_Argv(1), 0, true); + P_AddWadFile(COM_Argv(1), true); /* } } else { diff --git a/src/m_menu.c b/src/m_menu.c index ea58fec96..033268539 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5671,7 +5671,7 @@ static void M_HandleAddons(INT32 choice) // no characters? if (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\" -force", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + COM_BufAddText(va("addskins \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); } else S_StartSound(NULL, sfx_s26d); From a4e96d2380836f0cf30dcf68b5c6545d1fd26bcb Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 30 Aug 2023 19:20:35 +0200 Subject: [PATCH 024/239] bruh --- src/Makefile | 1 + src/args.c | 48 ++++++++++++++++++++++++------------------------ src/args.h | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/Makefile b/src/Makefile index 6825d5600..064c6b0be 100644 --- a/src/Makefile +++ b/src/Makefile @@ -626,6 +626,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/lzf.o \ $(OBJDIR)/vid_copy.o \ $(OBJDIR)/b_bot.o \ + $(OBJDIR)/args.o \ $(i_cdmus_o) \ $(i_net_o) \ $(i_system_o) \ diff --git a/src/args.c b/src/args.c index 465208e47..88eec9092 100644 --- a/src/args.c +++ b/src/args.c @@ -1,4 +1,4 @@ -#include +#include "doomtype.h" #include #include #include @@ -106,7 +106,7 @@ static void vec_free(Vec* vec) { } -static bool vec_add(Vec* vec, void* entry) { +static boolean vec_add(Vec* vec, void* entry) { if (vec->count + 1 > vec->capacity) { int new_capacity = vec->capacity < 8 ? 8 : vec->capacity * 2; void** new_array = realloc(vec->entries, sizeof(void*) * new_capacity); @@ -191,7 +191,7 @@ static MapEntry* map_find(Map* map, const char* key, uint32_t key_hash) { } -static bool map_grow(Map* map) { +static boolean map_grow(Map* map) { MapEntry* old_entries = map->entries; int old_capacity = map->capacity; int new_capacity = old_capacity < 8 ? 8 : old_capacity * 2; @@ -227,7 +227,7 @@ static bool map_grow(Map* map) { // Returns true if the key was found. -static bool map_get(Map* map, const char* key, void** value) { +static boolean map_get(Map* map, const char* key, void** value) { if (map->count == 0) return false; uint32_t key_hash = str_hash(key); @@ -241,7 +241,7 @@ static bool map_get(Map* map, const char* key, void** value) { // Adds a new entry to the map or updates the value of an existing entry. // (Note that the map stores its own internal copy of the key string.) -static bool map_set(Map* map, const char* key, void* value) { +static boolean map_set(Map* map, const char* key, void* value) { if (map->count == map->max_load_threshold) { if (!map_grow(map)) { return false; @@ -269,7 +269,7 @@ static bool map_set(Map* map, const char* key, void* value) { // Convenience wrapper for map_set(). This splits the key string into space- // separated words and adds a separate entry to the map for each word. -static bool map_set_splitkey(Map* map, const char* key_string, void* value) { +static boolean map_set_splitkey(Map* map, const char* key_string, void* value) { char *copy_of_key_string = str_dup(key_string); if (!copy_of_key_string) { return false; @@ -343,7 +343,7 @@ static void option_free(Option* opt) { } -static bool option_append_value(Option* opt, OptionValue value) { +static boolean option_append_value(Option* opt, OptionValue value) { if (opt->count + 1 > opt->capacity) { int new_capacity = opt->capacity < 4 ? 4 : opt->capacity * 2; OptionValue* new_array = realloc(opt->values, sizeof(OptionValue) * new_capacity); @@ -359,7 +359,7 @@ static bool option_append_value(Option* opt, OptionValue value) { } -static bool option_try_set(Option* opt, char* arg) { +static boolean option_try_set(Option* opt, char* arg) { if (opt->type == OPT_STR) { return option_append_value(opt, (OptionValue){.str_val = arg}); } @@ -579,7 +579,7 @@ static char* argstream_next(ArgStream* stream) { } -static bool argstream_has_next(ArgStream* stream) { +static boolean argstream_has_next(ArgStream* stream) { return stream->index < stream->count; } @@ -600,10 +600,10 @@ struct ArgParser { ap_callback_t callback; char* cmd_name; struct ArgParser* cmd_parser; - bool enable_help_command; - bool had_memory_error; + boolean enable_help_command; + boolean had_memory_error; struct ArgParser* parent; - bool first_positional_arg_ends_options; + boolean first_positional_arg_ends_options; }; @@ -748,7 +748,7 @@ char* ap_get_version(ArgParser* parser) { } -void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable) { +void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable) { parser->first_positional_arg_ends_options = enable; } @@ -832,7 +832,7 @@ int ap_count(ArgParser* parser, const char* name) { // Returns true if the specified flag or option was found. -bool ap_found(ArgParser* parser, const char* name) { +boolean ap_found(ArgParser* parser, const char* name) { Option* opt = ap_get_opt(parser, name); return opt->count > 0; } @@ -913,7 +913,7 @@ double* ap_dbl_values(ArgParser* parser, const char* name) { // Returns true if the parser has found one or more positional arguments. -bool ap_has_args(ArgParser* parser) { +boolean ap_has_args(ArgParser* parser) { return parser->positional_args->count > 0; } @@ -1016,7 +1016,7 @@ void ap_callback(ArgParser* parser, ap_callback_t function) { // Returns true if the parser has found a command. -bool ap_has_cmd(ArgParser* parser) { +boolean ap_has_cmd(ArgParser* parser) { return parser->cmd_name != NULL; } @@ -1034,7 +1034,7 @@ ArgParser* ap_cmd_parser(ArgParser* parser) { // Toggles support for the automatic 'help' command. -void ap_enable_help_command(ArgParser* parser, bool enable) { +void ap_enable_help_command(ArgParser* parser, boolean enable) { parser->enable_help_command = enable; } @@ -1056,7 +1056,7 @@ static void ap_handle_equals_opt(ArgParser* parser, const char* prefix, const ch char *value = strchr(arg, '=') + 1; Option* option; - bool found = map_get(parser->option_map, name, (void**)&option); + boolean found = map_get(parser->option_map, name, (void**)&option); if (!found || option->type == OPT_FLAG) { err(va("%s%s is not a recognised option name", prefix, name)); @@ -1101,7 +1101,7 @@ static void ap_handle_short_opt(ArgParser* parser, const char* arg, ArgStream* s for (size_t i = 0; i < strlen(arg); i++) { char keystr[] = {arg[i], 0}; Option* option; - bool found = map_get(parser->option_map, keystr, (void**)&option); + boolean found = map_get(parser->option_map, keystr, (void**)&option); if (!found) { if (arg[i] == 'h' && parser->helptext != NULL) { CONS_Printf("%s\n", parser->helptext); @@ -1134,7 +1134,7 @@ static void ap_parse_stream(ArgParser* parser, ArgStream* stream) { } ArgParser* cmd_parser; - bool is_first_arg = true; + boolean is_first_arg = true; while (argstream_has_next(stream)) { char* arg = argstream_next(stream); @@ -1216,7 +1216,7 @@ static void ap_parse_stream(ArgParser* parser, ArgStream* stream) { // Parse an array of string arguments. -static bool ap_parse_array(ArgParser* parser, int count, char* args[]) { +static boolean ap_parse_array(ArgParser* parser, int count, char* args[]) { if (parser->had_memory_error) { return false; } @@ -1237,7 +1237,7 @@ static bool ap_parse_array(ArgParser* parser, int count, char* args[]) { // are the arguments passed to main(), i.e. that the first element in [argv] is the program's name // and should be ignored when parsing the actual *arguments*. In some situations [argv] can be // empty, i.e. [argc == 0], which can lead to security vulnerabilities if not explicitly handled. -bool ap_parse(ArgParser* parser, int argc, char* argv[]) { +boolean ap_parse(ArgParser* parser, int argc, char* argv[]) { if (argc > 1) { return ap_parse_array(parser, argc - 1, argv + 1); } @@ -1250,7 +1250,7 @@ bool ap_parse(ArgParser* parser, int argc, char* argv[]) { /* --------------------- */ -bool ap_had_memory_error(ArgParser* parser) { +boolean ap_had_memory_error(ArgParser* parser) { return parser->had_memory_error; } @@ -1294,7 +1294,7 @@ void ap_print(ArgParser* parser) { /* --------------------- */ -void ap_cmd_help(ArgParser* parser, bool enable) { +void ap_cmd_help(ArgParser* parser, boolean enable) { ap_enable_help_command(parser, enable); } diff --git a/src/args.h b/src/args.h index 39cd57b5c..e2db1e501 100644 --- a/src/args.h +++ b/src/args.h @@ -8,7 +8,7 @@ #ifndef args_h #define args_h -#include +#include "doomtype.h" // ----------------------------------------------------------------------------- // Types. @@ -51,7 +51,7 @@ char* ap_get_version(ArgParser* parser); // If toggled to true, the first positional argument ends option parsing; all // subsequent arguments will be treated as positionals. Defaults to false. -void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable); +void ap_first_pos_arg_ends_options(ArgParser* parser, boolean enable); // Parses the application's command line arguments. The parameters are assumed // to be [argc] and [argv] as supplied to main(), i.e. the first element of the @@ -59,7 +59,7 @@ void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable); // if the arguments were successfully parsed. Returns false if parsing failed // due to a memory allocation error. (This memory allocation error may have // occured during set-up rather than during parsing.) -bool ap_parse(ArgParser* parser, int argc, char** argv); +boolean ap_parse(ArgParser* parser, int argc, char** argv); // Frees the memory associated with the parser and any subparsers. void ap_free(ArgParser* parser); @@ -88,7 +88,7 @@ void ap_dbl_opt(ArgParser* parser, const char* name, double fallback); int ap_count(ArgParser* parser, const char* name); // Returns true if the specified flag or option was found. -bool ap_found(ArgParser* parser, const char* name); +boolean ap_found(ArgParser* parser, const char* name); // Returns the value of a string option. char* ap_str_value(ArgParser* parser, const char* name); @@ -128,7 +128,7 @@ double* ap_dbl_values(ArgParser* parser, const char* name); // ----------------------------------------------------------------------------- // Returns true if the parser has found one or more positional arguments. -bool ap_has_args(ArgParser* parser); +boolean ap_has_args(ArgParser* parser); // Returns the number of positional arguments. int ap_count_args(ArgParser* parser); @@ -166,7 +166,7 @@ ArgParser* ap_cmd(ArgParser* parser, const char* name); void ap_callback(ArgParser* parser, ap_callback_t function); // Returns true if the parser has found a command. -bool ap_has_cmd(ArgParser* parser); +boolean ap_has_cmd(ArgParser* parser); // Returns the command name, if the parser has found a command. char* ap_cmd_name(ArgParser* parser); @@ -174,11 +174,11 @@ char* ap_cmd_name(ArgParser* parser); // Returns the command's parser instance, if the parser has found a command. ArgParser* ap_cmd_parser(ArgParser* parser); -// This boolean switch toggles support for an automatic 'help' command that +// This booleanean switch toggles support for an automatic 'help' command that // prints subcommand helptext. The value defaults to false but gets toggled // automatically to true whenever a command is registered. You can use this // function to disable the feature if required. -void ap_enable_help_command(ArgParser* parser, bool enable); +void ap_enable_help_command(ArgParser* parser, boolean enable); // ----------------------------------------------------------------------------- // Debugging utilities. @@ -188,14 +188,14 @@ void ap_enable_help_command(ArgParser* parser, bool enable); void ap_print(ArgParser* parser); // True if an attempt to allocate memory failed. -bool ap_had_memory_error(ArgParser* parser); +boolean ap_had_memory_error(ArgParser* parser); // ----------------------------------------------------------------------------- // Deprecated. // ----------------------------------------------------------------------------- // Replaced by ap_enable_help_command(). -void ap_cmd_help(ArgParser* parser, bool enable); +void ap_cmd_help(ArgParser* parser, boolean enable); // Replaced by ap_set_helptext(). void ap_helptext(ArgParser* parser, const char* helptext); From 9ba5c9a38b3817f558b900fd08abfb2938709c52 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 31 Aug 2023 03:35:42 +0200 Subject: [PATCH 025/239] bruuuuuh --- src/k_kart.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 5fc7a1bd0..0f2170263 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8665,11 +8665,16 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags, pat UINT8 *colormap = R_GetTranslationColormap((mo->colorized) ? TC_RAINBOW : skin, mo->color, GTC_CACHE); if (cv_minihead.value == 1) - V_DrawFixedPatch(amxpos + (2 * FRACUNIT), amypos + (2 * FRACUNIT), FRACUNIT/2, flags, 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); - + 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_showminimapnames.value && !(modeattacking || gamestate == GS_TIMEATTACK)) { const char *player_name = va("%c%s", V_GetSkincolorChar(mo->color), player_names[mo->player - players]); From d48b08856e43ccadd779c54f3da863c697fd6051 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 31 Aug 2023 10:42:43 +0200 Subject: [PATCH 026/239] 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); From 0a6f700c6fb34fd73db9812f21332207edde3627 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 31 Aug 2023 13:59:30 +0300 Subject: [PATCH 027/239] Addon browser can now be in 2 states - loading addons and loading localskins, which fixes its behavior when trying to load character addon as server admin --- src/m_menu.c | 54 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 033268539..ba3df2e82 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -145,6 +145,8 @@ INT32 mapwads[NUMMAPS]; //static char *char_notes = NULL; //static fixed_t char_scroll = 0; +boolean browselocalskins = false; + boolean menuactive = false; boolean fromlevelselect = false; @@ -338,7 +340,9 @@ menu_t OP_MonitorToggleDef; static void M_ScreenshotOptions(INT32 choice); static void M_EraseData(INT32 choice); +static void M_AddonsInternal(); static void M_Addons(INT32 choice); +static void M_LocalSkins(INT32 choice); static void M_AddonsOptions(INT32 choice); static patch_t *addonsp[NUM_EXT+5]; @@ -633,12 +637,13 @@ typedef enum // --------------------- static menuitem_t MPauseMenu[] = { - {IT_STRING | IT_CALL, NULL, "Addons...", M_Addons, 8}, - {IT_STRING | IT_SUBMENU, NULL, "Scramble Teams...", &MISC_ScrambleTeamDef, 16}, - {IT_STRING | IT_CALL, NULL, "Switch Map..." , M_MapChange, 24}, + {IT_STRING | IT_CALL, NULL, "Addons...", M_Addons, 8}, + {IT_STRING | IT_CALL, NULL, "Add local skins...", M_LocalSkins, 16}, + {IT_STRING | IT_SUBMENU, NULL, "Scramble Teams...", &MISC_ScrambleTeamDef, 24}, + {IT_STRING | IT_CALL, NULL, "Switch Map..." , M_MapChange, 32}, #ifdef HAVE_DISCORDRPC - {IT_STRING | IT_SUBMENU, NULL, "Ask To Join Requests...", &MISC_DiscordRequestsDef, 24}, + {IT_STRING | IT_SUBMENU, NULL, "Ask To Join Requests...", &MISC_DiscordRequestsDef, 32}, #endif {IT_CALL | IT_STRING, NULL, "Continue", M_SelectableClearMenus, 40}, @@ -663,6 +668,7 @@ static menuitem_t MPauseMenu[] = typedef enum { mpause_addons = 0, + mpause_addlocalskins, mpause_scramble, mpause_switchmap, #ifdef HAVE_DISCORDRPC @@ -3622,6 +3628,7 @@ void M_StartControlPanel(void) // Reset these in case splitscreen messes things up MPauseMenu[mpause_addons].alphaKey = 8; + MPauseMenu[mpause_addlocalskins].alphaKey = 16; MPauseMenu[mpause_scramble].alphaKey = 8; MPauseMenu[mpause_switchmap].alphaKey = 24; @@ -3640,9 +3647,6 @@ void M_StartControlPanel(void) MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; if (G_GametypeHasTeams()) MPauseMenu[mpause_scramble].status = IT_STRING | IT_SUBMENU; - } else { - MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; - MPauseMenu[mpause_addons].alphaKey += 8; } if (splitscreen) @@ -5152,12 +5156,10 @@ static void M_AddonsOptions(INT32 choice) #define LOCATIONSTRING1 "Visit \x83SRB2.ORG/MODS\x80 to get & make addons!" #define LOCATIONSTRING2 "Visit \x88SRB2.ORG/MODS\x80 to get & make addons!" -static void M_Addons(INT32 choice) +static void M_AddonsInternal() { const char *pathname = "."; - (void)choice; - #if 1 if (cv_addons_option.value == 0) pathname = usehome ? srb2home : srb2path; @@ -5218,6 +5220,20 @@ static void M_Addons(INT32 choice) M_SetupNextMenu(&MISC_AddonsDef); } +static void M_Addons(INT32 choice) +{ + (void)choice; + browselocalskins = false; + M_AddonsInternal(); +} + +static void M_LocalSkins(INT32 choice) +{ + (void)choice; + browselocalskins = true; + M_AddonsInternal(); +} + #define width 4 #define vpadding 27 #define h (BASEVIDHEIGHT-(2*vpadding)) @@ -5370,7 +5386,12 @@ static void M_DrawAddons(void) } if (Playing()) - V_DrawCenteredString(BASEVIDWIDTH/2, 5, warningflags, "Adding files mid-game may cause problems."); + { + if (browselocalskins) + V_DrawCenteredString(BASEVIDWIDTH/2, 5, V_ALLOWLOWERCASE, "Load \x83local skins\x80 from addons!"); + else + V_DrawCenteredString(BASEVIDWIDTH/2, 5, warningflags, "Adding files mid-game may cause problems."); + } else V_DrawCenteredString(BASEVIDWIDTH/2, 5, 0, (recommendedflags == V_SKYMAP ? LOCATIONSTRING2 : LOCATIONSTRING1)); @@ -5667,14 +5688,9 @@ static void M_HandleAddons(INT32 choice) case EXT_KART: #endif case EXT_PK3: - if (netgame || multiplayer) { - // no characters? - if (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)); - } - else - S_StartSound(NULL, sfx_s26d); + if (browselocalskins) { + 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)); } else COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); From 5760f25c74edd574c1c49c4704b4d7d463866786 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 31 Aug 2023 13:41:25 +0200 Subject: [PATCH 028/239] readd the namecheck to addlocalskin menu until we find a better way to check for skins c: --- src/m_menu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index ba3df2e82..965221e6e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5689,8 +5689,12 @@ static void M_HandleAddons(INT32 choice) #endif case EXT_PK3: if (browselocalskins) { - 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)); + if (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)); + } + else + S_StartSound(NULL, sfx_s26d); } else COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); From 2c1201ff34f28d9c4fd9ee585f4fc5ba1e60e9d4 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 1 Sep 2023 12:45:23 +0300 Subject: [PATCH 029/239] Add mo.rollsum and player.sliproll fields. Rendering and frame interpolation code was used, so they are NOT synch safe! --- src/lua_mobjlib.c | 31 ++++++++++++++++++++++++++ src/lua_playerlib.c | 16 ++++++++++++++ src/r_defs.h | 1 + src/r_main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/r_main.h | 1 + 5 files changed, 103 insertions(+) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 91c2158e8..22cb0f00a 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -16,6 +16,7 @@ #ifdef HAVE_BLUA #include "fastcmp.h" #include "r_things.h" +#include "r_main.h" #include "p_local.h" #include "g_game.h" #include "p_setup.h" @@ -65,6 +66,8 @@ int mobj_mobjnum_unimplemented(lua_State *L); int mobj_scale_setter(lua_State *L); int mobj_destscale_setter(lua_State *L); int mobj_standingslope_noset(lua_State *L); +int mobj_rollsum_getter(lua_State *L); +int mobj_rollsum_noset(lua_State *L); static const char *const array_opt[] ={"iterate",NULL}; @@ -78,6 +81,8 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, angle, udatalib_getter_angle, mobj_angle_setter), FIELD(mobj_t, rollangle, udatalib_getter_angle, udatalib_setter_angle), FIELD(mobj_t, sloperoll, udatalib_getter_angle, mobj_sloperoll_noop), + // Macro fails here + { "rollsum", 0, mobj_rollsum_getter, mobj_rollsum_noset }, FIELD(mobj_t, sprite, udatalib_getter_spritenum, udatalib_setter_spritenum), FIELD(mobj_t, frame, udatalib_getter_uint32, udatalib_setter_uint32), FIELD(mobj_t, anim_duration, udatalib_getter_uint16, udatalib_setter_uint16), @@ -174,13 +179,21 @@ int mobj_ ## field ## _noset(lua_State *L) \ return luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " should not be set directly.", #field); \ } +#define NOSET_USE(field, use) \ +int mobj_ ## field ## _noset(lua_State *L) \ +{ \ + return luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " should not be set directly. Use " LUA_QL(use) " instead.", #field); \ +} + NOSET(snext) NOSET(bnext) NOSET(info) NOSET(player) NOSET(standingslope) +NOSET_USE(rollsum, "rollangle") #undef NOSET +#undef NOSET_USE // Unimplemented fields (why would you need to set them like that explicitly? // No idea, i'm keeping it for synch reasons) @@ -539,6 +552,24 @@ int mobj_destscale_setter(lua_State *L) return 0; } +// WARNING: Not synch safe! +// Don't use this field in game logic code! +int mobj_rollsum_getter(lua_State *L) +{ + mobj_t *mo = GETMO(); + + angle_t rollsum = mo->rollangle + cv_sloperoll.value ? mo->sloperoll : 0; + + if (mo->player) + { + rollsum += R_PlayerSliptideAngle(mo->player); + } + + lua_pushangle(L, rollsum); + + return 1; +} + static int mobj_get(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index c687921ec..8ce7840f3 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -13,6 +13,7 @@ #include "doomdef.h" #ifdef HAVE_BLUA #include "fastcmp.h" +#include "r_main.h" #include "p_mobj.h" #include "d_player.h" #include "g_game.h" @@ -44,6 +45,10 @@ int player_splitscreenindex_noset(lua_State *L); int player_ping_getter(lua_State *L); int player_ping_noset(lua_State *L); +// Non synch safe! +int player_sliproll_getter(lua_State *L); +int player_sliproll_noset(lua_State *L); + #define FIELD(type, field_name, getter, setter) { #field_name, offsetof(type, field_name), getter, setter } static const udata_field_t player_fields[] = { // Player doesn't actually have field "name" so macro fails. Need to declare field manually. @@ -150,6 +155,7 @@ static const udata_field_t player_fields[] = { FIELD(player_t, fovadd, udatalib_getter_fixed, udatalib_setter_fixed), // Mmm yeah thats definitely synch safe #endif // Same as player.name + { "sliproll", 0, player_sliproll_getter, player_sliproll_noset }, { "ping", 0, player_ping_getter, player_ping_noset }, // Hmm originally setter doesn't exist so data is written as unreachable custom field... { NULL }, }; @@ -207,6 +213,7 @@ NOSET(kartstuff) NOSET(bot) NOSET(splitscreenindex) NOSET(ping) +NOSET(sliproll) #undef NOSET @@ -331,6 +338,15 @@ int player_ping_getter(lua_State *L) return 1; } +int player_sliproll_getter(lua_State *L) +{ + player_t *plr = GETPLAYER(); + + lua_pushangle(L, R_PlayerSliptideAngle(plr)); + + return 1; +} + static int lib_iteratePlayers(lua_State *L) { INT32 i = -1; diff --git a/src/r_defs.h b/src/r_defs.h index 559e3646b..26a11a6c0 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -19,6 +19,7 @@ // We rely on the thinker data struct to handle sound origins in sectors. #include "d_think.h" + // SECTORS do store MObjs anyway. #include "p_mobj.h" diff --git a/src/r_main.c b/src/r_main.c index dc914e79a..c381c9860 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -439,6 +439,60 @@ fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1) return FixedHypot(px1 - px2, py1 - py2); } +angle_t R_PlayerSliptideAngle(player_t *player) +{ + mobj_t *mo = player->mo; + + if (!cv_sliptideroll.value || !mo || P_MobjWasRemoved(mo)) return 0; + + size_t rot = mo->frame&FF_FRAMEMASK; + boolean papersprite = (mo->frame & FF_PAPERSPRITE); + + spritedef_t *sprdef; + spriteframe_t *sprframe; + angle_t ang = 0; + + interpmobjstate_t interp = {0}; + + // Yes. + if (R_UsingFrameInterpolation() && !paused) + { + R_InterpolateMobjState(mo, rendertimefrac, &interp); + } + else + { + R_InterpolateMobjState(mo, FRACUNIT, &interp); + } + + if (mo->skin && mo->sprite == SPR_PLAY) + { + sprdef = &((skin_t *)mo->skin)->spritedef; + + if (rot >= sprdef->numframes) + sprdef = &sprites[mo->sprite]; + } + else + { + sprdef = &sprites[mo->sprite]; + } + + if (rot >= sprdef->numframes) + { + sprdef = &sprites[states[S_UNKNOWN].sprite]; + rot = states[S_UNKNOWN].frame&FF_FRAMEMASK; + } + + sprframe = &sprdef->spriteframes[rot]; + + // No sprite frame? I guess it is possible + if (!sprframe) return 0; + + if (sprframe->rotate != SRF_SINGLE || papersprite) + ang = R_PointToAngle(interp.x, interp.y) - interp.angle; + + return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mo->player->sliproll*(mo->player->sliptidemem)); +} + // Little extra utility. Works in the same way as R_PointToAngle2 fixed_t R_PointToDist(fixed_t x, fixed_t y) { diff --git a/src/r_main.h b/src/r_main.h index 70adf1bb5..d6c966857 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -73,6 +73,7 @@ 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); 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); fixed_t R_ScaleFromGlobalAngle(angle_t visangle); subsector_t *R_PointInSubsector(fixed_t x, fixed_t y); From ca9277366cdb9eeff329d5e72a259e9c42be8bfb Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 1 Sep 2023 19:43:24 +0200 Subject: [PATCH 030/239] 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) From 90cc5a6cb0cf0f210d2a8c3518dbe73c429b29ff Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 15:30:21 +0200 Subject: [PATCH 031/239] 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 From 7da590df94863e0d18451f194923849e49d384ab Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 15:30:42 +0200 Subject: [PATCH 032/239] 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; From 98dfe528d8b46662c57ed910544d5308345058f8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 4 Sep 2023 16:37:11 +0200 Subject: [PATCH 033/239] 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. From 3675fdd3613e0a378ac0642a564b0f41fde1912c Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 5 Sep 2023 09:13:12 +0200 Subject: [PATCH 034/239] smoother slope rotation for players dont snap player directly to whatever theyre standing on instead make the sprite rotate a bit smoother see: https://git.do.srb2.org/haya_/Kart-Public/-/commit/8448d75b031fa86cdb854d13eda4712352d35a89 --- src/d_player.h | 1 + src/k_kart.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/d_player.h b/src/d_player.h index d7bfb80eb..a12fff93b 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -371,6 +371,7 @@ typedef struct player_s angle_t viewrollangle; angle_t tilt; + angle_t tilt_sprite; // Mouse aiming, where the guy is looking at! // It is updated with cmd->aiming. diff --git a/src/k_kart.c b/src/k_kart.c index fd3a46afe..ffd759bbb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3132,6 +3132,7 @@ static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useRes angle_t zangle = 0; angle_t xydirection = 0; angle_t an; + angle_t final_slope; INT32 pNum = K_FindPlayerNum(p); I_Assert(p != NULL); @@ -3171,7 +3172,14 @@ static angle_t K_GetSlopeRollAngle(player_t *p, boolean dontflip, boolean useRes zangle = InvAngle(zangle); an = (lookAngle - xydirection); - return FixedMul(zangle, FINESINE(an>>ANGLETOFINESHIFT)); + final_slope = -(FixedMul(FINESINE(an>>ANGLETOFINESHIFT), zangle)); + an = (INT32)(final_slope - p->tilt_sprite) / 2; // instead of just a direct snap + + if (an) + p->tilt_sprite += an; + else + p->tilt_sprite = final_slope; + return -p->tilt_sprite; } static void K_RollPlayerBySlopes(player_t *p, boolean usedistance) From 7f05d27f42a437e28f293829e849c5fbdfc7dfb6 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 5 Sep 2023 12:47:49 +0300 Subject: [PATCH 035/239] 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); From 78d50e4c43f1e85af6ae54c23d28da05e0c8455e Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 5 Sep 2023 23:01:03 +0200 Subject: [PATCH 036/239] just a bit more looks even better like this imo --- 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 ffd759bbb..04dcb4cb7 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3173,7 +3173,7 @@ 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) / 2; // instead of just a direct snap + an = (INT32)(final_slope - p->tilt_sprite) / 3; // instead of just a direct snap if (an) p->tilt_sprite += an; From 52c11d14443e7eb021c41bf88330d6ff9ddb9a06 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 6 Sep 2023 15:12:18 +0200 Subject: [PATCH 037/239] paletteshader stuff from hannu https://git.do.srb2.org/Hannu_Hanhi/SRB2/-/commit/2530e8b2938eb3ecb6f56b6cdc9916f387a72c6a this thing tanks my framerate to hell --- src/hardware/hw_defs.h | 2 + src/hardware/hw_main.c | 14 ++++++- src/hardware/hw_main.h | 1 + src/hardware/r_opengl/r_opengl.c | 63 ++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 294e4e791..d8f9dc5e8 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -231,6 +231,8 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { HWD_SET_SHADERS, + + HWD_SET_PALETTE_SHADER_ENABLED, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 834f617bf..eba58a985 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -64,6 +64,7 @@ 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 CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, @@ -115,7 +116,10 @@ static INT32 current_bsp_culling_distance = 0; consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, CV_screentextures_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_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}; + static void CV_filtermode_ONChange(void) { @@ -127,6 +131,13 @@ static void CV_anisotropic_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); } +static void CV_grpaletteshader_OnChange(void) +{ + if (rendermode == render_opengl) + HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); +} + + static void CV_screentextures_ONChange(void) { HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); @@ -5942,6 +5953,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grcorrecttricks); CV_RegisterVar(&cv_grsolvetjoin); + CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grbatching); CV_RegisterVar(&cv_grscreentextures); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 51a362c9e..48d37357c 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -179,6 +179,7 @@ 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_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d1690e9ee..e0df3399f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -26,6 +26,8 @@ #include "r_opengl.h" #include "r_vbo.h" +#include "../../v_video.h" // pLocalPalette + #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) @@ -511,6 +513,7 @@ typedef void (APIENTRY *PFNglLinkProgram) (GLuint); typedef void (APIENTRY *PFNglGetProgramiv) (GLuint, GLenum, GLint*); typedef void (APIENTRY *PFNglUseProgram) (GLuint); typedef void (APIENTRY *PFNglUniform1i) (GLint, GLint); +typedef void (APIENTRY *PFNglUniform1iv) (GLint, GLsizei, const GLint*); typedef void (APIENTRY *PFNglUniform1f) (GLint, GLfloat); typedef void (APIENTRY *PFNglUniform2f) (GLint, GLfloat, GLfloat); typedef void (APIENTRY *PFNglUniform3f) (GLint, GLfloat, GLfloat, GLfloat); @@ -532,6 +535,7 @@ static PFNglLinkProgram pglLinkProgram; static PFNglGetProgramiv pglGetProgramiv; static PFNglUseProgram pglUseProgram; static PFNglUniform1i pglUniform1i; +static PFNglUniform1iv pglUniform1iv; static PFNglUniform1f pglUniform1f; static PFNglUniform2f pglUniform2f; static PFNglUniform3f pglUniform3f; @@ -561,6 +565,9 @@ static GLint gl_portal_stencil_level = 0; static INT32 gl_portal_mode = HWD_PORTAL_NORMAL; +static GLint gl_palette[768]; +static INT32 gl_use_palette_shader = 0; + // 13062019 typedef enum { @@ -574,6 +581,8 @@ typedef enum // misc. (custom shaders) gluniform_leveltime, + + gluniform_palette, gluniform_max, } gluniform_t; @@ -708,6 +717,26 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_SOFTWARE_FADE_EQUATION \ "gl_FragColor = final_color;\n" \ "}\0" + +// +// Palette color quantization shader test. +// + +// Could test putting this to GLSL_SOFTWARE_FRAGMENT_SHADER and seeing what happens to performance. + +#define GLSL_PALETTE_FRAGMENT_SHADER \ + "uniform sampler2D tex;\n" \ + "uniform int palette[768];\n" \ + "void main(void) {\n" \ + "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "vec3 best = vec3(200.0);\n" \ + "for (int i = 0; i < 256; i++) {\n" \ + "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ + "best = mix(pal_color, best, step(length(best-texel), length(pal_color-texel)));\n" \ + "}\n" \ + "gl_FragColor = vec4(best[0], best[1], best[2] ,1.0);\n" \ + "}\0" + // // GLSL generic fragment shader @@ -747,6 +776,9 @@ static const char *fragment_shaders[] = { "void main(void) {\n" "gl_FragColor = texture2D(tex, gl_TexCoord[0].st);\n" "}\0", + + // Palette fragment shader + GLSL_PALETTE_FRAGMENT_SHADER, NULL, }; @@ -793,6 +825,9 @@ static const char *vertex_shaders[] = { // Sky vertex shader GLSL_DEFAULT_VERTEX_SHADER, + //Palette vertex shader + GLSL_DEFAULT_VERTEX_SHADER, + NULL, }; @@ -826,6 +861,7 @@ void SetupGLFunc4(void) pglGetProgramiv = GetGLFunc("glGetProgramiv"); pglUseProgram = GetGLFunc("glUseProgram"); pglUniform1i = GetGLFunc("glUniform1i"); + pglUniform1iv = GetGLFunc("glUniform1iv"); pglUniform1f = GetGLFunc("glUniform1f"); pglUniform2f = GetGLFunc("glUniform2f"); pglUniform3f = GetGLFunc("glUniform3f"); @@ -949,6 +985,8 @@ EXPORT boolean HWRAPI(LoadShaders) (void) // misc. (custom shaders) shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); + + shader->uniforms[gluniform_palette] = GETUNI("palette"); #undef GETUNI } @@ -1022,6 +1060,17 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } +static void InitPalette(void) +{ + int i; + for (i = 0; i < 256; i++) + { + gl_palette[i*3] = pLocalPalette[i].s.red; + gl_palette[i*3+1] = pLocalPalette[i].s.green; + gl_palette[i*3+2] = pLocalPalette[i].s.blue; + } +} + // -----------------+ // SetNoTexture : Disable texture // -----------------+ @@ -1312,6 +1361,8 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglClear(ClearMask); pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too + + InitPalette(); // just gonna put this here for now, could try doing it on gl init } @@ -2692,6 +2743,10 @@ 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) @@ -3760,6 +3815,12 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.alpha = 1; ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); + + if (gl_use_palette_shader) + { + pglUseProgram(gl_shaderprograms[8].program); // palette shader + pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + } pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); @@ -3768,6 +3829,8 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); tex_downloaded = finalScreenTexture; + if (gl_use_palette_shader) + pglUseProgram(0); } #endif //HWRENDER From 2ed4a7b548b26ea0929f4fb8e835aa2e2c0f4b3a Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 6 Sep 2023 15:19:39 +0200 Subject: [PATCH 038/239] Palette Lookup Texture https://git.do.srb2.org/Hannu_Hanhi/SRB2/-/commit/9562a95d0adb9384b5db26145ed03cb5d3e5a893 https://git.do.srb2.org/Hannu_Hanhi/SRB2/-/commit/d8a329b89dad75a57e076d88b8d5d1fdb5f959bc --- src/hardware/r_opengl/r_opengl.c | 65 ++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e0df3399f..dc715b32b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -27,6 +27,7 @@ #include "r_vbo.h" #include "../../v_video.h" // pLocalPalette +#include "../../r_data.h" // NearestColor #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) @@ -237,6 +238,7 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) #define pglTexEnvi glTexEnvi #define pglTexParameteri glTexParameteri #define pglTexImage2D glTexImage2D +#define pglTexImage3D glTexImage3D /* Fog */ #define pglFogf glFogf @@ -357,6 +359,8 @@ typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint static PFNglTexParameteri pglTexParameteri; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; +typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage3D pglTexImage3D; /* Fog */ typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param); @@ -478,6 +482,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexParameteri, glTexParameteri) GETOPENGLFUNC(pglTexImage2D, glTexImage2D) + GETOPENGLFUNC(pglTexImage3D, glTexImage3D) GETOPENGLFUNC(pglFogf, glFogf) GETOPENGLFUNC(pglFogfv, glFogfv) @@ -567,6 +572,7 @@ static INT32 gl_portal_mode = HWD_PORTAL_NORMAL; static GLint gl_palette[768]; static INT32 gl_use_palette_shader = 0; +static boolean gl_palette_initialized = false; // 13062019 typedef enum @@ -583,6 +589,7 @@ typedef enum gluniform_leveltime, gluniform_palette, + gluniform_color_lookup, gluniform_max, } gluniform_t; @@ -726,15 +733,17 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ + "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "vec3 best = vec3(200.0);\n" \ - "for (int i = 0; i < 256; i++) {\n" \ - "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ - "best = mix(pal_color, best, step(length(best-texel), length(pal_color-texel)));\n" \ - "}\n" \ - "gl_FragColor = vec4(best[0], best[1], best[2] ,1.0);\n" \ + "float pal_idx = texture3D(lookup_tex, texel)[0];\n" \ + "gl_FragColor = vec4(pal_idx, pal_idx, 0.5, 1.0);\n" \ + "//if (pal_idx == 0) {\n" \ + "//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" \ + "//} else {\n" \ + "//gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ + "//}\n" \ "}\0" @@ -872,6 +881,8 @@ void SetupGLFunc4(void) pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); #endif + pglTexImage3D = GetGLFunc("glTexImage3D"); // how about here then... + // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); } @@ -987,6 +998,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); shader->uniforms[gluniform_palette] = GETUNI("palette"); + shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); #undef GETUNI } @@ -1060,15 +1072,46 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } +GLuint palette_tex_num; + static void InitPalette(void) { - int i; + int i, r, g, b; + // init the palette for (i = 0; i < 256; i++) { gl_palette[i*3] = pLocalPalette[i].s.red; gl_palette[i*3+1] = pLocalPalette[i].s.green; gl_palette[i*3+2] = pLocalPalette[i].s.blue; } + // init the palette conversion lookup texture + GLubyte *pal_lookup_tex = malloc(256*256*256*sizeof(GLubyte)); + // smallest separation between all the colors in the srb2 palette is 6, so + // possibly a 64x64x64 lookup texture might be enough for 100% correct colors + // (min separation for 64^3 size is 4) + if (!pal_lookup_tex) + I_Error("Failed to allocate memory for generating palette lookup texture."); + + for (b = 0; b < 256; b++) + { + for (g = 0; g < 256; g++) + { + for (r = 0; r < 256; r++) + { + pal_lookup_tex[b*65536+g*256+r] = NearestColor(r, b, g); + } + } + } + pglGenTextures(1, &palette_tex_num); + 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, 256, 256, 256, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer + free(pal_lookup_tex); + pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + gl_palette_initialized = true; } // -----------------+ @@ -1362,7 +1405,8 @@ 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 - InitPalette(); // just gonna put this here for now, could try doing it on gl init + if (!gl_palette_initialized) + InitPalette(); // just gonna put this here for now } @@ -3820,6 +3864,8 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + pglActiveTexture(GL_TEXTURE1); + pglBindTexture(GL_TEXTURE_2D, palette_tex_num); } pglColor4ubv(white); @@ -3830,7 +3876,10 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; if (gl_use_palette_shader) + { pglUseProgram(0); + pglActiveTexture(GL_TEXTURE0); + } } #endif //HWRENDER From 9732e74bf3e445f6916479d4e9c8cbdebf42ebbc Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 6 Sep 2023 15:24:31 +0200 Subject: [PATCH 039/239] more work https://git.do.srb2.org/Hannu_Hanhi/SRB2/-/commit/140dba15b86ad7e206c50c8336103bee89e6b032 --- src/hardware/r_opengl/r_opengl.c | 52 +++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index dc715b32b..c75bba88b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -482,7 +482,6 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexParameteri, glTexParameteri) GETOPENGLFUNC(pglTexImage2D, glTexImage2D) - GETOPENGLFUNC(pglTexImage3D, glTexImage3D) GETOPENGLFUNC(pglFogf, glFogf) GETOPENGLFUNC(pglFogfv, glFogfv) @@ -737,13 +736,21 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "float pal_idx = texture3D(lookup_tex, texel)[0];\n" \ - "gl_FragColor = vec4(pal_idx, pal_idx, 0.5, 1.0);\n" \ - "//if (pal_idx == 0) {\n" \ - "//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" \ - "//} else {\n" \ - "//gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ - "//}\n" \ + "int pal_idx = texture3D(lookup_tex, (63.0/64.0) * texel + 1.0 / 128.0)[0] * 255;\n" \ + "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ + "}\0" + +#define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ + "uniform sampler2D tex;\n" \ + "uniform int palette[768];\n" \ + "void main(void) {\n" \ + "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "vec3 best = vec3(200.0);\n" \ + "for (int i = 0; i < 256; i++) {\n" \ + "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ + "best = mix(pal_color, best, step(length(best-texel), length(pal_color-texel)));\n" \ + "}\n" \ + "gl_FragColor = vec4(best[0], best[1], best[2] ,1.0);\n" \ "}\0" @@ -1073,6 +1080,14 @@ EXPORT void HWRAPI(KillShaders) (void) } GLuint palette_tex_num; +// length of one side of lookup texture +// smallest separation between all the colors in the srb2 palette is 6, so +// possibly a 64x64x64 lookup texture might be enough for 100% correct colors +// (min separation for 64^3 size is 4) +#define LUT_SIZE 64 +#define STEP_SIZE (256/LUT_SIZE) +// the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! +// the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! static void InitPalette(void) { @@ -1085,20 +1100,17 @@ static void InitPalette(void) gl_palette[i*3+2] = pLocalPalette[i].s.blue; } // init the palette conversion lookup texture - GLubyte *pal_lookup_tex = malloc(256*256*256*sizeof(GLubyte)); - // smallest separation between all the colors in the srb2 palette is 6, so - // possibly a 64x64x64 lookup texture might be enough for 100% correct colors - // (min separation for 64^3 size is 4) + GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); if (!pal_lookup_tex) I_Error("Failed to allocate memory for generating palette lookup texture."); - for (b = 0; b < 256; b++) + for (b = 0; b < LUT_SIZE; b++) { - for (g = 0; g < 256; g++) + for (g = 0; g < LUT_SIZE; g++) { - for (r = 0; r < 256; r++) + for (r = 0; r < LUT_SIZE; r++) { - pal_lookup_tex[b*65536+g*256+r] = NearestColor(r, b, g); + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+2, g*STEP_SIZE+2, b*STEP_SIZE+2); } } } @@ -1108,9 +1120,12 @@ static void InitPalette(void) pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (!pglTexImage3D) I_Error("pglTexImage3D is NULL!"); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, 256, 256, 256, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer + pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer free(pal_lookup_tex); + pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + pglUseProgram(0); + pglBindTexture(GL_TEXTURE_3D, 0); gl_palette_initialized = true; } @@ -3865,7 +3880,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_2D, palette_tex_num); + pglBindTexture(GL_TEXTURE_3D, palette_tex_num); } pglColor4ubv(white); @@ -3878,6 +3893,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) if (gl_use_palette_shader) { pglUseProgram(0); + pglBindTexture(GL_TEXTURE_3D, 0); pglActiveTexture(GL_TEXTURE0); } } From 01cd8f5a0f44216cdc532ca2664c37ab6b35675a Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 6 Sep 2023 18:02:04 +0200 Subject: [PATCH 040/239] 4fps this thing runs like crap 4fps --- src/hardware/hw_defs.h | 1 - src/hardware/hw_main.c | 23 +++++---- src/hardware/r_opengl/r_opengl.c | 83 ++++++++++++++++++++++---------- 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index d8f9dc5e8..1f6dd0f1c 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -231,7 +231,6 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { HWD_SET_SHADERS, - HWD_SET_PALETTE_SHADER_ENABLED, HWD_SET_TEXTUREFILTERMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index eba58a985..57df52185 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -86,6 +86,9 @@ 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_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL, CV_OnOff, + CV_grpaletteshader_OnChange, 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}}; @@ -116,10 +119,7 @@ static INT32 current_bsp_culling_distance = 0; consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, CV_screentextures_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_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL}; static void CV_filtermode_ONChange(void) { @@ -131,13 +131,6 @@ static void CV_anisotropic_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_granisotropicmode.value); } -static void CV_grpaletteshader_OnChange(void) -{ - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); -} - - static void CV_screentextures_ONChange(void) { HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); @@ -149,6 +142,12 @@ static void CV_useCustomShaders_ONChange(void) HWD.pfnInitCustomShaders(); } +static void CV_grpaletteshader_OnChange(void) +{ + if (rendermode == render_opengl) + HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); +} + // ========================================================================== // Globals // ========================================================================== @@ -5953,9 +5952,9 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_granisotropicmode); CV_RegisterVar(&cv_grcorrecttricks); CV_RegisterVar(&cv_grsolvetjoin); - CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grbatching); + CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grscreentextures); CV_RegisterVar(&cv_grrenderdistance); CV_RegisterVar(&cv_grportals); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index c75bba88b..32954be24 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -47,12 +47,13 @@ struct GLRGBAFloat GLfloat alpha; }; typedef struct GLRGBAFloat GLRGBAFloat; -static const GLubyte white[4] = { 255, 255, 255, 255 }; // ========================================================================== // CONSTANTS // ========================================================================== +static const GLubyte white[4] = { 255, 255, 255, 255 }; + // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 @@ -76,7 +77,9 @@ static FBITFIELD CurrentPolyFlags; static FTextureInfo* gr_cachetail = NULL; static FTextureInfo* gr_cachehead = NULL; -RGBA_t myPaletteData[256]; +static RGBA_t screenPalette[256] = {0}; +static GLuint palette_tex_num = 0; // 3D texture containing RGB -> palette index lookup table +RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; GLbyte screen_depth = 0; @@ -359,6 +362,8 @@ typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint static PFNglTexParameteri pglTexParameteri; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; + +/* 1.2 functions for 3D textures */ typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage3D pglTexImage3D; @@ -419,6 +424,9 @@ static PFNglColorPointer pglColorPointer; #ifndef GL_TEXTURE1 #define GL_TEXTURE1 0x84C1 #endif +#ifndef GL_TEXTURE2 +#define GL_TEXTURE2 0x84C2 +#endif boolean SetupGLfunc(void) { @@ -616,6 +624,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ "float startmap = (15.0 - lightnum) * 4.0;\n" \ "float scale = 160.0 / (lightz + 1.0);\n" \ + "float cap = (155.0 - light) * 0.26;\n" \ "return startmap - scale * 0.5;\n" \ "}\n" @@ -723,7 +732,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_SOFTWARE_FADE_EQUATION \ "gl_FragColor = final_color;\n" \ "}\0" - + // // Palette color quantization shader test. // @@ -735,16 +744,16 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ - "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "int pal_idx = texture3D(lookup_tex, (63.0/64.0) * texel + 1.0 / 128.0)[0] * 255;\n" \ + "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" - + #define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ "uniform sampler2D tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ - "vec3 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ "vec3 best = vec3(200.0);\n" \ "for (int i = 0; i < 256; i++) {\n" \ "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ @@ -792,10 +801,10 @@ static const char *fragment_shaders[] = { "void main(void) {\n" "gl_FragColor = texture2D(tex, gl_TexCoord[0].st);\n" "}\0", - + // Palette fragment shader GLSL_PALETTE_FRAGMENT_SHADER, - + NULL, }; @@ -840,8 +849,8 @@ static const char *vertex_shaders[] = { // Sky vertex shader GLSL_DEFAULT_VERTEX_SHADER, - - //Palette vertex shader + + // Palette vertex shader GLSL_DEFAULT_VERTEX_SHADER, NULL, @@ -851,6 +860,9 @@ static const char *vertex_shaders[] = { void SetupGLFunc4(void) { + /* 1.2 funcs */ + pglTexImage3D = GetGLFunc("glTexImage3D"); + /* 1.3 funcs */ pglActiveTexture = GetGLFunc("glActiveTexture"); pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); @@ -888,8 +900,6 @@ void SetupGLFunc4(void) pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); #endif - pglTexImage3D = GetGLFunc("glTexImage3D"); // how about here then... - // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); } @@ -1079,7 +1089,6 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } -GLuint palette_tex_num; // length of one side of lookup texture // smallest separation between all the colors in the srb2 palette is 6, so // possibly a 64x64x64 lookup texture might be enough for 100% correct colors @@ -1089,20 +1098,28 @@ GLuint palette_tex_num; // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -static void InitPalette(void) +static void InitPalette(RGBA_t *palette) { int i, r, g, b; // init the palette for (i = 0; i < 256; i++) { - gl_palette[i*3] = pLocalPalette[i].s.red; - gl_palette[i*3+1] = pLocalPalette[i].s.green; - gl_palette[i*3+2] = pLocalPalette[i].s.blue; + // crush to 16-bit rgb565, like software currently does + float fred = (float)(pLocalPalette[i].s.red >> 3); + float fgreen = (float)(pLocalPalette[i].s.green >> 2); + float fblue = (float)(pLocalPalette[i].s.blue >> 3); + // restore to rgb888 + gl_palette[i*3] = (GLint)(fred / 31.0f * 255.0f); + gl_palette[i*3+1] = (GLint)(fgreen / 63.0f * 255.0f); + gl_palette[i*3+2] = (GLint)(fblue / 31.0f * 255.0f); + + // 24-bit option + /*gl_palette[i*3] = pMasterPalette[i].s.red; + gl_palette[i*3+1] = pMasterPalette[i].s.green; + gl_palette[i*3+2] = pMasterPalette[i].s.blue;*/ } // init the palette conversion lookup texture GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); - if (!pal_lookup_tex) - I_Error("Failed to allocate memory for generating palette lookup texture."); for (b = 0; b < LUT_SIZE; b++) { @@ -1110,25 +1127,39 @@ static void InitPalette(void) { for (r = 0; r < LUT_SIZE; r++) { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+2, g*STEP_SIZE+2, b*STEP_SIZE+2); + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); } } } pglGenTextures(1, &palette_tex_num); + pglActiveTexture(GL_TEXTURE1); 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); // test: put gl_red instead of gl_red_integer + pglActiveTexture(GL_TEXTURE0); free(pal_lookup_tex); pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + + // bind the palette to the fancy shader here + pglUseProgram(gl_shaderprograms[9].program); + pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette); + // bind the palette to the fancy shader here + pglUseProgram(gl_shaderprograms[10].program); + pglUniform1iv(gl_shaderprograms[10].uniforms[gluniform_palette], 768, gl_palette); pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); + + // bind 3d lookup to unit 1, maybe it can stay there + pglActiveTexture(GL_TEXTURE1); + pglBindTexture(GL_TEXTURE_3D, palette_tex_num); + pglActiveTexture(GL_TEXTURE0); gl_palette_initialized = true; } + + // -----------------+ // SetNoTexture : Disable texture // -----------------+ @@ -1420,8 +1451,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) - InitPalette(); // just gonna put this here for now + InitPalette(); // just gonna put this here for now, could try doing it on gl init } @@ -1643,6 +1673,7 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) w = pTexInfo->width; h = pTexInfo->height; + #ifdef USE_PALETTED_TEXTURE if (glColorTableEXT && @@ -2802,7 +2833,7 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; } break; - + case HWD_SET_PALETTE_SHADER_ENABLED: gl_use_palette_shader = Value; break; From b53cc6fd2bb75d8a7bc15e3277c39990bc189851 Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 6 Sep 2023 18:29:26 +0200 Subject: [PATCH 041/239] fuck it palette renderer "lite" remove the goddamn lookup textures, this atleast runs okish and looks not that bad --- src/hardware/hw_main.c | 6 +- src/hardware/r_opengl/r_opengl.c | 104 +++---------------------------- 2 files changed, 11 insertions(+), 99 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 57df52185..b1563bebe 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -85,9 +85,7 @@ consvar_t cv_grcorrecttricks = {"gr_correcttricks", "Off", 0, CV_OnOff, NULL, 0, consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - -consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL, 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_grpaletteshader_OnChange, 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"}, @@ -5954,7 +5952,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grsolvetjoin); CV_RegisterVar(&cv_grbatching); - CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grscreentextures); CV_RegisterVar(&cv_grrenderdistance); CV_RegisterVar(&cv_grportals); @@ -5962,6 +5959,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_portalline); CV_RegisterVar(&cv_portalonly); CV_RegisterVar(&cv_secbright); + CV_RegisterVar(&cv_grpaletteshader); } // -------------------------------------------------------------------------- diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 32954be24..8de9b0974 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -27,7 +27,6 @@ #include "r_vbo.h" #include "../../v_video.h" // pLocalPalette -#include "../../r_data.h" // NearestColor #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) @@ -47,13 +46,12 @@ struct GLRGBAFloat GLfloat alpha; }; typedef struct GLRGBAFloat GLRGBAFloat; +static const GLubyte white[4] = { 255, 255, 255, 255 }; // ========================================================================== // CONSTANTS // ========================================================================== -static const GLubyte white[4] = { 255, 255, 255, 255 }; - // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 @@ -77,9 +75,7 @@ static FBITFIELD CurrentPolyFlags; static FTextureInfo* gr_cachetail = NULL; static FTextureInfo* gr_cachehead = NULL; -static RGBA_t screenPalette[256] = {0}; -static GLuint palette_tex_num = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA +RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; GLbyte screen_depth = 0; @@ -241,7 +237,6 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) #define pglTexEnvi glTexEnvi #define pglTexParameteri glTexParameteri #define pglTexImage2D glTexImage2D -#define pglTexImage3D glTexImage3D /* Fog */ #define pglFogf glFogf @@ -363,10 +358,6 @@ static PFNglTexParameteri pglTexParameteri; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; -/* 1.2 functions for 3D textures */ -typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -static PFNglTexImage3D pglTexImage3D; - /* Fog */ typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param); static PFNglFogf pglFogf; @@ -424,9 +415,6 @@ static PFNglColorPointer pglColorPointer; #ifndef GL_TEXTURE1 #define GL_TEXTURE1 0x84C1 #endif -#ifndef GL_TEXTURE2 -#define GL_TEXTURE2 0x84C2 -#endif boolean SetupGLfunc(void) { @@ -571,16 +559,15 @@ 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; + static INT32 gl_enable_screen_textures = 1; static GLint gl_portal_stencil_level = 0; static INT32 gl_portal_mode = HWD_PORTAL_NORMAL; -static GLint gl_palette[768]; -static INT32 gl_use_palette_shader = 0; -static boolean gl_palette_initialized = false; - // 13062019 typedef enum { @@ -596,7 +583,6 @@ typedef enum gluniform_leveltime, gluniform_palette, - gluniform_color_lookup, gluniform_max, } gluniform_t; @@ -624,7 +610,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ "float startmap = (15.0 - lightnum) * 4.0;\n" \ "float scale = 160.0 / (lightz + 1.0);\n" \ - "float cap = (155.0 - light) * 0.26;\n" \ "return startmap - scale * 0.5;\n" \ "}\n" @@ -732,7 +717,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_SOFTWARE_FADE_EQUATION \ "gl_FragColor = final_color;\n" \ "}\0" - + // // Palette color quantization shader test. // @@ -740,16 +725,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; // Could test putting this to GLSL_SOFTWARE_FRAGMENT_SHADER and seeing what happens to performance. #define GLSL_PALETTE_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform sampler3D lookup_tex;\n" \ - "uniform int palette[768];\n" \ - "void main(void) {\n" \ - "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ - "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ - "}\0" - -#define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ "uniform sampler2D tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ @@ -762,7 +737,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "gl_FragColor = vec4(best[0], best[1], best[2] ,1.0);\n" \ "}\0" - // // GLSL generic fragment shader // @@ -801,10 +775,10 @@ static const char *fragment_shaders[] = { "void main(void) {\n" "gl_FragColor = texture2D(tex, gl_TexCoord[0].st);\n" "}\0", - + // Palette fragment shader GLSL_PALETTE_FRAGMENT_SHADER, - + NULL, }; @@ -860,9 +834,6 @@ static const char *vertex_shaders[] = { void SetupGLFunc4(void) { - /* 1.2 funcs */ - pglTexImage3D = GetGLFunc("glTexImage3D"); - /* 1.3 funcs */ pglActiveTexture = GetGLFunc("glActiveTexture"); pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); @@ -1015,7 +986,6 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); shader->uniforms[gluniform_palette] = GETUNI("palette"); - shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); #undef GETUNI } @@ -1089,16 +1059,7 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } -// length of one side of lookup texture -// smallest separation between all the colors in the srb2 palette is 6, so -// possibly a 64x64x64 lookup texture might be enough for 100% correct colors -// (min separation for 64^3 size is 4) -#define LUT_SIZE 64 -#define STEP_SIZE (256/LUT_SIZE) -// the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! -// the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! - -static void InitPalette(RGBA_t *palette) +static void InitPalette(void) { int i, r, g, b; // init the palette @@ -1118,48 +1079,8 @@ static void InitPalette(RGBA_t *palette) gl_palette[i*3+1] = pMasterPalette[i].s.green; gl_palette[i*3+2] = pMasterPalette[i].s.blue;*/ } - // init the palette conversion lookup texture - GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); - - for (b = 0; b < LUT_SIZE; b++) - { - for (g = 0; g < LUT_SIZE; g++) - { - for (r = 0; r < LUT_SIZE; r++) - { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); - } - } - } - pglGenTextures(1, &palette_tex_num); - pglActiveTexture(GL_TEXTURE1); - 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); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer - pglActiveTexture(GL_TEXTURE0); - free(pal_lookup_tex); - pglUseProgram(gl_shaderprograms[8].program); - pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit - - // bind the palette to the fancy shader here - pglUseProgram(gl_shaderprograms[9].program); - pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette); - // bind the palette to the fancy shader here - pglUseProgram(gl_shaderprograms[10].program); - pglUniform1iv(gl_shaderprograms[10].uniforms[gluniform_palette], 768, gl_palette); - pglUseProgram(0); - pglBindTexture(GL_TEXTURE_3D, 0); - - // bind 3d lookup to unit 1, maybe it can stay there - pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); - pglActiveTexture(GL_TEXTURE0); - gl_palette_initialized = true; } - - // -----------------+ // SetNoTexture : Disable texture // -----------------+ @@ -1673,7 +1594,6 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo) w = pTexInfo->width; h = pTexInfo->height; - #ifdef USE_PALETTED_TEXTURE if (glColorTableEXT && @@ -3910,8 +3830,6 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); - pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); } pglColor4ubv(white); @@ -3922,11 +3840,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; if (gl_use_palette_shader) - { pglUseProgram(0); - pglBindTexture(GL_TEXTURE_3D, 0); - pglActiveTexture(GL_TEXTURE0); - } } #endif //HWRENDER From 228a9325986b96b86225c2b945950e2a70eb72bb Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 6 Sep 2023 19:54:14 +0300 Subject: [PATCH 042/239] Fix few typos --- src/d_netcmd.c | 2 +- src/k_kart.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 35e6857b1..debee58eb 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -512,7 +512,7 @@ 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, "Scoll"}, {SKINMENUTYPE_2D, "2d"}, {SKINMENUTYPE_GRID, "Grid"}, {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 skinselectgridsort_t[] ={ diff --git a/src/k_kart.c b/src/k_kart.c index fd3a46afe..3208c5f79 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -6647,7 +6647,7 @@ void K_CheckBumpers(void) if (winnernum > -1 && playeringame[winnernum]) { players[winnernum].marescore += winnerscoreadd; - CONS_Printf(M_GetText("%s recieved %d point%s for winning!\n"), player_names[winnernum], winnerscoreadd, (winnerscoreadd == 1 ? "" : "s")); + CONS_Printf(M_GetText("%s received %d point%s for winning!\n"), player_names[winnernum], winnerscoreadd, (winnerscoreadd == 1 ? "" : "s")); } for (i = 0; i < MAXPLAYERS; i++) // This can't go in the earlier loop because winning adds points From b7671804731041b68d063fd135872ae657ce2704 Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 7 Sep 2023 14:38:10 +0200 Subject: [PATCH 043/239] readd the lookup texture, adjust its size it runs a bit better like this, but also is a bit darker def needs adjustments --- src/hardware/hw_main.c | 22 ++++++--- src/hardware/r_opengl/r_opengl.c | 77 +++++++++++++++++++++++++++----- src/r_data.h | 2 - 3 files changed, 83 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b1563bebe..69e801c7e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -60,6 +60,9 @@ 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); @@ -144,6 +147,7 @@ static void CV_grpaletteshader_OnChange(void) { if (rendermode == render_opengl) HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); + gr_use_palette_shader = cv_grpaletteshader.value; } // ========================================================================== @@ -877,7 +881,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa 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); + FUINT lightnum = sector->lightlevel;//HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; @@ -912,13 +916,15 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (pfloor && (pfloor->flags & FF_FOG)) { - lightnum = HWR_CalcWallLight(pfloor->master->frontsector->lightlevel, v1x, v1y, v2x, v2y); 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(*list[i].lightlevel, v1x, v1y, v2x, v2y); colormap = list[i].extra_colormap; + lightnum = *list[i].lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); } } @@ -1305,8 +1311,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); } - lightnum = HWR_CalcWallLight(gr_frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); colormap = gr_frontsector->extra_colormap; + lightnum = gr_frontsector->lightlevel; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); if (gr_frontsector) Surf.PolyColor.s.alpha = 255; @@ -2127,8 +2134,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); 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); + Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); @@ -2250,8 +2259,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); 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); Surf.PolyColor.s.alpha = HWR_FogBlockAlpha(rover->master->frontsector->lightlevel, rover->master->frontsector->extra_colormap); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8de9b0974..69df4729e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -27,6 +27,7 @@ #include "r_vbo.h" #include "../../v_video.h" // pLocalPalette +#include "../../r_data.h" // NearestColor #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) @@ -72,8 +73,8 @@ static GLuint tex_downloaded = 0; static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; -static FTextureInfo* gr_cachetail = NULL; -static FTextureInfo* gr_cachehead = NULL; +static FTextureInfo *gr_cachetail = NULL; +static FTextureInfo *gr_cachehead = NULL; RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() @@ -237,6 +238,7 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) #define pglTexEnvi glTexEnvi #define pglTexParameteri glTexParameteri #define pglTexImage2D glTexImage2D +#define pglTexImage3D glTexImage3D /* Fog */ #define pglFogf glFogf @@ -357,6 +359,8 @@ typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint static PFNglTexParameteri pglTexParameteri; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; +typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage3D pglTexImage3D; /* Fog */ typedef void (APIENTRY * PFNglFogf) (GLenum pname, GLfloat param); @@ -561,6 +565,7 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; static INT32 gl_use_palette_shader = 0; +static boolean gl_palette_initialized = false; static INT32 gl_enable_screen_textures = 1; @@ -583,6 +588,7 @@ typedef enum gluniform_leveltime, gluniform_palette, + gluniform_color_lookup, gluniform_max, } gluniform_t; @@ -726,9 +732,19 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ + "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ + "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ + "}\0" + +#define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ + "uniform sampler2D tex;\n" \ + "uniform int palette[768];\n" \ + "void main(void) {\n" \ + "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \" \ "vec3 best = vec3(200.0);\n" \ "for (int i = 0; i < 256; i++) {\n" \ "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ @@ -871,6 +887,8 @@ void SetupGLFunc4(void) pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); #endif + pglTexImage3D = GetGLFunc("glTexImage3D"); // how about here then... + // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); } @@ -986,6 +1004,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); shader->uniforms[gluniform_palette] = GETUNI("palette"); + shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); #undef GETUNI } @@ -1049,7 +1068,6 @@ EXPORT void HWRAPI(UnSetShader) (void) gl_shadersenabled = false; gl_currentshaderprogram = 0; gl_shaderprogramchanged = true;// not sure if this is needed - if (!pglUseProgram) return; pglUseProgram(0); #endif } @@ -1059,8 +1077,18 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } +GLuint palette_tex_num; +// length of one side of lookup texture +// smallest separation between all the colors in the srb2 palette is 6, so +// possibly a 64x64x64 lookup texture might be enough for 100% correct colors +// (min separation for 64^3 size is 4) +#define LUT_SIZE 16 +#define STEP_SIZE (256/LUT_SIZE) +// the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! +// the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! + static void InitPalette(void) -{ +{ int i, r, g, b; // init the palette for (i = 0; i < 256; i++) @@ -1073,12 +1101,34 @@ static void InitPalette(void) gl_palette[i*3] = (GLint)(fred / 31.0f * 255.0f); gl_palette[i*3+1] = (GLint)(fgreen / 63.0f * 255.0f); gl_palette[i*3+2] = (GLint)(fblue / 31.0f * 255.0f); - - // 24-bit option - /*gl_palette[i*3] = pMasterPalette[i].s.red; - gl_palette[i*3+1] = pMasterPalette[i].s.green; - gl_palette[i*3+2] = pMasterPalette[i].s.blue;*/ } + + // init the palette conversion lookup texture + GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); + if (!pal_lookup_tex) + I_Error("Failed to allocate memory for generating palette lookup texture."); + + for (b = 0; b < LUT_SIZE; b++) + { + for (g = 0; g < LUT_SIZE; g++) + { + for (r = 0; r < LUT_SIZE; r++) + { + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); + } + } + } + pglGenTextures(1, &palette_tex_num); + 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); + pglTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer + free(pal_lookup_tex); + pglUseProgram(gl_shaderprograms[8].program); + pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + pglUseProgram(0); + pglBindTexture(GL_TEXTURE_3D, 0); + gl_palette_initialized = true; } // -----------------+ @@ -1372,7 +1422,8 @@ 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 - InitPalette(); // just gonna put this here for now, could try doing it on gl init + if (gl_use_palette_shader == 1) + InitPalette(); // just gonna put this here for now } @@ -3830,6 +3881,8 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + pglActiveTexture(GL_TEXTURE1); + pglBindTexture(GL_TEXTURE_3D, palette_tex_num); } pglColor4ubv(white); @@ -3840,7 +3893,11 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; if (gl_use_palette_shader) + { pglUseProgram(0); + pglBindTexture(GL_TEXTURE_3D, 0); + pglActiveTexture(GL_TEXTURE0); + } } #endif //HWRENDER diff --git a/src/r_data.h b/src/r_data.h index f371d40d7..6a8806988 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -104,6 +104,4 @@ UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); extern INT32 numtextures; -UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); - #endif From 9bdcfe9750cd4ca39fabd8e70ecc89d146b66b0a Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 7 Sep 2023 15:59:10 +0200 Subject: [PATCH 044/239] adjust some stuff bleh looks alr, but def loose some color depth with it --- src/hardware/r_opengl/r_opengl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 69df4729e..df245c664 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -737,7 +737,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ - "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ + "gl_FragColor = vec4(float(palette[pal_idx*3])/232.0, float(palette[pal_idx*3+1])/232.0, float(palette[pal_idx*3+2])/232.0, 1.0);\n" \ "}\0" #define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ @@ -1114,7 +1114,7 @@ static void InitPalette(void) { for (r = 0; r < LUT_SIZE; r++) { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+2, g*STEP_SIZE+2, b*STEP_SIZE+2); } } } @@ -1122,12 +1122,12 @@ static void InitPalette(void) 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); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer - free(pal_lookup_tex); + pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); + free(pal_lookup_tex); gl_palette_initialized = true; } From 09f79a693460aadc49b4cc2ca3fe51aa7f121bd8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 7 Sep 2023 17:24:06 +0200 Subject: [PATCH 045/239] Addfile per drag and drop https://git.do.srb2.org/SteelT/SRB2/-/commit/01cc2b91e189e4d268eddd38f3ba917133a07adc --- src/sdl/i_video.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 3fd96819c..09ed77658 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -969,6 +969,7 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint void I_GetEvent(void) { SDL_Event evt; + char* dropped_filedir; // We only want the first motion event, // otherwise we'll end up catching the warp back to center. //int mouseMotionOnce = 0; @@ -1293,6 +1294,11 @@ void I_GetEvent(void) if (currentMenu == &OP_JoystickSetDef) M_SetupJoystickMenu(0); break; + case SDL_DROPFILE: + dropped_filedir = evt.drop.file; + COM_BufInsertText(va("addfile \"%s\"", dropped_filedir)); + SDL_free(dropped_filedir); // Free dropped_filedir memory + break; case SDL_QUIT: I_Quit(); M_QuitResponse('y'); From b883d02abb4b972af761f94e7aa677d6d3dd7c13 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 7 Sep 2023 19:28:53 +0300 Subject: [PATCH 046/239] Use P_AddWadFile directly instead of command so non-ansii file names also supported --- src/sdl/i_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 09ed77658..d08b267f0 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -59,6 +59,7 @@ #endif #include "../doomstat.h" +#include "../p_setup.h" #include "../i_system.h" #include "../v_video.h" #include "../m_argv.h" @@ -1296,7 +1297,7 @@ void I_GetEvent(void) break; case SDL_DROPFILE: dropped_filedir = evt.drop.file; - COM_BufInsertText(va("addfile \"%s\"", dropped_filedir)); + P_AddWadFile(dropped_filedir); SDL_free(dropped_filedir); // Free dropped_filedir memory break; case SDL_QUIT: From 71ce5be570bfb2ba593b5f1c507c51647be139d9 Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 7 Sep 2023 23:54:22 +0200 Subject: [PATCH 047/239] me wondering why the hw sprite perfstats were broken + removing some stuff we dont need --- src/hardware/hw_main.c | 102 +++++++++++++++++++++-------------------- src/hardware/hw_main.h | 2 +- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 834f617bf..258573578 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -196,8 +196,6 @@ FTransform atransform; static float gr_viewx, gr_viewy, gr_viewz; float gr_viewsin, gr_viewcos; -static fixed_t dup_viewx, dup_viewy, dup_viewz; - static angle_t gr_aimingangle; static float gr_viewludsin, gr_viewludcos; @@ -528,7 +526,7 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t // 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(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 @@ -629,6 +627,9 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei // reference point for flat texture coord for each vertex around the polygon flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); + + // transform + v3d = planeVerts; if (FOFsector != NULL) { @@ -681,32 +682,39 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei flatyref = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); } -#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);\ -\ - /* Need to rotate before translate */\ - if (angle) /* Only needs to be done if there's an altered angle */\ - {\ - tempxsow = FLOAT_TO_FIXED(vert->s);\ - tempytow = FLOAT_TO_FIXED(vert->t);\ - vert->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle))));\ - vert->t = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));\ - }\ -\ - vert->x = (vx);\ - vert->y = height;\ - vert->z = (vy);\ -\ - if (slope)\ - {\ - fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED((vx)), FLOAT_TO_FIXED((vy)));\ - vert->y = FIXED_TO_FLOAT(fixedheight);\ - }\ -} - for (i = 0, v3d = planeVerts; i < nrPlaneVerts; i++,v3d++,pv++) - SETUP3DVERT(v3d, pv->x, pv->y); + for (i = 0; i < nrPlaneVerts; i++,v3d++,pv++) + { + // Hurdler: add scrolling texture on floor/ceiling + v3d->s = (float)((pv->x / fflatsize) - flatxref + scrollx); + v3d->t = (float)(flatyref - (pv->y / fflatsize) + scrolly); + + //v3d->s = (float)(pv->x / fflatsize); + //v3d->t = (float)(pv->y / fflatsize); + + // Need to rotate before translate + if (angle) // Only needs to be done if there's an altered angle + { + tempxsow = FLOAT_TO_FIXED(v3d->s); + tempytow = FLOAT_TO_FIXED(v3d->t); + v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); + v3d->t = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + } + + //v3d->s = (float)(v3d->s - flatxref + scrollx); + //v3d->t = (float)(flatyref - v3d->t + scrolly); + + v3d->x = pv->x; + v3d->y = height; + v3d->z = pv->y; + +#ifdef ESLOPE + if (slope) + { + fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED(pv->x), FLOAT_TO_FIXED(pv->y)); + v3d->y = FIXED_TO_FLOAT(fixedheight); + } +#endif + } HWR_Lighting(&Surf, lightlevel, planecolormap); @@ -3172,7 +3180,7 @@ void HWR_Subsector(size_t num) // 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); } } } @@ -3188,7 +3196,7 @@ void HWR_Subsector(size_t num) // 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); } } } @@ -3254,7 +3262,7 @@ 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); + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap); } } @@ -3306,7 +3314,7 @@ 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); + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap, sub); } } } @@ -5453,11 +5461,6 @@ void HWR_SetTransform(float fpov, player_t *player) postimg_t *postprocessor = &postimgtype[0]; INT32 i; - // copy view cam position for local use - dup_viewx = viewx; - dup_viewy = viewy; - dup_viewz = viewz; - gr_viewx = FIXED_TO_FLOAT(viewx); gr_viewy = FIXED_TO_FLOAT(viewy); gr_viewz = FIXED_TO_FLOAT(viewz); @@ -5657,7 +5660,6 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search HWR_PortalClipping(rootportal); } - //drawcount = 0; validcount++; if (cv_grbatching.value) HWD.pfnStartBatching(); @@ -5696,8 +5698,18 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_SetTransform(fpov, player);// restore transform } gr_collect_skywalls = false; + + ps_numsprites.value.i = gr_visspritecount; + PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); + PS_STOP_TIMING(ps_hw_spritesorttime); + PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); + PS_STOP_TIMING(ps_hw_spritedrawtime); + + ps_numdrawnodes.value.i = 0; + ps_hw_nodesorttime.value.p = 0; + ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } // free memory from portal list allocated by calls to Add2Lines @@ -5713,6 +5725,7 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * // TODO: is it okay if stencil test is on all the time even when its not needed? } + // ========================================================================== // Render the current frame. // ========================================================================== @@ -5870,19 +5883,8 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play // Render the BSP from the new viewpoint. portalcullsector = gr_portalcullsectors[portalnum]; HWR_RenderBSPNode((INT32)numnodes - 1); - - // Draw MD2 and sprites - ps_numsprites.value.i = gr_visspritecount; - PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); - PS_STOP_TIMING(ps_hw_spritesorttime); - PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); - PS_STOP_TIMING(ps_hw_spritedrawtime); - - ps_numdrawnodes.value.i = 0; - ps_hw_nodesorttime.value.p = 0; - ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 51a362c9e..4c1f893c1 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -111,7 +111,7 @@ 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(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 From 8737a40a4de107ffc0770f360111539670030ef4 Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 7 Sep 2023 23:55:26 +0200 Subject: [PATCH 048/239] bleh --- src/hardware/hw_main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 258573578..9e91e53cd 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5846,7 +5846,6 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) HWD.pfnSetSpecialState(HWD_SET_SHADERS, cv_grshaders.value); HWD.pfnSetShader(0); - //drawcount = 0; validcount++; portalclipline = NULL; From b1b592f88d4ed15ad01a0d219eb201a3525a873d Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 8 Sep 2023 10:38:48 +0200 Subject: [PATCH 049/239] readd the stuff blubuabb --- src/hardware/hw_main.c | 101 ++++++++++++++++++++--------------------- src/hardware/hw_main.h | 2 +- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9e91e53cd..2db41707f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -196,6 +196,8 @@ FTransform atransform; static float gr_viewx, gr_viewy, gr_viewz; float gr_viewsin, gr_viewcos; +static fixed_t dup_viewx, dup_viewy, dup_viewz; + static angle_t gr_aimingangle; static float gr_viewludsin, gr_viewludcos; @@ -526,7 +528,7 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t // 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) +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) { polyvertex_t * pv; float height; //constant y for all points on the convex flat polygon @@ -627,9 +629,6 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei // reference point for flat texture coord for each vertex around the polygon flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); - - // transform - v3d = planeVerts; if (FOFsector != NULL) { @@ -682,39 +681,32 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei flatyref = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); } - for (i = 0; i < nrPlaneVerts; i++,v3d++,pv++) - { - // Hurdler: add scrolling texture on floor/ceiling - v3d->s = (float)((pv->x / fflatsize) - flatxref + scrollx); - v3d->t = (float)(flatyref - (pv->y / fflatsize) + scrolly); - - //v3d->s = (float)(pv->x / fflatsize); - //v3d->t = (float)(pv->y / fflatsize); - - // Need to rotate before translate - if (angle) // Only needs to be done if there's an altered angle - { - tempxsow = FLOAT_TO_FIXED(v3d->s); - tempytow = FLOAT_TO_FIXED(v3d->t); - v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - v3d->t = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); - } - - //v3d->s = (float)(v3d->s - flatxref + scrollx); - //v3d->t = (float)(flatyref - v3d->t + scrolly); - - v3d->x = pv->x; - v3d->y = height; - v3d->z = pv->y; - -#ifdef ESLOPE - if (slope) - { - fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED(pv->x), FLOAT_TO_FIXED(pv->y)); - v3d->y = FIXED_TO_FLOAT(fixedheight); - } -#endif - } +#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);\ +\ + /* Need to rotate before translate */\ + if (angle) /* Only needs to be done if there's an altered angle */\ + {\ + tempxsow = FLOAT_TO_FIXED(vert->s);\ + tempytow = FLOAT_TO_FIXED(vert->t);\ + vert->s = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle))));\ + vert->t = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));\ + }\ +\ + vert->x = (vx);\ + vert->y = height;\ + vert->z = (vy);\ +\ + if (slope)\ + {\ + fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED((vx)), FLOAT_TO_FIXED((vy)));\ + vert->y = FIXED_TO_FLOAT(fixedheight);\ + }\ +} + for (i = 0, v3d = planeVerts; i < nrPlaneVerts; i++,v3d++,pv++) + SETUP3DVERT(v3d, pv->x, pv->y); HWR_Lighting(&Surf, lightlevel, planecolormap); @@ -3180,7 +3172,7 @@ void HWR_Subsector(size_t num) // 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); + PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap, sub); } } } @@ -3196,7 +3188,7 @@ void HWR_Subsector(size_t num) // 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); + PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, ceilingcolormap, sub); } } } @@ -3262,7 +3254,7 @@ 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); + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap, sub); } } @@ -3314,7 +3306,7 @@ 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); + rover->master->frontsector, 255, gr_frontsector->lightlist[light].extra_colormap, sub); } } } @@ -5461,6 +5453,11 @@ void HWR_SetTransform(float fpov, player_t *player) postimg_t *postprocessor = &postimgtype[0]; INT32 i; + // copy view cam position for local use + dup_viewx = viewx; + dup_viewy = viewy; + dup_viewz = viewz; + gr_viewx = FIXED_TO_FLOAT(viewx); gr_viewy = FIXED_TO_FLOAT(viewy); gr_viewz = FIXED_TO_FLOAT(viewz); @@ -5660,6 +5657,7 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search HWR_PortalClipping(rootportal); } + //drawcount = 0; validcount++; if (cv_grbatching.value) HWD.pfnStartBatching(); @@ -5698,18 +5696,8 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_SetTransform(fpov, player);// restore transform } gr_collect_skywalls = false; - - ps_numsprites.value.i = gr_visspritecount; - PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); - PS_STOP_TIMING(ps_hw_spritesorttime); - PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); - PS_STOP_TIMING(ps_hw_spritedrawtime); - - ps_numdrawnodes.value.i = 0; - ps_hw_nodesorttime.value.p = 0; - ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } // free memory from portal list allocated by calls to Add2Lines @@ -5882,8 +5870,19 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play // Render the BSP from the new viewpoint. portalcullsector = gr_portalcullsectors[portalnum]; HWR_RenderBSPNode((INT32)numnodes - 1); + + // Draw MD2 and sprites + ps_numsprites.value.i = gr_visspritecount; + PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); + PS_STOP_TIMING(ps_hw_spritesorttime); + PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); + PS_STOP_TIMING(ps_hw_spritedrawtime); + + ps_numdrawnodes.value.i = 0; + ps_hw_nodesorttime.value.p = 0; + ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 4c1f893c1..51a362c9e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -111,7 +111,7 @@ 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); +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_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 From 7beab3b582f0c7455a9676f3ae15ebe987e8aa23 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 8 Sep 2023 10:42:31 +0200 Subject: [PATCH 050/239] fix the sprite renderstats again aAAaaa --- src/hardware/hw_main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2db41707f..49bdaa499 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5696,8 +5696,18 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * HWR_SetTransform(fpov, player);// restore transform } gr_collect_skywalls = false; + + ps_numsprites.value.i = gr_visspritecount; + PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); + PS_STOP_TIMING(ps_hw_spritesorttime); + PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); + PS_STOP_TIMING(ps_hw_spritedrawtime); + + ps_numdrawnodes.value.i = 0; + ps_hw_nodesorttime.value.p = 0; + ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } // free memory from portal list allocated by calls to Add2Lines @@ -5871,18 +5881,8 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play portalcullsector = gr_portalcullsectors[portalnum]; HWR_RenderBSPNode((INT32)numnodes - 1); - // Draw MD2 and sprites - ps_numsprites.value.i = gr_visspritecount; - PS_START_TIMING(ps_hw_spritesorttime); HWR_SortVisSprites(); - PS_STOP_TIMING(ps_hw_spritesorttime); - PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); - PS_STOP_TIMING(ps_hw_spritedrawtime); - - ps_numdrawnodes.value.i = 0; - ps_hw_nodesorttime.value.p = 0; - ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); } From cdedf1349cd4e797a8e8ffcac3a9032d3278e888 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 11:47:19 +0300 Subject: [PATCH 051/239] 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); From 9cd0e6c38512e56ca2e0c4c34e886b7e5db49cca Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 12:00:10 +0300 Subject: [PATCH 052/239] 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) From a47aea4c9f01b411372b95d28dfc57866ef6bb55 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 18:29:05 +0300 Subject: [PATCH 053/239] Fix 'error in error handling' for cases when error happens in cvar.func right when cvar is registered --- src/lua_consolelib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index dc965851f..584fc2ef8 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -293,6 +293,8 @@ static void Lua_OnChange(void) //lua_settop(gL, 0); // Just in case... lua_pushcfunction(gL, LUA_GetErrorMessage); + int error_handler_i = abs_index(gL, -1); + // From CV_OnChange registry field, get the function for this cvar by name. lua_getfield(gL, LUA_REGISTRYINDEX, "CV_OnChange"); I_Assert(lua_istable(gL, -1)); @@ -304,7 +306,7 @@ static void Lua_OnChange(void) lua_getfield(gL, -1, cvname); // get consvar_t* userdata. lua_remove(gL, -2); // pop the CV_Vars table. - LUA_Call(gL, 1, 0, 1); // call function(cvar) + LUA_Call(gL, 1, 0, error_handler_i); // call function(cvar) lua_pop(gL, 2); // pop CV_OnChange table and error handler } From 1c9ea1eb2e9bb9e210d93f568dc5797083198cf7 Mon Sep 17 00:00:00 2001 From: lug420 Date: Sat, 9 Sep 2023 01:38:23 +0200 Subject: [PATCH 054/239] fix a crash with rotsprites + clean up this absolute mess --- src/hardware/hw_main.c | 2 +- src/r_patch.c | 2120 +++++++++++++++++++--------------------- src/r_patch.h | 137 ++- src/r_things.c | 2 +- 4 files changed, 1088 insertions(+), 1173 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 49bdaa499..aa9a921e2 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5065,7 +5065,7 @@ void HWR_ProjectSprite(mobj_t *thing) rollsum = (thing->rollangle)+(thing->sloperoll); rollangle = R_GetRollAngle(rollsum); - rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, sprinfo, rollangle); + rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); if (rotsprite != NULL) { diff --git a/src/r_patch.c b/src/r_patch.c index 881ca41de..efd49f5e2 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -1,1102 +1,1018 @@ -// 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; - } - } - } - else - { - /*for (i = 0; i <= NUMPLAYERSPRITES; i++) - { - if (i == NUMPLAYERSPRITES) - I_Error("Error parsing SPRTINFO lump: Unknown sprite2 name \"%s\"", newSpriteName); - if (!memcmp(newSpriteName,spr2names[i],4)) - { - spr2num = i; - break; - } - }*/ - // Fuckal: 2.1; playersprites don't exist - } - - // 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); - /*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 = &skins[skinnum]; - spriteinfo_t *sprinfo = skin->sprinfo; -#ifdef ROTSPRITE - R_FreeSkinRotSprite(skinnum); -#endif - M_Memcpy(&sprinfo[spr2num], 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) - { - 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, void *info, - INT32 rotationangle) -{ - rotsprite_t *rotsprite; - spriteinfo_t *sprinfo = (spriteinfo_t *)info; - boolean adjustfeet; - - adjustfeet = (rendermode == render_none); - - 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; - //sprframe->rotsprite.patch[rot][angle] = (patch_t *)grPatch; - HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); - return (patch_t *)grPatch; -} - -// -// R_CacheRotSprite -// -// Create a rotated sprite. -// -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, UINT8 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_Malloc(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+1 - minx); - height = (maxy+1 - miny); - - if ((unsigned)(width * height) > size) - { - UINT16 *src, *dest; - - - size = (width * height); - rawconv = Z_Malloc(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; - -} - -// -// R_FreeSingleRotSprite -// -// IS DEAD BECAUSE OF SIGSEG HELL -// - -// -// R_FreeSkinRotSprite -// -// Free sprite rotation data from memory, for a skin. -// Calls R_FreeSingleRotSprite. -// -/*void R_FreeSkinRotSprite(size_t skinnum) -{ - size_t i; - skin_t *skin = &skins[skinnum]; - spritedef_t *skinsprites = skin->sprites; - for (i = 0; i < NUMPLAYERSPRITES*2; i++) - { - R_FreeSingleRotSprite(skinsprites); - skinsprites++; - } -}*/ - -// -// R_FreeAllRotSprite -// -// Free ALL sprite rotation data from memory. -// -void R_FreeAllRotSprite(void) -{ - //INT32 i; - size_t s; - /*for (i = 0; i < numskins; ++i) - R_FreeSkinRotSprite(i);*/ -} -#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_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 diff --git a/src/r_patch.h b/src/r_patch.h index 054e28e11..ac8072a43 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -1,69 +1,68 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1993-1996 by id Software, Inc. -// Copyright (C) 2018-2019 by Jaime "Lactozilla" Passos. -// Copyright (C) 2019 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.h -/// \brief Patch generation. - -#ifndef __R_PATCH__ -#define __R_PATCH__ - -#include "r_defs.h" -#include "doomdef.h" - -// Structs -typedef enum -{ - ROTAXIS_X, // Roll (the default) - ROTAXIS_Y, // Pitch - ROTAXIS_Z // Yaw -} rotaxis_t; - -typedef struct -{ - INT32 x, y; - rotaxis_t rotaxis; -} spriteframepivot_t; - -typedef struct -{ - spriteframepivot_t pivot[64]; - boolean available; -} spriteinfo_t; - -// Conversions between patches / flats / textures... -boolean R_CheckIfPatch(lumpnum_t lump); -void R_TextureToFlat(size_t tex, UINT8 *flat); -void R_PatchToFlat(patch_t *patch, UINT8 *flat); -void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip); -patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency); -patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize); - -// SpriteInfo -extern spriteinfo_t spriteinfo[NUMSPRITES]; -void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps); -void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); - -// Sprite rotation -#ifdef ROTSPRITE -INT32 R_GetRollAngle(angle_t rollangle); -patch_t *Patch_GetRotatedSprite( - spriteframe_t *sprite, - size_t frame, size_t spriteangle, - boolean flip, void *info, - INT32 rotationangle); -rotsprite_t *RotatedPatch_Create(INT32 numangles); -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, UINT8 flip); -//void R_FreeSkinRotSprite(size_t skinnum); -extern fixed_t rollcosang[ROTANGLES]; -extern fixed_t rollsinang[ROTANGLES]; -void R_FreeAllRotSprite(void); -#endif - -#endif // __R_PATCH__ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 2018-2019 by Jaime "Lactozilla" Passos. +// Copyright (C) 2019 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.h +/// \brief Patch generation. + +#ifndef __R_PATCH__ +#define __R_PATCH__ + +#include "r_defs.h" +#include "doomdef.h" + +// Structs +typedef enum +{ + ROTAXIS_X, // Roll (the default) + ROTAXIS_Y, // Pitch + ROTAXIS_Z // Yaw +} rotaxis_t; + +typedef struct +{ + INT32 x, y; + rotaxis_t rotaxis; +} spriteframepivot_t; + +typedef struct +{ + spriteframepivot_t pivot[64]; + boolean available; +} spriteinfo_t; + +// Conversions between patches / flats / textures... +boolean R_CheckIfPatch(lumpnum_t lump); +void R_TextureToFlat(size_t tex, UINT8 *flat); +void R_PatchToFlat(patch_t *patch, UINT8 *flat); +void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip); +patch_t *R_FlatToPatch(UINT8 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize, boolean transparency); +patch_t *R_MaskedFlatToPatch(UINT16 *raw, UINT16 width, UINT16 height, UINT16 leftoffset, UINT16 topoffset, size_t *destsize); + +// SpriteInfo +extern spriteinfo_t spriteinfo[NUMSPRITES]; +void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps); +void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); + +// Sprite rotation +#ifdef ROTSPRITE +INT32 R_GetRollAngle(angle_t rollangle); +patch_t *Patch_GetRotatedSprite( + spriteframe_t *sprite, + size_t frame, size_t spriteangle, + boolean flip, boolean adjustfeet, + void *info, INT32 rotationangle); +rotsprite_t *RotatedPatch_Create(INT32 numangles); +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); + +extern fixed_t rollcosang[ROTANGLES]; +extern fixed_t rollsinang[ROTANGLES]; +#endif + +#endif // __R_PATCH__ diff --git a/src/r_things.c b/src/r_things.c index 26dad2f0b..66c583259 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1373,7 +1373,7 @@ static void R_ProjectSprite(mobj_t *thing) rollsum = (thing->rollangle) + (thing->sloperoll); rollangle = R_GetRollAngle(rollsum); - rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, sprinfo, rollangle); + rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); if (rotsprite != NULL) { From 3aac16432aa20878775e00f08eebc0bd8d2d9893 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sat, 9 Sep 2023 16:18:46 +0200 Subject: [PATCH 055/239] adjust things more try to mitigate performance loss and stutters readjust the look a bit cleanup stuff a bit this thing still pretty much runs badly --- src/hardware/r_opengl/r_opengl.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index df245c664..b7420717e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -565,7 +565,6 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; static INT32 gl_use_palette_shader = 0; -static boolean gl_palette_initialized = false; static INT32 gl_enable_screen_textures = 1; @@ -736,8 +735,8 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ - "gl_FragColor = vec4(float(palette[pal_idx*3])/232.0, float(palette[pal_idx*3+1])/232.0, float(palette[pal_idx*3+2])/232.0, 1.0);\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((11.0/12.0) * texel + 1.0 / 24.0))[0] * 255.0);\n" \ + "gl_FragColor = vec4(float(palette[pal_idx*3])/250.0, float(palette[pal_idx*3+1])/250.0, float(palette[pal_idx*3+2])/250.0, 1.0);\n" \ "}\0" #define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ @@ -850,6 +849,7 @@ static const char *vertex_shaders[] = { void SetupGLFunc4(void) { + pglTexImage3D = GetGLFunc("glTexImage3D"); pglActiveTexture = GetGLFunc("glActiveTexture"); pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); @@ -887,8 +887,6 @@ void SetupGLFunc4(void) pglGetUniformLocation = GetGLFunc("glGetUniformLocation"); #endif - pglTexImage3D = GetGLFunc("glTexImage3D"); // how about here then... - // GLU pgluBuild2DMipmaps = GetGLFunc("gluBuild2DMipmaps"); } @@ -1082,7 +1080,7 @@ GLuint palette_tex_num; // smallest separation between all the colors in the srb2 palette is 6, so // possibly a 64x64x64 lookup texture might be enough for 100% correct colors // (min separation for 64^3 size is 4) -#define LUT_SIZE 16 +#define LUT_SIZE 12 #define STEP_SIZE (256/LUT_SIZE) // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! @@ -1102,7 +1100,7 @@ static void InitPalette(void) gl_palette[i*3+1] = (GLint)(fgreen / 63.0f * 255.0f); gl_palette[i*3+2] = (GLint)(fblue / 31.0f * 255.0f); } - + // init the palette conversion lookup texture GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); if (!pal_lookup_tex) @@ -1114,21 +1112,21 @@ static void InitPalette(void) { for (r = 0; r < LUT_SIZE; r++) { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+2, g*STEP_SIZE+2, b*STEP_SIZE+2); + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+3, g*STEP_SIZE+3, b*STEP_SIZE+3); } } } + pglGenTextures(1, &palette_tex_num); 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); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer + pglTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); free(pal_lookup_tex); - gl_palette_initialized = true; } // -----------------+ From a639c87a90992823928290f7da0d4b9396d05434 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sun, 10 Sep 2023 16:43:42 +0200 Subject: [PATCH 056/239] rework this thing, use parts of the new palette renderer this atleast completely fixed the stutters and prob the memory leaks the thing had before its still super messy and idk --- src/hardware/r_opengl/r_opengl.c | 74 +++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b7420717e..403547837 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -25,6 +25,7 @@ #include #include "r_opengl.h" #include "r_vbo.h" +#include "../../z_zone.h" #include "../../v_video.h" // pLocalPalette #include "../../r_data.h" // NearestColor @@ -75,8 +76,9 @@ static FBITFIELD CurrentPolyFlags; static FTextureInfo *gr_cachetail = NULL; static FTextureInfo *gr_cachehead = NULL; - -RGBA_t myPaletteData[256]; +static GLuint palette_tex_num = 0; // 1D texture containing the screen palette +static GLuint pal_lookup_tex = 0; // 3D texture containing RGB -> palette index lookup table +RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; GLbyte screen_depth = 0; @@ -357,6 +359,8 @@ typedef void (APIENTRY * PFNglTexEnvi) (GLenum target, GLenum pname, GLint param static PFNglTexEnvi pglTexEnvi; typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint param); static PFNglTexParameteri pglTexParameteri; +typedef void (APIENTRY * PFNglTexImage1D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage1D pglTexImage1D; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); @@ -419,6 +423,9 @@ static PFNglColorPointer pglColorPointer; #ifndef GL_TEXTURE1 #define GL_TEXTURE1 0x84C1 #endif +#ifndef GL_TEXTURE2 +#define GL_TEXTURE2 0x84C2 +#endif boolean SetupGLfunc(void) { @@ -481,6 +488,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexParameteri, glTexParameteri) + GETOPENGLFUNC(pglTexImage1D, glTexImage1D) GETOPENGLFUNC(pglTexImage2D, glTexImage2D) GETOPENGLFUNC(pglFogf, glFogf) @@ -1005,6 +1013,20 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); #undef GETUNI + +// set permanent uniform values +#define UNIFORM_1(uniform, a, function) \ + if (uniform != -1) \ + function (uniform, a); + + pglUseProgram(shader->program); + + // texture unit numbers for the samplers used for palette rendering + UNIFORM_1(shader->uniforms[gluniform_palette], 2, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); + +#undef UNIFORM_1 + } #endif return true; @@ -1075,7 +1097,7 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } -GLuint palette_tex_num; + // length of one side of lookup texture // smallest separation between all the colors in the srb2 palette is 6, so // possibly a 64x64x64 lookup texture might be enough for 100% correct colors @@ -1101,32 +1123,39 @@ static void InitPalette(void) gl_palette[i*3+2] = (GLint)(fblue / 31.0f * 255.0f); } - // init the palette conversion lookup texture - GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); - if (!pal_lookup_tex) - I_Error("Failed to allocate memory for generating palette lookup texture."); - - for (b = 0; b < LUT_SIZE; b++) - { - for (g = 0; g < LUT_SIZE; g++) + // init the palette conversion lookup texture + UINT8 *pal_lookup_tex = Z_Malloc( + LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(UINT8), + PU_STATIC, NULL); + + if (!pal_lookup_tex) + I_Error("Failed to allocate memory for generating palette lookup texture."); + + for (b = 0; b < LUT_SIZE; b++) { - for (r = 0; r < LUT_SIZE; r++) + for (g = 0; g < LUT_SIZE; g++) { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+3, g*STEP_SIZE+3, b*STEP_SIZE+3); + for (r = 0; r < LUT_SIZE; r++) + { + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+3, g*STEP_SIZE+3, b*STEP_SIZE+3); + } } } - } - +#undef STEP_SIZE + Z_Free(pal_lookup_tex); + pglGenTextures(1, &palette_tex_num); + pglActiveTexture(GL_TEXTURE1); 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); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); // test: put gl_red instead of gl_red_integer + pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); + pglActiveTexture(GL_TEXTURE0); pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); - free(pal_lookup_tex); + } // -----------------+ @@ -3878,9 +3907,14 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) if (gl_use_palette_shader) { pglUseProgram(gl_shaderprograms[8].program); // palette shader - pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + pglGenTextures(1, &palette_tex_num); pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); + pglBindTexture(GL_TEXTURE_1D, palette_tex_num); + pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_palette); + pglActiveTexture(GL_TEXTURE0); } pglColor4ubv(white); @@ -3893,7 +3927,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) if (gl_use_palette_shader) { pglUseProgram(0); - pglBindTexture(GL_TEXTURE_3D, 0); + pglBindTexture(GL_TEXTURE_1D, 0); pglActiveTexture(GL_TEXTURE0); } } From 3ce4653bb5e9c090f1d49247e8d5e3fb07edcb5c Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sun, 10 Sep 2023 16:57:38 +0200 Subject: [PATCH 057/239] smol adjustment --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 403547837..870cc6652 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -743,7 +743,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((11.0/12.0) * texel + 1.0 / 24.0))[0] * 255.0);\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 11.0 + 0.5) / 12.0))[0] * 255.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/250.0, float(palette[pal_idx*3+1])/250.0, float(palette[pal_idx*3+2])/250.0, 1.0);\n" \ "}\0" From d3d40de996c9d45551c7e740e45348aec7ba2ae9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sun, 10 Sep 2023 18:59:31 +0200 Subject: [PATCH 058/239] unfuck this thing change lut size to full 64 holy fuck, goddamit, im so mad at this --- src/hardware/r_opengl/r_opengl.c | 41 +++++++++++--------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 870cc6652..a1c33bd9d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -25,7 +25,6 @@ #include #include "r_opengl.h" #include "r_vbo.h" -#include "../../z_zone.h" #include "../../v_video.h" // pLocalPalette #include "../../r_data.h" // NearestColor @@ -359,8 +358,6 @@ typedef void (APIENTRY * PFNglTexEnvi) (GLenum target, GLenum pname, GLint param static PFNglTexEnvi pglTexEnvi; typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint param); static PFNglTexParameteri pglTexParameteri; -typedef void (APIENTRY * PFNglTexImage1D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -static PFNglTexImage1D pglTexImage1D; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); @@ -423,9 +420,6 @@ static PFNglColorPointer pglColorPointer; #ifndef GL_TEXTURE1 #define GL_TEXTURE1 0x84C1 #endif -#ifndef GL_TEXTURE2 -#define GL_TEXTURE2 0x84C2 -#endif boolean SetupGLfunc(void) { @@ -488,7 +482,6 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexParameteri, glTexParameteri) - GETOPENGLFUNC(pglTexImage1D, glTexImage1D) GETOPENGLFUNC(pglTexImage2D, glTexImage2D) GETOPENGLFUNC(pglFogf, glFogf) @@ -573,6 +566,7 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; static INT32 gl_use_palette_shader = 0; +static boolean gl_palette_initialized = false; static INT32 gl_enable_screen_textures = 1; @@ -743,8 +737,8 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform int palette[768];\n" \ "void main(void) {\n" \ "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 11.0 + 0.5) / 12.0))[0] * 255.0);\n" \ - "gl_FragColor = vec4(float(palette[pal_idx*3])/250.0, float(palette[pal_idx*3+1])/250.0, float(palette[pal_idx*3+2])/250.0, 1.0);\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" #define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ @@ -1088,6 +1082,7 @@ EXPORT void HWRAPI(UnSetShader) (void) gl_shadersenabled = false; gl_currentshaderprogram = 0; gl_shaderprogramchanged = true;// not sure if this is needed + if (!pglUseProgram) return; pglUseProgram(0); #endif } @@ -1097,12 +1092,11 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } - // length of one side of lookup texture // smallest separation between all the colors in the srb2 palette is 6, so // possibly a 64x64x64 lookup texture might be enough for 100% correct colors // (min separation for 64^3 size is 4) -#define LUT_SIZE 12 +#define LUT_SIZE 64 #define STEP_SIZE (256/LUT_SIZE) // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! @@ -1124,9 +1118,7 @@ static void InitPalette(void) } // init the palette conversion lookup texture - UINT8 *pal_lookup_tex = Z_Malloc( - LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(UINT8), - PU_STATIC, NULL); + GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); if (!pal_lookup_tex) I_Error("Failed to allocate memory for generating palette lookup texture."); @@ -1137,25 +1129,24 @@ static void InitPalette(void) { for (r = 0; r < LUT_SIZE; r++) { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+3, g*STEP_SIZE+3, b*STEP_SIZE+3); + pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); } } } #undef STEP_SIZE - Z_Free(pal_lookup_tex); + pglGenTextures(1, &palette_tex_num); - pglActiveTexture(GL_TEXTURE1); 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); pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); - pglActiveTexture(GL_TEXTURE0); + free(pal_lookup_tex); pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); - + gl_palette_initialized = true; } // -----------------+ @@ -1449,7 +1440,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_use_palette_shader == 1) + if (!gl_palette_initialized) InitPalette(); // just gonna put this here for now } @@ -3908,13 +3899,8 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); - pglGenTextures(1, &palette_tex_num); pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_1D, palette_tex_num); - pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_palette); - pglActiveTexture(GL_TEXTURE0); + pglBindTexture(GL_TEXTURE_3D, palette_tex_num); } pglColor4ubv(white); @@ -3924,10 +3910,11 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); tex_downloaded = finalScreenTexture; + if (gl_use_palette_shader) { pglUseProgram(0); - pglBindTexture(GL_TEXTURE_1D, 0); + pglBindTexture(GL_TEXTURE_3D, 0); pglActiveTexture(GL_TEXTURE0); } } From 362c21505ddb77d8656e0d9134cec4c66267e7d1 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 11 Sep 2023 01:04:43 +0200 Subject: [PATCH 059/239] smol fixup fixes the weird black/white screen on game start --- src/hardware/r_opengl/r_opengl.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a1c33bd9d..bb3a019ac 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -585,11 +585,12 @@ typedef enum gluniform_fade_start, gluniform_fade_end, - // misc. (custom shaders) - gluniform_leveltime, - + // palette rendering gluniform_palette, gluniform_color_lookup, + + // misc. + gluniform_leveltime, gluniform_max, } gluniform_t; @@ -1000,11 +1001,12 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_fade_start] = GETUNI("fade_start"); shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); - // misc. (custom shaders) - shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); - + // palette rendering shader->uniforms[gluniform_palette] = GETUNI("palette"); shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); + + // misc. (custom shaders) + shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); #undef GETUNI @@ -1018,6 +1020,8 @@ EXPORT boolean HWRAPI(LoadShaders) (void) // texture unit numbers for the samplers used for palette rendering UNIFORM_1(shader->uniforms[gluniform_palette], 2, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); + + pglUseProgram(0); #undef UNIFORM_1 From 561af0e601008f5279519d547fbc03130e3fcae6 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 11 Sep 2023 02:14:22 +0200 Subject: [PATCH 060/239] smol adjustment --- src/hardware/r_opengl/r_opengl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index bb3a019ac..82787faf6 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -736,9 +736,13 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform sampler2D tex;\n" \ "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ + "uniform float lighting;\n" \ + GLSL_DOOM_COLORMAP \ "void main(void) {\n" \ - "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "float pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ + "float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" From f46b77ab7b9233b065e281c264de10a6f12f2060 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Mon, 11 Sep 2023 13:59:15 +0800 Subject: [PATCH 061/239] fix shader compile error, fix custom level palettes --- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/hardware/r_opengl/r_opengl.h | 4 ++++ src/v_video.c | 7 ++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 82787faf6..2b2dc1b1d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -566,7 +566,7 @@ static boolean gl_batching = false;// are we currently collecting batches? static GLint gl_palette[768]; static INT32 gl_use_palette_shader = 0; -static boolean gl_palette_initialized = false; +boolean gl_palette_initialized = false; static INT32 gl_enable_screen_textures = 1; @@ -740,7 +740,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_DOOM_COLORMAP \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "float pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ "float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ @@ -1109,7 +1109,7 @@ EXPORT void HWRAPI(KillShaders) (void) // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -static void InitPalette(void) +void InitPalette(void) { int i, r, g, b; // init the palette diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index 6d11bf4e3..f4a3f3849 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -133,4 +133,8 @@ typedef enum GLF_NOTEXENV = 0x02, } oglflags_t; +// in order for custom playpals n shit to work properly +extern boolean gl_palette_initialized; +void InitPalette(void); + #endif diff --git a/src/v_video.c b/src/v_video.c index 602e89248..77295c41b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -28,6 +28,7 @@ #ifdef HWRENDER #include "hardware/hw_main.h" +#include "hardware/r_opengl/r_opengl.h" #endif // Each screen is [vid.width*vid.height]; @@ -238,8 +239,12 @@ void V_SetPaletteLump(const char *pal) { LoadPalette(pal); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) + if (rendermode != render_soft && rendermode != render_none) { + // reset our palette lookups n shit + gl_palette_initialized = false; + InitPalette(); HWR_SetPalette(pLocalPalette); + } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) else #endif From 16a7e69292ae7629b0f37d35b1f4b368ea5960ac Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 11 Sep 2023 13:01:29 +0300 Subject: [PATCH 062/239] 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]; From 346433d248987d6f3ca4708150681a4bc38cbcd2 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 11 Sep 2023 13:17:12 +0300 Subject: [PATCH 063/239] 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); From 35cfdea9e71209e1987435a6c1284295035232e2 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 11 Sep 2023 15:55:59 +0200 Subject: [PATCH 064/239] 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), From 4455ebe58f08fdeb95da06efe639986c9e8eeafd Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sat, 2 Sep 2023 13:07:13 +0800 Subject: [PATCH 065/239] 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)) From f9f33aa53a3b8e72c8cc00c1073678a44d6b08c0 Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 11 Sep 2023 18:13:59 +0200 Subject: [PATCH 066/239] add lighttabble shader this was way too much headache set up a basic condition atm, so lighttable generation turns off if the paletteshader is turned off this will break visually if the shader is turned on midrace atm will implement smth better --- src/hardware/hw_defs.h | 3 + src/hardware/hw_drv.h | 6 + src/hardware/hw_main.c | 75 ++++++-- src/hardware/hw_main.h | 2 + src/hardware/r_opengl/r_opengl.c | 297 +++++++++++++++++++++++++++---- src/r_data.c | 10 +- src/r_defs.h | 6 + src/sdl/hwsym_sdl.c | 3 + src/sdl/i_video.c | 3 + 9 files changed, 363 insertions(+), 42 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 1f6dd0f1c..e4ec10b44 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -224,6 +224,7 @@ struct FSurfaceInfo RGBA_t PolyColor; RGBA_t TintColor; RGBA_t FadeColor; + UINT32 LightTableId; FLightInfo LightInfo; // jimita 14032019 }; typedef struct FSurfaceInfo FSurfaceInfo; @@ -232,6 +233,8 @@ enum hwdsetspecialstate { HWD_SET_SHADERS, HWD_SET_PALETTE_SHADER_ENABLED, + HWD_SET_SVAR1, + HWD_SET_SVAR2, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index c7786670a..d78ec6667 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -79,6 +79,9 @@ EXPORT void HWRAPI(InitCustomShaders) (void); EXPORT void HWRAPI(StartBatching) (void); EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); +EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable); +EXPORT void HWRAPI(ClearLightTableCache) (void); + // ========================================================================== // HWR DRIVER OBJECT, FOR CLIENT PROGRAM // ========================================================================== @@ -125,6 +128,9 @@ struct hwdriver_s StartBatching pfnStartBatching; RenderBatches pfnRenderBatches; + + AddLightTable pfnAddLightTable; + ClearLightTableCache pfnClearLightTableCache; }; extern struct hwdriver_s hwdriver; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 69e801c7e..c9024e472 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,6 +69,9 @@ static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); static void CV_grpaletteshader_OnChange(void); +static void CV_shadervar1_OnChange(void); +static void CV_shadervar2_OnChange(void); + static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, {HWD_SET_TEXTUREFILTER_MIXED1, "Linear_Nearest"}, @@ -90,6 +93,11 @@ 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_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletteshader_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shadervar1 = {"svar1", "1000", CV_CALL, CV_Unsigned, + CV_shadervar1_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shadervar2 = {"svar2", "1000", CV_CALL, CV_Unsigned, + CV_shadervar2_OnChange, 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}}; @@ -146,8 +154,22 @@ static void CV_useCustomShaders_ONChange(void) static void CV_grpaletteshader_OnChange(void) { if (rendermode == render_opengl) + { HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; + } +} + +static void CV_shadervar1_OnChange(void) +{ + if (rendermode == render_opengl) + HWD.pfnSetSpecialState(HWD_SET_SVAR1, cv_shadervar1.value); +} + +static void CV_shadervar2_OnChange(void) +{ + if (rendermode == render_opengl) + HWD.pfnSetSpecialState(HWD_SET_SVAR2, cv_shadervar2.value); } // ========================================================================== @@ -412,6 +434,7 @@ static size_t gr_numportalcullsectors = 0; void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { RGBA_t poly_color, tint_color, fade_color; + boolean default_colormap = false; poly_color.rgba = 0xFFFFFFFF; tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; @@ -463,6 +486,36 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.light_level = light_level; Surface->LightInfo.fade_start = (colormap != NULL) ? colormap->fadestart : 0; Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; + + if (!colormap) + { + colormap = &extra_colormaps[num_extra_colormaps]; + default_colormap = true; + } + if (!colormap->gl_lighttable_id) + { + UINT8 *colormap_pointer; + + CONS_Printf("Dbg: creating hwr lt, id %u, color %X, fadecolor %X\n", colormap->gl_lighttable_id, colormap->rgba, colormap->fadergba); + if (default_colormap) + { + CONS_Printf("Dbg: Watch out! it's the sneaky default colormap!\n"); + colormap_pointer = colormaps; + } + else + { + colormap_pointer = colormap->colormap; + } + colormap->gl_lighttable_id = HWD.pfnAddLightTable(colormap_pointer); + } + + Surface->LightTableId = colormap->gl_lighttable_id; +} + +void HWR_ClearLightTableCache() +{ + if (rendermode == render_opengl) + HWD.pfnClearLightTableCache(); } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work @@ -735,7 +788,7 @@ void HWR_RenderPlane(extrasubsector_t *xsub, boolean isceiling, fixed_t fixedhei else if (PolyFlags & PF_Ripple) HWD.pfnSetShader(5); // water shader else - HWD.pfnSetShader(1); // floor shader + HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags); } @@ -800,7 +853,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) break; } - HWD.pfnSetShader(2); // wall shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader HWD.pfnDrawPolygon(&pSurf, wallVerts, 4, i|PF_Modulated|PF_Decal); } } @@ -834,7 +887,7 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend { HWR_Lighting(pSurf, lightlevel, wallcolormap); - HWD.pfnSetShader(2); // wall shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader // don't draw to color buffer when drawing to stencil if (gl_drawing_stencil) @@ -2968,7 +3021,7 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t else blendmode |= PF_Masked|PF_Modulated; - HWD.pfnSetShader(1); // floor shader + HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader HWD.pfnDrawPolygon(&Surf, planeVerts, nrPlaneVerts, blendmode); } @@ -3767,7 +3820,7 @@ 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(1); // floor shader + HWD.pfnSetShader(gr_use_palette_shader ? 9 : 1); // floor shader HWD.pfnDrawPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated); } } @@ -4134,7 +4187,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) Surf.PolyColor.s.alpha = alpha; - HWD.pfnSetShader(3); // sprite shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); top = bot; @@ -4174,7 +4227,7 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) Surf.PolyColor.s.alpha = alpha; - HWD.pfnSetShader(3); // sprite shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); } @@ -4327,7 +4380,7 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) blend = PF_Translucent|PF_Occlude; } - HWD.pfnSetShader(3); // sprite shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); } } @@ -4421,7 +4474,7 @@ static inline void HWR_DrawPrecipitationSprite(gr_vissprite_t *spr) blend = PF_Translucent|PF_Occlude; } - HWD.pfnSetShader(3); // sprite shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 3); // sprite shader HWD.pfnDrawPolygon(&Surf, wallVerts, 4, blend|PF_Modulated); } @@ -5970,6 +6023,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_portalonly); CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletteshader); + CV_RegisterVar(&cv_shadervar1); + CV_RegisterVar(&cv_shadervar2); } // -------------------------------------------------------------------------- @@ -6033,7 +6088,7 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, pSurf->PolyColor.s.alpha = alpha; // put the alpha back after lighting - HWD.pfnSetShader(2); // wall shader + HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader if (blend & PF_Environment) blendmode |= PF_Occlude; // PF_Occlude must be used for solid objects diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 48d37357c..019b921c6 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -142,6 +142,8 @@ void HWR_AddLine(seg_t *line); boolean HWR_CheckBBox(fixed_t *bspcoord); void HWR_RenderDrawNodes(void); +void HWR_ClearLightTableCache(void); + // hw_main.c: Sprites void HWR_AddSprites(sector_t *sec); void HWR_ProjectSprite(mobj_t *thing); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 2b2dc1b1d..e5816c7c7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -75,9 +75,21 @@ static FBITFIELD CurrentPolyFlags; static FTextureInfo *gr_cachetail = NULL; static FTextureInfo *gr_cachehead = NULL; -static GLuint palette_tex_num = 0; // 1D texture containing the screen palette -static GLuint pal_lookup_tex = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA + +typedef struct LightTableCacheEntry_s +{ + GLuint id; + struct LightTableCacheEntry_s *next; +} LightTableCacheEntry_t; + +LightTableCacheEntry_t *ltcachehead = NULL; +LightTableCacheEntry_t *ltcachetail = NULL; + +// tweakable vars for shader tweaking and testing +float shadervar1 = 1.0; +float shadervar2 = 1.0; + +RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; GLbyte screen_depth = 0; @@ -585,12 +597,18 @@ typedef enum gluniform_fade_start, gluniform_fade_end, + // misc. + gluniform_leveltime, + // palette rendering gluniform_palette, gluniform_color_lookup, + gluniform_lighttable_tex, - // misc. - gluniform_leveltime, + // live tweaking + gluniform_svar1, + gluniform_svar2, + gluniform_max, } gluniform_t; @@ -611,6 +629,18 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; // GLSL Software fragment shader // +#define GLSL_DOOM_COLORMAP_floors \ + "float R_DoomColormap(float light, float z)\n" \ + "{\n" \ + "float lightnum = clamp(light / 17.0, 0.0, 15.0);\n" \ + "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ + "float startmap = (15.0 - lightnum) * 4.0;\n" \ + "float scale = 160.0 / (lightz + 1.0);\n" \ + "return startmap * 1.06 - scale * 0.5 * 1.15;\n" \ + "}\n" + +// 1.06 and 1.15 were chosen when trying to match software lighting in a test map + #define GLSL_DOOM_COLORMAP \ "float R_DoomColormap(float light, float z)\n" \ "{\n" \ @@ -621,6 +651,49 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "return startmap - scale * 0.5;\n" \ "}\n" +#define GLSL_DOOM_COLORMAP_walls \ + "float R_DoomColormap(float light, float z)\n" \ + "{\n" \ + "float lightnum = clamp(light / 17.0, 0.0, 15.0);\n" \ + "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ + "float startmap = (15.0 - lightnum) * 4.0;\n" \ + "float scale = 160.0 / (lightz + 1.0);\n" \ + "return startmap * 1.05 - scale * 1.0 * 1.1;\n" \ + "}\n" + +// 1.05 and 1.1 were chosen when trying to match software lighting in a test map + +#define GLSL_DOOM_COLORMAP_test \ + "float R_DoomColormap(float light, float z)\n" \ + "{\n" \ + "float lightnum = clamp(light / 8.0, 0.0, 31.0);\n" \ + "float scale = 160.0 / z;\n" \ + "float pindex = clamp(scale * 4.0, 0.0, 47.0);\n" \ + "float left = (31.0-lightnum)*2.0;\n" \ + "float right = 160.0 / floor((pindex+1.0) / 512.0);\n" \ + "return left - right;\n" \ + "}\n" + +// this one is adapted from here https://forum.zdoom.org/viewtopic.php?f=4&t=34984 +// and added -0.016 when trying to match it... doesnt really +#define GLSL_DOOM_COLORMAP_test2 \ + "float R_DoomColormap(float light, float z)\n" \ + "{\n" \ + "int L = int((light / 255.0) * 63.0);\n" \ + "int min_L = 36 - L;\n" \ + "if (min_L < 0)\n" \ + "min_L = 0;\n" \ + "else if (min_L > 31)\n" \ + "min_L = 31;\n" \ + "float scale = 1.0 / (gl_FragCoord.z - 0.016);\n" \ + "int index = (59 - L) - int(scale * 192.0 - 192.0);\n" \ + "if (index < min_L)\n" \ + "index = min_L;\n" \ + "else if (index > 31)\n" \ + "index = 31;\n" \ + "return float(index);\n" \ + "}\n" + #define GLSL_DOOM_LIGHT_EQUATION \ "float R_DoomLightingEquation(float light)\n" \ "{\n" \ @@ -648,16 +721,16 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "}\n" \ "final_color = mix(final_color, fade_color, darkness);\n" -#define GLSL_SOFTWARE_FRAGMENT_SHADER \ +#define GLSL_SOFTWARE_UNIFORMS \ "uniform sampler2D tex;\n" \ "uniform vec4 poly_color;\n" \ "uniform vec4 tint_color;\n" \ "uniform vec4 fade_color;\n" \ "uniform float lighting;\n" \ "uniform float fade_start;\n" \ - "uniform float fade_end;\n" \ - GLSL_DOOM_COLORMAP \ - GLSL_DOOM_LIGHT_EQUATION \ + "uniform float fade_end;\n" + +#define GLSL_SOFTWARE_MAIN \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ "vec4 base_color = texel * poly_color;\n" \ @@ -666,7 +739,56 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_SOFTWARE_FADE_EQUATION \ "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ - "}\0" + "}\n" + +#define GLSL_SOFTWARE_FRAGMENT_SHADER_FLOORS \ + GLSL_SOFTWARE_UNIFORMS \ + GLSL_DOOM_COLORMAP_floors \ + GLSL_DOOM_LIGHT_EQUATION \ + GLSL_SOFTWARE_MAIN \ + "\0" + +#define GLSL_SOFTWARE_FRAGMENT_SHADER_WALLS \ + GLSL_SOFTWARE_UNIFORMS \ + GLSL_DOOM_COLORMAP_walls \ + GLSL_DOOM_LIGHT_EQUATION \ + GLSL_SOFTWARE_MAIN \ + "\0" + +#define GLSL_SOFTWARE_PAL_UNIFORMS \ + "uniform sampler2D tex;\n" \ + "uniform sampler2D lighttable_tex;\n" \ + "uniform sampler3D lookup_tex;\n" \ + "uniform int palette[768];\n" \ + "uniform vec4 poly_color;\n" \ + "uniform float lighting;\n" \ + "uniform float svar1;\n" \ + "uniform float svar2;\n" + +#define GLSL_SOFTWARE_PAL_MAIN \ + "void main(void) {\n" \ + "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ + "int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \ + "vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \ + "int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \ + "vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \ + "final_color.a = texel.a * poly_color.a;\n" \ + "gl_FragColor = final_color;\n" \ + "}\n" + +#define GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_FLOORS \ + GLSL_SOFTWARE_PAL_UNIFORMS \ + GLSL_DOOM_COLORMAP_floors \ + GLSL_SOFTWARE_PAL_MAIN \ + "\0" + +#define GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_WALLS \ + GLSL_SOFTWARE_PAL_UNIFORMS \ + GLSL_DOOM_COLORMAP_walls \ + GLSL_SOFTWARE_PAL_MAIN \ + "\0" // // Water surface shader @@ -736,13 +858,9 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform sampler2D tex;\n" \ "uniform sampler3D lookup_tex;\n" \ "uniform int palette[768];\n" \ - "uniform float lighting;\n" \ - GLSL_DOOM_COLORMAP \ "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ - "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \ + "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ + "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" @@ -750,7 +868,7 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform sampler2D tex;\n" \ "uniform int palette[768];\n" \ "void main(void) {\n" \ - "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \" \ + "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ "vec3 best = vec3(200.0);\n" \ "for (int i = 0; i < 256; i++) {\n" \ "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ @@ -775,16 +893,16 @@ static const char *fragment_shaders[] = { GLSL_DEFAULT_FRAGMENT_SHADER, // Floor fragment shader - GLSL_SOFTWARE_FRAGMENT_SHADER, + GLSL_SOFTWARE_FRAGMENT_SHADER_FLOORS, // Wall fragment shader - GLSL_SOFTWARE_FRAGMENT_SHADER, + GLSL_SOFTWARE_FRAGMENT_SHADER_WALLS, // Sprite fragment shader - GLSL_SOFTWARE_FRAGMENT_SHADER, + GLSL_SOFTWARE_FRAGMENT_SHADER_WALLS, // Model fragment shader - GLSL_SOFTWARE_FRAGMENT_SHADER, + GLSL_SOFTWARE_FRAGMENT_SHADER_WALLS, // Water fragment shader GLSL_WATER_FRAGMENT_SHADER, @@ -800,6 +918,10 @@ static const char *fragment_shaders[] = { // Palette fragment shader GLSL_PALETTE_FRAGMENT_SHADER, + + GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_FLOORS, + + GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_WALLS, NULL, }; @@ -848,6 +970,10 @@ static const char *vertex_shaders[] = { // Palette vertex shader GLSL_DEFAULT_VERTEX_SHADER, + + GLSL_DEFAULT_VERTEX_SHADER, + + GLSL_DEFAULT_VERTEX_SHADER, NULL, }; @@ -1004,14 +1130,18 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_lighting] = GETUNI("lighting"); shader->uniforms[gluniform_fade_start] = GETUNI("fade_start"); shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); - - // palette rendering - shader->uniforms[gluniform_palette] = GETUNI("palette"); - shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); // misc. (custom shaders) shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); + // palette rendering + shader->uniforms[gluniform_palette] = GETUNI("palette"); + shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); + shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); + + shader->uniforms[gluniform_svar1] = GETUNI("svar1"); + shader->uniforms[gluniform_svar2] = GETUNI("svar2"); + #undef GETUNI // set permanent uniform values @@ -1024,6 +1154,10 @@ EXPORT boolean HWRAPI(LoadShaders) (void) // texture unit numbers for the samplers used for palette rendering UNIFORM_1(shader->uniforms[gluniform_palette], 2, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); + + UNIFORM_1(shader->uniforms[gluniform_svar1], shadervar1, pglUniform1f); + UNIFORM_1(shader->uniforms[gluniform_svar2], shadervar2, pglUniform1f); pglUseProgram(0); @@ -1100,6 +1234,7 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } +GLuint palette_tex_num; // length of one side of lookup texture // smallest separation between all the colors in the srb2 palette is 6, so // possibly a 64x64x64 lookup texture might be enough for 100% correct colors @@ -1148,12 +1283,31 @@ void InitPalette(void) 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); free(pal_lookup_tex); pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + // bind the palette to the fancy shader here + pglUseProgram(gl_shaderprograms[9].program); + pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette); + // bind tex unit 2 to lighttable tex + pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_lighttable_tex], 2); + pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_color_lookup], 1); + // bind the palette to the fancy shader here + pglUseProgram(gl_shaderprograms[10].program); + pglUniform1iv(gl_shaderprograms[10].uniforms[gluniform_palette], 768, gl_palette); + // bind tex unit 2 to lighttable tex + pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_lighttable_tex], 2); + pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_color_lookup], 1); pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); + + // bind 3d lookup to unit 1, maybe it can stay there + pglActiveTexture(GL_TEXTURE1); + pglBindTexture(GL_TEXTURE_3D, palette_tex_num); + pglActiveTexture(GL_TEXTURE0); gl_palette_initialized = true; } @@ -1336,6 +1490,51 @@ EXPORT void HWRAPI(ClearMipMapCache) (void) Flush(); } +EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable) +{ + LightTableCacheEntry_t *cache_entry = malloc(sizeof(LightTableCacheEntry_t)); + if (!ltcachetail) + { + ltcachehead = ltcachetail = cache_entry; + } + else + { + ltcachetail->next = cache_entry; + ltcachetail = cache_entry; + } + ltcachetail->next = NULL; + pglGenTextures(1, <cachetail->id); + if (!ltcachetail->id) + I_Error("hwr lighttable cache entry id is zero"); + 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); + // should this be a square? (256x256) + // if so, then could change the height. just need to allocate a temp + // 256x256 buffer and copy the lightmap there so there is a full 256x256 + // memory area for opengl to read from. + pglTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable); + + // restore the tex that was bound before + if (!gl_batching) + pglBindTexture(GL_TEXTURE_2D, tex_downloaded); + + return ltcachetail->id; +} + +EXPORT void HWRAPI(ClearLightTableCache) (void) +{ + while (ltcachehead) + { + pglDeleteTextures(1, <cachehead->id); + LightTableCacheEntry_t *next = ltcachehead->next; + free(ltcachehead); + ltcachehead = next; + } + ltcachetail = NULL; + + CONS_Printf("Debug: cleared hwr light tables\n"); +} // -----------------+ // ReadRect : Read a rectangle region of the truecolor framebuffer @@ -2016,6 +2215,9 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; + + diff = poly1->surf.LightTableId - poly2->surf.LightTableId; + if (diff != 0) return diff; diff = poly1->polyFlags - poly2->polyFlags; if (diff != 0) return diff; @@ -2148,7 +2350,15 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i firstFade.alpha = byte2float[currentSurfaceInfo.FadeColor.s.alpha]; if (gl_allowshaders) + { load_shaders(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); + if (gl_use_palette_shader) + { + pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now + pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); + pglActiveTexture(GL_TEXTURE0); + } + } if (currentPolyFlags & PF_NoTexture) currentTexture = 0; @@ -2266,7 +2476,8 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level || currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start || - currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end) + currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end || + currentSurfaceInfo.LightTableId != nextSurfaceInfo.LightTableId) { changeState = true; changeSurfaceInfo = true; @@ -2389,7 +2600,15 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha]; load_shaders(&nextSurfaceInfo, &poly, &tint, &fade); + + if (gl_use_palette_shader) + { + pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now + pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); + pglActiveTexture(GL_TEXTURE0); + } } + currentSurfaceInfo = nextSurfaceInfo; changeSurfaceInfo = false; @@ -2488,6 +2707,14 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.green = byte2float[pSurf->FadeColor.s.green]; fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; + + // inefficient. load the colormap texture + if (gl_use_palette_shader || gl_allowshaders) + { + pglActiveTexture(GL_TEXTURE2); + pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); + pglActiveTexture(GL_TEXTURE0); + } } load_shaders(pSurf, &poly, &tint, &fade); @@ -2834,6 +3061,14 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_PALETTE_SHADER_ENABLED: gl_use_palette_shader = Value; break; + + case HWD_SET_SVAR1: + shadervar1 = (float)Value / 1000.0f; + break; + + case HWD_SET_SVAR2: + shadervar2 = (float)Value / 1000.0f; + break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -3903,13 +4138,13 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (gl_use_palette_shader) + /*if (gl_use_palette_shader) { pglUseProgram(gl_shaderprograms[8].program); // palette shader - pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); + pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); pglActiveTexture(GL_TEXTURE1); pglBindTexture(GL_TEXTURE_3D, palette_tex_num); - } + }*/ pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); @@ -3919,12 +4154,12 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (gl_use_palette_shader) + /*if (gl_use_palette_shader) { pglUseProgram(0); pglBindTexture(GL_TEXTURE_3D, 0); pglActiveTexture(GL_TEXTURE0); - } + }*/ } #endif //HWRENDER diff --git a/src/r_data.c b/src/r_data.c index f982b0366..a352a48a7 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -26,6 +26,10 @@ #include "v_video.h" // pLocalPalette #include "dehacked.h" +#ifdef HWRENDER +#include "hardware/hw_main.h" +#endif + #if defined (_WIN32) || defined (_WIN32_WCE) #include // alloca(sizeof) #endif @@ -1137,6 +1141,10 @@ void R_ClearColormaps(void) foundcolormaps[i] = LUMPERROR; memset(extra_colormaps, 0, sizeof (extra_colormaps)); + +#ifdef HWRENDER + HWR_ClearLightTableCache(); +#endif } /*INT32 R_ColormapNumForName(char *name) @@ -1317,7 +1325,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) + if (rendermode == render_soft || cv_grpaletteshader.value == 1) { double r, g, b, cbrightness; int p; diff --git a/src/r_defs.h b/src/r_defs.h index 559e3646b..7254a6289 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -62,6 +62,12 @@ typedef struct INT32 fadergba; // The colour the colourmaps fade to lighttable_t *colormap; + + +#ifdef HWRENDER + // The id of the hardware lighttable. Zero means it does not exist yet. + UINT32 gl_lighttable_id; +#endif } extracolormap_t; // diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 2627c3fdb..dcaaa7f51 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -113,6 +113,9 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(StartBatching); GETFUNC(RenderBatches); + + GETFUNC(AddLightTable); + GETFUNC(ClearLightTableCache); #else //HWRENDER if (0 == strcmp("FinishUpdate", funcName)) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 3fd96819c..2966cb391 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2141,6 +2141,9 @@ void I_StartupGraphics(void) HWD.pfnStartBatching = hwSym("StartBatching",NULL); HWD.pfnRenderBatches = hwSym("RenderBatches",NULL); + + HWD.pfnAddLightTable = hwSym("AddLightTable",NULL); + HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL); if (!HWD.pfnInit()) // load the OpenGL library rendermode = render_soft; From 2553c9e87898af5d0fe55c5f99cbef91cbd5db0d Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 11 Sep 2023 18:30:35 +0200 Subject: [PATCH 067/239] cleanup a bit remove debug prints and vars clean stuff up a bit --- src/hardware/hw_defs.h | 2 - src/hardware/hw_main.c | 24 --------- src/hardware/r_opengl/r_opengl.c | 87 +++----------------------------- 3 files changed, 6 insertions(+), 107 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index e4ec10b44..6002fcf18 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -233,8 +233,6 @@ enum hwdsetspecialstate { HWD_SET_SHADERS, HWD_SET_PALETTE_SHADER_ENABLED, - HWD_SET_SVAR1, - HWD_SET_SVAR2, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c9024e472..173f423bf 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -69,9 +69,6 @@ static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); static void CV_grpaletteshader_OnChange(void); -static void CV_shadervar1_OnChange(void); -static void CV_shadervar2_OnChange(void); - static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, {HWD_SET_TEXTUREFILTER_MIXED1, "Linear_Nearest"}, @@ -93,11 +90,6 @@ 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_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletteshader_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shadervar1 = {"svar1", "1000", CV_CALL, CV_Unsigned, - CV_shadervar1_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_shadervar2 = {"svar2", "1000", CV_CALL, CV_Unsigned, - CV_shadervar2_OnChange, 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}}; @@ -160,18 +152,6 @@ static void CV_grpaletteshader_OnChange(void) } } -static void CV_shadervar1_OnChange(void) -{ - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_SVAR1, cv_shadervar1.value); -} - -static void CV_shadervar2_OnChange(void) -{ - if (rendermode == render_opengl) - HWD.pfnSetSpecialState(HWD_SET_SVAR2, cv_shadervar2.value); -} - // ========================================================================== // Globals // ========================================================================== @@ -496,10 +476,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col { UINT8 *colormap_pointer; - CONS_Printf("Dbg: creating hwr lt, id %u, color %X, fadecolor %X\n", colormap->gl_lighttable_id, colormap->rgba, colormap->fadergba); if (default_colormap) { - CONS_Printf("Dbg: Watch out! it's the sneaky default colormap!\n"); colormap_pointer = colormaps; } else @@ -6023,8 +6001,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_portalonly); CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletteshader); - CV_RegisterVar(&cv_shadervar1); - CV_RegisterVar(&cv_shadervar2); } // -------------------------------------------------------------------------- diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e5816c7c7..27ca423a6 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -85,10 +85,6 @@ typedef struct LightTableCacheEntry_s LightTableCacheEntry_t *ltcachehead = NULL; LightTableCacheEntry_t *ltcachetail = NULL; -// tweakable vars for shader tweaking and testing -float shadervar1 = 1.0; -float shadervar2 = 1.0; - RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; @@ -596,20 +592,15 @@ typedef enum gluniform_lighting, gluniform_fade_start, gluniform_fade_end, - - // misc. - gluniform_leveltime, // palette rendering gluniform_palette, gluniform_color_lookup, gluniform_lighttable_tex, - // live tweaking - gluniform_svar1, - gluniform_svar2, - - + // misc. + gluniform_leveltime, + gluniform_max, } gluniform_t; @@ -661,39 +652,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "return startmap * 1.05 - scale * 1.0 * 1.1;\n" \ "}\n" -// 1.05 and 1.1 were chosen when trying to match software lighting in a test map - -#define GLSL_DOOM_COLORMAP_test \ - "float R_DoomColormap(float light, float z)\n" \ - "{\n" \ - "float lightnum = clamp(light / 8.0, 0.0, 31.0);\n" \ - "float scale = 160.0 / z;\n" \ - "float pindex = clamp(scale * 4.0, 0.0, 47.0);\n" \ - "float left = (31.0-lightnum)*2.0;\n" \ - "float right = 160.0 / floor((pindex+1.0) / 512.0);\n" \ - "return left - right;\n" \ - "}\n" - -// this one is adapted from here https://forum.zdoom.org/viewtopic.php?f=4&t=34984 -// and added -0.016 when trying to match it... doesnt really -#define GLSL_DOOM_COLORMAP_test2 \ - "float R_DoomColormap(float light, float z)\n" \ - "{\n" \ - "int L = int((light / 255.0) * 63.0);\n" \ - "int min_L = 36 - L;\n" \ - "if (min_L < 0)\n" \ - "min_L = 0;\n" \ - "else if (min_L > 31)\n" \ - "min_L = 31;\n" \ - "float scale = 1.0 / (gl_FragCoord.z - 0.016);\n" \ - "int index = (59 - L) - int(scale * 192.0 - 192.0);\n" \ - "if (index < min_L)\n" \ - "index = min_L;\n" \ - "else if (index > 31)\n" \ - "index = 31;\n" \ - "return float(index);\n" \ - "}\n" - #define GLSL_DOOM_LIGHT_EQUATION \ "float R_DoomLightingEquation(float light)\n" \ "{\n" \ @@ -762,8 +720,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "uniform int palette[768];\n" \ "uniform vec4 poly_color;\n" \ "uniform float lighting;\n" \ - "uniform float svar1;\n" \ - "uniform float svar2;\n" #define GLSL_SOFTWARE_PAL_MAIN \ "void main(void) {\n" \ @@ -849,11 +805,9 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "}\0" // -// Palette color quantization shader test. +// Palette color quantization shader // -// Could test putting this to GLSL_SOFTWARE_FRAGMENT_SHADER and seeing what happens to performance. - #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ "uniform sampler3D lookup_tex;\n" \ @@ -864,19 +818,6 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ "}\0" -#define GLSL_PALETTE_FRAGMENT_SHADER_OLD \ - "uniform sampler2D tex;\n" \ - "uniform int palette[768];\n" \ - "void main(void) {\n" \ - "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "vec3 best = vec3(200.0);\n" \ - "for (int i = 0; i < 256; i++) {\n" \ - "vec3 pal_color = vec3(palette[i*3] / 255.0, palette[i*3+1] / 255.0, palette[i*3+2] / 255.0);\n" \ - "best = mix(pal_color, best, step(length(best-texel), length(pal_color-texel)));\n" \ - "}\n" \ - "gl_FragColor = vec4(best[0], best[1], best[2] ,1.0);\n" \ - "}\0" - // // GLSL generic fragment shader // @@ -1131,16 +1072,13 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_fade_start] = GETUNI("fade_start"); shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); - // misc. (custom shaders) - shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); - // palette rendering shader->uniforms[gluniform_palette] = GETUNI("palette"); shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); - shader->uniforms[gluniform_svar1] = GETUNI("svar1"); - shader->uniforms[gluniform_svar2] = GETUNI("svar2"); + // misc. (custom shaders) + shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); #undef GETUNI @@ -1156,9 +1094,6 @@ EXPORT boolean HWRAPI(LoadShaders) (void) UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); - UNIFORM_1(shader->uniforms[gluniform_svar1], shadervar1, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_svar2], shadervar2, pglUniform1f); - pglUseProgram(0); #undef UNIFORM_1 @@ -1532,8 +1467,6 @@ EXPORT void HWRAPI(ClearLightTableCache) (void) ltcachehead = next; } ltcachetail = NULL; - - CONS_Printf("Debug: cleared hwr light tables\n"); } // -----------------+ @@ -3061,14 +2994,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) case HWD_SET_PALETTE_SHADER_ENABLED: gl_use_palette_shader = Value; break; - - case HWD_SET_SVAR1: - shadervar1 = (float)Value / 1000.0f; - break; - - case HWD_SET_SVAR2: - shadervar2 = (float)Value / 1000.0f; - break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) From ec4140a9d29eaf1bb3c6328eb5c7ba52d5fbe42d Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 11 Sep 2023 20:00:09 +0200 Subject: [PATCH 068/239] remove custom shader toggle + clear colormaps when toggle palette shader the custom shader toggle often broke stuff when toggled while palette shader was active also clearing colormaps when toggling palette shader is ugly midlevel but atleast it doesent visually break completely def need to somehow reinitialze colormaps instead or smth --- src/hardware/hw_main.c | 13 ++++++++----- src/hardware/hw_main.h | 2 +- src/m_menu.c | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 173f423bf..1433087eb 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -30,6 +30,7 @@ #include "../r_fps.h" #include "../r_state.h" #include "../r_local.h" +#include "../r_data.h" #include "../r_patch.h" // a mystery as to what this is for #include "../r_bsp.h" // R_NoEncore #include "../r_main.h" // cv_fov @@ -66,7 +67,7 @@ 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_useCustomShaders_ONChange(void); static void CV_grpaletteshader_OnChange(void); static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, @@ -88,7 +89,6 @@ consvar_t cv_grcorrecttricks = {"gr_correcttricks", "Off", 0, CV_OnOff, NULL, 0, consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 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}; static CV_PossibleValue_t grrenderdistance_cons_t[] = { {0, "Max"}, {1, "1024"}, {2, "2048"}, {3, "4096"}, {4, "6144"}, {5, "8192"}, @@ -120,7 +120,9 @@ static INT32 current_bsp_culling_distance = 0; consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, CV_screentextures_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_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL}; // rip in peace sweet prince + +consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletteshader_OnChange, 0, NULL, NULL, 0, 0, NULL}; static void CV_filtermode_ONChange(void) { @@ -137,11 +139,11 @@ static void CV_screentextures_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } -static void CV_useCustomShaders_ONChange(void) +/*static void CV_useCustomShaders_ONChange(void) { if (rendermode == render_opengl) HWD.pfnInitCustomShaders(); -} +}*/ static void CV_grpaletteshader_OnChange(void) { @@ -149,6 +151,7 @@ static void CV_grpaletteshader_OnChange(void) { HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; + R_ClearColormaps(); } } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 019b921c6..37027da82 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -180,7 +180,7 @@ extern consvar_t cv_grfakecontrast; extern consvar_t cv_grfallbackplayermodel; extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; -extern consvar_t cv_grusecustomshaders; +//extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletteshader; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; diff --git a/src/m_menu.c b/src/m_menu.c index 980a4c694..fa4210c00 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1347,7 +1347,8 @@ 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, "Shaders", &cv_grshaders, 25}, - {IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, + //{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, // rip in peace sweet prince + {IT_STRING|IT_CVAR, NULL, "Palette Rendering", &cv_grpaletteshader, 35}, {IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 45}, {IT_STRING|IT_CVAR, NULL, "Texture Quality", &cv_scr_depth, 65}, @@ -1407,7 +1408,6 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING|IT_SUBMENU, NULL, "Advanced Settings...", &OP_SoundAdvancedDef, 155} }; - static menuitem_t OP_SoundAdvancedMenu[] = { #ifdef HAVE_OPENMPT From f91687209ba243be16db2aed532ed8ec3941f9dc Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Fri, 8 Sep 2023 10:15:57 +0800 Subject: [PATCH 069/239] 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)); 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 070/239] 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; From bac058d128c8ec2b2e0086272893b8362aab4859 Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 11 Sep 2023 20:07:03 +0200 Subject: [PATCH 071/239] forgor some things --- src/hardware/r_opengl/r_opengl.c | 10 +++++----- src/m_menu.c | 2 +- src/r_main.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 27ca423a6..71b66c22b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -32,8 +32,8 @@ #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) -// Eeeeh not sure is this right way, but it works -extern consvar_t cv_grusecustomshaders; +// Eeeeh not sure is this right way, but it works < sry :c +//extern consvar_t cv_grusecustomshaders; extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! @@ -982,12 +982,12 @@ EXPORT boolean HWRAPI(LoadShaders) (void) gl_shaderprogram_t *shader; const GLchar* vert_shader = vertex_shaders[i]; const GLchar* frag_shader = fragment_shaders[i]; - boolean custom = cv_grusecustomshaders.value && ((gl_customvertexshaders[i] || gl_customfragmentshaders[i]) && (i > 0)); + boolean custom = ((gl_customvertexshaders[i] || gl_customfragmentshaders[i]) && (i > 0)); // 18032019 - if (cv_grusecustomshaders.value && gl_customvertexshaders[i]) + if (gl_customvertexshaders[i]) vert_shader = gl_customvertexshaders[i]; - if (cv_grusecustomshaders.value && gl_customfragmentshaders[i]) + if (gl_customfragmentshaders[i]) frag_shader = gl_customfragmentshaders[i]; if (i >= MAXSHADERS) diff --git a/src/m_menu.c b/src/m_menu.c index fa4210c00..acaf7cb99 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1347,7 +1347,7 @@ 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, "Shaders", &cv_grshaders, 25}, - //{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, // rip in peace sweet prince + //{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, "Min Shader Brightness", &cv_secbright, 45}, diff --git a/src/r_main.c b/src/r_main.c index dc914e79a..f3b46668f 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1954,7 +1954,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grfakecontrast); CV_RegisterVar(&cv_grshearing); CV_RegisterVar(&cv_grshaders); - CV_RegisterVar(&cv_grusecustomshaders); + CV_RegisterVar(&cv_grpaletteshader); #endif #ifdef HWRENDER From 075148443907304fb5e035f9cb71342f65ae7f74 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 00:38:50 +0200 Subject: [PATCH 072/239] fix some effects idk lmao but this fixes a few effects to be "on par" with software renderer aswell as menus and hud stuff --- src/hardware/r_opengl/r_opengl.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index d8aa3a8c5..8c496f163 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -4078,13 +4078,12 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - /*if (gl_use_palette_shader) + if (gl_use_palette_shader) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); - }*/ + } pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); @@ -4094,12 +4093,11 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - /*if (gl_use_palette_shader) + if (gl_use_palette_shader) { pglUseProgram(0); - pglBindTexture(GL_TEXTURE_3D, 0); pglActiveTexture(GL_TEXTURE0); - }*/ + } } #endif //HWRENDER From 5bf722a1fbf8fa3475b136efb606a20ad06fdb31 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 01:50:46 +0200 Subject: [PATCH 073/239] only allow this thing when shaders are enabled aswell yes i will do it like that no i wont use gl_allowshaders i want this thing to be able to affect the menus and hud, just like software :p --- src/hardware/r_opengl/r_opengl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8c496f163..e18c142b4 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -32,6 +32,8 @@ #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) +#include "../hw_main.h" + // Eeeeh not sure is this right way, but it works < sry :c //extern consvar_t cv_grusecustomshaders; @@ -4078,7 +4080,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) ClearBuffer(true, false, false, &clearColour); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (gl_use_palette_shader) + if (gl_use_palette_shader && cv_grshaders.value) { pglUseProgram(gl_shaderprograms[8].program); // palette shader pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); @@ -4093,7 +4095,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (gl_use_palette_shader) + if (gl_use_palette_shader && cv_grshaders.value) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); From e2acb4c3fc4fec5ec75041b466d35019f41c9e3d Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 17:07:19 +0200 Subject: [PATCH 074/239] only do this when were running the palette shader --- src/hardware/hw_main.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 69af58a99..25395bda7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -470,27 +470,30 @@ 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 (!colormap) + if (gr_use_palette_shader) { - colormap = &extra_colormaps[num_extra_colormaps]; - default_colormap = true; - } - if (!colormap->gl_lighttable_id) + if (!colormap) { - UINT8 *colormap_pointer; - - if (default_colormap) - { - colormap_pointer = colormaps; + colormap = &extra_colormaps[num_extra_colormaps]; + default_colormap = true; } - else - { - colormap_pointer = colormap->colormap; - } - colormap->gl_lighttable_id = HWD.pfnAddLightTable(colormap_pointer); - } + if (!colormap->gl_lighttable_id) + { + UINT8 *colormap_pointer; - Surface->LightTableId = colormap->gl_lighttable_id; + if (default_colormap) + { + colormap_pointer = colormaps; + } + else + { + colormap_pointer = colormap->colormap; + } + colormap->gl_lighttable_id = HWD.pfnAddLightTable(colormap_pointer); + } + + Surface->LightTableId = colormap->gl_lighttable_id; + } } void HWR_ClearLightTableCache() @@ -6118,7 +6121,6 @@ void HWR_Startup(void) } } - // -------------------------------------------------------------------------- // Free resources allocated by the hardware renderer // -------------------------------------------------------------------------- From f83a937dc55ec9bc5c06604d86fe4168ba31e96c Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 18:56:51 +0200 Subject: [PATCH 075/239] redo parts of the lighttable shader this caused performance drops before even with the whole thing disabled --- src/hardware/r_opengl/r_opengl.c | 73 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e18c142b4..575290953 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -49,12 +49,21 @@ struct GLRGBAFloat GLfloat alpha; }; typedef struct GLRGBAFloat GLRGBAFloat; -static const GLubyte white[4] = { 255, 255, 255, 255 }; + +// lighttable list item +struct LTListItem +{ + UINT32 id; + struct LTListItem *next; +}; +typedef struct LTListItem LTListItem; // ========================================================================== // CONSTANTS // ========================================================================== +static const GLubyte white[4] = { 255, 255, 255, 255 }; + // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 @@ -72,20 +81,15 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; static GLuint tex_downloaded = 0; +static GLuint lt_downloaded = 0; // currently bound lighttable texture static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; static FTextureInfo *gr_cachetail = NULL; static FTextureInfo *gr_cachehead = NULL; -typedef struct LightTableCacheEntry_s -{ - GLuint id; - struct LightTableCacheEntry_s *next; -} LightTableCacheEntry_t; - -LightTableCacheEntry_t *ltcachehead = NULL; -LightTableCacheEntry_t *ltcachetail = NULL; +static LTListItem *LightTablesTail = NULL; +static LTListItem *LightTablesHead = NULL; RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() @@ -1427,48 +1431,47 @@ EXPORT void HWRAPI(ClearMipMapCache) (void) Flush(); } + EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable) { - LightTableCacheEntry_t *cache_entry = malloc(sizeof(LightTableCacheEntry_t)); - if (!ltcachetail) + LTListItem *item = malloc(sizeof(LTListItem)); + if (!LightTablesTail) { - ltcachehead = ltcachetail = cache_entry; + LightTablesHead = LightTablesTail = item; } else { - ltcachetail->next = cache_entry; - ltcachetail = cache_entry; + LightTablesTail->next = item; + LightTablesTail = item; } - ltcachetail->next = NULL; - pglGenTextures(1, <cachetail->id); - if (!ltcachetail->id) - I_Error("hwr lighttable cache entry id is zero"); - pglBindTexture(GL_TEXTURE_2D, ltcachetail->id); + item->next = NULL; + pglGenTextures(1, &item->id); + pglBindTexture(GL_TEXTURE_2D, item->id); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - // should this be a square? (256x256) - // if so, then could change the height. just need to allocate a temp - // 256x256 buffer and copy the lightmap there so there is a full 256x256 - // memory area for opengl to read from. pglTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable); - // restore the tex that was bound before - if (!gl_batching) - pglBindTexture(GL_TEXTURE_2D, tex_downloaded); + // restore previously bound texture + pglBindTexture(GL_TEXTURE_2D, tex_downloaded); - return ltcachetail->id; + return item->id; } +// Delete light table textures, ids given before become invalid and must not be used. EXPORT void HWRAPI(ClearLightTableCache) (void) { - while (ltcachehead) + while (LightTablesHead) { - pglDeleteTextures(1, <cachehead->id); - LightTableCacheEntry_t *next = ltcachehead->next; - free(ltcachehead); - ltcachehead = next; + LTListItem *item = LightTablesHead; + pglDeleteTextures(1, (GLuint *)&item->id); + LightTablesHead = item->next; + free(item); } - ltcachetail = NULL; + + LightTablesTail = NULL; + + // we no longer have a bound light table (if we had one), we just deleted it! + lt_downloaded = 0; } // -----------------+ @@ -2658,12 +2661,12 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - // inefficient. load the colormap texture - if (gl_use_palette_shader || gl_allowshaders) + if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); pglActiveTexture(GL_TEXTURE0); + lt_downloaded = pSurf->LightTableId; } } From b4d48cc9ec8a73790574b50b6557d05eece0902d Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 12 Sep 2023 21:55:35 +0300 Subject: [PATCH 076/239] Set palette uniform in InitPalette instead of DrawScreenFinalTexture --- src/hardware/r_opengl/r_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 575290953..62d2caa75 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1230,6 +1230,7 @@ void InitPalette(void) free(pal_lookup_tex); pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit + pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); // bind the palette to the fancy shader here pglUseProgram(gl_shaderprograms[9].program); pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette); @@ -4086,7 +4087,6 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) if (gl_use_palette_shader && cv_grshaders.value) { pglUseProgram(gl_shaderprograms[8].program); // palette shader - pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); pglActiveTexture(GL_TEXTURE1); } From b6ef6eb8018a383fe27189755fcc2836ea4d7df9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 12 Sep 2023 21:03:58 +0200 Subject: [PATCH 077/239] 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) { From 64b2e2ee37a2d2fb1e1b43d4084d8f01880091db Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:40:52 +0200 Subject: [PATCH 078/239] Fix bugs with HWR_SplitWall and sloped midtextures but cleaner performance still pretty bad, atleast this is cleaner than last time --- src/hardware/hw_main.c | 148 ++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 90 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 66adf3522..07f74f6a5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -951,6 +951,9 @@ 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; @@ -959,6 +962,8 @@ 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++) { @@ -1069,24 +1074,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif -#ifdef ESLOPE - if (endbheight >= endtop) -#endif - if (bheight >= top) - continue; + // Found a break + bot = min(max(bheight, realbot), top); + endbot = min(max(endbheight, endrealbot), endtop); - //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 @@ -1680,10 +1671,7 @@ 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) @@ -1719,6 +1707,10 @@ 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. @@ -1732,8 +1724,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // From CB if (gr_curline->polyseg) { - popentop = back->ceilingheight; - popenbottom = back->floorheight; + popentop = popentopslope = back->ceilingheight; + popenbottom = popenbottomslope = back->floorheight; } else #endif @@ -1741,10 +1733,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); -#else - popentop = min(front->ceilingheight, back->ceilingheight); - popenbottom = max(front->floorheight, back->floorheight); -#endif + + popentopslope = min(worldtopslope, worldhighslope); + popenbottomslope = max(worldbottomslope, worldlowslope); } #ifdef ESLOPE @@ -1753,12 +1744,16 @@ 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; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polybottomslope = polybottom; + polytop = polybottom + midtexheight; + polytopslope = polytop; } else { polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; + polytopslope = polytop; + polybottom = polytop - midtexheight; + polybottomslope = polybottom; } } else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -1767,12 +1762,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #endif { polybottom = popenbottom + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; + polytop = polybottom + midtexheight; + polybottomslope = popenbottomslope + gr_sidedef->rowoffset; + polytopslope = polybottomslope + midtexheight; } 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,6 +1783,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { lowcut = polybottom; highcut = polytop; + lowcutslope = polybottomslope; + highcutslope = polytopslope; } #endif else @@ -1790,83 +1792,49 @@ 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)) { - // 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; + texturevpeg = midtexheight - h + polybottom; + texturevpegslope = midtexheight - hS + polybottomslope; + } + else + { + texturevpeg = polytop - h; + texturevpegslope = polytopslope - hS; + } grTex = HWR_GetTexture(gr_midtexture); - 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; - } + 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[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); - } + 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); #endif // set alpha for transparent walls (new boom and legacy linedef types) - // ooops ! this do not work at all because render order we should render it in backtofront order + FBITFIELD blendmode; switch (gr_linedef->special) { From 06a2508a9cbb2ccc1dd018d06507b1b710d346d9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:52:25 +0200 Subject: [PATCH 079/239] cleanup HWR_SplitWall e --- src/hardware/hw_main.c | 83 ++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..7fe8f9be8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -915,11 +915,10 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // +// 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 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; @@ -930,48 +929,55 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa float endpegt, endpegb, endpegmul; float endheight = 0.0f, endbheight = 0.0f; - 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); + float diff; #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; + diff = endtop - endbot; + endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - endpegmul = (endpegb - endpegt) / (endtop - endbot); + + if (fpclassify(diff) == FP_ZERO) + endpegmul = 0.0; + else + endpegmul = (endpegb - endpegt) / diff; #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)) { @@ -987,7 +993,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } } - solid = false; + boolean solid = false; if ((sector->lightlist[i].flags & FF_CUTSOLIDS) && !(cutflag & FF_EXTRA)) solid = true; @@ -1007,10 +1013,8 @@ 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], v1x, v1y)); + endheight = FixedToFloat(P_GetZAt(&list[i], v2x, v2y)); } else height = endheight = FIXED_TO_FLOAT(list[i].height); @@ -1018,10 +1022,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { 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, v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(list[i].caster, v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); @@ -1050,10 +1052,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], v1x, v1y)); + endbheight = FixedToFloat(P_GetZAt(&list[i+1], v2x, v2y)); } else bheight = endbheight = FIXED_TO_FLOAT(list[i+1].height); @@ -1074,10 +1074,11 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif +#ifdef ESLOPE // Found a break bot = min(max(bheight, realbot), top); endbot = min(max(endbheight, endrealbot), endtop); - +#endif Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1706,7 +1707,7 @@ 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; @@ -1733,9 +1734,12 @@ 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 @@ -1769,7 +1773,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else { polytop = popentop + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; polybottom = polytop - midtexheight; polytopslope = popentopslope + gr_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; @@ -1800,11 +1803,14 @@ 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; - +#ifdef ESLOPE if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#endif { texturevpeg = midtexheight - h + polybottom; texturevpegslope = midtexheight - hS + polybottomslope; @@ -1831,7 +1837,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[0].y = FIXED_TO_FLOAT(l); wallVerts[2].y = FIXED_TO_FLOAT(hS); wallVerts[1].y = FIXED_TO_FLOAT(lS); -#endif // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; From a929636a289f10b8fafdc2c53a5da47e3f04acdc Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 01:52:25 +0200 Subject: [PATCH 080/239] Revert "cleanup HWR_SplitWall" This reverts commit 06a2508a9cbb2ccc1dd018d06507b1b710d346d9. --- src/hardware/hw_main.c | 83 ++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7fe8f9be8..07f74f6a5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -915,10 +915,11 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend // // HWR_SplitWall // -// 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 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; @@ -929,55 +930,48 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa float endpegt, endpegb, endpegmul; float endheight = 0.0f, endbheight = 0.0f; - 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); - 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; #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; - - // 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 = (pegb - pegt) / (top - bot); + + if (fpclassify(pegmul) == FP_NAN) pegmul = 0.0; - else - pegmul = (pegb - pegt) / diff; #ifdef ESLOPE endrealtop = endtop = wallVerts[2].y; endrealbot = endbot = wallVerts[1].y; - diff = endtop - endbot; - endpegt = wallVerts[2].t; endpegb = wallVerts[1].t; - - if (fpclassify(diff) == FP_ZERO) - endpegmul = 0.0; - else - endpegmul = (endpegb - endpegt) / diff; + endpegmul = (endpegb - endpegt) / (endtop - endbot); #endif + if (fpclassify(endpegmul) == FP_NAN) + endpegmul = 0.0; - for (INT32 i = 0; i < sector->numlights; i++) + for (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)) { @@ -993,7 +987,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } } - boolean solid = false; + solid = false; if ((sector->lightlist[i].flags & FF_CUTSOLIDS) && !(cutflag & FF_EXTRA)) solid = true; @@ -1013,8 +1007,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #ifdef ESLOPE if (list[i].slope) { - height = FixedToFloat(P_GetZAt(&list[i], v1x, v1y)); - endheight = FixedToFloat(P_GetZAt(&list[i], v2x, v2y)); + 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); } else height = endheight = FIXED_TO_FLOAT(list[i].height); @@ -1022,8 +1018,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (*list[i].caster->b_slope) { - bheight = FixedToFloat(P_GetZAt(list[i].caster, v1x, v1y)); - endbheight = FixedToFloat(P_GetZAt(list[i].caster, v2x, v2y)); + 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); } else bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); @@ -1052,8 +1050,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa { if (list[i+1].slope) { - bheight = FixedToFloat(P_GetZAt(&list[i+1], v1x, v1y)); - endbheight = FixedToFloat(P_GetZAt(&list[i+1], v2x, v2y)); + 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); } else bheight = endbheight = FIXED_TO_FLOAT(list[i+1].height); @@ -1074,11 +1074,10 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa } #endif -#ifdef ESLOPE // Found a break bot = min(max(bheight, realbot), top); endbot = min(max(endbheight, endrealbot), endtop); -#endif + Surf->PolyColor.s.alpha = alpha; #ifdef ESLOPE @@ -1707,7 +1706,7 @@ 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; @@ -1734,12 +1733,9 @@ 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 @@ -1773,6 +1769,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom else { polytop = popentop + gr_sidedef->rowoffset; + polybottom = polytop - textureheight[gr_midtexture]*repeats; polybottom = polytop - midtexheight; polytopslope = popentopslope + gr_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; @@ -1803,14 +1800,11 @@ 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; -#ifdef ESLOPE + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) -#else - if (gr_linedef->flags & ML_DONTPEGBOTTOM) -#endif { texturevpeg = midtexheight - h + polybottom; texturevpegslope = midtexheight - hS + polybottomslope; @@ -1837,6 +1831,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[0].y = FIXED_TO_FLOAT(l); wallVerts[2].y = FIXED_TO_FLOAT(hS); wallVerts[1].y = FIXED_TO_FLOAT(lS); +#endif // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; From ad4d587a526eb62114931a3eca2b760148c4e456 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 02:58:20 +0200 Subject: [PATCH 081/239] screw you bleh, pegging midtextures to slopes now works correctly, but cutting them is broken again atleast this fixes the performance issues no idea tho why it screws up things so much --- src/hardware/hw_main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 07f74f6a5..40ec21cbe 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1074,9 +1074,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; From 2cba586d9c3bd244e6aa52507895491eb32a3316 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 13 Sep 2023 03:54:12 +0200 Subject: [PATCH 082/239] im good at coding absolute bruh thing, but it somehow works, fixes the midtextures, and doesent kill performance lmao --- src/hardware/hw_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 40ec21cbe..6a254a285 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1075,7 +1075,8 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa #endif #ifdef ESLOPE - if (endbheight >= endtop) + if (endbheight > endtop) + endbot = endtop; #endif if (bheight >= top) continue; @@ -1085,12 +1086,9 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa if (bot < realbot) bot = realbot; - + #ifdef ESLOPE - endbot = endbheight; - - if (endbot < endrealbot) - endbot = endrealbot; + endbot = min(max(endbheight, endrealbot), endtop); #endif Surf->PolyColor.s.alpha = alpha; From 538de7d2d2b439331949320a31a99bc8ca37b041 Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 13 Sep 2023 04:42:35 +0200 Subject: [PATCH 083/239] 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 From 3204095afbe603957a6dd005615e337c5cce2d81 Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 13 Sep 2023 16:09:58 +0200 Subject: [PATCH 084/239] revert "redo parts of the lighttable shader" die --- src/hardware/r_opengl/r_opengl.c | 64 +++++++++++++++----------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 62d2caa75..69341f12a 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -50,19 +50,13 @@ struct GLRGBAFloat }; typedef struct GLRGBAFloat GLRGBAFloat; -// lighttable list item -struct LTListItem -{ - UINT32 id; - struct LTListItem *next; -}; -typedef struct LTListItem LTListItem; +static const GLubyte white[4] = { 255, 255, 255, 255 }; // ========================================================================== // CONSTANTS // ========================================================================== -static const GLubyte white[4] = { 255, 255, 255, 255 }; + // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 @@ -81,15 +75,20 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; static GLuint tex_downloaded = 0; -static GLuint lt_downloaded = 0; // currently bound lighttable texture static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; static FTextureInfo *gr_cachetail = NULL; static FTextureInfo *gr_cachehead = NULL; -static LTListItem *LightTablesTail = NULL; -static LTListItem *LightTablesHead = NULL; +typedef struct LightTableCacheEntry_s +{ + GLuint id; + struct LightTableCacheEntry_s *next; +} LightTableCacheEntry_t; + +LightTableCacheEntry_t *ltcachehead = NULL; +LightTableCacheEntry_t *ltcachetail = NULL; RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() @@ -1432,47 +1431,45 @@ EXPORT void HWRAPI(ClearMipMapCache) (void) Flush(); } - EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable) { - LTListItem *item = malloc(sizeof(LTListItem)); - if (!LightTablesTail) + LightTableCacheEntry_t *cache_entry = malloc(sizeof(LightTableCacheEntry_t)); + if (!ltcachetail) { - LightTablesHead = LightTablesTail = item; + ltcachehead = ltcachetail = cache_entry; } else { - LightTablesTail->next = item; - LightTablesTail = item; + ltcachetail->next = cache_entry; + ltcachetail = cache_entry; } - item->next = NULL; - pglGenTextures(1, &item->id); - pglBindTexture(GL_TEXTURE_2D, item->id); + ltcachetail->next = NULL; + pglGenTextures(1, <cachetail->id); + if (!ltcachetail->id) + I_Error("hwr lighttable cache entry id is zero"); + 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); // restore previously bound texture - pglBindTexture(GL_TEXTURE_2D, tex_downloaded); + if (!gl_batching) + pglBindTexture(GL_TEXTURE_2D, tex_downloaded); - return item->id; + return ltcachetail->id; } // Delete light table textures, ids given before become invalid and must not be used. EXPORT void HWRAPI(ClearLightTableCache) (void) { - while (LightTablesHead) + while (ltcachehead) { - LTListItem *item = LightTablesHead; - pglDeleteTextures(1, (GLuint *)&item->id); - LightTablesHead = item->next; - free(item); + pglDeleteTextures(1, <cachehead->id); + LightTableCacheEntry_t *next = ltcachehead->next; + free(ltcachehead); + ltcachehead = next; } - - LightTablesTail = NULL; - - // we no longer have a bound light table (if we had one), we just deleted it! - lt_downloaded = 0; + ltcachetail = NULL; } // -----------------+ @@ -2662,12 +2659,11 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) + if (gl_use_palette_shader && gl_allowshaders) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); pglActiveTexture(GL_TEXTURE0); - lt_downloaded = pSurf->LightTableId; } } From 9044a46b31ba9ad407f9aaa92034a407ef4039d9 Mon Sep 17 00:00:00 2001 From: lug420 Date: Wed, 13 Sep 2023 21:32:35 +0200 Subject: [PATCH 085/239] fix fullscreen toggle and resolution changes --- src/v_video.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 77295c41b..86f193106 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -225,8 +225,12 @@ void V_SetPalette(INT32 palettenum) LoadMapPalette(); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) + if (rendermode != render_soft && rendermode != render_none) { + // reset our palette lookups n shit + gl_palette_initialized = false; + InitPalette(); HWR_SetPalette(&pLocalPalette[palettenum*256]); + } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) else #endif From 679a8387c90c060875eef96440697652cf0e0ecf Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 14 Sep 2023 00:09:33 +0300 Subject: [PATCH 086/239] Add logo (WIP) --- logo.png | Bin 0 -> 4303 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 logo.png diff --git a/logo.png b/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..2f84c3321152c32a77735b482f6c72c57d2c0d64 GIT binary patch literal 4303 zcmeHKeNfVO9R8uL*TcN6tSrN}U1nyi7he*?UM%Z2C6}nZh}9w(saTod3refYrB~jq z)H4-q^x`5V<3JOEiom6*y&Ezhtt=8mFcC#!U%0m2?sm67pudVcK6h~3eO{jD_dE|L zw!}oir+QC?APByBQ{?v$go;(qJb3Gxd5`sKSH%G3GqgLvk){_)JddYh3@A>9d zsCSUNyAgidH?HPBzH!sJv}uPs0?)Sw-mWUt>^wh+Z;V|qp#z@ixrz0=Y;r<(CS~_* zA#+B4>2SEUr*d|S4WTBBVW7pQ*T;5&^w-|J>2w=qRZ|UZo%ZdEMyko6$r4Jo(%sXu z5AGbd=H+IqUi!}!c&p>&)5N#LBm_8-C31~Bv}TPHr8?FE;W%ygHC0vFthsz<-6Vq)bektmR1HI7O=kT8#%EtupYLX_mD2U7mW+W}Fl zYCAZnAw}?b$pBY+5ZgRL%H0~CLu__}NB?jTFp6H5xvFUqBemhIlw0(YloY1WXBLhO zuvDYlN`%k*6}@sKGeSG~IX(H+^Gh5lm({bYpe!XVo05zt2LjGf`AU*kgL2RH#j2bj zkv~Hjg{y`^zP`?udo{E*Cji$St22_8B=kR!=QV6?rXYqpIxlM-$eucW)CYI%y2>IM zQ$qX@YcS^;1!0rL=m*%^TKw_=o016DN@`53D;&X{Bo`9)8(j1N)Jp#cPapUsRP&3} zeqqEFHNiadqPmZVc{))UX;7DLxo}SK@(966=fJx`lQubj@ zidf;V5)@~@B4ACYIApdKf9N53sM`-p*;_$wC5A3yDEsDy2?a<-ExuwScnYMcPttNqFHT^n=<%noz{3JfkVlQ$Lq~we5z@L(!Non?JO{=;gE`vD)P6p%`uaY z@{MBk`}NAWN} zM~mC{Ga+p`ZG1;U8#=FzYIV)y{jA0WYsT3Zq?$lKADodttfG*Z(BQt&QbPds$V7-v zr#o40!~!?qZIrAvXw74pNnsX?U>_^P^h$C$V+K9sH9)ynu8){sD8?&t*JmkQxf!dc znwptQ6R3Lpp?O!C)7gMN!RqB^lxrj?J%*Qp?7j1{Zu|Bk1zQaCk7wzz@wMto8Cj#J?Lq^#2 zU1O*$B7ZbVXxO5aLIH>7M!vT<80qlN z4`DJocUBfpCd64SeMq_aZ(*)AKruNdgGZ{ v2ZBUk8qOJ)7{bT)_vzEV_6yK&+{F#pEqxaiL6_<>!&{fCV^aF literal 0 HcmV?d00001 From 8ee4fc2fa118d5fa19762185d82b0ca29def8af5 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 14 Sep 2023 00:18:22 +0300 Subject: [PATCH 087/239] Oops used upscaled image >< --- logo.png | Bin 4303 -> 480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/logo.png b/logo.png index 2f84c3321152c32a77735b482f6c72c57d2c0d64..a950aa51fd9dd2e47e679af9f3b68b5d8242d3c3 100644 GIT binary patch literal 480 zcmV<60U!Q}P)TmbIjG+B=<>t`j) zW-{5YGAmj8o+TtLAP9mW2!il`nGJclEb=CWh(mRZ))D-oDtf(KwDHfcTQ6q9)Q@5@ zM%XWqa9to*xQ@#Rz&GRVWD~x6enjoG;f-AMUI; z8_ObZOu_;5#1DZ?05BSHnXooYC7y^iVGR1jQ=-*V*t)lI{=W6b=9=gQxZ*qQkw!?k zN~np>51)7dMgu9)^Y~26>A@#{$YB%8p*qgU2x%bJ%SGobn#01q#1k$PDi5IptLxpg zhGQ7A83Y?hl{gjFB}5e4EZLZYXt0000go;(qJb3Gxd5`sKSH%G3GqgLvk){_)JddYh3@A>9d zsCSUNyAgidH?HPBzH!sJv}uPs0?)Sw-mWUt>^wh+Z;V|qp#z@ixrz0=Y;r<(CS~_* zA#+B4>2SEUr*d|S4WTBBVW7pQ*T;5&^w-|J>2w=qRZ|UZo%ZdEMyko6$r4Jo(%sXu z5AGbd=H+IqUi!}!c&p>&)5N#LBm_8-C31~Bv}TPHr8?FE;W%ygHC0vFthsz<-6Vq)bektmR1HI7O=kT8#%EtupYLX_mD2U7mW+W}Fl zYCAZnAw}?b$pBY+5ZgRL%H0~CLu__}NB?jTFp6H5xvFUqBemhIlw0(YloY1WXBLhO zuvDYlN`%k*6}@sKGeSG~IX(H+^Gh5lm({bYpe!XVo05zt2LjGf`AU*kgL2RH#j2bj zkv~Hjg{y`^zP`?udo{E*Cji$St22_8B=kR!=QV6?rXYqpIxlM-$eucW)CYI%y2>IM zQ$qX@YcS^;1!0rL=m*%^TKw_=o016DN@`53D;&X{Bo`9)8(j1N)Jp#cPapUsRP&3} zeqqEFHNiadqPmZVc{))UX;7DLxo}SK@(966=fJx`lQubj@ zidf;V5)@~@B4ACYIApdKf9N53sM`-p*;_$wC5A3yDEsDy2?a<-ExuwScnYMcPttNqFHT^n=<%noz{3JfkVlQ$Lq~we5z@L(!Non?JO{=;gE`vD)P6p%`uaY z@{MBk`}NAWN} zM~mC{Ga+p`ZG1;U8#=FzYIV)y{jA0WYsT3Zq?$lKADodttfG*Z(BQt&QbPds$V7-v zr#o40!~!?qZIrAvXw74pNnsX?U>_^P^h$C$V+K9sH9)ynu8){sD8?&t*JmkQxf!dc znwptQ6R3Lpp?O!C)7gMN!RqB^lxrj?J%*Qp?7j1{Zu|Bk1zQaCk7wzz@wMto8Cj#J?Lq^#2 zU1O*$B7ZbVXxO5aLIH>7M!vT<80qlN z4`DJocUBfpCd64SeMq_aZ(*)AKruNdgGZ{ v2ZBUk8qOJ)7{bT)_vzEV_6yK&+{F#pEqxaiL6_<>!&{fCV^aF From 13fd825bcf57d1bce3e3af5b1a72365e4b45f8a9 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Thu, 14 Sep 2023 03:43:11 +0200 Subject: [PATCH 088/239] hackiest shit to make custom shaders not kill palette shader this is so super dumb its unreal but it works --- src/hardware/hw_main.c | 9 +++++---- src/hardware/hw_main.h | 2 +- src/hardware/r_opengl/r_opengl.c | 21 +++++++++++++++------ src/r_main.c | 1 + 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 25395bda7..c98a7f47a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -67,7 +67,7 @@ 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_useCustomShaders_ONChange(void); static void CV_grpaletteshader_OnChange(void); static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, @@ -120,7 +120,7 @@ static INT32 current_bsp_culling_distance = 0; consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, CV_screentextures_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}; // rip in peace sweet prince +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}; @@ -139,11 +139,11 @@ static void CV_screentextures_ONChange(void) HWD.pfnSetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_grscreentextures.value); } -/*static void CV_useCustomShaders_ONChange(void) +static void CV_useCustomShaders_ONChange(void) { if (rendermode == render_opengl) HWD.pfnInitCustomShaders(); -}*/ +} static void CV_grpaletteshader_OnChange(void) { @@ -152,6 +152,7 @@ static void CV_grpaletteshader_OnChange(void) HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; R_ClearColormaps(); + InitPalette(); } } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 37027da82..019b921c6 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -180,7 +180,7 @@ extern consvar_t cv_grfakecontrast; extern consvar_t cv_grfallbackplayermodel; extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; -//extern consvar_t cv_grusecustomshaders; +extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletteshader; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 69341f12a..0c4a619aa 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -35,7 +35,7 @@ #include "../hw_main.h" // Eeeeh not sure is this right way, but it works < sry :c -//extern consvar_t cv_grusecustomshaders; +extern consvar_t cv_grusecustomshaders; extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! @@ -987,13 +987,14 @@ EXPORT boolean HWRAPI(LoadShaders) (void) gl_shaderprogram_t *shader; const GLchar* vert_shader = vertex_shaders[i]; const GLchar* frag_shader = fragment_shaders[i]; - boolean custom = ((gl_customvertexshaders[i] || gl_customfragmentshaders[i]) && (i > 0)); - + boolean custom = cv_grusecustomshaders.value && ((gl_customvertexshaders[i] || gl_customfragmentshaders[i]) && (i > 0)); + // 18032019 - if (gl_customvertexshaders[i]) + if (cv_grusecustomshaders.value && gl_customvertexshaders[i]) vert_shader = gl_customvertexshaders[i]; - if (gl_customfragmentshaders[i]) + if (cv_grusecustomshaders.value && gl_customfragmentshaders[i]) frag_shader = gl_customfragmentshaders[i]; + if (i >= MAXSHADERS) break; @@ -1114,7 +1115,9 @@ EXPORT boolean HWRAPI(LoadShaders) (void) EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boolean fragment) { #ifdef GL_SHADERS - if (!pglUseProgram) return; + if (!pglUseProgram) + return; + if (number < 1 || number > MAXSHADERS) I_Error("LoadCustomShader(): cannot load shader %d (max %d)", number, MAXSHADERS); @@ -1136,8 +1139,14 @@ EXPORT void HWRAPI(LoadCustomShader) (int number, char *shader, size_t size, boo EXPORT void HWRAPI(InitCustomShaders) (void) { #ifdef GL_SHADERS + KillShaders(); LoadShaders(); + +if (gl_use_palette_shader) + { + InitPalette(); + } #endif } diff --git a/src/r_main.c b/src/r_main.c index f3b46668f..512a2b65c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1954,6 +1954,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grfakecontrast); CV_RegisterVar(&cv_grshearing); CV_RegisterVar(&cv_grshaders); + CV_RegisterVar(&cv_grusecustomshaders); CV_RegisterVar(&cv_grpaletteshader); #endif From fe74e69da6aea63316288941234f860c15b4cd3a Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 14 Sep 2023 18:42:35 +0200 Subject: [PATCH 089/239] dont need this --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 6e66795da..9a3a2a3dc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -992,7 +992,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa INT32 solid, i; lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->PolyColor.s.alpha; - FUINT lightnum = sector->lightlevel;//HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); + FUINT lightnum = HWR_CalcWallLight(sector->lightlevel, v1x, v1y, v2x, v2y); extracolormap_t *colormap = NULL; realtop = top = wallVerts[3].y; From 8c7f35fa29d0ca35f3494c57858f1dab398a3b1c Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 14 Sep 2023 19:17:46 +0200 Subject: [PATCH 090/239] absolute hell lighttable sorting was on even with the palette shader disabled, but, we dont need that shit for non palette renderer mode hope this shit doesent break anything ever pls --- src/hardware/r_opengl/r_opengl.c | 18 +++++++++++++++++- src/v_video.c | 7 +++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 0c4a619aa..49b9726dc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2169,8 +2169,11 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; + if (gl_use_palette_shader) + { diff = poly1->surf.LightTableId - poly2->surf.LightTableId; if (diff != 0) return diff; + } diff = poly1->polyFlags - poly2->polyFlags; if (diff != 0) return diff; @@ -2428,7 +2431,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeState = true; changePolyFlags = true; } - if (gl_allowshaders) + if ((gl_allowshaders) && (gl_use_palette_shader)) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2442,6 +2445,19 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeSurfaceInfo = true; } } + else if ((gl_allowshaders) && (!gl_use_palette_shader)) + { + if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || + currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || + currentSurfaceInfo.FadeColor.rgba != nextSurfaceInfo.FadeColor.rgba || + currentSurfaceInfo.LightInfo.light_level != nextSurfaceInfo.LightInfo.light_level || + currentSurfaceInfo.LightInfo.fade_start != nextSurfaceInfo.LightInfo.fade_start || + currentSurfaceInfo.LightInfo.fade_end != nextSurfaceInfo.LightInfo.fade_end) + { + changeState = true; + changeSurfaceInfo = true; + } + } else { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba) diff --git a/src/v_video.c b/src/v_video.c index 86f193106..3be8fcf80 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -226,9 +226,11 @@ void V_SetPalette(INT32 palettenum) #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { + + if (cv_grpaletteshader.value == 1){ // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(); + InitPalette();} HWR_SetPalette(&pLocalPalette[palettenum*256]); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) @@ -244,9 +246,10 @@ void V_SetPaletteLump(const char *pal) LoadPalette(pal); #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { + if (cv_grpaletteshader.value == 1){ // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(); + InitPalette();} HWR_SetPalette(pLocalPalette); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) From f70f7152ab338b1e020d14b5fc2f80537b17b798 Mon Sep 17 00:00:00 2001 From: lug420 Date: Thu, 14 Sep 2023 20:24:36 +0200 Subject: [PATCH 091/239] let the thing do its thing fixes switching of paletterenderer thing --- src/hardware/hw_main.c | 2 +- src/r_data.c | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9a3a2a3dc..e534e4e09 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -151,7 +151,7 @@ static void CV_grpaletteshader_OnChange(void) { HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; - R_ClearColormaps(); + //R_ClearColormaps(); InitPalette(); } } diff --git a/src/r_data.c b/src/r_data.c index a352a48a7..40be149b1 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1325,12 +1325,11 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) extra_colormaps[mapnum].fadeend = (UINT16)fadeend; extra_colormaps[mapnum].fog = fog; - if (rendermode == render_soft || cv_grpaletteshader.value == 1) - { + double r, g, b, cbrightness; int p; lighttable_t *colormap_p; - + // Initialise the map and delta arrays // map[i] stores an RGB color (as double) for index i, // which is then converted to SRB2's palette later @@ -1409,8 +1408,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) colormap_p2 += 256; } } - } - + return (INT32)mapnum; } From f00c9d8c23a2e605883843e6518478d74d8ee011 Mon Sep 17 00:00:00 2001 From: lug420 Date: Fri, 15 Sep 2023 20:54:25 +0200 Subject: [PATCH 092/239] dont do this in dedi unecessary if someone runs this thing in dedi mode --- src/r_data.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/r_data.c b/src/r_data.c index 40be149b1..45c1da6cc 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1324,8 +1324,9 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) extra_colormaps[mapnum].fadestart = (UINT16)fadestart; extra_colormaps[mapnum].fadeend = (UINT16)fadeend; extra_colormaps[mapnum].fog = fog; - + if (rendermode == render_soft || rendermode == render_opengl) + { double r, g, b, cbrightness; int p; lighttable_t *colormap_p; @@ -1408,6 +1409,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) colormap_p2 += 256; } } + } return (INT32)mapnum; } From e4a575cc5ee900ddf9729e297cfda9c895cce3e8 Mon Sep 17 00:00:00 2001 From: lug420 Date: Fri, 15 Sep 2023 20:54:57 +0200 Subject: [PATCH 093/239] (hopefully) make flashpals work with palette rendering --- src/st_stuff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 966a0c9c6..cc3b2cb3b 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -233,8 +233,8 @@ void ST_doPaletteStuff(void) palette = 0; #ifdef HWRENDER - if (rendermode == render_opengl) - palette = 0; // No flashpals here in OpenGL + if (rendermode == render_opengl && (cv_grpaletteshader.value == 0)) + palette = 0; // Don't set the palette to a flashpal in OpenGL's truecolor mode #endif palette = min(max(palette, 0), 13); @@ -2167,7 +2167,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) + if (rendermode == render_soft || (cv_grpaletteshader.value == 1)) #endif if (rendermode != render_none) ST_doPaletteStuff(); From c2f3486e6d9b9628a30d09ee4e4a9855f1a250f7 Mon Sep 17 00:00:00 2001 From: lug420 Date: Fri, 15 Sep 2023 20:54:57 +0200 Subject: [PATCH 094/239] Revert "(hopefully) make flashpals work with palette rendering" This reverts commit e4a575cc5ee900ddf9729e297cfda9c895cce3e8. --- src/st_stuff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index cc3b2cb3b..966a0c9c6 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -233,8 +233,8 @@ void ST_doPaletteStuff(void) palette = 0; #ifdef HWRENDER - if (rendermode == render_opengl && (cv_grpaletteshader.value == 0)) - palette = 0; // Don't set the palette to a flashpal in OpenGL's truecolor mode + if (rendermode == render_opengl) + palette = 0; // No flashpals here in OpenGL #endif palette = min(max(palette, 0), 13); @@ -2167,7 +2167,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 || (cv_grpaletteshader.value == 1)) + if (rendermode == render_soft) #endif if (rendermode != render_none) ST_doPaletteStuff(); From 426cbee7524fc6a7a64359b16541db2014ec6c4f Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sat, 16 Sep 2023 13:45:39 +0800 Subject: [PATCH 095/239] Make flashpals work I hate this --- src/hardware/hw_main.c | 10 ++++++---- src/hardware/r_opengl/r_opengl.c | 32 +++++++++++++++++++++++--------- src/hardware/r_opengl/r_opengl.h | 2 +- src/st_stuff.c | 20 +++++++++----------- src/v_video.c | 15 ++++++++------- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e534e4e09..68241585a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -152,7 +152,7 @@ static void CV_grpaletteshader_OnChange(void) HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; //R_ClearColormaps(); - InitPalette(); + InitPalette(0); } } @@ -6156,8 +6156,6 @@ void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, pSurf->PolyColor.s.alpha = alpha; // put the alpha back after lighting - HWD.pfnSetShader(gr_use_palette_shader ? 10 : 2); // wall shader - if (blend & PF_Environment) blendmode |= PF_Occlude; // PF_Occlude must be used for solid objects @@ -6169,6 +6167,8 @@ 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 HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode, false); #ifdef WALLSPLATS @@ -6200,7 +6200,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (player->flashcount) + if (player->flashcount && !cv_grpaletteshader.value) { FOutVector v[4]; FSurfaceInfo Surf; @@ -6329,6 +6329,8 @@ void HWR_MakeScreenFinalTexture(void) void HWR_DrawScreenFinalTexture(int width, int height) { + if (gr_use_palette_shader) + HWD.pfnSetShader(11); //post processing HWD.pfnDrawScreenFinalTexture(width, height); } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 49b9726dc..e75ac1e6d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -751,6 +751,11 @@ static gl_shaderprogram_t gl_shaderprograms[MAXSHADERPROGRAMS]; GLSL_SOFTWARE_PAL_MAIN \ "\0" +#define GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_POSTPROCESS \ + GLSL_SOFTWARE_PAL_UNIFORMS \ + GLSL_SOFTWARE_PAL_MAIN \ + "\0" + // // Water surface shader // @@ -869,6 +874,8 @@ static const char *fragment_shaders[] = { GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_WALLS, + GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_POSTPROCESS, + NULL, }; @@ -1093,16 +1100,21 @@ EXPORT boolean HWRAPI(LoadShaders) (void) if (uniform != -1) \ function (uniform, a); +#define UNIFORM_2(uniform, a, b, function) \ + if (uniform != -1) \ + function (uniform, a, b); + pglUseProgram(shader->program); // texture unit numbers for the samplers used for palette rendering - UNIFORM_1(shader->uniforms[gluniform_palette], 2, pglUniform1i); + UNIFORM_2(shader->uniforms[gluniform_palette], 768, gl_palette, pglUniform1iv); UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); pglUseProgram(0); #undef UNIFORM_1 +#undef UNIFORM_2 } #endif @@ -1143,9 +1155,9 @@ EXPORT void HWRAPI(InitCustomShaders) (void) KillShaders(); LoadShaders(); -if (gl_use_palette_shader) + if (gl_use_palette_shader) { - InitPalette(); + InitPalette(0); } #endif } @@ -1193,20 +1205,22 @@ GLuint palette_tex_num; // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -void InitPalette(void) +void InitPalette(int flashnum) { int i, r, g, b; // init the palette - for (i = 0; i < 256; i++) + int flashoffset = flashnum*256; + for (i = 0+flashoffset; i < 256+flashoffset; i++) { + int fi = i-flashoffset; // crush to 16-bit rgb565, like software currently does float fred = (float)(pLocalPalette[i].s.red >> 3); float fgreen = (float)(pLocalPalette[i].s.green >> 2); float fblue = (float)(pLocalPalette[i].s.blue >> 3); // restore to rgb888 - gl_palette[i*3] = (GLint)(fred / 31.0f * 255.0f); - gl_palette[i*3+1] = (GLint)(fgreen / 63.0f * 255.0f); - gl_palette[i*3+2] = (GLint)(fblue / 31.0f * 255.0f); + gl_palette[fi*3] = (GLint)(fred / 31.0f * 255.0f); + gl_palette[fi*3+1] = (GLint)(fgreen / 63.0f * 255.0f); + gl_palette[fi*3+2] = (GLint)(fblue / 31.0f * 255.0f); } // init the palette conversion lookup texture @@ -1593,7 +1607,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too if (!gl_palette_initialized) - InitPalette(); // just gonna put this here for now + InitPalette(0); // just gonna put this here for now } diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index f4a3f3849..e8ef58a2c 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -135,6 +135,6 @@ typedef enum // in order for custom playpals n shit to work properly extern boolean gl_palette_initialized; -void InitPalette(void); +void InitPalette(int flashnum); #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index 966a0c9c6..2baa39c1a 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -232,18 +232,22 @@ void ST_doPaletteStuff(void) else palette = 0; + palette = min(max(palette, 0), 13); + #ifdef HWRENDER - if (rendermode == render_opengl) + if (rendermode == render_opengl && !cv_grpaletteshader.value) palette = 0; // No flashpals here in OpenGL #endif - palette = min(max(palette, 0), 13); - if (palette != st_palette) { st_palette = palette; - if (rendermode == render_soft) +#ifdef HWRENDER + if (rendermode != render_none && cv_grpaletteshader.value) +#else + if (rendermode != render_none) +#endif { //V_SetPaletteLump(GetPalette()); // Reset the palette -- is this needed? if (!splitscreen) @@ -2163,13 +2167,7 @@ void ST_Drawer(void) st_palette = -1; // Do red-/gold-shifts from damage/items -#ifdef HWRENDER - //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) -#endif - if (rendermode != render_none) ST_doPaletteStuff(); + if (rendermode != render_none) ST_doPaletteStuff(); if (st_overlay) { diff --git a/src/v_video.c b/src/v_video.c index 3be8fcf80..c6822e9fa 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -226,11 +226,11 @@ void V_SetPalette(INT32 palettenum) #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { - if (cv_grpaletteshader.value == 1){ - // reset our palette lookups n shit - gl_palette_initialized = false; - InitPalette();} + // reset our palette lookups n shit + gl_palette_initialized = false; + InitPalette(palettenum); + } HWR_SetPalette(&pLocalPalette[palettenum*256]); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) @@ -247,9 +247,10 @@ void V_SetPaletteLump(const char *pal) #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { if (cv_grpaletteshader.value == 1){ - // reset our palette lookups n shit - gl_palette_initialized = false; - InitPalette();} + // reset our palette lookups n shit + gl_palette_initialized = false; + InitPalette(0); + } HWR_SetPalette(pLocalPalette); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) From 69237d6a3a8a1b6948ebb2711af17b17df82a574 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sun, 17 Sep 2023 07:23:09 +0800 Subject: [PATCH 096/239] Fix stuttering and gamma --- src/hardware/hw_cache.c | 1 - src/hardware/hw_main.c | 3 +- src/hardware/r_opengl/r_opengl.c | 51 ++++++++++++++++++++++---------- src/hardware/r_opengl/r_opengl.h | 2 +- src/v_video.c | 17 +++++++---- 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index c27e17a16..bfd5fa26d 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -576,7 +576,6 @@ void HWR_SetPalette(RGBA_t *palette) Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); } } - // -------------------------------------------------------------------------- // Make sure texture is downloaded and set it as the source // -------------------------------------------------------------------------- diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 68241585a..d07c3d4c0 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -151,8 +151,7 @@ static void CV_grpaletteshader_OnChange(void) { HWD.pfnSetSpecialState(HWD_SET_PALETTE_SHADER_ENABLED, cv_grpaletteshader.value); gr_use_palette_shader = cv_grpaletteshader.value; - //R_ClearColormaps(); - InitPalette(0); + V_SetPalette(0); } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e75ac1e6d..67eec5058 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1157,7 +1157,7 @@ EXPORT void HWRAPI(InitCustomShaders) (void) if (gl_use_palette_shader) { - InitPalette(0); + InitPalette(0, false); } #endif } @@ -1205,24 +1205,42 @@ GLuint palette_tex_num; // the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! // the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! -void InitPalette(int flashnum) +void InitPalette(int flashnum, boolean skiplut) { int i, r, g, b; + + //Hudler: 16/10/99: added for OpenGL gamma correction + RGBA_t gamma_correction = {0x7F7F7F7F}; + + //Hurdler 16/10/99: added for OpenGL gamma correction + gamma_correction.s.red = (UINT8)cv_grgammared.value; + gamma_correction.s.green = (UINT8)cv_grgammagreen.value; + gamma_correction.s.blue = (UINT8)cv_grgammablue.value; + // init the palette int flashoffset = flashnum*256; for (i = 0+flashoffset; i < 256+flashoffset; i++) { int fi = i-flashoffset; + + // gamma correction + int pr, pg, pb; + pr = (UINT8)MIN((pLocalPalette[i].s.red*gamma_correction.s.red)/127, 255); + pg = (UINT8)MIN((pLocalPalette[i].s.green*gamma_correction.s.green)/127, 255); + pb = (UINT8)MIN((pLocalPalette[i].s.blue*gamma_correction.s.blue)/127, 255); + // crush to 16-bit rgb565, like software currently does - float fred = (float)(pLocalPalette[i].s.red >> 3); - float fgreen = (float)(pLocalPalette[i].s.green >> 2); - float fblue = (float)(pLocalPalette[i].s.blue >> 3); + float fred = (float)(pr >> 3); + float fgreen = (float)(pg >> 2); + float fblue = (float)(pb >> 3); // restore to rgb888 gl_palette[fi*3] = (GLint)(fred / 31.0f * 255.0f); gl_palette[fi*3+1] = (GLint)(fgreen / 63.0f * 255.0f); gl_palette[fi*3+2] = (GLint)(fblue / 31.0f * 255.0f); } + if (!skiplut) + { // init the palette conversion lookup texture GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); @@ -1239,17 +1257,18 @@ void InitPalette(int flashnum) } } } -#undef STEP_SIZE - - pglGenTextures(1, &palette_tex_num); - 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); - free(pal_lookup_tex); + pglGenTextures(1, &palette_tex_num); + 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); + free(pal_lookup_tex); + } +#undef STEP_SIZE + pglUseProgram(gl_shaderprograms[8].program); pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); @@ -1607,7 +1626,7 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too if (!gl_palette_initialized) - InitPalette(0); // just gonna put this here for now + InitPalette(0, false); // just gonna put this here for now } diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index e8ef58a2c..8bce7d15b 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -135,6 +135,6 @@ typedef enum // in order for custom playpals n shit to work properly extern boolean gl_palette_initialized; -void InitPalette(int flashnum); +void InitPalette(int flashnum, boolean skiplut); #endif diff --git a/src/v_video.c b/src/v_video.c index c6822e9fa..dbe26a001 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -226,12 +226,15 @@ void V_SetPalette(INT32 palettenum) #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { - if (cv_grpaletteshader.value == 1){ + // in palette rendering mode, we already manage our palette ourselves + if (cv_grpaletteshader.value == 1) + { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(palettenum); + InitPalette(palettenum, true); } - HWR_SetPalette(&pLocalPalette[palettenum*256]); + else + HWR_SetPalette(pLocalPalette); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) else @@ -246,12 +249,14 @@ void V_SetPaletteLump(const char *pal) LoadPalette(pal); #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { - if (cv_grpaletteshader.value == 1){ + if (cv_grpaletteshader.value == 1) + { // reset our palette lookups n shit gl_palette_initialized = false; - InitPalette(0); + InitPalette(0, false); } - HWR_SetPalette(pLocalPalette); + else + HWR_SetPalette(pLocalPalette); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) else From ddcd6b0d314e66e15200d64a50ea982ffa742e8e Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sat, 2 Sep 2023 13:06:12 +0800 Subject: [PATCH 097/239] Redo `localskin` command --- src/d_netcmd.c | 141 +++++++++++++++++++++++++++++++++---------------- src/m_menu.c | 2 +- 2 files changed, 97 insertions(+), 46 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 025360b39..f30cc4f75 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4676,56 +4676,107 @@ Command_Addskins (void) // args n stuff #include "args.h" -static void Command_GLocalSkin (void) { - ArgParser* parser = ap_new(); - ap_set_helptext(parser, "Usage: localskin [options] \n\nOptions: \n\ - -d, --display: Use the first displaying player instead of yourself.\n\ - Has no effect on replays. Omits any player related\n\ - options.\n\ - -a, --all: Set a localskin to all players. Omits any player related\n\ - options.\n\ - -p, --player: Set a localskin to a specific player name.\n\ - If omitted, defaults to the client player, unless -d \n\ - or --display is added."); - ap_set_version(parser, ""); - ap_str_opt(parser, "player p", player_names[consoleplayer]); - ap_flag(parser, "display d"); - ap_flag(parser, "all a"); +static void Command_GLocalSkin (void) +{ + size_t first_option; + size_t option_display; + size_t option_all; + size_t option_player; + + option_player = COM_CheckPartialParm("-p"); + option_display = COM_CheckPartialParm("-d"); + option_all = COM_CheckPartialParm("-a"); - ap_parse(parser, COM_Argc(), COM_ArgvList()); + char* fuck; // local skin name - boolean disply; - boolean allp; + if (!( first_option = COM_FirstOption() )) + first_option = COM_Argc(); - if (ap_found(parser, "display")) disply = true; else disply = false; - if (ap_found(parser, "all")) allp = true; else allp = false; - - INT32 i, idx; - i = 0; - idx = 0; - - for (idx = 0; idx < ap_count_args(parser); idx++) { - if (disply) { - SetLocalPlayerSkin(displayplayers[0], ap_arg(parser, idx), NULL); - return; - } else { - for (i = 0; i < MAXPLAYERS; i++) { - if (allp) { - SetLocalPlayerSkin(i, ap_arg(parser, idx), NULL); - } else { - if (fasticmp(player_names[i], ap_str_value(parser, "player"))) { - if (fasticmp(player_names[i], cv_playername.string)) - SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskin); - else - SetLocalPlayerSkin(i, ap_arg(parser, idx), NULL); - break; - } - } - } - } + if (first_option < 2) + { + /* holy fucking shit */ + CONS_Printf("localskin [-player ] [-display ] [-all]:\n"); + CONS_Printf(M_GetText("Set a localskin via its internal name (usually printed on the console).\n\n\ +* Using \"-player\" will set a localskin to a specified player.\n\ + Defaults to yourself.\n\ +* Using \"-display\" will set a localskin to the displayed player.\n\ + Defaults to 0, which is the first player displayed.\n\ + Can go up to 3 for splitscreen.\n\ +* Using \"-all\" will set a localskin to ALL players.\n\ +* \"localskin none\" removes the localskin, just like how\n\ + \"forceskin none\" does.\n")); + return; } - ap_free(parser); + fuck = ConcatCommandArgv(1, first_option); + + char* player_name = player_names[consoleplayer]; + char* display_num = "0"; + size_t dnum = 0; + + if (option_display) // -display + { + // handle default: 0 + if (COM_Argv(option_display + 1)[0] == "" || COM_Argv(option_display + 1)[0] != "-") + display_num = COM_Argv(option_display + 1); + + if (isdigit(display_num[0]) || display_num == "0") + { + dnum = atoi(display_num); + if (dnum > 3 || dnum < 0) // nuh uh + dnum = 0; + SetLocalPlayerSkin(displayplayers[dnum], fuck, NULL); + + CONS_Printf("Successfully applied localskin to displayed player.\n"); + return; + } + + CONS_Printf("Could not apply localskin.\n"); + + return; + } + else if (option_all) // -all + { + int i; + + for (i = 0; i < MAXPLAYERS; ++i) + { + if (!playeringame[i]) + continue; + SetLocalPlayerSkin(i, fuck, NULL); + } + CONS_Printf("Successfully applied localskin to all players.\n"); + + return; + } + else // -player or no other arguments + { + if (option_player) + { + int i; + player_name = COM_Argv(option_player + 1); + + for (i = 0; i < MAXPLAYERS; ++i) + { + if (fasticmp(player_names[i], player_name)) + SetLocalPlayerSkin(i, fuck, NULL); + } + CONS_Printf("Successfully applied localskin to specified player.\n"); + + return; + } + else + { + SetLocalPlayerSkin(consoleplayer, fuck, &cv_localskin); + CONS_Printf("Successfully applied localskin.\n"); + + return; + } + + CONS_Printf("Could not apply localskin.\n"); + + return; + } } #ifdef DELFILE diff --git a/src/m_menu.c b/src/m_menu.c index ceba6185b..c99bf003d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11999,7 +11999,7 @@ static void M_LocalSkinChange(INT32 choice) COM_BufAddText(va("localskin -a %s", cv_fakelocalskin.string)); break; case 4: - COM_BufAddText(va("localskin -d %s", cv_fakelocalskin.string)); + COM_BufAddText(va("localskin -d 0 %s", cv_fakelocalskin.string)); break; case 5: COM_BufAddText(va("localskin %s", cv_fakelocalskin.string)); From 1ecdd3dae69e18af5e9008e0af154d69ae84c401 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Thu, 14 Sep 2023 08:54:33 +0800 Subject: [PATCH 098/239] fix compilation error --- src/sdl/i_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index d08b267f0..e236d1fca 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1297,7 +1297,7 @@ void I_GetEvent(void) break; case SDL_DROPFILE: dropped_filedir = evt.drop.file; - P_AddWadFile(dropped_filedir); + P_AddWadFile(dropped_filedir, false); SDL_free(dropped_filedir); // Free dropped_filedir memory break; case SDL_QUIT: From ab93865255bd125842bda45c6f5a42f586721a84 Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 18 Sep 2023 15:39:13 +0200 Subject: [PATCH 099/239] make flashpals toggable could be a bit distracting for some --- src/hardware/hw_main.c | 5 ++++- src/hardware/hw_main.h | 1 + src/m_menu.c | 5 +++-- src/r_main.c | 1 + src/st_stuff.c | 10 ++++++++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d07c3d4c0..f5dec1d58 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -124,6 +124,8 @@ consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE 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_grflashpal = {"gr_flashpal", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static void CV_filtermode_ONChange(void) { HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_grfiltermode.value); @@ -6093,6 +6095,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_portalonly); CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletteshader); + CV_RegisterVar(&cv_grflashpal); } // -------------------------------------------------------------------------- @@ -6199,7 +6202,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (player->flashcount && !cv_grpaletteshader.value) + if (player->flashcount && !cv_grpaletteshader.value || player->flashcount && cv_grpaletteshader.value && !cv_grflashpal.value) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 019b921c6..5098c754e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -182,6 +182,7 @@ extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletteshader; +extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; diff --git a/src/m_menu.c b/src/m_menu.c index acaf7cb99..86759d8dc 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1706,8 +1706,9 @@ static menuitem_t OP_SaturnMenu[] = {IT_STRING | IT_CVAR, NULL, "Show Minimap Names", &cv_showminimapnames, 80}, {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 90}, {IT_STRING | IT_CVAR, NULL, "Less Midnight Channel Flicker", &cv_lessflicker, 110}, - {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 130}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 145}, + {IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 120}, + {IT_SUBMENU|IT_STRING, NULL, "Player distortion...", &OP_PlayerDistortDef, 140}, + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 155}, {IT_SUBMENU|IT_STRING, NULL, "Saturn Credits", &OP_SaturnCreditsDef, 170}, // uwu }; diff --git a/src/r_main.c b/src/r_main.c index 512a2b65c..34efa13b8 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1956,6 +1956,7 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_grshaders); CV_RegisterVar(&cv_grusecustomshaders); CV_RegisterVar(&cv_grpaletteshader); + CV_RegisterVar(&cv_grflashpal); #endif #ifdef HWRENDER diff --git a/src/st_stuff.c b/src/st_stuff.c index 2baa39c1a..10be523aa 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -235,7 +235,7 @@ void ST_doPaletteStuff(void) palette = min(max(palette, 0), 13); #ifdef HWRENDER - if (rendermode == render_opengl && !cv_grpaletteshader.value) + if (rendermode == render_opengl && !cv_grpaletteshader.value || rendermode == render_opengl && cv_grpaletteshader.value && !cv_grflashpal.value) palette = 0; // No flashpals here in OpenGL #endif @@ -244,7 +244,7 @@ void ST_doPaletteStuff(void) st_palette = palette; #ifdef HWRENDER - if (rendermode != render_none && cv_grpaletteshader.value) + if (rendermode != render_none && cv_grpaletteshader.value && cv_grflashpal.value) #else if (rendermode != render_none) #endif @@ -2167,6 +2167,12 @@ void ST_Drawer(void) st_palette = -1; // Do red-/gold-shifts from damage/items +#ifdef HWRENDER + //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) +#endif if (rendermode != render_none) ST_doPaletteStuff(); if (st_overlay) From ea10c9ac13a82e42556f43c9308dcf3a531a6d18 Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 18 Sep 2023 16:00:19 +0200 Subject: [PATCH 100/239] v3 --- src/doomdef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 5a914f218..84fc1641f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -149,8 +149,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v2.1 " -#define VERSIONSTRINGW L"Saturn v2.1" +#define VERSIONSTRING "Saturn v3 " +#define VERSIONSTRINGW L"Saturn v3" // 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! From e6a1e58405dc4aa74d03cea148d0ca346cf6255f Mon Sep 17 00:00:00 2001 From: lug420 Date: Mon, 18 Sep 2023 17:14:59 +0200 Subject: [PATCH 101/239] uaaagheue --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 27840eba6..923ec70ba 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1142,7 +1142,7 @@ static menuitem_t OP_MainMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Saturn Options...", &OP_SaturnDef, 140}, {IT_SUBMENU|IT_STRING, NULL, "Bird", &OP_BirdDef, 150}, - {IT_CALL|IT_STRING, NULL, "Fork Options...", M_LocalSkinMenu, 160}, + {IT_CALL|IT_STRING, NULL, "Local Skin Options...", M_LocalSkinMenu, 160}, }; static menuitem_t OP_ControlsMenu[] = From d86eec52ae6d272b6cf9ac3d8f8a733faf4cc919 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 26 Sep 2023 21:18:41 +0200 Subject: [PATCH 102/239] precip doesent need that stuff interpolated --- src/r_fps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index ac315c6a7..9c08f2af9 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -334,10 +334,10 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); out->scale = FRACUNIT; - out->spritexscale = R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - out->spriteyscale = R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); - out->spritexoffset = R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - out->spriteyoffset = R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); + out->spritexscale = mobj->spritexscale; + out->spriteyscale = mobj->spriteyscale; + out->spritexoffset = mobj->spritexoffset; + out->spriteyoffset = mobj->spriteyoffset; out->subsector = R_PointInSubsector(out->x, out->y); From 09cb8779e42a2e0fd5828e9e257d65c327f6250f Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sun, 24 Sep 2023 09:09:27 +0800 Subject: [PATCH 103/239] Fix an issue where flats dont look correctly without retoggling `gr_paletteshader` --- src/v_video.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index dbe26a001..db7f2747c 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -255,8 +255,7 @@ void V_SetPaletteLump(const char *pal) gl_palette_initialized = false; InitPalette(0, false); } - else - HWR_SetPalette(pLocalPalette); + HWR_SetPalette(pLocalPalette); } #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) else From 04edcd03f2a17b54bf3a1a8ba24c005927ce9d40 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 26 Sep 2023 22:42:39 +0200 Subject: [PATCH 104/239] refactor weather switching --- src/p_mobj.c | 15 ++------- src/p_spec.c | 93 ++++++++++------------------------------------------ 2 files changed, 20 insertions(+), 88 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 204532ea2..d5f281edd 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10359,7 +10359,7 @@ void P_SpawnPrecipitation(void) subsector_t *precipsector = NULL; precipmobj_t *rainmo = NULL; - if (dedicated || /*!cv_precipdensity*/!cv_drawdist_precip.value || curWeather == PRECIP_NONE) // SRB2Kart + if (dedicated || !(cv_drawdist_precip.value) || curWeather == PRECIP_NONE || curWeather == PRECIP_STORM_NORAIN) // SRB2Kart return; // Use the blockmap to narrow down our placing patterns @@ -10402,22 +10402,13 @@ 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)<flags = mobjinfo[MT_RAIN].flags; st = &states[mobjinfo[MT_RAIN].spawnstate]; @@ -2096,7 +2057,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->precipflags |= PCF_RAIN; //think->function.acp1 = (actionf_p1)P_RainThinker; } - else if (swap == PRECIP_SNOW) // Rain To Snow + else if (weathernum == PRECIP_SNOW) // Rain To Snow { INT32 z; @@ -2121,7 +2082,7 @@ void P_SwitchWeather(INT32 weathernum) //think->function.acp1 = (actionf_p1)P_SnowThinker; } - else if (swap == PRECIP_BLANK || swap == PRECIP_STORM_NORAIN) // Remove precip, but keep it around for reuse. + else // Remove precip, but keep it around for reuse. { //think->function.acp1 = (actionf_p1)P_NullPrecipThinker; @@ -2135,48 +2096,31 @@ void P_SwitchWeather(INT32 weathernum) case PRECIP_SNOW: // snow curWeather = PRECIP_SNOW; - if (!swap) + if (purge) 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 (!dontspawn && !swap) + if (purge) 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 (!dontspawn && !swap) + if (purge) P_SpawnPrecipitation(); break; } case PRECIP_STORM_NOSTRIKES: // storm w/o lightning { - boolean dontspawn = false; - - if (curWeather == PRECIP_RAIN || curWeather == PRECIP_STORM || curWeather == PRECIP_STORM_NOSTRIKES) - dontspawn = true; - - curWeather = PRECIP_STORM_NOSTRIKES; - - if (!dontspawn && !swap) + if (purge) P_SpawnPrecipitation(); break; @@ -2184,14 +2128,11 @@ 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: + case PRECIP_BLANK: //preloaded curWeather = PRECIP_BLANK; - if (!swap) + if (purge) P_SpawnPrecipitation(); break; From 50526d2728904b2e57391650b4df2396dc69b6f8 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 26 Sep 2023 22:44:52 +0200 Subject: [PATCH 105/239] remove parts of precip interpolation it looks exactly the same, but improves performance on maps with weather a bit --- src/r_fps.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 9c08f2af9..8ae69e435 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -330,18 +330,18 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst return; } - out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); - out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); - out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); + out->x = mobj->x; + out->y = mobj->y; + out->z = mobj->z; out->scale = FRACUNIT; out->spritexscale = mobj->spritexscale; out->spriteyscale = mobj->spriteyscale; out->spritexoffset = mobj->spritexoffset; out->spriteyoffset = mobj->spriteyoffset; - out->subsector = R_PointInSubsector(out->x, out->y); + out->subsector = mobj->subsector; - out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac); + out->angle = mobj->angle; } static void AddInterpolator(levelinterpolator_t* interpolator) From c4312e3f2f3a9dc5d0a179b738ec4a6d7c54774e Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 26 Sep 2023 22:54:34 +0200 Subject: [PATCH 106/239] smooooth console uncap console opening/closing animation --- src/console.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/console.c b/src/console.c index 99d032b7f..3c2230935 100644 --- a/src/console.c +++ b/src/console.c @@ -23,6 +23,7 @@ #include "g_input.h" #include "hu_stuff.h" #include "keys.h" +#include "r_main.h" #include "r_defs.h" #include "sounds.h" #include "st_stuff.h" @@ -602,32 +603,38 @@ static void CON_ChangeHeight(void) // static void CON_MoveConsole(void) { - fixed_t conspeed; + static fixed_t fracmovement = 0; Lock_state(); - conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT); - // instant if (!cons_speed.value) { con_curlines = con_destlines; + Unlock_state(); return; } - // up/down move to dest - if (con_curlines < con_destlines) + // Not instant - Increment fracmovement fractionally + fracmovement += FixedMul(cons_speed.value*vid.fdupy, renderdeltatics); + + if (con_curlines < con_destlines) // Move the console downwards { - con_curlines += FixedInt(conspeed); - if (con_curlines > con_destlines) - con_curlines = con_destlines; + con_curlines += FixedInt(fracmovement); // Move by fracmovement's integer value + if (con_curlines > con_destlines) // If we surpassed the destination... + con_curlines = con_destlines; // ...clamp to it! } - else if (con_curlines > con_destlines) + else // Move the console upwards { - con_curlines -= FixedInt(conspeed); + con_curlines -= FixedInt(fracmovement); if (con_curlines < con_destlines) con_curlines = con_destlines; + + if (con_destlines == 0) // If the console is being closed, not just moved up... + con_tick = 0; // ...don't show the blinking cursor } + + fracmovement %= FRACUNIT; // Reset fracmovement's integer value, but keep the fraction Unlock_state(); } @@ -724,10 +731,6 @@ void CON_Ticker(void) CON_ChangeHeight(); } - // console movement - if (con_destlines != con_curlines) - CON_MoveConsole(); - // clip the view, so that the part under the console is not drawn con_clipviewtop = -1; if (cons_backpic.value) // clip only when using an opaque background @@ -1774,6 +1777,10 @@ void CON_Drawer(void) if (con_curlines <= 0) CON_ClearHUD(); } + + // console movement + if (con_curlines != con_destlines) + CON_MoveConsole(); if (con_curlines > 0) CON_DrawConsole(); From c444d4180ecc8fe6a2303140e506b8e578d6cced Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 27 Sep 2023 00:46:48 +0200 Subject: [PATCH 107/239] completely remove precip interpolation DIE! --- src/hardware/hw_main.c | 18 +++++++++--------- src/p_mobj.c | 8 ++++---- src/r_fps.c | 8 ++++---- src/r_things.c | 20 ++++++++++---------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index feebc7bb7..a8c7c9301 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3911,7 +3911,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts { if (spr->precip) { - R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, rendertimefrac, &interp); + //R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, rendertimefrac, &interp); } else { @@ -3922,7 +3922,7 @@ static void HWR_RotateSpritePolyToAim(gr_vissprite_t *spr, FOutVector *wallVerts { if (spr->precip) { - R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, FRACUNIT, &interp); + //R_InterpolatePrecipMobjState((precipmobj_t *)spr->mobj, FRACUNIT, &interp); } else { @@ -5408,21 +5408,21 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) return; // uncapped/interpolation - interpmobjstate_t interp = {0}; + //interpmobjstate_t interp = {0}; // do interpolation - if (R_UsingFrameInterpolation() && !paused) + /*if (R_UsingFrameInterpolation() && !paused) { R_InterpolatePrecipMobjState(thing, rendertimefrac, &interp); } else { R_InterpolatePrecipMobjState(thing, FRACUNIT, &interp); - } + }*/ // transform the origin point - tr_x = FIXED_TO_FLOAT(interp.x) - gr_viewx; - tr_y = FIXED_TO_FLOAT(interp.y) - gr_viewy; + tr_x = FIXED_TO_FLOAT(thing->x) - gr_viewx; + tr_y = FIXED_TO_FLOAT(thing->y) - gr_viewy; // rotation around vertical axis tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); @@ -5431,8 +5431,8 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) if (tz < ZCLIP_PLANE) return; - tr_x = FIXED_TO_FLOAT(interp.x); - tr_y = FIXED_TO_FLOAT(interp.y); + tr_x = FIXED_TO_FLOAT(thing->x); + tr_y = FIXED_TO_FLOAT(thing->y); // decide which patch to use for sprite relative to player if ((unsigned)thing->sprite >= numsprites) diff --git a/src/p_mobj.c b/src/p_mobj.c index d5f281edd..b1b9dde6b 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3792,7 +3792,7 @@ void P_NullPrecipThinker(precipmobj_t *mobj) { //(void)mobj; mobj->precipflags &= ~PCF_THUNK; - R_ResetPrecipitationMobjInterpolationState(mobj); + //R_ResetPrecipitationMobjInterpolationState(mobj); } void P_SnowThinker(precipmobj_t *mobj) @@ -3803,7 +3803,7 @@ void P_SnowThinker(precipmobj_t *mobj) if ((mobj->z += mobj->momz) <= mobj->floorz) { mobj->z = mobj->ceilingz; - R_ResetPrecipitationMobjInterpolationState(mobj); + //R_ResetPrecipitationMobjInterpolationState(mobj); } } @@ -3828,7 +3828,7 @@ void P_RainThinker(precipmobj_t *mobj) return; mobj->z = mobj->ceilingz; - R_ResetPrecipitationMobjInterpolationState(mobj); + //R_ResetPrecipitationMobjInterpolationState(mobj); P_SetPrecipMobjState(mobj, S_RAIN1); return; @@ -10123,7 +10123,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype || mobj->subsector->sector->floorpic == skyflatnum) mobj->precipflags |= PCF_PIT; - R_ResetPrecipitationMobjInterpolationState(mobj); + //R_ResetPrecipitationMobjInterpolationState(mobj); return mobj; } diff --git a/src/r_fps.c b/src/r_fps.c index 8ae69e435..0c5d569e3 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -313,7 +313,7 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) } } -void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjstate_t *out) +/*void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjstate_t *out) { if (frac == FRACUNIT) { @@ -342,7 +342,7 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst out->subsector = mobj->subsector; out->angle = mobj->angle; -} +}*/ static void AddInterpolator(levelinterpolator_t* interpolator) { @@ -782,7 +782,7 @@ void R_ResetMobjInterpolationState(mobj_t *mobj) // // Reset the rendering interpolation state of the precipmobj. // -void R_ResetPrecipitationMobjInterpolationState(precipmobj_t *mobj) +/*void R_ResetPrecipitationMobjInterpolationState(precipmobj_t *mobj) { mobj->old_x2 = mobj->old_x; mobj->old_y2 = mobj->old_y; @@ -796,4 +796,4 @@ void R_ResetPrecipitationMobjInterpolationState(precipmobj_t *mobj) mobj->old_spriteyscale = mobj->spriteyscale; mobj->old_spritexoffset = mobj->spritexoffset; mobj->old_spriteyoffset = mobj->spriteyoffset; -} +}*/ diff --git a/src/r_things.c b/src/r_things.c index 8db590597..e93fd9834 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1716,7 +1716,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) fixed_t gz ,gzt; // uncapped/interpolation - interpmobjstate_t interp = {0}; + /*interpmobjstate_t interp = {0}; // do interpolation if (R_UsingFrameInterpolation() && !paused) @@ -1726,11 +1726,11 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) else { R_InterpolatePrecipMobjState(thing, FRACUNIT, &interp); - } + }*/ // transform the origin point - tr_x = interp.x - viewx; - tr_y = interp.y - viewy; + tr_x = thing->x - viewx; + tr_y = thing->y - viewy; gxt = FixedMul(tr_x, viewcos); gyt = -FixedMul(tr_y, viewsin); @@ -1799,12 +1799,12 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) if (x2 < portalclipstart || x1 > portalclipend) return; - if (P_PointOnLineSide(interp.x, interp.y, portalclipline) != 0) + if (P_PointOnLineSide(thing->x, thing->y, portalclipline) != 0) return; } //SoM: 3/17/2000: Disregard sprites that are out of view.. - gzt = interp.z + spritecachedinfo[lump].topoffset; + gzt = thing->z + spritecachedinfo[lump].topoffset; gz = gzt - spritecachedinfo[lump].height; if (thing->subsector->sector->cullheight) @@ -1817,12 +1817,12 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis = R_NewVisSprite(); vis->scale = vis->sortscale = yscale; //<dispoffset = 0; // Monster Iestyn: 23/11/15 - vis->gx = interp.x; - vis->gy = interp.y; + vis->gx = thing->x; + vis->gy = thing->y; vis->gz = gz; vis->gzt = gzt; vis->thingheight = 4*FRACUNIT; - vis->pz = interp.z; + vis->pz = thing->z; vis->pzt = vis->pz + vis->thingheight; vis->texturemid = vis->gzt - viewz; vis->scalestep = 0; @@ -1849,7 +1849,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->startfrac = 0; vis->xiscale = iscale; - vis->thingscale = interp.scale; + //vis->thingscale = interp.scale; if (vis->x1 > x1) vis->startfrac += vis->xiscale*(vis->x1-x1); From 689f5add6013115ef64d5d7b7ba218756d17783e Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 26 Sep 2023 22:54:34 +0200 Subject: [PATCH 108/239] smooooth console uncap console opening/closing animation --- src/console.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/console.c b/src/console.c index 99d032b7f..3c2230935 100644 --- a/src/console.c +++ b/src/console.c @@ -23,6 +23,7 @@ #include "g_input.h" #include "hu_stuff.h" #include "keys.h" +#include "r_main.h" #include "r_defs.h" #include "sounds.h" #include "st_stuff.h" @@ -602,32 +603,38 @@ static void CON_ChangeHeight(void) // static void CON_MoveConsole(void) { - fixed_t conspeed; + static fixed_t fracmovement = 0; Lock_state(); - conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT); - // instant if (!cons_speed.value) { con_curlines = con_destlines; + Unlock_state(); return; } - // up/down move to dest - if (con_curlines < con_destlines) + // Not instant - Increment fracmovement fractionally + fracmovement += FixedMul(cons_speed.value*vid.fdupy, renderdeltatics); + + if (con_curlines < con_destlines) // Move the console downwards { - con_curlines += FixedInt(conspeed); - if (con_curlines > con_destlines) - con_curlines = con_destlines; + con_curlines += FixedInt(fracmovement); // Move by fracmovement's integer value + if (con_curlines > con_destlines) // If we surpassed the destination... + con_curlines = con_destlines; // ...clamp to it! } - else if (con_curlines > con_destlines) + else // Move the console upwards { - con_curlines -= FixedInt(conspeed); + con_curlines -= FixedInt(fracmovement); if (con_curlines < con_destlines) con_curlines = con_destlines; + + if (con_destlines == 0) // If the console is being closed, not just moved up... + con_tick = 0; // ...don't show the blinking cursor } + + fracmovement %= FRACUNIT; // Reset fracmovement's integer value, but keep the fraction Unlock_state(); } @@ -724,10 +731,6 @@ void CON_Ticker(void) CON_ChangeHeight(); } - // console movement - if (con_destlines != con_curlines) - CON_MoveConsole(); - // clip the view, so that the part under the console is not drawn con_clipviewtop = -1; if (cons_backpic.value) // clip only when using an opaque background @@ -1774,6 +1777,10 @@ void CON_Drawer(void) if (con_curlines <= 0) CON_ClearHUD(); } + + // console movement + if (con_curlines != con_destlines) + CON_MoveConsole(); if (con_curlines > 0) CON_DrawConsole(); From 26b28f9b4d9c9a861cd68a35623cb3747bfaa5ab Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Sep 2023 01:49:54 +0200 Subject: [PATCH 109/239] why are these here?? --- src/r_things.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 8db590597..97e35c77e 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1638,8 +1638,6 @@ static void R_ProjectSprite(mobj_t *thing) vis->scale += FixedMul(scalestep, spriteyscale) * (vis->x1 - x1); } - vis->thingscale = interp.scale; - //Fab: lumppat is the lump number of the patch to use, this is different // than lumpid for sprites-in-pwad : the graphics are patched #ifdef ROTSPRITE @@ -1849,8 +1847,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->startfrac = 0; vis->xiscale = iscale; - vis->thingscale = interp.scale; - if (vis->x1 > x1) vis->startfrac += vis->xiscale*(vis->x1-x1); From 82fe3e5362256576905c87f4fc1c81436b711cd2 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Sep 2023 02:00:40 +0200 Subject: [PATCH 110/239] ughuguha --- src/r_things.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_things.c b/src/r_things.c index 97e35c77e..0163b301b 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1847,6 +1847,8 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->startfrac = 0; vis->xiscale = iscale; + vis->thingscale = interp.scale; + if (vis->x1 > x1) vis->startfrac += vis->xiscale*(vis->x1-x1); From acb139a8c65e5aaf39c50aea946d166da0bdd6a9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Sep 2023 02:02:03 +0200 Subject: [PATCH 111/239] die --- src/r_things.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index 0163b301b..ff9e2395a 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -951,7 +951,6 @@ static void R_DrawVisSprite(vissprite_t *vis) if (!(vis->scalestep)) { sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale); - //sprtopscreen += vis->shear.tan * vis->shear.offset; dc_iscale = FixedDiv(FRACUNIT, vis->scale); } From 02fab76406fa26dd2cd2a85132774ad67f92215a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 27 Sep 2023 02:17:23 +0200 Subject: [PATCH 112/239] remove all that crap nothing uses it, leftovers from cep port --- src/r_things.c | 8 +++----- src/r_things.h | 3 --- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index ff9e2395a..602dd3545 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -130,7 +130,7 @@ static void R_InstallSpriteLump(UINT16 wad, // graphics patch { char cn = R_Frame2Char(frame); // for debugging - INT32 r, ang; + INT32 r; lumpnum_t lumppat = wad; lumppat <<= 16; lumppat += lump; @@ -828,9 +828,9 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) static void R_DrawVisSprite(vissprite_t *vis) { column_t *column; - void (*localcolfunc)(column_t *); +#ifdef RANGECHECK INT32 texturecolumn; - INT32 pwidth; +#endif fixed_t frac; patch_t *patch = vis->patch; fixed_t this_scale = vis->thingscale; @@ -1205,8 +1205,6 @@ static void R_ProjectSprite(mobj_t *thing) fixed_t scalestep; // toast '16 fixed_t offset, offset2; boolean papersprite = (thing->frame & FF_PAPERSPRITE); - fixed_t paperoffset = 0, paperdistance = 0; - angle_t centerangle = 0; //SoM: 3/17/2000 fixed_t gz, gzt; diff --git a/src/r_things.h b/src/r_things.h index 4d246e7d8..39be3c3f1 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -136,10 +136,7 @@ typedef struct vissprite_s fixed_t thingscale; // the object's scale fixed_t sortscale; // sortscale only differs from scale for flat sprites fixed_t scalestep; // only for flat sprites, 0 otherwise - fixed_t paperoffset, paperdistance; // for paper sprites, offset/dist relative to the angle fixed_t xiscale; // negative if flipped - - angle_t centerangle; // for paper sprites fixed_t texturemid; patch_t *patch; From 6544851ba503162f5ee27896a40acaf8b0f672ac Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 27 Sep 2023 05:45:29 +0200 Subject: [PATCH 113/239] c90 shit --- src/r_main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 2205c4dc4..1e50aeb3c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -441,18 +441,19 @@ fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1) angle_t R_PlayerSliptideAngle(player_t *player) { - mobj_t *mo = player->mo; + mobj_t *mo; + spritedef_t *sprdef; + spriteframe_t *sprframe; + angle_t ang = 0; + interpmobjstate_t interp = {0}; - if (!cv_sliptideroll.value || !mo || P_MobjWasRemoved(mo)) return 0; + if (!cv_sliptideroll.value || !player || P_MobjWasRemoved(player->mo)) + return 0; - size_t rot = mo->frame&FF_FRAMEMASK; - boolean papersprite = (mo->frame & FF_PAPERSPRITE); + mo = player->mo; - spritedef_t *sprdef; - spriteframe_t *sprframe; - angle_t ang = 0; - - interpmobjstate_t interp = {0}; + size_t rot = mo->frame & FF_FRAMEMASK; + boolean papersprite = (mo->frame & FF_PAPERSPRITE); // Yes. if (R_UsingFrameInterpolation() && !paused) From dc0e67515bc617500801da04d8f32e3864e855aa Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 27 Sep 2023 06:00:27 +0200 Subject: [PATCH 114/239] compiler complains --- src/hardware/hw_main.c | 2 +- src/st_stuff.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index feebc7bb7..df2a4d82c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6210,7 +6210,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 && !cv_grpaletteshader.value) || (player->flashcount && cv_grpaletteshader.value && !cv_grflashpal.value)) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/st_stuff.c b/src/st_stuff.c index 1c7ba5190..266b554e1 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -247,7 +247,7 @@ void ST_doPaletteStuff(void) palette = min(max(palette, 0), 13); #ifdef HWRENDER - if (rendermode == render_opengl && !cv_grpaletteshader.value || rendermode == render_opengl && cv_grpaletteshader.value && !cv_grflashpal.value) + if ((rendermode == render_opengl && !cv_grpaletteshader.value) || (rendermode == render_opengl && cv_grpaletteshader.value && !cv_grflashpal.value)) palette = 0; // No flashpals here in OpenGL #endif From e10ed14a3cbf8e99be18f2725bc6d6cfc795a059 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 27 Sep 2023 12:36:10 +0300 Subject: [PATCH 115/239] Remove unneeded interpolation from R_PlayerSliptideAngle (this function is only used from lua, and lua is always running at 35 fps anyway) --- src/r_main.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 1e50aeb3c..0e8fc9361 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -445,7 +445,6 @@ angle_t R_PlayerSliptideAngle(player_t *player) spritedef_t *sprdef; spriteframe_t *sprframe; angle_t ang = 0; - interpmobjstate_t interp = {0}; if (!cv_sliptideroll.value || !player || P_MobjWasRemoved(player->mo)) return 0; @@ -455,16 +454,6 @@ angle_t R_PlayerSliptideAngle(player_t *player) size_t rot = mo->frame & FF_FRAMEMASK; boolean papersprite = (mo->frame & FF_PAPERSPRITE); - // Yes. - if (R_UsingFrameInterpolation() && !paused) - { - R_InterpolateMobjState(mo, rendertimefrac, &interp); - } - else - { - R_InterpolateMobjState(mo, FRACUNIT, &interp); - } - if (mo->skin && mo->sprite == SPR_PLAY) { sprdef = &((skin_t *)mo->skin)->spritedef; @@ -489,7 +478,7 @@ angle_t R_PlayerSliptideAngle(player_t *player) if (!sprframe) return 0; if (sprframe->rotate != SRF_SINGLE || papersprite) - ang = R_PointToAngle(interp.x, interp.y) - interp.angle; + ang = R_PointToAngle(mo->x, mo->y) - mo->angle; return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), mo->player->sliproll*(mo->player->sliptidemem)); } From 074be933ad50addc0f8fc370a0b302534cbea5a7 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 29 Sep 2023 15:15:13 +0200 Subject: [PATCH 116/239] remove asm FixedDiv and FixedMul functions DIE! --- src/m_fixed.c | 44 ---------------- src/m_fixed.h | 135 ++++++++------------------------------------------ 2 files changed, 22 insertions(+), 157 deletions(-) diff --git a/src/m_fixed.c b/src/m_fixed.c index 3724144f7..2da72fe05 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -23,50 +23,6 @@ #include "m_fixed.h" #include "tables.h" // ANGLETOFINESHIFT -#ifdef __USE_C_FIXEDMUL__ - -/** \brief The FixedMul function - - \param a fixed_t number - \param b fixed_t number - - \return a*b>>FRACBITS - -*/ -fixed_t FixedMul(fixed_t a, fixed_t b) -{ - // Need to cast to unsigned before shifting to avoid undefined behaviour - // for negative integers - return (fixed_t)(((UINT64)((INT64)a * b)) >> FRACBITS); -} - -#endif //__USE_C_FIXEDMUL__ - -#ifdef __USE_C_FIXEDDIV__ -/** \brief The FixedDiv2 function - - \param a fixed_t number - \param b fixed_t number - - \return a/b * FRACUNIT - -*/ -fixed_t FixedDiv2(fixed_t a, fixed_t b) -{ - INT64 ret; - - if (b == 0) - I_Error("FixedDiv: divide by zero"); - - ret = (((INT64)a * FRACUNIT)) / b; - - if ((ret > INT32_MAX) || (ret < INT32_MIN)) - I_Error("FixedDiv: divide by zero"); - return (fixed_t)ret; -} - -#endif // __USE_C_FIXEDDIV__ - fixed_t FixedSqrt(fixed_t x) { #ifdef HAVE_SQRT diff --git a/src/m_fixed.h b/src/m_fixed.h index 5ae029fc4..e64c9e0d4 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -62,126 +62,35 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) -#if defined (__WATCOMC__) && FRACBITS == 16 - #pragma aux FixedMul = \ - "imul ebx", \ - "shrd eax,edx,16" \ - parm [eax] [ebx] \ - value [eax] \ - modify exact [eax edx] +/** \brief The FixedMul function - #pragma aux FixedDiv2 = \ - "cdq", \ - "shld edx,eax,16", \ - "sal eax,16", \ - "idiv ebx" \ - parm [eax] [ebx] \ - value [eax] \ - modify exact [eax edx] -#elif defined (__GNUC__) && defined (__i386__) && !defined (NOASM) - // DJGPP, i386 linux, cygwin or mingw - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret; - asm - ( - "imull %2;" // a*b - "shrdl %3,%%edx,%0;" // shift logical right FRACBITS bits - :"=a" (ret) // eax is always the result and the first operand (%0,%1) - :"0" (a), "r" (b) // and %2 is what we use imull on with what in %1 - , "I" (FRACBITS) // %3 holds FRACBITS (normally 16) - :"cc", "%edx" // edx and condition codes clobbered - ); - return ret; - } + \param a fixed_t number + \param b fixed_t number - FUNCMATH FUNCINLINE static inline fixed_t FixedDiv2(fixed_t a, fixed_t b) - { - fixed_t ret; - asm - ( - "movl %1,%%edx;" // these two instructions allow the next two to pair, on the Pentium processor. - "sarl $31,%%edx;" // shift arithmetic right 31 on EDX - "shldl %3,%1,%%edx;" // DP shift logical left FRACBITS on EDX - "sall %3,%0;" // shift arithmetic left FRACBITS on EAX - "idivl %2;" // EDX/b = EAX - : "=a" (ret) - : "0" (a), "r" (b) - , "I" (FRACBITS) - : "%edx" - ); - return ret; - } -#elif defined (__GNUC__) && defined (__arm__) && !defined(__thumb__) && !defined(NOASM) //ARMv4 ASM - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // let abuse smull - { - fixed_t ret; - asm - ( - "smull %[lo], r1, %[a], %[b];" - "mov %[lo], %[lo], lsr %3;" - "orr %[lo], %[lo], r1, lsl %3;" - : [lo] "=&r" (ret) // rhi, rlo and rm must be distinct registers - : [a] "r" (a), [b] "r" (b) - , "i" (FRACBITS) - : "r1" - ); - return ret; - } + \return a*b>>FRACBITS - #define __USE_C_FIXEDDIV__ // no double or asm div in ARM land -#elif defined (__GNUC__) && defined (__ppc__) && !defined(NOASM) && 0 // WII: PPC CPU - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret, hi, lo; - asm - ( - "mullw %0, %2, %3;" - "mulhw %1, %2, %3" - : "=r" (hi), "=r" (lo) - : "r" (a), "r" (b) - , "I" (FRACBITS) - ); - ret = (INT64)((hi>>FRACBITS)+lo)<> FRACBITS); +} - #define __USE_C_FIXEDDIV__// Alam: I am lazy -#elif defined (__GNUC__) && defined (__mips__) && !defined(NOASM) && 0 // PSP: MIPS CPU - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret; - asm - ( - "mult %3, %4;" // a*b=h<32+l - : "=r" (ret), "=l" (a), "=h" (b) //todo: abuse shr opcode - : "0" (a), "r" (b) - , "I" (FRACBITS) - //: "+l", "+h" - ); - ret = (INT64)((a>>FRACBITS)+b)< Date: Fri, 29 Sep 2023 15:34:29 +0200 Subject: [PATCH 117/239] rip in pieces asm code this thing makes software crash so goddamn often, its useless nowadays anyways, and SRB2 removed it some time ago aswell https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2074?commit_id=7634a960314d5a576656cc4300a74caf889f8d7f --- SRB2.cbp | 18 - SRB2_common.props | 3 - Srb2.dev | 52 +- appveyor.yml | 8 - cmake/Modules/CMakeASM_YASMInformation.cmake | 46 - .../CMakeDetermineASM_YASMCompiler.cmake | 27 - cmake/Modules/CMakeTestASM_YASMCompiler.cmake | 23 - src/Android.mk | 2 +- src/CMakeLists.txt | 52 - src/Makefile | 33 - src/Makefile.cfg | 14 - src/asm_defs.inc | 43 - src/d_netcmd.c | 5 - src/p5prof.h | 278 --- src/r_draw.h | 14 - src/r_splats.c | 11 - src/screen.c | 31 - src/sdl/MakeCYG.cfg | 1 - src/sdl/MakeNIX.cfg | 1 - src/sdl/Makefile.cfg | 7 - src/sdl/i_main.c | 35 - src/tmap.s | 1587 ----------------- src/tmap_asm.s | 322 ---- src/tmap_mmx.nas | 674 ------- src/tmap_vc.nas | 48 - src/v_video.c | 11 - src/vid_copy.s | 61 - src/win32/Makefile.cfg | 4 - tools/anglechk.c | 1 - 29 files changed, 2 insertions(+), 3410 deletions(-) delete mode 100644 cmake/Modules/CMakeASM_YASMInformation.cmake delete mode 100644 cmake/Modules/CMakeDetermineASM_YASMCompiler.cmake delete mode 100644 cmake/Modules/CMakeTestASM_YASMCompiler.cmake delete mode 100644 src/asm_defs.inc delete mode 100644 src/p5prof.h delete mode 100644 src/tmap.s delete mode 100644 src/tmap_asm.s delete mode 100644 src/tmap_mmx.nas delete mode 100644 src/tmap_vc.nas delete mode 100644 src/vid_copy.s diff --git a/SRB2.cbp b/SRB2.cbp index acdc61c7f..b4cf543db 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -1996,24 +1996,6 @@ HW3SOUND for 3D hardware sound support