From b6fd7a1e9675f6fa6513f3aea765a334e56672c8 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 24 Apr 2025 13:02:26 +0200 Subject: [PATCH] put precip purge into a function to reduce code dupe and branching --- src/p_mobj.c | 20 ++++++-------------- src/p_saveg.c | 19 +------------------ src/p_spec.c | 44 +++++++++++++++----------------------------- src/p_spec.h | 1 + src/r_main.c | 22 +++------------------- 5 files changed, 26 insertions(+), 80 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index fb34b335d..364396ce8 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10174,21 +10174,13 @@ void P_RemoveSavegameMobj(mobj_t *mobj) thinker_t *th = (thinker_t*)mobj; // unlink from sector and block lists - if (th->function.acp1 == (actionf_p1)P_NullPrecipThinker) - { - P_UnsetPrecipThingPosition((precipmobj_t *)mobj); - } - else - { - // unlink from sector and block lists - P_UnsetThingPosition(mobj); + P_UnsetThingPosition(mobj); - // Remove touching_sectorlist from mobj. - if (sector_list) - { - P_DelSeclist(sector_list); - sector_list = NULL; - } + // Remove touching_sectorlist from mobj. + if (sector_list) + { + P_DelSeclist(sector_list); + sector_list = NULL; } // stop any playing sound diff --git a/src/p_saveg.c b/src/p_saveg.c index b5f11cedb..c63887b69 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2669,8 +2669,6 @@ 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; @@ -2696,22 +2694,7 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) } // remove all the current precip thinkers - currentprecipthinker = precipcap.next; - for (currentprecipthinker = precipcap.next; currentprecipthinker != &precipcap; currentprecipthinker = nextprecip) - { - nextprecip = currentprecipthinker->next; - -#ifdef PARANOIA - if (currentprecipthinker->function.acp1 != (actionf_p1)P_NullPrecipThinker) - { - (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 - } + P_PurgePrecipitation(); // we don't want the removed mobjs to come back iquetail = iquehead = 0; diff --git a/src/p_spec.c b/src/p_spec.c index 670289fcf..e14d09333 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1721,6 +1721,19 @@ static boolean is_rain_type (INT32 weathernum) } } +void P_PurgePrecipitation(void) +{ + thinker_t *think; + thinker_t *next; + + for (think = precipcap.next; think != NULL && think != &precipcap;) + { + next = think->next; + P_FreePrecipMobj((precipmobj_t *)think); + think = next; + } +} + // // P_SwitchWeather // @@ -1729,6 +1742,7 @@ static boolean is_rain_type (INT32 weathernum) void P_SwitchWeather(INT32 weathernum) { boolean purge = true; + boolean spawnprecip = false; if (weathernum == curWeather) return; @@ -1739,22 +1753,7 @@ void P_SwitchWeather(INT32 weathernum) if (purge) { - thinker_t *think; - thinker_t *next; - precipmobj_t *precipmobj; - - for (think = precipcap.next; think != &precipcap; think = next) - { - 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); - } + P_PurgePrecipitation(); } else // Rather than respawn all that crap, reuse it! { @@ -1764,11 +1763,6 @@ 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; INT32 z = 0; @@ -1813,8 +1807,6 @@ void P_SwitchWeather(INT32 weathernum) } } - boolean spawnprecip = false; - switch (weathernum) { case PRECIP_SNOW: // snow @@ -1822,23 +1814,17 @@ void P_SwitchWeather(INT32 weathernum) spawnprecip = true; break; case PRECIP_RAIN: // rain - { curWeather = PRECIP_RAIN; spawnprecip = true; break; - } case PRECIP_STORM: // storm - { curWeather = PRECIP_STORM; spawnprecip = true; break; - } case PRECIP_STORM_NOSTRIKES: // storm w/o lightning - { curWeather = PRECIP_STORM_NOSTRIKES; spawnprecip = true; break; - } case PRECIP_STORM_NORAIN: // storm w/o rain curWeather = PRECIP_STORM_NORAIN; break; diff --git a/src/p_spec.h b/src/p_spec.h index c89d024d2..60b10a8f4 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -74,6 +74,7 @@ INT32 P_FindMinSurroundingLight(sector_t *sector, INT32 max); void P_SetupSignExit(player_t *player); boolean P_IsFlagAtBase(mobjtype_t flag); +void P_PurgePrecipitation(void); void P_SwitchWeather(INT32 weathernum); boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller); diff --git a/src/r_main.c b/src/r_main.c index 4ff9a96ff..b1b707d1d 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -295,27 +295,11 @@ static void FlipCam4_OnChange(void) static void Precipstuff_OnChange(void) { - if (gamestate != GS_LEVEL) - return; - - thinker_t *think; - thinker_t *next; - precipmobj_t *precipmobj; - - for (think = precipcap.next; think != &precipcap; think = next) + if (gamestate == GS_LEVEL) { - 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); + P_PurgePrecipitation(); + P_SpawnPrecipitation(); } - - P_SpawnPrecipitation(); } //