From 24da82f02640dd55bc3e4f2d31ceb33357619dfc Mon Sep 17 00:00:00 2001 From: yellowtd Date: Sat, 16 Jan 2016 23:10:38 -0500 Subject: [PATCH 01/29] Begin work on OGL slope support unfinished --- src/hardware/hw_main.c | 210 ++++++++++++++++++++++++++++++++++------- 1 file changed, 175 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7d6caa049..63936b178 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -39,7 +39,9 @@ #include "../st_stuff.h" #include "../i_system.h" #include "../m_cheat.h" - +#ifdef ESLOPE +#include "../p_slopes.h" +#endif #include "hw_md2.h" #define R_FAKEFLOORS @@ -535,6 +537,9 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi angle_t angle = 0; FSurfaceInfo Surf; fixed_t tempxsow, tempytow; +#ifdef ESLOPE + pslope_t *slope = NULL; +#endif static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; @@ -543,6 +548,30 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi if (!xsub->planepoly) return; +#ifdef ESLOPE + // Get the slope pointer to simplify future code + if (sector) + { + // Yes this fixedheight check is needed again here + if (sector->f_slope && sector->floorheight == fixedheight) + slope = sector->f_slope; + else if (sector->c_slope && sector->ceilingheight == fixedheight) + slope = sector->c_slope; + } + else if (FOFsector) + { + // Yes this fixedheight check is needed again here + if (FOFsector->f_slope && FOFsector->floorheight == fixedheight) + slope = FOFsector->f_slope; + else if (FOFsector->c_slope && FOFsector->ceilingheight == fixedheight) + slope = FOFsector->c_slope; + } + + // Set fixedheight to the slope's height from our viewpoint, if we have a slope + if (slope) + fixedheight = P_GetZAt(slope, viewx, viewy); +#endif + height = FIXED_TO_FLOAT(fixedheight); pv = xsub->planepoly->pts; @@ -608,7 +637,12 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi if (FOFsector != NULL) { +#ifdef ESLOPE + if ((slope && slope == FOFsector->f_slope) + || fixedheight == FOFsector->floorheight) // it's a floor +#else if (fixedheight == FOFsector->floorheight) // it's a floor +#endif { scrollx = FIXED_TO_FLOAT(FOFsector->floor_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(FOFsector->floor_yoffs)/fflatsize; @@ -678,24 +712,13 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi v3d->x = pv->x; v3d->y = height; v3d->z = pv->y; -#ifdef SLOPENESS - if (sector && sector->special == 65535) - { - size_t q; - for (q = 0; q < sector->linecount; q++) - { - if (v3d->x == sector->lines[q]->v1->x>>FRACBITS) - { - if (v3d->z == sector->lines[q]->v1->y>>FRACBITS) - { - v3d->y += sector->lines[q]->v1->z>>FRACBITS; - break; - } - } - } - } -#else - (void)sector; + +#ifdef ESLOPE + if (slope) + { + fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED(pv->x), FLOAT_TO_FIXED(pv->y)); + v3d->y = FIXED_TO_FLOAT(fixedheight); + } #endif } @@ -714,6 +737,11 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi { sector_t *psector = gr_frontsector; +#ifdef ESLOPE + if (slope) + fixedheight = P_GetZAt(slope, psector->soundorg.x, psector->soundorg.y); +#endif + if (psector->ffloors) { ffloor_t *caster = psector->lightlist[R_GetPlaneLight(psector, fixedheight, false)].caster; @@ -1321,6 +1349,11 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) fixed_t worldtop, worldbottom; fixed_t worldhigh = 0, worldlow = 0; +#ifdef ESLOPE + fixed_t worldtopslope, worldbottomslope; + fixed_t worldhighslope = 0, worldlowslope = 0; + fixed_t v1x, v1y, v2x, v2y; +#endif GLTexture_t *grTex = NULL; float cliplow = 0.0f, cliphigh = 0.0f; @@ -1337,22 +1370,56 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; - if (gr_frontsector->heightsec != -1) - { - worldtop = sectors[gr_frontsector->heightsec].ceilingheight; - worldbottom = sectors[gr_frontsector->heightsec].floorheight; - } - else - { - worldtop = gr_frontsector->ceilingheight; - worldbottom = gr_frontsector->floorheight; - } - vs.x = ((polyvertex_t *)gr_curline->v1)->x; vs.y = ((polyvertex_t *)gr_curline->v1)->y; ve.x = ((polyvertex_t *)gr_curline->v2)->x; ve.y = ((polyvertex_t *)gr_curline->v2)->y; +#ifdef ESLOPE + v1x = FLOAT_TO_FIXED(vs.x); + v1y = FLOAT_TO_FIXED(vs.y); + v2x = FLOAT_TO_FIXED(ve.x); + v2y = FLOAT_TO_FIXED(ve.y); +#endif + + if (gr_frontsector->heightsec != -1) + { +#ifdef ESLOPE + worldtop = worldtopslope = sectors[gr_frontsector->heightsec].ceilingheight; + worldbottom = worldbottomslope = sectors[gr_frontsector->heightsec].floorheight; +#else + worldtop = sectors[gr_frontsector->heightsec].ceilingheight; + worldbottom = sectors[gr_frontsector->heightsec].floorheight; +#endif + } + else + { +#ifdef ESLOPE + if (gr_frontsector->c_slope) + { + worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y); + worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y); + } + else + { + worldtop = worldtopslope = gr_frontsector->ceilingheight; + } + + if (gr_frontsector->f_slope) + { + worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); + worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); + } + else + { + worldbottom = worldbottomslope = gr_frontsector->floorheight; + } +#else + worldtop = gr_frontsector->ceilingheight; + worldbottom = gr_frontsector->floorheight; +#endif + } + // remember vertices ordering // 3--2 // | /| @@ -1396,13 +1463,40 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // two sided line if (gr_backsector->heightsec != -1) { +#ifdef ESLOPE + worldhigh = worldhighslope = sectors[gr_backsector->heightsec].ceilingheight; + worldlow = worldlowslope = sectors[gr_backsector->heightsec].floorheight; +#else worldhigh = sectors[gr_backsector->heightsec].ceilingheight; worldlow = sectors[gr_backsector->heightsec].floorheight; +#endif } else { +#ifdef ESLOPE + if (gr_backsector->c_slope) + { + worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y); + worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y); + } + else + { + worldhigh = worldhighslope = gr_backsector->ceilingheight; + } + + if (gr_backsector->f_slope) + { + worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); + worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); + } + else + { + worldlow = worldlowslope = gr_backsector->floorheight; + } +#else worldhigh = gr_backsector->ceilingheight; worldlow = gr_backsector->floorheight; +#endif } // hack to allow height changes in outdoor areas @@ -1411,10 +1505,18 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_backsector->ceilingpic == skyflatnum) { worldtop = worldhigh; +#ifdef ESLOPE + worldtopslope = worldhighslope; +#endif } // check TOP TEXTURE - if (worldhigh < worldtop && texturetranslation[gr_sidedef->toptexture]) + if (( +#ifdef ESLOPE + worldhighslope < worldtopslope || +#endif + worldhigh < worldtop + ) && texturetranslation[gr_sidedef->toptexture]) { if (drawtextured) { @@ -1425,8 +1527,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // PEGGING if (gr_linedef->flags & ML_DONTPEGTOP) texturevpegtop = 0; - else +#ifdef ESLOPE + else if (gr_linedef->flags & ML_EFFECT1) texturevpegtop = worldhigh + textureheight[gr_sidedef->toptexture] - worldtop; + else + texturevpegtop = gr_backsector->ceilingheight + textureheight[gr_sidedef->toptexture] - gr_frontsector->ceilingheight; +#else + else + texturevpegtop = worldhigh + textureheight[gr_sidedef->toptexture] - worldtop; +#endif texturevpegtop += gr_sidedef->rowoffset; @@ -1434,14 +1543,34 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) texturevpegtop %= SHORT(textures[texturetranslation[gr_sidedef->toptexture]]->height)<scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpegtop + gr_frontsector->ceilingheight - gr_backsector->ceilingheight) * grTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + +#ifdef ESLOPE + // Adjust t value for sloped walls + if (!(gr_linedef->flags & ML_EFFECT1)) + { + // Unskewed + wallVerts[3].t += worldtop - gr_frontsector->ceilingheight; + wallVerts[2].t += worldtopslope - gr_frontsector->ceilingheight; + wallVerts[0].t += worldhigh - gr_backsector->ceilingheight; + wallVerts[1].t += worldhighslope - gr_backsector->ceilingheight; + } + +#endif } // set top/bottom coords +#ifdef ESLOPE + wallVerts[3].y = FIXED_TO_FLOAT(worldtop); + wallVerts[0].y = FIXED_TO_FLOAT(worldhigh); + wallVerts[2].y = FIXED_TO_FLOAT(worldtopslope); + wallVerts[1].y = FIXED_TO_FLOAT(worldhighslope); +#else wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldtop); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldhigh); +#endif if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, texturetranslation[gr_sidedef->toptexture], &Surf, FF_CUTSOLIDS); @@ -1452,7 +1581,11 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) } // check BOTTOM TEXTURE - if (worldlow > worldbottom && texturetranslation[gr_sidedef->bottomtexture]) //only if VISIBLE!!! + if (( +#ifdef ESLOPE + worldlowslope > worldbottomslope || +#endif + worldlow > worldbottom) && texturetranslation[gr_sidedef->bottomtexture]) //only if VISIBLE!!! { if (drawtextured) { @@ -1478,8 +1611,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) } // set top/bottom coords +#ifdef ESLOPE + wallVerts[3].y = FIXED_TO_FLOAT(worldlow); + wallVerts[0].y = FIXED_TO_FLOAT(worldbottom); + wallVerts[2].y = FIXED_TO_FLOAT(worldlowslope); + wallVerts[1].y = FIXED_TO_FLOAT(worldbottomslope); +#else wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldlow); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldbottom); +#endif if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, texturetranslation[gr_sidedef->bottomtexture], &Surf, FF_CUTSOLIDS); @@ -4544,7 +4684,7 @@ static void HWR_ProjectSprite(mobj_t *thing) tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); // thing is behind view plane? - if (tz < ZCLIP_PLANE) + if (tz < ZCLIP_PLANE && md2_models[thing->sprite].notfound == true) //Yellow: Only MD2's dont disappear return; tx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos); From 52ae3f2875220d67301c203814b704014f8f8131 Mon Sep 17 00:00:00 2001 From: yellowtd Date: Sun, 24 Jan 2016 03:41:30 -0500 Subject: [PATCH 02/29] GL slope walls and fixed plane culling --- src/hardware/hw_main.c | 173 +++++++++++++++++++++++++++++++++-------- 1 file changed, 139 insertions(+), 34 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 63936b178..34223457f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -521,7 +521,7 @@ static UINT8 HWR_FogBlockAlpha(INT32 light, UINT32 color, UINT32 fadecolor) // L // -----------------+ // HWR_RenderPlane : Render a floor or ceiling convex polygon // -----------------+ -static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fixedheight, +static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xsub, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, boolean fogplane, extracolormap_t *planecolormap) { polyvertex_t * pv; @@ -550,22 +550,21 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi #ifdef ESLOPE // Get the slope pointer to simplify future code - if (sector) + if (FOFsector) { - // Yes this fixedheight check is needed again here - if (sector->f_slope && sector->floorheight == fixedheight) - slope = sector->f_slope; - else if (sector->c_slope && sector->ceilingheight == fixedheight) - slope = sector->c_slope; - } - else if (FOFsector) - { - // Yes this fixedheight check is needed again here if (FOFsector->f_slope && FOFsector->floorheight == fixedheight) slope = FOFsector->f_slope; else if (FOFsector->c_slope && FOFsector->ceilingheight == fixedheight) slope = FOFsector->c_slope; } + else + { + // Use fixedheight to determine whether to check floor or ceiling because I hate my life + if (gr_frontsector->f_slope && gr_frontsector->floorheight == fixedheight) + slope = gr_frontsector->f_slope; + else if (gr_frontsector->c_slope && gr_frontsector->ceilingheight == fixedheight) + slope = gr_frontsector->c_slope; + } // Set fixedheight to the slope's height from our viewpoint, if we have a slope if (slope) @@ -657,7 +656,12 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, fixed_t fi } else if (gr_frontsector) { +#ifdef ESLOPE + if ((slope && slope == gr_frontsector->f_slope) + || fixedheight == gr_frontsector->floorheight) // it's a floor +#else if (fixedheight < dup_viewz) // it's a floor +#endif { scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatsize; @@ -1552,12 +1556,24 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) if (!(gr_linedef->flags & ML_EFFECT1)) { // Unskewed - wallVerts[3].t += worldtop - gr_frontsector->ceilingheight; - wallVerts[2].t += worldtopslope - gr_frontsector->ceilingheight; - wallVerts[0].t += worldhigh - gr_backsector->ceilingheight; - wallVerts[1].t += worldhighslope - gr_backsector->ceilingheight; + wallVerts[3].t -= (worldtop - gr_frontsector->ceilingheight) * grTex->scaleY; + wallVerts[2].t -= (worldtopslope - gr_frontsector->ceilingheight) * grTex->scaleY; + wallVerts[0].t -= (worldhigh - gr_backsector->ceilingheight) * grTex->scaleY; + wallVerts[1].t -= (worldhighslope - gr_backsector->ceilingheight) * grTex->scaleY; + } + else if (gr_linedef->flags & ML_DONTPEGTOP) + { + // Skewed by top + wallVerts[0].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; + wallVerts[1].t = (texturevpegtop + worldtopslope - worldhighslope) * grTex->scaleY; + } + else + { + // Skewed by bottom + wallVerts[0].t = (texturevpegtop + worldhigh - worldtop) * grTex->scaleY; + wallVerts[2].t = wallVerts[3].t - (worldhighslope - worldhigh) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldhighslope - worldtopslope) * grTex->scaleY; } - #endif } @@ -1594,10 +1610,19 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) grTex = HWR_GetTexture(texturetranslation[gr_sidedef->bottomtexture]); // PEGGING - if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#ifdef ESLOPE + if (!(gr_linedef->flags & ML_DONTPEGBOTTOM)) + texturevpegbottom = 0; + else if (gr_linedef->flags & ML_EFFECT1) texturevpegbottom = worldtop - worldlow; else - texturevpegbottom = 0; + texturevpegbottom = gr_frontsector->ceilingheight - gr_backsector->floorheight; +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + texturevpegbottom = worldtop - worldlow; + else + texturevpegbottom = 0; +#endif texturevpegbottom += gr_sidedef->rowoffset; @@ -1605,9 +1630,34 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) texturevpegbottom %= SHORT(textures[texturetranslation[gr_sidedef->bottomtexture]]->height)<scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpegbottom + gr_backsector->floorheight - gr_frontsector->floorheight) * grTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + +#ifdef ESLOPE + // Adjust t value for sloped walls + if (!(gr_linedef->flags & ML_EFFECT1)) + { + // Unskewed + wallVerts[0].t -= (worldbottom - gr_frontsector->floorheight) * grTex->scaleY; + wallVerts[1].t -= (worldbottomslope - gr_frontsector->floorheight) * grTex->scaleY; + wallVerts[3].t -= (worldlow - gr_backsector->floorheight) * grTex->scaleY; + wallVerts[2].t -= (worldlowslope - gr_backsector->floorheight) * grTex->scaleY; + } + else if (gr_linedef->flags & ML_DONTPEGBOTTOM) + { + // Skewed by bottom + wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[2].t = wallVerts[3].t - (worldlowslope - worldlow) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldbottomslope - worldlowslope) * grTex->scaleY; + } + else + { + // Skewed by top + wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[1].t = (texturevpegbottom + worldlowslope - worldbottomslope) * grTex->scaleY; + } +#endif } // set top/bottom coords @@ -1925,6 +1975,11 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) { fixed_t texturevpeg; // PEGGING +#ifdef ESLOPE + if ((gr_linedef->flags & (ML_DONTPEGBOTTOM|ML_EFFECT2)) == (ML_DONTPEGBOTTOM|ML_EFFECT2)) + texturevpeg = gr_frontsector->floorheight + textureheight[gr_sidedef->midtexture] - gr_frontsector->ceilingheight + gr_sidedef->rowoffset; + else +#endif if (gr_linedef->flags & ML_DONTPEGBOTTOM) texturevpeg = worldbottom + textureheight[gr_sidedef->midtexture] - worldtop + gr_sidedef->rowoffset; else @@ -1934,14 +1989,38 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) grTex = HWR_GetTexture(gr_midtexture); wallVerts[3].t = wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (texturevpeg + worldtop - worldbottom) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (texturevpeg + gr_frontsector->ceilingheight - gr_frontsector->floorheight) * grTex->scaleY; wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; + +#ifdef ESLOPE + // Texture correction for slopes + if (gr_linedef->flags & ML_EFFECT2) { + wallVerts[3].t += (gr_frontsector->ceilingheight - worldtop) * grTex->scaleY; + wallVerts[2].t += (gr_frontsector->ceilingheight - worldtopslope) * grTex->scaleY; + wallVerts[0].t += (gr_frontsector->floorheight - worldbottom) * grTex->scaleY; + wallVerts[1].t += (gr_frontsector->floorheight - worldbottomslope) * grTex->scaleY; + } else if (gr_linedef->flags & ML_DONTPEGBOTTOM) { + wallVerts[3].t = wallVerts[0].t + (worldbottom-worldtop) * grTex->scaleY; + wallVerts[2].t = wallVerts[1].t + (worldbottomslope-worldtopslope) * grTex->scaleY; + } else { + wallVerts[0].t = wallVerts[3].t - (worldbottom-worldtop) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldbottomslope-worldtopslope) * grTex->scaleY; + } +#endif } +#ifdef ESLOPE + //Set textures properly on single sided walls that are sloped + wallVerts[3].y = FIXED_TO_FLOAT(worldtop); + wallVerts[0].y = FIXED_TO_FLOAT(worldbottom); + wallVerts[2].y = FIXED_TO_FLOAT(worldtopslope); + wallVerts[1].y = FIXED_TO_FLOAT(worldbottomslope); + +#else // set top/bottom coords wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldtop); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(worldbottom); - +#endif // I don't think that solid walls can use translucent linedef types... if (gr_frontsector->numlights) HWR_SplitWall(gr_frontsector, wallVerts, gr_midtexture, &Surf, FF_CUTSOLIDS); @@ -1974,6 +2053,8 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) INT32 texnum; line_t * newline = NULL; // Multi-Property FOF + ///TODO add slope support (fixing cutoffs, proper wall clipping) - maybe just disable highcut/lowcut if either sector or FOF has a slope + /// to allow fun plane intersecting in OGL? But then people would abuse that and make software look bad. :C highcut = gr_frontsector->ceilingheight < gr_backsector->ceilingheight ? gr_frontsector->ceilingheight : gr_backsector->ceilingheight; lowcut = gr_frontsector->floorheight > gr_backsector->floorheight ? gr_frontsector->floorheight : gr_backsector->floorheight; @@ -3006,6 +3087,7 @@ static void HWR_Subsector(size_t num) INT32 floorlightlevel; INT32 ceilinglightlevel; INT32 locFloorHeight, locCeilingHeight; + INT32 cullFloorHeight, cullCeilingHeight; INT32 light = 0; fixed_t wh; extracolormap_t *floorcolormap; @@ -3063,26 +3145,41 @@ static void HWR_Subsector(size_t num) // ----- for special tricks with HW renderer ----- if (gr_frontsector->pseudoSector) { - locFloorHeight = gr_frontsector->virtualFloorheight; - locCeilingHeight = gr_frontsector->virtualCeilingheight; + cullFloorHeight = locFloorHeight = gr_frontsector->virtualFloorheight; + cullCeilingHeight = locCeilingHeight = gr_frontsector->virtualCeilingheight; } else if (gr_frontsector->virtualFloor) { - locFloorHeight = gr_frontsector->virtualFloorheight; + ///@TODO Is this whole virtualFloor mess even useful? I don't think it even triggers ever. + cullFloorHeight = locFloorHeight = gr_frontsector->virtualFloorheight; if (gr_frontsector->virtualCeiling) - locCeilingHeight = gr_frontsector->virtualCeilingheight; + cullCeilingHeight = locCeilingHeight = gr_frontsector->virtualCeilingheight; else - locCeilingHeight = gr_frontsector->ceilingheight; + cullCeilingHeight = locCeilingHeight = gr_frontsector->ceilingheight; } else if (gr_frontsector->virtualCeiling) { - locCeilingHeight = gr_frontsector->virtualCeilingheight; - locFloorHeight = gr_frontsector->floorheight; + cullCeilingHeight = locCeilingHeight = gr_frontsector->virtualCeilingheight; + cullFloorHeight = locFloorHeight = gr_frontsector->floorheight; } else { - locFloorHeight = gr_frontsector->floorheight; - locCeilingHeight = gr_frontsector->ceilingheight; + cullFloorHeight = locFloorHeight = gr_frontsector->floorheight; + cullCeilingHeight = locCeilingHeight = gr_frontsector->ceilingheight; + +#ifdef ESLOPE + if (gr_frontsector->f_slope) + { + cullFloorHeight = P_GetZAt(gr_frontsector->f_slope, viewx, viewy); + locFloorHeight = P_GetZAt(gr_frontsector->f_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } + + if (gr_frontsector->c_slope) + { + cullCeilingHeight = P_GetZAt(gr_frontsector->c_slope, viewx, viewy); + locCeilingHeight = P_GetZAt(gr_frontsector->c_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } +#endif } // ----- end special tricks ----- @@ -3113,14 +3210,18 @@ static void HWR_Subsector(size_t num) // render floor ? #ifdef DOPLANES // yeah, easy backface cull! :) - if (locFloorHeight < dup_viewz) + if (cullFloorHeight < dup_viewz) { if (gr_frontsector->floorpic != skyflatnum) { if (sub->validcount != validcount) { HWR_GetFlat(levelflats[gr_frontsector->floorpic].lumpnum); - HWR_RenderPlane(gr_frontsector, &extrasubsectors[num], locFloorHeight, PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, false, floorcolormap); + HWR_RenderPlane(gr_frontsector, &extrasubsectors[num], + // Hack to make things continue to work around slopes. + locFloorHeight == cullFloorHeight ? locFloorHeight : gr_frontsector->floorheight, + // We now return you to your regularly scheduled rendering. + PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, false, floorcolormap); } } else @@ -3131,14 +3232,18 @@ static void HWR_Subsector(size_t num) } } - if (locCeilingHeight > dup_viewz) + if (cullCeilingHeight > dup_viewz) { if (gr_frontsector->ceilingpic != skyflatnum) { if (sub->validcount != validcount) { HWR_GetFlat(levelflats[gr_frontsector->ceilingpic].lumpnum); - HWR_RenderPlane(NULL, &extrasubsectors[num], locCeilingHeight, PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, false, ceilingcolormap); + HWR_RenderPlane(NULL, &extrasubsectors[num], + // Hack to make things continue to work around slopes. + locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gr_frontsector->ceilingheight, + // We now return you to your regularly scheduled rendering. + PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, false, ceilingcolormap); } } else From e6235d4d6bddead7804facc24b2616e6f6404964 Mon Sep 17 00:00:00 2001 From: yellowtd Date: Mon, 25 Jan 2016 00:57:53 -0500 Subject: [PATCH 03/29] Fix FOF slope rendering in ogl should work as well as software if not better now --- src/hardware/hw_main.c | 107 +++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 15 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 34223457f..5cd3b5931 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1363,6 +1363,9 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) float cliplow = 0.0f, cliphigh = 0.0f; INT32 gr_midtexture; fixed_t h, l; // 3D sides and 2s middle textures +#ifdef ESLOPE + fixed_t hS, lS; +#endif FUINT lightnum = 0; // shut up compiler extracolormap_t *colormap; @@ -2076,6 +2079,26 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) texnum = texturetranslation[sides[newline->sidenum[0]].midtexture]; } +#ifdef ESLOPE + h = *rover->t_slope ? P_GetZAt(*rover->t_slope, v1x, v1y) : *rover->topheight; + hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; + l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; + lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; + //Hurdler: HW code starts here + //FIXME: check if peging is correct + // set top/bottom coords + + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[1].y = FIXED_TO_FLOAT(lS); + + +#else h = *rover->topheight; l = *rover->bottomheight; if (h > highcut) @@ -2087,6 +2110,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // set top/bottom coords wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); +#endif if (rover->flags & FF_FOG) { wallVerts[3].t = wallVerts[2].t = 0; @@ -2096,6 +2120,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) } else if (drawtextured) { +#ifdef ESLOPE // P.S. this is better-organized than the old version + fixed_t offs = sides[(newline ?: rover->master)->sidenum[0]].rowoffset; + grTex = HWR_GetTexture(texnum); + + wallVerts[3].t = (*rover->topheight - h + offs) * grTex->scaleY; + wallVerts[2].t = (*rover->topheight - hS + offs) * grTex->scaleY; + wallVerts[0].t = (*rover->topheight - l + offs) * grTex->scaleY; + wallVerts[1].t = (*rover->topheight - lS + offs) * grTex->scaleY; +#else grTex = HWR_GetTexture(texnum); if (newline) @@ -2108,6 +2141,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset) * grTex->scaleY; wallVerts[0].t = wallVerts[1].t = (h - l + (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset)) * grTex->scaleY; } +#endif wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; @@ -2180,7 +2214,26 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) newline = rover->master->frontsector->lines[0] + linenum; texnum = texturetranslation[sides[newline->sidenum[0]].midtexture]; } +#ifdef ESLOPE //backsides + h = *rover->t_slope ? P_GetZAt(*rover->t_slope, v1x, v1y) : *rover->topheight; + hS = *rover->t_slope ? P_GetZAt(*rover->t_slope, v2x, v2y) : *rover->topheight; + l = *rover->b_slope ? P_GetZAt(*rover->b_slope, v1x, v1y) : *rover->bottomheight; + lS = *rover->b_slope ? P_GetZAt(*rover->b_slope, v2x, v2y) : *rover->bottomheight; + if (!(*rover->t_slope) && !gr_frontsector->c_slope && !gr_backsector->c_slope && h > highcut) + h = hS = highcut; + if (!(*rover->b_slope) && !gr_frontsector->f_slope && !gr_backsector->f_slope && l < lowcut) + l = lS = lowcut; + //Hurdler: HW code starts here + //FIXME: check if peging is correct + // set top/bottom coords + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[1].y = FIXED_TO_FLOAT(lS); + + +#else h = *rover->topheight; l = *rover->bottomheight; if (h > highcut) @@ -2192,7 +2245,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // set top/bottom coords wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); - +#endif if (rover->flags & FF_FOG) { wallVerts[3].t = wallVerts[2].t = 0; @@ -3272,22 +3325,34 @@ static void HWR_Subsector(size_t num) for (rover = gr_frontsector->ffloors; rover; rover = rover->next) { + fixed_t cullHeight, centerHeight; + + // bottom plane +#ifdef ESLOPE + if (*rover->b_slope) + { + cullHeight = P_GetZAt(*rover->b_slope, viewx, viewy); + centerHeight = P_GetZAt(*rover->b_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } + else +#endif + cullHeight = centerHeight = *rover->bottomheight; if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) continue; if (sub->validcount == validcount) continue; - if (*rover->bottomheight <= gr_frontsector->ceilingheight && - *rover->bottomheight >= gr_frontsector->floorheight && - ((dup_viewz < *rover->bottomheight && !(rover->flags & FF_INVERTPLANES)) || - (dup_viewz > *rover->bottomheight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + if (centerHeight <= locCeilingHeight && + centerHeight >= locFloorHeight && + ((dup_viewz < cullHeight && !(rover->flags & FF_INVERTPLANES)) || + (dup_viewz > cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) { UINT8 alpha; - light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); if (rover->master->frontsector->extra_colormap) alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba, rover->master->frontsector->extra_colormap->fadergba); @@ -3303,7 +3368,7 @@ static void HWR_Subsector(size_t num) } else if (rover->flags & FF_TRANSLUCENT) // SoM: Flags are more efficient { - light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); #ifndef SORTING HWR_Add3DWater(levelflats[*rover->bottompic].lumpnum, &extrasubsectors[num], @@ -3322,21 +3387,33 @@ static void HWR_Subsector(size_t num) else { HWR_GetFlat(levelflats[*rover->bottompic].lumpnum); - light = R_GetPlaneLight(gr_frontsector, *rover->bottomheight, dup_viewz < *rover->bottomheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); HWR_RenderPlane(NULL, &extrasubsectors[num], *rover->bottomheight, PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, rover->master->frontsector, 255, false, gr_frontsector->lightlist[light].extra_colormap); } } - if (*rover->topheight >= gr_frontsector->floorheight && - *rover->topheight <= gr_frontsector->ceilingheight && - ((dup_viewz > *rover->topheight && !(rover->flags & FF_INVERTPLANES)) || - (dup_viewz < *rover->topheight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) + + // top plane +#ifdef ESLOPE + if (*rover->t_slope) + { + cullHeight = P_GetZAt(*rover->t_slope, viewx, viewy); + centerHeight = P_GetZAt(*rover->t_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } + else +#endif + cullHeight = centerHeight = *rover->topheight; + + if (centerHeight >= locFloorHeight && + centerHeight <= locCeilingHeight && + ((dup_viewz > cullHeight && !(rover->flags & FF_INVERTPLANES)) || + (dup_viewz < cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) { if (rover->flags & FF_FOG) { UINT8 alpha; - light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); if (rover->master->frontsector->extra_colormap) alpha = HWR_FogBlockAlpha(*gr_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap->rgba, rover->master->frontsector->extra_colormap->fadergba); @@ -3352,7 +3429,7 @@ static void HWR_Subsector(size_t num) } else if (rover->flags & FF_TRANSLUCENT) { - light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); #ifndef SORTING HWR_Add3DWater(levelflats[*rover->toppic].lumpnum, &extrasubsectors[num], @@ -3372,7 +3449,7 @@ static void HWR_Subsector(size_t num) else { HWR_GetFlat(levelflats[*rover->toppic].lumpnum); - light = R_GetPlaneLight(gr_frontsector, *rover->topheight, dup_viewz < *rover->topheight ? true : false); + light = R_GetPlaneLight(gr_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); HWR_RenderPlane(NULL, &extrasubsectors[num], *rover->topheight, PF_Occlude, *gr_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, rover->master->frontsector, 255, false, gr_frontsector->lightlist[light].extra_colormap); } From b3fbc37c943201e85212b145427ee17dde96e941 Mon Sep 17 00:00:00 2001 From: yellowtd Date: Wed, 27 Jan 2016 01:00:15 -0500 Subject: [PATCH 04/29] Midtextures, lights, and culling fixes for ogl slopes There's a weird issue with lights that's hard to diagnose but otherwise this is ready to go I think --- src/hardware/hw_main.c | 203 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 185 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5cd3b5931..52be99219 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1082,23 +1082,47 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, lightlist. This may also include leaving out parts of the wall that can't be seen */ GLTexture_t * glTex; + float realtop, realbot, top, bot; float pegt, pegb, pegmul; float height = 0.0f, bheight = 0.0f; + +#ifdef ESLOPE + float endrealtop, endrealbot, endtop, endbot; + float endpegt, endpegb, endpegmul; + float endheight = 0.0f, endbheight = 0.0f; + + fixed_t v1x = FLOAT_TO_FIXED(wallVerts[0].x); + fixed_t v1y = FLOAT_TO_FIXED(wallVerts[0].y); + fixed_t v2x = FLOAT_TO_FIXED(wallVerts[1].x); + fixed_t v2y = FLOAT_TO_FIXED(wallVerts[1].y); +#endif + INT32 solid, i; lightlist_t * list = sector->lightlist; const UINT8 alpha = Surf->FlatColor.s.alpha; FUINT lightnum; extracolormap_t *colormap; - realtop = top = wallVerts[2].y; + realtop = top = wallVerts[3].y; realbot = bot = wallVerts[0].y; - pegt = wallVerts[2].t; + pegt = wallVerts[3].t; pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); +#ifdef ESLOPE + endrealtop = endtop = wallVerts[2].y; + endrealbot = endbot = wallVerts[1].y; + endpegt = wallVerts[2].t; + endpegb = wallVerts[1].t; + endpegmul = (endpegb - endpegt) / (endtop - endbot); +#endif + for (i = 1; i < sector->numlights; i++) { +#ifdef ESLOPE + if (endtop < endrealbot) +#endif if (top < realbot) return; @@ -1131,14 +1155,39 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, if (cutflag == FF_CUTSOLIDS) // These are regular walls sent in from StoreWallRange, they shouldn't be cut from this solid = false; +#ifdef ESLOPE + if (list[i].slope) + { + height = FIXED_TO_FLOAT(P_GetZAt(list[i].slope, v1x, v1y)); + endheight = FIXED_TO_FLOAT(P_GetZAt(list[i].slope, v2x, v2y)); + } + else + height = endheight = FIXED_TO_FLOAT(list[i].height); + if (solid) + if (*list[i].caster->b_slope) + { + bheight = FIXED_TO_FLOAT(P_GetZAt(*list[i].caster->b_slope, v1x, v1y)); + endbheight = FIXED_TO_FLOAT(P_GetZAt(*list[i].caster->b_slope, v2x, v2y)); + } + else + bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); +#else height = FIXED_TO_FLOAT(list[i].height); if (solid) bheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); +#endif +#ifdef ESLOPE + if (endheight >= endtop) +#endif if (height >= top) { if (solid && top > bheight) top = bheight; +#ifdef ESLOPE + if (solid && endtop > endbheight) + endtop = endbheight; +#endif continue; } @@ -1148,6 +1197,13 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, if (bot < realbot) bot = realbot; +#ifdef ESLOPE + endbot = endheight; + + if (endbot < endrealbot) + endbot = endrealbot; +#endif + // colormap test if (list[i-1].caster) { @@ -1162,13 +1218,25 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, Surf->FlatColor.s.alpha = alpha; +#ifdef ESLOPE + wallVerts[3].t = pegt + ((realtop - top) * pegmul); + wallVerts[2].t = endpegt + ((endrealtop - endtop) * endpegmul); + wallVerts[0].t = pegt + ((realtop - bot) * pegmul); + wallVerts[1].t = endpegt + ((endrealtop - endbot) * endpegmul); + // set top/bottom coords + wallVerts[3].y = top; + wallVerts[2].y = endtop; + wallVerts[0].y = bot; + wallVerts[1].y = endbot; +#else wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); // set top/bottom coords wallVerts[2].y = wallVerts[3].y = top; wallVerts[0].y = wallVerts[1].y = bot; +#endif glTex = HWR_GetTexture(texnum); if (cutflag & FF_TRANSLUCENT) @@ -1182,9 +1250,19 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, top = bheight; else top = height; +#ifdef ESLOPE + if (solid) + endtop = endbheight; + else + endtop = endheight; +#endif } bot = realbot; +#ifdef ESLOPE + endbot = endrealbot; + if (endtop <= endrealbot) +#endif if (top <= realbot) return; @@ -1200,12 +1278,25 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, } Surf->FlatColor.s.alpha = alpha; - wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); - wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); +#ifdef ESLOPE + wallVerts[3].t = pegt + ((realtop - top) * pegmul); + wallVerts[2].t = endpegt + ((endrealtop - endtop) * endpegmul); + wallVerts[0].t = pegt + ((realtop - bot) * pegmul); + wallVerts[1].t = endpegt + ((endrealtop - endbot) * endpegmul); - // set top/bottom coords - wallVerts[2].y = wallVerts[3].y = top; - wallVerts[0].y = wallVerts[1].y = bot; + // set top/bottom coords + wallVerts[3].y = top; + wallVerts[2].y = endtop; + wallVerts[0].y = bot; + wallVerts[1].y = endbot; +#else + wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); + wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); + + // set top/bottom coords + wallVerts[2].y = wallVerts[3].y = top; + wallVerts[0].y = wallVerts[1].y = bot; +#endif glTex = HWR_GetTexture(texnum); if (cutflag & FF_TRANSLUCENT) @@ -1739,14 +1830,36 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) popentop = back->ceilingheight; popenbottom = back->floorheight; } -#endif else - { - popentop = front->ceilingheight < back->ceilingheight ? front->ceilingheight : back->ceilingheight; - popenbottom = front->floorheight > back->floorheight ? front->floorheight : back->floorheight; +#endif + { +#ifdef ESLOPE + popentop = min(worldtop, worldhigh); + popenbottom = max(worldbottom, worldlow); +#else + popentop = min(front->ceilingheight, back->ceilingheight); + popenbottom = max(front->floorheight, back->floorheight); +#endif } - if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#ifdef ESLOPE + if (gr_linedef->flags & ML_EFFECT2) + { + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + { + polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; + polytop = polybottom + textureheight[gr_midtexture]*repeats; + } + else + { + polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; + polybottom = polytop - textureheight[gr_midtexture]*repeats; + } + } + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else + if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#endif { polybottom = popenbottom + gr_sidedef->rowoffset; polytop = polybottom + textureheight[gr_midtexture]*repeats; @@ -1769,17 +1882,21 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) else { // The cut-off values of a linedef can always be constant, since every line has an absoulute front and or back sector - lowcut = front->floorheight > back->floorheight ? front->floorheight : back->floorheight; - highcut = front->ceilingheight < back->ceilingheight ? front->ceilingheight : back->ceilingheight; + lowcut = popenbottom; + highcut = popentop; } - h = polytop > highcut ? highcut : polytop; - l = polybottom < lowcut ? lowcut : polybottom; + h = min(highcut, polytop); + l = max(polybottom, lowcut); if (drawtextured) { // PEGGING +#ifdef ESLOPE + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) +#else if (gr_linedef->flags & ML_DONTPEGBOTTOM) +#endif texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; else texturevpeg = polytop - h; @@ -1798,6 +1915,52 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(h); wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); +#ifdef ESLOPE + // Correct to account for slopes + { + fixed_t midtextureslant; + + if (gr_linedef->flags & ML_EFFECT2) + midtextureslant = 0; + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + midtextureslant = worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + else + midtextureslant = worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + + polytop += midtextureslant; + polybottom += midtextureslant; + + highcut += worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + lowcut += worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + + // Texture stuff + h = min(highcut, polytop); + l = max(polybottom, lowcut); + + if (drawtextured) + { + // PEGGING + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + } + + wallVerts[2].y = FIXED_TO_FLOAT(h); + wallVerts[1].y = FIXED_TO_FLOAT(l); + } +#endif + // set alpha for transparent walls (new boom and legacy linedef types) // ooops ! this do not work at all because render order we should render it in backtofront order switch (gr_linedef->special) @@ -2739,10 +2902,14 @@ static void HWR_AddLine(seg_t * line) // and no middle texture. if ( #ifdef POLYOBJECTS - !line->polyseg + !line->polyseg && #endif - && gr_backsector->ceilingpic == gr_frontsector->ceilingpic + gr_backsector->ceilingpic == gr_frontsector->ceilingpic && gr_backsector->floorpic == gr_frontsector->floorpic +#ifdef ESLOPE + && gr_backsector->f_slope == gr_frontsector->f_slope + && gr_backsector->c_slope == gr_frontsector->c_slope +#endif && gr_backsector->lightlevel == gr_frontsector->lightlevel && gr_curline->sidedef->midtexture == 0 && !gr_backsector->ffloors && !gr_frontsector->ffloors) From f87f1b7b1a9ad9b91d816316b5a0ab40a40cdfd0 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 28 Jan 2016 13:56:23 +0000 Subject: [PATCH 05/29] Fixed compiler errors as well as a ton of tab spaces (apparently it's a common problem in this file anyway but whatever) --- src/hardware/hw_main.c | 556 +++++++++++++++++++++-------------------- 1 file changed, 281 insertions(+), 275 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 52be99219..ddab53a04 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -538,37 +538,39 @@ static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xs FSurfaceInfo Surf; fixed_t tempxsow, tempytow; #ifdef ESLOPE - pslope_t *slope = NULL; + pslope_t *slope = NULL; #endif static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; + (void)shittyUnusedVariable; ///@TODO remove shitty unused variable + // no convex poly were generated for this subsector if (!xsub->planepoly) return; #ifdef ESLOPE - // Get the slope pointer to simplify future code - if (FOFsector) - { - if (FOFsector->f_slope && FOFsector->floorheight == fixedheight) - slope = FOFsector->f_slope; - else if (FOFsector->c_slope && FOFsector->ceilingheight == fixedheight) - slope = FOFsector->c_slope; - } - else - { - // Use fixedheight to determine whether to check floor or ceiling because I hate my life - if (gr_frontsector->f_slope && gr_frontsector->floorheight == fixedheight) - slope = gr_frontsector->f_slope; - else if (gr_frontsector->c_slope && gr_frontsector->ceilingheight == fixedheight) - slope = gr_frontsector->c_slope; - } + // Get the slope pointer to simplify future code + if (FOFsector) + { + if (FOFsector->f_slope && FOFsector->floorheight == fixedheight) + slope = FOFsector->f_slope; + else if (FOFsector->c_slope && FOFsector->ceilingheight == fixedheight) + slope = FOFsector->c_slope; + } + else + { + // Use fixedheight to determine whether to check floor or ceiling because I hate my life + if (gr_frontsector->f_slope && gr_frontsector->floorheight == fixedheight) + slope = gr_frontsector->f_slope; + else if (gr_frontsector->c_slope && gr_frontsector->ceilingheight == fixedheight) + slope = gr_frontsector->c_slope; + } - // Set fixedheight to the slope's height from our viewpoint, if we have a slope - if (slope) - fixedheight = P_GetZAt(slope, viewx, viewy); + // Set fixedheight to the slope's height from our viewpoint, if we have a slope + if (slope) + fixedheight = P_GetZAt(slope, viewx, viewy); #endif height = FIXED_TO_FLOAT(fixedheight); @@ -638,7 +640,7 @@ static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xs { #ifdef ESLOPE if ((slope && slope == FOFsector->f_slope) - || fixedheight == FOFsector->floorheight) // it's a floor + || fixedheight == FOFsector->floorheight) // it's a floor #else if (fixedheight == FOFsector->floorheight) // it's a floor #endif @@ -658,7 +660,7 @@ static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xs { #ifdef ESLOPE if ((slope && slope == gr_frontsector->f_slope) - || fixedheight == gr_frontsector->floorheight) // it's a floor + || fixedheight == gr_frontsector->floorheight) // it's a floor #else if (fixedheight < dup_viewz) // it's a floor #endif @@ -718,11 +720,11 @@ static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xs v3d->z = pv->y; #ifdef ESLOPE - if (slope) - { - fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED(pv->x), FLOAT_TO_FIXED(pv->y)); - v3d->y = FIXED_TO_FLOAT(fixedheight); - } + if (slope) + { + fixedheight = P_GetZAt(slope, FLOAT_TO_FIXED(pv->x), FLOAT_TO_FIXED(pv->y)); + v3d->y = FIXED_TO_FLOAT(fixedheight); + } #endif } @@ -742,8 +744,8 @@ static void HWR_RenderPlane(sector_t *shittyUnusedVariable, extrasubsector_t *xs sector_t *psector = gr_frontsector; #ifdef ESLOPE - if (slope) - fixedheight = P_GetZAt(slope, psector->soundorg.x, psector->soundorg.y); + if (slope) + fixedheight = P_GetZAt(slope, psector->soundorg.x, psector->soundorg.y); #endif if (psector->ffloors) @@ -1096,6 +1098,9 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, fixed_t v1y = FLOAT_TO_FIXED(wallVerts[0].y); fixed_t v2x = FLOAT_TO_FIXED(wallVerts[1].x); fixed_t v2y = FLOAT_TO_FIXED(wallVerts[1].y); + // compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly + // use this as a temp var to store P_GetZAt's return value each time + fixed_t temp; #endif INT32 solid, i; @@ -1156,21 +1161,27 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, solid = false; #ifdef ESLOPE - if (list[i].slope) - { - height = FIXED_TO_FLOAT(P_GetZAt(list[i].slope, v1x, v1y)); - endheight = FIXED_TO_FLOAT(P_GetZAt(list[i].slope, v2x, v2y)); - } - else - height = endheight = FIXED_TO_FLOAT(list[i].height); + if (list[i].slope) + { + temp = P_GetZAt(list[i].slope, v1x, v1y); + height = FIXED_TO_FLOAT(temp); + temp = P_GetZAt(list[i].slope, v2x, v2y); + endheight = FIXED_TO_FLOAT(temp); + } + else + height = endheight = FIXED_TO_FLOAT(list[i].height); if (solid) - if (*list[i].caster->b_slope) - { - bheight = FIXED_TO_FLOAT(P_GetZAt(*list[i].caster->b_slope, v1x, v1y)); - endbheight = FIXED_TO_FLOAT(P_GetZAt(*list[i].caster->b_slope, v2x, v2y)); - } - else - bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); + { + if (*list[i].caster->b_slope) + { + temp = P_GetZAt(*list[i].caster->b_slope, v1x, v1y); + bheight = FIXED_TO_FLOAT(temp); + temp = P_GetZAt(*list[i].caster->b_slope, v2x, v2y); + endbheight = FIXED_TO_FLOAT(temp); + } + else + bheight = endbheight = FIXED_TO_FLOAT(*list[i].caster->bottomheight); + } #else height = FIXED_TO_FLOAT(list[i].height); if (solid) @@ -1178,15 +1189,15 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, #endif #ifdef ESLOPE - if (endheight >= endtop) + if (endheight >= endtop) #endif if (height >= top) { if (solid && top > bheight) top = bheight; #ifdef ESLOPE - if (solid && endtop > endbheight) - endtop = endbheight; + if (solid && endtop > endbheight) + endtop = endbheight; #endif continue; } @@ -1198,10 +1209,10 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, bot = realbot; #ifdef ESLOPE - endbot = endheight; + endbot = endheight; - if (endbot < endrealbot) - endbot = endrealbot; + if (endbot < endrealbot) + endbot = endrealbot; #endif // colormap test @@ -1228,7 +1239,7 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, wallVerts[3].y = top; wallVerts[2].y = endtop; wallVerts[0].y = bot; - wallVerts[1].y = endbot; + wallVerts[1].y = endbot; #else wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); @@ -1260,8 +1271,8 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, bot = realbot; #ifdef ESLOPE - endbot = endrealbot; - if (endtop <= endrealbot) + endbot = endrealbot; + if (endtop <= endrealbot) #endif if (top <= realbot) return; @@ -1279,16 +1290,16 @@ static void HWR_SplitWall(sector_t *sector, wallVert3D *wallVerts, INT32 texnum, Surf->FlatColor.s.alpha = alpha; #ifdef ESLOPE - wallVerts[3].t = pegt + ((realtop - top) * pegmul); - wallVerts[2].t = endpegt + ((endrealtop - endtop) * endpegmul); - wallVerts[0].t = pegt + ((realtop - bot) * pegmul); - wallVerts[1].t = endpegt + ((endrealtop - endbot) * endpegmul); + wallVerts[3].t = pegt + ((realtop - top) * pegmul); + wallVerts[2].t = endpegt + ((endrealtop - endtop) * endpegmul); + wallVerts[0].t = pegt + ((realtop - bot) * pegmul); + wallVerts[1].t = endpegt + ((endrealtop - endbot) * endpegmul); - // set top/bottom coords - wallVerts[3].y = top; - wallVerts[2].y = endtop; - wallVerts[0].y = bot; - wallVerts[1].y = endbot; + // set top/bottom coords + wallVerts[3].y = top; + wallVerts[2].y = endtop; + wallVerts[0].y = bot; + wallVerts[1].y = endbot; #else wallVerts[3].t = wallVerts[2].t = pegt + ((realtop - top) * pegmul); wallVerts[0].t = wallVerts[1].t = pegt + ((realtop - bot) * pegmul); @@ -1455,7 +1466,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) INT32 gr_midtexture; fixed_t h, l; // 3D sides and 2s middle textures #ifdef ESLOPE - fixed_t hS, lS; + fixed_t hS, lS; #endif FUINT lightnum = 0; // shut up compiler @@ -1474,10 +1485,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) ve.y = ((polyvertex_t *)gr_curline->v2)->y; #ifdef ESLOPE - v1x = FLOAT_TO_FIXED(vs.x); - v1y = FLOAT_TO_FIXED(vs.y); - v2x = FLOAT_TO_FIXED(ve.x); - v2y = FLOAT_TO_FIXED(ve.y); + v1x = FLOAT_TO_FIXED(vs.x); + v1y = FLOAT_TO_FIXED(vs.y); + v2x = FLOAT_TO_FIXED(ve.x); + v2y = FLOAT_TO_FIXED(ve.y); #endif if (gr_frontsector->heightsec != -1) @@ -1493,25 +1504,25 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) else { #ifdef ESLOPE - if (gr_frontsector->c_slope) - { - worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y); - worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y); - } - else - { - worldtop = worldtopslope = gr_frontsector->ceilingheight; - } + if (gr_frontsector->c_slope) + { + worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y); + worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y); + } + else + { + worldtop = worldtopslope = gr_frontsector->ceilingheight; + } - if (gr_frontsector->f_slope) - { - worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); - worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); - } - else - { - worldbottom = worldbottomslope = gr_frontsector->floorheight; - } + if (gr_frontsector->f_slope) + { + worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); + worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); + } + else + { + worldbottom = worldbottomslope = gr_frontsector->floorheight; + } #else worldtop = gr_frontsector->ceilingheight; worldbottom = gr_frontsector->floorheight; @@ -1572,25 +1583,25 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) else { #ifdef ESLOPE - if (gr_backsector->c_slope) - { - worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y); - worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y); - } - else - { - worldhigh = worldhighslope = gr_backsector->ceilingheight; - } + if (gr_backsector->c_slope) + { + worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y); + worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y); + } + else + { + worldhigh = worldhighslope = gr_backsector->ceilingheight; + } - if (gr_backsector->f_slope) - { - worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); - worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); - } - else - { - worldlow = worldlowslope = gr_backsector->floorheight; - } + if (gr_backsector->f_slope) + { + worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); + worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); + } + else + { + worldlow = worldlowslope = gr_backsector->floorheight; + } #else worldhigh = gr_backsector->ceilingheight; worldlow = gr_backsector->floorheight; @@ -1604,14 +1615,14 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) { worldtop = worldhigh; #ifdef ESLOPE - worldtopslope = worldhighslope; + worldtopslope = worldhighslope; #endif } // check TOP TEXTURE if (( #ifdef ESLOPE - worldhighslope < worldtopslope || + worldhighslope < worldtopslope || #endif worldhigh < worldtop ) && texturetranslation[gr_sidedef->toptexture]) @@ -1646,28 +1657,28 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; #ifdef ESLOPE - // Adjust t value for sloped walls - if (!(gr_linedef->flags & ML_EFFECT1)) - { - // Unskewed - wallVerts[3].t -= (worldtop - gr_frontsector->ceilingheight) * grTex->scaleY; - wallVerts[2].t -= (worldtopslope - gr_frontsector->ceilingheight) * grTex->scaleY; - wallVerts[0].t -= (worldhigh - gr_backsector->ceilingheight) * grTex->scaleY; - wallVerts[1].t -= (worldhighslope - gr_backsector->ceilingheight) * grTex->scaleY; - } - else if (gr_linedef->flags & ML_DONTPEGTOP) - { - // Skewed by top - wallVerts[0].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; - wallVerts[1].t = (texturevpegtop + worldtopslope - worldhighslope) * grTex->scaleY; - } - else - { - // Skewed by bottom - wallVerts[0].t = (texturevpegtop + worldhigh - worldtop) * grTex->scaleY; - wallVerts[2].t = wallVerts[3].t - (worldhighslope - worldhigh) * grTex->scaleY; - wallVerts[1].t = wallVerts[2].t - (worldhighslope - worldtopslope) * grTex->scaleY; - } + // Adjust t value for sloped walls + if (!(gr_linedef->flags & ML_EFFECT1)) + { + // Unskewed + wallVerts[3].t -= (worldtop - gr_frontsector->ceilingheight) * grTex->scaleY; + wallVerts[2].t -= (worldtopslope - gr_frontsector->ceilingheight) * grTex->scaleY; + wallVerts[0].t -= (worldhigh - gr_backsector->ceilingheight) * grTex->scaleY; + wallVerts[1].t -= (worldhighslope - gr_backsector->ceilingheight) * grTex->scaleY; + } + else if (gr_linedef->flags & ML_DONTPEGTOP) + { + // Skewed by top + wallVerts[0].t = (texturevpegtop + worldtop - worldhigh) * grTex->scaleY; + wallVerts[1].t = (texturevpegtop + worldtopslope - worldhighslope) * grTex->scaleY; + } + else + { + // Skewed by bottom + wallVerts[0].t = (texturevpegtop + worldhigh - worldtop) * grTex->scaleY; + wallVerts[2].t = wallVerts[3].t - (worldhighslope - worldhigh) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldhighslope - worldtopslope) * grTex->scaleY; + } #endif } @@ -1693,7 +1704,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // check BOTTOM TEXTURE if (( #ifdef ESLOPE - worldlowslope > worldbottomslope || + worldlowslope > worldbottomslope || #endif worldlow > worldbottom) && texturetranslation[gr_sidedef->bottomtexture]) //only if VISIBLE!!! { @@ -1729,28 +1740,28 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; #ifdef ESLOPE - // Adjust t value for sloped walls - if (!(gr_linedef->flags & ML_EFFECT1)) - { - // Unskewed - wallVerts[0].t -= (worldbottom - gr_frontsector->floorheight) * grTex->scaleY; - wallVerts[1].t -= (worldbottomslope - gr_frontsector->floorheight) * grTex->scaleY; - wallVerts[3].t -= (worldlow - gr_backsector->floorheight) * grTex->scaleY; - wallVerts[2].t -= (worldlowslope - gr_backsector->floorheight) * grTex->scaleY; - } - else if (gr_linedef->flags & ML_DONTPEGBOTTOM) - { - // Skewed by bottom - wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; - wallVerts[2].t = wallVerts[3].t - (worldlowslope - worldlow) * grTex->scaleY; - wallVerts[1].t = wallVerts[2].t - (worldbottomslope - worldlowslope) * grTex->scaleY; - } - else - { - // Skewed by top - wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; - wallVerts[1].t = (texturevpegbottom + worldlowslope - worldbottomslope) * grTex->scaleY; - } + // Adjust t value for sloped walls + if (!(gr_linedef->flags & ML_EFFECT1)) + { + // Unskewed + wallVerts[0].t -= (worldbottom - gr_frontsector->floorheight) * grTex->scaleY; + wallVerts[1].t -= (worldbottomslope - gr_frontsector->floorheight) * grTex->scaleY; + wallVerts[3].t -= (worldlow - gr_backsector->floorheight) * grTex->scaleY; + wallVerts[2].t -= (worldlowslope - gr_backsector->floorheight) * grTex->scaleY; + } + else if (gr_linedef->flags & ML_DONTPEGBOTTOM) + { + // Skewed by bottom + wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[2].t = wallVerts[3].t - (worldlowslope - worldlow) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldbottomslope - worldlowslope) * grTex->scaleY; + } + else + { + // Skewed by top + wallVerts[0].t = (texturevpegbottom + worldlow - worldbottom) * grTex->scaleY; + wallVerts[1].t = (texturevpegbottom + worldlowslope - worldbottomslope) * grTex->scaleY; + } #endif } @@ -1843,20 +1854,20 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) } #ifdef ESLOPE - if (gr_linedef->flags & ML_EFFECT2) - { - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - { - polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; - polytop = polybottom + textureheight[gr_midtexture]*repeats; - } - else - { - polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; - polybottom = polytop - textureheight[gr_midtexture]*repeats; - } - } - else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + if (gr_linedef->flags & ML_EFFECT2) + { + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + { + polybottom = max(front->floorheight, back->floorheight) + gr_sidedef->rowoffset; + polytop = polybottom + textureheight[gr_midtexture]*repeats; + } + else + { + polytop = min(front->ceilingheight, back->ceilingheight) + gr_sidedef->rowoffset; + polybottom = polytop - textureheight[gr_midtexture]*repeats; + } + } + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) #else if (gr_linedef->flags & ML_DONTPEGBOTTOM) #endif @@ -1893,7 +1904,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) { // PEGGING #ifdef ESLOPE - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) #else if (gr_linedef->flags & ML_DONTPEGBOTTOM) #endif @@ -1916,49 +1927,49 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].y = wallVerts[1].y = FIXED_TO_FLOAT(l); #ifdef ESLOPE - // Correct to account for slopes - { - fixed_t midtextureslant; + // Correct to account for slopes + { + fixed_t midtextureslant; - if (gr_linedef->flags & ML_EFFECT2) - midtextureslant = 0; - else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - midtextureslant = worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; - else - midtextureslant = worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; + if (gr_linedef->flags & ML_EFFECT2) + midtextureslant = 0; + else if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + midtextureslant = worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; + else + midtextureslant = worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; - polytop += midtextureslant; - polybottom += midtextureslant; + polytop += midtextureslant; + polybottom += midtextureslant; - highcut += worldtop < worldhigh - ? worldtopslope-worldtop - : worldhighslope-worldhigh; - lowcut += worldlow < worldbottom - ? worldbottomslope-worldbottom - : worldlowslope-worldlow; + highcut += worldtop < worldhigh + ? worldtopslope-worldtop + : worldhighslope-worldhigh; + lowcut += worldlow < worldbottom + ? worldbottomslope-worldbottom + : worldlowslope-worldlow; - // Texture stuff - h = min(highcut, polytop); - l = max(polybottom, lowcut); + // Texture stuff + h = min(highcut, polytop); + l = max(polybottom, lowcut); - if (drawtextured) - { - // PEGGING - if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) - texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; - else - texturevpeg = polytop - h; - wallVerts[2].t = texturevpeg * grTex->scaleY; - wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; - } + if (drawtextured) + { + // PEGGING + if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) + texturevpeg = textureheight[gr_sidedef->midtexture]*repeats - h + polybottom; + else + texturevpeg = polytop - h; + wallVerts[2].t = texturevpeg * grTex->scaleY; + wallVerts[1].t = (h - l + texturevpeg) * grTex->scaleY; + } - wallVerts[2].y = FIXED_TO_FLOAT(h); - wallVerts[1].y = FIXED_TO_FLOAT(l); - } + wallVerts[2].y = FIXED_TO_FLOAT(h); + wallVerts[1].y = FIXED_TO_FLOAT(l); + } #endif // set alpha for transparent walls (new boom and legacy linedef types) @@ -2142,9 +2153,9 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) fixed_t texturevpeg; // PEGGING #ifdef ESLOPE - if ((gr_linedef->flags & (ML_DONTPEGBOTTOM|ML_EFFECT2)) == (ML_DONTPEGBOTTOM|ML_EFFECT2)) + if ((gr_linedef->flags & (ML_DONTPEGBOTTOM|ML_EFFECT2)) == (ML_DONTPEGBOTTOM|ML_EFFECT2)) texturevpeg = gr_frontsector->floorheight + textureheight[gr_sidedef->midtexture] - gr_frontsector->ceilingheight + gr_sidedef->rowoffset; - else + else #endif if (gr_linedef->flags & ML_DONTPEGBOTTOM) texturevpeg = worldbottom + textureheight[gr_sidedef->midtexture] - worldtop + gr_sidedef->rowoffset; @@ -2160,28 +2171,27 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].s = wallVerts[1].s = cliphigh * grTex->scaleX; #ifdef ESLOPE - // Texture correction for slopes - if (gr_linedef->flags & ML_EFFECT2) { - wallVerts[3].t += (gr_frontsector->ceilingheight - worldtop) * grTex->scaleY; - wallVerts[2].t += (gr_frontsector->ceilingheight - worldtopslope) * grTex->scaleY; - wallVerts[0].t += (gr_frontsector->floorheight - worldbottom) * grTex->scaleY; - wallVerts[1].t += (gr_frontsector->floorheight - worldbottomslope) * grTex->scaleY; - } else if (gr_linedef->flags & ML_DONTPEGBOTTOM) { - wallVerts[3].t = wallVerts[0].t + (worldbottom-worldtop) * grTex->scaleY; - wallVerts[2].t = wallVerts[1].t + (worldbottomslope-worldtopslope) * grTex->scaleY; - } else { - wallVerts[0].t = wallVerts[3].t - (worldbottom-worldtop) * grTex->scaleY; - wallVerts[1].t = wallVerts[2].t - (worldbottomslope-worldtopslope) * grTex->scaleY; - } + // Texture correction for slopes + if (gr_linedef->flags & ML_EFFECT2) { + wallVerts[3].t += (gr_frontsector->ceilingheight - worldtop) * grTex->scaleY; + wallVerts[2].t += (gr_frontsector->ceilingheight - worldtopslope) * grTex->scaleY; + wallVerts[0].t += (gr_frontsector->floorheight - worldbottom) * grTex->scaleY; + wallVerts[1].t += (gr_frontsector->floorheight - worldbottomslope) * grTex->scaleY; + } else if (gr_linedef->flags & ML_DONTPEGBOTTOM) { + wallVerts[3].t = wallVerts[0].t + (worldbottom-worldtop) * grTex->scaleY; + wallVerts[2].t = wallVerts[1].t + (worldbottomslope-worldtopslope) * grTex->scaleY; + } else { + wallVerts[0].t = wallVerts[3].t - (worldbottom-worldtop) * grTex->scaleY; + wallVerts[1].t = wallVerts[2].t - (worldbottomslope-worldtopslope) * grTex->scaleY; + } #endif } #ifdef ESLOPE - //Set textures properly on single sided walls that are sloped + //Set textures properly on single sided walls that are sloped wallVerts[3].y = FIXED_TO_FLOAT(worldtop); wallVerts[0].y = FIXED_TO_FLOAT(worldbottom); wallVerts[2].y = FIXED_TO_FLOAT(worldtopslope); wallVerts[1].y = FIXED_TO_FLOAT(worldbottomslope); - #else // set top/bottom coords wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(worldtop); @@ -2255,12 +2265,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //FIXME: check if peging is correct // set top/bottom coords - wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[2].y = FIXED_TO_FLOAT(hS); - wallVerts[0].y = FIXED_TO_FLOAT(l); - wallVerts[1].y = FIXED_TO_FLOAT(lS); - - + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[1].y = FIXED_TO_FLOAT(lS); #else h = *rover->topheight; l = *rover->bottomheight; @@ -2284,13 +2292,13 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) else if (drawtextured) { #ifdef ESLOPE // P.S. this is better-organized than the old version - fixed_t offs = sides[(newline ?: rover->master)->sidenum[0]].rowoffset; + fixed_t offs = sides[(newline ?: rover->master)->sidenum[0]].rowoffset; grTex = HWR_GetTexture(texnum); - wallVerts[3].t = (*rover->topheight - h + offs) * grTex->scaleY; - wallVerts[2].t = (*rover->topheight - hS + offs) * grTex->scaleY; - wallVerts[0].t = (*rover->topheight - l + offs) * grTex->scaleY; - wallVerts[1].t = (*rover->topheight - lS + offs) * grTex->scaleY; + wallVerts[3].t = (*rover->topheight - h + offs) * grTex->scaleY; + wallVerts[2].t = (*rover->topheight - hS + offs) * grTex->scaleY; + wallVerts[0].t = (*rover->topheight - l + offs) * grTex->scaleY; + wallVerts[1].t = (*rover->topheight - lS + offs) * grTex->scaleY; #else grTex = HWR_GetTexture(texnum); @@ -2390,12 +2398,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //FIXME: check if peging is correct // set top/bottom coords - wallVerts[3].y = FIXED_TO_FLOAT(h); - wallVerts[2].y = FIXED_TO_FLOAT(hS); - wallVerts[0].y = FIXED_TO_FLOAT(l); - wallVerts[1].y = FIXED_TO_FLOAT(lS); - - + wallVerts[3].y = FIXED_TO_FLOAT(h); + wallVerts[2].y = FIXED_TO_FLOAT(hS); + wallVerts[0].y = FIXED_TO_FLOAT(l); + wallVerts[1].y = FIXED_TO_FLOAT(lS); #else h = *rover->topheight; l = *rover->bottomheight; @@ -2902,17 +2908,17 @@ static void HWR_AddLine(seg_t * line) // and no middle texture. if ( #ifdef POLYOBJECTS - !line->polyseg && + !line->polyseg && #endif - gr_backsector->ceilingpic == gr_frontsector->ceilingpic - && gr_backsector->floorpic == gr_frontsector->floorpic + gr_backsector->ceilingpic == gr_frontsector->ceilingpic + && gr_backsector->floorpic == gr_frontsector->floorpic #ifdef ESLOPE - && gr_backsector->f_slope == gr_frontsector->f_slope - && gr_backsector->c_slope == gr_frontsector->c_slope + && gr_backsector->f_slope == gr_frontsector->f_slope + && gr_backsector->c_slope == gr_frontsector->c_slope #endif && gr_backsector->lightlevel == gr_frontsector->lightlevel - && gr_curline->sidedef->midtexture == 0 - && !gr_backsector->ffloors && !gr_frontsector->ffloors) + && gr_curline->sidedef->midtexture == 0 + && !gr_backsector->ffloors && !gr_frontsector->ffloors) // SoM: For 3D sides... Boris, would you like to take a // crack at rendering 3D sides? You would need to add the // above check and add code to HWR_StoreWallRange... @@ -3307,7 +3313,7 @@ static void HWR_Subsector(size_t num) INT32 floorlightlevel; INT32 ceilinglightlevel; INT32 locFloorHeight, locCeilingHeight; - INT32 cullFloorHeight, cullCeilingHeight; + INT32 cullFloorHeight, cullCeilingHeight; INT32 light = 0; fixed_t wh; extracolormap_t *floorcolormap; @@ -3370,7 +3376,7 @@ static void HWR_Subsector(size_t num) } else if (gr_frontsector->virtualFloor) { - ///@TODO Is this whole virtualFloor mess even useful? I don't think it even triggers ever. + ///@TODO Is this whole virtualFloor mess even useful? I don't think it even triggers ever. cullFloorHeight = locFloorHeight = gr_frontsector->virtualFloorheight; if (gr_frontsector->virtualCeiling) cullCeilingHeight = locCeilingHeight = gr_frontsector->virtualCeilingheight; @@ -3388,17 +3394,17 @@ static void HWR_Subsector(size_t num) cullCeilingHeight = locCeilingHeight = gr_frontsector->ceilingheight; #ifdef ESLOPE - if (gr_frontsector->f_slope) - { - cullFloorHeight = P_GetZAt(gr_frontsector->f_slope, viewx, viewy); - locFloorHeight = P_GetZAt(gr_frontsector->f_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); - } + if (gr_frontsector->f_slope) + { + cullFloorHeight = P_GetZAt(gr_frontsector->f_slope, viewx, viewy); + locFloorHeight = P_GetZAt(gr_frontsector->f_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } - if (gr_frontsector->c_slope) - { - cullCeilingHeight = P_GetZAt(gr_frontsector->c_slope, viewx, viewy); - locCeilingHeight = P_GetZAt(gr_frontsector->c_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); - } + if (gr_frontsector->c_slope) + { + cullCeilingHeight = P_GetZAt(gr_frontsector->c_slope, viewx, viewy); + locCeilingHeight = P_GetZAt(gr_frontsector->c_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } #endif } // ----- end special tricks ----- @@ -3438,10 +3444,10 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[gr_frontsector->floorpic].lumpnum); HWR_RenderPlane(gr_frontsector, &extrasubsectors[num], - // Hack to make things continue to work around slopes. - locFloorHeight == cullFloorHeight ? locFloorHeight : gr_frontsector->floorheight, - // We now return you to your regularly scheduled rendering. - PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, false, floorcolormap); + // Hack to make things continue to work around slopes. + locFloorHeight == cullFloorHeight ? locFloorHeight : gr_frontsector->floorheight, + // We now return you to your regularly scheduled rendering. + PF_Occlude, floorlightlevel, levelflats[gr_frontsector->floorpic].lumpnum, NULL, 255, false, floorcolormap); } } else @@ -3460,10 +3466,10 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[gr_frontsector->ceilingpic].lumpnum); HWR_RenderPlane(NULL, &extrasubsectors[num], - // Hack to make things continue to work around slopes. - locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gr_frontsector->ceilingheight, - // We now return you to your regularly scheduled rendering. - PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, false, ceilingcolormap); + // Hack to make things continue to work around slopes. + locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gr_frontsector->ceilingheight, + // We now return you to your regularly scheduled rendering. + PF_Occlude, ceilinglightlevel, levelflats[gr_frontsector->ceilingpic].lumpnum,NULL, 255, false, ceilingcolormap); } } else @@ -3492,16 +3498,16 @@ static void HWR_Subsector(size_t num) for (rover = gr_frontsector->ffloors; rover; rover = rover->next) { - fixed_t cullHeight, centerHeight; + fixed_t cullHeight, centerHeight; // bottom plane #ifdef ESLOPE - if (*rover->b_slope) - { - cullHeight = P_GetZAt(*rover->b_slope, viewx, viewy); - centerHeight = P_GetZAt(*rover->b_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); - } - else + if (*rover->b_slope) + { + cullHeight = P_GetZAt(*rover->b_slope, viewx, viewy); + centerHeight = P_GetZAt(*rover->b_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } + else #endif cullHeight = centerHeight = *rover->bottomheight; @@ -3562,12 +3568,12 @@ static void HWR_Subsector(size_t num) // top plane #ifdef ESLOPE - if (*rover->t_slope) - { - cullHeight = P_GetZAt(*rover->t_slope, viewx, viewy); - centerHeight = P_GetZAt(*rover->t_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); - } - else + if (*rover->t_slope) + { + cullHeight = P_GetZAt(*rover->t_slope, viewx, viewy); + centerHeight = P_GetZAt(*rover->t_slope, gr_frontsector->soundorg.x, gr_frontsector->soundorg.y); + } + else #endif cullHeight = centerHeight = *rover->topheight; From ce793dfe282c748ca53dd2d5dbb4a8af7c7f1d25 Mon Sep 17 00:00:00 2001 From: RedEnchilada Date: Sun, 21 Feb 2016 22:32:38 -0600 Subject: [PATCH 06/29] Fix vissprite-related crashing in OGL --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ddab53a04..d62683206 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5039,7 +5039,7 @@ static void HWR_ProjectSprite(mobj_t *thing) tz = (tr_x * gr_viewcos) + (tr_y * gr_viewsin); // thing is behind view plane? - if (tz < ZCLIP_PLANE && md2_models[thing->sprite].notfound == true) //Yellow: Only MD2's dont disappear + if (tz < ZCLIP_PLANE && (!cv_grmd2.value || md2_models[thing->sprite].notfound == true)) //Yellow: Only MD2's dont disappear return; tx = (tr_x * gr_viewsin) - (tr_y * gr_viewcos); From bcd05b1c6328419c8b90278729f8b649494a40f0 Mon Sep 17 00:00:00 2001 From: RedEnchilada Date: Sun, 21 Feb 2016 23:02:09 -0600 Subject: [PATCH 07/29] Also fixed it for MD2s --- src/hardware/hw_main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d62683206..529c2603c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4520,11 +4520,10 @@ static void HWR_SortVisSprites(void) gr_vsprsortedhead.next = gr_vsprsortedhead.prev = &gr_vsprsortedhead; for (i = 0; i < gr_visspritecount; i++) { - bestdist = ZCLIP_PLANE-1; - bestdispoffset = INT32_MAX; + best = NULL; for (ds = unsorted.next; ds != &unsorted; ds = ds->next) { - if (ds->tz > bestdist) + if (!best || ds->tz > bestdist) { bestdist = ds->tz; bestdispoffset = ds->dispoffset; From 3c5a8b806d5ba20c83a7d4200752fdf916338001 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 4 Apr 2016 20:49:01 +0100 Subject: [PATCH 08/29] Fix slope planes rendering at wrong heights when visportals are visible on-screen --- src/r_plane.c | 27 ++++++++++++++++++++------- src/r_plane.h | 3 ++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 417f0360a..d26afbe5a 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -475,7 +475,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, && lightlevel == check->lightlevel && xoff == check->xoffs && yoff == check->yoffs && planecolormap == check->extra_colormap - && !pfloor && !check->ffloor && check->viewz == viewz + && !pfloor && !check->ffloor + && check->viewx == viewx && check->viewy == viewy && check->viewz == viewz && check->viewangle == viewangle #ifdef ESLOPE && check->slope == slope @@ -497,6 +498,8 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, check->yoffs = yoff; check->extra_colormap = planecolormap; check->ffloor = pfloor; + check->viewx = viewx; + check->viewy = viewy; check->viewz = viewz; check->viewangle = viewangle + plangle; check->plangle = plangle; @@ -567,6 +570,8 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) new_pl->yoffs = pl->yoffs; new_pl->extra_colormap = pl->extra_colormap; new_pl->ffloor = pl->ffloor; + new_pl->viewx = pl->viewx; + new_pl->viewy = pl->viewy; new_pl->viewz = pl->viewz; new_pl->viewangle = pl->viewangle; new_pl->plangle = pl->plangle; @@ -954,11 +959,11 @@ void R_DrawSinglePlane(visplane_t *pl) xoffs *= fudge; yoffs /= fudge; - vx = FIXED_TO_FLOAT(viewx+xoffs); - vy = FIXED_TO_FLOAT(viewy-yoffs); - vz = FIXED_TO_FLOAT(viewz); + vx = FIXED_TO_FLOAT(pl->viewx+xoffs); + vy = FIXED_TO_FLOAT(pl->viewy-yoffs); + vz = FIXED_TO_FLOAT(pl->viewz); - temp = P_GetZAt(pl->slope, viewx, viewy); + temp = P_GetZAt(pl->slope, pl->viewx, pl->viewy); zeroheight = FIXED_TO_FLOAT(temp); #define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) @@ -982,9 +987,9 @@ void R_DrawSinglePlane(visplane_t *pl) n.z = -cos(ang); ang = ANG2RAD(pl->plangle); - temp = P_GetZAt(pl->slope, viewx + FLOAT_TO_FIXED(sin(ang)), viewy + FLOAT_TO_FIXED(cos(ang))); + temp = P_GetZAt(pl->slope, pl->viewx + FLOAT_TO_FIXED(sin(ang)), pl->viewy + FLOAT_TO_FIXED(cos(ang))); m.y = FIXED_TO_FLOAT(temp) - zeroheight; - temp = P_GetZAt(pl->slope, viewx + FLOAT_TO_FIXED(cos(ang)), viewy - FLOAT_TO_FIXED(sin(ang))); + temp = P_GetZAt(pl->slope, pl->viewx + FLOAT_TO_FIXED(cos(ang)), pl->viewy - FLOAT_TO_FIXED(sin(ang))); n.y = FIXED_TO_FLOAT(temp) - zeroheight; m.x /= fudge; @@ -1040,6 +1045,14 @@ void R_DrawSinglePlane(visplane_t *pl) stop = pl->maxx + 1; + if (viewx != pl->viewx || viewy != pl->viewy) + { + viewx = pl->viewx; + viewy = pl->viewy; + } + if (viewz != pl->viewz) + viewz = pl->viewz; + for (x = pl->minx; x <= stop; x++) { R_MakeSpans(x, pl->top[x-1], pl->bottom[x-1], diff --git a/src/r_plane.h b/src/r_plane.h index 239723ed1..562c6a9ae 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -27,7 +27,8 @@ typedef struct visplane_s { struct visplane_s *next; - fixed_t height, viewz; + fixed_t height; + fixed_t viewx, viewy, viewz; angle_t viewangle; angle_t plangle; INT32 picnum; From 44fe6e053330f61e1bccc07e4c30435fb1ea18e2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 4 Apr 2016 21:46:51 +0100 Subject: [PATCH 09/29] Fix sky rendering when visportals are on-screen. They now render the same way they would if you were actually at the other side of each portal. Why didn't they do this before? --- src/r_plane.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index d26afbe5a..ef8570590 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -299,7 +299,7 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) } length = FixedMul (distance,distscale[x1]); - angle = (currentplane->viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; + angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; /// \note Wouldn't it be faster just to add viewx and viewy // to the plane's x/yoffs anyway?? @@ -501,7 +501,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, check->viewx = viewx; check->viewy = viewy; check->viewz = viewz; - check->viewangle = viewangle + plangle; + check->viewangle = viewangle; check->plangle = plangle; #ifdef POLYOBJECTS_PLANES check->polyobj = NULL; @@ -670,7 +670,6 @@ void R_MakeSpans(INT32 x, INT32 t1, INT32 b1, INT32 t2, INT32 b2) void R_DrawPlanes(void) { visplane_t *pl; - angle_t skyviewangle = viewangle; // the flat angle itself can mess with viewangle, so do your own angle instead! INT32 x; INT32 angle; INT32 i; @@ -709,7 +708,7 @@ void R_DrawPlanes(void) if (dc_yl <= dc_yh) { - angle = (skyviewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; + angle = (pl->viewangle + xtoviewangle[x])>>ANGLETOSKYSHIFT; dc_x = x; dc_source = R_GetColumn(skytexture, @@ -862,13 +861,13 @@ void R_DrawSinglePlane(visplane_t *pl) #ifdef ESLOPE if (!pl->slope) // Don't mess with angle on slopes! We'll handle this ourselves later #endif - if (viewangle != pl->viewangle) + if (viewangle != pl->viewangle+pl->plangle) { memset(cachedheight, 0, sizeof (cachedheight)); - angle = (pl->viewangle-ANGLE_90)>>ANGLETOFINESHIFT; + angle = (pl->viewangle+pl->plangle-ANGLE_90)>>ANGLETOFINESHIFT; basexscale = FixedDiv(FINECOSINE(angle),centerxfrac); baseyscale = -FixedDiv(FINESINE(angle),centerxfrac); - viewangle = pl->viewangle; + viewangle = pl->viewangle+pl->plangle; } currentplane = pl; @@ -978,7 +977,7 @@ void R_DrawSinglePlane(visplane_t *pl) p.y = FIXED_TO_FLOAT(temp) - vz; // m is the v direction vector in view space - ang = ANG2RAD(ANGLE_180 - viewangle - pl->plangle); + ang = ANG2RAD(ANGLE_180 - pl->viewangle); m.x = cos(ang); m.z = sin(ang); From 48e3b5e37da8951185ddad99d065b2b1d2b1574f Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 5 Apr 2016 10:43:56 +0100 Subject: [PATCH 10/29] Corrected botch-up with plane viewangles, slope planes probably broke because of the last commit --- src/r_plane.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index ef8570590..ac7dcb90e 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -299,7 +299,7 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) } length = FixedMul (distance,distscale[x1]); - angle = (viewangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; + angle = (currentplane->viewangle + currentplane->plangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; /// \note Wouldn't it be faster just to add viewx and viewy // to the plane's x/yoffs anyway?? @@ -970,14 +970,14 @@ void R_DrawSinglePlane(visplane_t *pl) // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = ANG2RAD(ANGLE_270 - viewangle); + ang = ANG2RAD(ANGLE_270 - pl->viewangle); p.x = vx * cos(ang) - vy * sin(ang); p.z = vx * sin(ang) + vy * cos(ang); temp = P_GetZAt(pl->slope, -xoffs, yoffs); p.y = FIXED_TO_FLOAT(temp) - vz; // m is the v direction vector in view space - ang = ANG2RAD(ANGLE_180 - pl->viewangle); + ang = ANG2RAD(ANGLE_180 - (pl->viewangle + pl->plangle)); m.x = cos(ang); m.z = sin(ang); From 969a254cb69b0fcf74e6835cffa5b56be2e6b730 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sat, 30 Apr 2016 14:59:51 -0500 Subject: [PATCH 11/29] Remove the super float from non-Sonic characters Should fix conflicts with Lua-scripted jump spin abilities. --- src/p_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index b4c91a30b..4aca886b8 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -6842,7 +6842,7 @@ static void P_MovePlayer(player_t *player) } } // Super Sonic move - if (player->charflags & SF_SUPER && player->powers[pw_super] && player->speed > FixedMul(5<mo->scale) + if (player->skin == 0 && player->powers[pw_super] && player->speed > FixedMul(5<mo->scale) && P_MobjFlip(player->mo)*player->mo->momz <= 0) { if (player->panim == PA_ROLL || player->mo->state == &states[S_PLAY_PAIN]) From 2ddde836011cf1620ea35b9ad8293b2ff44454e0 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 1 May 2016 22:14:42 +0100 Subject: [PATCH 12/29] General improvements to Lua error messages for out-of-bounds stuff. The idea is for the layman Lua user to understand better what range of values to use for mobj types, states, sfxs, player #s etc. Additionally, mobjinfo/states/sfxinfo/hudinfo tables all now have actual bound checks when accessing/editing them. Yikes, why didn't they have any before?! --- src/lua_baselib.c | 61 +++++++++++++++++++++++++++------------------ src/lua_hudlib.c | 2 ++ src/lua_infolib.c | 27 +++++++++++++++++--- src/lua_playerlib.c | 2 +- src/lua_skinlib.c | 2 +- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 1488f4024..525f2fe68 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -295,8 +295,8 @@ static int lib_pSpawnMobj(lua_State *L) fixed_t z = luaL_checkfixed(L, 3); mobjtype_t type = luaL_checkinteger(L, 4); NOHUD - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnMobj(x, y, z, type), META_MOBJ); return 1; } @@ -321,8 +321,8 @@ static int lib_pSpawnMissile(lua_State *L) NOHUD if (!source || !dest) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnMissile(source, dest, type), META_MOBJ); return 1; } @@ -338,8 +338,8 @@ static int lib_pSpawnXYZMissile(lua_State *L) NOHUD if (!source || !dest) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnXYZMissile(source, dest, type, x, y, z), META_MOBJ); return 1; } @@ -357,8 +357,8 @@ static int lib_pSpawnPointMissile(lua_State *L) NOHUD if (!source) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnPointMissile(source, xa, ya, za, type, x, y, z), META_MOBJ); return 1; } @@ -374,8 +374,8 @@ static int lib_pSpawnAlteredDirectionMissile(lua_State *L) NOHUD if (!source) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnAlteredDirectionMissile(source, type, x, y, z, shiftingAngle), META_MOBJ); return 1; } @@ -403,8 +403,8 @@ static int lib_pSPMAngle(lua_State *L) NOHUD if (!source) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SPMAngle(source, type, angle, allowaim, flags2), META_MOBJ); return 1; } @@ -417,8 +417,8 @@ static int lib_pSpawnPlayerMissile(lua_State *L) NOHUD if (!source) return LUA_ErrInvalid(L, "mobj_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); LUA_PushUserdata(L, P_SpawnPlayerMissile(source, type, flags2), META_MOBJ); return 1; } @@ -437,8 +437,8 @@ static int lib_pWeaponOrPanel(lua_State *L) { mobjtype_t type = luaL_checkinteger(L, 1); //HUDSAFE - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); lua_pushboolean(L, P_WeaponOrPanel(type)); return 1; } @@ -477,8 +477,10 @@ static int lib_pSpawnParaloop(lua_State *L) statenum_t nstate = luaL_optinteger(L, 8, S_NULL); boolean spawncenter = lua_optboolean(L, 9); NOHUD - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); + if (nstate >= NUMSTATES) + return luaL_error(L, "state %d out of range (0 - %d)", nstate, NUMSTATES-1); P_SpawnParaloop(x, y, z, radius, number, type, nstate, rotangle, spawncenter); return 0; } @@ -908,8 +910,8 @@ static int lib_pSpawnSpinMobj(lua_State *L) NOHUD if (!player) return LUA_ErrInvalid(L, "player_t"); - if (type > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (type >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); P_SpawnSpinMobj(player, type); return 0; } @@ -1274,6 +1276,8 @@ static int lib_pSetMobjStateNF(lua_State *L) NOHUD if (!mobj) return LUA_ErrInvalid(L, "mobj_t"); + if (state >= NUMSTATES) + return luaL_error(L, "state %d out of range (0 - %d)", state, NUMSTATES-1); if (mobj->player && state == S_NULL) return luaL_error(L, "Attempt to remove player mobj with S_NULL."); lua_pushboolean(L, P_SetMobjStateNF(mobj, state)); @@ -1385,8 +1389,8 @@ static int lib_pIsFlagAtBase(lua_State *L) { mobjtype_t flag = luaL_checkinteger(L, 1); NOHUD - if (flag > MT_LASTFREESLOT) - return luaL_error(L, "mobjtype_t out of bounds error!"); + if (flag >= NUMMOBJTYPES) + return luaL_error(L, "mobj type %d out of range (0 - %d)", flag, NUMMOBJTYPES-1); lua_pushboolean(L, P_IsFlagAtBase(flag)); return 1; } @@ -1619,7 +1623,7 @@ static int lib_rSetPlayerSkin(lua_State *L) { INT32 i = luaL_checkinteger(L, 2); if (i < 0 || i >= MAXSKINS) - return luaL_error(L, "argument #2 cannot exceed MAXSKINS"); + return luaL_error(L, "skin number (argument #2) %d out of range (0 - %d)", i, MAXSKINS-1); SetPlayerSkinByNum(player-players, i); } else // skin name @@ -1639,6 +1643,8 @@ static int lib_sStartSound(lua_State *L) sfxenum_t sound_id = luaL_checkinteger(L, 2); player_t *player = NULL; NOHUD + if (sound_id >= NUMSFX) + return luaL_error(L, "sfx %d out of range (0 - %d)", sound_id, NUMSFX-1); if (!lua_isnil(L, 1)) { origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -1663,12 +1669,15 @@ static int lib_sStartSoundAtVolume(lua_State *L) INT32 volume = (INT32)luaL_checkinteger(L, 3); player_t *player = NULL; NOHUD + if (!lua_isnil(L, 1)) { origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); if (!origin) return LUA_ErrInvalid(L, "mobj_t"); } + if (sound_id >= NUMSFX) + return luaL_error(L, "sfx %d out of range (0 - %d)", sound_id, NUMSFX-1); if (!lua_isnone(L, 4) && lua_isuserdata(L, 4)) { player = *((player_t **)luaL_checkudata(L, 4, META_PLAYER)); @@ -1800,6 +1809,8 @@ static int lib_sIdPlaying(lua_State *L) { sfxenum_t id = luaL_checkinteger(L, 1); NOHUD + if (id >= NUMSFX) + return luaL_error(L, "sfx %d out of range (0 - %d)", id, NUMSFX-1); lua_pushboolean(L, S_IdPlaying(id)); return 1; } @@ -1811,6 +1822,8 @@ static int lib_sSoundPlaying(lua_State *L) NOHUD if (!origin) return LUA_ErrInvalid(L, "mobj_t"); + if (id >= NUMSFX) + return luaL_error(L, "sfx %d out of range (0 - %d)", id, NUMSFX-1); lua_pushboolean(L, S_SoundPlaying(origin, id)); return 1; } @@ -1831,7 +1844,7 @@ static int lib_gDoReborn(lua_State *L) INT32 playernum = luaL_checkinteger(L, 1); NOHUD if (playernum >= MAXPLAYERS) - return luaL_error(L, "playernum out of bounds error!"); + return luaL_error(L, "playernum %d out of range (0 - %d)", playernum, MAXPLAYERS-1); G_DoReborn(playernum); return 0; } diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 52770a88a..c4a72f074 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -166,6 +166,8 @@ static int lib_getHudInfo(lua_State *L) lua_remove(L, 1); i = luaL_checkinteger(L, 1); + if (i >= NUMHUDITEMS) + return luaL_error(L, "hudinfo[] index %d out of range (0 - %d)", i, NUMHUDITEMS-1); LUA_PushUserdata(L, &hudinfo[i], META_HUDINFO); return 1; } diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 0fddebaba..6c99e4f6e 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -146,6 +146,8 @@ static int lib_getState(lua_State *L) lua_remove(L, 1); i = luaL_checkinteger(L, 1); + if (i >= NUMSTATES) + return luaL_error(L, "states[] index %d out of range (0 - %d)", i, NUMSTATES-1); LUA_PushUserdata(L, &states[i], META_STATE); return 1; } @@ -155,7 +157,12 @@ static int lib_setState(lua_State *L) { state_t *state; lua_remove(L, 1); // don't care about states[] userdata. - state = &states[luaL_checkinteger(L, 1)]; // get the state to assign to. + { + UINT32 i = luaL_checkinteger(L, 1); + if (i >= NUMSTATES) + return luaL_error(L, "states[] index %d out of range (0 - %d)", i, NUMSTATES-1); + state = &states[i]; // get the state to assign to. + } luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table. lua_remove(L, 1); // pop state num, don't need it any more. lua_settop(L, 1); // cut the stack here. the only thing left now is the table of data we're assigning to the state. @@ -436,6 +443,8 @@ static int lib_getMobjInfo(lua_State *L) lua_remove(L, 1); i = luaL_checkinteger(L, 1); + if (i >= NUMMOBJTYPES) + return luaL_error(L, "mobjinfo[] index %d out of range (0 - %d)", i, NUMMOBJTYPES-1); LUA_PushUserdata(L, &mobjinfo[i], META_MOBJINFO); return 1; } @@ -445,7 +454,12 @@ static int lib_setMobjInfo(lua_State *L) { mobjinfo_t *info; lua_remove(L, 1); // don't care about mobjinfo[] userdata. - info = &mobjinfo[luaL_checkinteger(L, 1)]; // get the mobjinfo to assign to. + { + UINT32 i = luaL_checkinteger(L, 1); + if (i >= NUMMOBJTYPES) + return luaL_error(L, "mobjinfo[] index %d out of range (0 - %d)", i, NUMMOBJTYPES-1); + info = &mobjinfo[i]; // get the mobjinfo to assign to. + } luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table. lua_remove(L, 1); // pop mobjtype num, don't need it any more. lua_settop(L, 1); // cut the stack here. the only thing left now is the table of data we're assigning to the mobjinfo. @@ -717,6 +731,8 @@ static int lib_getSfxInfo(lua_State *L) lua_remove(L, 1); i = luaL_checkinteger(L, 1); + if (i >= NUMSFX) + return luaL_error(L, "sfxinfo[] index %d out of range (0 - %d)", i, NUMSFX-1); LUA_PushUserdata(L, &S_sfx[i], META_SFXINFO); return 1; } @@ -727,7 +743,12 @@ static int lib_setSfxInfo(lua_State *L) sfxinfo_t *info; lua_remove(L, 1); - info = &S_sfx[luaL_checkinteger(L, 1)]; // get the mobjinfo to assign to. + { + UINT32 i = luaL_checkinteger(L, 1); + if (i >= NUMSFX) + return luaL_error(L, "sfxinfo[] index %d out of range (0 - %d)", i, NUMSFX-1); + info = &S_sfx[i]; // get the mobjinfo to assign to. + } luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table. lua_remove(L, 1); // pop mobjtype num, don't need it any more. lua_settop(L, 1); // cut the stack here. the only thing left now is the table of data we're assigning to the mobjinfo. diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index 53af2e3ac..388fe3175 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -55,7 +55,7 @@ static int lib_getPlayer(lua_State *L) { lua_Integer i = luaL_checkinteger(L, 2); if (i < 0 || i >= MAXPLAYERS) - return luaL_error(L, "players[] index cannot exceed MAXPLAYERS"); + return luaL_error(L, "players[] index %d out of range (0 - %d)", i, MAXPLAYERS-1); if (!playeringame[i]) return 0; if (!players[i].mo) diff --git a/src/lua_skinlib.c b/src/lua_skinlib.c index f07b4564c..545cf55b0 100644 --- a/src/lua_skinlib.c +++ b/src/lua_skinlib.c @@ -244,7 +244,7 @@ static int lib_getSkin(lua_State *L) { i = luaL_checkinteger(L, 2); if (i < 0 || i >= MAXSKINS) - return luaL_error(L, "skins[] index cannot exceed MAXSKINS"); + return luaL_error(L, "skins[] index %d out of range (0 - %d)", i, MAXSKINS-1); if (i >= numskins) return 0; LUA_PushUserdata(L, &skins[i], META_SKIN); From 37575d2219f2ce388192ac1fe373be4a8ef5354a Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Mon, 2 May 2016 04:08:48 -0700 Subject: [PATCH 13/29] Revert "Another thing that probably needed to check for slopes" This breaks plane display for thok barriers This reverts commit ee00da6a74a62c74a56722b7b70fc50aa45c7f05. --- src/r_segs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 3f11bb364..24c01f167 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2046,13 +2046,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } -#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; From 7c79bbc0b3ae17aaa03cc469a63050073f2b3c71 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Mon, 2 May 2016 05:29:30 -0700 Subject: [PATCH 14/29] Proper overflow checking, applied to FOFs and midtex's too This fixes the annoying flickering when you pass by water, FOFs, tall grass, etc. --- src/m_misc.c | 11 --------- src/m_misc.h | 1 - src/r_segs.c | 63 ++++++++++++++++++++++++++++++++------------------ src/r_things.c | 23 +++++------------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/m_misc.c b/src/m_misc.c index 22effdddf..6899059b6 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1787,17 +1787,6 @@ UINT8 M_CountBits(UINT32 num, UINT8 size) return sum; } - -/** Get the most significant bit in a number. - * (integer log2) - */ -UINT8 M_HighestBit(UINT32 num) -{ - UINT8 i = 0; - while (num >>= 1) ++i; - return i; -} - const char *GetRevisionString(void) { static char rev[9] = {0}; diff --git a/src/m_misc.h b/src/m_misc.h index f681bfcb3..5fc4fa63b 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -95,7 +95,6 @@ void M_SetupMemcpy(void); // counting bits, for weapon ammo code, usually FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size); -FUNCMATH UINT8 M_HighestBit(UINT32 num); // Flags for AA trees. #define AATREE_ZUSER 1 // Treat values as z_zone-allocated blocks and set their user fields diff --git a/src/r_segs.c b/src/r_segs.c index 24c01f167..ca24df586 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -288,6 +288,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) line_t *ldef; sector_t *front, *back; INT32 times, repeats; + INT64 overflow_test; #ifdef ESLOPE INT32 range; #endif @@ -485,7 +486,6 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep; } - #ifndef ESLOPE if (curline->linedef->flags & ML_DONTPEGBOTTOM) { @@ -523,6 +523,16 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) // calculate lighting if (maskedtexturecol[dc_x] != INT16_MAX) { + // Check for overflows first + overflow_test = (INT64)centeryfrac - (((INT64)dc_texturemid*spryscale)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) + { + // Eh, no, go away, don't waste our time + spryscale += rw_scalestep; + continue; + } + if (dc_numlights) { lighttable_t **xwalllights; @@ -947,16 +957,38 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) // Set heights according to plane, or slope, whichever { fixed_t left_top, right_top, left_bottom, right_bottom; + INT64 overflow_test; - left_top = *pfloor->t_slope ? P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y) : *pfloor->topheight; - right_top = *pfloor->t_slope ? P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y) : *pfloor->topheight; - left_bottom = *pfloor->b_slope ? P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y) : *pfloor->bottomheight; - right_bottom = *pfloor->b_slope ? P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y) : *pfloor->bottomheight; + if (*pfloor->t_slope) + { + left_top = P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y) - viewz; + right_top = P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y) - viewz; + } + else + left_top = right_top = *pfloor->topheight - viewz; - left_top -= viewz; - right_top -= viewz; - left_bottom -= viewz; - right_bottom -= viewz; + if (*pfloor->b_slope) + { + left_bottom = P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y) - viewz; + right_bottom = P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y) - viewz; + } + else + left_bottom = right_bottom = *pfloor->bottomheight - viewz; + + // overflow tests + // if any of these fail, abandon. likely we're too high up to see anything anyway + overflow_test = (INT64)centeryfrac - (((INT64)left_top*ds->scale1)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; + overflow_test = (INT64)centeryfrac - (((INT64)left_bottom*ds->scale1)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; + overflow_test = (INT64)centeryfrac - (((INT64)right_top*ds->scale2)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; + overflow_test = (INT64)centeryfrac - (((INT64)right_bottom*ds->scale2)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; top_frac = centeryfrac - FixedMul(left_top, ds->scale1); bottom_frac = centeryfrac - FixedMul(left_bottom, ds->scale1); @@ -1133,19 +1165,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); - //Handle over/underflows before they happen. This fixes the textures part of the FOF rendering bug. - //...for the most part, anyway. - if (((signed)dc_texturemid > 0 && (spryscale>>FRACBITS > INT32_MAX / (signed)dc_texturemid)) - || ((signed)dc_texturemid < 0 && (spryscale) && (signed)(dc_texturemid)>>FRACBITS < (INT32_MIN / spryscale))) - { - spryscale += rw_scalestep; -#ifdef ESLOPE - top_frac += top_step; - bottom_frac += bottom_step; -#endif - continue; - } - #ifdef ESLOPE sprtopscreen = windowtop = top_frac; sprbotscreen = windowbottom = bottom_frac; diff --git a/src/r_things.c b/src/r_things.c index 2ec2f6ead..c53f8914c 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -744,10 +744,16 @@ static void R_DrawVisSprite(vissprite_t *vis) patch_t *patch = W_CacheLumpNum(vis->patch, PU_CACHE); fixed_t this_scale = vis->mobj->scale; INT32 x1, x2; + INT64 overflow_test; if (!patch) return; + // Check for overflow + overflow_test = (INT64)centeryfrac - (((INT64)vis->texturemid*vis->scale)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; // fixed point mult would overflow + colfunc = basecolfunc; // hack: this isn't resetting properly somewhere. dc_colormap = vis->colormap; if ((vis->mobj->flags & MF_BOSS) && (vis->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" @@ -1239,15 +1245,6 @@ static void R_ProjectSprite(mobj_t *thing) return; } - // quick check for possible overflows - // if either of these triggers then there's a possibility that drawing is unsafe - if (M_HighestBit(abs(gzt - viewz)) + M_HighestBit(abs(yscale)) > 47 // 31 bits + 16 from the division by FRACUNIT - || M_HighestBit(abs(gz - viewz)) + M_HighestBit(abs(yscale)) > 47) - { - CONS_Debug(DBG_RENDER, "Suspected overflow in ProjectSprite (sprite %s), ignoring\n", sprnames[thing->sprite]); - return; - } - // store information in a vissprite vis = R_NewVisSprite(); vis->heightsec = heightsec; //SoM: 3/17/2000 @@ -1458,14 +1455,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; } - // quick check for possible overflows - // if either of these triggers then there's a possibility that drawing is unsafe - if (M_HighestBit(abs(gzt - viewz)) + M_HighestBit(abs(yscale)) > 47) // 31 bits + 16 from the division by FRACUNIT - { - CONS_Debug(DBG_RENDER, "Suspected overflow in ProjectPrecipitationSprite (sprite %s), ignoring\n", sprnames[thing->sprite]); - return; - } - // store information in a vissprite vis = R_NewVisSprite(); vis->scale = yscale; //< Date: Mon, 2 May 2016 17:04:28 +0100 Subject: [PATCH 15/29] Hack to fix DSZ2 left route waterslide: apply Red's step up changes only to slopes that is, I believe slopes are why he added this code anyway *shrugs* --- src/p_map.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 612f15220..7ed28751f 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1969,22 +1969,28 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) thing->z = (thing->ceilingz = thingtop = tmceilingz) - thing->height; thing->eflags |= MFE_JUSTSTEPPEDDOWN; } - else if (tmceilingz < thingtop && thingtop - tmceilingz <= maxstep) +#ifdef ESLOPE + // HACK TO FIX DSZ2: apply only if slopes are involved + else if (tmceilingslope && tmceilingz < thingtop && thingtop - tmceilingz <= maxstep) { thing->z = (thing->ceilingz = thingtop = tmceilingz) - thing->height; thing->eflags |= MFE_JUSTSTEPPEDDOWN; } +#endif } else if (thing->z == thing->floorz && tmfloorz < thing->z && thing->z - tmfloorz <= maxstep) { thing->z = thing->floorz = tmfloorz; thing->eflags |= MFE_JUSTSTEPPEDDOWN; } - else if (tmfloorz > thing->z && tmfloorz - thing->z <= maxstep) +#ifdef ESLOPE + // HACK TO FIX DSZ2: apply only if slopes are involved + else if (tmfloorslope && tmfloorz > thing->z && tmfloorz - thing->z <= maxstep) { thing->z = thing->floorz = tmfloorz; thing->eflags |= MFE_JUSTSTEPPEDDOWN; } +#endif } if (thing->eflags & MFE_VERTICALFLIP) From eba382df1bbe3e0f8b3ec686dc028d0c51798e1a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 2 May 2016 22:08:14 +0100 Subject: [PATCH 16/29] Fix up the ceiling sky hack (yuck) a bit so my commit doesn't break thok barrier planes now Interestingly these changes somehow fix how thok barrier walls block the planes, which was an issue even before slopes I believe --- src/r_segs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index ca24df586..9b1533daa 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1903,9 +1903,11 @@ void R_StoreWallRange(INT32 start, INT32 stop) && backsector->ceilingpic == skyflatnum) { #ifdef ESLOPE - worldtopslope = worldhighslope = + worldtopslope = max(worldtopslope, worldhighslope); + worldhighslope = worldtopslope; #endif - worldtop = worldhigh; + worldtop = max(worldtop, worldhigh); + worldhigh = worldtop; } ds_p->sprtopclip = ds_p->sprbottomclip = NULL; @@ -2065,8 +2067,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } +#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; From 782f6e9330db8882e972e039edf840a90da4ebc2 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Mon, 2 May 2016 22:25:00 -0700 Subject: [PATCH 17/29] dupx and dupy are important for Lua too --- src/lua_hudlib.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index c4a72f074..33cc1b367 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -528,6 +528,22 @@ static int libd_height(lua_State *L) return 1; } +static int libd_dupx(lua_State *L) +{ + HUDONLY + lua_pushinteger(L, vid.dupx); // push integral scale (patch scale) + lua_pushfixed(L, vid.fdupx); // push fixed point scale (position scale) + return 2; +} + +static int libd_dupy(lua_State *L) +{ + HUDONLY + lua_pushinteger(L, vid.dupy); // push integral scale (patch scale) + lua_pushfixed(L, vid.fdupy); // push fixed point scale (position scale) + return 2; +} + static int libd_renderer(lua_State *L) { HUDONLY @@ -552,6 +568,8 @@ static luaL_Reg lib_draw[] = { {"getColormap", libd_getColormap}, {"width", libd_width}, {"height", libd_height}, + {"dupx", libd_dupx}, + {"dupy", libd_dupy}, {"renderer", libd_renderer}, {NULL, NULL} }; From 8adacf7c3234538ec814f2748f6ae95f88d4011e Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Tue, 3 May 2016 06:02:52 -0700 Subject: [PATCH 18/29] update to use 2.1.15 assets --- .travis.yml | 4 ++-- src/config.h.in | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 54c5901d0..9fd65786f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,8 @@ addons: before_script: - mkdir -p $HOME/srb2_cache - - wget --verbose --server-response -c http://rosenthalcastle.org/srb2/SRB2-v2114-assets.7z -O $HOME/srb2_cache/SRB2-v2114-assets.7z - - 7z x $HOME/srb2_cache/SRB2-v2114-assets.7z -oassets + - wget --verbose --server-response -c http://rosenthalcastle.org/srb2/SRB2-v2115-assets.7z -O $HOME/srb2_cache/SRB2-v2115-assets.7z + - 7z x $HOME/srb2_cache/SRB2-v2115-assets.7z -oassets - mkdir build - cd build - cmake .. diff --git a/src/config.h.in b/src/config.h.in index eef4fec13..f95a0e975 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -29,14 +29,14 @@ #else /* Manually defined asset hashes for non-CMake builds - * Last updated 2000 / 00 / 00 + * Last updated 2015 / 05 / 03 */ #define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" #define ASSET_HASH_ZONES_DTA "303838c6c534d9540288360fa49cca60" #define ASSET_HASH_PLAYER_DTA "cfca0f1c73023cbbd8f844f45480f799" #define ASSET_HASH_RINGS_DTA "85901ad4bf94637e5753d2ac2c03ea26" #ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "0c66790502e648bfce90fdc5bb15722e" +#define ASSET_HASH_PATCH_DTA "6db9bd55c2f9b04123740ad71ea6b841" #endif #endif From 2c221da45358dfbd477a05a33d731569dcb53d45 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 3 May 2016 15:26:54 +0100 Subject: [PATCH 19/29] Revert "Fix up the ceiling sky hack (yuck) a bit so my commit doesn't break thok barrier planes now" This created HOMs in THZ2's skybox, ack. This reverts commit eba382df1bbe3e0f8b3ec686dc028d0c51798e1a. --- src/r_segs.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 9b1533daa..ca24df586 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1903,11 +1903,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) && backsector->ceilingpic == skyflatnum) { #ifdef ESLOPE - worldtopslope = max(worldtopslope, worldhighslope); - worldhighslope = worldtopslope; + worldtopslope = worldhighslope = #endif - worldtop = max(worldtop, worldhigh); - worldhigh = worldtop; + worldtop = worldhigh; } ds_p->sprtopclip = ds_p->sprbottomclip = NULL; @@ -2067,13 +2065,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) markceiling = false; } -#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; From 652ddfef9a050377cbfee26c4f28546047a80e42 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Wed, 4 May 2016 03:23:29 -0700 Subject: [PATCH 20/29] invalid skins when starting a local game no longer break see https://mb.srb2.org/showthread.php?t=41370 --- src/d_netcmd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index b4ba92182..4f0a9f50c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1113,6 +1113,13 @@ static void SendNameAndColor(void) players[consoleplayer].mo->color = (UINT8)players[consoleplayer].skincolor; } } + else + { + cv_skin.value = players[consoleplayer].skin; + CV_StealthSet(&cv_skin, skins[players[consoleplayer].skin].name); + // will always be same as current + SetPlayerSkin(consoleplayer, cv_skin.string); + } return; } @@ -1230,6 +1237,13 @@ static void SendNameAndColor2(void) players[secondplaya].mo->color = players[secondplaya].skincolor; } } + else + { + cv_skin.value = players[secondplaya].skin; + CV_StealthSet(&cv_skin, skins[players[secondplaya].skin].name); + // will always be same as current + SetPlayerSkin(secondplaya, cv_skin.string); + } return; } From 93a9b0cc84371ceeea6e2616b1c1440eb1d0ef3d Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Wed, 4 May 2016 05:43:05 -0700 Subject: [PATCH 21/29] update patch stuff again. please don't make me do this again. --- .travis.yml | 4 ++-- src/config.h.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9fd65786f..9878e6ca9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,8 @@ addons: before_script: - mkdir -p $HOME/srb2_cache - - wget --verbose --server-response -c http://rosenthalcastle.org/srb2/SRB2-v2115-assets.7z -O $HOME/srb2_cache/SRB2-v2115-assets.7z - - 7z x $HOME/srb2_cache/SRB2-v2115-assets.7z -oassets + - wget --verbose --server-response -c http://rosenthalcastle.org/srb2/SRB2-v2115-assets-2.7z -O $HOME/srb2_cache/SRB2-v2115-assets-2.7z + - 7z x $HOME/srb2_cache/SRB2-v2115-assets-2.7z -oassets - mkdir build - cd build - cmake .. diff --git a/src/config.h.in b/src/config.h.in index f95a0e975..5f06ec45d 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -36,7 +36,7 @@ #define ASSET_HASH_PLAYER_DTA "cfca0f1c73023cbbd8f844f45480f799" #define ASSET_HASH_RINGS_DTA "85901ad4bf94637e5753d2ac2c03ea26" #ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "6db9bd55c2f9b04123740ad71ea6b841" +#define ASSET_HASH_PATCH_DTA "dbbf8bc6121618ee3be2d5b14650429b" #endif #endif From bd935a6a5cbdd0e844b4b0051bad8a75d5f2729a Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Wed, 4 May 2016 05:45:18 -0700 Subject: [PATCH 22/29] that should be skin2, not skin --- src/d_netcmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4f0a9f50c..24fa7caa7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1239,10 +1239,10 @@ static void SendNameAndColor2(void) } else { - cv_skin.value = players[secondplaya].skin; - CV_StealthSet(&cv_skin, skins[players[secondplaya].skin].name); + cv_skin2.value = players[secondplaya].skin; + CV_StealthSet(&cv_skin2, skins[players[secondplaya].skin].name); // will always be same as current - SetPlayerSkin(secondplaya, cv_skin.string); + SetPlayerSkin(secondplaya, cv_skin2.string); } return; } From a4a5ac161ff6f75bdc2107b65faf3f9297969727 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 4 May 2016 20:14:24 +0100 Subject: [PATCH 23/29] One line through selfish methods. Probably works in both Next and Internal. --- src/f_finale.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/f_finale.c b/src/f_finale.c index 9c3da5a68..3d0af7474 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1006,6 +1006,7 @@ static const char *credits[] = { "\1Texture Artists", "Ryan \"Blaze Hedgehog\" Bloom", "Buddy \"KinkaJoy\" Fischer", + "Vivian \"toaster\" Grannell", "Kepa \"Nev3r\" Iceta", "Jarrett \"JEV3\" Voight", "", From 4274fb7b92497e7abbb5bfd08aa88dc246641b25 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Thu, 5 May 2016 02:31:53 -0700 Subject: [PATCH 24/29] I hate FOFs; attempted to fix extra tall FOFs breaking Previous overflow fix resulted in extra tall FOFs disappearing up close (see: ERZ1's elevators at start) This works "better" in that only some lighting bugs and really really finicky visual glitches show now. I give up trying to totally fix this stuff dfsdfgdgf --- src/r_segs.c | 62 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index ca24df586..251367af9 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -718,7 +718,8 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) line_t *newline = NULL; #ifdef ESLOPE // Render FOF sides kinda like normal sides, with the frac and step and everything - fixed_t top_frac, top_step, bottom_frac, bottom_step; + // NOTE: INT64 instead of fixed_t because overflow concerns + INT64 top_frac, top_step, bottom_frac, bottom_step; #endif void (*colfunc_2s) (column_t *); @@ -798,6 +799,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) #ifdef ESLOPE fixed_t leftheight, rightheight; fixed_t pfloorleft, pfloorright; + INT64 overflow_test; #endif light = &frontsector->lightlist[i]; rlight = &dc_lightlist[p]; @@ -833,6 +835,14 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) leftheight -= viewz; rightheight -= viewz; + + overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + rlight->height = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->heightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); @@ -842,7 +852,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) continue; if (light->height > *pfloor->topheight && i+1 < dc_numlights && frontsector->lightlist[i+1].height > *pfloor->topheight) - continue; + continue; lheight = light->height;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : light->height; rlight->heightstep = -FixedMul (rw_scalestep, (lheight - viewz)); @@ -861,6 +871,13 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) leftheight -= viewz; rightheight -= viewz; + overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); + if (overflow_test < 0) overflow_test = -overflow_test; + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + rlight->botheight = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->botheightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); @@ -957,7 +974,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) // Set heights according to plane, or slope, whichever { fixed_t left_top, right_top, left_bottom, right_bottom; - INT64 overflow_test; if (*pfloor->t_slope) { @@ -975,25 +991,11 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else left_bottom = right_bottom = *pfloor->bottomheight - viewz; - // overflow tests - // if any of these fail, abandon. likely we're too high up to see anything anyway - overflow_test = (INT64)centeryfrac - (((INT64)left_top*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; - overflow_test = (INT64)centeryfrac - (((INT64)left_bottom*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; - overflow_test = (INT64)centeryfrac - (((INT64)right_top*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; - overflow_test = (INT64)centeryfrac - (((INT64)right_bottom*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) return; - - top_frac = centeryfrac - FixedMul(left_top, ds->scale1); - bottom_frac = centeryfrac - FixedMul(left_bottom, ds->scale1); - top_step = centeryfrac - FixedMul(right_top, ds->scale2); - bottom_step = centeryfrac - FixedMul(right_bottom, ds->scale2); + // using INT64 to avoid 32bit overflow + top_frac = (INT64)centeryfrac - (((INT64)left_top * ds->scale1) >> FRACBITS); + bottom_frac = (INT64)centeryfrac - (((INT64)left_bottom * ds->scale1) >> FRACBITS); + top_step = (INT64)centeryfrac - (((INT64)right_top * ds->scale2) >> FRACBITS); + bottom_step = (INT64)centeryfrac - (((INT64)right_bottom * ds->scale2) >> FRACBITS); top_step = (top_step-top_frac)/(range); bottom_step = (bottom_step-bottom_frac)/(range); @@ -1019,8 +1021,12 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) INT32 lighteffect = 0; #ifdef ESLOPE - sprtopscreen = windowtop = top_frac; - sprbotscreen = windowbottom = bottom_frac; + if (top_frac > (INT64)INT32_MAX) sprtopscreen = windowtop = INT32_MAX; + else if (top_frac < (INT64)INT32_MIN) sprtopscreen = windowtop = INT32_MIN; + else sprtopscreen = windowtop = (fixed_t)top_frac; + if (bottom_frac > (INT64)INT32_MAX) sprbotscreen = windowbottom = INT32_MAX; + else if (bottom_frac < (INT64)INT32_MIN) sprbotscreen = windowbottom = INT32_MIN; + else sprbotscreen = windowbottom = (fixed_t)bottom_frac; top_frac += top_step; bottom_frac += bottom_step; @@ -1166,8 +1172,12 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); #ifdef ESLOPE - sprtopscreen = windowtop = top_frac; - sprbotscreen = windowbottom = bottom_frac; + if (top_frac > (INT64)INT32_MAX) sprtopscreen = windowtop = INT32_MAX; + else if (top_frac < (INT64)INT32_MIN) sprtopscreen = windowtop = INT32_MIN; + else sprtopscreen = windowtop = (fixed_t)top_frac; + if (bottom_frac > (INT64)INT32_MAX) sprbotscreen = windowbottom = INT32_MAX; + else if (bottom_frac < (INT64)INT32_MIN) sprbotscreen = windowbottom = INT32_MIN; + else sprbotscreen = windowbottom = (fixed_t)bottom_frac; top_frac += top_step; bottom_frac += bottom_step; From 5e8be250a71bc5fe1956e3b90e6977b7f6a80e62 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Thu, 5 May 2016 06:33:19 -0700 Subject: [PATCH 25/29] fix going under FOFs causing artifacts i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs i hate FOFs --- src/r_segs.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 251367af9..a5aec0346 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1005,6 +1005,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } #endif +#define CLAMPMAX INT32_MAX +#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out. + // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++) { @@ -1021,12 +1024,12 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) INT32 lighteffect = 0; #ifdef ESLOPE - if (top_frac > (INT64)INT32_MAX) sprtopscreen = windowtop = INT32_MAX; - else if (top_frac < (INT64)INT32_MIN) sprtopscreen = windowtop = INT32_MIN; - else sprtopscreen = windowtop = (fixed_t)top_frac; - if (bottom_frac > (INT64)INT32_MAX) sprbotscreen = windowbottom = INT32_MAX; - else if (bottom_frac < (INT64)INT32_MIN) sprbotscreen = windowbottom = INT32_MIN; - else sprbotscreen = windowbottom = (fixed_t)bottom_frac; + if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; + else if (top_frac < (INT64)CLAMPMIN) sprtopscreen = windowtop = CLAMPMIN; + else sprtopscreen = windowtop = (fixed_t)top_frac; + if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; + else if (bottom_frac < (INT64)CLAMPMIN) sprbotscreen = windowbottom = CLAMPMIN; + else sprbotscreen = windowbottom = (fixed_t)bottom_frac; top_frac += top_step; bottom_frac += bottom_step; @@ -1172,12 +1175,12 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); #ifdef ESLOPE - if (top_frac > (INT64)INT32_MAX) sprtopscreen = windowtop = INT32_MAX; - else if (top_frac < (INT64)INT32_MIN) sprtopscreen = windowtop = INT32_MIN; - else sprtopscreen = windowtop = (fixed_t)top_frac; - if (bottom_frac > (INT64)INT32_MAX) sprbotscreen = windowbottom = INT32_MAX; - else if (bottom_frac < (INT64)INT32_MIN) sprbotscreen = windowbottom = INT32_MIN; - else sprbotscreen = windowbottom = (fixed_t)bottom_frac; + if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; + else if (top_frac < (INT64)CLAMPMIN) sprtopscreen = windowtop = CLAMPMIN; + else sprtopscreen = windowtop = (fixed_t)top_frac; + if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; + else if (bottom_frac < (INT64)CLAMPMIN) sprbotscreen = windowbottom = CLAMPMIN; + else sprbotscreen = windowbottom = (fixed_t)bottom_frac; top_frac += top_step; bottom_frac += bottom_step; @@ -1196,6 +1199,9 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } } colfunc = wallcolfunc; + +#undef CLAMPMAX +#undef CLAMPMIN } // From ce4b5db49434ef1db88109b27d98d69fd100de89 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Thu, 5 May 2016 07:20:53 -0700 Subject: [PATCH 26/29] organize conditions in a more optimized way the most common condition (correct drawing) shouldn't be last, however it can't be first without making the conditions longer anyway. it's a nitpicky thing, but this is the renderer we're talking about here. --- src/r_segs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index a5aec0346..120735be3 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1025,11 +1025,11 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) #ifdef ESLOPE if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac < (INT64)CLAMPMIN) sprtopscreen = windowtop = CLAMPMIN; - else sprtopscreen = windowtop = (fixed_t)top_frac; + else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; + else sprtopscreen = windowtop = CLAMPMIN; if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac < (INT64)CLAMPMIN) sprbotscreen = windowbottom = CLAMPMIN; - else sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else sprbotscreen = windowbottom = CLAMPMIN; top_frac += top_step; bottom_frac += bottom_step; @@ -1176,11 +1176,11 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) #ifdef ESLOPE if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac < (INT64)CLAMPMIN) sprtopscreen = windowtop = CLAMPMIN; - else sprtopscreen = windowtop = (fixed_t)top_frac; + else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; + else sprtopscreen = windowtop = CLAMPMIN; if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac < (INT64)CLAMPMIN) sprbotscreen = windowbottom = CLAMPMIN; - else sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else sprbotscreen = windowbottom = CLAMPMIN; top_frac += top_step; bottom_frac += bottom_step; From 857cd3236954366c75f1ce0ee99b56a184d29d47 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 5 May 2016 17:49:57 +0100 Subject: [PATCH 27/29] step through light heights too if there is an overflow for a midtexture column --- src/r_segs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/r_segs.c b/src/r_segs.c index 120735be3..a254d43aa 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -529,6 +529,14 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) { // Eh, no, go away, don't waste our time + if (dc_numlights) + { + for (i = 0; i < dc_numlights; i++) + { + rlight = &dc_lightlist[i]; + rlight->height += rlight->heightstep; + } + } spryscale += rw_scalestep; continue; } From c8cdded81e2b7f73017be371083454e2b56dc884 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 5 May 2016 18:19:06 +0100 Subject: [PATCH 28/29] Multiply downwards thrust on slopes by the actual "gravity" variable. Also account for mobj scale (it affects gravity added in P_CheckGravity, so it makes sense here). --- src/p_slopes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/p_slopes.c b/src/p_slopes.c index 797fe46b4..d8f2936b8 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -1133,7 +1133,9 @@ void P_ButteredSlope(mobj_t *mo) // This makes it harder to zigzag up steep slopes, as well as allows greater top speed when rolling down // Multiply by gravity - thrust = FixedMul(thrust, FRACUNIT/2); // TODO actually get this + thrust = FixedMul(thrust, gravity); // TODO account for per-sector gravity etc + // Multiply by scale (gravity strength depends on mobj scale) + thrust = FixedMul(thrust, mo->scale); P_Thrust(mo, mo->standingslope->xydirection, thrust); } From 604ae7d072c94515c4724eb395b10c24789df348 Mon Sep 17 00:00:00 2001 From: Inuyasha Date: Thu, 5 May 2016 19:23:46 -0700 Subject: [PATCH 29/29] move variable fetching from Lua out of min/max macros --- src/lua_mathlib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lua_mathlib.c b/src/lua_mathlib.c index a55e3a0e4..d78cb23a4 100644 --- a/src/lua_mathlib.c +++ b/src/lua_mathlib.c @@ -32,13 +32,17 @@ static int lib_abs(lua_State *L) static int lib_min(lua_State *L) { - lua_pushinteger(L, min(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2))); + int a = luaL_checkinteger(L, 1); + int b = luaL_checkinteger(L, 2); + lua_pushinteger(L, min(a,b)); return 1; } static int lib_max(lua_State *L) { - lua_pushinteger(L, max(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2))); + int a = luaL_checkinteger(L, 1); + int b = luaL_checkinteger(L, 2); + lua_pushinteger(L, max(a,b)); return 1; }