Clean up the ranges code a bit

This commit is contained in:
Magnus Norddahl 2024-12-16 22:17:18 +01:00
commit e30831a409
7 changed files with 403 additions and 227 deletions

View file

@ -71,14 +71,8 @@ ADD_STAT(lightmap)
uint32_t atlasPixelCount = levelMesh->AtlasPixelCount();
auto stats = levelMesh->GatherTilePixelStats();
int indexBufferTotal = levelMesh->FreeLists.Index.back().End;
int indexBufferUsed = 0;
int pos = 0;
for (const auto& range : levelMesh->FreeLists.Index)
{
indexBufferUsed += range.Start - pos;
pos = range.End;
}
int indexBufferTotal = levelMesh->FreeLists.Index.GetTotalSize();
int indexBufferUsed = levelMesh->FreeLists.Index.GetUsedSize();
out.Format(
"Surfaces: %u (awaiting updates: %u)\n"
@ -403,7 +397,7 @@ void DoomLevelMesh::UploadDynLights(FLevelLocals& doomMap)
memcpy(&copyptr[4 + 4 * size0], &lightdata.arrays[1][0], size1 * sizeof(FVector4));
memcpy(&copyptr[4 + 4 * (size0 + size1)], &lightdata.arrays[2][0], size2 * sizeof(FVector4));
AddRange(UploadRanges.DynLight, { 0, totalsize });
UploadRanges.DynLight.Add(0, totalsize);
}
void DoomLevelMesh::UpdateWallPortals()
@ -466,7 +460,7 @@ void DoomLevelMesh::UpdateLight(FDynamicLight* light)
int lightindex = light->levelmesh[index].index - 1;
int portalgroup = light->levelmesh[index].portalgroup;
CopyToMeshLight(light, Mesh.Lights[lightindex], portalgroup);
AddRange(UploadRanges.Light, { lightindex, lightindex + 1 });
UploadRanges.Light.Add(lightindex, 1);
}
}
@ -902,7 +896,7 @@ void DoomLevelMesh::SetSideLights(FLevelLocals& doomMap, unsigned int sideIndex)
SetColor(uinfo.LightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, absalpha);
}
AddRange(UploadRanges.LightUniforms, { uinfo.Start, uinfo.Start + uinfo.Count });
UploadRanges.LightUniforms.Add(uinfo.Start, uinfo.Count);
}
}
@ -928,7 +922,7 @@ void DoomLevelMesh::SetFlatLights(FLevelLocals& doomMap, unsigned int sectorInde
{
SetColor(uinfo.LightUniforms[i], &doomMap, lightmode, lightlevel, rel, fullbrightScene, Colormap, alpha);
}
AddRange(UploadRanges.LightUniforms, { uinfo.Start, uinfo.Start + uinfo.Count });
UploadRanges.LightUniforms.Add(uinfo.Start, uinfo.Count);
}
}
@ -1115,7 +1109,7 @@ void DoomLevelMesh::AddToDrawList(TArray<DrawRangeInfo>& drawRanges, int pipelin
{
// Remember the location if we have to remove it again
DrawRangeInfo info;
info.DrawIndexStart = RemoveRange(FreeLists.DrawIndex, indexCount);
info.DrawIndexStart = FreeLists.DrawIndex.Alloc(indexCount);
info.DrawIndexCount = indexCount;
info.DrawType = drawType;
info.PipelineID = pipelineID;
@ -1123,21 +1117,18 @@ void DoomLevelMesh::AddToDrawList(TArray<DrawRangeInfo>& drawRanges, int pipelin
// Copy the indexes over from the unsorted index list
memcpy(&Mesh.DrawIndexes[info.DrawIndexStart], &Mesh.Indexes[indexStart], indexCount * sizeof(uint32_t));
AddRange(UploadRanges.DrawIndex, { info.DrawIndexStart, info.DrawIndexStart + indexCount });
UploadRanges.DrawIndex.Add(info.DrawIndexStart, indexCount);
// Add to the draw lists
AddRange(DrawList[(int)drawType][pipelineID], { info.DrawIndexStart, info.DrawIndexStart + indexCount });
DrawList[(int)drawType][pipelineID].Add(info.DrawIndexStart, indexCount);
}
void DoomLevelMesh::RemoveFromDrawList(const TArray<DrawRangeInfo>& drawRanges)
{
for (const DrawRangeInfo& info : drawRanges)
{
int start = info.DrawIndexStart;
int end = info.DrawIndexStart + info.DrawIndexCount;
RemoveRange(DrawList[(int)info.DrawType][info.PipelineID], { start, end });
AddRange(FreeLists.DrawIndex, { start, end });
DrawList[(int)info.DrawType][info.PipelineID].Remove(info.DrawIndexStart, info.DrawIndexCount);
FreeLists.DrawIndex.Free(info.DrawIndexStart, info.DrawIndexCount);
}
}
@ -1182,7 +1173,7 @@ void DoomLevelMesh::SortDrawLists()
range->DrawIndexStart = sortedStart;
}
int listEnd = indexes.Size();
list.Push({ listStart, listEnd });
list.Add(listStart, listEnd - listStart);
}
}