diff --git a/sc2/src/uqm/plandata.c b/sc2/src/uqm/plandata.c index 9f354ebaa..ac8bc5fb0 100644 --- a/sc2/src/uqm/plandata.c +++ b/sc2/src/uqm/plandata.c @@ -608,6 +608,11 @@ STAR_DESC starmap_array[] = {{MAX_X_UNIVERSE << 1, MAX_Y_UNIVERSE << 1}, 0, 0, 0, 0}, }; +STAR_DESC * +GetAllStars( void ) +{ + return starmap_array; +} COUNT GetStarCount( void ) diff --git a/sc2/src/uqm/planets/generate-base.cpp b/sc2/src/uqm/planets/generate-base.cpp index 5e4f250dc..8133d513f 100644 --- a/sc2/src/uqm/planets/generate-base.cpp +++ b/sc2/src/uqm/planets/generate-base.cpp @@ -28,6 +28,8 @@ #include "uqm/planets/generate/gendefault.h" #include "uqm/gendef.h" +#include "uqm/planets/planets.h" +#include "uqm/starmap.h" /* * XXX: Note that the way that defaults get called via C++ is a bit @@ -63,6 +65,17 @@ namespace Planets ::detail:: Generate_m { + using namespace std::literals::string_literals; + + namespace + { + namespace C + { + const bool debug= true; + const bool debugGenerationByValidatingAllStars= false or C::debug; + } + } + Generator::~Generator()= default; @@ -203,28 +216,58 @@ namespace Planets ::detail:: Generate_m void Generator::add( const std::string &name, std::unique_ptr< Generator > gen ) { + if( C::debug ) + { + std::cerr << "Attempting to register `" << name << "` generator." << std::endl; + } if( registry().count( name ) ) { throw std::runtime_error( "Double registration of `" + name + "`" ); } registry()[ name ]= std::move( gen ); } + + namespace + { + void + validateAllStars() + { + for( int i= 0; i < GetStarCount(); ++i ) + { + const auto &star= GetAllStars()[ i ]; + if( star.supplement == nullptr ) continue; + + std::cerr << "Checking if required generator `" << star.supplement << "` is " + << "present..."; + if( not registry().count( star.supplement ) ) + { + std::cerr << " NO!!!!" << std::endl; + throw std::runtime_error{ "Solar system generator `"s + star.supplement + + "` was needed but not found" }; + } + + std::cerr << " yes" << std::endl; + } + } + } } extern "C" { using Planets::SolarSystem; - using Planets::detail::Generate_m::registry; + using namespace Planets::detail::Generate_m; extern GenerateFunctions *getGenerateCxxFunctions( void ); void SetupGeneratorForSolarSystem( STAR_DESC *const desc, SolarSystem *const solarSys ) { + if( C::debugGenerationByValidatingAllStars ) validateAllStars(); + // Must either have a legacy constructor or a named lookup, // but not both. - + // If there's a legacy builder, we must have no supplement. // We just go to the old way of doing things... if( desc->Index ) diff --git a/sc2/src/uqm/planets/planets.h b/sc2/src/uqm/planets/planets.h index bc53c7103..f56235ec2 100644 --- a/sc2/src/uqm/planets/planets.h +++ b/sc2/src/uqm/planets/planets.h @@ -115,6 +115,8 @@ typedef struct solarsys_state SOLARSYS_STATE; extern "C" { #endif +extern STAR_DESC *GetAllStars( void ); + struct planet_desc { DWORD rand_seed;