From aec041af072e140d7c756c7115f2872d5b33bd10 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:04:03 -0500 Subject: [PATCH 01/91] Update deh_tables.c --- src/deh_tables.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/deh_tables.c b/src/deh_tables.c index 5733d9b0e..1b877d4b4 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -3822,6 +3822,7 @@ const char *const MOBJTYPE_LIST[] = { // array length left dynamic for sanity t "MT_BIGMACE", // Big Mace "MT_SMALLGRABCHAIN", // Small Grab Chain "MT_BIGGRABCHAIN", // Big Grab Chain + "MT_BLUESPRINGBALL", // Blue spring on a ball "MT_YELLOWSPRINGBALL", // Yellow spring on a ball "MT_REDSPRINGBALL", // Red spring on a ball "MT_SMALLFIREBAR", // Small Firebar From 4da83888c9e2407f5582cb7c2cab39f92e3c0c97 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:11:31 -0500 Subject: [PATCH 02/91] Update info.c --- src/info.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/info.c b/src/info.c index 29a79b1d6..8281cb80c 100644 --- a/src/info.c +++ b/src/info.c @@ -2234,6 +2234,13 @@ state_t states[NUMSTATES] = {SPR_BMCE, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BIGMACE {SPR_SMCH, 1, -1, {NULL}, 0, 0, S_NULL}, // S_SMALLGRABCHAIN {SPR_BMCH, 1, -1, {NULL}, 0, 0, S_NULL}, // S_BIGGRABCHAIN + + // Blue spring on a ball + {SPR_BSPB, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BLUESPRINGBALL + {SPR_BSPB, 4, 4, {A_Pain}, 0, 0, S_BLUESPRINGBALL3}, // S_BLUESPRINGBALL2 + {SPR_BSPB, 3, 1, {NULL}, 0, 0, S_BLUESPRINGBALL4}, // S_BLUESPRINGBALL3 + {SPR_BSPB, 2, 1, {NULL}, 0, 0, S_BLUESPRINGBALL5}, // S_BLUESPRINGBALL4 + {SPR_BSPB, 1, 1, {NULL}, 0, 0, S_BLUESPRINGBALL}, // S_BLUESPRINGBALL5 // Yellow spring on a ball {SPR_YSPB, 0, -1, {NULL}, 0, 0, S_NULL}, // S_YELLOWSPRINGBALL @@ -11511,6 +11518,33 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = MF_SCENERY|MF_SPECIAL|MF_NOGRAVITY, // flags S_NULL // raisestate }, + + { // MT_BLUESPRINGBALL + 1133, // doomednum + S_BLUESPRINGBALL, // spawnstate + 1000, // spawnhealth + S_BLUESPRINGBALL2, // seestate + sfx_None, // seesound + 0, // reactiontime + sfx_None, // attacksound + S_NULL, // painstate + 0, // painchance + sfx_spring, // painsound + S_NULL, // meleestate + S_NULL, // missilestate + S_NULL, // deathstate + S_NULL, // xdeathstate + sfx_None, // deathsound + 24*FRACUNIT, // speed + 17*FRACUNIT, // radius + 34*FRACUNIT, // height + 1, // display offset + 11*FRACUNIT, // mass + 0, // damage + sfx_mswing, // activesound + MF_SCENERY|MF_SPRING|MF_NOGRAVITY, // flags + S_BLUESPRINGBALL2 // raisestate + }, { // MT_YELLOWSPRINGBALL 1134, // doomednum From 8ce067d7ebca9cb96878f902a6ec7022b2fab5f8 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:13:59 -0500 Subject: [PATCH 03/91] Update p_mobj.c --- src/p_mobj.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_mobj.c b/src/p_mobj.c index 7ba6d1fad..0fdf95155 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10379,6 +10379,7 @@ static fixed_t P_DefaultMobjShadowScale (mobj_t *thing) case MT_SMALLGRABCHAIN: case MT_BIGGRABCHAIN: + case MT_BLUESPRINGBALL: case MT_YELLOWSPRINGBALL: case MT_REDSPRINGBALL: From 802f5ab4ea9119e4796f6ec5c96ba1a96a303f1e Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:17:13 -0500 Subject: [PATCH 04/91] Update info.h --- src/info.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/info.h b/src/info.h index 604922beb..125497644 100644 --- a/src/info.h +++ b/src/info.h @@ -779,6 +779,7 @@ typedef enum sprite SPR_BMCH, // Big Mace Chain SPR_SMCE, // Small Mace SPR_BMCE, // Big Mace + SPR_BSPB, // Blue spring on a ball SPR_YSPB, // Yellow spring on a ball SPR_RSPB, // Red spring on a ball SPR_SFBR, // Small Firebar @@ -2669,6 +2670,14 @@ typedef enum state S_SMALLGRABCHAIN, S_BIGGRABCHAIN, + // Blue spring on a ball + S_BLUESPRINGBALL, + S_BLUESPRINGBALL2, + S_BLUESPRINGBALL3, + S_BLUESPRINGBALL4, + S_BLUESPRINGBALL5, + + // Yellow spring on a ball S_YELLOWSPRINGBALL, S_YELLOWSPRINGBALL2, @@ -4644,6 +4653,7 @@ typedef enum mobj_type MT_BIGMACE, // Big Mace MT_SMALLGRABCHAIN, // Small Grab Chain MT_BIGGRABCHAIN, // Big Grab Chain + MT_BLUESPRINGBALL, // Blue spring on a ball MT_YELLOWSPRINGBALL, // Yellow spring on a ball MT_REDSPRINGBALL, // Red spring on a ball MT_SMALLFIREBAR, // Small Firebar From 3195022936adef7d3019a435f198e7eea56e5da3 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:19:32 -0500 Subject: [PATCH 05/91] Update deh_tables.c --- src/deh_tables.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/deh_tables.c b/src/deh_tables.c index 1b877d4b4..d2087ebb0 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -1867,6 +1867,13 @@ const char *const STATE_LIST[] = { // array length left dynamic for sanity testi "S_SMALLGRABCHAIN", "S_BIGGRABCHAIN", + // Blue spring on a ball + "S_BLUESPRINGBALL", + "S_BLUESPRINGBALL2", + "S_BLUESPRINGBALL3", + "S_BLUESPRINGBALL4", + "S_BLUESPRINGBALL5", + // Yellow spring on a ball "S_YELLOWSPRINGBALL", "S_YELLOWSPRINGBALL2", From 8fbf24d68b018eeaffc9ffca788c67f60d53b8ef Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:35:17 -0500 Subject: [PATCH 06/91] Update info.c --- src/info.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/info.c b/src/info.c index 8281cb80c..3da92bb96 100644 --- a/src/info.c +++ b/src/info.c @@ -245,6 +245,7 @@ char sprnames[NUMSPRITES + 1][5] = "BMCH", // Big Mace Chain "SMCE", // Small Mace "BMCE", // Big Mace + "BSPB", // Blue spring on a ball "YSPB", // Yellow spring on a ball "RSPB", // Red spring on a ball "SFBR", // Small Firebar From b0fe3b6b5ac3aaef0ca9ac1e84052017d73c19f7 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 00:36:41 -0500 Subject: [PATCH 07/91] Update hw_light.c --- src/hardware/hw_light.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hardware/hw_light.c b/src/hardware/hw_light.c index 987d70c69..76fecd7aa 100644 --- a/src/hardware/hw_light.c +++ b/src/hardware/hw_light.c @@ -340,6 +340,7 @@ light_t *t_lspr[NUMSPRITES] = &lspr[NOLIGHT], // SPR_BMCH &lspr[NOLIGHT], // SPR_SMCE &lspr[NOLIGHT], // SPR_BMCE + &lspr[NOLIGHT], // SPR_BSPB &lspr[NOLIGHT], // SPR_YSPB &lspr[NOLIGHT], // SPR_RSPB &lspr[REDBALL_L], // SPR_SFBR From 6c9b73ba29a21bed9762408a874d88c265e3a70e Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 11:53:24 -0500 Subject: [PATCH 08/91] Fixed formatting From 63c95e91867559ce062a54774e1285b839a740d4 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 11:55:03 -0500 Subject: [PATCH 09/91] Update info.c --- src/info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/info.c b/src/info.c index 3da92bb96..c53241cdf 100644 --- a/src/info.c +++ b/src/info.c @@ -2237,7 +2237,7 @@ state_t states[NUMSTATES] = {SPR_BMCH, 1, -1, {NULL}, 0, 0, S_NULL}, // S_BIGGRABCHAIN // Blue spring on a ball - {SPR_BSPB, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BLUESPRINGBALL + {SPR_BSPB, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BLUESPRINGBALL {SPR_BSPB, 4, 4, {A_Pain}, 0, 0, S_BLUESPRINGBALL3}, // S_BLUESPRINGBALL2 {SPR_BSPB, 3, 1, {NULL}, 0, 0, S_BLUESPRINGBALL4}, // S_BLUESPRINGBALL3 {SPR_BSPB, 2, 1, {NULL}, 0, 0, S_BLUESPRINGBALL5}, // S_BLUESPRINGBALL4 From 3b01da753f0cdb457ee94c5f0f3707288de7321f Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 16:17:21 -0500 Subject: [PATCH 10/91] Update p_mobj.c --- src/p_mobj.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 0fdf95155..ac971f5db 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10378,8 +10378,8 @@ static fixed_t P_DefaultMobjShadowScale (mobj_t *thing) case MT_SMALLGRABCHAIN: case MT_BIGGRABCHAIN: - - case MT_BLUESPRINGBALL: + + case MT_BLUESPRINGBALL: case MT_YELLOWSPRINGBALL: case MT_REDSPRINGBALL: From 6f4117f7161a46c6b6751eb56d0e4416bcee7ade Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 16:18:54 -0500 Subject: [PATCH 11/91] Update info.h --- src/info.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/info.h b/src/info.h index 125497644..1a26922f7 100644 --- a/src/info.h +++ b/src/info.h @@ -2677,7 +2677,6 @@ typedef enum state S_BLUESPRINGBALL4, S_BLUESPRINGBALL5, - // Yellow spring on a ball S_YELLOWSPRINGBALL, S_YELLOWSPRINGBALL2, From 979ebe262bde2fbd003c9ec97a5d56254cd19c6f Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 18:03:36 -0500 Subject: [PATCH 12/91] Update info.c --- src/info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/info.c b/src/info.c index c53241cdf..9b1c4ac55 100644 --- a/src/info.c +++ b/src/info.c @@ -2235,7 +2235,7 @@ state_t states[NUMSTATES] = {SPR_BMCE, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BIGMACE {SPR_SMCH, 1, -1, {NULL}, 0, 0, S_NULL}, // S_SMALLGRABCHAIN {SPR_BMCH, 1, -1, {NULL}, 0, 0, S_NULL}, // S_BIGGRABCHAIN - + // Blue spring on a ball {SPR_BSPB, 0, -1, {NULL}, 0, 0, S_NULL}, // S_BLUESPRINGBALL {SPR_BSPB, 4, 4, {A_Pain}, 0, 0, S_BLUESPRINGBALL3}, // S_BLUESPRINGBALL2 @@ -11519,7 +11519,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = MF_SCENERY|MF_SPECIAL|MF_NOGRAVITY, // flags S_NULL // raisestate }, - + { // MT_BLUESPRINGBALL 1133, // doomednum S_BLUESPRINGBALL, // spawnstate From 3f63bb1a676a0f1b0fea925651346f4659f43b52 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Wed, 2 Dec 2020 18:16:22 -0500 Subject: [PATCH 13/91] Update p_mobj.c --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index ac971f5db..6c7721aa1 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10378,7 +10378,7 @@ static fixed_t P_DefaultMobjShadowScale (mobj_t *thing) case MT_SMALLGRABCHAIN: case MT_BIGGRABCHAIN: - + case MT_BLUESPRINGBALL: case MT_YELLOWSPRINGBALL: case MT_REDSPRINGBALL: From b975eedd9b1030815d7e6395d93b9edc7922cf6c Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 26 Apr 2021 14:00:34 -0700 Subject: [PATCH 14/91] Fix two bugs with Lua MIN, MAX Plus cvars 1) Any cvar without MIN, MAX would be disallowed; now check that at least one of those values is actually present. 2) Handle value index properly when shifting array. --- src/lua_consolelib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index e839d4e15..51e83d792 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -400,23 +400,23 @@ static int lib_cvRegisterVar(lua_State *L) { memmove(&cvpv[2], &cvpv[0], i * sizeof *cvpv); + i += 2; } cvpv[n].strvalue = MINMAX[n]; minmax_unset &= ~(1 << n); } else { - n = i; + n = i++; cvpv[n].strvalue = Z_StrDup(strval); } cvpv[n].value = (INT32)lua_tonumber(L, 6); - i++; lua_pop(L, 1); } - if (minmax_unset) + if (minmax_unset && minmax_unset != 3) FIELDERROR("PossibleValue", "custom PossibleValue table requires requires both MIN and MAX keys if one is present"); cvpv[i].value = 0; From 1a5f0d94f3379ed2c07e83190c140cd3246359bf Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Sat, 1 May 2021 14:05:01 -0400 Subject: [PATCH 15/91] Expose P_ThrustEvenIn2D and P_VectorInstaThrust --- src/p_user.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index c5f919c78..6a879c785 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -104,8 +104,7 @@ void P_Thrust(mobj_t *mo, angle_t angle, fixed_t move) mo->momy += FixedMul(move, FINESINE(angle)); } -#if 0 -static inline void P_ThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move) +void P_ThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move) { angle >>= ANGLETOFINESHIFT; @@ -113,7 +112,7 @@ static inline void P_ThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move) mo->momy += FixedMul(move, FINESINE(angle)); } -static inline void P_VectorInstaThrust(fixed_t xa, fixed_t xb, fixed_t xc, fixed_t ya, fixed_t yb, fixed_t yc, +void P_VectorInstaThrust(fixed_t xa, fixed_t xb, fixed_t xc, fixed_t ya, fixed_t yb, fixed_t yc, fixed_t za, fixed_t zb, fixed_t zc, fixed_t momentum, mobj_t *mo) { fixed_t a1, b1, c1, a2, b2, c2, i, j, k; @@ -143,7 +142,6 @@ static inline void P_VectorInstaThrust(fixed_t xa, fixed_t xb, fixed_t xc, fixed mo->momy = j; mo->momz = k; } -#endif // // P_InstaThrust From 47a2710ec292b551ce559813863611ef1805c3f7 Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Sat, 1 May 2021 14:05:07 -0400 Subject: [PATCH 16/91] Expose P_ThrustEvenIn2D, P_InstaThrustEvenIn2D, and P_VectorInstaThrust to Lua --- src/lua_baselib.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 4667fdbf4..64c5967b8 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1514,6 +1514,19 @@ static int lib_pInstaThrust(lua_State *L) return 0; } +static int lib_pInstaThrustEvenIn2D(lua_State *L) +{ + mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + angle_t angle = luaL_checkangle(L, 2); + fixed_t move = luaL_checkfixed(L, 3); + NOHUD + INLEVEL + if (!mo) + return LUA_ErrInvalid(L, "mobj_t"); + P_InstaThrustEvenIn2D(mo, angle, move); + return 0; +} + static int lib_pReturnThrustX(lua_State *L) { angle_t angle; @@ -2075,6 +2088,40 @@ static int lib_pThrust(lua_State *L) return 0; } +static int lib_pThrustEvenIn2D(lua_State *L) +{ + mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + angle_t angle = luaL_checkangle(L, 2); + fixed_t move = luaL_checkfixed(L, 3); + NOHUD + INLEVEL + if (!mo) + return LUA_ErrInvalid(L, "mobj_t"); + P_ThrustEvenIn2D(mo, angle, move); + return 0; +} + +static int lib_pVectorInstaThrust(lua_State *L) +{ + fixed_t xa = luaL_checkfixed(L, 1); + fixed_t xb = luaL_checkfixed(L, 2); + fixed_t xc = luaL_checkfixed(L, 3); + fixed_t ya = luaL_checkfixed(L, 4); + fixed_t yb = luaL_checkfixed(L, 5); + fixed_t yc = luaL_checkfixed(L, 6); + fixed_t za = luaL_checkfixed(L, 7); + fixed_t zb = luaL_checkfixed(L, 8); + fixed_t zc = luaL_checkfixed(L, 9); + fixed_t momentum = luaL_checkfixed(L, 10); + mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 11, META_MOBJ)); + NOHUD + INLEVEL + if (!mo) + return LUA_ErrInvalid(L, "mobj_t"); + P_VectorInstaThrust(xa, xb, xc, ya, yb, yc, za, zb, zc, momentum, mo); + return 0; +} + static int lib_pSetMobjStateNF(lua_State *L) { mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -3853,6 +3900,7 @@ static luaL_Reg lib[] = { {"P_DoPlayerFinish",lib_pDoPlayerFinish}, {"P_DoPlayerExit",lib_pDoPlayerExit}, {"P_InstaThrust",lib_pInstaThrust}, + {"P_InstaThrustEvenIn2D",lib_pInstaThrustEvenIn2D}, {"P_ReturnThrustX",lib_pReturnThrustX}, {"P_ReturnThrustY",lib_pReturnThrustY}, {"P_LookForEnemies",lib_pLookForEnemies}, @@ -3900,6 +3948,8 @@ static luaL_Reg lib[] = { // p_spec {"P_Thrust",lib_pThrust}, + {"P_ThrustEvenIn2D",lib_pThrustEvenIn2D}, + {"P_VectorInstaThrust",lib_pVectorInstaThrust}, {"P_SetMobjStateNF",lib_pSetMobjStateNF}, {"P_DoSuperTransformation",lib_pDoSuperTransformation}, {"P_ExplodeMissile",lib_pExplodeMissile}, From e16a8946807349c5b308e422aaf09a1f29b8252b Mon Sep 17 00:00:00 2001 From: Radicalicious Date: Sat, 1 May 2021 20:47:01 -0400 Subject: [PATCH 17/91] Actually define newly exposed thrust functions. Oops. --- src/p_local.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/p_local.h b/src/p_local.h index 8a5084962..ab6ef0177 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -527,6 +527,9 @@ boolean P_Teleport(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, angle_t angle boolean P_SetMobjStateNF(mobj_t *mobj, statenum_t state); boolean P_CheckMissileSpawn(mobj_t *th); void P_Thrust(mobj_t *mo, angle_t angle, fixed_t move); +void P_ThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move); +void P_VectorInstaThrust(fixed_t xa, fixed_t xb, fixed_t xc, fixed_t ya, fixed_t yb, fixed_t yc, + fixed_t za, fixed_t zb, fixed_t zc, fixed_t momentum, mobj_t *mo); void P_DoSuperTransformation(player_t *player, boolean giverings); void P_ExplodeMissile(mobj_t *mo); void P_CheckGravity(mobj_t *mo, boolean affect); From 701c1e26c481af0502f51e7285ef7302ccef74a6 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sat, 18 Jun 2022 23:35:22 -0500 Subject: [PATCH 18/91] Implement epicenter and radius support for quakes. --- src/p_tick.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/p_tick.c b/src/p_tick.c index 28ace9288..c8c927ae1 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -23,6 +23,7 @@ #include "lua_hook.h" #include "m_perfstats.h" #include "i_system.h" // I_GetPreciseTime +#include "r_main.h" // Object place #include "m_cheat.h" @@ -740,7 +741,22 @@ void P_Ticker(boolean run) if (quake.time) { fixed_t ir = quake.intensity>>1; - /// \todo Calculate distance from epicenter if set and modulate the intensity accordingly based on radius. + + if (quake.epicenter) { + // Calculate 3D distance from epicenter, using camera. + // Uses only player 1 camera because only one quake variable exists. + fixed_t xydist = R_PointToDist2(camera.x, camera.y, quake.epicenter->x, quake.epicenter->y); + fixed_t dist = R_PointToDist2(0, camera.z, xydist, quake.epicenter->z); + + CONS_Printf("%d\n", dist / FRACUNIT); + + // More effect closer to epicenter, outside of radius = no effect + if (!quake.radius || dist > quake.radius) + ir = 0; + else + ir = FixedMul(ir, FRACUNIT - FixedDiv(dist, quake.radius)); + } + quake.x = M_RandomRange(-ir,ir); quake.y = M_RandomRange(-ir,ir); quake.z = M_RandomRange(-ir,ir); From a546b553c42f14e1f0128b1e63cc9718b9f4477e Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sat, 18 Jun 2022 23:37:53 -0500 Subject: [PATCH 19/91] Oops, forgot to remove a debug print. --- src/p_tick.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index c8c927ae1..4915c5df2 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -748,8 +748,6 @@ void P_Ticker(boolean run) fixed_t xydist = R_PointToDist2(camera.x, camera.y, quake.epicenter->x, quake.epicenter->y); fixed_t dist = R_PointToDist2(0, camera.z, xydist, quake.epicenter->z); - CONS_Printf("%d\n", dist / FRACUNIT); - // More effect closer to epicenter, outside of radius = no effect if (!quake.radius || dist > quake.radius) ir = 0; From 90a93a516e8fe5658dc960277fab74f6232ed6d3 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 6 Sep 2022 18:42:12 -0500 Subject: [PATCH 20/91] Move quake calculation code to r_main.c, keep timer in p_tick.c --- src/p_tick.c | 22 ---------------------- src/r_main.c | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 4915c5df2..5430e651c 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -739,29 +739,7 @@ void P_Ticker(boolean run) countdown2--; if (quake.time) - { - fixed_t ir = quake.intensity>>1; - - if (quake.epicenter) { - // Calculate 3D distance from epicenter, using camera. - // Uses only player 1 camera because only one quake variable exists. - fixed_t xydist = R_PointToDist2(camera.x, camera.y, quake.epicenter->x, quake.epicenter->y); - fixed_t dist = R_PointToDist2(0, camera.z, xydist, quake.epicenter->z); - - // More effect closer to epicenter, outside of radius = no effect - if (!quake.radius || dist > quake.radius) - ir = 0; - else - ir = FixedMul(ir, FRACUNIT - FixedDiv(dist, quake.radius)); - } - - quake.x = M_RandomRange(-ir,ir); - quake.y = M_RandomRange(-ir,ir); - quake.z = M_RandomRange(-ir,ir); --quake.time; - } - else - quake.x = quake.y = quake.z = 0; if (metalplayback) G_ReadMetalTic(metalplayback); diff --git a/src/r_main.c b/src/r_main.c index f19962d41..f5992f98b 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1123,6 +1123,7 @@ void R_SetupFrame(player_t *player) { camera_t *thiscam; boolean chasecam = false; + boolean ispaused = paused || P_AutoPause(); if (splitscreen && player == &players[secondarydisplayplayer] && player != &players[consoleplayer]) @@ -1191,6 +1192,30 @@ void R_SetupFrame(player_t *player) } } } + + if (quake.time && !ispaused) + { + fixed_t ir = quake.intensity>>1; + + if (quake.epicenter) { + // Calculate 3D distance from epicenter, using the camera. + fixed_t xydist = R_PointToDist2(thiscam->x, thiscam->y, quake.epicenter->x, quake.epicenter->y); + fixed_t dist = R_PointToDist2(0, thiscam->z, xydist, quake.epicenter->z); + + // More effect closer to epicenter, outside of radius = no effect + if (!quake.radius || dist > quake.radius) + ir = 0; + else + ir = FixedMul(ir, FRACUNIT - FixedDiv(dist, quake.radius)); + } + + quake.x = M_RandomRange(-ir,ir); + quake.y = M_RandomRange(-ir,ir); + quake.z = M_RandomRange(-ir,ir); + } + else if (!ispaused) + quake.x = quake.y = quake.z = 0; + viewz += quake.z; viewplayer = player; From c907c20480719e908e3aa3d3fff65fb9eb4e9f43 Mon Sep 17 00:00:00 2001 From: spherallic Date: Wed, 5 Apr 2023 23:59:37 +0200 Subject: [PATCH 21/91] Do not apply pmomz when jumping through a platform --- src/p_map.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index a7d1f4abd..33d599a6c 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3065,11 +3065,14 @@ static boolean P_ThingHeightClip(mobj_t *thing) if (!rover || ((rover->fofflags & FOF_EXISTS) && (rover->fofflags & FOF_SOLID))) { hitfloor = bouncing; - if (thing->eflags & MFE_VERTICALFLIP) - thing->pmomz = thing->ceilingz - (thing->z + thing->height); - else - thing->pmomz = thing->floorz - thing->z; - thing->eflags |= MFE_APPLYPMOMZ; + if (!(thing->player) || !(thing->player->pflags & PF_JUMPED || bouncing)) + { + if (thing->eflags & MFE_VERTICALFLIP) + thing->pmomz = thing->ceilingz - (thing->z + thing->height); + else + thing->pmomz = thing->floorz - thing->z; + thing->eflags |= MFE_APPLYPMOMZ; + } if (thing->eflags & MFE_VERTICALFLIP) thing->z = thing->ceilingz - thing->height; From 39869b4492d133f044b970826e5ee74782d3854d Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 31 May 2023 22:21:31 -0500 Subject: [PATCH 22/91] Expose P_TouchSpecialThing --- src/lua_baselib.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769..8409a8377 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2195,6 +2195,19 @@ static int lib_pDoMatchSuper(lua_State *L) return 0; } +static int lib_pTouchSpecialThing(lua_State *L) +{ + mobj_t *special = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + mobj_t *toucher = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + boolean heightcheck = lua_optboolean(L, 3); + NOHUD + INLEVEL + if (!special || !toucher) + return LUA_ErrInvalid(L, "mobj_t"); + P_TouchSpecialThing(special, toucher, heightcheck); + return 0; +} + // P_SPEC //////////// @@ -4133,6 +4146,7 @@ static luaL_Reg lib[] = { {"P_FloorzAtPos",lib_pFloorzAtPos}, {"P_CeilingzAtPos",lib_pCeilingzAtPos}, {"P_DoSpring",lib_pDoSpring}, + {"P_TouchSpecialThing",lib_pTouchSpecialThing}, {"P_TryCameraMove", lib_pTryCameraMove}, {"P_TeleportCameraMove", lib_pTeleportCameraMove}, From 16e44e1b6e4b61cbe2c7516ceb6dd13d03e138bb Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 31 May 2023 22:28:53 -0500 Subject: [PATCH 23/91] Expose FollowMobj-related functions --- src/lua_baselib.c | 45 ++++++++++++++++++++++++++++++++++++++++++ src/p_local.h | 4 ++++ src/p_user.c | 50 +++++++++++++++++++++++++---------------------- 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769..7f64b7ddf 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1714,6 +1714,48 @@ static int lib_pSwitchShield(lua_State *L) return 0; } +static int lib_pDoTailsOverlay(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + mobj_t *tails = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + NOHUD + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + if (!tails) + return LUA_ErrInvalid(L, "mobj_t"); + P_DoTailsOverlay(player, tails); + return 0; +} + +static int lib_pDoMetalJetFume(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + mobj_t *fume = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + NOHUD + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + if (!fume) + return LUA_ErrInvalid(L, "mobj_t"); + P_DoMetalJetFume(player, fume); + return 0; +} + +static int lib_pDoFollowMobj(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + mobj_t *followmobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); + NOHUD + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + if (!followmobj) + return LUA_ErrInvalid(L, "mobj_t"); + P_DoFollowMobj(player, followmobj); + return 0; +} + static int lib_pPlayerCanEnterSpinGaps(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -4115,6 +4157,9 @@ static luaL_Reg lib[] = { {"P_SpawnSpinMobj",lib_pSpawnSpinMobj}, {"P_Telekinesis",lib_pTelekinesis}, {"P_SwitchShield",lib_pSwitchShield}, + {"P_DoTailsOverlay",lib_pDoTailsOverlay}, + {"P_DoMetalJetFume",lib_pDoMetalJetFume}, + {"P_DoFollowMobj",lib_pDoFollowMobj}, {"P_PlayerCanEnterSpinGaps",lib_pPlayerCanEnterSpinGaps}, {"P_PlayerShouldUseSpinHeight",lib_pPlayerShouldUseSpinHeight}, diff --git a/src/p_local.h b/src/p_local.h index cc060e4ee..776e9e122 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -213,6 +213,10 @@ void P_SpawnThokMobj(player_t *player); void P_SpawnSpinMobj(player_t *player, mobjtype_t type); void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range); +void P_DoTailsOverlay(player_t *player, mobj_t *tails); +void P_DoMetalJetFume(player_t *player, mobj_t *fume); +void P_DoFollowMobj(player_t *player, mobj_t *followmobj); + void P_PlayLivesJingle(player_t *player); #define P_PlayRinglossSound(s) S_StartSound(s, (mariomode) ? sfx_mario8 : sfx_altow1 + P_RandomKey(4)); #define P_PlayDeathSound(s) S_StartSound(s, sfx_altdi1 + P_RandomKey(4)); diff --git a/src/p_user.c b/src/p_user.c index 0f3282da5..253161c04 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11103,7 +11103,7 @@ static void P_MinecartThink(player_t *player) } // Handle Tails' fluff -static void P_DoTailsOverlay(player_t *player, mobj_t *tails) +void P_DoTailsOverlay(player_t *player, mobj_t *tails) { // init... boolean smilesonground = P_IsObjectOnGround(player->mo); @@ -11308,7 +11308,7 @@ static void P_DoTailsOverlay(player_t *player, mobj_t *tails) } // Metal Sonic's jet fume -static void P_DoMetalJetFume(player_t *player, mobj_t *fume) +void P_DoMetalJetFume(player_t *player, mobj_t *fume) { static const UINT8 FUME_SKINCOLORS[] = { @@ -11439,6 +11439,30 @@ static void P_DoMetalJetFume(player_t *player, mobj_t *fume) P_SpawnGhostMobj(fume); } +// Handle Followmobj behavior +void P_DoFollowMobj(player_t *player, mobj_t *followmobj) +{ + if (LUAh_FollowMobj(player, followmobj) || P_MobjWasRemoved(followmobj)) + {;} + else + { + switch (followmobj->type) + { + case MT_TAILSOVERLAY: // c: + P_DoTailsOverlay(player, followmobj); + break; + case MT_METALJETFUME: + P_DoMetalJetFume(player, followmobj); + break; + default: + var1 = 1; + var2 = 0; + A_CapeChase(followmobj); + break; + } + } +} + // // P_PlayerThink // @@ -12894,27 +12918,7 @@ void P_PlayerAfterThink(player_t *player) } if (player->followmobj) - { - if (LUA_HookFollowMobj(player, player->followmobj) || P_MobjWasRemoved(player->followmobj)) - {;} - else - { - switch (player->followmobj->type) - { - case MT_TAILSOVERLAY: // c: - P_DoTailsOverlay(player, player->followmobj); - break; - case MT_METALJETFUME: - P_DoMetalJetFume(player, player->followmobj); - break; - default: - var1 = 1; - var2 = 0; - A_CapeChase(player->followmobj); - break; - } - } - } + P_DoFollowMobj(player, player->followmobj); } P_DoPlayerHeadSigns(player); // Spawn Tag/CTF signs over player's head From 84438ff8376391fee0cfb160fb637a23102963e2 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 31 May 2023 22:39:08 -0500 Subject: [PATCH 24/91] Expose P_GivePlayerSpheres to Lua --- src/lua_baselib.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769..0ebb143ca 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1422,6 +1422,18 @@ static int lib_pGivePlayerRings(lua_State *L) return 0; } +static int lib_pGivePlayerSpheres(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + INT32 num_spheres = (INT32)luaL_checkinteger(L, 2); + NOHUD + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + P_GivePlayerSpheres(player, num_spheres); + return 0; +} + static int lib_pGivePlayerLives(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -4091,6 +4103,7 @@ static luaL_Reg lib[] = { {"P_SpawnShieldOrb",lib_pSpawnShieldOrb}, {"P_SpawnGhostMobj",lib_pSpawnGhostMobj}, {"P_GivePlayerRings",lib_pGivePlayerRings}, + {"P_GivePlayerSpheres",lib_pGivePlayerSpheres}, {"P_GivePlayerLives",lib_pGivePlayerLives}, {"P_GiveCoopLives",lib_pGiveCoopLives}, {"P_ResetScore",lib_pResetScore}, From 34477133cc646e42441cde2679bb6ac580292e52 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 31 May 2023 22:49:30 -0500 Subject: [PATCH 25/91] Expose P_DoSpinDashDust to Lua --- src/lua_baselib.c | 12 ++++++++++++ src/p_local.h | 1 + src/p_user.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769..090c1c371 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1664,6 +1664,17 @@ static int lib_pDoJump(lua_State *L) return 0; } +static int lib_pDoSpinDashDust(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + NOHUD + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + P_DoSpinDashDust(player); + return 0; +} + static int lib_pSpawnThokMobj(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); @@ -4111,6 +4122,7 @@ static luaL_Reg lib[] = { {"P_HomingAttack",lib_pHomingAttack}, {"P_SuperReady",lib_pSuperReady}, {"P_DoJump",lib_pDoJump}, + {"P_DoSpinDashDust",lib_pDoSpinDashDust}, {"P_SpawnThokMobj",lib_pSpawnThokMobj}, {"P_SpawnSpinMobj",lib_pSpawnSpinMobj}, {"P_Telekinesis",lib_pTelekinesis}, diff --git a/src/p_local.h b/src/p_local.h index cc060e4ee..c07b7029b 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -203,6 +203,7 @@ void P_Earthquake(mobj_t *inflictor, mobj_t *source, fixed_t radius); boolean P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user boolean P_SuperReady(player_t *player); void P_DoJump(player_t *player, boolean soundandstate); +void P_DoSpinDashDust(player_t *player); #define P_AnalogMove(player) (P_ControlStyle(player) == CS_LMAOGALOG) boolean P_TransferToNextMare(player_t *player); UINT8 P_FindLowestMare(void); diff --git a/src/p_user.c b/src/p_user.c index 0f3282da5..22c2bd3a9 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4537,7 +4537,7 @@ void P_DoJump(player_t *player, boolean soundandstate) } } -static void P_DoSpinDashDust(player_t *player) +void P_DoSpinDashDust(player_t *player) { UINT32 i; mobj_t *particle; From 7a7cee7ca575246d2b01632977dd886484b589f3 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Wed, 31 May 2023 23:03:22 -0500 Subject: [PATCH 26/91] Expose P_CheckSkyHit to Lua --- src/lua_baselib.c | 15 +++++++++++++++ src/p_local.h | 1 + src/p_mobj.c | 21 +++++++++++---------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769..1a189fabd 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1030,6 +1030,20 @@ static int lib_pRailThinker(lua_State *L) return 1; } +static int lib_pCheckSkyHit(lua_State *L) +{ + mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + line_t *line = *((line_t **)luaL_checkudata(L, 2, META_LINE)); + //HUDSAFE + INLEVEL + if (!mobj) + return LUA_ErrInvalid(L, "mobj_t"); + if (!line) + return LUA_ErrInvalid(L, "line_t"); + lua_pushboolean(L, P_CheckSkyHit(mobj, line)); + return 1; +} + static int lib_pXYMovement(lua_State *L) { mobj_t *actor = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -4059,6 +4073,7 @@ static luaL_Reg lib[] = { {"P_CreateFloorSpriteSlope",lib_pCreateFloorSpriteSlope}, {"P_RemoveFloorSpriteSlope",lib_pRemoveFloorSpriteSlope}, {"P_RailThinker",lib_pRailThinker}, + {"P_CheckSkyHit",lib_pCheckSkyHit}, {"P_XYMovement",lib_pXYMovement}, {"P_RingXYMovement",lib_pRingXYMovement}, {"P_SceneryXYMovement",lib_pSceneryXYMovement}, diff --git a/src/p_local.h b/src/p_local.h index cc060e4ee..91634e803 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -297,6 +297,7 @@ void P_RunOverlays(void); void P_HandleMinecartSegments(mobj_t *mobj); void P_MobjThinker(mobj_t *mobj); boolean P_RailThinker(mobj_t *mobj); +boolean P_CheckSkyHit(mobj_t *mo, line_t *line); void P_PushableThinker(mobj_t *mobj); void P_SceneryThinker(mobj_t *mobj); diff --git a/src/p_mobj.c b/src/p_mobj.c index eeaf54776..fad4f7743 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1753,14 +1753,15 @@ bustupdone: // // P_CheckSkyHit // -static boolean P_CheckSkyHit(mobj_t *mo) +boolean P_CheckSkyHit(mobj_t *mo, line_t *line) { - if (ceilingline && ceilingline->backsector - && ceilingline->backsector->ceilingpic == skyflatnum - && ceilingline->frontsector - && ceilingline->frontsector->ceilingpic == skyflatnum - && (mo->z >= ceilingline->frontsector->ceilingheight - || mo->z >= ceilingline->backsector->ceilingheight)) + if (line && (line->special == 41 || + (line->backsector + && line->backsector->ceilingpic == skyflatnum + && line->frontsector + && line->frontsector->ceilingpic == skyflatnum + && (mo->z >= line->frontsector->ceilingheight + || mo->z >= line->backsector->ceilingheight)))) return true; return false; } @@ -1867,7 +1868,7 @@ void P_XYMovement(mobj_t *mo) mo->fuse += ((5 - mo->threshold) * TICRATE); // Check for hit against sky here - if (P_CheckSkyHit(mo)) + if (P_CheckSkyHit(mo, ceilingline)) { // Hack to prevent missiles exploding // against the sky. @@ -1887,7 +1888,7 @@ void P_XYMovement(mobj_t *mo) mo->flags &= ~MF_STICKY; //Don't check again! // Check for hit against sky here - if (P_CheckSkyHit(mo)) + if (P_CheckSkyHit(mo, ceilingline)) { // Hack to prevent missiles exploding // against the sky. @@ -1946,7 +1947,7 @@ void P_XYMovement(mobj_t *mo) else if (mo->flags & MF_MISSILE) { // explode a missile - if (P_CheckSkyHit(mo)) + if (P_CheckSkyHit(mo, ceilingline)) { // Hack to prevent missiles exploding // against the sky. From 8919b35b936b365730001e5d69ca050a75dc830f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Fri, 2 Jun 2023 22:19:30 +0200 Subject: [PATCH 27/91] Fix buffer overflow when linedef type 415 executes --- src/p_spec.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index aa04a723e..d91129610 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2613,7 +2613,15 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (lumpnum == LUMPERROR || W_LumpLength(lumpnum) == 0) CONS_Debug(DBG_SETUP, "Line type 415 Executor: script lump %s not found/not valid.\n", line->stringargs[0]); else - COM_BufInsertText(W_CacheLumpNum(lumpnum, PU_CACHE)); + { + void *lump = W_CacheLumpNum(lumpnum, PU_CACHE); + size_t len = W_LumpLength(lumpnum); + char *text = Z_Malloc(len + 1, PU_CACHE, NULL); + memcpy(text, lump, len); + text[len] = '\0'; + COM_BufInsertText(text); + Z_Free(text); + } } break; From 826a70323ccabcdce551b2b0e8e786dcd525f1d7 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:04:01 -0500 Subject: [PATCH 28/91] LUA_HookFollowMobj instead of LUAh_FollowMobj --- 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 253161c04..2200185ac 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -11442,7 +11442,7 @@ void P_DoMetalJetFume(player_t *player, mobj_t *fume) // Handle Followmobj behavior void P_DoFollowMobj(player_t *player, mobj_t *followmobj) { - if (LUAh_FollowMobj(player, followmobj) || P_MobjWasRemoved(followmobj)) + if (LUA_HookFollowMobj(player, followmobj) || P_MobjWasRemoved(followmobj)) {;} else { From 2647b108406258aac6fcf8bf522cb2be8b68305c Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Sat, 1 Jul 2023 22:24:11 -0500 Subject: [PATCH 29/91] Require valid toucher.player --- src/lua_baselib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 8409a8377..1f8baedc2 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2204,6 +2204,8 @@ static int lib_pTouchSpecialThing(lua_State *L) INLEVEL if (!special || !toucher) return LUA_ErrInvalid(L, "mobj_t"); + if (!toucher->player) + return luaL_error(L, "P_TouchSpecialThing requires a valid toucher.player."); P_TouchSpecialThing(special, toucher, heightcheck); return 0; } From aaced79b41db8aea3e56b38ef3857aa836b3b6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Tue, 25 Jul 2023 16:37:20 +0200 Subject: [PATCH 30/91] Fix segfaults on some systems due to polyvertex being NULL --- src/hardware/hw_main.c | 96 +++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 36ff86abd..c650ecb51 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -582,10 +582,26 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); - x1 = ((polyvertex_t *)line->pv1)->x; - y1 = ((polyvertex_t *)line->pv1)->y; - xd = ((polyvertex_t *)line->pv2)->x - x1; - yd = ((polyvertex_t *)line->pv2)->y - y1; + 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; + } // 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; @@ -1068,10 +1084,26 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom gl_sidedef = gl_curline->sidedef; gl_linedef = gl_curline->linedef; - vs.x = ((polyvertex_t *)gl_curline->pv1)->x; - vs.y = ((polyvertex_t *)gl_curline->pv1)->y; - ve.x = ((polyvertex_t *)gl_curline->pv2)->x; - ve.y = ((polyvertex_t *)gl_curline->pv2)->y; + if (gl_curline->pv1) + { + vs.x = ((polyvertex_t *)gl_curline->pv1)->x; + vs.y = ((polyvertex_t *)gl_curline->pv1)->y; + } + else + { + vs.x = FIXED_TO_FLOAT(gl_curline->v1->x); + vs.y = FIXED_TO_FLOAT(gl_curline->v1->y); + } + if (gl_curline->pv2) + { + ve.x = ((polyvertex_t *)gl_curline->pv2)->x; + ve.y = ((polyvertex_t *)gl_curline->pv2)->y; + } + else + { + ve.x = FIXED_TO_FLOAT(gl_curline->v2->x); + ve.y = FIXED_TO_FLOAT(gl_curline->v2->y); + } v1x = FLOAT_TO_FIXED(vs.x); v1y = FLOAT_TO_FIXED(vs.y); @@ -1866,10 +1898,26 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (afrontsector->f_slope || afrontsector->c_slope || abacksector->f_slope || abacksector->c_slope) { fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y); + if (gl_curline->pv1) + { + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y); + } + else + { + v1x = gl_curline->v1->x; + v1y = gl_curline->v1->y; + } + if (gl_curline->pv2) + { + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y); + } + else + { + v2x = gl_curline->v2->x; + v2y = gl_curline->v2->y; + } #define SLOPEPARAMS(slope, end1, end2, normalheight) \ end1 = P_GetZAt(slope, v1x, v1y, normalheight); \ end2 = P_GetZAt(slope, v2x, v2y, normalheight); @@ -2242,10 +2290,26 @@ static void HWR_AddLine(seg_t * line) gl_curline = line; - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y); + if (gl_curline->pv1) + { + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv1)->y); + } + else + { + v1x = gl_curline->v1->x; + v1y = gl_curline->v1->y; + } + if (gl_curline->pv2) + { + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gl_curline->pv2)->y); + } + else + { + v2x = gl_curline->v2->x; + v2y = gl_curline->v2->y; + } // OPTIMIZE: quickly reject orthogonal back sides. angle1 = R_PointToAngle64(v1x, v1y); From 4ea2887d7fa41cd753b46b05de6920b9d84d3fbc Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 00:31:51 -0300 Subject: [PATCH 31/91] Lua colorlib: extracolormap support --- src/CMakeLists.txt | 1 + src/lua_baselib.c | 22 +++ src/lua_colorlib.c | 335 +++++++++++++++++++++++++++++++++++++++++++++ src/lua_libs.h | 2 + src/lua_maplib.c | 5 + src/lua_script.c | 1 + src/m_misc.c | 14 ++ src/m_misc.h | 3 + src/p_local.h | 4 + src/p_map.c | 32 +++++ src/r_data.c | 55 ++++---- src/r_data.h | 1 + src/r_things.c | 42 +----- 13 files changed, 457 insertions(+), 60 deletions(-) create mode 100644 src/lua_colorlib.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b926b3b7a..92cc11637 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -105,6 +105,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 lua_blockmaplib.c lua_hudlib.c lua_hudlib_drawlist.c + lua_colorlib.c lua_inputlib.c ) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 915669bb2..ecebae4ac 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -213,6 +213,7 @@ static const struct { {META_HUDINFO, "hudinfo_t"}, {META_PATCH, "patch_t"}, {META_COLORMAP, "colormap"}, + {META_EXTRACOLORMAP,"extracolormap_t"}, {META_CAMERA, "camera_t"}, {META_ACTION, "action"}, @@ -1928,6 +1929,26 @@ static int lib_pCeilingzAtPos(lua_State *L) return 1; } +static int lib_pGetSectorColormapAt(lua_State *L) +{ + sector_t *sector = NULL; + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); + fixed_t x = luaL_checkfixed(L, 2); + fixed_t y = luaL_checkfixed(L, 3); + fixed_t z = luaL_checkfixed(L, 4); + INLEVEL + if (!sector) + return LUA_ErrInvalid(L, "sector_t"); + extracolormap_t *exc; + if (sector) + exc = P_GetColormapFromSectorAt(sector, x, y, z); + else + exc = P_GetSectorColormapAt(x, y, z); + LUA_PushUserdata(L, exc, META_EXTRACOLORMAP); + return 1; +} + static int lib_pDoSpring(lua_State *L) { mobj_t *spring = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -4151,6 +4172,7 @@ static luaL_Reg lib[] = { {"P_RadiusAttack",lib_pRadiusAttack}, {"P_FloorzAtPos",lib_pFloorzAtPos}, {"P_CeilingzAtPos",lib_pCeilingzAtPos}, + {"P_GetSectorColormapAt",lib_pGetSectorColormapAt}, {"P_DoSpring",lib_pDoSpring}, {"P_TryCameraMove", lib_pTryCameraMove}, {"P_TeleportCameraMove", lib_pTeleportCameraMove}, diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c new file mode 100644 index 000000000..ee7074e84 --- /dev/null +++ b/src/lua_colorlib.c @@ -0,0 +1,335 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2021-2022 by "Lactozilla". +// Copyright (C) 2014-2023 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file lua_colorlib.c +/// \brief color and colormap libraries for Lua scripting + +#include "doomdef.h" +#include "fastcmp.h" +#include "r_data.h" + +#include "lua_script.h" +#include "lua_libs.h" + +static UINT8 GetRGBAColorsFromTable(lua_State *L, UINT32 index, UINT8 *rgba, boolean useAlpha) +{ + UINT8 num = 0; + + lua_pushnil(L); + + while (lua_next(L, index)) { + lua_Integer i = 0; + const char *field = NULL; + if (lua_isnumber(L, -2)) + i = lua_tointeger(L, -2); + else + field = luaL_checkstring(L, -2); + +#define CHECKFIELD(p, c) (i == p || (field && fastcmp(field, c))) +#define RGBASET(p, c) { \ + INT32 color = luaL_checkinteger(L, -1); \ + if (color < 0 || color > 255) \ + luaL_error(L, c " channel %d out of range (0 - 255)", color); \ + rgba[p] = (UINT8)color; \ + num++; \ + } + + if (CHECKFIELD(1, "r")) { + RGBASET(0, "red color"); + } else if (CHECKFIELD(2, "g")) { + RGBASET(1, "green color"); + } else if (CHECKFIELD(3, "b")) { + RGBASET(2, "blue color"); + } else if (useAlpha && CHECKFIELD(4, "a")) { + RGBASET(3, "alpha"); + } + +#undef CHECKFIELD +#undef RGBASET + + lua_pop(L, 1); + } + + return num; +} + +#define IS_HEX_CHAR(x) ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F')) +#define ARE_HEX_CHARS(str, i) IS_HEX_CHAR(str[i]) && IS_HEX_CHAR(str[i + 1]) + +static UINT32 hex2int(char x) +{ + if (x >= '0' && x <= '9') + return x - '0'; + else if (x >= 'a' && x <= 'f') + return x - 'a' + 10; + else if (x >= 'A' && x <= 'F') + return x - 'A' + 10; + + return 0; +} + +static UINT8 ParseHTMLColor(const char *str, UINT8 *rgba, size_t numc) +{ + const char *hex = str; + + if (hex[0] == '#') + hex++; + else if (!IS_HEX_CHAR(hex[0])) + return 0; + + size_t len = strlen(hex); + + if (len == 3) + { + // Shorthand like #09C + for (unsigned i = 0; i < 3; i++) + { + if (!IS_HEX_CHAR(hex[i])) + return 0; + + UINT32 hx = hex2int(hex[i]); + *rgba++ = (hx * 16) + hx; + } + + return 3; + } + else if (len == 6 || len == 8) + { + if (numc != 4) + len = 6; + + // A triplet like #0099CC + for (unsigned i = 0; i < len; i += 2) + { + if (!ARE_HEX_CHARS(hex, i)) + return false; + + *rgba++ = (hex2int(hex[i]) * 16) + hex2int(hex[i + 1]); + } + + return len; + } + + return 0; +} + +///////////////////////// +// extracolormap userdata +///////////////////////// + +enum extracolormap_e { + extracolormap_r = 0, + extracolormap_g, + extracolormap_b, + extracolormap_a, + extracolormap_rgba, + extracolormap_fade_r, + extracolormap_fade_g, + extracolormap_fade_b, + extracolormap_fade_a, + extracolormap_fade_rgba, + extracolormap_fade_start, + extracolormap_fade_end, + extracolormap_colormap +}; + +static const char *const extracolormap_opt[] = { + "r", + "g", + "b", + "a", + "rgba", + "fade_r", + "fade_g", + "fade_b", + "fade_a", + "fade_rgba", + "fade_start", + "fade_end", + "colormap", + NULL}; + +#define ALPHA_SCALE_FACTOR 102 // (255 / 25) * 10 +#define SCALE_ALPHA_UP(alpha) (((alpha) * ALPHA_SCALE_FACTOR) / 10) +#define SCALE_ALPHA_DOWN(alpha) (((alpha) * 10) / ALPHA_SCALE_FACTOR) + +static int extracolormap_get(lua_State *L) +{ + extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP)); + enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt); + + switch (field) + { + case extracolormap_r: + lua_pushinteger(L, R_GetRgbaR(exc->rgba)); + break; + case extracolormap_g: + lua_pushinteger(L, R_GetRgbaG(exc->rgba)); + break; + case extracolormap_b: + lua_pushinteger(L, R_GetRgbaB(exc->rgba)); + break; + case extracolormap_a: + lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->rgba))); + break; + case extracolormap_rgba: + lua_pushinteger(L, R_GetRgbaR(exc->rgba)); + lua_pushinteger(L, R_GetRgbaG(exc->rgba)); + lua_pushinteger(L, R_GetRgbaB(exc->rgba)); + lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->rgba))); + return 4; + case extracolormap_fade_r: + lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); + break; + case extracolormap_fade_g: + lua_pushinteger(L, R_GetRgbaG(exc->fadergba)); + break; + case extracolormap_fade_b: + lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); + break; + case extracolormap_fade_a: + lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->fadergba))); + break; + case extracolormap_fade_rgba: + lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); + lua_pushinteger(L, R_GetRgbaG(exc->fadergba)); + lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); + lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->fadergba))); + return 4; + case extracolormap_fade_start: + lua_pushinteger(L, exc->fadestart); + break; + case extracolormap_fade_end: + lua_pushinteger(L, exc->fadeend); + break; + case extracolormap_colormap: + LUA_PushUserdata(L, exc->colormap, META_COLORMAP); + break; + } + return 1; +} + +static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba) +{ + rgba[3] = SCALE_ALPHA_UP(rgba[3]); + + if (lua_type(L, 3) == LUA_TSTRING) + { + const char *str = lua_tostring(L, 3); + UINT8 parsed = ParseHTMLColor(str, rgba, 4); + if (!parsed) + luaL_error(L, "Malformed HTML color '%s'", str); + } + else + GetRGBAColorsFromTable(L, 3, rgba, true); + + rgba[3] = SCALE_ALPHA_DOWN(rgba[3]); +} + +static int extracolormap_set(lua_State *L) +{ + extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP)); + enum extracolormap_e field = luaL_checkoption(L, 2, NULL, extracolormap_opt); + + UINT8 r = R_GetRgbaR(exc->rgba); + UINT8 g = R_GetRgbaG(exc->rgba); + UINT8 b = R_GetRgbaB(exc->rgba); + UINT8 a = R_GetRgbaA(exc->rgba); + + UINT8 fr = R_GetRgbaR(exc->fadergba); + UINT8 fg = R_GetRgbaG(exc->fadergba); + UINT8 fb = R_GetRgbaB(exc->fadergba); + UINT8 fa = R_GetRgbaA(exc->fadergba); + + UINT8 rgba[4]; + + INT32 old_rgba = exc->rgba, old_fade_rgba = exc->fadergba; // It's not unsigned? + UINT8 old_fade_start = exc->fadestart, old_fade_end = exc->fadeend; + +#define val luaL_checkinteger(L, 3) + + switch(field) + { + case extracolormap_r: + exc->rgba = R_PutRgbaRGBA(val, g, b, a); + break; + case extracolormap_g: + exc->rgba = R_PutRgbaRGBA(r, val, b, a); + break; + case extracolormap_b: + exc->rgba = R_PutRgbaRGBA(r, g, val, a); + break; + case extracolormap_a: + exc->rgba = R_PutRgbaRGBA(r, g, b, SCALE_ALPHA_DOWN(val)); + break; + case extracolormap_rgba: + rgba[0] = r; + rgba[1] = g; + rgba[2] = b; + rgba[3] = a; + GetExtraColormapRGBA(L, rgba); + exc->rgba = R_PutRgbaRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); + break; + case extracolormap_fade_r: + exc->fadergba = R_PutRgbaRGBA(val, fg, fb, fa); + break; + case extracolormap_fade_g: + exc->fadergba = R_PutRgbaRGBA(fr, val, fb, fa); + break; + case extracolormap_fade_b: + exc->fadergba = R_PutRgbaRGBA(fr, fg, val, fa); + break; + case extracolormap_fade_a: + exc->fadergba = R_PutRgbaRGBA(fr, fg, fb, SCALE_ALPHA_DOWN(val)); + break; + case extracolormap_fade_rgba: + rgba[0] = fr; + rgba[1] = fg; + rgba[2] = fb; + rgba[3] = fa; + GetExtraColormapRGBA(L, rgba); + exc->fadergba = R_PutRgbaRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); + break; + case extracolormap_fade_start: + if (val > 31) + return luaL_error(L, "fade start %d out of range (0 - 31)", val); + exc->fadestart = val; + break; + case extracolormap_fade_end: + if (val > 31) + return luaL_error(L, "fade end %d out of range (0 - 31)", val); + exc->fadeend = val; + break; + case extracolormap_colormap: + return luaL_error(L, LUA_QL("extracolormap_t") " field " LUA_QS " should not be set directly.", extracolormap_opt[field]); + } + +#undef val + + if (exc->rgba != old_rgba + || exc->fadergba != old_fade_rgba + || exc->fadestart != old_fade_start + || exc->fadeend != old_fade_end) + R_GenerateLightTable(exc, true); + + return 0; +} + +int LUA_ColorLib(lua_State *L) +{ + luaL_newmetatable(L, META_EXTRACOLORMAP); + lua_pushcfunction(L, extracolormap_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, extracolormap_set); + lua_setfield(L, -2, "__newindex"); + lua_pop(L, 1); + + return 0; +} diff --git a/src/lua_libs.h b/src/lua_libs.h index 7f8d21f38..b520bb983 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -84,6 +84,7 @@ extern boolean mousegrabbedbylua; #define META_HUDINFO "HUDINFO_T*" #define META_PATCH "PATCH_T*" #define META_COLORMAP "COLORMAP" +#define META_EXTRACOLORMAP "EXTRACOLORMAP_T" #define META_CAMERA "CAMERA_T*" #define META_ACTION "ACTIONF_T*" @@ -111,4 +112,5 @@ int LUA_TagLib(lua_State *L); int LUA_PolyObjLib(lua_State *L); int LUA_BlockmapLib(lua_State *L); int LUA_HudLib(lua_State *L); +int LUA_ColorLib(lua_State *L); int LUA_InputLib(lua_State *L); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 3d95cdb75..440d1fce4 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -57,6 +57,7 @@ enum sector_e { sector_ffloors, sector_fslope, sector_cslope, + sector_extracolormap, sector_flags, sector_specialflags, sector_damagetype, @@ -95,6 +96,7 @@ static const char *const sector_opt[] = { "ffloors", "f_slope", "c_slope", + "extracolormap", "flags", "specialflags", "damagetype", @@ -751,6 +753,9 @@ static int sector_get(lua_State *L) case sector_cslope: // c_slope LUA_PushUserdata(L, sector->c_slope, META_SLOPE); return 1; + case sector_extracolormap: // extra_colormap + LUA_PushUserdata(L, sector->extra_colormap, META_EXTRACOLORMAP); + return 1; case sector_flags: // flags lua_pushinteger(L, sector->flags); return 1; diff --git a/src/lua_script.c b/src/lua_script.c index 6a5982006..8b081c587 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -58,6 +58,7 @@ static lua_CFunction liblist[] = { LUA_PolyObjLib, // polyobj_t LUA_BlockmapLib, // blockmap stuff LUA_HudLib, // HUD stuff + LUA_ColorLib, // general color functions LUA_InputLib, // inputs NULL }; diff --git a/src/m_misc.c b/src/m_misc.c index f547f5c41..68bc52055 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -2805,3 +2805,17 @@ boolean M_IsStringEmpty(const char *s) return true; } + +// Rounds off floating numbers and checks for 0 - 255 bounds +int M_RoundUp(double number) +{ + if (number > 255.0l) + return 255; + if (number < 0.0l) + return 0; + + if ((int)number <= (int)(number - 0.5f)) + return (int)number + 1; + + return (int)number; +} diff --git a/src/m_misc.h b/src/m_misc.h index 8cad7ba9a..753991e70 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -112,6 +112,9 @@ boolean M_IsStringEmpty(const char *s); // counting bits, for weapon ammo code, usually FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size); +// Rounds off floating numbers and checks for 0 - 255 bounds +int M_RoundUp(double number); + #include "w_wad.h" extern char configfile[MAX_WADPATH]; diff --git a/src/p_local.h b/src/p_local.h index 563e257d8..7110d3494 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -438,6 +438,10 @@ boolean PIT_PushableMoved(mobj_t *thing); boolean P_DoSpring(mobj_t *spring, mobj_t *object); +INT32 P_GetSectorLightAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z); +extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z); +extracolormap_t *P_GetSectorColormapAt(fixed_t x, fixed_t y, fixed_t z); + // // P_SETUP // diff --git a/src/p_map.c b/src/p_map.c index 132a3cf85..9ffe238e9 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -5067,3 +5067,35 @@ fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) return ceilingz; } + +INT32 P_GetSectorLightAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z) +{ + if (!sector->numlights) + return -1; + + INT32 light = sector->numlights - 1; + + // R_GetPlaneLight won't work on sloped lights! + for (INT32 lightnum = 1; lightnum < sector->numlights; lightnum++) { + fixed_t h = P_GetLightZAt(§or->lightlist[lightnum], x, y); + if (h <= z) { + light = lightnum - 1; + break; + } + } + + return light; +} + +extracolormap_t *P_GetColormapFromSectorAt(sector_t *sector, fixed_t x, fixed_t y, fixed_t z) +{ + if (sector->numlights) + return *sector->lightlist[P_GetSectorLightAt(sector, x, y, z)].extra_colormap; + else + return sector->extra_colormap; +} + +extracolormap_t *P_GetSectorColormapAt(fixed_t x, fixed_t y, fixed_t z) +{ + return P_GetColormapFromSectorAt(R_PointInSubsector(x, y)->sector, x, y, z); +} diff --git a/src/r_data.c b/src/r_data.c index 4b7492f90..1795e7727 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -692,9 +692,26 @@ extracolormap_t *R_ColormapForName(char *name) // static double deltas[256][3], map[256][3]; -static int RoundUp(double number); +static colorlookup_t lighttable_lut; + +static UINT8 LightTableNearest(UINT8 r, UINT8 g, UINT8 b) +{ + return NearestColor(r, g, b); +} + +static UINT8 LightTableNearest_LUT(UINT8 r, UINT8 g, UINT8 b) +{ + return GetColorLUT(&lighttable_lut, r, g, b); +} lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) +{ + extra_colormap->colormap = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8); + R_GenerateLightTable(extra_colormap, false); + return extra_colormap->colormap; +} + +void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; double maskamt = 0, othermask = 0; @@ -711,7 +728,6 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) UINT8 fadestart = extra_colormap->fadestart, fadedist = extra_colormap->fadeend - extra_colormap->fadestart; - lighttable_t *lighttable = NULL; size_t i; ///////////////////// @@ -753,6 +769,16 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) int p; char *colormap_p; + UINT8 (*NearestColorFunc)(UINT8, UINT8, UINT8); + + if (uselookup) + { + InitColorLUT(&lighttable_lut, pMasterPalette, false); + NearestColorFunc = LightTableNearest_LUT; + } + else + NearestColorFunc = LightTableNearest; + // Initialise the map and delta arrays // map[i] stores an RGB color (as double) for index i, // which is then converted to SRB2's palette later @@ -783,8 +809,7 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) // Now allocate memory for the actual colormap array itself! // aligned on 8 bit for asm code - colormap_p = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8); - lighttable = (UINT8 *)colormap_p; + colormap_p = (char *)extra_colormap->colormap; // Calculate the palette index for each palette index, for each light level // (as well as the two unused colormap lines we inherited from Doom) @@ -792,9 +817,9 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) { for (i = 0; i < 256; i++) { - *colormap_p = NearestColor((UINT8)RoundUp(map[i][0]), - (UINT8)RoundUp(map[i][1]), - (UINT8)RoundUp(map[i][2])); + *colormap_p = NearestColorFunc((UINT8)M_RoundUp(map[i][0]), + (UINT8)M_RoundUp(map[i][1]), + (UINT8)M_RoundUp(map[i][2])); colormap_p++; if ((UINT32)p < fadestart) @@ -818,8 +843,6 @@ lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap) } } } - - return lighttable; } extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) @@ -1133,20 +1156,6 @@ UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette) return (UINT8)bestcolor; } -// Rounds off floating numbers and checks for 0 - 255 bounds -static int RoundUp(double number) -{ - if (number > 255.0l) - return 255; - if (number < 0.0l) - return 0; - - if ((int)number <= (int)(number - 0.5f)) - return (int)number + 1; - - return (int)number; -} - #ifdef EXTRACOLORMAPLUMPS const char *R_NameForColormap(extracolormap_t *extra_colormap) { diff --git a/src/r_data.h b/src/r_data.h index ef5c967e5..364f85b6d 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -92,6 +92,7 @@ typedef enum TMCF_OVERRIDE = 1<<13, } textmapcolormapflags_t; +void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup); lighttable_t *R_CreateLightTable(extracolormap_t *extra_colormap); extracolormap_t * R_CreateColormapFromLinedef(char *p1, char *p2, char *p3); extracolormap_t* R_CreateColormap(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags); diff --git a/src/r_things.c b/src/r_things.c index 90b80dda8..a0b49072e 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1306,8 +1306,8 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, patch_t *patch; fixed_t xscale, yscale, shadowxscale, shadowyscale, shadowskew, x1, x2; INT32 heightsec, phs; - INT32 light = 0; - fixed_t scalemul; UINT8 trans; + fixed_t scalemul; + UINT8 trans; fixed_t floordiff; fixed_t groundz; pslope_t *groundslope; @@ -1425,27 +1425,7 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale, if (thing->renderflags & RF_NOCOLORMAPS) shadow->extra_colormap = NULL; else - { - if (thing->subsector->sector->numlights) - { - INT32 lightnum; - light = thing->subsector->sector->numlights - 1; - - // R_GetPlaneLight won't work on sloped lights! - for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) { - fixed_t h = P_GetLightZAt(&thing->subsector->sector->lightlist[lightnum], interp.x, interp.y); - if (h <= shadow->gzt) { - light = lightnum - 1; - break; - } - } - } - - if (thing->subsector->sector->numlights) - shadow->extra_colormap = *thing->subsector->sector->lightlist[light].extra_colormap; - else - shadow->extra_colormap = thing->subsector->sector->extra_colormap; - } + shadow->extra_colormap = P_GetColormapFromSectorAt(thing->subsector->sector, interp.x, interp.y, shadow->gzt); shadow->transmap = R_GetTranslucencyTable(trans + 1); shadow->colormap = scalelight[0][0]; // full dark! @@ -2132,21 +2112,9 @@ static void R_ProjectSprite(mobj_t *thing) if (thing->subsector->sector->numlights) { - INT32 lightnum; - fixed_t top = (splat) ? gz : gzt; - light = thing->subsector->sector->numlights - 1; - - // R_GetPlaneLight won't work on sloped lights! - for (lightnum = 1; lightnum < thing->subsector->sector->numlights; lightnum++) { - fixed_t h = P_GetLightZAt(&thing->subsector->sector->lightlist[lightnum], interp.x, interp.y); - if (h <= top) { - light = lightnum - 1; - break; - } - } - //light = R_GetPlaneLight(thing->subsector->sector, gzt, false); - lightnum = (*thing->subsector->sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT); + light = P_GetSectorLightAt(thing->subsector->sector, interp.x, interp.y, splat ? gz : gzt); + INT32 lightnum = (*thing->subsector->sector->lightlist[light].lightlevel >> LIGHTSEGSHIFT); if (lightnum < 0) spritelights = scalelight[0]; else if (lightnum >= LIGHTLEVELS) From b670f97ed1512655c7bd0463fc54b9f06106e40d Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 00:36:11 -0300 Subject: [PATCH 32/91] Add lighttable_t support --- src/lua_baselib.c | 1 + src/lua_colorlib.c | 33 ++++++++++++++++++++++++++++++++- src/lua_libs.h | 3 ++- src/r_defs.h | 3 +++ src/r_draw.c | 2 -- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index ecebae4ac..cdda48e8f 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -214,6 +214,7 @@ static const struct { {META_PATCH, "patch_t"}, {META_COLORMAP, "colormap"}, {META_EXTRACOLORMAP,"extracolormap_t"}, + {META_LIGHTTABLE, "lighttable_t"}, {META_CAMERA, "camera_t"}, {META_ACTION, "action"}, diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index ee7074e84..a963a6a6b 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -209,7 +209,7 @@ static int extracolormap_get(lua_State *L) lua_pushinteger(L, exc->fadeend); break; case extracolormap_colormap: - LUA_PushUserdata(L, exc->colormap, META_COLORMAP); + LUA_PushUserdata(L, exc->colormap, META_LIGHTTABLE); break; } return 1; @@ -321,6 +321,29 @@ static int extracolormap_set(lua_State *L) return 0; } +static int lighttable_get(lua_State *L) +{ + void **userdata; + + lighttable_t *table = *((lighttable_t **)luaL_checkudata(L, 1, META_LIGHTTABLE)); + UINT32 row = luaL_checkinteger(L, 2); + if (row < 1 || row > 34) + return luaL_error(L, "lighttable row %d out of range (1 - %d)", row, 34); + + userdata = lua_newuserdata(L, sizeof(void *)); + *userdata = &table[256 * (row - 1)]; + luaL_getmetatable(L, META_COLORMAP); + lua_setmetatable(L, -2); + + return 1; +} + +static int lighttable_len(lua_State *L) +{ + lua_pushinteger(L, NUM_PALETTE_ENTRIES); + return 1; +} + int LUA_ColorLib(lua_State *L) { luaL_newmetatable(L, META_EXTRACOLORMAP); @@ -331,5 +354,13 @@ int LUA_ColorLib(lua_State *L) lua_setfield(L, -2, "__newindex"); lua_pop(L, 1); + luaL_newmetatable(L, META_LIGHTTABLE); + lua_pushcfunction(L, lighttable_get); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lighttable_len); + lua_setfield(L, -2, "__len"); + lua_pop(L, 1); + return 0; } diff --git a/src/lua_libs.h b/src/lua_libs.h index b520bb983..65d5acb1b 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -84,7 +84,8 @@ extern boolean mousegrabbedbylua; #define META_HUDINFO "HUDINFO_T*" #define META_PATCH "PATCH_T*" #define META_COLORMAP "COLORMAP" -#define META_EXTRACOLORMAP "EXTRACOLORMAP_T" +#define META_EXTRACOLORMAP "EXTRACOLORMAP_T*" +#define META_LIGHTTABLE "LIGHTTABLE_T*" #define META_CAMERA "CAMERA_T*" #define META_ACTION "ACTIONF_T*" diff --git a/src/r_defs.h b/src/r_defs.h index a9b9a4a08..1edbba473 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -53,6 +53,9 @@ typedef struct // Could even use more than 32 levels. typedef UINT8 lighttable_t; +#define NUM_PALETTE_ENTRIES 256 +#define DEFAULT_STARTTRANSCOLOR 96 + #define CMF_FADEFULLBRIGHTSPRITES 1 #define CMF_FOG 4 diff --git a/src/r_draw.c b/src/r_draw.c index df9e1a460..671767b21 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -132,8 +132,6 @@ UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask; #define RAINBOW_TT_CACHE_INDEX (MAXSKINS + 4) #define BLINK_TT_CACHE_INDEX (MAXSKINS + 5) #define DASHMODE_TT_CACHE_INDEX (MAXSKINS + 6) -#define DEFAULT_STARTTRANSCOLOR 96 -#define NUM_PALETTE_ENTRIES 256 static UINT8 **translationtablecache[MAXSKINS + 7] = {NULL}; UINT8 skincolor_modified[MAXSKINCOLORS]; From ec8757d716e196d5d0f226a1fbfdef6827d287b5 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 05:00:46 -0300 Subject: [PATCH 33/91] Extend extracolormap alpha range --- src/hardware/hw_defs.h | 3 -- src/hardware/hw_main.c | 8 ++--- src/hardware/hw_md2.c | 3 -- src/hardware/r_opengl/r_opengl.c | 2 +- src/lua_colorlib.c | 20 ++++-------- src/r_data.c | 54 ++++++++++++++++---------------- 6 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 74c4ed7d2..b02f2824a 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -276,9 +276,6 @@ struct FSurfaceInfo }; typedef struct FSurfaceInfo FSurfaceInfo; -#define GL_DEFAULTMIX 0x00000000 -#define GL_DEFAULTFOG 0xFF000000 - //Hurdler: added for backward compatibility enum hwdsetspecialstate { diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 36ff86abd..568161425 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -186,8 +186,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col RGBA_t poly_color, tint_color, fade_color; poly_color.rgba = 0xFFFFFFFF; - tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; - fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : GL_DEFAULTFOG; + tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : 0x00000000; + fade_color.rgba = (colormap != NULL) ? (UINT32)colormap->fadergba : 0xFF000000; // Crappy backup coloring if you can't do shaders if (!HWR_UseShader()) @@ -201,7 +201,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col blue = (float)poly_color.s.blue; // 48 is just an arbritrary value that looked relatively okay. - tint_alpha = (float)(sqrt(tint_color.s.alpha) * 48) / 255.0f; + tint_alpha = (float)(sqrt((float)tint_color.s.alpha / 10.2) * 48) / 255.0f; // 8 is roughly the brightness of the "close" color in Software, and 16 the brightness of the "far" color. // 8 is too bright for dark levels, and 16 is too dark for bright levels. @@ -242,7 +242,7 @@ UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if RGBA_t realcolor, surfcolor; INT32 alpha; - realcolor.rgba = (colormap != NULL) ? colormap->rgba : GL_DEFAULTMIX; + realcolor.rgba = (colormap != NULL) ? colormap->rgba : 0x00000000; if (cv_glshaders.value && gl_shadersavailable) { diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index d005f0037..6d1f12664 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1140,9 +1140,6 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendpatch, INT32 ski Z_ChangeTag(newMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED); } -#define NORMALFOG 0x00000000 -#define FADEFOG 0x19000000 - static boolean HWR_AllowModel(mobj_t *mobj) { // Signpost overlay. Not needed. diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 71cb5ca70..6c0c90fc5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -697,7 +697,7 @@ static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; #define GLSL_SOFTWARE_TINT_EQUATION \ "if (tint_color.a > 0.0) {\n" \ "float color_bright = sqrt((base_color.r * base_color.r) + (base_color.g * base_color.g) + (base_color.b * base_color.b));\n" \ - "float strength = sqrt(9.0 * tint_color.a);\n" \ + "float strength = sqrt(tint_color.a);\n" \ "final_color.r = clamp((color_bright * (tint_color.r * strength)) + (base_color.r * (1.0 - strength)), 0.0, 1.0);\n" \ "final_color.g = clamp((color_bright * (tint_color.g * strength)) + (base_color.g * (1.0 - strength)), 0.0, 1.0);\n" \ "final_color.b = clamp((color_bright * (tint_color.b * strength)) + (base_color.b * (1.0 - strength)), 0.0, 1.0);\n" \ diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index a963a6a6b..1aed69836 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -155,10 +155,6 @@ static const char *const extracolormap_opt[] = { "colormap", NULL}; -#define ALPHA_SCALE_FACTOR 102 // (255 / 25) * 10 -#define SCALE_ALPHA_UP(alpha) (((alpha) * ALPHA_SCALE_FACTOR) / 10) -#define SCALE_ALPHA_DOWN(alpha) (((alpha) * 10) / ALPHA_SCALE_FACTOR) - static int extracolormap_get(lua_State *L) { extracolormap_t *exc = *((extracolormap_t **)luaL_checkudata(L, 1, META_EXTRACOLORMAP)); @@ -176,13 +172,13 @@ static int extracolormap_get(lua_State *L) lua_pushinteger(L, R_GetRgbaB(exc->rgba)); break; case extracolormap_a: - lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->rgba))); + lua_pushinteger(L, R_GetRgbaA(exc->rgba)); break; case extracolormap_rgba: lua_pushinteger(L, R_GetRgbaR(exc->rgba)); lua_pushinteger(L, R_GetRgbaG(exc->rgba)); lua_pushinteger(L, R_GetRgbaB(exc->rgba)); - lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->rgba))); + lua_pushinteger(L, R_GetRgbaA(exc->rgba)); return 4; case extracolormap_fade_r: lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); @@ -194,13 +190,13 @@ static int extracolormap_get(lua_State *L) lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); break; case extracolormap_fade_a: - lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->fadergba))); + lua_pushinteger(L, R_GetRgbaA(exc->fadergba)); break; case extracolormap_fade_rgba: lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); lua_pushinteger(L, R_GetRgbaG(exc->fadergba)); lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); - lua_pushinteger(L, SCALE_ALPHA_UP(R_GetRgbaA(exc->fadergba))); + lua_pushinteger(L, R_GetRgbaA(exc->fadergba)); return 4; case extracolormap_fade_start: lua_pushinteger(L, exc->fadestart); @@ -217,8 +213,6 @@ static int extracolormap_get(lua_State *L) static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba) { - rgba[3] = SCALE_ALPHA_UP(rgba[3]); - if (lua_type(L, 3) == LUA_TSTRING) { const char *str = lua_tostring(L, 3); @@ -228,8 +222,6 @@ static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba) } else GetRGBAColorsFromTable(L, 3, rgba, true); - - rgba[3] = SCALE_ALPHA_DOWN(rgba[3]); } static int extracolormap_set(lua_State *L) @@ -266,7 +258,7 @@ static int extracolormap_set(lua_State *L) exc->rgba = R_PutRgbaRGBA(r, g, val, a); break; case extracolormap_a: - exc->rgba = R_PutRgbaRGBA(r, g, b, SCALE_ALPHA_DOWN(val)); + exc->rgba = R_PutRgbaRGBA(r, g, b, val); break; case extracolormap_rgba: rgba[0] = r; @@ -286,7 +278,7 @@ static int extracolormap_set(lua_State *L) exc->fadergba = R_PutRgbaRGBA(fr, fg, val, fa); break; case extracolormap_fade_a: - exc->fadergba = R_PutRgbaRGBA(fr, fg, fb, SCALE_ALPHA_DOWN(val)); + exc->fadergba = R_PutRgbaRGBA(fr, fg, fb, val); break; case extracolormap_fade_rgba: rgba[0] = fr; diff --git a/src/r_data.c b/src/r_data.c index 1795e7727..e2b74da40 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -438,7 +438,7 @@ extracolormap_t *R_CreateDefaultColormap(boolean lighttable) exc->fadeend = 31; exc->flags = 0; exc->rgba = 0; - exc->fadergba = 0x19000000; + exc->fadergba = 0xFF000000; exc->colormap = lighttable ? R_CreateLightTable(exc) : NULL; #ifdef EXTRACOLORMAPLUMPS exc->lump = LUMPERROR; @@ -553,7 +553,7 @@ boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, && !flags) ) && (!checkrgba ? true : rgba == 0) - && (!checkfadergba ? true : fadergba == 0x19000000) + && (!checkfadergba ? true : (unsigned)fadergba == 0xFF000000) #ifdef EXTRACOLORMAPLUMPS && lump == LUMPERROR && extra_colormap->lumpname[0] == 0 @@ -654,7 +654,7 @@ extracolormap_t *R_ColormapForName(char *name) if (lump == LUMPERROR) I_Error("R_ColormapForName: Cannot find colormap lump %.8s\n", name); - exc = R_GetColormapFromListByValues(0, 0x19000000, 0, 31, 0, lump); + exc = R_GetColormapFromListByValues(0, 0xFF000000, 0, 31, 0, lump); if (exc) return exc; @@ -674,7 +674,7 @@ extracolormap_t *R_ColormapForName(char *name) exc->fadeend = 31; exc->flags = 0; exc->rgba = 0; - exc->fadergba = 0x19000000; + exc->fadergba = 0xFF000000; R_AddColormapToList(exc); @@ -737,7 +737,7 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup) cmaskg = cg; cmaskb = cb; - maskamt = (double)(ca/24.0l); + maskamt = (double)(ca/255.0l); othermask = 1 - maskamt; maskamt /= 0xff; @@ -753,7 +753,7 @@ void R_GenerateLightTable(extracolormap_t *extra_colormap, boolean uselookup) cdestb = cfb; // fade alpha unused in software - // maskamt = (double)(cfa/24.0l); + // maskamt = (double)(cfa/255.0l); // othermask = 1 - maskamt; // maskamt /= 0xff; @@ -851,7 +851,7 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) UINT8 cr = 0, cg = 0, cb = 0, ca = 0, cfr = 0, cfg = 0, cfb = 0, cfa = 25; UINT32 fadestart = 0, fadeend = 31; UINT8 flags = 0; - INT32 rgba = 0, fadergba = 0x19000000; + INT32 rgba = 0, fadergba = 0xFF000000; #define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0) #define ALPHA2INT(x) (x >= 'a' && x <= 'z' ? x - 'a' : x >= 'A' && x <= 'Z' ? x - 'A' : x >= '0' && x <= '9' ? 25 : 0) @@ -859,13 +859,13 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) // Get base colormap value // First alpha-only, then full value if (p1[0] >= 'a' && p1[0] <= 'z' && !p1[1]) - ca = (p1[0] - 'a'); + ca = ((p1[0] - 'a') * 102) / 10; else if (p1[0] == '#' && p1[1] >= 'a' && p1[1] <= 'z' && !p1[2]) - ca = (p1[1] - 'a'); + ca = ((p1[1] - 'a') * 102) / 10; else if (p1[0] >= 'A' && p1[0] <= 'Z' && !p1[1]) - ca = (p1[0] - 'A'); + ca = ((p1[0] - 'A') * 102) / 10; else if (p1[0] == '#' && p1[1] >= 'A' && p1[1] <= 'Z' && !p1[2]) - ca = (p1[1] - 'A'); + ca = ((p1[1] - 'A') * 102) / 10; else if (p1[0] == '#') { // For each subsequent value, the value before it must exist @@ -881,20 +881,20 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6])); if (p1[7] >= 'a' && p1[7] <= 'z') - ca = (p1[7] - 'a'); + ca = ((p1[7] - 'a') * 102) / 10; else if (p1[7] >= 'A' && p1[7] <= 'Z') - ca = (p1[7] - 'A'); + ca = ((p1[7] - 'A') * 102) / 10; else - ca = 25; + ca = 255; } else - ca = 25; + ca = 255; } else - ca = 25; + ca = 255; } else - ca = 25; + ca = 255; } #define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0) @@ -924,13 +924,13 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) // Get fade (dark) colormap value // First alpha-only, then full value if (p3[0] >= 'a' && p3[0] <= 'z' && !p3[1]) - cfa = (p3[0] - 'a'); + cfa = ((p3[0] - 'a') * 102) / 10; else if (p3[0] == '#' && p3[1] >= 'a' && p3[1] <= 'z' && !p3[2]) - cfa = (p3[1] - 'a'); + cfa = ((p3[1] - 'a') * 102) / 10; else if (p3[0] >= 'A' && p3[0] <= 'Z' && !p3[1]) - cfa = (p3[0] - 'A'); + cfa = ((p3[0] - 'A') * 102) / 10; else if (p3[0] == '#' && p3[1] >= 'A' && p3[1] <= 'Z' && !p3[2]) - cfa = (p3[1] - 'A'); + cfa = ((p3[1] - 'A') * 102) / 10; else if (p3[0] == '#') { // For each subsequent value, the value before it must exist @@ -946,20 +946,20 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) cfb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6])); if (p3[7] >= 'a' && p3[7] <= 'z') - cfa = (p3[7] - 'a'); + cfa = ((p3[7] - 'a') * 102) / 10; else if (p3[7] >= 'A' && p3[7] <= 'Z') - cfa = (p3[7] - 'A'); + cfa = ((p3[7] - 'A') * 102) / 10; else - cfa = 25; + cfa = 255; } else - cfa = 25; + cfa = 255; } else - cfa = 25; + cfa = 255; } else - cfa = 25; + cfa = 255; } #undef ALPHA2INT #undef HEX2INT From a48030d02dc6d26cfc8a6a145cdbfa4a625631ce Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 05:08:22 -0300 Subject: [PATCH 34/91] Support number as accepted value for "rgba" or "fade_rgba" fields --- src/lua_colorlib.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index 1aed69836..312b32571 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -220,8 +220,26 @@ static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba) if (!parsed) luaL_error(L, "Malformed HTML color '%s'", str); } - else + else if (lua_type(L, 3) == LUA_TTABLE) GetRGBAColorsFromTable(L, 3, rgba, true); + else + { + UINT32 colors = lua_tointeger(L, 3); + if (colors > 0xFFFFFF) + { + rgba[0] = (colors >> 24) & 0xFF; + rgba[1] = (colors >> 16) & 0xFF; + rgba[2] = (colors >> 8) & 0xFF; + rgba[3] = colors & 0xFF; + } + else + { + rgba[0] = (colors >> 16) & 0xFF; + rgba[1] = (colors >> 8) & 0xFF; + rgba[2] = colors & 0xFF; + rgba[3] = 0xFF; + } + } } static int extracolormap_set(lua_State *L) From 0e2b6a94234ac0fe01263b4ede5f77bff6119faa Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 05:13:56 -0300 Subject: [PATCH 35/91] Rename fields --- src/lua_colorlib.c | 83 ++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index 312b32571..f4a641744 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -124,32 +124,32 @@ static UINT8 ParseHTMLColor(const char *str, UINT8 *rgba, size_t numc) ///////////////////////// enum extracolormap_e { - extracolormap_r = 0, - extracolormap_g, - extracolormap_b, - extracolormap_a, - extracolormap_rgba, - extracolormap_fade_r, - extracolormap_fade_g, - extracolormap_fade_b, - extracolormap_fade_a, - extracolormap_fade_rgba, + extracolormap_red = 0, + extracolormap_green, + extracolormap_blue, + extracolormap_alpha, + extracolormap_color, + extracolormap_fade_red, + extracolormap_fade_green, + extracolormap_fade_blue, + extracolormap_fade_alpha, + extracolormap_fade_color, extracolormap_fade_start, extracolormap_fade_end, extracolormap_colormap }; static const char *const extracolormap_opt[] = { - "r", - "g", - "b", - "a", - "rgba", - "fade_r", - "fade_g", - "fade_b", - "fade_a", - "fade_rgba", + "red", + "green", + "blue", + "alpha", + "color", + "fade_red", + "fade_green", + "fade_blue", + "fade_alpha", + "fade_color", "fade_start", "fade_end", "colormap", @@ -162,37 +162,37 @@ static int extracolormap_get(lua_State *L) switch (field) { - case extracolormap_r: + case extracolormap_red: lua_pushinteger(L, R_GetRgbaR(exc->rgba)); break; - case extracolormap_g: + case extracolormap_green: lua_pushinteger(L, R_GetRgbaG(exc->rgba)); break; - case extracolormap_b: + case extracolormap_blue: lua_pushinteger(L, R_GetRgbaB(exc->rgba)); break; - case extracolormap_a: + case extracolormap_alpha: lua_pushinteger(L, R_GetRgbaA(exc->rgba)); break; - case extracolormap_rgba: + case extracolormap_color: lua_pushinteger(L, R_GetRgbaR(exc->rgba)); lua_pushinteger(L, R_GetRgbaG(exc->rgba)); lua_pushinteger(L, R_GetRgbaB(exc->rgba)); lua_pushinteger(L, R_GetRgbaA(exc->rgba)); return 4; - case extracolormap_fade_r: + case extracolormap_fade_red: lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); break; - case extracolormap_fade_g: + case extracolormap_fade_green: lua_pushinteger(L, R_GetRgbaG(exc->fadergba)); break; - case extracolormap_fade_b: + case extracolormap_fade_blue: lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); break; - case extracolormap_fade_a: + case extracolormap_fade_alpha: lua_pushinteger(L, R_GetRgbaA(exc->fadergba)); break; - case extracolormap_fade_rgba: + case extracolormap_fade_color: lua_pushinteger(L, R_GetRgbaR(exc->fadergba)); lua_pushinteger(L, R_GetRgbaG(exc->fadergba)); lua_pushinteger(L, R_GetRgbaB(exc->fadergba)); @@ -205,6 +205,9 @@ static int extracolormap_get(lua_State *L) lua_pushinteger(L, exc->fadeend); break; case extracolormap_colormap: + // I'm not sure if making the colormap available makes sense. + // It's a read-only field, only used by one of the renderers, and + // the only way to manipulate it is by modifying the other fields. LUA_PushUserdata(L, exc->colormap, META_LIGHTTABLE); break; } @@ -266,19 +269,19 @@ static int extracolormap_set(lua_State *L) switch(field) { - case extracolormap_r: + case extracolormap_red: exc->rgba = R_PutRgbaRGBA(val, g, b, a); break; - case extracolormap_g: + case extracolormap_green: exc->rgba = R_PutRgbaRGBA(r, val, b, a); break; - case extracolormap_b: + case extracolormap_blue: exc->rgba = R_PutRgbaRGBA(r, g, val, a); break; - case extracolormap_a: + case extracolormap_alpha: exc->rgba = R_PutRgbaRGBA(r, g, b, val); break; - case extracolormap_rgba: + case extracolormap_color: rgba[0] = r; rgba[1] = g; rgba[2] = b; @@ -286,19 +289,19 @@ static int extracolormap_set(lua_State *L) GetExtraColormapRGBA(L, rgba); exc->rgba = R_PutRgbaRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); break; - case extracolormap_fade_r: + case extracolormap_fade_red: exc->fadergba = R_PutRgbaRGBA(val, fg, fb, fa); break; - case extracolormap_fade_g: + case extracolormap_fade_green: exc->fadergba = R_PutRgbaRGBA(fr, val, fb, fa); break; - case extracolormap_fade_b: + case extracolormap_fade_blue: exc->fadergba = R_PutRgbaRGBA(fr, fg, val, fa); break; - case extracolormap_fade_a: + case extracolormap_fade_alpha: exc->fadergba = R_PutRgbaRGBA(fr, fg, fb, val); break; - case extracolormap_fade_rgba: + case extracolormap_fade_color: rgba[0] = fr; rgba[1] = fg; rgba[2] = fb; From a54d3a274a49297b22a8a3da95bd78a1914aa86c Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 4 Aug 2023 14:29:26 -0300 Subject: [PATCH 36/91] Remove assignment by table --- src/lua_colorlib.c | 59 +++++----------------------------------------- 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/src/lua_colorlib.c b/src/lua_colorlib.c index f4a641744..1e6e82333 100644 --- a/src/lua_colorlib.c +++ b/src/lua_colorlib.c @@ -17,48 +17,6 @@ #include "lua_script.h" #include "lua_libs.h" -static UINT8 GetRGBAColorsFromTable(lua_State *L, UINT32 index, UINT8 *rgba, boolean useAlpha) -{ - UINT8 num = 0; - - lua_pushnil(L); - - while (lua_next(L, index)) { - lua_Integer i = 0; - const char *field = NULL; - if (lua_isnumber(L, -2)) - i = lua_tointeger(L, -2); - else - field = luaL_checkstring(L, -2); - -#define CHECKFIELD(p, c) (i == p || (field && fastcmp(field, c))) -#define RGBASET(p, c) { \ - INT32 color = luaL_checkinteger(L, -1); \ - if (color < 0 || color > 255) \ - luaL_error(L, c " channel %d out of range (0 - 255)", color); \ - rgba[p] = (UINT8)color; \ - num++; \ - } - - if (CHECKFIELD(1, "r")) { - RGBASET(0, "red color"); - } else if (CHECKFIELD(2, "g")) { - RGBASET(1, "green color"); - } else if (CHECKFIELD(3, "b")) { - RGBASET(2, "blue color"); - } else if (useAlpha && CHECKFIELD(4, "a")) { - RGBASET(3, "alpha"); - } - -#undef CHECKFIELD -#undef RGBASET - - lua_pop(L, 1); - } - - return num; -} - #define IS_HEX_CHAR(x) ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F')) #define ARE_HEX_CHARS(str, i) IS_HEX_CHAR(str[i]) && IS_HEX_CHAR(str[i + 1]) @@ -205,29 +163,24 @@ static int extracolormap_get(lua_State *L) lua_pushinteger(L, exc->fadeend); break; case extracolormap_colormap: - // I'm not sure if making the colormap available makes sense. - // It's a read-only field, only used by one of the renderers, and - // the only way to manipulate it is by modifying the other fields. LUA_PushUserdata(L, exc->colormap, META_LIGHTTABLE); break; } return 1; } -static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba) +static void GetExtraColormapRGBA(lua_State *L, UINT8 *rgba, int arg) { - if (lua_type(L, 3) == LUA_TSTRING) + if (lua_type(L, arg) == LUA_TSTRING) { - const char *str = lua_tostring(L, 3); + const char *str = lua_tostring(L, arg); UINT8 parsed = ParseHTMLColor(str, rgba, 4); if (!parsed) luaL_error(L, "Malformed HTML color '%s'", str); } - else if (lua_type(L, 3) == LUA_TTABLE) - GetRGBAColorsFromTable(L, 3, rgba, true); else { - UINT32 colors = lua_tointeger(L, 3); + UINT32 colors = lua_tointeger(L, arg); if (colors > 0xFFFFFF) { rgba[0] = (colors >> 24) & 0xFF; @@ -286,7 +239,7 @@ static int extracolormap_set(lua_State *L) rgba[1] = g; rgba[2] = b; rgba[3] = a; - GetExtraColormapRGBA(L, rgba); + GetExtraColormapRGBA(L, rgba, 3); exc->rgba = R_PutRgbaRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); break; case extracolormap_fade_red: @@ -306,7 +259,7 @@ static int extracolormap_set(lua_State *L) rgba[1] = fg; rgba[2] = fb; rgba[3] = fa; - GetExtraColormapRGBA(L, rgba); + GetExtraColormapRGBA(L, rgba, 3); exc->fadergba = R_PutRgbaRGBA(rgba[0], rgba[1], rgba[2], rgba[3]); break; case extracolormap_fade_start: From 4f6da8dc0f6b96c214a9f7b190de4a181ee59a01 Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Sun, 10 Sep 2023 16:10:32 +0200 Subject: [PATCH 37/91] Fix a "maybe-uninitialized" compiler warning --- src/r_things.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index be9c5cdff..8fabb8027 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3201,8 +3201,8 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) INT16 sz = spr->sz; INT16 szt = spr->szt; - fixed_t texturemid, yscale, scalestep = spr->scalestep; - INT32 height; + fixed_t texturemid = 0, yscale = 0, scalestep = spr->scalestep; // "= 0" pleases the compiler + INT32 height = 0; if (scalestep) { From b53b2df7eeae7f3fe4f01418962495de6541a506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sun, 17 Sep 2023 22:44:47 +0200 Subject: [PATCH 38/91] Fix saturation option not being applied on OpenGL --- src/v_video.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 3f958b286..25da6af40 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1336,32 +1336,33 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) // This is now a function since it's otherwise repeated 2 times and honestly looks retarded: static UINT32 V_GetHWConsBackColor(void) { - UINT32 hwcolor; + UINT8 r, g, b; switch (cons_backcolor.value) { - case 0: hwcolor = 0xffffff00; break; // White - case 1: hwcolor = 0x80808000; break; // Black - case 2: hwcolor = 0xdeb88700; break; // Sepia - case 3: hwcolor = 0x40201000; break; // Brown - case 4: hwcolor = 0xfa807200; break; // Pink - case 5: hwcolor = 0xff69b400; break; // Raspberry - case 6: hwcolor = 0xff000000; break; // Red - case 7: hwcolor = 0xffd68300; break; // Creamsicle - case 8: hwcolor = 0xff800000; break; // Orange - case 9: hwcolor = 0xdaa52000; break; // Gold - case 10: hwcolor = 0x80800000; break; // Yellow - case 11: hwcolor = 0x00ff0000; break; // Emerald - case 12: hwcolor = 0x00800000; break; // Green - case 13: hwcolor = 0x4080ff00; break; // Cyan - case 14: hwcolor = 0x4682b400; break; // Steel - case 15: hwcolor = 0x1e90ff00; break; // Periwinkle - case 16: hwcolor = 0x0000ff00; break; // Blue - case 17: hwcolor = 0xff00ff00; break; // Purple - case 18: hwcolor = 0xee82ee00; break; // Lavender + case 0: r = 0xff; g = 0xff; b = 0xff; break; // White + case 1: r = 0x80; g = 0x80; b = 0x80; break; // Black + case 2: r = 0xde; g = 0xb8; b = 0x87; break; // Sepia + case 3: r = 0x40; g = 0x20; b = 0x10; break; // Brown + case 4: r = 0xfa; g = 0x80; b = 0x72; break; // Pink + case 5: r = 0xff; g = 0x69; b = 0xb4; break; // Raspberry + case 6: r = 0xff; g = 0x00; b = 0x00; break; // Red + case 7: r = 0xff; g = 0xd6; b = 0x83; break; // Creamsicle + case 8: r = 0xff; g = 0x80; b = 0x00; break; // Orange + case 9: r = 0xda; g = 0xa5; b = 0x20; break; // Gold + case 10: r = 0x80; g = 0x80; b = 0x00; break; // Yellow + case 11: r = 0x00; g = 0xff; b = 0x00; break; // Emerald + case 12: r = 0x00; g = 0x80; b = 0x00; break; // Green + case 13: r = 0x40; g = 0x80; b = 0xff; break; // Cyan + case 14: r = 0x46; g = 0x82; b = 0xb4; break; // Steel + case 15: r = 0x1e; g = 0x90; b = 0xff; break; // Periwinkle + case 16: r = 0x00; g = 0x00; b = 0xff; break; // Blue + case 17: r = 0xff; g = 0x00; b = 0xff; break; // Purple + case 18: r = 0xee; g = 0x82; b = 0xee; break; // Lavender // Default green - default: hwcolor = 0x00800000; break; + default: r = 0x00; g = 0x80; b = 0x00; break; } - return hwcolor; + V_CubeApply(&r, &g, &b); + return (r << 24) | (g << 16) | (b << 8); } #endif From fc205082956990dcfc40381976c4724ce8902e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Mon, 18 Sep 2023 18:16:10 +0200 Subject: [PATCH 39/91] Fix saturation not being applied on colormaps in OpenGL --- src/hardware/hw_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f2022bcea..78c0b1dab 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -229,6 +229,8 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col // Clamp the light level, since it can sometimes go out of the 0-255 range from animations light_level = min(max(light_level, 0), 255); + V_CubeApply(&tint_color.s.red, &tint_color.s.green, &tint_color.s.blue); + V_CubeApply(&fade_color.s.red, &fade_color.s.green, &fade_color.s.blue); Surface->PolyColor.rgba = poly_color.rgba; Surface->TintColor.rgba = tint_color.rgba; Surface->FadeColor.rgba = fade_color.rgba; From a8fe500d0e22beb37e7c734d74cfa2632199bbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Tue, 19 Sep 2023 19:05:43 +0200 Subject: [PATCH 40/91] Add auto-kick for inactive players --- src/netcode/d_clisrv.c | 35 +++++++++++++++++++++++++++++++++++ src/netcode/d_clisrv.h | 4 ++-- src/netcode/d_net.h | 1 + src/netcode/d_netcmd.c | 1 + src/netcode/protocol.h | 1 + 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index f06192f2c..efa251ff7 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -113,6 +113,7 @@ consvar_t cv_blamecfail = CVAR_INIT ("blamecfail", "Off", CV_SAVE|CV_NETVAR, CV_ static CV_PossibleValue_t playbackspeed_cons_t[] = {{1, "MIN"}, {10, "MAX"}, {0, NULL}}; consvar_t cv_playbackspeed = CVAR_INIT ("playbackspeed", "1", 0, playbackspeed_cons_t, NULL); +consvar_t cv_idletime = CVAR_INIT ("idletime", "0", CV_SAVE, CV_Unsigned, NULL); consvar_t cv_dedicatedidletime = CVAR_INIT ("dedicatedidletime", "10", CV_SAVE, CV_Unsigned, NULL); void ResetNode(INT32 node) @@ -492,6 +493,10 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) HU_AddChatText(va("\x82*%s has been banned (%s)", player_names[pnum], reason), false); kickreason = KR_BAN; break; + case KICK_MSG_IDLE: + HU_AddChatText(va("\x82*%s has left the game (Inactive for too long)", player_names[pnum]), false); + kickreason = KR_TIMEOUT; + break; } if (pnum == consoleplayer) @@ -507,6 +512,8 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) M_StartMessage(M_GetText("Server closed connection\n(synch failure)\nPress ESC\n"), NULL, MM_NOTHING); else if (msg == KICK_MSG_PING_HIGH) M_StartMessage(M_GetText("Server closed connection\n(Broke ping limit)\nPress ESC\n"), NULL, MM_NOTHING); + else if (msg == KICK_MSG_IDLE) + M_StartMessage(M_GetText("Server closed connection\n(Inactive for too long)\nPress ESC\n"), NULL, MM_NOTHING); else if (msg == KICK_MSG_BANNED) M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING); else if (msg == KICK_MSG_CUSTOM_KICK) @@ -1267,6 +1274,30 @@ static void UpdatePingTable(void) } } +static void IdleUpdate(void) +{ + INT32 i; + if (!server || !netgame) + return; + + for (i = 1; i < MAXPLAYERS; i++) + { + if (cv_idletime.value && playeringame[i] && playernode[i] != UINT8_MAX && !players[i].quittime && !players[i].spectator && i != serverplayer) + { + if (players[i].cmd.forwardmove || players[i].cmd.sidemove || players[i].cmd.buttons) + netnodes[i].lastinput = gametime; + + if (gametime - netnodes[i].lastinput > cv_idletime.value * TICRATE) + { + netnodes[i].lastinput = gametime; + SendKick(i, KICK_MSG_IDLE | KICK_MSG_KEEP_BODY); + } + } + else + netnodes[i].lastinput = gametime; + } +} + // Handle timeouts to prevent definitive freezes from happenning static void HandleNodeTimeouts(void) { @@ -1299,6 +1330,8 @@ void NetKeepAlive(void) GetPackets(); + IdleUpdate(); + #ifdef MASTERSERVER MasterClient_Ticker(); #endif @@ -1419,6 +1452,8 @@ void NetUpdate(void) GetPackets(); // get packet from client or from server + IdleUpdate(); + // The client sends the command after receiving from the server // The server sends it before because this is better in single player diff --git a/src/netcode/d_clisrv.h b/src/netcode/d_clisrv.h index d87ead9ec..db9a780cd 100644 --- a/src/netcode/d_clisrv.h +++ b/src/netcode/d_clisrv.h @@ -48,7 +48,7 @@ typedef enum KR_TIMEOUT = 4, //Connection Timeout KR_BAN = 5, //Banned by server KR_LEAVE = 6, //Quit the game - + KR_IDLE = 7, //Remained still for too long } kickreason_t; /* the max number of name changes in some time period */ @@ -73,7 +73,7 @@ extern UINT32 realpingtable[MAXPLAYERS]; extern UINT32 playerpingtable[MAXPLAYERS]; extern tic_t servermaxping; -extern consvar_t cv_netticbuffer, cv_resynchattempts, cv_blamecfail, cv_playbackspeed, cv_dedicatedidletime; +extern consvar_t cv_netticbuffer, cv_resynchattempts, cv_blamecfail, cv_playbackspeed, cv_idletime, cv_dedicatedidletime; // Used in d_net, the only dependence void D_ClientServerInit(void); diff --git a/src/netcode/d_net.h b/src/netcode/d_net.h index 549f2b93c..e8e3b5895 100644 --- a/src/netcode/d_net.h +++ b/src/netcode/d_net.h @@ -43,6 +43,7 @@ typedef struct netnode_s { boolean ingame; // set false as nodes leave game tic_t freezetimeout; // Until when can this node freeze the server before getting a timeout? + tic_t lastinput; // the last tic the player has made any input SINT8 player; SINT8 player2; // say the numplayer for this node if any (splitscreen) diff --git a/src/netcode/d_netcmd.c b/src/netcode/d_netcmd.c index 5afa95561..0cceac112 100644 --- a/src/netcode/d_netcmd.c +++ b/src/netcode/d_netcmd.c @@ -601,6 +601,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_showjoinaddress); CV_RegisterVar(&cv_blamecfail); CV_RegisterVar(&cv_dedicatedidletime); + CV_RegisterVar(&cv_idletime); COM_AddCommand("ping", Command_Ping_f, COM_LUA); CV_RegisterVar(&cv_nettimeout); diff --git a/src/netcode/protocol.h b/src/netcode/protocol.h index a992e3b69..c084d920c 100644 --- a/src/netcode/protocol.h +++ b/src/netcode/protocol.h @@ -331,6 +331,7 @@ typedef struct #define KICK_MSG_PING_HIGH 6 #define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_BAN 8 +#define KICK_MSG_IDLE 9 #define KICK_MSG_KEEP_BODY 0x80 #endif From 05926ceec8a87671696cc5cc617bb9d5bcec5d29 Mon Sep 17 00:00:00 2001 From: spherallic Date: Wed, 20 Sep 2023 15:42:19 +0200 Subject: [PATCH 41/91] Group NiGHTS star/chip hitboxes with rings --- src/r_bbox.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/r_bbox.c b/src/r_bbox.c index cf417ec37..5b2a817f1 100644 --- a/src/r_bbox.c +++ b/src/r_bbox.c @@ -267,18 +267,17 @@ static boolean is_tangible (mobj_t *thing) boolean R_ThingBoundingBoxVisible(mobj_t *thing) { INT32 cvmode = cv_renderhitbox.value; + boolean ring = false; if (multiplayer) // No hitboxes in multiplayer to avoid cheating return false; - // Do not render bbox for these switch (thing->type) { default: - // First person / awayviewmobj -- rendering - // a bbox too close to the viewpoint causes - // anomalies and these are exactly on the - // viewpoint! + // First person / awayviewmobj -- rendering a bbox + // too close to the viewpoint causes anomalies + // and these are exactly on the viewpoint! if (thing != r_viewmobj) { break; @@ -290,6 +289,16 @@ boolean R_ThingBoundingBoxVisible(mobj_t *thing) // are rendered using portals in Software, // r_viewmobj does not point here. return false; + + case MT_RING: + case MT_BLUESPHERE: + case MT_NIGHTSSTAR: + case MT_NIGHTSCHIP: + // Rings and similar objects are often placed + // in large amounts, so they are handled + // separately from other tangible objects. + ring = true; + break; } switch (cvmode) @@ -304,16 +313,10 @@ boolean R_ThingBoundingBoxVisible(mobj_t *thing) return !is_tangible(thing); case RENDERHITBOX_TANGIBLE: - // Exclude rings from here, lots of them! - if (thing->type == MT_RING) - { - return false; - } - - return is_tangible(thing); + return !ring && is_tangible(thing); case RENDERHITBOX_RINGS: - return (thing->type == MT_RING || thing->type == MT_BLUESPHERE); + return ring; default: return false; From 8fd9a82a19d49cae116ccbd0eb338c231eaa4cd3 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Thu, 21 Sep 2023 02:06:06 -0300 Subject: [PATCH 42/91] Raise sidedef limits Also, fixes reading of GL3 nodes to use 32-bit indices for line IDs. --- src/lua_maplib.c | 2 +- src/p_map.c | 2 +- src/p_maputl.c | 4 +- src/p_saveg.c | 29 ++++++------ src/p_setup.c | 121 ++++++++++++++++++++++++++--------------------- src/p_spec.c | 14 +++--- src/r_defs.h | 4 +- 7 files changed, 97 insertions(+), 79 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index e34397993..7302c727a 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1072,7 +1072,7 @@ static int line_get(lua_State *L) LUA_PushUserdata(L, &sides[line->sidenum[0]], META_SIDE); return 1; case line_backside: // backside - if (line->sidenum[1] == 0xffff) + if (line->sidenum[1] == NO_SIDEDEF) return 0; LUA_PushUserdata(L, &sides[line->sidenum[1]], META_SIDE); return 1; diff --git a/src/p_map.c b/src/p_map.c index 80135db74..e328dc9e6 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3900,7 +3900,7 @@ retry: P_PathTraverse(leadx, traily, leadx + mo->momx, traily + mo->momy, PT_ADDLINES, PTR_SlideTraverse); - if (bestslideline && mo->player && bestslideline->sidenum[1] != 0xffff) + if (bestslideline && mo->player && bestslideline->sidenum[1] != NO_SIDEDEF) { sector_t *sec = P_PointOnLineSide(mo->x, mo->y, bestslideline) ? bestslideline->frontsector : bestslideline->backsector; P_CheckLavaWall(mo, sec); diff --git a/src/p_maputl.c b/src/p_maputl.c index e36d5fd72..9c30d3ead 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -290,7 +290,7 @@ void P_CameraLineOpening(line_t *linedef) sector_t *back; fixed_t frontfloor, frontceiling, backfloor, backceiling; - if (linedef->sidenum[1] == 0xffff) + if (linedef->sidenum[1] == NO_SIDEDEF) { // single sided line openrange = 0; @@ -426,7 +426,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) { sector_t *front, *back; - if (linedef->sidenum[1] == 0xffff) + if (linedef->sidenum[1] == NO_SIDEDEF) { // single sided line openrange = 0; diff --git a/src/p_saveg.c b/src/p_saveg.c index faecd1377..3bcfea7cd 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1079,7 +1079,7 @@ static void ArchiveSectors(void) if (diff) { - WRITEUINT16(save_p, i); + WRITEUINT32(save_p, i); WRITEUINT8(save_p, diff); if (diff & SD_DIFF2) WRITEUINT8(save_p, diff2); @@ -1150,18 +1150,19 @@ static void ArchiveSectors(void) } } - WRITEUINT16(save_p, 0xffff); + WRITEUINT32(save_p, 0xffffffff); } static void UnArchiveSectors(void) { - UINT16 i, j; + UINT32 i; + UINT16 j; UINT8 diff, diff2, diff3, diff4; for (;;) { - i = READUINT16(save_p); + i = READUINT32(save_p); - if (i == 0xffff) + if (i == 0xffffffff) break; if (i > numsectors) @@ -1299,7 +1300,7 @@ static void ArchiveLines(void) if (li->executordelay != spawnli->executordelay) diff2 |= LD_EXECUTORDELAY; - if (li->sidenum[0] != 0xffff) + if (li->sidenum[0] != NO_SIDEDEF) { si = &sides[li->sidenum[0]]; spawnsi = &spawnsides[li->sidenum[0]]; @@ -1313,7 +1314,7 @@ static void ArchiveLines(void) if (si->midtexture != spawnsi->midtexture) diff |= LD_S1MIDTEX; } - if (li->sidenum[1] != 0xffff) + if (li->sidenum[1] != NO_SIDEDEF) { si = &sides[li->sidenum[1]]; spawnsi = &spawnsides[li->sidenum[1]]; @@ -1332,7 +1333,7 @@ static void ArchiveLines(void) if (diff) { - WRITEINT16(save_p, i); + WRITEUINT32(save_p, i); WRITEUINT8(save_p, diff); if (diff & LD_DIFF2) WRITEUINT8(save_p, diff2); @@ -1391,21 +1392,21 @@ static void ArchiveLines(void) WRITEINT32(save_p, li->executordelay); } } - WRITEUINT16(save_p, 0xffff); + WRITEUINT32(save_p, 0xffffffff); } static void UnArchiveLines(void) { - UINT16 i; + UINT32 i; line_t *li; side_t *si; UINT8 diff, diff2; // no diff3 for (;;) { - i = READUINT16(save_p); + i = READUINT32(save_p); - if (i == 0xffff) + if (i == 0xffffffff) break; if (i > numlines) I_Error("Invalid line number %u from server", i); @@ -1892,7 +1893,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) if (diff & MD_RTIME) WRITEINT32(save_p, mobj->reactiontime); if (diff & MD_STATE) - WRITEUINT16(save_p, mobj->state-states); + WRITEUINT32(save_p, mobj->state-states); if (diff & MD_TICS) WRITEINT32(save_p, mobj->tics); if (diff & MD_SPRITE) { @@ -2916,7 +2917,7 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker) mobj->reactiontime = mobj->info->reactiontime; if (diff & MD_STATE) - mobj->state = &states[READUINT16(save_p)]; + mobj->state = &states[READUINT32(save_p)]; else mobj->state = &states[mobj->info->spawnstate]; if (diff & MD_TICS) diff --git a/src/p_setup.c b/src/p_setup.c index 0390761b6..733a47792 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1111,40 +1111,40 @@ static void P_InitializeLinedef(line_t *ld) // cph 2006/09/30 - fix sidedef errors right away. // cph 2002/07/20 - these errors are fatal if not fixed, so apply them for (j = 0; j < 2; j++) - if (ld->sidenum[j] != 0xffff && ld->sidenum[j] >= (UINT16)numsides) + if (ld->sidenum[j] != NO_SIDEDEF && ld->sidenum[j] >= (UINT32)numsides) { - ld->sidenum[j] = 0xffff; + ld->sidenum[j] = NO_SIDEDEF; CONS_Debug(DBG_SETUP, "P_InitializeLinedef: Linedef %s has out-of-range sidedef number\n", sizeu1((size_t)(ld - lines))); } // killough 11/98: fix common wad errors (missing sidedefs): - if (ld->sidenum[0] == 0xffff) + if (ld->sidenum[0] == NO_SIDEDEF) { ld->sidenum[0] = 0; // Substitute dummy sidedef for missing right side // cph - print a warning about the bug CONS_Debug(DBG_SETUP, "P_InitializeLinedef: Linedef %s missing first sidedef\n", sizeu1((size_t)(ld - lines))); } - if ((ld->sidenum[1] == 0xffff) && (ld->flags & ML_TWOSIDED)) + if ((ld->sidenum[1] == NO_SIDEDEF) && (ld->flags & ML_TWOSIDED)) { ld->flags &= ~ML_TWOSIDED; // Clear 2s flag for missing left side // cph - print a warning about the bug CONS_Debug(DBG_SETUP, "P_InitializeLinedef: Linedef %s has two-sided flag set, but no second sidedef\n", sizeu1((size_t)(ld - lines))); } - if (ld->sidenum[0] != 0xffff) + if (ld->sidenum[0] != NO_SIDEDEF) { sides[ld->sidenum[0]].special = ld->special; sides[ld->sidenum[0]].line = ld; } - if (ld->sidenum[1] != 0xffff) + if (ld->sidenum[1] != NO_SIDEDEF) { sides[ld->sidenum[1]].special = ld->special; sides[ld->sidenum[1]].line = ld; } } -static void P_SetLinedefV1(size_t i, UINT16 vertex_num) +static void P_SetLinedefV1(size_t i, UINT32 vertex_num) { if (vertex_num >= numvertexes) { @@ -1154,7 +1154,7 @@ static void P_SetLinedefV1(size_t i, UINT16 vertex_num) lines[i].v1 = &vertexes[vertex_num]; } -static void P_SetLinedefV2(size_t i, UINT16 vertex_num) +static void P_SetLinedefV2(size_t i, UINT32 vertex_num) { if (vertex_num >= numvertexes) { @@ -1179,17 +1179,22 @@ static void P_LoadLinedefs(UINT8 *data) memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; ld->executordelay = 0; - P_SetLinedefV1(i, SHORT(mld->v1)); - P_SetLinedefV2(i, SHORT(mld->v2)); + P_SetLinedefV1(i, (UINT16)SHORT(mld->v1)); + P_SetLinedefV2(i, (UINT16)SHORT(mld->v2)); - ld->sidenum[0] = SHORT(mld->sidenum[0]); - ld->sidenum[1] = SHORT(mld->sidenum[1]); + ld->sidenum[0] = (UINT16)SHORT(mld->sidenum[0]); + ld->sidenum[1] = (UINT16)SHORT(mld->sidenum[1]); + + if (ld->sidenum[0] == 0xffff) + ld->sidenum[0] = NO_SIDEDEF; + if (ld->sidenum[1] == 0xffff) + ld->sidenum[1] = NO_SIDEDEF; P_InitializeLinedef(ld); } } -static void P_SetSidedefSector(size_t i, UINT16 sector_num) +static void P_SetSidedefSector(size_t i, UINT32 sector_num) { // cph 2006/09/30 - catch out-of-range sector numbers; use sector 0 instead if (sector_num >= numsectors) @@ -1350,7 +1355,7 @@ static void P_LoadSidedefs(UINT8 *data) sd->offsetx_top = sd->offsetx_mid = sd->offsetx_bot = 0; sd->offsety_top = sd->offsety_mid = sd->offsety_bot = 0; - P_SetSidedefSector(i, SHORT(msd->sector)); + P_SetSidedefSector(i, (UINT16)SHORT(msd->sector)); // Special info stored in texture fields! switch (sd->special) @@ -2489,7 +2494,7 @@ static void P_WriteTextmap(void) fprintf(f, "v1 = %s;\n", sizeu1(wlines[i].v1 - vertexes)); fprintf(f, "v2 = %s;\n", sizeu1(wlines[i].v2 - vertexes)); fprintf(f, "sidefront = %d;\n", wlines[i].sidenum[0]); - if (wlines[i].sidenum[1] != 0xffff) + if (wlines[i].sidenum[1] != NO_SIDEDEF) fprintf(f, "sideback = %d;\n", wlines[i].sidenum[1]); firsttag = Tag_FGet(&wlines[i].tags); if (firsttag != 0) @@ -2954,8 +2959,8 @@ static void P_LoadTextmap(void) memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; ld->executordelay = 0; - ld->sidenum[0] = 0xffff; - ld->sidenum[1] = 0xffff; + ld->sidenum[0] = NO_SIDEDEF; + ld->sidenum[1] = NO_SIDEDEF; TextmapParse(linesPos[i], i, ParseTextmapLinedefParameter); @@ -2963,7 +2968,7 @@ static void P_LoadTextmap(void) I_Error("P_LoadTextmap: linedef %s has no v1 value set!\n", sizeu1(i)); if (!ld->v2) I_Error("P_LoadTextmap: linedef %s has no v2 value set!\n", sizeu1(i)); - if (ld->sidenum[0] == 0xffff) + if (ld->sidenum[0] == NO_SIDEDEF) I_Error("P_LoadTextmap: linedef %s has no sidefront value set!\n", sizeu1(i)); P_InitializeLinedef(ld); @@ -3017,7 +3022,7 @@ static void P_ProcessLinedefsAfterSidedefs(void) for (; i--; ld++) { ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here - ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; + ld->backsector = ld->sidenum[1] != NO_SIDEDEF ? sides[ld->sidenum[1]].sector : 0; if (udmf) continue; @@ -3256,9 +3261,9 @@ static void P_InitializeSeg(seg_t *seg) { if (seg->linedef) { - UINT16 side = seg->linedef->sidenum[seg->side]; + UINT32 side = seg->linedef->sidenum[seg->side]; - if (side == 0xffff) + if (side == NO_SIDEDEF) I_Error("P_InitializeSeg: Seg %s refers to side %d of linedef %s, which doesn't exist!\n", sizeu1((size_t)(seg - segs)), seg->side, sizeu1((size_t)(seg->linedef - lines))); seg->sidedef = &sides[side]; @@ -3443,7 +3448,7 @@ static boolean P_LoadExtraVertices(UINT8 **data) static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype) { size_t i, k; - INT16 m; + size_t m; seg_t *seg; // Subsectors @@ -3466,23 +3471,33 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype { case NT_XGLN: case NT_XGL3: - for (m = 0; m < subsectors[i].numlines; m++, k++) + for (m = 0; m < (size_t)subsectors[i].numlines; m++, k++) { UINT32 vertexnum = READUINT32((*data)); - UINT16 linenum; - if (vertexnum >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid vertex %d!\n", sizeu1(k), m, vertexnum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid vertex %d!\n", sizeu1(k), sizeu1(m), vertexnum); segs[k - 1 + ((m == 0) ? subsectors[i].numlines : 0)].v2 = segs[k].v1 = &vertexes[vertexnum]; READUINT32((*data)); // partner, can be ignored by software renderer - linenum = (nodetype == NT_XGL3) ? READUINT32((*data)) : READUINT16((*data)); - if (linenum != 0xFFFF && linenum >= numlines) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu2(i), linenum); - segs[k].glseg = (linenum == 0xFFFF); - segs[k].linedef = (linenum == 0xFFFF) ? NULL : &lines[linenum]; + if (nodetype == NT_XGL3) + { + UINT32 linenum = READUINT32((*data)); + if (linenum != 0xFFFFFFFF && linenum >= numlines) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu2(i), linenum); + segs[k].glseg = linenum == 0xFFFFFFFF; + segs[k].linedef = linenum == 0xFFFFFFFF ? NULL : &lines[linenum]; + } + else + { + UINT16 linenum = READUINT16((*data)); + if (linenum != 0xFFFF && linenum >= numlines) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu2(i), linenum); + segs[k].glseg = linenum == 0xFFFF; + segs[k].linedef = linenum == 0xFFFF ? NULL : &lines[linenum]; + } + segs[k].side = READUINT8((*data)); } while (segs[subsectors[i].firstline].glseg) @@ -3494,18 +3509,18 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype break; case NT_XNOD: - for (m = 0; m < subsectors[i].numlines; m++, k++) + for (m = 0; m < (size_t)subsectors[i].numlines; m++, k++) { UINT32 v1num = READUINT32((*data)); UINT32 v2num = READUINT32((*data)); UINT16 linenum = READUINT16((*data)); if (v1num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid v1 %d!\n", sizeu1(k), m, v1num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v1 %d!\n", sizeu1(k), sizeu1(m), v1num); if (v2num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid v2 %d!\n", sizeu1(k), m, v2num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v2 %d!\n", sizeu1(k), sizeu1(m), v2num); if (linenum >= numlines) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid linedef %d!\n", sizeu1(k), m, linenum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu1(m), linenum); segs[k].v1 = &vertexes[v1num]; segs[k].v2 = &vertexes[v2num]; @@ -3990,7 +4005,7 @@ static void P_LinkMapData(void) if (!seg->sidedef) CorruptMapError(va("P_LinkMapData: seg->sidedef is NULL " "(subsector %s, firstline is %d)", sizeu1(i), ss->firstline)); - if (seg->sidedef - sides < 0 || seg->sidedef - sides > (UINT16)numsides) + if (seg->sidedef - sides < 0 || seg->sidedef - sides > (UINT32)numsides) CorruptMapError(va("P_LinkMapData: seg->sidedef refers to sidedef %s of %s " "(subsector %s, firstline is %d)", sizeu1(sidei), sizeu2(numsides), sizeu3(i), ss->firstline)); @@ -4915,7 +4930,7 @@ static void P_ConvertBinaryLinedefTypes(void) break; case 259: //Custom FOF - if (lines[i].sidenum[1] == 0xffff) + if (lines[i].sidenum[1] == NO_SIDEDEF) I_Error("Custom FOF (tag %d) found without a linedef back side!", tag); lines[i].args[0] = tag; @@ -5269,8 +5284,8 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[1] = sides[lines[i].sidenum[0]].midtexture; lines[i].args[2] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; lines[i].args[3] = sides[lines[i].sidenum[0]].rowoffset >> FRACBITS; - lines[i].args[4] = (lines[i].sidenum[1] != 0xffff) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : 0; - lines[i].args[5] = (lines[i].sidenum[1] != 0xffff) ? sides[lines[i].sidenum[1]].rowoffset >> FRACBITS : -1; + lines[i].args[4] = (lines[i].sidenum[1] != NO_SIDEDEF) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : 0; + lines[i].args[5] = (lines[i].sidenum[1] != NO_SIDEDEF) ? sides[lines[i].sidenum[1]].rowoffset >> FRACBITS : -1; lines[i].args[6] = sides[lines[i].sidenum[0]].bottomtexture; break; case 414: //Play sound effect @@ -5374,7 +5389,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[1] = max(sides[lines[i].sidenum[0]].textureoffset >> FRACBITS, 0); // failsafe: if user specifies Back Y Offset and NOT Front Y Offset, use the Back Offset // to be consistent with other light and fade specials - lines[i].args[2] = ((lines[i].sidenum[1] != 0xFFFF && !(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS)) ? + lines[i].args[2] = ((lines[i].sidenum[1] != NO_SIDEDEF && !(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS)) ? max(min(sides[lines[i].sidenum[1]].rowoffset >> FRACBITS, 255), 0) : max(min(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS, 255), 0)); } @@ -5479,7 +5494,7 @@ static void P_ConvertBinaryLinedefTypes(void) break; case 442: //Change object type state lines[i].args[0] = tag; - lines[i].args[1] = (lines[i].sidenum[1] == 0xffff) ? 1 : 0; + lines[i].args[1] = (lines[i].sidenum[1] == NO_SIDEDEF) ? 1 : 0; break; case 443: //Call Lua function if (lines[i].stringargs[0] == NULL) @@ -5547,7 +5562,7 @@ static void P_ConvertBinaryLinedefTypes(void) case 452: //Set FOF translucency lines[i].args[0] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; lines[i].args[1] = sides[lines[i].sidenum[0]].rowoffset >> FRACBITS; - lines[i].args[2] = lines[i].sidenum[1] != 0xffff ? (sides[lines[i].sidenum[1]].textureoffset >> FRACBITS) : (P_AproxDistance(lines[i].dx, lines[i].dy) >> FRACBITS); + lines[i].args[2] = lines[i].sidenum[1] != NO_SIDEDEF ? (sides[lines[i].sidenum[1]].textureoffset >> FRACBITS) : (P_AproxDistance(lines[i].dx, lines[i].dy) >> FRACBITS); if (lines[i].flags & ML_MIDPEG) lines[i].args[3] |= TMST_RELATIVE; if (lines[i].flags & ML_NOCLIMB) @@ -5556,8 +5571,8 @@ static void P_ConvertBinaryLinedefTypes(void) case 453: //Fade FOF lines[i].args[0] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; lines[i].args[1] = sides[lines[i].sidenum[0]].rowoffset >> FRACBITS; - lines[i].args[2] = lines[i].sidenum[1] != 0xffff ? (sides[lines[i].sidenum[1]].textureoffset >> FRACBITS) : (lines[i].dx >> FRACBITS); - lines[i].args[3] = lines[i].sidenum[1] != 0xffff ? (sides[lines[i].sidenum[1]].rowoffset >> FRACBITS) : (abs(lines[i].dy) >> FRACBITS); + lines[i].args[2] = lines[i].sidenum[1] != NO_SIDEDEF ? (sides[lines[i].sidenum[1]].textureoffset >> FRACBITS) : (lines[i].dx >> FRACBITS); + lines[i].args[3] = lines[i].sidenum[1] != NO_SIDEDEF ? (sides[lines[i].sidenum[1]].rowoffset >> FRACBITS) : (abs(lines[i].dy) >> FRACBITS); if (lines[i].flags & ML_MIDPEG) lines[i].args[4] |= TMFT_RELATIVE; if (lines[i].flags & ML_WRAPMIDTEX) @@ -5584,7 +5599,7 @@ static void P_ConvertBinaryLinedefTypes(void) break; case 455: //Fade colormap { - INT32 speed = (INT32)((((lines[i].flags & ML_DONTPEGBOTTOM) || !sides[lines[i].sidenum[0]].rowoffset) && lines[i].sidenum[1] != 0xFFFF) ? + INT32 speed = (INT32)((((lines[i].flags & ML_DONTPEGBOTTOM) || !sides[lines[i].sidenum[0]].rowoffset) && lines[i].sidenum[1] != NO_SIDEDEF) ? abs(sides[lines[i].sidenum[1]].rowoffset >> FRACBITS) : abs(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS)); @@ -5614,7 +5629,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[0] = tag; lines[i].args[1] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; lines[i].args[2] = sides[lines[i].sidenum[0]].rowoffset >> FRACBITS; - lines[i].args[3] = (lines[i].sidenum[1] != 0xffff) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : 0; + lines[i].args[3] = (lines[i].sidenum[1] != NO_SIDEDEF) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : 0; lines[i].args[4] = !!(lines[i].flags & ML_NOSKEW); break; case 459: //Control text prompt @@ -5634,7 +5649,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[2] |= TMP_ALLPLAYERS; if (lines[i].flags & ML_MIDSOLID) lines[i].args[2] |= TMP_FREEZETHINKERS;*/ - lines[i].args[3] = (lines[i].sidenum[1] != 0xFFFF) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : tag; + lines[i].args[3] = (lines[i].sidenum[1] != NO_SIDEDEF) ? sides[lines[i].sidenum[1]].textureoffset >> FRACBITS : tag; break; case 460: //Award rings lines[i].args[0] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; @@ -5647,7 +5662,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[3] = (lines[i].flags & ML_SKEWTD) ? AngleFixed(R_PointToAngle2(lines[i].v1->x, lines[i].v1->y, lines[i].v2->x, lines[i].v2->y)) >> FRACBITS : 0; if (lines[i].flags & ML_NOCLIMB) { - if (lines[i].sidenum[1] != 0xffff) // Make sure the linedef has a back side + if (lines[i].sidenum[1] != NO_SIDEDEF) // Make sure the linedef has a back side { lines[i].args[4] = 1; lines[i].args[5] = sides[lines[i].sidenum[1]].textureoffset >> FRACBITS; @@ -5681,7 +5696,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[0] = tag; lines[i].args[1] = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS; lines[i].args[2] = sides[lines[i].sidenum[0]].rowoffset >> FRACBITS; - if (lines[i].sidenum[1] != 0xffff) + if (lines[i].sidenum[1] != NO_SIDEDEF) lines[i].args[3] = sides[lines[i].sidenum[1]].textureoffset >> FRACBITS; break; case 482: //Polyobject - move @@ -5753,7 +5768,7 @@ static void P_ConvertBinaryLinedefTypes(void) if (!(lines[i].flags & ML_DONTPEGBOTTOM)) lines[i].args[1] /= 100; // allow Back Y Offset to be consistent with other fade specials - lines[i].args[2] = (lines[i].sidenum[1] != 0xffff && !sides[lines[i].sidenum[0]].rowoffset) ? + lines[i].args[2] = (lines[i].sidenum[1] != NO_SIDEDEF && !sides[lines[i].sidenum[0]].rowoffset) ? abs(sides[lines[i].sidenum[1]].rowoffset >> FRACBITS) : abs(sides[lines[i].sidenum[0]].rowoffset >> FRACBITS); if (lines[i].flags & ML_MIDPEG) @@ -5780,7 +5795,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[0] = tag; if (lines[i].flags & ML_MIDPEG) { - if (lines[i].sidenum[1] == 0xffff) + if (lines[i].sidenum[1] == NO_SIDEDEF) { CONS_Debug(DBG_GAMELOGIC, "Line special %d (line #%s) missing back side!\n", lines[i].special, sizeu1(i)); lines[i].special = 0; @@ -5810,7 +5825,7 @@ static void P_ConvertBinaryLinedefTypes(void) lines[i].args[0] = lines[i].special >= 507; if (lines[i].special % 2 == 0) { - if (lines[i].sidenum[1] == 0xffff) + if (lines[i].sidenum[1] == NO_SIDEDEF) { CONS_Debug(DBG_GAMELOGIC, "Line special %d (line #%s) missing back side!\n", lines[i].special, sizeu1(i)); lines[i].special = 0; @@ -5966,7 +5981,7 @@ static void P_ConvertBinaryLinedefTypes(void) { UINT8 side = lines[i].special >= 714; - if (side == 1 && lines[i].sidenum[1] == 0xffff) + if (side == 1 && lines[i].sidenum[1] == NO_SIDEDEF) CONS_Debug(DBG_GAMELOGIC, "P_ConvertBinaryMap: Line special %d (line #%s) missing 2nd side!\n", lines[i].special, sizeu1(i)); else { diff --git a/src/p_spec.c b/src/p_spec.c index 28ecc60f4..73bb0da88 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -557,7 +557,7 @@ static inline sector_t *getSector(INT32 currentSector, INT32 line, INT32 side) */ static inline boolean twoSided(INT32 sector, INT32 line) { - return (sectors[sector].lines[line])->sidenum[1] != 0xffff; + return (sectors[sector].lines[line])->sidenum[1] != NO_SIDEDEF; } #endif @@ -2897,7 +2897,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { size_t linenum; side_t *setfront = &sides[line->sidenum[0]]; - side_t *setback = (line->args[3] && line->sidenum[1] != 0xffff) ? &sides[line->sidenum[1]] : setfront; + side_t *setback = (line->args[3] && line->sidenum[1] != NO_SIDEDEF) ? &sides[line->sidenum[1]] : setfront; side_t *this; boolean always = !(line->args[2]); // If args[2] is set: Only change mid texture if mid texture already exists on tagged lines, etc. @@ -2919,7 +2919,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } // Back side - if (line->args[1] != TMSD_FRONT && lines[linenum].sidenum[1] != 0xffff) + if (line->args[1] != TMSD_FRONT && lines[linenum].sidenum[1] != NO_SIDEDEF) { this = &sides[lines[linenum].sidenum[1]]; if (always || this->toptexture) this->toptexture = setback->toptexture; @@ -3153,7 +3153,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->args[2] & TMCF_RELATIVE) { - extracolormap_t *target = (!udmf && (line->flags & ML_TFERLINE) && line->sidenum[1] != 0xFFFF) ? + extracolormap_t *target = (!udmf && (line->flags & ML_TFERLINE) && line->sidenum[1] != NO_SIDEDEF) ? sides[line->sidenum[1]].colormap_data : sectors[secnum].extra_colormap; // use back colormap instead of target sector extracolormap_t *exc = R_AddColormaps( @@ -3482,7 +3482,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } if (!udmf && (line->flags & ML_TFERLINE)) // use back colormap instead of target sector - sectors[secnum].extra_colormap = (line->sidenum[1] != 0xFFFF) ? + sectors[secnum].extra_colormap = (line->sidenum[1] != NO_SIDEDEF) ? sides[line->sidenum[1]].colormap_data : NULL; exc = sectors[secnum].extra_colormap; @@ -7598,7 +7598,7 @@ static void P_SpawnScrollers(void) { if (l->args[1] != TMSD_BACK) Add_Scroller(sc_side, l->args[2] << (FRACBITS - SCROLL_SHIFT), l->args[3] << (FRACBITS - SCROLL_SHIFT), control, lines[s].sidenum[0], accel, 0); - if (l->args[1] != TMSD_FRONT && lines[s].sidenum[1] != 0xffff) + if (l->args[1] != TMSD_FRONT && lines[s].sidenum[1] != NO_SIDEDEF) Add_Scroller(sc_side, l->args[2] << (FRACBITS - SCROLL_SHIFT), l->args[3] << (FRACBITS - SCROLL_SHIFT), control, lines[s].sidenum[1], accel, 0); } break; @@ -7609,7 +7609,7 @@ static void P_SpawnScrollers(void) Add_Scroller(sc_side, -l->args[1] << FRACBITS, l->args[2] << FRACBITS, -1, l->sidenum[0], accel, 0); if (l->args[0] != TMSD_FRONT) { - if (l->sidenum[1] != 0xffff) + if (l->sidenum[1] != NO_SIDEDEF) Add_Scroller(sc_side, -l->args[1] << FRACBITS, l->args[2] << FRACBITS, -1, l->sidenum[1], accel, 0); else CONS_Debug(DBG_GAMELOGIC, "Line special 500 (line #%s) missing back side!\n", sizeu1(i)); diff --git a/src/r_defs.h b/src/r_defs.h index dfd2d6d70..6463e6f5d 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -512,6 +512,8 @@ typedef enum #define NUMLINEARGS 10 #define NUMLINESTRINGARGS 2 +#define NO_SIDEDEF 0xFFFFFFFF + typedef struct line_s { // Vertices, from v1 to v2. @@ -529,7 +531,7 @@ typedef struct line_s char *stringargs[NUMLINESTRINGARGS]; // Visual appearance: sidedefs. - UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided + UINT32 sidenum[2]; // sidenum[1] will be NO_SIDEDEF if one-sided fixed_t alpha; // translucency UINT8 blendmode; // blendmode INT32 executordelay; From 5e501bae0767124adee00f8f0db0334b32422342 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 21 Sep 2023 13:19:38 +0100 Subject: [PATCH 43/91] v.getSpritePatch/v.getSprite2Patch fix: Fix offset inconsistency between rotated sprites and non-rotated sprites This was caused by rotated sprites having FEETADJUST offsets applied, when non-rotated sprites did not. FEETADJUST is not actually needed in the HUD, so I've removed it from the rotated sprites (thankfully this is also the easiest way to fix it too) --- src/lua_hudlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 6eec91273..899e5a2dc 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -517,7 +517,7 @@ static int libd_getSpritePatch(lua_State *L) INT32 rot = R_GetRollAngle(rollangle); if (rot) { - patch_t *rotsprite = Patch_GetRotatedSprite(sprframe, frame, angle, sprframe->flip & (1<flip & (1<flip & (1<flip & (1< Date: Thu, 21 Sep 2023 15:50:30 +0100 Subject: [PATCH 44/91] Remove adjustfeet parameter from Patch_GetRotatedSprite, remove [2] from spriteframe_t's rotated array. Following from my previous commit, these things are no longer needed: they existed ONLY for adding FEETADJUST offsets to rotated sprites in Lua HUD code. --- src/hardware/hw_main.c | 2 +- src/lua_hudlib.c | 4 ++-- src/r_defs.h | 2 +- src/r_patch.h | 2 +- src/r_patchrotation.c | 11 +++-------- src/r_things.c | 2 +- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 59af61753..4a000f83a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5259,7 +5259,7 @@ static void HWR_ProjectSprite(mobj_t *thing) rollangle = R_GetRollAngle(spriterotangle); } - rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); + rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, sprinfo, rollangle); if (rotsprite != NULL) { diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 899e5a2dc..cf03776e0 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -517,7 +517,7 @@ static int libd_getSpritePatch(lua_State *L) INT32 rot = R_GetRollAngle(rollangle); if (rot) { - patch_t *rotsprite = Patch_GetRotatedSprite(sprframe, frame, angle, sprframe->flip & (1<flip & (1<flip & (1<flip & (1<= ROTANGLES) return NULL; - rotsprite = sprite->rotated[type][spriteangle]; + rotsprite = sprite->rotated[spriteangle]; if (rotsprite == NULL) { rotsprite = RotatedPatch_Create(ROTANGLES); - sprite->rotated[type][spriteangle] = rotsprite; + sprite->rotated[spriteangle] = rotsprite; } if (flip) @@ -111,10 +110,6 @@ patch_t *Patch_GetRotatedSprite( } RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); - - //BP: we cannot use special tric in hardware mode because feet in ground caused by z-buffer - if (adjustfeet) - ((patch_t *)rotsprite->patches[idx])->topoffset += FEETADJUST>>FRACBITS; } return rotsprite->patches[idx]; diff --git a/src/r_things.c b/src/r_things.c index 89c4f35eb..85d76fecd 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1794,7 +1794,7 @@ static void R_ProjectSprite(mobj_t *thing) rollangle = R_GetRollAngle(spriterotangle); } - rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, false, sprinfo, rollangle); + rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, sprinfo, rollangle); if (rotsprite != NULL) { From 340eee8691697e2dd55f7eab84da0da0e83feb46 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 21 Sep 2023 16:13:55 +0100 Subject: [PATCH 45/91] Added some notes related to FEETADJUST for reference, made another tweak --- src/r_patchrotation.c | 6 ++---- src/r_things.c | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c index 0cf4a9841..b91069849 100644 --- a/src/r_patchrotation.c +++ b/src/r_patchrotation.c @@ -10,7 +10,7 @@ /// \brief Patch rotation. #include "r_patchrotation.h" -#include "r_things.h" // FEETADJUST +#include "r_things.h" // FEETADJUST (todo: is this needed anymore? -- Monster Iestyn 21 Sep 2023 ) #include "z_zone.h" #include "w_wad.h" #include "r_main.h" // R_PointToAngle @@ -69,15 +69,13 @@ patch_t *Patch_GetRotatedSprite( boolean flip, void *info, INT32 rotationangle) { - rotsprite_t *rotsprite; + rotsprite_t *rotsprite = sprite->rotated[spriteangle]; spriteinfo_t *sprinfo = (spriteinfo_t *)info; INT32 idx = rotationangle; if (rotationangle < 1 || rotationangle >= ROTANGLES) return NULL; - rotsprite = sprite->rotated[spriteangle]; - if (rotsprite == NULL) { rotsprite = RotatedPatch_Create(ROTANGLES); diff --git a/src/r_things.c b/src/r_things.c index 85d76fecd..0d4b9a1e5 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -337,6 +337,11 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 spritecachedinfo[numspritelumps].height = height< Date: Mon, 2 Oct 2023 23:31:21 +0200 Subject: [PATCH 46/91] Coins? --- src/r_bbox.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_bbox.c b/src/r_bbox.c index 5b2a817f1..8ccad2bb5 100644 --- a/src/r_bbox.c +++ b/src/r_bbox.c @@ -294,6 +294,7 @@ boolean R_ThingBoundingBoxVisible(mobj_t *thing) case MT_BLUESPHERE: case MT_NIGHTSSTAR: case MT_NIGHTSCHIP: + case MT_COIN: // Rings and similar objects are often placed // in large amounts, so they are handled // separately from other tangible objects. From 436de2180831aec6b14de01e1aa61ba894c5c1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 7 Oct 2023 00:07:56 +0200 Subject: [PATCH 47/91] Refactor code after review comments --- src/d_player.h | 1 + src/netcode/d_clisrv.c | 10 +++++----- src/netcode/d_net.h | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 7ad5b9f81..ca700d4e1 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -607,6 +607,7 @@ typedef struct player_s tic_t jointime; // Timer when player joins game to change skin/color tic_t quittime; // Time elapsed since user disconnected, zero if connected + tic_t lastinputtime; // the last tic the player has made any input #ifdef HWRENDER fixed_t fovadd; // adjust FOV for hw rendering #endif diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index efa251ff7..4571930f8 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -1282,19 +1282,19 @@ static void IdleUpdate(void) for (i = 1; i < MAXPLAYERS; i++) { - if (cv_idletime.value && playeringame[i] && playernode[i] != UINT8_MAX && !players[i].quittime && !players[i].spectator && i != serverplayer) + if (cv_idletime.value && playeringame[i] && playernode[i] != UINT8_MAX && !players[i].quittime && !players[i].spectator && !IsPlayerAdmin(i)) { if (players[i].cmd.forwardmove || players[i].cmd.sidemove || players[i].cmd.buttons) - netnodes[i].lastinput = gametime; + players[i].lastinputtime = gametime; - if (gametime - netnodes[i].lastinput > cv_idletime.value * TICRATE) + if (gametime - players[i].lastinputtime > (tic_t)cv_idletime.value * TICRATE * 60) { - netnodes[i].lastinput = gametime; + players[i].lastinputtime = gametime; SendKick(i, KICK_MSG_IDLE | KICK_MSG_KEEP_BODY); } } else - netnodes[i].lastinput = gametime; + players[i].lastinputtime = gametime; } } diff --git a/src/netcode/d_net.h b/src/netcode/d_net.h index e8e3b5895..549f2b93c 100644 --- a/src/netcode/d_net.h +++ b/src/netcode/d_net.h @@ -43,7 +43,6 @@ typedef struct netnode_s { boolean ingame; // set false as nodes leave game tic_t freezetimeout; // Until when can this node freeze the server before getting a timeout? - tic_t lastinput; // the last tic the player has made any input SINT8 player; SINT8 player2; // say the numplayer for this node if any (splitscreen) From 80e386b16f66079fcef80bcfb116135b8524efe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 14 Oct 2023 21:50:59 +0200 Subject: [PATCH 48/91] Expose lastinputtime to Lua --- src/lua_baselib.c | 1 + src/lua_playerlib.c | 8 ++++++++ src/netcode/d_clisrv.c | 13 ++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 8cb6d185d..d1fa8f368 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3572,6 +3572,7 @@ static int lib_gAddPlayer(lua_State *L) newplayer->jointime = 0; newplayer->quittime = 0; + newplayer->lastinputtime = 0; // Read the skin argument (defaults to Sonic) if (!lua_isnoneornil(L, 1)) diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 827e5a405..d0858e044 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -223,6 +223,7 @@ enum player_e player_blocked, player_jointime, player_quittime, + player_lastinputtime, player_ping, #ifdef HWRENDER player_fovadd, @@ -371,6 +372,7 @@ static const char *const player_opt[] = { "blocked", "jointime", "quittime", + "lastinputtime", "ping", #ifdef HWRENDER "fovadd", @@ -826,6 +828,9 @@ static int player_get(lua_State *L) case player_quittime: lua_pushinteger(L, plr->quittime); break; + case player_lastinputtime: + lua_pushinteger(L, plr->lastinputtime); + break; case player_ping: lua_pushinteger(L, playerpingtable[plr - players]); break; @@ -1349,6 +1354,9 @@ static int player_set(lua_State *L) case player_quittime: plr->quittime = (tic_t)luaL_checkinteger(L, 3); break; + case player_lastinputtime: + plr->lastinputtime = (tic_t)luaL_checkinteger(L, 3); + break; #ifdef HWRENDER case player_fovadd: plr->fovadd = luaL_checkfixed(L, 3); diff --git a/src/netcode/d_clisrv.c b/src/netcode/d_clisrv.c index 4571930f8..7804b068f 100644 --- a/src/netcode/d_clisrv.c +++ b/src/netcode/d_clisrv.c @@ -227,6 +227,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) newplayer->jointime = 0; newplayer->quittime = 0; + newplayer->lastinputtime = 0; READSTRINGN(*p, player_names[newplayernum], MAXPLAYERNAME); @@ -1282,19 +1283,21 @@ static void IdleUpdate(void) for (i = 1; i < MAXPLAYERS; i++) { - if (cv_idletime.value && playeringame[i] && playernode[i] != UINT8_MAX && !players[i].quittime && !players[i].spectator && !IsPlayerAdmin(i)) + if (cv_idletime.value && playeringame[i] && playernode[i] != UINT8_MAX && !players[i].quittime && !players[i].spectator && !players[i].bot && !IsPlayerAdmin(i) && i != serverplayer) { if (players[i].cmd.forwardmove || players[i].cmd.sidemove || players[i].cmd.buttons) - players[i].lastinputtime = gametime; + players[i].lastinputtime = 0; + else + players[i].lastinputtime++; - if (gametime - players[i].lastinputtime > (tic_t)cv_idletime.value * TICRATE * 60) + if (players[i].lastinputtime > (tic_t)cv_idletime.value * TICRATE * 60) { - players[i].lastinputtime = gametime; + players[i].lastinputtime = 0; SendKick(i, KICK_MSG_IDLE | KICK_MSG_KEEP_BODY); } } else - players[i].lastinputtime = gametime; + players[i].lastinputtime = 0; } } From 6fac101cbeee6fe278c910047e32fb936720b699 Mon Sep 17 00:00:00 2001 From: Logan Arias Date: Sun, 22 Oct 2023 11:49:23 -0400 Subject: [PATCH 49/91] Disable libcurl when building without network support --- src/Makefile.d/features.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index 653100cb5..a66779c07 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -18,6 +18,10 @@ opts+=-DHWRENDER sources+=$(call List,hardware/Sourcefile) endif +ifdef NONET +NOCURL=1 +endif + ifndef NOMD5 sources+=md5.c endif From 9d650b0ddca510f61d2d9f948bffb948175f5ba0 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 25 Oct 2023 07:26:34 -0400 Subject: [PATCH 50/91] Makefile: add lua_colorlib.c --- src/Sourcefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sourcefile b/src/Sourcefile index 6ed1f3b4c..7beb98c9e 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -94,3 +94,4 @@ lua_blockmaplib.c lua_hudlib.c lua_hudlib_drawlist.c lua_inputlib.c +lua_colorlib.c From 229d0364d4a8b37beec8e9f4851da6be426533b5 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 25 Oct 2023 07:40:55 -0400 Subject: [PATCH 51/91] Fixed lookup sides for 32-bit systems --- src/lua_maplib.c | 5 ++++- src/p_setup.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 7302c727a..2a02b1a24 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1243,6 +1243,9 @@ static int side_get(lua_State *L) return 1; case side_text: { + boolean isfrontside; + size_t sidei = side-sides; + if (udmf) { LUA_Deprecated(L, "(sidedef_t).text", "(sidedef_t).line.stringargs"); @@ -1250,7 +1253,7 @@ static int side_get(lua_State *L) return 1; } - boolean isfrontside = side->line->sidenum[0] == side-sides; + isfrontside = side->line->sidenum[0] == sidei; lua_pushstring(L, side->line->stringargs[isfrontside ? 0 : 1]); return 1; diff --git a/src/p_setup.c b/src/p_setup.c index 733a47792..effd2c368 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -4005,7 +4005,7 @@ static void P_LinkMapData(void) if (!seg->sidedef) CorruptMapError(va("P_LinkMapData: seg->sidedef is NULL " "(subsector %s, firstline is %d)", sizeu1(i), ss->firstline)); - if (seg->sidedef - sides < 0 || seg->sidedef - sides > (UINT32)numsides) + if (seg->sidedef - sides < 0 || sidei > numsides) CorruptMapError(va("P_LinkMapData: seg->sidedef refers to sidedef %s of %s " "(subsector %s, firstline is %d)", sizeu1(sidei), sizeu2(numsides), sizeu3(i), ss->firstline)); From ec1b629609cf6fccf1cf6c85705d76b11fb0c998 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 25 Oct 2023 08:00:04 -0400 Subject: [PATCH 52/91] spriteframe_t only gave 1D array, not 2D for rotated --- src/r_things.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 0d4b9a1e5..66a637b13 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -138,8 +138,7 @@ static void R_InstallSpriteLump(UINT16 wad, // graphics patch #ifdef ROTSPRITE for (r = 0; r < 16; r++) { - sprtemp[frame].rotated[0][r] = NULL; - sprtemp[frame].rotated[1][r] = NULL; + sprtemp[frame].rotated[r] = NULL; } #endif From fd41bf188dc895a1039a1f8f12ebadadb728c3e7 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 25 Oct 2023 12:16:10 -0400 Subject: [PATCH 53/91] sidenum[0] is an uint32_t, not uint16_t --- src/p_spec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 73bb0da88..2dcd45f4d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1796,7 +1796,7 @@ void P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller) if (trigid < 0 || trigid > 31) // limited by 32 bit variable { - CONS_Debug(DBG_GAMELOGIC, "Unlockable trigger (sidedef %hu): bad trigger ID %d\n", triggerline->sidenum[0], trigid); + CONS_Debug(DBG_GAMELOGIC, "Unlockable trigger (sidedef %u): bad trigger ID %d\n", triggerline->sidenum[0], trigid); return; } else if (!(unlocktriggers & (1 << trigid))) @@ -1809,7 +1809,7 @@ void P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller) if (unlockid <= 0 || unlockid > MAXUNLOCKABLES) // limited by unlockable count { - CONS_Debug(DBG_GAMELOGIC, "Unlockable check (sidedef %hu): bad unlockable ID %d\n", triggerline->sidenum[0], unlockid); + CONS_Debug(DBG_GAMELOGIC, "Unlockable check (sidedef %u): bad unlockable ID %d\n", triggerline->sidenum[0], unlockid); return; } else if (!(serverGamedata->unlocked[unlockid-1])) @@ -2940,7 +2940,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 trigid = line->args[0]; if (trigid < 0 || trigid > 31) // limited by 32 bit variable - CONS_Debug(DBG_GAMELOGIC, "Unlockable trigger (sidedef %hu): bad trigger ID %d\n", line->sidenum[0], trigid); + CONS_Debug(DBG_GAMELOGIC, "Unlockable trigger (sidedef %u): bad trigger ID %d\n", line->sidenum[0], trigid); else { unlocktriggers |= 1 << trigid; From 23268bf3e53abfe0667465631a4027d1f56cd49d Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 27 Oct 2023 16:29:47 +0200 Subject: [PATCH 54/91] Move input-related Lua variables into the library --- src/lua_inputlib.c | 60 ++++++++++++++++++++++++++++++++++++---------- src/lua_script.c | 2 ++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index 1f75ee6fe..0602b3db6 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -145,6 +145,30 @@ static luaL_Reg lib[] = { {NULL, NULL} }; +/////////////// +// VARIABLES // +/////////////// + +static int lib_get(lua_State *L) +{ + const char *field = luaL_checkstring(L, 2); + + if (fastcmp(field, "mouse")) + { + LUA_PushUserdata(L, &mouse, META_MOUSE); + return 1; + } + else if (fastcmp(field, "mouse2")) + { + LUA_PushUserdata(L, &mouse2, META_MOUSE); + return 1; + } + else + { + return 0; + } +} + /////////////////// // gamekeydown[] // /////////////////// @@ -239,19 +263,6 @@ static int mouse_num(lua_State *L) int LUA_InputLib(lua_State *L) { - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getGameKeyDown); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setGameKeyDown); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_lenGameKeyDown); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "gamekeydown"); - luaL_newmetatable(L, META_KEYEVENT); lua_pushcfunction(L, keyevent_get); lua_setfield(L, -2, "__index"); @@ -265,6 +276,29 @@ int LUA_InputLib(lua_State *L) lua_setfield(L, -2, "__len"); lua_pop(L, 1); + // Register the library, then add __index and __newindex + // metamethods to it to allow global variables luaL_register(L, "input", lib); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_get); + lua_setfield(L, -2, "__index"); + lua_setmetatable(L, -2); + + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getGameKeyDown); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_setGameKeyDown); + lua_setfield(L, -2, "__newindex"); + + lua_pushcfunction(L, lib_lenGameKeyDown); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_pushvalue(L, -1); // TODO: 2.3: Delete (gamekeydown moved to input library) + lua_setglobal(L, "gamekeydown"); // Delete too + lua_setfield(L, -2, "gamekeydown"); + lua_pop(L, 1); + return 0; } diff --git a/src/lua_script.c b/src/lua_script.c index 392935b4f..9e106999d 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -415,9 +415,11 @@ int LUA_PushGlobals(lua_State *L, const char *word) } else if (fastcmp(word, "stagefailed")) { lua_pushboolean(L, stagefailed); return 1; + // TODO: 2.3: Deprecated (moved to the input library) } else if (fastcmp(word, "mouse")) { LUA_PushUserdata(L, &mouse, META_MOUSE); return 1; + // TODO: 2.3: Deprecated (moved to the input library) } else if (fastcmp(word, "mouse2")) { LUA_PushUserdata(L, &mouse2, META_MOUSE); return 1; From 4fa4d6e0766b2e427357f36a178cb797c4177ac9 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 27 Oct 2023 17:34:29 +0200 Subject: [PATCH 55/91] Implement input.ignoregameinputs --- src/g_game.c | 3 ++- src/g_input.c | 11 ++++++++--- src/lua_inputlib.c | 25 +++++++++++++++++++++++++ src/lua_libs.h | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index fae311694..962c2fd14 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -51,6 +51,7 @@ #include "r_fps.h" // frame interpolation/uncapped #include "lua_hud.h" +#include "lua_libs.h" gameaction_t gameaction; gamestate_t gamestate = GS_NULL; @@ -1170,7 +1171,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) // why build a ticcmd if we're paused? // Or, for that matter, if we're being reborn. // ...OR if we're blindfolded. No looking into the floor. - if (paused || P_AutoPause() || (gamestate == GS_LEVEL && (player->playerstate == PST_REBORN || ((gametyperules & GTR_TAG) + if (ignoregameinputs || paused || P_AutoPause() || (gamestate == GS_LEVEL && (player->playerstate == PST_REBORN || ((gametyperules & GTR_TAG) && (leveltime < hidetime * TICRATE) && (player->pflags & PF_TAGIT))))) {//@TODO splitscreen player cmd->angleturn = ticcmd_oldangleturn[forplayer]; diff --git a/src/g_input.c b/src/g_input.c index fa30c1984..97c0505a3 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -18,6 +18,8 @@ #include "hu_stuff.h" // need HUFONT start & end #include "netcode/d_net.h" #include "console.h" +#include "lua_script.h" +#include "lua_libs.h" #define MAXMOUSESENSITIVITY 100 // sensitivity steps @@ -116,7 +118,10 @@ void G_MapEventsToControls(event_t *ev) { case ev_keydown: if (ev->key < NUMINPUTS) - gamekeydown[ev->key] = 1; + { + if (!ignoregameinputs) + gamekeydown[ev->key] = 1; + } #ifdef PARANOIA else { @@ -144,7 +149,7 @@ void G_MapEventsToControls(event_t *ev) case ev_joystick: // buttons are virtual keys i = ev->key; - if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on) + if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on || ignoregameinputs) break; if (ev->x != INT32_MAX) joyxmove[i] = ev->x; if (ev->y != INT32_MAX) joyymove[i] = ev->y; @@ -152,7 +157,7 @@ void G_MapEventsToControls(event_t *ev) case ev_joystick2: // buttons are virtual keys i = ev->key; - if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on) + if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on || ignoregameinputs) break; if (ev->x != INT32_MAX) joy2xmove[i] = ev->x; if (ev->y != INT32_MAX) joy2ymove[i] = ev->y; diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index 0602b3db6..eeb61fed7 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -20,6 +20,7 @@ #include "lua_libs.h" boolean mousegrabbedbylua = true; +boolean ignoregameinputs = false; /////////////// // FUNCTIONS // @@ -163,12 +164,33 @@ static int lib_get(lua_State *L) LUA_PushUserdata(L, &mouse2, META_MOUSE); return 1; } + else if (fastcmp(field, "ignoregameinputs")) + { + lua_pushboolean(L, ignoregameinputs); + return 1; + } else { return 0; } } +static int lib_set(lua_State *L) +{ + const char *field = luaL_checkstring(L, 2); + + if (fastcmp(field, "ignoregameinputs")) + { + ignoregameinputs = luaL_checkboolean(L, 3); + } + else + { + lua_rawset(L, 1); + } + + return 0; +} + /////////////////// // gamekeydown[] // /////////////////// @@ -282,6 +304,9 @@ int LUA_InputLib(lua_State *L) lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_get); lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_set); + lua_setfield(L, -2, "__newindex"); lua_setmetatable(L, -2); lua_newuserdata(L, 0); diff --git a/src/lua_libs.h b/src/lua_libs.h index 7f8d21f38..2e3c70652 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -13,6 +13,7 @@ extern lua_State *gL; extern boolean mousegrabbedbylua; +extern boolean ignoregameinputs; #define MUTABLE_TAGS From bc9a378521f2d63dc46b75579b9cce63f3b7e0e5 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 27 Oct 2023 20:17:27 +0200 Subject: [PATCH 56/91] Refactor userdata metatable registration --- src/lua_consolelib.c | 5 +- src/lua_hudlib.c | 40 ++--------- src/lua_infolib.c | 107 +++------------------------- src/lua_inputlib.c | 14 +--- src/lua_maplib.c | 163 ++++++------------------------------------- src/lua_mobjlib.c | 39 ++--------- src/lua_playerlib.c | 33 +-------- src/lua_polyobjlib.c | 29 +------- src/lua_script.c | 29 ++++++++ src/lua_script.h | 8 +++ src/lua_skinlib.c | 35 ++-------- 11 files changed, 89 insertions(+), 413 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 0ab8ad9c3..b34105004 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -626,10 +626,7 @@ static int cvar_get(lua_State *L) int LUA_ConsoleLib(lua_State *L) { // Metatable for consvar_t - luaL_newmetatable(L, META_CVAR); - lua_pushcfunction(L, cvar_get); - lua_setfield(L, -2, "__index"); - lua_pop(L,1); + LUA_RegisterUserdataMetatable(L, META_CVAR, cvar_get, NULL, NULL); cvar_fields_ref = Lua_CreateFieldTable(L, cvar_opt); diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 6eec91273..ed0ec86f8 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1404,16 +1404,13 @@ int LUA_HudLib(lua_State *L) luaL_register(L, NULL, lib_draw); lib_draw_ref = luaL_ref(L, LUA_REGISTRYINDEX); - luaL_newmetatable(L, META_HUDINFO); - lua_pushcfunction(L, hudinfo_get); - lua_setfield(L, -2, "__index"); + LUA_RegisterUserdataMetatable(L, META_HUDINFO, hudinfo_get, hudinfo_set, hudinfo_num); + LUA_RegisterUserdataMetatable(L, META_COLORMAP, colormap_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_PATCH, patch_get, patch_set, NULL); + LUA_RegisterUserdataMetatable(L, META_CAMERA, camera_get, camera_set, NULL); - lua_pushcfunction(L, hudinfo_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, hudinfo_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); + patch_fields_ref = Lua_CreateFieldTable(L, patch_opt); + camera_fields_ref = Lua_CreateFieldTable(L, camera_opt); lua_newuserdata(L, 0); lua_createtable(L, 0, 2); @@ -1425,31 +1422,6 @@ int LUA_HudLib(lua_State *L) lua_setmetatable(L, -2); lua_setglobal(L, "hudinfo"); - luaL_newmetatable(L, META_COLORMAP); - lua_pushcfunction(L, colormap_get); - lua_setfield(L, -2, "__index"); - lua_pop(L,1); - - luaL_newmetatable(L, META_PATCH); - lua_pushcfunction(L, patch_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, patch_set); - 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_pushcfunction(L, camera_set); - lua_setfield(L, -2, "__newindex"); - 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 3764acf6a..6b15cc33f 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -1914,96 +1914,18 @@ int LUA_InfoLib(lua_State *L) lua_newtable(L); lua_setfield(L, LUA_REGISTRYINDEX, LREG_ACTIONS); - luaL_newmetatable(L, META_STATE); - lua_pushcfunction(L, state_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, state_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, state_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_MOBJINFO); - lua_pushcfunction(L, mobjinfo_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, mobjinfo_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, mobjinfo_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); + LUA_RegisterUserdataMetatable(L, META_STATE, state_get, state_set, state_num); + LUA_RegisterUserdataMetatable(L, META_MOBJINFO, mobjinfo_get, mobjinfo_set, mobjinfo_num); + LUA_RegisterUserdataMetatable(L, META_SKINCOLOR, skincolor_get, skincolor_set, skincolor_num); + LUA_RegisterUserdataMetatable(L, META_COLORRAMP, colorramp_get, colorramp_set, colorramp_len); + LUA_RegisterUserdataMetatable(L, META_SFXINFO, sfxinfo_get, sfxinfo_set, sfxinfo_num); + LUA_RegisterUserdataMetatable(L, META_SPRITEINFO, spriteinfo_get, spriteinfo_set, spriteinfo_num); + LUA_RegisterUserdataMetatable(L, META_PIVOTLIST, pivotlist_get, pivotlist_set, pivotlist_num); + LUA_RegisterUserdataMetatable(L, META_FRAMEPIVOT, framepivot_get, framepivot_set, framepivot_num); + LUA_RegisterUserdataMetatable(L, META_LUABANKS, lib_getluabanks, lib_setluabanks, lib_luabankslen); mobjinfo_fields_ref = Lua_CreateFieldTable(L, mobjinfo_opt); - luaL_newmetatable(L, META_SKINCOLOR); - lua_pushcfunction(L, skincolor_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, skincolor_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, skincolor_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_COLORRAMP); - lua_pushcfunction(L, colorramp_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, colorramp_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, colorramp_len); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); - - luaL_newmetatable(L, META_SFXINFO); - lua_pushcfunction(L, sfxinfo_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, sfxinfo_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, sfxinfo_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_SPRITEINFO); - lua_pushcfunction(L, spriteinfo_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, spriteinfo_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, spriteinfo_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_PIVOTLIST); - lua_pushcfunction(L, pivotlist_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, pivotlist_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, pivotlist_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_FRAMEPIVOT); - lua_pushcfunction(L, framepivot_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, framepivot_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, framepivot_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSprname); @@ -2104,16 +2026,5 @@ int LUA_InfoLib(lua_State *L) lua_setmetatable(L, -2); lua_setglobal(L, "spriteinfo"); - luaL_newmetatable(L, META_LUABANKS); - lua_pushcfunction(L, lib_getluabanks); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setluabanks); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_luabankslen); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - return 0; } diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index eeb61fed7..34b44e3af 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -285,18 +285,8 @@ static int mouse_num(lua_State *L) int LUA_InputLib(lua_State *L) { - luaL_newmetatable(L, META_KEYEVENT); - lua_pushcfunction(L, keyevent_get); - lua_setfield(L, -2, "__index"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_MOUSE); - lua_pushcfunction(L, mouse_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, mouse_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); + LUA_RegisterUserdataMetatable(L, META_KEYEVENT, keyevent_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_MOUSE, mouse_get, NULL, mouse_num); // Register the library, then add __index and __newindex // metamethods to it to allow global variables diff --git a/src/lua_maplib.c b/src/lua_maplib.c index e34397993..998615850 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -2843,120 +2843,37 @@ static int mapheaderinfo_get(lua_State *L) int LUA_MapLib(lua_State *L) { - luaL_newmetatable(L, META_SECTORLINES); - lua_pushcfunction(L, sectorlines_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, sectorlines_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_SECTOR); - lua_pushcfunction(L, sector_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, sector_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, sector_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); + LUA_RegisterUserdataMetatable(L, META_SECTORLINES, sectorlines_get, NULL, sectorlines_num); + LUA_RegisterUserdataMetatable(L, META_SECTOR, sector_get, sector_set, sector_num); + LUA_RegisterUserdataMetatable(L, META_SUBSECTOR, subsector_get, NULL, subsector_num); + LUA_RegisterUserdataMetatable(L, META_LINE, line_get, NULL, line_num); + LUA_RegisterUserdataMetatable(L, META_LINEARGS, lineargs_get, NULL, lineargs_len); + LUA_RegisterUserdataMetatable(L, META_LINESTRINGARGS, linestringargs_get, NULL, linestringargs_len); + LUA_RegisterUserdataMetatable(L, META_SIDENUM, sidenum_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_SIDE, side_get, side_set, side_num); + LUA_RegisterUserdataMetatable(L, META_VERTEX, vertex_get, NULL, vertex_num); + LUA_RegisterUserdataMetatable(L, META_FFLOOR, ffloor_get, ffloor_set, NULL); + LUA_RegisterUserdataMetatable(L, META_BBOX, bbox_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_SLOPE, slope_get, slope_set, NULL); + LUA_RegisterUserdataMetatable(L, META_VECTOR2, vector2_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_VECTOR3, vector3_get, NULL, NULL); + LUA_RegisterUserdataMetatable(L, META_MAPHEADER, mapheaderinfo_get, NULL, NULL); sector_fields_ref = Lua_CreateFieldTable(L, sector_opt); - - luaL_newmetatable(L, META_SUBSECTOR); - lua_pushcfunction(L, subsector_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, subsector_num); - 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"); - - lua_pushcfunction(L, line_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - line_fields_ref = Lua_CreateFieldTable(L, line_opt); - - luaL_newmetatable(L, META_LINEARGS); - lua_pushcfunction(L, lineargs_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lineargs_len); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_LINESTRINGARGS); - lua_pushcfunction(L, linestringargs_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, linestringargs_len); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_SIDENUM); - lua_pushcfunction(L, sidenum_get); - lua_setfield(L, -2, "__index"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_SIDE); - lua_pushcfunction(L, side_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, side_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, side_num); - 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"); - - lua_pushcfunction(L, vertex_num); - 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"); - - lua_pushcfunction(L, ffloor_set); - lua_setfield(L, -2, "__newindex"); - lua_pop(L, 1); - ffloor_fields_ref = Lua_CreateFieldTable(L, ffloor_opt); + slope_fields_ref = Lua_CreateFieldTable(L, slope_opt); + mapheaderinfo_fields_ref = Lua_CreateFieldTable(L, mapheaderinfo_opt); #ifdef HAVE_LUA_SEGS - luaL_newmetatable(L, META_SEG); - lua_pushcfunction(L, seg_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, seg_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); + LUA_RegisterUserdataMetatable(L, META_SEG, seg_get, NULL, seg_num); + LUA_RegisterUserdataMetatable(L, META_NODE, node_get, NULL, node_num); + LUA_RegisterUserdataMetatable(L, META_NODECHILDREN, nodechildren_get, NULL, NULL); seg_fields_ref = Lua_CreateFieldTable(L, seg_opt); - - luaL_newmetatable(L, META_NODE); - lua_pushcfunction(L, node_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, node_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - node_fields_ref = Lua_CreateFieldTable(L, node_opt); luaL_newmetatable(L, META_NODEBBOX); @@ -2965,48 +2882,8 @@ int LUA_MapLib(lua_State *L) lua_pushcfunction(L, nodebbox_call); lua_setfield(L, -2, "__call"); lua_pop(L, 1); - - luaL_newmetatable(L, META_NODECHILDREN); - lua_pushcfunction(L, nodechildren_get); - lua_setfield(L, -2, "__index"); - lua_pop(L, 1); #endif - luaL_newmetatable(L, META_BBOX); - lua_pushcfunction(L, bbox_get); - lua_setfield(L, -2, "__index"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_SLOPE); - lua_pushcfunction(L, slope_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, slope_set); - 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"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_VECTOR3); - lua_pushcfunction(L, vector3_get); - lua_setfield(L, -2, "__index"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_MAPHEADER); - lua_pushcfunction(L, mapheaderinfo_get); - lua_setfield(L, -2, "__index"); - - //lua_pushcfunction(L, mapheaderinfo_num); - //lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - mapheaderinfo_fields_ref = Lua_CreateFieldTable(L, mapheaderinfo_opt); - LUA_PushTaggableObjectArray(L, "sectors", lib_iterateSectors, lib_getSector, diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index fddf958be..19f30b70e 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -1163,43 +1163,12 @@ static int lib_nummapthings(lua_State *L) int LUA_MobjLib(lua_State *L) { - luaL_newmetatable(L, META_MOBJ); - lua_pushcfunction(L, mobj_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, mobj_set); - lua_setfield(L, -2, "__newindex"); - lua_pop(L,1); + LUA_RegisterUserdataMetatable(L, META_MOBJ, mobj_get, mobj_set, NULL); + LUA_RegisterUserdataMetatable(L, META_THINGARGS, thingargs_get, NULL, thingargs_len); + LUA_RegisterUserdataMetatable(L, META_THINGSTRINGARGS, thingstringargs_get, NULL, thingstringargs_len); + LUA_RegisterUserdataMetatable(L, META_MAPTHING, mapthing_get, mapthing_set, mapthing_num); mobj_fields_ref = Lua_CreateFieldTable(L, mobj_opt); - - luaL_newmetatable(L, META_THINGARGS); - lua_pushcfunction(L, thingargs_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, thingargs_len); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_THINGSTRINGARGS); - lua_pushcfunction(L, thingstringargs_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, thingstringargs_len); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_MAPTHING); - lua_pushcfunction(L, mapthing_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, mapthing_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, mapthing_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); - mapthing_fields_ref = Lua_CreateFieldTable(L, mapthing_opt); LUA_PushTaggableObjectArray(L, "mapthings", diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 827e5a405..975025c44 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -1523,38 +1523,11 @@ static int ticcmd_set(lua_State *L) int LUA_PlayerLib(lua_State *L) { - luaL_newmetatable(L, META_PLAYER); - lua_pushcfunction(L, player_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, player_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, player_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); + LUA_RegisterUserdataMetatable(L, META_PLAYER, player_get, player_set, player_num); + LUA_RegisterUserdataMetatable(L, META_POWERS, power_get, power_set, power_len); + LUA_RegisterUserdataMetatable(L, META_TICCMD, ticcmd_get, ticcmd_set, NULL); player_fields_ref = Lua_CreateFieldTable(L, player_opt); - - luaL_newmetatable(L, META_POWERS); - lua_pushcfunction(L, power_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, power_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, power_len); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); - - luaL_newmetatable(L, META_TICCMD); - lua_pushcfunction(L, ticcmd_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, ticcmd_set); - lua_setfield(L, -2, "__newindex"); - lua_pop(L,1); - ticcmd_fields_ref = Lua_CreateFieldTable(L, ticcmd_opt); lua_newuserdata(L, 0); diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index c3d9d9d1a..d011ccfaa 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -447,32 +447,9 @@ static int lib_numPolyObjects(lua_State *L) int LUA_PolyObjLib(lua_State *L) { - luaL_newmetatable(L, META_POLYOBJVERTICES); - lua_pushcfunction(L, polyobjvertices_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, polyobjvertices_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_POLYOBJLINES); - lua_pushcfunction(L, polyobjlines_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, polyobjlines_num); - lua_setfield(L, -2, "__len"); - lua_pop(L, 1); - - luaL_newmetatable(L, META_POLYOBJ); - lua_pushcfunction(L, polyobj_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, polyobj_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, polyobj_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); + LUA_RegisterUserdataMetatable(L, META_POLYOBJVERTICES, polyobjvertices_get, NULL, polyobjvertices_num); + LUA_RegisterUserdataMetatable(L, META_POLYOBJLINES, polyobjlines_get, NULL, polyobjlines_num); + LUA_RegisterUserdataMetatable(L, META_POLYOBJ, polyobj_get, polyobj_set, polyobj_num); lua_newuserdata(L, 0); lua_createtable(L, 0, 2); diff --git a/src/lua_script.c b/src/lua_script.c index 9e106999d..562114583 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1832,3 +1832,32 @@ void LUA_PushTaggableObjectArray lua_setmetatable(L, -2); lua_setglobal(L, field); } + +void LUA_RegisterUserdataMetatable( + lua_State *L, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len +) +{ + luaL_newmetatable(L, name); + + if (get) + { + lua_pushcfunction(L, get); + lua_setfield(L, -2, "__index"); + } + if (set) + { + lua_pushcfunction(L, set); + lua_setfield(L, -2, "__newindex"); + } + if (len) + { + lua_pushcfunction(L, len); + lua_setfield(L, -2, "__len"); + } + + lua_pop(L, 1); +} diff --git a/src/lua_script.h b/src/lua_script.h index d0b06a719..8a4eb9f13 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -73,6 +73,14 @@ void LUA_PushTaggableObjectArray size_t sizeof_element, const char *meta); +void LUA_RegisterUserdataMetatable( + lua_State *L, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len +); + void LUA_InsertTaggroupIterator ( lua_State *L, taggroup_t *garray[], diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index 041c5d598..6c41758b1 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -373,40 +373,13 @@ static int sprite_get(lua_State *L) int LUA_SkinLib(lua_State *L) { - luaL_newmetatable(L, META_SKIN); - lua_pushcfunction(L, skin_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, skin_set); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, skin_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); + LUA_RegisterUserdataMetatable(L, META_SKIN, skin_get, skin_set, skin_num); + LUA_RegisterUserdataMetatable(L, META_SOUNDSID, soundsid_get, NULL, soundsid_num); + LUA_RegisterUserdataMetatable(L, META_SKINSPRITES, lib_getSkinSprite, NULL, lib_numSkinsSprites); + LUA_RegisterUserdataMetatable(L, META_SKINSPRITESLIST, sprite_get, NULL, NULL); skin_fields_ref = Lua_CreateFieldTable(L, skin_opt); - luaL_newmetatable(L, META_SOUNDSID); - lua_pushcfunction(L, soundsid_get); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, soundsid_num); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); - - luaL_newmetatable(L, META_SKINSPRITES); - lua_pushcfunction(L, lib_getSkinSprite); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numSkinsSprites); - lua_setfield(L, -2, "__len"); - lua_pop(L,1); - - luaL_newmetatable(L, META_SKINSPRITESLIST); - lua_pushcfunction(L, sprite_get); - lua_setfield(L, -2, "__index"); - lua_pop(L,1); - lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSkin); From 7a7d4f832a3d1ad18949bc02bda04dea7296398f Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Fri, 27 Oct 2023 21:34:53 +0200 Subject: [PATCH 57/91] Remove stupid whitespace --- src/lua_maplib.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 998615850..a0a7120a2 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -35,7 +35,7 @@ enum sector_e { sector_floorpic, sector_floorxoffset, sector_flooryoffset, - sector_floorangle, + sector_floorangle, sector_ceilingpic, sector_ceilingxoffset, sector_ceilingyoffset, @@ -43,7 +43,7 @@ enum sector_e { sector_lightlevel, sector_floorlightlevel, sector_floorlightabsolute, - sector_floorlightsec, + sector_floorlightsec, sector_ceilinglightlevel, sector_ceilinglightabsolute, sector_ceilinglightsec, @@ -77,14 +77,14 @@ static const char *const sector_opt[] = { "ceilingpic", "ceilingxoffset", "ceilingyoffset", - "ceilingangle", + "ceilingangle", "lightlevel", "floorlightlevel", "floorlightabsolute", "floorlightsec", "ceilinglightlevel", "ceilinglightabsolute", - "ceilinglightsec", + "ceilinglightsec", "special", "tag", "taglist", @@ -663,11 +663,11 @@ static int sector_get(lua_State *L) lua_pushfixed(L, sector->flooryoffset); return 1; } - case sector_floorangle: + case sector_floorangle: { lua_pushangle(L, sector->floorangle); return 1; - } + } case sector_ceilingpic: // ceilingpic { levelflat_t *levelflat = &levelflats[sector->ceilingpic]; @@ -691,7 +691,7 @@ static int sector_get(lua_State *L) { lua_pushangle(L, sector->ceilingangle); return 1; - } + } case sector_lightlevel: lua_pushinteger(L, sector->lightlevel); return 1; @@ -703,7 +703,7 @@ static int sector_get(lua_State *L) return 1; case sector_floorlightsec: lua_pushinteger(L, sector->floorlightsec); - return 1; + return 1; case sector_ceilinglightlevel: lua_pushinteger(L, sector->ceilinglightlevel); return 1; @@ -712,7 +712,7 @@ static int sector_get(lua_State *L) return 1; case sector_ceilinglightsec: lua_pushinteger(L, sector->ceilinglightsec); - return 1; + return 1; case sector_special: lua_pushinteger(L, sector->special); return 1; @@ -842,7 +842,7 @@ static int sector_set(lua_State *L) break; case sector_floorangle: sector->floorangle = luaL_checkangle(L, 3); - break; + break; case sector_ceilingpic: sector->ceilingpic = P_AddLevelFlatRuntime(luaL_checkstring(L, 3)); break; @@ -866,7 +866,7 @@ static int sector_set(lua_State *L) break; case sector_floorlightsec: sector->floorlightsec = (INT32)luaL_checkinteger(L, 3); - break; + break; case sector_ceilinglightlevel: sector->ceilinglightlevel = (INT16)luaL_checkinteger(L, 3); break; @@ -875,7 +875,7 @@ static int sector_set(lua_State *L) break; case sector_ceilinglightsec: sector->ceilinglightsec = (INT32)luaL_checkinteger(L, 3); - break; + break; case sector_special: sector->special = (INT16)luaL_checkinteger(L, 3); break; From d1dbdee016631a62dd9883bc01eb777054d7942c Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sat, 28 Oct 2023 00:24:04 +0200 Subject: [PATCH 58/91] Refactor global userdata registration --- src/lua_hudlib.c | 10 +--- src/lua_infolib.c | 109 ++++--------------------------------------- src/lua_inputlib.c | 25 ++-------- src/lua_maplib.c | 101 ++++++++++----------------------------- src/lua_playerlib.c | 10 +--- src/lua_polyobjlib.c | 10 +--- src/lua_script.c | 72 ++++++++++++++++++++++++++-- src/lua_script.h | 26 +++++++++++ src/lua_skinlib.c | 10 +--- src/lua_taglib.c | 17 +++---- 10 files changed, 142 insertions(+), 248 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index ed0ec86f8..666a11abc 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1412,15 +1412,7 @@ int LUA_HudLib(lua_State *L) patch_fields_ref = Lua_CreateFieldTable(L, patch_opt); camera_fields_ref = Lua_CreateFieldTable(L, camera_opt); - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getHudInfo); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_hudinfolen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "hudinfo"); + LUA_RegisterGlobalUserdata(L, "hudinfo", lib_getHudInfo, NULL, lib_hudinfolen); luaL_register(L, "hud", lib_hud); return 0; diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 6b15cc33f..020eba152 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -1926,105 +1926,16 @@ int LUA_InfoLib(lua_State *L) mobjinfo_fields_ref = Lua_CreateFieldTable(L, mobjinfo_opt); - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSprname); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_sprnamelen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "sprnames"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSpr2name); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_spr2namelen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "spr2names"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSpr2default); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setSpr2default); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_spr2namelen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "spr2defaults"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getState); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setState); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_statelen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "states"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getMobjInfo); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setMobjInfo); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_mobjinfolen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "mobjinfo"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSkinColor); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setSkinColor); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_skincolorslen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "skincolors"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSfxInfo); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setSfxInfo); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_sfxlen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_pushvalue(L, -1); - lua_setglobal(L, "S_sfx"); - lua_setglobal(L, "sfxinfo"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSpriteInfo); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setSpriteInfo); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_spriteinfolen); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "spriteinfo"); + LUA_RegisterGlobalUserdata(L, "sprnames", lib_getSprname, NULL, lib_sprnamelen); + LUA_RegisterGlobalUserdata(L, "spr2names", lib_getSpr2name, NULL, lib_spr2namelen); + LUA_RegisterGlobalUserdata(L, "spr2defaults", lib_getSpr2default, lib_setSpr2default, lib_spr2namelen); + LUA_RegisterGlobalUserdata(L, "states", lib_getState, lib_setState, lib_statelen); + LUA_RegisterGlobalUserdata(L, "mobjinfo", lib_getMobjInfo, lib_setMobjInfo, lib_mobjinfolen); + LUA_RegisterGlobalUserdata(L, "skincolors", lib_getSkinColor, lib_setSkinColor, lib_skincolorslen); + LUA_RegisterGlobalUserdata(L, "spriteinfo", lib_getSpriteInfo, lib_setSpriteInfo, lib_spriteinfolen); + LUA_RegisterGlobalUserdata(L, "sfxinfo", lib_getSfxInfo, lib_setSfxInfo, lib_sfxlen); + // TODO: 2.3: Delete this alias + LUA_RegisterGlobalUserdata(L, "S_sfx", lib_getSfxInfo, lib_setSfxInfo, lib_sfxlen); return 0; } diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index 34b44e3af..ef3a9011f 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -291,28 +291,11 @@ int LUA_InputLib(lua_State *L) // Register the library, then add __index and __newindex // metamethods to it to allow global variables luaL_register(L, "input", lib); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_get); - lua_setfield(L, -2, "__index"); + LUA_CreateAndSetMetatable(L, lib_get, lib_set, NULL, false); - lua_pushcfunction(L, lib_set); - lua_setfield(L, -2, "__newindex"); - lua_setmetatable(L, -2); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getGameKeyDown); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_setGameKeyDown); - lua_setfield(L, -2, "__newindex"); - - lua_pushcfunction(L, lib_lenGameKeyDown); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_pushvalue(L, -1); // TODO: 2.3: Delete (gamekeydown moved to input library) - lua_setglobal(L, "gamekeydown"); // Delete too - lua_setfield(L, -2, "gamekeydown"); + LUA_CreateAndSetUserdataField(L, -1, "gamekeydown", lib_getGameKeyDown, lib_setGameKeyDown, lib_lenGameKeyDown, false); + // TODO: 2.3: Delete this alias (moved to input library) + LUA_RegisterGlobalUserdata(L, "gamekeydown", lib_getGameKeyDown, lib_setGameKeyDown, lib_lenGameKeyDown); lua_pop(L, 1); return 0; diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a0a7120a2..2e1aab3eb 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -2868,6 +2868,27 @@ int LUA_MapLib(lua_State *L) slope_fields_ref = Lua_CreateFieldTable(L, slope_opt); mapheaderinfo_fields_ref = Lua_CreateFieldTable(L, mapheaderinfo_opt); + LUA_RegisterGlobalUserdata(L, "subsectors", lib_getSubsector, NULL, lib_numsubsectors); + LUA_RegisterGlobalUserdata(L, "sides", lib_getSide, NULL, lib_numsides); + LUA_RegisterGlobalUserdata(L, "vertexes", lib_getVertex, NULL, lib_numvertexes); + LUA_RegisterGlobalUserdata(L, "mapheaderinfo", lib_getMapheaderinfo, NULL, lib_nummapheaders); + + LUA_PushTaggableObjectArray(L, "sectors", + lib_iterateSectors, + lib_getSector, + lib_numsectors, + tags_sectors, + &numsectors, §ors, + sizeof (sector_t), META_SECTOR); + + LUA_PushTaggableObjectArray(L, "lines", + lib_iterateLines, + lib_getLine, + lib_numlines, + tags_lines, + &numlines, &lines, + sizeof (line_t), META_LINE); + #ifdef HAVE_LUA_SEGS LUA_RegisterUserdataMetatable(L, META_SEG, seg_get, NULL, seg_num); LUA_RegisterUserdataMetatable(L, META_NODE, node_get, NULL, node_num); @@ -2882,84 +2903,10 @@ int LUA_MapLib(lua_State *L) lua_pushcfunction(L, nodebbox_call); lua_setfield(L, -2, "__call"); lua_pop(L, 1); + + LUA_RegisterGlobalUserdata(L, "segs", lib_getSeg, NULL, lib_numsegs); + LUA_RegisterGlobalUserdata(L, "nodes", lib_getNode, NULL, lib_numnodes); #endif - LUA_PushTaggableObjectArray(L, "sectors", - lib_iterateSectors, - lib_getSector, - lib_numsectors, - tags_sectors, - &numsectors, §ors, - sizeof (sector_t), META_SECTOR); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSubsector); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numsubsectors); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "subsectors"); - - LUA_PushTaggableObjectArray(L, "lines", - lib_iterateLines, - lib_getLine, - lib_numlines, - tags_lines, - &numlines, &lines, - sizeof (line_t), META_LINE); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSide); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numsides); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "sides"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getVertex); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numvertexes); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "vertexes"); - -#ifdef HAVE_LUA_SEGS - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSeg); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numsegs); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "segs"); - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getNode); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numnodes); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "nodes"); -#endif - - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getMapheaderinfo); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_nummapheaders); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "mapheaderinfo"); return 0; } diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 975025c44..ac829d0c4 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -1530,14 +1530,6 @@ int LUA_PlayerLib(lua_State *L) player_fields_ref = Lua_CreateFieldTable(L, player_opt); ticcmd_fields_ref = Lua_CreateFieldTable(L, ticcmd_opt); - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getPlayer); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_lenPlayer); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "players"); + LUA_RegisterGlobalUserdata(L, "players", lib_getPlayer, NULL, lib_lenPlayer); return 0; } diff --git a/src/lua_polyobjlib.c b/src/lua_polyobjlib.c index d011ccfaa..6c016f8b2 100644 --- a/src/lua_polyobjlib.c +++ b/src/lua_polyobjlib.c @@ -451,14 +451,6 @@ int LUA_PolyObjLib(lua_State *L) LUA_RegisterUserdataMetatable(L, META_POLYOBJLINES, polyobjlines_get, NULL, polyobjlines_num); LUA_RegisterUserdataMetatable(L, META_POLYOBJ, polyobj_get, polyobj_set, polyobj_num); - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getPolyObject); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numPolyObjects); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "polyobjects"); + LUA_RegisterGlobalUserdata(L, "polyobjects", lib_getPolyObject, NULL, lib_numPolyObjects); return 0; } diff --git a/src/lua_script.c b/src/lua_script.c index 562114583..9aea96ac7 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1833,16 +1833,13 @@ void LUA_PushTaggableObjectArray lua_setglobal(L, field); } -void LUA_RegisterUserdataMetatable( +static void SetBasicMetamethods( lua_State *L, - const char *name, lua_CFunction get, lua_CFunction set, lua_CFunction len ) { - luaL_newmetatable(L, name); - if (get) { lua_pushcfunction(L, get); @@ -1858,6 +1855,73 @@ void LUA_RegisterUserdataMetatable( lua_pushcfunction(L, len); lua_setfield(L, -2, "__len"); } +} +void LUA_RegisterUserdataMetatable( + lua_State *L, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len +) +{ + luaL_newmetatable(L, name); + SetBasicMetamethods(L, get, set, len); lua_pop(L, 1); } + +// If keep is true, leaves the metatable on the stack. +// Otherwise, the stack size remains unchanged. +void LUA_CreateAndSetMetatable( + lua_State *L, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len, + boolean keep +) +{ + lua_newtable(L); + SetBasicMetamethods(L, get, set, len); + + lua_pushvalue(L, -1); + lua_setmetatable(L, -3); + + if (!keep) + lua_pop(L, 1); +} + +// If keep is true, leaves the userdata and metatable on the stack. +// Otherwise, the stack size remains unchanged. +void LUA_CreateAndSetUserdataField( + lua_State *L, + int index, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len, + boolean keep +) +{ + if (index < 0 && index > LUA_REGISTRYINDEX) + index -= 3; + + lua_newuserdata(L, 0); + LUA_CreateAndSetMetatable(L, get, set, len, true); + + lua_pushvalue(L, -2); + lua_setfield(L, index, name); + + if (!keep) + lua_pop(L, 2); +} + +void LUA_RegisterGlobalUserdata( + lua_State *L, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len +) +{ + LUA_CreateAndSetUserdataField(L, LUA_GLOBALSINDEX, name, get, set, len, false); +} diff --git a/src/lua_script.h b/src/lua_script.h index 8a4eb9f13..dd9a2568e 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -81,6 +81,32 @@ void LUA_RegisterUserdataMetatable( lua_CFunction len ); +void LUA_CreateAndSetMetatable( + lua_State *L, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len, + boolean keep +); + +void LUA_CreateAndSetUserdataField( + lua_State *L, + int index, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len, + boolean keep +); + +void LUA_RegisterGlobalUserdata( + lua_State *L, + const char *name, + lua_CFunction get, + lua_CFunction set, + lua_CFunction len +); + void LUA_InsertTaggroupIterator ( lua_State *L, taggroup_t *garray[], diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index 6c41758b1..3debd3746 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -380,15 +380,7 @@ int LUA_SkinLib(lua_State *L) skin_fields_ref = Lua_CreateFieldTable(L, skin_opt); - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_pushcfunction(L, lib_getSkin); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numSkins); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "skins"); + LUA_RegisterGlobalUserdata(L, "skins", lib_getSkin, NULL, lib_numSkins); return 0; } diff --git a/src/lua_taglib.c b/src/lua_taglib.c index 2ba60df99..5ed457534 100644 --- a/src/lua_taglib.c +++ b/src/lua_taglib.c @@ -426,17 +426,12 @@ set_taglist_metatable(lua_State *L, const char *meta) int LUA_TagLib(lua_State *L) { - lua_newuserdata(L, 0); - lua_createtable(L, 0, 2); - lua_createtable(L, 0, 1); - lua_pushcfunction(L, lib_iterateTags); - lua_setfield(L, -2, "iterate"); - lua_setfield(L, -2, "__index"); - - lua_pushcfunction(L, lib_numTags); - lua_setfield(L, -2, "__len"); - lua_setmetatable(L, -2); - lua_setglobal(L, "tags"); + LUA_CreateAndSetUserdataField(L, LUA_GLOBALSINDEX, "tags", NULL, NULL, lib_numTags, true); + lua_createtable(L, 0, 1); + lua_pushcfunction(L, lib_iterateTags); + lua_setfield(L, -2, "iterate"); + lua_setfield(L, -2, "__index"); + lua_pop(L, 2); open_taglist(L); From c3f79a112f3ec5cff160f9040196d284ffd4f9d8 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sat, 28 Oct 2023 11:06:30 +0200 Subject: [PATCH 59/91] Add LUA_SetCFunctionField --- src/deh_lua.c | 3 +-- src/lua_baselib.c | 3 +-- src/lua_maplib.c | 6 ++---- src/lua_script.c | 33 +++++++++++++-------------------- src/lua_script.h | 2 ++ src/lua_taglib.c | 12 ++++-------- src/lua_thinkerlib.c | 3 +-- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/deh_lua.c b/src/deh_lua.c index 0b789547b..7188d25e3 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -771,8 +771,7 @@ int LUA_SOCLib(lua_State *L) lua_register(L,"getActionName",lib_getActionName); luaL_newmetatable(L, META_ACTION); - lua_pushcfunction(L, action_call); - lua_setfield(L, -2, "__call"); + LUA_SetCFunctionField(L, "__call", action_call); lua_pop(L, 1); return 0; diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1821550b8..f7ed763a9 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -4300,8 +4300,7 @@ int LUA_BaseLib(lua_State *L) // Set metatable for string lua_pushliteral(L, ""); // dummy string lua_getmetatable(L, -1); // get string metatable - lua_pushcfunction(L,lib_concat); // push concatination function - lua_setfield(L,-2,"__add"); // ... store it as mathematical addition + LUA_SetCFunctionField(L, "__add", lib_concat); lua_pop(L, 2); // pop metatable and dummy string lua_newtable(L); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 2e1aab3eb..efa2edf20 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -2898,10 +2898,8 @@ int LUA_MapLib(lua_State *L) node_fields_ref = Lua_CreateFieldTable(L, node_opt); luaL_newmetatable(L, META_NODEBBOX); - //lua_pushcfunction(L, nodebbox_get); - //lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, nodebbox_call); - lua_setfield(L, -2, "__call"); + //LUA_SetCFunctionField(L, "__index", nodebbox_get); + LUA_SetCFunctionField(L, "__call", nodebbox_call); lua_pop(L, 1); LUA_RegisterGlobalUserdata(L, "segs", lib_getSeg, NULL, lib_numsegs); diff --git a/src/lua_script.c b/src/lua_script.c index 9aea96ac7..5cacc3f01 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -578,8 +578,7 @@ static void LUA_ClearState(void) // lock the global namespace lua_getmetatable(L, LUA_GLOBALSINDEX); - lua_pushcfunction(L, setglobals); - lua_setfield(L, -2, "__newindex"); + LUA_SetCFunctionField(L, "__newindex", setglobals); lua_newtable(L); lua_setfield(L, -2, "__metatable"); lua_pop(L, 1); @@ -1815,20 +1814,17 @@ void LUA_PushTaggableObjectArray lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_createtable(L, 0, 2); - lua_pushcfunction(L, iterator); - lua_setfield(L, -2, "iterate"); + LUA_SetCFunctionField(L, "iterate", iterator); LUA_InsertTaggroupIterator(L, garray, max_elements, element_array, sizeof_element, meta); lua_createtable(L, 0, 1); - lua_pushcfunction(L, indexer); - lua_setfield(L, -2, "__index"); + LUA_SetCFunctionField(L, "__index", indexer); lua_setmetatable(L, -2); lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, counter); - lua_setfield(L, -2, "__len"); + LUA_SetCFunctionField(L, "__len", counter); lua_setmetatable(L, -2); lua_setglobal(L, field); } @@ -1841,20 +1837,17 @@ static void SetBasicMetamethods( ) { if (get) - { - lua_pushcfunction(L, get); - lua_setfield(L, -2, "__index"); - } + LUA_SetCFunctionField(L, "__index", get); if (set) - { - lua_pushcfunction(L, set); - lua_setfield(L, -2, "__newindex"); - } + LUA_SetCFunctionField(L, "__newindex", set); if (len) - { - lua_pushcfunction(L, len); - lua_setfield(L, -2, "__len"); - } + LUA_SetCFunctionField(L, "__len", len); +} + +void LUA_SetCFunctionField(lua_State *L, const char *name, lua_CFunction value) +{ + lua_pushcfunction(L, value); + lua_setfield(L, -2, name); } void LUA_RegisterUserdataMetatable( diff --git a/src/lua_script.h b/src/lua_script.h index dd9a2568e..53d848f8e 100644 --- a/src/lua_script.h +++ b/src/lua_script.h @@ -73,6 +73,8 @@ void LUA_PushTaggableObjectArray size_t sizeof_element, const char *meta); +void LUA_SetCFunctionField(lua_State *L, const char *name, lua_CFunction value); + void LUA_RegisterUserdataMetatable( lua_State *L, const char *name, diff --git a/src/lua_taglib.c b/src/lua_taglib.c index 5ed457534..9e73a050c 100644 --- a/src/lua_taglib.c +++ b/src/lua_taglib.c @@ -372,8 +372,7 @@ void LUA_InsertTaggroupIterator lua_pushcclosure(L, lib_numTaggroupElements, 2); lua_setfield(L, -2, "__len"); - lua_pushcfunction(L, element_iterator); - lua_setfield(L, -2, "__call"); + LUA_SetCFunctionField(L, "__call", element_iterator); lua_pushcclosure(L, lib_getTaggroup, 1); lua_setfield(L, -2, "tagged"); } @@ -414,11 +413,9 @@ set_taglist_metatable(lua_State *L, const char *meta) lua_setfenv(L, -2); lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, taglist_len); - lua_setfield(L, -2, "__len"); + LUA_SetCFunctionField(L, "__len", taglist_len); - lua_pushcfunction(L, taglist_equal); - lua_setfield(L, -2, "__eq"); + LUA_SetCFunctionField(L, "__eq", taglist_equal); #ifdef MUTABLE_TAGS return luaL_ref(L, LUA_REGISTRYINDEX); #endif @@ -428,8 +425,7 @@ int LUA_TagLib(lua_State *L) { LUA_CreateAndSetUserdataField(L, LUA_GLOBALSINDEX, "tags", NULL, NULL, lib_numTags, true); lua_createtable(L, 0, 1); - lua_pushcfunction(L, lib_iterateTags); - lua_setfield(L, -2, "iterate"); + LUA_SetCFunctionField(L, "iterate", lib_iterateTags); lua_setfield(L, -2, "__index"); lua_pop(L, 2); diff --git a/src/lua_thinkerlib.c b/src/lua_thinkerlib.c index cff92f34d..f1be8c789 100644 --- a/src/lua_thinkerlib.c +++ b/src/lua_thinkerlib.c @@ -127,8 +127,7 @@ static int lib_startIterate(lua_State *L) int LUA_ThinkerLib(lua_State *L) { luaL_newmetatable(L, META_ITERATIONSTATE); - lua_pushcfunction(L, iterationState_gc); - lua_setfield(L, -2, "__gc"); + LUA_SetCFunctionField(L, "__gc", iterationState_gc); lua_pop(L, 1); lua_createtable(L, 0, 1); From e264caffe3599f37c119aeac91c3e54f16bce9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Fri, 2 Jun 2023 23:44:50 +0200 Subject: [PATCH 60/91] Fix dangling pointer in mapthing after removing mobj --- src/p_mobj.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_mobj.c b/src/p_mobj.c index a81845918..5c352cd04 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11204,6 +11204,10 @@ void P_RemoveMobj(mobj_t *mobj) P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); + // clear the reference from the mapthing + if (mobj->spawnpoint) + mobj->spawnpoint->mobj = NULL; + R_RemoveMobjInterpolator(mobj); // free block From c0146744b7af018a73c29c7df9d57c523841da89 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sat, 28 Oct 2023 14:46:10 +0200 Subject: [PATCH 61/91] Normalise 2.3-related TODO comments --- src/deh_lua.c | 6 ++++-- src/g_game.c | 2 +- src/g_input.c | 2 +- src/lua_maplib.c | 12 +----------- src/lua_playerlib.c | 2 +- src/p_mobj.c | 6 +++--- src/p_saveg.h | 2 +- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/deh_lua.c b/src/deh_lua.c index 7188d25e3..e596e166f 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -297,7 +297,8 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) CacheAndPushConstant(L, word, (lua_Integer)PF_FULLSTASIS); return 1; } - else if (fastcmp(p, "USEDOWN")) // Remove case when 2.3 nears release... + // TODO: 2.3: Delete this alias + else if (fastcmp(p, "USEDOWN")) { CacheAndPushConstant(L, word, (lua_Integer)PF_SPINDOWN); return 1; @@ -583,7 +584,8 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) return 0; } - if (fastcmp(word, "BT_USE")) // Remove case when 2.3 nears release... + // TODO: 2.3: Delete this alias + if (fastcmp(word, "BT_USE")) { CacheAndPushConstant(L, word, (lua_Integer)BT_SPIN); return 1; diff --git a/src/g_game.c b/src/g_game.c index 962c2fd14..438428b90 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4347,7 +4347,7 @@ void G_LoadGameSettings(void) } #define GAMEDATA_ID 0x86E4A27C // Change every major version, as usual -#define COMPAT_GAMEDATA_ID 0xFCAFE211 // Can be removed entirely for 2.3 +#define COMPAT_GAMEDATA_ID 0xFCAFE211 // TODO: 2.3: Delete // G_LoadGameData // Loads the main data file, which stores information such as emblems found, etc. diff --git a/src/g_input.c b/src/g_input.c index 97c0505a3..8b5056331 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -1002,7 +1002,7 @@ static void setcontrol(INT32 (*gc)[2]) INT32 player = ((void*)gc == (void*)&gamecontrolbis ? 1 : 0); boolean nestedoverride = false; - // Update me for 2.3 + // TODO: 2.3: Delete the "use" alias namectrl = (stricmp(COM_Argv(1), "use")) ? COM_Argv(1) : "spin"; for (numctrl = 0; numctrl < NUM_GAMECONTROLS && stricmp(namectrl, gamecontrolname[numctrl]); diff --git a/src/lua_maplib.c b/src/lua_maplib.c index efa2edf20..588a6b4e6 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1043,17 +1043,7 @@ static int line_get(lua_State *L) lua_pushinteger(L, line->special); return 1; case line_tag: - // HELLO - // THIS IS LJ SONIC - // HOW IS YOUR DAY? - // BY THE WAY WHEN 2.3 OR 3.0 OR 4.0 OR SRB3 OR SRB4 OR WHATEVER IS OUT - // YOU SHOULD REMEMBER TO CHANGE THIS SO IT ALWAYS RETURNS A UNSIGNED VALUE - // HAVE A NICE DAY - // - // - // - // - // you are ugly + // TODO: 2.3: Always return a unsigned value lua_pushinteger(L, Tag_FGet(&line->tags)); return 1; case line_taglist: diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index ac829d0c4..66d9c009b 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -407,7 +407,7 @@ static int player_get(lua_State *L) case player_realmo: LUA_PushUserdata(L, plr->mo, META_MOBJ); break; - // Kept for backward-compatibility + // TODO: 2.3: Kept for backward-compatibility // Should be fixed to work like "realmo" later case player_mo: if (plr->spectator) diff --git a/src/p_mobj.c b/src/p_mobj.c index a81845918..1ec46d528 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10571,14 +10571,14 @@ static fixed_t P_DefaultMobjShadowScale (mobj_t *thing) case MT_EXPLOSIONRING: case MT_SCATTERRING: case MT_GRENADERING: - + case MT_BOUNCEPICKUP: case MT_RAILPICKUP: case MT_AUTOPICKUP: case MT_EXPLODEPICKUP: case MT_SCATTERPICKUP: case MT_GRENADEPICKUP: - + case MT_REDRING: case MT_THROWNBOUNCE: case MT_THROWNINFINITY: @@ -13319,7 +13319,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean return true; } -// Pre-UDMF backwards compatibility stuff. Remove for 2.3 +// TODO: 2.3: Delete (Pre-UDMF backwards compatibility stuff) static void P_SetAmbush(mapthing_t *mthing, mobj_t *mobj) { if (mobj->type == MT_NIGHTSBUMPER diff --git a/src/p_saveg.h b/src/p_saveg.h index 73fcfd583..545008e7e 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -18,7 +18,7 @@ #pragma interface #endif -#define NEWSKINSAVES (INT16_MAX) // Purely for backwards compatibility, remove this for 2.3 +#define NEWSKINSAVES (INT16_MAX) // TODO: 2.3: Delete (Purely for backwards compatibility) // Persistent storage/archiving. // These are the load / save game routines. From 8608ded317c46e435dcfa2fb1936bfd963e1ec18 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sat, 28 Oct 2023 15:19:35 +0200 Subject: [PATCH 62/91] Add deprecation TODOs --- src/deh_soc.c | 2 ++ src/lua_baselib.c | 2 ++ src/lua_consolelib.c | 1 + src/lua_infolib.c | 3 +++ src/lua_maplib.c | 2 ++ src/lua_mathlib.c | 1 + src/p_setup.c | 9 +++++++-- src/p_spec.c | 4 +++- src/p_user.c | 13 +++++++------ 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 59eb0a9bd..6162034de 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -911,6 +911,7 @@ static void readspriteframe(MYFILE *f, spriteinfo_t *sprinfo, UINT8 frame) sprinfo->pivot[frame].x = value; else if (fastcmp(word, "YPIVOT")) sprinfo->pivot[frame].y = value; + // TODO: 2.3: Delete else if (fastcmp(word, "ROTAXIS")) deh_warning("SpriteInfo: ROTAXIS is deprecated and will be removed."); else @@ -1617,6 +1618,7 @@ void readlevelheader(MYFILE *f, INT32 num) sizeof(mapheaderinfo[num-1]->musname), va("Level header %d: music", num)); } } + // TODO: 2.3: Delete else if (fastcmp(word, "MUSICSLOT")) deh_warning("Level header %d: MusicSlot parameter is deprecated and will be removed.\nUse \"Music\" instead.", num); else if (fastcmp(word, "MUSICTRACK")) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index f7ed763a9..c5ed4ddb6 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1788,6 +1788,7 @@ static int lib_pMove(lua_State *L) return 2; } +// TODO: 2.3: Delete static int lib_pTeleportMove(lua_State *L) { mobj_t *ptmthing = tmthing; @@ -2266,6 +2267,7 @@ static int lib_pMobjTouchingSectorSpecial(lua_State *L) return 1; } +// TODO: 2.3: Delete static int lib_pThingOnSpecial3DFloor(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index b34105004..c281b23b3 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -194,6 +194,7 @@ static int lib_comAddCommand(lua_State *L) if (lua_gettop(L) >= 3) { // For the third argument, only take a boolean or a number. lua_settop(L, 3); + // TODO: 2.3: Remove boolean option if (lua_type(L, 3) == LUA_TBOOLEAN) { CONS_Alert(CONS_WARNING, diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 020eba152..ed78811ce 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -318,6 +318,7 @@ static int PopPivotSubTable(spriteframepivot_t *pivot, lua_State *L, int stk, in pivot[idx].x = (INT32)value; else if (ikey == 2 || (key && fastcmp(key, "y"))) pivot[idx].y = (INT32)value; + // TODO: 2.3: Delete else if (ikey == 3 || (key && fastcmp(key, "rotaxis"))) LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed.") else if (ikey == -1 && (key != NULL)) @@ -571,6 +572,7 @@ static int framepivot_get(lua_State *L) lua_pushinteger(L, framepivot->x); else if (fastcmp("y", field)) lua_pushinteger(L, framepivot->y); + // TODO: 2.3: Delete else if (fastcmp("rotaxis", field)) { LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed."); @@ -600,6 +602,7 @@ static int framepivot_set(lua_State *L) framepivot->x = luaL_checkinteger(L, 3); else if (fastcmp("y", field)) framepivot->y = luaL_checkinteger(L, 3); + // TODO: 2.3: delete else if (fastcmp("rotaxis", field)) LUA_UsageWarning(L, "\"rotaxis\" is deprecated and will be removed.") else diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 588a6b4e6..df06e9721 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -1098,6 +1098,7 @@ static int line_get(lua_State *L) case line_polyobj: LUA_PushUserdata(L, line->polyobj, META_POLYOBJ); return 1; + // TODO: 2.3: Delete case line_text: { if (udmf) @@ -1231,6 +1232,7 @@ static int side_get(lua_State *L) case side_repeatcnt: lua_pushinteger(L, side->repeatcnt); return 1; + // TODO: 2.3: Delete case side_text: { if (udmf) diff --git a/src/lua_mathlib.c b/src/lua_mathlib.c index d0fe6863f..1bc6019de 100644 --- a/src/lua_mathlib.c +++ b/src/lua_mathlib.c @@ -125,6 +125,7 @@ static int lib_fixeddiv(lua_State *L) return 1; } +// TODO: 2.3: Delete static int lib_fixedrem(lua_State *L) { LUA_Deprecated(L, "FixedRem(a, b)", "a % b"); diff --git a/src/p_setup.c b/src/p_setup.c index 0390761b6..7f6fcd36c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1679,7 +1679,7 @@ static void ParseTextmapSectorParameter(UINT32 i, const char *param, const char if ((id = strchr(id, ' '))) id++; } - } + } else if (fastcmp(param, "xpanningfloor")) sectors[i].floorxoffset = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "ypanningfloor")) @@ -6132,6 +6132,7 @@ static void P_ConvertBinarySectorTypes(void) case 14: //Non-ramp sector sectors[i].specialflags |= SSF_NOSTEPDOWN; break; + // TODO: 2.3: Delete case 15: //Bouncy FOF CONS_Alert(CONS_WARNING, M_GetText("Deprecated bouncy FOF sector type detected. Please use linedef type 76 instead.\n")); break; @@ -6166,12 +6167,14 @@ static void P_ConvertBinarySectorTypes(void) sectors[i].flags |= MSF_TRIGGERLINE_PLANE; sectors[i].triggerer = TO_PLAYER; break; + // TODO: 2.3: Delete case 6: //Trigger linedef executor (Emerald check) CONS_Alert(CONS_WARNING, M_GetText("Deprecated emerald check sector type detected. Please use linedef types 337-339 instead.\n")); sectors[i].triggertag = tag; sectors[i].flags &= ~MSF_TRIGGERLINE_PLANE; sectors[i].triggerer = TO_PLAYEREMERALDS; break; + // TODO: 2.3: Delete case 7: //Trigger linedef executor (NiGHTS mare) CONS_Alert(CONS_WARNING, M_GetText("Deprecated NiGHTS mare sector type detected. Please use linedef types 340-342 instead.\n")); sectors[i].triggertag = tag; @@ -6181,9 +6184,11 @@ static void P_ConvertBinarySectorTypes(void) case 8: //Check for linedef executor on FOFs sectors[i].flags |= MSF_TRIGGERLINE_MOBJ; break; + // TODO: 2.3: Delete case 10: //Special stage time/spheres requirements CONS_Alert(CONS_WARNING, M_GetText("Deprecated sector type for special stage requirements detected. Please use the SpecialStageTime and SpecialStageSpheres level header options instead.\n")); break; + // TODO: 2.3: Delete case 11: //Custom global gravity CONS_Alert(CONS_WARNING, M_GetText("Deprecated sector type for global gravity detected. Please use the Gravity level header option instead.\n")); break; @@ -6822,7 +6827,7 @@ static void P_ConvertBinaryThingTypes(void) default: break; } - + // Clear binary thing height hacks, to prevent interfering with UDMF-only flags mapthings[i].options &= 0xF; } diff --git a/src/p_spec.c b/src/p_spec.c index 28ecc60f4..aa4ee37cf 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2661,7 +2661,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) titlemapcameraref = altview; else if (!mo->player->awayviewtics || mo->player->awayviewmobj != altview) { P_SetTarget(&mo->player->awayviewmobj, altview); - + if (mo->player == &players[displayplayer]) P_ResetCamera(mo->player, &camera); // reset p1 camera on p1 getting an awayviewmobj else if (splitscreen && mo->player == &players[secondarydisplayplayer]) @@ -4178,6 +4178,7 @@ sector_t *P_MobjTouchingSectorSpecial(mobj_t *mo, INT32 section, INT32 number) return NULL; } +// TODO: 2.3: Delete // Deprecated in favor of P_MobjTouchingSectorSpecial // Kept for Lua backwards compatibility only sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) @@ -6229,6 +6230,7 @@ void P_SpawnSpecials(boolean fromnetsave) sector->flags |= MSF_TRIGGERSPECIAL_TOUCH; } + // TODO: 2.3: Delete everything below // Process deprecated binary sector specials if (udmf || !sector->special) continue; diff --git a/src/p_user.c b/src/p_user.c index 5730d476d..453a10b5b 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2775,6 +2775,7 @@ static void P_CheckBouncySectors(player_t *player) if (!(rover->fofflags & FOF_EXISTS)) continue; // FOFs should not be bouncy if they don't even "exist" + // TODO: 2.3: Delete // Handle deprecated bouncy FOF sector type if (!udmf && GETSECSPECIAL(rover->master->frontsector->special, 1) == 15) { @@ -11390,7 +11391,7 @@ static void P_DoTailsOverlay(player_t *player, mobj_t *tails) tails->y = player->mo->y + P_ReturnThrustY(tails, tails->angle, FixedMul(backwards, tails->scale)); tails->z = player->mo->z + zoffs; P_SetThingPosition(tails); - + if (player->mo->flags2 & MF2_SHADOW) tails->flags2 |= MF2_SHADOW; else @@ -11606,7 +11607,7 @@ void P_PlayerThink(player_t *player) P_SetTarget(&player->awayviewmobj, NULL); // remove awayviewmobj asap if invalid player->awayviewtics = 1; // reset to one, the below code will immediately set it to zero } - + if (player->awayviewtics && player->awayviewtics != -1) { player->awayviewtics--; @@ -12278,11 +12279,11 @@ void P_PlayerThink(player_t *player) if (!(player->stronganim)) player->stronganim = player->panim; else if (player->panim != player->stronganim) - player->powers[pw_strong] = STR_NONE; - } + player->powers[pw_strong] = STR_NONE; + } else if (player->stronganim) player->stronganim = 0; - + //pw_super acts as a timer now if (player->powers[pw_super] && (player->mo->state < &states[S_PLAY_SUPER_TRANS1] @@ -12389,7 +12390,7 @@ void P_PlayerThink(player_t *player) if (player->jumpfactor < FixedMul(skins[player->skin].jumpfactor, 5*FRACUNIT/4)) // Boost jump height. player->jumpfactor += FRACUNIT/300; - if ((player->charflags & SF_MACHINE) && (!(player->powers[pw_strong] == STR_METAL))) + if ((player->charflags & SF_MACHINE) && (!(player->powers[pw_strong] == STR_METAL))) player->powers[pw_strong] = STR_METAL; } From f705e53826d80b7c46a10712a55294b290de6c17 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sat, 28 Oct 2023 11:49:26 -0400 Subject: [PATCH 63/91] GitLab CI: try compiling with dummy interface with musl --- .gitlab-ci.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b292bfc06..19391e80c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -419,6 +419,43 @@ Debian stable Clang: # make echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" +Debian stable musl: + stage: build + + allow_failure: true + + artifacts: + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-musl" + + variables: + CC: musl-gcc + LDD: musl-ldd + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install musl-tools + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 SDL=0 NOHW=1 NOZLIB=1 NOCURL=1 NOGME=1 NOOPENMPT=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 SDL=0 NOHW=1 NOZLIB=1 NOCURL=1 NOGME=1 NOOPENMPT=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + Debian testing Clang: extends: Debian stable Clang From 86d7c9862c053acf7ab7f6b81108b568f53aa041 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sat, 28 Oct 2023 16:20:49 +0000 Subject: [PATCH 64/91] Update .gitlab-ci.yml file Now, try compiling with musl on Debian testing --- .gitlab-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 19391e80c..3de507d61 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -469,3 +469,16 @@ Debian testing Clang: WFLAGS: -Wno-cast-align -Wno-deprecated-non-prototype CFLAGS: -Wno-cast-align -Wno-deprecated-non-prototype LDFLAGS: -Wl,-fuse-ld=gold + +Debian testing musl: + extends: Debian stable musl + + image: debian:testing-slim + + artifacts: + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-testing-musl" + + variables: + CC: musl-gcc + LDD: musl-ldd + LDFLAGS: -Wl,-fuse-ld=gold From b658a9629ebd4799bb971fd4ba8c05fdee04f101 Mon Sep 17 00:00:00 2001 From: katsy Date: Sat, 28 Oct 2023 16:16:17 -0500 Subject: [PATCH 65/91] Revert "Merge branch 'master' into next" This reverts commit b26cf5248feef9bee90fd889e2c086667e5f69fd, reversing changes made to a68440c4dba18990e92c836cd01e4caa0abcde3a. --- src/Makefile.d/features.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index 887e511fa..8b713718c 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -18,10 +18,6 @@ opts+=-DHWRENDER sources+=$(call List,hardware/Sourcefile) endif -ifdef NONET -NOCURL=1 -endif - ifndef NOMD5 sources+=md5.c endif From 18f61ab90cf5003c38dfc8bcdcaeb50a25849811 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sun, 29 Oct 2023 05:14:48 +0000 Subject: [PATCH 66/91] Update .gitlab-ci.yml file Add ARM64=1 for arm build --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3de507d61..c61e181a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -345,7 +345,7 @@ Debian stable:arm64: - - | # make echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" - - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 ERRORMODE=1 NONX86=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 NONX86=1 + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 ERRORMODE=1 NONX86=1C || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 NONX86=1 ARM64=1 - | # make echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" From 340d515754197d2f54570760440740b25b25e12b Mon Sep 17 00:00:00 2001 From: katsy <205-katsy@users.noreply.git.do.srb2.org> Date: Sun, 29 Oct 2023 17:43:40 +0000 Subject: [PATCH 67/91] Fix for "Leader of the Chaotix" name change bug (credit Zwip Zwap Zapony) --- src/netcode/d_netcmd.c | 2 +- src/p_saveg.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/netcode/d_netcmd.c b/src/netcode/d_netcmd.c index 5afa95561..52df53b5a 100644 --- a/src/netcode/d_netcmd.c +++ b/src/netcode/d_netcmd.c @@ -1241,7 +1241,7 @@ static void SetColorLocal(INT32 playernum, UINT16 color) // static void SendNameAndColor(void) { - char buf[MAXPLAYERNAME+6]; + char buf[MAXPLAYERNAME+7]; char *p; p = buf; diff --git a/src/p_saveg.c b/src/p_saveg.c index faecd1377..4aa2318fd 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -175,7 +175,7 @@ static void P_NetArchivePlayers(void) WRITEUINT16(save_p, players[i].flashpal); WRITEUINT16(save_p, players[i].flashcount); - WRITEUINT8(save_p, players[i].skincolor); + WRITEUINT16(save_p, players[i].skincolor); WRITEINT32(save_p, players[i].skin); WRITEUINT32(save_p, players[i].availabilities); WRITEUINT32(save_p, players[i].score); @@ -404,7 +404,7 @@ static void P_NetUnArchivePlayers(void) players[i].flashpal = READUINT16(save_p); players[i].flashcount = READUINT16(save_p); - players[i].skincolor = READUINT8(save_p); + players[i].skincolor = READUINT16(save_p); players[i].skin = READINT32(save_p); players[i].availabilities = READUINT32(save_p); players[i].score = READUINT32(save_p); From cd6cd5395930a51ae5b62e4737480b9219a769ae Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Mon, 30 Oct 2023 04:38:51 +0000 Subject: [PATCH 68/91] Combine vid.dupx and vid.dupy --- src/console.c | 12 +- src/f_finale.c | 23 +- src/hardware/hw_draw.c | 218 ++++++++---------- src/lua_hudlib.c | 18 +- src/m_anigif.c | 2 +- src/m_menu.c | 61 +++-- src/m_misc.c | 4 +- src/r_sky.c | 4 +- src/screen.c | 10 +- src/screen.h | 12 +- src/st_stuff.c | 4 +- src/v_video.c | 507 +++++++++++++++++++---------------------- src/v_video.h | 2 +- src/y_inter.c | 6 +- 14 files changed, 408 insertions(+), 475 deletions(-) diff --git a/src/console.c b/src/console.c index 21b608ce4..dbd7c938a 100644 --- a/src/console.c +++ b/src/console.c @@ -543,13 +543,13 @@ static void CON_RecalcSize(void) con_scalefactor = 1; break; case V_SMALLSCALEPATCH: - con_scalefactor = vid.smalldupx; + con_scalefactor = vid.smalldup; break; case V_MEDSCALEPATCH: - con_scalefactor = vid.meddupx; + con_scalefactor = vid.meddup; break; default: // Full scaling - con_scalefactor = vid.dupx; + con_scalefactor = vid.dup; break; } @@ -667,7 +667,7 @@ static void CON_MoveConsole(void) } // Not instant - Increment fracmovement fractionally - fracmovement += FixedMul(cons_speed.value*vid.fdupy, renderdeltatics); + fracmovement += FixedMul(cons_speed.value*vid.fdup, renderdeltatics); if (con_curlines < con_destlines) // Move the console downwards { @@ -1764,9 +1764,9 @@ static void CON_DrawBackpic(void) con_backpic = W_CachePatchNum(piclump, PU_PATCH); // Center the backpic, and draw a vertically cropped patch. - w = (con_backpic->width * vid.dupx); + w = con_backpic->width * vid.dup; x = (vid.width / 2) - (w / 2); - h = con_curlines/vid.dupy; + h = con_curlines/vid.dup; // If the patch doesn't fill the entire screen, // then fill the sides with a solid color. diff --git a/src/f_finale.c b/src/f_finale.c index 7afed27d0..68e9c3216 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1327,7 +1327,7 @@ void F_CreditDrawer(void) y += 12< vid.height) + if (FixedMul(y,vid.dup) > vid.height) break; } } @@ -1362,7 +1362,7 @@ void F_CreditTicker(void) case 1: y += 30< vid.height) + if (FixedMul(y,vid.dup) > vid.height) break; } @@ -2082,7 +2082,7 @@ void F_EndingDrawer(void) if (goodending && finalecount >= TICRATE && finalecount < INFLECTIONPOINT) { INT32 workingtime = finalecount - TICRATE; - fixed_t radius = ((vid.width/vid.dupx)*(INFLECTIONPOINT - TICRATE - workingtime))/(INFLECTIONPOINT - TICRATE); + fixed_t radius = ((vid.width/vid.dup)*(INFLECTIONPOINT - TICRATE - workingtime))/(INFLECTIONPOINT - TICRATE); angle_t fa; INT32 eemeralds_cur[4]; char patchname[7] = "CEMGx0"; @@ -2287,7 +2287,6 @@ void F_InitMenuPresValues(void) void F_SkyScroll(const char *patchname) { INT32 x, basey = 0; - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); patch_t *pat; if (rendermode == render_none) @@ -2315,17 +2314,17 @@ void F_SkyScroll(const char *patchname) curbgy %= pat->height * 16; // Ooh, fancy frame interpolation - x = ((curbgx*dupz) + FixedInt((rendertimefrac-FRACUNIT) * curbgxspeed*dupz)) / 16; - basey = ((curbgy*dupz) + FixedInt((rendertimefrac-FRACUNIT) * curbgyspeed*dupz)) / 16; + x = ((curbgx*vid.dup) + FixedInt((rendertimefrac-FRACUNIT) * curbgxspeed*vid.dup)) / 16; + basey = ((curbgy*vid.dup) + FixedInt((rendertimefrac-FRACUNIT) * curbgyspeed*vid.dup)) / 16; if (x > 0) // Make sure that we don't leave the left or top sides empty - x -= pat->width * dupz; + x -= pat->width * vid.dup; if (basey > 0) - basey -= pat->height * dupz; + basey -= pat->height * vid.dup; - for (; x < vid.width; x += pat->width * dupz) + for (; x < vid.width; x += pat->width * vid.dup) { - for (INT32 y = basey; y < vid.height; y += pat->height * dupz) + for (INT32 y = basey; y < vid.height; y += pat->height * vid.dup) V_DrawScaledPatch(x, y, V_NOSCALESTART, pat); } @@ -2603,7 +2602,7 @@ static void F_LoadAlacroixGraphics(SINT8 newttscale) static void F_FigureActiveTtScale(void) { - SINT8 newttscale = max(1, min(6, vid.dupx)); + SINT8 newttscale = max(1, min(6, vid.dup)); SINT8 oldttscale = activettscale; if (newttscale == testttscale) @@ -4095,7 +4094,7 @@ static fixed_t F_GetPromptHideHudBound(void) F_GetPageTextGeometry(&pagelines, &rightside, &boxh, &texth, &texty, &namey, &chevrony, &textx, &textr); // calc boxheight (see V_DrawPromptBack) - boxh *= vid.dupy; + boxh *= vid.dup; boxh = (boxh * 4) + (boxh/2)*5; // 4 lines of space plus gaps between and some leeway // return a coordinate to check diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index eb0b9e332..ec9dc7613 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -78,10 +78,8 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) // | /| // |/ | // 0--1 - float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; - float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; - float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; - float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float sdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; + float pdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; // make patch ready in hardware cache HWR_GetPatch(gpatch); @@ -90,25 +88,23 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - pdupx = pdupy = 2.0f; + pdup = 2.0f; break; case V_SMALLSCALEPATCH: - pdupx = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupx); - pdupy = 2.0f * FIXED_TO_FLOAT(vid.fsmalldupy); + pdup = 2.0f * FIXED_TO_FLOAT(vid.fsmalldup); break; case V_MEDSCALEPATCH: - pdupx = 2.0f * FIXED_TO_FLOAT(vid.fmeddupx); - pdupy = 2.0f * FIXED_TO_FLOAT(vid.fmeddupy); + pdup = 2.0f * FIXED_TO_FLOAT(vid.fmeddup); break; } if (option & V_NOSCALESTART) - sdupx = sdupy = 2.0f; + sdup = 2.0f; - v[0].x = v[3].x = (x*sdupx-(gpatch->leftoffset)*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-(gpatch->topoffset)*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdup-(gpatch->leftoffset)*pdup)/vid.width - 1; + v[2].x = v[1].x = (x*sdup+(gpatch->width-gpatch->leftoffset)*pdup)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdup-(gpatch->topoffset)*pdup)/vid.height; + v[2].y = v[3].y = 1-(y*sdup+(gpatch->height-gpatch->topoffset)*pdup)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -137,7 +133,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p // | /| // |/ | // 0--1 - float dupx, dupy, fscalew, fscaleh, fwidth, fheight; + float dup, fscalew, fscaleh, fwidth, fheight; UINT8 perplayershuffle = 0; @@ -149,25 +145,21 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p hwrPatch = ((GLPatch_t *)gpatch->hardware); - dupx = (float)vid.dupx; - dupy = (float)vid.dupy; + dup = (float)vid.dup; switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - dupx = dupy = 1.0f; + dup = 1.0f; break; case V_SMALLSCALEPATCH: - dupx = (float)vid.smalldupx; - dupy = (float)vid.smalldupy; + dup = (float)vid.smalldup; break; case V_MEDSCALEPATCH: - dupx = (float)vid.meddupx; - dupy = (float)vid.meddupy; + dup = (float)vid.meddup; break; } - dupx = dupy = (dupx < dupy ? dupx : dupy); fscalew = fscaleh = FIXED_TO_FLOAT(pscale); if (vscale != pscale) fscaleh = FIXED_TO_FLOAT(vscale); @@ -261,8 +253,8 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p if (!(option & V_NOSCALESTART)) { - cx = cx * dupx; - cy = cy * dupy; + cx = cx * dup; + cy = cy * dup; if (!(option & V_SCALEPATCHMASK)) { @@ -279,40 +271,40 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p } } // centre screen - if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dup) > 1.0E-36f) { if (option & V_SNAPTORIGHT) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)); + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup)); else if (!(option & V_SNAPTOLEFT)) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/2; + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup))/2; if (perplayershuffle & 4) - cx -= ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/4; + cx -= ((float)vid.width - ((float)BASEVIDWIDTH * dup))/4; else if (perplayershuffle & 8) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/4; + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup))/4; } - if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dupy) > 1.0E-36f) + if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dup) > 1.0E-36f) { if (option & V_SNAPTOBOTTOM) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)); + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup)); else if (!(option & V_SNAPTOTOP)) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/2; + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/2; if (perplayershuffle & 1) - cy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/4; + cy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/4; else if (perplayershuffle & 2) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/4; + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/4; } } } if (pscale != FRACUNIT || vscale != FRACUNIT || (splitscreen && option & V_PERPLAYER)) { - fwidth = (float)(gpatch->width) * fscalew * dupx; - fheight = (float)(gpatch->height) * fscaleh * dupy; + fwidth = (float)(gpatch->width) * fscalew * dup; + fheight = (float)(gpatch->height) * fscaleh * dup; } else { - fwidth = (float)(gpatch->width) * dupx; - fheight = (float)(gpatch->height) * dupy; + fwidth = (float)(gpatch->width) * dup; + fheight = (float)(gpatch->height) * dup; } // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 @@ -379,7 +371,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // | /| // |/ | // 0--1 - float dupx, dupy, fscalew, fscaleh, fwidth, fheight; + float dup, fscalew, fscaleh, fwidth, fheight; UINT8 perplayershuffle = 0; @@ -391,25 +383,21 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, hwrPatch = ((GLPatch_t *)gpatch->hardware); - dupx = (float)vid.dupx; - dupy = (float)vid.dupy; + dup = (float)vid.dup; switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - dupx = dupy = 1.0f; + dup = 1.0f; break; case V_SMALLSCALEPATCH: - dupx = (float)vid.smalldupx; - dupy = (float)vid.smalldupy; + dup = (float)vid.smalldup; break; case V_MEDSCALEPATCH: - dupx = (float)vid.meddupx; - dupy = (float)vid.meddupy; + dup = (float)vid.meddup; break; } - dupx = dupy = (dupx < dupy ? dupx : dupy); fscalew = fscaleh = FIXED_TO_FLOAT(pscale); if (vscale != pscale) fscaleh = FIXED_TO_FLOAT(vscale); @@ -487,8 +475,8 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (!(option & V_NOSCALESTART)) { - cx = cx * dupx; - cy = cy * dupy; + cx = cx * dup; + cy = cy * dup; if (!(option & V_SCALEPATCHMASK)) { @@ -496,27 +484,27 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // no the patch is cropped do not do this ever // centre screen - if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dup) > 1.0E-36f) { if (option & V_SNAPTORIGHT) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)); + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup)); else if (!(option & V_SNAPTOLEFT)) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/2; + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup))/2; if (perplayershuffle & 4) - cx -= ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/4; + cx -= ((float)vid.width - ((float)BASEVIDWIDTH * dup))/4; else if (perplayershuffle & 8) - cx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx))/4; + cx += ((float)vid.width - ((float)BASEVIDWIDTH * dup))/4; } - if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dupy) > 1.0E-36f) + if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dup) > 1.0E-36f) { if (option & V_SNAPTOBOTTOM) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)); + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup)); else if (!(option & V_SNAPTOTOP)) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/2; + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/2; if (perplayershuffle & 1) - cy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/4; + cy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/4; else if (perplayershuffle & 2) - cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy))/4; + cy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup))/4; } } } @@ -532,13 +520,13 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (pscale != FRACUNIT || vscale != FRACUNIT || (splitscreen && option & V_PERPLAYER)) { - fwidth *= fscalew * dupx; - fheight *= fscaleh * dupy; + fwidth *= fscalew * dup; + fheight *= fscaleh * dup; } else { - fwidth *= dupx; - fheight *= dupy; + fwidth *= dup; + fheight *= dup; } // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 @@ -674,9 +662,9 @@ void HWR_DrawPic(INT32 x, INT32 y, lumpnum_t lumpnum) // 0--1 v[0].x = v[3].x = 2.0f * (float)x/vid.width - 1; - v[2].x = v[1].x = 2.0f * (float)(x + patch->width*FIXED_TO_FLOAT(vid.fdupx))/vid.width - 1; + v[2].x = v[1].x = 2.0f * (float)(x + patch->width*FIXED_TO_FLOAT(vid.fdup))/vid.width - 1; v[0].y = v[1].y = 1.0f - 2.0f * (float)y/vid.height; - v[2].y = v[3].y = 1.0f - 2.0f * (float)(y + patch->height*FIXED_TO_FLOAT(vid.fdupy))/vid.height; + v[2].y = v[3].y = 1.0f - 2.0f * (float)(y + patch->height*FIXED_TO_FLOAT(vid.fdup))/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -866,35 +854,33 @@ void HWR_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color, UINT16 ac if (!(color & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; + fx *= vid.dup; + fy *= vid.dup; + fw *= vid.dup; + fh *= vid.dup; - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; - - if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf((float)vid.width - (float)BASEVIDWIDTH * vid.dup) > 1.0E-36f) { if (color & V_SNAPTORIGHT) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)); + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)); else if (!(color & V_SNAPTOLEFT)) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 2; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 2; if (perplayershuffle & 4) - fx -= ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx -= ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 4; else if (perplayershuffle & 8) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 4; } - if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dupy) > 1.0E-36f) + if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * vid.dup) > 1.0E-36f) { // same thing here if (color & V_SNAPTOBOTTOM) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)); + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)); else if (!(color & V_SNAPTOTOP)) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 2; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 2; if (perplayershuffle & 1) - fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 4; else if (perplayershuffle & 2) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 4; } } @@ -1032,10 +1018,10 @@ void HWR_DrawViewBorder(INT32 clearlines) clearlines = BASEVIDHEIGHT; // refresh all // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdupx)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdupy)); - top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdupy)); - side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwindowx), vid.fdupx)); + baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; + baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdup)); + top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdup)); + side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwindowx), vid.fdup)); // top HWR_DrawFlatFill(0, 0, @@ -1250,35 +1236,35 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color, UINT32 if (!(color & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; + float dup = (float)vid.dup; - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; + fx *= dup; + fy *= dup; + fw *= dup; + fh *= dup; - if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dup) > 1.0E-36f) { if (color & V_SNAPTORIGHT) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)); + fx += ((float)vid.width - ((float)BASEVIDWIDTH * dup)); else if (!(color & V_SNAPTOLEFT)) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 2; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * dup)) / 2; if (perplayershuffle & 4) - fx -= ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx -= ((float)vid.width - ((float)BASEVIDWIDTH * dup)) / 4; else if (perplayershuffle & 8) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * dup)) / 4; } - if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dupy) > 1.0E-36f) + if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dup) > 1.0E-36f) { // same thing here if (color & V_SNAPTOBOTTOM) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)); + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup)); else if (!(color & V_SNAPTOTOP)) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 2; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup)) / 2; if (perplayershuffle & 1) - fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dup)) / 4; else if (perplayershuffle & 2) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dup)) / 4; } } @@ -1416,8 +1402,6 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) if (!(color & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; - if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { RGBA_t rgbaColour = V_GetColor(color); @@ -1430,33 +1414,33 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) return; } - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; + fx *= vid.dup; + fy *= vid.dup; + fw *= vid.dup; + fh *= vid.dup; - if (fabsf((float)vid.width - (float)BASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf((float)vid.width - (float)BASEVIDWIDTH * vid.dup) > 1.0E-36f) { if (color & V_SNAPTORIGHT) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)); + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)); else if (!(color & V_SNAPTOLEFT)) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 2; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 2; if (perplayershuffle & 4) - fx -= ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx -= ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 4; else if (perplayershuffle & 8) - fx += ((float)vid.width - ((float)BASEVIDWIDTH * dupx)) / 4; + fx += ((float)vid.width - ((float)BASEVIDWIDTH * vid.dup)) / 4; } - if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * dupy) > 1.0E-36f) + if (fabsf((float)vid.height - (float)BASEVIDHEIGHT * vid.dup) > 1.0E-36f) { // same thing here if (color & V_SNAPTOBOTTOM) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)); + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)); else if (!(color & V_SNAPTOTOP)) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 2; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 2; if (perplayershuffle & 1) - fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy -= ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 4; else if (perplayershuffle & 2) - fy += ((float)vid.height - ((float)BASEVIDHEIGHT * dupy)) / 4; + fy += ((float)vid.height - ((float)BASEVIDHEIGHT * vid.dup)) / 4; } } diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 6eec91273..159344faa 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -1206,19 +1206,11 @@ static int libd_height(lua_State *L) return 1; } -static int libd_dupx(lua_State *L) +static int libd_dup(lua_State *L) { HUDONLY - lua_pushinteger(L, vid.dupx); // push integral scale (patch scale) - lua_pushfixed(L, vid.fdupx); // push fixed point scale (position scale) - return 2; -} - -static int libd_dupy(lua_State *L) -{ - HUDONLY - lua_pushinteger(L, vid.dupy); // push integral scale (patch scale) - lua_pushfixed(L, vid.fdupy); // push fixed point scale (position scale) + lua_pushinteger(L, vid.dup); // push integral scale (patch scale) + lua_pushfixed(L, vid.fdup); // push fixed point scale (position scale) return 2; } @@ -1338,8 +1330,8 @@ static luaL_Reg lib_draw[] = { // properties {"width", libd_width}, {"height", libd_height}, - {"dupx", libd_dupx}, - {"dupy", libd_dupy}, + {"dupx", libd_dup}, + {"dupy", libd_dup}, {"renderer", libd_renderer}, {"localTransFlag", libd_getlocaltransflag}, {"userTransFlag", libd_getusertransflag}, diff --git a/src/m_anigif.c b/src/m_anigif.c index 90e4c69ce..5bc7717e0 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -462,7 +462,7 @@ static void GIF_headwrite(void) // Image width/height if (gif_downscale) { - scrbuf_downscaleamt = vid.dupx; + scrbuf_downscaleamt = vid.dup; rwidth = (vid.width / scrbuf_downscaleamt); rheight = (vid.height / scrbuf_downscaleamt); } diff --git a/src/m_menu.c b/src/m_menu.c index 523430ed8..629f53d24 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -214,7 +214,7 @@ static fixed_t lsoffs[2]; #define lshli levelselectselect[2] #define lshseperation 101 -#define lsbasevseperation ((62*vid.height)/(BASEVIDHEIGHT*vid.dupy)) //62 +#define lsbasevseperation ((62*vid.height)/(BASEVIDHEIGHT*vid.dup)) //62 #define lsheadingheight 16 #define getheadingoffset(row) (levelselect.rows[row].header[0] ? lsheadingheight : 0) #define lsvseperation(row) (lsbasevseperation + getheadingoffset(row)) @@ -3574,16 +3574,16 @@ void M_Drawer(void) { if (customversionstring[0] != '\0') { - V_DrawThinString(vid.dupx, vid.height - 17*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT, "Mod version:"); - V_DrawThinString(vid.dupx, vid.height - 9*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, customversionstring); + V_DrawThinString(vid.dup, vid.height - 17*vid.dup, V_NOSCALESTART|V_TRANSLUCENT, "Mod version:"); + V_DrawThinString(vid.dup, vid.height - 9*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, customversionstring); } else { #ifdef DEVELOP // Development -- show revision / branch info - V_DrawThinString(vid.dupx, vid.height - 17*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, compbranch); - V_DrawThinString(vid.dupx, vid.height - 9*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); + V_DrawThinString(vid.dup, vid.height - 17*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, compbranch); + V_DrawThinString(vid.dup, vid.height - 9*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); #else // Regular build - V_DrawThinString(vid.dupx, vid.height - 9*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, va("%s", VERSIONSTRING)); + V_DrawThinString(vid.dup, vid.height - 9*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, va("%s", VERSIONSTRING)); #endif } } @@ -5757,16 +5757,15 @@ static void M_DrawRecordAttackForeground(void) INT32 i; INT32 height = (fg->height / 2); - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); for (i = -12; i < (BASEVIDHEIGHT/height) + 12; i++) { INT32 y = ((i*height) - (height - ((FixedInt(recatkdrawtimer*2))%height))); // don't draw above the screen { - INT32 sy = FixedMul(y, dupz<> FRACBITS; - if (vid.height != BASEVIDHEIGHT * dupz) - sy += (vid.height - (BASEVIDHEIGHT * dupz)) / 2; + INT32 sy = FixedMul(y, vid.dup<> FRACBITS; + if (vid.height != BASEVIDHEIGHT * vid.dup) + sy += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; if ((sy+height) < 0) continue; } @@ -5790,13 +5789,12 @@ static void M_DrawRecordAttackForeground(void) static void M_DrawNightsAttackMountains(void) { static fixed_t bgscrollx; - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); patch_t *background = W_CachePatchName(curbgname, PU_PATCH); INT16 w = background->width; INT32 x = FixedInt(-bgscrollx) % w; INT32 y = BASEVIDHEIGHT - (background->height * 2); - if (vid.height != BASEVIDHEIGHT * dupz) + if (vid.height != BASEVIDHEIGHT * vid.dup) V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 158); V_DrawFill(0, y+50, vid.width, BASEVIDHEIGHT, V_SNAPTOLEFT|31); @@ -5952,7 +5950,7 @@ static void M_DrawLevelPlatterMenu(void) } // draw from top to bottom - while (y < (vid.height/vid.dupy)) + while (y < (vid.height/vid.dup)) { M_DrawLevelPlatterRow(iter, y); y += lsvseperation(iter); @@ -7799,9 +7797,9 @@ static void M_DrawSoundTest(void) } } - y = (BASEVIDWIDTH-(vid.width/vid.dupx))/2; + y = (BASEVIDWIDTH-(vid.width/vid.dup))/2; - V_DrawFill(y, 20, vid.width/vid.dupx, 24, 159); + V_DrawFill(y, 20, vid.width/vid.dup, 24, 159); { static fixed_t st_scroll = -FRACUNIT; const char* titl; @@ -8371,8 +8369,8 @@ static void M_DrawLoadGameData(void) INT32 i, prev_i = 1, savetodraw, x, y, hsep = 90; skin_t *charskin = NULL; - if (vid.width != BASEVIDWIDTH*vid.dupx) - hsep = (hsep*vid.width)/(BASEVIDWIDTH*vid.dupx); + if (vid.width != BASEVIDWIDTH*vid.dup) + hsep = (hsep*vid.width)/(BASEVIDWIDTH*vid.dup); for (i = 2; prev_i; i = -(i + ((UINT32)i >> 31))) // draws from outwards in; 2, -2, 1, -1, 0 { @@ -9357,7 +9355,7 @@ static void M_DrawSetupChoosePlayerMenu(void) INT16 bgwidth = charbg->width; INT16 fgwidth = charfg->width; INT32 x, y; - INT32 w = (vid.width/vid.dupx); + INT32 w = (vid.width/vid.dup); if (abs(char_scroll) > FRACUNIT/4) char_scroll -= FixedMul((char_scroll>>2), renderdeltatics); @@ -9393,7 +9391,7 @@ static void M_DrawSetupChoosePlayerMenu(void) // Background and borders V_DrawFill(0, 0, bgwidth, vid.height, V_SNAPTOTOP|colormap[101]); { - INT32 sw = (BASEVIDWIDTH * vid.dupx); + INT32 sw = (BASEVIDWIDTH * vid.dup); INT32 bw = (vid.width - sw) / 2; col = colormap[106]; if (bw) @@ -10815,7 +10813,7 @@ void M_DrawMarathon(void) const char *cvstring; char *work; angle_t fa; - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy), xspan = (vid.width/dupz), yspan = (vid.height/dupz), diffx = (xspan - BASEVIDWIDTH)/2, diffy = (yspan - BASEVIDHEIGHT)/2, maxy = BASEVIDHEIGHT + diffy; + INT32 xspan = (vid.width/vid.dup), yspan = (vid.height/vid.dup), diffx = (xspan - BASEVIDWIDTH)/2, diffy = (yspan - BASEVIDHEIGHT)/2, maxy = BASEVIDHEIGHT + diffy; curbgxspeed = 0; curbgyspeed = 18; @@ -10888,16 +10886,17 @@ void M_DrawMarathon(void) INT32 trans = V_60TRANS+((cnt&~3)<<(V_ALPHASHIFT-2)); INT32 height = fg->height / 2; char patchname[7] = "CEMGx0"; + INT32 dup; - dupz = (w*7)/6; //(w*42*120)/(360*6); -- I don't know why this works but I'm not going to complain. - dupz = ((dupz>>FRACBITS) % height); + dup = (w*7)/6; //(w*42*120)/(360*6); -- I don't know why this works but I'm not going to complain. + dup = ((dup>>FRACBITS) % height); y = height/2; - while (y+dupz >= -diffy) + while (y+dup >= -diffy) y -= height; - while (y-2-dupz < maxy) + while (y-2-dup < maxy) { - V_DrawFixedPatch(((BASEVIDWIDTH-190)<<(FRACBITS-1)), (y-2-dupz)<>FRACBITS) % height); - y = dupz+(height/4); - x = 105+dupz; + //dup = (w*height)/18; + dup = ((w>>FRACBITS) % height); + y = dup+(height/4); + x = 105+dup; while (y >= -diffy) { x -= height; y -= height; } - while (y-dupz < maxy && x < (xspan/2)) + while (y-dup < maxy && x < (xspan/2)) { V_DrawFill((BASEVIDWIDTH/2)-x-height, -diffy, height, diffy+y+height, 153); V_DrawFill((BASEVIDWIDTH/2)+x, (maxy-y)-height, height, height+y, 153); diff --git a/src/m_misc.c b/src/m_misc.c index f547f5c41..d4b272f1d 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -989,7 +989,7 @@ static inline boolean M_PNGLib(void) static void M_PNGFrame(png_structp png_ptr, png_infop png_info_ptr, png_bytep png_buf) { - png_uint_16 downscale = apng_downscale ? vid.dupx : 1; + png_uint_16 downscale = apng_downscale ? vid.dup : 1; png_uint_32 pitch = png_get_rowbytes(png_ptr, png_info_ptr); PNG_CONST png_uint_32 width = vid.width / downscale; @@ -1055,7 +1055,7 @@ static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) apng_downscale = (!!cv_apng_downscale.value); - downscale = apng_downscale ? vid.dupx : 1; + downscale = apng_downscale ? vid.dup : 1; apng_FILE = fopen(filename,"wb+"); // + mode for reading if (!apng_FILE) diff --git a/src/r_sky.c b/src/r_sky.c index c47029f0b..edde4c218 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -75,6 +75,6 @@ void R_SetupSkyDraw(void) */ void R_SetSkyScale(void) { - fixed_t difference = vid.fdupx-(vid.dupx<> V_BLENDSHIFT); fixed_t col, ofs, colfrac, rowfrac, fdup, vdup; - INT32 dupx, dupy; + INT32 dup; const column_t *column; UINT8 *desttop, *dest, *deststart, *destend; const UINT8 *source, *deststop; @@ -555,30 +555,23 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca patchdrawfunc = (v_translevel) ? transmappedpdraw : mappedpdraw; } - dupx = vid.dupx; - dupy = vid.dupy; - if (scrn & V_SCALEPATCHMASK) switch ((scrn & V_SCALEPATCHMASK) >> V_SCALEPATCHSHIFT) + dup = vid.dup; + if (scrn & V_SCALEPATCHMASK) switch (scrn & V_SCALEPATCHMASK) { - case 1: // V_NOSCALEPATCH - dupx = dupy = 1; + case V_NOSCALEPATCH: + dup = 1; break; - case 2: // V_SMALLSCALEPATCH - dupx = vid.smalldupx; - dupy = vid.smalldupy; + case V_SMALLSCALEPATCH: + dup = vid.smalldup; break; - case 3: // V_MEDSCALEPATCH - dupx = vid.meddupx; - dupy = vid.meddupy; - break; - default: + case V_MEDSCALEPATCH: + dup = vid.meddup; break; } - // only use one dup, to avoid stretching (har har) - dupx = dupy = (dupx < dupy ? dupx : dupy); - fdup = vdup = FixedMul(dupx<>= FRACBITS; y >>= FRACBITS; @@ -703,30 +696,30 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca } } - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (scrn & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * dup)); else if (!(scrn & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * dup)) / 2; if (perplayershuffle & 4) - x -= (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x -= (vid.width - (BASEVIDWIDTH * dup)) / 4; else if (perplayershuffle & 8) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x += (vid.width - (BASEVIDWIDTH * dup)) / 4; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * dup) { // same thing here if (scrn & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * dup)); else if (!(scrn & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 2; if (perplayershuffle & 1) - y -= (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y -= (vid.height - (BASEVIDHEIGHT * dup)) / 4; else if (perplayershuffle & 2) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 4; } } @@ -737,11 +730,11 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca { pwidth = patch->width<>= FRACBITS; } else - pwidth = patch->width * dupx; + pwidth = patch->width * dup; deststart = desttop; destend = desttop + pwidth; @@ -797,7 +790,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, IN // boolean flip = false; fixed_t col, ofs, colfrac, rowfrac, fdup, vdup; - INT32 dupx, dupy; + INT32 dup; const column_t *column; UINT8 *desttop, *dest; const UINT8 *source, *deststop; @@ -845,30 +838,23 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, IN patchdrawfunc = (v_translevel) ? transmappedpdraw : mappedpdraw; } - dupx = vid.dupx; - dupy = vid.dupy; - if (scrn & V_SCALEPATCHMASK) switch ((scrn & V_SCALEPATCHMASK) >> V_SCALEPATCHSHIFT) + dup = vid.dup; + if (scrn & V_SCALEPATCHMASK) switch (scrn & V_SCALEPATCHMASK) { - case 1: // V_NOSCALEPATCH - dupx = dupy = 1; + case V_NOSCALEPATCH: + dup = 1; break; - case 2: // V_SMALLSCALEPATCH - dupx = vid.smalldupx; - dupy = vid.smalldupy; + case V_SMALLSCALEPATCH: + dup = vid.smalldup; break; - case 3: // V_MEDSCALEPATCH - dupx = vid.meddupx; - dupy = vid.meddupy; - break; - default: + case V_MEDSCALEPATCH: + dup = vid.meddup; break; } - // only use one dup, to avoid stretching (har har) - dupx = dupy = (dupx < dupy ? dupx : dupy); - fdup = vdup = FixedMul(dupx<>= FRACBITS; y >>= FRACBITS; @@ -971,30 +957,30 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, IN // if it's meant to cover the whole screen, black out the rest // no the patch is cropped do not do this ever - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (scrn & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * dup)); else if (!(scrn & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * dup)) / 2; if (perplayershuffle & 4) - x -= (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x -= (vid.width - (BASEVIDWIDTH * dup)) / 4; else if (perplayershuffle & 8) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x += (vid.width - (BASEVIDWIDTH * dup)) / 4; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * dup) { // same thing here if (scrn & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * dup)); else if (!(scrn & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 2; if (perplayershuffle & 1) - y -= (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y -= (vid.height - (BASEVIDHEIGHT * dup)) / 4; else if (perplayershuffle & 2) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 4; } } @@ -1150,22 +1136,22 @@ static void V_BlitScaledPic(INT32 rx1, INT32 ry1, INT32 scrn, pic_t * pic) dest = screens[scrn] + max(0, ry1 * vid.width) + max(0, rx1); // y cliping to the screen - if (ry1 + height * vid.dupy >= vid.width) - height = (vid.width - ry1) / vid.dupy - 1; + if (ry1 + height * vid.dup >= vid.width) + height = (vid.width - ry1) / vid.dup - 1; // WARNING no x clipping (not needed for the moment) - for (y = max(0, -ry1 / vid.dupy); y < height; y++) + for (y = max(0, -ry1 / vid.dup); y < height; y++) { - for (dupy = vid.dupy; dupy; dupy--) + for (dupy = vid.dup; dupy; dupy--) { src = pic->data + y * width; for (x = 0; x < width; x++) { - for (dupx = vid.dupx; dupx; dupx--) + for (dupx = vid.dup; dupx; dupx--) *dest++ = *src; src++; } - dest += vid.width - vid.dupx * width; + dest += vid.width - vid.dup * width; } } } @@ -1262,44 +1248,42 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { // Clear the entire screen, from dest to deststop. Yes, this really works. memset(screens[0], (c&255), vid.width * vid.height * vid.bpp); return; } - x *= dupx; - y *= dupy; - w *= dupx; - h *= dupy; + x *= vid.dup; + y *= vid.dup; + w *= vid.dup; + h *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; if (perplayershuffle & 4) - x -= (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x -= (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; else if (perplayershuffle & 8) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; if (perplayershuffle & 1) - y -= (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y -= (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; else if (perplayershuffle & 2) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; } } @@ -1474,38 +1458,36 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - - x *= dupx; - y *= dupy; - w *= dupx; - h *= dupy; + x *= vid.dup; + y *= vid.dup; + w *= vid.dup; + h *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; if (perplayershuffle & 4) - x -= (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x -= (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; else if (perplayershuffle & 8) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; if (perplayershuffle & 1) - y -= (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y -= (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; else if (perplayershuffle & 2) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; } } @@ -1658,38 +1640,36 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - - x *= dupx; - y *= dupy; - w *= dupx; - h *= dupy; + x *= vid.dup; + y *= vid.dup; + w *= vid.dup; + h *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; if (perplayershuffle & 4) - x -= (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x -= (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; else if (perplayershuffle & 8) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 4; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 4; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; if (perplayershuffle & 1) - y -= (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y -= (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; else if (perplayershuffle & 2) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 4; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 4; } } @@ -1735,7 +1715,7 @@ void V_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c, UINT16 color, U // void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) { - INT32 u, v, dupx, dupy; + INT32 u, v; fixed_t dx, dy, xfrac, yfrac; const UINT8 *src, *deststop; UINT8 *flat, *dest; @@ -1754,29 +1734,27 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) flat = W_CacheLumpNum(flatnum, PU_CACHE); - dupx = dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - - dest = screens[0] + y*dupy*vid.width + x*dupx; + dest = screens[0] + y*vid.dup*vid.width + x*vid.dup; deststop = screens[0] + vid.rowbytes * vid.height; // from V_DrawScaledPatch - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen - dest += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + dest += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here - dest += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width / 2; + dest += (vid.height - (BASEVIDHEIGHT * vid.dup)) * vid.width / 2; } - w *= dupx; - h *= dupy; + w *= vid.dup; + h *= vid.dup; - dx = FixedDiv(FRACUNIT, dupx<<(FRACBITS-2)); - dy = FixedDiv(FRACUNIT, dupy<<(FRACBITS-2)); + dx = FixedDiv(FRACUNIT, vid.dup<<(FRACBITS-2)); + dy = FixedDiv(FRACUNIT, vid.dup<<(FRACBITS-2)); yfrac = 0; for (v = 0; v < h; v++, dest += vid.width) @@ -1799,8 +1777,7 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) // void V_DrawPatchFill(patch_t *pat) { - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = pat->width * dupz, ph = pat->height * dupz; + INT32 x, y, pw = pat->width * vid.dup, ph = pat->height * vid.dup; for (x = 0; x < vid.width; x += pw) { @@ -1876,11 +1853,11 @@ void V_DrawPromptBack(INT32 boxheight, INT32 color) boxheight = -boxheight; else // 4 lines of space plus gaps between and some leeway boxheight = ((boxheight * 4) + (boxheight/2)*5); - V_DrawFill((BASEVIDWIDTH-(vid.width/vid.dupx))/2, BASEVIDHEIGHT-boxheight, (vid.width/vid.dupx),boxheight, (color-256)|V_SNAPTOBOTTOM); + V_DrawFill((BASEVIDWIDTH-(vid.width/vid.dup))/2, BASEVIDHEIGHT-boxheight, (vid.width/vid.dup),boxheight, (color-256)|V_SNAPTOBOTTOM); return; } - boxheight *= vid.dupy; + boxheight *= vid.dup; if (color == INT32_MAX) color = cons_backcolor.value; @@ -2099,7 +2076,7 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = (option & V_CHARCOLORMASK); const UINT8 *colormap = NULL; @@ -2110,20 +2087,19 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; switch (option & V_SPACINGMASK) { @@ -2155,9 +2131,9 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 8*dupy; + cy += 8*dup; else - cy += 12*dupy; + cy += 12*dup; continue; } @@ -2170,17 +2146,17 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) // character does not exist or is a space if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/2; + w = charwidth * dup; + center = w/2 - hu_font[c]->width*dup/2; } else - w = hu_font[c]->width * dupx; + w = hu_font[c]->width * dup; if (cx > scrwidth) continue; @@ -2215,7 +2191,7 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2226,20 +2202,19 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; charflags = (option & V_CHARCOLORMASK); @@ -2273,9 +2248,9 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 4*dupy; + cy += 4*dup; else - cy += 6*dupy; + cy += 6*dup; continue; } @@ -2287,17 +2262,17 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/4; + w = charwidth * dup; + center = w/2 - hu_font[c]->width*dup/4; } else - w = hu_font[c]->width * dupx / 2; + w = hu_font[c]->width * dup / 2; if (cx > scrwidth) continue; @@ -2333,7 +2308,7 @@ void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *s // void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2344,20 +2319,19 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; charflags = (option & V_CHARCOLORMASK); @@ -2391,9 +2365,9 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 8*dupy; + cy += 8*dup; else - cy += 12*dupy; + cy += 12*dup; continue; } @@ -2405,14 +2379,14 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) - w = charwidth * dupx; + w = charwidth * dup; else - w = tny_font[c]->width * dupx; + w = tny_font[c]->width * dup; if (cx > scrwidth) continue; @@ -2471,7 +2445,7 @@ void V_DrawRightAlignedSmallThinString(INT32 x, INT32 y, INT32 option, const cha void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2482,20 +2456,19 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; charflags = (option & V_CHARCOLORMASK); @@ -2529,9 +2502,9 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += (8*dupy)<= HU_FONTSIZE || !hu_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/2); + w = charwidth * dup; + center = w/2 - hu_font[c]->width*(dup/2); } else - w = hu_font[c]->width * dupx; + w = hu_font[c]->width * dup; if ((cx>>FRACBITS) > scrwidth) continue; @@ -2587,7 +2560,7 @@ void V_DrawRightAlignedStringAtFixed(fixed_t x, fixed_t y, INT32 option, const c void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2598,20 +2571,19 @@ void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *st if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; charflags = (option & V_CHARCOLORMASK); @@ -2645,9 +2617,9 @@ void V_DrawSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *st cx = x; if (option & V_RETURN8) - cy += (4*dupy)<= HU_FONTSIZE || !hu_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/4); + w = charwidth * dup; + center = w/2 - hu_font[c]->width*(dup/4); } else - w = hu_font[c]->width * dupx / 2; + w = hu_font[c]->width * dup / 2; if ((cx>>FRACBITS) > scrwidth) break; @@ -2704,7 +2676,7 @@ void V_DrawRightAlignedSmallStringAtFixed(fixed_t x, fixed_t y, INT32 option, co void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2715,20 +2687,19 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; charflags = (option & V_CHARCOLORMASK); @@ -2762,9 +2733,9 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str cx = x; if (option & V_RETURN8) - cy += (8*dupy)<= HU_FONTSIZE || !tny_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/2); + w = charwidth * dup; + center = w/2 - tny_font[c]->width*(dup/2); } else - w = tny_font[c]->width * dupx; + w = tny_font[c]->width * dup; if ((cx>>FRACBITS) > scrwidth) break; @@ -2821,7 +2792,7 @@ void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, con void V_DrawSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2832,20 +2803,19 @@ void V_DrawSmallThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char if (option & V_NOSCALESTART) { - dupx = vid.dupx<= HU_FONTSIZE || !tny_font[c]) { - cx += FixedMul(spacewidth, dupx); + cx += FixedMul(spacewidth, dup); continue; } if (charwidth) { - w = FixedMul(charwidth, dupx); - center = w/2 - tny_font[c]->width*(dupx/4); + w = FixedMul(charwidth, dup); + center = w/2 - tny_font[c]->width*(dup/4); } else - w = tny_font[c]->width * dupx / 2; + w = tny_font[c]->width * dup / 2; if (cx > scrwidth) break; @@ -2941,7 +2911,7 @@ void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) boolean neg; if (flags & (V_NOSCALESTART|V_NOSCALEPATCH)) - w *= vid.dupx; + w *= vid.dup; if ((neg = num < 0)) num = -num; @@ -2966,7 +2936,7 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) INT32 w = tallnum[0]->width; if (flags & (V_NOSCALESTART|V_NOSCALEPATCH)) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -3001,7 +2971,7 @@ void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num) // void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) { - INT32 w, c, dupx, dupy, scrwidth = BASEVIDWIDTH; + INT32 w, c, dup, scrwidth = BASEVIDWIDTH; fixed_t cx = x, cy = y; const char *ch = string; @@ -3011,15 +2981,14 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else - dupx = dupy = 1; + dup = 1; if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; for (;;) { @@ -3029,18 +2998,18 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) if (c == '\n') { cx = x; - cy += (12*dupy)<= CRED_FONTSIZE) { - cx += (16*dupx)<width * dupx; + w = cred_font[c]->width * dup; if ((cx>>FRACBITS) > scrwidth) continue; @@ -3054,7 +3023,7 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UINT8 *basecolormap, UINT8 *outlinecolormap, const char *string) { fixed_t cx, cy, w; - INT32 c, dupx, dupy, scrwidth, left = 0; + INT32 c, dup, scrwidth, left = 0; const char *ch = string; if (option & V_CENTERNAMETAG) @@ -3066,20 +3035,19 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; for (;;ch++) { @@ -3088,7 +3056,7 @@ static void V_DrawNameTagLine(INT32 x, INT32 y, INT32 option, fixed_t scale, UIN if (*ch == '\n') { cx = x<= NT_FONTSIZE || !ntb_font[c] || !nto_font[c]) { - cx += FixedMul((4 * dupx)*FRACUNIT, scale); + cx += FixedMul((4 * dup)*FRACUNIT, scale); continue; } - w = FixedMul(((ntb_font[c]->width)+2 * dupx) * FRACUNIT, scale); + w = FixedMul(((ntb_font[c]->width)+2 * dup) * FRACUNIT, scale); if (FixedInt(cx) > scrwidth) continue; @@ -3277,27 +3245,26 @@ INT32 V_CreditStringWidth(const char *string) // void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, left = 0; const char *ch = string; INT32 charflags = (option & V_CHARCOLORMASK); const UINT8 *colormap = NULL; if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.width/vid.dup; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } if (option & V_NOSCALEPATCH) - scrwidth *= vid.dupx; + scrwidth *= vid.dup; for (;;ch++) { @@ -3313,18 +3280,18 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) if (*ch == '\n') { cx = x; - cy += 12*dupy; + cy += 12*dup; continue; } c = *ch - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) { - cx += 16*dupx; + cx += 16*dup; continue; } - w = lt_font[c]->width * dupx; + w = lt_font[c]->width * dup; if (cx > scrwidth) continue; @@ -3435,7 +3402,7 @@ INT32 V_StringWidth(const char *string, INT32 option) } if (option & (V_NOSCALESTART|V_NOSCALEPATCH)) - w *= vid.dupx; + w *= vid.dup; return w; } @@ -3682,7 +3649,7 @@ Unoptimized version { // Shift this row of pixels to the right by 2 tmpscr[y*vid.width] = srcscr[y*vid.width]; - M_Memcpy(&tmpscr[y*vid.width+vid.dupx], &srcscr[y*vid.width], vid.width-vid.dupx); + M_Memcpy(&tmpscr[y*vid.width+vid.dup], &srcscr[y*vid.width], vid.width-vid.dup); } else M_Memcpy(&tmpscr[y*vid.width], &srcscr[y*vid.width], vid.width); @@ -3783,31 +3750,23 @@ void V_Recalc(void) { // scale 1,2,3 times in x and y the patches for the menus and overlays... // calculated once and for all, used by routines in v_video.c and v_draw.c - vid.dupx = vid.width / BASEVIDWIDTH; - vid.dupy = vid.height / BASEVIDHEIGHT; - vid.dupx = vid.dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - vid.fdupx = FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT); - vid.fdupy = FixedDiv(vid.height*FRACUNIT, BASEVIDHEIGHT*FRACUNIT); -#ifdef HWRENDER - //if (rendermode != render_opengl && rendermode != render_none) // This was just placing it incorrectly at non aspect correct resolutions in opengl - // 13/11/18: - // The above is no longer necessary, since we want OpenGL to be just like software now - // -- Monster Iestyn -#endif - vid.fdupx = vid.fdupy = (vid.fdupx < vid.fdupy ? vid.fdupx : vid.fdupy); + // Set dup based on width or height, whichever is less + if (((vid.width*FRACUNIT) / BASEVIDWIDTH) < ((vid.height*FRACUNIT) / BASEVIDHEIGHT)) + { + vid.dup = vid.width / BASEVIDWIDTH; + vid.fdup = (vid.width*FRACUNIT) / BASEVIDWIDTH; + } + else + { + vid.dup = vid.height / BASEVIDHEIGHT; + vid.fdup = (vid.height*FRACUNIT) / BASEVIDHEIGHT; + } - vid.meddupx = (UINT8)(vid.dupx >> 1) + 1; - vid.meddupy = (UINT8)(vid.dupy >> 1) + 1; + vid.meddup = (UINT8)(vid.dup >> 1) + 1; + vid.smalldup = (UINT8)(vid.dup / 3) + 1; #ifdef HWRENDER - vid.fmeddupx = vid.meddupx*FRACUNIT; - vid.fmeddupy = vid.meddupy*FRACUNIT; -#endif - - vid.smalldupx = (UINT8)(vid.dupx / 3) + 1; - vid.smalldupy = (UINT8)(vid.dupy / 3) + 1; -#ifdef HWRENDER - vid.fsmalldupx = vid.smalldupx*FRACUNIT; - vid.fsmalldupy = vid.smalldupy*FRACUNIT; + vid.fmeddup = vid.meddup*FRACUNIT; + vid.fsmalldup = vid.smalldup*FRACUNIT; #endif } diff --git a/src/v_video.h b/src/v_video.h index ff03836b5..80936f3ee 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -36,7 +36,7 @@ cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, // Allocates buffer screens, call before R_Init. void V_Init(void); -// Recalculates the viddef (dupx, dupy, etc.) according to the current screen resolution. +// Recalculates the viddef (dup, fdup, etc.) according to the current screen resolution. void V_Recalc(void); // Color look-up table diff --git a/src/y_inter.c b/src/y_inter.c index 69dc931ba..369ec3904 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -536,7 +536,7 @@ void Y_IntermissionDrawer(void) if (animatetic && (tic_t)intertic >= animatetic) { - const INT32 scradjust = (vid.width/vid.dupx)>>3; // 40 for BASEVIDWIDTH + const INT32 scradjust = (vid.width/vid.dup)>>3; // 40 for BASEVIDWIDTH INT32 animatetimer = (intertic - animatetic); if (animatetimer <= 16) { @@ -687,7 +687,7 @@ void Y_IntermissionDrawer(void) if (intertic > 1) { - if (stagefailed && data.spec.emeraldy < (vid.height/vid.dupy)+16) + if (stagefailed && data.spec.emeraldy < (vid.height/vid.dup)+16) { emeraldx += intertic - 6; } @@ -1163,7 +1163,7 @@ void Y_Ticker(void) } else { - if (data.spec.emeraldy < (vid.height/vid.dupy)+16) + if (data.spec.emeraldy < (vid.height/vid.dup)+16) { data.spec.emeraldy += (++data.spec.emeraldmomy); } From 4e446d22d602f8a35dc269834dbddddeaddccaee Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 31 Oct 2023 04:04:01 -0300 Subject: [PATCH 69/91] Fix pickedchar not being set when it should have been --- src/d_main.c | 5 +++-- src/g_demo.c | 8 ++++++-- src/m_menu.c | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 80907a013..274e4ceb3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1614,6 +1614,9 @@ void D_SRB2Main(void) if (D_CheckNetGame()) autostart = true; + if (!dedicated) + pickedchar = R_SkinAvailable(cv_defaultskin.string); + // check for a driver that wants intermission stats // start the apropriate game based on parms if (M_CheckParm("-metal")) @@ -1627,8 +1630,6 @@ void D_SRB2Main(void) autostart = true; } - pickedchar = R_SkinAvailable(cv_defaultskin.string); - // user settings come before "+" parameters. if (dedicated) COM_ImmedExecute(va("exec \"%s"PATHSEP"adedserv.cfg\"\n", srb2home)); diff --git a/src/g_demo.c b/src/g_demo.c index cb168dfd9..632947291 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -1492,8 +1492,12 @@ void G_BeginRecording(void) demo_p += 16; // Skin - for (i = 0; i < 16 && cv_skin.string[i]; i++) - name[i] = cv_skin.string[i]; + const char *skinname = cv_skin.string; + if (pickedchar >= 0 && pickedchar < numskins) + skinname = skins[pickedchar].name; + + for (i = 0; i < 16 && skinname[i]; i++) + name[i] = skinname[i]; for (; i < 16; i++) name[i] = '\0'; M_Memcpy(demo_p,name,16); diff --git a/src/m_menu.c b/src/m_menu.c index 629f53d24..e2866f32b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10372,6 +10372,8 @@ static void M_ChooseNightsAttack(INT32 choice) sprintf(gpath,"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(cv_nextmap.value)); snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, skins[cv_chooseskin.value-1].name); + pickedchar = cv_chooseskin.value-1; + if (!cv_autorecord.value) remove(va("%s"PATHSEP"%s.lmp", srb2home, nameofdemo)); else @@ -10401,6 +10403,8 @@ static void M_ChooseTimeAttack(INT32 choice) sprintf(gpath,"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(cv_nextmap.value)); snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, skins[cv_chooseskin.value-1].name); + pickedchar = cv_chooseskin.value-1; + if (!cv_autorecord.value) remove(va("%s"PATHSEP"%s.lmp", srb2home, nameofdemo)); else From 36e20ac619a7da0d8b640d36b5ff46cabc825539 Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Thu, 2 Feb 2023 15:47:42 +0100 Subject: [PATCH 70/91] Tiny caption loop optimisation --- src/screen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screen.c b/src/screen.c index 0719da83c..61e63cdf4 100644 --- a/src/screen.c +++ b/src/screen.c @@ -552,7 +552,7 @@ void SCR_ClosedCaptions(void) { UINT8 i; boolean gamestopped = (paused || P_AutoPause()); - INT32 basey = BASEVIDHEIGHT; + INT32 basey = BASEVIDHEIGHT - 20; if (gamestate != wipegamestate) return; @@ -585,7 +585,7 @@ void SCR_ClosedCaptions(void) continue; flags = V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE; - y = basey-((i + 2)*10); + y = basey-(i*10); if (closedcaptions[i].b) { From c2aa6d4c74d50d239cbe264bd7eddec2bc9db4d7 Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Thu, 2 Feb 2023 15:49:54 +0100 Subject: [PATCH 71/91] Fix captions being over-affected by GUI scale Captions' pop-in animation now starts 8 GUI pixels above the resting position, instead of (2 x GUI scale) GUI above it --- src/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screen.c b/src/screen.c index 61e63cdf4..73e09963c 100644 --- a/src/screen.c +++ b/src/screen.c @@ -589,7 +589,7 @@ void SCR_ClosedCaptions(void) if (closedcaptions[i].b) { - y -= closedcaptions[i].b * vid.dup; + y -= closedcaptions[i].b * 4; if (renderisnewtic) { closedcaptions[i].b--; From 8cf6e8252c4c7b9bc5b79e4e7f780364ce0418aa Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Thu, 2 Feb 2023 15:50:40 +0100 Subject: [PATCH 72/91] Interpolate captions --- src/s_sound.c | 2 +- src/screen.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index ada1a0fd2..a579292ff 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -513,7 +513,7 @@ void S_StartCaption(sfxenum_t sfx_id, INT32 cnum, UINT16 lifespan) closedcaptions[set].c = ((cnum == -1) ? NULL : &channels[cnum]); closedcaptions[set].s = sfx; closedcaptions[set].t = lifespan; - closedcaptions[set].b = 2; // bob + closedcaptions[set].b = 3; // bob } void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) diff --git a/src/screen.c b/src/screen.c index 73e09963c..3c50ec67e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -572,7 +572,8 @@ void SCR_ClosedCaptions(void) for (i = 0; i < NUMCAPTIONS; i++) { - INT32 flags, y; + INT32 flags; + fixed_t y; char dot; boolean music; @@ -585,14 +586,19 @@ void SCR_ClosedCaptions(void) continue; flags = V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_ALLOWLOWERCASE; - y = basey-(i*10); + y = (basey-(i*10)) * FRACUNIT; if (closedcaptions[i].b) { - y -= closedcaptions[i].b * 4; if (renderisnewtic) - { closedcaptions[i].b--; + + if (closedcaptions[i].b) // If the caption hasn't reached its final destination... + { + y -= closedcaptions[i].b * 4 * FRACUNIT; // ...move it per tic... + y += (rendertimefrac % FRACUNIT) * 4; // ...and interpolate it per frame + // We have to modulo it by FRACUNIT, so that it won't be a tic ahead with interpolation disabled + // Unlike everything else, captions are (intentionally) interpolated from T to T+1 instead of T-1 to T } } @@ -606,7 +612,7 @@ void SCR_ClosedCaptions(void) else dot = ' '; - V_DrawRightAlignedString(BASEVIDWIDTH - 20, y, flags, + V_DrawRightAlignedStringAtFixed((BASEVIDWIDTH-20) * FRACUNIT, y, flags, va("%c [%s]", dot, (closedcaptions[i].s->caption[0] ? closedcaptions[i].s->caption : closedcaptions[i].s->name))); } } From e9637322f92160e015b50c7fa240c006baf9223f Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 31 Oct 2023 16:45:47 -0300 Subject: [PATCH 73/91] Simplify fix pickedchar doesn't need to be set in these two places, since G_DeferedInitNew already does that. --- src/g_demo.c | 5 +---- src/m_menu.c | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index 632947291..7026c3391 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -1492,10 +1492,7 @@ void G_BeginRecording(void) demo_p += 16; // Skin - const char *skinname = cv_skin.string; - if (pickedchar >= 0 && pickedchar < numskins) - skinname = skins[pickedchar].name; - + const char *skinname = skins[players[0].skin].name; for (i = 0; i < 16 && skinname[i]; i++) name[i] = skinname[i]; for (; i < 16; i++) diff --git a/src/m_menu.c b/src/m_menu.c index e2866f32b..629f53d24 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -10372,8 +10372,6 @@ static void M_ChooseNightsAttack(INT32 choice) sprintf(gpath,"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(cv_nextmap.value)); snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, skins[cv_chooseskin.value-1].name); - pickedchar = cv_chooseskin.value-1; - if (!cv_autorecord.value) remove(va("%s"PATHSEP"%s.lmp", srb2home, nameofdemo)); else @@ -10403,8 +10401,6 @@ static void M_ChooseTimeAttack(INT32 choice) sprintf(gpath,"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(cv_nextmap.value)); snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, skins[cv_chooseskin.value-1].name); - pickedchar = cv_chooseskin.value-1; - if (!cv_autorecord.value) remove(va("%s"PATHSEP"%s.lmp", srb2home, nameofdemo)); else From d6b92de6910fccb845820fb206e3af3d7979270b Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 31 Oct 2023 16:52:12 -0300 Subject: [PATCH 74/91] Revert these --- src/p_saveg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 3bcfea7cd..b496dce50 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1893,7 +1893,7 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type) if (diff & MD_RTIME) WRITEINT32(save_p, mobj->reactiontime); if (diff & MD_STATE) - WRITEUINT32(save_p, mobj->state-states); + WRITEUINT16(save_p, mobj->state-states); if (diff & MD_TICS) WRITEINT32(save_p, mobj->tics); if (diff & MD_SPRITE) { @@ -2917,7 +2917,7 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker) mobj->reactiontime = mobj->info->reactiontime; if (diff & MD_STATE) - mobj->state = &states[READUINT32(save_p)]; + mobj->state = &states[READUINT16(save_p)]; else mobj->state = &states[mobj->info->spawnstate]; if (diff & MD_TICS) From 7643ffadbc7887eab545e061674ab359e075a5c6 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Wed, 1 Nov 2023 15:13:40 +0000 Subject: [PATCH 75/91] Update .gitlab-ci.yml file Limit builds to just "Windows x86" and "Debian stable:amd64", all other builds can be started manually --- .gitlab-ci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c61e181a5..ef2304410 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -159,6 +159,9 @@ stages: Debian testing GCC: stage: build + + when: manual + image: debian:testing-slim allow_failure: true @@ -198,6 +201,8 @@ Debian testing GCC: Windows x86: stage: build + when: on_success + artifacts: paths: - "bin/" @@ -228,6 +233,8 @@ Windows x86: Debian stable:amd64: stage: build + when: on_success + artifacts: paths: - "bin/" @@ -270,6 +277,8 @@ Debian stable:amd64: Debian stable:i386: stage: build + when: manual + artifacts: paths: - "bin/" @@ -311,6 +320,8 @@ Debian stable:i386: Debian stable:arm64: stage: build + when: manual + artifacts: paths: - "bin/" @@ -353,6 +364,8 @@ Debian stable:arm64: Windows x64: stage: build + when: manual + artifacts: paths: - "bin/" @@ -383,6 +396,8 @@ Windows x64: Debian stable Clang: stage: build + when: manual + allow_failure: true artifacts: @@ -422,6 +437,8 @@ Debian stable Clang: Debian stable musl: stage: build + when: manual + allow_failure: true artifacts: @@ -459,6 +476,8 @@ Debian stable musl: Debian testing Clang: extends: Debian stable Clang + when: manual + image: debian:testing-slim artifacts: @@ -473,6 +492,8 @@ Debian testing Clang: Debian testing musl: extends: Debian stable musl + when: manual + image: debian:testing-slim artifacts: From 5d188221429e439d535956b2cc867f129691427f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 4 Nov 2023 14:21:17 +0100 Subject: [PATCH 76/91] Improve file search performance on Linux and FreeBSD --- src/filesrch.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/filesrch.c b/src/filesrch.c index 313f286e1..111dfd6e7 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -433,9 +433,19 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want // okay, now we actually want searchpath to incorporate d_name strcpy(&searchpath[searchpathindex[depthleft]],dent->d_name); +#if defined(__linux__) || defined(__FreeBSD__) + if (dent->d_type == DT_UNKNOWN) + if (lstat(searchpath,&fsstat) == 0 && S_ISDIR(fsstat.st_mode)) + dent->d_type = DT_DIR; + + // Linux and FreeBSD has a special field for file type on dirent, so use that to speed up lookups. + // FIXME: should we also follow symlinks? + if (dent->d_type == DT_DIR && depthleft) +#else if (stat(searchpath,&fsstat) < 0) // do we want to follow symlinks? if not: change it to lstat ; // was the file (re)moved? can't stat it else if (S_ISDIR(fsstat.st_mode) && depthleft) +#endif { searchpathindex[--depthleft] = strlen(searchpath) + 1; dirhandle[depthleft] = opendir(searchpath); From 55444cf20460c8d38f843446195e43a8ab0b9b68 Mon Sep 17 00:00:00 2001 From: Krabs <75001008+krabsisa@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:31:03 -0500 Subject: [PATCH 77/91] Update version num (no, .14 isn't releasing yet) --- appveyor.yml | 2 +- src/version.h | 6 +++--- src/win32/Srb2win.rc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 63d801b73..d0d94b982 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.2.13.{branch}-{build} +version: 2.2.14.{branch}-{build} os: MinGW environment: diff --git a/src/version.h b/src/version.h index 3242cad67..8d8f8978e 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ -#define SRB2VERSION "2.2.13"/* this must be the first line, for cmake !! */ +#define SRB2VERSION "2.2.14"/* this must be the first line, for cmake !! */ // The Modification ID; must be obtained from a Master Server Admin ( https://mb.srb2.org/members/?key=ms_admin ). // DO NOT try to set this otherwise, or your modification will be unplayable through the Master Server. @@ -9,7 +9,7 @@ // it's only for detection of the version the player is using so the MS can alert them of an update. // Only set it higher, not lower, obviously. // Note that we use this to help keep internal testing in check; this is why v2.2.0 is not version "1". -#define MODVERSION 54 +#define MODVERSION 55 // Define this as a prerelease version suffix (pre#, RC#) -//#define BETAVERSION "pre1" +#define BETAVERSION "nightly" diff --git a/src/win32/Srb2win.rc b/src/win32/Srb2win.rc index b69900746..9ee9b7d3f 100644 --- a/src/win32/Srb2win.rc +++ b/src/win32/Srb2win.rc @@ -77,8 +77,8 @@ END #include "../doomdef.h" // Needed for version string VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,2,13,0 - PRODUCTVERSION 2,2,13,0 + FILEVERSION 2,2,14,0 + PRODUCTVERSION 2,2,14,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L From 7c986c6d292d8470accd242a81ed14656cc63d18 Mon Sep 17 00:00:00 2001 From: SMS Alfredo <65426124+SMS-Alfredo@users.noreply.github.com> Date: Thu, 9 Nov 2023 17:01:27 -0600 Subject: [PATCH 78/91] Make sure bot has CA_FLY or CA2_SPINDASH for their behaviors --- src/b_bot.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/b_bot.c b/src/b_bot.c index 57f762304..033288a86 100644 --- a/src/b_bot.c +++ b/src/b_bot.c @@ -239,7 +239,8 @@ static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) // SPINNING if (!(player->pflags & (PF_SPINNING|PF_STARTDASH)) && mem->thinkstate == AI_SPINFOLLOW) mem->thinkstate = AI_FOLLOW; - else if (mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_SPINFOLLOW) + else if ((mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_SPINFOLLOW) + && bot->charability2 == CA2_SPINDASH) { if (!_2d) { @@ -329,7 +330,7 @@ static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) if (mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_CATCHUP || (mem->thinkstate == AI_SPINFOLLOW && player->pflags & PF_JUMPED)) { // Flying catch-up - if (bot->pflags & PF_THOKKED) + if (bot->charability == CA_FLY && bot->pflags & PF_THOKKED) { cmd->forwardmove = min(MAXPLMOVE, (dist/scale)>>3); if (zdist < -64*scale) From 2062553d22a5c4a544f11080e17a09addf93cd1b Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Thu, 9 Nov 2023 20:21:04 -0500 Subject: [PATCH 79/91] Update i_system.c Add a check for overflowing the TERIOS buffer --- src/sdl/i_system.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 2a26f3f50..9dd80e6ef 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -607,6 +607,7 @@ void I_GetConsoleEvents(void) return; ev.type = ev_console; + ev.key = 0; if (read(STDIN_FILENO, &key, 1) == -1 || !key) return; @@ -633,7 +634,7 @@ void I_GetConsoleEvents(void) } else return; } - else + else if (tty_con.cursor < sizeof (tty_con.buffer)) { // push regular character ev.key = tty_con.buffer[tty_con.cursor] = key; From f644877bd3926ff841587a53e0821ee2d0fbda97 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Fri, 10 Nov 2023 15:42:37 +0000 Subject: [PATCH 80/91] Update .gitlab-ci.yml file Fixup ARM64 build --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef2304410..4e284ce65 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -356,7 +356,7 @@ Debian stable:arm64: - - | # make echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" - - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 ERRORMODE=1 NONX86=1C || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 NONX86=1 ARM64=1 + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 ERRORMODE=1 NONX86=1 ARM64=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 NONX86=1 ARM64=1 - | # make echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" From 8cc7a88c5f09de7391d50a0f10401ac7ff7861d6 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Thu, 16 Nov 2023 22:00:23 +0100 Subject: [PATCH 81/91] Make module music volume more accurate --- src/sdl/mixer_sound.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 0a39c7f28..bd4a23c0d 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -759,8 +759,8 @@ static void mix_gme(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif @@ -783,8 +783,8 @@ static void mix_openmpt(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif From 13aed6ad25fd723c8ea2bf08c0bdc5486806fc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 18 Nov 2023 14:44:59 +0100 Subject: [PATCH 82/91] Add apropos console command --- src/command.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index e0deff8e1..d20c9c4ff 100644 --- a/src/command.c +++ b/src/command.c @@ -51,9 +51,11 @@ static void COM_CEchoDuration_f(void); static void COM_Exec_f(void); static void COM_Wait_f(void); static void COM_Help_f(void); +static void COM_Apropos_f(void); static void COM_Toggle_f(void); static void COM_Add_f(void); + static void CV_EnforceExecVersion(void); static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr); static boolean CV_Command(void); @@ -344,6 +346,7 @@ void COM_Init(void) COM_AddCommand("exec", COM_Exec_f, 0); COM_AddCommand("wait", COM_Wait_f, 0); COM_AddCommand("help", COM_Help_f, COM_LUA); + COM_AddCommand("apropos", COM_Apropos_f, COM_LUA); COM_AddCommand("toggle", COM_Toggle_f, COM_LUA); COM_AddCommand("add", COM_Add_f, COM_LUA); RegisterNetXCmd(XD_NETVAR, Got_NetVar); @@ -879,7 +882,7 @@ static void COM_Help_f(void) boolean floatmode = false; const char *cvalue = NULL; CONS_Printf("\x82""Variable %s:\n", cvar->name); - CONS_Printf(M_GetText(" flags :")); + CONS_Printf(M_GetText(" flags: ")); if (cvar->flags & CV_SAVE) CONS_Printf("AUTOSAVE "); if (cvar->flags & CV_FLOAT) @@ -1030,6 +1033,35 @@ static void COM_Help_f(void) } } +static void COM_Apropos_f(void) +{ + xcommand_t *cmd; + consvar_t *cvar; + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("apropos : Search for cvars and cmds containing text\n")); + return; + } + + CONS_Printf("\x82""Matching variables:\n"); + for (cvar = consvar_vars; cvar; cvar = cvar->next) + { + if (cvar->flags & CV_NOSHOWHELP) + continue; + if (strstr(cvar->name, COM_Argv(1)) != NULL) + CONS_Printf("%s ", cvar->name); + } + + CONS_Printf("\x82""\nMatching commands:\n"); + for (cmd = com_commands; cmd; cmd = cmd->next) + { + if (strstr(cmd->name, COM_Argv(1)) != NULL) + CONS_Printf("%s ", cmd->name); + } + CONS_Printf("\n"); +} + /** Toggles a console variable. Useful for on/off values. * * This works on on/off, yes/no values only From fa050cdebf89b8ea0aeb888a2b9289e5ae0ffd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 18 Nov 2023 20:44:26 +0100 Subject: [PATCH 83/91] Redesign search mechanism --- src/command.c | 90 ++++++++++++++++++++++++++++++--------------------- src/console.c | 27 ++-------------- 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/src/command.c b/src/command.c index d20c9c4ff..d41a55153 100644 --- a/src/command.c +++ b/src/command.c @@ -51,7 +51,7 @@ static void COM_CEchoDuration_f(void); static void COM_Exec_f(void); static void COM_Wait_f(void); static void COM_Help_f(void); -static void COM_Apropos_f(void); +static void COM_Find_f(void); static void COM_Toggle_f(void); static void COM_Add_f(void); @@ -346,7 +346,7 @@ void COM_Init(void) COM_AddCommand("exec", COM_Exec_f, 0); COM_AddCommand("wait", COM_Wait_f, 0); COM_AddCommand("help", COM_Help_f, COM_LUA); - COM_AddCommand("apropos", COM_Apropos_f, COM_LUA); + COM_AddCommand("find", COM_Find_f, COM_LUA); COM_AddCommand("toggle", COM_Toggle_f, COM_LUA); COM_AddCommand("add", COM_Add_f, COM_LUA); RegisterNetXCmd(XD_NETVAR, Got_NetVar); @@ -979,31 +979,8 @@ static void COM_Help_f(void) return; } - CONS_Printf("No exact match, searching...\n"); - - // variables - CONS_Printf("\x82""Variables:\n"); - for (cvar = consvar_vars; cvar; cvar = cvar->next) - { - if ((cvar->flags & CV_NOSHOWHELP) || (!strstr(cvar->name, help))) - continue; - CONS_Printf("%s ", cvar->name); - i++; - } - - // commands - CONS_Printf("\x82""\nCommands:\n"); - for (cmd = com_commands; cmd; cmd = cmd->next) - { - if (!strstr(cmd->name, help)) - continue; - CONS_Printf("%s ",cmd->name); - i++; - } - - CONS_Printf("\x82""\nCheck wiki.srb2.org for more or type help \n"); - - CONS_Debug(DBG_GAMELOGIC, "\x87Total : %d\n", i); + CONS_Printf("No variable or command named %s", help); + CONS_Printf("\x82""\nCheck wiki.srb2.org for more or try typing help without arguments\n"); } return; } @@ -1033,33 +1010,74 @@ static void COM_Help_f(void) } } -static void COM_Apropos_f(void) +static void COM_Find_f(void) { + static char prefix[80]; xcommand_t *cmd; consvar_t *cvar; + cmdalias_t *alias; + const char *match; + const char *help; + size_t helplen; + boolean matchesany; if (COM_Argc() != 2) { - CONS_Printf(M_GetText("apropos : Search for cvars and cmds containing text\n")); + CONS_Printf(M_GetText("find : Search for variables, commands and aliases containing \n")); return; } - CONS_Printf("\x82""Matching variables:\n"); + help = COM_Argv(1); + helplen = strlen(help); + CONS_Printf("\x82""Variables:\n"); + matchesany = false; for (cvar = consvar_vars; cvar; cvar = cvar->next) { if (cvar->flags & CV_NOSHOWHELP) continue; - if (strstr(cvar->name, COM_Argv(1)) != NULL) - CONS_Printf("%s ", cvar->name); + match = strstr(cvar->name, help); + if (match != NULL) + { + memcpy(prefix, cvar->name, match - cvar->name); + prefix[match - cvar->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } } + if (!matchesany) + CONS_Printf(" (none)\n"); - CONS_Printf("\x82""\nMatching commands:\n"); + CONS_Printf("\x82""Commands:\n"); + matchesany = false; for (cmd = com_commands; cmd; cmd = cmd->next) { - if (strstr(cmd->name, COM_Argv(1)) != NULL) - CONS_Printf("%s ", cmd->name); + match = strstr(cmd->name, help); + if (match != NULL) + { + memcpy(prefix, cmd->name, match - cmd->name); + prefix[match - cmd->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } } - CONS_Printf("\n"); + if (!matchesany) + CONS_Printf(" (none)\n"); + + CONS_Printf("\x82""Aliases:\n"); + matchesany = false; + for (alias = com_alias; alias; alias = alias->next) + { + match = strstr(alias->name, help); + if (match != NULL) + { + memcpy(prefix, alias->name, match - alias->name); + prefix[match - alias->name] = '\0'; + CONS_Printf(" %s\x83%s\x80%s\n", prefix, help, &match[helplen]); + matchesany = true; + } + } + if (!matchesany) + CONS_Printf(" (none)\n"); } /** Toggles a console variable. Useful for on/off values. diff --git a/src/console.c b/src/console.c index dbd7c938a..01b90ebc3 100644 --- a/src/console.c +++ b/src/console.c @@ -921,7 +921,8 @@ boolean CON_Responder(event_t *ev) static UINT8 consdown = false; // console is treated differently due to rare usage // sequential completions a la 4dos - static char completion[80]; + static char completioncmd[80 + sizeof("find ")] = "find "; + static char *completion = &completioncmd[sizeof("find ")-1]; static INT32 skips; @@ -1057,36 +1058,14 @@ boolean CON_Responder(event_t *ev) // show all cvars/commands that match what we have inputted if (key == KEY_TAB) { - size_t i, len; - if (!completion[0]) { if (!input_len || input_len >= 40 || strchr(inputlines[inputline], ' ')) return true; strcpy(completion, inputlines[inputline]); } - len = strlen(completion); - - //first check commands - CONS_Printf("\nCommands:\n"); - for (i = 0, cmd = COM_CompleteCommand(completion, i); cmd; cmd = COM_CompleteCommand(completion, ++i)) - CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len); - if (i == 0) CONS_Printf(" (none)\n"); - - //now we move on to CVARs - CONS_Printf("Variables:\n"); - for (i = 0, cmd = CV_CompleteVar(completion, i); cmd; cmd = CV_CompleteVar(completion, ++i)) - CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len); - if (i == 0) CONS_Printf(" (none)\n"); - - //and finally aliases - CONS_Printf("Aliases:\n"); - for (i = 0, cmd = COM_CompleteAlias(completion, i); cmd; cmd = COM_CompleteAlias(completion, ++i)) - CONS_Printf(" \x83" "%s" "\x80" "%s\n", completion, cmd+len); - if (i == 0) CONS_Printf(" (none)\n"); - + COM_BufInsertText(completioncmd); completion[0] = 0; - return true; } // --- From e6dfeace843570ad7a13565eb729d143ce95a1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sun, 19 Nov 2023 13:17:18 +0100 Subject: [PATCH 84/91] Fix anisotropic and FOV settings not saving --- src/hardware/hw_main.c | 17 ++--------------- src/hardware/hw_main.h | 1 - src/r_main.c | 2 +- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2d7c99861..a473a9292 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -169,7 +169,6 @@ ps_metric_t ps_hw_batchdrawtime = {0}; boolean gl_init = false; boolean gl_maploaded = false; -boolean gl_sessioncommandsadded = false; boolean gl_shadersavailable = true; // ========================================================================== @@ -6595,7 +6594,7 @@ consvar_t cv_glfakecontrast = CVAR_INIT ("gr_fakecontrast", "Smooth", CV_SAVE, g consvar_t cv_glslopecontrast = CVAR_INIT ("gr_slopecontrast", "Off", CV_SAVE, CV_OnOff, NULL); consvar_t cv_glfiltermode = CVAR_INIT ("gr_filtermode", "Nearest", CV_SAVE|CV_CALL, glfiltermode_cons_t, CV_glfiltermode_OnChange); -consvar_t cv_glanisotropicmode = CVAR_INIT ("gr_anisotropicmode", "1", CV_CALL, glanisotropicmode_cons_t, CV_glanisotropic_OnChange); +consvar_t cv_glanisotropicmode = CVAR_INIT ("gr_anisotropicmode", "1", CV_SAVE|CV_CALL, glanisotropicmode_cons_t, CV_glanisotropic_OnChange); consvar_t cv_glsolvetjoin = CVAR_INIT ("gr_solvetjoin", "On", 0, CV_OnOff, NULL); @@ -6637,6 +6636,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_glallowshaders); CV_RegisterVar(&cv_glfiltermode); + CV_RegisterVar(&cv_glanisotropicmode); CV_RegisterVar(&cv_glsolvetjoin); CV_RegisterVar(&cv_glbatching); @@ -6646,14 +6646,6 @@ void HWR_AddCommands(void) #endif } -void HWR_AddSessionCommands(void) -{ - if (gl_sessioncommandsadded) - return; - CV_RegisterVar(&cv_glanisotropicmode); - gl_sessioncommandsadded = true; -} - // -------------------------------------------------------------------------- // Setup the hardware renderer // -------------------------------------------------------------------------- @@ -6664,7 +6656,6 @@ void HWR_Startup(void) CONS_Printf("HWR_Startup()...\n"); HWR_InitPolyPool(); - HWR_AddSessionCommands(); HWR_InitMapTextures(); HWR_InitModels(); #ifdef ALAM_LIGHTING @@ -6687,10 +6678,6 @@ void HWR_Startup(void) // -------------------------------------------------------------------------- void HWR_Switch(void) { - // Add session commands - if (!gl_sessioncommandsadded) - HWR_AddSessionCommands(); - // Set special states from CVARs HWD.pfnSetSpecialState(HWD_SET_TEXTUREFILTERMODE, cv_glfiltermode.value); HWD.pfnSetSpecialState(HWD_SET_TEXTUREANISOTROPICMODE, cv_glanisotropicmode.value); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 9450ca2c5..cce4e8f0a 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -54,7 +54,6 @@ UINT8 *HWR_GetScreenshot(void); boolean HWR_Screenshot(const char *pathname); void HWR_AddCommands(void); -void HWR_AddSessionCommands(void); void transform(float *cx, float *cy, float *cz); INT32 HWR_GetTextureUsed(void); void HWR_DoPostProcessor(player_t *player); diff --git a/src/r_main.c b/src/r_main.c index 6c7bedbf1..0cfccab8c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -158,7 +158,7 @@ consvar_t cv_drawdist = CVAR_INIT ("drawdist", "Infinite", CV_SAVE, drawdist_con consvar_t cv_drawdist_nights = CVAR_INIT ("drawdist_nights", "2048", CV_SAVE, drawdist_cons_t, NULL); consvar_t cv_drawdist_precip = CVAR_INIT ("drawdist_precip", "1024", CV_SAVE, drawdist_precip_cons_t, NULL); //consvar_t cv_precipdensity = CVAR_INIT ("precipdensity", "Moderate", CV_SAVE, precipdensity_cons_t, NULL); -consvar_t cv_fov = CVAR_INIT ("fov", "90", CV_FLOAT|CV_CALL, fov_cons_t, Fov_OnChange); +consvar_t cv_fov = CVAR_INIT ("fov", "90", CV_SAVE|CV_FLOAT|CV_CALL, fov_cons_t, Fov_OnChange); // Okay, whoever said homremoval causes a performance hit should be shot. consvar_t cv_homremoval = CVAR_INIT ("homremoval", "No", CV_SAVE, homremoval_cons_t, NULL); From 977cd0db24e4af2770b3b168dfefee741e8ea5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Wed, 22 Nov 2023 19:41:35 +0100 Subject: [PATCH 85/91] Fix LAN discovery for SRB2 servers --- src/netcode/i_tcp.c | 95 ++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/netcode/i_tcp.c b/src/netcode/i_tcp.c index 698234579..9c0e8eb2b 100644 --- a/src/netcode/i_tcp.c +++ b/src/netcode/i_tcp.c @@ -154,6 +154,8 @@ typedef union #define ERRSOCKET (-1) #endif +#define IPV6_MULTICAST_ADDRESS "ff15::57e1:1a12" + // define socklen_t in DOS/Windows if it is not already defined #ifdef USE_WINSOCK1 typedef int socklen_t; @@ -621,6 +623,7 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6); #endif socklen_t d, da = (socklen_t)sizeof(mysockaddr_t); + ssize_t status; switch (sockaddr->any.sa_family) { @@ -631,7 +634,12 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr default: d = da; break; } - return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); + status = sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d); + if (status == -1) + { + CONS_Alert(CONS_WARNING, "Unable to send packet to %s: %s\n", SOCK_AddrToStr(sockaddr), strerror(errno)); + } + return status; } static void SOCK_Send(void) @@ -770,6 +778,24 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen return (SOCKET_TYPE)ERRSOCKET; } +#ifdef HAVE_IPV6 + if (family == AF_INET6) + { + // we need to set all of this *after* binding to an address! + if (memcmp(&straddr.ip6.sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0) //IN6_ARE_ADDR_EQUAL + { + struct ipv6_mreq maddr; + + inet_pton(AF_INET6, IPV6_MULTICAST_ADDRESS, &maddr.ipv6mr_multiaddr); + maddr.ipv6mr_interface = 0; + if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, &maddr, sizeof(maddr)) != 0) + { + CONS_Alert(CONS_WARNING, M_GetText("Could not register multicast address\n")); + } + } + } +#endif + #ifdef FIONBIO // make it non blocking opt = true; @@ -950,65 +976,28 @@ static boolean UDP_Socket(void) // ip + udp packetheaderlength = 20 + 8; // for stats - hints.ai_family = AF_INET; - gaie = I_getaddrinfo("127.0.0.1", "0", &hints, &ai); - if (gaie == 0) - { - runp = ai; - while (runp != NULL && s < MAXNETNODES+1) - { - memcpy(&clientaddress[s], runp->ai_addr, runp->ai_addrlen); - s++; - runp = runp->ai_next; - } - I_freeaddrinfo(ai); - } - else - { - clientaddress[s].any.sa_family = AF_INET; - clientaddress[s].ip4.sin_port = htons(0); - clientaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); //GetLocalAddress(); // my own ip - s++; - } + clientaddress[s].any.sa_family = AF_INET; + clientaddress[s].ip4.sin_port = htons(0); + clientaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); //GetLocalAddress(); // my own ip + s++; s = 0; // setup broadcast adress to BROADCASTADDR entry - gaie = I_getaddrinfo("255.255.255.255", "0", &hints, &ai); - if (gaie == 0) - { - runp = ai; - while (runp != NULL && s < MAXNETNODES+1) - { - memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen); - s++; - runp = runp->ai_next; - } - I_freeaddrinfo(ai); - } - else - { - broadcastaddress[s].any.sa_family = AF_INET; - broadcastaddress[s].ip4.sin_port = htons(0); - broadcastaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_BROADCAST); - s++; - } + broadcastaddress[s].any.sa_family = AF_INET; + broadcastaddress[s].ip4.sin_port = htons(atoi(DEFAULTPORT)); + broadcastaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_BROADCAST); + s++; + #ifdef HAVE_IPV6 if (b_ipv6) { - hints.ai_family = AF_INET6; - gaie = I_getaddrinfo("ff02::1", "0", &hints, &ai); - if (gaie == 0) - { - runp = ai; - while (runp != NULL && s < MAXNETNODES+1) - { - memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen); - s++; - runp = runp->ai_next; - } - I_freeaddrinfo(ai); - } + broadcastaddress[s].any.sa_family = AF_INET6; + broadcastaddress[s].ip6.sin6_port = htons(atoi(DEFAULTPORT)); + broadcastaddress[s].ip6.sin6_flowinfo = 0; + inet_pton(AF_INET6, IPV6_MULTICAST_ADDRESS, &broadcastaddress[s].ip6.sin6_addr); + broadcastaddress[s].ip6.sin6_scope_id = 0; + s++; } #endif From 3c921044a35734e1c1326f7008c4049f7fce5b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Wed, 22 Nov 2023 20:26:55 +0100 Subject: [PATCH 86/91] Fix Windows build --- src/netcode/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netcode/i_tcp.c b/src/netcode/i_tcp.c index 9c0e8eb2b..0b650de49 100644 --- a/src/netcode/i_tcp.c +++ b/src/netcode/i_tcp.c @@ -788,7 +788,7 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen inet_pton(AF_INET6, IPV6_MULTICAST_ADDRESS, &maddr.ipv6mr_multiaddr); maddr.ipv6mr_interface = 0; - if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, &maddr, sizeof(maddr)) != 0) + if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, (const char *)&maddr, sizeof(maddr)) != 0) { CONS_Alert(CONS_WARNING, M_GetText("Could not register multicast address\n")); } From 563ce141ce0406a915cee9260033a209d53181ab Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 21 Nov 2023 21:15:09 -0300 Subject: [PATCH 87/91] Fix P_GetSectorColormapAt --- src/lua_baselib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 97bc9319c..3074187a3 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2025,14 +2025,18 @@ static int lib_pCeilingzAtPos(lua_State *L) static int lib_pGetSectorColormapAt(lua_State *L) { + boolean has_sector = false; sector_t *sector = NULL; - if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + if (!lua_isnoneornil(L, 1)) + { + has_sector = true; sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); + } fixed_t x = luaL_checkfixed(L, 2); fixed_t y = luaL_checkfixed(L, 3); fixed_t z = luaL_checkfixed(L, 4); INLEVEL - if (!sector) + if (has_sector && !sector) return LUA_ErrInvalid(L, "sector_t"); extracolormap_t *exc; if (sector) From 46bd7344c5b17b72e1cbe647f3e0649be8c54abe Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Thu, 23 Nov 2023 13:39:24 -0300 Subject: [PATCH 88/91] Rename 'sector.extracolormap' to just 'sector.colormap' --- src/lua_maplib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 2cc4ec2a2..1d85b786f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -57,7 +57,7 @@ enum sector_e { sector_ffloors, sector_fslope, sector_cslope, - sector_extracolormap, + sector_colormap, sector_flags, sector_specialflags, sector_damagetype, @@ -96,7 +96,7 @@ static const char *const sector_opt[] = { "ffloors", "f_slope", "c_slope", - "extracolormap", + "colormap", "flags", "specialflags", "damagetype", @@ -753,7 +753,7 @@ static int sector_get(lua_State *L) case sector_cslope: // c_slope LUA_PushUserdata(L, sector->c_slope, META_SLOPE); return 1; - case sector_extracolormap: // extra_colormap + case sector_colormap: // extra_colormap LUA_PushUserdata(L, sector->extra_colormap, META_EXTRACOLORMAP); return 1; case sector_flags: // flags From 1009c31ad1eb9fccc30c757e3c236e3e82a08d45 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Thu, 23 Nov 2023 14:36:02 -0300 Subject: [PATCH 89/91] Change some instances of sizeu1 to sizeu2 --- src/p_setup.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index effd2c368..211ce54e2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3264,7 +3264,7 @@ static void P_InitializeSeg(seg_t *seg) UINT32 side = seg->linedef->sidenum[seg->side]; if (side == NO_SIDEDEF) - I_Error("P_InitializeSeg: Seg %s refers to side %d of linedef %s, which doesn't exist!\n", sizeu1((size_t)(seg - segs)), seg->side, sizeu1((size_t)(seg->linedef - lines))); + I_Error("P_InitializeSeg: Seg %s refers to side %d of linedef %s, which doesn't exist!\n", sizeu1((size_t)(seg - segs)), seg->side, sizeu2((size_t)(seg->linedef - lines))); seg->sidedef = &sides[side]; @@ -3475,7 +3475,7 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype { UINT32 vertexnum = READUINT32((*data)); if (vertexnum >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid vertex %d!\n", sizeu1(k), sizeu1(m), vertexnum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid vertex %d!\n", sizeu1(k), sizeu2(m), vertexnum); segs[k - 1 + ((m == 0) ? subsectors[i].numlines : 0)].v2 = segs[k].v1 = &vertexes[vertexnum]; @@ -3516,11 +3516,11 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype UINT16 linenum = READUINT16((*data)); if (v1num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v1 %d!\n", sizeu1(k), sizeu1(m), v1num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v1 %d!\n", sizeu1(k), sizeu2(m), v1num); if (v2num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v2 %d!\n", sizeu1(k), sizeu1(m), v2num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid v2 %d!\n", sizeu1(k), sizeu2(m), v2num); if (linenum >= numlines) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu1(m), linenum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %s has invalid linedef %d!\n", sizeu1(k), sizeu2(m), linenum); segs[k].v1 = &vertexes[v1num]; segs[k].v2 = &vertexes[v2num]; @@ -4012,7 +4012,7 @@ static void P_LinkMapData(void) if (!seg->sidedef->sector) CorruptMapError(va("P_LinkMapData: seg->sidedef->sector is NULL " "(subsector %s, firstline is %d, sidedef is %s)", sizeu1(i), ss->firstline, - sizeu1(sidei))); + sizeu2(sidei))); ss->sector = seg->sidedef->sector; } From e50993861eec17cf26cb96d4c63fa22a1f8982c0 Mon Sep 17 00:00:00 2001 From: SMS Alfredo Date: Sun, 26 Nov 2023 20:38:49 +0000 Subject: [PATCH 90/91] Dedicated Shield / Super Transformation Button --- src/d_player.h | 4 + src/d_ticcmd.h | 27 +++-- src/deh_lua.c | 2 +- src/deh_tables.c | 7 +- src/g_game.c | 10 +- src/g_input.c | 22 ++-- src/g_input.h | 4 +- src/lua_baselib.c | 3 +- src/m_menu.c | 57 ++++----- src/p_local.h | 2 +- src/p_user.c | 296 +++++++++++++++++++++++----------------------- src/y_inter.c | 6 +- 12 files changed, 227 insertions(+), 213 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index ca700d4e1..1409e28b3 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -158,6 +158,10 @@ typedef enum PF_FORCESTRAFE = 1<<28, // Turning inputs are translated into strafing inputs PF_CANCARRY = 1<<29, // Can carry another player? PF_FINISHED = 1<<30, // The player finished the level. NOT the same as exiting + + // True if shield button down last tic + // This may be the final flag, but 2.3 could free up the others + PF_SHIELDDOWN = 1<<31, // up to 1<<31 is free } pflags_t; diff --git a/src/d_ticcmd.h b/src/d_ticcmd.h index 2481ed738..43eb0f00b 100644 --- a/src/d_ticcmd.h +++ b/src/d_ticcmd.h @@ -26,20 +26,23 @@ // Button/action code definitions. typedef enum { - // First 4 bits are weapon change info, DO NOT USE! - BT_WEAPONMASK = 0x0F, //our first four bits. + // First 3 bits are weapon change info, DO NOT USE! + BT_WEAPONMASK = 0x07, //our first three bits. + + BT_SHIELD = 1<<3, // shield or super action - BT_WEAPONNEXT = 1<<4, - BT_WEAPONPREV = 1<<5, - - BT_ATTACK = 1<<6, // shoot rings - BT_SPIN = 1<<7, - BT_CAMLEFT = 1<<8, // turn camera left - BT_CAMRIGHT = 1<<9, // turn camera right - BT_TOSSFLAG = 1<<10, - BT_JUMP = 1<<11, - BT_FIRENORMAL = 1<<12, // Fire a normal ring no matter what + BT_WEAPONNEXT = 1<<4, // select next weapon + BT_WEAPONPREV = 1<<5, // select previous weapon + BT_ATTACK = 1<<6, // shoot rings + BT_SPIN = 1<<7, // spin action + BT_CAMLEFT = 1<<8, // turn camera left + BT_CAMRIGHT = 1<<9, // turn camera right + BT_TOSSFLAG = 1<<10, // toss flag or emeralds + BT_JUMP = 1<<11, // jump action + BT_FIRENORMAL = 1<<12, // fire a normal ring no matter what + + // custom lua buttons BT_CUSTOM1 = 1<<13, BT_CUSTOM2 = 1<<14, BT_CUSTOM3 = 1<<15, diff --git a/src/deh_lua.c b/src/deh_lua.c index e596e166f..b8daa0430 100644 --- a/src/deh_lua.c +++ b/src/deh_lua.c @@ -589,7 +589,7 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word) { CacheAndPushConstant(L, word, (lua_Integer)BT_SPIN); return 1; - } + } for (i = 0; INT_CONST[i].n; i++) if (fastcmp(word,INT_CONST[i].n)) { diff --git a/src/deh_tables.c b/src/deh_tables.c index bf148d82b..b53cd00c8 100644 --- a/src/deh_tables.c +++ b/src/deh_tables.c @@ -5576,7 +5576,8 @@ struct int_const_s const INT_CONST[] = { {"ROTAXIS_Z",ROTAXIS_Z}, // Buttons (ticcmd_t) - {"BT_WEAPONMASK",BT_WEAPONMASK}, //our first four bits. + {"BT_WEAPONMASK",BT_WEAPONMASK}, //our first three bits. + {"BT_SHIELD",BT_SHIELD}, {"BT_WEAPONNEXT",BT_WEAPONNEXT}, {"BT_WEAPONPREV",BT_WEAPONPREV}, {"BT_ATTACK",BT_ATTACK}, // shoot rings @@ -5756,9 +5757,7 @@ struct int_const_s const INT_CONST[] = { {"GC_WEPSLOT5",GC_WEPSLOT5}, {"GC_WEPSLOT6",GC_WEPSLOT6}, {"GC_WEPSLOT7",GC_WEPSLOT7}, - {"GC_WEPSLOT8",GC_WEPSLOT8}, - {"GC_WEPSLOT9",GC_WEPSLOT9}, - {"GC_WEPSLOT10",GC_WEPSLOT10}, + {"GC_SHIELD",GC_SHIELD}, {"GC_FIRE",GC_FIRE}, {"GC_FIRENORMAL",GC_FIRENORMAL}, {"GC_TOSSFLAG",GC_TOSSFLAG}, diff --git a/src/g_game.c b/src/g_game.c index 438428b90..1388148e7 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1335,7 +1335,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) #if NUM_WEAPONS > 10 "Add extra inputs to g_input.h/gamecontrols_e" #endif - //use the four avaliable bits to determine the weapon. + //use the three avaliable bits to determine the weapon. cmd->buttons &= ~BT_WEAPONMASK; for (i = 0; i < NUM_WEAPONS; ++i) if (PLAYERINPUTDOWN(ssplayer, GC_WEPSLOT1 + i)) @@ -1353,9 +1353,14 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) axis = PlayerJoyAxis(ssplayer, JA_FIRENORMAL); if (PLAYERINPUTDOWN(ssplayer, GC_FIRENORMAL) || (usejoystick && axis > 0)) cmd->buttons |= BT_FIRENORMAL; - + + // Toss flag button if (PLAYERINPUTDOWN(ssplayer, GC_TOSSFLAG)) cmd->buttons |= BT_TOSSFLAG; + + // Shield button + if (PLAYERINPUTDOWN(ssplayer, GC_SHIELD)) + cmd->buttons |= BT_SHIELD; // Lua scriptable buttons if (PLAYERINPUTDOWN(ssplayer, GC_CUSTOM1)) @@ -2748,6 +2753,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) p->pflags |= PF_SPINDOWN; p->pflags |= PF_ATTACKDOWN; p->pflags |= PF_JUMPDOWN; + p->pflags |= PF_SHIELDDOWN; p->playerstate = PST_LIVE; p->panim = PA_IDLE; // standing animation diff --git a/src/g_input.c b/src/g_input.c index 8b5056331..3f1be37ba 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -576,9 +576,7 @@ static const char *gamecontrolname[NUM_GAMECONTROLS] = "weapon5", "weapon6", "weapon7", - "weapon8", - "weapon9", - "weapon10", + "shield", "fire", "firenormal", "tossflag", @@ -693,6 +691,7 @@ void G_DefineDefaultControls(void) gamecontroldefault[gcs_fps][GC_CENTERVIEW ][0] = KEY_LCTRL; gamecontroldefault[gcs_fps][GC_JUMP ][0] = KEY_SPACE; gamecontroldefault[gcs_fps][GC_SPIN ][0] = KEY_LSHIFT; + gamecontroldefault[gcs_fps][GC_SHIELD ][0] = KEY_LALT; gamecontroldefault[gcs_fps][GC_FIRE ][0] = KEY_RCTRL; gamecontroldefault[gcs_fps][GC_FIRE ][1] = KEY_MOUSE1+0; gamecontroldefault[gcs_fps][GC_FIRENORMAL ][0] = KEY_RALT; @@ -713,6 +712,7 @@ void G_DefineDefaultControls(void) gamecontroldefault[gcs_platform][GC_CENTERVIEW ][0] = KEY_END; gamecontroldefault[gcs_platform][GC_JUMP ][0] = KEY_SPACE; gamecontroldefault[gcs_platform][GC_SPIN ][0] = KEY_LSHIFT; + gamecontroldefault[gcs_platform][GC_SHIELD ][0] = KEY_LALT; gamecontroldefault[gcs_platform][GC_FIRE ][0] = 's'; gamecontroldefault[gcs_platform][GC_FIRE ][1] = KEY_MOUSE1+0; gamecontroldefault[gcs_platform][GC_FIRENORMAL ][0] = 'w'; @@ -728,9 +728,6 @@ void G_DefineDefaultControls(void) gamecontroldefault[i][GC_WEPSLOT5 ][0] = '5'; gamecontroldefault[i][GC_WEPSLOT6 ][0] = '6'; gamecontroldefault[i][GC_WEPSLOT7 ][0] = '7'; - gamecontroldefault[i][GC_WEPSLOT8 ][0] = '8'; - gamecontroldefault[i][GC_WEPSLOT9 ][0] = '9'; - gamecontroldefault[i][GC_WEPSLOT10 ][0] = '0'; gamecontroldefault[i][GC_TOSSFLAG ][0] = '\''; gamecontroldefault[i][GC_CAMTOGGLE ][0] = 'v'; gamecontroldefault[i][GC_CAMRESET ][0] = 'r'; @@ -749,15 +746,15 @@ void G_DefineDefaultControls(void) gamecontroldefault[i][GC_CUSTOM1 ][1] = KEY_JOY1+1; // B gamecontroldefault[i][GC_CUSTOM2 ][1] = KEY_JOY1+3; // Y gamecontroldefault[i][GC_CUSTOM3 ][1] = KEY_JOY1+8; // Left Stick - gamecontroldefault[i][GC_CAMTOGGLE ][1] = KEY_JOY1+4; // LB + gamecontroldefault[i][GC_SHIELD ][1] = KEY_JOY1+4; // LB gamecontroldefault[i][GC_CENTERVIEW ][1] = KEY_JOY1+5; // RB - gamecontroldefault[i][GC_SCREENSHOT ][1] = KEY_JOY1+6; // Back + gamecontroldefault[i][GC_SCORES ][1] = KEY_JOY1+6; // Back gamecontroldefault[i][GC_SYSTEMMENU ][0] = KEY_JOY1+7; // Start gamecontroldefault[i][GC_WEAPONPREV ][1] = KEY_HAT1+2; // D-Pad Left gamecontroldefault[i][GC_WEAPONNEXT ][1] = KEY_HAT1+3; // D-Pad Right gamecontroldefault[i][GC_VIEWPOINTNEXT][1] = KEY_JOY1+9; // Right Stick gamecontroldefault[i][GC_TOSSFLAG ][1] = KEY_HAT1+0; // D-Pad Up - gamecontroldefault[i][GC_SCORES ][1] = KEY_HAT1+1; // D-Pad Down + gamecontroldefault[i][GC_CAMTOGGLE ][1] = KEY_HAT1+1; // D-Pad Down // Second player controls only have joypad defaults gamecontrolbisdefault[i][GC_JUMP ][1] = KEY_2JOY1+0; // A @@ -765,15 +762,15 @@ void G_DefineDefaultControls(void) gamecontrolbisdefault[i][GC_CUSTOM1 ][1] = KEY_2JOY1+1; // B gamecontrolbisdefault[i][GC_CUSTOM2 ][1] = KEY_2JOY1+3; // Y gamecontrolbisdefault[i][GC_CUSTOM3 ][1] = KEY_2JOY1+8; // Left Stick - gamecontrolbisdefault[i][GC_CAMTOGGLE ][1] = KEY_2JOY1+4; // LB + gamecontrolbisdefault[i][GC_SHIELD ][1] = KEY_2JOY1+4; // LB gamecontrolbisdefault[i][GC_CENTERVIEW ][1] = KEY_2JOY1+5; // RB - gamecontrolbisdefault[i][GC_SCREENSHOT ][1] = KEY_2JOY1+6; // Back + //gamecontrolbisdefault[i][GC_SCORES ][1] = KEY_2JOY1+6; // Back //gamecontrolbisdefault[i][GC_SYSTEMMENU ][0] = KEY_2JOY1+7; // Start gamecontrolbisdefault[i][GC_WEAPONPREV ][1] = KEY_2HAT1+2; // D-Pad Left gamecontrolbisdefault[i][GC_WEAPONNEXT ][1] = KEY_2HAT1+3; // D-Pad Right gamecontrolbisdefault[i][GC_VIEWPOINTNEXT][1] = KEY_2JOY1+9; // Right Stick gamecontrolbisdefault[i][GC_TOSSFLAG ][1] = KEY_2HAT1+0; // D-Pad Up - //gamecontrolbisdefault[i][GC_SCORES ][1] = KEY_2HAT1+1; // D-Pad Down + gamecontrolbisdefault[i][GC_CAMTOGGLE ][1] = KEY_2HAT1+1; // D-Pad Down } } @@ -1004,6 +1001,7 @@ static void setcontrol(INT32 (*gc)[2]) // TODO: 2.3: Delete the "use" alias namectrl = (stricmp(COM_Argv(1), "use")) ? COM_Argv(1) : "spin"; + for (numctrl = 0; numctrl < NUM_GAMECONTROLS && stricmp(namectrl, gamecontrolname[numctrl]); numctrl++) diff --git a/src/g_input.h b/src/g_input.h index e9c909e6e..48c103076 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -74,9 +74,7 @@ typedef enum GC_WEPSLOT5, GC_WEPSLOT6, GC_WEPSLOT7, - GC_WEPSLOT8, - GC_WEPSLOT9, - GC_WEPSLOT10, + GC_SHIELD, GC_FIRE, GC_FIRENORMAL, GC_TOSSFLAG, diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 16f238abe..bdc5c4501 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1686,11 +1686,12 @@ static int lib_pHomingAttack(lua_State *L) static int lib_pSuperReady(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + boolean transform = (boolean)lua_opttrueboolean(L, 2); //HUDSAFE INLEVEL if (!player) return LUA_ErrInvalid(L, "player_t"); - lua_pushboolean(L, P_SuperReady(player)); + lua_pushboolean(L, P_SuperReady(player, transform)); return 1; } diff --git a/src/m_menu.c b/src/m_menu.c index 629f53d24..45e74c0fc 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1068,6 +1068,7 @@ static menuitem_t OP_ChangeControlsMenu[] = {IT_CALL | IT_STRING2, NULL, "Move Right", M_ChangeControl, GC_STRAFERIGHT }, {IT_CALL | IT_STRING2, NULL, "Jump", M_ChangeControl, GC_JUMP }, {IT_CALL | IT_STRING2, NULL, "Spin", M_ChangeControl, GC_SPIN }, + {IT_CALL | IT_STRING2, NULL, "Shield", M_ChangeControl, GC_SHIELD }, {IT_HEADER, NULL, "Camera", NULL, 0}, {IT_SPACE, NULL, NULL, NULL, 0}, // padding {IT_CALL | IT_STRING2, NULL, "Look Up", M_ChangeControl, GC_LOOKUP }, @@ -13167,23 +13168,23 @@ static void M_Setup1PControlsMenu(INT32 choice) currentMenu->lastOn = itemOn; // Unhide the nine non-P2 controls and their headers - //OP_ChangeControlsMenu[18+0].status = IT_HEADER; - //OP_ChangeControlsMenu[18+1].status = IT_SPACE; + //OP_ChangeControlsMenu[19+0].status = IT_HEADER; + //OP_ChangeControlsMenu[19+1].status = IT_SPACE; // ... - OP_ChangeControlsMenu[18+2].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[18+3].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[18+4].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[18+5].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[18+6].status = IT_CALL|IT_STRING2; - //OP_ChangeControlsMenu[18+7].status = IT_CALL|IT_STRING2; - //OP_ChangeControlsMenu[18+8].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[18+9].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+2].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+3].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+4].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+5].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+6].status = IT_CALL|IT_STRING2; + //OP_ChangeControlsMenu[19+7].status = IT_CALL|IT_STRING2; + //OP_ChangeControlsMenu[19+8].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[19+9].status = IT_CALL|IT_STRING2; // ... - OP_ChangeControlsMenu[28+0].status = IT_HEADER; - OP_ChangeControlsMenu[28+1].status = IT_SPACE; + OP_ChangeControlsMenu[29+0].status = IT_HEADER; + OP_ChangeControlsMenu[29+1].status = IT_SPACE; // ... - OP_ChangeControlsMenu[28+2].status = IT_CALL|IT_STRING2; - OP_ChangeControlsMenu[28+3].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[29+2].status = IT_CALL|IT_STRING2; + OP_ChangeControlsMenu[29+3].status = IT_CALL|IT_STRING2; OP_ChangeControlsDef.prevMenu = &OP_P1ControlsDef; OP_ChangeControlsDef.menuid &= ~(((1 << MENUBITS) - 1) << MENUBITS); // remove second level @@ -13199,23 +13200,23 @@ static void M_Setup2PControlsMenu(INT32 choice) currentMenu->lastOn = itemOn; // Hide the nine non-P2 controls and their headers - //OP_ChangeControlsMenu[18+0].status = IT_GRAYEDOUT2; - //OP_ChangeControlsMenu[18+1].status = IT_GRAYEDOUT2; + //OP_ChangeControlsMenu[19+0].status = IT_GRAYEDOUT2; + //OP_ChangeControlsMenu[19+1].status = IT_GRAYEDOUT2; // ... - OP_ChangeControlsMenu[18+2].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[18+3].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[18+4].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[18+5].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[18+6].status = IT_GRAYEDOUT2; - //OP_ChangeControlsMenu[18+7].status = IT_GRAYEDOUT2; - //OP_ChangeControlsMenu[18+8].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[18+9].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+2].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+3].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+4].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+5].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+6].status = IT_GRAYEDOUT2; + //OP_ChangeControlsMenu[19+7].status = IT_GRAYEDOUT2; + //OP_ChangeControlsMenu[19+8].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[19+9].status = IT_GRAYEDOUT2; // ... - OP_ChangeControlsMenu[28+0].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[28+1].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[29+0].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[29+1].status = IT_GRAYEDOUT2; // ... - OP_ChangeControlsMenu[28+2].status = IT_GRAYEDOUT2; - OP_ChangeControlsMenu[28+3].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[29+2].status = IT_GRAYEDOUT2; + OP_ChangeControlsMenu[29+3].status = IT_GRAYEDOUT2; OP_ChangeControlsDef.prevMenu = &OP_P2ControlsDef; OP_ChangeControlsDef.menuid &= ~(((1 << MENUBITS) - 1) << MENUBITS); // remove second level diff --git a/src/p_local.h b/src/p_local.h index c26c09860..1f1548b86 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -202,7 +202,7 @@ mobj_t *P_LookForEnemies(player_t *player, boolean nonenemies, boolean bullet); void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius); void P_Earthquake(mobj_t *inflictor, mobj_t *source, fixed_t radius); boolean P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user -boolean P_SuperReady(player_t *player); +boolean P_SuperReady(player_t *player, boolean transform); void P_DoJump(player_t *player, boolean soundandstate); void P_DoSpinDashDust(player_t *player); #define P_AnalogMove(player) (P_ControlStyle(player) == CS_LMAOGALOG) diff --git a/src/p_user.c b/src/p_user.c index c0e87bf73..a856d2592 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -666,7 +666,7 @@ static void P_DeNightserizePlayer(player_t *player) player->powers[pw_carry] = CR_NIGHTSFALL; player->powers[pw_underwater] = 0; - player->pflags &= ~(PF_SPINDOWN|PF_JUMPDOWN|PF_ATTACKDOWN|PF_STARTDASH|PF_GLIDING|PF_STARTJUMP|PF_JUMPED|PF_NOJUMPDAMAGE|PF_THOKKED|PF_SPINNING|PF_DRILLING|PF_TRANSFERTOCLOSEST); + player->pflags &= ~(PF_SPINDOWN|PF_JUMPDOWN|PF_ATTACKDOWN|PF_SHIELDDOWN|PF_STARTDASH|PF_GLIDING|PF_STARTJUMP|PF_JUMPED|PF_NOJUMPDAMAGE|PF_THOKKED|PF_SPINNING|PF_DRILLING|PF_TRANSFERTOCLOSEST); player->secondjump = 0; player->homing = 0; player->climbing = 0; @@ -794,7 +794,7 @@ void P_NightserizePlayer(player_t *player, INT32 nighttime) } } - player->pflags &= ~(PF_SPINDOWN|PF_JUMPDOWN|PF_ATTACKDOWN|PF_STARTDASH|PF_GLIDING|PF_JUMPED|PF_NOJUMPDAMAGE|PF_THOKKED|PF_SHIELDABILITY|PF_SPINNING|PF_DRILLING); + player->pflags &= ~(PF_SPINDOWN|PF_JUMPDOWN|PF_ATTACKDOWN|PF_SHIELDDOWN|PF_STARTDASH|PF_GLIDING|PF_JUMPED|PF_NOJUMPDAMAGE|PF_THOKKED|PF_SHIELDABILITY|PF_SPINNING|PF_DRILLING); player->homing = 0; player->mo->fuse = 0; player->speed = 0; @@ -1342,8 +1342,6 @@ void P_DoSuperTransformation(player_t *player, boolean giverings) if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOSSMUSIC) && P_IsLocalPlayer(player)) P_PlayJingle(player, JT_SUPER); - S_StartSound(NULL, sfx_supert); //let all players hear it -mattw_cfi - player->mo->momx = player->mo->momy = player->mo->momz = player->cmomx = player->cmomy = player->rmomx = player->rmomy = 0; // Transformation animation @@ -1360,8 +1358,11 @@ void P_DoSuperTransformation(player_t *player, boolean giverings) player->powers[pw_sneakers] = 0; } - if (!G_CoopGametype()) + if (G_CoopGametype()) + S_StartSound(player->mo, sfx_supert); //only hear it near yourself in co-op + else { + S_StartSound(NULL, sfx_supert); //let all players hear it -mattw_cfi HU_SetCEchoFlags(0); HU_SetCEchoDuration(5); HU_DoCEcho(va("%s\\is now super.\\\\\\\\", player_names[player-players])); @@ -1370,6 +1371,56 @@ void P_DoSuperTransformation(player_t *player, boolean giverings) P_PlayerFlagBurst(player, false); } +// +// P_DoSuperDetransformation +// +// Detransform into regular Sonic! +static void P_DoSuperDetransformation(player_t *player) +{ + player->powers[pw_emeralds] = 0; // lost the power stones + P_SpawnGhostMobj(player->mo); + + player->powers[pw_super] = 0; + + // Restore color + if ((player->powers[pw_shield] & SH_STACK) == SH_FIREFLOWER) + { + player->mo->color = SKINCOLOR_WHITE; + G_GhostAddColor(GHC_FIREFLOWER); + } + else + { + player->mo->color = P_GetPlayerColor(player); + G_GhostAddColor(GHC_NORMAL); + } + + if (!G_CoopGametype()) + player->powers[pw_flashing] = flashingtics-1; + + if (player->mo->sprite2 & FF_SPR2SUPER) + P_SetPlayerMobjState(player->mo, player->mo->state-states); + + // Inform the netgame that the champion has fallen in the heat of battle. + if (!G_CoopGametype()) + { + S_StartSound(NULL, sfx_s3k66); //let all players hear it. + HU_SetCEchoFlags(0); + HU_SetCEchoDuration(5); + HU_DoCEcho(va("%s\\is no longer super.\\\\\\\\", player_names[player-players])); + } + + // Resume normal music if you're the console player + if (P_IsLocalPlayer(player)) + { + music_stack_noposition = true; // HACK: Do not reposition next music + music_stack_fadeout = MUSICRATE/2; // HACK: Fade out current music + } + P_RestoreMusic(player); + + // If you had a shield, restore its visual significance. + P_SpawnShieldOrb(player); +} + // Adds to the player's score void P_AddPlayerScore(player_t *player, UINT32 amount) { @@ -4086,6 +4137,16 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) I_Assert(player != NULL); I_Assert(!P_MobjWasRemoved(player->mo)); + + // Toss a flag + if (cmd->buttons & BT_TOSSFLAG && G_GametypeHasTeams() + && !(player->powers[pw_super]) && !(player->tossdelay)) + { + if (!(player->gotflag & (GF_REDFLAG|GF_BLUEFLAG))) + P_PlayerEmeraldBurst(player, true); // Toss emeralds + else + P_PlayerFlagBurst(player, true); + } if (!(cmd->buttons & (BT_ATTACK|BT_FIRENORMAL))) { @@ -4095,9 +4156,10 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) return; } - if (player->pflags & PF_ATTACKDOWN || player->climbing || (G_TagGametype() && !(player->pflags & PF_TAGIT))) + if (player->pflags & PF_ATTACKDOWN || player->climbing) return; + // Fire a fireball if we have the Fire Flower powerup! if (((player->powers[pw_shield] & SH_STACK) == SH_FIREFLOWER) && !(player->weapondelay)) { player->pflags |= PF_ATTACKDOWN; @@ -4109,7 +4171,8 @@ static void P_DoFiring(player_t *player, ticcmd_t *cmd) return; } - if (!G_RingSlingerGametype() || player->weapondelay) + // No ringslinging outside of ringslinger! + if (!G_RingSlingerGametype() || player->weapondelay || (G_TagGametype() && !(player->pflags & PF_TAGIT))) return; player->pflags |= PF_ATTACKDOWN; @@ -4287,34 +4350,7 @@ static void P_DoSuperStuff(player_t *player) // If you're super and not Sonic, de-superize! if (!(ALL7EMERALDS(emeralds) && player->charflags & SF_SUPER)) { - player->powers[pw_super] = 0; - P_SetPlayerMobjState(player->mo, S_PLAY_STND); - if (P_IsLocalPlayer(player)) - { - music_stack_noposition = true; // HACK: Do not reposition next music - music_stack_fadeout = MUSICRATE/2; // HACK: Fade out current music - } - P_RestoreMusic(player); - P_SpawnShieldOrb(player); - - // Restore color - if ((player->powers[pw_shield] & SH_STACK) == SH_FIREFLOWER) - { - player->mo->color = SKINCOLOR_WHITE; - G_GhostAddColor(GHC_FIREFLOWER); - } - else - { - player->mo->color = P_GetPlayerColor(player); - G_GhostAddColor(GHC_NORMAL); - } - - if (!G_CoopGametype()) - { - HU_SetCEchoFlags(0); - HU_SetCEchoDuration(5); - HU_DoCEcho(va("%s\\is no longer super.\\\\\\\\", player_names[player-players])); - } + P_DoSuperDetransformation(player); return; } @@ -4341,69 +4377,37 @@ static void P_DoSuperStuff(player_t *player) // Ran out of rings while super! if (player->rings <= 0 || player->exiting) - { - player->powers[pw_emeralds] = 0; // lost the power stones - P_SpawnGhostMobj(player->mo); - - player->powers[pw_super] = 0; - - // Restore color - if ((player->powers[pw_shield] & SH_STACK) == SH_FIREFLOWER) - { - player->mo->color = SKINCOLOR_WHITE; - G_GhostAddColor(GHC_FIREFLOWER); - } - else - { - player->mo->color = P_GetPlayerColor(player); - G_GhostAddColor(GHC_NORMAL); - } - - if (!G_CoopGametype()) - player->powers[pw_flashing] = flashingtics-1; - - if (player->mo->sprite2 & FF_SPR2SUPER) - P_SetPlayerMobjState(player->mo, player->mo->state-states); - - // Inform the netgame that the champion has fallen in the heat of battle. - if (!G_CoopGametype()) - { - S_StartSound(NULL, sfx_s3k66); //let all players hear it. - HU_SetCEchoFlags(0); - HU_SetCEchoDuration(5); - HU_DoCEcho(va("%s\\is no longer super.\\\\\\\\", player_names[player-players])); - } - - // Resume normal music if you're the console player - if (P_IsLocalPlayer(player)) - { - music_stack_noposition = true; // HACK: Do not reposition next music - music_stack_fadeout = MUSICRATE/2; // HACK: Fade out current music - } - P_RestoreMusic(player); - - // If you had a shield, restore its visual significance. - P_SpawnShieldOrb(player); - } + P_DoSuperDetransformation(player); } } // // P_SuperReady // -// Returns true if player is ready to turn super, duh +// Returns true if player is ready to transform or detransform // -boolean P_SuperReady(player_t *player) +boolean P_SuperReady(player_t *player, boolean transform) { - if (!player->powers[pw_super] - && !player->powers[pw_invulnerability] + if (!transform && + (player->powers[pw_super] < TICRATE*3/2 + || !G_CoopGametype())) // No turning back in competitive! + return false; + else if (transform + && (player->powers[pw_super] + || !ALL7EMERALDS(emeralds) + || !(player->rings >= 50))) + return false; + + if (player->mo && !player->powers[pw_tailsfly] + && !player->powers[pw_carry] && (player->charflags & SF_SUPER) - && (player->pflags & PF_JUMPED) - && !(player->powers[pw_shield] & SH_NOSTACK) - && !(maptol & TOL_NIGHTS) - && ALL7EMERALDS(emeralds) - && (player->rings >= 50)) + && !P_PlayerInPain(player) + && !player->climbing + && !(player->pflags & (PF_FULLSTASIS|PF_THOKKED|PF_STARTDASH|PF_GLIDING|PF_SLIDING|PF_SHIELDABILITY)) + && ((player->pflags & PF_JUMPED) || (P_IsObjectOnGround(player->mo) && (player->panim == PA_IDLE || player->panim == PA_EDGE + || player->panim == PA_WALK || player->panim == PA_RUN || (player->charflags & SF_DASHMODE && player->panim == PA_DASH)))) + && !(maptol & TOL_NIGHTS)) return true; return false; @@ -5094,7 +5098,7 @@ static boolean P_PlayerShieldThink(player_t *player, ticcmd_t *cmd, mobj_t *lock { mobj_t *lockonshield = NULL; - if ((player->powers[pw_shield] & SH_NOSTACK) && !player->powers[pw_super] && !(player->pflags & PF_SPINDOWN) + if ((player->powers[pw_shield] & SH_NOSTACK) && !player->powers[pw_super] && !(player->pflags & PF_SHIELDDOWN) && ((!(player->pflags & PF_THOKKED) || (((player->powers[pw_shield] & SH_NOSTACK) == SH_BUBBLEWRAP || (player->powers[pw_shield] & SH_NOSTACK) == SH_ATTRACT) && player->secondjump == UINT8_MAX) ))) // thokked is optional if you're bubblewrapped / 3dblasted { if ((player->powers[pw_shield] & SH_NOSTACK) == SH_ATTRACT && !(player->charflags & SF_NOSHIELDABILITY)) @@ -5121,7 +5125,7 @@ static boolean P_PlayerShieldThink(player_t *player, ticcmd_t *cmd, mobj_t *lock } } } - if ((!(player->charflags & SF_NOSHIELDABILITY)) && (cmd->buttons & BT_SPIN && !LUA_HookPlayer(player, HOOK(ShieldSpecial)))) // Spin button effects + if ((!(player->charflags & SF_NOSHIELDABILITY)) && (cmd->buttons & BT_SHIELD && !LUA_HookPlayer(player, HOOK(ShieldSpecial)))) // Shield button effects { // Force stop if ((player->powers[pw_shield] & ~(SH_FORCEHP|SH_STACK)) == SH_FORCE) @@ -5242,52 +5246,45 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) ; else if (P_PlayerShieldThink(player, cmd, lockonthok, visual)) ; - else if ((cmd->buttons & BT_SPIN)) + else if ((cmd->buttons & BT_SPIN) && !LUA_HookPlayer(player, HOOK(JumpSpinSpecial))) { - if (!(player->pflags & PF_SPINDOWN) && P_SuperReady(player)) + switch (player->charability) { - // If you can turn super and aren't already, - // and you don't have a shield, do it! - P_DoSuperTransformation(player, false); - } - else if (!LUA_HookPlayer(player, HOOK(JumpSpinSpecial))) - switch (player->charability) - { - case CA_THOK: - if (player->powers[pw_super]) // Super Sonic float + case CA_THOK: + if (player->powers[pw_super]) // Super Sonic float + { + if ((player->speed > 5*player->mo->scale) // FixedMul(5<mo->scale), but scale is FRACUNIT-based + && (P_MobjFlip(player->mo)*player->mo->momz <= 0)) { - if ((player->speed > 5*player->mo->scale) // FixedMul(5<mo->scale), but scale is FRACUNIT-based - && (P_MobjFlip(player->mo)*player->mo->momz <= 0)) + if (player->panim != PA_RUN && player->panim != PA_WALK) { - if (player->panim != PA_RUN && player->panim != PA_WALK) - { - if (player->speed >= FixedMul(player->runspeed, player->mo->scale)) - P_SetPlayerMobjState(player->mo, S_PLAY_FLOAT_RUN); - else - P_SetPlayerMobjState(player->mo, S_PLAY_FLOAT); - } - - player->mo->momz = 0; - player->pflags &= ~(PF_STARTJUMP|PF_SPINNING); - player->secondjump = 1; + if (player->speed >= FixedMul(player->runspeed, player->mo->scale)) + P_SetPlayerMobjState(player->mo, S_PLAY_FLOAT_RUN); + else + P_SetPlayerMobjState(player->mo, S_PLAY_FLOAT); } + + player->mo->momz = 0; + player->pflags &= ~(PF_STARTJUMP|PF_SPINNING); + player->secondjump = 1; } - break; - case CA_TELEKINESIS: - if (!(player->pflags & (PF_THOKKED|PF_SPINDOWN)) || (player->charflags & SF_MULTIABILITY)) - { - P_Telekinesis(player, - -FixedMul(player->actionspd, player->mo->scale), // -ve thrust (pulling towards player) - FixedMul(384*FRACUNIT, player->mo->scale)); - } - break; - case CA_TWINSPIN: - if ((player->charability2 == CA2_MELEE) && (!(player->pflags & (PF_THOKKED|PF_SPINDOWN)) || player->charflags & SF_MULTIABILITY)) - P_DoTwinSpin(player); - break; - default: - break; - } + } + break; + case CA_TELEKINESIS: + if (!(player->pflags & (PF_THOKKED|PF_SPINDOWN)) || (player->charflags & SF_MULTIABILITY)) + { + P_Telekinesis(player, + -FixedMul(player->actionspd, player->mo->scale), // -ve thrust (pulling towards player) + FixedMul(384*FRACUNIT, player->mo->scale)); + } + break; + case CA_TWINSPIN: + if ((player->charability2 == CA2_MELEE) && (!(player->pflags & (PF_THOKKED|PF_SPINDOWN)) || player->charflags & SF_MULTIABILITY)) + P_DoTwinSpin(player); + break; + default: + break; + } } } @@ -5350,12 +5347,6 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd) } else if (player->pflags & PF_SLIDING || ((gametyperules & GTR_TEAMFLAGS) && player->gotflag) || player->pflags & PF_SHIELDABILITY) ; - /*else if (P_SuperReady(player)) - { - // If you can turn super and aren't already, - // and you don't have a shield, do it! - P_DoSuperTransformation(player, false); - }*/ else if (player->pflags & PF_JUMPED) { if (!LUA_HookPlayer(player, HOOK(AbilitySpecial))) @@ -8686,18 +8677,31 @@ void P_MovePlayer(player_t *player) && player->panim == PA_IDLE && !(player->powers[pw_carry])) P_DoTeeter(player); - // Toss a flag - if (G_GametypeHasTeams() && (cmd->buttons & BT_TOSSFLAG) && !(player->powers[pw_super]) && !(player->tossdelay)) + // Check for fire and shield buttons + if (!player->exiting && !(player->pflags & PF_STASIS)) { - if (!(player->gotflag & (GF_REDFLAG|GF_BLUEFLAG))) - P_PlayerEmeraldBurst(player, true); // Toss emeralds - else - P_PlayerFlagBurst(player, true); - } - - // check for fire - if (!player->exiting) + // Check for fire buttons P_DoFiring(player, cmd); + + // Release the shield button + if (!(cmd->buttons & BT_SHIELD)) + player->pflags &= ~PF_SHIELDDOWN; + + // Shield button behavior + // Check P_PlayerShieldThink for actual shields! + else if (!(player->pflags & PF_SHIELDDOWN)) + { + // Transform into super if we can! + if (P_SuperReady(player, true)) + P_DoSuperTransformation(player, false); + + // Detransform from super if we can! + else if (P_SuperReady(player, false)) + P_DoSuperDetransformation(player); + + player->pflags |= PF_SHIELDDOWN; + } + } { boolean atspinheight = false; diff --git a/src/y_inter.c b/src/y_inter.c index 369ec3904..cbe057582 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -579,9 +579,9 @@ void Y_IntermissionDrawer(void) { if (LUA_HudEnabled(hud_intermissiontitletext)) { - const char *ringtext = "\x82" "50 rings, no shield"; - const char *tut1text = "\x82" "press " "\x80" "spin"; - const char *tut2text = "\x82" "mid-" "\x80" "jump"; + const char *ringtext = "\x82" "get 50 rings then"; + const char *tut1text = "\x82" "press " "\x80" "shield"; + const char *tut2text = "\x82" "to " "\x80" "transform"; ttheight = 8; V_DrawLevelTitle(data.spec.passedx1 + xoffset1, ttheight, 0, data.spec.passed1); ttheight += V_LevelNameHeight(data.spec.passed3) + 2; From 30e48fd555c7d91b0e43fa99034a18a16e484d3f Mon Sep 17 00:00:00 2001 From: bitten2up <575-bitten2up@users.noreply.git.do.srb2.org> Date: Wed, 29 Nov 2023 11:19:53 +0000 Subject: [PATCH 91/91] I_SetSongTrack(int) should be I_SetSongTrack(INT32) --- src/dummy/i_sound.c | 2 +- src/sdl/mixer_sound.c | 2 +- src/sdl/sdl_sound.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index ba0fc6423..436187805 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -164,7 +164,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false; diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 0a39c7f28..a2a4d3ef0 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -1441,7 +1441,7 @@ void I_SetMusicVolume(UINT8 volume) Mix_VolumeMusic(get_real_volume(music_volume)); } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { #ifdef HAVE_GME // If the specified track is within the number of tracks playing, then change it diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 2ca35b954..2705261d6 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1471,7 +1471,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false;