From 602701d6ddb42b85cb4779f7dacf1be81852c89a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 11 Jan 2018 16:55:42 +0000 Subject: [PATCH 01/14] G_DoPlayDemo: prepend srb2home to the demo name (if an external file) so that demos in custom home paths can be loaded --- src/d_netcmd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3696dd974..0d174548c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1452,7 +1452,12 @@ static void Command_Playdemo_f(void) CONS_Printf(M_GetText("Playing back demo '%s'.\n"), name); - G_DoPlayDemo(name); + // Internal if no extension, external if one exists + // If external, convert the file name to a path in SRB2's home directory + if (FIL_CheckExtension(name)) + G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)) + else + G_DoPlayDemo(name); } static void Command_Timedemo_f(void) From f1b8e122a20b61289844013786a68dfddd349330 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 12 Jan 2018 20:05:09 +0000 Subject: [PATCH 02/14] Fix missing semicolon --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0d174548c..82d2a33a8 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1455,7 +1455,7 @@ static void Command_Playdemo_f(void) // Internal if no extension, external if one exists // If external, convert the file name to a path in SRB2's home directory if (FIL_CheckExtension(name)) - G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)) + G_DoPlayDemo(va("%s"PATHSEP"%s", srb2home, name)); else G_DoPlayDemo(name); } From 0ef7aff5c0a847a46147ef525695c4361f12e8ac Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 16 Jan 2018 15:21:49 +0000 Subject: [PATCH 03/14] Prevent SV_SpawnPlayer from being able to freeze the game if gametic is 0. Additionally add a sanity check to prevent the loop going on more than necessary anyway This commit fixes -playdemo and -timedemo params for command line, allowing them to actually work again --- src/d_clisrv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d48f223c7..378b23f95 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4445,6 +4445,7 @@ static void Local_Maketic(INT32 realtics) void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) { tic_t tic; + UINT8 numadjust = 0; (void)x; (void)y; @@ -4454,7 +4455,21 @@ void SV_SpawnPlayer(INT32 playernum, INT32 x, INT32 y, angle_t angle) // spawning, but will be applied afterwards. for (tic = server ? maketic : (neededtic - 1); tic >= gametic; tic--) + { + if (numadjust++ == BACKUPTICS) + { + DEBFILE(va("SV_SpawnPlayer: All netcmds for player %d adjusted!\n", playernum)); + // We already adjusted them all, waste of time doing the same thing over and over + // This shouldn't happen normally though, either gametic was 0 (which is handled now anyway) + // or maketic >= gametic + BACKUPTICS + // -- Monster Iestyn 16/01/18 + break; + } netcmds[tic%BACKUPTICS][playernum].angleturn = (INT16)((angle>>16) | TICCMD_RECEIVED); + + if (!tic) // failsafe for gametic == 0 -- Monster Iestyn 16/01/18 + break; + } } // create missed tic From fa3998e942ca6600919ec5e594b11d1d1c2485ac Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 20 Jan 2018 21:18:16 +0000 Subject: [PATCH 04/14] Some fixes to prevent bad table key types causing Lua panic errors for joining players in netgames: * ArchiveTables: print an error if invalid key, to alert script author potentially * UnArchiveTables: if the key is found to be nil after reading key and value, print an error and don't set them in the table --- src/lua_script.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 167e4a0b4..ce0f19c14 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -767,11 +767,19 @@ static void ArchiveTables(void) lua_pushnil(gL); while (lua_next(gL, -2)) { - ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + // Write key + e = ArchiveValue(TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. + if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + { + lua_pushvalue(gL, -2); + CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -1), luaL_typename(gL, -1), i); + lua_pop(gL, 1); + } + // Write value e = ArchiveValue(TABLESINDEX, -1); if (e == 1) n++; // the table contained a new table we'll have to archive. :( - else if (e == 2) + else if (e == 2) // invalid value type { lua_pushvalue(gL, -2); CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -1), luaL_typename(gL, -1)); @@ -912,11 +920,17 @@ static void UnArchiveTables(void) lua_rawgeti(gL, TABLESINDEX, i); while (true) { - if (UnArchiveValue(TABLESINDEX) == 1) + if (UnArchiveValue(TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) + if (UnArchiveValue(TABLESINDEX) == 2) // read value n++; - lua_rawset(gL, -3); + if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) + { + CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); + lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors + } + else + lua_rawset(gL, -3); } lua_pop(gL, 1); } From f6c740840afc39ac0e450d47f9c399c55b552e01 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Jan 2018 19:18:17 +0000 Subject: [PATCH 05/14] Move sky plane-drawing code from R_DrawPlanes to a new function called by R_DrawSinglePlane This potentially allows FOFs and polyobjects to display sky flats on them properly, unless skyboxes are involved in which case they'd fail either way I also updated or added comments to some places of the sky drawing code and related where useful --- src/r_plane.c | 103 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 670152eda..1f7d30423 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -694,10 +694,10 @@ void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2) void R_DrawPlanes(void) { visplane_t *pl; - INT32 x; - INT32 angle; INT32 i; + // Note: are these two lines really needed? + // R_DrawSinglePlane and R_DrawSkyPlane do span/column drawer resets themselves anyway spanfunc = basespanfunc; wallcolfunc = walldrawerfunc; @@ -705,45 +705,6 @@ void R_DrawPlanes(void) { for (pl = visplanes[i]; pl; pl = pl->next) { - // sky flat - if (pl->picnum == skyflatnum) - { - if (!viewsky) - { - skyVisible = true; - continue; - } - - // use correct aspect ratio scale - dc_iscale = skyscale; - - // Sky is always drawn full bright, - // i.e. colormaps[0] is used. - // Because of this hack, sky is not affected - // by INVUL inverse mapping. - dc_colormap = colormaps; - dc_texturemid = skytexturemid; - dc_texheight = textureheight[skytexture] - >>FRACBITS; - for (x = pl->minx; x <= pl->maxx; x++) - { - dc_yl = pl->top[x]; - dc_yh = pl->bottom[x]; - - if (dc_yl <= dc_yh) - { - angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; - dc_iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); - dc_x = x; - dc_source = - R_GetColumn(texturetranslation[skytexture], - angle); - wallcolfunc(); - } - } - continue; - } - if (pl->ffloor != NULL #ifdef POLYOBJECTS_PLANES || pl->polyobj != NULL @@ -760,6 +721,59 @@ void R_DrawPlanes(void) #endif } +// R_DrawSkyPlane +// +// Draws the sky within the plane's top/bottom bounds +// Note: this uses column drawers instead of span drawers, since the sky is always a texture +// +static void R_DrawSkyPlane(visplane_t *pl) +{ + INT32 x; + INT32 angle; + + // If we're not supposed to draw the sky (e.g. for skyboxes), don't do anything! + // This probably utterly ruins sky rendering for FOFs and polyobjects, unfortunately + if (!viewsky) + { + // Mark that the sky was visible here for next tic + // (note: this is a hack and it sometimes can cause HOMs to appear for a tic IIRC) + skyVisible = true; + return; + } + + // Reset column drawer function (note: couldn't we just call walldrawerfunc directly?) + // (that is, unless we'll need to switch drawers in future for some reason) + wallcolfunc = walldrawerfunc; + + // use correct aspect ratio scale + dc_iscale = skyscale; + + // Sky is always drawn full bright, + // i.e. colormaps[0] is used. + // Because of this hack, sky is not affected + // by sector colormaps (INVUL inverse mapping is not implemented in SRB2 so is irrelevant). + dc_colormap = colormaps; + dc_texturemid = skytexturemid; + dc_texheight = textureheight[skytexture] + >>FRACBITS; + for (x = pl->minx; x <= pl->maxx; x++) + { + dc_yl = pl->top[x]; + dc_yh = pl->bottom[x]; + + if (dc_yl <= dc_yh) + { + angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; + dc_iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x]>>ANGLETOFINESHIFT)); + dc_x = x; + dc_source = + R_GetColumn(texturetranslation[skytexture], + angle); + wallcolfunc(); + } + } +} + void R_DrawSinglePlane(visplane_t *pl) { INT32 light = 0; @@ -771,6 +785,13 @@ void R_DrawSinglePlane(visplane_t *pl) if (!(pl->minx <= pl->maxx)) return; + // sky flat + if (pl->picnum == skyflatnum) + { + R_DrawSkyPlane(pl); + return; + } + #ifndef NOWATER itswater = false; #endif From 5c70d6e6cad16a76336ad65b1de36ff4e90d9ff2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Jan 2018 19:29:41 +0000 Subject: [PATCH 06/14] Fix skies in software being displayed backwards (I'll get round to OpenGL later) --- src/r_plane.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_plane.c b/src/r_plane.c index 1f7d30423..e87cf6fd3 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -768,7 +768,7 @@ static void R_DrawSkyPlane(visplane_t *pl) dc_x = x; dc_source = R_GetColumn(texturetranslation[skytexture], - angle); + -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 wallcolfunc(); } } From 7d150485c95d3d3e0207b5bb15af16d236ab01d3 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 28 Jan 2018 22:08:58 +0000 Subject: [PATCH 07/14] More sky fixes for software: * Thok barriers with slopes now render fine in software * The solid "sky walls" between different-height thok barriers adjacent to each other are gone. Forever. --- src/r_bsp.c | 49 +++++++++++--------- src/r_segs.c | 123 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 103 insertions(+), 69 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index ad4975cde..7fa6d0481 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -508,21 +508,26 @@ static void R_AddLine(seg_t *line) SLOPEPARAMS( backsector->f_slope, backf1, backf2, backsector->floorheight) SLOPEPARAMS( backsector->c_slope, backc1, backc2, backsector->ceilingheight) #undef SLOPEPARAMS - if ((backc1 <= frontf1 && backc2 <= frontf2) - || (backf1 >= frontc1 && backf2 >= frontc2)) + // if both ceilings are skies, consider it always "open" + if (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) { - goto clipsolid; + if ((backc1 <= frontf1 && backc2 <= frontf2) + || (backf1 >= frontc1 && backf2 >= frontc2)) + { + goto clipsolid; + } + + // Check for automap fix. Store in doorclosed for r_segs.c + doorclosed = (backc1 <= backf1 && backc2 <= backf2 + && ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture) + && ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture) + //&& (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) + ); + + if (doorclosed) + goto clipsolid; } - // Check for automap fix. Store in doorclosed for r_segs.c - doorclosed = (backc1 <= backf1 && backc2 <= backf2 - && ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture) - && ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture) - && (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum)); - - if (doorclosed) - goto clipsolid; - // Window. if (backc1 != frontc1 || backc2 != frontc2 || backf1 != frontf1 || backf2 != frontf2) @@ -533,16 +538,20 @@ static void R_AddLine(seg_t *line) else #endif { - if (backsector->ceilingheight <= frontsector->floorheight - || backsector->floorheight >= frontsector->ceilingheight) + // if both ceilings are skies, consider it always "open" + if (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) { - goto clipsolid; - } + if (backsector->ceilingheight <= frontsector->floorheight + || backsector->floorheight >= frontsector->ceilingheight) + { + goto clipsolid; + } - // Check for automap fix. Store in doorclosed for r_segs.c - doorclosed = R_DoorClosed(); - if (doorclosed) - goto clipsolid; + // Check for automap fix. Store in doorclosed for r_segs.c + doorclosed = R_DoorClosed(); + if (doorclosed) + goto clipsolid; + } // Window. if (backsector->ceilingheight != frontsector->ceilingheight diff --git a/src/r_segs.c b/src/r_segs.c index ecf707e0f..705122ca6 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2032,6 +2032,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) else { // two sided line + boolean bothceilingssky = false; // turned on if both back and front ceilings are sky #ifdef ESLOPE if (backsector->c_slope) { @@ -2063,10 +2064,11 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (frontsector->ceilingpic == skyflatnum && backsector->ceilingpic == skyflatnum) { + bothceilingssky = true; #ifdef ESLOPE - worldtopslope = worldhighslope = + //worldtopslope = worldhighslope; #endif - worldtop = worldhigh; + //worldtop = worldhigh; } ds_p->sprtopclip = ds_p->sprbottomclip = NULL; @@ -2099,58 +2101,65 @@ void R_StoreWallRange(INT32 start, INT32 stop) // ds_p->sprbottomclip = negonearray; } - if ( -#ifdef ESLOPE - worldtopslope < worldhighslope || -#endif - worldtop < worldhigh) + if (!bothceilingssky) { - ds_p->silhouette |= SIL_TOP; + if ( #ifdef ESLOPE - if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) + worldtopslope < worldhighslope || +#endif + worldtop < worldhigh) + { + ds_p->silhouette |= SIL_TOP; +#ifdef ESLOPE + if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) + ds_p->tsilheight = INT32_MIN; + else + ds_p->tsilheight = (frontsector->c_slope ? INT32_MIN : frontsector->ceilingheight); +#else + ds_p->tsilheight = frontsector->ceilingheight; +#endif + } +#ifdef ESLOPE + else if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) +#else + else if (backsector->ceilingheight < viewz) +#endif + { + ds_p->silhouette |= SIL_TOP; ds_p->tsilheight = INT32_MIN; - else - ds_p->tsilheight = (frontsector->c_slope ? INT32_MIN : frontsector->ceilingheight); -#else - ds_p->tsilheight = frontsector->ceilingheight; -#endif - } -#ifdef ESLOPE - else if ((backsector->c_slope ? P_GetZAt(backsector->c_slope, viewx, viewy) : backsector->ceilingheight) < viewz) -#else - else if (backsector->ceilingheight < viewz) -#endif - { - ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = INT32_MIN; - // ds_p->sprtopclip = screenheightarray; + // ds_p->sprtopclip = screenheightarray; + } } -#ifdef ESLOPE - if (worldhigh <= worldbottom && worldhighslope <= worldbottomslope) -#else - if (worldhigh <= worldbottom) -#endif + if (!bothceilingssky) { - ds_p->sprbottomclip = negonearray; - ds_p->bsilheight = INT32_MAX; - ds_p->silhouette |= SIL_BOTTOM; - } +#ifdef ESLOPE + if (worldhigh <= worldbottom && worldhighslope <= worldbottomslope) +#else + if (worldhigh <= worldbottom) +#endif + { + ds_p->sprbottomclip = negonearray; + ds_p->bsilheight = INT32_MAX; + ds_p->silhouette |= SIL_BOTTOM; + } #ifdef ESLOPE - if (worldlow >= worldtop && worldlowslope >= worldtopslope) + if (worldlow >= worldtop && worldlowslope >= worldtopslope) #else - if (worldlow >= worldtop) + if (worldlow >= worldtop) #endif - { - ds_p->sprtopclip = screenheightarray; - ds_p->tsilheight = INT32_MIN; - ds_p->silhouette |= SIL_TOP; + { + ds_p->sprtopclip = screenheightarray; + ds_p->tsilheight = INT32_MIN; + ds_p->silhouette |= SIL_TOP; + } } //SoM: 3/25/2000: This code fixes an automap bug that didn't check // frontsector->ceiling and backsector->floor to see if a door was closed. // Without the following code, sprites get displayed behind closed doors. + if (!bothceilingssky) { #ifdef ESLOPE if (doorclosed || (worldhigh <= worldbottom && worldhighslope <= worldbottomslope)) @@ -2200,7 +2209,14 @@ void R_StoreWallRange(INT32 start, INT32 stop) markfloor = false; } - if (worldhigh != worldtop + if (bothceilingssky) + { + // double ceiling skies are special + // we don't want to lower the ceiling clipping, (no new plane is drawn anyway) + // so we can see the floor of thok barriers always regardless of sector properties + markceiling = false; + } + else if (worldhigh != worldtop #ifdef ESLOPE || worldhighslope != worldtopslope || backsector->c_slope != frontsector->c_slope @@ -2226,19 +2242,28 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } - if (backsector->ceilingheight <= frontsector->floorheight || - backsector->floorheight >= frontsector->ceilingheight) + if (!bothceilingssky) { - // closed door - markceiling = markfloor = true; +#ifdef ESLOPE + if ((worldhigh <= worldbottom && worldhighslope <= worldbottomslope) + || (worldlow >= worldtop && worldlowslope >= worldtopslope)) +#else + if (backsector->ceilingheight <= frontsector->floorheight + || backsector->floorheight >= frontsector->ceilingheight) +#endif + { + // closed door + markceiling = markfloor = true; + } } // check TOP TEXTURE - if (worldhigh < worldtop + if (!bothceilingssky // never draw the top texture if on + && (worldhigh < worldtop #ifdef ESLOPE || worldhighslope < worldtopslope #endif - ) + )) { fixed_t texheight; // top texture @@ -2687,12 +2712,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) markfloor = false; } - if (( + if (frontsector->ceilingpic != skyflatnum + && ( #ifdef ESLOPE frontsector->c_slope ? P_GetZAt(frontsector->c_slope, viewx, viewy) : #endif - frontsector->ceilingheight) <= viewz && - frontsector->ceilingpic != skyflatnum) + frontsector->ceilingheight) <= viewz) { // below view plane markceiling = false; From 9e4c985d70eab4ca79889bc574ca9cd0f732182b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 Jan 2018 22:05:04 +0000 Subject: [PATCH 08/14] some cleanup of software's seg rendering code, moved Red's polyobject plane hack to R_StoreWallRange since it doesn't actually need to be done every column draw (I suspect polyobject planes don't actually need the minx/maxx hacks anymore, but I haven't the time to test that tonight nor is this branch really suited for it anyway) --- src/r_segs.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 705122ca6..200c8c81b 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1366,7 +1366,6 @@ static void R_RenderSegLoop (void) // mark floor / ceiling areas yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; - // no space above wall? top = ceilingclip[rw_x]+1; // no space above wall? @@ -1375,12 +1374,9 @@ static void R_RenderSegLoop (void) if (markceiling) { - bottom = yl-1; + bottom = yl > floorclip[rw_x] ? floorclip[rw_x] : yl; - if (bottom >= floorclip[rw_x]) - bottom = floorclip[rw_x]-1; - - if (top <= bottom) + if (top <= --bottom) { ceilingplane->top[rw_x] = (INT16)top; ceilingplane->bottom[rw_x] = (INT16)bottom; @@ -1397,24 +1393,13 @@ static void R_RenderSegLoop (void) if (markfloor) { -#if 0 // Old Doom Legacy code - bottom = floorclip[rw_x]-1; - if (top <= ceilingclip[rw_x]) - top = ceilingclip[rw_x]+1; - if (top <= bottom && floorplane) - { - floorplane->top[rw_x] = (INT16)top; - floorplane->bottom[rw_x] = (INT16)bottom; - } -#else // Spiffy new PRBoom code - top = yh < ceilingclip[rw_x] ? ceilingclip[rw_x] : yh; + top = yh < ceilingclip[rw_x] ? ceilingclip[rw_x] : yh; if (++top <= bottom && floorplane) { floorplane->top[rw_x] = (INT16)top; floorplane->bottom[rw_x] = (INT16)bottom; } -#endif } if (numffloors) @@ -1428,7 +1413,7 @@ static void R_RenderSegLoop (void) #ifdef POLYOBJECTS_PLANES if (ffloor[i].polyobj && (!curline->polyseg || ffloor[i].polyobj != curline->polyseg)) continue; - +/* // FIXME hack to fix planes disappearing when a seg goes behind the camera. This NEEDS to be changed to be done properly. -Red if (curline->polyseg) { if (ffloor[i].plane->minx > rw_x) @@ -1436,6 +1421,7 @@ static void R_RenderSegLoop (void) else if (ffloor[i].plane->maxx < rw_x) ffloor[i].plane->maxx = rw_x; } +*/ #endif if (ffloor[i].height < viewz) @@ -1451,7 +1437,7 @@ static void R_RenderSegLoop (void) #ifdef POLYOBJECTS_PLANES // Polyobject-specific hack to fix plane leaking -Red - if (curline->polyseg && ffloor[i].polyobj && ffloor[i].polyobj == curline->polyseg && top_w >= bottom_w) { + if (ffloor[i].polyobj && top_w >= bottom_w) { ffloor[i].plane->top[rw_x] = ffloor[i].plane->bottom[rw_x] = 0xFFFF; } else #endif @@ -1475,7 +1461,7 @@ static void R_RenderSegLoop (void) #ifdef POLYOBJECTS_PLANES // Polyobject-specific hack to fix plane leaking -Red - if (curline->polyseg && ffloor[i].polyobj && ffloor[i].polyobj == curline->polyseg && top_w >= bottom_w) { + if (ffloor[i].polyobj && top_w >= bottom_w) { ffloor[i].plane->top[rw_x] = ffloor[i].plane->bottom[rw_x] = 0xFFFF; } else #endif @@ -3175,6 +3161,22 @@ void R_StoreWallRange(INT32 start, INT32 stop) for (i = 0; i < numffloors; i++) R_ExpandPlane(ffloor[i].plane, rw_x, rw_stopx - 1); } +#ifdef POLYOBJECTS_PLANES + // FIXME hack to fix planes disappearing when a seg goes behind the camera. This NEEDS to be changed to be done properly. -Red + if (curline->polyseg) + { + for (i = 0; i < numffloors; i++) + { + if (!ffloor[i].polyobj || ffloor[i].polyobj != curline->polyseg) + continue; + if (ffloor[i].plane->minx > rw_x) + ffloor[i].plane->minx = rw_x; + + if (ffloor[i].plane->maxx < rw_stopx - 1) + ffloor[i].plane->maxx = rw_stopx - 1; + } + } +#endif } #ifdef WALLSPLATS From ecf2eed37f005f4eea9acff0ff51e0cf851c7451 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 1 Feb 2018 22:04:04 +0000 Subject: [PATCH 09/14] Pushing all my work to make OpenGL consistent with my changes to software's sky so far --- src/hardware/hw_main.c | 252 ++++++++++++++++++----------------------- 1 file changed, 111 insertions(+), 141 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 864cd04b6..dbc8faf20 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1409,9 +1409,9 @@ static void HWR_SplitFog(sector_t *sector, wallVert3D *wallVerts, FSurfaceInfo* HWR_AddTransparentWall(wallVerts, Surf, 0, PF_Translucent|PF_NoTexture, true, lightnum, colormap); } -// HWR_DrawSkyWalls +// HWR_DrawSkyWall // Draw walls into the depth buffer so that anything behind is culled properly -static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t bottom, fixed_t top) +static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf) { HWD.pfnSetTexture(NULL); // no texture @@ -1419,9 +1419,7 @@ static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t b wallVerts[0].t = wallVerts[1].t = 0; wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = 0; - // set top/bottom coords - wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(top); // No real way to find the correct height of this - wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(bottom); // worldlow/bottom because it needs to cover up the lower thok barrier wall + // this no longer sets top/bottom coords, this should be done before caling the function HWR_ProjectWall(wallVerts, Surf, PF_Invisible|PF_Clip|PF_NoTexture, 255, NULL); // PF_Invisible so it's not drawn into the colour buffer // PF_NoTexture for no texture @@ -1542,8 +1540,9 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) if (gr_backsector) { - INT32 gr_toptexture, gr_bottomtexture; + INT32 gr_toptexture = 0, gr_bottomtexture = 0; // two sided line + boolean bothceilingssky = false; // turned on if both back and front ceilings are sky #ifdef ESLOPE SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight) @@ -1559,13 +1558,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) if (gr_frontsector->ceilingpic == skyflatnum && gr_backsector->ceilingpic == skyflatnum) { - worldtop = worldhigh; + bothceilingssky = true; + //worldtop = worldhigh; #ifdef ESLOPE - worldtopslope = worldhighslope; + //worldtopslope = worldhighslope; #endif } - gr_toptexture = R_GetTextureNum(gr_sidedef->toptexture); + if (!bothceilingssky) + gr_toptexture = R_GetTextureNum(gr_sidedef->toptexture); gr_bottomtexture = R_GetTextureNum(gr_sidedef->bottomtexture); // check TOP TEXTURE @@ -2008,84 +2009,42 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) }*/ } - // Isn't this just the most lovely mess +#if 1 + // Sky culling + // No longer so much a mess as before! if (!gr_curline->polyseg) // Don't do it for polyobjects { - if (gr_frontsector->ceilingpic == skyflatnum || gr_backsector->ceilingpic == skyflatnum) + if (gr_frontsector->ceilingpic == skyflatnum) { - fixed_t depthwallheight; - - if (!gr_sidedef->toptexture || (gr_frontsector->ceilingpic == skyflatnum && gr_backsector->ceilingpic == skyflatnum)) // when both sectors are sky, the top texture isn't drawn - depthwallheight = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; - else - depthwallheight = gr_frontsector->ceilingheight > gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; - - if (gr_frontsector->ceilingheight-gr_frontsector->floorheight <= 0) // current sector is a thok barrier + if (gr_backsector->ceilingpic != skyflatnum) // don't cull if back sector is also sky { - if (gr_backsector->ceilingheight-gr_backsector->floorheight <= 0) // behind sector is also a thok barrier - { - if (!gr_sidedef->bottomtexture) // Only extend further down if there's no texture - HWR_DrawSkyWall(wallVerts, &Surf, worldbottom < worldlow ? worldbottom : worldlow, INT32_MAX); - else - HWR_DrawSkyWall(wallVerts, &Surf, worldbottom > worldlow ? worldbottom : worldlow, INT32_MAX); - } - // behind sector is not a thok barrier - else if (gr_backsector->ceilingheight <= gr_frontsector->ceilingheight) // behind sector ceiling is lower or equal to current sector - HWR_DrawSkyWall(wallVerts, &Surf, depthwallheight, INT32_MAX); - // gr_front/backsector heights need to be used here because of the worldtop being set to worldhigh earlier on - } - else if (gr_backsector->ceilingheight-gr_backsector->floorheight <= 0) // behind sector is a thok barrier, current sector is not - { - if (gr_backsector->ceilingheight >= gr_frontsector->ceilingheight // thok barrier ceiling height is equal to or greater than current sector ceiling height - || gr_backsector->floorheight <= gr_frontsector->floorheight // thok barrier ceiling height is equal to or less than current sector floor height - || gr_backsector->ceilingpic != skyflatnum) // thok barrier is not a sky - HWR_DrawSkyWall(wallVerts, &Surf, depthwallheight, INT32_MAX); - } - else // neither sectors are thok barriers - { - if ((gr_backsector->ceilingheight < gr_frontsector->ceilingheight && !gr_sidedef->toptexture) // no top texture and sector behind is lower - || gr_backsector->ceilingpic != skyflatnum) // behind sector is not a sky - HWR_DrawSkyWall(wallVerts, &Surf, depthwallheight, INT32_MAX); + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(INT32_MAX); // draw to top of map space +#ifdef ESLOPE + wallVerts[0].y = FIXED_TO_FLOAT(worldtop); + wallVerts[1].y = FIXED_TO_FLOAT(worldtopslope); +#else + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldtop); +#endif + HWR_DrawSkyWall(wallVerts, &Surf); } } - // And now for sky floors! - if (gr_frontsector->floorpic == skyflatnum || gr_backsector->floorpic == skyflatnum) + + if (gr_frontsector->floorpic == skyflatnum) { - fixed_t depthwallheight; - - if (!gr_sidedef->bottomtexture) - depthwallheight = worldbottom > worldlow ? worldbottom : worldlow; - else - depthwallheight = worldbottom < worldlow ? worldbottom : worldlow; - - if (gr_frontsector->ceilingheight-gr_frontsector->floorheight <= 0) // current sector is a thok barrier + if (gr_backsector->floorpic != skyflatnum) // don't cull if back sector is also sky { - if (gr_backsector->ceilingheight-gr_backsector->floorheight <= 0) // behind sector is also a thok barrier - { - if (!gr_sidedef->toptexture) // Only extend up if there's no texture - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, worldtop > worldhigh ? worldtop : worldhigh); - else - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, worldtop < worldhigh ? worldtop : worldhigh); - } - // behind sector is not a thok barrier - else if (gr_backsector->floorheight >= gr_frontsector->floorheight) // behind sector floor is greater or equal to current sector - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, depthwallheight); - } - else if (gr_backsector->ceilingheight-gr_backsector->floorheight <= 0) // behind sector is a thok barrier, current sector is not - { - if (gr_backsector->floorheight <= gr_frontsector->floorheight // thok barrier floor height is equal to or less than current sector floor height - || gr_backsector->ceilingheight >= gr_frontsector->ceilingheight // thok barrier floor height is equal to or greater than current sector ceiling height - || gr_backsector->floorpic != skyflatnum) // thok barrier is not a sky - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, depthwallheight); - } - else // neither sectors are thok barriers - { - if ((gr_backsector->floorheight > gr_frontsector->floorheight && !gr_sidedef->bottomtexture) // no bottom texture and sector behind is higher - || gr_backsector->floorpic != skyflatnum) // behind sector is not a sky - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, depthwallheight); +#ifdef ESLOPE + wallVerts[3].y = FIXED_TO_FLOAT(worldbottom); + wallVerts[2].y = FIXED_TO_FLOAT(worldbottomslope); +#else + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldbottom); +#endif + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(INT32_MIN); // draw to bottom of map space + HWR_DrawSkyWall(wallVerts, &Surf); } } } +#endif } else { @@ -2156,9 +2115,27 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) if (!gr_curline->polyseg) { if (gr_frontsector->ceilingpic == skyflatnum) // It's a single-sided line with sky for its sector - HWR_DrawSkyWall(wallVerts, &Surf, worldtop, INT32_MAX); + { + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(INT32_MAX); // draw to top of map space +#ifdef ESLOPE + wallVerts[0].y = FIXED_TO_FLOAT(worldtop); + wallVerts[1].y = FIXED_TO_FLOAT(worldtopslope); +#else + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldtop); +#endif + HWR_DrawSkyWall(wallVerts, &Surf); + } if (gr_frontsector->floorpic == skyflatnum) - HWR_DrawSkyWall(wallVerts, &Surf, INT32_MIN, worldbottom); + { +#ifdef ESLOPE + wallVerts[3].y = FIXED_TO_FLOAT(worldbottom); + wallVerts[2].y = FIXED_TO_FLOAT(worldbottomslope); +#else + wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldbottom); +#endif + wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(INT32_MIN); // draw to bottom of map space + HWR_DrawSkyWall(wallVerts, &Surf); + } } } @@ -2483,54 +2460,38 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks backf1 = backf2 = abacksector->floorheight; backc1 = backc2 = abacksector->ceilingheight; } - - // now check for closed sectors! - if (backc1 <= frontf1 && backc2 <= frontf2) + // properly render skies (consider door "open" if both ceilings are sky) + if (abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum) { - checkforemptylines = false; - if (!seg->sidedef->toptexture) - return false; - - if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) - return false; - - return true; - } - - if (backf1 >= frontc1 && backf2 >= frontc2) - { - checkforemptylines = false; - if (!seg->sidedef->bottomtexture) - return false; - - // properly render skies (consider door "open" if both floors are sky): - if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) - return false; - - return true; - } - - if (backc1 <= backf1 && backc2 <= backf2) - { - checkforemptylines = false; - // preserve a kind of transparent door/lift special effect: - if (backc1 < frontc1 || backc2 < frontc2) + // now check for closed sectors! + if (backc1 <= frontf1 && backc2 <= frontf2) { - if (!seg->sidedef->toptexture) - return false; + checkforemptylines = false; + //if (!seg->sidedef->toptexture) + //return false; + + return true; } - if (backf1 > frontf1 || backf2 > frontf2) + + if (backf1 >= frontc1 && backf2 >= frontc2) { - if (!seg->sidedef->bottomtexture) - return false; + checkforemptylines = false; + //if (!seg->sidedef->bottomtexture) + //return false; + + return true; } - if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) - return false; - if (abacksector->floorpic == skyflatnum && afrontsector->floorpic == skyflatnum) - return false; - - return true; + if (backc1 <= backf1 && backc2 <= backf2) + { + // preserve a kind of transparent door/lift special effect: + if (((backc1 >= frontc1 && backc2 >= frontc2) || seg->sidedef->toptexture) + && ((backf1 <= frontf1 && backf2 <= frontf2) || seg->sidedef->bottomtexture)) + { + checkforemptylines = false; + return true; + } + } } if (backc1 != frontc1 || backc2 != frontc2 @@ -3008,19 +2969,23 @@ static void HWR_AddLine(seg_t * line) SLOPEPARAMS( gr_backsector->c_slope, backc1, backc2, gr_backsector->ceilingheight) #undef SLOPEPARAMS - // Closed door. - if ((backc1 <= frontf1 && backc2 <= frontf2) - || (backf1 >= frontc1 && backf2 >= frontc2)) + if (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) { - goto clipsolid; - } + // Closed door. + if ((backc1 <= frontf1 && backc2 <= frontf2) + || (backf1 >= frontc1 && backf2 >= frontc2)) + { + goto clipsolid; + } - // Check for automap fix. - if (backc1 <= backf1 && backc2 <= backf2 - && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) - && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) - && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) - goto clipsolid; + // Check for automap fix. + if (backc1 <= backf1 && backc2 <= backf2 + && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) + && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) + //&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + ) + goto clipsolid; + } // Window. if (backc1 != frontc1 || backc2 != frontc2 @@ -3032,17 +2997,22 @@ static void HWR_AddLine(seg_t * line) else #endif { - // Closed door. - if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || - gr_backsector->floorheight >= gr_frontsector->ceilingheight) - goto clipsolid; - // Check for automap fix. - if (gr_backsector->ceilingheight <= gr_backsector->floorheight - && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) - && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) - && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) - goto clipsolid; + if (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + { + // Closed door. + if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || + gr_backsector->floorheight >= gr_frontsector->ceilingheight) + goto clipsolid; + + // Check for automap fix. + if (gr_backsector->ceilingheight <= gr_backsector->floorheight + && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) + && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) + //&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + ) + goto clipsolid; + } // Window. if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || From 0dc867c05e1f6bfe16c6e4ee7d6e7154a151eab5 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 3 Feb 2018 18:30:49 +0000 Subject: [PATCH 10/14] Cleanup of the code I've tweaked for skies, added SLOPEPARAMS macro to R_StoreWallRange for use in getting seg end z positions --- src/hardware/hw_main.c | 31 +++-------- src/r_bsp.c | 9 +--- src/r_segs.c | 120 ++++++++++++----------------------------- 3 files changed, 42 insertions(+), 118 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index dbc8faf20..042b8e90b 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1555,14 +1555,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // hack to allow height changes in outdoor areas // This is what gets rid of the upper textures if there should be sky - if (gr_frontsector->ceilingpic == skyflatnum && - gr_backsector->ceilingpic == skyflatnum) + if (gr_frontsector->ceilingpic == skyflatnum + && gr_backsector->ceilingpic == skyflatnum) { bothceilingssky = true; - //worldtop = worldhigh; -#ifdef ESLOPE - //worldtopslope = worldhighslope; -#endif } if (!bothceilingssky) @@ -2464,21 +2460,10 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum) { // now check for closed sectors! - if (backc1 <= frontf1 && backc2 <= frontf2) + if ((backc1 <= frontf1 && backc2 <= frontf2) + || (backf1 >= frontc1 && backf2 >= frontc2)) { checkforemptylines = false; - //if (!seg->sidedef->toptexture) - //return false; - - return true; - } - - if (backf1 >= frontc1 && backf2 >= frontc2) - { - checkforemptylines = false; - //if (!seg->sidedef->bottomtexture) - //return false; - return true; } @@ -2981,9 +2966,7 @@ static void HWR_AddLine(seg_t * line) // Check for automap fix. if (backc1 <= backf1 && backc2 <= backf2 && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) - && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) - //&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) - ) + && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture)) goto clipsolid; } @@ -3008,9 +2991,7 @@ static void HWR_AddLine(seg_t * line) // Check for automap fix. if (gr_backsector->ceilingheight <= gr_backsector->floorheight && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) - && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) - //&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) - ) + && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture)) goto clipsolid; } diff --git a/src/r_bsp.c b/src/r_bsp.c index 7fa6d0481..3cfad1549 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -220,10 +220,7 @@ static INT32 R_DoorClosed(void) // preserve a kind of transparent door/lift special effect: && (backsector->ceilingheight >= frontsector->ceilingheight || curline->sidedef->toptexture) - && (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture) - - // properly render skies (consider door "open" if both ceilings are sky): - && (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum); + && (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture); } // @@ -520,9 +517,7 @@ static void R_AddLine(seg_t *line) // Check for automap fix. Store in doorclosed for r_segs.c doorclosed = (backc1 <= backf1 && backc2 <= backf2 && ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture) - && ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture) - //&& (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) - ); + && ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture)); if (doorclosed) goto clipsolid; diff --git a/src/r_segs.c b/src/r_segs.c index 200c8c81b..6ed1417d8 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1894,29 +1894,26 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } - if (frontsector->c_slope) { - worldtop = P_GetZAt(frontsector->c_slope, segleft.x, segleft.y) - viewz; - worldtopslope = P_GetZAt(frontsector->c_slope, segright.x, segright.y) - viewz; - } else { - worldtopslope = -#else - { -#endif - worldtop = frontsector->ceilingheight - viewz; - } +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, segleft.x, segleft.y); \ + end2 = P_GetZAt(slope, segright.x, segright.y); \ + } else \ + end1 = end2 = normalheight; -#ifdef ESLOPE - if (frontsector->f_slope) { - worldbottom = P_GetZAt(frontsector->f_slope, segleft.x, segleft.y) - viewz; - worldbottomslope = P_GetZAt(frontsector->f_slope, segright.x, segright.y) - viewz; - } else { - worldbottomslope = + SLOPEPARAMS(frontsector->c_slope, worldtop, worldtopslope, frontsector->ceilingheight) + SLOPEPARAMS(frontsector->f_slope, worldbottom, worldbottomslope, frontsector->floorheight) + // subtract viewz from these to turn them into + // positions relative to the camera's z position + worldtop -= viewz; + worldtopslope -= viewz; + worldbottom -= viewz; + worldbottomslope -= viewz; #else - { + worldtop = frontsector->ceilingheight - viewz; + worldbottom = frontsector->floorheight - viewz; #endif - worldbottom = frontsector->floorheight - viewz; - } midtexture = toptexture = bottomtexture = maskedtexture = 0; ds_p->maskedtexturecol = NULL; @@ -2021,40 +2018,23 @@ void R_StoreWallRange(INT32 start, INT32 stop) boolean bothceilingssky = false; // turned on if both back and front ceilings are sky #ifdef ESLOPE - if (backsector->c_slope) { - worldhigh = P_GetZAt(backsector->c_slope, segleft.x, segleft.y) - viewz; - worldhighslope = P_GetZAt(backsector->c_slope, segright.x, segright.y) - viewz; - } else { - worldhighslope = + SLOPEPARAMS(backsector->c_slope, worldhigh, worldhighslope, backsector->ceilingheight) + SLOPEPARAMS(backsector->f_slope, worldlow, worldlowslope, backsector->floorheight) + worldhigh -= viewz; + worldhighslope -= viewz; + worldlow -= viewz; + worldlowslope -= viewz; #else - { + worldhigh = backsector->ceilingheight - viewz; + worldlow = backsector->floorheight - viewz; #endif - worldhigh = backsector->ceilingheight - viewz; - } - - -#ifdef ESLOPE - if (backsector->f_slope) { - worldlow = P_GetZAt(backsector->f_slope, segleft.x, segleft.y) - viewz; - worldlowslope = P_GetZAt(backsector->f_slope, segright.x, segright.y) - viewz; - } else { - worldlowslope = -#else - { -#endif - worldlow = backsector->floorheight - viewz; - } - // hack to allow height changes in outdoor areas + // This is what gets rid of the upper textures if there should be sky if (frontsector->ceilingpic == skyflatnum && backsector->ceilingpic == skyflatnum) { bothceilingssky = true; -#ifdef ESLOPE - //worldtopslope = worldhighslope; -#endif - //worldtop = worldhigh; } ds_p->sprtopclip = ds_p->sprbottomclip = NULL; @@ -2375,16 +2355,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) continue; #ifdef ESLOPE - if (*rover->t_slope) { - high1 = P_GetZAt(*rover->t_slope, segleft.x, segleft.y); - highslope1 = P_GetZAt(*rover->t_slope, segright.x, segright.y); - } else - high1 = highslope1 = *rover->topheight; - if (*rover->b_slope) { - low1 = P_GetZAt(*rover->b_slope, segleft.x, segleft.y); - lowslope1 = P_GetZAt(*rover->b_slope, segright.x, segright.y); - } else - low1 = lowslope1 = *rover->bottomheight; + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; @@ -2416,16 +2388,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) } #ifdef ESLOPE - if (*r2->t_slope) { - high2 = P_GetZAt(*r2->t_slope, segleft.x, segleft.y); - highslope2 = P_GetZAt(*r2->t_slope, segright.x, segright.y); - } else - high2 = highslope2 = *r2->topheight; - if (*r2->b_slope) { - low2 = P_GetZAt(*r2->b_slope, segleft.x, segleft.y); - lowslope2 = P_GetZAt(*r2->b_slope, segright.x, segright.y); - } else - low2 = lowslope2 = *r2->bottomheight; + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) continue; @@ -2458,16 +2422,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) continue; #ifdef ESLOPE - if (*rover->t_slope) { - high1 = P_GetZAt(*rover->t_slope, segleft.x, segleft.y); - highslope1 = P_GetZAt(*rover->t_slope, segright.x, segright.y); - } else - high1 = highslope1 = *rover->topheight; - if (*rover->b_slope) { - low1 = P_GetZAt(*rover->b_slope, segleft.x, segleft.y); - lowslope1 = P_GetZAt(*rover->b_slope, segright.x, segright.y); - } else - low1 = lowslope1 = *rover->bottomheight; + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) + SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) if ((high1 < lowcut && highslope1 < lowcutslope) || (low1 > highcut && lowslope1 > highcutslope)) continue; @@ -2499,17 +2455,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) } #ifdef ESLOPE - if (*r2->t_slope) { - high2 = P_GetZAt(*r2->t_slope, segleft.x, segleft.y); - highslope2 = P_GetZAt(*r2->t_slope, segright.x, segright.y); - } else - high2 = highslope2 = *r2->topheight; - if (*r2->b_slope) { - low2 = P_GetZAt(*r2->b_slope, segleft.x, segleft.y); - lowslope2 = P_GetZAt(*r2->b_slope, segright.x, segright.y); - } else - low2 = lowslope2 = *r2->bottomheight; - + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) +#undef SLOPEPARAMS if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) continue; if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) From 33a538383f633e5f6b8f3b5c15905e0552602383 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 3 Feb 2018 19:48:18 +0000 Subject: [PATCH 11/14] Added proper support for upside-down thok barriers, in both renderers Thankfully it was really just a copy+paste of the code I already tinkered with for the normal ceiling sky based thok barriers, but tweaked for floors instead --- src/hardware/hw_main.c | 27 +++++++++++---- src/r_bsp.c | 11 ++++-- src/r_segs.c | 79 ++++++++++++++++++++++++++---------------- 3 files changed, 78 insertions(+), 39 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 042b8e90b..610ad492b 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1543,6 +1543,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) INT32 gr_toptexture = 0, gr_bottomtexture = 0; // two sided line boolean bothceilingssky = false; // turned on if both back and front ceilings are sky + boolean bothfloorssky = false; // likewise, but for floors #ifdef ESLOPE SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight) @@ -1561,9 +1562,17 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) bothceilingssky = true; } + // likewise, but for floors and upper textures + if (gr_frontsector->floorpic == skyflatnum + && gr_backsector->floorpic == skyflatnum) + { + bothfloorssky = true; + } + if (!bothceilingssky) gr_toptexture = R_GetTextureNum(gr_sidedef->toptexture); - gr_bottomtexture = R_GetTextureNum(gr_sidedef->bottomtexture); + if (!bothfloorssky) + gr_bottomtexture = R_GetTextureNum(gr_sidedef->bottomtexture); // check TOP TEXTURE if (( @@ -2457,7 +2466,9 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks backc1 = backc2 = abacksector->ceilingheight; } // properly render skies (consider door "open" if both ceilings are sky) - if (abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum) + // same for floors + if ((abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum) + && (abacksector->floorpic != skyflatnum || afrontsector->floorpic != skyflatnum)) { // now check for closed sectors! if ((backc1 <= frontf1 && backc2 <= frontf2) @@ -2953,8 +2964,10 @@ static void HWR_AddLine(seg_t * line) SLOPEPARAMS( gr_backsector->f_slope, backf1, backf2, gr_backsector->floorheight) SLOPEPARAMS( gr_backsector->c_slope, backc1, backc2, gr_backsector->ceilingheight) #undef SLOPEPARAMS - - if (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + // if both ceilings are skies, consider it always "open" + // same for floors + if ((gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + && (gr_backsector->floorpic != skyflatnum || gr_frontsector->floorpic != skyflatnum)) { // Closed door. if ((backc1 <= frontf1 && backc2 <= frontf2) @@ -2980,8 +2993,10 @@ static void HWR_AddLine(seg_t * line) else #endif { - - if (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + // if both ceilings are skies, consider it always "open" + // same for floors + if ((gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) + && (gr_backsector->floorpic != skyflatnum || gr_frontsector->floorpic != skyflatnum)) { // Closed door. if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || diff --git a/src/r_bsp.c b/src/r_bsp.c index 3cfad1549..5b0a4ca36 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -506,7 +506,9 @@ static void R_AddLine(seg_t *line) SLOPEPARAMS( backsector->c_slope, backc1, backc2, backsector->ceilingheight) #undef SLOPEPARAMS // if both ceilings are skies, consider it always "open" - if (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) + // same for floors + if ((backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) + && (backsector->floorpic != skyflatnum || frontsector->floorpic != skyflatnum)) { if ((backc1 <= frontf1 && backc2 <= frontf2) || (backf1 >= frontc1 && backf2 >= frontc2)) @@ -534,7 +536,9 @@ static void R_AddLine(seg_t *line) #endif { // if both ceilings are skies, consider it always "open" - if (backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) + // same for floors + if ((backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) + && (backsector->floorpic != skyflatnum || frontsector->floorpic != skyflatnum)) { if (backsector->ceilingheight <= frontsector->floorheight || backsector->floorheight >= frontsector->ceilingheight) @@ -926,7 +930,8 @@ static void R_Subsector(size_t num) #ifdef ESLOPE frontsector->f_slope ? P_GetZAt(frontsector->f_slope, viewx, viewy) : #endif - frontsector->floorheight) < viewz || (frontsector->heightsec != -1 + frontsector->floorheight) < viewz || frontsector->floorpic == skyflatnum + || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum))) { floorplane = R_FindPlane(frontsector->floorheight, frontsector->floorpic, floorlightlevel, diff --git a/src/r_segs.c b/src/r_segs.c index 6ed1417d8..ff3a956ad 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2016,6 +2016,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) { // two sided line boolean bothceilingssky = false; // turned on if both back and front ceilings are sky + boolean bothfloorssky = false; // likewise, but for floors #ifdef ESLOPE SLOPEPARAMS(backsector->c_slope, worldhigh, worldhighslope, backsector->ceilingheight) @@ -2037,34 +2038,44 @@ void R_StoreWallRange(INT32 start, INT32 stop) bothceilingssky = true; } + // likewise, but for floors and upper textures + if (frontsector->floorpic == skyflatnum + && backsector->floorpic == skyflatnum) + { + bothfloorssky = true; + } + ds_p->sprtopclip = ds_p->sprbottomclip = NULL; ds_p->silhouette = 0; - if ( -#ifdef ESLOPE - worldbottomslope > worldlowslope || -#endif - worldbottom > worldlow) + if (!bothfloorssky) { - ds_p->silhouette = SIL_BOTTOM; + if ( #ifdef ESLOPE - if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) + worldbottomslope > worldlowslope || +#endif + worldbottom > worldlow) + { + ds_p->silhouette = SIL_BOTTOM; +#ifdef ESLOPE + if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) + ds_p->bsilheight = INT32_MAX; + else + ds_p->bsilheight = (frontsector->f_slope ? INT32_MAX : frontsector->floorheight); +#else + ds_p->bsilheight = frontsector->floorheight; +#endif + } +#ifdef ESLOPE + else if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) +#else + else if (backsector->floorheight > viewz) +#endif + { + ds_p->silhouette = SIL_BOTTOM; ds_p->bsilheight = INT32_MAX; - else - ds_p->bsilheight = (frontsector->f_slope ? INT32_MAX : frontsector->floorheight); -#else - ds_p->bsilheight = frontsector->floorheight; -#endif - } -#ifdef ESLOPE - else if ((backsector->f_slope ? P_GetZAt(backsector->f_slope, viewx, viewy) : backsector->floorheight) > viewz) -#else - else if (backsector->floorheight > viewz) -#endif - { - ds_p->silhouette = SIL_BOTTOM; - ds_p->bsilheight = INT32_MAX; - // ds_p->sprbottomclip = negonearray; + // ds_p->sprbottomclip = negonearray; + } } if (!bothceilingssky) @@ -2097,7 +2108,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } - if (!bothceilingssky) + if (!bothceilingssky && !bothfloorssky) { #ifdef ESLOPE if (worldhigh <= worldbottom && worldhighslope <= worldbottomslope) @@ -2125,7 +2136,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) //SoM: 3/25/2000: This code fixes an automap bug that didn't check // frontsector->ceiling and backsector->floor to see if a door was closed. // Without the following code, sprites get displayed behind closed doors. - if (!bothceilingssky) + if (!bothceilingssky && !bothfloorssky) { #ifdef ESLOPE if (doorclosed || (worldhigh <= worldbottom && worldhighslope <= worldbottomslope)) @@ -2149,7 +2160,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } - if (worldlow != worldbottom + if (bothfloorssky) + { + // see double ceiling skies comment + // this is the same but for upside down thok barriers where the floor is sky and the ceiling is normal + markfloor = false; + } + else if (worldlow != worldbottom #ifdef ESLOPE || worldlowslope != worldbottomslope || backsector->f_slope != frontsector->f_slope @@ -2161,7 +2178,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || backsector->floor_yoffs != frontsector->floor_yoffs || backsector->floorpic_angle != frontsector->floorpic_angle //SoM: 3/22/2000: Prevents bleeding. - || frontsector->heightsec != -1 + || (frontsector->heightsec != -1 && frontsector->floorpic != skyflatnum) || backsector->floorlightsec != frontsector->floorlightsec //SoM: 4/3/2000: Check for colormaps || frontsector->extra_colormap != backsector->extra_colormap @@ -2208,7 +2225,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } - if (!bothceilingssky) + if (!bothceilingssky && !bothfloorssky) { #ifdef ESLOPE if ((worldhigh <= worldbottom && worldhighslope <= worldbottomslope) @@ -2278,11 +2295,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) } } // check BOTTOM TEXTURE - if (worldlow > worldbottom + if (!bothfloorssky // never draw the bottom texture if on + && (worldlow > worldbottom #ifdef ESLOPE || worldlowslope > worldbottomslope #endif - ) //seulement si VISIBLE!!! + )) //seulement si VISIBLE!!! { // bottom texture bottomtexture = R_GetTextureNum(sidedef->bottomtexture); @@ -2636,7 +2654,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) // and doesn't need to be marked. if (frontsector->heightsec == -1) { - if (( + if (frontsector->floorpic != skyflatnum + && ( #ifdef ESLOPE frontsector->f_slope ? P_GetZAt(frontsector->f_slope, viewx, viewy) : #endif From 493af49a000034bf45c68a9319280a5b1d37dd84 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 3 Feb 2018 21:39:36 +0000 Subject: [PATCH 12/14] Correct backwards skies for OpenGL too --- src/hardware/hw_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 610ad492b..44da2b9f2 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5487,8 +5487,9 @@ static void HWR_DrawSkyBackground(player_t *player) dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->width/256.0f); - v[0].sow = v[3].sow = ((float) angle / ((ANGLE_90-1)*dimensionmultiply)); - v[2].sow = v[1].sow = (-1.0f/dimensionmultiply)+((float) angle / ((ANGLE_90-1)*dimensionmultiply)); + v[0].sow = v[3].sow = ((float) (-angle) / ((ANGLE_90-1)*dimensionmultiply)); // left + v[2].sow = v[1].sow = v[0].sow + (1.0f/dimensionmultiply); // right (or left + 1.0f) + // use +angle and -1.0f above instead if you wanted old backwards behavior // Y angle = aimingangle; @@ -5502,13 +5503,13 @@ static void HWR_DrawSkyBackground(player_t *player) if (atransform.flip) { // During vertical flip the sky should be flipped and it's y movement should also be flipped obviously - v[3].tow = v[2].tow = -(0.5f-(0.5f/dimensionmultiply)); - v[0].tow = v[1].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + v[3].tow = v[2].tow = -(0.5f-(0.5f/dimensionmultiply)); // top + v[0].tow = v[1].tow = v[3].tow - (1.0f/dimensionmultiply); // bottom (or top - 1.0f) } else { - v[3].tow = v[2].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); - v[0].tow = v[1].tow = -(0.5f-(0.5f/dimensionmultiply)); + v[0].tow = v[1].tow = -(0.5f-(0.5f/dimensionmultiply)); // bottom + v[3].tow = v[2].tow = v[0].tow - (1.0f/dimensionmultiply); // top (or bottom - 1.0f) } if (angle > ANGLE_180) // Do this because we don't want the sky to suddenly teleport when crossing over 0 to 360 and vice versa From efe9204f78b1e9dc03ec498bf018535f434d8c19 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Feb 2018 17:46:01 +0000 Subject: [PATCH 13/14] Fixed sky-sky thok barriers showing HOM (turns out the floor and ceiling share the same plane, so I've modified the code to account for this) Additionally, place some optimisations in both software and OpenGL; in particular one has been added for when all of back and front sector (floor and ceiling) is sky: since everything is "open" anyway, we can simply the usual checks involved. --- src/hardware/hw_main.c | 91 ++++++++++++++++++++++++++++++++++-------- src/r_bsp.c | 48 +++++++++++++++------- src/r_segs.c | 43 +++++++++++--------- 3 files changed, 133 insertions(+), 49 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 44da2b9f2..597990a62 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2433,6 +2433,12 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks { fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends + boolean bothceilingssky = false, bothfloorssky = false; + + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + bothceilingssky = true; + if (abacksector->floorpic == skyflatnum && afrontsector->floorpic == skyflatnum) + bothfloorssky = true; // GZDoom method of sloped line clipping @@ -2467,8 +2473,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks } // properly render skies (consider door "open" if both ceilings are sky) // same for floors - if ((abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum) - && (abacksector->floorpic != skyflatnum || afrontsector->floorpic != skyflatnum)) + if (!bothceilingssky && !bothfloorssky) { // now check for closed sectors! if ((backc1 <= frontf1 && backc2 <= frontf2) @@ -2490,12 +2495,21 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks } } - if (backc1 != frontc1 || backc2 != frontc2 - || backf1 != frontf1 || backf2 != frontf2) + if (!bothceilingssky) { + if (backc1 != frontc1 || backc2 != frontc2) { checkforemptylines = false; return false; } + } + + if (!bothfloorssky) { + if (backf1 != frontf1 || backf2 != frontf2) + { + checkforemptylines = false; + return false; + } + } return false; } @@ -2798,6 +2812,7 @@ static void HWR_AddLine(seg_t * line) #ifndef NEWCLIP INT32 x1, x2; angle_t span, tspan; + boolean bothceilingssky = false, bothfloorssky = false; #endif // SoM: Backsector needs to be run through R_FakeFlat @@ -2923,7 +2938,30 @@ static void HWR_AddLine(seg_t * line) } else { + boolean bothceilingssky = false, bothfloorssky = false; + gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); + + if (gr_backsector->ceilingpic == skyflatnum && gr_frontsector->ceilingpic == skyflatnum) + bothceilingssky = true; + if (gr_backsector->floorpic == skyflatnum && gr_frontsector->floorpic == skyflatnum) + bothfloorssky = true; + + if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then + { + if ( +#ifdef POLYOBJECTS + !line->polyseg && +#endif + !line->sidedef->midtexture + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || (gr_frontsector->tag == gr_backsector->tag))) + return; // line is empty, don't even bother + // treat like wide open window instead + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; + } + if (CheckClip(line, gr_frontsector, gr_backsector)) { gld_clipper_SafeAddClipRange(angle2, angle1); @@ -2946,6 +2984,25 @@ static void HWR_AddLine(seg_t * line) gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); + if (gr_backsector->ceilingpic == skyflatnum && gr_frontsector->ceilingpic == skyflatnum) + bothceilingssky = true; + if (gr_backsector->floorpic == skyflatnum && gr_frontsector->floorpic == skyflatnum) + bothfloorssky = true; + + if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then + { + if ( +#ifdef POLYOBJECTS + !line->polyseg && +#endif + !line->sidedef->midtexture + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || (gr_frontsector->tag == gr_backsector->tag))) + return; // line is empty, don't even bother + + goto clippass; // treat like wide open window instead + } + #ifdef ESLOPE if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) { @@ -2966,8 +3023,7 @@ static void HWR_AddLine(seg_t * line) #undef SLOPEPARAMS // if both ceilings are skies, consider it always "open" // same for floors - if ((gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) - && (gr_backsector->floorpic != skyflatnum || gr_frontsector->floorpic != skyflatnum)) + if (!bothceilingssky && !bothfloorssky) { // Closed door. if ((backc1 <= frontf1 && backc2 <= frontf2) @@ -2984,19 +3040,19 @@ static void HWR_AddLine(seg_t * line) } // Window. - if (backc1 != frontc1 || backc2 != frontc2 - || backf1 != frontf1 || backf2 != frontf2) - { - goto clippass; - } + 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; } else #endif { // if both ceilings are skies, consider it always "open" // same for floors - if ((gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum) - && (gr_backsector->floorpic != skyflatnum || gr_frontsector->floorpic != skyflatnum)) + if (!bothceilingssky && !bothfloorssky) { // Closed door. if (gr_backsector->ceilingheight <= gr_frontsector->floorheight || @@ -3011,9 +3067,12 @@ static void HWR_AddLine(seg_t * line) } // Window. - if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || - gr_backsector->floorheight != gr_frontsector->floorheight) - goto clippass; + if (!bothceilingssky) // ceilings are always the "same" when sky + if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight) + goto clippass; + if (!bothfloorssky) // floors are always the "same" when sky + if (gr_backsector->floorheight != gr_frontsector->floorheight) + goto clippass; } // Reject empty lines used for triggers and special events. diff --git a/src/r_bsp.c b/src/r_bsp.c index 5b0a4ca36..183def25a 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -401,6 +401,7 @@ static void R_AddLine(seg_t *line) INT32 x1, x2; angle_t angle1, angle2, span, tspan; static sector_t tempsec; // ceiling/water hack + boolean bothceilingssky = false, bothfloorssky = false; if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; @@ -487,6 +488,25 @@ static void R_AddLine(seg_t *line) doorclosed = 0; + if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum) + bothceilingssky = true; + if (backsector->floorpic == skyflatnum && frontsector->floorpic == skyflatnum) + bothfloorssky = true; + + if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then + { + if ( +#ifdef POLYOBJECTS + !line->polyseg && +#endif + !line->sidedef->midtexture + && ((!frontsector->ffloors && !backsector->ffloors) + || (frontsector->tag == backsector->tag))) + return; // line is empty, don't even bother + + goto clippass; // treat like wide open window instead + } + // Closed door. #ifdef ESLOPE if (frontsector->f_slope || frontsector->c_slope || backsector->f_slope || backsector->c_slope) @@ -507,8 +527,7 @@ static void R_AddLine(seg_t *line) #undef SLOPEPARAMS // if both ceilings are skies, consider it always "open" // same for floors - if ((backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) - && (backsector->floorpic != skyflatnum || frontsector->floorpic != skyflatnum)) + if (!bothceilingssky && !bothfloorssky) { if ((backc1 <= frontf1 && backc2 <= frontf2) || (backf1 >= frontc1 && backf2 >= frontc2)) @@ -526,19 +545,19 @@ static void R_AddLine(seg_t *line) } // Window. - if (backc1 != frontc1 || backc2 != frontc2 - || backf1 != frontf1 || backf2 != frontf2) - { - goto clippass; - } + 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; } else #endif { // if both ceilings are skies, consider it always "open" // same for floors - if ((backsector->ceilingpic != skyflatnum || frontsector->ceilingpic != skyflatnum) - && (backsector->floorpic != skyflatnum || frontsector->floorpic != skyflatnum)) + if (!bothceilingssky && !bothfloorssky) { if (backsector->ceilingheight <= frontsector->floorheight || backsector->floorheight >= frontsector->ceilingheight) @@ -553,11 +572,12 @@ static void R_AddLine(seg_t *line) } // Window. - if (backsector->ceilingheight != frontsector->ceilingheight - || backsector->floorheight != frontsector->floorheight) - { - goto clippass; - } + 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; } // Reject empty lines used for triggers and special events. diff --git a/src/r_segs.c b/src/r_segs.c index ff3a956ad..5395f414a 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1321,6 +1321,18 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) #undef CLAMPMIN } +// R_ExpandPlaneY +// +// A simple function to modify a vsplane's top and bottom for a particular column +// Sort of like R_ExpandPlane in r_plane.c, except this is vertical expansion +static inline void R_ExpandPlaneY(visplane_t *pl, INT32 x, INT16 top, INT16 bottom) +{ + // Expand the plane, don't shrink it! + // note: top and bottom default to 0xFFFF and 0x0000 respectively, which is totally compatible with this + if (pl->top[x] > top) pl->top[x] = top; + if (pl->bottom[x] < bottom) pl->bottom[x] = bottom; +} + // // R_RenderSegLoop // Draws zero, one, or two textures (and possibly a masked @@ -1344,7 +1356,6 @@ UINT32 nombre = 100000; #endif //profile stuff --------------------------------------------------------- - static void R_RenderSegLoop (void) { angle_t angle; @@ -1374,13 +1385,19 @@ static void R_RenderSegLoop (void) if (markceiling) { +#if 0 + bottom = yl-1; + + if (bottom >= floorclip[rw_x]) + bottom = floorclip[rw_x]-1; + + if (top <= bottom) +#else bottom = yl > floorclip[rw_x] ? floorclip[rw_x] : yl; - if (top <= --bottom) - { - ceilingplane->top[rw_x] = (INT16)top; - ceilingplane->bottom[rw_x] = (INT16)bottom; - } + if (top <= --bottom && ceilingplane) +#endif + R_ExpandPlaneY(ceilingplane, rw_x, top, bottom); } @@ -1396,10 +1413,7 @@ static void R_RenderSegLoop (void) top = yh < ceilingclip[rw_x] ? ceilingclip[rw_x] : yh; if (++top <= bottom && floorplane) - { - floorplane->top[rw_x] = (INT16)top; - floorplane->bottom[rw_x] = (INT16)bottom; - } + R_ExpandPlaneY(floorplane, rw_x, top, bottom); } if (numffloors) @@ -1413,15 +1427,6 @@ static void R_RenderSegLoop (void) #ifdef POLYOBJECTS_PLANES if (ffloor[i].polyobj && (!curline->polyseg || ffloor[i].polyobj != curline->polyseg)) continue; -/* - // FIXME hack to fix planes disappearing when a seg goes behind the camera. This NEEDS to be changed to be done properly. -Red - if (curline->polyseg) { - if (ffloor[i].plane->minx > rw_x) - ffloor[i].plane->minx = rw_x; - else if (ffloor[i].plane->maxx < rw_x) - ffloor[i].plane->maxx = rw_x; - } -*/ #endif if (ffloor[i].height < viewz) From fbd4ce1d473a6f41f9a579e5c7316f39c9140c4b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Feb 2018 18:11:32 +0000 Subject: [PATCH 14/14] optimised R_ExpandPlane too --- src/r_plane.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index e87cf6fd3..bc510bbb5 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -625,7 +625,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) // overlap. void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) { - INT32 unionl, unionh; +// INT32 unionl, unionh; // INT32 x; #ifdef POLYOBJECTS_PLANES @@ -634,6 +634,9 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) return; #endif + if (pl->minx > start) pl->minx = start; + if (pl->maxx < stop) pl->maxx = stop; +/* if (start < pl->minx) { unionl = start; @@ -651,15 +654,16 @@ void R_ExpandPlane(visplane_t *pl, INT32 start, INT32 stop) { unionh = pl->maxx; } -/* for (x = start; x <= stop; x++) if (pl->top[x] != 0xffff || pl->bottom[x] != 0x0000) break; if (x <= stop) I_Error("R_ExpandPlane: planes in same subsector overlap?!\nminx: %d, maxx: %d, start: %d, stop: %d\n", pl->minx, pl->maxx, start, stop); -*/ + pl->minx = unionl, pl->maxx = unionh; +*/ + } //