From cd8312ebc1851757e5b30f69d8bc8f36feef76c4 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 28 Apr 2024 02:03:40 -0400 Subject: [PATCH] On generation check that the whole starmap is properly sorted. (I should probably make this check runtime-sticky... with huge dynamical games it might get a bit noticable that we slow down for each solar system load event.) --- sc2/src/uqm/planets/generate-base.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sc2/src/uqm/planets/generate-base.cpp b/sc2/src/uqm/planets/generate-base.cpp index 0a9263cc1..c1e02c111 100644 --- a/sc2/src/uqm/planets/generate-base.cpp +++ b/sc2/src/uqm/planets/generate-base.cpp @@ -23,6 +23,7 @@ #include #include +#include #include @@ -232,6 +233,21 @@ namespace Planets ::detail:: Generate_m void validateAllStars() { + const auto where= std::is_sorted_until( GetAllStars(), + GetAllStars() + GetStarCount(), + []( const auto &lhs_, const auto &rhs_ ) + { + const auto &lhs= lhs_.star_pt; + const auto &rhs= rhs_.star_pt; + + if( lhs.y == rhs.y ) return lhs.x < rhs.x; + return lhs.y < rhs.y; + } ); + if( where != GetAllStars() + GetStarCount() ) + { + throw std::runtime_error( "Found star out of order" ); + } + for( int i= 0; i < GetStarCount(); ++i ) { const auto &star= GetAllStars()[ i ];