From 7075da44eb78aab56f51b6c9a7c3760de8392f18 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 10 Nov 2019 22:18:31 +0100 Subject: [PATCH] Bit more work on the bindings. --- library/voxelman_library.cpp | 4 ++++ library/voxelman_library.h | 2 ++ library/voxelman_library_merger.cpp | 18 ++++++++++++++++++ library/voxelman_library_merger.h | 2 ++ library/voxelman_library_simple.cpp | 19 ++++++++++++++++++- library/voxelman_library_simple.h | 2 ++ world_generator/main/biome.cpp | 18 ++++++++++++++++++ world_generator/main/biome.h | 1 + world_generator/main/dungeon.cpp | 18 ++++++++++++++++++ world_generator/main/dungeon.h | 2 ++ world_generator/main/dungeon_room.cpp | 18 ++++++++++++++++++ world_generator/main/dungeon_room.h | 2 ++ world_generator/main/planet.cpp | 17 +++++++++++++++++ world_generator/main/planet.h | 2 ++ 14 files changed, 124 insertions(+), 1 deletion(-) diff --git a/library/voxelman_library.cpp b/library/voxelman_library.cpp index 5309b9e..3ebc646 100644 --- a/library/voxelman_library.cpp +++ b/library/voxelman_library.cpp @@ -32,6 +32,8 @@ void VoxelmanLibrary::set_clutter_material(Ref mat) { Ref VoxelmanLibrary::get_voxel_surface(int index) const { return Ref(); } +void VoxelmanLibrary::add_voxel_surface(Ref value) { +} void VoxelmanLibrary::set_voxel_surface(int index, Ref value) { } void VoxelmanLibrary::remove_surface(int index) { @@ -46,6 +48,8 @@ void VoxelmanLibrary::clear_surfaces() { Ref VoxelmanLibrary::get_liquid_voxel_surface(int index) const { return Ref(); } +void VoxelmanLibrary::add_liquid_voxel_surface(Ref value) { +} void VoxelmanLibrary::set_liquid_voxel_surface(int index, Ref value) { } void VoxelmanLibrary::remove_liquid_surface(int index) { diff --git a/library/voxelman_library.h b/library/voxelman_library.h index e60d6db..23e636f 100644 --- a/library/voxelman_library.h +++ b/library/voxelman_library.h @@ -27,12 +27,14 @@ public: void set_clutter_material(Ref mat); virtual Ref get_voxel_surface(int index) const; + virtual void add_voxel_surface(Ref value); virtual void set_voxel_surface(int index, Ref value); virtual void remove_surface(int index); virtual int get_num_surfaces(); virtual void clear_surfaces(); virtual Ref get_liquid_voxel_surface(int index) const; + virtual void add_liquid_voxel_surface(Ref value); virtual void set_liquid_voxel_surface(int index, Ref value); virtual void remove_liquid_surface(int index); virtual int get_liquid_num_surfaces(); diff --git a/library/voxelman_library_merger.cpp b/library/voxelman_library_merger.cpp index 079c5ce..ee28bf4 100644 --- a/library/voxelman_library_merger.cpp +++ b/library/voxelman_library_merger.cpp @@ -42,6 +42,15 @@ Ref VoxelmanLibraryMerger::get_voxel_surface(int index) const { return _voxel_surfaces[index]; } +void VoxelmanLibraryMerger::add_voxel_surface(Ref value) { + ERR_FAIL_COND(!value.is_valid()); + + value->set_library(Ref(this)); + value->set_id(_voxel_surfaces.size()); + + _voxel_surfaces.push_back(value); +} + void VoxelmanLibraryMerger::set_voxel_surface(int index, Ref value) { ERR_FAIL_COND(index < 0); @@ -121,6 +130,15 @@ Ref VoxelmanLibraryMerger::get_liquid_voxel_surface(int index) con return _liquid_surfaces[index]; } +void VoxelmanLibraryMerger::add_liquid_voxel_surface(Ref value) { + ERR_FAIL_COND(!value.is_valid()); + + value->set_library(Ref(this)); + value->set_id(_liquid_surfaces.size()); + + _liquid_surfaces.push_back(value); +} + void VoxelmanLibraryMerger::set_liquid_voxel_surface(int index, Ref value) { ERR_FAIL_COND(index < 0); diff --git a/library/voxelman_library_merger.h b/library/voxelman_library_merger.h index 9b74730..83b901d 100644 --- a/library/voxelman_library_merger.h +++ b/library/voxelman_library_merger.h @@ -32,6 +32,7 @@ public: void set_margin(const int margin); Ref get_voxel_surface(int index) const; + void add_voxel_surface(Ref value); void set_voxel_surface(int index, Ref value); void remove_surface(int index); int get_num_surfaces(); @@ -41,6 +42,7 @@ public: void set_voxel_surfaces(const Vector &surfaces); Ref get_liquid_voxel_surface(int index) const; + void add_liquid_voxel_surface(Ref value); void set_liquid_voxel_surface(int index, Ref value); void remove_liquid_surface(int index); int get_liquid_num_surfaces(); diff --git a/library/voxelman_library_simple.cpp b/library/voxelman_library_simple.cpp index 81d9a7f..0c189fc 100644 --- a/library/voxelman_library_simple.cpp +++ b/library/voxelman_library_simple.cpp @@ -25,6 +25,15 @@ Ref VoxelmanLibrarySimple::get_voxel_surface(int index) const { return _voxel_surfaces[index]; } +void VoxelmanLibrarySimple::add_voxel_surface(Ref value) { + ERR_FAIL_COND(!value.is_valid()); + + value->set_library(Ref(this)); + value->set_id(_voxel_surfaces.size()); + + _voxel_surfaces.push_back(value); +} + void VoxelmanLibrarySimple::set_voxel_surface(int index, Ref value) { ERR_FAIL_COND(index < 0); @@ -85,6 +94,15 @@ Ref VoxelmanLibrarySimple::get_liquid_voxel_surface(int index) con return _liquid_surfaces[index]; } +void VoxelmanLibrarySimple::add_liquid_voxel_surface(Ref value) { + ERR_FAIL_COND(!value.is_valid()); + + value->set_library(Ref(this)); + value->set_id(_liquid_surfaces.size()); + + _liquid_surfaces.push_back(value); +} + void VoxelmanLibrarySimple::set_liquid_voxel_surface(int index, Ref value) { ERR_FAIL_COND(index < 0); @@ -183,7 +201,6 @@ VoxelmanLibrarySimple::~VoxelmanLibrarySimple() { _liquid_surfaces.clear(); } - void VoxelmanLibrarySimple::_bind_methods() { ClassDB::bind_method(D_METHOD("get_atlas_columns"), &VoxelmanLibrarySimple::get_atlas_columns); ClassDB::bind_method(D_METHOD("set_atlas_columns", "value"), &VoxelmanLibrarySimple::set_atlas_columns); diff --git a/library/voxelman_library_simple.h b/library/voxelman_library_simple.h index 363db8b..f3c7e94 100644 --- a/library/voxelman_library_simple.h +++ b/library/voxelman_library_simple.h @@ -23,6 +23,7 @@ public: void set_atlas_rows(int s); Ref get_voxel_surface(int index) const; + void add_voxel_surface(Ref value); void set_voxel_surface(int index, Ref value); void remove_surface(int index); int get_num_surfaces(); @@ -32,6 +33,7 @@ public: void set_voxel_surfaces(const Vector &surfaces); Ref get_liquid_voxel_surface(int index) const; + void add_liquid_voxel_surface(Ref value); void set_liquid_voxel_surface(int index, Ref value); void remove_liquid_surface(int index); int get_liquid_num_surfaces(); diff --git a/world_generator/main/biome.cpp b/world_generator/main/biome.cpp index 609dc78..63bf258 100644 --- a/world_generator/main/biome.cpp +++ b/world_generator/main/biome.cpp @@ -115,17 +115,33 @@ void Biome::generate_stack_bind(Node *chunk, int x, int z, bool spawn_mobs) { } void Biome::setup() { + if (!_data.is_valid()) + return; + if (has_method("_setup")) { call("_setup"); } } void Biome::setup_library(Ref library) { + if (!_data.is_valid()) + return; + if (has_method("_setup_library")) { call("_setup_library", library); } } +void Biome::_setup_library(Ref library) { + for (int i = 0; i < _data->get_voxel_surface_count(); ++i) { + Ref s = _data->get_voxel_surface(i); + + if (s.is_valid()) { + library->add_voxel_surface(s); + } + } +} + Biome::Biome() { } @@ -144,6 +160,8 @@ void Biome::_bind_methods() { ClassDB::bind_method(D_METHOD("setup"), &Biome::setup); ClassDB::bind_method(D_METHOD("setup_library", "library"), &Biome::setup_library); + ClassDB::bind_method(D_METHOD("_setup_library", "library"), &Biome::_setup_library); + ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &Biome::generate_chunk_bind); ClassDB::bind_method(D_METHOD("generate_stack", "chunk", "x", "z", "spawn_mobs"), &Biome::generate_stack_bind); diff --git a/world_generator/main/biome.h b/world_generator/main/biome.h index 22dc589..713d7aa 100644 --- a/world_generator/main/biome.h +++ b/world_generator/main/biome.h @@ -57,6 +57,7 @@ public: void setup(); void setup_library(Ref library); + void _setup_library(Ref library); Biome(); ~Biome(); diff --git a/world_generator/main/dungeon.cpp b/world_generator/main/dungeon.cpp index 3062ab9..d61754b 100644 --- a/world_generator/main/dungeon.cpp +++ b/world_generator/main/dungeon.cpp @@ -200,17 +200,33 @@ int Dungeon::get_entity_data_count() const { } void Dungeon::setup() { + if (!_data.is_valid()) + return; + if (has_method("_setup")) { call("_setup"); } } void Dungeon::setup_library(Ref library) { + if (!_data.is_valid()) + return; + if (has_method("_setup_library")) { call("_setup_library", library); } } +void Dungeon::_setup_library(Ref library) { + for (int i = 0; i < _data->get_voxel_surface_count(); ++i) { + Ref s = _data->get_voxel_surface(i); + + if (s.is_valid()) { + library->add_voxel_surface(s); + } + } +} + void Dungeon::generate_chunk(VoxelChunk *chunk, bool spawn_mobs) { ERR_FAIL_COND(!ObjectDB::instance_validate(chunk)); @@ -264,6 +280,8 @@ void Dungeon::_bind_methods() { ClassDB::bind_method(D_METHOD("setup"), &Dungeon::setup); ClassDB::bind_method(D_METHOD("setup_library", "library"), &Dungeon::setup_library); + ClassDB::bind_method(D_METHOD("_setup_library", "library"), &Dungeon::_setup_library); + ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &Dungeon::generate_chunk_bind); ClassDB::bind_method(D_METHOD("generate_structure", "structure", "spawn_mobs"), &Dungeon::generate_structure); diff --git a/world_generator/main/dungeon.h b/world_generator/main/dungeon.h index d552f60..7f5ff87 100644 --- a/world_generator/main/dungeon.h +++ b/world_generator/main/dungeon.h @@ -95,6 +95,8 @@ public: void setup(); void setup_library(Ref library); + void _setup_library(Ref library); + void generate_chunk(VoxelChunk *chunk, bool spawn_mobs); void generate_chunk_bind(Node *chunk, bool spawn_mobs); void generate_structure(Ref structure, bool spawn_mobs); diff --git a/world_generator/main/dungeon_room.cpp b/world_generator/main/dungeon_room.cpp index 5edcdd0..e67a4af 100644 --- a/world_generator/main/dungeon_room.cpp +++ b/world_generator/main/dungeon_room.cpp @@ -128,17 +128,33 @@ int DungeonRoom::get_entity_data_count() const { } void DungeonRoom::setup() { + if (!_data.is_valid()) + return; + if (has_method("_setup")) { call("_setup"); } } void DungeonRoom::setup_library(Ref library) { + if (!_data.is_valid()) + return; + if (has_method("_setup_library")) { call("_setup_library", library); } } +void DungeonRoom::_setup_library(Ref library) { + for (int i = 0; i < _data->get_voxel_surface_count(); ++i) { + Ref s = _data->get_voxel_surface(i); + + if (s.is_valid()) { + library->add_voxel_surface(s); + } + } +} + void DungeonRoom::generate_chunk(VoxelChunk *chunk, bool spawn_mobs) { ERR_FAIL_COND(!ObjectDB::instance_validate(chunk)); @@ -182,6 +198,8 @@ void DungeonRoom::_bind_methods() { ClassDB::bind_method(D_METHOD("setup"), &DungeonRoom::setup); ClassDB::bind_method(D_METHOD("setup_library", "library"), &DungeonRoom::setup_library); + ClassDB::bind_method(D_METHOD("_setup_library", "library"), &DungeonRoom::_setup_library); + ClassDB::bind_method(D_METHOD("generate_chunk", "chunk", "spawn_mobs"), &DungeonRoom::generate_chunk_bind); ClassDB::bind_method(D_METHOD("generate_room", "structure", "spawn_mobs"), &DungeonRoom::generate_room); diff --git a/world_generator/main/dungeon_room.h b/world_generator/main/dungeon_room.h index 8ccb2df..18f6046 100644 --- a/world_generator/main/dungeon_room.h +++ b/world_generator/main/dungeon_room.h @@ -72,6 +72,8 @@ public: void setup(); void setup_library(Ref library); + void _setup_library(Ref library); + void generate_chunk(VoxelChunk *chunk, bool spawn_mobs); void generate_chunk_bind(Node *chunk, bool spawn_mobs); void generate_room(Ref structure, bool spawn_mobs); diff --git a/world_generator/main/planet.cpp b/world_generator/main/planet.cpp index ef3a458..1244c37 100644 --- a/world_generator/main/planet.cpp +++ b/world_generator/main/planet.cpp @@ -77,17 +77,33 @@ int Planet::get_dungeon_count() const { } void Planet::setup() { + if (!_data.is_valid()) + return; + if (has_method("_setup")) { call("_setup"); } } void Planet::setup_library(Ref library) { + 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); + + if (s.is_valid()) { + library->add_voxel_surface(s); + } + } +} + void Planet::generate_chunk(VoxelChunk *chunk, bool spawn_mobs) { ERR_FAIL_COND(!ObjectDB::instance_validate(chunk)); @@ -123,6 +139,7 @@ void Planet::_bind_methods() { ClassDB::bind_method(D_METHOD("generate_chunk", "chunk"), &Planet::generate_chunk_bind); ClassDB::bind_method(D_METHOD("setup"), &Planet::setup); ClassDB::bind_method(D_METHOD("setup_library", "library"), &Planet::setup_library); + ClassDB::bind_method(D_METHOD("_setup_library", "library"), &Planet::_setup_library); ClassDB::bind_method(D_METHOD("get_seed"), &Planet::get_seed); ClassDB::bind_method(D_METHOD("set_seed", "value"), &Planet::set_seed); diff --git a/world_generator/main/planet.h b/world_generator/main/planet.h index 6a0053f..e9a86ee 100644 --- a/world_generator/main/planet.h +++ b/world_generator/main/planet.h @@ -48,6 +48,8 @@ public: void setup(); void setup_library(Ref library); + void _setup_library(Ref library); + void generate_chunk(VoxelChunk *chunk, bool spawn_mobs); void generate_chunk_bind(Node *chunk, bool spawn_mobs); Ref generate_map();