diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 93b8c133ba9cc4cef48e6ae34edb7d77c779d2a2..fd67bb0f9338fb44f48233f963e89628fb180390 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -176,10 +176,25 @@ typedef struct //#define MAX_TRANSPARENTWALL 256 +/*typedef enum { + PLANE_NORMAL = 0, + PLANE_POLYOBJECT = 1 +} EPlaneIsPolyObj;*/ + +typedef enum { + PSIDE_FLOOR = 0, + PSIDE_CEILING = 1 +} EPlaneSide; + typedef struct { - extrasubsector_t *xsub; - boolean isceiling; + union { + extrasubsector_t *xsub; + polyobj_t *polyobject; + }; + boolean ispolyobj; //tag for above union + + EPlaneSide pside; fixed_t fixedheight; levelflat_t *levelflat; sector_t *FOFSector; @@ -192,19 +207,6 @@ typedef struct //static size_t numplanes = 0; // a list of transparent floors to be drawn //static planeinfo_t *planeinfo = NULL; -typedef struct -{ - polyobj_t *polyobject; - boolean isceiling; - fixed_t fixedheight; - levelflat_t *levelflat; - sector_t *FOFSector; - planetype_t planetype; - extracolormap_t *colormap; - UINT8 lightlevel; - UINT8 opacity; -} polyplaneinfo_t; - //static size_t numpolyplanes = 0; // a list of transparent poyobject floors to be drawn //static polyplaneinfo_t *polyplaneinfo = NULL; @@ -388,6 +390,9 @@ static void HWR_RenderPlane(const planeinfo_t *plane) static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; + I_Assert(plane); + I_Assert(plane->ispolyobj == false); + // no convex poly were generated for this subsector if (!plane->xsub->planepoly) return; @@ -396,16 +401,16 @@ static void HWR_RenderPlane(const planeinfo_t *plane) // Get the slope pointer to simplify future code if (plane->FOFSector) { - if (plane->FOFSector->f_slope && !plane->isceiling) //plane->side == FLOOR + if (plane->FOFSector->f_slope && plane->pside == PSIDE_FLOOR) slope = plane->FOFSector->f_slope; - else if (plane->FOFSector->c_slope && plane->isceiling) //plane->side == CEILING + else if (plane->FOFSector->c_slope && plane->pside == PSIDE_CEILING) slope = plane->FOFSector->c_slope; } else { - if (gr_frontsector->f_slope && !plane->isceiling) + if (gr_frontsector->f_slope && plane->pside == PSIDE_FLOOR) slope = gr_frontsector->f_slope; - else if (gr_frontsector->c_slope && plane->isceiling) + else if (gr_frontsector->c_slope && plane->pside == PSIDE_CEILING) slope = gr_frontsector->c_slope; } @@ -485,13 +490,13 @@ static void HWR_RenderPlane(const planeinfo_t *plane) if (plane->FOFSector != NULL) { - if (!plane->isceiling) // it's a floor + if (plane->pside == PSIDE_FLOOR) { scrollx = FIXED_TO_FLOAT(plane->FOFSector->floor_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(plane->FOFSector->floor_yoffs)/fflatheight; angle = plane->FOFSector->floorpic_angle; } - else // it's a ceiling + else if(plane->pside == PSIDE_CEILING) { scrollx = FIXED_TO_FLOAT(plane->FOFSector->ceiling_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(plane->FOFSector->ceiling_yoffs)/fflatheight; @@ -500,13 +505,13 @@ static void HWR_RenderPlane(const planeinfo_t *plane) } else if (gr_frontsector) { - if (!plane->isceiling) // it's a floor + if (plane->pside == PSIDE_FLOOR) { scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatheight; angle = gr_frontsector->floorpic_angle; } - else // it's a ceiling + else if(plane->pside == PSIDE_CEILING) { scrollx = FIXED_TO_FLOAT(gr_frontsector->ceiling_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(gr_frontsector->ceiling_yoffs)/fflatheight; @@ -2923,6 +2928,8 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) #endif } +static void HWR_AddTransparentFloor(const planeinfo_t *plane); + #ifdef POLYOBJECTS // @@ -2968,7 +2975,7 @@ static inline void HWR_AddPolyObjectSegs(void) } #ifdef POLYOBJECTS_PLANES -static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) +static void HWR_RenderPolyObjectPlane(const planeinfo_t *plane) { float height; //constant y for all points on the convex flat polygon FOutVector *v3d; @@ -2986,9 +2993,12 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) static FOutVector *planeVerts = NULL; static UINT16 numAllocedPlaneVerts = 0; - nrPlaneVerts = polyplane->polyobject->numVertices; + I_Assert(plane); + I_Assert(plane->ispolyobj == true); - height = FIXED_TO_FLOAT(polyplane->fixedheight); + nrPlaneVerts = plane->polyobject->numVertices; + + height = FIXED_TO_FLOAT(plane->fixedheight); if (nrPlaneVerts < 3) //not even a triangle ? return; @@ -3008,18 +3018,18 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) } // set texture for polygon - if (polyplane->levelflat != NULL) + if (plane->levelflat != NULL) { - HWR_GetLevelFlat(polyplane->levelflat); - if (polyplane->levelflat->type == LEVELFLAT_TEXTURE) + HWR_GetLevelFlat(plane->levelflat); + if (plane->levelflat->type == LEVELFLAT_TEXTURE) { - fflatwidth = textures[polyplane->levelflat->u.texture.num]->width; - fflatheight = textures[polyplane->levelflat->u.texture.num]->height; + fflatwidth = textures[plane->levelflat->u.texture.num]->width; + fflatheight = textures[plane->levelflat->u.texture.num]->height; texflat = true; } - else if (polyplane->levelflat->type == LEVELFLAT_FLAT) + else if (plane->levelflat->type == LEVELFLAT_FLAT) { - len = W_LumpLength(polyplane->levelflat->u.flat.lumpnum); + len = W_LumpLength(plane->levelflat->u.flat.lumpnum); switch (len) { @@ -3053,36 +3063,36 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) HWD.pfnSetTexture(NULL); // reference point for flat texture coord for each vertex around the polygon - flatxref = (float)((polyplane->polyobject->origVerts[0].x & (~flatflag)) / fflatwidth); - flatyref = (float)((polyplane->polyobject->origVerts[0].y & (~flatflag)) / fflatheight); + flatxref = (float)((plane->polyobject->origVerts[0].x & (~flatflag)) / fflatwidth); + flatyref = (float)((plane->polyobject->origVerts[0].y & (~flatflag)) / fflatheight); // transform v3d = planeVerts; - if (polyplane->FOFSector != NULL) + if (plane->FOFSector != NULL) { - if (!polyplane->isceiling) // it's a floor + if (plane->pside == PSIDE_FLOOR) { - scrollx = FIXED_TO_FLOAT(polyplane->FOFSector->floor_xoffs)/fflatwidth; - scrolly = FIXED_TO_FLOAT(polyplane->FOFSector->floor_yoffs)/fflatheight; - angle = polyplane->FOFSector->floorpic_angle>>ANGLETOFINESHIFT; + scrollx = FIXED_TO_FLOAT(plane->FOFSector->floor_xoffs)/fflatwidth; + scrolly = FIXED_TO_FLOAT(plane->FOFSector->floor_yoffs)/fflatheight; + angle = plane->FOFSector->floorpic_angle>>ANGLETOFINESHIFT; } - else // it's a ceiling + else if(plane->pside == PSIDE_CEILING) { - scrollx = FIXED_TO_FLOAT(polyplane->FOFSector->ceiling_xoffs)/fflatwidth; - scrolly = FIXED_TO_FLOAT(polyplane->FOFSector->ceiling_yoffs)/fflatheight; - angle = polyplane->FOFSector->ceilingpic_angle>>ANGLETOFINESHIFT; + scrollx = FIXED_TO_FLOAT(plane->FOFSector->ceiling_xoffs)/fflatwidth; + scrolly = FIXED_TO_FLOAT(plane->FOFSector->ceiling_yoffs)/fflatheight; + angle = plane->FOFSector->ceilingpic_angle>>ANGLETOFINESHIFT; } } else if (gr_frontsector) { - if (!polyplane->isceiling) // it's a floor + if (plane->pside == PSIDE_FLOOR) { scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatheight; angle = gr_frontsector->floorpic_angle>>ANGLETOFINESHIFT; } - else // it's a ceiling + else if(plane->pside == PSIDE_CEILING) { scrollx = FIXED_TO_FLOAT(gr_frontsector->ceiling_xoffs)/fflatwidth; scrolly = FIXED_TO_FLOAT(gr_frontsector->ceiling_yoffs)/fflatheight; @@ -3112,13 +3122,13 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) // Means the flat is offset based on the original vertex locations if (texflat) { - v3d->s = (float)(FIXED_TO_FLOAT(polyplane->polyobject->origVerts[i].x) / fflatwidth) + scrollx; - v3d->t = -(float)(FIXED_TO_FLOAT(polyplane->polyobject->origVerts[i].y) / fflatheight) + scrolly; + v3d->s = (float)(FIXED_TO_FLOAT(plane->polyobject->origVerts[i].x) / fflatwidth) + scrollx; + v3d->t = -(float)(FIXED_TO_FLOAT(plane->polyobject->origVerts[i].y) / fflatheight) + scrolly; } else { - v3d->s = (float)((FIXED_TO_FLOAT(polyplane->polyobject->origVerts[i].x) / fflatwidth) - flatxref + scrollx); - v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(polyplane->polyobject->origVerts[i].y) / fflatheight) + scrolly); + v3d->s = (float)((FIXED_TO_FLOAT(plane->polyobject->origVerts[i].x) / fflatwidth) - flatxref + scrollx); + v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(plane->polyobject->origVerts[i].y) / fflatheight) + scrolly); } // Need to rotate before translate @@ -3132,15 +3142,15 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) v3d->t = (FIXED_TO_FLOAT(-FixedMul(tempxs, FINESINE(angle)) - FixedMul(tempyt, FINECOSINE(angle)))); } - v3d->x = FIXED_TO_FLOAT(polyplane->polyobject->vertices[i]->x); + v3d->x = FIXED_TO_FLOAT(plane->polyobject->vertices[i]->x); v3d->y = height; - v3d->z = FIXED_TO_FLOAT(polyplane->polyobject->vertices[i]->y); + v3d->z = FIXED_TO_FLOAT(plane->polyobject->vertices[i]->y); } hwdblendmode_t blendmode; EPolyFlags polyflags; - if (polyplane->planetype == PLANE_TRANSLUCENT) + if (plane->planetype == PLANE_TRANSLUCENT) { blendmode = HWD_BLEND_TRANSLUCENT; polyflags = PF_Occlude; @@ -3150,23 +3160,21 @@ static void HWR_RenderPolyObjectPlane(const polyplaneinfo_t *polyplane) polyflags = 0; } - HWR_Lighting(polyplane->lightlevel, polyplane->colormap, polyplane->opacity, HWD_SHADER_FLOOR); + HWR_Lighting(plane->lightlevel, plane->colormap, plane->opacity, HWD_SHADER_FLOOR); HWR_RenderSurface(planeVerts, nrPlaneVerts, blendmode, polyflags); } -static void HWR_AddTransparentPolyobjectFloor(const polyplaneinfo_t *polyplane); - -static void HWR_AddPolyPlane(polyobj_t *polyobject, boolean isceiling) +static void HWR_AddPolyPlane(polyobj_t *polyobject, EPlaneSide pside) { sector_t *polyobjsector = polyobject->lines[0]->backsector; levelflat_t *levelflat; fixed_t fixedheight; - if(isceiling == false) { //FLOOR + if(pside == PSIDE_FLOOR) { levelflat = &levelflats[polyobjsector->floorpic]; fixedheight = polyobjsector->floorheight; - } else { //CEILING + } else if(pside == PSIDE_CEILING) { levelflat = &levelflats[polyobjsector->ceilingpic]; fixedheight = polyobjsector->ceilingheight; } @@ -3184,9 +3192,10 @@ static void HWR_AddPolyPlane(polyobj_t *polyobject, boolean isceiling) colormap = *gr_frontsector->lightlist[lightindex].extra_colormap; } - polyplaneinfo_t plane = { + planeinfo_t plane = { .polyobject = polyobject, - .isceiling = isceiling, + .ispolyobj = true, + .pside = pside, .fixedheight = fixedheight, .levelflat = levelflat, .FOFSector = polyobjsector, @@ -3198,7 +3207,7 @@ static void HWR_AddPolyPlane(polyobj_t *polyobject, boolean isceiling) { plane.planetype = PLANE_TRANSLUCENT; plane.opacity = trans2alpha[polyobject->translucency]; - HWR_AddTransparentPolyobjectFloor(&plane); + HWR_AddTransparentFloor(&plane); } else { @@ -3230,22 +3239,20 @@ static void HWR_AddPolyObjectPlanes(void) && polyobjsector->floorheight >= gr_frontsector->floorheight && (viewz < polyobjsector->floorheight)) { - HWR_AddPolyPlane(po_ptrs[i], false); + HWR_AddPolyPlane(po_ptrs[i], PSIDE_FLOOR); } if (polyobjsector->ceilingheight >= gr_frontsector->floorheight && polyobjsector->ceilingheight <= gr_frontsector->ceilingheight && (viewz > polyobjsector->ceilingheight)) { - HWR_AddPolyPlane(po_ptrs[i], true); + HWR_AddPolyPlane(po_ptrs[i], PSIDE_CEILING); } } } #endif #endif -static void HWR_AddTransparentFloor(const planeinfo_t *plane); - -static void HWR_AddFOFPlane(size_t num, ffloor_t *rover, boolean isceiling, INT32 lightindex) +static void HWR_AddFOFPlane(size_t num, ffloor_t *rover, EPlaneSide pside, INT32 lightindex) { sector_t *FOFSector = rover->master->frontsector; UINT8 lightlevel = *gr_frontsector->lightlist[lightindex].lightlevel; @@ -3254,17 +3261,18 @@ static void HWR_AddFOFPlane(size_t num, ffloor_t *rover, boolean isceiling, INT3 levelflat_t *levelflat; fixed_t fixedheight; - if(isceiling == false) { //FLOOR + if(pside == PSIDE_FLOOR) { levelflat = &levelflats[*rover->bottompic]; fixedheight = *rover->bottomheight; - } else { //CEILING + } else if(pside == PSIDE_CEILING) { levelflat = &levelflats[*rover->toppic]; fixedheight = *rover->topheight; } planeinfo_t plane = { .xsub = &extrasubsectors[num], - .isceiling = isceiling, + .ispolyobj = false, + .pside = pside, .fixedheight = fixedheight, .FOFSector = FOFSector, .lightlevel = lightlevel, @@ -3426,53 +3434,49 @@ static void HWR_Subsector(const size_t num) // render floor ? #ifdef DOPLANES - // yeah, easy backface cull! :) - if (cullFloorHeight < dup_viewz) { - if (gr_frontsector->floorpic != skyflatnum) { - if (sub->validcount != validcount) { //TODO: move it out? - const planeinfo_t plane = { - .xsub = &extrasubsectors[num], - .isceiling = false, //FLOOR + { + planeinfo_t plane = { + .xsub = &extrasubsectors[num], + .ispolyobj = false, + .FOFSector = NULL, + .planetype = PLANE_OPAQUE, + .opacity = 0xFF + }; + // yeah, easy backface cull! :) + if (cullFloorHeight < dup_viewz) { + if (gr_frontsector->floorpic != skyflatnum) { + if (sub->validcount != validcount) { //TODO: move it out? + plane.pside = PSIDE_FLOOR; // Hack to make things continue to work around slopes. - .fixedheight = (locFloorHeight == cullFloorHeight) ? locFloorHeight : gr_frontsector->floorheight, - .levelflat = &levelflats[gr_frontsector->floorpic], - .FOFSector = NULL, - .planetype = PLANE_OPAQUE, - .colormap = floorcolormap, - .lightlevel = floorlightlevel, - .opacity = 0xFF - }; - HWR_RenderPlane(&plane); - } - } - else { + plane.fixedheight = (locFloorHeight == cullFloorHeight) ? locFloorHeight : gr_frontsector->floorheight; + plane.levelflat = &levelflats[gr_frontsector->floorpic]; + plane.colormap = floorcolormap; + plane.lightlevel = floorlightlevel; + HWR_RenderPlane(&plane); + } + } else { #ifdef POLYSKY - HWR_RenderSkyPlane(&extrasubsectors[num], locFloorHeight); + HWR_RenderSkyPlane(&extrasubsectors[num], locFloorHeight); #endif + } } - } - if (cullCeilingHeight > dup_viewz) { - if (gr_frontsector->ceilingpic != skyflatnum) { - if (sub->validcount != validcount) { - const planeinfo_t plane = { - .xsub = &extrasubsectors[num], - .isceiling = true, //CEILING + if (cullCeilingHeight > dup_viewz) { + if (gr_frontsector->ceilingpic != skyflatnum) { + if (sub->validcount != validcount) { + plane.pside = PSIDE_CEILING; // Hack to make things continue to work around slopes. - .fixedheight = (locCeilingHeight == cullCeilingHeight) ? locCeilingHeight : gr_frontsector->ceilingheight, - .levelflat = &levelflats[gr_frontsector->ceilingpic], - .FOFSector = NULL, - .planetype = PLANE_OPAQUE, - .colormap = ceilingcolormap, - .lightlevel = ceilinglightlevel, - .opacity = 0xFF - }; - HWR_RenderPlane(&plane); - } - } else { + plane.fixedheight = (locCeilingHeight == cullCeilingHeight) ? locCeilingHeight : gr_frontsector->ceilingheight; + plane.levelflat = &levelflats[gr_frontsector->ceilingpic]; + plane.colormap = ceilingcolormap; + plane.lightlevel = ceilinglightlevel; + HWR_RenderPlane(&plane); + } + } else { #ifdef POLYSKY - HWR_RenderSkyPlane(&extrasubsectors[num], locCeilingHeight); + HWR_RenderSkyPlane(&extrasubsectors[num], locCeilingHeight); #endif + } } } @@ -3515,7 +3519,7 @@ static void HWR_Subsector(const size_t num) (dup_viewz > bCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)) ) ) { INT32 botLight = R_GetPlaneLight(gr_frontsector, bCenterHeight, dup_viewz < bCullHeight ? true : false); - HWR_AddFOFPlane(num, rover, false, botLight); + HWR_AddFOFPlane(num, rover, PSIDE_FLOOR, botLight); } // top plane @@ -3535,7 +3539,7 @@ static void HWR_Subsector(const size_t num) (dup_viewz < tCullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)) ) ) { INT32 topLight = R_GetPlaneLight(gr_frontsector, tCenterHeight, dup_viewz < tCullHeight ? true : false); - HWR_AddFOFPlane(num, rover, true, topLight); + HWR_AddFOFPlane(num, rover, PSIDE_CEILING, topLight); } } } @@ -4726,7 +4730,6 @@ typedef struct gr_drawnode_s union { wallinfo_t wall; planeinfo_t plane; - polyplaneinfo_t polyplane; }; //tagged union struct gr_drawnode_s *next; @@ -4747,7 +4750,7 @@ static void HWR_RenderDrawNodes(void) { switch(sortnode[i].type) { case NODE_WALL: HWR_RenderWall(&sortnode[i].wall); break; case NODE_PLANE: HWR_RenderPlane(&sortnode[i].plane); break; - case NODE_POLYPLANE: HWR_RenderPolyObjectPlane(&sortnode[i].polyplane); break; + case NODE_POLYPLANE: HWR_RenderPolyObjectPlane(&sortnode[i].plane); break; } } } @@ -4755,20 +4758,11 @@ static void HWR_RenderDrawNodes(void) { // This will likely turn into a copy of HWR_Add3DWater and replace it. static void HWR_AddTransparentFloor(const planeinfo_t *plane) { - sortnode[drawcount].type = NODE_PLANE; + sortnode[drawcount].type = (plane->ispolyobj) ? NODE_POLYPLANE : NODE_PLANE; sortnode[drawcount].plane = *plane; //copying it ++drawcount; } -// Adding this for now until I can create extrasubsector info for polyobjects -// When that happens it'll just be done through HWR_AddTransparentFloor and HWR_RenderPlane -static void HWR_AddTransparentPolyobjectFloor(const polyplaneinfo_t *polyplane) -{ - sortnode[drawcount].type = NODE_POLYPLANE; - sortnode[drawcount].polyplane = *polyplane; //copying it - ++drawcount; -} - // // HWR_CreateDrawNodes // Creates and sorts a list of drawnodes for the scene being rendered.