#include "terraingen.h" #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 { TerrainGen::TerrainGen() : sess(new geoworld::SynthesisSession()), geoMorphRegistry(new DefaultGMRegistry()) {} TerrainGen::~TerrainGen() { delete sess; delete geoMorphRegistry; } void TerrainGen::_register_methods() { register_property("Configuration", &TerrainGen::set_config, &TerrainGen::get_config, String()); register_property("Output File", &TerrainGen::outputFile, "default.pgw"); register_property("Tile Size", &TerrainGen::tileDim, 128); register_property("Width", &TerrainGen::width, 4000); register_property("Height", &TerrainGen::height, 4000); register_property("Depth", &TerrainGen::depth, 20000); register_method("build", &TerrainGen::build); } String TerrainGen::get_config() { return config; } void TerrainGen::set_config(String config) { MetaConfig cfg; std::ifstream incfg(config.utf8().get_data(), std::ios::in); YAMLMetaConfigReader cfgreader(incfg); bool bResult = cfgreader.load(cfg); if (!bResult) ;//throw Exception(); std::ifstream ingenesis(cfg.resources.genesis, std::ios::in), ingmfactories(cfg.resources.gmfactories, std::ios::in), indepsynth(cfg.resources.depsynth, std::ios::in); auto gmfactoriesreader = YAMLGeoMorphConfigReader(ingmfactories); geoMorphRegistry->configure(gmfactoriesreader); auto mineralsReader = MineralsYAMLReader( cfg.resources.minerals.c_str(), cfg.resources.classes.c_str() ); auto synthReader = YAMLDepositSynthCfgReader(indepsynth); auto synthSessReader = YAMLSynthSessCfgReader(ingenesis); bResult = sess->init( mineralsReader, synthReader, synthSessReader ); if (bResult) this->config = config; else ;//throw Exception(); } void TerrainGen::build() { std::string outputFile = this->outputFile.utf8().get_data(); sess->generate(outputFile, *geoMorphRegistry, width, height, depth); } }