From da3ffafc9095e5c67959c1454e19b98b7fd412fc Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jan 2025 05:07:56 +0100 Subject: [PATCH] we dont really need to check for precipthinkers in the precip thinkerlist also makes precip handling in P_NetUnArchiveThinkers a little safer --- src/p_saveg.c | 23 ++++++++++++++--------- src/p_spec.c | 4 ++++ src/p_tick.c | 22 ++++++---------------- src/r_main.c | 2 ++ 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 20dd40937..dcf8f0de9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2670,6 +2670,8 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) { thinker_t *currentthinker; thinker_t *next; + thinker_t *currentprecipthinker; + thinker_t *nextprecip; UINT8 tclass; UINT8 restoreNum = false; UINT32 i; @@ -2694,19 +2696,22 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) } } - currentthinker = precipcap.next; - for (currentthinker = precipcap.next; currentthinker != &precipcap; currentthinker = next) + // remove all the current precip thinkers + currentprecipthinker = precipcap.next; + for (currentprecipthinker = precipcap.next; currentprecipthinker != &precipcap; currentprecipthinker = nextprecip) { - next = currentthinker->next; + nextprecip = currentprecipthinker->next; - if (currentthinker->function.acp1 == (actionf_p1)P_NullPrecipThinker) - P_RemoveSavegameMobj((mobj_t *)currentthinker); // item isn't saved, don't remove it - else +#ifdef PARANOIA + if (currentprecipthinker->function.acp1 != (actionf_p1)P_NullPrecipThinker) { - (next->prev = currentthinker->prev)->next = next; - R_DestroyLevelInterpolators(currentthinker); - Z_Free(currentthinker); + (next->prev = currentprecipthinker->prev)->next = nextprecip; + R_DestroyLevelInterpolators(currentprecipthinker); + Z_Free(currentprecipthinker); } + else +#endif + P_RemoveSavegameMobj((mobj_t *)currentprecipthinker); // item isn't saved, don't remove it } // we don't want the removed mobjs to come back diff --git a/src/p_spec.c b/src/p_spec.c index 1fba46ea5..12b42e990 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1783,8 +1783,10 @@ void P_SwitchWeather(INT32 weathernum) { next = think->next; +#ifdef PARANOIA if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker +#endif precipmobj = (precipmobj_t *)think; P_FreePrecipMobj(precipmobj); @@ -1798,8 +1800,10 @@ void P_SwitchWeather(INT32 weathernum) for (think = precipcap.next; think != &precipcap; think = think->next) { +#ifdef PARANOIA if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker +#endif precipmobj = (precipmobj_t *)think; diff --git a/src/p_tick.c b/src/p_tick.c index cb583706e..32cf7b785 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -57,6 +57,7 @@ void Command_Numthinkers_f(void) INT32 count = 0; actionf_p1 action; thinker_t *think; + thinker_t *listtype; if (gamestate != GS_LEVEL) { @@ -105,25 +106,14 @@ void Command_Numthinkers_f(void) return; } - if (num == 2) // P_NullPrecipThinker - { - for (think = precipcap.next; think != &precipcap; think = think->next) - { - if (think->function.acp1 != action) - continue; + listtype = (num == 2) ? &precipcap : &thinkercap; - count++; - } - } - else + for (think = listtype->next; think != listtype; think = think->next) { - for (think = thinkercap.next; think != &thinkercap; think = think->next) - { - if (think->function.acp1 != action) - continue; + if (think->function.acp1 != action) + continue; - count++; - } + count++; } CONS_Printf("%d\n", count); diff --git a/src/r_main.c b/src/r_main.c index 27ec6c09b..37a94b9ef 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -314,8 +314,10 @@ static void Precipstuff_OnChange(void) { next = think->next; +#ifdef PARANOIA if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker +#endif precipmobj = (precipmobj_t *)think; P_FreePrecipMobj(precipmobj);