- 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]->type);
lumpFile.Write32(surfaces[i]->typeIndex); 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(surfaces[i]->lightmapNum);
lumpFile.Write32(coordOffsets); lumpFile.Write32(coordOffsets);
coordOffsets += surfaces[i]->numVerts; coordOffsets += surfaces[i]->numVerts;

View file

@ -99,6 +99,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->plane.SetDistance(surf->verts[0]); surf->plane.SetDistance(surf->verts[0]);
surf->type = ST_LOWERSIDE; surf->type = ST_LOWERSIDE;
surf->typeIndex = side - &doomMap.Sides[0]; surf->typeIndex = side - &doomMap.Sides[0];
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf)); surfaces.push_back(std::move(surf));
} }
@ -142,6 +143,7 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->type = ST_UPPERSIDE; surf->type = ST_UPPERSIDE;
surf->typeIndex = side - &doomMap.Sides[0]; surf->typeIndex = side - &doomMap.Sides[0];
surf->bSky = bSky; surf->bSky = bSky;
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf)); surfaces.push_back(std::move(surf));
} }
@ -171,34 +173,14 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side)
surf->plane.SetDistance(surf->verts[0]); surf->plane.SetDistance(surf->verts[0]);
surf->type = ST_MIDDLESIDE; surf->type = ST_MIDDLESIDE;
surf->typeIndex = side - &doomMap.Sides[0]; surf->typeIndex = side - &doomMap.Sides[0];
surf->controlSector = nullptr;
surfaces.push_back(std::move(surf)); 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>(); auto surf = std::make_unique<surface_t>();
surf->numVerts = sub->numlines; surf->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts); surf->verts.resize(surf->numVerts);
@ -216,11 +198,15 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->plane = sector->floorplane; surf->plane = sector->floorplane;
surf->type = ST_FLOOR; surf->type = ST_FLOOR;
surf->typeIndex = i; surf->typeIndex = typeIndex;
surf->controlSector = is3DFloor ? sector : nullptr;
surfaces.push_back(std::move(surf)); 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->numVerts = sub->numlines;
surf->verts.resize(surf->numVerts); surf->verts.resize(surf->numVerts);
@ -242,11 +228,41 @@ static void CreateSubsectorSurfaces(FLevel &doomMap)
surf->plane = sector->ceilingplane; surf->plane = sector->ceilingplane;
surf->type = ST_CEILING; surf->type = ST_CEILING;
surf->typeIndex = i; surf->typeIndex = typeIndex;
surf->controlSector = is3DFloor ? sector : nullptr;
surfaces.push_back(std::move(surf)); 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); 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 // convert from fixed point(FRACUNIT) to floating point
#define F(x) (((float)(x))/65536.0f) #define F(x) (((float)(x))/65536.0f)
struct IntSector;
struct surface_t struct surface_t
{ {
kexPlane plane; kexPlane plane;
@ -60,6 +62,7 @@ struct surface_t
std::vector<float> lightmapCoords; std::vector<float> lightmapCoords;
surfaceType_t type; surfaceType_t type;
int typeIndex; int typeIndex;
IntSector *controlSector;
bool bSky; bool bSky;
}; };