refactor a bunch of crap and fix skyportals

This commit is contained in:
Alug committed 2024-10-25 22:58:10 +02:00
1 parent a6be267325
commit cee28c6166
11 files changed
+364 -167

No files matched your search

+1
View File
@@ -33,6 +33,7 @@ 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
drawseg_t *curdrawsegs = NULL; /**< This is used to handle multiple lists for masked drawsegs. */
drawseg_t *drawsegs = NULL;
drawseg_t *ds_p = NULL;
+1
View File
@@ -32,6 +32,7 @@ extern portal_t *g_portal; // is curline a portal seg?
extern INT32 checkcoord[12][4];
extern drawseg_t *curdrawsegs;
extern drawseg_t *drawsegs;
extern drawseg_t *ds_p;
extern INT32 doorclosed;
+54 -12
View File
@@ -1479,8 +1479,8 @@ static void R_PortalFrame(portal_t *portal)
viewz = portal->viewz;
viewangle = portal->viewangle;
// newview->sin = FINESINE(newview->angle>>ANGLETOFINESHIFT);
// newview->cos = FINECOSINE(newview->angle>>ANGLETOFINESHIFT);
viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT);
viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT);
portalclipstart = portal->start;
portalclipend = portal->end;
@@ -1488,15 +1488,33 @@ static void R_PortalFrame(portal_t *portal)
if (portal->clipline != -1)
{
portalclipline = &lines[portal->clipline];
viewsector = portalcullsector = portalclipline->frontsector;
portalcullsector = portalclipline->frontsector;
viewsector = portalclipline->frontsector;
}
else
{
portalclipline = NULL;
viewsector = portalcullsector = R_PointInSubsector(viewx, viewy)->sector;
portalcullsector = NULL;
viewsector = R_PointInSubsector(viewx, viewy)->sector;
}
}
static void Mask_Pre (maskcount_t* m)
{
m->drawsegs[0] = ds_p - drawsegs;
m->vissprites[0] = visspritecount;
m->viewx = viewx;
m->viewy = viewy;
m->viewz = viewz;
m->viewsector = viewsector;
}
static void Mask_Post (maskcount_t* m)
{
m->drawsegs[1] = ds_p - drawsegs;
m->vissprites[1] = visspritecount;
}
// ================
// R_RenderView
// ================
@@ -1509,6 +1527,9 @@ static void R_PortalFrame(portal_t *portal)
void R_RenderPlayerView(player_t *player)
{
INT32 nummasks = 1;
maskcount_t* masks = malloc(sizeof(maskcount_t));
// if this is display player 1
if (cv_homremoval.value && player == &players[displayplayers[0]])
{
@@ -1561,18 +1582,26 @@ void R_RenderPlayerView(player_t *player)
Portal_InitList();
// The head node is the last node output.
Mask_Pre(&masks[nummasks - 1]);
curdrawsegs = ds_p;
ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0;
PS_START_TIMING(ps_bsptime);
R_RenderBSPNode((INT32)numnodes - 1);
PS_STOP_TIMING(ps_bsptime);
Mask_Post(&masks[nummasks - 1]);
R_AddPrecipitationSprites();
PS_START_TIMING(ps_sw_spritecliptime);
R_ClipSprites();
R_ClipSprites(drawsegs, NULL);
PS_STOP_TIMING(ps_sw_spritecliptime);
ps_numsprites.value.i = numvisiblesprites;
// Add skybox portals caused by sky visplanes.
if (skyboxmo[0] && cv_skybox.value)
Portal_AddSkyboxPortals();
PS_START_TIMING(ps_sw_portaltime);
// Portal rendering. Hijacks the BSP traversal.
if (portal_base)
@@ -1583,6 +1612,8 @@ void R_RenderPlayerView(player_t *player)
{
portalrender = portal->pass; // Recursiveness depth.
R_ClearFFloorClips();
// Apply the viewpoint stored for the portal.
R_PortalFrame(portal);
@@ -1595,17 +1626,26 @@ void R_RenderPlayerView(player_t *player)
// that were previously stored.
Portal_ClipApply(portal);
validcount++;
masks = realloc(masks, (++nummasks)*sizeof(maskcount_t));
Mask_Pre(&masks[nummasks - 1]);
curdrawsegs = ds_p;
portalskipprecipmobjs = portal->isskybox;
// Render the BSP from the new viewpoint, and clip
// any sprites with the new clipsegs and window.
R_RenderBSPNode((INT32)numnodes - 1);
R_ClipSprites();
Mask_Post(&masks[nummasks - 1]);
portalskipprecipmobjs = false;
R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal);
Portal_Remove(portal);
validcount++;
}
portalcullsector = NULL; // Just in case...
}
PS_STOP_TIMING(ps_sw_portaltime);
@@ -1618,8 +1658,10 @@ void R_RenderPlayerView(player_t *player)
// draw mid texture and sprite
// And now 3D floors/sides!
PS_START_TIMING(ps_sw_maskedtime);
R_DrawMasked();
R_DrawMasked(masks, nummasks);
PS_STOP_TIMING(ps_sw_maskedtime);
free(masks);
}
// =========================================================================
+19 -37
View File
@@ -41,13 +41,7 @@
// good night sweet prince
//#define SHITPLANESPARENCY
//SoM: 3/23/2000: Use Boom visplane hashing.
#define VISPLANEHASHBITS 9
#define VISPLANEHASHMASK ((1<<VISPLANEHASHBITS)-1)
// the last visplane list is outside of the hash table and is used for fof planes
#define MAXVISPLANES ((1<<VISPLANEHASHBITS)+1)
static visplane_t *visplanes[MAXVISPLANES];
visplane_t *visplanes[MAXVISPLANES];
static visplane_t *freetail;
static visplane_t **freehead = &freetail;
@@ -265,6 +259,24 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2)
spanfunc();
}
void R_ClearFFloorClips (void)
{
INT32 i, p;
// opening / clipping determination
for (i = 0; i < viewwidth; i++)
{
for (p = 0; p < MAXFFLOORS; p++)
{
ffloor[p].f_clip[i] = (INT16)viewheight;
ffloor[p].c_clip[i] = -1;
}
}
numffloors = 0;
}
//
// R_ClearPlanes
// At begining of frame.
@@ -287,8 +299,6 @@ void R_ClearPlanes(void)
}
}
numffloors = 0;
for (i = 0; i < MAXVISPLANES; i++)
{
for (*freehead = visplanes[i], visplanes[i] = NULL;
@@ -1185,31 +1195,3 @@ void R_PlaneBounds(visplane_t *plane)
plane->high = hi;
plane->low = low;
}
/** Creates portals for the currently existing sky visplanes.
* The visplanes are also removed and cleared from the list.
*/
void Portal_AddSkyboxPortals (void)
{
visplane_t *pl;
INT32 i;
UINT16 count = 0;
for (i = 0; i < MAXVISPLANES; i++, pl++)
{
for (pl = visplanes[i]; pl; pl = pl->next)
{
if (pl->picnum == skyflatnum)
{
Portal_AddSkybox(pl);
pl->minx = 0;
pl->maxx = -1;
count++;
}
}
}
CONS_Debug(DBG_RENDER, "Skybox portals: %d\n", count);
}
+3 -2
View File
@@ -18,6 +18,7 @@
#include "r_data.h"
#include "p_polyobj.h"
//SoM: 3/23/2000: Use Boom visplane hashing.
#define VISPLANEHASHBITS 9
#define VISPLANEHASHMASK ((1<<VISPLANEHASHBITS)-1)
// the last visplane list is outside of the hash table and is used for fof planes
@@ -56,6 +57,7 @@ typedef struct visplane_s
boolean noencore;
} visplane_t;
extern visplane_t *visplanes[MAXVISPLANES];
extern visplane_t *floorplane;
extern visplane_t *ceilingplane;
@@ -76,6 +78,7 @@ extern lighttable_t **planezlight;
void R_InitPlanes(void);
void R_ClearPlanes(void);
void R_ClearFFloorClips (void);
void R_MapPlane(INT32 y, INT32 x1, INT32 x2);
void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2);
@@ -116,6 +119,4 @@ typedef struct planemgr_s
extern visffloor_t ffloor[MAXFFLOORS];
extern INT32 numffloors;
void Portal_AddSkyboxPortals (void);
#endif
+102 -45
View File
@@ -1,8 +1,9 @@
// SONIC ROBO BLAST 2
// SONIC ROBO BLAST 2 KART
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2018 by Sonic Team Junior.
// Copyright (C) 2024 by Kart Krew.
// Copyright (C) 2020 by Sonic Team Junior.
// Copyright (C) 2000 by DooM Legacy Team.
// Copyright (C) 1996 by id Software, Inc.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
@@ -17,14 +18,17 @@
#include "doomstat.h"
#include "p_spec.h" // Skybox viewpoints
#include "z_zone.h"
#include "r_things.h"
#include "r_sky.h"
UINT8 portalrender; /**< When rendering a portal, it establishes the depth of the current BSP traversal. */
sector_t *portalcullsector;
boolean portalskipprecipmobjs = false;
// Linked list for portals.
portal_t *portal_base, *portal_cap;
line_t *portalclipline;
sector_t *portalcullsector;
INT32 portalclipstart, portalclipend;
portal_t *g_portal; // is curline a portal seg?
@@ -35,32 +39,6 @@ void Portal_InitList (void)
portal_base = portal_cap = NULL;
}
/** Store the clipping window for a portal in its given range.
*
* The window is copied from the current window at the time
* the function is called, so it is useful for converting one-sided
* lines into portals.
*/
void Portal_ClipRange (portal_t* portal)
{
INT32 start = portal->start;
INT32 end = portal->end;
INT16 *ceil = portal->ceilingclip;
INT16 *floor = portal->floorclip;
fixed_t *scale = portal->frontscale;
INT32 i;
for (i = 0; i < end-start; i++)
{
*ceil = ceilingclip[start+i];
ceil++;
*floor = floorclip[start+i];
floor++;
*scale = frontscale[start+i];
scale++;
}
}
/** Apply the clipping window from a portal.
*/
void Portal_ClipApply (const portal_t* portal)
@@ -95,12 +73,12 @@ void Portal_ClipApply (const portal_t* portal)
}
}
portal_t* Portal_Add (const INT16 x1, const INT16 x2)
static portal_t* Portal_Add (const INT16 x1, const INT16 x2)
{
portal_t *portal = Z_Malloc(sizeof(portal_t), PU_LEVEL, NULL);
INT16 *ceilingclipsave = Z_Malloc(sizeof(INT16)*(x2-x1), PU_LEVEL, NULL);
INT16 *floorclipsave = Z_Malloc(sizeof(INT16)*(x2-x1), PU_LEVEL, NULL);
fixed_t *frontscalesave = Z_Malloc(sizeof(fixed_t)*(x2-x1), PU_LEVEL, NULL);
INT16 *ceilingclipsave = Z_Malloc(sizeof(INT16)*(x2-x1 + 1), PU_LEVEL, NULL);
INT16 *floorclipsave = Z_Malloc(sizeof(INT16)*(x2-x1 + 1), PU_LEVEL, NULL);
fixed_t *frontscalesave = Z_Malloc(sizeof(fixed_t)*(x2-x1 + 1), PU_LEVEL, NULL);
// Linked list.
if (!portal_base)
@@ -125,11 +103,14 @@ portal_t* Portal_Add (const INT16 x1, const INT16 x2)
// Increase recursion level.
portal->pass = portalrender+1;
portal->isskybox = false;
return portal;
}
void Portal_Remove (portal_t* portal)
{
portalcullsector = NULL;
portal_base = portal->next;
Z_Free(portal->ceilingclip);
Z_Free(portal->floorclip);
@@ -181,8 +162,6 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con
portal->clipline = line2;
Portal_ClipRange(portal);
g_portal = portal; // this tells R_StoreWallRange that curline is a portal seg
}
@@ -199,26 +178,68 @@ static void Portal_ClipVisplane (const visplane_t* plane, portal_t* portal)
for (i = 0; i < end - start; i++)
{
portal->ceilingclip[i] = plane->top[i + start];
// Invalid column.
if (plane->top[i + start] == 65535)
{
portal->ceilingclip[i] = -1;
portal->floorclip[i] = -1;
continue;
}
portal->ceilingclip[i] = plane->top[i + start] - 1;
portal->floorclip[i] = plane->bottom[i + start] + 1;
portal->frontscale[i] = INT32_MAX;
}
}
extern INT32 viewwidth;
static boolean TrimVisplaneBounds (const visplane_t* plane, INT16* start, INT16* end)
{
*start = plane->minx;
*end = plane->maxx + 1;
// Visplanes have 1-px pads on their sides (extra columns).
// Trim them, else it may render out of bounds.
if (*end > viewwidth)
*end = viewwidth;
if (!(*start < *end))
return true;
/** Trims a visplane's horizontal gap to match its render area.
*
* Visplanes' minx/maxx may sometimes exceed the area they're
* covering. This merely adjusts the boundaries to the next
* valid area.
*/
while (plane->bottom[*start] == 0 && plane->top[*start] == 65535 && *start < *end)
{
(*start)++;
}
while (plane->bottom[*end - 1] == 0 && plane->top[*start] == 65535 && *end > *start)
{
(*end)--;
}
return false;
}
/** Creates a skybox portal out of a visplane.
*
* Applies the necessary offsets and rotation to give
* a depth illusion to the skybox.
*/
void Portal_AddSkybox (const visplane_t* plane)
static void Portal_AddSkybox (const visplane_t* plane)
{
INT16 start = plane->minx;
INT16 end = plane->maxx + 1;
INT16 start, end;
mapheader_t *mh;
portal_t* portal;
if (!(start < end))
if (TrimVisplaneBounds(plane, &start, &end))
return;
portal = Portal_Add(start, end);
@@ -227,7 +248,9 @@ void Portal_AddSkybox (const visplane_t* plane)
portal->viewx = skyboxmo[0]->x;
portal->viewy = skyboxmo[0]->y;
portal->viewz = skyboxmo[0]->z;
portal->viewz = 0;
if (skyboxmo[0]->spawnpoint)
portal->viewz = ((fixed_t)skyboxmo[0]->spawnpoint->angle)<<FRACBITS;
portal->viewangle = viewangle + skyboxmo[0]->angle;
mh = mapheaderinfo[gamemap-1];
@@ -236,6 +259,7 @@ void Portal_AddSkybox (const visplane_t* plane)
if (skyboxmo[1])
{
fixed_t x = 0, y = 0;
angle_t ang = skyboxmo[0]->angle>>ANGLETOFINESHIFT;
if (mh->skybox_scalex > 0)
x = (viewx - skyboxmo[1]->x) / mh->skybox_scalex;
@@ -247,8 +271,9 @@ void Portal_AddSkybox (const visplane_t* plane)
else if (mh->skybox_scaley < 0)
y = (viewy - skyboxmo[1]->y) * -mh->skybox_scaley;
portal->viewx += x;
portal->viewy += y;
// Apply transform to account for the skybox viewport angle.
portal->viewx += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang));
portal->viewy += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang));
}
if (mh->skybox_scalez > 0)
@@ -257,4 +282,36 @@ void Portal_AddSkybox (const visplane_t* plane)
portal->viewz += viewz * -mh->skybox_scalez;
portal->clipline = -1;
portal->isskybox = true;
}
/** Creates portals for the currently existing sky visplanes.
* The visplanes are also removed and cleared from the list.
*/
void Portal_AddSkyboxPortals (void)
{
visplane_t *pl;
INT32 i;
UINT16 count = 0;
for (i = 0; i < MAXVISPLANES; i++, pl++)
{
for (pl = visplanes[i]; pl; pl = pl->next)
{
//if (pl->minx >= pl->maxx)
//continue;
if (pl->picnum == skyflatnum)
{
Portal_AddSkybox(pl);
pl->minx = 0;
pl->maxx = -1;
count++;
}
}
}
//CONS_Debug(DBG_RENDER, "Skybox portals: %d\n", count);
}
+13 -2
View File
@@ -11,10 +11,12 @@
/// \file r_portal.h
/// \brief Software renderer portal struct, functions, linked list extern.
#ifndef __R_PORTAL__
#define __R_PORTAL__
#include "r_data.h"
#include "r_plane.h" // visplanes
/*
* Portal structure for the software renderer.
*/
@@ -29,6 +31,7 @@ typedef struct portal_s
angle_t viewangle;
UINT8 pass; /**< Keeps track of the portal's recursion depth. */
boolean isskybox;
INT32 clipline; /**< Optional clipline for line-based portals. */
// Clipping information.
@@ -42,11 +45,19 @@ typedef struct portal_s
extern portal_t* portal_base;
extern portal_t* portal_cap;
extern UINT8 portalrender;
extern boolean portalskipprecipmobjs;
extern line_t *portalclipline;
extern sector_t *portalcullsector;
extern INT32 portalclipstart, portalclipend;
void Portal_InitList (void);
void Portal_Remove (portal_t* portal);
void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, const INT32 x2);
void Portal_AddSkybox (const visplane_t* plane);
void Portal_ClipRange (portal_t* portal);
void Portal_ClipApply (const portal_t* portal);
void Portal_AddSkyboxPortals (void);
#endif
+4
View File
@@ -15,6 +15,7 @@
#include "r_local.h"
#include "r_sky.h"
#include "r_portal.h"
#include "r_splats.h"
#include "w_wad.h"
@@ -1642,6 +1643,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
if (ds_p == drawsegs+maxdrawsegs)
{
size_t curpos = curdrawsegs - drawsegs;
size_t pos = ds_p - drawsegs;
size_t newmax = maxdrawsegs ? maxdrawsegs*2 : 128;
if (firstseg)
@@ -1649,6 +1651,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
drawsegs = Z_Realloc(drawsegs, newmax*sizeof (*drawsegs), PU_STATIC, NULL);
ds_p = drawsegs + pos;
maxdrawsegs = newmax;
curdrawsegs = drawsegs + curpos;
if (firstseg)
firstseg = drawsegs + (size_t)firstseg;
}
@@ -1701,6 +1704,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
// borrowed fix from *cough* zdoom *cough*
// [RH] We also need to adjust the openings pointers that
// were already stored in drawsegs.
//for (ds = curdrawsegs; ds < ds_p; ds++)
for (ds = drawsegs; ds < ds_p; ds++)
{
#define ADJUST(p) if (ds->p + ds->x1 >= oldopenings && ds->p + ds->x1 <= oldlast) ds->p = ds->p - oldopenings + openings;
-4
View File
@@ -92,10 +92,6 @@ extern angle_t viewangle, aimingangle, viewroll;
extern UINT8 viewssnum; // splitscreen view number
extern sector_t *viewsector;
extern player_t *viewplayer;
extern UINT8 portalrender;
extern sector_t *portalcullsector;
extern line_t *portalclipline;
extern INT32 portalclipstart, portalclipend;
extern consvar_t cv_allowmlook;
extern consvar_t cv_maxportals;
+152 -62
View File
@@ -25,6 +25,7 @@
#include "r_things.h"
#include "r_patch.h"
#include "r_plane.h"
#include "r_portal.h"
#include "p_tick.h"
#include "p_local.h"
#include "p_slopes.h"
@@ -1970,6 +1971,12 @@ void R_AddPrecipitationSprites(void)
return;
}
// do not render in skybox
if (portalskipprecipmobjs)
{
return;
}
R_GetRenderBlockMapDimensions(drawdist, &xl, &xh, &yl, &yh);
for (bx = xl; bx <= xh; bx++)
@@ -1993,46 +2000,47 @@ void R_AddPrecipitationSprites(void)
//
// R_SortVisSprites
//
static vissprite_t vsprsortedhead;
void R_SortVisSprites(void)
static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 end)
{
UINT32 i;
UINT32 i, count = 0;
vissprite_t *ds, *dsprev, *dsnext, *dsfirst;
vissprite_t *best = NULL;
vissprite_t unsorted;
fixed_t bestscale;
INT32 bestdispoffset;
if (!visspritecount)
return;
dsfirst = &unsorted;
dsprev = dsfirst;
dsnext = dsfirst;
unsorted.next = unsorted.prev = &unsorted;
I_Assert(start <= end);
dsfirst = R_GetVisSprite(0);
// The first's prev and last's next will be set to
// nonsense, but are fixed in a moment
for (i = 0, dsnext = dsfirst, ds = NULL; i < visspritecount; i++)
for (i = start; i < end; ++i)
{
dsprev = ds;
ds = dsnext;
if (i < visspritecount - 1) dsnext = R_GetVisSprite(i + 1);
ds = R_GetVisSprite(i);
ds->next = dsnext;
ds->prev = dsprev;
// Do not include this sprite, since it is completely obscured
if (ds->cut & SC_NOTVISIBLE)
{
continue;
}
dsnext = ds;
dsprev->next = dsnext;
dsnext->prev = dsprev;
dsprev = dsnext;
count++;
}
// Fix first and last. ds still points to the last one after the loop
dsfirst->prev = &unsorted;
unsorted.next = dsfirst;
if (ds)
ds->next = &unsorted;
unsorted.prev = ds;
dsnext->next = dsfirst;
dsfirst->prev = dsnext;
// pull the vissprites out by scale
vsprsortedhead.next = vsprsortedhead.prev = &vsprsortedhead;
for (i = 0; i < visspritecount; i++)
vsprsortedhead->next = vsprsortedhead->prev = vsprsortedhead;
for (i = 0; i < count; i++)
{
bestscale = bestdispoffset = INT32_MAX;
for (ds = unsorted.next; ds != &unsorted; ds = ds->next)
@@ -2058,15 +2066,12 @@ void R_SortVisSprites(void)
best = ds;
}
}
if (best)
{
best->next->prev = best->prev;
best->prev->next = best->next;
best->next = &vsprsortedhead;
best->prev = vsprsortedhead.prev;
vsprsortedhead.prev->next = best;
vsprsortedhead.prev = best;
}
best->next->prev = best->prev;
best->prev->next = best->next;
best->next = vsprsortedhead;
best->prev = vsprsortedhead->prev;
vsprsortedhead->prev->next = best;
vsprsortedhead->prev = best;
}
}
@@ -2076,28 +2081,28 @@ void R_SortVisSprites(void)
static drawnode_t *R_CreateDrawNode(drawnode_t *link);
static drawnode_t nodebankhead;
static drawnode_t nodehead;
static void R_CreateDrawNodes(void)
static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean tempskip)
{
drawnode_t *entry;
drawseg_t *ds;
INT32 i, p, best, x1, x2;
fixed_t bestdelta, delta;
vissprite_t *rover;
static vissprite_t vsprsortedhead;
drawnode_t *r2;
visplane_t *plane;
INT32 sintersect;
fixed_t scale = 0;
// Add the 3D floors, thicksides, and masked textures...
for (ds = ds_p; ds-- > drawsegs ;)
for (ds = drawsegs + mask->drawsegs[1]; ds-- > drawsegs + mask->drawsegs[0];)
{
if (ds->numthicksides)
{
for (i = 0; i < ds->numthicksides; i++)
{
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->thickseg = ds;
entry->ffloor = ds->thicksides[i];
}
@@ -2113,7 +2118,7 @@ static void R_CreateDrawNodes(void)
else
{
// Put it in!
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->plane = plane;
entry->seg = ds;
}
@@ -2121,7 +2126,7 @@ static void R_CreateDrawNodes(void)
}
if (ds->maskedtexturecol)
{
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->seg = ds;
}
if (ds->numffloorplanes)
@@ -2153,7 +2158,7 @@ static void R_CreateDrawNodes(void)
}
if (best != -1)
{
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->plane = ds->ffloorplanes[best];
entry->seg = ds;
ds->ffloorplanes[best] = NULL;
@@ -2164,6 +2169,9 @@ static void R_CreateDrawNodes(void)
}
}
if (tempskip)
return;
// find all the remaining polyobject planes and add them on the end of the list
// probably this is a terrible idea if we wanted them to be sorted properly
// but it works getting them in for now
@@ -2179,16 +2187,18 @@ static void R_CreateDrawNodes(void)
PolyObjects[i].visplane = NULL;
continue;
}
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->plane = plane;
// note: no seg is set, for what should be obvious reasons
PolyObjects[i].visplane = NULL;
}
if (visspritecount == 0)
// No vissprites in this mask?
if (mask->vissprites[1] - mask->vissprites[0] == 0)
return;
R_SortVisSprites();
R_SortVisSprites(&vsprsortedhead, mask->vissprites[0], mask->vissprites[1]);
for (rover = vsprsortedhead.prev; rover != &vsprsortedhead; rover = rover->prev)
{
if (rover->szt > vid.height || rover->sz < 0)
@@ -2196,7 +2206,7 @@ static void R_CreateDrawNodes(void)
sintersect = (rover->x1 + rover->x2) / 2;
for (r2 = nodehead.next; r2 != &nodehead; r2 = r2->next)
for (r2 = head->next; r2 != head; r2 = r2->next)
{
if (r2->plane)
{
@@ -2335,9 +2345,9 @@ static void R_CreateDrawNodes(void)
}
}
}
if (r2 == &nodehead)
if (r2 == head)
{
entry = R_CreateDrawNode(&nodehead);
entry = R_CreateDrawNode(head);
entry->sprite = rover;
}
}
@@ -2381,25 +2391,24 @@ static void R_DoneWithNode(drawnode_t *node)
(node->prev = &nodebankhead)->next = node;
}
static void R_ClearDrawNodes(void)
static void R_ClearDrawNodes(drawnode_t* head)
{
drawnode_t *rover;
drawnode_t *next;
for (rover = nodehead.next; rover != &nodehead ;)
for (rover = head->next; rover != head;)
{
next = rover->next;
R_DoneWithNode(rover);
rover = next;
}
nodehead.next = nodehead.prev = &nodehead;
head->next = head->prev = head;
}
void R_InitDrawNodes(void)
{
nodebankhead.next = nodebankhead.prev = &nodebankhead;
nodehead.next = nodehead.prev = &nodehead;
}
//
@@ -2463,7 +2472,7 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2)
// R_ClipVisSprite
// Clips vissprites without drawing, so that portals can work. -Red
static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2)
static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* portal)
{
drawseg_t *ds;
INT32 x;
@@ -2502,8 +2511,36 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2)
ds = curr->user;
if (ds->portalpass > 0 && ds->portalpass <= portalrender)
continue; // is a portal
if (ds->portalpass != 66) // unused?
{
if (ds->portalpass > 0 && ds->portalpass <= portalrender)
continue; // is a portal
if (ds->scale1 > ds->scale2)
{
lowscale = ds->scale2;
scale = ds->scale1;
}
else
{
lowscale = ds->scale1;
scale = ds->scale2;
}
if (scale < spr->sortscale ||
(lowscale < spr->sortscale &&
!R_PointOnSegSide (spr->gx, spr->gy, ds->curline)))
{
// masked mid texture?
/*
if (ds->maskedtexturecol)
R_RenderMaskedSegRange (ds, r1, r2);
*/
// seg is behind sprite
continue;
}
}
r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1;
r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2;
@@ -2654,11 +2691,34 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2)
if (!R_CheckSpriteVisible(spr, x1, x2))
spr->cut |= SC_NOTVISIBLE;
}
if (portal)
{
INT32 start_index = max(portal->start, x1);
INT32 end_index = min(portal->start + portal->end - portal->start, x2);
for (x = x1; x < start_index; x++)
{
spr->clipbot[x] = -1;
spr->cliptop[x] = -1;
}
for (x = start_index; x <= end_index; x++)
{
if (spr->clipbot[x] > portal->floorclip[x - portal->start])
spr->clipbot[x] = portal->floorclip[x - portal->start];
if (spr->cliptop[x] < portal->ceilingclip[x - portal->start])
spr->cliptop[x] = portal->ceilingclip[x - portal->start];
}
for (x = end_index + 1; x <= x2; x++)
{
spr->clipbot[x] = -1;
spr->cliptop[x] = -1;
}
}
}
void R_ClipSprites(void)
void R_ClipSprites(drawseg_t* dsstart, portal_t* portal)
{
const size_t maxdrawsegs = ds_p - drawsegs;
const size_t maxdrawsegs = ds_p - dsstart;
const INT32 cx = viewwidth / 2;
drawseg_t* ds;
INT32 i;
@@ -2691,7 +2751,7 @@ void R_ClipSprites(void)
}
}
for (ds = ds_p; ds-- > drawsegs;)
for (ds = ds_p; ds-- > dsstart;)
{
if (ds->silhouette || ds->maskedtexturecol)
{
@@ -2745,7 +2805,7 @@ void R_ClipSprites(void)
drawsegs_xrange_count = drawsegs_xranges[0].count;
}
R_ClipVisSprite(spr, spr->x1, spr->x2);
R_ClipVisSprite(spr, spr->x1, spr->x2, portal);
if ((spr->cut & SC_NOTVISIBLE) == 0)
numvisiblesprites++;
@@ -2790,14 +2850,12 @@ boolean R_ThingWithinDist (mobj_t *thing, fixed_t limit_dist)
//
// R_DrawMasked
//
void R_DrawMasked(void)
static void R_DrawMaskedList (drawnode_t* head)
{
drawnode_t *r2;
drawnode_t *next;
R_CreateDrawNodes();
for (r2 = nodehead.next; r2 != &nodehead; r2 = r2->next)
for (r2 = head->next; r2 != head; r2 = r2->next)
{
if (r2->plane)
{
@@ -2835,7 +2893,39 @@ void R_DrawMasked(void)
r2 = next;
}
}
R_ClearDrawNodes();
}
void R_DrawMasked(maskcount_t* masks, INT32 nummasks)
{
drawnode_t *heads; /**< Drawnode lists; as many as number of views/portals. */
INT32 i;
heads = calloc(nummasks, sizeof(drawnode_t));
for (i = 0; i < nummasks; i++)
{
heads[i].next = heads[i].prev = &heads[i];
viewx = masks[i].viewx;
viewy = masks[i].viewy;
viewz = masks[i].viewz;
viewsector = masks[i].viewsector;
R_CreateDrawNodes(&masks[i], &heads[i], false);
}
for (; nummasks > 0; nummasks--)
{
viewx = masks[nummasks - 1].viewx;
viewy = masks[nummasks - 1].viewy;
viewz = masks[nummasks - 1].viewz;
viewsector = masks[nummasks - 1].viewsector;
R_DrawMaskedList(&heads[nummasks - 1]);
R_ClearDrawNodes(&heads[nummasks - 1]);
}
free(heads);
}
// ==========================================================================
+15 -3
View File
@@ -16,6 +16,7 @@
#include "sounds.h"
#include "r_plane.h"
#include "r_portal.h"
#include "r_patch.h"
// "Left" and "Right" character symbols for additional rotation functionality
@@ -60,7 +61,6 @@ extern INT32 lengthcol;
fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope);
void R_DrawMaskedColumn(column_t *column);
void R_SortVisSprites(void);
//faB: find sprites in wadfile, replace existing, add new ones
// (only sprites from namelist are added or replaced)
@@ -71,7 +71,19 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel);
void R_AddPrecipitationSprites(void);
void R_InitSprites(void);
void R_ClearSprites(void);
void R_DrawMasked(void);
/** Used to count the amount of masked elements
* per portal to later group them in separate
* drawnode lists.
*/
typedef struct
{
size_t drawsegs[2];
size_t vissprites[2];
fixed_t viewx, viewy, viewz; /**< View z stored at the time of the BSP traversal for the view/portal. Masked sorting/drawing needs it. */
sector_t* viewsector;
} maskcount_t;
void R_DrawMasked(maskcount_t* masks, INT32 nummasks);
boolean R_ThingVisible (mobj_t *thing);
boolean R_ThingWithinDist (mobj_t *thing, fixed_t limit_dist);
@@ -193,7 +205,7 @@ typedef struct vissprite_s
extern UINT32 visspritecount, numvisiblesprites;
void R_ClipSprites(void);
void R_ClipSprites(drawseg_t* dsstart, portal_t* portal);
UINT8 *R_GetSpriteTranslation(vissprite_t *vis);