Some settings in world will now get distributed to chunks. is_build_threaded has been moved from coxel chunk default to voxel chunk. ALso fixed a few crashes.

This commit is contained in:
Relintai 2020-04-18 02:15:01 +02:00
parent 7d20bd10d8
commit 4a2321b161
7 changed files with 59 additions and 19 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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<VoxelChunkDefault> 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<VoxelChunk> chunk) {
Ref<VoxelChunkDefault> c = chunk;
if (c.is_valid()) {
c->set_build_flags(get_build_flags());
c->set_build_flags(_build_flags);
}
}

View File

@ -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");

View File

@ -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;

View File

@ -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<VoxelChunk> 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<VoxelmanLibrary> VoxelWorld::get_library() {
}
void VoxelWorld::set_library(const Ref<VoxelmanLibrary> &library) {
_library = library;
for (int i = 0; i < get_chunk_count(); ++i) {
Ref<VoxelChunk> c = get_chunk_index(i);
if (!c.is_valid())
continue;
c->set_library(_library);
}
}
Ref<VoxelmanLevelGenerator> 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<VoxelChunk> c = get_chunk_index(i);
if (!c.is_valid())
continue;
c->set_voxel_scale(_voxel_scale);
}
}
int VoxelWorld::get_chunk_spawn_range() const {

View File

@ -87,7 +87,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
if (!spatial_editor || !_world)
if (!spatial_editor || !_world || !_world->is_inside_world())
return false;
Camera *camera = p_camera;