From 762223db7ceca9ed428da723c84f121c6292bf4c Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 17 Jan 2020 20:45:55 -0800 Subject: [PATCH] Duplicated code is gone, so sad --- src/hardware/hw_main.c | 44 +++----------------- src/r_things.c | 93 ++++++++++++++++++++++++------------------ src/r_things.h | 9 ++++ 3 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e658051a6..7ab0929da 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5399,7 +5399,7 @@ static void HWR_AddSprites(sector_t *sec) #ifdef HWPRECIP precipmobj_t *precipthing; #endif - fixed_t approx_dist, limit_dist, hoop_limit_dist; + fixed_t limit_dist, hoop_limit_dist; // BSP is traversed by subsector. // A sector might have been split into several @@ -5418,37 +5418,10 @@ static void HWR_AddSprites(sector_t *sec) // If a limit exists, handle things a tiny bit different. limit_dist = (fixed_t)(cv_drawdist.value) << FRACBITS; hoop_limit_dist = (fixed_t)(cv_drawdist_nights.value) << FRACBITS; - if (limit_dist || hoop_limit_dist) + for (thing = sec->thinglist; thing; thing = thing->snext) { - for (thing = sec->thinglist; thing; thing = thing->snext) - { - if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW || - thing == r_viewmobj) - continue; - - approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); - - if (thing->sprite == SPR_HOOP) - { - if (hoop_limit_dist && approx_dist > hoop_limit_dist) - continue; - } - else - { - if (limit_dist && approx_dist > limit_dist) - continue; - } - + if (R_ThingVisibleWithinDist(thing, limit_dist, hoop_limit_dist)) HWR_ProjectSprite(thing); - } - } - else - { - // Draw everything in sector, no checks - for (thing = sec->thinglist; thing; thing = thing->snext) - if (!(thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW || - thing == r_viewmobj)) - HWR_ProjectSprite(thing); } #ifdef HWPRECIP @@ -5457,15 +5430,8 @@ static void HWR_AddSprites(sector_t *sec) { for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) { - if (precipthing->precipflags & PCF_INVISIBLE) - continue; - - approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); - - if (approx_dist > limit_dist) - continue; - - HWR_ProjectPrecipitationSprite(precipthing); + if (R_PrecipThingVisible(precipthing, limit_dist)) + HWR_ProjectPrecipitationSprite(precipthing); } } #endif diff --git a/src/r_things.c b/src/r_things.c index 2a18c06a4..2a2872a34 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1808,7 +1808,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) mobj_t *thing; precipmobj_t *precipthing; // Tails 08-25-2002 INT32 lightnum; - fixed_t approx_dist, limit_dist, hoop_limit_dist; + fixed_t limit_dist, hoop_limit_dist; if (rendermode != render_soft) return; @@ -1841,37 +1841,10 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) // If a limit exists, handle things a tiny bit different. limit_dist = (fixed_t)(cv_drawdist.value) << FRACBITS; hoop_limit_dist = (fixed_t)(cv_drawdist_nights.value) << FRACBITS; - if (limit_dist || hoop_limit_dist) + for (thing = sec->thinglist; thing; thing = thing->snext) { - for (thing = sec->thinglist; thing; thing = thing->snext) - { - if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW || - thing == r_viewmobj) - continue; - - approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); - - if (thing->sprite == SPR_HOOP) - { - if (hoop_limit_dist && approx_dist > hoop_limit_dist) - continue; - } - else - { - if (limit_dist && approx_dist > limit_dist) - continue; - } - + if (R_ThingVisibleWithinDist(thing, limit_dist, hoop_limit_dist)) R_ProjectSprite(thing); - } - } - else - { - // Draw everything in sector, no checks - for (thing = sec->thinglist; thing; thing = thing->snext) - if (!(thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW || - thing == r_viewmobj)) - R_ProjectSprite(thing); } // no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off @@ -1879,15 +1852,8 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) { for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) { - if (precipthing->precipflags & PCF_INVISIBLE) - continue; - - approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); - - if (approx_dist > limit_dist) - continue; - - R_ProjectPrecipitationSprite(precipthing); + if (R_PrecipThingVisible(precipthing, limit_dist)) + R_ProjectPrecipitationSprite(precipthing); } } } @@ -2582,6 +2548,55 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) } } +/* Check if thing may be drawn from our current view. */ +boolean R_ThingVisible (mobj_t *thing) +{ + return (!( + thing->sprite == SPR_NULL || + ( thing->flags2 & (MF2_DONTDRAW) ) || + thing == r_viewmobj + )); +} + +boolean R_ThingVisibleWithinDist (mobj_t *thing, + fixed_t limit_dist, + fixed_t hoop_limit_dist) +{ + fixed_t approx_dist; + + if (! R_ThingVisible(thing)) + return false; + + approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); + + if (thing->sprite == SPR_HOOP) + { + if (hoop_limit_dist && approx_dist > hoop_limit_dist) + return false; + } + else + { + if (limit_dist && approx_dist > limit_dist) + return false; + } + + return true; +} + +/* Check if precipitation may be drawn from our current view. */ +boolean R_PrecipThingVisible (precipmobj_t *precipthing, + fixed_t limit_dist) +{ + fixed_t approx_dist; + + if (( precipthing->precipflags & PCF_INVISIBLE )) + return false; + + approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); + + return ( approx_dist <= limit_dist ); +} + // // R_DrawMasked // diff --git a/src/r_things.h b/src/r_things.h index 1b74dd74e..76587868d 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -61,6 +61,15 @@ void R_InitSprites(void); void R_ClearSprites(void); void R_ClipSprites(drawseg_t* dsstart, portal_t* portal); +boolean R_ThingVisible (mobj_t *thing); + +boolean R_ThingVisibleWithinDist (mobj_t *thing, + fixed_t draw_dist, + fixed_t nights_draw_dist); + +boolean R_PrecipThingVisible (precipmobj_t *precipthing, + fixed_t precip_draw_dist); + /** Used to count the amount of masked elements * per portal to later group them in separate * drawnode lists.