8000 Make sure surfaceGrid is always processed at the end of the loop · DaemonEngine/Daemon-vulkan@4a1e331 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a1e331

Browse files
committed
Make sure surfaceGrid is always processed at the end of the loop
1 parent 6aa0f9d commit 4a1e331

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/engine/renderer/GeometryOptimiser.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -462,38 +462,38 @@ static void OptimiseMaterialSurfaces( std::vector<MaterialSurface>& materialSurf
462462
Grid<SurfaceIndexes> surfaceIdxsGrid( true );
463463
surfaceIdxsGrid.SetSize( gridSize[0], gridSize[1], gridSize[2] );
464464

465-
uint32_t surfaceIndex = 0;
466465
MaterialSurface* surface = &materialSurfaces[0];
467-
while ( true ) {
468-
MaterialSurface* surface2 = &materialSurfaces[surfaceIndex];
469-
if ( surface2->skyBrush ) {
470-
surfaceIndex++;
466+
MaterialSurface* surface2;
467+
bool addedSurfaces = false;
471468

472-
if ( surfaceIndex == materialSurfaces.size() ) {
473-
break;
474-
}
475-
476-
continue;
469+
std::function<void()> processGrid = [&]() {
470+
if ( !addedSurfaces ) {
471+
surface = surface2;
472+
return;
477473
}
478474

479-
bool newGrid = materialSurfaceSort( *surface, *surface2 );
480-
481-
if ( surfaceIndex == materialSurfaces.size() - 1 ) {
482-
newGrid = true;
475+
for ( Grid<uint32_t>::Iterator it = surfaceGrid.begin(); it != surfaceGrid.end(); it++ ) {
476+
if ( *it ) {
477+
SurfaceIndexes* srfIdxs = &surfaceIdxsGrid( it - surfaceGrid.begin() );
478+
surface->count = *it;
479+
ProcessMaterialSurface( surface, srfIdxs, processedMaterialSurfaces, vertices, idxs, &numIndices );
480+
}
483481
}
484482

485-
if ( newGrid ) {
486-
for ( Grid<uint32_t>::Iterator it = surfaceGrid.begin(); it != surfaceGrid.end(); it++ ) {
487-
if ( *it ) {
488-
SurfaceIndexes* srfIdxs = &surfaceIdxsGrid( it - surfaceGrid.begin() );
489-
surface->count = *it;
490-
ProcessMaterialSurface( surface, srfIdxs, processedMaterialSurfaces, vertices, idxs, &numIndices );
491-
}
492-
}
483+
surfaceGrid.Clear();
493484

494-
surfaceGrid.Clear();
485+
surface = surface2;
486+
addedSurfaces = false;
487+
};
495488

496-
surface = surface2;
489+
for ( uint32_t surfaceIndex = 0; surfaceIndex < materialSurfaces.size(); surfaceIndex++ ) {
490+
surface2 = &materialSurfaces[surfaceIndex];
491+
if ( surface2->skyBrush ) {
492+
continue;
493+
}
494+
495+
if ( materialSurfaceSort( *surface, *surface2 ) ) {
496+
processGrid();
497497
}
498498

499499
for ( uint32_t i = 0; i < surface2->count; i += 3 ) {
@@ -527,14 +527,13 @@ static void OptimiseMaterialSurfaces( std::vector<MaterialSurface>& materialSurf
527527

528528
surface2->count = oldCount;
529529
*count = 0;
530+
} else {
531+
addedSurfaces = true;
530532
}
531533
}
532-
533-
surfaceIndex++;
534-
if ( surfaceIndex == materialSurfaces.size() ) {
535-
break;
536-
}
537534
}
535+
536+
processGrid();
538537
}
539538

540539
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces,

0 commit comments

Comments
 (0)
0