From 086d0113c5bbd58aaccaddcb487f7ee7cde1c347 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 27 May 2024 18:14:59 +0200 Subject: [PATCH 01/36] 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"); -- 2.54.0 From 4847e4e3cb19a60c9b38a0e5bb2ad880e199f4c3 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:22:48 +0200 Subject: [PATCH 02/36] 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++) -- 2.54.0 From 455bbe47c283620d182e264b24931e814fcc7cc9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 22:38:20 +0200 Subject: [PATCH 03/36] 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; -- 2.54.0 From 37d3e2ae1a679f437c6333d7b58074d9e84801d1 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:02:54 +0200 Subject: [PATCH 04/36] 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; -- 2.54.0 From faa5dbd0e73057bb19cacfa7daa3a18d86f260ee Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:55:03 +0200 Subject: [PATCH 05/36] 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; } -- 2.54.0 From 040ddb1f40b17c84427c95a241a102c0e8f633bb Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:23:14 +0300 Subject: [PATCH 06/36] 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 -- 2.54.0 From 6269c7c827feed85ef1bb246b4bed51c565bc6d5 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 30 May 2024 19:32:18 +0300 Subject: [PATCH 07/36] 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 -- 2.54.0 From dc03359f3a44481338715be809ebf9038bd47e6f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 30 May 2024 19:59:01 +0200 Subject: [PATCH 08/36] 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) -- 2.54.0 From b01a2836ea51bfd8d52b8b1116df8ee93052db3d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:29:40 +0200 Subject: [PATCH 09/36] 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; -- 2.54.0 From 37a394ebaa63db043ff11a3526100fcb4938239e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 31 May 2024 23:04:26 +0200 Subject: [PATCH 10/36] 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) { -- 2.54.0 From 8052eb1c3a0bf58fe531485ba709b528d75ba0fe Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:29:20 +0200 Subject: [PATCH 11/36] 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; -- 2.54.0 From 957159d4859b2c73221b55cd9d2444d925bf904f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 16:31:49 +0200 Subject: [PATCH 12/36] 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; -- 2.54.0 From 38633a85168f8577bfedd9899327821980f4dcfc Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 1 Jun 2024 17:03:27 +0200 Subject: [PATCH 13/36] 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; -- 2.54.0 From da9d57a6246ee969db0f69ca115eea857f15d468 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:39:22 +0300 Subject: [PATCH 14/36] 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 +} -- 2.54.0 From 1747ebf481fab9e30d69aee23df7e59a9ec52d60 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:43:09 +0300 Subject: [PATCH 15/36] 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 +} -- 2.54.0 From 0e927ce4bd087988c29487fd00f5e9055c1ad514 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:43:42 +0300 Subject: [PATCH 16/36] 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 +} -- 2.54.0 From bf75644144290de36bca71126294b60e3938cd99 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 28 May 2024 20:28:27 +0200 Subject: [PATCH 17/36] 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) -- 2.54.0 From ee2ec01eb9796c41f435cbfa41a7046bff4039c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 2 Jun 2024 00:44:48 +0200 Subject: [PATCH 18/36] 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 // ================== -- 2.54.0 From cae40928ad16d088168bc4ba890de890d9337ee6 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 3 Jun 2024 00:17:11 +0300 Subject: [PATCH 19/36] 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); -- 2.54.0 From f977af6a802ffb4330a21d9c790a0e37c72c8e5b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 15:13:39 +0200 Subject: [PATCH 20/36] 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 21/36] 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! -- 2.54.0 From 9de3db7c97492486264c7faf378598f5b8d77868 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 16:52:25 +0200 Subject: [PATCH 22/36] 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 -- 2.54.0 From ea510f95b899220be4251a8b95729f9b9e874db6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 17:15:36 +0200 Subject: [PATCH 23/36] 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 24/36] 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 // ================== -- 2.54.0 From 716685d809e836a8aa920732a52703fae420c0ad Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 3 Jun 2024 17:15:16 +0200 Subject: [PATCH 25/36] 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}, -- 2.54.0 From 9b3eaa6fe85a1c9e9264219124516e9e365f53bb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 4 Jun 2024 17:10:24 +0200 Subject: [PATCH 26/36] 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; } // -- 2.54.0 From 4246e429487eb58e3f81aa25bf8c001d3f5a077c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 5 Jun 2024 02:27:18 +0200 Subject: [PATCH 27/36] 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); - } - } } // -------------------------------------------------------------------------- -- 2.54.0 From 1503daf02bb1b4d3a64d119abacf4f59e2ecc0a4 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 5 Jun 2024 14:42:23 +0200 Subject: [PATCH 28/36] 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; -- 2.54.0 From 51392590372e0cef59ca7023296c1aedaafdf8b9 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:42:32 +0200 Subject: [PATCH 29/36] 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(); -- 2.54.0 From cfe6e081689fd65267d10c7c708deaff587cdc68 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:47:06 +0200 Subject: [PATCH 30/36] 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 -- 2.54.0 From f8a8b8ac6e1f02e038e0b17f6f6334cca869fe10 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:53:40 +0200 Subject: [PATCH 31/36] 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) -- 2.54.0 From 4abc2ab5bd32037f7889d055346ea2b28e50a744 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 6 Jun 2024 18:57:04 +0200 Subject: [PATCH 32/36] 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 */ -- 2.54.0 From bd7103d109b026df8b737bbea157283c987e8c54 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:03:58 +0200 Subject: [PATCH 33/36] 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. -- 2.54.0 From 6ffb50530dff945c4b42b8bd1307186fb468e5f3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:13:17 +0200 Subject: [PATCH 34/36] 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); -- 2.54.0 From 07d631e320e096b5190eb6e70fde329c346cc051 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:14:22 +0200 Subject: [PATCH 35/36] 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); -- 2.54.0 From d66e7e660d781b84e4281b4e697c9196e7b63fd4 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 9 Jun 2024 18:49:33 +0200 Subject: [PATCH 36/36] 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; -- 2.54.0