[8125274] | 1 | #include "terraingen.h"
|
---|
| 2 |
|
---|
| 3 | #include <mars_log.h>
|
---|
| 4 | #include <gmdefault.h>
|
---|
| 5 |
|
---|
| 6 | namespace godot {
|
---|
| 7 | TerrainGen::TerrainGen() : core(NULL), geoMorphRegistry(NULL) {}
|
---|
| 8 | TerrainGen::~TerrainGen() {
|
---|
| 9 | delete core;
|
---|
| 10 | delete geoMorphRegistry;
|
---|
| 11 | }
|
---|
| 12 | void TerrainGen::_init() {
|
---|
| 13 | geoMorphRegistry = new geoworld::DefaultGMRegistry();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | void TerrainGen::_register_methods() {
|
---|
| 17 | register_property<TerrainGen, String>("Configuration", &TerrainGen::set_config, &TerrainGen::get_config, String());
|
---|
| 18 | register_property<TerrainGen, String>("OutputFile", &TerrainGen::outputFile, "default.pgw");
|
---|
| 19 | register_property<TerrainGen, short>("TileSize", &TerrainGen::tileDim, 128);
|
---|
| 20 | register_property<TerrainGen, short>("Width", &TerrainGen::width, 4000);
|
---|
| 21 | register_property<TerrainGen, short>("Height", &TerrainGen::height, 4000);
|
---|
| 22 | register_property<TerrainGen, short>("Depth", &TerrainGen::depth, 20000);
|
---|
| 23 |
|
---|
| 24 | register_method("build", &TerrainGen::build);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | String TerrainGen::get_config() {
|
---|
| 28 | return config;
|
---|
| 29 | }
|
---|
| 30 | void TerrainGen::set_config(String config) {
|
---|
| 31 | delete this->core;
|
---|
| 32 | try {
|
---|
| 33 | this->core = new TerrainGeneratorCore(config.utf8().get_data(), this->geoMorphRegistry);
|
---|
| 34 | } catch (std::exception * ex) {
|
---|
| 35 | this->core = NULL;
|
---|
| 36 | LOG(mars::Log::Fatal) << "Caught exception: " << ex->what();
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | void TerrainGen::build() {
|
---|
| 41 | std::string outputFile = this->outputFile.utf8().get_data();
|
---|
| 42 | this->core->generate(outputFile, tileDim, width, height, depth);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|