- add 3d floor ceiling and floor surfaces

This commit is contained in:
Magnus Norddahl 2018-11-03 22:43:00 +01:00
parent 0f6da0df5d
commit 5ea89ac1b6
3 changed files with 68 additions and 49 deletions

View file

@ -613,7 +613,7 @@ void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
lumpFile.Write32(surfaces[i]->type);
lumpFile.Write32(surfaces[i]->typeIndex);
lumpFile.Write32(0xffffffff/*surfaces[i]->controlSector*/);
lumpFile.Write32(surfaces[i]->controlSector ? (uint32_t)(surfaces[i]->controlSector - &map->Sectors[0]) : 0xffffffff);
lumpFile.Write32(surfaces[i]->lightmapNum);
lumpFile.Write32(coordOffsets);
coordOffsets += surfaces[i]->numVerts;

View file

@ -99,6 +99,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->plane.SetDistance(surf->verts[0]);
surf->type = ST_LOWERSIDE;
surf->typeIndex = side - &doomMap.Sides[0];
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf));
}
@ -142,6 +143,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_UPPERSIDE;
surf->typeIndex = side - &doomMap.Sides[0];
surf->bSky = bSky;
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf));
}
@ -171,34 +173,14 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->plane.SetDistance(surf->verts[0]);
surf->type = ST_MIDDLESIDE;
surf->typeIndex = side - &doomMap.Sides[0];
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf));
}
}
static void CreateSubsectorSurfaces(FLevel &doomMap)
static void CreateFloorSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSector *sector, int typeIndex, bool is3DFloor)
{
printf("------------- Building subsector surfaces -------------\n");
for (int i = 0; i < doomMap.NumGLSubsectors; i++)
{
printf("subsectors: %i / %i\r", i + 1, doomMap.NumGLSubsectors);
MapSubsectorEx *sub = &doomMap.GLSubsectors[i];
if (sub->numlines < 3)
{
continue;
}
IntSector *sector = doomMap.GetSectorFromSubSector(sub);
if (!sector)
continue;
if (sector->controlsector)
continue;
auto surf = std::make_unique<surface_t>();
surf->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts);
@ -216,11 +198,15 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->plane = sector->floorplane;
surf->type = ST_FLOOR;
surf->typeIndex = i;
surf->typeIndex = typeIndex;
surf->controlSector = is3DFloor ? sector : nullptr;
surfaces.push_back(std::move(surf));
}
surf = std::make_unique<surface_t>();
static void CreateCeilingSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSector *sector, int typeIndex, bool is3DFloor)
{
auto surf = std::make_unique<surface_t>();
surf->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts);
@ -242,9 +228,39 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->plane = sector->ceilingplane;
surf->type = ST_CEILING;
surf->typeIndex = i;
surf->typeIndex = typeIndex;
surf->controlSector = is3DFloor ? sector : nullptr;
surfaces.push_back(std::move(surf));
}
static void CreateSubsectorSurfaces(FLevel &doomMap)
{
printf("------------- Building subsector surfaces -------------\n");
for (int i = 0; i < doomMap.NumGLSubsectors; i++)
{
printf("subsectors: %i / %i\r", i + 1, doomMap.NumGLSubsectors);
MapSubsectorEx *sub = &doomMap.GLSubsectors[i];
if (sub->numlines < 3)
{
continue;
}
IntSector *sector = doomMap.GetSectorFromSubSector(sub);
if (!sector || sector->controlsector)
continue;
CreateFloorSurface(doomMap, sub, sector, i, false);
CreateCeilingSurface(doomMap, sub, sector, i, false);
for (unsigned int j = 0; j < sector->x3dfloors.Size(); j++)
{
CreateFloorSurface(doomMap, sub, sector->x3dfloors[j], i, true);
CreateCeilingSurface(doomMap, sub, sector->x3dfloors[j], i, false);
}
}
printf("\nLeaf surfaces: %i\n", (int)surfaces.size() - doomMap.NumGLSubsectors);

View file

@ -45,6 +45,8 @@ enum surfaceType_t
// convert from fixed point(FRACUNIT) to floating point
#define F(x) (((float)(x))/65536.0f)
struct IntSector;
struct surface_t
{
kexPlane plane;
@ -60,6 +62,7 @@ struct surface_t
std::vector<float> lightmapCoords;
surfaceType_t type;
int typeIndex;
IntSector *controlSector;
bool bSky;
};