diff --git a/world/default/terra_world_default.cpp b/world/default/terra_world_default.cpp index 82740f0..244aeca 100644 --- a/world/default/terra_world_default.cpp +++ b/world/default/terra_world_default.cpp @@ -62,6 +62,10 @@ void TerraWorldDefault::set_num_lods(const int value) { } void TerraWorldDefault::update_lods() { + if (!get_active()) { + return; + } + call("_update_lods"); } @@ -191,7 +195,7 @@ Ref TerraWorldDefault::_create_chunk(int x, int z, Ref c s.instance(); s->set_job_type(TerraMesherJobStep::TYPE_NORMAL); tj->add_jobs_step(s); - + s.instance(); s->set_job_type(TerraMesherJobStep::TYPE_NORMAL_LOD); s->set_lod_index(1); @@ -261,6 +265,34 @@ TerraWorldDefault::TerraWorldDefault() { TerraWorldDefault ::~TerraWorldDefault() { } +void TerraWorldDefault::_notification(int p_what) { + TerraWorld::_notification(p_what); + + switch (p_what) { + case NOTIFICATION_ACTIVE_STATE_CHANGED: { + if (!is_inside_tree()) { + return; + } + + bool active = get_active(); + + for (int i = 0; i < chunk_get_count(); ++i) { + Ref chunk = chunk_get_index(i); + + if (chunk.is_valid()) { + chunk->set_visible(active); + } + } + + if (active) { + update_lods(); + } + + break; + } + } +} + /* void TerraWorldDefault::_notification(int p_what) { TerraWorld::_notification(p_what); diff --git a/world/default/terra_world_default.h b/world/default/terra_world_default.h index 79c41dd..f149c10 100644 --- a/world/default/terra_world_default.h +++ b/world/default/terra_world_default.h @@ -52,6 +52,7 @@ public: ~TerraWorldDefault(); protected: + void _notification(int p_what); void _update_lods(); Ref _create_chunk(int x, int z, Ref p_chunk); virtual void _chunk_added(Ref chunk); diff --git a/world/terra_world.cpp b/world/terra_world.cpp index af55621..74a8cb5 100644 --- a/world/terra_world.cpp +++ b/world/terra_world.cpp @@ -43,6 +43,15 @@ SOFTWARE. const String TerraWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level"; +bool TerraWorld::get_active() const { + return _active; +} +void TerraWorld::set_active(const bool value) { + _active = value; + + notification(NOTIFICATION_ACTIVE_STATE_CHANGED); +} + bool TerraWorld::get_editable() const { return _editable; } @@ -371,6 +380,10 @@ Ref TerraWorld::_create_chunk(const int x, const int z, Refset_size(_chunk_size_x, _chunk_size_z, _data_margin_start, _data_margin_end); //chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale)); + if (!get_active()) { + chunk->set_visible(false); + } + chunk_add(chunk, x, z); return chunk; @@ -792,6 +805,7 @@ int TerraWorld::get_channel_index_info(const TerraWorld::ChannelTypeInfo channel } TerraWorld::TerraWorld() { + _active = true; _editable = false; _is_priority_generation = true; @@ -871,7 +885,8 @@ void TerraWorld::_notification(int p_what) { chunk->build(); } } - } break; + break; + } case NOTIFICATION_INTERNAL_PROCESS: { _num_frame_chunk_build_steps = 0; @@ -929,7 +944,8 @@ void TerraWorld::_notification(int p_what) { chunk_generate(chunk); } - } break; + break; + } case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { for (int i = 0; i < _chunks_vector.size(); ++i) { Ref chunk = _chunks_vector[i]; @@ -944,8 +960,8 @@ void TerraWorld::_notification(int p_what) { chunk->generation_physics_process(get_physics_process_delta_time()); } } - - } break; + break; + } case NOTIFICATION_EXIT_TREE: { for (int i = 0; i < _chunks_vector.size(); ++i) { Ref chunk = _chunks_vector[i]; @@ -957,8 +973,8 @@ void TerraWorld::_notification(int p_what) { } } } - - } break; + break; + } case NOTIFICATION_TRANSFORM_CHANGED: { for (int i = 0; i < _chunks_vector.size(); ++i) { Ref chunk = _chunks_vector[i]; @@ -967,14 +983,18 @@ void TerraWorld::_notification(int p_what) { chunk->world_transform_changed(); } } - - } break; + break; + } } } void TerraWorld::_bind_methods() { ADD_SIGNAL(MethodInfo("chunk_mesh_generation_finished", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); + ClassDB::bind_method(D_METHOD("get_active"), &TerraWorld::get_active); + ClassDB::bind_method(D_METHOD("set_active", "value"), &TerraWorld::set_active); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "get_active"); + ClassDB::bind_method(D_METHOD("get_editable"), &TerraWorld::get_editable); ClassDB::bind_method(D_METHOD("set_editable", "value"), &TerraWorld::set_editable); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "get_editable"); @@ -1131,4 +1151,6 @@ void TerraWorld::_bind_methods() { BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE); BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL); BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW); + + BIND_CONSTANT(NOTIFICATION_ACTIVE_STATE_CHANGED); } diff --git a/world/terra_world.h b/world/terra_world.h index ec585e5..a74aa00 100644 --- a/world/terra_world.h +++ b/world/terra_world.h @@ -26,11 +26,11 @@ SOFTWARE. #include "core/version.h" #if VERSION_MAJOR > 3 -#include "core/templates/hash_map.h" #include "core/config/engine.h" +#include "core/templates/hash_map.h" #else -#include "core/hash_map.h" #include "core/engine.h" +#include "core/hash_map.h" #endif #include "../defines.h" @@ -61,9 +61,16 @@ public: CHANNEL_TYPE_INFO_LIQUID_FLOW, }; + enum { + NOTIFICATION_ACTIVE_STATE_CHANGED = 9000, + }; + static const String BINDING_STRING_CHANNEL_TYPE_INFO; public: + bool get_active() const; + void set_active(const bool value); + bool get_editable() const; void set_editable(const bool value); @@ -228,6 +235,7 @@ public: }; private: + bool _active; bool _editable; bool _is_priority_generation; @@ -245,22 +253,22 @@ private: int _chunk_spawn_range; HashMap, IntPosHasher> _chunks; - Vector > _chunks_vector; + Vector> _chunks_vector; - Vector > _world_areas; + Vector> _world_areas; - Vector > _voxel_structures; + Vector> _voxel_structures; NodePath _player_path; Spatial *_player; int _max_concurrent_generations; - Vector > _generation_queue; - Vector > _generating; + Vector> _generation_queue; + Vector> _generating; int _max_frame_chunk_build_steps; int _num_frame_chunk_build_steps; - Vector > _lights; + Vector> _lights; }; _FORCE_INLINE_ bool operator==(const TerraWorld::IntPos &a, const TerraWorld::IntPos &b) {