diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 33149e63a6..d78f774a0d 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -1219,7 +1219,7 @@ struct side_t uint16_t Flags; int UDMFIndex; // needed to access custom UDMF fields which are stored in loading order. FLightNode * lighthead; // all dynamic lights that may affect this wall - LightmapSurface *lightmap[4]; + LightmapSurface* lightmap; seg_t **segs; // all segs belonging to this sidedef in ascending order. Used for precise rendering int numsegs; int sidenum; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index ad1667abd5..f8e7004e04 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3297,18 +3297,19 @@ void MapLoader::SetSideLightmap(const LightmapSurface &surface) { if (!surface.ControlSector) { - int index = 0; - switch (surface.Type) + if (surface.Type == ST_UPPERWALL) { - default: - case ST_MIDDLEWALL: index = 1; break; - case ST_UPPERWALL: index = 0; break; - case ST_LOWERWALL: index = 3; break; + surface.Side->lightmap[0] = surface; + } + else if (surface.Type == ST_MIDDLEWALL) + { + surface.Side->lightmap[1] = surface; + surface.Side->lightmap[2] = surface; + } + else if (surface.Type == ST_LOWERWALL) + { + surface.Side->lightmap[3] = surface; } - - surface.Side->lightmap[index][0] = surface; - if (surface.Type == ST_MIDDLEWALL) - surface.Side->lightmap[index + 1][0] = surface; } else { @@ -3317,7 +3318,7 @@ void MapLoader::SetSideLightmap(const LightmapSurface &surface) { if (ffloors[i]->model == surface.ControlSector) { - surface.Side->lightmap[1][i + 1] = surface; + surface.Side->lightmap[4 + i] = surface; } } } @@ -3359,7 +3360,7 @@ void MapLoader::LoadLightmap(MapData *map) unsigned int allSurfaces = 0; for (unsigned int i = 0; i < Level->sides.Size(); i++) - allSurfaces += 3 + Level->sides[i].sector->e->XFloor.ffloors.Size() * 3; + allSurfaces += 4 + Level->sides[i].sector->e->XFloor.ffloors.Size(); for (unsigned int i = 0; i < Level->subsectors.Size(); i++) allSurfaces += 2 + Level->subsectors[i].sector->e->XFloor.ffloors.Size() * 2; @@ -3373,12 +3374,8 @@ void MapLoader::LoadLightmap(MapData *map) for (unsigned int i = 0; i < Level->sides.Size(); i++) { auto& side = Level->sides[i]; - unsigned int count = 1 + side.sector->e->XFloor.ffloors.Size(); - side.lightmap[0] = &Level->LMSurfaces[offset]; - side.lightmap[1] = &Level->LMSurfaces[offset + count]; - side.lightmap[2] = side.lightmap[1]; - side.lightmap[3] = &Level->LMSurfaces[offset + count * 2]; - offset += count * 3; + side.lightmap = &Level->LMSurfaces[offset]; + offset += 4 + side.sector->e->XFloor.ffloors.Size(); } for (unsigned int i = 0; i < Level->subsectors.Size(); i++) { diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 6fdc3577af..3c08493c95 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -256,10 +256,10 @@ public: void ProcessDecals(HWDrawInfo *di); int CreateVertices(FFlatVertex *&ptr, bool nosplit); - void SplitLeftEdge (FFlatVertex *&ptr, float *lightuv, float lindex); - void SplitRightEdge(FFlatVertex *&ptr, float *lightuv, float lindex); - void SplitUpperEdge(FFlatVertex *&ptr, float *lightuv, float lindex); - void SplitLowerEdge(FFlatVertex *&ptr, float *lightuv, float lindex); + void SplitLeftEdge (FFlatVertex *&ptr, texcoord* lightuv, float lindex); + void SplitRightEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex); + void SplitUpperEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex); + void SplitLowerEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex); void CountLeftEdge (unsigned &ptr); void CountRightEdge(unsigned &ptr); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index ab2a948c47..12a5fbfc35 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1216,9 +1216,9 @@ void HWWall::DoTexture(HWDrawInfo *di, int _type,seg_t * seg, int peg, type = _type; - if (type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM) + if (seg->sidedef->lightmap && type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM) { - lightmap = seg->sidedef->lightmap[type - RENDERWALL_TOP]; + lightmap = &seg->sidedef->lightmap[type - RENDERWALL_TOP]; } else { @@ -1685,14 +1685,14 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, int rov translucent = false; } - LightmapSurface *surf = nullptr; + lightmap = nullptr; if (seg->sidedef == seg->linedef->sidedef[0]) - surf = seg->linedef->sidedef[1]->lightmap[1]; + lightmap = seg->linedef->sidedef[1]->lightmap; else - surf = seg->linedef->sidedef[0]->lightmap[1]; + lightmap = seg->linedef->sidedef[0]->lightmap; - if (surf) - lightmap = &surf[1 + roverIndex]; + if (lightmap) + lightmap += 4 + roverIndex; sector_t * sec = sub ? sub->sector : seg->frontsector; diff --git a/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp b/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp index ac26713dc3..092d8dce68 100644 --- a/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp @@ -34,7 +34,7 @@ EXTERN_CVAR(Bool, gl_seamless) // //========================================================================== -void HWWall::SplitUpperEdge(FFlatVertex *&ptr, float *lightuv, float lindex) +void HWWall::SplitUpperEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex) { side_t *sidedef = seg->sidedef; float polyw = glseg.fracright - glseg.fracleft; @@ -43,8 +43,8 @@ void HWWall::SplitUpperEdge(FFlatVertex *&ptr, float *lightuv, float lindex) float fact = (ztop[1] - ztop[0]) / polyw; float facc = (zceil[1] - zceil[0]) / polyw; float facf = (zfloor[1] - zfloor[0]) / polyw; - float faclu = (lightuv[UPRGT * 2] - lightuv[UPLFT * 2]) / polyw; - float faclv = (lightuv[UPRGT * 2 + 1] - lightuv[UPLFT * 2 + 1]) / polyw; + float faclu = (lightuv[UPRGT].u - lightuv[UPLFT].u) / polyw; + float faclv = (lightuv[UPRGT].v - lightuv[UPLFT].v) / polyw; for (int i = 0; i < sidedef->numsegs - 1; i++) { @@ -60,8 +60,8 @@ void HWWall::SplitUpperEdge(FFlatVertex *&ptr, float *lightuv, float lindex) ptr->z = ztop[0] + fact * fracfac; ptr->u = tcs[UPLFT].u + facu * fracfac; ptr->v = tcs[UPLFT].v + facv * fracfac; - ptr->lu = lightuv[UPLFT * 2] + faclu * fracfac; - ptr->lv = lightuv[UPLFT * 2 + 1] + faclv * fracfac; + ptr->lu = lightuv[UPLFT].u + faclu * fracfac; + ptr->lv = lightuv[UPLFT].v + faclv * fracfac; ptr->lindex = lindex; ptr++; } @@ -73,7 +73,7 @@ void HWWall::SplitUpperEdge(FFlatVertex *&ptr, float *lightuv, float lindex) // //========================================================================== -void HWWall::SplitLowerEdge(FFlatVertex *&ptr, float *lightuv, float lindex) +void HWWall::SplitLowerEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex) { side_t *sidedef = seg->sidedef; float polyw = glseg.fracright - glseg.fracleft; @@ -82,8 +82,8 @@ void HWWall::SplitLowerEdge(FFlatVertex *&ptr, float *lightuv, float lindex) float facb = (zbottom[1] - zbottom[0]) / polyw; float facc = (zceil[1] - zceil[0]) / polyw; float facf = (zfloor[1] - zfloor[0]) / polyw; - float faclu = (lightuv[LORGT * 2] - lightuv[LOLFT * 2]) / polyw; - float faclv = (lightuv[LORGT * 2 + 1] - lightuv[LOLFT * 2 + 1]) / polyw; + float faclu = (lightuv[LORGT].u - lightuv[LOLFT].u) / polyw; + float faclv = (lightuv[LORGT].v - lightuv[LOLFT].v) / polyw; for (int i = sidedef->numsegs - 2; i >= 0; i--) { @@ -99,8 +99,8 @@ void HWWall::SplitLowerEdge(FFlatVertex *&ptr, float *lightuv, float lindex) ptr->z = zbottom[0] + facb * fracfac; ptr->u = tcs[LOLFT].u + facu * fracfac; ptr->v = tcs[LOLFT].v + facv * fracfac; - ptr->lu = lightuv[LOLFT * 2] + faclu * fracfac; - ptr->lv = lightuv[LOLFT * 2 + 1] + faclv * fracfac; + ptr->lu = lightuv[LOLFT].u + faclu * fracfac; + ptr->lv = lightuv[LOLFT].v + faclv * fracfac; ptr->lindex = lindex; ptr++; } @@ -112,7 +112,7 @@ void HWWall::SplitLowerEdge(FFlatVertex *&ptr, float *lightuv, float lindex) // //========================================================================== -void HWWall::SplitLeftEdge(FFlatVertex *&ptr, float *lightuv, float lindex) +void HWWall::SplitLeftEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex) { if (vertexes[0] == NULL) return; @@ -125,8 +125,8 @@ void HWWall::SplitLeftEdge(FFlatVertex *&ptr, float *lightuv, float lindex) float polyh1 = ztop[0] - zbottom[0]; float factv1 = polyh1 ? (tcs[UPLFT].v - tcs[LOLFT].v) / polyh1 : 0; float factu1 = polyh1 ? (tcs[UPLFT].u - tcs[LOLFT].u) / polyh1 : 0; - float factlv1 = polyh1 ? (lightuv[UPLFT * 2 + 1] - lightuv[LOLFT * 2 + 1]) / polyh1 : 0; - float factlu1 = polyh1 ? (lightuv[UPLFT * 2] - lightuv[LOLFT * 2]) / polyh1 : 0; + float factlv1 = polyh1 ? (lightuv[UPLFT].v - lightuv[LOLFT].v) / polyh1 : 0; + float factlu1 = polyh1 ? (lightuv[UPLFT].u - lightuv[LOLFT].u) / polyh1 : 0; while (inumheights && vi->heightlist[i] <= zbottom[0]) i++; while (inumheights && vi->heightlist[i] < ztop[0]) @@ -136,8 +136,8 @@ void HWWall::SplitLeftEdge(FFlatVertex *&ptr, float *lightuv, float lindex) ptr->z = vi->heightlist[i]; ptr->u = factu1*(vi->heightlist[i] - ztop[0]) + tcs[UPLFT].u; ptr->v = factv1*(vi->heightlist[i] - ztop[0]) + tcs[UPLFT].v; - ptr->lu = factlu1 * (vi->heightlist[i] - ztop[0]) + lightuv[UPLFT * 2]; - ptr->lv = factlv1 * (vi->heightlist[i] - ztop[0]) + lightuv[UPLFT * 2 + 1]; + ptr->lu = factlu1 * (vi->heightlist[i] - ztop[0]) + lightuv[UPLFT].u; + ptr->lv = factlv1 * (vi->heightlist[i] - ztop[0]) + lightuv[UPLFT].v; ptr->lindex = lindex; ptr++; i++; @@ -151,7 +151,7 @@ void HWWall::SplitLeftEdge(FFlatVertex *&ptr, float *lightuv, float lindex) // //========================================================================== -void HWWall::SplitRightEdge(FFlatVertex *&ptr, float *lightuv, float lindex) +void HWWall::SplitRightEdge(FFlatVertex *&ptr, texcoord* lightuv, float lindex) { if (vertexes[1] == NULL) return; @@ -164,8 +164,8 @@ void HWWall::SplitRightEdge(FFlatVertex *&ptr, float *lightuv, float lindex) float polyh2 = ztop[1] - zbottom[1]; float factv2 = polyh2 ? (tcs[UPRGT].v - tcs[LORGT].v) / polyh2 : 0; float factu2 = polyh2 ? (tcs[UPRGT].u - tcs[LORGT].u) / polyh2 : 0; - float factlv2 = polyh2 ? (lightuv[UPRGT * 2 + 1] - lightuv[LORGT * 2 + 1]) / polyh2 : 0; - float factlu2 = polyh2 ? (lightuv[UPRGT * 2] - lightuv[LORGT * 2]) / polyh2 : 0; + float factlv2 = polyh2 ? (lightuv[UPRGT].v - lightuv[LORGT].v) / polyh2 : 0; + float factlu2 = polyh2 ? (lightuv[UPRGT].u - lightuv[LORGT].u) / polyh2 : 0; while (i>0 && vi->heightlist[i] >= ztop[1]) i--; while (i>0 && vi->heightlist[i] > zbottom[1]) @@ -175,8 +175,8 @@ void HWWall::SplitRightEdge(FFlatVertex *&ptr, float *lightuv, float lindex) ptr->z = vi->heightlist[i]; ptr->u = factu2*(vi->heightlist[i] - ztop[1]) + tcs[UPRGT].u; ptr->v = factv2*(vi->heightlist[i] - ztop[1]) + tcs[UPRGT].v; - ptr->lu = factlu2 * (vi->heightlist[i] - ztop[1]) + lightuv[UPRGT * 2]; - ptr->lv = factlv2 * (vi->heightlist[i] - ztop[1]) + lightuv[UPRGT * 2 + 1]; + ptr->lu = factlu2 * (vi->heightlist[i] - ztop[1]) + lightuv[UPRGT].u; + ptr->lv = factlv2 * (vi->heightlist[i] - ztop[1]) + lightuv[UPRGT].v; ptr->lindex = lindex; ptr++; i--; @@ -194,25 +194,25 @@ static float ZeroLightmapUVs[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0. int HWWall::CreateVertices(FFlatVertex *&ptr, bool split) { - float* lightuv = ZeroLightmapUVs; + texcoord* lightuv = (texcoord*)ZeroLightmapUVs; float lindex = -1.0f; if (lightmap && lightmap->Type != ST_NULL) { - lightuv = lightmap->TexCoords; + lightuv = (texcoord*)lightmap->TexCoords; lindex = (float)lightmap->LightmapNum; } auto oo = ptr; - ptr->Set(glseg.x1, zbottom[0], glseg.y1, tcs[LOLFT].u, tcs[LOLFT].v, lightuv[LOLFT * 2], lightuv[LOLFT * 2 + 1], lindex); + ptr->Set(glseg.x1, zbottom[0], glseg.y1, tcs[LOLFT].u, tcs[LOLFT].v, lightuv[LOLFT].u, lightuv[LOLFT].v, lindex); ptr++; if (split && glseg.fracleft == 0) SplitLeftEdge(ptr, lightuv, lindex); - ptr->Set(glseg.x1, ztop[0], glseg.y1, tcs[UPLFT].u, tcs[UPLFT].v, lightuv[UPLFT * 2], lightuv[UPLFT * 2 + 1], lindex); + ptr->Set(glseg.x1, ztop[0], glseg.y1, tcs[UPLFT].u, tcs[UPLFT].v, lightuv[UPLFT].u, lightuv[UPLFT].v, lindex); ptr++; if (split && !(flags & HWF_NOSPLITUPPER && seg->sidedef->numsegs > 1)) SplitUpperEdge(ptr, lightuv, lindex); - ptr->Set(glseg.x2, ztop[1], glseg.y2, tcs[UPRGT].u, tcs[UPRGT].v, lightuv[UPRGT * 2], lightuv[UPRGT * 2 + 1], lindex); + ptr->Set(glseg.x2, ztop[1], glseg.y2, tcs[UPRGT].u, tcs[UPRGT].v, lightuv[UPRGT].u, lightuv[UPRGT].v, lindex); ptr++; if (split && glseg.fracright == 1) SplitRightEdge(ptr, lightuv, lindex); - ptr->Set(glseg.x2, zbottom[1], glseg.y2, tcs[LORGT].u, tcs[LORGT].v, lightuv[LORGT * 2], lightuv[LORGT * 2 + 1], lindex); + ptr->Set(glseg.x2, zbottom[1], glseg.y2, tcs[LORGT].u, tcs[LORGT].v, lightuv[LORGT].u, lightuv[LORGT].v, lindex); ptr++; if (split && !(flags & HWF_NOSPLITLOWER) && seg->sidedef->numsegs > 1) SplitLowerEdge(ptr, lightuv, lindex); return int(ptr - oo);