Fix wall portals not getting freed

This commit is contained in:
Magnus Norddahl 2024-08-26 02:05:38 +02:00
commit dedd7245f2
3 changed files with 42 additions and 12 deletions

View file

@ -183,6 +183,19 @@ void DoomLevelMesh::BeginFrame(FLevelLocals& doomMap)
}
CreateLights(doomMap);
UpdateWallPortals();
}
void DoomLevelMesh::UpdateWallPortals()
{
WallPortals.Clear();
for (int sideIndex : SidePortals)
{
for (HWWall& wall : Sides[sideIndex].WallPortals)
{
WallPortals.Push(&wall);
}
}
}
void DoomLevelMesh::CreateLights(FLevelLocals& doomMap)
@ -393,6 +406,8 @@ void DoomLevelMesh::FreeSide(FLevelLocals& doomMap, unsigned int sideIndex)
for (auto& uni : Sides[sideIndex].Uniforms)
FreeUniforms(uni.Start, uni.Count);
Sides[sideIndex].Uniforms.Clear();
Sides[sideIndex].WallPortals.Clear();
}
void DoomLevelMesh::FreeFlat(FLevelLocals& doomMap, unsigned int sectorIndex)
@ -537,9 +552,16 @@ void DoomLevelMesh::UpdateSide(FLevelLocals& doomMap, unsigned int sideIndex)
state.AlphaFunc(Alpha_GEqual, 0.f);
CreateWallSurface(side, disp, state, result.list, false, true, sideIndex);
if (result.portals.Size() != 0 && !Sides[sideIndex].InSidePortalsList)
{
// Register side having portals
SidePortals.Push(sideIndex);
Sides[sideIndex].InSidePortalsList = true;
}
for (HWWall& portal : result.portals)
{
WallPortals.Push(portal);
Sides[sideIndex].WallPortals.Push(portal);
}
CreateWallSurface(side, disp, state, result.portals, true, false, sideIndex);

View file

@ -55,6 +55,8 @@ struct SideSurfaceBlock
int FirstSurface = -1;
TArray<GeometryFreeInfo> Geometries;
TArray<UniformsAllocInfo> Uniforms;
TArray<HWWall> WallPortals;
bool InSidePortalsList = false;
};
struct FlatSurfaceBlock
@ -77,7 +79,8 @@ public:
void BuildSectorGroups(const FLevelLocals& doomMap);
TArray<HWWall> WallPortals;
TArray<int> SidePortals;
TArray<HWWall*> WallPortals;
TArray<int> sectorGroup; // index is sector, value is sectorGroup
TArray<int> sectorPortals[2]; // index is sector+plane, value is index into the portal list
@ -112,6 +115,8 @@ private:
void FreeSide(FLevelLocals& doomMap, unsigned int sideIndex);
void FreeFlat(FLevelLocals& doomMap, unsigned int sectorIndex);
void UpdateWallPortals();
void SetSubsectorLightmap(int surfaceIndex);
void SetSideLightmap(int surfaceIndex);

View file

@ -445,13 +445,13 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state)
state.SetDepthMask(false);
state.EnableTexture(false);
state.SetEffect(EFF_PORTAL);
for (HWWall& wall : portals)
for (HWWall* wall : portals)
{
state.BeginQuery();
wall.MakeVertices(state, false);
wall.RenderWall(state, HWWall::RWF_BLANK);
wall.vertcount = 0;
wall->MakeVertices(state, false);
wall->RenderWall(state, HWWall::RWF_BLANK);
wall->vertcount = 0;
state.EndQuery();
}
@ -471,14 +471,17 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state)
}
state.SetCulling(Cull_None);
// retrieve the query results and use them to fill the portal manager with portals
state.GetQueryResults(queryStart, queryEnd - queryStart, QueryResultsBuffer);
for (unsigned int i = 0, count = QueryResultsBuffer.Size(); i < count; i++)
if (queryStart != queryEnd)
{
bool portalVisible = QueryResultsBuffer[i];
if (portalVisible)
// retrieve the query results and use them to fill the portal manager with portals
state.GetQueryResults(queryStart, queryEnd - queryStart, QueryResultsBuffer);
for (unsigned int i = 0, count = QueryResultsBuffer.Size(); i < count; i++)
{
PutWallPortal(portals[i], state);
bool portalVisible = QueryResultsBuffer[i];
if (portalVisible)
{
PutWallPortal(*portals[i], state);
}
}
}