Merged PlanetData into Planet.

This commit is contained in:
Relintai 2020-07-21 17:28:28 +02:00
parent 59dde526b9
commit 733f754783
9 changed files with 253 additions and 459 deletions

1
SCsub
View File

@ -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",

View File

@ -10,7 +10,6 @@ def get_doc_classes():
"DungeonCorridorData",
"DungeonData",
"DungeonRoomData",
"PlanetData",
"WorldGeneratorPropData",
"BiomeData",

View File

@ -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<Planet> PlanetData::get_planet() {
return _planet;
}
void PlanetData::set_planet(const Ref<Planet> &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<FastnoiseNoiseParams> PlanetData::get_humidity_noise_params() {
return _humidity_noise_params;
}
void PlanetData::set_humidity_noise_params(Ref<FastnoiseNoiseParams> value) {
_humidity_noise_params = value;
}
Ref<FastnoiseNoiseParams> PlanetData::get_temperature_noise_params() {
return _temperature_noise_params;
}
void PlanetData::set_temperature_noise_params(Ref<FastnoiseNoiseParams> value) {
_temperature_noise_params = value;
}
#endif
//Biomes
Ref<BiomeData> PlanetData::get_biome_data(const int index) const {
ERR_FAIL_INDEX_V(index, _biome_datas.size(), Ref<BiomeData>());
return _biome_datas.get(index);
}
void PlanetData::set_biome_data(const int index, const Ref<BiomeData> biome_data) {
ERR_FAIL_INDEX(index, _biome_datas.size());
_biome_datas.set(index, biome_data);
}
void PlanetData::add_biome_data(const Ref<BiomeData> 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<Variant> PlanetData::get_biome_datas() {
Vector<Variant> 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<Variant> &biome_datas) {
_biome_datas.clear();
for (int i = 0; i < biome_datas.size(); i++) {
Ref<BiomeData> biome_data = Ref<BiomeData>(biome_datas[i]);
_biome_datas.push_back(biome_data);
}
}
#ifdef VOXELMAN_PRESENT
//Environments
Ref<EnvironmentData> PlanetData::get_environment_data(const int index) const {
ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref<EnvironmentData>());
return _environment_datas.get(index);
}
void PlanetData::set_environment_data(const int index, const Ref<EnvironmentData> environment_data) {
ERR_FAIL_INDEX(index, _environment_datas.size());
_environment_datas.set(index, environment_data);
}
void PlanetData::add_environment_data(const Ref<EnvironmentData> 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<Variant> PlanetData::get_environment_datas() {
Vector<Variant> 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<Variant> &environment_datas) {
_environment_datas.clear();
for (int i = 0; i < environment_datas.size(); i++) {
Ref<EnvironmentData> environment_data = Ref<EnvironmentData>(environment_datas[i]);
_environment_datas.push_back(environment_data);
}
}
//// Surfaces ////
Ref<VoxelSurface> PlanetData::get_voxel_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>());
return _voxel_surfaces.get(index);
}
void PlanetData::set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.set(index, voxel_surface);
}
void PlanetData::add_voxel_surface(const Ref<VoxelSurface> 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<Variant> PlanetData::get_voxel_surfaces() {
Vector<Variant> 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<Variant> &voxel_surfaces) {
_voxel_surfaces.clear();
for (int i = 0; i < voxel_surfaces.size(); i++) {
Ref<EnvironmentData> voxel_surface = Ref<EnvironmentData>(voxel_surfaces[i]);
_voxel_surfaces.push_back(voxel_surface);
}
}
#endif
Ref<Planet> PlanetData::instance() {
Ref<Planet> planet;
if (!_planet.is_valid()) {
planet.instance();
} else {
planet = _planet->duplicate();
}
planet->set_data(Ref<PlanetData>(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);
}

View File

@ -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<Planet> get_planet();
void set_planet(const Ref<Planet> &planet);
Vector2 get_level_range();
void set_level_range(Vector2 value);
#ifdef FASTNOISE_PRESENT
Ref<FastnoiseNoiseParams> get_humidity_noise_params();
void set_humidity_noise_params(Ref<FastnoiseNoiseParams> value);
Ref<FastnoiseNoiseParams> get_temperature_noise_params();
void set_temperature_noise_params(Ref<FastnoiseNoiseParams> value);
#endif
//Biomes
Ref<BiomeData> get_biome_data(const int index) const;
void set_biome_data(const int index, const Ref<BiomeData> biome_data);
void add_biome_data(const Ref<BiomeData> biome_data);
void remove_biome_data(const int index);
int get_biome_data_count() const;
Vector<Variant> get_biome_datas();
void set_biome_datas(const Vector<Variant> &biome_datas);
#ifdef VOXELMAN_PRESENT
//Environments
Ref<EnvironmentData> get_environment_data(const int index) const;
void set_environment_data(const int index, const Ref<EnvironmentData> environment_data);
void add_environment_data(const Ref<EnvironmentData> environment_data);
void remove_environment_data(const int index);
int get_environment_data_count() const;
Vector<Variant> get_environment_datas();
void set_environment_datas(const Vector<Variant> &environment_datas);
//Surfaces
Ref<VoxelSurface> get_voxel_surface(const int index) const;
void set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void remove_voxel_surface(const int index);
int get_voxel_surface_count() const;
Vector<Variant> get_voxel_surfaces();
void set_voxel_surfaces(const Vector<Variant> &voxel_surfaces);
#endif
Ref<Planet> instance();
PlanetData();
~PlanetData();
protected:
static void _bind_methods();
private:
int _id;
Ref<Planet> _planet;
Vector2 _level_range;
#ifdef FASTNOISE_PRESENT
Ref<FastnoiseNoiseParams> _humidity_noise_params;
Ref<FastnoiseNoiseParams> _temperature_noise_params;
#endif
Vector<Ref<BiomeData> > _biome_datas;
#ifdef VOXELMAN_PRESENT
Vector<Ref<EnvironmentData> > _environment_datas;
Vector<Ref<VoxelSurface> > _voxel_surfaces;
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
#endif
};
#endif

View File

@ -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<FastnoiseNoiseParams> Planet::get_humidity_noise_params() {
return _humidity_noise_params;
}
void Planet::set_humidity_noise_params(Ref<FastnoiseNoiseParams> value) {
_humidity_noise_params = value;
}
Ref<FastnoiseNoiseParams> Planet::get_temperature_noise_params() {
return _temperature_noise_params;
}
void Planet::set_temperature_noise_params(Ref<FastnoiseNoiseParams> value) {
_temperature_noise_params = value;
}
#endif
#ifdef VOXELMAN_PRESENT
Ref<EnvironmentData> Planet::get_environment() {
return _environment;
@ -45,13 +70,6 @@ void Planet::set_environment(Ref<EnvironmentData> value) {
}
#endif
Ref<PlanetData> Planet::get_data() {
return _data;
}
void Planet::set_data(Ref<PlanetData> value) {
_data = value;
}
Ref<Biome> Planet::get_biome(const int index) const {
ERR_FAIL_INDEX_V(index, _biomes.size(), Ref<Biome>());
@ -75,6 +93,26 @@ int Planet::get_biome_count() const {
return _biomes.size();
}
Vector<Variant> Planet::get_biomes() {
Vector<Variant> 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<Variant> &biomes) {
_biomes.clear();
for (int i = 0; i < biomes.size(); i++) {
Ref<Biome> biome_data = Ref<Biome>(biomes[i]);
_biomes.push_back(biome_data);
}
}
//// Dungeons ////
Ref<Dungeon> Planet::get_dungeon(const int index) const {
ERR_FAIL_INDEX_V(index, _dungeons.size(), Ref<Dungeon>());
@ -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<EnvironmentData> Planet::get_environment_data(const int index) const {
ERR_FAIL_INDEX_V(index, _environment_datas.size(), Ref<EnvironmentData>());
return _environment_datas.get(index);
}
void Planet::set_environment_data(const int index, const Ref<EnvironmentData> environment_data) {
ERR_FAIL_INDEX(index, _environment_datas.size());
_environment_datas.set(index, environment_data);
}
void Planet::add_environment_data(const Ref<EnvironmentData> 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<Variant> Planet::get_environment_datas() {
Vector<Variant> 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<Variant> &environment_datas) {
_environment_datas.clear();
for (int i = 0; i < environment_datas.size(); i++) {
Ref<EnvironmentData> environment_data = Ref<EnvironmentData>(environment_datas[i]);
_environment_datas.push_back(environment_data);
}
}
//// Surfaces ////
Ref<VoxelSurface> Planet::get_voxel_surface(const int index) const {
ERR_FAIL_INDEX_V(index, _voxel_surfaces.size(), Ref<VoxelSurface>());
return _voxel_surfaces.get(index);
}
void Planet::set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface) {
ERR_FAIL_INDEX(index, _voxel_surfaces.size());
_voxel_surfaces.set(index, voxel_surface);
}
void Planet::add_voxel_surface(const Ref<VoxelSurface> 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<Variant> Planet::get_voxel_surfaces() {
Vector<Variant> 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<Variant> &voxel_surfaces) {
_voxel_surfaces.clear();
for (int i = 0; i < voxel_surfaces.size(); i++) {
Ref<EnvironmentData> voxel_surface = Ref<EnvironmentData>(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<VoxelmanLibrary> 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<VoxelmanLibrary> library) {
for (int i = 0; i < _data->get_voxel_surface_count(); ++i) {
Ref<VoxelSurface> s = _data->get_voxel_surface(i);
for (int i = 0; i < get_voxel_surface_count(); ++i) {
Ref<VoxelSurface> s = get_voxel_surface(i);
if (s.is_valid()) {
library->add_voxel_surface(s);
@ -179,6 +300,7 @@ Ref<Image> 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);

View File

@ -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<FastnoiseNoiseParams> get_humidity_noise_params();
void set_humidity_noise_params(Ref<FastnoiseNoiseParams> value);
Ref<FastnoiseNoiseParams> get_temperature_noise_params();
void set_temperature_noise_params(Ref<FastnoiseNoiseParams> value);
#endif
#ifdef VOXELMAN_PRESENT
//Environment
Ref<EnvironmentData> get_environment();
void set_environment(Ref<EnvironmentData> value);
#endif
Ref<PlanetData> get_data();
void set_data(Ref<PlanetData> value);
//Biomes
Ref<Biome> get_biome(const int index) const;
void set_biome(const int index, const Ref<Biome> biome);
@ -67,6 +75,9 @@ public:
void remove_biome(const int index);
int get_biome_count() const;
Vector<Variant> get_biomes();
void set_biomes(const Vector<Variant> &biome_datas);
//Dungeons
Ref<Dungeon> get_dungeon(const int index) const;
void set_dungeon(const int index, const Ref<Dungeon> dungeon);
@ -74,6 +85,29 @@ public:
void remove_dungeon(const int index);
int get_dungeon_count() const;
#ifdef VOXELMAN_PRESENT
//Environments
Ref<EnvironmentData> get_environment_data(const int index) const;
void set_environment_data(const int index, const Ref<EnvironmentData> environment_data);
void add_environment_data(const Ref<EnvironmentData> environment_data);
void remove_environment_data(const int index);
int get_environment_data_count() const;
Vector<Variant> get_environment_datas();
void set_environment_datas(const Vector<Variant> &environment_datas);
//Surfaces
Ref<VoxelSurface> get_voxel_surface(const int index) const;
void set_voxel_surface(const int index, const Ref<VoxelSurface> voxel_surface);
void add_voxel_surface(const Ref<VoxelSurface> voxel_surface);
void remove_voxel_surface(const int index);
int get_voxel_surface_count() const;
Vector<Variant> get_voxel_surfaces();
void set_voxel_surfaces(const Vector<Variant> &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<EnvironmentData> _environment;
#endif
Ref<PlanetData> _data;
Vector<Ref<Biome> > _biomes;
Vector<Ref<Dungeon> > _dungeons;
#ifdef FASTNOISE_PRESENT
Ref<FastnoiseNoiseParams> _humidity_noise_params;
Ref<FastnoiseNoiseParams> _temperature_noise_params;
#endif
#ifdef VOXELMAN_PRESENT
Vector<Ref<EnvironmentData> > _environment_datas;
Vector<Ref<VoxelSurface> > _voxel_surfaces;
Vector<Ref<VoxelSurface> > _liquid_voxel_surfaces;
#endif
};
#endif

View File

@ -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<DungeonCorridorData>();
ClassDB::register_class<DungeonData>();
ClassDB::register_class<BiomeData>();
ClassDB::register_class<PlanetData>();
ClassDB::register_class<WorldGeneratorPropData>();
ClassDB::register_class<DungeonRoom>();

View File

@ -24,17 +24,17 @@ SOFTWARE.
#include "core/version.h"
Ref<PlanetData> WorldGenerator::get_planet_data(const int index) const {
ERR_FAIL_INDEX_V(index, _planet_datas.size(), Ref<PlanetData>());
Ref<Planet> WorldGenerator::get_planet_data(const int index) const {
ERR_FAIL_INDEX_V(index, _planet_datas.size(), Ref<Planet>());
return _planet_datas.get(index);
}
void WorldGenerator::set_planet_data(const int index, const Ref<PlanetData> planet_data) {
void WorldGenerator::set_planet_data(const int index, const Ref<Planet> planet_data) {
ERR_FAIL_INDEX(index, _planet_datas.size());
_planet_datas.set(index, planet_data);
}
void WorldGenerator::add_planet_data(const Ref<PlanetData> planet_data) {
void WorldGenerator::add_planet_data(const Ref<Planet> planet_data) {
_planet_datas.push_back(planet_data);
}
void WorldGenerator::remove_planet_data(const int index) {
@ -61,7 +61,7 @@ Vector<Variant> WorldGenerator::get_planet_datas() {
void WorldGenerator::set_planet_datas(const Vector<Variant> &planet_datas) {
_planet_datas.clear();
for (int i = 0; i < planet_datas.size(); i++) {
Ref<PlanetData> planet_data = Ref<PlanetData>(planet_datas[i]);
Ref<Planet> planet_data = Ref<Planet>(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");
}

View File

@ -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<PlanetData> get_planet_data(const int index) const;
void set_planet_data(const int index, const Ref<PlanetData> planet_data);
void add_planet_data(const Ref<PlanetData> planet_data);
Ref<Planet> get_planet_data(const int index) const;
void set_planet_data(const int index, const Ref<Planet> planet_data);
void add_planet_data(const Ref<Planet> 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<Ref<PlanetData> > _planet_datas;
Vector<Ref<Planet> > _planet_datas;
};
#endif