source: Revenant/gdmodule/src/terraingen.cpp@ f40df48

Last change on this file since f40df48 was dd8f5b4, checked in by Jonathan Neufeld <support@…>, 4 years ago

(WIP) GD Native module

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include "terraingen.h"
2
3#include <geoworld.h>
4#include <iostream>
5#include <fstream>
6#include <gmregistry.h>
7#include <gwmorphs/gmdefault.h>
8#include <yamlgmcfgrd.h>
9#include <yamlminreader.h>
10#include <yamlsessreader.h>
11#include <yamldepositsynthreader.h>
12#include <yamlmetaconfig.h>
13#include <synthsession.h>
14#include <PNGDEM.h>
15
16using namespace geoworld;
17using namespace genesis;
18using namespace mars;
19using namespace std;
20
21namespace godot {
22 TerrainGen::TerrainGen() : sess(new geoworld::SynthesisSession()), geoMorphRegistry(new DefaultGMRegistry()) {}
23 TerrainGen::~TerrainGen() {
24 delete sess;
25 delete geoMorphRegistry;
26 }
27
28 void TerrainGen::_register_methods() {
29 register_property<TerrainGen, String>("Configuration", &TerrainGen::set_config, &TerrainGen::get_config, String());
30 register_property<TerrainGen, String>("Output File", &TerrainGen::outputFile, "default.pgw");
31 register_property<TerrainGen, short>("Tile Size", &TerrainGen::tileDim, 128);
32 register_property<TerrainGen, short>("Width", &TerrainGen::width, 4000);
33 register_property<TerrainGen, short>("Height", &TerrainGen::height, 4000);
34 register_property<TerrainGen, short>("Depth", &TerrainGen::depth, 20000);
35
36 register_method("build", &TerrainGen::build);
37 }
38
39 String TerrainGen::get_config() {
40 return config;
41 }
42 void TerrainGen::set_config(String config) {
43 MetaConfig cfg;
44 std::ifstream incfg(config.utf8().get_data(), std::ios::in);
45 YAMLMetaConfigReader cfgreader(incfg);
46
47 bool bResult = cfgreader.load(cfg);
48 if (!bResult)
49 ;//throw Exception();
50
51 std::ifstream
52 ingenesis(cfg.resources.genesis, std::ios::in),
53 ingmfactories(cfg.resources.gmfactories, std::ios::in),
54 indepsynth(cfg.resources.depsynth, std::ios::in);
55
56 auto gmfactoriesreader = YAMLGeoMorphConfigReader(ingmfactories);
57
58 geoMorphRegistry->configure(gmfactoriesreader);
59
60 auto mineralsReader = MineralsYAMLReader(
61 cfg.resources.minerals.c_str(),
62 cfg.resources.classes.c_str()
63 );
64 auto synthReader = YAMLDepositSynthCfgReader(indepsynth);
65 auto synthSessReader = YAMLSynthSessCfgReader(ingenesis);
66
67 bResult = sess->init(
68 mineralsReader,
69 synthReader,
70 synthSessReader
71 );
72 if (bResult)
73 this->config = config;
74 else
75 ;//throw Exception();
76 }
77
78 void TerrainGen::build() {
79 std::string outputFile = this->outputFile.utf8().get_data();
80 sess->generate(outputFile, *geoMorphRegistry, width, height, depth);
81 }
82}
Note: See TracBrowser for help on using the repository browser.