Merge branch 'i-can-see-myself' into 'master'

Don't draw yourself in first person!

See merge request STJr/SRB2!697
This commit is contained in:
James R 2020-01-31 02:34:11 -05:00
commit aad4b6f8a1
5 changed files with 98 additions and 104 deletions

View File

@ -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,35 +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)
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))
HWR_ProjectSprite(thing);
}
#ifdef HWPRECIP
@ -5455,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
@ -5727,7 +5695,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
if ((thing->flags2 & MF2_LINKDRAW) && thing->tracer)
{
// bodge support - not nearly as comprehensive as r_things.c, but better than nothing
if (thing->tracer->sprite == SPR_NULL || thing->tracer->flags2 & MF2_DONTDRAW)
if (! R_ThingVisible(thing->tracer))
return;
}

View File

@ -71,6 +71,7 @@ angle_t viewangle, aimingangle;
fixed_t viewcos, viewsin;
sector_t *viewsector;
player_t *viewplayer;
mobj_t *r_viewmobj;
//
// precalculated math tables
@ -741,8 +742,6 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y)
// R_SetupFrame
//
static mobj_t *viewmobj;
// WARNING: a should be unsigned but to add with 2048, it isn't!
#define AIMINGTODY(a) FixedDiv((FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160)>>FRACBITS, fovtan)
@ -799,16 +798,16 @@ void R_SetupFrame(player_t *player)
if (player->awayviewtics)
{
// cut-away view stuff
viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN
I_Assert(viewmobj != NULL);
viewz = viewmobj->z + 20*FRACUNIT;
r_viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN
I_Assert(r_viewmobj != NULL);
viewz = r_viewmobj->z + 20*FRACUNIT;
aimingangle = player->awayviewaiming;
viewangle = viewmobj->angle;
viewangle = r_viewmobj->angle;
}
else if (!player->spectator && chasecam)
// use outside cam view
{
viewmobj = NULL;
r_viewmobj = NULL;
viewz = thiscam->z + (thiscam->height>>1);
aimingangle = thiscam->aiming;
viewangle = thiscam->angle;
@ -818,11 +817,11 @@ void R_SetupFrame(player_t *player)
{
viewz = player->viewz;
viewmobj = player->mo;
I_Assert(viewmobj != NULL);
r_viewmobj = player->mo;
I_Assert(r_viewmobj != NULL);
aimingangle = player->aiming;
viewangle = viewmobj->angle;
viewangle = r_viewmobj->angle;
if (!demoplayback && player->playerstate != PST_DEAD)
{
@ -856,13 +855,13 @@ void R_SetupFrame(player_t *player)
}
else
{
viewx = viewmobj->x;
viewy = viewmobj->y;
viewx = r_viewmobj->x;
viewy = r_viewmobj->y;
viewx += quake.x;
viewy += quake.y;
if (viewmobj->subsector)
viewsector = viewmobj->subsector->sector;
if (r_viewmobj->subsector)
viewsector = r_viewmobj->subsector->sector;
else
viewsector = R_PointInSubsector(viewx, viewy)->sector;
}
@ -884,12 +883,12 @@ void R_SkyboxFrame(player_t *player)
thiscam = &camera;
// cut-away view stuff
viewmobj = skyboxmo[0];
r_viewmobj = skyboxmo[0];
#ifdef PARANOIA
if (!viewmobj)
if (!r_viewmobj)
{
const size_t playeri = (size_t)(player - players);
I_Error("R_SkyboxFrame: viewmobj null (player %s)", sizeu1(playeri));
I_Error("R_SkyboxFrame: r_viewmobj null (player %s)", sizeu1(playeri));
}
#endif
if (player->awayviewtics)
@ -920,13 +919,13 @@ void R_SkyboxFrame(player_t *player)
}
}
}
viewangle += viewmobj->angle;
viewangle += r_viewmobj->angle;
viewplayer = player;
viewx = viewmobj->x;
viewy = viewmobj->y;
viewz = viewmobj->z; // 26/04/17: use actual Z position instead of spawnpoint angle!
viewx = r_viewmobj->x;
viewy = r_viewmobj->y;
viewz = r_viewmobj->z; // 26/04/17: use actual Z position instead of spawnpoint angle!
if (mapheaderinfo[gamemap-1])
{
@ -966,29 +965,29 @@ void R_SkyboxFrame(player_t *player)
else if (mh->skybox_scaley < 0)
y = (campos.y - skyboxmo[1]->y) * -mh->skybox_scaley;
if (viewmobj->angle == 0)
if (r_viewmobj->angle == 0)
{
viewx += x;
viewy += y;
}
else if (viewmobj->angle == ANGLE_90)
else if (r_viewmobj->angle == ANGLE_90)
{
viewx -= y;
viewy += x;
}
else if (viewmobj->angle == ANGLE_180)
else if (r_viewmobj->angle == ANGLE_180)
{
viewx -= x;
viewy -= y;
}
else if (viewmobj->angle == ANGLE_270)
else if (r_viewmobj->angle == ANGLE_270)
{
viewx += y;
viewy -= x;
}
else
{
angle_t ang = viewmobj->angle>>ANGLETOFINESHIFT;
angle_t ang = r_viewmobj->angle>>ANGLETOFINESHIFT;
viewx += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang));
viewy += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang));
}
@ -999,8 +998,8 @@ void R_SkyboxFrame(player_t *player)
viewz += campos.z * -mh->skybox_scalez;
}
if (viewmobj->subsector)
viewsector = viewmobj->subsector->sector;
if (r_viewmobj->subsector)
viewsector = r_viewmobj->subsector->sector;
else
viewsector = R_PointInSubsector(viewx, viewy)->sector;

View File

@ -83,6 +83,7 @@ extern fixed_t viewx, viewy, viewz;
extern angle_t viewangle, aimingangle;
extern sector_t *viewsector;
extern player_t *viewplayer;
extern mobj_t *r_viewmobj;
extern consvar_t cv_allowmlook;
extern consvar_t cv_maxportals;

View File

@ -1413,7 +1413,7 @@ static void R_ProjectSprite(mobj_t *thing)
thing = thing->tracer;
if (thing->sprite == SPR_NULL || thing->flags2 & MF2_DONTDRAW)
if (! R_ThingVisible(thing))
return;
tr_x = thing->x - viewx;
@ -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,35 +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)
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))
R_ProjectSprite(thing);
}
// no, no infinite draw distance for precipitation. this option at zero is supposed to turn it off
@ -1877,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);
}
}
}
@ -2580,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
//

View File

@ -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.