From dca5eb13f0124b7565151034c06c23fae80b6229 Mon Sep 17 00:00:00 2001 From: RaveYard <29225776+MrRaveYard@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:03:14 +0200 Subject: [PATCH] Fix variety of bugs and assume that any surface not contained in LIGHTMAP lump does not need updating --- .../rendering/vulkan/textures/vk_texture.cpp | 2 +- src/maploader/maploader.cpp | 22 +++++++++++++-- src/rendering/hwrenderer/doom_levelmesh.cpp | 28 +++++++++---------- src/rendering/hwrenderer/doom_levelmesh.h | 4 +-- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/common/rendering/vulkan/textures/vk_texture.cpp b/src/common/rendering/vulkan/textures/vk_texture.cpp index d29d7094e3..b33f5c8493 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.cpp +++ b/src/common/rendering/vulkan/textures/vk_texture.cpp @@ -191,7 +191,7 @@ void VkTextureManager::CreateLightmap() void VkTextureManager::CreateLightmap(int newLMTextureSize, int newLMTextureCount, TArray&& newPixelData) { - if (LMTextureSize == newLMTextureSize && LMTextureCount == newLMTextureCount) + if (LMTextureSize == newLMTextureSize && LMTextureCount == newLMTextureCount && newPixelData.Size() == 0) return; LMTextureSize = newLMTextureSize; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 7b6da7cd08..7472d54156 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3083,6 +3083,11 @@ void MapLoader::LoadLightmap(MapData* map) TArray 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 diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index 32d15ed7c8..15613cbda0 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -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); } } } diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index 0cf89fd50e..64f9117e37 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -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);