Fix variety of bugs and assume that any surface not contained in LIGHTMAP lump does not need updating

This commit is contained in:
RaveYard 2023-09-13 19:03:14 +02:00 committed by Christoph Oelckers
parent 537cd7790d
commit dca5eb13f0
4 changed files with 37 additions and 19 deletions

View file

@ -191,7 +191,7 @@ void VkTextureManager::CreateLightmap()
void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCount, TArray<uint16_t>&& newPixelData)
{
if (LMTextureSize == newLMTextureSize && LMTextureCount == newLMTextureCount)
if (LMTextureSize == newLMTextureSize && LMTextureCount == newLMTextureCount && newPixelData.Size() == 0)
return;
LMTextureSize = newLMTextureSize;

View file

@ -3083,6 +3083,11 @@ void MapLoader::LoadLightmap(MapData* map)
TArray<DoomLevelMeshSurface> zdraySurfaces;
for (auto& surface : Level->levelMesh->Surfaces)
{
surface.needsUpdate = false; // let's consider everything valid until we make a mistake trying to change this surface
}
for (uint32_t i = 0; i < numSurfaces; i++)
{
LevelMeshSurfaceType type = (LevelMeshSurfaceType)fr.ReadUInt32();
@ -3204,6 +3209,7 @@ void MapLoader::LoadLightmap(MapData* map)
{
Printf("Can't remap lightmap surface ((%d, %d), (%d, %d), %d) -> ((%d, %d), (%d, %d), %d)\n", srcMinX, srcMinY, srcMaxX, srcMaxY, srcPage, dstX, dstY, dstX + srcW, dstY + srcH, dstPage);
}
realSurface.needsUpdate = true;
continue;
}
@ -3223,13 +3229,25 @@ void MapLoader::LoadLightmap(MapData* map)
dst[dstIndex + 2] = src[index + 2];
}
}
}
realSurface.needsUpdate = false; // this surface is good
if (developer >= 3)
{
int loadedSurfaces = 0;
for (auto& surface : Level->levelMesh->Surfaces)
{
if (!surface.needsUpdate)
{
loadedSurfaces++;
}
}
Printf(PRINT_HIGH, "%d/%d surfaces were successfully loaded from lightmap.\n", loadedSurfaces, Level->levelMesh->Surfaces.Size());
}
if (errors && developer <= 0)
{
Printf(PRINT_HIGH, "Pre-calculated LIGHTMAP surfaces do not match current level surfaces. Restart this level with 'developer 1' for further details.\nPerhaps you forget to rebuild lightmaps after modifying the map?");
Printf(PRINT_HIGH, "Pre-calculated LIGHTMAP surfaces do not match current level surfaces. Restart this level with 'developer 1' for further details.\nPerhaps you forget to rebuild lightmaps after modifying the map?\n");
}
#if 0
// Apply compression predictor

View file

@ -695,19 +695,19 @@ void DoomLevelMesh::CreateSideSurfaces(FLevelLocals &doomMap, side_t *side)
}
}
void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor)
void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, sector_t *controlSector, int typeIndex)
{
DoomLevelMeshSurface surf;
surf.bSky = IsSkySector(sector, sector_t::floor);
secplane_t plane;
if (!is3DFloor)
if (!controlSector)
{
plane = sector->floorplane;
}
else
{
plane = sector->ceilingplane;
plane = controlSector->ceilingplane;
plane.FlipVert();
}
@ -728,26 +728,26 @@ void DoomLevelMesh::CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub,
surf.Type = ST_FLOOR;
surf.typeIndex = typeIndex;
surf.sampleDimension = sector->planes[sector_t::floor].LightmapSampleDistance;
surf.ControlSector = is3DFloor ? sector : nullptr;
surf.sampleDimension = (controlSector ? controlSector : sector)->planes[sector_t::floor].LightmapSampleDistance;
surf.ControlSector = controlSector;
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
Surfaces.Push(surf);
}
void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor)
void DoomLevelMesh::CreateCeilingSurface(FLevelLocals& doomMap, subsector_t* sub, sector_t* sector, sector_t* controlSector, int typeIndex)
{
DoomLevelMeshSurface surf;
surf.bSky = IsSkySector(sector, sector_t::ceiling);
secplane_t plane;
if (!is3DFloor)
if (!controlSector)
{
plane = sector->ceilingplane;
}
else
{
plane = sector->floorplane;
plane = controlSector->floorplane;
plane.FlipVert();
}
@ -768,8 +768,8 @@ void DoomLevelMesh::CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub
surf.Type = ST_CEILING;
surf.typeIndex = typeIndex;
surf.sampleDimension = sector->planes[sector_t::ceiling].LightmapSampleDistance;
surf.ControlSector = is3DFloor ? sector : nullptr;
surf.sampleDimension = (controlSector ? controlSector : sector)->planes[sector_t::ceiling].LightmapSampleDistance;
surf.ControlSector = controlSector;
surf.plane = FVector4((float)plane.Normal().X, (float)plane.Normal().Y, (float)plane.Normal().Z, -(float)plane.D);
Surfaces.Push(surf);
@ -790,13 +790,13 @@ void DoomLevelMesh::CreateSubsectorSurfaces(FLevelLocals &doomMap)
if (!sector || IsControlSector(sector))
continue;
CreateFloorSurface(doomMap, sub, sector, i, false);
CreateCeilingSurface(doomMap, sub, sector, i, false);
CreateFloorSurface(doomMap, sub, sector, nullptr, i);
CreateCeilingSurface(doomMap, sub, sector, nullptr, i);
for (unsigned int j = 0; j < sector->e->XFloor.ffloors.Size(); j++)
{
CreateFloorSurface(doomMap, sub, sector->e->XFloor.ffloors[j]->model, i, true);
CreateCeilingSurface(doomMap, sub, sector->e->XFloor.ffloors[j]->model, i, true);
CreateFloorSurface(doomMap, sub, sector, sector->e->XFloor.ffloors[j]->model, i);
CreateCeilingSurface(doomMap, sub, sector, sector->e->XFloor.ffloors[j]->model, i);
}
}
}

View file

@ -55,8 +55,8 @@ public:
private:
void CreateSubsectorSurfaces(FLevelLocals &doomMap);
void CreateCeilingSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor);
void CreateFloorSurface(FLevelLocals &doomMap, subsector_t *sub, sector_t *sector, int typeIndex, bool is3DFloor);
void CreateCeilingSurface(FLevelLocals& doomMap, subsector_t* sub, sector_t* sector, sector_t* controlSector, int typeIndex);
void CreateFloorSurface(FLevelLocals& doomMap, subsector_t* sub, sector_t* sector, sector_t* controlSector, int typeIndex);
void CreateSideSurfaces(FLevelLocals &doomMap, side_t *side);
void SetSubsectorLightmap(DoomLevelMeshSurface* surface);