From 46738de038a55bcecf978706647b83a86dea786a Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Oct 2024 00:30:51 +0200 Subject: [PATCH] Revert "refactor a bunch of crap and fix skyportals" This reverts commit d4c36c64fcb7b4e0a56e87450af53ad39edbc66d. --- src/r_bsp.c | 1 - src/r_bsp.h | 1 - src/r_main.c | 66 +++------------ src/r_plane.c | 56 ++++++++----- src/r_plane.h | 5 +- src/r_portal.c | 147 +++++++++++---------------------- src/r_portal.h | 15 +--- src/r_segs.c | 4 - src/r_state.h | 4 + src/r_things.c | 214 ++++++++++++++----------------------------------- src/r_things.h | 18 +---- 11 files changed, 167 insertions(+), 364 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index b037b8e53..04b213f7b 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -33,7 +33,6 @@ 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; diff --git a/src/r_bsp.h b/src/r_bsp.h index 49862b8be..f93541d7b 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -32,7 +32,6 @@ 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; diff --git a/src/r_main.c b/src/r_main.c index 18b893a27..7e4b86b3c 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1290,8 +1290,8 @@ static void R_PortalFrame(portal_t *portal) viewz = portal->viewz; viewangle = portal->viewangle; - viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); - viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); + // newview->sin = FINESINE(newview->angle>>ANGLETOFINESHIFT); + // newview->cos = FINECOSINE(newview->angle>>ANGLETOFINESHIFT); portalclipstart = portal->start; portalclipend = portal->end; @@ -1299,33 +1299,15 @@ static void R_PortalFrame(portal_t *portal) if (portal->clipline != -1) { portalclipline = &lines[portal->clipline]; - portalcullsector = portalclipline->frontsector; - viewsector = portalclipline->frontsector; + viewsector = portalcullsector = portalclipline->frontsector; } else { portalclipline = NULL; - portalcullsector = NULL; - viewsector = R_PointInSubsector(viewx, viewy)->sector; + viewsector = portalcullsector = 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 // ================ @@ -1338,9 +1320,6 @@ static void Mask_Post (maskcount_t* m) 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]]) { @@ -1393,26 +1372,18 @@ 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(drawsegs, NULL); + R_ClipSprites(); 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) @@ -1423,8 +1394,6 @@ void R_RenderPlayerView(player_t *player) { portalrender = portal->pass; // Recursiveness depth. - R_ClearFFloorClips(); - // Apply the viewpoint stored for the portal. R_PortalFrame(portal); @@ -1437,26 +1406,17 @@ 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); - Mask_Post(&masks[nummasks - 1]); - - portalskipprecipmobjs = false; - - R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal); + R_ClipSprites(); Portal_Remove(portal); + + validcount++; } + + portalcullsector = NULL; // Just in case... } PS_STOP_TIMING(ps_sw_portaltime); @@ -1469,10 +1429,8 @@ void R_RenderPlayerView(player_t *player) // draw mid texture and sprite // And now 3D floors/sides! PS_START_TIMING(ps_sw_maskedtime); - R_DrawMasked(masks, nummasks); + R_DrawMasked(); PS_STOP_TIMING(ps_sw_maskedtime); - - free(masks); } // ========================================================================= diff --git a/src/r_plane.c b/src/r_plane.c index d1f3a888e..7af5aff5b 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -41,7 +41,13 @@ // good night sweet prince //#define SHITPLANESPARENCY -visplane_t *visplanes[MAXVISPLANES]; +//SoM: 3/23/2000: Use Boom visplane hashing. +#define VISPLANEHASHBITS 9 +#define VISPLANEHASHMASK ((1<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); +} diff --git a/src/r_plane.h b/src/r_plane.h index 935fcd1ab..023cdaf09 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -18,7 +18,6 @@ #include "r_data.h" #include "p_polyobj.h" -//SoM: 3/23/2000: Use Boom visplane hashing. #define VISPLANEHASHBITS 9 #define VISPLANEHASHMASK ((1<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) @@ -73,12 +95,12 @@ void Portal_ClipApply (const portal_t* portal) } } -static portal_t* Portal_Add (const INT16 x1, const INT16 x2) +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 + 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); + 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); // Linked list. if (!portal_base) @@ -103,14 +125,11 @@ static 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); @@ -162,6 +181,8 @@ 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 } @@ -178,68 +199,26 @@ static void Portal_ClipVisplane (const visplane_t* plane, portal_t* portal) for (i = 0; i < end - start; i++) { - // 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->ceilingclip[i] = plane->top[i + start]; 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. */ -static void Portal_AddSkybox (const visplane_t* plane) +void Portal_AddSkybox (const visplane_t* plane) { - INT16 start, end; + INT16 start = plane->minx; + INT16 end = plane->maxx + 1; mapheader_t *mh; portal_t* portal; - if (TrimVisplaneBounds(plane, &start, &end)) + if (!(start < end)) return; portal = Portal_Add(start, end); @@ -248,9 +227,7 @@ static void Portal_AddSkybox (const visplane_t* plane) portal->viewx = skyboxmo[0]->x; portal->viewy = skyboxmo[0]->y; - portal->viewz = 0; - if (skyboxmo[0]->spawnpoint) - portal->viewz = ((fixed_t)skyboxmo[0]->spawnpoint->angle)<viewz = skyboxmo[0]->z; portal->viewangle = viewangle + skyboxmo[0]->angle; mh = mapheaderinfo[gamemap-1]; @@ -259,7 +236,6 @@ static 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; @@ -271,9 +247,8 @@ static void Portal_AddSkybox (const visplane_t* plane) else if (mh->skybox_scaley < 0) y = (viewy - skyboxmo[1]->y) * -mh->skybox_scaley; - // 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)); + portal->viewx += x; + portal->viewy += y; } if (mh->skybox_scalez > 0) @@ -282,36 +257,4 @@ static 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); } diff --git a/src/r_portal.h b/src/r_portal.h index e6271aa9f..e870681ec 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -11,12 +11,10 @@ /// \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. */ @@ -31,7 +29,6 @@ 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. @@ -45,19 +42,11 @@ 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 diff --git a/src/r_segs.c b/src/r_segs.c index 1bf873be8..6ef58e28e 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -15,7 +15,6 @@ #include "r_local.h" #include "r_sky.h" -#include "r_portal.h" #include "r_splats.h" #include "w_wad.h" @@ -1647,7 +1646,6 @@ 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) @@ -1655,7 +1653,6 @@ 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; } @@ -1708,7 +1705,6 @@ 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; diff --git a/src/r_state.h b/src/r_state.h index 63cfb5ff9..2df2ffbc6 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -92,6 +92,10 @@ 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; diff --git a/src/r_things.c b/src/r_things.c index 0e6e261ff..b6c9f90b2 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -25,7 +25,6 @@ #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_setup.h" @@ -2044,12 +2043,6 @@ 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++) @@ -2073,47 +2066,46 @@ void R_AddPrecipitationSprites(void) // // R_SortVisSprites // +static vissprite_t vsprsortedhead; -static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 end) +void R_SortVisSprites(void) { - UINT32 i, count = 0; + UINT32 i; vissprite_t *ds, *dsprev, *dsnext, *dsfirst; vissprite_t *best = NULL; vissprite_t unsorted; fixed_t bestscale; INT32 bestdispoffset; - dsfirst = &unsorted; - dsprev = dsfirst; - dsnext = dsfirst; + if (!visspritecount) + return; - I_Assert(start <= end); + unsorted.next = unsorted.prev = &unsorted; - for (i = start; i < end; ++i) + 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++) { - ds = R_GetVisSprite(i); + dsprev = ds; + ds = dsnext; + if (i < visspritecount - 1) dsnext = R_GetVisSprite(i + 1); - // 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++; + ds->next = dsnext; + ds->prev = dsprev; } - dsnext->next = dsfirst; - dsfirst->prev = dsnext; + // 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; // pull the vissprites out by scale - vsprsortedhead->next = vsprsortedhead->prev = vsprsortedhead; - for (i = 0; i < count; i++) + vsprsortedhead.next = vsprsortedhead.prev = &vsprsortedhead; + for (i = 0; i < visspritecount; i++) { bestscale = bestdispoffset = INT32_MAX; for (ds = unsorted.next; ds != &unsorted; ds = ds->next) @@ -2139,12 +2131,15 @@ static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 e best = ds; } } - best->next->prev = best->prev; - best->prev->next = best->next; - best->next = vsprsortedhead; - best->prev = vsprsortedhead->prev; - vsprsortedhead->prev->next = best; - vsprsortedhead->prev = best; + 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; + } } } @@ -2154,28 +2149,28 @@ static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 e static drawnode_t *R_CreateDrawNode(drawnode_t *link); static drawnode_t nodebankhead; +static drawnode_t nodehead; -static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean tempskip) +static void R_CreateDrawNodes(void) { 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 = drawsegs + mask->drawsegs[1]; ds-- > drawsegs + mask->drawsegs[0];) + for (ds = ds_p; ds-- > drawsegs ;) { if (ds->numthicksides) { for (i = 0; i < ds->numthicksides; i++) { - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->thickseg = ds; entry->ffloor = ds->thicksides[i]; } @@ -2191,7 +2186,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps else { // Put it in! - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->plane = plane; entry->seg = ds; } @@ -2199,7 +2194,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps } if (ds->maskedtexturecol) { - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->seg = ds; } if (ds->numffloorplanes) @@ -2231,7 +2226,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps } if (best != -1) { - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->plane = ds->ffloorplanes[best]; entry->seg = ds; ds->ffloorplanes[best] = NULL; @@ -2242,9 +2237,6 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps } } - 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 @@ -2260,18 +2252,16 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps PolyObjects[i].visplane = NULL; continue; } - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->plane = plane; // note: no seg is set, for what should be obvious reasons PolyObjects[i].visplane = NULL; } - // No vissprites in this mask? - if (mask->vissprites[1] - mask->vissprites[0] == 0) + if (visspritecount == 0) return; - R_SortVisSprites(&vsprsortedhead, mask->vissprites[0], mask->vissprites[1]); - + R_SortVisSprites(); for (rover = vsprsortedhead.prev; rover != &vsprsortedhead; rover = rover->prev) { if (rover->szt > vid.height || rover->sz < 0) @@ -2279,7 +2269,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps sintersect = (rover->x1 + rover->x2) / 2; - for (r2 = head->next; r2 != head; r2 = r2->next) + for (r2 = nodehead.next; r2 != &nodehead; r2 = r2->next) { if (r2->plane) { @@ -2418,9 +2408,9 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps } } } - if (r2 == head) + if (r2 == &nodehead) { - entry = R_CreateDrawNode(head); + entry = R_CreateDrawNode(&nodehead); entry->sprite = rover; } } @@ -2464,24 +2454,25 @@ static void R_DoneWithNode(drawnode_t *node) (node->prev = &nodebankhead)->next = node; } -static void R_ClearDrawNodes(drawnode_t* head) +static void R_ClearDrawNodes(void) { drawnode_t *rover; drawnode_t *next; - for (rover = head->next; rover != head;) + for (rover = nodehead.next; rover != &nodehead ;) { next = rover->next; R_DoneWithNode(rover); rover = next; } - head->next = head->prev = head; + nodehead.next = nodehead.prev = &nodehead; } void R_InitDrawNodes(void) { nodebankhead.next = nodebankhead.prev = &nodebankhead; + nodehead.next = nodehead.prev = &nodehead; } // @@ -2545,7 +2536,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, portal_t* portal) +static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) { drawseg_t *ds; INT32 x; @@ -2584,36 +2575,8 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port ds = curr->user; - 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; - } - } + if (ds->portalpass > 0 && ds->portalpass <= portalrender) + continue; // is a portal r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2; @@ -2764,34 +2727,11 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port 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(drawseg_t* dsstart, portal_t* portal) +void R_ClipSprites(void) { - const size_t maxdrawsegs = ds_p - dsstart; + const size_t maxdrawsegs = ds_p - drawsegs; const INT32 cx = viewwidth / 2; drawseg_t* ds; INT32 i; @@ -2824,7 +2764,7 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) } } - for (ds = ds_p; ds-- > dsstart;) + for (ds = ds_p; ds-- > drawsegs;) { if (ds->silhouette || ds->maskedtexturecol) { @@ -2878,7 +2818,7 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) drawsegs_xrange_count = drawsegs_xranges[0].count; } - R_ClipVisSprite(spr, spr->x1, spr->x2, portal); + R_ClipVisSprite(spr, spr->x1, spr->x2); if ((spr->cut & SC_NOTVISIBLE) == 0) numvisiblesprites++; @@ -2923,12 +2863,14 @@ boolean R_ThingWithinDist (mobj_t *thing, fixed_t limit_dist) // // R_DrawMasked // -static void R_DrawMaskedList (drawnode_t* head) +void R_DrawMasked(void) { drawnode_t *r2; drawnode_t *next; - for (r2 = head->next; r2 != head; r2 = r2->next) + R_CreateDrawNodes(); + + for (r2 = nodehead.next; r2 != &nodehead; r2 = r2->next) { if (r2->plane) { @@ -2966,39 +2908,7 @@ static void R_DrawMaskedList (drawnode_t* head) r2 = next; } } -} - -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); + R_ClearDrawNodes(); } // ========================================================================== diff --git a/src/r_things.h b/src/r_things.h index dd9509213..1af5d99bd 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -16,7 +16,6 @@ #include "sounds.h" #include "r_plane.h" -#include "r_portal.h" #include "r_patch.h" // "Left" and "Right" character symbols for additional rotation functionality @@ -64,6 +63,7 @@ fixed_t R_GetSpriteDirectionalLighting(angle_t angle); 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) @@ -74,19 +74,7 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel); void R_AddPrecipitationSprites(void); void R_InitSprites(void); void R_ClearSprites(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); +void R_DrawMasked(void); boolean R_ThingVisible (mobj_t *thing); boolean R_ThingWithinDist (mobj_t *thing, fixed_t limit_dist); @@ -208,7 +196,7 @@ typedef struct vissprite_s extern UINT32 visspritecount, numvisiblesprites; -void R_ClipSprites(drawseg_t* dsstart, portal_t* portal); +void R_ClipSprites(void); UINT8 *R_GetSpriteTranslation(vissprite_t *vis);