From 9442a463d46284bc85cfac927bc1b7dc1ef6d832 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:43:50 +0200 Subject: [PATCH 01/91] Shrink drawlists, take 2 Approximately 2/3rds smaller --- src/lua_hudlib_drawlist.c | 45 ++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index de1f234c3..7ec5398e4 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -37,27 +37,32 @@ typedef struct drawitem_s { enum drawitem_e type; fixed_t x; fixed_t y; - fixed_t w; - fixed_t h; - INT32 c; - fixed_t scale; - fixed_t hscale; - fixed_t vscale; - patch_t *patch; - INT32 flags; - UINT16 basecolor; - UINT16 outlinecolor; + union { + INT32 flags; + INT32 c; + }; + + union { + fixed_t scale; // drawScaled + fixed_t hscale; // drawStretched + fixed_t w; // drawFill + INT32 align; // drawString + INT32 num; // drawNum, drawPaddedNum, drawPingNum + UINT16 color; // fadeScreen + }; + union { + fixed_t vscale; // drawStretched + fixed_t h; // drawFill + INT32 digits; // drawPaddedNum + UINT8 strength; // fadeScreen + }; + + // pointers (and size_t's) last, for potentially better packing + union { + patch_t *patch; + size_t stroffset; // offset into strbuf to get str + }; const UINT8 *colormap; - UINT8 *basecolormap; - UINT8 *outlinecolormap; - fixed_t sx; - fixed_t sy; - INT32 num; - INT32 digits; - size_t stroffset; // offset into strbuf to get str - UINT16 color; - UINT8 strength; - INT32 align; } drawitem_t; // The internal structure of a drawlist. From 5f69bfcf222535b73bae57a7d0c8a702f1298566 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Tue, 2 Apr 2024 03:22:24 +0200 Subject: [PATCH 02/91] Split game drawlist per displayplayer --- src/lua_hud.h | 2 +- src/lua_hudlib.c | 29 +++++------------------------ src/st_stuff.c | 13 ++++++++----- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/lua_hud.h b/src/lua_hud.h index d0fec7f1e..ce9f6e7a8 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -44,7 +44,7 @@ extern boolean hud_running; boolean LUA_HudEnabled(enum hud option); -void LUAh_GameHUD(player_t *stplyr, huddrawlist_h list); +void LUAh_GameHUD(huddrawlist_h list); void LUAh_ScoresHUD(huddrawlist_h list); void LUAh_IntermissionHUD(huddrawlist_h list); void LUAh_VoteHUD(huddrawlist_h list); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 2f81d98bf..3ec03537b 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1413,7 +1413,7 @@ boolean LUA_HudEnabled(enum hud option) } // Hook for HUD rendering -void LUAh_GameHUD(player_t *stplayr, huddrawlist_h list) +void LUAh_GameHUD(huddrawlist_h list) { if (!gL || !(hudAvailable & (1< 2 && stplayr == &players[displayplayers[3]]) - { - LUA_PushUserdata(gL, &camera[3], META_CAMERA); - camnum = 4; - } - else if (splitscreen > 1 && stplayr == &players[displayplayers[2]]) - { - LUA_PushUserdata(gL, &camera[2], META_CAMERA); - camnum = 3; - } - else if (splitscreen && stplayr == &players[displayplayers[1]]) - { - LUA_PushUserdata(gL, &camera[1], META_CAMERA); - camnum = 2; - } - else - { - LUA_PushUserdata(gL, &camera[0], META_CAMERA); - camnum = 1; - } + LUA_PushUserdata(gL, stplyr, META_PLAYER); + LUA_PushUserdata(gL, &camera[stplyrnum], META_CAMERA); + camnum = stplyrnum + 1; lua_pushnil(gL); while (lua_next(gL, -5) != 0) { lua_pushvalue(gL, -5); // graphics library (HUD[1]) - lua_pushvalue(gL, -5); // stplayr + lua_pushvalue(gL, -5); // stplyr lua_pushvalue(gL, -5); // camera LUA_Call(gL, 3, 0, 1); } diff --git a/src/st_stuff.c b/src/st_stuff.c index 2ecfd73d5..3e64e6626 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -193,7 +193,7 @@ hudinfo_t hudinfo[NUMHUDITEMS] = { 240, 160}, // HUD_LAP }; -static huddrawlist_h luahuddrawlist_game; +static huddrawlist_h luahuddrawlist_game[MAXSPLITSCREENPLAYERS]; // variable to stop mayonaka static from flickering consvar_t cv_lessflicker = {"lessflicker", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -473,7 +473,8 @@ void ST_Init(void) ST_LoadGraphics(); - luahuddrawlist_game = LUA_HUD_CreateDrawList(); + for (int i = 0; i < MAXSPLITSCREENPLAYERS; i++) + luahuddrawlist_game[i] = LUA_HUD_CreateDrawList(); } // change the status bar too, when pressing F12 while viewing a demo. @@ -846,7 +847,7 @@ static void ST_overlayDrawer(void) { if (renderisnewtic) { - LUAh_GameHUD(stplyr, luahuddrawlist_game); + LUAh_GameHUD(luahuddrawlist_game[stplyrnum]); } } @@ -1024,7 +1025,8 @@ void ST_Drawer(void) { if (renderisnewtic) { - LUA_HUD_ClearDrawList(luahuddrawlist_game); + for (i = 0; i <= splitscreen; i++) + LUA_HUD_ClearDrawList(luahuddrawlist_game[i]); } // No deadview! @@ -1035,7 +1037,8 @@ void ST_Drawer(void) ST_overlayDrawer(); } - LUA_HUD_DrawList(luahuddrawlist_game); + for (i = 0; i <= splitscreen; i++) + LUA_HUD_DrawList(luahuddrawlist_game[i]); // draw Midnight Channel's overlay ontop if (mapheaderinfo[gamemap-1]->typeoflevel & TOL_TV) // Very specific Midnight Channel stuff. From b2f9a29eb0bca107ad4bbe7ce65832d48bcb57f3 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:00:23 +0200 Subject: [PATCH 03/91] Lua HUD interpolation --- src/lua_hud.h | 3 + src/lua_hudlib.c | 31 +++++++++ src/lua_hudlib_drawlist.c | 142 +++++++++++++++++++++++++++++--------- 3 files changed, 144 insertions(+), 32 deletions(-) diff --git a/src/lua_hud.h b/src/lua_hud.h index ce9f6e7a8..8601192b6 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -41,6 +41,9 @@ enum hud { }; extern boolean hud_running; +extern UINT8 hud_interptag; +extern UINT32 hud_interpcounter; +extern boolean hud_interpstring; boolean LUA_HudEnabled(enum hud option); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 3ec03537b..62aa30c37 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -32,6 +32,9 @@ #define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!"); boolean hud_running = false; +UINT8 hud_interptag = 0; +UINT32 hud_interpcounter = 0; +boolean hud_interpstring = false; static UINT8 hud_enabled[(hud_MAX/8)+1]; static UINT8 hudAvailable; // hud hooks field @@ -1178,6 +1181,20 @@ static int libd_getDrawInfo(lua_State *L) return 3; } +static int libd_interpolate(lua_State *L) +{ + HUDONLY + hud_interptag = luaL_checkinteger(L, 1); + return 0; +} + +static int libd_interpString(lua_State *L) +{ + HUDONLY + hud_interpstring = luaL_checkboolean(L, 1); + return 0; +} + static luaL_Reg lib_draw[] = { {"patchExists", libd_patchExists}, {"cachePatch", libd_cachePatch}, @@ -1205,6 +1222,8 @@ static luaL_Reg lib_draw[] = { {"getDrawInfo", libd_getDrawInfo}, {"getHudColor", libd_getHudColor}, {"useColorHud", libd_useColorHud}, + {"interpolate", libd_interpolate}, + {"interpString", libd_interpString}, {NULL, NULL} }; @@ -1438,8 +1457,11 @@ void LUAh_GameHUD(huddrawlist_h list) LUA_PushUserdata(gL, &camera[stplyrnum], META_CAMERA); camnum = stplyrnum + 1; + hud_interpcounter = 0; lua_pushnil(gL); while (lua_next(gL, -5) != 0) { + hud_interptag = 0; + hud_interpcounter++; lua_pushvalue(gL, -5); // graphics library (HUD[1]) lua_pushvalue(gL, -5); // stplyr lua_pushvalue(gL, -5); // camera @@ -1474,7 +1496,10 @@ void LUAh_ScoresHUD(huddrawlist_h list) I_Assert(lua_istable(gL, -1)); lua_remove(gL, -3); // pop HUD lua_pushnil(gL); + hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { + hud_interptag = 0; + hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); } @@ -1507,7 +1532,10 @@ void LUAh_IntermissionHUD(huddrawlist_h list) I_Assert(lua_istable(gL, -1)); lua_remove(gL, -3); // pop HUD lua_pushnil(gL); + hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { + hud_interptag = 0; + hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); } @@ -1540,7 +1568,10 @@ void LUAh_VoteHUD(huddrawlist_h list) I_Assert(lua_istable(gL, -1)); lua_remove(gL, -3); // pop HUD lua_pushnil(gL); + hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { + hud_interptag = 0; + hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); } diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 7ec5398e4..14a24d90e 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -11,11 +11,16 @@ /// \brief a data structure for managing cached drawlists for the Lua hud lib #include "lua_hudlib_drawlist.h" +#include "lua_hud.h" +#include "blua/lstate.h" // shhhhhh +#include "lua_libs.h" #include #include "v_video.h" #include "z_zone.h" +#include "r_main.h" +#include "r_fps.h" enum drawitem_e { DI_Draw = 0, @@ -34,6 +39,7 @@ enum drawitem_e { // A single draw item with all possible arguments needed for a draw call. typedef struct drawitem_s { + UINT64 id; enum drawitem_e type; fixed_t x; fixed_t y; @@ -68,8 +74,10 @@ typedef struct drawitem_s { // The internal structure of a drawlist. struct huddrawlist_s { drawitem_t *items; - size_t items_capacity; size_t items_len; + drawitem_t *olditems; + size_t olditems_len; + size_t capacity; char *strbuf; size_t strbuf_capacity; size_t strbuf_len; @@ -93,8 +101,10 @@ huddrawlist_h LUA_HUD_CreateDrawList(void) drawlist = (huddrawlist_h) Z_Calloc(sizeof(struct huddrawlist_s), PU_STATIC, NULL); drawlist->items = NULL; - drawlist->items_capacity = 0; drawlist->items_len = 0; + drawlist->olditems = NULL; + drawlist->olditems_len = 0; + drawlist->capacity = 0; drawlist->strbuf = NULL; drawlist->strbuf_capacity = 0; drawlist->strbuf_len = 0; @@ -104,15 +114,14 @@ huddrawlist_h LUA_HUD_CreateDrawList(void) void LUA_HUD_ClearDrawList(huddrawlist_h list) { + // swap the old and new lists + void *tmp = list->olditems; + list->olditems = list->items; + list->items = tmp; + // rather than deallocate, we'll just save the existing allocation and empty // it out for reuse - - // this memset probably isn't necessary - if (list->items) - { - memset(list->items, 0, sizeof(drawitem_t) * list->items_capacity); - } - + list->olditems_len = list->items_len; list->items_len = 0; if (list->strbuf) @@ -130,6 +139,10 @@ void LUA_HUD_DestroyDrawList(huddrawlist_h list) { Z_Free(list->items); } + if (list->olditems) + { + Z_Free(list->olditems); + } if (list->strbuf) { Z_Free(list->strbuf); @@ -148,11 +161,11 @@ boolean LUA_HUD_IsDrawListValid(huddrawlist_h list) static size_t AllocateDrawItem(huddrawlist_h list) { if (!list) I_Error("can't allocate draw item: invalid list"); - if (list->items_capacity <= list->items_len + 1) + if (list->capacity <= list->items_len) { - if (list->items_capacity == 0) list->items_capacity = 128; - else list->items_capacity *= 2; - list->items = (drawitem_t *) Z_Realloc(list->items, sizeof(struct drawitem_s) * list->items_capacity, PU_STATIC, NULL); + list->capacity = list->capacity == 0 ? 128 : list->capacity * 2; + list->items = Z_Realloc(list->items, sizeof(struct drawitem_s) * list->capacity, PU_STATIC, NULL); + list->olditems = Z_Realloc(list->olditems, sizeof(struct drawitem_s) * list->capacity, PU_STATIC, NULL); } return list->items_len++; @@ -183,6 +196,14 @@ static size_t CopyString(huddrawlist_h list, const char* str) } } +// leave bit 0 free for the string mode +#define INTERP_LATCH 1 + +#define GETITEMID \ + item->id = hud_interptag \ + ? (((UINT64)gL->savedpc << 32) | (hud_interpcounter << 9) | (hud_interptag << 1) | (hud_interpstring ? INTERP_LATCH : 0)) \ + : 0; + void LUA_HUD_AddDraw( huddrawlist_h list, INT32 x, @@ -194,9 +215,10 @@ void LUA_HUD_AddDraw( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_Draw; - item->x = x; - item->y = y; + item->x = x << FRACBITS; + item->y = y << FRACBITS; item->patch = patch; item->flags = flags; item->colormap = colormap; @@ -214,6 +236,7 @@ void LUA_HUD_AddDrawScaled( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawScaled; item->x = x; item->y = y; @@ -236,6 +259,7 @@ void LUA_HUD_AddDrawStretched( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawStretched; item->x = x; item->y = y; @@ -256,6 +280,7 @@ void LUA_HUD_AddDrawNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawNum; item->x = x; item->y = y; @@ -274,6 +299,7 @@ void LUA_HUD_AddDrawPaddedNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawPaddedNum; item->x = x; item->y = y; @@ -293,6 +319,7 @@ void LUA_HUD_AddDrawPingNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawPingNum; item->x = x; item->y = y; @@ -312,6 +339,7 @@ void LUA_HUD_AddDrawFill( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawFill; item->x = x; item->y = y; @@ -331,6 +359,7 @@ void LUA_HUD_AddDrawString( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawString; item->x = x; item->y = y; @@ -349,6 +378,7 @@ void LUA_HUD_AddDrawKartString( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawKartString; item->x = x; item->y = y; @@ -366,6 +396,7 @@ void LUA_HUD_AddDrawLevelTitle( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + GETITEMID item->type = DI_DrawLevelTitle; item->x = x; item->y = y; @@ -389,6 +420,11 @@ void LUA_HUD_AddFadeScreen( void LUA_HUD_DrawList(huddrawlist_h list) { size_t i; + size_t j = 0; + fixed_t frac = R_UsingFrameInterpolation() ? rendertimefrac : FRACUNIT; + fixed_t lerpx = 0, lerpy = 0; + drawitem_t *latchitem = NULL; + drawitem_t *oldlatchitem = NULL; if (!list) I_Error("HUD drawlist invalid"); if (list->items_len <= 0) return; @@ -397,68 +433,110 @@ void LUA_HUD_DrawList(huddrawlist_h list) for (i = 0; i < list->items_len; i++) { drawitem_t *item = &list->items[i]; + drawitem_t *olditem = NULL; const char *itemstr = &list->strbuf[item->stroffset]; + if (item->id) { + // find the old one too + // this is kinda cursed... we need to check every item + // but stop when the first-checked item is reached again + size_t stop = j; + while(true) + { + if (j == list->olditems_len) + { + // wrap around + j = 0; + if (j == stop) // i'm dumb + break; + } + drawitem_t *old = &list->olditems[j++]; + if (old->id == item->id) + { + // gotcha! + olditem = old; + if (item->id & INTERP_LATCH) { + if (!latchitem) { + lerpx = FixedMul(frac, item->x - olditem->x); + lerpy = FixedMul(frac, item->y - olditem->y); + latchitem = item; + oldlatchitem = olditem; + } + } else { + lerpx = FixedMul(frac, item->x - olditem->x); + lerpy = FixedMul(frac, item->y - olditem->y); + latchitem = NULL; + } + break; + } + if (j == stop) + break; + } + } + + #define LERP(it) (olditem ? olditem->it + FixedMul(frac, item->it - olditem->it) : item->it) + #define LERPS(it) (olditem ? (latchitem ? (latchitem->it + (item->it - latchitem->it)) - (latchitem->it - oldlatchitem->it) : olditem->it) + lerp##it : item->it) + switch (item->type) { case DI_Draw: - V_DrawFixedPatch(item->x<y<flags, item->patch, item->colormap); + V_DrawFixedPatch(LERPS(x), LERPS(y), FRACUNIT, item->flags, item->patch, item->colormap); break; case DI_DrawScaled: - V_DrawFixedPatch(item->x, item->y, item->scale, item->flags, item->patch, item->colormap); + V_DrawFixedPatch(LERPS(x), LERPS(y), LERP(scale), item->flags, item->patch, item->colormap); break; case DI_DrawStretched: - V_DrawStretchyFixedPatch(item->x, item->y, item->hscale, item->vscale, item->flags, item->patch, item->colormap); + V_DrawStretchyFixedPatch(LERPS(x), LERPS(y), LERP(hscale), LERP(vscale), item->flags, item->patch, item->colormap); break; case DI_DrawNum: - V_DrawTallNum(item->x, item->y, item->flags, item->num); + V_DrawTallNum(LERPS(x), LERPS(y), item->flags, item->num); break; case DI_DrawPaddedNum: - V_DrawPaddedTallNum(item->x, item->y, item->flags, item->num, item->digits); + V_DrawPaddedTallNum(LERPS(x), LERPS(y), item->flags, item->num, item->digits); break; case DI_DrawPingNum: - V_DrawPingNum(item->x, item->y, item->flags, item->num, item->colormap); + V_DrawPingNum(LERPS(x), LERPS(y), item->flags, item->num, item->colormap); break; case DI_DrawFill: - V_DrawFill(item->x, item->y, item->w, item->h, item->c); + V_DrawFill(LERPS(x), LERPS(y), item->w, item->h, item->c); break; case DI_DrawString: switch(item->align) { // hu_font case align_left: - V_DrawString(item->x, item->y, item->flags, itemstr); + V_DrawString(LERPS(x), LERPS(y), item->flags, itemstr); break; case align_center: - V_DrawCenteredString(item->x, item->y, item->flags, itemstr); + V_DrawCenteredString(LERPS(x), LERPS(y), item->flags, itemstr); break; case align_right: - V_DrawRightAlignedString(item->x, item->y, item->flags, itemstr); + V_DrawRightAlignedString(LERPS(x), LERPS(y), item->flags, itemstr); break; case align_fixed: - V_DrawStringAtFixed(item->x, item->y, item->flags, itemstr); + V_DrawStringAtFixed(LERPS(x), LERPS(y), item->flags, itemstr); break; // hu_font, 0.5x scale case align_small: - V_DrawSmallString(item->x, item->y, item->flags, itemstr); + V_DrawSmallString(LERPS(x), LERPS(y), item->flags, itemstr); break; case align_smallright: - V_DrawRightAlignedSmallString(item->x, item->y, item->flags, itemstr); + V_DrawRightAlignedSmallString(LERPS(x), LERPS(y), item->flags, itemstr); break; // tny_font case align_thin: - V_DrawThinString(item->x, item->y, item->flags, itemstr); + V_DrawThinString(LERPS(x), LERPS(y), item->flags, itemstr); break; case align_thinright: - V_DrawRightAlignedThinString(item->x, item->y, item->flags, itemstr); + V_DrawRightAlignedThinString(LERPS(x), LERPS(y), item->flags, itemstr); break; } break; case DI_DrawKartString: - V_DrawKartString(item->x, item->y, item->flags, itemstr); + V_DrawKartString(LERPS(x), LERPS(y), item->flags, itemstr); break; case DI_DrawLevelTitle: - V_DrawLevelTitle(item->x, item->y, item->flags, itemstr); + V_DrawLevelTitle(LERPS(x), LERPS(y), item->flags, itemstr); break; case DI_FadeScreen: V_DrawFadeScreen(item->color, item->strength); From aeb5ae994ecd92cfea78da5c423af52cc76db854 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Wed, 3 Apr 2024 01:37:24 +0200 Subject: [PATCH 04/91] Subpixel interpolation for strings and drawfill --- src/lua_hudlib_drawlist.c | 119 +++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 14a24d90e..8aaaa67ff 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -196,6 +196,116 @@ static size_t CopyString(huddrawlist_h list, const char* str) } } +static void CalcCoords(huddrawlist_h list, drawitem_t *item) +{ + if (!(item->flags & V_NOSCALESTART) && cv_uncappedhud.value) + { + INT32 dupx = vid.dupx; + INT32 dupy = vid.dupy; + + item->flags |= V_NOSCALESTART; + + if (item->flags & V_SCALEPATCHMASK) switch ((item->flags & V_SCALEPATCHMASK) >> V_SCALEPATCHSHIFT) + { + case 1: // V_NOSCALEPATCH + dupx = dupy = 1; + break; + case 2: // V_SMALLSCALEPATCH + dupx = vid.smalldupx; + dupy = vid.smalldupy; + break; + case 3: // V_MEDSCALEPATCH + dupx = vid.meddupx; + dupy = vid.meddupy; + break; + default: + break; + } + + // only use one dup, to avoid stretching (har har) + dupx = dupy = (dupx < dupy ? dupx : dupy); + + INT32 x = item->x * dupx; + INT32 y = item->y * dupy; + + if (vid.width != BASEVIDWIDTH * dupx) + { + // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // so center this imaginary screen + if ((item->flags & (V_HORZSCREEN|V_SNAPTOLEFT)) == (V_HORZSCREEN|V_SNAPTOLEFT)) + x += (vid.width/2 - (BASEVIDWIDTH/2 * dupx)); + else if (item->flags & V_SNAPTORIGHT) + x += (vid.width - (BASEVIDWIDTH * dupx)); + else if (!(item->flags & V_SNAPTOLEFT)) + x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + } + if (vid.height != BASEVIDHEIGHT * dupy) + { + // same thing here + if ((item->flags & (V_SPLITSCREEN|V_SNAPTOTOP)) == (V_SPLITSCREEN|V_SNAPTOTOP)) + y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)); + else if (item->flags & V_SNAPTOBOTTOM) + y += (vid.height - (BASEVIDHEIGHT * dupy)); + else if (!(item->flags & V_SNAPTOTOP)) + y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + } + + // need to compensate for dup here + + if (item->align == align_center) + x -= (V_StringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1))/2; + if (item->align == align_right) + x -= V_StringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1); + if (item->align == align_thinright) + x -= V_ThinStringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1); + + item->x = x; + item->y = y; + } +} + +static void CalcFillCoords(drawitem_t *item) +{ + if (!(item->flags & V_NOSCALESTART) && cv_uncappedhud.value) + { + INT32 dupx = vid.dupx; + INT32 dupy = vid.dupy; + INT32 x = item->x * dupx; + INT32 y = item->y * dupy; + INT32 c = item->c; + + item->flags |= V_NOSCALESTART; + item->w *= dupx; + item->h *= dupy; + + // Center it if necessary + if (vid.width != BASEVIDWIDTH * dupx) + { + // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // so center this imaginary screen + if (c & V_SNAPTORIGHT) + x += (vid.width - (BASEVIDWIDTH * dupx)); + else if (!(c & V_SNAPTOLEFT)) + x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + } + if (vid.height != BASEVIDHEIGHT * dupy) + { + // same thing here + if (c & V_SNAPTOBOTTOM) + y += (vid.height - (BASEVIDHEIGHT * dupy)); + else if (!(c & V_SNAPTOTOP)) + y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + } + if (c & V_SPLITSCREEN) + y += (BASEVIDHEIGHT * dupy)/2; + if (c & V_HORZSCREEN) + x += (BASEVIDWIDTH * dupx)/2; + + item->x = x; + item->y = y; + } +} + // leave bit 0 free for the string mode #define INTERP_LATCH 1 @@ -346,6 +456,7 @@ void LUA_HUD_AddDrawFill( item->w = w; item->h = h; item->c = c; + CalcFillCoords(item); } void LUA_HUD_AddDrawString( @@ -366,6 +477,7 @@ void LUA_HUD_AddDrawString( item->stroffset = CopyString(list, str); item->flags = flags; item->align = align; + CalcCoords(list, item); } void LUA_HUD_AddDrawKartString( @@ -436,7 +548,7 @@ void LUA_HUD_DrawList(huddrawlist_h list) drawitem_t *olditem = NULL; const char *itemstr = &list->strbuf[item->stroffset]; - if (item->id) { + if (item->id && cv_uncappedhud.value) { // find the old one too // this is kinda cursed... we need to check every item // but stop when the first-checked item is reached again @@ -475,7 +587,10 @@ void LUA_HUD_DrawList(huddrawlist_h list) } #define LERP(it) (olditem ? olditem->it + FixedMul(frac, item->it - olditem->it) : item->it) - #define LERPS(it) (olditem ? (latchitem ? (latchitem->it + (item->it - latchitem->it)) - (latchitem->it - oldlatchitem->it) : olditem->it) + lerp##it : item->it) + + // half of this could be done when the coordinates are latched... zzzzzz + #define LERPS(it) (latchitem ? ((latchitem->it + (item->it - latchitem->it)) - (latchitem->it - oldlatchitem->it)) + lerp##it : (olditem ? olditem->it + lerp##it : item->it)) + //define LERPS(it) (olditem ? (latchitem ? (latchitem->it + (item->it - latchitem->it)) - (latchitem->it - oldlatchitem->it) : olditem->it) + lerp##it : item->it) switch (item->type) { From 18e0485f399b928ac970814f365c4ebacbf64232 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:21:41 +0200 Subject: [PATCH 05/91] Make this less insufferable * Zero is now a valid tag for v.interpolate * Reset lerp coordinates when v.interpString is called again * Leaving string mode enabled on exit no longer breaks other scripts * Fix fadeScreen having an uninitialized ID --- src/lua_hud.h | 3 ++ src/lua_hudlib.c | 36 ++++++++++++++++++---- src/lua_hudlib_drawlist.c | 63 +++++++++++++++++++++++++-------------- 3 files changed, 73 insertions(+), 29 deletions(-) diff --git a/src/lua_hud.h b/src/lua_hud.h index 8601192b6..ccaed738d 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -41,9 +41,12 @@ enum hud { }; extern boolean hud_running; + +extern boolean hud_interpolate; extern UINT8 hud_interptag; extern UINT32 hud_interpcounter; extern boolean hud_interpstring; +extern boolean hud_interplatch; boolean LUA_HudEnabled(enum hud option); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 62aa30c37..bceb9ebc4 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -32,9 +32,12 @@ #define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!"); boolean hud_running = false; + +boolean hud_interpolate = false; UINT8 hud_interptag = 0; UINT32 hud_interpcounter = 0; boolean hud_interpstring = false; +boolean hud_interplatch = false; static UINT8 hud_enabled[(hud_MAX/8)+1]; static UINT8 hudAvailable; // hud hooks field @@ -1184,14 +1187,35 @@ static int libd_getDrawInfo(lua_State *L) static int libd_interpolate(lua_State *L) { HUDONLY - hud_interptag = luaL_checkinteger(L, 1); + + // do type checking even if interpolation is disabled + boolean newinterpolate; + UINT8 newtag; + + if (lua_isnumber(L, 1)) + { + newinterpolate = true; + newtag = luaL_checkinteger(L, 1); + } + else + { + newinterpolate = luaL_checkboolean(L, 1); + newtag = 0; + } + + if (!cv_uncappedhud.value) + return 0; + + hud_interpolate = newinterpolate; + hud_interptag = newtag; + return 0; } static int libd_interpString(lua_State *L) { HUDONLY - hud_interpstring = luaL_checkboolean(L, 1); + hud_interpstring = hud_interplatch = luaL_checkboolean(L, 1); return 0; } @@ -1460,7 +1484,7 @@ void LUAh_GameHUD(huddrawlist_h list) hud_interpcounter = 0; lua_pushnil(gL); while (lua_next(gL, -5) != 0) { - hud_interptag = 0; + hud_interpolate = hud_interpstring = hud_interplatch = false; hud_interpcounter++; lua_pushvalue(gL, -5); // graphics library (HUD[1]) lua_pushvalue(gL, -5); // stplyr @@ -1498,7 +1522,7 @@ void LUAh_ScoresHUD(huddrawlist_h list) lua_pushnil(gL); hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { - hud_interptag = 0; + hud_interpolate = hud_interpstring = hud_interplatch = false; hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); @@ -1534,7 +1558,7 @@ void LUAh_IntermissionHUD(huddrawlist_h list) lua_pushnil(gL); hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { - hud_interptag = 0; + hud_interpolate = hud_interpstring = hud_interplatch = false; hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); @@ -1570,7 +1594,7 @@ void LUAh_VoteHUD(huddrawlist_h list) lua_pushnil(gL); hud_interpcounter = 0; while (lua_next(gL, -3) != 0) { - hud_interptag = 0; + hud_interpolate = hud_interpstring = hud_interplatch = false; hud_interpcounter++; lua_pushvalue(gL, -3); // graphics library (HUD[1]) LUA_Call(gL, 1, 0, 1); diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 8aaaa67ff..65e6cef42 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -306,13 +306,27 @@ static void CalcFillCoords(drawitem_t *item) } } -// leave bit 0 free for the string mode #define INTERP_LATCH 1 +#define INTERP_STRING 2 -#define GETITEMID \ - item->id = hud_interptag \ - ? (((UINT64)gL->savedpc << 32) | (hud_interpcounter << 9) | (hud_interptag << 1) | (hud_interpstring ? INTERP_LATCH : 0)) \ - : 0; +static UINT64 GetItemId(void) +{ + if (!hud_interpolate) + return 0; + + // leave bits 0 and 1 free for the string mode + UINT64 id = ((UINT64)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2); + + if (hud_interplatch) + { + id |= INTERP_LATCH; + hud_interplatch = false; + } + if (hud_interpstring) + id |= INTERP_STRING; + + return id; +} void LUA_HUD_AddDraw( huddrawlist_h list, @@ -325,7 +339,7 @@ void LUA_HUD_AddDraw( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_Draw; item->x = x << FRACBITS; item->y = y << FRACBITS; @@ -346,7 +360,7 @@ void LUA_HUD_AddDrawScaled( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawScaled; item->x = x; item->y = y; @@ -369,7 +383,7 @@ void LUA_HUD_AddDrawStretched( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawStretched; item->x = x; item->y = y; @@ -390,7 +404,7 @@ void LUA_HUD_AddDrawNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawNum; item->x = x; item->y = y; @@ -409,7 +423,7 @@ void LUA_HUD_AddDrawPaddedNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawPaddedNum; item->x = x; item->y = y; @@ -429,7 +443,7 @@ void LUA_HUD_AddDrawPingNum( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawPingNum; item->x = x; item->y = y; @@ -449,7 +463,7 @@ void LUA_HUD_AddDrawFill( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawFill; item->x = x; item->y = y; @@ -470,7 +484,7 @@ void LUA_HUD_AddDrawString( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawString; item->x = x; item->y = y; @@ -490,7 +504,7 @@ void LUA_HUD_AddDrawKartString( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawKartString; item->x = x; item->y = y; @@ -508,7 +522,7 @@ void LUA_HUD_AddDrawLevelTitle( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; - GETITEMID + item->id = GetItemId(); item->type = DI_DrawLevelTitle; item->x = x; item->y = y; @@ -524,6 +538,8 @@ void LUA_HUD_AddFadeScreen( { size_t i = AllocateDrawItem(list); drawitem_t *item = &list->items[i]; + // nothing to interpolate here + item->id = 0; item->type = DI_FadeScreen; item->color = color; item->strength = strength; @@ -548,7 +564,7 @@ void LUA_HUD_DrawList(huddrawlist_h list) drawitem_t *olditem = NULL; const char *itemstr = &list->strbuf[item->stroffset]; - if (item->id && cv_uncappedhud.value) { + if (item->id) { // find the old one too // this is kinda cursed... we need to check every item // but stop when the first-checked item is reached again @@ -568,13 +584,11 @@ void LUA_HUD_DrawList(huddrawlist_h list) // gotcha! olditem = old; if (item->id & INTERP_LATCH) { - if (!latchitem) { - lerpx = FixedMul(frac, item->x - olditem->x); - lerpy = FixedMul(frac, item->y - olditem->y); - latchitem = item; - oldlatchitem = olditem; - } - } else { + lerpx = FixedMul(frac, item->x - olditem->x); + lerpy = FixedMul(frac, item->y - olditem->y); + latchitem = item; + oldlatchitem = olditem; + } else if (!(item->id & INTERP_STRING)) { lerpx = FixedMul(frac, item->x - olditem->x); lerpy = FixedMul(frac, item->y - olditem->y); latchitem = NULL; @@ -584,6 +598,9 @@ void LUA_HUD_DrawList(huddrawlist_h list) if (j == stop) break; } + } else { + lerpx = lerpy = 0; + latchitem = NULL; } #define LERP(it) (olditem ? olditem->it + FixedMul(frac, item->it - olditem->it) : item->it) From 60e42472e32679b025615bc8257e2a9bf0f43386 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:00:54 +0200 Subject: [PATCH 06/91] Do string coordinate calcs on all functions (and fix) --- src/lua_hudlib_drawlist.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 65e6cef42..4a58371c8 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -196,7 +196,7 @@ static size_t CopyString(huddrawlist_h list, const char* str) } } -static void CalcCoords(huddrawlist_h list, drawitem_t *item) +static void CalcStringCoords(drawitem_t *item, const char *string) { if (!(item->flags & V_NOSCALESTART) && cv_uncappedhud.value) { @@ -228,6 +228,12 @@ static void CalcCoords(huddrawlist_h list, drawitem_t *item) INT32 x = item->x * dupx; INT32 y = item->y * dupy; + if (item->flags & V_SPLITSCREEN) + y += (BASEVIDHEIGHT * (dupy - 1))/2; + + if (item->flags & V_HORZSCREEN) + x += (BASEVIDWIDTH * (dupx - 1))/2; + if (vid.width != BASEVIDWIDTH * dupx) { // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, @@ -251,13 +257,17 @@ static void CalcCoords(huddrawlist_h list, drawitem_t *item) } // need to compensate for dup here - - if (item->align == align_center) - x -= (V_StringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1))/2; - if (item->align == align_right) - x -= V_StringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1); - if (item->align == align_thinright) - x -= V_ThinStringWidth(&list->strbuf[item->stroffset], item->flags) * (dupx - 1); + if (item->type == DI_DrawString) + { + if (item->align == align_center) + x -= (V_StringWidth(string, item->flags) * (dupx - 1))/2; + if (item->align == align_right) + x -= V_StringWidth(string, item->flags) * (dupx - 1); + if (item->align == align_smallright) + x -= V_SmallStringWidth(string, item->flags) * (dupx - 1); + if (item->align == align_thinright) + x -= V_ThinStringWidth(string, item->flags) * (dupx - 1); + } item->x = x; item->y = y; @@ -410,6 +420,7 @@ void LUA_HUD_AddDrawNum( item->y = y; item->num = num; item->flags = flags; + CalcStringCoords(item, NULL); } void LUA_HUD_AddDrawPaddedNum( @@ -430,6 +441,7 @@ void LUA_HUD_AddDrawPaddedNum( item->num = num; item->digits = digits; item->flags = flags; + CalcStringCoords(item, NULL); } void LUA_HUD_AddDrawPingNum( @@ -450,6 +462,7 @@ void LUA_HUD_AddDrawPingNum( item->num = num; item->flags = flags; item->colormap = colormap; + CalcStringCoords(item, NULL); } void LUA_HUD_AddDrawFill( @@ -491,7 +504,8 @@ void LUA_HUD_AddDrawString( item->stroffset = CopyString(list, str); item->flags = flags; item->align = align; - CalcCoords(list, item); + if (item->align != align_fixed) + CalcStringCoords(item, str); } void LUA_HUD_AddDrawKartString( @@ -510,6 +524,7 @@ void LUA_HUD_AddDrawKartString( item->y = y; item->stroffset = CopyString(list, str); item->flags = flags; + CalcStringCoords(item, str); } void LUA_HUD_AddDrawLevelTitle( @@ -528,6 +543,7 @@ void LUA_HUD_AddDrawLevelTitle( item->y = y; item->stroffset = CopyString(list, str); item->flags = flags; + CalcStringCoords(item, str); } void LUA_HUD_AddFadeScreen( From 995777c676657f45b0db2b5d158edc63a9b070cd Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:36:23 +0200 Subject: [PATCH 07/91] Exclude string mode flags from olditem search --- src/lua_hudlib_drawlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 4a58371c8..c621512ba 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -595,7 +595,7 @@ void LUA_HUD_DrawList(huddrawlist_h list) break; } drawitem_t *old = &list->olditems[j++]; - if (old->id == item->id) + if ((old->id & ~3) == (item->id & ~3)) { // gotcha! olditem = old; From 1abf6a4ce1302d46073c28c8b97cecee8e19962a Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Tue, 23 Apr 2024 21:17:06 +0200 Subject: [PATCH 08/91] Add interpolation docs to LUASTUFF --- LUASTUFF.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/LUASTUFF.md b/LUASTUFF.md index 05ca33bd0..96df6b5f8 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -52,6 +52,45 @@ Returns the displayplayer's HUD color. Returns true if colorization is enabled, false otherwise. +## v.interpolate(true) + +Enables HUD interpolation. Each call to a drawing function will have its coordinates interpolated +by assigning an unique ID to every call. +For example, three successive calls to `v.draw` will each have their own ID and interpolation offsets. +Pass `true` to enable interpolation, `false` to disable. + +Alternatively, pass a number to enable interpolation with the specified tag. +Tags allow HUD items drawn by the same call to a drawing function to be differentiated. +Valid tags range from 0-255. +For example, when iterating players, use a unique tag for each player to avoid artifacting: +```lua +for p in players.iterate do + -- enable interpolation, using player numbers as the tag + -- every draw will have different interp offsets per player + v.interpolate(#p) + + -- doesn't matter for unconditional draws like this one... + v.draw(...) + + -- but it does matter if there's a condition! + -- without tags, this patch would warp between players + -- whenever their `someVar` changes + if p.someVar then v.draw(...) end +end + +-- don't want interpolation anymore? then disable it +v.interpolate(false) +``` +NOTE: The default tag for `true` is 0. + +## v.interpString(true) + +Enables string interpolation mode. The next call to a drawing function will have its interpolation offsets +latched and reused for all following draw calls. +Disable with `false` when done. + +When using a custom string drawer, enable this mode to avoid interpolation artifacting when the string changes. + ## mobj.spritexscale, mobj.spriteyscale, mobj.spritexoffset, mobj.spriteyoffset, mobj.rollangle, mobj.sloperoll, mobj.rollmodel fields Same fields as in SRB2 2.2 From 9cd1233c3224bf2000180a1ce866348c4bdd268f Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Thu, 23 May 2024 16:36:26 +0200 Subject: [PATCH 09/91] Dust this crap off a bit --- src/lua_hud.h | 10 +++++----- src/lua_hudlib_drawlist.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lua_hud.h b/src/lua_hud.h index ccaed738d..5d1f41c83 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -42,11 +42,11 @@ enum hud { extern boolean hud_running; -extern boolean hud_interpolate; -extern UINT8 hud_interptag; -extern UINT32 hud_interpcounter; -extern boolean hud_interpstring; -extern boolean hud_interplatch; +extern boolean hud_interpolate; // interpolation enabled +extern UINT8 hud_interptag; // current tag +extern UINT32 hud_interpcounter; // number of HUD hooks ran +extern boolean hud_interpstring; // string mode +extern boolean hud_interplatch; // string mode was toggled boolean LUA_HudEnabled(enum hud option); diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index c621512ba..98f0d45e7 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -318,6 +318,7 @@ static void CalcFillCoords(drawitem_t *item) #define INTERP_LATCH 1 #define INTERP_STRING 2 +#define INTERP_FLAGS 3 // all bits combined static UINT64 GetItemId(void) { @@ -325,7 +326,7 @@ static UINT64 GetItemId(void) return 0; // leave bits 0 and 1 free for the string mode - UINT64 id = ((UINT64)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2); + UINT64 id = ((uintptr_t)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2); if (hud_interplatch) { @@ -580,7 +581,8 @@ void LUA_HUD_DrawList(huddrawlist_h list) drawitem_t *olditem = NULL; const char *itemstr = &list->strbuf[item->stroffset]; - if (item->id) { + if (item->id) + { // find the old one too // this is kinda cursed... we need to check every item // but stop when the first-checked item is reached again @@ -595,16 +597,19 @@ void LUA_HUD_DrawList(huddrawlist_h list) break; } drawitem_t *old = &list->olditems[j++]; - if ((old->id & ~3) == (item->id & ~3)) + if ((old->id & ~INTERP_FLAGS) == (item->id & ~INTERP_FLAGS)) // don't include flags in search { // gotcha! olditem = old; - if (item->id & INTERP_LATCH) { + if (item->id & INTERP_LATCH) + { lerpx = FixedMul(frac, item->x - olditem->x); lerpy = FixedMul(frac, item->y - olditem->y); latchitem = item; oldlatchitem = olditem; - } else if (!(item->id & INTERP_STRING)) { + } + else if (!(item->id & INTERP_STRING)) + { lerpx = FixedMul(frac, item->x - olditem->x); lerpy = FixedMul(frac, item->y - olditem->y); latchitem = NULL; @@ -614,7 +619,9 @@ void LUA_HUD_DrawList(huddrawlist_h list) if (j == stop) break; } - } else { + } + else + { lerpx = lerpy = 0; latchitem = NULL; } From a17a5387ff294d0a0a8916f8f97be508d2f6aec7 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Sat, 25 May 2024 14:08:52 +0200 Subject: [PATCH 10/91] Rename interpString to interpLatch --- src/lua_hudlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index bceb9ebc4..bc56e6688 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1212,7 +1212,7 @@ static int libd_interpolate(lua_State *L) return 0; } -static int libd_interpString(lua_State *L) +static int libd_interpLatch(lua_State *L) { HUDONLY hud_interpstring = hud_interplatch = luaL_checkboolean(L, 1); @@ -1247,7 +1247,7 @@ static luaL_Reg lib_draw[] = { {"getHudColor", libd_getHudColor}, {"useColorHud", libd_useColorHud}, {"interpolate", libd_interpolate}, - {"interpString", libd_interpString}, + {"interpLatch", libd_interpLatch}, {NULL, NULL} }; From 142c01f516f839d48e292ff115203b3b8f0677c0 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Sat, 25 May 2024 14:09:20 +0200 Subject: [PATCH 11/91] Update docs for interpLatch --- LUASTUFF.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/LUASTUFF.md b/LUASTUFF.md index 96df6b5f8..79e2a2545 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -83,12 +83,37 @@ v.interpolate(false) ``` NOTE: The default tag for `true` is 0. -## v.interpString(true) +## v.interpLatch(true) -Enables string interpolation mode. The next call to a drawing function will have its interpolation offsets -latched and reused for all following draw calls. -Disable with `false` when done. +Enables interpolation offset latching. The next call to a drawing function will have its lerp offsets +saved and reused for all following draw calls. Disable with `false` when done. +Interpolation cannot easily "snap" between two points; latching can help overcome this by manually +setting the lerp offsets. +```lua +v.interpolate(true) +-- X coordinate for the HUD item +-- every so often, this will wrap around to zero +local x = (leveltime*4) % 256 + +-- draw an interpolated patch, but... when X rolls back to zero, +-- the patch will slide all the way across the screen! +v.draw(x, 100, ...) + +-- this is where interpLatch comes into play +-- enable latching, then draw an invisible patch, +-- moving at the same speed as the visible patch +-- the exact coordinates don't matter, it just has to move at the right speed +v.interpLatch(true) +v.draw(leveltime*4, 0, v.cachePatch("K_TRNULL")) + +-- now we can draw the patch again, and when X becomes zero, +-- it'll snap right back without sliding across the screen +v.draw(x, 150, ...) + +-- don't forget to turn off latching! +v.interpLatch(false) +``` When using a custom string drawer, enable this mode to avoid interpolation artifacting when the string changes. ## mobj.spritexscale, mobj.spriteyscale, mobj.spritexoffset, mobj.spriteyoffset, mobj.rollangle, mobj.sloperoll, mobj.rollmodel fields From b310168c126c6437ada26ab20ce0061b63827486 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 25 May 2024 16:39:16 +0300 Subject: [PATCH 12/91] Store hooks in a table with integer keys instead of registry with string keys --- src/lua_hooklib.c | 423 +++++++++++++++++++++++++++++----------------- 1 file changed, 271 insertions(+), 152 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index a1ea4fdaf..d7f89bffd 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -86,8 +86,6 @@ struct hook_s }; typedef struct hook_s* hook_p; -#define FMT_HOOKID "hook_%d" - // For each mobj type, a linked list to its thinker and collision hooks. // That way, we don't have to iterate through all the hooks. // We could do that with all other mobj hooks, but it would probably just be @@ -237,9 +235,9 @@ static int lib_addHook(lua_State *L) *lastp = hookp; // set the hook function in the registry. - lua_pushfstring(L, FMT_HOOKID, hook.id); + lua_getfield(L, LUA_REGISTRYINDEX, "hooks"); lua_pushvalue(L, 1); - lua_settable(L, LUA_REGISTRYINDEX); + lua_rawseti(L, -2, hook.id); return 0; } @@ -248,6 +246,10 @@ int LUA_HookLib(lua_State *L) memset(hooksAvailable,0,sizeof(UINT8[(hook_MAX/8)+1])); roothook = NULL; lua_register(L, "addHook", lib_addHook); + + lua_newtable(L); + lua_setfield(L, LUA_REGISTRYINDEX, "hooks"); + return 0; } @@ -255,26 +257,30 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[which/8] & (1<<(which%8)))) return false; I_Assert(mo->type < NUMMOBJTYPES); - + if (!(mobjhooks[MT_NULL] || mobjhooks[mo->type])) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic mobj hooks for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == which) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) LUA_PushUserdata(gL, mo, META_MOBJ); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 1, 1)) { if (!hookp->error || cv_debug & DBG_LUA) @@ -292,10 +298,9 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which) if (hookp->type == which) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) LUA_PushUserdata(gL, mo, META_MOBJ); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 1, 1)) { if (!hookp->error || cv_debug & DBG_LUA) @@ -317,20 +322,24 @@ boolean LUAh_PlayerHook(player_t *plr, enum hook which) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[which/8] & (1<<(which%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = playerhooks; hookp; hookp = hookp->next) if (hookp->type == which) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) LUA_PushUserdata(gL, plr, META_PLAYER); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 1, 1)) { if (!hookp->error || cv_debug & DBG_LUA) @@ -352,25 +361,30 @@ boolean LUAh_PlayerHook(player_t *plr, enum hook which) void LUAh_MapChange(INT16 mapnumber) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MapChange/8] & (1<<(hook_MapChange%8)))) return; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + lua_pushinteger(gL, mapnumber); for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_MapChange) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 0, 1)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } } - + lua_settop(gL, 0); } @@ -378,22 +392,27 @@ void LUAh_MapChange(INT16 mapnumber) void LUAh_MapLoad(void) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MapLoad/8] & (1<<(hook_MapLoad%8)))) return; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + lua_pushinteger(gL, gamemap); for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_MapLoad) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 0, 1)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } } lua_settop(gL, 0); @@ -403,25 +422,30 @@ void LUAh_MapLoad(void) void LUAh_PlayerJoin(int playernum) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerJoin/8] & (1<<(hook_PlayerJoin%8)))) return; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + lua_pushinteger(gL, playernum); for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerJoin) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 0, 1)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } } - + lua_settop(gL, 0); } @@ -429,22 +453,26 @@ void LUAh_PlayerJoin(int playernum) void LUAh_PreThinkFrame(void) { hook_p hookp; + int HOOKSINDEX; // variables used by perf stats int hook_index = 0; precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8)))) return; - + lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) { if (hookp->type == hook_PreThinkFrame) - { + { if (cv_perfstats.value == 4) time_taken = I_GetPreciseTime(); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); if (lua_pcall(gL, 0, 0, 1)) { if (!hookp->error || cv_debug & DBG_LUA) CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); @@ -456,22 +484,22 @@ void LUAh_PreThinkFrame(void) lua_Debug ar; time_taken = I_GetPreciseTime() - time_taken; // we need the function, let's just retrieve it again - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_getinfo(gL, ">S", &ar); PS_SetPreThinkFrameHookInfo(hook_index, time_taken, ar.short_src); hook_index++; } } - + } - lua_pop(gL, 1); // Pop error handler + lua_pop(gL, 2); // Pop error handler and hooks table } // Hook for frame (after mobj and player thinkers) void LUAh_ThinkFrame(void) { hook_p hookp; + int HOOKSINDEX; // variables used by perf stats int hook_index = 0; precise_t time_taken = 0; @@ -481,14 +509,17 @@ void LUAh_ThinkFrame(void) lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) { if (hookp->type == hook_ThinkFrame) { if (cv_perfstats.value == 3) time_taken = I_GetPreciseTime(); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); if (lua_pcall(gL, 0, 0, 1)) { if (!hookp->error || cv_debug & DBG_LUA) CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); @@ -500,8 +531,7 @@ void LUAh_ThinkFrame(void) lua_Debug ar; time_taken = I_GetPreciseTime() - time_taken; // we need the function, let's just retrieve it again - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_getinfo(gL, ">S", &ar); PS_SetThinkFrameHookInfo(hook_index, time_taken, ar.short_src); hook_index++; @@ -509,13 +539,14 @@ void LUAh_ThinkFrame(void) } } - lua_pop(gL, 1); // Pop error handler + lua_pop(gL, 2); // Pop error handler and hooks table } // Hook for frame (at end of tick, ie after overlays, precipitation, specials) void LUAh_PostThinkFrame(void) { hook_p hookp; + int HOOKSINDEX; // variables used by perf stats int hook_index = 0; precise_t time_taken = 0; @@ -524,14 +555,17 @@ void LUAh_PostThinkFrame(void) lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) { if (hookp->type == hook_PostThinkFrame) { if (cv_perfstats.value == 5) time_taken = I_GetPreciseTime(); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); if (lua_pcall(gL, 0, 0, 1)) { if (!hookp->error || cv_debug & DBG_LUA) CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); @@ -543,8 +577,7 @@ void LUAh_PostThinkFrame(void) lua_Debug ar; time_taken = I_GetPreciseTime() - time_taken; // we need the function, let's just retrieve it again - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_getinfo(gL, ">S", &ar); PS_SetPostThinkFrameHookInfo(hook_index, time_taken, ar.short_src); hook_index++; @@ -552,25 +585,29 @@ void LUAh_PostThinkFrame(void) } } - lua_pop(gL, 1); // Pop error handler + lua_pop(gL, 2); // Pop error handler and hooks table } // Hook for Y_Ticker void LUAh_IntermissionThinker(void) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_IntermissionThinker/8] & (1<<(hook_IntermissionThinker%8)))) return; - lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_pushcfunction(gL, LUA_GetErrorMessage);; + + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); for (hookp = roothook; hookp; hookp = hookp->next) { if (hookp->type == hook_IntermissionThinker) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); if (lua_pcall(gL, 0, 0, 1)) { if (!hookp->error || cv_debug & DBG_LUA) CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); @@ -580,25 +617,29 @@ void LUAh_IntermissionThinker(void) } } - lua_pop(gL, 1); // Pop error handler + lua_pop(gL, 2); // Pop error handler and hooks table } // Hook for Y_VoteTicker void LUAh_VoteThinker(void) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_VoteThinker/8] & (1<<(hook_VoteThinker%8)))) return; lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) { if (hookp->type == hook_VoteThinker) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); if (lua_pcall(gL, 0, 0, 1)) { if (!hookp->error || cv_debug & DBG_LUA) CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); @@ -608,7 +649,7 @@ void LUAh_VoteThinker(void) } } - lua_pop(gL, 1); // Pop error handler + lua_pop(gL, 2); // Pop error handler and hooks table } @@ -617,29 +658,33 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) { hook_p hookp; UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no. + int HOOKSINDEX; if (!gL || !(hooksAvailable[which/8] & (1<<(which%8)))) return 0; I_Assert(thing1->type < NUMMOBJTYPES); - + if (!(mobjcollidehooks[MT_NULL] || mobjcollidehooks[thing1->type])) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic mobj collision hooks for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == which) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, thing1, META_MOBJ); LUA_PushUserdata(gL, thing2, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -663,13 +708,12 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which) if (hookp->type == which) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, thing1, META_MOBJ); LUA_PushUserdata(gL, thing2, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -698,25 +742,29 @@ boolean LUAh_MobjThinker(mobj_t *mo) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MobjThinker/8] & (1<<(hook_MobjThinker%8)))) return false; I_Assert(mo->type < NUMMOBJTYPES); - + if (!(mobjthinkerhooks[MT_NULL] || mobjthinkerhooks[mo->type])) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic mobj thinker hooks for (hookp = mobjthinkerhooks[MT_NULL]; hookp; hookp = hookp->next) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) LUA_PushUserdata(gL, mo, META_MOBJ); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 1, 1)) { if (!hookp->error || cv_debug & DBG_LUA) @@ -733,10 +781,9 @@ boolean LUAh_MobjThinker(mobj_t *mo) for (hookp = mobjthinkerhooks[mo->type]; hookp; hookp = hookp->next) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) LUA_PushUserdata(gL, mo, META_MOBJ); - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); if (lua_pcall(gL, 1, 1, 1)) { if (!hookp->error || cv_debug & DBG_LUA) @@ -759,29 +806,33 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_TouchSpecial/8] & (1<<(hook_TouchSpecial%8)))) return false; I_Assert(special->type < NUMMOBJTYPES); - - if (!(mobjhooks[MT_NULL] || mobjhooks[special->type])) + + if (!(mobjhooks[MT_NULL] || mobjhooks[special->type])) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic touch special hooks for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_TouchSpecial) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, special, META_MOBJ); LUA_PushUserdata(gL, toucher, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -800,13 +851,12 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher) if (hookp->type == hook_TouchSpecial) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, special, META_MOBJ); LUA_PushUserdata(gL, toucher, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -830,31 +880,35 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 { hook_p hookp; UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no. + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_ShouldDamage/8] & (1<<(hook_ShouldDamage%8)))) return 0; I_Assert(target->type < NUMMOBJTYPES); - + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic should damage hooks for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldDamage) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); lua_pushinteger(gL, damage); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); @@ -880,15 +934,14 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 if (hookp->type == hook_ShouldDamage) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); lua_pushinteger(gL, damage); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); @@ -919,31 +972,35 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MobjDamage/8] & (1<<(hook_MobjDamage%8)))) return false; I_Assert(target->type < NUMMOBJTYPES); - + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic mobj damage hooks for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_MobjDamage) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); lua_pushinteger(gL, damage); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); @@ -964,15 +1021,14 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 if (hookp->type == hook_MobjDamage) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); lua_pushinteger(gL, damage); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); lua_pushvalue(gL, -5); @@ -998,29 +1054,33 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MobjDeath/8] & (1<<(hook_MobjDeath%8)))) return false; I_Assert(target->type < NUMMOBJTYPES); - + if (!(mobjhooks[MT_NULL] || mobjhooks[target->type])) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // Look for all generic mobj death hooks for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next) if (hookp->type == hook_MobjDeath) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1040,14 +1100,13 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source) if (hookp->type == hook_MobjDeath) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1072,22 +1131,26 @@ boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_BotTiccmd/8] & (1<<(hook_BotTiccmd%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_BotTiccmd) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, bot, META_PLAYER); LUA_PushUserdata(gL, cmd, META_TICCMD); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -1112,23 +1175,27 @@ boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerCmd/8] & (1<<(hook_PlayerCmd%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + hook_cmd_running = true; for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerCmd) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, cmd, META_TICCMD); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 1, 1)) { @@ -1153,23 +1220,27 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_BotAI/8] & (1<<(hook_BotAI%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_BotAI && (hookp->s.skinname == NULL || !strcmp(hookp->s.skinname, ((skin_t*)tails->skin)->name))) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, sonic, META_MOBJ); LUA_PushUserdata(gL, tails, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 8, 1)) { @@ -1181,10 +1252,10 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) } // This turns forward, backward, left, right, jump, and spin into a proper ticcmd for tails. - if (lua_istable(gL, 2+1)) { + if (lua_istable(gL, -8)) { boolean forward=false, backward=false, left=false, right=false, strafeleft=false, straferight=false, jump=false, spin=false; #define CHECKFIELD(field) \ - lua_getfield(gL, 2+1, #field);\ + lua_getfield(gL, -8, #field);\ if (lua_toboolean(gL, -1))\ field = true;\ lua_pop(gL, 1); @@ -1200,7 +1271,7 @@ boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) #undef CHECKFIELD B_KeysToTiccmd(tails, cmd, forward, backward, left, right, strafeleft, straferight, jump, spin); } else - B_KeysToTiccmd(tails, cmd, lua_toboolean(gL, 2+1), lua_toboolean(gL, 2+2), lua_toboolean(gL, 2+3), lua_toboolean(gL, 2+4), lua_toboolean(gL, 2+5), lua_toboolean(gL, 2+6), lua_toboolean(gL, 2+7), lua_toboolean(gL, 2+8)); + B_KeysToTiccmd(tails, cmd, lua_toboolean(gL, -8), lua_toboolean(gL, -7), lua_toboolean(gL, -6), lua_toboolean(gL, -5), lua_toboolean(gL, -4), lua_toboolean(gL, -3), lua_toboolean(gL, -2), lua_toboolean(gL, -1)); lua_pop(gL, 8); hooked = true; @@ -1215,30 +1286,34 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_LinedefExecute/8] & (1<<(hook_LinedefExecute%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next) if (!strcmp(hookp->s.funcname, line->text)) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, line, META_LINE); LUA_PushUserdata(gL, mo, META_MOBJ); LUA_PushUserdata(gL, sector, META_SECTOR); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); if (lua_pcall(gL, 3, 0, 1)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } hooked = true; } @@ -1254,16 +1329,21 @@ boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerMsg/8] & (1<<(hook_PlayerMsg%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerMsg) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player if (flags & 2 /*HU_CSAY*/) { // csay TODO: make HU_CSAY accessible outside hu_stuff.c @@ -1285,8 +1365,7 @@ boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg, int mute) else lua_pushboolean(gL, false); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -6); lua_pushvalue(gL, -6); lua_pushvalue(gL, -6); @@ -1313,24 +1392,28 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_HurtMsg/8] & (1<<(hook_HurtMsg%8)))) return false; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_HurtMsg && (hookp->s.mt == MT_NULL || (inflictor && hookp->s.mt == inflictor->type))) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1354,61 +1437,69 @@ void LUAh_NetArchiveHook(lua_CFunction archFunc) { hook_p hookp; int errorhandlerindex; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_NetVars/8] & (1<<(hook_NetVars%8)))) return; // stack: tables I_Assert(lua_gettop(gL) > 0); I_Assert(lua_istable(gL, -1)); - + lua_pushcfunction(gL, LUA_GetErrorMessage); errorhandlerindex = lua_gettop(gL); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // tables becomes an upvalue of archFunc - lua_pushvalue(gL, -2); + lua_pushvalue(gL, -3); lua_pushcclosure(gL, archFunc, 1); // stack: tables, archFunc for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_NetVars) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -2); // archFunc if (lua_pcall(gL, 1, 0, errorhandlerindex)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } } - lua_pop(gL, 2); // Pop archFunc and error handler + lua_pop(gL, 3); // Pop archFunc, error handler and hooks table // stack: tables } void LUAh_PlayerQuit(player_t *plr, int reason) { hook_p hookp; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8)))) return; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerQuit) { - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit lua_pushinteger(gL, reason); // Reason for quitting } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -3); lua_pushvalue(gL, -3); if (lua_pcall(gL, 2, 0, 1)) { - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); } } @@ -1421,6 +1512,7 @@ boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boo { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_MusicChange/8] & (1<<(hook_MusicChange%8)))) return false; @@ -1428,11 +1520,14 @@ boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boo lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_MusicChange) { - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushstring(gL, oldname); lua_pushstring(gL, newname); lua_pushinteger(gL, *mflags); @@ -1480,26 +1575,30 @@ UINT8 LUAh_ShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no. + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_ShouldSpin/8] & (1<<(hook_ShouldSpin%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to check for mobj type because it will always be MT_PLAYER in this case. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldSpin) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1529,26 +1628,30 @@ UINT8 LUAh_ShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no. + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_ShouldExplode/8] & (1<<(hook_ShouldExplode%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to check for mobj type because it will always be MT_PLAYER in this case. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldExplode) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1578,26 +1681,30 @@ UINT8 LUAh_ShouldSquish(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no. + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_ShouldSquish/8] & (1<<(hook_ShouldSquish%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to check for mobj type because it will always be MT_PLAYER in this case. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_ShouldSquish) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1627,26 +1734,30 @@ boolean LUAh_PlayerSpin(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerSpin/8] & (1<<(hook_PlayerSpin%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to look for target->type because it will always be MT_PLAYER. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerSpin) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1670,26 +1781,30 @@ boolean LUAh_PlayerSquish(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerSquish/8] & (1<<(hook_PlayerSquish%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to look for target->type because it will always be MT_PLAYER. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerSquish) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1713,26 +1828,30 @@ boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source) { hook_p hookp; boolean hooked = false; + int HOOKSINDEX; if (!gL || !(hooksAvailable[hook_PlayerExplode/8] & (1<<(hook_PlayerExplode%8)))) return 0; lua_settop(gL, 0); lua_pushcfunction(gL, LUA_GetErrorMessage); + lua_getfield(gL, LUA_REGISTRYINDEX, "hooks"); + HOOKSINDEX = lua_gettop(gL); + I_Assert(lua_istable(L, HOOKSINDEX)); + // We can afford not to look for target->type because it will always be MT_PLAYER. for (hookp = roothook; hookp; hookp = hookp->next) if (hookp->type == hook_PlayerExplode) { ps_lua_mobjhooks.value.i++; - if (lua_gettop(gL) == 1) + if (lua_gettop(gL) == 2) { LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, inflictor, META_MOBJ); LUA_PushUserdata(gL, source, META_MOBJ); } - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); + lua_rawgeti(gL, HOOKSINDEX, hookp->id); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); lua_pushvalue(gL, -4); @@ -1749,4 +1868,4 @@ boolean LUAh_PlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *source) } lua_settop(gL, 0); return hooked; -} \ No newline at end of file +} From 05a56512606ce4c1e04b4fea0075aa2dd71bcf41 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Sat, 25 May 2024 17:05:08 +0200 Subject: [PATCH 13/91] Finishing touches Some cleanup, also interpolate drawfill size (dunno why it wasn't before) --- src/lua_hudlib_drawlist.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 98f0d45e7..ff98c6e8b 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -318,7 +318,7 @@ static void CalcFillCoords(drawitem_t *item) #define INTERP_LATCH 1 #define INTERP_STRING 2 -#define INTERP_FLAGS 3 // all bits combined +#define INTERP_FLAGMASK 0x3 static UINT64 GetItemId(void) { @@ -587,17 +587,15 @@ void LUA_HUD_DrawList(huddrawlist_h list) // this is kinda cursed... we need to check every item // but stop when the first-checked item is reached again size_t stop = j; - while(true) + do { if (j == list->olditems_len) { - // wrap around j = 0; - if (j == stop) // i'm dumb - break; + continue; } drawitem_t *old = &list->olditems[j++]; - if ((old->id & ~INTERP_FLAGS) == (item->id & ~INTERP_FLAGS)) // don't include flags in search + if ((old->id & ~INTERP_FLAGMASK) == (item->id & ~INTERP_FLAGMASK)) { // gotcha! olditem = old; @@ -616,9 +614,8 @@ void LUA_HUD_DrawList(huddrawlist_h list) } break; } - if (j == stop) - break; } + while (j != stop); } else { @@ -653,7 +650,7 @@ void LUA_HUD_DrawList(huddrawlist_h list) V_DrawPingNum(LERPS(x), LERPS(y), item->flags, item->num, item->colormap); break; case DI_DrawFill: - V_DrawFill(LERPS(x), LERPS(y), item->w, item->h, item->c); + V_DrawFill(LERPS(x), LERPS(y), LERP(w), LERP(h), item->c); break; case DI_DrawString: switch(item->align) From ddddc7a89804e3c3fe1cf2732ff3d2bacc63a9d5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 00:52:09 +0200 Subject: [PATCH 14/91] draw a black screen instead of "nothing" during wipes on disabled screentextures should resolve the intense flashing that can occur --- src/hardware/hw_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 0a922bbf3..d2a5b8189 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6247,6 +6247,12 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) lumpnum_t lumpnum; size_t lsize; + if (cv_grscreentextures.value == 0) + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap + return; + } + if (wipenum > 99 || scrnnum > 99) // not a valid wipe number return; // shouldn't end up here really, the loop should've stopped running beforehand From 67aa71170fea7b5a7f006a589b02b5cb4bf8bce2 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 00:52:40 +0200 Subject: [PATCH 15/91] when not using screentextures draw kart bg on intermission screen --- src/hardware/hw_main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d2a5b8189..fc137c109 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6238,7 +6238,12 @@ void HWR_EndScreenWipe(void) void HWR_DrawIntermissionBG(void) { - HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); + patch_t *bgpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + + if (cv_grscreentextures.value != 3) + V_DrawPatchFill(bgpatch); // use the neato kart bg for intermission on disabled screen textures + else + HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) From 086d0113c5bbd58aaccaddcb487f7ee7cde1c347 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 27 May 2024 18:14:59 +0200 Subject: [PATCH 16/91] Optimize field lookups in Lua metatables https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2024#cd5b5ee262bf5129c4d400ad60d006e1fa917c1f --- src/lua_consolelib.c | 56 ++++++++-- src/lua_hudlib.c | 12 ++- src/lua_infolib.c | 231 ++++++++++++++++++++++++++++++----------- src/lua_maplib.c | 238 ++++++++++++++++++++++++++++++++++--------- src/lua_mobjlib.c | 148 ++++++++++++++++++--------- src/lua_playerlib.c | 83 +++++++++++---- src/lua_script.c | 37 +++++-- src/lua_script.h | 4 +- src/lua_skinlib.c | 7 +- 9 files changed, 622 insertions(+), 194 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 7d9cd67ec..ad1df2b22 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -580,27 +580,59 @@ static luaL_Reg lib[] = { {NULL, NULL} }; +enum cvar_e +{ + cvar_name, + cvar_defaultvalue, + cvar_flags, + cvar_value, + cvar_string, + cvar_changed, +}; + +static const char *const cvar_opt[] = { + "name", + "defaultvalue", + "flags", + "value", + "string", + "changed", + NULL, +}; + +static int cvar_fields_ref = LUA_NOREF; + static int cvar_get(lua_State *L) { consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR); - const char *field = luaL_checkstring(L, 2); + enum cvar_e field = Lua_optoption(L, 2, -1, cvar_fields_ref); - if(fastcmp(field,"name")) + switch (field) + { + case cvar_name: lua_pushstring(L, cvar->name); - else if(fastcmp(field,"defaultvalue")) + break; + case cvar_defaultvalue: lua_pushstring(L, cvar->defaultvalue); - else if(fastcmp(field,"flags")) + break; + case cvar_flags: lua_pushinteger(L, cvar->flags); - else if(fastcmp(field,"value")) + break; + case cvar_value: lua_pushinteger(L, cvar->value); - else if(fastcmp(field,"string")) + break; + case cvar_string: lua_pushstring(L, cvar->string); - else if(fastcmp(field,"changed")) + break; + case cvar_changed: lua_pushboolean(L, cvar->changed); - else if (devparm) - return luaL_error(L, LUA_QL("consvar_t") " has no field named " LUA_QS, field); - else - return 0; + break; + default: + if (devparm) + return luaL_error(L, LUA_QL("consvar_t") " has no field named " LUA_QS, field); + else + return 0; + } return 1; } @@ -612,6 +644,8 @@ int LUA_ConsoleLib(lua_State *L) lua_setfield(L, -2, "__index"); lua_pop(L,1); + cvar_fields_ref = Lua_CreateFieldTable(L, cvar_opt); + // Set empty registry tables lua_newtable(L); lua_setfield(L, LUA_REGISTRYINDEX, "COM_Command"); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index bc56e6688..0af7f2c36 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -106,6 +106,8 @@ static const char *const hudhook_opt[] = { "vote", NULL}; +static int patch_fields_ref = LUA_NOREF; + // alignment types for v.drawString enum align { align_left = 0, @@ -229,6 +231,8 @@ static const char *const hud_drawinfo_options[] = { "minimap", NULL}; +static int camera_fields_ref = LUA_NOREF; + static int lib_getHudInfo(lua_State *L) { UINT32 i; @@ -298,7 +302,7 @@ static int colormap_get(lua_State *L) static int patch_get(lua_State *L) { patch_t *patch = *((patch_t **)luaL_checkudata(L, 1, META_PATCH)); - enum patch field = luaL_checkoption(L, 2, NULL, patch_opt); + enum patch field = Lua_optoption(L, 2, -1, patch_fields_ref); // patches are CURRENTLY always valid, expected to be cached with PU_STATIC // this may change in the future, so patch.valid still exists @@ -333,7 +337,7 @@ static int patch_set(lua_State *L) static int camera_get(lua_State *L) { camera_t *cam = *((camera_t **)luaL_checkudata(L, 1, META_CAMERA)); - enum cameraf field = luaL_checkoption(L, 2, NULL, camera_opt); + enum cameraf field = Lua_optoption(L, 2, -1, camera_fields_ref); // cameras should always be valid unless I'm a nutter I_Assert(cam != NULL); @@ -1439,11 +1443,15 @@ int LUA_HudLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L,1); + patch_fields_ref = Lua_CreateFieldTable(L, patch_opt); + luaL_newmetatable(L, META_CAMERA); lua_pushcfunction(L, camera_get); lua_setfield(L, -2, "__index"); lua_pop(L,1); + camera_fields_ref = Lua_CreateFieldTable(L, camera_opt); + luaL_register(L, "hud", lib_hud); return 0; } diff --git a/src/lua_infolib.c b/src/lua_infolib.c index c94b42b5b..5c6918890 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -565,75 +565,161 @@ static int lib_mobjinfolen(lua_State *L) return 1; } +enum mobjinfo_e +{ + mobjinfo_doomednum, + mobjinfo_spawnstate, + mobjinfo_spawnhealth, + mobjinfo_seestate, + mobjinfo_seesound, + mobjinfo_reactiontime, + mobjinfo_attacksound, + mobjinfo_painstate, + mobjinfo_painchance, + mobjinfo_painsound, + mobjinfo_meleestate, + mobjinfo_missilestate, + mobjinfo_deathstate, + mobjinfo_xdeathstate, + mobjinfo_deathsound, + mobjinfo_speed, + mobjinfo_radius, + mobjinfo_height, + mobjinfo_dispoffset, + mobjinfo_mass, + mobjinfo_damage, + mobjinfo_activesound, + mobjinfo_flags, + mobjinfo_raisestate, +}; + +const char *const mobjinfo_opt[] = { + "doomednum", + "spawnstate", + "spawnhealth", + "seestate", + "seesound", + "reactiontime", + "attacksound", + "painstate", + "painchance", + "painsound", + "meleestate", + "missilestate", + "deathstate", + "xdeathstate", + "deathsound", + "speed", + "radius", + "height", + "dispoffset", + "mass", + "damage", + "activesound", + "flags", + "raisestate", + NULL, +}; + +static int mobjinfo_fields_ref = LUA_NOREF; + // mobjinfo_t *, field -> number static int mobjinfo_get(lua_State *L) { mobjinfo_t *info = *((mobjinfo_t **)luaL_checkudata(L, 1, META_MOBJINFO)); - const char *field = luaL_checkstring(L, 2); + enum mobjinfo_e field = luaL_checkoption(L, 2, mobjinfo_opt[0], mobjinfo_opt); I_Assert(info != NULL); I_Assert(info >= mobjinfo); - if (fastcmp(field,"doomednum")) + switch (field) + { + case mobjinfo_doomednum: lua_pushinteger(L, info->doomednum); - else if (fastcmp(field,"spawnstate")) + break; + case mobjinfo_spawnstate: lua_pushinteger(L, info->spawnstate); - else if (fastcmp(field,"spawnhealth")) + break; + case mobjinfo_spawnhealth: lua_pushinteger(L, info->spawnhealth); - else if (fastcmp(field,"seestate")) + break; + case mobjinfo_seestate: lua_pushinteger(L, info->seestate); - else if (fastcmp(field,"seesound")) + break; + case mobjinfo_seesound: lua_pushinteger(L, info->seesound); - else if (fastcmp(field,"reactiontime")) + break; + case mobjinfo_reactiontime: lua_pushinteger(L, info->reactiontime); - else if (fastcmp(field,"attacksound")) + break; + case mobjinfo_attacksound: lua_pushinteger(L, info->attacksound); - else if (fastcmp(field,"painstate")) + break; + case mobjinfo_painstate: lua_pushinteger(L, info->painstate); - else if (fastcmp(field,"painchance")) + break; + case mobjinfo_painchance: lua_pushinteger(L, info->painchance); - else if (fastcmp(field,"painsound")) + break; + case mobjinfo_painsound: lua_pushinteger(L, info->painsound); - else if (fastcmp(field,"meleestate")) + break; + case mobjinfo_meleestate: lua_pushinteger(L, info->meleestate); - else if (fastcmp(field,"missilestate")) + break; + case mobjinfo_missilestate: lua_pushinteger(L, info->missilestate); - else if (fastcmp(field,"deathstate")) + break; + case mobjinfo_deathstate: lua_pushinteger(L, info->deathstate); - else if (fastcmp(field,"xdeathstate")) + break; + case mobjinfo_xdeathstate: lua_pushinteger(L, info->xdeathstate); - else if (fastcmp(field,"deathsound")) + break; + case mobjinfo_deathsound: lua_pushinteger(L, info->deathsound); - else if (fastcmp(field,"speed")) + break; + case mobjinfo_speed: lua_pushinteger(L, info->speed); // sometimes it's fixed_t, sometimes it's not... - else if (fastcmp(field,"radius")) + break; + case mobjinfo_radius: lua_pushfixed(L, info->radius); - else if (fastcmp(field,"height")) + break; + case mobjinfo_height: lua_pushfixed(L, info->height); - else if (fastcmp(field,"dispoffset")) + break; + case mobjinfo_dispoffset: lua_pushinteger(L, info->dispoffset); - else if (fastcmp(field,"mass")) + break; + case mobjinfo_mass: lua_pushinteger(L, info->mass); - else if (fastcmp(field,"damage")) + break; + case mobjinfo_damage: lua_pushinteger(L, info->damage); - else if (fastcmp(field,"activesound")) + break; + case mobjinfo_activesound: lua_pushinteger(L, info->activesound); - else if (fastcmp(field,"flags")) + break; + case mobjinfo_flags: lua_pushinteger(L, info->flags); - else if (fastcmp(field,"raisestate")) + break; + case mobjinfo_raisestate: lua_pushinteger(L, info->raisestate); - else { + break; + default: lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); lua_pushlightuserdata(L, info); lua_rawget(L, -2); if (!lua_istable(L, -1)) { // no extra values table - CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "mobjinfo_t", field); + CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "mobjinfo_t", lua_tostring(L, 2)); return 0; } - lua_getfield(L, -1, field); + lua_pushvalue(L, 2); // field name + lua_gettable(L, -2); if (lua_isnil(L, -1)) // no value for this field - CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "mobjinfo_t", field); + CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; returning nil.\n"), "mobjinfo_t", lua_tostring(L, 2)); + break; } return 1; } @@ -642,7 +728,7 @@ static int mobjinfo_get(lua_State *L) static int mobjinfo_set(lua_State *L) { mobjinfo_t *info = *((mobjinfo_t **)luaL_checkudata(L, 1, META_MOBJINFO)); - const char *field = luaL_checkstring(L, 2); + enum mobjinfo_e field = Lua_optoption(L, 2, -1, mobjinfo_fields_ref); if (hud_running) return luaL_error(L, "Do not alter mobjinfo in HUD rendering code!"); @@ -652,55 +738,81 @@ static int mobjinfo_set(lua_State *L) I_Assert(info != NULL); I_Assert(info >= mobjinfo); - if (fastcmp(field,"doomednum")) + switch (field) + { + case mobjinfo_doomednum: info->doomednum = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"spawnstate")) + break; + case mobjinfo_spawnstate: info->spawnstate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"spawnhealth")) + break; + case mobjinfo_spawnhealth: info->spawnhealth = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"seestate")) + break; + case mobjinfo_seestate: info->seestate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"seesound")) + break; + case mobjinfo_seesound: info->seesound = luaL_checkinteger(L, 3); - else if (fastcmp(field,"reactiontime")) + break; + case mobjinfo_reactiontime: info->reactiontime = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"attacksound")) + break; + case mobjinfo_attacksound: info->attacksound = luaL_checkinteger(L, 3); - else if (fastcmp(field,"painstate")) + break; + case mobjinfo_painstate: info->painstate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"painchance")) + break; + case mobjinfo_painchance: info->painchance = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"painsound")) + break; + case mobjinfo_painsound: info->painsound = luaL_checkinteger(L, 3); - else if (fastcmp(field,"meleestate")) + break; + case mobjinfo_meleestate: info->meleestate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"missilestate")) + break; + case mobjinfo_missilestate: info->missilestate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"deathstate")) + break; + case mobjinfo_deathstate: info->deathstate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"xdeathstate")) + break; + case mobjinfo_xdeathstate: info->xdeathstate = luaL_checkinteger(L, 3); - else if (fastcmp(field,"deathsound")) + break; + case mobjinfo_deathsound: info->deathsound = luaL_checkinteger(L, 3); - else if (fastcmp(field,"speed")) + break; + case mobjinfo_speed: info->speed = luaL_checkfixed(L, 3); - else if (fastcmp(field,"radius")) + break; + case mobjinfo_radius: info->radius = luaL_checkfixed(L, 3); - else if (fastcmp(field,"height")) + break; + case mobjinfo_height: info->height = luaL_checkfixed(L, 3); - else if (fastcmp(field,"dispoffset")) + break; + case mobjinfo_dispoffset: info->dispoffset = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"mass")) + break; + case mobjinfo_mass: info->mass = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"damage")) + break; + case mobjinfo_damage: info->damage = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"activesound")) + break; + case mobjinfo_activesound: info->activesound = luaL_checkinteger(L, 3); - else if (fastcmp(field,"flags")) + break; + case mobjinfo_flags: info->flags = (INT32)luaL_checkinteger(L, 3); - else if (fastcmp(field,"raisestate")) + break; + case mobjinfo_raisestate: info->raisestate = luaL_checkinteger(L, 3); - else { + break; + default: lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); lua_pushlightuserdata(L, info); @@ -708,18 +820,17 @@ static int mobjinfo_set(lua_State *L) if (lua_isnil(L, -1)) { // This index doesn't have a table for extra values yet, let's make one. lua_pop(L, 1); - CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; adding it as Lua data.\n"), "mobjinfo_t", field); + CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; adding it as Lua data.\n"), "mobjinfo_t", lua_tostring(L, 2)); lua_newtable(L); lua_pushlightuserdata(L, info); lua_pushvalue(L, -2); // ext value table lua_rawset(L, -4); // LREG_EXTVARS table } + lua_pushvalue(L, 2); // key lua_pushvalue(L, 3); // value to store - lua_setfield(L, -2, field); + lua_settable(L, -3); lua_pop(L, 2); } - //else - //return luaL_error(L, LUA_QL("mobjinfo_t") " has no field named " LUA_QS, field); return 0; } @@ -921,6 +1032,8 @@ int LUA_InfoLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + mobjinfo_fields_ref = Lua_CreateFieldTable(L, mobjinfo_opt); + luaL_newmetatable(L, META_SFXINFO); lua_pushcfunction(L, sfxinfo_get); lua_setfield(L, -2, "__index"); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 96222ba0a..2ae2ce395 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -71,6 +71,8 @@ enum subsector_e { subsector_firstline, }; +static int sector_fields_ref = LUA_NOREF; + static const char *const subsector_opt[] = { "valid", "sector", @@ -78,6 +80,8 @@ static const char *const subsector_opt[] = { "firstline", NULL}; +static int subsector_fields_ref = LUA_NOREF; + enum line_e { line_valid = 0, line_v1, @@ -120,6 +124,8 @@ static const char *const line_opt[] = { "callcount", NULL}; +static int line_fields_ref = LUA_NOREF; + enum side_e { side_valid = 0, side_textureoffset, @@ -146,6 +152,8 @@ static const char *const side_opt[] = { "text", NULL}; +static int side_fields_ref = LUA_NOREF; + enum vertex_e { vertex_valid = 0, vertex_x, @@ -160,6 +168,8 @@ static const char *const vertex_opt[] = { "z", NULL}; +static int vertex_fields_ref = LUA_NOREF; + enum ffloor_e { ffloor_valid = 0, ffloor_topheight, @@ -196,6 +206,8 @@ static const char *const ffloor_opt[] = { "alpha", NULL}; +static int ffloor_fields_ref = LUA_NOREF; + enum slope_e { slope_valid = 0, slope_o, @@ -222,6 +234,8 @@ static const char *const slope_opt[] = { "flags", NULL}; +static int slope_fields_ref = LUA_NOREF; + // shared by both vector2_t and vector3_t enum vector_e { vector_x = 0, @@ -387,7 +401,7 @@ static int sectorlines_num(lua_State *L) static int sector_get(lua_State *L) { sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); - enum sector_e field = luaL_checkoption(L, 2, sector_opt[0], sector_opt); + enum sector_e field = Lua_optoption(L, 2, sector_valid, sector_fields_ref); INT16 i; if (!sector) @@ -473,7 +487,7 @@ static int sector_get(lua_State *L) static int sector_set(lua_State *L) { sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); - enum sector_e field = luaL_checkoption(L, 2, sector_opt[0], sector_opt); + enum sector_e field = Lua_optoption(L, 2, sector_valid, sector_fields_ref); if (!sector) return luaL_error(L, "accessed sector_t doesn't exist anymore."); @@ -551,7 +565,7 @@ static int sector_num(lua_State *L) static int subsector_get(lua_State *L) { subsector_t *subsector = *((subsector_t **)luaL_checkudata(L, 1, META_SUBSECTOR)); - enum subsector_e field = luaL_checkoption(L, 2, subsector_opt[0], subsector_opt); + enum subsector_e field = Lua_optoption(L, 2, subsector_valid, subsector_fields_ref); if (!subsector) { @@ -590,7 +604,7 @@ static int subsector_num(lua_State *L) static int line_get(lua_State *L) { line_t *line = *((line_t **)luaL_checkudata(L, 1, META_LINE)); - enum line_e field = luaL_checkoption(L, 2, line_opt[0], line_opt); + enum line_e field = Lua_optoption(L, 2, line_valid, line_fields_ref); if (!line) { @@ -715,7 +729,7 @@ static int sidenum_get(lua_State *L) static int side_get(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); - enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); + enum side_e field = Lua_optoption(L, 2, side_valid, side_fields_ref); if (!side) { @@ -765,7 +779,7 @@ static int side_get(lua_State *L) static int side_set(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); - enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); + enum side_e field = Lua_optoption(L, 2, side_valid, side_fields_ref); if (!side) { @@ -816,7 +830,7 @@ static int side_num(lua_State *L) static int vertex_get(lua_State *L) { vertex_t *vertex = *((vertex_t **)luaL_checkudata(L, 1, META_VERTEX)); - enum vertex_e field = luaL_checkoption(L, 2, vertex_opt[0], vertex_opt); + enum vertex_e field = Lua_optoption(L, 2, vertex_valid, vertex_fields_ref); if (!vertex) { @@ -1085,7 +1099,7 @@ static int lib_numvertexes(lua_State *L) static int ffloor_get(lua_State *L) { ffloor_t *ffloor = *((ffloor_t **)luaL_checkudata(L, 1, META_FFLOOR)); - enum ffloor_e field = luaL_checkoption(L, 2, ffloor_opt[0], ffloor_opt); + enum ffloor_e field = Lua_optoption(L, 2, ffloor_valid, ffloor_fields_ref); INT16 i; if (!ffloor) @@ -1161,7 +1175,7 @@ static int ffloor_get(lua_State *L) static int ffloor_set(lua_State *L) { ffloor_t *ffloor = *((ffloor_t **)luaL_checkudata(L, 1, META_FFLOOR)); - enum ffloor_e field = luaL_checkoption(L, 2, ffloor_opt[0], ffloor_opt); + enum ffloor_e field = Lua_optoption(L, 2, ffloor_valid, ffloor_fields_ref); if (!ffloor) return luaL_error(L, "accessed ffloor_t doesn't exist anymore."); @@ -1239,7 +1253,7 @@ static int ffloor_set(lua_State *L) static int slope_get(lua_State *L) { pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); - enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt); + enum slope_e field = Lua_optoption(L, 2, slope_valid, slope_fields_ref); if (!slope) { @@ -1289,7 +1303,7 @@ static int slope_get(lua_State *L) static int slope_set(lua_State *L) { pslope_t *slope = *((pslope_t **)luaL_checkudata(L, 1, META_SLOPE)); - enum slope_e field = luaL_checkoption(L, 2, slope_opt[0], slope_opt); + enum slope_e field = Lua_optoption(L, 2, slope_valid, slope_fields_ref); if (!slope) return luaL_error(L, "accessed pslope_t doesn't exist anymore."); @@ -1446,86 +1460,197 @@ static int lib_nummapheaders(lua_State *L) return 1; } +enum mapheaderinfo_e +{ + mapheaderinfo_lvlttl, + mapheaderinfo_subttl, + mapheaderinfo_zonttl, + mapheaderinfo_actnum, + mapheaderinfo_typeoflevel, + mapheaderinfo_nextlevel, + mapheaderinfo_musname, + mapheaderinfo_mustrack, + mapheaderinfo_muspos, + mapheaderinfo_musinterfadeout, + mapheaderinfo_musintername, + mapheaderinfo_forcecharacter, + mapheaderinfo_weather, + mapheaderinfo_skynum, + mapheaderinfo_skybox_scalex, + mapheaderinfo_skybox_scaley, + mapheaderinfo_skybox_scalez, + mapheaderinfo_interscreen, + mapheaderinfo_runsoc, + mapheaderinfo_scriptname, + mapheaderinfo_precutscenenum, + mapheaderinfo_cutscenenum, + mapheaderinfo_countdown, + mapheaderinfo_palette, + mapheaderinfo_numlaps, + mapheaderinfo_unlockrequired, + mapheaderinfo_levelselect, + mapheaderinfo_bonustype, + mapheaderinfo_saveoverride, + mapheaderinfo_levelflags, + mapheaderinfo_menuflags, + //mapheaderinfo_automap, + mapheaderinfo_mobj_scale, +}; + +static const char *const mapheaderinfo_opt[] = { + "lvlttl", + "subttl", + "zonttl", + "actnum", + "typeoflevel", + "nextlevel", + "musname", + "mustrack", + "muspos", + "musinterfadeout", + "musintername", + "forcecharacter", + "weather", + "skynum", + "skybox_scalex", + "skybox_scaley", + "skybox_scalez", + "interscreen", + "runsoc", + "scriptname", + "precutscenenum", + "cutscenenum", + "countdown", + "palette", + "numlaps", + "unlockrequired", + "levelselect", + "bonustype", + "saveoverride", + "levelflags", + "menuflags", + //"automap", + "mobj_scale", + NULL, +}; + +static int mapheaderinfo_fields_ref = LUA_NOREF; + static int mapheaderinfo_get(lua_State *L) { mapheader_t *header = *((mapheader_t **)luaL_checkudata(L, 1, META_MAPHEADER)); - const char *field = luaL_checkstring(L, 2); + enum mapheaderinfo_e field = Lua_optoption(L, 2, -1, mapheaderinfo_fields_ref); INT16 i; - if (fastcmp(field,"lvlttl")) + switch (field) + { + case mapheaderinfo_lvlttl: lua_pushstring(L, header->lvlttl); - else if (fastcmp(field,"subttl")) + break; + case mapheaderinfo_subttl: lua_pushstring(L, header->subttl); - else if (fastcmp(field,"zonttl")) + break; + case mapheaderinfo_zonttl: lua_pushstring(L, header->zonttl); - else if (fastcmp(field,"actnum")) + break; + case mapheaderinfo_actnum: lua_pushstring(L, header->actnum); - else if (fastcmp(field,"typeoflevel")) + break; + case mapheaderinfo_typeoflevel: lua_pushinteger(L, header->typeoflevel); - else if (fastcmp(field,"nextlevel")) + break; + case mapheaderinfo_nextlevel: lua_pushinteger(L, header->nextlevel); - else if (fastcmp(field,"musname")) + break; + case mapheaderinfo_musname: lua_pushstring(L, header->musname); - else if (fastcmp(field,"mustrack")) + break; + case mapheaderinfo_mustrack: lua_pushinteger(L, header->mustrack); - else if (fastcmp(field,"muspos")) + break; + case mapheaderinfo_muspos: lua_pushinteger(L, header->muspos); - else if (fastcmp(field,"musinterfadeout")) + break; + case mapheaderinfo_musinterfadeout: lua_pushinteger(L, header->musinterfadeout); - else if (fastcmp(field,"musintername")) + break; + case mapheaderinfo_musintername: lua_pushstring(L, header->musintername); - else if (fastcmp(field,"forcecharacter")) + break; + case mapheaderinfo_forcecharacter: lua_pushstring(L, header->forcecharacter); - else if (fastcmp(field,"weather")) + break; + case mapheaderinfo_weather: lua_pushinteger(L, header->weather); - else if (fastcmp(field,"skynum")) + break; + case mapheaderinfo_skynum: lua_pushinteger(L, header->skynum); - else if (fastcmp(field,"skybox_scalex")) + break; + case mapheaderinfo_skybox_scalex: lua_pushinteger(L, header->skybox_scalex); - else if (fastcmp(field,"skybox_scaley")) + break; + case mapheaderinfo_skybox_scaley: lua_pushinteger(L, header->skybox_scaley); - else if (fastcmp(field,"skybox_scalez")) + break; + case mapheaderinfo_skybox_scalez: lua_pushinteger(L, header->skybox_scalez); - else if (fastcmp(field,"interscreen")) { + break; + case mapheaderinfo_interscreen: for (i = 0; i < 8; i++) if (!header->interscreen[i]) break; lua_pushlstring(L, header->interscreen, i); - } else if (fastcmp(field,"runsoc")) + break; + case mapheaderinfo_runsoc: lua_pushstring(L, header->runsoc); - else if (fastcmp(field,"scriptname")) + break; + case mapheaderinfo_scriptname: lua_pushstring(L, header->scriptname); - else if (fastcmp(field,"precutscenenum")) + break; + case mapheaderinfo_precutscenenum: lua_pushinteger(L, header->precutscenenum); - else if (fastcmp(field,"cutscenenum")) + break; + case mapheaderinfo_cutscenenum: lua_pushinteger(L, header->cutscenenum); - else if (fastcmp(field,"countdown")) + break; + case mapheaderinfo_countdown: lua_pushinteger(L, header->countdown); - else if (fastcmp(field,"palette")) + break; + case mapheaderinfo_palette: lua_pushinteger(L, header->palette); - else if (fastcmp(field,"numlaps")) + break; + case mapheaderinfo_numlaps: lua_pushinteger(L, header->numlaps); - else if (fastcmp(field,"unlockrequired")) + break; + case mapheaderinfo_unlockrequired: lua_pushinteger(L, header->unlockrequired); - else if (fastcmp(field,"levelselect")) + break; + case mapheaderinfo_levelselect: lua_pushinteger(L, header->levelselect); - else if (fastcmp(field,"bonustype")) + break; + case mapheaderinfo_bonustype: lua_pushinteger(L, header->bonustype); - else if (fastcmp(field,"saveoverride")) + break; + case mapheaderinfo_saveoverride: lua_pushinteger(L, header->saveoverride); - else if (fastcmp(field,"levelflags")) + break; + case mapheaderinfo_levelflags: lua_pushinteger(L, header->levelflags); - else if (fastcmp(field,"menuflags")) + break; + case mapheaderinfo_menuflags: lua_pushinteger(L, header->menuflags); - /*else if (fastcmp(field,"automap")) - lua_pushboolean(L, header->automap);*/ - else if (fastcmp(field,"mobj_scale")) + break; + /*case mapheaderinfo_automap: + lua_pushstring(L, header->selectheading); + break;*/ + case mapheaderinfo_mobj_scale: lua_pushfixed(L, header->mobj_scale); + break; // TODO add support for reading numGradedMares and grades - else { + default: // Read custom vars now // (note: don't include the "LUA." in your lua scripts!) UINT8 j = 0; - for (;j < header->numCustomOptions && !fastcmp(field, header->customopts[j].option); ++j); + for (;j < header->numCustomOptions && !fastcmp(lua_tostring(L, 2), header->customopts[j].option); ++j); if(j < header->numCustomOptions) lua_pushstring(L, header->customopts[j].value); @@ -1533,6 +1658,7 @@ static int mapheaderinfo_get(lua_State *L) lua_pushnil(L); } return 1; + } int LUA_MapLib(lua_State *L) @@ -1556,6 +1682,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + sector_fields_ref = Lua_CreateFieldTable(L, sector_opt); + luaL_newmetatable(L, META_SUBSECTOR); lua_pushcfunction(L, subsector_get); lua_setfield(L, -2, "__index"); @@ -1564,6 +1692,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + subsector_fields_ref = Lua_CreateFieldTable(L, subsector_opt); + luaL_newmetatable(L, META_LINE); lua_pushcfunction(L, line_get); lua_setfield(L, -2, "__index"); @@ -1572,6 +1702,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + line_fields_ref = Lua_CreateFieldTable(L, line_opt); + luaL_newmetatable(L, META_SIDENUM); lua_pushcfunction(L, sidenum_get); lua_setfield(L, -2, "__index"); @@ -1588,6 +1720,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + side_fields_ref = Lua_CreateFieldTable(L, side_opt); + luaL_newmetatable(L, META_VERTEX); lua_pushcfunction(L, vertex_get); lua_setfield(L, -2, "__index"); @@ -1596,6 +1730,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + vertex_fields_ref = Lua_CreateFieldTable(L, vertex_opt); + luaL_newmetatable(L, META_FFLOOR); lua_pushcfunction(L, ffloor_get); lua_setfield(L, -2, "__index"); @@ -1604,6 +1740,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); + ffloor_fields_ref = Lua_CreateFieldTable(L, ffloor_opt); + luaL_newmetatable(L, META_SLOPE); lua_pushcfunction(L, slope_get); lua_setfield(L, -2, "__index"); @@ -1612,6 +1750,8 @@ int LUA_MapLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); + slope_fields_ref = Lua_CreateFieldTable(L, slope_opt); + luaL_newmetatable(L, META_VECTOR2); lua_pushcfunction(L, vector2_get); lua_setfield(L, -2, "__index"); @@ -1630,6 +1770,8 @@ int LUA_MapLib(lua_State *L) //lua_setfield(L, -2, "__len"); lua_pop(L, 1); + mapheaderinfo_fields_ref = Lua_CreateFieldTable(L, mapheaderinfo_opt); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSector); diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 7b1db5327..866ea6550 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -769,14 +769,41 @@ static int mobj_set(lua_State *L) #undef NOSETPOS #undef NOFIELD +enum mapthing_e { + mapthing_valid = 0, + mapthing_x, + mapthing_y, + mapthing_angle, + mapthing_type, + mapthing_options, + mapthing_z, + mapthing_extrainfo, + mapthing_mobj, +}; + +const char *const mapthing_opt[] = { + "valid", + "x", + "y", + "angle", + "type", + "options", + "z", + "extrainfo", + "mobj", + NULL, +}; + +static int mapthing_fields_ref = LUA_NOREF; + static int mapthing_get(lua_State *L) { mapthing_t *mt = *((mapthing_t **)luaL_checkudata(L, 1, META_MAPTHING)); - const char *field = luaL_checkstring(L, 2); - lua_Integer number; + enum mapthing_e field = Lua_optoption(L, 2, -1, mapthing_fields_ref); + lua_settop(L, 2); if (!mt) { - if (fastcmp(field,"valid")) { + if (field == mapthing_valid) { lua_pushboolean(L, false); return 1; } @@ -785,39 +812,50 @@ static int mapthing_get(lua_State *L) return 0; } - if (fastcmp(field,"valid")) { - lua_pushboolean(L, true); - return 1; - } else if(fastcmp(field,"x")) - number = mt->x; - else if(fastcmp(field,"y")) - number = mt->y; - else if(fastcmp(field,"angle")) - number = mt->angle; - else if(fastcmp(field,"type")) - number = mt->type; - else if(fastcmp(field,"options")) - number = mt->options; - else if(fastcmp(field,"z")) - number = mt->z; - else if(fastcmp(field,"extrainfo")) - number = mt->extrainfo; - else if(fastcmp(field,"mobj")) { - LUA_PushUserdata(L, mt->mobj, META_MOBJ); - return 1; - } else if (devparm) - return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field); - else - return 0; + switch (field) + { + case mapthing_valid: + lua_pushboolean(L, true); + break; + case mapthing_x: + lua_pushinteger(L, mt->x); + break; + case mapthing_y: + lua_pushinteger(L, mt->y); + break; + case mapthing_angle: + lua_pushinteger(L, mt->angle); + break; + case mapthing_type: + lua_pushinteger(L, mt->type); + break; + case mapthing_options: + lua_pushinteger(L, mt->options); + break; + case mapthing_z: + lua_pushinteger(L, mt->z); + break; + case mapthing_extrainfo: + lua_pushinteger(L, mt->extrainfo); + break; + case mapthing_mobj: + LUA_PushUserdata(L, mt->mobj, META_MOBJ); + break; + default: + if (devparm) + return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field); + else + return 0; + } - lua_pushinteger(L, number); return 1; } static int mapthing_set(lua_State *L) { mapthing_t *mt = *((mapthing_t **)luaL_checkudata(L, 1, META_MAPTHING)); - const char *field = luaL_checkstring(L, 2); + enum mapthing_e field = Lua_optoption(L, 2, -1, mapthing_fields_ref); + lua_settop(L, 3); if (!mt) return luaL_error(L, "accessed mapthing_t doesn't exist anymore."); @@ -827,24 +865,38 @@ static int mapthing_set(lua_State *L) if (hook_cmd_running) return luaL_error(L, "Do not alter mapthing_t in BuildCMD code!"); - if(fastcmp(field,"x")) - mt->x = (INT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"y")) - mt->y = (INT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"angle")) - mt->angle = (INT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"type")) - mt->type = (UINT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"options")) - mt->options = (UINT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"z")) - mt->z = (INT16)luaL_checkinteger(L, 3); - else if(fastcmp(field,"extrainfo")) - mt->extrainfo = (UINT8)luaL_checkinteger(L, 3); - else if(fastcmp(field,"mobj")) - mt->mobj = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); - else - return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field); + switch (field) + { + case mapthing_x: + mt->x = (INT16)luaL_checkinteger(L, 3); + break; + case mapthing_y: + mt->y = (INT16)luaL_checkinteger(L, 3); + break; + case mapthing_angle: + mt->angle = (INT16)luaL_checkinteger(L, 3); + break; + case mapthing_type: + mt->type = (UINT16)luaL_checkinteger(L, 3); + break; + case mapthing_options: + mt->options = (UINT16)luaL_checkinteger(L, 3); + break; + case mapthing_z: + mt->z = (INT16)luaL_checkinteger(L, 3); + break; + case mapthing_extrainfo: + INT32 extrainfo = luaL_checkinteger(L, 3); + if (extrainfo & ~15) + return luaL_error(L, "mapthing_t extrainfo set %d out of range (%d - %d)", extrainfo, 0, 15); + mt->extrainfo = (UINT8)extrainfo; + break; + case mapthing_mobj: + mt->mobj = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + break; + default: + return luaL_error(L, LUA_QL("mapthing_t") " has no field named " LUA_QS, field); + } return 0; } @@ -915,6 +967,8 @@ int LUA_MobjLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L,1); + mapthing_fields_ref = Lua_CreateFieldTable(L, mapthing_opt); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getMapthing); diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 70324fa02..2d79d536d 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -694,30 +694,65 @@ static int kartstuff_len(lua_State *L) } #define NOFIELD luaL_error(L, LUA_QL("ticcmd_t") " has no field named " LUA_QS, field) +#define NOSET luaL_error(L, LUA_QL("ticcmd_t") " field " LUA_QS " should not be set directly.", field) + +enum ticcmd_e +{ + ticcmd_forwardmove, + ticcmd_sidemove, + ticcmd_angleturn, + ticcmd_aiming, + ticcmd_buttons, + ticcmd_driftturn, + ticcmd_latency, +}; + +static const char *const ticcmd_opt[] = { + "forwardmove", + "sidemove", + "angleturn", + "aiming", + "buttons", + "driftturn", + "latency", + NULL, +}; + +static int ticcmd_fields_ref = LUA_NOREF; static int ticcmd_get(lua_State *L) { ticcmd_t *cmd = *((ticcmd_t **)luaL_checkudata(L, 1, META_TICCMD)); - const char *field = luaL_checkstring(L, 2); + enum ticcmd_e field = Lua_optoption(L, 2, -1, ticcmd_fields_ref); if (!cmd) return LUA_ErrInvalid(L, "player_t"); - if (fastcmp(field,"forwardmove")) + switch (field) + { + case ticcmd_forwardmove: lua_pushinteger(L, cmd->forwardmove); - else if (fastcmp(field,"sidemove")) + break; + case ticcmd_sidemove: lua_pushinteger(L, cmd->sidemove); - else if (fastcmp(field,"angleturn")) + break; + case ticcmd_angleturn: lua_pushinteger(L, cmd->angleturn); - else if (fastcmp(field,"aiming")) + break; + case ticcmd_aiming: lua_pushinteger(L, cmd->aiming); - else if (fastcmp(field,"buttons")) + break; + case ticcmd_buttons: lua_pushinteger(L, cmd->buttons); - else if (fastcmp(field,"driftturn")) + break; + case ticcmd_driftturn: lua_pushinteger(L, cmd->driftturn); - else if (fastcmp(field,"latency")) + break; + case ticcmd_latency: lua_pushinteger(L, cmd->latency); - else + break; + default: return NOFIELD; + } return 1; } @@ -725,32 +760,44 @@ static int ticcmd_get(lua_State *L) static int ticcmd_set(lua_State *L) { ticcmd_t *cmd = *((ticcmd_t **)luaL_checkudata(L, 1, META_TICCMD)); - const char *field = luaL_checkstring(L, 2); + enum ticcmd_e field = Lua_optoption(L, 2, -1, ticcmd_fields_ref); if (!cmd) return LUA_ErrInvalid(L, "ticcmd_t"); if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); - if (fastcmp(field,"forwardmove")) + switch (field) + { + case ticcmd_forwardmove: cmd->forwardmove = (SINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"sidemove")) + break; + case ticcmd_sidemove: cmd->sidemove = (SINT8)luaL_checkinteger(L, 3); - else if (fastcmp(field,"angleturn")) + break; + case ticcmd_angleturn: cmd->angleturn = (INT16)luaL_checkinteger(L, 3); - else if (fastcmp(field,"aiming")) + break; + case ticcmd_aiming: cmd->aiming = (INT16)luaL_checkinteger(L, 3); - else if (fastcmp(field,"buttons")) + break; + case ticcmd_buttons: cmd->buttons = (UINT16)luaL_checkinteger(L, 3); - else if (fastcmp(field,"driftturn")) + break; + case ticcmd_driftturn: cmd->driftturn = (INT16)luaL_checkinteger(L, 3); - else + break; + case ticcmd_latency: + return NOSET; + default: return NOFIELD; + } return 0; } #undef NOFIELD +#undef NOSET int LUA_PlayerLib(lua_State *L) { @@ -797,6 +844,8 @@ int LUA_PlayerLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L,1); + ticcmd_fields_ref = Lua_CreateFieldTable(L, ticcmd_opt); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getPlayer); diff --git a/src/lua_script.c b/src/lua_script.c index 3af655efe..381448e72 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1678,13 +1678,36 @@ void LUA_UnArchiveDemo(void) } // For mobj_t, player_t, etc. to take custom variables. -int Lua_optoption(lua_State *L, int narg, - const char *def, const char *const lst[]) +int Lua_optoption(lua_State *L, int narg, int def, int list_ref) { - const char *name = (def) ? luaL_optstring(L, narg, def) : luaL_checkstring(L, narg); - int i; - for (i=0; lst[i]; i++) - if (fastcmp(lst[i], name)) - return i; + if (lua_isnoneornil(L, narg)) + return def; + + I_Assert(lua_checkstack(L, 2)); + luaL_checkstring(L, narg); + + lua_rawgeti(L, LUA_REGISTRYINDEX, list_ref); + I_Assert(lua_istable(L, -1)); + lua_pushvalue(L, narg); + lua_rawget(L, -2); + + if (lua_isnumber(L, -1)) + return lua_tointeger(L, -1); return -1; +} + + +int Lua_CreateFieldTable(lua_State *L, const char *const lst[]) +{ + int i; + + lua_newtable(L); + for (i = 0; lst[i] != NULL; i++) + { + lua_pushstring(L, lst[i]); + lua_pushinteger(L, i); + lua_settable(L, -3); + } + + return luaL_ref(L, LUA_REGISTRYINDEX); } \ No newline at end of file diff --git a/src/lua_script.h b/src/lua_script.h index a22e47c12..9903315c2 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -63,8 +63,8 @@ void LUA_UnArchiveDemo(void); void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c void LUA_CVarChanged(const char *name); // lua_consolelib.c -int Lua_optoption(lua_State *L, int narg, - const char *def, const char *const lst[]); +int Lua_optoption(lua_State *L, int narg, int def, int list_ref); +int Lua_CreateFieldTable(lua_State *L, const char *const lst[]); void LUAh_NetArchiveHook(lua_CFunction archFunc); // Console wrapper diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index 286e983c1..403ac834e 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -38,6 +38,7 @@ enum skin { skin_highresscale, skin_soundsid }; + static const char *const skin_opt[] = { "valid", "name", @@ -61,10 +62,12 @@ static const char *const skin_opt[] = { #define UNIMPLEMENTED luaL_error(L, LUA_QL("skin_t") " field " LUA_QS " is not implemented for Lua and cannot be accessed.", skin_opt[field]) +static int skin_fields_ref = LUA_NOREF; + static int skin_get(lua_State *L) { skin_t *skin = *((skin_t **)luaL_checkudata(L, 1, META_SKIN)); - enum skin field = luaL_checkoption(L, 2, NULL, skin_opt); + enum skin field = Lua_optoption(L, 2, -1, skin_fields_ref); INT32 i; // skins are always valid, only added, never removed @@ -253,6 +256,8 @@ int LUA_SkinLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L,1); + skin_fields_ref = Lua_CreateFieldTable(L, skin_opt); + luaL_newmetatable(L, META_SOUNDSID); lua_pushcfunction(L, soundsid_get); lua_setfield(L, -2, "__index"); From 4847e4e3cb19a60c9b38a0e5bb2ad880e199f4c3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:22:48 +0200 Subject: [PATCH 17/91] that should be there lul --- src/r_things.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index dfe05dbdf..183b6b93e 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2029,6 +2029,7 @@ void R_AddPrecipitationSprites(void) INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th, *next; + // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off if (drawdist == 0) { return; @@ -2036,7 +2037,6 @@ void R_AddPrecipitationSprites(void) R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh); - // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off for (bx = xl; bx <= xh; bx++) { for (by = yl; by <= yh; by++) From 455bbe47c283620d182e264b24931e814fcc7cc9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:38:20 +0200 Subject: [PATCH 18/91] smth smth encore magic numbers idk --- src/hardware/hw_cache.c | 8 +++++--- src/hardware/hw_main.c | 4 ++-- src/r_draw8.c | 4 ++-- src/r_main.h | 3 +++ src/r_plane.c | 4 ++-- src/r_segs.c | 16 ++++++++-------- src/r_things.c | 4 ++-- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 848f8243f..2a5ec4ff5 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -26,6 +26,7 @@ #include "../z_zone.h" #include "../v_video.h" #include "../r_draw.h" +#include "../r_main.h" #include "../r_patch.h" // patch rotation INT32 patchformat = GL_TEXFMT_AP_88; // use alpha for holes @@ -344,7 +345,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, boolean noe #ifdef GLENCORE if (encoremap && !noencore) - grtex->mipmap.colormap += (256*32); + grtex->mipmap.colormap += COLORMAP_REMAPOFFSET; #endif blockwidth = texture->width; @@ -647,7 +648,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) #ifdef GLENCORE if (!noencoremap && encoremap) - grmip->colormap += (256*32); + grmip->colormap += COLORMAP_REMAPOFFSET; #endif if (!grmip->downloaded && !grmip->data) @@ -729,7 +730,8 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap) { GLMipmap_t *grmip, *newmip; - if (colormap == colormaps || colormap == NULL) + // Blatant hack for encore colormapping aside... + if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) { // Load the default (green) color in doom cache (temporary?) AND hardware cache HWR_GetPatch(gpatch); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index fc137c109..4893bd5f3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5285,7 +5285,7 @@ void HWR_ProjectSprite(mobj_t *thing) vis->colormap = colormaps; #ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif } @@ -5416,7 +5416,7 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) #ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += (256*32); + vis->colormap += COLORMAP_REMAPOFFSET; #endif // set top/bottom coords diff --git a/src/r_draw8.c b/src/r_draw8.c index 93a0796a3..f3ebf0ff9 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -1696,7 +1696,7 @@ void R_DrawColumnShadowed_8(void) { dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (solid && dc_yl < bheight) dc_yl = bheight; continue; @@ -1714,7 +1714,7 @@ void R_DrawColumnShadowed_8(void) dc_colormap = dc_lightlist[i].rcolormap; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } dc_yh = realyh; if (dc_yl <= realyh) diff --git a/src/r_main.h b/src/r_main.h index 56e351138..7c2249873 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -64,6 +64,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // There a 0-31, i.e. 32 LUT in the COLORMAP lump. #define NUMCOLORMAPS 32 +#define COLORMAP_SIZE (256*LIGHTLEVELS) +#define COLORMAP_REMAPOFFSET COLORMAP_SIZE + // Utility functions. INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); diff --git a/src/r_plane.c b/src/r_plane.c index f89e10330..6bd6f212d 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -295,7 +295,7 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) ds_colormap = planezlight[pindex]; } if (encoremap && !currentplane->noencore) - ds_colormap += (256*32); + ds_colormap += COLORMAP_REMAPOFFSET; if (currentplane->extra_colormap) ds_colormap = currentplane->extra_colormap->colormap + (ds_colormap - colormaps); @@ -675,7 +675,7 @@ static void R_DrawSkyPlane(visplane_t *pl) // by INVUL inverse mapping. dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = skytexturemid; dc_texheight = textureheight[skytexture] >>FRACBITS; diff --git a/src/r_segs.c b/src/r_segs.c index 219b142e0..4a231938b 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -208,7 +208,7 @@ static void R_DrawWallSplats(void) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; if (encoremap && !(seg->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -573,7 +573,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) { dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; continue; } @@ -594,7 +594,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) windowtop = windowbottom + 1; dc_colormap = rlight->rcolormap; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } windowbottom = realbot; if (windowtop < windowbottom) @@ -612,7 +612,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) dc_colormap = walllights[pindex]; if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (frontsector->extra_colormap) dc_colormap = frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1107,7 +1107,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } if (solid && windowtop < bheight) windowtop = bheight; @@ -1139,7 +1139,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { dc_colormap = rlight->rcolormap; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; } } windowbottom = sprbotscreen; @@ -1160,7 +1160,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); @@ -1396,7 +1396,7 @@ static void R_RenderSegLoop (void) dc_colormap = walllights[pindex]; if (encoremap && !(curline->linedef->flags & ML_TFERLINE)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_x = rw_x; dc_iscale = 0xffffffffu / (unsigned)rw_scale; diff --git a/src/r_things.c b/src/r_things.c index 183b6b93e..933181ce7 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -816,7 +816,7 @@ static void R_DrawVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap && !vis->mobj->color && !(vis->mobj->flags & MF_DONTENCOREMAP)) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = vis->texturemid; dc_texheight = 0; @@ -939,7 +939,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) dc_colormap = colormaps; if (encoremap) - dc_colormap += (256*32); + dc_colormap += COLORMAP_REMAPOFFSET; dc_iscale = FixedDiv(FRACUNIT, vis->scale); dc_texturemid = vis->texturemid; From 37d3e2ae1a679f437c6333d7b58074d9e84801d1 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:02:54 +0200 Subject: [PATCH 19/91] scale sprite draw distance with mapobjscale --- src/hardware/hw_main.c | 8 ++++---- src/r_things.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4893bd5f3..750b245fc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4795,12 +4795,12 @@ void HWR_AddSprites(sector_t *sec) { // Use the smaller setting if (cv_drawdist.value) - limit_dist = min(current_bsp_culling_distance, cv_drawdist.value << FRACBITS); + limit_dist = min(current_bsp_culling_distance, (fixed_t)(cv_drawdist.value) * mapobjectscale); else limit_dist = current_bsp_culling_distance; } else - limit_dist = cv_drawdist.value << FRACBITS; + limit_dist = (fixed_t)(cv_drawdist.value) * mapobjectscale; // Handle all things in sector. // If a limit exists, handle things a tiny bit different. @@ -4903,9 +4903,9 @@ static void HWR_AddPrecipitationSprites(void) precipmobj_t *th; if (current_bsp_culling_distance) - drawdist = min(current_bsp_culling_distance, cv_drawdist_precip.value * mapobjectscale); + drawdist = min(current_bsp_culling_distance, (fixed_t)(cv_drawdist_precip.value) * mapobjectscale); else - drawdist = cv_drawdist_precip.value * mapobjectscale; + drawdist = (fixed_t)(cv_drawdist_precip.value) * mapobjectscale; // No to infinite precipitation draw distance. if (drawdist == 0) diff --git a/src/r_things.c b/src/r_things.c index 933181ce7..64468ffa9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1932,7 +1932,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // Handle all things in sector. // If a limit exists, handle things a tiny bit different. - if ((limit_dist = (fixed_t)(/*(maptol & TOL_NIGHTS) ? cv_drawdist_nights.value : */cv_drawdist.value) << FRACBITS)) + if ((limit_dist = (fixed_t)(cv_drawdist.value) * mapobjectscale)) { for (thing = sec->thinglist; thing; thing = thing->snext) { @@ -2024,7 +2024,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // void R_AddPrecipitationSprites(void) { - const fixed_t drawdist = cv_drawdist_precip.value * mapobjectscale; + const fixed_t drawdist = (fixed_t)(cv_drawdist_precip.value) * mapobjectscale; INT32 xl, xh, yl, yh, bx, by; precipmobj_t *th, *next; From faa5dbd0e73057bb19cacfa7daa3a18d86f260ee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:55:03 +0200 Subject: [PATCH 20/91] split sprite draw loops so crap doesent constantly check for papersprites on all sprites --- src/r_things.c | 61 ++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 64468ffa9..1ea932ac3 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -724,9 +724,7 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) static void R_DrawVisSprite(vissprite_t *vis) { column_t *column; -#ifdef RANGECHECK INT32 texturecolumn; -#endif fixed_t frac; patch_t *patch = vis->patch; fixed_t this_scale = vis->thingscale; @@ -874,12 +872,16 @@ static void R_DrawVisSprite(vissprite_t *vis) } #endif - for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) + + // Split drawing loops for paper and non-paper to reduce conditional checks per sprite + if (vis->scalestep) { fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); - if (vis->scalestep) // currently papersprites only - { + // Papersprite drawing loop + for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + { #ifndef RANGECHECK if ((frac>>FRACBITS) < 0 || (frac>>FRACBITS) >= SHORT(patch->width)) // if this doesn't work i'm removing papersprites break; @@ -887,22 +889,30 @@ static void R_DrawVisSprite(vissprite_t *vis) sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale)); dc_iscale = (0xffffffffu / (unsigned)spryscale); spryscale += scalestep; + + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + + if (vis->vflip) + R_DrawFlippedMaskedColumn(column, patch->height); + else + R_DrawMaskedColumn(column); } -#ifdef RANGECHECK - texturecolumn = frac>>FRACBITS; - - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) - I_Error("R_DrawSpriteRange: bad texturecolumn"); - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); -#else - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[frac>>FRACBITS])); -#endif - if (vis->vflip) - R_DrawFlippedMaskedColumn(column, patch->height); - else - R_DrawMaskedColumn(column); } + else + { + for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + { + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + if (vis->vflip) + R_DrawFlippedMaskedColumn(column, patch->height); + else + R_DrawMaskedColumn(column); + } + } +#undef CLAMP colfunc = basecolfunc; dc_hires = 0; @@ -914,9 +924,7 @@ static void R_DrawVisSprite(vissprite_t *vis) static void R_DrawPrecipitationVisSprite(vissprite_t *vis) { column_t *column; -#ifdef RANGECHECK INT32 texturecolumn; -#endif fixed_t frac; patch_t *patch; INT64 overflow_test; @@ -956,20 +964,15 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { -#ifdef RANGECHECK - texturecolumn = frac>>FRACBITS; - - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) - I_Error("R_DrawPrecipitationSpriteRange: bad texturecolumn"); - + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); -#else - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[frac>>FRACBITS])); -#endif + R_DrawMaskedColumn(column); } +#undef CLAMP colfunc = basecolfunc; } From 040ddb1f40b17c84427c95a241a102c0e8f633bb Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:23:14 +0300 Subject: [PATCH 21/91] Revert "Revert "Don't traverse the entire HOME directory to find wads"" This reverts commit 443905ffb3dd8904c395c9c50570ccc17b42dd27. --- src/sdl/i_system.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 9574d6ec5..48e513afc 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -4039,12 +4039,16 @@ static const char *locateWad(void) #endif #ifndef NOHOME // find in $HOME - I_OutputMsg(",HOME"); + I_OutputMsg(",HOME/" DEFAULTDIR); if ((envstr = I_GetEnv("HOME")) != NULL) { + char *tmp = malloc(strlen(envstr) + sizeof(DEFAULTDIR)); + strcpy(tmp, envstr); + strcat(tmp, DEFAULTDIR); WadPath = searchWad(envstr); if (WadPath) return WadPath; + free(tmp); } #endif #ifdef DEFAULTSEARCHPATH1 From 6269c7c827feed85ef1bb246b4bed51c565bc6d5 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:32:18 +0300 Subject: [PATCH 22/91] Use tmp variable for searchWad since envstr doesn't get changed --- src/sdl/i_system.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 48e513afc..7a5f79f58 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -4042,13 +4042,14 @@ static const char *locateWad(void) I_OutputMsg(",HOME/" DEFAULTDIR); if ((envstr = I_GetEnv("HOME")) != NULL) { - char *tmp = malloc(strlen(envstr) + sizeof(DEFAULTDIR)); + char *tmp = malloc(strlen(envstr) + sizeof(PATHSEP) + sizeof(DEFAULTDIR)); strcpy(tmp, envstr); + strcat(tmp, PATHSEP); strcat(tmp, DEFAULTDIR); - WadPath = searchWad(envstr); + WadPath = searchWad(tmp); + free(tmp); if (WadPath) return WadPath; - free(tmp); } #endif #ifdef DEFAULTSEARCHPATH1 From dc03359f3a44481338715be809ebf9038bd47e6f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 30 May 2024 19:59:01 +0200 Subject: [PATCH 23/91] theres no value 3 oops i shouldnt do stuff after waking up at 4 in the morning lol --- src/hardware/hw_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 750b245fc..3cf998d84 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -184,7 +184,7 @@ static void CV_anisotropic_ONChange(void) static void CV_screentextures_ONChange(void) { ONLY_IF_GL_LOADED - if (cv_grscreentextures.value != 3) + if (cv_grscreentextures.value != 2) { #ifdef USE_FBO_OGL CV_Set(&cv_grframebuffer, "Off"); @@ -6240,10 +6240,10 @@ void HWR_DrawIntermissionBG(void) { patch_t *bgpatch = W_CachePatchName("SRB2BACK", PU_CACHE); - if (cv_grscreentextures.value != 3) - V_DrawPatchFill(bgpatch); // use the neato kart bg for intermission on disabled screen textures - else + if (cv_grscreentextures.value == 2) HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); + else + V_DrawPatchFill(bgpatch); // use the neato kart bg for intermission on disabled screen textures } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) From b01a2836ea51bfd8d52b8b1116df8ee93052db3d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:29:40 +0200 Subject: [PATCH 24/91] cleanup some super old stuff that did nothing lul --- src/hardware/hw_glob.h | 2 -- src/r_defs.h | 9 +-------- src/r_patch.c | 4 ++-- src/r_things.c | 42 +++++++++++++++--------------------------- src/r_things.h | 2 -- 5 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index a5b66a429..542a99b33 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -30,11 +30,9 @@ typedef struct gr_vissprite_s float gz, gzt; float tz, ty; float scale; - //lumpnum_t patchlumpnum; float spritexscale, spriteyscale; float spritexoffset, spriteyoffset; UINT32 renderflags; - UINT8 rotateflags; GLPatch_t *gpatch; boolean flip; UINT8 translucency; //alpha level 0-255 diff --git a/src/r_defs.h b/src/r_defs.h index 81e3f0c3a..40a4db023 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -649,15 +649,8 @@ typedef struct INT16 leftoffset; // pixels to the left of origin INT16 topoffset; // pixels below the origin INT32 columnofs[8]; // only [width] used - UINT8 *columns; // Software column data // the [0] is &columnofs[width] - - void *hardware; // OpenGL patch, allocated whenever necessary - -#ifdef ROTSPRITE - rotsprite_t *rotated; // Rotated patches -#endif -} patch_t; +}ATTRPACK patch_t; #ifdef _MSC_VER #pragma warning(disable : 4200) diff --git a/src/r_patch.c b/src/r_patch.c index 597a1a0de..bf0f28aa9 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -48,8 +48,8 @@ boolean R_CheckIfPatch(lumpnum_t lump) patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC); - width = patch->width; - height = patch->height; + width = SHORT(patch->width); + height = SHORT(patch->height); result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4)); diff --git a/src/r_things.c b/src/r_things.c index 1ea932ac3..8def2ff83 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -152,7 +152,6 @@ static void R_InstallSpriteLump(UINT16 wad, // graphics patch } #endif/*ROTSPRITE*/ - if (rotation == 0) { // the lump should be used for all rotations @@ -578,10 +577,8 @@ static vissprite_t *R_GetVisSprite(UINT32 num) static vissprite_t *R_NewVisSprite(void) { - if (visspritecount == MAXVISSPRITES) { - //CONS_Alert(CONS_ERROR, M_GetText("R_NewVisSprite: too many vissprites requested (maximum is %i)\n"), MAXVISSPRITES); + if (visspritecount == MAXVISSPRITES) return &overflowsprite; - } return R_GetVisSprite(visspritecount++); } @@ -656,8 +653,6 @@ void R_DrawMaskedColumn(column_t *column) dc_texturemid = basetexturemid; } -INT32 lengthcol; // column->length : for flipped column function pointers and multi-patch on 2sided wall = texture->height - static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) { INT32 topscreen; @@ -860,9 +855,6 @@ static void R_DrawVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; - lengthcol = SHORT(patch->height); - -#if 1 // Something is occasionally setting 1px-wide sprites whose frac is exactly the width of the sprite, causing crashes due to // accessing invalid column info. Until the cause is found, let's try to correct those manually... { @@ -870,7 +862,6 @@ static void R_DrawVisSprite(vissprite_t *vis) if (temp > 0) vis->x2 -= temp; } -#endif #define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) @@ -1177,6 +1168,7 @@ static void R_ProjectSprite(mobj_t *thing) // rotsprite fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; + #ifdef ROTSPRITE patch_t *rotsprite = NULL; INT32 rollangle = 0; @@ -1482,7 +1474,6 @@ static void R_ProjectSprite(mobj_t *thing) scalestep = (yscale2 - yscale)/(x2 - x1); scalestep = scalestep ? scalestep : 1; - // The following two are alternate sorting methods which might be more applicable in some circumstances. TODO - maybe enable via MF2? // sortscale = max(yscale, yscale2); @@ -1558,16 +1549,13 @@ static void R_ProjectSprite(mobj_t *thing) if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { - fixed_t top = gzt; - fixed_t bottom = interp.z; - if (viewz < sectors[phs].floorheight ? - bottom >= sectors[heightsec].floorheight : - top < sectors[heightsec].floorheight) + interp.z >= sectors[heightsec].floorheight : + gzt < sectors[heightsec].floorheight) return; if (viewz > sectors[phs].ceilingheight ? - top < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : - bottom >= sectors[heightsec].ceilingheight) + gzt < sectors[heightsec].ceilingheight && viewz >= sectors[heightsec].ceilingheight : + interp.z >= sectors[heightsec].ceilingheight) return; } @@ -1594,6 +1582,15 @@ static void R_ProjectSprite(mobj_t *thing) vis->x1 = x1 < 0 ? 0 : x1; vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; + // PORTAL SEMI-CLIPPING + if (portalrender) + { + if (vis->x1 < portalclipstart) + vis->x1 = portalclipstart; + if (vis->x2 > portalclipend) + vis->x2 = portalclipend; + } + vis->sector = thing->subsector->sector; vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, sortscale))>>FRACBITS); @@ -1604,15 +1601,6 @@ static void R_ProjectSprite(mobj_t *thing) else vis->extra_colormap = thing->subsector->sector->extra_colormap; - // PORTAL SEMI-CLIPPING - if (portalrender) - { - if (vis->x1 < portalclipstart) - vis->x1 = portalclipstart; - if (vis->x2 > portalclipend) - vis->x2 = portalclipend; - } - vis->xscale = FixedMul(spritexscale, xscale); //SoM: 4/17/2000 vis->scale = FixedMul(spriteyscale, yscale); //<thingscale = interp.scale; diff --git a/src/r_things.h b/src/r_things.h index 88e1abdab..da2e90168 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -172,12 +172,10 @@ typedef struct vissprite_s spritecut_e cut; UINT32 renderflags; - UINT8 rotateflags; fixed_t spritexscale, spriteyscale; fixed_t spritexoffset, spriteyoffset; - INT16 clipbot[MAXVIDWIDTH], cliptop[MAXVIDWIDTH]; boolean precip; From 37a394ebaa63db043ff11a3526100fcb4938239e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 31 May 2024 23:04:26 +0200 Subject: [PATCH 25/91] flexible array stuff for columnofs hopefully this fixes some crashes or smth --- src/r_defs.h | 2 +- src/r_patch.c | 28 ++++++++++++---------------- src/r_things.c | 3 +-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index 40a4db023..99a185c7a 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -648,7 +648,7 @@ typedef struct INT16 height; INT16 leftoffset; // pixels to the left of origin INT16 topoffset; // pixels below the origin - INT32 columnofs[8]; // only [width] used + INT32 columnofs[]; // only [width] used // the [0] is &columnofs[width] }ATTRPACK patch_t; diff --git a/src/r_patch.c b/src/r_patch.c index bf0f28aa9..eea97cfbb 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -772,6 +772,17 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) return 0xFF00; } +#ifdef HWRENDER +static patch_t *R_CreateHardwarePatch(patch_t *patch) +{ + GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); + grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); + grPatch->rawpatch = patch; + HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); + return (patch_t *)grPatch; +} +#endif + #ifdef ROTSPRITE // // R_GetRollAngle @@ -792,11 +803,7 @@ INT32 R_GetRollAngle(angle_t rollangle) return ra; } -patch_t *Patch_GetRotatedSprite( - spriteframe_t *sprite, - size_t frame, size_t spriteangle, - boolean flip, boolean adjustfeet, - void *info, INT32 rotationangle) +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; @@ -882,17 +889,6 @@ static void RotatedPatch_CalculateDimensions( *newheight = max(height, max(h1, h2)); } -#ifdef HWRENDER -static patch_t *R_CreateHardwarePatch(patch_t *patch) -{ - GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); - grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); - grPatch->rawpatch = patch; - HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); - return (patch_t *)grPatch; -} -#endif - void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) { UINT32 i; diff --git a/src/r_things.c b/src/r_things.c index 8def2ff83..c0efbf751 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1370,8 +1370,7 @@ static void R_ProjectSprite(mobj_t *thing) rollsum += thing->rollangle; rollangle = R_GetRollAngle(rollsum); - rotsprite = Patch_GetRotatedSprite( - sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); + rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); if (rotsprite != NULL) { From 8052eb1c3a0bf58fe531485ba709b528d75ba0fe Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:29:20 +0200 Subject: [PATCH 26/91] fix papersprites in software (hopefully) lul --- src/r_things.c | 178 ++++++++++++++++++++++++++++++++++++------------- src/r_things.h | 3 + 2 files changed, 133 insertions(+), 48 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index c0efbf751..daf589980 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -863,25 +863,27 @@ static void R_DrawVisSprite(vissprite_t *vis) vis->x2 -= temp; } -#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) - // Split drawing loops for paper and non-paper to reduce conditional checks per sprite if (vis->scalestep) { + fixed_t horzscale = FixedMul(vis->spritexscale, this_scale); fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); // Papersprite drawing loop - for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, spryscale += scalestep) { -#ifndef RANGECHECK - if ((frac>>FRACBITS) < 0 || (frac>>FRACBITS) >= SHORT(patch->width)) // if this doesn't work i'm removing papersprites - break; -#endif + angle_t angle = ((vis->centerangle + xtoviewangle[dc_x]) >> ANGLETOFINESHIFT) & 0xFFF; + texturecolumn = (vis->paperoffset - FixedMul(FINETANGENT(angle), vis->paperdistance)) / horzscale; + + if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) + continue; + + if (vis->xiscale < 0) // Flipped sprite + texturecolumn = SHORT(patch->width) - 1 - texturecolumn; + sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale)); dc_iscale = (0xffffffffu / (unsigned)spryscale); - spryscale += scalestep; - texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); if (vis->vflip) @@ -892,9 +894,12 @@ static void R_DrawVisSprite(vissprite_t *vis) } else { + // Non-paper drawing loop for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); +#undef CLAMP column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); if (vis->vflip) @@ -903,7 +908,7 @@ static void R_DrawVisSprite(vissprite_t *vis) R_DrawMaskedColumn(column); } } -#undef CLAMP + colfunc = basecolfunc; dc_hires = 0; @@ -1126,12 +1131,14 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope) static void R_ProjectSprite(mobj_t *thing) { mobj_t *oldthing = thing; + fixed_t tr_x, tr_y; fixed_t gxt, gyt; fixed_t tx, tz; fixed_t xscale, yscale, sortscale; //added : 02-02-98 : aaargll..if I were a math-guy!!! INT32 x1, x2; + INT32 x1test = 0, x2test = 0; spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1157,6 +1164,7 @@ 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; @@ -1176,8 +1184,6 @@ static void R_ProjectSprite(mobj_t *thing) angle_t pitchnroll = 0; angle_t sliptiderollangle = 0; #endif - - fixed_t ang_scale = FRACUNIT; INT32 dist = -1; @@ -1209,7 +1215,7 @@ static void R_ProjectSprite(mobj_t *thing) tz = gxt-gyt; // thing is behind view plane? - if (!(papersprite) && (tz < FixedMul(MINZ, this_scale))) // papersprite clipping is handled later + if (!papersprite && (tz < FixedMul(MINZ, this_scale))) // papersprite clipping is handled later return; gxt = -FixedMul(tr_x, viewsin); @@ -1280,14 +1286,9 @@ static void R_ProjectSprite(mobj_t *thing) { ang = R_PointToAngle (interp.x, interp.y) - interp.angle; camang = R_PointToAngle (interp.x, interp.y); - } - - if (sprframe->rotate != SRF_SINGLE || papersprite) - { + if (mirrored) ang = InvAngle(ang); - if (papersprite) - ang_scale = abs(FINESINE(ang>>ANGLETOFINESHIFT)); } if (sprframe->rotate == SRF_SINGLE) @@ -1387,10 +1388,11 @@ static void R_ProjectSprite(mobj_t *thing) } #endif + flip = !flip != !hflip; + // calculate edges of the shape spritexscale = interp.spritexscale; spriteyscale = interp.spriteyscale; - if (spritexscale < 1 || spriteyscale < 1) return; @@ -1409,39 +1411,19 @@ static void R_ProjectSprite(mobj_t *thing) spr_offset += interp.spritexoffset * flipoffset; spr_topoffset += interp.spriteyoffset * flipoffset; } - - flip = !flip != !hflip; if (flip) offset = spr_offset - spr_width; else offset = -spr_offset; - //offset = FixedMul(offset, FixedMul(spritexscale, this_scale)); - //offset2 = FixedMul(spr_width, FixedMul(spritexscale, this_scale)); // OH GOD I'M REVOOOOORTINGGGG AHHHHHHH - offset = FixedMul(offset, FixedMul(spritexscale, this_scale)); - tx += FixedMul(offset, ang_scale); - x1 = (centerxfrac + FixedMul (tx,xscale)) >>FRACBITS; - - // off the right side? - if (x1 > viewwidth) - return; - offset2 = FixedMul(spr_width, FixedMul(spritexscale, this_scale)); - tx += FixedMul(offset2, ang_scale); - x2 = ((centerxfrac + FixedMul (tx,xscale)) >> FRACBITS) - 1; - - // off the left side - if (x2 < 0) - return; if (papersprite) { - fixed_t yscale2, cosmul, sinmul, tz2; - - if (x2 <= x1) - return; + fixed_t xscale2, yscale2, cosmul, sinmul, tx2, tz2; + INT32 range; if (ang >= ANGLE_180) { @@ -1458,7 +1440,22 @@ static void R_ProjectSprite(mobj_t *thing) gyt = -FixedMul(tr_y, viewsin); tz = gxt-gyt; yscale = FixedDiv(projectiony, tz); - if (yscale < 64) return; // Fix some funky visuals + + gxt = -FixedMul(tr_x, viewsin); + gyt = FixedMul(tr_y, viewcos); + tx = -(gyt + gxt); + xscale = FixedDiv(projection, tz); + x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; + + // Get paperoffset (offset) and paperoffset (distance) + paperoffset = -FixedMul(tr_x, cosmul) - FixedMul(tr_y, sinmul); + paperdistance = -FixedMul(tr_x, sinmul) + FixedMul(tr_y, cosmul); + if (paperdistance < 0) + { + paperoffset = -paperoffset; + paperdistance = -paperdistance; + } + centerangle = viewangle - interp.angle; tr_x += FixedMul(offset2, cosmul); tr_y += FixedMul(offset2, sinmul); @@ -1466,13 +1463,72 @@ static void R_ProjectSprite(mobj_t *thing) gyt = -FixedMul(tr_y, viewsin); tz2 = gxt-gyt; yscale2 = FixedDiv(projectiony, tz2); - if (yscale2 < 64) return; // ditto + //if (yscale2 < 64) return; // ditto + + gxt = -FixedMul(tr_x, viewsin); + gyt = FixedMul(tr_y, viewcos); + tx2 = -(gyt + gxt); + xscale2 = FixedDiv(projection, tz2); + x2 = ((centerxfrac + FixedMul(tx2,xscale2))>>FRACBITS); if (max(tz, tz2) < FixedMul(MINZ, this_scale)) // non-papersprite clipping is handled earlier return; - scalestep = (yscale2 - yscale)/(x2 - x1); - scalestep = scalestep ? scalestep : 1; + // Needs partially clipped + if (tz < FixedMul(MINZ, this_scale)) + { + fixed_t div = FixedDiv(tz2-tz, FixedMul(MINZ, this_scale)-tz); + tx += FixedDiv(tx2-tx, div); + tz = FixedMul(MINZ, this_scale); + } + else if (tz2 < FixedMul(MINZ, this_scale)) + { + fixed_t div = FixedDiv(tz-tz2, FixedMul(MINZ, this_scale)-tz2); + tx2 += FixedDiv(tx-tx2, div); + tz2 = FixedMul(MINZ, this_scale); + } + + if ((tx2 / 4) < -(FixedMul(tz2, fovtan)) || (tx / 4) > FixedMul(tz, fovtan)) // too far off the side? + return; + + yscale = FixedDiv(projectiony, tz); + xscale = FixedDiv(projection, tz); + + x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; + + // off the right side? + if (x1 > viewwidth) + return; + + yscale2 = FixedDiv(projectiony, tz2); + xscale2 = FixedDiv(projection, tz2); + + x2 = (centerxfrac + FixedMul(tx2,xscale2))>>FRACBITS; + + // off the left side + if (x2 < 0) + return; + + range = x2 - x1; + + if (range < 0) + return; + + range++; // fencepost problem + + if (range > 32767) + { + // If the range happens to be too large for fixed_t, + // abort the draw to avoid xscale becoming negative due to arithmetic overflow. + return; + } + + scalestep = ((yscale2 - yscale)/range) ?: 1; + + if (scalestep == 0) + scalestep = 1; + + xscale = FixedDiv(range<>FRACBITS; + x1 = centerx + (FixedMul(tx,xscale) / FRACUNIT); - xscale = FixedMul(xscale, ang_scale); + x1test = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; + + if (x1test > viewwidth) + x1test = 0; + + // off the right side? + if (x1 > viewwidth) + return; + + tx += offset2; + //x2 = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS); x2--; + x2 = (centerx + (FixedMul(tx,xscale) / FRACUNIT)) - 1; + + x2test = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS) - 1; + + if (x2test < 0) + x2test = 0; + + // off the left side + if (x2 < 0) + return; + } // PORTAL SPRITE CLIPPING if (portalrender) @@ -1575,6 +1654,9 @@ static void R_ProjectSprite(mobj_t *thing) vis->pzt = vis->pz + vis->thingheight; vis->texturemid = FixedDiv(gzt - viewz, spriteyscale); vis->scalestep = scalestep; + vis->paperoffset = paperoffset; + vis->paperdistance = paperdistance; + vis->centerangle = centerangle; vis->mobj = thing; // Easy access! Tails 06-07-2002 diff --git a/src/r_things.h b/src/r_things.h index da2e90168..5b74eea02 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -149,8 +149,11 @@ 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 957159d4859b2c73221b55cd9d2444d925bf904f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:31:49 +0200 Subject: [PATCH 27/91] forgor to remove that --- src/r_things.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index daf589980..23208c622 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1138,7 +1138,6 @@ static void R_ProjectSprite(mobj_t *thing) fixed_t xscale, yscale, sortscale; //added : 02-02-98 : aaargll..if I were a math-guy!!! INT32 x1, x2; - INT32 x1test = 0, x2test = 0; spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1149,7 +1148,6 @@ static void R_ProjectSprite(mobj_t *thing) size_t rot; UINT8 flip; - /*boolean vflip = (!(thing->eflags & MFE_VERTICALFLIP) != !R_ThingVerticallyFlipped(thing));*/ boolean mirrored = thing->mirrored; boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); @@ -1542,11 +1540,6 @@ static void R_ProjectSprite(mobj_t *thing) //x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; x1 = centerx + (FixedMul(tx,xscale) / FRACUNIT); - x1test = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; - - if (x1test > viewwidth) - x1test = 0; - // off the right side? if (x1 > viewwidth) return; @@ -1555,11 +1548,6 @@ static void R_ProjectSprite(mobj_t *thing) //x2 = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS); x2--; x2 = (centerx + (FixedMul(tx,xscale) / FRACUNIT)) - 1; - x2test = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS) - 1; - - if (x2test < 0) - x2test = 0; - // off the left side if (x2 < 0) return; From 38633a85168f8577bfedd9899327821980f4dcfc Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 17:03:27 +0200 Subject: [PATCH 28/91] stuffs --- src/r_things.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 23208c622..884da6302 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -744,7 +744,7 @@ static void R_DrawVisSprite(vissprite_t *vis) // 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)) + if (vis->startfrac < 0 || vis->startfrac > (SHORT(patch->width) << FRACBITS)) { // never draw vissprites with startfrac out of patch range return; @@ -1554,7 +1554,7 @@ static void R_ProjectSprite(mobj_t *thing) } // PORTAL SPRITE CLIPPING - if (portalrender) + if (portalrender && portalclipline) { if (x2 < portalclipstart || x1 > portalclipend) return; @@ -1652,7 +1652,7 @@ static void R_ProjectSprite(mobj_t *thing) vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; // PORTAL SEMI-CLIPPING - if (portalrender) + if (portalrender && portalclipline) { if (vis->x1 < portalclipstart) vis->x1 = portalclipstart; @@ -1809,7 +1809,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) tx = -(gyt + gxt); // too far off the side? - if (abs(tx) > tz<<2) + if (abs(tx) > FixedMul(tz, fovtan)<<2) return; // aspect ratio stuff : @@ -1857,7 +1857,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; // PORTAL SPRITE CLIPPING - if (portalrender) + if (portalrender && portalclipline) { if (x2 < portalclipstart || x1 > portalclipend) return; @@ -1889,12 +1889,13 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->pzt = vis->pz + vis->thingheight; vis->texturemid = vis->gzt - viewz; vis->scalestep = 0; + vis->paperdistance = 0; vis->x1 = x1 < 0 ? 0 : x1; vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; // PORTAL SEMI-CLIPPING - if (portalrender) + if (portalrender && portalclipline) { if (vis->x1 < portalclipstart) vis->x1 = portalclipstart; From da9d57a6246ee969db0f69ca115eea857f15d468 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:39:22 +0300 Subject: [PATCH 29/91] Fix compilation for some gcc versions --- src/lua_maplib.c | 4 +++- src/lua_mobjlib.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 2ae2ce395..d92cd1f8b 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1647,6 +1647,7 @@ static int mapheaderinfo_get(lua_State *L) break; // TODO add support for reading numGradedMares and grades default: + { // Read custom vars now // (note: don't include the "LUA." in your lua scripts!) UINT8 j = 0; @@ -1657,6 +1658,7 @@ static int mapheaderinfo_get(lua_State *L) else lua_pushnil(L); } + } return 1; } @@ -1832,4 +1834,4 @@ int LUA_MapLib(lua_State *L) lua_setmetatable(L, -2); lua_setglobal(L, "mapheaderinfo"); return 0; -} \ No newline at end of file +} diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 866ea6550..f62e59486 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -886,11 +886,13 @@ static int mapthing_set(lua_State *L) mt->z = (INT16)luaL_checkinteger(L, 3); break; case mapthing_extrainfo: + { INT32 extrainfo = luaL_checkinteger(L, 3); if (extrainfo & ~15) return luaL_error(L, "mapthing_t extrainfo set %d out of range (%d - %d)", extrainfo, 0, 15); mt->extrainfo = (UINT8)extrainfo; break; + } case mapthing_mobj: mt->mobj = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); break; @@ -979,4 +981,4 @@ int LUA_MobjLib(lua_State *L) lua_setmetatable(L, -2); lua_setglobal(L, "mapthings"); return 0; -} \ No newline at end of file +} From 1747ebf481fab9e30d69aee23df7e59a9ec52d60 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:43:09 +0300 Subject: [PATCH 30/91] Lua_optoption shouldn't change stack state at the end of call now --- src/lua_script.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 381448e72..13cdf7bdf 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1680,6 +1680,8 @@ void LUA_UnArchiveDemo(void) // For mobj_t, player_t, etc. to take custom variables. int Lua_optoption(lua_State *L, int narg, int def, int list_ref) { + int result = -1; + if (lua_isnoneornil(L, narg)) return def; @@ -1692,8 +1694,11 @@ int Lua_optoption(lua_State *L, int narg, int def, int list_ref) lua_rawget(L, -2); if (lua_isnumber(L, -1)) - return lua_tointeger(L, -1); - return -1; + result = lua_tointeger(L, -1); + + lua_pop(L, 2); // Pop result and fields table + + return result; } @@ -1710,4 +1715,4 @@ int Lua_CreateFieldTable(lua_State *L, const char *const lst[]) } return luaL_ref(L, LUA_REGISTRYINDEX); -} \ No newline at end of file +} From 0e927ce4bd087988c29487fd00f5e9055c1ad514 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:43:42 +0300 Subject: [PATCH 31/91] Make sfxinfo_t and state_t use field tables too --- src/lua_infolib.c | 269 ++++++++++++++++++++++++++++++---------------- 1 file changed, 176 insertions(+), 93 deletions(-) diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 5c6918890..3ab044188 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -26,32 +26,6 @@ boolean LUA_CallAction(const char *action, mobj_t *actor); state_t *astate; -enum sfxinfo_read { - sfxinfor_name = 0, - sfxinfor_singular, - sfxinfor_priority, - sfxinfor_flags, // "pitch" - sfxinfor_skinsound -}; -const char *const sfxinfo_ropt[] = { - "name", - "singular", - "priority", - "flags", - "skinsound", - NULL}; - -enum sfxinfo_write { - sfxinfow_singular = 0, - sfxinfow_priority, - sfxinfow_flags // "pitch" -}; -const char *const sfxinfo_wopt[] = { - "singular", - "priority", - "flags", - NULL}; - // // Sprite Names // @@ -101,7 +75,7 @@ static void A_Lua(mobj_t *actor) { boolean found = false; I_Assert(actor != NULL); - + lua_settop(gL, 0); // Just in case... lua_pushcfunction(gL, LUA_GetErrorMessage); @@ -286,7 +260,7 @@ boolean LUA_CallAction(const char *csaction, mobj_t *actor) if (superstack && fasticmp(csaction, superactions[superstack-1])) // the action is calling itself, return false; // let it call the hardcoded function instead. - + lua_pushcfunction(gL, LUA_GetErrorMessage); // grab function by uppercase name. @@ -330,49 +304,93 @@ boolean LUA_CallAction(const char *csaction, mobj_t *actor) return true; // action successfully called. } +enum state_e { + state_sprite = 0, + state_frame, + state_tics, + state_action, + state_var1, + state_var2, + state_nextstate, +}; + +const char *const state_opt[] = { + "sprite", + "frame", + "tics", + "action", + "var1", + "var2", + "nextstate", + NULL +}; + +static int state_fields_ref = LUA_NOREF; + // state_t *, field -> number static int state_get(lua_State *L) { state_t *st = *((state_t **)luaL_checkudata(L, 1, META_STATE)); - const char *field = luaL_checkstring(L, 2); + enum state_e field = Lua_optoption(L, 2, -1, state_fields_ref); lua_Integer number; - if (fastcmp(field,"sprite")) - number = st->sprite; - else if (fastcmp(field,"frame")) - number = st->frame; - else if (fastcmp(field,"tics")) - number = st->tics; - else if (fastcmp(field,"action")) { - const char *name; - if (!st->action.acp1) // Action is NULL. - return 0; // return nil. - if (st->action.acp1 == (actionf_p1)A_Lua) { // This is a Lua function? - lua_getfield(L, LUA_REGISTRYINDEX, LREG_STATEACTION); - I_Assert(lua_istable(L, -1)); - lua_pushlightuserdata(L, st); // Push the state pointer and - lua_rawget(L, -2); // use it to get the actual Lua function. - lua_remove(L, -2); // pop LREG_STATEACTION - return 1; // Return the Lua function. + switch (field) + { + case state_sprite: + number = st->sprite; + break; + + case state_frame: + number = st->frame; + break; + + case state_tics: + number = st->tics; + break; + + case state_action: + { + const char *name; + if (!st->action.acp1) // Action is NULL. + return 0; // return nil. + if (st->action.acp1 == (actionf_p1)A_Lua) { // This is a Lua function? + lua_getfield(L, LUA_REGISTRYINDEX, LREG_STATEACTION); + I_Assert(lua_istable(L, -1)); + lua_pushlightuserdata(L, st); // Push the state pointer and + lua_rawget(L, -2); // use it to get the actual Lua function. + lua_remove(L, -2); // pop LREG_STATEACTION + return 1; // Return the Lua function. + } + name = LUA_GetActionName(&st->action); // find a hardcoded function name + if (!name) // If it's not a hardcoded function and it's not a Lua function... + return 0; // Just what is this?? + // get the function from the global + // because the metatable will trigger. + lua_getglobal(L, name); // actually gets from LREG_ACTIONS if applicable, and pushes a new C closure if not. + lua_pushstring(L, name); // push the name we found. + return 2; // return both the function and its name, in case somebody wanted to do a comparison by name or something? } - name = LUA_GetActionName(&st->action); // find a hardcoded function name - if (!name) // If it's not a hardcoded function and it's not a Lua function... - return 0; // Just what is this?? - // get the function from the global - // because the metatable will trigger. - lua_getglobal(L, name); // actually gets from LREG_ACTIONS if applicable, and pushes a new C closure if not. - lua_pushstring(L, name); // push the name we found. - return 2; // return both the function and its name, in case somebody wanted to do a comparison by name or something? - } else if (fastcmp(field,"var1")) - number = st->var1; - else if (fastcmp(field,"var2")) - number = st->var2; - else if (fastcmp(field,"nextstate")) - number = st->nextstate; - else if (devparm) - return luaL_error(L, LUA_QL("state_t") " has no field named " LUA_QS, field); - else - return 0; + break; + + case state_var1: + number = st->var1; + break; + + case state_var2: + number = st->var2; + break; + + case state_nextstate: + number = st->nextstate; + break; + + default: + { + if (devparm) + return luaL_error(L, LUA_QL("state_t") " has no field named " LUA_QS, field); + return 0; + } + } lua_pushinteger(L, number); return 1; @@ -382,7 +400,7 @@ static int state_get(lua_State *L) static int state_set(lua_State *L) { state_t *st = *((state_t **)luaL_checkudata(L, 1, META_STATE)); - const char *field = luaL_checkstring(L, 2); + enum state_e field = Lua_optoption(L, 2, -1, state_fields_ref); lua_Integer value; if (hud_running) @@ -390,16 +408,24 @@ static int state_set(lua_State *L) if (hook_cmd_running) return luaL_error(L, "Do not alter states in BuildCMD code!"); - if (fastcmp(field,"sprite")) { + switch (field) + { + case state_sprite: value = luaL_checknumber(L, 3); if (value < SPR_NULL || value >= NUMSPRITES) return luaL_error(L, "sprite number %d is invalid.", value); st->sprite = (spritenum_t)value; - } else if (fastcmp(field,"frame")) + break; + + case state_frame: st->frame = (UINT32)luaL_checknumber(L, 3); - else if (fastcmp(field,"tics")) + break; + + case state_tics: st->tics = (INT32)luaL_checknumber(L, 3); - else if (fastcmp(field,"action")) { + break; + + case state_action: switch(lua_type(L, 3)) { case LUA_TNIL: // Null? Set the action to nothing, then. @@ -420,17 +446,26 @@ static int state_set(lua_State *L) default: // ?! return luaL_typerror(L, 3, "function"); } - } else if (fastcmp(field,"var1")) + break; + + case state_var1: st->var1 = (INT32)luaL_checknumber(L, 3); - else if (fastcmp(field,"var2")) + break; + + case state_var2: st->var2 = (INT32)luaL_checknumber(L, 3); - else if (fastcmp(field,"nextstate")) { + break; + + case state_nextstate: value = luaL_checkinteger(L, 3); if (value < S_NULL || value >= NUMSTATES) return luaL_error(L, "nextstate number %d is invalid.", value); st->nextstate = (statenum_t)value; - } else + break; + + default: return luaL_error(L, LUA_QL("state_t") " has no field named " LUA_QS, field); + } return 0; } @@ -627,7 +662,7 @@ static int mobjinfo_fields_ref = LUA_NOREF; static int mobjinfo_get(lua_State *L) { mobjinfo_t *info = *((mobjinfo_t **)luaL_checkudata(L, 1, META_MOBJINFO)); - enum mobjinfo_e field = luaL_checkoption(L, 2, mobjinfo_opt[0], mobjinfo_opt); + enum mobjinfo_e field = Lua_optoption(L, 2, -1, mobjinfo_fields_ref); I_Assert(info != NULL); I_Assert(info >= mobjinfo); @@ -863,6 +898,25 @@ static int lib_getSfxInfo(lua_State *L) return 1; } +enum sfxinfo_e { + sfxinfo_name = 0, + sfxinfo_singular, + sfxinfo_priority, + sfxinfo_flags, // "pitch" + sfxinfo_skinsound +}; + +const char *const sfxinfo_opt[] = { + "name", + "singular", + "priority", + "flags", + "skinsound", + NULL +}; + +static int sfxinfo_fields_ref = LUA_NOREF; + // stack: dummy, S_sfx[] table index, table of values to set. static int lib_setSfxInfo(lua_State *L) { @@ -886,22 +940,44 @@ static int lib_setSfxInfo(lua_State *L) lua_pushnil(L); while (lua_next(L, 1)) { - enum sfxinfo_write i; + enum sfxinfo_e i; if (lua_isnumber(L, 2)) - i = lua_tointeger(L, 2) - 1; // lua is one based, this enum is zero based. + { + int j = lua_tointeger(L, 2) - 1; + + // Read and Write enums were combined, need to do this switch now + switch (j) + { + case 1: + i = sfxinfo_singular; + break; + + case 2: + i = sfxinfo_priority; + break; + + case 3: + i = sfxinfo_flags; + break; + + default: + i = -1; + break; + } + } else - i = luaL_checkoption(L, 2, NULL, sfxinfo_wopt); + i = Lua_optoption(L, 2, -1, sfxinfo_fields_ref); switch(i) { - case sfxinfow_singular: + case sfxinfo_singular: info->singularity = luaL_checkboolean(L, 3); break; - case sfxinfow_priority: + case sfxinfo_priority: info->priority = (INT32)luaL_checkinteger(L, 3); break; - case sfxinfow_flags: + case sfxinfo_flags: info->pitch = (INT32)luaL_checkinteger(L, 3); break; default: @@ -923,29 +999,29 @@ static int lib_sfxlen(lua_State *L) static int sfxinfo_get(lua_State *L) { sfxinfo_t *sfx = *((sfxinfo_t **)luaL_checkudata(L, 1, META_SFXINFO)); - enum sfxinfo_read field = luaL_checkoption(L, 2, NULL, sfxinfo_ropt); + enum sfxinfo_e field = Lua_optoption(L, 2, -1, sfxinfo_fields_ref); I_Assert(sfx != NULL); switch (field) { - case sfxinfor_name: + case sfxinfo_name: lua_pushstring(L, sfx->name); return 1; - case sfxinfor_singular: + case sfxinfo_singular: lua_pushboolean(L, sfx->singularity); return 1; - case sfxinfor_priority: + case sfxinfo_priority: lua_pushinteger(L, sfx->priority); return 1; - case sfxinfor_flags: + case sfxinfo_flags: lua_pushinteger(L, sfx->pitch); return 1; - case sfxinfor_skinsound: + case sfxinfo_skinsound: lua_pushinteger(L, sfx->skinsound); return 1; default: - return luaL_error(L, "impossible error"); + return luaL_error(L, LUA_QL("sfxinfo_t") " has no field named " LUA_QS, lua_tostring(L, 2)); } return 0; } @@ -954,7 +1030,7 @@ static int sfxinfo_get(lua_State *L) static int sfxinfo_set(lua_State *L) { sfxinfo_t *sfx = *((sfxinfo_t **)luaL_checkudata(L, 1, META_SFXINFO)); - enum sfxinfo_write field = luaL_checkoption(L, 2, NULL, sfxinfo_wopt); + int field = Lua_optoption(L, 2, -1, sfxinfo_fields_ref); if (hud_running) return luaL_error(L, "Do not alter S_sfx in HUD rendering code!"); @@ -969,17 +1045,20 @@ static int sfxinfo_set(lua_State *L) switch (field) { - case sfxinfow_singular: + case sfxinfo_singular: sfx->singularity = luaL_checkboolean(L, 1); break; - case sfxinfow_priority: + case sfxinfo_priority: sfx->priority = luaL_checkinteger(L, 1); break; - case sfxinfow_flags: + case sfxinfo_flags: sfx->pitch = luaL_checkinteger(L, 1); break; default: - return luaL_error(L, "impossible error"); + if (field == -1) + return luaL_error(L, LUA_QL("sfxinfo_t") " has no field named " LUA_QS, lua_tostring(L, 2)); + else + return luaL_error(L, LUA_QL("sfxinfo_t") " field " LUA_QS " is read-only", lua_tostring(L, 2)); } return 0; } @@ -1021,6 +1100,8 @@ int LUA_InfoLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + state_fields_ref = Lua_CreateFieldTable(L, state_opt); + luaL_newmetatable(L, META_MOBJINFO); lua_pushcfunction(L, mobjinfo_get); lua_setfield(L, -2, "__index"); @@ -1045,6 +1126,8 @@ int LUA_InfoLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + sfxinfo_fields_ref = Lua_CreateFieldTable(L, sfxinfo_opt); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSprname); @@ -1096,4 +1179,4 @@ int LUA_InfoLib(lua_State *L) lua_setglobal(L, "S_sfx"); lua_setglobal(L, "sfxinfo"); return 0; -} \ No newline at end of file +} From bf75644144290de36bca71126294b60e3938cd99 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:28:27 +0200 Subject: [PATCH 32/91] make r_fps if else hell a bit more bearable to look at lol lmao --- src/r_fps.c | 67 ++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 91044b42e..52a89098f 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -287,6 +287,11 @@ angle_t R_InterpolateAngle(angle_t from, angle_t to) return (R_LerpAngle(from, to, rendertimefrac)); }*/ +#define IFCHANGED(a, b)\ +if (mobj->a == mobj->b)\ +(out->a = mobj->b);\ +else + void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) { if (frac == FRACUNIT) @@ -308,44 +313,28 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) return; } - if (mobj->x == mobj->old_x) - out->x = mobj->x; - else + IFCHANGED(x, old_x) out->x = R_LerpFixed(mobj->old_x, mobj->x, frac); - if (mobj->y == mobj->old_y) - out->y = mobj->y; - else + IFCHANGED(y, old_y) out->y = R_LerpFixed(mobj->old_y, mobj->y, frac); - if (mobj->z == mobj->old_z) - out->z = mobj->z; - else + IFCHANGED(z, old_z) out->z = R_LerpFixed(mobj->old_z, mobj->z, frac); - if (mobj->spritexscale == mobj->old_spritexscale) - out->spritexscale = mobj->spritexscale; - else + IFCHANGED(spritexscale, old_spritexscale) out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac); - if (mobj->spriteyscale == mobj->old_spriteyscale) - out->spriteyscale = mobj->spriteyscale; - else + IFCHANGED(spriteyscale, old_spriteyscale) out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac); - if (mobj->spritexoffset == mobj->old_spritexoffset) - out->spritexoffset = mobj->spritexoffset; - else + IFCHANGED(spritexoffset, old_spritexoffset) out->spritexoffset = mobj->resetinterp ? mobj->spritexoffset : R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac); - if (mobj->spriteyoffset == mobj->old_spriteyoffset) - out->spriteyoffset = mobj->spriteyoffset; - else + IFCHANGED(spriteyoffset, old_spriteyoffset) out->spriteyoffset = mobj->resetinterp ? mobj->spriteyoffset : R_LerpFixed(mobj->old_spriteyoffset, mobj->spriteyoffset, frac); - if (mobj->scale == mobj->old_scale) // Tiny optimisation - scale is usually unchanging, so let's skip a lerp, two FixedMuls, and two FixedDivs - out->scale = mobj->scale; - else + IFCHANGED(scale, old_scale) out->scale = mobj->resetinterp ? mobj->scale : R_LerpFixed(mobj->old_scale, mobj->scale, frac); if (cv_mobjssector.value) @@ -355,39 +344,27 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out) if (mobj->player) { - if (mobj->angle == mobj->player->old_frameangle) - out->angle = mobj->player->frameangle; - else + IFCHANGED(angle, player->old_frameangle) out->angle = mobj->resetinterp ? mobj->player->frameangle : R_LerpAngle(mobj->player->old_frameangle, mobj->player->frameangle, frac); } else { - if (mobj->angle == mobj->old_angle) - out->angle = mobj->angle; - else + IFCHANGED(angle, old_angle) out->angle = mobj->resetinterp ? mobj->angle : R_LerpAngle(mobj->old_angle, mobj->angle, frac); } // pitch roll stuff - if (mobj->pitch == mobj->old_pitch) - out->pitch = mobj->pitch; - else + IFCHANGED(pitch, old_pitch) out->pitch = mobj->resetinterp ? mobj->pitch : R_LerpAngle(mobj->old_pitch, mobj->pitch, frac); - if (mobj->roll == mobj->old_roll) - out->roll = mobj->roll; - else + IFCHANGED(roll, old_roll) out->roll = mobj->resetinterp ? mobj->roll : R_LerpAngle(mobj->old_roll, mobj->roll, frac); // and the slope stuff - if (mobj->slopepitch == mobj->old_slopepitch) - out->slopepitch = mobj->slopepitch; - else + IFCHANGED(slopepitch, old_slopepitch) out->slopepitch = mobj->resetinterp ? mobj->slopepitch : R_LerpAngle(mobj->old_slopepitch, mobj->slopepitch, frac); - if (mobj->sloperoll == mobj->old_sloperoll) - out->sloperoll = mobj->sloperoll; - else + IFCHANGED(sloperoll, old_sloperoll) out->sloperoll = mobj->resetinterp ? mobj->sloperoll : R_LerpAngle(mobj->old_sloperoll, mobj->sloperoll, frac); } @@ -422,12 +399,12 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst else out->subsector = mobj->subsector; - if (mobj->angle == mobj->old_angle) - out->angle = mobj->angle; - else + IFCHANGED(angle, old_angle) out->angle = R_LerpAngle(mobj->old_angle, mobj->angle, frac); } +#undef IFCHANGED + static void AddInterpolator(levelinterpolator_t* interpolator) { if (levelinterpolators_len >= levelinterpolators_size) From ee2ec01eb9796c41f435cbfa41a7046bff4039c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 2 Jun 2024 00:44:48 +0200 Subject: [PATCH 33/91] use shader to prevent sprite floor clipping from durr lul --- src/hardware/hw_main.c | 25 ------------------------- src/hardware/hw_shaders.c | 2 +- src/hardware/hw_shaders.h | 11 +++++++++++ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3cf998d84..c5be8d185 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3970,18 +3970,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // Let dispoffset work first since this adjust each vertex HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); - // push it toward the camera to mitigate floor-clipping sprites - { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - for (i = 0; i < 4; i++) - { - baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; - baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; - baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; - } - } - realtop = top = baseWallVerts[3].y; realbot = bot = baseWallVerts[0].y; towtop = baseWallVerts[3].t; @@ -4252,19 +4240,6 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) // ...nah HWR_RotateSpritePolyToAim(spr, wallVerts, false); - // push it toward the camera to mitigate floor-clipping sprites - { - float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); - float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; - size_t i; - for (i = 0; i < 4; i++) - { - wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; - wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; - wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; - } - } - // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. // sprite lighting by modulating the RGB components /// \todo coloured diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 427bd1540..a20375981 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -33,7 +33,7 @@ static struct { {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Sprite shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, + {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Model shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index eb705c34c..e817419a1 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -31,6 +31,17 @@ "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ "}\0" +// Sprite clipping makes me want to McFucking Die + +#define GLSL_SPRITECLIP_HACK_VERTEX_SHADER \ + "void main(void) {\n" \ + "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \ + "gl_FrontColor = gl_Color;\n" \ + "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ + "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ + "gl_Position.z -= 80 / gl_Position.z;\n" \ + "}\0" + // ================== // Fragment shaders // ================== From cae40928ad16d088168bc4ba890de890d9337ee6 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 3 Jun 2024 00:17:11 +0300 Subject: [PATCH 34/91] Use Z_Calloc to allocate wadfile_t to avoid having uninitialized fields --- src/w_wad.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index cd2968494..15c7db38c 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -789,7 +789,7 @@ UINT16 W_InitFile(const char *filename, boolean local) // // link wad file to search files // - wadfile = Z_Malloc(sizeof (*wadfile), PU_STATIC, NULL); + wadfile = Z_Calloc(sizeof (*wadfile), PU_STATIC, NULL); wadfile->filename = Z_StrDup(filename); wadfile->handle = handle; wadfile->numlumps = (UINT16)numlumps; @@ -798,7 +798,6 @@ UINT16 W_InitFile(const char *filename, boolean local) 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); From f977af6a802ffb4330a21d9c790a0e37c72c8e5b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 15:13:39 +0200 Subject: [PATCH 35/91] fix le dispoffset --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 23 ++++++++++++++++++++++- src/hardware/hw_shaders.c | 4 ++++ src/hardware/hw_shaders.h | 2 +- src/r_things.c | 3 +-- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 419549d73..d16b490b7 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -174,6 +174,7 @@ enum SHADER_NONE = -1, SHADER_FLOOR = 0, SHADER_WALL, + SHADER_SPRITECLIPHACK, SHADER_MODEL, SHADER_SPRITE, SHADER_WATER, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c5be8d185..61d4e85e0 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3967,6 +3967,17 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) baseWallVerts[0].t = baseWallVerts[1].t = gpatch->max_t; } + // if it has a dispoffset, push it a little towards the camera + if (spr->dispoffset) + { + float co = -gr_viewcos*(0.05f*spr->dispoffset); + float si = -gr_viewsin*(0.05f*spr->dispoffset); + baseWallVerts[0].z = baseWallVerts[3].z = baseWallVerts[0].z+si; + baseWallVerts[1].z = baseWallVerts[2].z = baseWallVerts[1].z+si; + baseWallVerts[0].x = baseWallVerts[3].x = baseWallVerts[0].x+co; + baseWallVerts[1].x = baseWallVerts[2].x = baseWallVerts[1].x+co; + } + // Let dispoffset work first since this adjust each vertex HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); @@ -4236,8 +4247,18 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_DrawSpriteShadow(spr, gpatch, this_scale); } + // if it has a dispoffset, push it a little towards the camera + if (spr->dispoffset) + { + float co = -gr_viewcos*(0.05f*spr->dispoffset); + float si = -gr_viewsin*(0.05f*spr->dispoffset); + wallVerts[0].z = wallVerts[3].z = wallVerts[0].z+si; + wallVerts[1].z = wallVerts[2].z = wallVerts[1].z+si; + wallVerts[0].x = wallVerts[3].x = wallVerts[0].x+co; + wallVerts[1].x = wallVerts[2].x = wallVerts[1].x+co; + } + // Let dispoffset work first since this adjust each vertex - // ...nah HWR_RotateSpritePolyToAim(spr, wallVerts, false); // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index a20375981..fb6b9661c 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -33,6 +33,9 @@ static struct { {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Sprite shader + {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, + + // Sprite clipping hack shader (for pulling things out of the floor) {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Model shader @@ -424,6 +427,7 @@ customshaderxlat_t shaderxlat[] = {"Flat", SHADER_FLOOR}, {"WallTexture", SHADER_WALL}, {"Sprite", SHADER_SPRITE}, + {"SpriteClipHack", SHADER_SPRITECLIPHACK}, {"Model", SHADER_MODEL}, {"WaterRipple", SHADER_WATER}, {"Fog", SHADER_FOG}, diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index e817419a1..3840eaef1 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -39,7 +39,7 @@ "gl_FrontColor = gl_Color;\n" \ "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_Position.z -= 80 / gl_Position.z;\n" \ + "gl_Position.z -= 80.0 / gl_Position.z;\n" \ "}\0" // ================== diff --git a/src/r_things.c b/src/r_things.c index 884da6302..0fa96a4ce 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -299,8 +299,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, spritecachedinfo[numspritelumps].height = SHORT(patch.height)< Date: Mon, 3 Jun 2024 13:53:59 +0200 Subject: [PATCH 36/91] add toggle for beta intermission screen + smol cleanup --- src/d_netcmd.c | 4 ++++ src/d_netcmd.h | 2 ++ src/hardware/hw_main.c | 7 +------ src/y_inter.c | 29 ++++++++++++++++++----------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1e46da57f..8701448b4 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -577,6 +577,8 @@ static CV_PossibleValue_t skinselectgridsort_t[] ={ }; consvar_t cv_skinselectgridsort ={ "skinselectgridsort", "Real name", CV_SAVE|CV_CALL|CV_NOINIT, skinselectgridsort_t, sortSkinGrid, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_betainterscreen = {"betaintermissionscreen", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + INT16 gametype = GT_RACE; // SRB2kart boolean forceresetplayers = false; boolean deferencoremode = false; @@ -822,6 +824,8 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_netdemosyncquality); CV_RegisterVar(&cv_maxdemosize); CV_RegisterVar(&cv_keyboardlayout); + + CV_RegisterVar(&cv_betainterscreen); } // ========================================================================= diff --git a/src/d_netcmd.h b/src/d_netcmd.h index e9934e237..b02b68f00 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -205,6 +205,8 @@ extern consvar_t cv_showtrackaddon; extern consvar_t cv_showspecstuff; +extern consvar_t cv_betainterscreen; + typedef enum { SKINMENUTYPE_SCROLL = 0, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 61d4e85e0..af7fc8f37 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6234,12 +6234,7 @@ void HWR_EndScreenWipe(void) void HWR_DrawIntermissionBG(void) { - patch_t *bgpatch = W_CachePatchName("SRB2BACK", PU_CACHE); - - if (cv_grscreentextures.value == 2) - HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); - else - V_DrawPatchFill(bgpatch); // use the neato kart bg for intermission on disabled screen textures + HWD.pfnDrawScreenTexture(HWD_SCREENTEXTURE_GENERIC1, NULL, 0); } void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) diff --git a/src/y_inter.c b/src/y_inter.c index cc1d7dd9c..58cfdc4e0 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -100,10 +100,10 @@ static y_data data; static patch_t *bgpatch = NULL; // INTERSCR static patch_t *widebgpatch = NULL; // INTERSCW static patch_t *bgtile = NULL; // SPECTILE/SRB2BACK -static patch_t *interpic = NULL; // custom picture defined in map header -static boolean usetile; +//static patch_t *interpic = NULL; // custom picture defined in map header +//static boolean usetile; boolean usebuffer = false; -static boolean useinterpic; +//static boolean useinterpic; static INT32 timer; static INT32 intertic; @@ -392,9 +392,16 @@ void Y_IntermissionDrawer(void) if (!usebuffer) V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); - if (useinterpic) - V_DrawScaledPatch(0, 0, 0, interpic); - else if (!usetile) + if (cv_betainterscreen.value +#ifdef HWRENDER + || (rendermode == render_opengl && cv_grscreentextures.value != 2) // use the neato kart bg for intermission on disabled screen textures +#endif + ) + V_DrawPatchFill(bgtile); // use the neato kart bg for intermission on disabled screen textures + //else if (useinterpic) + //V_DrawScaledPatch(0, 0, 0, interpic); + //else if (!usetile) + else { if (rendermode == render_soft && usebuffer) VID_BlitLinearScreen(screens[1], screens[0], vid.width*vid.bpp, vid.height, vid.width*vid.bpp, vid.rowbytes); @@ -412,8 +419,8 @@ void Y_IntermissionDrawer(void) V_DrawScaledPatch(0, 0, 0, bgpatch); } } - else if (bgtile) - V_DrawPatchFill(bgtile); + //else if (bgtile) + //V_DrawPatchFill(bgtile); if (usebuffer) // Fade everything out V_DrawFadeScreen(0xFF00, 22); @@ -937,8 +944,8 @@ void Y_StartIntermission(void) //if (intertype == int_race || intertype == int_match) { - //bgtile = W_CachePatchName("SRB2BACK", PU_STATIC); - usetile = useinterpic = false; + bgtile = W_CachePatchName("SRB2BACK", PU_STATIC); + //usetile = useinterpic = false; usebuffer = true; } @@ -988,7 +995,7 @@ static void Y_UnloadData(void) UNLOAD(bgpatch); UNLOAD(widebgpatch); UNLOAD(bgtile); - UNLOAD(interpic); + //UNLOAD(interpic); } // SRB2Kart: Voting! From 9de3db7c97492486264c7faf378598f5b8d77868 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 16:52:25 +0200 Subject: [PATCH 37/91] add shader for shadows to also fix sprite shadows in pal render --- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 8 +++++--- src/hardware/hw_shaders.c | 4 ++++ src/hardware/hw_shaders.h | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index d16b490b7..9f95f8fcd 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -173,6 +173,7 @@ enum { SHADER_NONE = -1, SHADER_FLOOR = 0, + SHADER_SHADOW, SHADER_WALL, SHADER_SPRITECLIPHACK, SHADER_MODEL, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index af7fc8f37..6fae23c77 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3647,6 +3647,7 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t { FOutVector swallVerts[4]; FSurfaceInfo sSurf; + FBITFIELD blendmode = 0; fixed_t floorheight, mobjfloor; pslope_t *floorslope; fixed_t slopez; @@ -3802,13 +3803,14 @@ 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); - + if (HWR_UseShader()) { - shader = SHADER_FLOOR; // floor shader + shader = SHADER_SHADOW; + blendmode |= PF_ColorMapped; } - HWR_ProcessPolygon(&sSurf, swallVerts, 4, PF_Translucent|PF_Modulated, shader, false); + HWR_ProcessPolygon(&sSurf, swallVerts, 4, blendmode|PF_Translucent|PF_Modulated, shader, false); } } diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index fb6b9661c..c4109837c 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -29,6 +29,9 @@ static struct { // Floor shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_FLOOR_FRAGMENT_SHADER}, + // Shadow shader + {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_SHADOW_FRAGMENT_SHADER}, + // Wall shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, @@ -425,6 +428,7 @@ static inline UINT16 HWR_FindShaderDefs(UINT16 wadnum) customshaderxlat_t shaderxlat[] = { {"Flat", SHADER_FLOOR}, + {"Shadow", SHADER_SHADOW}, {"WallTexture", SHADER_WALL}, {"Sprite", SHADER_SPRITE}, {"SpriteClipHack", SHADER_SPRITECLIPHACK}, diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 3840eaef1..6c225b1a8 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -144,6 +144,26 @@ "gl_FragColor = final_color;\n" \ "}\n" \ "#endif\0" + +#define GLSL_SOFTWARE_FRAGMENT_SHADER_NOPAL \ + "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 \ + "void main(void) {\n" \ + "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "vec4 base_color = texel * poly_color;\n" \ + "vec4 final_color = base_color;\n" \ + GLSL_SOFTWARE_TINT_EQUATION \ + GLSL_SOFTWARE_FADE_EQUATION \ + "final_color.a = texel.a * poly_color.a;\n" \ + "gl_FragColor = final_color;\n" \ + "}\n" \ // hand tuned adjustments for light level calculation #define GLSL_FLOOR_FUDGES \ @@ -161,6 +181,10 @@ #define GLSL_WALL_FRAGMENT_SHADER \ GLSL_WALL_FUDGES \ GLSL_SOFTWARE_FRAGMENT_SHADER + +#define GLSL_SHADOW_FRAGMENT_SHADER \ + GLSL_FLOOR_FUDGES \ + GLSL_SOFTWARE_FRAGMENT_SHADER_NOPAL // // Water surface shader From ea510f95b899220be4251a8b95729f9b9e874db6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 17:15:36 +0200 Subject: [PATCH 38/91] Revert "fix le dispoffset" This reverts commit f977af6a802ffb4330a21d9c790a0e37c72c8e5b. --- src/hardware/hw_defs.h | 1 - src/hardware/hw_main.c | 23 +---------------------- src/hardware/hw_shaders.c | 4 ---- src/hardware/hw_shaders.h | 2 +- src/r_things.c | 3 ++- 5 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 9f95f8fcd..b19106fff 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -175,7 +175,6 @@ enum SHADER_FLOOR = 0, SHADER_SHADOW, SHADER_WALL, - SHADER_SPRITECLIPHACK, SHADER_MODEL, SHADER_SPRITE, SHADER_WATER, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 6fae23c77..eed9f9232 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3969,17 +3969,6 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) baseWallVerts[0].t = baseWallVerts[1].t = gpatch->max_t; } - // if it has a dispoffset, push it a little towards the camera - if (spr->dispoffset) - { - float co = -gr_viewcos*(0.05f*spr->dispoffset); - float si = -gr_viewsin*(0.05f*spr->dispoffset); - baseWallVerts[0].z = baseWallVerts[3].z = baseWallVerts[0].z+si; - baseWallVerts[1].z = baseWallVerts[2].z = baseWallVerts[1].z+si; - baseWallVerts[0].x = baseWallVerts[3].x = baseWallVerts[0].x+co; - baseWallVerts[1].x = baseWallVerts[2].x = baseWallVerts[1].x+co; - } - // Let dispoffset work first since this adjust each vertex HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); @@ -4249,18 +4238,8 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) HWR_DrawSpriteShadow(spr, gpatch, this_scale); } - // if it has a dispoffset, push it a little towards the camera - if (spr->dispoffset) - { - float co = -gr_viewcos*(0.05f*spr->dispoffset); - float si = -gr_viewsin*(0.05f*spr->dispoffset); - wallVerts[0].z = wallVerts[3].z = wallVerts[0].z+si; - wallVerts[1].z = wallVerts[2].z = wallVerts[1].z+si; - wallVerts[0].x = wallVerts[3].x = wallVerts[0].x+co; - wallVerts[1].x = wallVerts[2].x = wallVerts[1].x+co; - } - // Let dispoffset work first since this adjust each vertex + // ...nah HWR_RotateSpritePolyToAim(spr, wallVerts, false); // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index c4109837c..17485f1be 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -36,9 +36,6 @@ static struct { {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Sprite shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, - - // Sprite clipping hack shader (for pulling things out of the floor) {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Model shader @@ -431,7 +428,6 @@ customshaderxlat_t shaderxlat[] = {"Shadow", SHADER_SHADOW}, {"WallTexture", SHADER_WALL}, {"Sprite", SHADER_SPRITE}, - {"SpriteClipHack", SHADER_SPRITECLIPHACK}, {"Model", SHADER_MODEL}, {"WaterRipple", SHADER_WATER}, {"Fog", SHADER_FOG}, diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 6c225b1a8..45f3aed9e 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -39,7 +39,7 @@ "gl_FrontColor = gl_Color;\n" \ "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_Position.z -= 80.0 / gl_Position.z;\n" \ + "gl_Position.z -= 80 / gl_Position.z;\n" \ "}\0" // ================== diff --git a/src/r_things.c b/src/r_things.c index 0fa96a4ce..884da6302 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -299,7 +299,8 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, spritecachedinfo[numspritelumps].height = SHORT(patch.height)< Date: Mon, 3 Jun 2024 17:15:39 +0200 Subject: [PATCH 39/91] Revert "use shader to prevent sprite floor clipping" This reverts commit ee2ec01eb9796c41f435cbfa41a7046bff4039c9. --- src/hardware/hw_main.c | 25 +++++++++++++++++++++++++ src/hardware/hw_shaders.c | 2 +- src/hardware/hw_shaders.h | 11 ----------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index eed9f9232..007a05de1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3972,6 +3972,18 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) // Let dispoffset work first since this adjust each vertex HWR_RotateSpritePolyToAim(spr, baseWallVerts, false); + // push it toward the camera to mitigate floor-clipping sprites + { + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + for (i = 0; i < 4; i++) + { + baseWallVerts[i].x += (gr_viewx - baseWallVerts[i].x)*distfact; + baseWallVerts[i].z += (gr_viewy - baseWallVerts[i].z)*distfact; + baseWallVerts[i].y += (gr_viewz - baseWallVerts[i].y)*distfact; + } + } + realtop = top = baseWallVerts[3].y; realbot = bot = baseWallVerts[0].y; towtop = baseWallVerts[3].t; @@ -4242,6 +4254,19 @@ static void HWR_DrawSprite(gr_vissprite_t *spr) // ...nah HWR_RotateSpritePolyToAim(spr, wallVerts, false); + // push it toward the camera to mitigate floor-clipping sprites + { + float sprdist = sqrtf((spr->x1 - gr_viewx)*(spr->x1 - gr_viewx) + (spr->z1 - gr_viewy)*(spr->z1 - gr_viewy) + (spr->ty - gr_viewz)*(spr->ty - gr_viewz)); + float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + size_t i; + for (i = 0; i < 4; i++) + { + wallVerts[i].x += (gr_viewx - wallVerts[i].x)*distfact; + wallVerts[i].z += (gr_viewy - wallVerts[i].z)*distfact; + wallVerts[i].y += (gr_viewz - wallVerts[i].y)*distfact; + } + } + // This needs to be AFTER the shadows so that the regular sprites aren't drawn completely black. // sprite lighting by modulating the RGB components /// \todo coloured diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 17485f1be..658de5ef6 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -36,7 +36,7 @@ static struct { {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Sprite shader - {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, + {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, // Model shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 45f3aed9e..8f600fa79 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -31,17 +31,6 @@ "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ "}\0" -// Sprite clipping makes me want to McFucking Die - -#define GLSL_SPRITECLIP_HACK_VERTEX_SHADER \ - "void main(void) {\n" \ - "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_FrontColor = gl_Color;\n" \ - "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ - "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_Position.z -= 80 / gl_Position.z;\n" \ - "}\0" - // ================== // Fragment shaders // ================== From 716685d809e836a8aa920732a52703fae420c0ad Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 17:15:16 +0200 Subject: [PATCH 40/91] zzz... --- src/hardware/hw_shaders.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 658de5ef6..efebecc18 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -30,7 +30,7 @@ static struct { {GLSL_DEFAULT_VERTEX_SHADER, GLSL_FLOOR_FRAGMENT_SHADER}, // Shadow shader - {GLSL_SPRITECLIP_HACK_VERTEX_SHADER, GLSL_SHADOW_FRAGMENT_SHADER}, + {GLSL_DEFAULT_VERTEX_SHADER, GLSL_SHADOW_FRAGMENT_SHADER}, // Wall shader {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, From 9b3eaa6fe85a1c9e9264219124516e9e365f53bb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 4 Jun 2024 17:10:24 +0200 Subject: [PATCH 41/91] smol optimization to skin loading --- src/r_things.c | 92 +++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 884da6302..c37807c73 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -275,58 +275,50 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, for (l = startlump; l < endlump; l++) { - if (memcmp(lumpinfo[l].name,sprname,4)==0) + if (memcmp(lumpinfo[l].name,sprname,4)) + continue; + + frame = R_Char2Frame(lumpinfo[l].name[4]); + rotation = (UINT8)(lumpinfo[l].name[5] - '0'); + + if (frame >= 64 || !(R_ValidSpriteAngle(rotation))) // Give an actual NAME error -_-... { - frame = R_Char2Frame(lumpinfo[l].name[4]); - rotation = (UINT8)(lumpinfo[l].name[5] - '0'); - - if (frame >= 64 || !(R_ValidSpriteAngle(rotation))) // Give an actual NAME error -_-... - { - CONS_Alert(CONS_WARNING, M_GetText("Bad sprite name: %s\n"), W_CheckNameForNumPwad(wadnum,l)); - continue; - } - - // skip NULL sprites from very old dmadds pwads - if (W_LumpLengthPwad(wadnum,l)<=8) - continue; - - // store sprite info in lookup tables - //FIXME : numspritelumps do not duplicate sprite replacements - W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); - spritecachedinfo[numspritelumps].width = SHORT(patch.width)<0 && SHORT(patch.topoffset)= max_spritelumps) - { - max_spritelumps *= 2; - Z_Realloc(spritecachedinfo, max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); - } - - ++numadded; + CONS_Alert(CONS_WARNING, M_GetText("Bad sprite name: %s\n"), W_CheckNameForNumPwad(wadnum,l)); + continue; } + + // skip NULL sprites from very old dmadds pwads + if (W_LumpLengthPwad(wadnum,l)<=8) + continue; + + // store sprite info in lookup tables + //FIXME : numspritelumps do not duplicate sprite replacements + W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); + spritecachedinfo[numspritelumps].width = SHORT(patch.width)<= max_spritelumps) + { + max_spritelumps *= 2; + Z_Realloc(spritecachedinfo, max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); + } + + ++numadded; } // From 4246e429487eb58e3f81aa25bf8c001d3f5a077c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 5 Jun 2024 02:27:18 +0200 Subject: [PATCH 42/91] minor sprite opitmizations --- src/hardware/hw_main.c | 136 +++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 66 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 007a05de1..3ef71658d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3062,13 +3062,13 @@ void HWR_AddPolyObjectPlanes(void) for (i = 0; i < numpolys; i++) { - polyobjsector = po_ptrs[i]->lines[0]->backsector; // the in-level polyobject sector - if (!(po_ptrs[i]->flags & POF_RENDERPLANES)) // Only render planes when you should continue; if (po_ptrs[i]->translucency >= NUMTRANSMAPS) continue; + + polyobjsector = po_ptrs[i]->lines[0]->backsector; // the in-level polyobject sector if (polyobjsector->floorheight <= gr_frontsector->ceilingheight && polyobjsector->floorheight >= gr_frontsector->floorheight @@ -4739,35 +4739,39 @@ void HWR_DrawSprites(void) for (i = 0; i < gr_visspritecount; i++) { gr_vissprite_t *spr = gr_vsprorder[i]; - if (spr->precip) - HWR_DrawPrecipitationSprite(spr); - 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->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); + if (spr->precip) + { + HWR_DrawPrecipitationSprite(spr); + continue; + } + + 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 - HWR_DrawMD2(spr); + 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->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); + } + else { - if (!cv_grmdls.value || md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) - HWR_DrawSprite(spr); - else - HWR_DrawMD2(spr); - } + if (!cv_grmdls.value || md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) + HWR_DrawSprite(spr); + else + HWR_DrawMD2(spr); + } } } @@ -4806,7 +4810,46 @@ void HWR_AddSprites(sector_t *sec) // Handle all things in sector. // If a limit exists, handle things a tiny bit different. - if (limit_dist) + if (limit_dist == 0) + { + // Draw everything in sector, no checks + for (thing = sec->thinglist; thing; thing = thing->snext) + { + split_drawsprite = false; + + if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW) + continue; + + splitflags = thing->eflags & (MFE_DRAWONLYFORP1|MFE_DRAWONLYFORP2|MFE_DRAWONLYFORP3|MFE_DRAWONLYFORP4); + + if (splitscreen && splitflags) + { + if (thing->eflags & MFE_DRAWONLYFORP1) + if (viewssnum == 0) + split_drawsprite = true; + + if (thing->eflags & MFE_DRAWONLYFORP2) + if (viewssnum == 1) + split_drawsprite = true; + + if (thing->eflags & MFE_DRAWONLYFORP3 && splitscreen > 1) + if (viewssnum == 2) + split_drawsprite = true; + + if (thing->eflags & MFE_DRAWONLYFORP4 && splitscreen > 2) + if (viewssnum == 3) + split_drawsprite = true; + } + else + split_drawsprite = true; + + if (!split_drawsprite) + continue; + + HWR_ProjectSprite(thing); + } + } + else { for (thing = sec->thinglist; thing; thing = thing->snext) { @@ -4849,45 +4892,6 @@ void HWR_AddSprites(sector_t *sec) HWR_ProjectSprite(thing); } } - else - { - // Draw everything in sector, no checks - for (thing = sec->thinglist; thing; thing = thing->snext) - { - split_drawsprite = false; - - if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW) - continue; - - splitflags = thing->eflags & (MFE_DRAWONLYFORP1|MFE_DRAWONLYFORP2|MFE_DRAWONLYFORP3|MFE_DRAWONLYFORP4); - - if (splitscreen && splitflags) - { - if (thing->eflags & MFE_DRAWONLYFORP1) - if (viewssnum == 0) - split_drawsprite = true; - - if (thing->eflags & MFE_DRAWONLYFORP2) - if (viewssnum == 1) - split_drawsprite = true; - - if (thing->eflags & MFE_DRAWONLYFORP3 && splitscreen > 1) - if (viewssnum == 2) - split_drawsprite = true; - - if (thing->eflags & MFE_DRAWONLYFORP4 && splitscreen > 2) - if (viewssnum == 3) - split_drawsprite = true; - } - else - split_drawsprite = true; - - if (!split_drawsprite) - continue; - - HWR_ProjectSprite(thing); - } - } } // -------------------------------------------------------------------------- From 1503daf02bb1b4d3a64d119abacf4f59e2ecc0a4 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 5 Jun 2024 14:42:23 +0200 Subject: [PATCH 43/91] more minor loop stuff --- src/hardware/hw_bsp.c | 14 ++-- src/hardware/hw_cache.c | 30 +++++--- src/hardware/hw_main.c | 165 +++++++++++++++++++++------------------- src/r_bsp.c | 32 ++++---- src/r_data.c | 61 ++++++++------- src/r_main.c | 20 ++--- src/r_plane.c | 46 ++++++----- src/r_segs.c | 5 +- src/r_things.c | 1 + 9 files changed, 196 insertions(+), 178 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index ebf18ed14..91759c819 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -772,9 +772,11 @@ static INT32 SolveTProblem(void) for (l = 0; l < addsubsector; l++) { p = extrasubsectors[l].planepoly; - if (p) - for (i = 0; i < p->numpts; i++) - SearchSegInBSP((INT32)numnodes-1, &p->pts[i], p); + if (!p) + continue; + + for (i = 0; i < p->numpts; i++) + SearchSegInBSP((INT32)numnodes-1, &p->pts[i], p); } //CONS_Debug(DBG_RENDER, "numsplitpoly %d\n", numsplitpoly); return numsplitpoly; @@ -802,8 +804,10 @@ static void AdjustSegs(void) count = subsectors[i].numlines; lseg = &segs[subsectors[i].firstline]; p = extrasubsectors[i].planepoly; - //if (!p) - //continue; + + if (!p) + continue; + for (; count--; lseg++) { float distv1,distv2,tmp; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 2a5ec4ff5..98034970d 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -381,16 +381,17 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex, boolean noe realpatch); Z_Unlock(realpatch); } + //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( if (format2bpp(grtex->mipmap.format)==4) { for (i = 3; i < blocksize*4; i += 4) // blocksize*4 because blocksize doesn't include the bpp { - if (block[i] == 0) - { - grtex->mipmap.flags |= TF_TRANSPARENT; - break; - } + if (block[i] != 0) + continue; + + grtex->mipmap.flags |= TF_TRANSPARENT; + break; } } @@ -629,8 +630,12 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) #ifdef GLENCORE flat = grMipmap->data; for (steppy = 0; steppy < size; steppy++) - if (flat[steppy] != HWR_PATCHES_CHROMAKEY_COLORINDEX) - flat[steppy] = grMipmap->colormap[flat[steppy]]; + { + if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX) + continue; + + flat[steppy] = grMipmap->colormap[flat[steppy]]; + } #endif } @@ -743,11 +748,12 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap) for (grmip = gpatch->mipmap; grmip->nextcolormap; ) { grmip = grmip->nextcolormap; - if (grmip->colormap == colormap) - { - HWR_LoadMappedPatch(grmip, gpatch); - return; - } + + if (grmip->colormap != colormap) + continue; + + HWR_LoadMappedPatch(grmip, gpatch); + return; } // not found, create it! // If we are here, the sprite with the current colormap is not already in hardware memory diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3ef71658d..1cba83059 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -882,75 +882,75 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc for (i = 0; i < subsector->numlines; i++, line++) { - if (line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(viewx, viewy, line) == 0) + if (!(line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(viewx, viewy, line) == 0)) + continue; + + P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); + dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); + + if (line->pv1) { - P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); - dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); - - if (line->pv1) - { - x1 = ((polyvertex_t *)line->pv1)->x; - y1 = ((polyvertex_t *)line->pv1)->y; - } - else - { - x1 = FIXED_TO_FLOAT(line->v1->x); - y1 = FIXED_TO_FLOAT(line->v1->x); - } - if (line->pv2) - { - xd = ((polyvertex_t *)line->pv2)->x - x1; - yd = ((polyvertex_t *)line->pv2)->y - y1; - } - else - { - xd = FIXED_TO_FLOAT(line->v2->x) - x1; - yd = FIXED_TO_FLOAT(line->v2->y) - y1; - } + x1 = ((polyvertex_t *)line->pv1)->x; + y1 = ((polyvertex_t *)line->pv1)->y; + } + else + { + x1 = FIXED_TO_FLOAT(line->v1->x); + y1 = FIXED_TO_FLOAT(line->v1->x); + } + if (line->pv2) + { + xd = ((polyvertex_t *)line->pv2)->x - x1; + yd = ((polyvertex_t *)line->pv2)->y - y1; + } + else + { + xd = FIXED_TO_FLOAT(line->v2->x) - x1; + yd = FIXED_TO_FLOAT(line->v2->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; + // 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); + 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); + 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); + // 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); + 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; + // 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); + 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 - HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true); - } + // Draw + HWR_ProcessPolygon(&Surf, horizonpts, 6, PolyFlags, shader, true); } } } @@ -3230,11 +3230,11 @@ static void HWR_Subsector(size_t num) { sector_t *controlSec = §ors[rover->secnum]; - if (controlSec->moved == true) - { - anyMoved = true; - break; - } + if (controlSec->moved != true) + continue; + + anyMoved = true; + break; } } @@ -3635,8 +3635,11 @@ static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t hei delta1 = z - (*rover->bottomheight + ((*rover->topheight - *rover->bottomheight)/2)); delta2 = thingtop - (*rover->bottomheight + ((*rover->topheight - *rover->bottomheight)/2)); - if (*rover->topheight > floorz && abs(delta1) < abs(delta2)) - floorz = *rover->topheight; + + if (!(*rover->topheight > floorz && abs(delta1) < abs(delta2))) + continue; + + floorz = *rover->topheight; } } @@ -4041,13 +4044,13 @@ static void HWR_SplitSprite(gr_vissprite_t *spr) for (i = 1; i < sector->numlights; i++) { fixed_t h = P_GetLightZAt(§or->lightlist[i], spr->mobj->x, spr->mobj->y); - if (h <= temp) - { - if (!(spr->mobj->frame & FF_FULLBRIGHT)) - lightlevel = *list[i-1].lightlevel > 255 ? 255 : *list[i-1].lightlevel; - colormap = list[i-1].extra_colormap; - break; - } + if (!(h <= temp)) + continue; + + if (!(spr->mobj->frame & FF_FULLBRIGHT)) + lightlevel = *list[i-1].lightlevel > 255 ? 255 : *list[i-1].lightlevel; + colormap = list[i-1].extra_colormap; + break; } for (i = 0; i < sector->numlights; i++) @@ -5578,8 +5581,10 @@ void HWR_SetTransform(float fpov, player_t *player) for (i = 0; i <= splitscreen; i++) { - if (player == &players[displayplayers[i]]) - postprocessor = &postimgtype[i]; + if (player != &players[displayplayers[i]]) + continue; + + postprocessor = &postimgtype[i]; } atransform.flip = false; @@ -6146,11 +6151,11 @@ void HWR_DoPostProcessor(player_t *player) for (i = splitscreen; i > 0; i--) { - if (player == &players[displayplayers[i]]) - { - type = &postimgtype[i]; - break; - } + if (player != &players[displayplayers[i]]) + continue; + + type = &postimgtype[i]; + break; } // Armageddon Blast Flash! diff --git a/src/r_bsp.c b/src/r_bsp.c index 02f4d8c83..dc409feba 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -266,11 +266,11 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, for (i = 0; i <= splitscreen; i++) { - if (viewplayer == &players[displayplayers[i]] && camera[i].chase) - { - heightsec = R_PointInSubsector(camera[i].x, camera[i].y)->sector->heightsec; - break; - } + if (!(viewplayer == &players[displayplayers[i]] && camera[i].chase)) + continue; + + heightsec = R_PointInSubsector(camera[i].x, camera[i].y)->sector->heightsec; + break; } if (i > splitscreen && viewmobj) @@ -907,11 +907,11 @@ static void R_Subsector(size_t num) { sector_t *controlSec = §ors[rover->secnum]; - if (controlSec->moved == true) - { - anyMoved = true; - break; - } + if (controlSec->moved != true) + continue; + + anyMoved = true; + break; } } @@ -1185,13 +1185,13 @@ void R_Prep3DFloors(sector_t *sector) count = 1; for (rover = sector->ffloors; rover; rover = rover->next) { - if ((rover->flags & FF_EXISTS) && (!(rover->flags & FF_NOSHADE) - || (rover->flags & FF_CUTLEVEL) || (rover->flags & FF_CUTSPRITES))) - { + if (!((rover->flags & FF_EXISTS) && (!(rover->flags & FF_NOSHADE) + || (rover->flags & FF_CUTLEVEL) || (rover->flags & FF_CUTSPRITES)))) + continue; + + count++; + if (rover->flags & FF_DOUBLESHADOW) count++; - if (rover->flags & FF_DOUBLESHADOW) - count++; - } } if (count != sector->numlights) diff --git a/src/r_data.c b/src/r_data.c index 69b0ce1ac..ad8b420f3 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -429,22 +429,24 @@ void R_LoadTextures(void) } // Add all the textures between TX_START and TX_END - if (texstart != INT16_MAX && texend != INT16_MAX) + if (!(texstart != INT16_MAX && texend != INT16_MAX)) + continue; + + // PK3s have subfolders, so we can't just make a simple sum + if (W_FileHasFolders(wadfiles[w])) { - // PK3s have subfolders, so we can't just make a simple sum - if (W_FileHasFolders(wadfiles[w])) + for (j = texstart; j < texend; j++) { - for (j = texstart; j < texend; j++) - { - if (!W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it - numtextures++; - } - } - else - { - numtextures += (UINT32)(texend - texstart); + if (W_IsLumpFolder((UINT16)w, j)) // Check if lump is a folder; if not, then count it + continue; + + numtextures++; } } + else + { + numtextures += (UINT32)(texend - texstart); + } } // If no textures found by this point, bomb out @@ -1003,26 +1005,26 @@ lumpnum_t R_GetFlatNumForName(const char *name) { switch (wadfiles[i]->type) { - case RET_WAD: - if ((start = W_CheckNumForNamePwad("F_START", (UINT16)i, 0)) == INT16_MAX) - { - if ((start = W_CheckNumForNamePwad("FF_START", (UINT16)i, 0)) == INT16_MAX) + case RET_WAD: + if ((start = W_CheckNumForNamePwad("F_START", (UINT16)i, 0)) == INT16_MAX) + { + if ((start = W_CheckNumForNamePwad("FF_START", (UINT16)i, 0)) == INT16_MAX) + continue; + else if ((end = W_CheckNumForNamePwad("FF_END", (UINT16)i, start)) == INT16_MAX) + continue; + } + else + if ((end = W_CheckNumForNamePwad("F_END", (UINT16)i, start)) == INT16_MAX) + continue; + break; + case RET_PK3: + if ((start = W_CheckNumForFolderStartPK3("Flats/", i, 0)) == INT16_MAX) continue; - else if ((end = W_CheckNumForNamePwad("FF_END", (UINT16)i, start)) == INT16_MAX) + if ((end = W_CheckNumForFolderEndPK3("Flats/", i, start)) == INT16_MAX) continue; - } - else - if ((end = W_CheckNumForNamePwad("F_END", (UINT16)i, start)) == INT16_MAX) - continue; - break; - case RET_PK3: - if ((start = W_CheckNumForFolderStartPK3("Flats/", i, 0)) == INT16_MAX) + break; + default: continue; - if ((end = W_CheckNumForFolderEndPK3("Flats/", i, start)) == INT16_MAX) - continue; - break; - default: - continue; } // Now find lump with specified name in that range. @@ -1310,6 +1312,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) { if (foundcolormaps[i] != LUMPERROR) continue; + if (maskcolor == extra_colormaps[i].maskcolor && fadecolor == extra_colormaps[i].fadecolor && fabs(maskamt - extra_colormaps[i].maskamt) < DBL_EPSILON diff --git a/src/r_main.c b/src/r_main.c index a15258c48..f1ffeebce 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1687,11 +1687,11 @@ void R_RenderPlayerView(player_t *player) // load previous saved value of skyVisible for the player for (i = 0; i <= splitscreen; i++) { - if (player == &players[displayplayers[i]]) - { - skyVisible = skyVisiblePerPlayer[i]; - break; - } + if (player != &players[displayplayers[i]]) + continue; + + skyVisible = skyVisiblePerPlayer[i]; + break; } portalrender = 0; @@ -1814,11 +1814,11 @@ void R_RenderPlayerView(player_t *player) // this is so that P1 can't affect whether P2 can see a skybox or not, or vice versa for (i = 0; i <= splitscreen; i++) { - if (player == &players[displayplayers[i]]) - { - skyVisiblePerPlayer[i] = skyVisible; - break; - } + if (player != &players[displayplayers[i]]) + continue; + + skyVisiblePerPlayer[i] = skyVisible; + break; } } diff --git a/src/r_plane.c b/src/r_plane.c index 6bd6f212d..6299edd9e 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -674,25 +674,26 @@ static void R_DrawSkyPlane(visplane_t *pl) // Because of this hack, sky is not affected // by INVUL inverse mapping. dc_colormap = colormaps; + if (encoremap) dc_colormap += COLORMAP_REMAPOFFSET; + dc_texturemid = skytexturemid; - dc_texheight = textureheight[skytexture] - >>FRACBITS; + dc_texheight = textureheight[skytexture] >>FRACBITS; + for (x = pl->minx; x <= pl->maxx; x++) { dc_yl = pl->top[x]; dc_yh = pl->bottom[x]; - if (dc_yl <= dc_yh) - { - angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; - dc_iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); - dc_x = x; - dc_source = - R_GetColumn(texturetranslation[skytexture], - angle); - wallcolfunc(); - } + + if (!(dc_yl <= dc_yh)) + continue; + + angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; + dc_iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); + dc_x = x; + dc_source = R_GetColumn(texturetranslation[skytexture], angle); + wallcolfunc(); } } @@ -839,18 +840,15 @@ void R_DrawSinglePlane(visplane_t *pl) // Don't draw planes that shouldn't be drawn. for (rover = pl->ffloor->target->ffloors; rover; rover = rover->next) { - if ((pl->ffloor->flags & FF_CUTEXTRA) && (rover->flags & FF_EXTRA)) - { - if (pl->ffloor->flags & FF_EXTRA) - { - // The plane is from an extra 3D floor... Check the flags so - // there are no undesired cuts. - if (((pl->ffloor->flags & (FF_FOG|FF_SWIMMABLE)) == (rover->flags & (FF_FOG|FF_SWIMMABLE))) - && pl->height < *rover->topheight - && pl->height > *rover->bottomheight) - return; - } - } + if (!((pl->ffloor->flags & FF_CUTEXTRA) && (rover->flags & FF_EXTRA))) + continue; + + // The plane is from an extra 3D floor... Check the flags so + // there are no undesired cuts. + if (((pl->ffloor->flags & (FF_FOG|FF_SWIMMABLE)) == (rover->flags & (FF_FOG|FF_SWIMMABLE))) + && pl->height < *rover->topheight + && pl->height > *rover->bottomheight) + return; } if (pl->ffloor->flags & FF_TRANSLUCENT) diff --git a/src/r_segs.c b/src/r_segs.c index 4a231938b..b70e06ff6 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -496,7 +496,6 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) } } - dc_texheight = textureheight[texnum]>>FRACBITS; // draw the columns @@ -983,7 +982,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++) { - if (maskedtexturecol[dc_x] != INT16_MAX) + if (maskedtexturecol[dc_x] == INT16_MAX) + continue; + { if (ffloortextureslide) { // skew FOF walls if (oldx != -1) diff --git a/src/r_things.c b/src/r_things.c index c37807c73..87cbc33d6 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -447,6 +447,7 @@ void R_AddSpriteDefs(UINT16 wadnum) for (i = 0; i < numsprites; i++) { spritename = sprnames[i]; + if (spritename[4] && wadnum >= (UINT16)spritename[4]) continue; From 51392590372e0cef59ca7023296c1aedaafdf8b9 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:42:32 +0200 Subject: [PATCH 44/91] fix HAVE_CURL --- src/d_clisrv.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 471d329a4..69c87a157 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1333,9 +1333,13 @@ static inline void CL_DrawConnectionStatus(void) { strncpy(tempname, filename, sizeof(tempname)-1); } - +#ifdef HAVE_CURL V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-58-30, 0, va(M_GetText("%s downloading"), ((cl_mode == CL_DOWNLOADHTTPFILES) ? "\x82""HTTP" : "\x85""Direct"))); +#else + V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-58-30, 0, + va(M_GetText("%s downloading"),("\x85""Direct"))); +#endif V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-58-22, V_YELLOWMAP, va(M_GetText("\"%s\""), tempname)); V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, V_20TRANS|V_MONOSPACE, @@ -2170,7 +2174,9 @@ static void M_ConfirmConnect(event_t *ev) static void AbortConnection(void) { +#ifdef HAVE_CURL CURLAbortFile(); +#endif D_QuitNetGame(); CL_Reset(); D_StartTitle(); From cfe6e081689fd65267d10c7c708deaff587cdc68 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:47:06 +0200 Subject: [PATCH 45/91] fix masterserver ifdef --- src/mserv.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mserv.h b/src/mserv.h index 5a74771a4..76bd5fd28 100644 --- a/src/mserv.h +++ b/src/mserv.h @@ -90,9 +90,11 @@ char *GetMODVersion(int id); #endif char *GetMasterServerRules(void); +#endif void AddMServCommands(void); +#ifdef MASTERSERVER /* HTTP */ void HMS_set_api (char *api); int HMS_register (void); @@ -105,4 +107,4 @@ const char * HMS_fetch_rules (char *buffer, size_t size_of_buffer); #endif -#endif \ No newline at end of file +#endif From f8a8b8ac6e1f02e038e0b17f6f6334cca869fe10 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:53:40 +0200 Subject: [PATCH 46/91] disable upx on nix by default --- src/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Makefile b/src/Makefile index 20f33a471..98351a8a2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -106,6 +106,8 @@ ifeq ($(OS),Windows_NT) # all windows are Windows_NT... else # if you on the *nix + NOUPX=1 + system:=$(shell uname -s) ifeq ($(system),Linux) From 4abc2ab5bd32037f7889d055346ea2b28e50a744 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:57:04 +0200 Subject: [PATCH 47/91] fix redifinition warning --- src/sdl/IMG_xpm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sdl/IMG_xpm.c b/src/sdl/IMG_xpm.c index 458131620..7a68185fa 100644 --- a/src/sdl/IMG_xpm.c +++ b/src/sdl/IMG_xpm.c @@ -1198,6 +1198,8 @@ SDL_Surface *IMG_ReadXPMFromArray(const char **xpm) return load_xpm(xpm, NULL); } +#undef MAX + #else /* not LOAD_XPM */ /* See if an image is contained in a data source */ From bd7103d109b026df8b737bbea157283c987e8c54 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:03:58 +0200 Subject: [PATCH 48/91] add check earlier in p_killmobj --- src/p_inter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_inter.c b/src/p_inter.c index 14c712033..68d02cdd9 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1908,8 +1908,8 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) mobj_t *mo; int ms; - //if (inflictor && (inflictor->type == MT_SHELL || inflictor->type == MT_FIREBALL)) - // P_SetTarget(&target->tracer, inflictor); + if (!target || P_MobjWasRemoved(target)) + return; if (!useNightsSS && G_IsSpecialStage(gamemap) && target->player && sstimer > 6) sstimer = 6; // Just let P_Ticker take care of the rest. From 6ffb50530dff945c4b42b8bd1307186fb468e5f3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:13:17 +0200 Subject: [PATCH 49/91] add mobj check here --- src/p_user.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/p_user.c b/src/p_user.c index 4cf785529..8f2f1eaa7 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1195,6 +1195,9 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) { mobj_t *ghost; + if (!mobj || P_MobjWasRemoved(mobj)) + return; + ghost = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_GHOST); P_SetScale(ghost, mobj->scale); From 07d631e320e096b5190eb6e70fde329c346cc051 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:14:22 +0200 Subject: [PATCH 50/91] e --- src/p_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index 8f2f1eaa7..3bee5abcd 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1196,7 +1196,7 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) mobj_t *ghost; if (!mobj || P_MobjWasRemoved(mobj)) - return; + return NULL; ghost = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_GHOST); From d66e7e660d781b84e4281b4e697c9196e7b63fd4 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:49:33 +0200 Subject: [PATCH 51/91] reset those here ig need a better place tbh but those occasionally could get stuck for some reason so just reset them when the menu gets opened --- src/m_menu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index d7dc233b1..8693d6f29 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4160,6 +4160,11 @@ void M_StartControlPanel(void) menuactive = true; + DPADUPSCROLL = false; + DPADDOWNSCROLL = false; + DPADLEFTSCROLL = false; + DPADRIGHTSCROLL = false; + if (demo.playback) { currentMenu = &PlaybackMenuDef; From 3412bb5380a9ee4ae6ec21b80be156234c4c368d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 22:02:46 +0200 Subject: [PATCH 52/91] fix encore flipcam with ogl shearing --- 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 64bc0d949..12e70f945 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2960,7 +2960,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (shearing) { float dy = FIXED_TO_FLOAT(AIMINGTODY((stransform->viewaiming)) * 2)* ((float)vid.width / vid.height) / ((float)BASEVIDWIDTH / BASEVIDHEIGHT); //screen_width/BASEVIDWIDTH; - if (stransform->flip) + if (stransform->flip || stransform->mirrorflip) dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f); } From be7461ad5110bab6b65be7d361d1a1749c061eb7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 22:31:29 +0200 Subject: [PATCH 53/91] use sdl ogl render instead of software for software mode on nix oops --- src/sdl/i_video.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f90f5bb18..16f4c4336 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2023,12 +2023,11 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) else if (cv_vidwait.value) flags |= SDL_RENDERER_PRESENTVSYNC; - // 3 August 2022 - // Possibly a Windows 11 issue; the default - // "direct3d" driver (D3D9) causes Drmingw exchndl - // to not write RPT files. Every other driver - // seems fine. +#ifdef _WIN32 SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11"); +#else + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); +#endif renderer = SDL_CreateRenderer(window, -1, flags); if (renderer == NULL) From 967220178cfeb8118495c61355f9fb36337f0b67 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 22:32:54 +0200 Subject: [PATCH 54/91] remove windows timing crap again it actually made stuff a little wonky so revert that --- src/sdl/i_system.c | 47 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7a5f79f58..f1171342e 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3189,28 +3189,21 @@ ticcmd_t *I_BaseTiccmd4(void) return &emptycmd4; } +// +// I_GetTime +// returns time in 1/TICRATE second tics +// + static Uint64 timer_frequency; precise_t I_GetPreciseTime(void) { -#if defined(_WIN32) - LARGE_INTEGER counter; - QueryPerformanceCounter(&counter); - return counter.QuadPart; -#else return SDL_GetPerformanceCounter(); -#endif } UINT64 I_GetPrecisePrecision(void) { -#if defined(_WIN32) - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - return frequency.QuadPart; -#else return SDL_GetPerformanceFrequency(); -#endif } static UINT32 frame_rate; @@ -3237,24 +3230,14 @@ static void I_InitFrameTime(const UINT64 now, const UINT32 cap) } double I_GetFrameTime(void) -{ -#if defined(_WIN32) - LARGE_INTEGER now; - QueryPerformanceCounter(&now); - const UINT64 nowValue = now.QuadPart; -#else +{ const UINT64 now = SDL_GetPerformanceCounter(); -#endif const UINT32 cap = R_GetFramerateCap(); if (cap != frame_rate) { // Maybe do this in a OnChange function for cv_fpscap? -#if defined(_WIN32) - I_InitFrameTime(nowValue, cap); -#else I_InitFrameTime(now, cap); -#endif } if (frame_rate == 0) @@ -3264,17 +3247,10 @@ double I_GetFrameTime(void) } else { -#if defined(_WIN32) - elapsed_frames += (nowValue - frame_epoch) / frame_frequency; -#else elapsed_frames += (now - frame_epoch) / frame_frequency; -#endif } -#if defined(_WIN32) - frame_epoch = nowValue; // moving epoch -#else - frame_epoch = now; // moving epoch -#endif + + frame_epoch = now; // moving epoch return elapsed_frames; } @@ -3283,13 +3259,8 @@ double I_GetFrameTime(void) // void I_StartupTimer(void) { -#if defined(_WIN32) - LARGE_INTEGER frequency; - QueryPerformanceFrequency(&frequency); - timer_frequency = frequency.QuadPart; -#else timer_frequency = SDL_GetPerformanceFrequency(); -#endif + I_InitFrameTime(0, R_GetFramerateCap()); elapsed_frames = 0.0; } From 335b10a69444900cf7af653918a61d45888915e8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 22:33:36 +0200 Subject: [PATCH 55/91] forgor --- src/sdl/i_system.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index f1171342e..b20eeba7d 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -3306,12 +3306,7 @@ void I_SleepDuration(precise_t duration) // hard sleep function. if (sleepvalue > 0 && (dest - cur) > delaygranularity) { -#if defined(_WIN32) - DWORD sleepDuration = (DWORD)min((INT64)(dest - cur), sleepvalue); - SleepEx(sleepDuration, TRUE); -#else I_Sleep(sleepvalue); -#endif } // Otherwise, this is a spinloop. From 225ecce676b53c1aa346098bf574be1c05df5012 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 12:59:23 +0200 Subject: [PATCH 56/91] lower min audio buffersize to 256 --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index b140978a3..21d29b231 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -65,7 +65,7 @@ static void AmigaType_OnChange(void); consvar_t cv_samplerate = {"samplerate", "44100", 0, CV_Unsigned, NULL, 22050, NULL, NULL, 0, 0, NULL}; //Alam: For easy hacking? -static CV_PossibleValue_t audbuffersize_cons_t[] = {{512, "512"}, {1024, "1024"}, {2048, "2048"}, {4096, "4096"}, {0, NULL}}; +static CV_PossibleValue_t audbuffersize_cons_t[] = {{256, "256"}, {512, "512"}, {1024, "1024"}, {2048, "2048"}, {4096, "4096"}, {0, NULL}}; consvar_t cv_audbuffersize = {"buffersize", "2048", CV_SAVE, audbuffersize_cons_t, BufferSize_OnChange, 0, NULL, NULL, 0, 0, NULL}; // stereo reverse From 41eb2ee9692e26773e5f20f81943baf90babe4b9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 21:49:20 +0200 Subject: [PATCH 57/91] =?UTF-8?q?fix=20oopsie=20on=20titled=20software=20w?= =?UTF-8?q?=C3=B6ter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/r_draw8.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index f3ebf0ff9..6b5d177db 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -943,7 +943,7 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_szp->x*width) * planelightfloat; From 953862f13314ed1bf3c2590290aaefe3eca6fc93 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 11 Jun 2024 10:02:23 +0200 Subject: [PATCH 58/91] change this to int64 cause it fixes the intermission thing on high res idk why that fixes it tbh but it does --- 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 58cfdc4e0..5d292f36c 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -437,7 +437,7 @@ void Y_IntermissionDrawer(void) if (sorttic != -1 && intertic >= sorttic && !demo.playback) { - INT32 count = (intertic - sorttic); + INT64 count = (intertic - sorttic); if (count < 8) x -= ((((count<>FRACBITS) / (8 * vid.dupx); From 3a1a58bcfc7e26147d79454898a77987167887a0 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 11 Jun 2024 01:35:22 +0200 Subject: [PATCH 59/91] more interp fixes --- src/d_clisrv.c | 17 +++++++++++++++-- src/g_game.c | 1 + src/p_spec.c | 7 +------ src/p_telept.c | 20 ++++++++++++-------- src/p_tick.c | 7 ------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 69c87a157..0174dc484 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -48,6 +48,7 @@ #include "s_sound.h" // sfx_syfail #include "m_perfstats.h" #include "d_main.h" +#include "r_fps.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -6083,6 +6084,8 @@ boolean TryRunTics(tic_t realtics) if (ticking) { + boolean tickInterp = true; + // run the count * tics while (neededtic > gametic) { @@ -6093,10 +6096,20 @@ boolean TryRunTics(tic_t realtics) if (update_stats) PS_START_TIMING(ps_tictime); - G_Ticker((gametic % NEWTICRATERATIO) == 0); + boolean run = (gametic % NEWTICRATERATIO) == 0; + + if (run && tickInterp) + { + // Update old view state BEFORE ticking so resetting + // the old interpolation state from game logic works. + R_UpdateViewInterpolation(); + tickInterp = false; // do not update again in sped-up tics + } + + G_Ticker(run); ExtraDataTicker(); gametic++; - consistancy[gametic%TICQUEUE] = Consistancy(); + consistancy[gametic % TICQUEUE] = Consistancy(); if (update_stats) { diff --git a/src/g_game.c b/src/g_game.c index 8352d0b98..2ce7bd6d1 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2131,6 +2131,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); P_ResetCamera(&players[(*displayplayerp)], camerap); + R_ResetViewInterpolation(viewd); } } diff --git a/src/p_spec.c b/src/p_spec.c index 9fb1953ee..aace89a2a 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2371,11 +2371,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) y = sides[line->sidenum[0]].rowoffset; z = line->frontsector->ceilingheight; - P_UnsetThingPosition(mo); - mo->x += x; - mo->y += y; - mo->z += z; - P_SetThingPosition(mo); + P_SetOrigin(mo, mo->x + x, mo->y + y, mo->z + z); if (mo->player) { @@ -2394,7 +2390,6 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) camera[i].reset = true; camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); R_RelativeTeleportViewInterpolation(i, x, y, z, 0); - R_ResetViewInterpolation(i + 1); // reset view interp as well break; } } diff --git a/src/p_telept.c b/src/p_telept.c index 9229079c9..4e7747315 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -84,8 +84,10 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, { if (thing->player != &players[displayplayers[i]]) continue; + if (camera[i].chase) P_ResetCamera(thing->player, &camera[i]); + R_ResetViewInterpolation(i + 1); break; } @@ -157,14 +159,16 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player == &players[displayplayers[i]]) - { - localangle[i] = angle; - if (camera[i].chase) - P_ResetCamera(thing->player, &camera[i]); - R_ResetViewInterpolation(i + 1); - break; - } + if (thing->player != &players[displayplayers[i]]) + continue; + + localangle[i] = angle; + + if (camera[i].chase) + P_ResetCamera(thing->player, &camera[i]); + + R_ResetViewInterpolation(i + 1); + break; } // don't run in place after a teleport diff --git a/src/p_tick.c b/src/p_tick.c index 6416142ce..e9c550bc0 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -581,13 +581,6 @@ void P_Ticker(boolean run) if (playeringame[i]) ++players[i].jointime; - if (run) - { - // Update old view state BEFORE ticking so resetting - // the old interpolation state from game logic works. - R_UpdateViewInterpolation(); - } - if (objectplacing) { if (OP_FreezeObjectplace()) From efe7dd23b695c08e34bf8e8707ea28b8797e5b6b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 12 Jun 2024 22:36:03 +0200 Subject: [PATCH 60/91] revert this part idk if that was netsafe so --- src/p_spec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index aace89a2a..9fb1953ee 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2371,7 +2371,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) y = sides[line->sidenum[0]].rowoffset; z = line->frontsector->ceilingheight; - P_SetOrigin(mo, mo->x + x, mo->y + y, mo->z + z); + P_UnsetThingPosition(mo); + mo->x += x; + mo->y += y; + mo->z += z; + P_SetThingPosition(mo); if (mo->player) { @@ -2390,6 +2394,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) camera[i].reset = true; camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); R_RelativeTeleportViewInterpolation(i, x, y, z, 0); + R_ResetViewInterpolation(i + 1); // reset view interp as well break; } } From ea49d92932c90392c985f0f07c572a34d4b26f92 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Jun 2024 14:47:20 +0200 Subject: [PATCH 61/91] add missing HAVE_THREADS --- src/d_netfil.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 9c32a41f4..4eb8f2dc3 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1300,8 +1300,9 @@ void CURLPrepareFile(const char* url, int dfilenum) curl_starttime = time(NULL); curl_running = true; - +#ifdef HAVE_THREADS I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL); +#endif } } From 0068312ce395c70f1fb5f3034eebc2bf1f862ba6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Jun 2024 12:51:57 +0200 Subject: [PATCH 62/91] Revert "revert this part" This reverts commit efe7dd23b695c08e34bf8e8707ea28b8797e5b6b. --- src/p_spec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 9fb1953ee..aace89a2a 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2371,11 +2371,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) y = sides[line->sidenum[0]].rowoffset; z = line->frontsector->ceilingheight; - P_UnsetThingPosition(mo); - mo->x += x; - mo->y += y; - mo->z += z; - P_SetThingPosition(mo); + P_SetOrigin(mo, mo->x + x, mo->y + y, mo->z + z); if (mo->player) { @@ -2394,7 +2390,6 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) camera[i].reset = true; camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); R_RelativeTeleportViewInterpolation(i, x, y, z, 0); - R_ResetViewInterpolation(i + 1); // reset view interp as well break; } } From 2f55c10ce3d9e7201b6ec4694654a3b0abf2e459 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Jun 2024 12:52:00 +0200 Subject: [PATCH 63/91] Revert "more interp fixes" This reverts commit 3a1a58bcfc7e26147d79454898a77987167887a0. --- src/d_clisrv.c | 17 ++--------------- src/g_game.c | 1 - src/p_spec.c | 7 ++++++- src/p_telept.c | 20 ++++++++------------ src/p_tick.c | 7 +++++++ 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0174dc484..69c87a157 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -48,7 +48,6 @@ #include "s_sound.h" // sfx_syfail #include "m_perfstats.h" #include "d_main.h" -#include "r_fps.h" #ifdef CLIENT_LOADINGSCREEN // cl loading screen @@ -6084,8 +6083,6 @@ boolean TryRunTics(tic_t realtics) if (ticking) { - boolean tickInterp = true; - // run the count * tics while (neededtic > gametic) { @@ -6096,20 +6093,10 @@ boolean TryRunTics(tic_t realtics) if (update_stats) PS_START_TIMING(ps_tictime); - boolean run = (gametic % NEWTICRATERATIO) == 0; - - if (run && tickInterp) - { - // Update old view state BEFORE ticking so resetting - // the old interpolation state from game logic works. - R_UpdateViewInterpolation(); - tickInterp = false; // do not update again in sped-up tics - } - - G_Ticker(run); + G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); gametic++; - consistancy[gametic % TICQUEUE] = Consistancy(); + consistancy[gametic%TICQUEUE] = Consistancy(); if (update_stats) { diff --git a/src/g_game.c b/src/g_game.c index 2ce7bd6d1..8352d0b98 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2131,7 +2131,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); P_ResetCamera(&players[(*displayplayerp)], camerap); - R_ResetViewInterpolation(viewd); } } diff --git a/src/p_spec.c b/src/p_spec.c index aace89a2a..9fb1953ee 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2371,7 +2371,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) y = sides[line->sidenum[0]].rowoffset; z = line->frontsector->ceilingheight; - P_SetOrigin(mo, mo->x + x, mo->y + y, mo->z + z); + P_UnsetThingPosition(mo); + mo->x += x; + mo->y += y; + mo->z += z; + P_SetThingPosition(mo); if (mo->player) { @@ -2390,6 +2394,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) camera[i].reset = true; camera[i].subsector = R_PointInSubsector(camera[i].x, camera[i].y); R_RelativeTeleportViewInterpolation(i, x, y, z, 0); + R_ResetViewInterpolation(i + 1); // reset view interp as well break; } } diff --git a/src/p_telept.c b/src/p_telept.c index 4e7747315..9229079c9 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -84,10 +84,8 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, { if (thing->player != &players[displayplayers[i]]) continue; - if (camera[i].chase) P_ResetCamera(thing->player, &camera[i]); - R_ResetViewInterpolation(i + 1); break; } @@ -159,16 +157,14 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player != &players[displayplayers[i]]) - continue; - - localangle[i] = angle; - - if (camera[i].chase) - P_ResetCamera(thing->player, &camera[i]); - - R_ResetViewInterpolation(i + 1); - break; + if (thing->player == &players[displayplayers[i]]) + { + localangle[i] = angle; + if (camera[i].chase) + P_ResetCamera(thing->player, &camera[i]); + R_ResetViewInterpolation(i + 1); + break; + } } // don't run in place after a teleport diff --git a/src/p_tick.c b/src/p_tick.c index e9c550bc0..6416142ce 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -581,6 +581,13 @@ void P_Ticker(boolean run) if (playeringame[i]) ++players[i].jointime; + if (run) + { + // Update old view state BEFORE ticking so resetting + // the old interpolation state from game logic works. + R_UpdateViewInterpolation(); + } + if (objectplacing) { if (OP_FreezeObjectplace()) From c35887f5ee44bccbb68a3e41118107f727114b23 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Jun 2024 12:52:09 +0200 Subject: [PATCH 64/91] Revert "fix some interpolation issues" This reverts commit e19f6f6656409b6a487dbb6f761ff3bc90daea33. --- src/g_game.c | 2 -- src/p_telept.c | 6 +----- src/p_tick.c | 8 +------- src/p_user.c | 1 + src/r_fps.c | 13 ++----------- 5 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 8352d0b98..aaa6b6fbe 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2117,8 +2117,6 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) { camerap = &camera[viewnum-1]; P_ResetCamera(&players[(*displayplayerp)], camerap); - - R_ResetViewInterpolation(viewnum); } if (viewnum > splits) diff --git a/src/p_telept.c b/src/p_telept.c index 9229079c9..7c9da2269 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -82,12 +82,8 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player != &players[displayplayers[i]]) - continue; - if (camera[i].chase) + if (thing->player == &players[displayplayers[i]] && camera[i].chase) P_ResetCamera(thing->player, &camera[i]); - R_ResetViewInterpolation(i + 1); - break; } // don't run in place after a teleport diff --git a/src/p_tick.c b/src/p_tick.c index 6416142ce..183c42a4b 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -581,13 +581,6 @@ void P_Ticker(boolean run) if (playeringame[i]) ++players[i].jointime; - if (run) - { - // Update old view state BEFORE ticking so resetting - // the old interpolation state from game logic works. - R_UpdateViewInterpolation(); - } - if (objectplacing) { if (OP_FreezeObjectplace()) @@ -834,6 +827,7 @@ void P_Ticker(boolean run) if (run) { R_UpdateLevelInterpolators(); + R_UpdateViewInterpolation(); // Hack: ensure newview is assigned every tic. // Ensures view interpolation is T-1 to T in poor network conditions diff --git a/src/p_user.c b/src/p_user.c index 3bee5abcd..de3ac7367 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3962,6 +3962,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall { P_MoveChaseCamera(player, thiscam, false); R_ResetViewInterpolation(num + 1); + R_ResetViewInterpolation(num + 1); } return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming); diff --git a/src/r_fps.c b/src/r_fps.c index 52a89098f..48990876a 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -23,8 +23,6 @@ #include "r_state.h" #include "z_zone.h" #include "console.h" // con_startup_loadprogress -#include "i_time.h" - #ifdef HWRENDER #include "hardware/hw_main.h" // for cv_grshearing #endif @@ -82,7 +80,6 @@ static viewvars_t skyview_old[MAXSPLITSCREENPLAYERS]; static viewvars_t skyview_new[MAXSPLITSCREENPLAYERS]; static viewvars_t *oldview = &pview_old[0]; -static tic_t last_view_update; static int oldview_invalid[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; viewvars_t *newview = &pview_new[0]; @@ -203,27 +200,21 @@ void R_UpdateViewInterpolation(void) if (oldview_invalid[i]) oldview_invalid[i]--; } - - last_view_update = I_GetTime(); } void R_ResetViewInterpolation(UINT8 p) { - // Wait an extra tic if the interpolation state hasn't - // updated yet. - int t = last_view_update == I_GetTime() ? 1 : 2; - if (p == 0) { UINT8 i; for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - oldview_invalid[i] = t; + oldview_invalid[i]++; } } else { - oldview_invalid[p - 1] = t; + oldview_invalid[p - 1]++; } } From c13e780f2903a341014010e554ed36b38d16a009 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 20 Jun 2024 16:55:58 +0300 Subject: [PATCH 65/91] Try fix glib preallocating too much space for sound freeslots --- src/dehacked.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 8b181a563..8c3d75db3 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9130,12 +9130,15 @@ int LUA_EnumLib(lua_State *L) char *str = NULL; int size = 0; + // Sound enum tables preallocated for sfx_freeslot0 elements because using NUMSFX may be too + // much if number of skins increased a lot (because of skinsound freeslots) + /* SFX (SFX_) */ lua_pushcfunction(L, lua_glib_new_enum); - lua_createtable(L, 0, NUMSFX); + lua_createtable(L, 0, sfx_freeslot0); for (int i = 0; i < NUMSFX; i++) { - if (!S_sfx[i].name) continue; + if (!S_sfx[i].name || !S_sfx[i].priority) continue; if (lua_enumlib_sprintf_upper(&str, &size, "SFX_%s", S_sfx[i].name) == NULL) return luaL_error(L, "Ran out of memory."); @@ -9150,10 +9153,10 @@ int LUA_EnumLib(lua_State *L) /* SFX (DS) */ lua_pushcfunction(L, lua_glib_new_enum); - lua_createtable(L, 0, NUMSFX); + lua_createtable(L, 0, sfx_freeslot0); for (int i = 0; i < NUMSFX; i++) { - if (!S_sfx[i].name) continue; + if (!S_sfx[i].name || !S_sfx[i].priority) continue; if (lua_enumlib_sprintf_upper(&str, &size, "DS%s", S_sfx[i].name) == NULL) return luaL_error(L, "Ran out of memory."); @@ -9188,10 +9191,10 @@ int LUA_EnumLib(lua_State *L) { /* SFX (sfx_) */ lua_pushcfunction(L, lua_glib_new_enum); - lua_createtable(L, 0, NUMSFX); + lua_createtable(L, 0, sfx_freeslot0); for (int i = 0; i < NUMSFX; i++) { - if (!S_sfx[i].name) continue; + if (!S_sfx[i].name || !S_sfx[i].priority) continue; lua_pushfstring(L, "sfx_%s", S_sfx[i].name); lua_pushinteger(L, i); @@ -9422,4 +9425,4 @@ void LUA_SetActionByName(void *state, const char *actiontocompare) return; } } -} \ No newline at end of file +} From 112716dae58ee75794948f456241795308ef3c26 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 17 Jun 2024 17:11:20 +0200 Subject: [PATCH 66/91] Do not access memory on misaligned addresses https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2438 --- src/byteptr.h | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index 9756e7d95..0b3935e63 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -11,17 +11,12 @@ /// \brief Macros to read/write from/to a UINT8 *, /// used for packet creation and such -#if defined (__alpha__) || defined (__arm__) || defined (__mips__) || defined (__ia64__) || defined (__clang__) -#define DEALIGNED -#endif - #include "endian.h" #ifndef SRB2_BIG_ENDIAN // // Little-endian machines // -#ifdef DEALIGNED #define WRITEUINT8(p,b) do { UINT8 *p_tmp = (void *)p; const UINT8 tv = ( UINT8)(b); memcpy(p, &tv, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; } while (0) #define WRITESINT8(p,b) do { SINT8 *p_tmp = (void *)p; const SINT8 tv = ( UINT8)(b); memcpy(p, &tv, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; } while (0) #define WRITEINT16(p,b) do { INT16 *p_tmp = (void *)p; const INT16 tv = ( INT16)(b); memcpy(p, &tv, sizeof( INT16)); p_tmp++; p = (void *)p_tmp; } while (0) @@ -31,20 +26,8 @@ #define WRITECHAR(p,b) do { char *p_tmp = (void *)p; const char tv = ( char)(b); memcpy(p, &tv, sizeof( char)); p_tmp++; p = (void *)p_tmp; } while (0) #define WRITEFIXED(p,b) do { fixed_t *p_tmp = (void *)p; const fixed_t tv = (fixed_t)(b); memcpy(p, &tv, sizeof(fixed_t)); p_tmp++; p = (void *)p_tmp; } while (0) #define WRITEANGLE(p,b) do { angle_t *p_tmp = (void *)p; const angle_t tv = (angle_t)(b); memcpy(p, &tv, sizeof(angle_t)); p_tmp++; p = (void *)p_tmp; } while (0) -#else -#define WRITEUINT8(p,b) do { UINT8 *p_tmp = ( UINT8 *)p; *p_tmp = ( UINT8)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITESINT8(p,b) do { SINT8 *p_tmp = ( SINT8 *)p; *p_tmp = ( SINT8)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEINT16(p,b) do { INT16 *p_tmp = ( INT16 *)p; *p_tmp = ( INT16)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEUINT16(p,b) do { UINT16 *p_tmp = ( UINT16 *)p; *p_tmp = ( UINT16)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEINT32(p,b) do { INT32 *p_tmp = ( INT32 *)p; *p_tmp = ( INT32)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEUINT32(p,b) do { UINT32 *p_tmp = ( UINT32 *)p; *p_tmp = ( UINT32)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITECHAR(p,b) do { char *p_tmp = ( char *)p; *p_tmp = ( char)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEFIXED(p,b) do { fixed_t *p_tmp = (fixed_t *)p; *p_tmp = (fixed_t)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#define WRITEANGLE(p,b) do { angle_t *p_tmp = (angle_t *)p; *p_tmp = (angle_t)(b); p_tmp++; p = (void *)p_tmp; } while (0) -#endif #ifdef __GNUC__ -#ifdef DEALIGNED #define READUINT8(p) ({ UINT8 *p_tmp = (void *)p; UINT8 b; memcpy(&b, p, sizeof( UINT8)); p_tmp++; p = (void *)p_tmp; b; }) #define READSINT8(p) ({ SINT8 *p_tmp = (void *)p; SINT8 b; memcpy(&b, p, sizeof( SINT8)); p_tmp++; p = (void *)p_tmp; b; }) #define READINT16(p) ({ INT16 *p_tmp = (void *)p; INT16 b; memcpy(&b, p, sizeof( INT16)); p_tmp++; p = (void *)p_tmp; b; }) @@ -55,17 +38,6 @@ #define READFIXED(p) ({ fixed_t *p_tmp = (void *)p; fixed_t b; memcpy(&b, p, sizeof(fixed_t)); p_tmp++; p = (void *)p_tmp; b; }) #define READANGLE(p) ({ angle_t *p_tmp = (void *)p; angle_t b; memcpy(&b, p, sizeof(angle_t)); p_tmp++; p = (void *)p_tmp; b; }) #else -#define READUINT8(p) ({ UINT8 *p_tmp = ( UINT8 *)p; UINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READSINT8(p) ({ SINT8 *p_tmp = ( SINT8 *)p; SINT8 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READINT16(p) ({ INT16 *p_tmp = ( INT16 *)p; INT16 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READUINT16(p) ({ UINT16 *p_tmp = ( UINT16 *)p; UINT16 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READINT32(p) ({ INT32 *p_tmp = ( INT32 *)p; INT32 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READUINT32(p) ({ UINT32 *p_tmp = ( UINT32 *)p; UINT32 b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READCHAR(p) ({ char *p_tmp = ( char *)p; char b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READFIXED(p) ({ fixed_t *p_tmp = (fixed_t *)p; fixed_t b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#define READANGLE(p) ({ angle_t *p_tmp = (angle_t *)p; angle_t b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) -#endif -#else #define READUINT8(p) *(( UINT8 *)p)++ #define READSINT8(p) *(( SINT8 *)p)++ #define READINT16(p) *(( INT16 *)p)++ @@ -148,8 +120,6 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #define READANGLE(p) ({ angle_t *p_tmp = (angle_t *)p; angle_t b = readulong(p); p_tmp++; p = (void *)p_tmp; b; }) #endif //SRB2_BIG_ENDIAN -#undef DEALIGNED - #define WRITESTRINGN(p, s, n) ({ \ size_t tmp_i; \ \ From 2e7cd51ff8718751fe05081285305c391342a450 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 20 Jun 2024 02:42:49 +0200 Subject: [PATCH 67/91] limit localskins to 32 hope this doesent just die lol --- src/doomdef.h | 1 + src/hardware/hw_md2.c | 6 ++++-- src/hardware/hw_md2.h | 2 +- src/r_draw.c | 2 +- src/r_things.c | 14 ++++++++++---- src/r_things.h | 4 ++-- src/st_stuff.c | 12 ++++++------ src/st_stuff.h | 12 ++++++------ 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 2b5f93b19..c032ec77b 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -211,6 +211,7 @@ extern char logfilename[1024]; #define MAXPLAYERS 16 #define MAXSKINS 255 +#define MAXLOCALSKINS 32 #define PLAYERSMASK (MAXPLAYERS-1) #define MAXPLAYERNAME 21 diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5818f01b2..0b43095da 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -75,7 +75,7 @@ md2_t md2_models[NUMSPRITES]; md2_t md2_playermodels[MAXSKINS]; -md2_t md2_localplayermodels[MAXSKINS]; +md2_t md2_localplayermodels[MAXLOCALSKINS]; /* @@ -494,7 +494,9 @@ void HWR_InitMD2(void) md2_playermodels[s].skin = -1; md2_playermodels[s].notfound = true; md2_playermodels[s].error = false; - + } + for (s = 0; s < MAXLOCALSKINS; s++) + { md2_localplayermodels[s].scale = -1.0f; md2_localplayermodels[s].model = NULL; md2_localplayermodels[s].grpatch = NULL; diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index a6f06428e..7b58a6f97 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -37,7 +37,7 @@ typedef struct extern md2_t md2_models[NUMSPRITES]; extern md2_t md2_playermodels[MAXSKINS]; -extern md2_t md2_localplayermodels[MAXSKINS]; +extern md2_t md2_localplayermodels[MAXLOCALSKINS]; void HWR_InitMD2(void); void HWR_DrawMD2(gr_vissprite_t *spr); diff --git a/src/r_draw.c b/src/r_draw.c index c19febc8a..fa19a6ac2 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -143,7 +143,7 @@ UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask; #define NUM_PALETTE_ENTRIES 256 static UINT8** translationtablecache[TT_CACHE_SIZE] = {NULL}; -static UINT8** localtranslationtablecache[MAXSKINS] = {NULL}; +static UINT8** localtranslationtablecache[MAXLOCALSKINS] = {NULL}; // See also the enum skincolors_t diff --git a/src/r_things.c b/src/r_things.c index 87cbc33d6..2ed6e636b 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2936,14 +2936,14 @@ UINT8 skinstatscount[9][9] = { {0, 0, 0, 0, 0, 0, 0, 0, 0} }; UINT8 skinsorted[MAXSKINS]; -skin_t localskins[MAXSKINS]; -skin_t allskins[MAXSKINS*2]; +skin_t localskins[MAXLOCALSKINS]; +skin_t allskins[MAXSKINS+MAXLOCALSKINS]; // 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]; +CV_PossibleValue_t localskin_cons_t[MAXLOCALSKINS+1]; #endif static void Sk_SetDefaultValue(skin_t *skin, boolean local) @@ -3383,11 +3383,17 @@ void R_AddSkins(UINT16 wadnum, boolean local) // advance by default lastlump = lump + 1; - if (( (local) ? numlocalskins : numskins ) >= MAXSKINS) + if (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 } + if (numlocalskins >= MAXLOCALSKINS) + { + CONS_Alert(CONS_WARNING, M_GetText("Unable to add localskin, too many localskins are loaded (%d maximum)\n"), MAXLOCALSKINS); + continue; // so we know how many skins couldn't be added + } + buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); size = W_LumpLengthPwad(wadnum, lump); diff --git a/src/r_things.h b/src/r_things.h index 5b74eea02..3e2414da1 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -220,8 +220,8 @@ extern UINT8 skinstatscount[9][9]; extern UINT8 skinsorted[MAXSKINS]; void sortSkinGrid(void); -extern skin_t localskins[MAXSKINS]; -extern skin_t allskins[MAXSKINS*2]; +extern skin_t localskins[MAXLOCALSKINS]; +extern skin_t allskins[MAXSKINS+MAXLOCALSKINS]; 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 3e64e6626..b78f47519 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -56,17 +56,17 @@ 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 +patch_t *localfacerankprefix[MAXLOCALSKINS]; // ranking +patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted +patch_t *localfacemmapprefix[MAXLOCALSKINS]; // 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 +char *localfacerankprefix_name[MAXLOCALSKINS]; // ranking +char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted +char *localfacemmapprefix_name[MAXLOCALSKINS]; // minimap // ------------------------------------------ // status bar overlay diff --git a/src/st_stuff.h b/src/st_stuff.h index 46fcc4d67..0c3258d01 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -78,15 +78,15 @@ 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 *localfacerankprefix[MAXLOCALSKINS]; // ranking +extern patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted +extern patch_t *localfacemmapprefix[MAXLOCALSKINS]; // 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 char *localfacerankprefix_name[MAXLOCALSKINS]; // ranking +extern char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted +extern char *localfacemmapprefix_name[MAXLOCALSKINS]; // minimap extern patch_t *livesback; extern patch_t *ngradeletters[7]; From 1a96d968372f3bb3d4d99c16e6a6f394b2f74a5a Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 20 Jun 2024 03:00:48 +0200 Subject: [PATCH 68/91] forgor this --- src/r_things.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r_things.c b/src/r_things.c index 2ed6e636b..5ca80d2aa 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2995,6 +2995,9 @@ void R_InitSkins(void) { skin_cons_t[i].value = 0; skin_cons_t[i].strvalue = NULL; + } + for (i = 0; i <= MAXLOCALSKINS; i++) + { localskin_cons_t[i].value = 0; localskin_cons_t[i].strvalue = NULL; } From ca58c1dee2ad8e79d70660dd2ab13c4a700a4bfd Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 20 Jun 2024 16:22:13 +0200 Subject: [PATCH 69/91] these appear to be unused so comment them out dont need 6 arrays being allocated with MAXSKINS for nothing lul --- src/st_stuff.c | 22 +++++++++++----------- src/st_stuff.h | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index b78f47519..765f235d2 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -56,17 +56,17 @@ patch_t *facerankprefix[MAXSKINS]; // ranking patch_t *facewantprefix[MAXSKINS]; // wanted patch_t *facemmapprefix[MAXSKINS]; // minimap -patch_t *localfacerankprefix[MAXLOCALSKINS]; // ranking -patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted -patch_t *localfacemmapprefix[MAXLOCALSKINS]; // minimap +patch_t *localfacerankprefix[MAXSKINS]; // ranking +patch_t *localfacewantprefix[MAXSKINS]; // wanted +patch_t *localfacemmapprefix[MAXSKINS]; // minimap -char *facerankprefix_name[MAXSKINS]; // ranking +/*char *facerankprefix_name[MAXSKINS]; // ranking char *facewantprefix_name[MAXSKINS]; // wanted char *facemmapprefix_name[MAXSKINS]; // minimap -char *localfacerankprefix_name[MAXLOCALSKINS]; // ranking -char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted -char *localfacemmapprefix_name[MAXLOCALSKINS]; // minimap +char *localfacerankprefix_name[MAXSKINS]; // ranking +char *localfacewantprefix_name[MAXSKINS]; // wanted +char *localfacemmapprefix_name[MAXSKINS]; // minimap*/ // ------------------------------------------ // status bar overlay @@ -395,9 +395,9 @@ void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skin facewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); facemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); - facerankprefix_name[skinnum] = rankstr; + /*facerankprefix_name[skinnum] = rankstr; facewantprefix_name[skinnum] = wantstr; - facemmapprefix_name[skinnum] = mmapstr; + facemmapprefix_name[skinnum] = mmapstr;*/ } void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skinnum) @@ -406,9 +406,9 @@ void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); - localfacerankprefix_name[skinnum] = rankstr; + /*localfacerankprefix_name[skinnum] = rankstr; localfacewantprefix_name[skinnum] = wantstr; - localfacemmapprefix_name[skinnum] = mmapstr; + localfacemmapprefix_name[skinnum] = mmapstr;*/ //CONS_Printf("Added rank prefix %s\n", rankstr); //CONS_Printf("Added want prefix %s\n", wantstr); diff --git a/src/st_stuff.h b/src/st_stuff.h index 0c3258d01..6809f90fc 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -78,15 +78,15 @@ 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[MAXLOCALSKINS]; // ranking -extern patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted -extern patch_t *localfacemmapprefix[MAXLOCALSKINS]; // minimap -extern char *facerankprefix_name[MAXSKINS]; // ranking +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[MAXLOCALSKINS]; // ranking -extern char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted -extern char *localfacemmapprefix_name[MAXLOCALSKINS]; // 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]; From 3d5e03315891ce020b2966f16df2d94e34b40eb3 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 20 Jun 2024 21:13:50 +0200 Subject: [PATCH 70/91] oops --- src/st_stuff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 765f235d2..681f2d920 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -56,17 +56,17 @@ 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 +patch_t *localfacerankprefix[MAXLOCALSKINS]; // ranking +patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted +patch_t *localfacemmapprefix[MAXLOCALSKINS]; // 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*/ +char *localfacerankprefix_name[MAXLOCALSKINS]; // ranking +char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted +char *localfacemmapprefix_name[MAXLOCALSKINS]; // minimap*/ // ------------------------------------------ // status bar overlay From 74ce725e3de5c2d8f69857a13a14f592fcaa9adf Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 20 Jun 2024 21:16:04 +0200 Subject: [PATCH 71/91] oops 2 --- src/st_stuff.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/st_stuff.h b/src/st_stuff.h index 6809f90fc..250db1e7f 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -78,15 +78,15 @@ 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 *localfacerankprefix[MAXLOCALSKINS]; // ranking +extern patch_t *localfacewantprefix[MAXLOCALSKINS]; // wanted +extern patch_t *localfacemmapprefix[MAXLOCALSKINS]; // 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 char *localfacerankprefix_name[MAXLOCALSKINS]; // ranking +extern char *localfacewantprefix_name[MAXLOCALSKINS]; // wanted +extern char *localfacemmapprefix_name[MAXLOCALSKINS]; // minimap*/ extern patch_t *livesback; extern patch_t *ngradeletters[7]; From b19935416730e2d9462a841f67b70a7ea0ca2691 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 22 Jun 2024 03:43:11 +0200 Subject: [PATCH 72/91] this should be called on mapload --- src/p_setup.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index c99326116..4d6988e65 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3034,7 +3034,12 @@ boolean P_SetupLevel(boolean skipprecip) #ifdef HWRENDER // not win32 only 19990829 by Kin if (rendermode == render_opengl) + { + HWR_FreeExtraSubsectors(); + + // stuff like HWR_CreatePlanePolygons is called there HWR_LoadLevel(); + } #endif // oh god I hope this helps From 9c5a0ed7ee455a28a067c83a6b730ac1a2b8af80 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 22 Jun 2024 07:14:33 +0200 Subject: [PATCH 73/91] move HWR_LoadLevel to hw_main --- src/hardware/hw_main.c | 19 +++++++++++++++++++ src/p_setup.c | 11 ----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 1cba83059..5369c51a3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5960,6 +5960,25 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) HWR_RenderFrame(viewnumber, player, false); } +void HWR_LoadLevel(void) +{ + // Lactozilla (December 8, 2019) + // Level setup used to free EVERY mipmap from memory. + // Even mipmaps that aren't related to level textures. + // Presumably, the hardware render code used to store textures as level data. + // Meaning, they had memory allocated and marked with the PU_LEVEL tag. + // Level textures are only reloaded after R_LoadTextures, which is + // when the texture list is loaded. + + // Sal: Unfortunately, NOT freeing them causes the dreaded Color Bug. + HWR_FreeMipmapCache(); + + HWR_CreatePlanePolygons((INT32)numnodes - 1); + + if (HWR_ShouldUsePaletteRendering()) + HWR_SetMapPalette(); +} + // enable or disable palette rendering state depending on settings and availability // called when relevant settings change // shader recompilation is done in the cvar callback diff --git a/src/p_setup.c b/src/p_setup.c index 4d6988e65..fbfde84a0 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3308,17 +3308,6 @@ boolean P_SetupLevel(boolean skipprecip) return true; } -#ifdef HWRENDER -void HWR_LoadLevel(void) -{ - HWR_FreeMipmapCache(); - HWR_CreatePlanePolygons((INT32)numnodes - 1); - - if (HWR_ShouldUsePaletteRendering()) - HWR_SetMapPalette(); -} -#endif - // // P_RunSOC // From 06248e5388226fd511023d23d73eb0cc27265b7b Mon Sep 17 00:00:00 2001 From: NepDisk <16447892+NepDisk@users.noreply.github.com> Date: Sat, 22 Jun 2024 19:16:01 -0400 Subject: [PATCH 74/91] Linux customshader compilation fix https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2418/ --- src/hardware/hw_shaders.c | 101 +++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index efebecc18..6757d6fe4 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -446,6 +446,101 @@ void HWR_LoadAllCustomShaders(void) HWR_LoadCustomShadersFromFile(i, W_FileHasFolders(wadfiles[i])); } +static const char version_directives[][14] = { + "#version 330\n", + "#version 150\n", + "#version 140\n", + "#version 130\n", + "#version 120\n", + "#version 110\n", +}; + +static boolean HWR_VersionDirectiveExists(const char* source) +{ + return strncmp(source, "#version", 8) == 0; +} + +static char* HWR_PrependVersionDirective(const char* source, UINT32 version_index) +{ + const UINT32 version_len = sizeof(version_directives[version_index]) - 1; + const UINT32 source_len = strlen(source); + + char* result = Z_Malloc(source_len + version_len + 1, PU_STATIC, NULL); + strcpy(result, version_directives[version_index]); + strcpy(result + version_len, source); + + return result; +} + +static void HWR_ReplaceVersionInplace(char* shader, UINT32 version_index) +{ + shader[9] = version_directives[version_index][9]; + shader[10] = version_directives[version_index][10]; + shader[11] = version_directives[version_index][11]; +} + +static boolean HWR_CheckVersionDirectives(const char* vert, const char* frag) +{ + return HWR_VersionDirectiveExists(vert) && HWR_VersionDirectiveExists(frag); +} + +static void HWR_TryToCompileShaderWithImplicitVersion(INT32 shader_index, INT32 shaderxlat_id) +{ + char* vert_shader = gl_shaders[shader_index].vertex; + char* frag_shader = gl_shaders[shader_index].fragment; + + boolean vert_shader_version_exists = HWR_VersionDirectiveExists(vert_shader); + boolean frag_shader_version_exists = HWR_VersionDirectiveExists(frag_shader); + + if(!vert_shader_version_exists) { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: vertex shader '%s' is missing a #version directive\n", HWR_GetShaderName(shaderxlat_id)); + } + + if(!frag_shader_version_exists) { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: fragment shader '%s' is missing a #version directive\n", HWR_GetShaderName(shaderxlat_id)); + } + + // try to compile as is + HWR_CompileShader(shader_index); + if (gl_shaders[shader_index].compiled) + return; + + // try each version directive + for(UINT32 i = 0; i < sizeof(version_directives) / sizeof(version_directives[0]); ++i) { + CONS_Alert(CONS_NOTICE, "HWR_TryToCompileShaderWithImplicitVersion: Trying %s\n", version_directives[i]); + + if(!vert_shader_version_exists) { + // first time reallocation would have to be made + + if(i == 0) { + void* old = (void*)gl_shaders[shader_index].vertex; + vert_shader = gl_shaders[shader_index].vertex = HWR_PrependVersionDirective(vert_shader, i); + Z_Free(old); + } else { + HWR_ReplaceVersionInplace(vert_shader, i); + } + } + + if(!frag_shader_version_exists) { + if(i == 0) { + void* old = (void*)gl_shaders[shader_index].fragment; + frag_shader = gl_shaders[shader_index].fragment = HWR_PrependVersionDirective(frag_shader, i); + Z_Free(old); + } else { + HWR_ReplaceVersionInplace(frag_shader, i); + } + } + + HWR_CompileShader(shader_index); + if (gl_shaders[shader_index].compiled) { + CONS_Alert(CONS_NOTICE, "HWR_TryToCompileShaderWithImplicitVersion: Compiled with %s\n", + version_directives[i]); + CONS_Alert(CONS_WARNING, "Implicit GLSL version is used. Correct behavior is not guaranteed\n"); + return; + } + } +} + void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) { UINT16 lump; @@ -608,7 +703,11 @@ skip_field: gl_shaders[shader_index].fragment = Z_StrDup(gl_shadersources[i].fragment); if (!gl_shaders[shader_index].vertex) gl_shaders[shader_index].vertex = Z_StrDup(gl_shadersources[i].vertex); - HWR_CompileShader(shader_index); + if(!HWR_CheckVersionDirectives(gl_shaders[shader_index].vertex, gl_shaders[shader_index].fragment)) { + HWR_TryToCompileShaderWithImplicitVersion(shader_index, i); + } else { + HWR_CompileShader(shader_index); + } if (!gl_shaders[shader_index].compiled) CONS_Alert(CONS_ERROR, "HWR_LoadCustomShadersFromFile: A compilation error occured for the %s shader in file %s. See the console messages above for more information.\n", shaderxlat[i].type, wadfiles[wadnum]->filename); } From 0bd5ca5e3fb8a1e7a79aeb42f696a28f374ddab0 Mon Sep 17 00:00:00 2001 From: NepDisk <16447892+NepDisk@users.noreply.github.com> Date: Sat, 22 Jun 2024 19:21:21 -0400 Subject: [PATCH 75/91] Allow Users to Connect to Servers While In-Game https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2401/ --- src/d_clisrv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 69c87a157..5d5c2d28d 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -23,6 +23,7 @@ #include "d_netfil.h" // fileneedednum #include "d_main.h" #include "g_game.h" +#include "m_menu.h" // M_ClearMenus #include "hu_stuff.h" #include "keys.h" #include "g_input.h" // JOY1 @@ -3046,8 +3047,17 @@ static void Command_connect(void) if (Playing() || demo.title) { - CONS_Printf(M_GetText("You cannot connect while in a game. End this game first.\n")); - return; + M_ClearMenus(true); + if (demo.title) + G_CheckDemoStatus(); + + if (netgame) + { + D_QuitNetGame(); + CL_Reset(); + } + + D_StartTitle(); } // modified game check: no longer handled From d449a1b7141e8f71530c368d615cad0bc4117f38 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 25 Jun 2024 13:39:33 +0200 Subject: [PATCH 76/91] remove this again --- src/p_user.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index de3ac7367..bd13b9852 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1195,9 +1195,6 @@ mobj_t *P_SpawnGhostMobj(mobj_t *mobj) { mobj_t *ghost; - if (!mobj || P_MobjWasRemoved(mobj)) - return NULL; - ghost = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_GHOST); P_SetScale(ghost, mobj->scale); From ec2fd5b38f3a574d3c4d0a4039e03fa19a2848bc Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 30 Jun 2024 06:45:48 +0200 Subject: [PATCH 77/91] prevent crash in hw bsp --- src/hardware/hw_bsp.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 91759c819..a5f76df06 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -667,9 +667,15 @@ static boolean PointInSeg(polyvertex_t *a,polyvertex_t *v1,polyvertex_t *v2) // v1 = origine ax= v2->x-v1->x; ay= v2->y-v1->y; - norm = (float)hypot(ax, ay); - ax /= norm; - ay /= norm; + norm = hypotf(ax, ay); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" + if (norm != 0) // yes, this can be exactly 0 +#pragma GCC diagnostic pop + { + ax /= norm; + ay /= norm; + } bx = a->x-v1->x; by = a->y-v1->y; //d = a.b From 008a9b9b3f11b5fc8a6d32649627c468e8a89bf4 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 30 Jun 2024 06:46:12 +0200 Subject: [PATCH 78/91] optimize ogl polyobjs slightly --- src/hardware/hw_main.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5369c51a3..c12261aac 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2854,9 +2854,6 @@ static boolean HWR_CheckBBox(const fixed_t *bspcoord) void HWR_AddPolyObjectSegs(void) { size_t i, j; - seg_t gr_fakeline; - polyvertex_t pv1; - polyvertex_t pv2; // Sort through all the polyobjects for (i = 0; i < numpolys; ++i) @@ -2864,19 +2861,7 @@ void HWR_AddPolyObjectSegs(void) // Render the polyobject's lines for (j = 0; j < po_ptrs[i]->segCount; ++j) { - // Copy the info of a polyobject's seg, then convert it to OpenGL floating point - M_Memcpy(&gr_fakeline, po_ptrs[i]->segs[j], sizeof(seg_t)); - - // Now convert the line to float and add it to be rendered - pv1.x = FIXED_TO_FLOAT(gr_fakeline.v1->x); - pv1.y = FIXED_TO_FLOAT(gr_fakeline.v1->y); - pv2.x = FIXED_TO_FLOAT(gr_fakeline.v2->x); - pv2.y = FIXED_TO_FLOAT(gr_fakeline.v2->y); - - gr_fakeline.pv1 = &pv1; - gr_fakeline.pv2 = &pv2; - - HWR_AddLine(&gr_fakeline); + HWR_AddLine(po_ptrs[i]->segs[j]); } } } From 266f5149b52e4de48be7043028516469a25a1c26 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Jul 2024 12:58:40 +0200 Subject: [PATCH 79/91] smoller opitmizations --- src/hardware/hw_main.c | 81 ++++++++++++++++++++++-------------------- src/r_things.c | 37 +++++++++---------- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c12261aac..55a9ad485 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2107,20 +2107,20 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom INT32 texnum; line_t * newline = NULL; // Multi-Property FOF - if (!cv_grfofcut.value) - { - ///TODO add slope support (fixing cutoffs, proper wall clipping) - maybe just disable highcut/lowcut if either sector or FOF has a slope - /// to allow fun plane intersecting in OGL? But then people would abuse that and make software look bad. :C - highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; - lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; - } - else + if (cv_grfofcut.value) { lowcut = max(worldbottom, worldlow); highcut = min(worldtop, worldhigh); lowcutslope = max(worldbottomslope, worldlowslope); highcutslope = min(worldtopslope, worldhighslope); } + else + { + ///TODO add slope support (fixing cutoffs, proper wall clipping) - maybe just disable highcut/lowcut if either sector or FOF has a slope + /// to allow fun plane intersecting in OGL? But then people would abuse that and make software look bad. :C + highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; + lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; + } if (gr_backsector->ffloors) { @@ -2129,12 +2129,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || (rover->flags & FF_INVERTSIDES)) continue; - if (!cv_grfofcut.value) - { - if (*rover->topheight < lowcut || *rover->bottomheight > highcut) - continue; - } - else + if (cv_grfofcut.value) { SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) @@ -2142,6 +2137,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; } + else + { + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + } texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -2157,14 +2157,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = P_GetFFloorBottomZAt(rover, v1x, v1y); lS = P_GetFFloorBottomZAt(rover, v2x, v2y); - if (!cv_grfofcut.value) - { - if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) - h = hS = highcut; - if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) - l = lS = lowcut; - } - else + if (cv_grfofcut.value) { // Adjust the heights so the FOF does not overlap with top and bottom textures. if (h >= highcut && hS >= highcutslope) @@ -2178,6 +2171,13 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom lS = lowcutslope; } } + else + { + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; + } //Hurdler: HW code starts here //FIXME: check if peging is correct @@ -2258,7 +2258,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom lightnum = rover->master->frontsector->lightlevel; colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - }else{ + } + else + { lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); colormap = rover->master->frontsector->extra_colormap; } @@ -2300,12 +2302,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_ALLSIDES)) continue; - if (!cv_grfofcut.value) - { - if (*rover->topheight < lowcut || *rover->bottomheight > highcut) - continue; - } - else + if (cv_grfofcut.value) { SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) @@ -2313,7 +2310,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; } - + else + { + if (*rover->topheight < lowcut || *rover->bottomheight > highcut) + continue; + } texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -2329,14 +2330,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = P_GetFFloorBottomZAt(rover, v1x, v1y); lS = P_GetFFloorBottomZAt(rover, v2x, v2y); - if (!cv_grfofcut.value) - { - if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) - h = hS = highcut; - if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) - l = lS = lowcut; - } - else + if (cv_grfofcut.value) { // Adjust the heights so the FOF does not overlap with top and bottom textures. if (h >= highcut && hS >= highcutslope) @@ -2350,6 +2344,13 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom lS = lowcutslope; } } + else + { + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; + } //Hurdler: HW code starts here //FIXME: check if peging is correct @@ -2397,7 +2398,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom lightnum = rover->master->frontsector->lightlevel; colormap = rover->master->frontsector->extra_colormap; lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - }else{ + } + else + { lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); colormap = rover->master->frontsector->extra_colormap; } diff --git a/src/r_things.c b/src/r_things.c index 5ca80d2aa..372ddb964 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -628,7 +628,7 @@ void R_DrawMaskedColumn(column_t *column) if (dc_yh >= vid.height) dc_yh = vid.height - 1; - if (dc_yl <= dc_yh && dc_yl < vid.height && dc_yh > 0) + if (dc_yl <= dc_yh && dc_yh > 0) { dc_source = (UINT8 *)column + 3; dc_texturemid = basetexturemid - (topdelta<length : for flipped column function pointers and multi-patch on 2sided wall = texture->height + +static void R_DrawFlippedMaskedColumn(column_t *column) { INT32 topscreen; INT32 bottomscreen; @@ -662,11 +664,10 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) if (topdelta <= prevdelta) topdelta += prevdelta; prevdelta = topdelta; - topdelta = texheight-column->length-topdelta; + topdelta = lengthcol-column->length-topdelta; topscreen = sprtopscreen + spryscale*topdelta; bottomscreen = sprbotscreen == INT32_MAX ? topscreen + spryscale*column->length : sprbotscreen + spryscale*column->length; - dc_yl = (topscreen+FRACUNIT-1)>>FRACBITS; dc_yh = (bottomscreen-1)>>FRACBITS; @@ -687,7 +688,7 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) if (dc_yh >= vid.height) dc_yh = vid.height - 1; - if (dc_yl <= dc_yh && dc_yl < vid.height && dc_yh > 0) + if (dc_yl <= dc_yh && dc_yh > 0) { dc_source = ZZ_Alloc(column->length); for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) @@ -712,7 +713,9 @@ static void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight) static void R_DrawVisSprite(vissprite_t *vis) { column_t *column; + void (*localcolfunc)(column_t *); INT32 texturecolumn; + INT32 pwidth; fixed_t frac; patch_t *patch = vis->patch; fixed_t this_scale = vis->thingscale; @@ -856,11 +859,15 @@ static void R_DrawVisSprite(vissprite_t *vis) vis->x2 -= temp; } + localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; + lengthcol = patch->height; + // Split drawing loops for paper and non-paper to reduce conditional checks per sprite if (vis->scalestep) { fixed_t horzscale = FixedMul(vis->spritexscale, this_scale); fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); + pwidth = SHORT(patch->width); // Papersprite drawing loop for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, spryscale += scalestep) @@ -868,37 +875,31 @@ static void R_DrawVisSprite(vissprite_t *vis) angle_t angle = ((vis->centerangle + xtoviewangle[dc_x]) >> ANGLETOFINESHIFT) & 0xFFF; texturecolumn = (vis->paperoffset - FixedMul(FINETANGENT(angle), vis->paperdistance)) / horzscale; - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) + if (texturecolumn < 0 || texturecolumn >= pwidth) continue; if (vis->xiscale < 0) // Flipped sprite - texturecolumn = SHORT(patch->width) - 1 - texturecolumn; + texturecolumn = pwidth - 1 - texturecolumn; sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale)); dc_iscale = (0xffffffffu / (unsigned)spryscale); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); - if (vis->vflip) - R_DrawFlippedMaskedColumn(column, patch->height); - else - R_DrawMaskedColumn(column); + localcolfunc (column); } } else { + pwidth = SHORT(patch->width); + // Non-paper drawing loop for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { -#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) - texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); -#undef CLAMP + texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); - if (vis->vflip) - R_DrawFlippedMaskedColumn(column, patch->height); - else - R_DrawMaskedColumn(column); + localcolfunc (column); } } From 09746257694a211188a49803392a042aaa1003ec Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 30 Jun 2024 10:04:22 +0200 Subject: [PATCH 80/91] no need for this --- src/hardware/hw_main.c | 101 +++++++++++------------------------------ 1 file changed, 26 insertions(+), 75 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 55a9ad485..edeb4ad1e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -54,6 +54,8 @@ #define SOFTLIGHT(llevel) HWR_ShouldUsePaletteRendering() ? ((llevel) >> LIGHTSEGSHIFT) << LIGHTSEGSHIFT : (llevel) +#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) + // ========================================================================== // the hardware driver object // ========================================================================== @@ -558,12 +560,8 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if else { light = light - (255 - light); - // Don't go out of bounds - if (light < 0) - light = 0; - else if (light > 255) - light = 255; + light = CLAMP(light, 0, 255); alpha = (realcolor.s.alpha*255)/25; @@ -602,11 +600,7 @@ static FUINT HWR_CalcWallLight(FUINT lightnum, fixed_t v1x, fixed_t v1y, fixed_t if (extralight != 0) { finallight += extralight; - - if (finallight < 0) - finallight = 0; - if (finallight > 255) - finallight = 255; + finallight = CLAMP(finallight, 0 , 255); } } @@ -646,11 +640,7 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, angle_t dir, fixed_t delta) if (extralight != 0) { finallight += extralight; - - if (finallight < 0) - finallight = 0; - if (finallight > 255) - finallight = 255; + finallight = CLAMP(finallight, 0 , 255); } } @@ -1135,27 +1125,15 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, { if (pfloor && (pfloor->flags & FF_FOG)) { - if (HWR_ShouldUsePaletteRendering()) - { - lightnum = pfloor->master->frontsector->lightlevel; - colormap = pfloor->master->frontsector->extra_colormap; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); - }else{ - lightnum = HWR_CalcWallLight(pfloor->master->frontsector->lightlevel, v1x, v1y, v2x, v2y); - colormap = pfloor->master->frontsector->extra_colormap; - } + lightnum = pfloor->master->frontsector->lightlevel; + colormap = pfloor->master->frontsector->extra_colormap; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); } else { - if (HWR_ShouldUsePaletteRendering()) - { - lightnum = *list[i].lightlevel; - colormap = list[i].extra_colormap; - 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; + colormap = list[i].extra_colormap; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, v1x, v1y, v2x, v2y); } } @@ -1522,17 +1500,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom cliplow = (float)texturehpeg; cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); - if (HWR_ShouldUsePaletteRendering()) - { - lightnum = gr_frontsector->lightlevel; - colormap = gr_frontsector->extra_colormap; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - } - else - { - lightnum = HWR_CalcWallLight(gr_frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); - colormap = gr_frontsector->extra_colormap; - } + lightnum = gr_frontsector->lightlevel; + colormap = gr_frontsector->extra_colormap; + lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); if (gr_linedef->flags & ML_TFERLINE) noencore = true; @@ -2253,18 +2223,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - if (HWR_ShouldUsePaletteRendering()) - { - lightnum = rover->master->frontsector->lightlevel; - colormap = rover->master->frontsector->extra_colormap; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - } - else - { - lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); - colormap = rover->master->frontsector->extra_colormap; - } - + lightnum = rover->master->frontsector->lightlevel; + colormap = rover->master->frontsector->extra_colormap; + 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); if (gr_frontsector->numlights) @@ -2393,17 +2355,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom blendmode = PF_Fog|PF_NoTexture; - if (HWR_ShouldUsePaletteRendering()) - { - lightnum = rover->master->frontsector->lightlevel; - colormap = rover->master->frontsector->extra_colormap; - lightnum = colormap ? lightnum : HWR_CalcWallLight(lightnum, vs.x, vs.y, ve.x, ve.y); - } - else - { - lightnum = HWR_CalcWallLight(rover->master->frontsector->lightlevel, vs.x, vs.y, ve.x, ve.y); - colormap = rover->master->frontsector->extra_colormap; - } + lightnum = rover->master->frontsector->lightlevel; + colormap = rover->master->frontsector->extra_colormap; + 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); @@ -4568,10 +4522,7 @@ void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean planeinfo->isceiling = isceiling; planeinfo->fixedheight = fixedheight; - if (HWR_ShouldUsePaletteRendering()) - planeinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; - else - planeinfo->lightlevel = lightlevel; + planeinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; planeinfo->lumpnum = lumpnum; planeinfo->xsub = xsub; @@ -4591,10 +4542,7 @@ void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *polysector, polyplaneinfo->isceiling = isceiling; polyplaneinfo->fixedheight = fixedheight; - if (HWR_ShouldUsePaletteRendering()) - polyplaneinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; - else - polyplaneinfo->lightlevel = lightlevel; + polyplaneinfo->lightlevel = (planecolormap && (planecolormap->fog & 1)) ? 255 : lightlevel; polyplaneinfo->lumpnum = lumpnum; polyplaneinfo->polysector = polysector; @@ -6307,4 +6255,7 @@ void HWR_DrawScreenFinalTexture(INT32 width, INT32 height) { HWD.pfnDrawScreenFinalTexture(HWD_SCREENTEXTURE_GENERIC2, width, height); } + +#undef CLAMP + #endif // HWRENDER From 31b7482c3aaaa889c3bc91ff00c1d0ad86b87f95 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 30 Jun 2024 18:31:31 +0200 Subject: [PATCH 81/91] small optimization to batching --- src/hardware/hw_batching.c | 58 ++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index e0afb6054..f23505bd1 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -35,7 +35,7 @@ int finalVertexArrayAllocSize = 65536; PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed int polygonArraySize = 0; -UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray +PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray int polygonArrayAllocSize = 65536; FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon @@ -55,7 +55,7 @@ void HWR_StartBatching(void) finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); - polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); + polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } @@ -96,8 +96,8 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt free(polygonArray); polygonArray = new_array; // also need to redo the index array, dont need to copy it though - free(polygonIndexArray); - polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); + free(polygonArraySorted); + polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); } while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) @@ -134,10 +134,8 @@ void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPt static int comparePolygons(const void *p1, const void *p2) { - unsigned int index1 = *(const unsigned int*)p1; - unsigned int index2 = *(const unsigned int*)p2; - PolygonArrayEntry* poly1 = &polygonArray[index1]; - PolygonArrayEntry* poly2 = &polygonArray[index2]; + PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; + PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; int diff; INT64 diff64; UINT32 downloaded1 = 0; @@ -155,7 +153,7 @@ static int comparePolygons(const void *p1, const void *p2) // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) - return index1 - index2; + return poly1 - poly2; if (poly1->texture) downloaded1 = poly1->texture->downloaded; // there should be a opengl texture name here, usable for comparisons @@ -184,10 +182,8 @@ static int comparePolygons(const void *p1, const void *p2) static int comparePolygonsNoShaders(const void *p1, const void *p2) { - unsigned int index1 = *(const unsigned int*)p1; - unsigned int index2 = *(const unsigned int*)p2; - PolygonArrayEntry* poly1 = &polygonArray[index1]; - PolygonArrayEntry* poly2 = &polygonArray[index2]; + PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; + PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; int diff; INT64 diff64; @@ -205,7 +201,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) downloaded2 = texture2->downloaded; // skywalls and horizon lines must retain their order for horizon lines to work if (!texture1 && !texture2) - return index1 - index2; + return poly1 - poly2; diff64 = downloaded1 - downloaded2; if (diff64 != 0) return diff64; @@ -225,7 +221,7 @@ void HWR_RenderBatches(void) int finalVertexWritePos = 0;// position in finalVertexArray int finalIndexWritePos = 0;// position in finalVertexIndexArray - int polygonReadPos = 0;// position in polygonIndexArray + int polygonReadPos = 0;// position in polygonArraySorted int currentShader; int nextShader = 0; @@ -258,18 +254,18 @@ void HWR_RenderBatches(void) ps_hw_numcalls.value.i = ps_hw_numverts.value.i = 0; ps_hw_numshaders.value.i = ps_hw_numtextures.value.i = ps_hw_numpolyflags.value.i = ps_hw_numcolors.value.i = 1; - // init polygonIndexArray + // init polygonArraySorted for (i = 0; i < polygonArraySize; i++) { - polygonIndexArray[i] = i; + polygonArraySorted[i] = &polygonArray[i]; } // sort polygons PS_START_TIMING(ps_hw_batchsorttime); if (cv_grshaders.value && gr_shadersavailable) - qs22j(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons); + qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons); else - qs22j(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders); + qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders); PS_STOP_TIMING(ps_hw_batchsorttime); // sort order // 1. shader @@ -280,10 +276,10 @@ void HWR_RenderBatches(void) PS_START_TIMING(ps_hw_batchdrawtime); - currentShader = polygonArray[polygonIndexArray[0]].shader; - currentTexture = polygonArray[polygonIndexArray[0]].texture; - currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags; - currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf; + currentShader = polygonArraySorted[0]->shader; + currentTexture = polygonArraySorted[0]->texture; + currentPolyFlags = polygonArraySorted[0]->polyFlags; + currentSurfaceInfo = polygonArraySorted[0]->surf; // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms // and a color array could replace the color calls. @@ -322,8 +318,8 @@ void HWR_RenderBatches(void) // reset write pos // repeat loop - int index = polygonIndexArray[polygonReadPos++]; - int numVerts = polygonArray[index].numVerts; + PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++]; + int numVerts = entry->numVerts; // before writing, check if there is enough room // using 'while' instead of 'if' here makes sure that there will *always* be enough room. // probably never will this loop run more than once though @@ -344,7 +340,7 @@ void HWR_RenderBatches(void) finalVertexIndexArray = new_index_array; } // write the vertices of the polygon - memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex], + memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex], numVerts * sizeof(FOutVector)); // write the indexes, pointing to the fan vertexes but in triangles format firstIndex = finalVertexWritePos; @@ -364,11 +360,11 @@ void HWR_RenderBatches(void) else { // check if a state change is required, set the change bools and next vars - int nextIndex = polygonIndexArray[polygonReadPos]; - nextShader = polygonArray[nextIndex].shader; - nextTexture = polygonArray[nextIndex].texture; - nextPolyFlags = polygonArray[nextIndex].polyFlags; - nextSurfaceInfo = polygonArray[nextIndex].surf; + PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos]; + nextShader = nextEntry->shader; + nextTexture = nextEntry->texture; + nextPolyFlags = nextEntry->polyFlags; + nextSurfaceInfo = nextEntry->surf; if (nextPolyFlags & PF_NoTexture) nextTexture = 0; if (currentShader != nextShader && cv_grshaders.value && gr_shadersavailable) From 2316c117b1d4ba4d38f877b2b705e4dd022323a9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Jul 2024 16:07:11 +0200 Subject: [PATCH 82/91] improve teleport interpolation stuff --- src/g_game.c | 11 ++++++++++- src/p_spec.c | 6 +----- src/p_telept.c | 23 ++++++++++++++--------- src/s_sound.c | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index aaa6b6fbe..887fd8ffd 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2108,7 +2108,7 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) olddisplayplayer = (*displayplayerp); /* Check if anyone is available to view. */ - if (( playernum = G_FindView(playernum, viewnum, onlyactive, playernum < olddisplayplayer) ) == -1) + if ((playernum = G_FindView(playernum, viewnum, onlyactive, playernum < olddisplayplayer)) == -1) return; /* Focus our target view first so that we don't take its player. */ @@ -2117,6 +2117,10 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) { camerap = &camera[viewnum-1]; P_ResetCamera(&players[(*displayplayerp)], camerap); + + // Make sure the viewport doesn't interpolate at all into + // its new position -- just snap instantly into place. + R_ResetViewInterpolation(viewnum); } if (viewnum > splits) @@ -2129,6 +2133,11 @@ void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive) (*displayplayerp) = G_FindView(0, viewd, onlyactive, false); P_ResetCamera(&players[(*displayplayerp)], camerap); + + + // Make sure the viewport doesn't interpolate at all into + // its new position -- just snap instantly into place. + R_ResetViewInterpolation(viewd); } } diff --git a/src/p_spec.c b/src/p_spec.c index 9fb1953ee..ddf938330 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2371,11 +2371,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) y = sides[line->sidenum[0]].rowoffset; z = line->frontsector->ceilingheight; - P_UnsetThingPosition(mo); - mo->x += x; - mo->y += y; - mo->z += z; - P_SetThingPosition(mo); + P_SetOrigin(mo, mo->x + x, mo->y + y, mo->z + z); if (mo->player) { diff --git a/src/p_telept.c b/src/p_telept.c index 7c9da2269..a7cef7b1d 100644 --- a/src/p_telept.c +++ b/src/p_telept.c @@ -82,8 +82,13 @@ void P_MixUp(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle, // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player == &players[displayplayers[i]] && camera[i].chase) + if (thing->player != &players[displayplayers[i]]) + continue; + + if (camera[i].chase) P_ResetCamera(thing->player, &camera[i]); + + R_ResetViewInterpolation(i + 1); } // don't run in place after a teleport @@ -153,14 +158,14 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle // move chasecam at new player location for (i = 0; i <= splitscreen; i++) { - if (thing->player == &players[displayplayers[i]]) - { - localangle[i] = angle; - if (camera[i].chase) - P_ResetCamera(thing->player, &camera[i]); - R_ResetViewInterpolation(i + 1); - break; - } + if (thing->player != &players[displayplayers[i]]) + continue; + + localangle[i] = angle; + if (camera[i].chase) + P_ResetCamera(thing->player, &camera[i]); + + R_ResetViewInterpolation(i + 1); } // don't run in place after a teleport diff --git a/src/s_sound.c b/src/s_sound.c index 21d29b231..ae036a3db 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1996,7 +1996,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 strncpy(newmusic, mmusic, 6); - if(LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms)) + if (LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms)) return; // No Music (empty string) From 7f34a1d83e52204cf337574ff66df27cbddb2524 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Jul 2024 20:54:34 +0200 Subject: [PATCH 83/91] add gr_lightdithering to shader mhhm dithering --- src/hardware/hw_main.c | 15 ++++++++++++ src/hardware/hw_main.h | 1 + src/hardware/hw_shaders.c | 7 ++++++ src/hardware/hw_shaders.h | 42 +++++++++++++++++++++++++++++--- src/hardware/r_opengl/r_opengl.c | 6 +++++ 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index edeb4ad1e..6c98c8c97 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -81,6 +81,8 @@ static void CV_grshaders_OnChange(void); static void CV_grpaletterendering_OnChange(void); static void CV_grpalettedepth_OnChange(void); +static void CV_grlightdithering_OnChange(void); + static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}}; static CV_PossibleValue_t grfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, @@ -157,6 +159,8 @@ consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, C static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 bits"}, {0, NULL}}; consvar_t cv_grpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_grpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lightdither = {"gr_lightdithering", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grlightdithering_OnChange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -217,6 +221,15 @@ static void CV_grpaletterendering_OnChange(void) } } +static void CV_grlightdithering_OnChange(void) +{ + ONLY_IF_GL_LOADED + if (gr_shadersavailable) + { + HWR_CompileShaders(); + } +} + static void CV_grpalettedepth_OnChange(void) { ONLY_IF_GL_LOADED @@ -5999,6 +6012,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grpalettedepth); CV_RegisterVar(&cv_grflashpal); + CV_RegisterVar(&cv_lightdither); + #ifdef USE_FBO_OGL CV_RegisterVar(&cv_grframebuffer); #endif diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 1c51e2981..b5a775365 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -179,6 +179,7 @@ extern consvar_t cv_grrenderdistance; extern consvar_t cv_grpaletterendering; extern consvar_t cv_grpalettedepth; extern consvar_t cv_grflashpal; +extern consvar_t cv_lightdither; extern consvar_t cv_grscreentextures; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 6757d6fe4..b58ca4137 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -82,6 +82,7 @@ static shadertarget_t gl_shadertargets[NUMSHADERTARGETS]; #define WHITESPACE_CHARS " \t" #define PALETTE_RENDERING_DEFINE "#define SRB2_PALETTE_RENDERING" +#define LIGHT_DITHERING_DEFINE "#define SRB2_LIGHT_DITHER" // Initialize shader variables and the backend's shader system. Load the base shaders. // Returns false if shaders cannot be used. @@ -282,6 +283,9 @@ static char *HWR_PreprocessShader(char *original) if (cv_grpaletterendering.value) ADD_TO_LEN(PALETTE_RENDERING_DEFINE) + if (cv_lightdither.value) + ADD_TO_LEN(LIGHT_DITHERING_DEFINE) + #undef ADD_TO_LEN #define VERSION_PART "#version " @@ -323,6 +327,9 @@ static char *HWR_PreprocessShader(char *original) if (cv_grpaletterendering.value) WRITE_DEFINE(PALETTE_RENDERING_DEFINE) + if (cv_lightdither.value) + WRITE_DEFINE(LIGHT_DITHERING_DEFINE) + #undef WRITE_DEFINE // Write a #line directive, so compiler errors will report line numbers from the diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 8f600fa79..6f3ef225e 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -51,15 +51,49 @@ // // Include GLSL_FLOOR_FUDGES or GLSL_WALL_FUDGES or define the fudges in shaders that use this macro. +#define GLSL_DOOM_COLORMAP_DITHER \ + "float baseValue = max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ + "float halfResolutionx = scr_resolution.x;\n" \ + "float halfResolutiony = scr_resolution.y;\n" \ + "if (scr_resolution.x > 1280.0) {\n" \ + " halfResolutionx = scr_resolution.x * 0.5;\n" \ + "}\n" \ + "if (scr_resolution.y > 720.0) {\n" \ + " halfResolutiony = scr_resolution.y * 0.5;\n" \ + "}\n" \ + "vec2 normalizedPosition = position * vec2(halfResolutionx / scr_resolution.x, halfResolutiony / scr_resolution.y);\n" \ + "int x = int(mod(normalizedPosition.x, 8.0));\n" \ + "int y = int(mod(normalizedPosition.y, 8.0));\n" \ + "float bayerMatrix[8][8] = float[8][8](\n" \ + "float[8](0.0, 32.0, 8.0, 40.0, 2.0, 34.0, 10.0, 42.0),\n" \ + "float[8](48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0),\n" \ + "float[8](12.0, 44.0, 4.0, 36.0, 14.0, 46.0, 6.0, 38.0),\n" \ + "float[8](60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0),\n" \ + "float[8](3.0, 35.0, 11.0, 43.0, 1.0, 33.0, 9.0, 41.0),\n" \ + "float[8](51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0),\n" \ + "float[8](15.0, 47.0, 7.0, 39.0, 13.0, 45.0, 5.0, 37.0),\n" \ + "float[8](63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0)\n" \ + ");\n" \ + "float threshold = bayerMatrix[y][x] / 64.0;\n" \ + "return baseValue + threshold - 0.5 / 64.0;\n" \ + +#define GLSL_DOOM_COLORMAP_NODITHER \ + "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ + #define GLSL_DOOM_COLORMAP \ - "float R_DoomColormap(float light, float z)\n" \ + "uniform vec2 scr_resolution;\n" \ + "float R_DoomColormap(float light, float z, vec2 position)\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" \ "float cap = (155.0 - light) * 0.26;\n" \ - "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ + "#ifdef SRB2_LIGHT_DITHER\n" \ + GLSL_DOOM_COLORMAP_DITHER \ + "#else\n" \ + GLSL_DOOM_COLORMAP_NODITHER \ + "#endif\n" \ "}\n" // lighting cap adjustment: // first num (155.0), increase to make it start to go dark sooner @@ -69,7 +103,7 @@ "float R_DoomLightingEquation(float light)\n" \ "{\n" \ "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float colormap = floor(R_DoomColormap(light, z)) + 0.5;\n" \ + "float colormap = floor(R_DoomColormap(light, z, gl_FragCoord.xy)) + 0.5;\n" \ "return clamp(colormap, 0.0, 31.0) / 32.0;\n" \ "}\n" @@ -95,7 +129,7 @@ #define GLSL_PALETTE_RENDERING \ "float tex_pal_idx = texture3D(palette_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" \ + "float light_y = clamp(floor(R_DoomColormap(lighting, z, gl_FragCoord.xy)), 0.0, 31.0);\n" \ "vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \ "vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \ "final_color.a = texel.a * poly_color.a;\n" \ diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 12e70f945..50c686332 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -669,6 +669,8 @@ typedef enum // misc. gluniform_leveltime, + + gluniform_scr_resolution, gluniform_max, } gluniform_t; @@ -1836,6 +1838,8 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF UNIFORM_1(shader->uniforms[gluniform_leveltime], ((float)shader_leveltime) / TICRATE, pglUniform1f); + UNIFORM_2(shader->uniforms[gluniform_scr_resolution], vid.width, vid.height, pglUniform2f); + #undef UNIFORM_1 #undef UNIFORM_2 #undef UNIFORM_3 @@ -1953,6 +1957,8 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex"); shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); + shader->uniforms[gluniform_scr_resolution] = GETUNI("scr_resolution"); + // misc. shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); #undef GETUNI From 40143375fc674386e4dcae069c1f9bdb357d82d3 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 1 Jul 2024 22:42:25 +0300 Subject: [PATCH 84/91] If shader compilation failed, print info log --- src/hardware/r_opengl/r_opengl.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 50c686332..c3d0daf0d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -608,6 +608,7 @@ typedef void (APIENTRY *PFNglDeleteProgram) (GLuint); typedef void (APIENTRY *PFNglAttachShader) (GLuint, GLuint); typedef void (APIENTRY *PFNglLinkProgram) (GLuint); typedef void (APIENTRY *PFNglGetProgramiv) (GLuint, GLenum, GLint*); +typedef void (APIENTRY *PFNglGetProgramInfoLog) (GLuint, GLsizei, GLsizei*, GLchar*); typedef void (APIENTRY *PFNglUseProgram) (GLuint); typedef void (APIENTRY *PFNglUniform1i) (GLint, GLint); typedef void (APIENTRY *PFNglUniform1f) (GLint, GLfloat); @@ -630,6 +631,7 @@ static PFNglDeleteProgram pglDeleteProgram; static PFNglAttachShader pglAttachShader; static PFNglLinkProgram pglLinkProgram; static PFNglGetProgramiv pglGetProgramiv; +static PFNglGetProgramInfoLog pglGetProgramInfoLog; static PFNglUseProgram pglUseProgram; static PFNglUniform1i pglUniform1i; static PFNglUniform1f pglUniform1f; @@ -737,6 +739,7 @@ void SetupGLFunc4(void) pglAttachShader = GetGLFunc("glAttachShader"); pglLinkProgram = GetGLFunc("glLinkProgram"); pglGetProgramiv = GetGLFunc("glGetProgramiv"); + pglGetProgramInfoLog = GetGLFunc("glGetProgramInfoLog"); pglUseProgram = GetGLFunc("glUseProgram"); pglUniform1i = GetGLFunc("glUniform1i"); pglUniform1f = GetGLFunc("glUniform1f"); @@ -1854,6 +1857,7 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) GLint result; const GLchar *vert_shader = shader->vertex_shader; const GLchar *frag_shader = shader->fragment_shader; + GLchar info_log[512]; if (shader->program) pglDeleteProgram(shader->program); @@ -1883,7 +1887,10 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) pglGetShaderiv(gl_vertShader, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { - GL_MSG_Error("Error compiling vertex shader", gl_vertShader, i); + pglGetShaderInfoLog(gl_vertShader, 512, NULL, info_log); + + GL_MSG_Error("Error compiling vertex shader: %s\n", info_log); + pglDeleteShader(gl_vertShader); return false; } @@ -1910,7 +1917,9 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) pglGetShaderiv(gl_fragShader, GL_COMPILE_STATUS, &result); if (result == GL_FALSE) { - GL_MSG_Error("Error compiling fragment shader", gl_fragShader, i); + pglGetShaderInfoLog(gl_fragShader, 512, NULL, info_log); + + GL_MSG_Error("Error compiling fragment shader: %s\n", info_log); pglDeleteShader(gl_vertShader); pglDeleteShader(gl_fragShader); return false; @@ -1936,7 +1945,8 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) // couldn't link? if (result != GL_TRUE) { - GL_MSG_Error("Shader_CompileProgram: Error linking shader program %s\n", HWR_GetShaderName(i)); + pglGetProgramInfoLog(shader->program, 512, NULL, info_log); + GL_MSG_Error("Shader_CompileProgram: Error linking shader program %s: %s\n", HWR_GetShaderName(i), info_log); pglDeleteProgram(shader->program); return false; } From 3456ef96a767f042b496caf49294c79a0a9d7f45 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 1 Jul 2024 23:15:59 +0300 Subject: [PATCH 85/91] Use a fake 2d array in dither shader so it compiles with older glsl versions (1.20 at least) --- src/hardware/hw_shaders.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 6f3ef225e..775a16db9 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -64,17 +64,17 @@ "vec2 normalizedPosition = position * vec2(halfResolutionx / scr_resolution.x, halfResolutiony / scr_resolution.y);\n" \ "int x = int(mod(normalizedPosition.x, 8.0));\n" \ "int y = int(mod(normalizedPosition.y, 8.0));\n" \ - "float bayerMatrix[8][8] = float[8][8](\n" \ - "float[8](0.0, 32.0, 8.0, 40.0, 2.0, 34.0, 10.0, 42.0),\n" \ - "float[8](48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0),\n" \ - "float[8](12.0, 44.0, 4.0, 36.0, 14.0, 46.0, 6.0, 38.0),\n" \ - "float[8](60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0),\n" \ - "float[8](3.0, 35.0, 11.0, 43.0, 1.0, 33.0, 9.0, 41.0),\n" \ - "float[8](51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0),\n" \ - "float[8](15.0, 47.0, 7.0, 39.0, 13.0, 45.0, 5.0, 37.0),\n" \ - "float[8](63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0)\n" \ + "float bayerMatrix[8*8] = float[8*8](\n" \ + "0.0, 32.0, 8.0, 40.0, 2.0, 34.0, 10.0, 42.0,\n" \ + "48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0,\n" \ + "12.0, 44.0, 4.0, 36.0, 14.0, 46.0, 6.0, 38.0,\n" \ + "60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0,\n" \ + "3.0, 35.0, 11.0, 43.0, 1.0, 33.0, 9.0, 41.0,\n" \ + "51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0,\n" \ + "15.0, 47.0, 7.0, 39.0, 13.0, 45.0, 5.0, 37.0,\n" \ + "63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0\n" \ ");\n" \ - "float threshold = bayerMatrix[y][x] / 64.0;\n" \ + "float threshold = bayerMatrix[y*8 + x] / 64.0;\n" \ "return baseValue + threshold - 0.5 / 64.0;\n" \ #define GLSL_DOOM_COLORMAP_NODITHER \ @@ -190,10 +190,12 @@ // hand tuned adjustments for light level calculation #define GLSL_FLOOR_FUDGES \ + "#version 120\n" \ "#define STARTMAP_FUDGE 1.06\n" \ "#define SCALE_FUDGE 1.15\n" #define GLSL_WALL_FUDGES \ + "#version 120\n" \ "#define STARTMAP_FUDGE 1.05\n" \ "#define SCALE_FUDGE 2.2\n" From d37a1c799fe02aeb8fe8e769715e0c02f122eccd Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Jul 2024 23:09:00 +0200 Subject: [PATCH 86/91] change dither matrix to 4x4 a little grittier also smol cleanup --- src/hardware/hw_shaders.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 775a16db9..4464acfca 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -56,26 +56,22 @@ "float halfResolutionx = scr_resolution.x;\n" \ "float halfResolutiony = scr_resolution.y;\n" \ "if (scr_resolution.x > 1280.0) {\n" \ - " halfResolutionx = scr_resolution.x * 0.5;\n" \ + "halfResolutionx = scr_resolution.x * 0.5;\n" \ "}\n" \ "if (scr_resolution.y > 720.0) {\n" \ - " halfResolutiony = scr_resolution.y * 0.5;\n" \ + "halfResolutiony = scr_resolution.y * 0.5;\n" \ "}\n" \ "vec2 normalizedPosition = position * vec2(halfResolutionx / scr_resolution.x, halfResolutiony / scr_resolution.y);\n" \ - "int x = int(mod(normalizedPosition.x, 8.0));\n" \ - "int y = int(mod(normalizedPosition.y, 8.0));\n" \ - "float bayerMatrix[8*8] = float[8*8](\n" \ - "0.0, 32.0, 8.0, 40.0, 2.0, 34.0, 10.0, 42.0,\n" \ - "48.0, 16.0, 56.0, 24.0, 50.0, 18.0, 58.0, 26.0,\n" \ - "12.0, 44.0, 4.0, 36.0, 14.0, 46.0, 6.0, 38.0,\n" \ - "60.0, 28.0, 52.0, 20.0, 62.0, 30.0, 54.0, 22.0,\n" \ - "3.0, 35.0, 11.0, 43.0, 1.0, 33.0, 9.0, 41.0,\n" \ - "51.0, 19.0, 59.0, 27.0, 49.0, 17.0, 57.0, 25.0,\n" \ - "15.0, 47.0, 7.0, 39.0, 13.0, 45.0, 5.0, 37.0,\n" \ - "63.0, 31.0, 55.0, 23.0, 61.0, 29.0, 53.0, 21.0\n" \ + "int x = int(mod(normalizedPosition.x, 4.0));\n" \ + "int y = int(mod(normalizedPosition.y, 4.0));\n" \ + "float bayerMatrix[4*4] = float[4*4](\n" \ + "0.0, 8.0, 2.0, 10.0,\n" \ + "12.0, 4.0, 14.0, 6.0,\n" \ + "3.0, 11.0, 1.0, 9.0,\n" \ + "15.0, 7.0, 13.0, 5.0\n" \ ");\n" \ - "float threshold = bayerMatrix[y*8 + x] / 64.0;\n" \ - "return baseValue + threshold - 0.5 / 64.0;\n" \ + "float threshold = bayerMatrix[y*4 + x] / 16.0;\n" \ + "return baseValue + threshold - 0.5 / 16.0;\n" \ #define GLSL_DOOM_COLORMAP_NODITHER \ "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ From fc014535440f0686f3fad08e7a18546a9f664f46 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Jul 2024 23:08:24 +0200 Subject: [PATCH 87/91] scale dithering a little diff for a little smoother "fade" in pal render --- src/hardware/hw_shaders.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index 4464acfca..7b188f64b 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -70,7 +70,11 @@ "3.0, 11.0, 1.0, 9.0,\n" \ "15.0, 7.0, 13.0, 5.0\n" \ ");\n" \ + "#ifdef SRB2_PALETTE_RENDERING\n" \ + "float threshold = bayerMatrix[y*4 + x] / 12.0;\n" \ + "#else\n" \ "float threshold = bayerMatrix[y*4 + x] / 16.0;\n" \ + "#endif\n" \ "return baseValue + threshold - 0.5 / 16.0;\n" \ #define GLSL_DOOM_COLORMAP_NODITHER \ From f73e84e0adc33a7faba99d1049a7a889388c8785 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 2 Jul 2024 02:26:45 +0200 Subject: [PATCH 88/91] stuff --- src/g_game.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 887fd8ffd..68edfed35 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2251,13 +2251,14 @@ void G_Ticker(boolean run) buf = gametic % TICQUEUE; if (!demo.playback) - // read/write demo and check turbo cheat - for (i = 0; i < MAXPLAYERS; i++) { - cmd = &players[i].cmd; - - if (playeringame[i]) + for (i = 0; i < MAXPLAYERS; i++) // read/write demo and check turbo cheat { + cmd = &players[i].cmd; + + if (!playeringame[i]) + continue; + //@TODO all this throwdir stuff shouldn't be here! But it stays for now to maintain 1.0.4 compat... // Remove for 1.1! From 606717d253616a8476155a2a08fc1bc34429e836 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 24 Jun 2024 21:03:53 +0200 Subject: [PATCH 89/91] prevent potential crash when trying to kill bananachain --- src/p_inter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_inter.c b/src/p_inter.c index 68d02cdd9..e0e0986e6 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1955,7 +1955,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) { if (target->movedir != 0 && target->movedir < (UINT16)target->target->player->kartstuff[k_itemamount]) { - if (target->target->hnext) + if (target->target->hnext && !P_MobjWasRemoved(target->target->hnext)) K_KillBananaChain(target->target->hnext, inflictor, source); target->target->player->kartstuff[k_itemamount] = 0; } From c59564723c727f4e803ac3c3aaa7337a7d0fa39b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Jul 2024 13:04:11 +0200 Subject: [PATCH 90/91] Clamp lindex during vissprite light calculation Mitigates against negative or very large xscale values causing lindex to evaluate < 0, preventing a potential colormap indexing-related crash. --- src/r_things.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 372ddb964..a769960ea 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -954,7 +954,6 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; -#define CLAMP(x, min_val, max_val) ((x) < (min_val) ? (min_val) : ((x) > (max_val) ? (max_val) : (x))) for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); @@ -962,7 +961,6 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) R_DrawMaskedColumn(column); } -#undef CLAMP colfunc = basecolfunc; } @@ -1048,8 +1046,9 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) { lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); - if (lindex >= MAXLIGHTSCALE) - lindex = MAXLIGHTSCALE-1; + // Mitigate against negative xscale and arithmetic overflow + lindex = CLAMP(lindex, 0, MAXLIGHTSCALE - 1); + newsprite->colormap = spritelights[lindex]; } } @@ -1725,8 +1724,8 @@ static void R_ProjectSprite(mobj_t *thing) // diminished light lindex = FixedMul(xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); - if (lindex >= MAXLIGHTSCALE) - lindex = MAXLIGHTSCALE-1; + // Mitigate against negative xscale and arithmetic overflow + lindex = CLAMP(lindex, 0, MAXLIGHTSCALE - 1); vis->colormap = spritelights[lindex]; } From 66ce0871bc8ca89ed3930d450cb7f6ce300f515d Mon Sep 17 00:00:00 2001 From: NepDisk <16447892+NepDisk@users.noreply.github.com> Date: Sat, 22 Jun 2024 18:48:56 -0400 Subject: [PATCH 91/91] Fix automap multiplayer crash https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2488 --- src/am_map.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/am_map.c b/src/am_map.c index 666113ddb..d94ec7262 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -1015,6 +1015,9 @@ static inline void AM_drawPlayers(void) { if (!playeringame[i] || players[i].spectator) continue; + + if (!players[i].mo) + continue; p = &players[i]; if (p->skincolor > 0)