2023-06-20 04:33:09 +00:00
# include "StarRootLoader.hpp"
# include "StarCelestialDatabase.hpp"
# include "StarWorldTemplate.hpp"
# include "StarWorldServer.hpp"
using namespace Star ;
int main ( int argc , char * * argv ) {
try {
RootLoader rootLoader ( { { } , { } , { } , LogLevel : : Error , false , { } } ) ;
rootLoader . addParameter ( " coordinate " , " coordinate " , OptionParser : : Optional , " world coordinate to test " ) ;
rootLoader . addParameter ( " regions " , " regions " , OptionParser : : Optional , " number of regions to generate, default 1000 " ) ;
rootLoader . addParameter ( " regionsize " , " size " , OptionParser : : Optional , " width / height of each generation region, default 10 " ) ;
rootLoader . addParameter ( " reportevery " , " report regions " , OptionParser : : Optional , " number of generation regions before each progress report, default 20 " ) ;
RootUPtr root ;
OptionParser : : Options options ;
tie ( root , options ) = rootLoader . commandInitOrDie ( argc , argv ) ;
coutf ( " Fully loading root... " ) ;
root - > fullyLoad ( ) ;
coutf ( " done \n " ) ;
CelestialMasterDatabase celestialDatabase ;
CelestialCoordinate coordinate ;
if ( auto coordinateOption = options . parameters . maybe ( " coordinate " ) ) {
coordinate = CelestialCoordinate ( coordinateOption - > first ( ) ) ;
} else {
coordinate = celestialDatabase . findRandomWorld ( 100 , 50 , [ & ] ( CelestialCoordinate const & coord ) {
return celestialDatabase . parameters ( coord ) - > isVisitable ( ) ;
} ) . take ( ) ;
}
unsigned regionsToGenerate = 1000 ;
if ( auto regionsOption = options . parameters . maybe ( " regions " ) )
regionsToGenerate = lexicalCast < unsigned > ( regionsOption - > first ( ) ) ;
unsigned regionSize = 10 ;
if ( auto regionSizeOption = options . parameters . maybe ( " regionsize " ) )
regionSize = lexicalCast < unsigned > ( regionSizeOption - > first ( ) ) ;
unsigned reportEvery = 20 ;
if ( auto reportEveryOption = options . parameters . maybe ( " reportevery " ) )
reportEvery = lexicalCast < unsigned > ( reportEveryOption - > first ( ) ) ;
2023-06-27 10:23:44 +00:00
coutf ( " testing generation on coordinate {} \n " , coordinate ) ;
2023-06-20 04:33:09 +00:00
auto worldParameters = celestialDatabase . parameters ( coordinate ) . take ( ) ;
auto worldTemplate = make_shared < WorldTemplate > ( worldParameters . visitableParameters ( ) , SkyParameters ( ) , worldParameters . seed ( ) ) ;
auto rand = RandomSource ( worldTemplate - > worldSeed ( ) ) ;
2024-02-19 15:55:19 +00:00
WorldServer worldServer ( std : : move ( worldTemplate ) , File : : ephemeralFile ( ) ) ;
2023-06-20 04:33:09 +00:00
Vec2U worldSize = worldServer . geometry ( ) . size ( ) ;
double start = Time : : monotonicTime ( ) ;
double lastReport = Time : : monotonicTime ( ) ;
2023-06-27 10:23:44 +00:00
coutf ( " Starting world generation for {} regions \n " , regionsToGenerate ) ;
2023-06-20 04:33:09 +00:00
for ( unsigned i = 0 ; i < regionsToGenerate ; + + i ) {
if ( i ! = 0 & & i % reportEvery = = 0 ) {
float gps = reportEvery / ( Time : : monotonicTime ( ) - lastReport ) ;
lastReport = Time : : monotonicTime ( ) ;
2023-06-27 10:23:44 +00:00
coutf ( " [{}] {}s | Generatons Per Second: {} \n " , i , Time : : monotonicTime ( ) - start , gps ) ;
2023-06-20 04:33:09 +00:00
}
RectI region = RectI : : withCenter ( Vec2I ( rand . randInt ( 0 , worldSize [ 0 ] ) , rand . randInt ( 0 , worldSize [ 1 ] ) ) , Vec2I : : filled ( regionSize ) ) ;
worldServer . generateRegion ( region ) ;
}
2023-06-27 10:23:44 +00:00
coutf ( " Finished generating {} regions with size {}x{} in world '{}' in {} seconds " , regionsToGenerate , regionSize , regionSize , coordinate , Time : : monotonicTime ( ) - start ) ;
2023-06-20 04:33:09 +00:00
return 0 ;
} catch ( std : : exception const & e ) {
2023-06-27 10:23:44 +00:00
cerrf ( " Exception caught: {} \n " , outputException ( e , true ) ) ;
2023-06-20 04:33:09 +00:00
return 1 ;
}
}