From dd73787c8b6bb8216fc646d4f7ce102347d713e5 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 19:54:20 +0200 Subject: [PATCH] Revert "optimize precip thinker" This reverts commit bc382366a129b4b6139b82ede6ed94e86747a759. --- src/hardware/hw_main.c | 16 +++-- src/info.c | 20 +++--- src/m_perfstats.c | 5 ++ src/p_local.h | 1 - src/p_mobj.c | 157 ++++++++++++++++++++--------------------- src/p_mobj.h | 33 +++++---- src/p_spec.c | 5 +- src/p_tick.c | 34 ++++----- src/r_things.c | 20 ++++-- 9 files changed, 150 insertions(+), 141 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 57b41ea49..4592d0cd0 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5322,12 +5322,6 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {0}; - // okay... this is a hack, but weather isn't networked, so it should be ok - if (!P_PrecipThinker(thing)) - { - return; - } - // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || dist < cv_grmaxinterpdist.value)) { @@ -5423,6 +5417,16 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); vis->precip = true; + + // okay... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } } static boolean drewsky = false; diff --git a/src/info.c b/src/info.c index a86a679f0..8e0bd979a 100644 --- a/src/info.c +++ b/src/info.c @@ -1822,7 +1822,7 @@ state_t states[NUMSTATES] = // Rain {SPR_RAIN, FF_TRANS50, -1, {NULL}, 0, 0, S_NULL}, // S_RAIN1 - {SPR_NULL, 0, -1, {NULL}, 0, 0, S_NULL}, // S_RAINRETURN + {SPR_RAIN, FF_TRANS50, 1, {NULL}, 0, 0, S_RAIN1}, // S_RAINRETURN // Snowflake {SPR_SNO1, 0, -1, {NULL}, 0, 0, S_NULL}, // S_SNOW1 @@ -1841,9 +1841,9 @@ state_t states[NUMSTATES] = {SPR_SPLH, FF_TRANS50|8, 2, {NULL}, 0, 0, S_NULL}, // S_SPLISH9 // Water Splash - {SPR_SPLA, FF_TRANS50 , 3, {NULL}, 0, 0, S_SPLASH2}, // S_SPLASH1 - {SPR_SPLA, FF_TRANS70|1, 3, {NULL}, 0, 0, S_SPLASH3}, // S_SPLASH2 - {SPR_SPLA, FF_TRANS90|2, 3, {NULL}, 0, 0, S_NULL}, // S_SPLASH3 + {SPR_SPLA, FF_TRANS50 , 3, {NULL}, 0, 0, S_SPLASH2}, // S_SPLASH1 + {SPR_SPLA, FF_TRANS70|1, 3, {NULL}, 0, 0, S_SPLASH3}, // S_SPLASH2 + {SPR_SPLA, FF_TRANS90|2, 3, {NULL}, 0, 0, S_RAINRETURN}, // S_SPLASH3 // Smoke {SPR_SMOK, FF_TRANS50 , 4, {NULL}, 0, 0, S_SMOKE2}, // S_SMOKE1 @@ -11215,22 +11215,22 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = S_RAIN1, // spawnstate 1000, // spawnhealth S_NULL, // seestate - sfx_rainin, // seesound - 0, // reactiontime + sfx_None, // seesound + 8, // reactiontime sfx_None, // attacksound S_NULL, // painstate 0, // painchance sfx_None, // painsound S_NULL, // meleestate S_NULL, // missilestate - S_SPLASH1, // deathstate + S_NULL, // deathstate S_NULL, // xdeathstate sfx_None, // deathsound -72*FRACUNIT, // speed -- -24*FRACUNIT originally, srb2kart x3 (nya) 1*FRACUNIT, // radius 8*FRACUNIT, // height 0, // display offset - 80, // mass + 4, // mass 0, // damage sfx_None, // activesound MF_NOBLOCKMAP, // flags @@ -11243,7 +11243,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 1000, // spawnhealth S_NULL, // seestate sfx_None, // seesound - 0, // reactiontime + 8, // reactiontime sfx_None, // attacksound S_NULL, // painstate 0, // painchance @@ -11257,7 +11257,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 4*FRACUNIT, // radius 4*FRACUNIT, // height 0, // display offset - 0, // mass + 4, // mass 0, // damage sfx_None, // activesound MF_NOBLOCKMAP, // flags diff --git a/src/m_perfstats.c b/src/m_perfstats.c index a8f9550f4..04e51a657 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -58,6 +58,7 @@ static ps_metric_t ps_regularcount = {0}; static ps_metric_t ps_scenerycount = {0}; static ps_metric_t ps_nothinkcount = {0}; static ps_metric_t ps_otherthcount = {0}; +static ps_metric_t ps_precipcount = {0}; static ps_metric_t ps_removecount = {0}; ps_metric_t ps_checkposition_calls = {0}; @@ -172,6 +173,7 @@ perfstatrow_t thinkercount_rows[] = { {" scenery", " Scenery: ", &ps_scenerycount, PS_LEVEL}, {" nothink", " Nothink: ", &ps_nothinkcount, PS_HIDE_ZERO|PS_LEVEL}, {" other ", " Other: ", &ps_otherthcount, PS_LEVEL}, + {" precip ", " Precipitation: ", &ps_precipcount, PS_LEVEL}, {" remove ", " Pending removal:", &ps_removecount, PS_LEVEL}, {0} }; @@ -570,6 +572,7 @@ static void PS_CountThinkers(void) ps_scenerycount.value.i = 0; ps_nothinkcount.value.i = 0; ps_otherthcount.value.i = 0; + ps_precipcount.value.i = 0; ps_removecount.value.i = 0; for (thinker = thinkercap.next; thinker != &thinkercap; thinker = thinker->next) { @@ -587,6 +590,8 @@ static void PS_CountThinkers(void) else ps_regularcount.value.i++; } + else if (thinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) + ps_precipcount.value.i++; else ps_otherthcount.value.i++; } diff --git a/src/p_local.h b/src/p_local.h index 67ca4beef..e1a07526a 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -70,7 +70,6 @@ extern thinker_t thinkercap; void P_InitThinkers(void); void P_AddThinker(thinker_t *thinker); void P_RemoveThinker(thinker_t *thinker); -void P_UnlinkThinker(thinker_t *thinker); // // P_USER diff --git a/src/p_mobj.c b/src/p_mobj.c index a7a4a5e01..3a4fdfe3f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -338,7 +338,7 @@ static boolean P_SetPrecipMobjState(precipmobj_t *mobj, statenum_t state) if (state == S_NULL) { // Remove mobj - P_FreePrecipMobj(mobj); + P_RemovePrecipMobj(mobj); return false; } st = &states[state]; @@ -3595,86 +3595,67 @@ void P_RecalcPrecipInSector(sector_t *sector) // // P_NullPrecipThinker // -// Just the identification of a precip thinker. The thinker -// should never actually be called! +// For "Blank" precipitation // void P_NullPrecipThinker(precipmobj_t *mobj) { - (void)mobj; - I_Assert("P_NullPrecipThinker should not be called" == 0); + //(void)mobj; + mobj->precipflags &= ~PCF_THUNK; + R_ResetPrecipitationMobjInterpolationState(mobj); } -boolean P_PrecipThinker(precipmobj_t *mobj) +void P_SnowThinker(precipmobj_t *mobj) { - if (mobj->lastThink == leveltime) - return true; // already thinked this tick - - mobj->lastThink = leveltime; - - R_ResetPrecipitationMobjInterpolationState(mobj); P_CycleStateAnimation((mobj_t *)mobj); - if (mobj->state == &states[S_RAINRETURN]) - { - // Reset to ceiling! - if (!P_SetPrecipMobjState(mobj, mobj->info->spawnstate)) - return false; - - mobj->z = mobj->ceilingz; - mobj->momz = mobj->info->speed; - mobj->precipflags &= ~PCF_SPLASH; - } - - if (mobj->tics != -1) - { - if (mobj->tics) - { - mobj->tics--; - } - - if (mobj->tics == 0) - { - if ((mobj->precipflags & PCF_SPLASH) && (mobj->state->nextstate == S_NULL)) - { - // HACK: sprite changes are 1 tic late, so you would see splashes on the ceiling if not for this state. - // We need to use the settings from the previous state, since some of those are NOT 1 tic late. - INT32 frame = (mobj->frame & ~FF_FRAMEMASK); - - if (!P_SetPrecipMobjState(mobj, S_RAINRETURN)) - return false; - - mobj->frame = frame; - return true; - } - else - { - if (!P_SetPrecipMobjState(mobj, mobj->state->nextstate)) - return false; - } - } - } - - if (mobj->precipflags & PCF_SPLASH) - return true; - // adjust height if ((mobj->z += mobj->momz) <= mobj->floorz) { - if ((mobj->info->deathstate == S_NULL) || (mobj->precipflags & PCF_PIT)) // no splashes on sky or bottomless pits - { - mobj->z = mobj->ceilingz; - } - else - { - if (!P_SetPrecipMobjState(mobj, mobj->info->deathstate)) - return false; + mobj->z = mobj->ceilingz; + R_ResetPrecipitationMobjInterpolationState(mobj); + } +} - mobj->z = mobj->floorz; - mobj->precipflags |= PCF_SPLASH; - } +void P_RainThinker(precipmobj_t *mobj) +{ + P_CycleStateAnimation((mobj_t *)mobj); + + if (mobj->state != &states[S_RAIN1]) + { + // cycle through states, + // calling action functions at transitions + if (mobj->tics <= 0) + return; + + if (--mobj->tics) + return; + + if (!P_SetPrecipMobjState(mobj, mobj->state->nextstate)) + return; + + if (mobj->state != &states[S_RAINRETURN]) + return; + + mobj->z = mobj->ceilingz; + R_ResetPrecipitationMobjInterpolationState(mobj); + P_SetPrecipMobjState(mobj, S_RAIN1); + + return; } - return true; + // adjust height + if ((mobj->z += mobj->momz) > mobj->floorz) + return; + + // no splashes on sky or bottomless pits + if (mobj->precipflags & PCF_PIT) + { + mobj->z = mobj->ceilingz; + return; + } + + mobj->z = mobj->floorz; + P_SetPrecipMobjState(mobj, S_SPLASH1); } static void P_RingThinker(mobj_t *mobj) @@ -9883,21 +9864,17 @@ mobj_t *P_SpawnShadowMobj(mobj_t * caster) static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) { - const mobjinfo_t *info = &mobjinfo[type]; state_t *st; precipmobj_t *mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL); fixed_t starting_floorz; - mobj->type = type; - mobj->info = info; - mobj->x = x; mobj->y = y; - mobj->flags = info->flags; + mobj->flags = mobjinfo[type].flags; // do not set the state with P_SetMobjState, // because action routines can not be called yet - st = &states[info->spawnstate]; + st = &states[mobjinfo[type].spawnstate]; mobj->state = st; mobj->tics = st->tics; @@ -9912,7 +9889,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->ceilingz = P_GetSectorCeilingZAt(mobj->subsector->sector, x, y); mobj->z = z; - mobj->momz = info->speed; + mobj->momz = mobjinfo[type].speed; mobj->thinker.function.acp1 = (actionf_p1)P_NullPrecipThinker; P_AddThinker(&mobj->thinker); @@ -9931,6 +9908,21 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype return mobj; } +static inline precipmobj_t *P_SpawnRainMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) +{ + precipmobj_t *mo = P_SpawnPrecipMobj(x,y,z,type); + mo->precipflags |= PCF_RAIN; + //mo->thinker.function.acp1 = (actionf_p1)P_RainThinker; + return mo; +} + +static inline precipmobj_t *P_SpawnSnowMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) +{ + precipmobj_t *mo = P_SpawnPrecipMobj(x,y,z,type); + //mo->thinker.function.acp1 = (actionf_p1)P_SnowThinker; + return mo; +} + // // P_RemoveMobj // @@ -10062,7 +10054,7 @@ boolean P_MobjWasRemoved(mobj_t *mobj) return !(mobj && mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker); } -void P_FreePrecipMobj(precipmobj_t *mobj) +void P_RemovePrecipMobj(precipmobj_t *mobj) { // unlink from sector and block lists P_UnsetPrecipThingPosition(mobj); @@ -10074,9 +10066,7 @@ void P_FreePrecipMobj(precipmobj_t *mobj) } // free block - // Precipmobjs don't actually think using their thinker, - // so the free cannot be delayed. - P_UnlinkThinker((thinker_t*)mobj); + P_RemoveThinker((thinker_t *)mobj); } // Clearing out stuff for savegames @@ -10112,7 +10102,12 @@ void P_RemoveSavegameMobj(mobj_t *mobj) // free block // Here we use the same code as R_RemoveThinkerDelayed, but without reference counting (we're removing everything so it shouldn't matter) and without touching currentthinker since we aren't in P_RunThinkers - P_UnlinkThinker((thinker_t*)mobj); + { + thinker_t *thinker = (thinker_t *)mobj; + thinker_t *next = thinker->next; + (next->prev = thinker->prev)->next = next; + Z_Free(thinker); + } } static CV_PossibleValue_t respawnitemtime_cons_t[] = {{1, "MIN"}, {300, "MAX"}, {0, NULL}}; @@ -10166,7 +10161,7 @@ void P_SpawnPrecipitation(void) if (curWeather == PRECIP_SNOW) { - rainmo = P_SpawnPrecipMobj(x, y, height, MT_SNOWFLAKE); + rainmo = P_SpawnSnowMobj(x, y, height, MT_SNOWFLAKE); mrand = M_RandomByte(); if (mrand < 64) P_SetPrecipMobjState(rainmo, S_SNOW3); @@ -10174,7 +10169,7 @@ void P_SpawnPrecipitation(void) P_SetPrecipMobjState(rainmo, S_SNOW2); } else // everything else. - rainmo = P_SpawnPrecipMobj(x, y, height, MT_RAIN); + rainmo = P_SpawnRainMobj(x, y, height, MT_RAIN); floorz = rainmo->floorz >> FRACBITS; ceilingz = rainmo->ceilingz >> FRACBITS; diff --git a/src/p_mobj.h b/src/p_mobj.h index 2f3d210c9..90c9cceb1 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -254,21 +254,24 @@ typedef enum // PRECIPITATION flags ?! ?! ?! // typedef enum { - PCF_INVISIBLE = 1, // Don't draw. - PCF_PIT = 1<<1, // Above pit. - PCF_FOF = 1<<2, // Above FOF. - PCF_MOVINGFOF = 1<<3, // Above MOVING FOF (this means we need to keep floorz up to date...) - PCF_SPLASH = 1<<4, // Splashed on the ground, return to the ceiling after the animation's over - PCF_THUNK = 1<<5, // Ran the thinker this tic. + // Don't draw. + PCF_INVISIBLE = 1, + // Above pit. + PCF_PIT = 2, + // Above FOF. + PCF_FOF = 4, + // Above MOVING FOF (this means we need to keep floorz up to date...) + PCF_MOVINGFOF = 8, + // Is rain. + PCF_RAIN = 16, + // Ran the thinker this tic. + PCF_THUNK = 32, } precipflag_t; // Map Object definition. typedef struct mobj_s { // List: thinker links. thinker_t thinker; - - mobjtype_t type; - const mobjinfo_t *info; // &mobjinfo[mobj->type] // Info for drawing: position. fixed_t x, y, z; @@ -342,6 +345,9 @@ typedef struct mobj_s struct mobj_s *hnext; struct mobj_s *hprev; + mobjtype_t type; + const mobjinfo_t *info; // &mobjinfo[mobj->type] + INT32 health; // for player this is rings + 1 // Movement direction, movement generation (zig-zagging). @@ -421,9 +427,6 @@ typedef struct precipmobj_s // List: thinker links. thinker_t thinker; - mobjtype_t type; - const mobjinfo_t *info; // &mobjinfo[mobj->type] - // Info for drawing: position. fixed_t x, y, z; fixed_t old_x, old_y, old_z; // position interpolation @@ -477,7 +480,6 @@ typedef struct precipmobj_s INT32 tics; // state tic counter state_t *state; INT32 flags; // flags from mobjinfo tables - tic_t lastThink; } precipmobj_t; typedef struct actioncache_s @@ -517,9 +519,10 @@ void P_SpawnParaloop(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 numb boolean P_BossTargetPlayer(mobj_t *actor, boolean closest); boolean P_SupermanLook4Players(mobj_t *actor); void P_DestroyRobots(void); -boolean P_PrecipThinker(precipmobj_t *mobj); +void P_SnowThinker(precipmobj_t *mobj); +void P_RainThinker(precipmobj_t *mobj); void P_NullPrecipThinker(precipmobj_t *mobj); -void P_FreePrecipMobj(precipmobj_t *mobj); +void P_RemovePrecipMobj(precipmobj_t *mobj); void P_SetScale(mobj_t *mobj, fixed_t newscale); void P_XYMovement(mobj_t *mo); void P_EmeraldManager(void); diff --git a/src/p_spec.c b/src/p_spec.c index 4dd6e8283..5e64f4422 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2063,7 +2063,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj = (precipmobj_t *)think; - P_FreePrecipMobj(precipmobj); + P_RemovePrecipMobj(precipmobj); } } else if (swap && !((swap == PRECIP_BLANK && curWeather == PRECIP_STORM_NORAIN) || (swap == PRECIP_STORM_NORAIN && curWeather == PRECIP_BLANK))) // Rather than respawn all that crap, reuse it! @@ -2090,6 +2090,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->precipflags &= ~PCF_INVISIBLE; + precipmobj->precipflags |= PCF_RAIN; //think->function.acp1 = (actionf_p1)P_RainThinker; } else if (swap == PRECIP_SNOW) // Rain To Snow @@ -2113,7 +2114,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->frame = st->frame; precipmobj->momz = mobjinfo[MT_SNOWFLAKE].speed; - precipmobj->precipflags &= ~(PCF_INVISIBLE); + precipmobj->precipflags &= ~(PCF_INVISIBLE|PCF_RAIN); //think->function.acp1 = (actionf_p1)P_SnowThinker; } diff --git a/src/p_tick.c b/src/p_tick.c index c00db9a2a..e9b1d2302 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -63,6 +63,8 @@ void Command_Numthinkers_f(void) CONS_Printf(M_GetText("numthinkers <#>: Count number of thinkers\n")); CONS_Printf( "\t1: P_MobjThinker\n" + /*"\t2: P_RainThinker\n" + "\t3: P_SnowThinker\n"*/ "\t2: P_NullPrecipThinker\n" "\t3: T_Friction\n" "\t4: T_Pusher\n" @@ -78,6 +80,14 @@ void Command_Numthinkers_f(void) action = (actionf_p1)P_MobjThinker; CONS_Printf(M_GetText("Number of %s: "), "P_MobjThinker"); break; + /*case 2: + action = (actionf_p1)P_RainThinker; + CONS_Printf(M_GetText("Number of %s: "), "P_RainThinker"); + break; + case 3: + action = (actionf_p1)P_SnowThinker; + CONS_Printf(M_GetText("Number of %s: "), "P_SnowThinker"); + break;*/ case 2: action = (actionf_p1)P_NullPrecipThinker; CONS_Printf(M_GetText("Number of %s: "), "P_NullPrecipThinker"); @@ -213,6 +223,7 @@ static thinker_t *currentthinker; // void P_RemoveThinkerDelayed(thinker_t *thinker) { + thinker_t *next; #ifdef PARANOIA if (thinker->next) thinker->next = NULL; @@ -222,29 +233,14 @@ void P_RemoveThinkerDelayed(thinker_t *thinker) if (thinker->references) return; - R_DestroyLevelInterpolators(thinker); - + /* Remove from main thinker list */ + next = thinker->next; /* Note that currentthinker is guaranteed to point to us, * and since we're freeing our memory, we had better change that. So * point it to thinker->prev, so the iterator will correctly move on to * thinker->prev->next = thinker->next */ - currentthinker = thinker->prev; - /* Remove from main thinker list */ - P_UnlinkThinker(thinker); -} - -// -// P_UnlinkThinker() -// -// Actually removes thinker from the list and frees its memory. -// -void P_UnlinkThinker(thinker_t *thinker) -{ - thinker_t *next = thinker->next; - - I_Assert(thinker->references == 0); - - (next->prev = thinker->prev)->next = next; + (next->prev = currentthinker = thinker->prev)->next = next; + R_DestroyLevelInterpolators(thinker); Z_Free(thinker); } diff --git a/src/r_things.c b/src/r_things.c index 031492618..e7bf64011 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1739,12 +1739,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) // uncapped/interpolation interpmobjstate_t interp = {0}; - // okay... this is a hack, but weather isn't networked, so it should be ok - if (!P_PrecipThinker(thing)) - { - return; - } - // do interpolation if (R_UsingFrameInterpolation() && !paused && (!cv_grmaxinterpdist.value || dist < cv_grmaxinterpdist.value)) { @@ -1837,7 +1831,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) if (thing->subsector->sector->cullheight) { if (R_DoCulling(thing->subsector->sector->cullheight, viewsector->cullheight, viewz, gz, gzt)) - return; + goto weatherthink; } // store information in a vissprite @@ -1901,6 +1895,18 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->precip = true; vis->vflip = false; vis->isScaled = false; + +weatherthink: + // okay... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } + } // R_AddSprites