From 999e5618d744b9edaff8a2ec9ea7c9ae9c7f8994 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Sep 2024 01:00:47 +0200 Subject: [PATCH] fix precip performance issuess on certain maps --- src/p_mobj.c | 67 +++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 208575d52..da0461139 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10174,9 +10174,8 @@ consvar_t cv_suddendeath = {"suddendeath", "Off", CV_NETVAR|CV_CHEAT|CV_NOSHOWHE void P_SpawnPrecipitation(void) { - INT32 i, j, k, mrand; - fixed_t basex, basey, x, y, z, height; - fixed_t precipscale = cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT; + INT32 i, mrand; + fixed_t basex, basey, j, x, y, z; subsector_t *precipsector = NULL; precipmobj_t *rainmo = NULL; @@ -10189,9 +10188,10 @@ void P_SpawnPrecipitation(void) basex = bmaporgx + (i % bmapwidth) * MAPBLOCKSIZE; basey = bmaporgy + (i / bmapwidth) * MAPBLOCKSIZE; - for (j = 0; j < FRACUNIT; j += precipscale) + for (j = 0; j < FRACUNIT; j += cv_mobjscaleprecip.value ? mapobjectscale : FRACUNIT) { - UINT16 numparticles = 0; + INT32 floorz; + INT32 ceilingz; x = ((cv_lessprecip.value ? basex*1.5 : basex) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); y = ((cv_lessprecip.value ? basey*1.5 : basey) + ((M_RandomKey(MAPBLOCKUNITS<<3)<>3)); @@ -10206,50 +10206,37 @@ void P_SpawnPrecipitation(void) // Not in a sector with visible sky? if (precipsector->sector->ceilingpic != skyflatnum) continue; - - height = precipsector->sector->ceilingheight - precipsector->sector->floorheight; - height = FixedDiv(height, precipscale); - // Exists, but is too small for reasonable precipitation. - if (height < 64<sector->floorheight <= precipsector->sector->ceilingheight - (32<sector->ceilingheight; - for (k = 0; k < numparticles; k++) + if (curWeather == PRECIP_SNOW) { - INT32 floorz; - INT32 ceilingz; + rainmo = P_SpawnPrecipMobj(x, y, z, MT_SNOWFLAKE); + mrand = M_RandomByte(); + if (mrand < 64) + P_SetPrecipMobjState(rainmo, S_SNOW3); + else if (mrand < 144) + P_SetPrecipMobjState(rainmo, S_SNOW2); + } + else // everything else. + rainmo = P_SpawnPrecipMobj(x, y, z, MT_RAIN); - if (curWeather == PRECIP_SNOW) - { - rainmo = P_SpawnPrecipMobj(x, y, z, MT_SNOWFLAKE); - mrand = M_RandomByte(); - if (mrand < 64) - P_SetPrecipMobjState(rainmo, S_SNOW3); - else if (mrand < 144) - P_SetPrecipMobjState(rainmo, S_SNOW2); - } - else // everything else. - rainmo = P_SpawnPrecipMobj(x, y, z, MT_RAIN); + floorz = rainmo->floorz >> FRACBITS; + ceilingz = rainmo->ceilingz >> FRACBITS; - floorz = rainmo->floorz >> FRACBITS; - ceilingz = rainmo->ceilingz >> FRACBITS; - - if (floorz < ceilingz) - { - // Randomly assign a height, now that floorz is set. - rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; - } - else - { - // ...except if the floor is above the ceiling. - rainmo->z = ceilingz << FRACBITS; - } + if (floorz < ceilingz) + { + // Randomly assign a height, now that floorz is set. + rainmo->z = M_RandomRange(floorz, ceilingz) << FRACBITS; + } + else + { + // ...except if the floor is above the ceiling. + rainmo->z = ceilingz << FRACBITS; } } }