2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2023-03-31 12:53:31 +00:00
|
|
|
// Copyright (C) 1999-2023 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file r_bsp.c
|
|
|
|
/// \brief BSP traversal, handling of LineSegs for rendering
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "r_local.h"
|
|
|
|
#include "r_state.h"
|
2019-06-01 19:26:25 +00:00
|
|
|
#include "r_portal.h" // Add seg portals
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#include "r_splats.h"
|
|
|
|
#include "p_local.h" // camera
|
2015-10-10 16:57:35 +00:00
|
|
|
#include "p_slopes.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
#include "z_zone.h" // Check R_Prep3DFloors
|
2020-04-12 11:14:39 +00:00
|
|
|
#include "taglist.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
seg_t *curline;
|
|
|
|
side_t *sidedef;
|
|
|
|
line_t *linedef;
|
|
|
|
sector_t *frontsector;
|
|
|
|
sector_t *backsector;
|
|
|
|
|
|
|
|
// very ugly realloc() of drawsegs at run-time, I upped it to 512
|
|
|
|
// instead of 256.. and someone managed to send me a level with
|
|
|
|
// 896 drawsegs! So too bad here's a limit removal a-la-Boom
|
2019-06-10 15:12:18 +00:00
|
|
|
drawseg_t *curdrawsegs = NULL; /**< This is used to handle multiple lists for masked drawsegs. */
|
2014-03-15 16:59:03 +00:00
|
|
|
drawseg_t *drawsegs = NULL;
|
|
|
|
drawseg_t *ds_p = NULL;
|
|
|
|
|
2023-08-23 16:43:02 +00:00
|
|
|
boolean bothceilingssky = false; // turned on if both back and front ceilings are sky
|
|
|
|
boolean bothfloorssky = false; // likewise, but for floors
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// indicates doors closed wrt automap bugfix:
|
|
|
|
INT32 doorclosed;
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_ClearDrawSegs
|
|
|
|
//
|
|
|
|
void R_ClearDrawSegs(void)
|
|
|
|
{
|
|
|
|
ds_p = drawsegs;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix from boom.
|
|
|
|
#define MAXSEGS (MAXVIDWIDTH/2+1)
|
|
|
|
|
|
|
|
// newend is one past the last valid seg
|
|
|
|
static cliprange_t *newend;
|
|
|
|
static cliprange_t solidsegs[MAXSEGS];
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_ClipSolidWallSegment
|
|
|
|
// Does handle solid walls,
|
|
|
|
// e.g. single sided LineDefs (middle texture)
|
|
|
|
// that entirely block the view.
|
|
|
|
//
|
|
|
|
static void R_ClipSolidWallSegment(INT32 first, INT32 last)
|
|
|
|
{
|
|
|
|
cliprange_t *next;
|
|
|
|
cliprange_t *start;
|
|
|
|
|
|
|
|
// Find the first range that touches the range (adjacent pixels are touching).
|
|
|
|
start = solidsegs;
|
|
|
|
while (start->last < first - 1)
|
|
|
|
start++;
|
|
|
|
|
|
|
|
if (first < start->first)
|
|
|
|
{
|
|
|
|
if (last < start->first - 1)
|
|
|
|
{
|
|
|
|
// Post is entirely visible (above start), so insert a new clippost.
|
|
|
|
R_StoreWallRange(first, last);
|
|
|
|
next = newend;
|
|
|
|
newend++;
|
|
|
|
// NO MORE CRASHING!
|
|
|
|
if (newend - solidsegs > MAXSEGS)
|
|
|
|
I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n");
|
|
|
|
|
|
|
|
while (next != start)
|
|
|
|
{
|
|
|
|
*next = *(next-1);
|
|
|
|
next--;
|
|
|
|
}
|
|
|
|
next->first = first;
|
|
|
|
next->last = last;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a fragment above *start.
|
|
|
|
R_StoreWallRange(first, start->first - 1);
|
|
|
|
// Now adjust the clip size.
|
|
|
|
start->first = first;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom contained in start?
|
|
|
|
if (last <= start->last)
|
|
|
|
return;
|
|
|
|
|
|
|
|
next = start;
|
|
|
|
while (last >= (next+1)->first - 1)
|
|
|
|
{
|
|
|
|
// There is a fragment between two posts.
|
|
|
|
R_StoreWallRange(next->last + 1, (next+1)->first - 1);
|
|
|
|
next++;
|
|
|
|
|
|
|
|
if (last <= next->last)
|
|
|
|
{
|
|
|
|
// Bottom is contained in next.
|
|
|
|
// Adjust the clip size.
|
|
|
|
start->last = next->last;
|
|
|
|
goto crunch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a fragment after *next.
|
|
|
|
R_StoreWallRange(next->last + 1, last);
|
|
|
|
// Adjust the clip size.
|
|
|
|
start->last = last;
|
|
|
|
|
|
|
|
// Remove start+1 to next from the clip list, because start now covers their area.
|
|
|
|
crunch:
|
|
|
|
if (next == start)
|
|
|
|
return; // Post just extended past the bottom of one post.
|
|
|
|
|
|
|
|
while (next++ != newend)
|
|
|
|
*++start = *next; // Remove a post.
|
|
|
|
|
|
|
|
newend = start + 1;
|
|
|
|
|
|
|
|
// NO MORE CRASHING!
|
|
|
|
if (newend - solidsegs > MAXSEGS)
|
|
|
|
I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_ClipPassWallSegment
|
|
|
|
// Clips the given range of columns, but does not include it in the clip list.
|
|
|
|
// Does handle windows, e.g. LineDefs with upper and lower texture.
|
|
|
|
//
|
|
|
|
static inline void R_ClipPassWallSegment(INT32 first, INT32 last)
|
|
|
|
{
|
|
|
|
cliprange_t *start;
|
|
|
|
|
|
|
|
// Find the first range that touches the range
|
|
|
|
// (adjacent pixels are touching).
|
|
|
|
start = solidsegs;
|
|
|
|
while (start->last < first - 1)
|
|
|
|
start++;
|
|
|
|
|
|
|
|
if (first < start->first)
|
|
|
|
{
|
|
|
|
if (last < start->first - 1)
|
|
|
|
{
|
|
|
|
// Post is entirely visible (above start).
|
|
|
|
R_StoreWallRange(first, last);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a fragment above *start.
|
|
|
|
R_StoreWallRange(first, start->first - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom contained in start?
|
|
|
|
if (last <= start->last)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (last >= (start+1)->first - 1)
|
|
|
|
{
|
|
|
|
// There is a fragment between two posts.
|
|
|
|
R_StoreWallRange(start->last + 1, (start+1)->first - 1);
|
|
|
|
start++;
|
|
|
|
|
|
|
|
if (last <= start->last)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a fragment after *next.
|
|
|
|
R_StoreWallRange(start->last + 1, last);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_ClearClipSegs
|
|
|
|
//
|
|
|
|
void R_ClearClipSegs(void)
|
|
|
|
{
|
|
|
|
solidsegs[0].first = -0x7fffffff;
|
|
|
|
solidsegs[0].last = -1;
|
|
|
|
solidsegs[1].first = viewwidth;
|
|
|
|
solidsegs[1].last = 0x7fffffff;
|
|
|
|
newend = solidsegs + 2;
|
|
|
|
}
|
2014-11-12 00:55:07 +00:00
|
|
|
void R_PortalClearClipSegs(INT32 start, INT32 end)
|
|
|
|
{
|
|
|
|
solidsegs[0].first = -0x7fffffff;
|
|
|
|
solidsegs[0].last = start-1;
|
|
|
|
solidsegs[1].first = end;
|
|
|
|
solidsegs[1].last = 0x7fffffff;
|
|
|
|
newend = solidsegs + 2;
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// R_DoorClosed
|
|
|
|
//
|
|
|
|
// This function is used to fix the automap bug which
|
|
|
|
// showed lines behind closed doors simply because the door had a dropoff.
|
|
|
|
//
|
|
|
|
// It assumes that Doom has already ruled out a door being closed because
|
|
|
|
// of front-back closure (e.g. front floor is taller than back ceiling).
|
2017-01-10 20:07:02 +00:00
|
|
|
static INT32 R_DoorClosed(void)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
return
|
|
|
|
|
|
|
|
// if door is closed because back is shut:
|
|
|
|
backsector->ceilingheight <= backsector->floorheight
|
|
|
|
|
|
|
|
// preserve a kind of transparent door/lift special effect:
|
|
|
|
&& (backsector->ceilingheight >= frontsector->ceilingheight || curline->sidedef->toptexture)
|
|
|
|
|
2018-02-03 18:30:49 +00:00
|
|
|
&& (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If player's view height is underneath fake floor, lower the
|
|
|
|
// drawn ceiling to be just under the floor height, and replace
|
|
|
|
// the drawn floor and ceiling textures, and light level, with
|
|
|
|
// the control sector's.
|
|
|
|
//
|
|
|
|
// Similar for ceiling, only reflected.
|
|
|
|
//
|
|
|
|
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
|
|
|
|
INT32 *ceilinglightlevel, boolean back)
|
|
|
|
{
|
|
|
|
if (floorlightlevel)
|
|
|
|
*floorlightlevel = sec->floorlightsec == -1 ?
|
2021-09-19 06:58:21 +00:00
|
|
|
(sec->floorlightabsolute ? sec->floorlightlevel : max(0, min(255, sec->lightlevel + sec->floorlightlevel))) : sectors[sec->floorlightsec].lightlevel;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (ceilinglightlevel)
|
|
|
|
*ceilinglightlevel = sec->ceilinglightsec == -1 ?
|
2021-09-19 06:58:21 +00:00
|
|
|
(sec->ceilinglightabsolute ? sec->ceilinglightlevel : max(0, min(255, sec->lightlevel + sec->ceilinglightlevel))) : sectors[sec->ceilinglightsec].lightlevel;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-09-10 20:16:04 +00:00
|
|
|
// if (sec->midmap != -1)
|
|
|
|
// mapnum = sec->midmap;
|
|
|
|
// In original colormap code, this block did not run if sec->midmap was set
|
|
|
|
if (!sec->extra_colormap && sec->heightsec != -1)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
const sector_t *s = §ors[sec->heightsec];
|
|
|
|
mobj_t *viewmobj = viewplayer->mo;
|
|
|
|
INT32 heightsec;
|
|
|
|
boolean underwater;
|
|
|
|
|
|
|
|
if (splitscreen && viewplayer == &players[secondarydisplayplayer] && camera2.chase)
|
|
|
|
heightsec = R_PointInSubsector(camera2.x, camera2.y)->sector->heightsec;
|
|
|
|
else if (camera.chase && viewplayer == &players[displayplayer])
|
|
|
|
heightsec = R_PointInSubsector(camera.x, camera.y)->sector->heightsec;
|
|
|
|
else if (viewmobj)
|
|
|
|
heightsec = R_PointInSubsector(viewmobj->x, viewmobj->y)->sector->heightsec;
|
|
|
|
else
|
|
|
|
return sec;
|
|
|
|
underwater = heightsec != -1 && viewz <= sectors[heightsec].floorheight;
|
|
|
|
|
|
|
|
// Replace sector being drawn, with a copy to be hacked
|
|
|
|
*tempsec = *sec;
|
|
|
|
|
|
|
|
// Replace floor and ceiling height with other sector's heights.
|
|
|
|
tempsec->floorheight = s->floorheight;
|
|
|
|
tempsec->ceilingheight = s->ceilingheight;
|
|
|
|
|
|
|
|
if ((underwater && (tempsec-> floorheight = sec->floorheight,
|
|
|
|
tempsec->ceilingheight = s->floorheight - 1, !back)) || viewz <= s->floorheight)
|
|
|
|
{ // head-below-floor hack
|
|
|
|
tempsec->floorpic = s->floorpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->floorxoffset = s->floorxoffset;
|
|
|
|
tempsec->flooryoffset = s->flooryoffset;
|
|
|
|
tempsec->floorangle = s->floorangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (underwater)
|
|
|
|
{
|
|
|
|
if (s->ceilingpic == skyflatnum)
|
|
|
|
{
|
|
|
|
tempsec->floorheight = tempsec->ceilingheight+1;
|
|
|
|
tempsec->ceilingpic = tempsec->floorpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->ceilingxoffset = tempsec->floorxoffset;
|
|
|
|
tempsec->ceilingyoffset = tempsec->flooryoffset;
|
|
|
|
tempsec->ceilingangle = tempsec->floorangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempsec->ceilingpic = s->ceilingpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->ceilingxoffset = s->ceilingxoffset;
|
|
|
|
tempsec->ceilingyoffset = s->ceilingyoffset;
|
|
|
|
tempsec->ceilingangle = s->ceilingangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempsec->lightlevel = s->lightlevel;
|
|
|
|
|
|
|
|
if (floorlightlevel)
|
2021-09-19 06:58:21 +00:00
|
|
|
*floorlightlevel = s->floorlightsec == -1 ? (s->floorlightabsolute ? s->floorlightlevel : max(0, min(255, s->lightlevel + s->floorlightlevel)))
|
2014-03-15 16:59:03 +00:00
|
|
|
: sectors[s->floorlightsec].lightlevel;
|
|
|
|
|
|
|
|
if (ceilinglightlevel)
|
2021-09-19 06:58:21 +00:00
|
|
|
*ceilinglightlevel = s->ceilinglightsec == -1 ? (s->ceilinglightabsolute ? s->ceilinglightlevel : max(0, min(255, s->lightlevel + s->ceilinglightlevel)))
|
2014-03-15 16:59:03 +00:00
|
|
|
: sectors[s->ceilinglightsec].lightlevel;
|
|
|
|
}
|
|
|
|
else if (heightsec != -1 && viewz >= sectors[heightsec].ceilingheight
|
|
|
|
&& sec->ceilingheight > s->ceilingheight)
|
|
|
|
{ // Above-ceiling hack
|
|
|
|
tempsec->ceilingheight = s->ceilingheight;
|
|
|
|
tempsec->floorheight = s->ceilingheight + 1;
|
|
|
|
|
|
|
|
tempsec->floorpic = tempsec->ceilingpic = s->ceilingpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->floorxoffset = tempsec->ceilingxoffset = s->ceilingxoffset;
|
|
|
|
tempsec->flooryoffset = tempsec->ceilingyoffset = s->ceilingyoffset;
|
|
|
|
tempsec->floorangle = tempsec->ceilingangle = s->ceilingangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (s->floorpic == skyflatnum) // SKYFIX?
|
|
|
|
{
|
|
|
|
tempsec->ceilingheight = tempsec->floorheight-1;
|
|
|
|
tempsec->floorpic = tempsec->ceilingpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->floorxoffset = tempsec->ceilingxoffset;
|
|
|
|
tempsec->flooryoffset = tempsec->ceilingyoffset;
|
|
|
|
tempsec->floorangle = tempsec->ceilingangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempsec->ceilingheight = sec->ceilingheight;
|
|
|
|
tempsec->floorpic = s->floorpic;
|
2022-11-25 23:01:27 +00:00
|
|
|
tempsec->floorxoffset = s->floorxoffset;
|
|
|
|
tempsec->flooryoffset = s->flooryoffset;
|
|
|
|
tempsec->floorangle = s->floorangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tempsec->lightlevel = s->lightlevel;
|
|
|
|
|
|
|
|
if (floorlightlevel)
|
2021-09-19 06:58:21 +00:00
|
|
|
*floorlightlevel = s->floorlightsec == -1 ? (s->floorlightabsolute ? s->floorlightlevel : max(0, min(255, s->lightlevel + s->floorlightlevel)))
|
|
|
|
: sectors[s->floorlightsec].lightlevel;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (ceilinglightlevel)
|
2021-09-19 06:58:21 +00:00
|
|
|
*ceilinglightlevel = s->ceilinglightsec == -1 ? (s->ceilinglightabsolute ? s->ceilinglightlevel : max(0, min(255, s->lightlevel + s->ceilinglightlevel)))
|
|
|
|
: sectors[s->ceilinglightsec].lightlevel;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
sec = tempsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
|
2017-01-10 20:07:02 +00:00
|
|
|
boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back)
|
|
|
|
{
|
2023-08-23 18:46:48 +00:00
|
|
|
if (P_SectorHasPortal(front) && !P_SectorHasPortal(back))
|
|
|
|
return false;
|
|
|
|
else if (!P_SectorHasPortal(front) && P_SectorHasPortal(back))
|
|
|
|
return false;
|
|
|
|
|
2017-01-10 20:07:02 +00:00
|
|
|
return (
|
|
|
|
!line->polyseg &&
|
|
|
|
back->ceilingpic == front->ceilingpic
|
|
|
|
&& back->floorpic == front->floorpic
|
|
|
|
&& back->f_slope == front->f_slope
|
|
|
|
&& back->c_slope == front->c_slope
|
|
|
|
&& back->lightlevel == front->lightlevel
|
|
|
|
&& !line->sidedef->midtexture
|
|
|
|
// Check offsets too!
|
2022-11-25 23:01:27 +00:00
|
|
|
&& back->floorxoffset == front->floorxoffset
|
|
|
|
&& back->flooryoffset == front->flooryoffset
|
|
|
|
&& back->floorangle == front->floorangle
|
|
|
|
&& back->ceilingxoffset == front->ceilingxoffset
|
|
|
|
&& back->ceilingyoffset == front->ceilingyoffset
|
|
|
|
&& back->ceilingangle == front->ceilingangle
|
2017-01-10 20:07:02 +00:00
|
|
|
// Consider altered lighting.
|
2021-09-19 06:58:21 +00:00
|
|
|
&& back->floorlightlevel == front->floorlightlevel
|
|
|
|
&& back->floorlightabsolute == front->floorlightabsolute
|
|
|
|
&& back->ceilinglightlevel == front->ceilinglightlevel
|
|
|
|
&& back->ceilinglightabsolute == front->ceilinglightabsolute
|
2017-01-10 20:07:02 +00:00
|
|
|
&& back->floorlightsec == front->floorlightsec
|
|
|
|
&& back->ceilinglightsec == front->ceilinglightsec
|
|
|
|
// Consider colormaps
|
|
|
|
&& back->extra_colormap == front->extra_colormap
|
|
|
|
&& ((!front->ffloors && !back->ffloors)
|
2020-04-12 13:03:14 +00:00
|
|
|
|| Tag_Compare(&front->tags, &back->tags)));
|
2017-01-10 20:07:02 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// R_AddLine
|
|
|
|
// Clips the given segment and adds any visible pieces to the line list.
|
|
|
|
//
|
|
|
|
static void R_AddLine(seg_t *line)
|
|
|
|
{
|
|
|
|
INT32 x1, x2;
|
|
|
|
angle_t angle1, angle2, span, tspan;
|
2018-12-09 22:34:17 +00:00
|
|
|
static sector_t tempsec;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
portalline = false;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES))
|
|
|
|
return;
|
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
// big room fix
|
2022-12-27 19:31:55 +00:00
|
|
|
angle1 = R_PointToAngle64(line->v1->x, line->v1->y);
|
|
|
|
angle2 = R_PointToAngle64(line->v2->x, line->v2->y);
|
2014-03-15 16:59:03 +00:00
|
|
|
curline = line;
|
|
|
|
|
|
|
|
// Clip to view edges.
|
|
|
|
span = angle1 - angle2;
|
|
|
|
|
|
|
|
// Back side? i.e. backface culling?
|
|
|
|
if (span >= ANGLE_180)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Global angle needed by segcalc.
|
|
|
|
rw_angle1 = angle1;
|
|
|
|
angle1 -= viewangle;
|
|
|
|
angle2 -= viewangle;
|
|
|
|
|
|
|
|
tspan = angle1 + clipangle;
|
|
|
|
if (tspan > doubleclipangle)
|
|
|
|
{
|
|
|
|
tspan -= doubleclipangle;
|
|
|
|
|
|
|
|
// Totally off the left edge?
|
|
|
|
if (tspan >= span)
|
|
|
|
return;
|
|
|
|
|
|
|
|
angle1 = clipangle;
|
|
|
|
}
|
|
|
|
tspan = clipangle - angle2;
|
|
|
|
if (tspan > doubleclipangle)
|
|
|
|
{
|
|
|
|
tspan -= doubleclipangle;
|
|
|
|
|
|
|
|
// Totally off the left edge?
|
|
|
|
if (tspan >= span)
|
|
|
|
return;
|
|
|
|
|
|
|
|
angle2 = -(signed)clipangle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The seg is in the view range, but not necessarily visible.
|
|
|
|
angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT;
|
|
|
|
angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT;
|
|
|
|
x1 = viewangletox[angle1];
|
|
|
|
x2 = viewangletox[angle2];
|
|
|
|
|
|
|
|
// Does not cross a pixel?
|
|
|
|
if (x1 >= x2) // killough 1/31/98 -- change == to >= for robustness
|
|
|
|
return;
|
|
|
|
|
|
|
|
backsector = line->backsector;
|
|
|
|
|
|
|
|
// Portal line
|
2016-02-06 18:57:26 +00:00
|
|
|
if (line->linedef->special == 40 && line->side == 0)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2020-04-15 08:05:59 +00:00
|
|
|
// Render portal if recursiveness limit hasn't been reached.
|
|
|
|
// Otherwise, render the wall normally.
|
2014-11-12 00:55:07 +00:00
|
|
|
if (portalrender < cv_maxportals.value)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2020-04-15 08:05:59 +00:00
|
|
|
size_t p;
|
2020-04-17 08:34:24 +00:00
|
|
|
mtag_t tag = Tag_FGet(&line->linedef->tags);
|
2020-04-15 08:05:59 +00:00
|
|
|
INT32 li1 = line->linedef-lines;
|
|
|
|
INT32 li2;
|
|
|
|
|
|
|
|
for (p = 0; (li2 = Tag_Iterate_Lines(tag, p)) >= 0; p++)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2020-04-15 08:05:59 +00:00
|
|
|
// Skip invalid lines.
|
2020-04-17 08:34:24 +00:00
|
|
|
if ((tag != Tag_FGet(&lines[li2].tags)) || (lines[li1].special != lines[li2].special) || (li1 == li2))
|
2020-04-15 08:05:59 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Portal_Add2Lines(li1, li2, x1, x2);
|
2014-11-12 00:55:07 +00:00
|
|
|
goto clipsolid;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Single sided line?
|
|
|
|
if (!backsector)
|
|
|
|
goto clipsolid;
|
|
|
|
|
|
|
|
backsector = R_FakeFlat(backsector, &tempsec, NULL, NULL, true);
|
|
|
|
|
|
|
|
doorclosed = 0;
|
2023-08-23 16:43:02 +00:00
|
|
|
bothceilingssky = bothfloorssky = false;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2023-08-23 16:43:02 +00:00
|
|
|
// hack to allow height changes in outdoor areas
|
|
|
|
// This is what gets rid of the upper textures if there should be sky
|
|
|
|
if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum
|
2023-08-23 18:04:50 +00:00
|
|
|
&& !(P_SectorHasCeilingPortal(backsector) || P_SectorHasCeilingPortal(frontsector)))
|
2018-02-07 17:46:01 +00:00
|
|
|
bothceilingssky = true;
|
2023-08-23 16:43:02 +00:00
|
|
|
|
|
|
|
// likewise, but for floors and upper textures
|
|
|
|
if (backsector->floorpic == skyflatnum && frontsector->floorpic == skyflatnum
|
2023-08-23 18:04:50 +00:00
|
|
|
&& !(P_SectorHasFloorPortal(backsector) || P_SectorHasFloorPortal(frontsector)))
|
2018-02-07 17:46:01 +00:00
|
|
|
bothfloorssky = true;
|
|
|
|
|
|
|
|
if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then
|
|
|
|
{
|
2020-05-02 10:08:31 +00:00
|
|
|
if (!line->polyseg &&
|
|
|
|
!line->sidedef->midtexture
|
|
|
|
&& ((!frontsector->ffloors && !backsector->ffloors)
|
2020-07-10 14:51:11 +00:00
|
|
|
|| Tag_Compare(&frontsector->tags, &backsector->tags)))
|
2018-02-07 17:46:01 +00:00
|
|
|
return; // line is empty, don't even bother
|
|
|
|
|
|
|
|
goto clippass; // treat like wide open window instead
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Closed door.
|
2016-03-18 23:58:58 +00:00
|
|
|
if (frontsector->f_slope || frontsector->c_slope || backsector->f_slope || backsector->c_slope)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2016-03-18 23:58:58 +00:00
|
|
|
fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends
|
|
|
|
fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends
|
|
|
|
#define SLOPEPARAMS(slope, end1, end2, normalheight) \
|
2020-05-18 13:23:56 +00:00
|
|
|
end1 = P_GetZAt(slope, line->v1->x, line->v1->y, normalheight); \
|
|
|
|
end2 = P_GetZAt(slope, line->v2->x, line->v2->y, normalheight);
|
2016-03-18 23:58:58 +00:00
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
SLOPEPARAMS(frontsector->f_slope, frontf1, frontf2, frontsector-> floorheight)
|
2016-03-18 23:58:58 +00:00
|
|
|
SLOPEPARAMS(frontsector->c_slope, frontc1, frontc2, frontsector->ceilingheight)
|
2020-03-22 14:17:16 +00:00
|
|
|
SLOPEPARAMS( backsector->f_slope, backf1, backf2, backsector-> floorheight)
|
|
|
|
SLOPEPARAMS( backsector->c_slope, backc1, backc2, backsector->ceilingheight)
|
2016-03-18 23:58:58 +00:00
|
|
|
#undef SLOPEPARAMS
|
2018-01-28 22:08:58 +00:00
|
|
|
// if both ceilings are skies, consider it always "open"
|
2018-02-03 19:48:18 +00:00
|
|
|
// same for floors
|
2018-02-07 17:46:01 +00:00
|
|
|
if (!bothceilingssky && !bothfloorssky)
|
2016-03-18 23:58:58 +00:00
|
|
|
{
|
2018-01-28 22:08:58 +00:00
|
|
|
if ((backc1 <= frontf1 && backc2 <= frontf2)
|
|
|
|
|| (backf1 >= frontc1 && backf2 >= frontc2))
|
|
|
|
{
|
|
|
|
goto clipsolid;
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-01-28 22:08:58 +00:00
|
|
|
// Check for automap fix. Store in doorclosed for r_segs.c
|
|
|
|
doorclosed = (backc1 <= backf1 && backc2 <= backf2
|
|
|
|
&& ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture)
|
2018-02-03 18:30:49 +00:00
|
|
|
&& ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture));
|
2016-03-18 23:58:58 +00:00
|
|
|
|
2018-01-28 22:08:58 +00:00
|
|
|
if (doorclosed)
|
|
|
|
goto clipsolid;
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2016-03-18 23:58:58 +00:00
|
|
|
// Window.
|
2018-02-07 17:46:01 +00:00
|
|
|
if (!bothceilingssky) // ceilings are always the "same" when sky
|
|
|
|
if (backc1 != frontc1 || backc2 != frontc2)
|
|
|
|
goto clippass;
|
|
|
|
if (!bothfloorssky) // floors are always the "same" when sky
|
|
|
|
if (backf1 != frontf1 || backf2 != frontf2)
|
|
|
|
goto clippass;
|
2016-03-18 23:58:58 +00:00
|
|
|
}
|
|
|
|
else
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-01-28 22:08:58 +00:00
|
|
|
// if both ceilings are skies, consider it always "open"
|
2018-02-03 19:48:18 +00:00
|
|
|
// same for floors
|
2018-02-07 17:46:01 +00:00
|
|
|
if (!bothceilingssky && !bothfloorssky)
|
2016-03-18 23:58:58 +00:00
|
|
|
{
|
2018-01-28 22:08:58 +00:00
|
|
|
if (backsector->ceilingheight <= frontsector->floorheight
|
|
|
|
|| backsector->floorheight >= frontsector->ceilingheight)
|
|
|
|
{
|
|
|
|
goto clipsolid;
|
|
|
|
}
|
2016-03-18 23:58:58 +00:00
|
|
|
|
2018-01-28 22:08:58 +00:00
|
|
|
// Check for automap fix. Store in doorclosed for r_segs.c
|
|
|
|
doorclosed = R_DoorClosed();
|
|
|
|
if (doorclosed)
|
|
|
|
goto clipsolid;
|
|
|
|
}
|
2016-03-18 23:58:58 +00:00
|
|
|
|
|
|
|
// Window.
|
2018-02-07 17:46:01 +00:00
|
|
|
if (!bothceilingssky) // ceilings are always the "same" when sky
|
|
|
|
if (backsector->ceilingheight != frontsector->ceilingheight)
|
|
|
|
goto clippass;
|
|
|
|
if (!bothfloorssky) // floors are always the "same" when sky
|
|
|
|
if (backsector->floorheight != frontsector->floorheight)
|
|
|
|
goto clippass;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reject empty lines used for triggers and special events.
|
|
|
|
// Identical floor and ceiling on both sides, identical light levels on both sides,
|
|
|
|
// and no middle texture.
|
2017-01-10 20:07:02 +00:00
|
|
|
if (R_IsEmptyLine(line, frontsector, backsector))
|
2014-03-15 16:59:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
clippass:
|
|
|
|
R_ClipPassWallSegment(x1, x2 - 1);
|
|
|
|
return;
|
|
|
|
|
|
|
|
clipsolid:
|
|
|
|
R_ClipSolidWallSegment(x1, x2 - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_CheckBBox
|
|
|
|
// Checks BSP node/subtree bounding box.
|
|
|
|
// Returns true if some part of the bbox might be visible.
|
|
|
|
//
|
|
|
|
// | 0 | 1 | 2
|
|
|
|
// --+---+---+---
|
|
|
|
// 0 | 0 | 1 | 2
|
|
|
|
// 1 | 4 | 5 | 6
|
|
|
|
// 2 | 8 | 9 | A
|
|
|
|
INT32 checkcoord[12][4] =
|
|
|
|
{
|
|
|
|
{3, 0, 2, 1},
|
|
|
|
{3, 0, 2, 0},
|
|
|
|
{3, 1, 2, 0},
|
|
|
|
{0}, // UNUSED
|
|
|
|
{2, 0, 2, 1},
|
|
|
|
{0}, // UNUSED
|
|
|
|
{3, 1, 3, 0},
|
|
|
|
{0}, // UNUSED
|
|
|
|
{2, 0, 3, 1},
|
|
|
|
{2, 1, 3, 1},
|
|
|
|
{2, 1, 3, 0}
|
|
|
|
};
|
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
static boolean R_CheckBBox(const fixed_t *bspcoord)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-12-09 22:34:17 +00:00
|
|
|
angle_t angle1, angle2;
|
|
|
|
INT32 sx1, sx2, boxpos;
|
|
|
|
const INT32* check;
|
2014-03-15 16:59:03 +00:00
|
|
|
cliprange_t *start;
|
|
|
|
|
|
|
|
// Find the corners of the box that define the edges from current viewpoint.
|
2018-12-09 22:34:17 +00:00
|
|
|
if ((boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT] ? 1 : 2) + (viewy >= bspcoord[BOXTOP] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8)) == 5)
|
2014-03-15 16:59:03 +00:00
|
|
|
return true;
|
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
check = checkcoord[boxpos];
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
// big room fix
|
2022-12-27 19:31:55 +00:00
|
|
|
angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle;
|
|
|
|
angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
if ((signed)angle1 < (signed)angle2)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2018-12-09 22:34:17 +00:00
|
|
|
if ((angle1 >= ANGLE_180) && (angle1 < ANGLE_270))
|
|
|
|
angle1 = ANGLE_180-1;
|
|
|
|
else
|
2018-12-25 06:14:05 +00:00
|
|
|
angle2 = ANGLE_180;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 22:34:17 +00:00
|
|
|
if ((signed)angle2 >= (signed)clipangle) return false;
|
|
|
|
if ((signed)angle1 <= -(signed)clipangle) return false;
|
|
|
|
if ((signed)angle1 >= (signed)clipangle) angle1 = clipangle;
|
|
|
|
if ((signed)angle2 <= -(signed)clipangle) angle2 = 0-clipangle;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// Find the first clippost that touches the source post (adjacent pixels are touching).
|
|
|
|
angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT;
|
|
|
|
angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT;
|
|
|
|
sx1 = viewangletox[angle1];
|
|
|
|
sx2 = viewangletox[angle2];
|
|
|
|
|
|
|
|
// Does not cross a pixel.
|
2018-12-09 22:34:17 +00:00
|
|
|
if (sx1 >= sx2) return false;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
start = solidsegs;
|
|
|
|
while (start->last < sx2)
|
|
|
|
start++;
|
|
|
|
|
|
|
|
if (sx1 >= start->first && sx2 <= start->last)
|
|
|
|
return false; // The clippost contains the new span.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t numpolys; // number of polyobjects in current subsector
|
|
|
|
size_t num_po_ptrs; // number of polyobject pointers allocated
|
|
|
|
polyobj_t **po_ptrs; // temp ptr array to sort polyobject pointers
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_PolyobjCompare
|
|
|
|
//
|
|
|
|
// Callback for qsort that compares the z distance of two polyobjects.
|
|
|
|
// Returns the difference such that the closer polyobject will be
|
|
|
|
// sorted first.
|
|
|
|
//
|
|
|
|
static int R_PolyobjCompare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const polyobj_t *po1 = *(const polyobj_t * const *)p1;
|
|
|
|
const polyobj_t *po2 = *(const polyobj_t * const *)p2;
|
|
|
|
|
|
|
|
return po1->zdist - po2->zdist;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_SortPolyObjects
|
|
|
|
//
|
|
|
|
// haleyjd 03/03/06: Here's the REAL meat of Eternity's polyobject system.
|
|
|
|
// Hexen just figured this was impossible, but as mentioned in polyobj.c,
|
|
|
|
// it is perfectly doable within the confines of the BSP tree. Polyobjects
|
|
|
|
// must be sorted to draw in DOOM's front-to-back order within individual
|
|
|
|
// subsectors. This is a modified version of R_SortVisSprites.
|
|
|
|
//
|
|
|
|
void R_SortPolyObjects(subsector_t *sub)
|
|
|
|
{
|
|
|
|
if (numpolys)
|
|
|
|
{
|
|
|
|
polyobj_t *po;
|
|
|
|
INT32 i = 0;
|
|
|
|
|
|
|
|
// allocate twice the number needed to minimize allocations
|
|
|
|
if (num_po_ptrs < numpolys*2)
|
|
|
|
{
|
|
|
|
// use free instead realloc since faster (thanks Lee ^_^)
|
|
|
|
free(po_ptrs);
|
|
|
|
po_ptrs = malloc((num_po_ptrs = numpolys*2)
|
|
|
|
* sizeof(*po_ptrs));
|
|
|
|
}
|
|
|
|
|
|
|
|
po = sub->polyList;
|
|
|
|
|
|
|
|
while (po)
|
|
|
|
{
|
|
|
|
po->zdist = R_PointToDist2(viewx, viewy,
|
|
|
|
po->centerPt.x, po->centerPt.y);
|
|
|
|
po_ptrs[i++] = po;
|
|
|
|
po = (polyobj_t *)(po->link.next);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the polyobjects are NOT in any particular order, so use qsort
|
|
|
|
// 03/10/06: only bother if there are actually polys to sort
|
|
|
|
if (numpolys >= 2)
|
|
|
|
{
|
|
|
|
qsort(po_ptrs, numpolys, sizeof(polyobj_t *),
|
|
|
|
R_PolyobjCompare);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 00:55:07 +00:00
|
|
|
//
|
|
|
|
// R_PolysegCompare
|
|
|
|
//
|
|
|
|
// Callback for qsort to sort the segs of a polyobject. Returns such that the
|
|
|
|
// closer one is sorted first. I sure hope this doesn't break anything. -Red
|
|
|
|
//
|
|
|
|
static int R_PolysegCompare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const seg_t *seg1 = *(const seg_t * const *)p1;
|
|
|
|
const seg_t *seg2 = *(const seg_t * const *)p2;
|
2015-01-01 19:50:31 +00:00
|
|
|
fixed_t dist1v1, dist1v2, dist2v1, dist2v2;
|
2014-11-12 00:55:07 +00:00
|
|
|
|
|
|
|
// TODO might be a better way to get distance?
|
2015-01-01 19:50:31 +00:00
|
|
|
#define pdist(x, y) (FixedMul(R_PointToDist(x, y), FINECOSINE((R_PointToAngle(x, y)-viewangle)>>ANGLETOFINESHIFT))+0xFFFFFFF)
|
|
|
|
#define vxdist(v) pdist(v->x, v->y)
|
2014-11-12 00:55:07 +00:00
|
|
|
|
2015-01-01 19:50:31 +00:00
|
|
|
dist1v1 = vxdist(seg1->v1);
|
|
|
|
dist1v2 = vxdist(seg1->v2);
|
|
|
|
dist2v1 = vxdist(seg2->v1);
|
|
|
|
dist2v2 = vxdist(seg2->v2);
|
2014-11-12 00:55:07 +00:00
|
|
|
|
2015-01-01 19:50:31 +00:00
|
|
|
if (min(dist1v1, dist1v2) != min(dist2v1, dist2v2))
|
|
|
|
return min(dist1v1, dist1v2) - min(dist2v1, dist2v2);
|
|
|
|
|
|
|
|
{ // That didn't work, so now let's try this.......
|
|
|
|
fixed_t delta1, delta2, x1, y1, x2, y2;
|
|
|
|
vertex_t *near1, *near2, *far1, *far2; // wherever you are~
|
|
|
|
|
|
|
|
delta1 = R_PointToDist2(seg1->v1->x, seg1->v1->y, seg1->v2->x, seg1->v2->y);
|
|
|
|
delta2 = R_PointToDist2(seg2->v1->x, seg2->v1->y, seg2->v2->x, seg2->v2->y);
|
|
|
|
|
|
|
|
delta1 = FixedDiv(128<<FRACBITS, delta1);
|
|
|
|
delta2 = FixedDiv(128<<FRACBITS, delta2);
|
|
|
|
|
|
|
|
if (dist1v1 < dist1v2)
|
|
|
|
{
|
|
|
|
near1 = seg1->v1;
|
|
|
|
far1 = seg1->v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
near1 = seg1->v2;
|
|
|
|
far1 = seg1->v1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dist2v1 < dist2v2)
|
|
|
|
{
|
|
|
|
near2 = seg2->v1;
|
|
|
|
far2 = seg2->v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
near2 = seg2->v2;
|
|
|
|
far2 = seg2->v1;
|
|
|
|
}
|
|
|
|
|
|
|
|
x1 = near1->x + FixedMul(far1->x-near1->x, delta1);
|
|
|
|
y1 = near1->y + FixedMul(far1->y-near1->y, delta1);
|
|
|
|
|
|
|
|
x2 = near2->x + FixedMul(far2->x-near2->x, delta2);
|
|
|
|
y2 = near2->y + FixedMul(far2->y-near2->y, delta2);
|
|
|
|
|
|
|
|
return pdist(x1, y1)-pdist(x2, y2);
|
2014-11-12 00:55:07 +00:00
|
|
|
}
|
|
|
|
#undef vxdist
|
2015-01-01 19:50:31 +00:00
|
|
|
#undef pdist
|
2014-11-12 00:55:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// R_AddPolyObjects
|
|
|
|
//
|
|
|
|
// haleyjd 02/19/06
|
|
|
|
// Adds all segs in all polyobjects in the given subsector.
|
|
|
|
//
|
|
|
|
static void R_AddPolyObjects(subsector_t *sub)
|
|
|
|
{
|
|
|
|
polyobj_t *po = sub->polyList;
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
numpolys = 0;
|
|
|
|
|
|
|
|
// count polyobjects
|
|
|
|
while (po)
|
|
|
|
{
|
|
|
|
++numpolys;
|
|
|
|
po = (polyobj_t *)(po->link.next);
|
|
|
|
}
|
|
|
|
|
2020-05-02 17:43:53 +00:00
|
|
|
// for render stats
|
2021-10-25 17:49:15 +00:00
|
|
|
ps_numpolyobjects.value.i += numpolys;
|
2020-05-02 17:43:53 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// sort polyobjects
|
|
|
|
R_SortPolyObjects(sub);
|
|
|
|
|
|
|
|
// render polyobjects
|
|
|
|
for (i = 0; i < numpolys; ++i)
|
|
|
|
{
|
2014-11-12 00:55:07 +00:00
|
|
|
qsort(po_ptrs[i]->segs, po_ptrs[i]->segCount, sizeof(seg_t *), R_PolysegCompare);
|
2014-03-15 16:59:03 +00:00
|
|
|
for (j = 0; j < po_ptrs[i]->segCount; ++j)
|
|
|
|
R_AddLine(po_ptrs[i]->segs[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_Subsector
|
|
|
|
// Determine floor/ceiling planes.
|
|
|
|
// Add sprites of things in sector.
|
|
|
|
// Draw one or more line segments.
|
|
|
|
//
|
|
|
|
|
|
|
|
drawseg_t *firstseg;
|
|
|
|
|
|
|
|
static void R_Subsector(size_t num)
|
|
|
|
{
|
|
|
|
INT32 count, floorlightlevel, ceilinglightlevel, light;
|
|
|
|
seg_t *line;
|
|
|
|
subsector_t *sub;
|
|
|
|
static sector_t tempsec; // Deep water hack
|
|
|
|
extracolormap_t *floorcolormap;
|
|
|
|
extracolormap_t *ceilingcolormap;
|
2016-10-09 19:55:04 +00:00
|
|
|
fixed_t floorcenterz, ceilingcenterz;
|
2022-04-25 18:16:41 +00:00
|
|
|
ffloor_t *rover;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#ifdef RANGECHECK
|
|
|
|
if (num >= numsubsectors)
|
|
|
|
I_Error("R_Subsector: ss %s with numss = %s\n", sizeu1(num), sizeu2(numsubsectors));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// subsectors added at run-time
|
|
|
|
if (num >= numsubsectors)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sub = &subsectors[num];
|
|
|
|
frontsector = sub->sector;
|
|
|
|
count = sub->numlines;
|
|
|
|
line = &segs[sub->firstline];
|
|
|
|
|
|
|
|
// Deep water/fake ceiling effect.
|
|
|
|
frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false);
|
|
|
|
|
|
|
|
floorcolormap = ceilingcolormap = frontsector->extra_colormap;
|
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
floorcenterz = P_GetSectorFloorZAt (frontsector, frontsector->soundorg.x, frontsector->soundorg.y);
|
|
|
|
ceilingcenterz = P_GetSectorCeilingZAt(frontsector, frontsector->soundorg.x, frontsector->soundorg.y);
|
2016-10-09 19:55:04 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// Check and prep all 3D floors. Set the sector floor/ceiling light levels and colormaps.
|
|
|
|
if (frontsector->ffloors)
|
|
|
|
{
|
2022-04-25 18:16:41 +00:00
|
|
|
boolean anyMoved = frontsector->moved;
|
|
|
|
|
|
|
|
if (anyMoved == false)
|
|
|
|
{
|
|
|
|
for (rover = frontsector->ffloors; rover; rover = rover->next)
|
|
|
|
{
|
|
|
|
sector_t *controlSec = §ors[rover->secnum];
|
|
|
|
|
|
|
|
if (controlSec->moved == true)
|
|
|
|
{
|
|
|
|
anyMoved = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anyMoved == true)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
frontsector->numlights = sub->sector->numlights = 0;
|
|
|
|
R_Prep3DFloors(frontsector);
|
|
|
|
sub->sector->lightlist = frontsector->lightlist;
|
|
|
|
sub->sector->numlights = frontsector->numlights;
|
|
|
|
sub->sector->moved = frontsector->moved = false;
|
|
|
|
}
|
|
|
|
|
2016-10-09 19:55:04 +00:00
|
|
|
light = R_GetPlaneLight(frontsector, floorcenterz, false);
|
2021-09-19 06:58:21 +00:00
|
|
|
if (frontsector->floorlightsec == -1 && !frontsector->floorlightabsolute)
|
|
|
|
floorlightlevel = max(0, min(255, *frontsector->lightlist[light].lightlevel + frontsector->floorlightlevel));
|
2018-09-12 20:06:56 +00:00
|
|
|
floorcolormap = *frontsector->lightlist[light].extra_colormap;
|
2016-10-09 19:55:04 +00:00
|
|
|
light = R_GetPlaneLight(frontsector, ceilingcenterz, false);
|
2021-09-19 06:58:21 +00:00
|
|
|
if (frontsector->ceilinglightsec == -1 && !frontsector->ceilinglightabsolute)
|
|
|
|
ceilinglightlevel = max(0, min(255, *frontsector->lightlist[light].lightlevel + frontsector->ceilinglightlevel));
|
2018-09-12 20:06:56 +00:00
|
|
|
ceilingcolormap = *frontsector->lightlist[light].extra_colormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub->sector->extra_colormap = frontsector->extra_colormap;
|
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
if (P_GetSectorFloorZAt(frontsector, viewx, viewy) < viewz
|
2020-03-20 17:55:29 +00:00
|
|
|
|| frontsector->floorpic == skyflatnum
|
2023-08-23 18:46:48 +00:00
|
|
|
|| P_SectorHasFloorPortal(frontsector)
|
2020-03-20 17:55:29 +00:00
|
|
|
|| (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2021-04-05 14:23:21 +00:00
|
|
|
floorplane = R_FindPlane(frontsector, frontsector->floorheight, frontsector->floorpic, floorlightlevel,
|
2023-08-23 18:04:50 +00:00
|
|
|
frontsector->floorxoffset, frontsector->flooryoffset, frontsector->floorangle, floorcolormap, NULL, NULL, frontsector->f_slope, P_SectorHasFloorPortal(frontsector) ? &frontsector->portal_floor : NULL);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
floorplane = NULL;
|
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
if (P_GetSectorCeilingZAt(frontsector, viewx, viewy) > viewz
|
2020-03-20 17:55:29 +00:00
|
|
|
|| frontsector->ceilingpic == skyflatnum
|
2023-08-23 18:46:48 +00:00
|
|
|
|| P_SectorHasCeilingPortal(frontsector)
|
2020-03-20 17:55:29 +00:00
|
|
|
|| (frontsector->heightsec != -1 && sectors[frontsector->heightsec].floorpic == skyflatnum))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2021-04-05 14:23:21 +00:00
|
|
|
ceilingplane = R_FindPlane(frontsector, frontsector->ceilingheight, frontsector->ceilingpic,
|
2022-11-25 23:01:27 +00:00
|
|
|
ceilinglightlevel, frontsector->ceilingxoffset, frontsector->ceilingyoffset, frontsector->ceilingangle,
|
2023-08-23 18:04:50 +00:00
|
|
|
ceilingcolormap, NULL, NULL, frontsector->c_slope, P_SectorHasCeilingPortal(frontsector) ? &frontsector->portal_ceiling : NULL);
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ceilingplane = NULL;
|
|
|
|
|
|
|
|
numffloors = 0;
|
2015-05-22 03:13:51 +00:00
|
|
|
ffloor[numffloors].slope = NULL;
|
2014-03-15 16:59:03 +00:00
|
|
|
ffloor[numffloors].plane = NULL;
|
2015-01-01 19:50:31 +00:00
|
|
|
ffloor[numffloors].polyobj = NULL;
|
2014-03-15 16:59:03 +00:00
|
|
|
if (frontsector->ffloors)
|
|
|
|
{
|
2016-10-09 19:55:04 +00:00
|
|
|
fixed_t heightcheck, planecenterz;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
for (rover = frontsector->ffloors; rover && numffloors < MAXFFLOORS; rover = rover->next)
|
|
|
|
{
|
2022-07-31 10:04:42 +00:00
|
|
|
if (!(rover->fofflags & FOF_EXISTS) || !(rover->fofflags & FOF_RENDERPLANES))
|
2014-03-15 16:59:03 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (frontsector->cullheight)
|
|
|
|
{
|
2014-11-12 00:55:07 +00:00
|
|
|
if (R_DoCulling(frontsector->cullheight, viewsector->cullheight, viewz, *rover->bottomheight, *rover->topheight))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2014-11-12 00:55:07 +00:00
|
|
|
rover->norender = leveltime;
|
|
|
|
continue;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ffloor[numffloors].plane = NULL;
|
2015-01-01 19:50:31 +00:00
|
|
|
ffloor[numffloors].polyobj = NULL;
|
2016-01-21 18:50:05 +00:00
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
heightcheck = P_GetFFloorBottomZAt(rover, viewx, viewy);
|
2016-01-21 18:50:05 +00:00
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
planecenterz = P_GetFFloorBottomZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y);
|
2015-09-24 20:35:55 +00:00
|
|
|
if (planecenterz <= ceilingcenterz
|
|
|
|
&& planecenterz >= floorcenterz
|
2022-07-31 10:04:42 +00:00
|
|
|
&& ((viewz < heightcheck && (rover->fofflags & FOF_BOTHPLANES || !(rover->fofflags & FOF_INVERTPLANES)))
|
|
|
|
|| (viewz > heightcheck && (rover->fofflags & FOF_BOTHPLANES || rover->fofflags & FOF_INVERTPLANES))))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2015-09-24 20:35:55 +00:00
|
|
|
light = R_GetPlaneLight(frontsector, planecenterz,
|
2016-03-29 14:40:01 +00:00
|
|
|
viewz < heightcheck);
|
2016-01-21 18:50:05 +00:00
|
|
|
|
2021-04-05 14:23:21 +00:00
|
|
|
ffloor[numffloors].plane = R_FindPlane(rover->master->frontsector, *rover->bottomheight, *rover->bottompic,
|
2014-03-15 16:59:03 +00:00
|
|
|
*frontsector->lightlist[light].lightlevel, *rover->bottomxoffs,
|
2023-08-23 07:24:06 +00:00
|
|
|
*rover->bottomyoffs, *rover->bottomangle, *frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->b_slope, NULL);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2015-05-17 03:32:12 +00:00
|
|
|
ffloor[numffloors].slope = *rover->b_slope;
|
2015-05-17 04:55:49 +00:00
|
|
|
|
|
|
|
// Tell the renderer this sector has slopes in it.
|
|
|
|
if (ffloor[numffloors].slope)
|
|
|
|
frontsector->hasslope = true;
|
2015-05-17 03:32:12 +00:00
|
|
|
|
2016-03-29 14:40:01 +00:00
|
|
|
ffloor[numffloors].height = heightcheck;
|
2014-03-15 16:59:03 +00:00
|
|
|
ffloor[numffloors].ffloor = rover;
|
|
|
|
numffloors++;
|
|
|
|
}
|
|
|
|
if (numffloors >= MAXFFLOORS)
|
|
|
|
break;
|
|
|
|
ffloor[numffloors].plane = NULL;
|
2015-01-01 19:50:31 +00:00
|
|
|
ffloor[numffloors].polyobj = NULL;
|
2015-05-17 03:32:12 +00:00
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
heightcheck = P_GetFFloorTopZAt(rover, viewx, viewy);
|
2016-01-21 18:50:05 +00:00
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
planecenterz = P_GetFFloorTopZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y);
|
2015-09-24 20:35:55 +00:00
|
|
|
if (planecenterz >= floorcenterz
|
|
|
|
&& planecenterz <= ceilingcenterz
|
2022-07-31 10:04:42 +00:00
|
|
|
&& ((viewz > heightcheck && (rover->fofflags & FOF_BOTHPLANES || !(rover->fofflags & FOF_INVERTPLANES)))
|
|
|
|
|| (viewz < heightcheck && (rover->fofflags & FOF_BOTHPLANES || rover->fofflags & FOF_INVERTPLANES))))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2016-03-29 14:40:01 +00:00
|
|
|
light = R_GetPlaneLight(frontsector, planecenterz, viewz < heightcheck);
|
2016-01-21 18:50:05 +00:00
|
|
|
|
2021-04-05 14:23:21 +00:00
|
|
|
ffloor[numffloors].plane = R_FindPlane(rover->master->frontsector, *rover->topheight, *rover->toppic,
|
2014-03-15 16:59:03 +00:00
|
|
|
*frontsector->lightlist[light].lightlevel, *rover->topxoffs, *rover->topyoffs, *rover->topangle,
|
2023-08-23 07:24:06 +00:00
|
|
|
*frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->t_slope, NULL);
|
2015-05-17 03:32:12 +00:00
|
|
|
|
|
|
|
ffloor[numffloors].slope = *rover->t_slope;
|
2015-05-17 04:55:49 +00:00
|
|
|
|
|
|
|
// Tell the renderer this sector has slopes in it.
|
|
|
|
if (ffloor[numffloors].slope)
|
|
|
|
frontsector->hasslope = true;
|
2015-05-17 03:32:12 +00:00
|
|
|
|
2016-03-29 14:40:01 +00:00
|
|
|
ffloor[numffloors].height = heightcheck;
|
2014-03-15 16:59:03 +00:00
|
|
|
ffloor[numffloors].ffloor = rover;
|
|
|
|
numffloors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Polyobjects have planes, too!
|
|
|
|
if (sub->polyList)
|
|
|
|
{
|
|
|
|
polyobj_t *po = sub->polyList;
|
|
|
|
sector_t *polysec;
|
|
|
|
|
|
|
|
while (po)
|
|
|
|
{
|
|
|
|
if (numffloors >= MAXFFLOORS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!(po->flags & POF_RENDERPLANES)) // Don't draw planes
|
|
|
|
{
|
|
|
|
po = (polyobj_t *)(po->link.next);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
polysec = po->lines[0]->backsector;
|
|
|
|
ffloor[numffloors].plane = NULL;
|
|
|
|
|
2016-10-09 19:55:04 +00:00
|
|
|
if (polysec->floorheight <= ceilingcenterz
|
|
|
|
&& polysec->floorheight >= floorcenterz
|
2014-03-15 16:59:03 +00:00
|
|
|
&& (viewz < polysec->floorheight))
|
|
|
|
{
|
|
|
|
light = R_GetPlaneLight(frontsector, polysec->floorheight, viewz < polysec->floorheight);
|
2021-04-05 14:23:21 +00:00
|
|
|
ffloor[numffloors].plane = R_FindPlane(polysec, polysec->floorheight, polysec->floorpic,
|
2022-11-25 23:01:27 +00:00
|
|
|
(light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->floorxoffset, polysec->flooryoffset,
|
|
|
|
polysec->floorangle-po->angle,
|
2020-03-20 17:55:29 +00:00
|
|
|
(light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po,
|
2023-08-23 07:24:06 +00:00
|
|
|
NULL, NULL);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
ffloor[numffloors].height = polysec->floorheight;
|
|
|
|
ffloor[numffloors].polyobj = po;
|
2015-05-22 03:13:51 +00:00
|
|
|
ffloor[numffloors].slope = NULL;
|
2015-04-06 16:22:27 +00:00
|
|
|
po->visplane = ffloor[numffloors].plane;
|
2014-03-15 16:59:03 +00:00
|
|
|
numffloors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numffloors >= MAXFFLOORS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ffloor[numffloors].plane = NULL;
|
|
|
|
|
2016-10-09 19:55:04 +00:00
|
|
|
if (polysec->ceilingheight >= floorcenterz
|
|
|
|
&& polysec->ceilingheight <= ceilingcenterz
|
2014-03-15 16:59:03 +00:00
|
|
|
&& (viewz > polysec->ceilingheight))
|
|
|
|
{
|
2019-08-22 21:30:36 +00:00
|
|
|
light = R_GetPlaneLight(frontsector, polysec->floorheight, viewz < polysec->floorheight);
|
2021-04-05 14:23:21 +00:00
|
|
|
ffloor[numffloors].plane = R_FindPlane(polysec, polysec->ceilingheight, polysec->ceilingpic,
|
2022-11-25 23:01:27 +00:00
|
|
|
(light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->ceilingxoffset, polysec->ceilingyoffset, polysec->ceilingangle-po->angle,
|
2020-03-20 17:55:29 +00:00
|
|
|
(light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po,
|
2023-08-23 07:24:06 +00:00
|
|
|
NULL, NULL);
|
2014-11-12 00:55:07 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
ffloor[numffloors].polyobj = po;
|
|
|
|
ffloor[numffloors].height = polysec->ceilingheight;
|
2015-05-22 03:13:51 +00:00
|
|
|
ffloor[numffloors].slope = NULL;
|
2015-04-06 16:22:27 +00:00
|
|
|
po->visplane = ffloor[numffloors].plane;
|
2014-03-15 16:59:03 +00:00
|
|
|
numffloors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
po = (polyobj_t *)(po->link.next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// killough 9/18/98: Fix underwater slowdown, by passing real sector
|
|
|
|
// instead of fake one. Improve sprite lighting by basing sprite
|
|
|
|
// lightlevels on floor & ceiling lightlevels in the surrounding area.
|
|
|
|
//
|
|
|
|
// 10/98 killough:
|
|
|
|
//
|
|
|
|
// NOTE: TeamTNT fixed this bug incorrectly, messing up sprite lighting!!!
|
|
|
|
// That is part of the 242 effect!!! If you simply pass sub->sector to
|
|
|
|
// the old code you will not get correct lighting for underwater sprites!!!
|
|
|
|
// Either you must pass the fake sector and handle validcount here, on the
|
|
|
|
// real sector, or you must account for the lighting in some other way,
|
|
|
|
// like passing it as an argument.
|
|
|
|
R_AddSprites(sub->sector, (floorlightlevel+ceilinglightlevel)/2);
|
|
|
|
|
|
|
|
firstseg = NULL;
|
|
|
|
|
|
|
|
// haleyjd 02/19/06: draw polyobjects before static lines
|
|
|
|
if (sub->polyList)
|
|
|
|
R_AddPolyObjects(sub);
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
// CONS_Debug(DBG_GAMELOGIC, "Adding normal line %d...(%d)\n", line->linedef-lines, leveltime);
|
2020-05-02 10:08:31 +00:00
|
|
|
if (!line->glseg && !line->polyseg) // ignore segs that belong to polyobjects
|
|
|
|
R_AddLine(line);
|
2014-03-15 16:59:03 +00:00
|
|
|
line++;
|
|
|
|
curline = NULL; /* cph 2001/11/18 - must clear curline now we're done with it, so stuff doesn't try using it for other things */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// R_Prep3DFloors
|
|
|
|
//
|
|
|
|
// This function creates the lightlists that the given sector uses to light
|
|
|
|
// floors/ceilings/walls according to the 3D floors.
|
|
|
|
void R_Prep3DFloors(sector_t *sector)
|
|
|
|
{
|
|
|
|
ffloor_t *rover;
|
|
|
|
ffloor_t *best;
|
|
|
|
fixed_t bestheight, maxheight;
|
2018-09-10 20:28:39 +00:00
|
|
|
INT32 count, i;
|
2014-03-15 16:59:03 +00:00
|
|
|
sector_t *sec;
|
2016-05-22 03:53:04 +00:00
|
|
|
pslope_t *bestslope = NULL;
|
2015-05-18 04:51:38 +00:00
|
|
|
fixed_t heighttest; // I think it's better to check the Z height at the sector's center
|
|
|
|
// than assume unsloped heights are accurate indicators of order in sloped sectors. -Red
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
count = 1;
|
|
|
|
for (rover = sector->ffloors; rover; rover = rover->next)
|
|
|
|
{
|
2022-07-31 10:04:42 +00:00
|
|
|
if ((rover->fofflags & FOF_EXISTS) && (!(rover->fofflags & FOF_NOSHADE)
|
|
|
|
|| (rover->fofflags & FOF_CUTLEVEL) || (rover->fofflags & FOF_CUTSPRITES)))
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
count++;
|
2022-07-31 10:04:42 +00:00
|
|
|
if (rover->fofflags & FOF_DOUBLESHADOW)
|
2014-03-15 16:59:03 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != sector->numlights)
|
|
|
|
{
|
|
|
|
Z_Free(sector->lightlist);
|
|
|
|
sector->lightlist = Z_Calloc(sizeof (*sector->lightlist) * count, PU_LEVEL, NULL);
|
|
|
|
sector->numlights = count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memset(sector->lightlist, 0, sizeof (lightlist_t) * count);
|
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
heighttest = P_GetSectorCeilingZAt(sector, sector->soundorg.x, sector->soundorg.y);
|
2015-05-18 04:51:38 +00:00
|
|
|
|
|
|
|
sector->lightlist[0].height = heighttest + 1;
|
2015-08-25 03:09:19 +00:00
|
|
|
sector->lightlist[0].slope = sector->c_slope;
|
2014-03-15 16:59:03 +00:00
|
|
|
sector->lightlist[0].lightlevel = §or->lightlevel;
|
|
|
|
sector->lightlist[0].caster = NULL;
|
2018-09-12 20:06:56 +00:00
|
|
|
sector->lightlist[0].extra_colormap = §or->extra_colormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
sector->lightlist[0].flags = 0;
|
|
|
|
|
|
|
|
maxheight = INT32_MAX;
|
|
|
|
for (i = 1; i < count; i++)
|
|
|
|
{
|
|
|
|
bestheight = INT32_MAX * -1;
|
|
|
|
best = NULL;
|
|
|
|
for (rover = sector->ffloors; rover; rover = rover->next)
|
|
|
|
{
|
|
|
|
rover->lastlight = 0;
|
2022-07-31 10:04:42 +00:00
|
|
|
if (!(rover->fofflags & FOF_EXISTS) || (rover->fofflags & FOF_NOSHADE
|
|
|
|
&& !(rover->fofflags & FOF_CUTLEVEL) && !(rover->fofflags & FOF_CUTSPRITES)))
|
2014-03-15 16:59:03 +00:00
|
|
|
continue;
|
|
|
|
|
2020-03-22 14:17:16 +00:00
|
|
|
heighttest = P_GetFFloorTopZAt(rover, sector->soundorg.x, sector->soundorg.y);
|
2015-05-18 04:51:38 +00:00
|
|
|
|
|
|
|
if (heighttest > bestheight && heighttest < maxheight)
|
|
|
|
{
|
|
|
|
best = rover;
|
|
|
|
bestheight = heighttest;
|
|
|
|
bestslope = *rover->t_slope;
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-31 10:04:42 +00:00
|
|
|
if (rover->fofflags & FOF_DOUBLESHADOW) {
|
2020-03-22 14:17:16 +00:00
|
|
|
heighttest = P_GetFFloorBottomZAt(rover, sector->soundorg.x, sector->soundorg.y);
|
2015-05-18 04:51:38 +00:00
|
|
|
|
|
|
|
if (heighttest > bestheight
|
|
|
|
&& heighttest < maxheight)
|
|
|
|
{
|
|
|
|
best = rover;
|
|
|
|
bestheight = heighttest;
|
|
|
|
bestslope = *rover->b_slope;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
if (!best)
|
|
|
|
{
|
|
|
|
sector->numlights = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sector->lightlist[i].height = maxheight = bestheight;
|
|
|
|
sector->lightlist[i].caster = best;
|
2022-07-31 10:04:42 +00:00
|
|
|
sector->lightlist[i].flags = best->fofflags;
|
2015-05-18 04:51:38 +00:00
|
|
|
sector->lightlist[i].slope = bestslope;
|
2014-03-15 16:59:03 +00:00
|
|
|
sec = §ors[best->secnum];
|
|
|
|
|
2022-07-31 10:04:42 +00:00
|
|
|
if (best->fofflags & FOF_NOSHADE)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
sector->lightlist[i].lightlevel = sector->lightlist[i-1].lightlevel;
|
|
|
|
sector->lightlist[i].extra_colormap = sector->lightlist[i-1].extra_colormap;
|
|
|
|
}
|
2022-07-31 10:04:42 +00:00
|
|
|
else if (best->fofflags & FOF_COLORMAPONLY)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
sector->lightlist[i].lightlevel = sector->lightlist[i-1].lightlevel;
|
2018-09-12 20:06:56 +00:00
|
|
|
sector->lightlist[i].extra_colormap = &sec->extra_colormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sector->lightlist[i].lightlevel = best->toplightlevel;
|
2018-09-12 20:06:56 +00:00
|
|
|
sector->lightlist[i].extra_colormap = &sec->extra_colormap;
|
2014-03-15 16:59:03 +00:00
|
|
|
}
|
|
|
|
|
2022-07-31 10:04:42 +00:00
|
|
|
if (best->fofflags & FOF_DOUBLESHADOW)
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
2020-03-22 14:17:16 +00:00
|
|
|
heighttest = P_GetFFloorBottomZAt(best, sector->soundorg.x, sector->soundorg.y);
|
2015-05-18 04:51:38 +00:00
|
|
|
if (bestheight == heighttest) ///TODO: do this in a more efficient way -Red
|
2014-03-15 16:59:03 +00:00
|
|
|
{
|
|
|
|
sector->lightlist[i].lightlevel = sector->lightlist[best->lastlight].lightlevel;
|
|
|
|
sector->lightlist[i].extra_colormap =
|
|
|
|
sector->lightlist[best->lastlight].extra_colormap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
best->lastlight = i - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside)
|
|
|
|
{
|
|
|
|
INT32 i;
|
|
|
|
|
|
|
|
if (!underside)
|
|
|
|
{
|
|
|
|
for (i = 1; i < sector->numlights; i++)
|
|
|
|
if (sector->lightlist[i].height <= planeheight)
|
|
|
|
return i - 1;
|
|
|
|
|
|
|
|
return sector->numlights - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < sector->numlights; i++)
|
|
|
|
if (sector->lightlist[i].height < planeheight)
|
|
|
|
return i - 1;
|
|
|
|
|
|
|
|
return sector->numlights - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// RenderBSPNode
|
|
|
|
// Renders all subsectors below a given node,
|
|
|
|
// traversing subtree recursively.
|
|
|
|
// Just call with BSP root.
|
|
|
|
//
|
|
|
|
// killough 5/2/98: reformatted, removed tail recursion
|
|
|
|
|
|
|
|
void R_RenderBSPNode(INT32 bspnum)
|
|
|
|
{
|
|
|
|
node_t *bsp;
|
|
|
|
INT32 side;
|
2020-05-02 17:43:53 +00:00
|
|
|
|
2021-10-25 17:49:15 +00:00
|
|
|
ps_numbspcalls.value.i++;
|
2020-05-02 17:43:53 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
while (!(bspnum & NF_SUBSECTOR)) // Found a subsector?
|
|
|
|
{
|
|
|
|
bsp = &nodes[bspnum];
|
|
|
|
|
|
|
|
// Decide which side the view point is on.
|
|
|
|
side = R_PointOnSide(viewx, viewy, bsp);
|
|
|
|
// Recursively divide front space.
|
|
|
|
R_RenderBSPNode(bsp->children[side]);
|
|
|
|
|
|
|
|
// Possibly divide back space.
|
|
|
|
|
|
|
|
if (!R_CheckBBox(bsp->bbox[side^1]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bspnum = bsp->children[side^1];
|
|
|
|
}
|
2014-11-12 00:55:07 +00:00
|
|
|
|
2019-12-11 14:35:34 +00:00
|
|
|
// PORTAL CULLING
|
|
|
|
if (portalcullsector) {
|
|
|
|
sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector;
|
|
|
|
if (sect != portalcullsector)
|
|
|
|
return;
|
|
|
|
portalcullsector = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
|
|
|
|
}
|