From 18c2cfcacec0a09e2bbdf73c4389daf87f00c4f8 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Sun, 19 Sep 2021 15:52:54 +0200 Subject: [PATCH] Clean up arguments for the lighting effect functions --- src/p_lights.c | 76 ++++++++++++++++++-------------------------------- src/p_spec.c | 24 ++++++++-------- src/p_spec.h | 6 ++-- 3 files changed, 42 insertions(+), 64 deletions(-) diff --git a/src/p_lights.c b/src/p_lights.c index 1e41146da..4775597df 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -63,34 +63,27 @@ void T_FireFlicker(fireflicker_t *flick) /** Spawns an adjustable fire flicker effect in a sector. * - * \param minsector Sector whose light level is used as the darkest. - * \param maxsector Sector whose light level is used as the brightest, - * and also the target sector for the effect. + * \param sector Target sector for the effect. + * \param lighta One of the two light levels to move between. + * \param lightb The other light level. * \param length Four times the number of tics between flickers. * \sa T_FireFlicker */ -fireflicker_t *P_SpawnAdjustableFireFlicker(sector_t *minsector, sector_t *maxsector, INT32 length) +fireflicker_t *P_SpawnAdjustableFireFlicker(sector_t *sector, INT16 lighta, INT16 lightb, INT32 length) { fireflicker_t *flick; - P_RemoveLighting(maxsector); // out with the old, in with the new + P_RemoveLighting(sector); // out with the old, in with the new flick = Z_Calloc(sizeof (*flick), PU_LEVSPEC, NULL); P_AddThinker(THINK_MAIN, &flick->thinker); flick->thinker.function.acp1 = (actionf_p1)T_FireFlicker; - flick->sector = maxsector; - flick->maxlight = maxsector->lightlevel; - flick->minlight = minsector->lightlevel; - if (flick->minlight > flick->maxlight) - { - // You mixed them up, you dummy. - INT32 oops = flick->minlight; - flick->minlight = flick->maxlight; - flick->maxlight = oops; - } + flick->sector = sector; + flick->maxlight = max(lighta, lightb); + flick->minlight = min(lighta, lightb); flick->count = flick->resetcount = length/4; - maxsector->lightingdata = flick; + sector->lightingdata = flick; // input bounds checking and stuff if (!flick->resetcount) @@ -194,9 +187,9 @@ void T_StrobeFlash(strobe_t *flash) /** Spawns an adjustable strobe light effect in a sector. * - * \param minsector Sector whose light level is used as the darkest. - * \param maxsector Sector whose light level is used as the brightest, - * and also the target sector for the effect. + * \param sector Target sector for the effect. + * \param lighta One of the two light levels to move between. + * \param lightb The other light level. * \param darktime Time in tics for the light to be dark. * \param brighttime Time in tics for the light to be bright. * \param inSync If true, the effect will be kept in sync @@ -207,29 +200,21 @@ void T_StrobeFlash(strobe_t *flash) * the strobe flash is random. * \sa T_StrobeFlash */ -strobe_t *P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector, INT32 darktime, INT32 brighttime, boolean inSync) +strobe_t *P_SpawnAdjustableStrobeFlash(sector_t *sector, INT16 lighta, INT16 lightb, INT32 darktime, INT32 brighttime, boolean inSync) { strobe_t *flash; - P_RemoveLighting(maxsector); // out with the old, in with the new + P_RemoveLighting(sector); // out with the old, in with the new flash = Z_Calloc(sizeof (*flash), PU_LEVSPEC, NULL); P_AddThinker(THINK_MAIN, &flash->thinker); - flash->sector = maxsector; + flash->sector = sector; flash->darktime = darktime; flash->brighttime = brighttime; flash->thinker.function.acp1 = (actionf_p1)T_StrobeFlash; - flash->maxlight = maxsector->lightlevel; - flash->minlight = minsector->lightlevel; - - if (flash->minlight > flash->maxlight) - { - // You mixed them up, you dummy. - INT32 oops = flash->minlight; - flash->minlight = flash->maxlight; - flash->maxlight = oops; - } + flash->maxlight = max(lighta, lightb); + flash->minlight = min(lighta, lightb); if (flash->minlight == flash->maxlight) flash->minlight = 0; @@ -239,7 +224,7 @@ strobe_t *P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector, else flash->count = 1; - maxsector->lightingdata = flash; + sector->lightingdata = flash; return flash; } @@ -276,31 +261,24 @@ void T_Glow(glow_t *g) /** Spawns an adjustable glowing light effect in a sector. * - * \param minsector Sector whose light level is used as the darkest. - * \param maxsector Sector whose light level is used as the brightest, - * and also the target sector for the effect. + * \param sector Target sector for the effect. + * \param lighta One of the two light levels to move between. + * \param lightb The other light level. * \param length The speed of the effect. * \sa T_Glow */ -glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, INT32 length) +glow_t *P_SpawnAdjustableGlowingLight(sector_t *sector, INT16 lighta, INT16 lightb, INT32 length) { glow_t *g; - P_RemoveLighting(maxsector); // out with the old, in with the new + P_RemoveLighting(sector); // out with the old, in with the new g = Z_Calloc(sizeof (*g), PU_LEVSPEC, NULL); P_AddThinker(THINK_MAIN, &g->thinker); - g->sector = maxsector; - g->minlight = minsector->lightlevel; - g->maxlight = maxsector->lightlevel; - if (g->minlight > g->maxlight) - { - // You mixed them up, you dummy. - INT32 oops = g->minlight; - g->minlight = g->maxlight; - g->maxlight = oops; - } + g->sector = sector; + g->minlight = min(lighta, lightb); + g->maxlight = max(lighta, lightb); g->thinker.function.acp1 = (actionf_p1)T_Glow; g->direction = 1; g->speed = length/4; @@ -317,7 +295,7 @@ glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, g->speed = (g->maxlight - g->minlight)/2; } - maxsector->lightingdata = g; + sector->lightingdata = g; return g; } diff --git a/src/p_spec.c b/src/p_spec.c index d682b4242..833a67290 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2520,7 +2520,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT16 reallightlevel = sectors[secnum].lightlevel; sectors[secnum].lightlevel = line->backsector->lightlevel; - flick = P_SpawnAdjustableFireFlicker(line->frontsector, §ors[secnum], + flick = P_SpawnAdjustableFireFlicker(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, P_AproxDistance(line->dx, line->dy)>>FRACBITS); // Make sure the starting light level is in range. @@ -2535,7 +2535,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { // Use front sector for min, target sector for max, // the same way linetype 61 does it. - P_SpawnAdjustableFireFlicker(line->frontsector, §ors[secnum], + P_SpawnAdjustableFireFlicker(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, P_AproxDistance(line->dx, line->dy)>>FRACBITS); } } @@ -2554,7 +2554,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT16 reallightlevel = sectors[secnum].lightlevel; sectors[secnum].lightlevel = line->backsector->lightlevel; - glow = P_SpawnAdjustableGlowingLight(line->frontsector, §ors[secnum], + glow = P_SpawnAdjustableGlowingLight(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, P_AproxDistance(line->dx, line->dy)>>FRACBITS); // Make sure the starting light level is in range. @@ -2569,7 +2569,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { // Use front sector for min, target sector for max, // the same way linetype 602 does it. - P_SpawnAdjustableGlowingLight(line->frontsector, §ors[secnum], + P_SpawnAdjustableGlowingLight(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, P_AproxDistance(line->dx, line->dy)>>FRACBITS); } } @@ -2588,7 +2588,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT16 reallightlevel = sectors[secnum].lightlevel; sectors[secnum].lightlevel = line->backsector->lightlevel; - flash = P_SpawnAdjustableStrobeFlash(line->frontsector, §ors[secnum], + flash = P_SpawnAdjustableStrobeFlash(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, abs(line->dx)>>FRACBITS, abs(line->dy)>>FRACBITS, false); // Make sure the starting light level is in range. @@ -2603,7 +2603,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { // Use front sector for min, target sector for max, // the same way linetype 602 does it. - P_SpawnAdjustableStrobeFlash(line->frontsector, §ors[secnum], + P_SpawnAdjustableStrobeFlash(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, abs(line->dx)>>FRACBITS, abs(line->dy)>>FRACBITS, false); } } @@ -2622,7 +2622,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT16 reallightlevel = sectors[secnum].lightlevel; sectors[secnum].lightlevel = line->backsector->lightlevel; - flash = P_SpawnAdjustableStrobeFlash(line->frontsector, §ors[secnum], + flash = P_SpawnAdjustableStrobeFlash(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, abs(line->dx)>>FRACBITS, abs(line->dy)>>FRACBITS, true); // Make sure the starting light level is in range. @@ -2637,7 +2637,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { // Use front sector for min, target sector for max, // the same way linetype 602 does it. - P_SpawnAdjustableStrobeFlash(line->frontsector, §ors[secnum], + P_SpawnAdjustableStrobeFlash(§ors[secnum], line->frontsector->lightlevel, sectors[secnum].lightlevel, abs(line->dx)>>FRACBITS, abs(line->dy)>>FRACBITS, true); } } @@ -6960,28 +6960,28 @@ void P_SpawnSpecials(boolean fromnetsave) case 602: // Adjustable pulsating light sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(tag, s) - P_SpawnAdjustableGlowingLight(§ors[sec], §ors[s], + P_SpawnAdjustableGlowingLight(§ors[s], sectors[sec].lightlevel, sectors[s].lightlevel, P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 603: // Adjustable flickering light sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(tag, s) - P_SpawnAdjustableFireFlicker(§ors[sec], §ors[s], + P_SpawnAdjustableFireFlicker(§ors[s], sectors[sec].lightlevel, sectors[s].lightlevel, P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 604: // Adjustable Blinking Light (unsynchronized) sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(tag, s) - P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], + P_SpawnAdjustableStrobeFlash(§ors[s], sectors[sec].lightlevel, sectors[s].lightlevel, abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, false); break; case 605: // Adjustable Blinking Light (synchronized) sec = sides[*lines[i].sidenum].sector - sectors; TAG_ITER_SECTORS(tag, s) - P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], + P_SpawnAdjustableStrobeFlash(§ors[s], sectors[sec].lightlevel, sectors[s].lightlevel, abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, true); break; diff --git a/src/p_spec.h b/src/p_spec.h index 19f8a847c..95005882b 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -284,15 +284,15 @@ typedef struct void P_RemoveLighting(sector_t *sector); void T_FireFlicker(fireflicker_t *flick); -fireflicker_t *P_SpawnAdjustableFireFlicker(sector_t *minsector, sector_t *maxsector, INT32 length); +fireflicker_t *P_SpawnAdjustableFireFlicker(sector_t *sector, INT16 lighta, INT16 lightb, INT32 length); void T_LightningFlash(lightflash_t *flash); void T_StrobeFlash(strobe_t *flash); void P_SpawnLightningFlash(sector_t *sector); -strobe_t * P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector, INT32 darktime, INT32 brighttime, boolean inSync); +strobe_t * P_SpawnAdjustableStrobeFlash(sector_t *sector, INT16 lighta, INT16 lightb, INT32 darktime, INT32 brighttime, boolean inSync); void T_Glow(glow_t *g); -glow_t *P_SpawnAdjustableGlowingLight(sector_t *minsector, sector_t *maxsector, INT32 length); +glow_t *P_SpawnAdjustableGlowingLight(sector_t *sector, INT16 lighta, INT16 lightb, INT32 length); void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean ticbased); void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean force);