@@ -462,38 +462,38 @@ static void OptimiseMaterialSurfaces( std::vector<MaterialSurface>& materialSurf
462
462
Grid<SurfaceIndexes> surfaceIdxsGrid ( true );
463
463
surfaceIdxsGrid.SetSize ( gridSize[0 ], gridSize[1 ], gridSize[2 ] );
464
464
465
- uint32_t surfaceIndex = 0 ;
466
465
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 ;
471
468
472
- if ( surfaceIndex == materialSurfaces.size () ) {
473
- break ;
474
- }
475
-
476
- continue ;
469
+ std::function<void ()> processGrid = [&]() {
470
+ if ( !addedSurfaces ) {
471
+ surface = surface2;
472
+ return ;
477
473
}
478
474
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
+ }
483
481
}
484
482
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 ();
493
484
494
- surfaceGrid.Clear ();
485
+ surface = surface2;
486
+ addedSurfaces = false ;
487
+ };
495
488
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 ();
497
497
}
498
498
499
499
for ( uint32_t i = 0 ; i < surface2->count ; i += 3 ) {
@@ -527,14 +527,13 @@ static void OptimiseMaterialSurfaces( std::vector<MaterialSurface>& materialSurf
527
527
528
528
surface2->count = oldCount;
529
529
*count = 0 ;
530
+ } else {
531
+ addedSurfaces = true ;
530
532
}
531
533
}
532
-
533
- surfaceIndex++;
534
- if ( surfaceIndex == materialSurfaces.size () ) {
535
- break ;
536
- }
537
534
}
535
+
536
+ processGrid ();
538
537
}
539
538
540
539
std::vector<MaterialSurface> OptimiseMapGeometryMaterial ( world_t * world, bspSurface_t** rendererSurfaces, int numSurfaces,
0 commit comments