diff --git a/world/default/voxel_chunk_default.cpp b/world/default/voxel_chunk_default.cpp index 3bfd197..81fcfa4 100644 --- a/world/default/voxel_chunk_default.cpp +++ b/world/default/voxel_chunk_default.cpp @@ -46,13 +46,6 @@ typedef class StandardMaterial3D SpatialMaterial; const String VoxelChunkDefault::BINDING_STRING_ACTIVE_BUILD_PHASE_TYPE = "Normal,Process,Physics Process"; const String VoxelChunkDefault::BINDING_STRING_BUILD_FLAGS = "Use Isolevel,Use Lighting,Use AO,Use RAO,Generate AO,Generate RAO,Bake Lights,Create Collider,Create Lods"; -_FORCE_INLINE_ bool VoxelChunkDefault::get_is_build_threaded() const { - return _is_build_threaded; -} -_FORCE_INLINE_ void VoxelChunkDefault::set_is_build_threaded(const bool value) { - _is_build_threaded = value; -} - _FORCE_INLINE_ int VoxelChunkDefault::get_build_flags() const { return _build_flags; } @@ -602,7 +595,9 @@ void VoxelChunkDefault::create_colliders(const int mesh_index, const int layer_m PhysicsServer::get_singleton()->body_add_shape(body_rid, shape_rid); PhysicsServer::get_singleton()->body_set_state(body_rid, PhysicsServer::BODY_STATE_TRANSFORM, get_transform()); - PhysicsServer::get_singleton()->body_set_space(body_rid, get_voxel_world()->get_world()->get_space()); + + if (get_voxel_world()->is_inside_world()) + PhysicsServer::get_singleton()->body_set_space(body_rid, get_voxel_world()->get_world()->get_space()); m[MESH_TYPE_INDEX_BODY] = body_rid; m[MESH_TYPE_INDEX_SHAPE] = shape_rid; @@ -997,7 +992,7 @@ void VoxelChunkDefault::free_chunk() { VoxelChunkDefault::VoxelChunkDefault() { _lights_dirty = false; _is_generating = false; - _is_build_threaded = false; + _abort_build = false; _dirty = false; _state = VOXEL_CHUNK_STATE_OK; @@ -1361,10 +1356,6 @@ void VoxelChunkDefault::wait_and_finish_thread() { } void VoxelChunkDefault::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_is_build_threaded"), &VoxelChunkDefault::get_is_build_threaded); - ClassDB::bind_method(D_METHOD("set_is_build_threaded", "value"), &VoxelChunkDefault::set_is_build_threaded); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_build_threaded"), "set_is_build_threaded", "get_is_build_threaded"); - ClassDB::bind_method(D_METHOD("get_build_flags"), &VoxelChunkDefault::get_build_flags); ClassDB::bind_method(D_METHOD("set_build_flags", "value"), &VoxelChunkDefault::set_build_flags); ADD_PROPERTY(PropertyInfo(Variant::INT, "build_flags", PROPERTY_HINT_FLAGS, BINDING_STRING_BUILD_FLAGS), "set_build_flags", "get_build_flags"); diff --git a/world/default/voxel_chunk_default.h b/world/default/voxel_chunk_default.h index 3bd50db..615eae1 100644 --- a/world/default/voxel_chunk_default.h +++ b/world/default/voxel_chunk_default.h @@ -135,9 +135,6 @@ public: }; public: - bool get_is_build_threaded() const; - void set_is_build_threaded(const bool value); - int get_build_flags() const; void set_build_flags(const int flags); @@ -266,7 +263,6 @@ protected: int _build_flags; - bool _is_build_threaded; bool _abort_build; int _current_build_phase; diff --git a/world/default/voxel_world_default.cpp b/world/default/voxel_world_default.cpp index e06f005..8d6c241 100644 --- a/world/default/voxel_world_default.cpp +++ b/world/default/voxel_world_default.cpp @@ -29,6 +29,15 @@ _FORCE_INLINE_ int VoxelWorldDefault::get_build_flags() const { } _FORCE_INLINE_ void VoxelWorldDefault::set_build_flags(const int flags) { _build_flags = flags; + + for (int i = 0; i < get_chunk_count(); ++i) { + Ref c = get_chunk_index(i); + + if (!c.is_valid()) + continue; + + c->set_build_flags(_build_flags); + } } float VoxelWorldDefault::get_lod_update_interval() const { @@ -95,7 +104,7 @@ void VoxelWorldDefault::_chunk_added(Ref chunk) { Ref c = chunk; if (c.is_valid()) { - c->set_build_flags(get_build_flags()); + c->set_build_flags(_build_flags); } } diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 541a60c..9838122 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -42,6 +42,13 @@ typedef PackedColorArray PoolColorArray; typedef PackedInt32Array PoolIntArray; #endif +_FORCE_INLINE_ bool VoxelChunk::get_is_build_threaded() const { + return _is_build_threaded; +} +_FORCE_INLINE_ void VoxelChunk::set_is_build_threaded(const bool value) { + _is_build_threaded = value; +} + _FORCE_INLINE_ bool VoxelChunk::get_process() const { return _is_processing; } @@ -705,6 +712,7 @@ void VoxelChunk::set_transform(const Transform &transform) { } VoxelChunk::VoxelChunk() { + _is_build_threaded = false; _is_processing = false; _is_phisics_processing = false; @@ -846,6 +854,10 @@ void VoxelChunk::_bind_methods() { ClassDB::bind_method(D_METHOD("get_physics_process"), &VoxelChunk::get_physics_process); ClassDB::bind_method(D_METHOD("set_physics_process", "value"), &VoxelChunk::set_physics_process); + ClassDB::bind_method(D_METHOD("get_is_build_threaded"), &VoxelChunk::get_is_build_threaded); + ClassDB::bind_method(D_METHOD("set_is_build_threaded", "value"), &VoxelChunk::set_is_build_threaded); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_build_threaded"), "set_is_build_threaded", "get_is_build_threaded"); + ClassDB::bind_method(D_METHOD("get_transform"), &VoxelChunk::get_transform); ClassDB::bind_method(D_METHOD("set_transform", "value"), &VoxelChunk::set_transform); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform"); diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 3ffda87..3ac7ef1 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -72,6 +72,9 @@ public: }; public: + bool get_is_build_threaded() const; + void set_is_build_threaded(const bool value); + bool get_process() const; void set_process(const bool value); @@ -213,6 +216,8 @@ protected: */ static void _bind_methods(); + bool _is_build_threaded; + bool _is_processing; bool _is_phisics_processing; diff --git a/world/voxel_world.cpp b/world/voxel_world.cpp index f6e9ffd..f80479c 100644 --- a/world/voxel_world.cpp +++ b/world/voxel_world.cpp @@ -88,6 +88,15 @@ bool VoxelWorld::get_use_threads() const { } void VoxelWorld::set_use_threads(const bool value) { _use_threads = OS::get_singleton()->can_use_threads() ? value : false; + + for (int i = 0; i < get_chunk_count(); ++i) { + Ref c = get_chunk_index(i); + + if (!c.is_valid()) + continue; + + c->set_is_build_threaded(_use_threads); + } } int VoxelWorld::get_max_concurrent_generations() const { @@ -109,6 +118,15 @@ Ref VoxelWorld::get_library() { } void VoxelWorld::set_library(const Ref &library) { _library = library; + + for (int i = 0; i < get_chunk_count(); ++i) { + Ref c = get_chunk_index(i); + + if (!c.is_valid()) + continue; + + c->set_library(_library); + } } Ref VoxelWorld::get_level_generator() const { @@ -123,6 +141,15 @@ float VoxelWorld::get_voxel_scale() const { } void VoxelWorld::set_voxel_scale(const float value) { _voxel_scale = value; + + for (int i = 0; i < get_chunk_count(); ++i) { + Ref c = get_chunk_index(i); + + if (!c.is_valid()) + continue; + + c->set_voxel_scale(_voxel_scale); + } } int VoxelWorld::get_chunk_spawn_range() const { diff --git a/world/voxel_world_editor.cpp b/world/voxel_world_editor.cpp index a0a02ef..9fbf9b8 100644 --- a/world/voxel_world_editor.cpp +++ b/world/voxel_world_editor.cpp @@ -87,7 +87,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Refis_inside_world()) return false; Camera *camera = p_camera;