From 15787a97bbbc656ebbd588a975965feb1ce89d41 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 25 Jul 2024 21:17:48 +0300 Subject: [PATCH] Make water trail not use hardcode freeslots too --- src/dehacked.c | 14 ----------- src/info.c | 68 +------------------------------------------------- src/info.h | 16 ------------ src/k_kart.c | 41 ++++++++++++++++++++++++------ 4 files changed, 34 insertions(+), 105 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 0b9a6ada5..094e3d641 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -6497,17 +6497,6 @@ static const char *const STATE_LIST[] = { // array length left dynamic for sanit #ifdef SEENAMES "S_NAMECHECK", #endif - - "S_WATERTRAIL1", - "S_WATERTRAIL2", - "S_WATERTRAIL3", - "S_WATERTRAIL4", - "S_WATERTRAIL5", - "S_WATERTRAILUNDERLAY1", - "S_WATERTRAILUNDERLAY2", - "S_WATERTRAILUNDERLAY3", - "S_WATERTRAILUNDERLAY4", - "S_WATERTRAILUNDERLAY5", }; // RegEx to generate this from info.h: ^\tMT_([^,]+), --> \t"MT_\1", @@ -7302,9 +7291,6 @@ static const char *const MOBJTYPE_LIST[] = { // array length left dynamic for s #ifdef SEENAMES "MT_NAMECHECK", #endif - - "MT_WATERTRAIL", - "MT_WATERTRAILUNDERLAY", }; static const char *const MOBJFLAG_LIST[] = { diff --git a/src/info.c b/src/info.c index 9726a670e..0d5dbea71 100644 --- a/src/info.c +++ b/src/info.c @@ -66,7 +66,7 @@ char sprnames[NUMSPRITES + 1][5] = "CNDL","DOCH","DUCK","GTRE","CHES","CHIM","DRGN","LZMN","PGSS","ZTCH", "MKMA","MKMP","RTCH","BOWL","BOWH","BRRL","BRRR","HRSE","TOAH","BFRT", "OFRT","RFRT","PFRT","ASPK","HBST","HBSO","HBSF","WBLZ","WBLN","OPUL", - "TGEM","TCOI","FWRK","XMS4","XMS5","VIEW","WTRL", + "TGEM","TCOI","FWRK","XMS4","XMS5","VIEW", }; // Doesn't work with g++, needs actionf_p1 (don't modify this comment) @@ -3410,18 +3410,6 @@ state_t states[NUMSTATES] = #ifdef SEENAMES {SPR_NULL, 0, 1, {NULL}, 0, 0, S_NULL}, // S_NAMECHECK #endif - - // Water Trail - {SPR_WTRL, FF_PAPERSPRITE , 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAIL1 - {SPR_WTRL, FF_PAPERSPRITE|1, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAIL2 - {SPR_WTRL, FF_PAPERSPRITE|2, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAIL3 - {SPR_WTRL, FF_PAPERSPRITE|3, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAIL4 - {SPR_WTRL, FF_PAPERSPRITE|4, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAIL5 - {SPR_WTRL, FF_TRANS50|FF_PAPERSPRITE|5, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAILUNDERLAY1 - {SPR_WTRL, FF_TRANS50|FF_PAPERSPRITE|6, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAILUNDERLAY2 - {SPR_WTRL, FF_TRANS50|FF_PAPERSPRITE|7, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAILUNDERLAY3 - {SPR_WTRL, FF_TRANS50|FF_PAPERSPRITE|8, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAILUNDERLAY4 - {SPR_WTRL, FF_TRANS50|FF_PAPERSPRITE|9, 2, {NULL}, 0, 0, S_INVISIBLE}, // S_WATERTRAILUNDERLAY5 }; mobjinfo_t mobjinfo[NUMMOBJTYPES] = @@ -20215,60 +20203,6 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = S_NULL // raisestate }, #endif - - { // MT_WATERTRAIL - -1, // doomednum - S_WATERTRAIL1, // spawnstate - 1000, // spawnhealth - S_NULL, // seestate - sfx_None, // seesound - 8, // reactiontime - sfx_None, // attacksound - S_NULL, // painstate - 0, // painchance - sfx_None, // painsound - S_NULL, // meleestate - S_NULL, // missilestate - S_NULL, // deathstate - S_NULL, // xdeathstate - sfx_None, // deathsound - 0, // speed - 48*FRACUNIT, // radius - 32*FRACUNIT, // height - 1, // display offset - 100, // mass - 1, // damage - sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOCLIP|MF_NOGRAVITY|MF_SCENERY|MF_DONTENCOREMAP, // flags - S_NULL // raisestate - }, - - { // MT_WATERTRAILUNDERLAY - -1, // doomednum - S_WATERTRAILUNDERLAY1, // spawnstate - 1000, // spawnhealth - S_NULL, // seestate - sfx_None, // seesound - 8, // reactiontime - sfx_None, // attacksound - S_NULL, // painstate - 0, // painchance - sfx_None, // painsound - S_NULL, // meleestate - S_NULL, // missilestate - S_NULL, // deathstate - S_NULL, // xdeathstate - sfx_None, // deathsound - 0, // speed - 48*FRACUNIT, // radius - 32*FRACUNIT, // height - 0, // display offset - 100, // mass - 1, // damage - sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOCLIP|MF_NOGRAVITY|MF_SCENERY|MF_DONTENCOREMAP, // flags - S_NULL // raisestate - }, }; diff --git a/src/info.h b/src/info.h index d663a91a0..aff87a663 100644 --- a/src/info.h +++ b/src/info.h @@ -1018,8 +1018,6 @@ typedef enum sprite // First person view sprites; this is a sprite so that it can be replaced by a specialized MD2 draw later SPR_VIEW, - SPR_WTRL, // Water Trail - SPR_FIRSTFREESLOT, SPR_LASTFREESLOT = SPR_FIRSTFREESLOT + NUMSPRITEFREESLOTS - 1, NUMSPRITES @@ -4308,17 +4306,6 @@ typedef enum state S_NAMECHECK, #endif - S_WATERTRAIL1, - S_WATERTRAIL2, - S_WATERTRAIL3, - S_WATERTRAIL4, - S_WATERTRAIL5, - S_WATERTRAILUNDERLAY1, - S_WATERTRAILUNDERLAY2, - S_WATERTRAILUNDERLAY3, - S_WATERTRAILUNDERLAY4, - S_WATERTRAILUNDERLAY5, - S_FIRSTFREESLOT, S_LASTFREESLOT = S_FIRSTFREESLOT + NUMSTATEFREESLOTS - 1, NUMSTATES @@ -5130,9 +5117,6 @@ typedef enum mobj_type MT_NAMECHECK, #endif - MT_WATERTRAIL, - MT_WATERTRAILUNDERLAY, - MT_FIRSTFREESLOT, MT_LASTFREESLOT = MT_FIRSTFREESLOT + NUMMOBJFREESLOTS - 1, NUMMOBJTYPES diff --git a/src/k_kart.c b/src/k_kart.c index 724abab79..5ee67a008 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5848,6 +5848,27 @@ static mobj_t *K_SpawnOrMoveMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t typ void K_SpawnWaterRunParticles(mobj_t *mobj) { + mobjtype_t watertrailunderlay = LUA_EvalMathEx("MT_WATERTRAILUNDERLAY", NULL); + + // Technically, we'd need only 1 check after we try get all necessary states, but fetching these + // constants is a bit costly (if they are missing. If they are not, lua_glib helps us ;3), + // so if this one is missing we quit early and if not we continue and check if we have + // everything we need later + if (!watertrailunderlay) + return; + + statenum_t watertrailunderlay_minstate = LUA_EvalMathEx("S_WATERTRAILUNDERLAY1", NULL); + statenum_t watertrailunderlay_maxstate = LUA_EvalMathEx("S_WATERTRAILUNDERLAYLAST", NULL); + + mobjtype_t watertrail = LUA_EvalMathEx("MT_WATERTRAILUNDERLAY", NULL); + + statenum_t watertrail_minstate = LUA_EvalMathEx("S_WATERTRAIL1", NULL); + statenum_t watertrail_maxstate = LUA_EvalMathEx("S_WATERTRAILLAST", NULL); + + if (!(watertrailunderlay_minstate && watertrailunderlay_maxstate && watertrail && watertrail_minstate && watertrail_maxstate) || // Check if we're missing something + (watertrail_minstate > watertrail_maxstate && watertrailunderlay_minstate > watertrailunderlay_maxstate)) // Check if some of these were freeslot'd in wrong order + return; + fixed_t runSpeed = 14 * mobj->scale; fixed_t curSpeed = INT32_MAX; fixed_t topSpeed = INT32_MAX; @@ -5902,7 +5923,7 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) { trailScale = mapobjectscale; // Scaling is based off difference between runspeed and top speed } - + trailScale = FixedMul(trailScale, 3*FRACUNIT/4); if (trailScale > 0) @@ -5910,9 +5931,13 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) //const angle_t forwardangle = K_MomentumAngle(mobj); const angle_t forwardangle = R_PointToAngle2(0, 0, mobj->momx, mobj->momy); const fixed_t playerVisualRadius = mobj->radius + (8 * mobj->scale); - const size_t numFrames = S_WATERTRAIL5 - S_WATERTRAIL1; - const statenum_t curOverlayFrame = S_WATERTRAIL1 + (leveltime % numFrames); - const statenum_t curUnderlayFrame = S_WATERTRAILUNDERLAY1 + (leveltime % numFrames); + + // Those should be equal ideally but thats not guaranteed now + const size_t numOverlayFrames = watertrail_maxstate - watertrail_minstate; + const size_t numUnderlayFrames = watertrailunderlay_maxstate - watertrailunderlay_minstate; + + const statenum_t curOverlayFrame = watertrail_minstate + (leveltime % numOverlayFrames); + const statenum_t curUnderlayFrame = watertrailunderlay_minstate + (leveltime % numUnderlayFrames); fixed_t x1, x2, y1, y2; mobj_t *water; @@ -5929,7 +5954,7 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) // Left // underlay water = K_SpawnOrMoveMobj(x1, y1, - ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[MT_WATERTRAILUNDERLAY].height, mobj->scale) : mobj->watertop), MT_WATERTRAILUNDERLAY, + ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[watertrailunderlay].height, mobj->scale) : mobj->watertop), watertrailunderlay, mobj, 0); water->angle = forwardangle - ANGLE_180 - ANGLE_22h; water->destscale = trailScale; @@ -5942,7 +5967,7 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) // overlay water = K_SpawnOrMoveMobj(x1, y1, - ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[MT_WATERTRAIL].height, mobj->scale) : mobj->watertop), MT_WATERTRAIL, + ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[watertrail].height, mobj->scale) : mobj->watertop), watertrail, mobj, 1); water->angle = forwardangle - ANGLE_180 - ANGLE_22h; water->destscale = trailScale; @@ -5956,7 +5981,7 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) // Right // Underlay water = K_SpawnOrMoveMobj(x2, y2, - ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[MT_WATERTRAILUNDERLAY].height, mobj->scale) : mobj->watertop), MT_WATERTRAILUNDERLAY, + ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[watertrailunderlay].height, mobj->scale) : mobj->watertop), watertrailunderlay, mobj, 2); water->angle = forwardangle - ANGLE_180 + ANGLE_22h; water->destscale = trailScale; @@ -5969,7 +5994,7 @@ void K_SpawnWaterRunParticles(mobj_t *mobj) // Overlay water = K_SpawnOrMoveMobj(x2, y2, - ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[MT_WATERTRAIL].height, mobj->scale) : mobj->watertop), MT_WATERTRAIL, + ((mobj->eflags & MFE_VERTICALFLIP) ? mobj->waterbottom - FixedMul(mobjinfo[watertrail].height, mobj->scale) : mobj->watertop), watertrail, mobj, 3); water->angle = forwardangle - ANGLE_180 + ANGLE_22h; water->destscale = trailScale;