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.)
This commit is contained in:
2024-04-28 02:03:40 -04:00
parent d4f9485f90
commit cd8312ebc1
+16
View File
@@ -23,6 +23,7 @@
#include <exception>
#include <stdexcept>
#include <algorithm>
#include <iostream>
@@ -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 ];