diff --git a/SCsub b/SCsub index cfe1b99..6e3e8ca 100644 --- a/SCsub +++ b/SCsub @@ -31,7 +31,6 @@ sources = [ "data/dungeon_corridor_data.cpp", "data/dungeon_data.cpp", "data/biome_data.cpp", - "data/planet_data.cpp", "data/world_generator_prop_data.cpp", "world_generator.cpp", diff --git a/config.py b/config.py index a5f5e68..fda6ce5 100644 --- a/config.py +++ b/config.py @@ -10,7 +10,6 @@ def get_doc_classes(): "DungeonCorridorData", "DungeonData", "DungeonRoomData", - "PlanetData", "WorldGeneratorPropData", "BiomeData", diff --git a/data/planet_data.cpp b/data/planet_data.cpp deleted file mode 100644 index 48d8d3f..0000000 --- a/data/planet_data.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* -Copyright (c) 2019-2020 Péter Magyar - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#include "planet_data.h" - -#include "core/version.h" - -#include "../main/planet.h" - -int PlanetData::get_id() const { - return _id; -} -void PlanetData::set_id(const int value) { - _id = value; -} - -Ref PlanetData::get_planet() { - return _planet; -} -void PlanetData::set_planet(const Ref &planet) { - _planet = planet; -} - -Vector2 PlanetData::get_level_range() { - return _level_range; -} -void PlanetData::set_level_range(Vector2 value) { - _level_range = value; -} - -#ifdef FASTNOISE_PRESENT -Ref PlanetData::get_humidity_noise_params() { - return _humidity_noise_params; -} -void PlanetData::set_humidity_noise_params(Ref value) { - _humidity_noise_params = value; -} - -Ref PlanetData::get_temperature_noise_params() { - return _temperature_noise_params; -} -void PlanetData::set_temperature_noise_params(Ref value) { - _temperature_noise_params = value; -} -#endif - -//Biomes -Ref PlanetData::get_biome_data(const int index) const { - ERR_FAIL_INDEX_V(index, _biome_datas.size(), Ref()); - - return _biome_datas.get(index); -} -void PlanetData::set_biome_data(const int index, const Ref biome_data) { - ERR_FAIL_INDEX(index, _biome_datas.size()); - - _biome_datas.set(index, biome_data); -} -void PlanetData::add_biome_data(const Ref biome_data) { - _biome_datas.push_back(biome_data); -} -void PlanetData::remove_biome_data(const int index) { - ERR_FAIL_INDEX(index, _biome_datas.size()); - - _biome_datas.remove(index); -} -int PlanetData::get_biome_data_count() const { - return _biome_datas.size(); -} - -Vector PlanetData::get_biome_datas() { - Vector r; - for (int i = 0; i < _biome_datas.size(); i++) { -#if VERSION_MAJOR < 4 - r.push_back(_biome_datas[i].get_ref_ptr()); -#else - r.push_back(_biome_datas[i]); -#endif - } - return r; -} -void PlanetData::set_biome_datas(const Vector &biome_datas) { - _biome_datas.clear(); - for (int i = 0; i < biome_datas.size(); i++) { - Ref biome_data = Ref(biome_datas[i]); - - _biome_datas.push_back(biome_data); - } -} - -#ifdef VOXELMAN_PRESENT -//Environments -Ref PlanetData::get_environment_data(const int index) const { - ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref()); - - return _environment_datas.get(index); -} -void PlanetData::set_environment_data(const int index, const Ref environment_data) { - ERR_FAIL_INDEX(index, _environment_datas.size()); - - _environment_datas.set(index, environment_data); -} -void PlanetData::add_environment_data(const Ref environment_data) { - _environment_datas.push_back(environment_data); -} -void PlanetData::remove_environment_data(const int index) { - ERR_FAIL_INDEX(index, _environment_datas.size()); - - _environment_datas.remove(index); -} -int PlanetData::get_environment_data_count() const { - return _environment_datas.size(); -} - -Vector PlanetData::get_environment_datas() { - Vector r; - for (int i = 0; i < _environment_datas.size(); i++) { -#if VERSION_MAJOR < 4 - r.push_back(_environment_datas[i].get_ref_ptr()); -#else - r.push_back(_environment_datas[i]); -#endif - } - return r; -} -void PlanetData::set_environment_datas(const Vector &environment_datas) { - _environment_datas.clear(); - for (int i = 0; i < environment_datas.size(); i++) { - Ref environment_data = Ref(environment_datas[i]); - - _environment_datas.push_back(environment_data); - } -} - -//// Surfaces //// -Ref PlanetData::get_voxel_surface(const int index) const { - ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref()); - - return _voxel_surfaces.get(index); -} -void PlanetData::set_voxel_surface(const int index, const Ref voxel_surface) { - ERR_FAIL_INDEX(index, _voxel_surfaces.size()); - - _voxel_surfaces.set(index, voxel_surface); -} -void PlanetData::add_voxel_surface(const Ref voxel_surface) { - _voxel_surfaces.push_back(voxel_surface); -} -void PlanetData::remove_voxel_surface(const int index) { - ERR_FAIL_INDEX(index, _voxel_surfaces.size()); - - _voxel_surfaces.remove(index); -} -int PlanetData::get_voxel_surface_count() const { - return _voxel_surfaces.size(); -} - -Vector PlanetData::get_voxel_surfaces() { - Vector r; - for (int i = 0; i < _voxel_surfaces.size(); i++) { -#if VERSION_MAJOR < 4 - r.push_back(_voxel_surfaces[i].get_ref_ptr()); -#else - r.push_back(_voxel_surfaces[i]); -#endif - } - return r; -} -void PlanetData::set_voxel_surfaces(const Vector &voxel_surfaces) { - _voxel_surfaces.clear(); - for (int i = 0; i < voxel_surfaces.size(); i++) { - Ref voxel_surface = Ref(voxel_surfaces[i]); - - _voxel_surfaces.push_back(voxel_surface); - } -} - -#endif - -Ref PlanetData::instance() { - Ref planet; - - if (!_planet.is_valid()) { - planet.instance(); - } else { - planet = _planet->duplicate(); - } - - planet->set_data(Ref(this)); - - return planet; -} - -PlanetData::PlanetData() { - _id = 0; -} -PlanetData::~PlanetData() { -#ifdef FASTNOISE_PRESENT - _humidity_noise_params.unref(); - _temperature_noise_params.unref(); -#endif - - _biome_datas.clear(); - -#ifdef VOXELMAN_PRESENT - _environment_datas.clear(); - _voxel_surfaces.clear(); - _liquid_voxel_surfaces.clear(); -#endif -} - -void PlanetData::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_id"), &PlanetData::get_id); - ClassDB::bind_method(D_METHOD("set_id", "value"), &PlanetData::set_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); - - ClassDB::bind_method(D_METHOD("get_planet"), &PlanetData::get_planet); - ClassDB::bind_method(D_METHOD("set_planet", "value"), &PlanetData::set_planet); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "planet", PROPERTY_HINT_RESOURCE_TYPE, "Planet"), "set_planet", "get_planet"); - - ClassDB::bind_method(D_METHOD("get_level_range"), &PlanetData::get_level_range); - ClassDB::bind_method(D_METHOD("set_level_range", "value"), &PlanetData::set_level_range); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range"); - -#ifdef FASTNOISE_PRESENT - ClassDB::bind_method(D_METHOD("get_humidity_noise_params"), &PlanetData::get_humidity_noise_params); - ClassDB::bind_method(D_METHOD("set_humidity_noise_params", "value"), &PlanetData::set_humidity_noise_params); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "humidity_noise_params", PROPERTY_HINT_RESOURCE_TYPE, "FastnoiseNoiseParams"), "set_humidity_noise_params", "get_humidity_noise_params"); - - ClassDB::bind_method(D_METHOD("get_temperature_noise_params"), &PlanetData::get_temperature_noise_params); - ClassDB::bind_method(D_METHOD("set_temperature_noise_params", "value"), &PlanetData::set_temperature_noise_params); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "temperature_noise_params", PROPERTY_HINT_RESOURCE_TYPE, "FastnoiseNoiseParams"), "set_temperature_noise_params", "get_temperature_noise_params"); -#endif - - //Biomes - ClassDB::bind_method(D_METHOD("get_biome_data", "index"), &PlanetData::get_biome_data); - ClassDB::bind_method(D_METHOD("set_biome_data", "index", "data"), &PlanetData::set_biome_data); - ClassDB::bind_method(D_METHOD("add_biome_data", "biome_data"), &PlanetData::add_biome_data); - ClassDB::bind_method(D_METHOD("remove_biome_data", "index"), &PlanetData::remove_biome_data); - ClassDB::bind_method(D_METHOD("get_biome_data_count"), &PlanetData::get_biome_data_count); - - ClassDB::bind_method(D_METHOD("get_biome_datas"), &PlanetData::get_biome_datas); - ClassDB::bind_method(D_METHOD("set_biome_datas", "biome_datas"), &PlanetData::set_biome_datas); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "biome_datas", PROPERTY_HINT_NONE, "17/17:BiomeData", PROPERTY_USAGE_DEFAULT, "BiomeData"), "set_biome_datas", "get_biome_datas"); - -#ifdef VOXELMAN_PRESENT - //Environments - ClassDB::bind_method(D_METHOD("get_environment_data", "index"), &PlanetData::get_environment_data); - ClassDB::bind_method(D_METHOD("set_environment_data", "index", "data"), &PlanetData::set_environment_data); - ClassDB::bind_method(D_METHOD("add_environment_data", "environment_data"), &PlanetData::add_environment_data); - ClassDB::bind_method(D_METHOD("remove_environment_data", "index"), &PlanetData::remove_environment_data); - ClassDB::bind_method(D_METHOD("get_environment_data_count"), &PlanetData::get_environment_data_count); - - ClassDB::bind_method(D_METHOD("get_environment_datas"), &PlanetData::get_environment_datas); - ClassDB::bind_method(D_METHOD("set_environment_datas", "environment_datas"), &PlanetData::set_environment_datas); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "environment_datas", PROPERTY_HINT_NONE, "17/17:EnvironmentData", PROPERTY_USAGE_DEFAULT, "EnvironmentData"), "set_environment_datas", "get_environment_datas"); - - //Surfaces - ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &PlanetData::get_voxel_surface); - ClassDB::bind_method(D_METHOD("set_voxel_surface", "index", "data"), &PlanetData::set_voxel_surface); - ClassDB::bind_method(D_METHOD("add_voxel_surface", "voxel_surface"), &PlanetData::add_voxel_surface); - ClassDB::bind_method(D_METHOD("remove_voxel_surface", "index"), &PlanetData::remove_voxel_surface); - ClassDB::bind_method(D_METHOD("get_voxel_surface_count"), &PlanetData::get_voxel_surface_count); - - ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &PlanetData::get_voxel_surfaces); - ClassDB::bind_method(D_METHOD("set_voxel_surfaces", "voxel_surfaces"), &PlanetData::set_voxel_surfaces); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurface", PROPERTY_USAGE_DEFAULT, "VoxelSurface"), "set_voxel_surfaces", "get_voxel_surfaces"); -#endif - - ClassDB::bind_method(D_METHOD("instance"), &PlanetData::instance); -} diff --git a/data/planet_data.h b/data/planet_data.h deleted file mode 100644 index d2113a0..0000000 --- a/data/planet_data.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright (c) 2019-2020 Péter Magyar - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef biome_data_H -#define biome_data_H - -#include "core/resource.h" -#include "core/script_language.h" -#include "core/ustring.h" - -#ifdef FASTNOISE_PRESENT -#include "../../fastnoise/fastnoise_noise_params.h" -#endif - -#include "../data/biome_data.h" -#include "../main/planet.h" - -#ifdef VOXELMAN_PRESENT -#include "../../voxelman/library/voxel_surface.h" -#include "../../voxelman/world/environment_data.h" -#endif - -class Planet; - -class PlanetData : public Resource { - GDCLASS(PlanetData, Resource); - -public: - int get_id() const; - void set_id(const int value); - - Ref get_planet(); - void set_planet(const Ref &planet); - - Vector2 get_level_range(); - void set_level_range(Vector2 value); - -#ifdef FASTNOISE_PRESENT - Ref get_humidity_noise_params(); - void set_humidity_noise_params(Ref value); - - Ref get_temperature_noise_params(); - void set_temperature_noise_params(Ref value); -#endif - - //Biomes - Ref get_biome_data(const int index) const; - void set_biome_data(const int index, const Ref biome_data); - void add_biome_data(const Ref biome_data); - void remove_biome_data(const int index); - int get_biome_data_count() const; - - Vector get_biome_datas(); - void set_biome_datas(const Vector &biome_datas); - -#ifdef VOXELMAN_PRESENT - //Environments - Ref get_environment_data(const int index) const; - void set_environment_data(const int index, const Ref environment_data); - void add_environment_data(const Ref environment_data); - void remove_environment_data(const int index); - int get_environment_data_count() const; - - Vector get_environment_datas(); - void set_environment_datas(const Vector &environment_datas); - - //Surfaces - Ref get_voxel_surface(const int index) const; - void set_voxel_surface(const int index, const Ref voxel_surface); - void add_voxel_surface(const Ref voxel_surface); - void remove_voxel_surface(const int index); - int get_voxel_surface_count() const; - - Vector get_voxel_surfaces(); - void set_voxel_surfaces(const Vector &voxel_surfaces); - -#endif - - Ref instance(); - - PlanetData(); - ~PlanetData(); - -protected: - static void _bind_methods(); - -private: - int _id; - - Ref _planet; - - Vector2 _level_range; - -#ifdef FASTNOISE_PRESENT - Ref _humidity_noise_params; - Ref _temperature_noise_params; -#endif - - Vector > _biome_datas; - -#ifdef VOXELMAN_PRESENT - Vector > _environment_datas; - Vector > _voxel_surfaces; - Vector > _liquid_voxel_surfaces; -#endif -}; - -#endif diff --git a/main/planet.cpp b/main/planet.cpp index 78f18c8..872601a 100644 --- a/main/planet.cpp +++ b/main/planet.cpp @@ -22,6 +22,15 @@ SOFTWARE. #include "planet.h" +#include "core/version.h" + +int Planet::get_id() const { + return _id; +} +void Planet::set_id(const int value) { + _id = value; +} + int Planet::get_current_seed() { return _current_seed; } @@ -36,6 +45,22 @@ void Planet::set_level_range(Vector2 value) { _level_range = value; } +#ifdef FASTNOISE_PRESENT +Ref Planet::get_humidity_noise_params() { + return _humidity_noise_params; +} +void Planet::set_humidity_noise_params(Ref value) { + _humidity_noise_params = value; +} + +Ref Planet::get_temperature_noise_params() { + return _temperature_noise_params; +} +void Planet::set_temperature_noise_params(Ref value) { + _temperature_noise_params = value; +} +#endif + #ifdef VOXELMAN_PRESENT Ref Planet::get_environment() { return _environment; @@ -45,13 +70,6 @@ void Planet::set_environment(Ref value) { } #endif -Ref Planet::get_data() { - return _data; -} -void Planet::set_data(Ref value) { - _data = value; -} - Ref Planet::get_biome(const int index) const { ERR_FAIL_INDEX_V(index, _biomes.size(), Ref()); @@ -75,6 +93,26 @@ int Planet::get_biome_count() const { return _biomes.size(); } +Vector Planet::get_biomes() { + Vector r; + for (int i = 0; i < _biomes.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_biomes[i].get_ref_ptr()); +#else + r.push_back(_biomes[i]); +#endif + } + return r; +} +void Planet::set_biomes(const Vector &biomes) { + _biomes.clear(); + for (int i = 0; i < biomes.size(); i++) { + Ref biome_data = Ref(biomes[i]); + + _biomes.push_back(biome_data); + } +} + //// Dungeons //// Ref Planet::get_dungeon(const int index) const { ERR_FAIL_INDEX_V(index, _dungeons.size(), Ref()); @@ -98,10 +136,96 @@ int Planet::get_dungeon_count() const { return _dungeons.size(); } -void Planet::setup() { - if (!_data.is_valid()) - return; +#ifdef VOXELMAN_PRESENT +//Environments +Ref Planet::get_environment_data(const int index) const { + ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref()); + return _environment_datas.get(index); +} +void Planet::set_environment_data(const int index, const Ref environment_data) { + ERR_FAIL_INDEX(index, _environment_datas.size()); + + _environment_datas.set(index, environment_data); +} +void Planet::add_environment_data(const Ref environment_data) { + _environment_datas.push_back(environment_data); +} +void Planet::remove_environment_data(const int index) { + ERR_FAIL_INDEX(index, _environment_datas.size()); + + _environment_datas.remove(index); +} +int Planet::get_environment_data_count() const { + return _environment_datas.size(); +} + +Vector Planet::get_environment_datas() { + Vector r; + for (int i = 0; i < _environment_datas.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_environment_datas[i].get_ref_ptr()); +#else + r.push_back(_environment_datas[i]); +#endif + } + return r; +} +void Planet::set_environment_datas(const Vector &environment_datas) { + _environment_datas.clear(); + for (int i = 0; i < environment_datas.size(); i++) { + Ref environment_data = Ref(environment_datas[i]); + + _environment_datas.push_back(environment_data); + } +} + +//// Surfaces //// +Ref Planet::get_voxel_surface(const int index) const { + ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref()); + + return _voxel_surfaces.get(index); +} +void Planet::set_voxel_surface(const int index, const Ref voxel_surface) { + ERR_FAIL_INDEX(index, _voxel_surfaces.size()); + + _voxel_surfaces.set(index, voxel_surface); +} +void Planet::add_voxel_surface(const Ref voxel_surface) { + _voxel_surfaces.push_back(voxel_surface); +} +void Planet::remove_voxel_surface(const int index) { + ERR_FAIL_INDEX(index, _voxel_surfaces.size()); + + _voxel_surfaces.remove(index); +} +int Planet::get_voxel_surface_count() const { + return _voxel_surfaces.size(); +} + +Vector Planet::get_voxel_surfaces() { + Vector r; + for (int i = 0; i < _voxel_surfaces.size(); i++) { +#if VERSION_MAJOR < 4 + r.push_back(_voxel_surfaces[i].get_ref_ptr()); +#else + r.push_back(_voxel_surfaces[i]); +#endif + } + return r; +} +void Planet::set_voxel_surfaces(const Vector &voxel_surfaces) { + _voxel_surfaces.clear(); + for (int i = 0; i < voxel_surfaces.size(); i++) { + Ref voxel_surface = Ref(voxel_surfaces[i]); + + _voxel_surfaces.push_back(voxel_surface); + } +} + +#endif + +void Planet::setup() { if (has_method("_setup")) { call("_setup"); } @@ -111,17 +235,14 @@ void Planet::setup() { void Planet::setup_library(Ref library) { ERR_FAIL_COND(!library.is_valid()); - if (!_data.is_valid()) - return; - if (has_method("_setup_library")) { call("_setup_library", library); } } void Planet::_setup_library(Ref library) { - for (int i = 0; i < _data->get_voxel_surface_count(); ++i) { - Ref s = _data->get_voxel_surface(i); + for (int i = 0; i < get_voxel_surface_count(); ++i) { + Ref s = get_voxel_surface(i); if (s.is_valid()) { library->add_voxel_surface(s); @@ -179,6 +300,7 @@ Ref Planet::generate_map() { } Planet::Planet() { + _id = 0; _current_seed = 0; } Planet::~Planet() { @@ -188,7 +310,17 @@ Planet::~Planet() { _biomes.clear(); _dungeons.clear(); - _data.unref(); + +#ifdef FASTNOISE_PRESENT + _humidity_noise_params.unref(); + _temperature_noise_params.unref(); +#endif + +#ifdef VOXELMAN_PRESENT + _environment_datas.clear(); + _voxel_surfaces.clear(); + _liquid_voxel_surfaces.clear(); +#endif } void Planet::_bind_methods() { @@ -213,6 +345,10 @@ void Planet::_bind_methods() { ClassDB::bind_method(D_METHOD("setup_library", "library"), &Planet::setup_library); + ClassDB::bind_method(D_METHOD("get_id"), &Planet::get_id); + ClassDB::bind_method(D_METHOD("set_id", "value"), &Planet::set_id); + ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); + ClassDB::bind_method(D_METHOD("get_current_seed"), &Planet::get_current_seed); ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &Planet::set_current_seed); ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed"); @@ -221,16 +357,22 @@ void Planet::_bind_methods() { ClassDB::bind_method(D_METHOD("set_level_range", "value"), &Planet::set_level_range); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "level_range"), "set_level_range", "get_level_range"); +#ifdef FASTNOISE_PRESENT + ClassDB::bind_method(D_METHOD("get_humidity_noise_params"), &Planet::get_humidity_noise_params); + ClassDB::bind_method(D_METHOD("set_humidity_noise_params", "value"), &Planet::set_humidity_noise_params); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "humidity_noise_params", PROPERTY_HINT_RESOURCE_TYPE, "FastnoiseNoiseParams"), "set_humidity_noise_params", "get_humidity_noise_params"); + + ClassDB::bind_method(D_METHOD("get_temperature_noise_params"), &Planet::get_temperature_noise_params); + ClassDB::bind_method(D_METHOD("set_temperature_noise_params", "value"), &Planet::set_temperature_noise_params); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "temperature_noise_params", PROPERTY_HINT_RESOURCE_TYPE, "FastnoiseNoiseParams"), "set_temperature_noise_params", "get_temperature_noise_params"); +#endif + #ifdef VOXELMAN_PRESENT ClassDB::bind_method(D_METHOD("get_environment"), &Planet::get_environment); ClassDB::bind_method(D_METHOD("set_environment", "value"), &Planet::set_environment); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "EnvironmentData"), "set_environment", "get_environment"); #endif - ClassDB::bind_method(D_METHOD("get_data"), &Planet::get_data); - ClassDB::bind_method(D_METHOD("set_data", "value"), &Planet::set_data); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "PlanetData", 0), "set_data", "get_data"); - //biomes ClassDB::bind_method(D_METHOD("get_biome", "index"), &Planet::get_biome); ClassDB::bind_method(D_METHOD("set_biome", "index", "data"), &Planet::set_biome); @@ -238,6 +380,10 @@ void Planet::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_biome", "index"), &Planet::remove_biome); ClassDB::bind_method(D_METHOD("get_biome_count"), &Planet::get_biome_count); + ClassDB::bind_method(D_METHOD("get_biomes"), &Planet::get_biomes); + ClassDB::bind_method(D_METHOD("set_biomes", "biomes"), &Planet::set_biomes); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "biomes", PROPERTY_HINT_NONE, "17/17:Biome", PROPERTY_USAGE_DEFAULT, "Biome"), "set_biomes", "get_biomes"); + //Dungeons ClassDB::bind_method(D_METHOD("get_dungeon", "index"), &Planet::get_dungeon); ClassDB::bind_method(D_METHOD("set_dungeon", "index", "data"), &Planet::set_dungeon); @@ -245,6 +391,30 @@ void Planet::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_dungeon", "index"), &Planet::remove_dungeon); ClassDB::bind_method(D_METHOD("get_dungeon_count"), &Planet::get_dungeon_count); +#ifdef VOXELMAN_PRESENT + //Environments + ClassDB::bind_method(D_METHOD("get_environment_data", "index"), &Planet::get_environment_data); + ClassDB::bind_method(D_METHOD("set_environment_data", "index", "data"), &Planet::set_environment_data); + ClassDB::bind_method(D_METHOD("add_environment_data", "environment_data"), &Planet::add_environment_data); + ClassDB::bind_method(D_METHOD("remove_environment_data", "index"), &Planet::remove_environment_data); + ClassDB::bind_method(D_METHOD("get_environment_data_count"), &Planet::get_environment_data_count); + + ClassDB::bind_method(D_METHOD("get_environment_datas"), &Planet::get_environment_datas); + ClassDB::bind_method(D_METHOD("set_environment_datas", "environment_datas"), &Planet::set_environment_datas); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "environment_datas", PROPERTY_HINT_NONE, "17/17:EnvironmentData", PROPERTY_USAGE_DEFAULT, "EnvironmentData"), "set_environment_datas", "get_environment_datas"); + + //Surfaces + ClassDB::bind_method(D_METHOD("get_voxel_surface", "index"), &Planet::get_voxel_surface); + ClassDB::bind_method(D_METHOD("set_voxel_surface", "index", "data"), &Planet::set_voxel_surface); + ClassDB::bind_method(D_METHOD("add_voxel_surface", "voxel_surface"), &Planet::add_voxel_surface); + ClassDB::bind_method(D_METHOD("remove_voxel_surface", "index"), &Planet::remove_voxel_surface); + ClassDB::bind_method(D_METHOD("get_voxel_surface_count"), &Planet::get_voxel_surface_count); + + ClassDB::bind_method(D_METHOD("get_voxel_surfaces"), &Planet::get_voxel_surfaces); + ClassDB::bind_method(D_METHOD("set_voxel_surfaces", "voxel_surfaces"), &Planet::set_voxel_surfaces); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurface", PROPERTY_USAGE_DEFAULT, "VoxelSurface"), "set_voxel_surfaces", "get_voxel_surfaces"); +#endif + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "_generate_map")); ClassDB::bind_method(D_METHOD("generate_map"), &Planet::generate_map); diff --git a/main/planet.h b/main/planet.h index 9706a7e..77004f9 100644 --- a/main/planet.h +++ b/main/planet.h @@ -30,7 +30,9 @@ SOFTWARE. #include "biome.h" #include "dungeon.h" -#include "../data/planet_data.h" +#ifdef FASTNOISE_PRESENT +#include "../../fastnoise/fastnoise_noise_params.h" +#endif #ifdef VOXELMAN_PRESENT #include "../../voxelman/library/voxel_surface.h" @@ -39,27 +41,33 @@ SOFTWARE. #include "../../voxelman/world/voxel_chunk.h" #endif -class PlanetData; - class Planet : public Resource { GDCLASS(Planet, Resource); public: + int get_id() const; + void set_id(const int value); + int get_current_seed(); void set_current_seed(int value); Vector2 get_level_range(); void set_level_range(Vector2 value); +#ifdef FASTNOISE_PRESENT + Ref get_humidity_noise_params(); + void set_humidity_noise_params(Ref value); + + Ref get_temperature_noise_params(); + void set_temperature_noise_params(Ref value); +#endif + #ifdef VOXELMAN_PRESENT //Environment Ref get_environment(); void set_environment(Ref value); #endif - Ref get_data(); - void set_data(Ref value); - //Biomes Ref get_biome(const int index) const; void set_biome(const int index, const Ref biome); @@ -67,6 +75,9 @@ public: void remove_biome(const int index); int get_biome_count() const; + Vector get_biomes(); + void set_biomes(const Vector &biome_datas); + //Dungeons Ref get_dungeon(const int index) const; void set_dungeon(const int index, const Ref dungeon); @@ -74,6 +85,29 @@ public: void remove_dungeon(const int index); int get_dungeon_count() const; +#ifdef VOXELMAN_PRESENT + //Environments + Ref get_environment_data(const int index) const; + void set_environment_data(const int index, const Ref environment_data); + void add_environment_data(const Ref environment_data); + void remove_environment_data(const int index); + int get_environment_data_count() const; + + Vector get_environment_datas(); + void set_environment_datas(const Vector &environment_datas); + + //Surfaces + Ref get_voxel_surface(const int index) const; + void set_voxel_surface(const int index, const Ref voxel_surface); + void add_voxel_surface(const Ref voxel_surface); + void remove_voxel_surface(const int index); + int get_voxel_surface_count() const; + + Vector get_voxel_surfaces(); + void set_voxel_surfaces(const Vector &voxel_surfaces); + +#endif + void setup(); #ifdef VOXELMAN_PRESENT @@ -95,6 +129,8 @@ protected: static void _bind_methods(); private: + int _id; + int _current_seed; Vector2 _level_range; @@ -102,9 +138,19 @@ private: Ref _environment; #endif - Ref _data; Vector > _biomes; Vector > _dungeons; + +#ifdef FASTNOISE_PRESENT + Ref _humidity_noise_params; + Ref _temperature_noise_params; +#endif + +#ifdef VOXELMAN_PRESENT + Vector > _environment_datas; + Vector > _voxel_surfaces; + Vector > _liquid_voxel_surfaces; +#endif }; #endif diff --git a/register_types.cpp b/register_types.cpp index 26906f1..cb6d023 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -26,7 +26,6 @@ SOFTWARE. #include "data/dungeon_corridor_data.h" #include "data/dungeon_data.h" #include "data/dungeon_room_data.h" -#include "data/planet_data.h" #include "data/world_generator_prop_data.h" #include "main/biome.h" @@ -42,7 +41,6 @@ void register_world_generator_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/world_generator.cpp b/world_generator.cpp index f3b28f6..fbdb63f 100644 --- a/world_generator.cpp +++ b/world_generator.cpp @@ -24,17 +24,17 @@ SOFTWARE. #include "core/version.h" -Ref WorldGenerator::get_planet_data(const int index) const { - ERR_FAIL_INDEX_V(index, _planet_datas.size(), Ref()); +Ref WorldGenerator::get_planet_data(const int index) const { + ERR_FAIL_INDEX_V(index, _planet_datas.size(), Ref()); return _planet_datas.get(index); } -void WorldGenerator::set_planet_data(const int index, const Ref planet_data) { +void WorldGenerator::set_planet_data(const int index, const Ref planet_data) { ERR_FAIL_INDEX(index, _planet_datas.size()); _planet_datas.set(index, planet_data); } -void WorldGenerator::add_planet_data(const Ref planet_data) { +void WorldGenerator::add_planet_data(const Ref planet_data) { _planet_datas.push_back(planet_data); } void WorldGenerator::remove_planet_data(const int index) { @@ -61,7 +61,7 @@ Vector WorldGenerator::get_planet_datas() { void WorldGenerator::set_planet_datas(const Vector &planet_datas) { _planet_datas.clear(); for (int i = 0; i < planet_datas.size(); i++) { - Ref planet_data = Ref(planet_datas[i]); + Ref planet_data = Ref(planet_datas[i]); _planet_datas.push_back(planet_data); } @@ -95,5 +95,5 @@ void WorldGenerator::_bind_methods() { ClassDB::bind_method(D_METHOD("get_planet_datas"), &WorldGenerator::get_planet_datas); ClassDB::bind_method(D_METHOD("set_planet_datas", "planet_datas"), &WorldGenerator::set_planet_datas); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "planet_datas", PROPERTY_HINT_NONE, "17/17:PlanetData", PROPERTY_USAGE_DEFAULT, "PlanetData"), "set_planet_datas", "get_planet_datas"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "planet_datas", PROPERTY_HINT_NONE, "17/17:Planet", PROPERTY_USAGE_DEFAULT, "Planet"), "set_planet_datas", "get_planet_datas"); } diff --git a/world_generator.h b/world_generator.h index 0fe1db1..f2b40d2 100644 --- a/world_generator.h +++ b/world_generator.h @@ -26,17 +26,15 @@ SOFTWARE. #include "core/resource.h" #include "core/vector.h" -#include "data/planet_data.h" - #include "main/planet.h" class WorldGenerator : public Resource { GDCLASS(WorldGenerator, Resource); public: - Ref get_planet_data(const int index) const; - void set_planet_data(const int index, const Ref planet_data); - void add_planet_data(const Ref planet_data); + Ref get_planet_data(const int index) const; + void set_planet_data(const int index, const Ref planet_data); + void add_planet_data(const Ref planet_data); void remove_planet_data(const int index); int get_planet_data_count() const; @@ -53,7 +51,7 @@ protected: static void _bind_methods(); private: - Vector > _planet_datas; + Vector > _planet_datas; }; #endif