#include "core.h" #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace geoworld; using namespace genesis; using namespace mars; using namespace std; namespace godot { TerrainGeneratorCore::TerrainGeneratorCore(const boost::filesystem::path path, geoworld::GeoMorphRegistry * geoMorphRegistry) : sess(new SynthesisSession()), geoMorphRegistry(geoMorphRegistry) { LOGN << "Attempting to load from config " << path; MetaConfig cfg; std::ifstream incfg; incfg.exceptions(std::ifstream::failbit | std::ifstream::badbit); incfg.open(path.c_str(), std::ios::in); YAMLMetaConfigReader cfgreader(incfg); cfgreader.load(cfg); incfg.close(); LOGN << "Now loading Genesis = " << cfg.resources.genesis << ", Factories = " << cfg.resources.gmfactories << ", and Deposit Synthesis = " << cfg.resources.depsynth; std::ifstream ingenesis, ingmfactories, indepsynth; ingenesis.exceptions(std::ifstream::failbit | std::ifstream::badbit); ingmfactories.exceptions(std::ifstream::failbit | std::ifstream::badbit); indepsynth.exceptions(std::ifstream::failbit | std::ifstream::badbit); const boost::filesystem::path container = path.parent_path(), genesisConfig = container / cfg.resources.genesis, factoriesConfig = container / cfg.resources.gmfactories, depSynthConfig = container / cfg.resources.depsynth; ingenesis.open(genesisConfig.c_str(), std::ios::in); ingmfactories.open(factoriesConfig.c_str(), std::ios::in); indepsynth.open(depSynthConfig.c_str(), std::ios::in); auto gmfactoriesreader = YAMLGeoMorphConfigReader(ingmfactories); LOGN << "Configuring GM Factories"; geoMorphRegistry->configure(gmfactoriesreader); LOGN << "Loading Minerals = " << cfg.resources.minerals << ", Classes = " << cfg.resources.classes; const boost::filesystem::path mineralsConfig = container / cfg.resources.minerals, classesConfig = container / cfg.resources.classes; auto mineralsReader = MineralsYAMLReader( mineralsConfig.c_str(), classesConfig.c_str(), NULL ); auto synthReader = YAMLDepositSynthCfgReader(indepsynth); auto synthSessReader = YAMLSynthSessCfgReader(ingenesis); LOGN << "Initializing synthesis session"; this->sess->addListener(this); bool bResult = this->sess->init( mineralsReader, synthReader, synthSessReader ); if (!bResult) LOG(mars::Log::Fatal) << "Failed to generate the world"; ingenesis.close(); ingmfactories.close(); indepsynth.close(); } void TerrainGeneratorCore::generate(const boost::filesystem::path outputFile, const unsigned short nTileDim, const unsigned long nWorldWidth, const unsigned long nWorldHeight, const unsigned short nWorldDepth) { LOGN << "Generating to " << outputFile << ", with dimensions " << nWorldWidth << 'x' << nWorldHeight << 'x' << nWorldDepth << '@' << nTileDim; this->sess->setTileDim(nTileDim); this->sess->generate(outputFile.c_str(), *geoMorphRegistry, nWorldWidth, nWorldHeight, nWorldDepth); } TerrainGeneratorCore::~TerrainGeneratorCore() { delete sess; delete geoMorphRegistry; } void TerrainGeneratorCore::onRaster( GeoWorld * const pWorld ) { LOGN << "Rastering..."; } void TerrainGeneratorCore::onRejects( GeoWorld * const pWorld, const MorphList & rejects ) { LOG(mars::Log::Warn) << "Rejects: "; for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i) LOG(mars::Log::Warn) << "\t- " << (*i)->getTypeName(); } void TerrainGeneratorCore::onInitMorph( GeoWorld * const pWorld, const GeoMorph * pMorph ) { LOGN << "Initialize Morph: " << pMorph->getTypeName(); const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph); if (NULL != pBGM) { LOGN << ", bbox=" << pBGM->getBBox(); } } void TerrainGeneratorCore::onGenerate( GeoWorld * const pWorld ) { LOGN << "Generating world at LOD " << pWorld->getLOD(); } void TerrainGeneratorCore::onDoMorph (GeoWorld * const pWorld, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal) { LOGN << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal; } void TerrainGeneratorCore::onCreateMiddleTier (GeoWorld * const pWorld, const std::string & sFileName) { LOGN << "Generating Pageable-World File \"" << sFileName << "\""; } void TerrainGeneratorCore::onGenerateMiddleTier (GeoWorld * const pWorld, const PagedGeoWorld * const pPgWorld) { LOGN << "Dumping a sample"; const LockedGWSection * pSection = pPgWorld->lockro(-500, -500, 2000, 1000); *pSection >> GLOBALDEM; DUMP_GLOBALDEM(); pPgWorld->unlock(pSection); } void TerrainGeneratorCore::onPrepareMorphs( GeoWorld * const pWorld, const MorphList & morphs ) { LOGN << "Chosen morphs: "; for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i) LOGN << "\t- " << (*i)->getTypeName(); } void TerrainGeneratorCore::onPrepareMorphs2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & morphs ) { LOGN << "P" << nPass << ": " << "Chosen morphs: "; for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i) LOGN << "\t- " << (*i)->getTypeName(); } void TerrainGeneratorCore::onInitMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const GeoMorph * pMorph ) { LOGN << "P" << nPass << ": " << "Initialize Morph: " << pMorph->getTypeName(); const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph); if (NULL != pBGM) { LOGN << ", bbox=" << pBGM->getBBox(); } } void TerrainGeneratorCore::onDoMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal ) { LOGN << "P" << nPass << ": " << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal; } void TerrainGeneratorCore::onRaster2( PagedGeoWorld * const pPgWorld, const unsigned short nPass ) { LOGN << "P" << nPass << ": " << "Rastering..."; } void TerrainGeneratorCore::onPass2( PagedGeoWorld * const pPgWorld, const unsigned short nPass ) { LOGN << "Begin pass #" << nPass; } void TerrainGeneratorCore::onGenerate2( PagedGeoWorld * const pPgWorld ) { LOGN << "Generating world at LOD " << pPgWorld->getLOD(); } void TerrainGeneratorCore::onRejects2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & rejects ) { LOG(mars::Log::Warn) << "P" << nPass << ": " << "Rejects: "; for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i) LOG(mars::Log::Warn) << "\t- " << (*i)->getTypeName(); } void TerrainGeneratorCore::onGenerateGeoHostLayers (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth) { LOGN << "Generating Geology Host layers..."; } void TerrainGeneratorCore::onSpawnMinerals (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth) { LOGN << "Generating some minerals..."; } void TerrainGeneratorCore::onSpawnMinerals2 (PagedGeoWorld * const pPgWorld, const unsigned short nPass, DepositSynthesizer * const pDepSynth) { LOGN << "Generating some minerals..."; } }