From 3f8ca3136e430d45777454a862eddd9fa5d2f251 Mon Sep 17 00:00:00 2001 From: Relintai <relintai@protonmail.com> Date: Fri, 13 Oct 2023 20:41:22 +0200 Subject: [PATCH] Codestyle fixes. --- .../terraman/world/jobs/terrain_prop_job.cpp | 12 ++- modules/terraman/world/terrain_chunk.cpp | 96 ++++++++++++------- modules/terraman/world/terrain_world.cpp | 72 +++++++++----- 3 files changed, 120 insertions(+), 60 deletions(-) diff --git a/modules/terraman/world/jobs/terrain_prop_job.cpp b/modules/terraman/world/jobs/terrain_prop_job.cpp index bcd49dcb1..355aad1f8 100644 --- a/modules/terraman/world/jobs/terrain_prop_job.cpp +++ b/modules/terraman/world/jobs/terrain_prop_job.cpp @@ -223,8 +223,9 @@ void TerrainPropJob::phase_prop() { } void TerrainPropJob::_physics_process(float delta) { - if (_phase == 0) + if (_phase == 0) { phase_physics_process(); + } } void TerrainPropJob::_execute_phase() { @@ -308,8 +309,9 @@ void TerrainPropJob::phase_setup() { for (int i = 0; i < _chunk->mesh_data_resource_get_count(); ++i) { Ref<Texture> tex = _chunk->mesh_data_resource_get_texture(i); - if (!tex.is_valid()) + if (!tex.is_valid()) { continue; + } Rect2 r = cache->additional_texture_get_uv_rect(tex); @@ -384,8 +386,9 @@ void TerrainPropJob::phase_steps() { } //allocate - if (count > 0) + if (count > 0) { chunk->meshes_create(TerrainChunkDefault::MESH_INDEX_PROP, count); + } } else { //we have the meshes, just clear @@ -394,8 +397,9 @@ void TerrainPropJob::phase_steps() { for (int i = 0; i < count; ++i) { mesh_rid = chunk->mesh_rid_get_index(TerrainChunkDefault::MESH_INDEX_PROP, TerrainChunkDefault::MESH_TYPE_INDEX_MESH, i); - if (RS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0) + if (RS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0) { RS::get_singleton()->mesh_remove_surface(mesh_rid, 0); + } } } } diff --git a/modules/terraman/world/terrain_chunk.cpp b/modules/terraman/world/terrain_chunk.cpp index 6d131bd0c..3bc88e7da 100644 --- a/modules/terraman/world/terrain_chunk.cpp +++ b/modules/terraman/world/terrain_chunk.cpp @@ -364,8 +364,9 @@ uint8_t TerrainChunk::get_voxel(const int p_x, const int p_z, const int p_channe uint8_t *ch = _channels.get(p_channel_index); - if (!ch) + if (!ch) { return 0; + } return ch[get_data_index(x, z)]; } @@ -386,8 +387,9 @@ int TerrainChunk::channel_get_count() const { } void TerrainChunk::channel_set_count(const int count) { - if (count == _channels.size()) + if (count == _channels.size()) { return; + } if (_channels.size() >= count) { for (int i = count; i < _channels.size(); ++i) { @@ -419,14 +421,16 @@ bool TerrainChunk::channel_is_allocated(const int channel_index) { void TerrainChunk::channel_ensure_allocated(const int channel_index, const uint8_t default_value) { ERR_FAIL_INDEX(channel_index, _channels.size()); - if (_channels[channel_index] == NULL) + if (_channels[channel_index] == NULL) { channel_allocate(channel_index, default_value); + } } void TerrainChunk::channel_allocate(const int channel_index, const uint8_t default_value) { ERR_FAIL_INDEX(channel_index, _channels.size()); - if (_channels[channel_index] != NULL) + if (_channels[channel_index] != NULL) { return; + } uint32_t size = _data_size_x * _data_size_z; @@ -487,13 +491,15 @@ PoolByteArray TerrainChunk::channel_get_array(const int channel_index) const { uint32_t size = _data_size_x * _data_size_z; - if (channel_index >= _channels.size()) + if (channel_index >= _channels.size()) { return arr; + } uint8_t *ch = _channels.get(channel_index); - if (ch == NULL) + if (ch == NULL) { return arr; + } arr.resize(size); @@ -504,17 +510,20 @@ PoolByteArray TerrainChunk::channel_get_array(const int channel_index) const { return arr; } void TerrainChunk::channel_set_array(const int channel_index, const PoolByteArray &array) { - if (array.size() == 0) + if (array.size() == 0) { return; + } - if (_channels.size() <= channel_index) + if (_channels.size() <= channel_index) { channel_set_count(channel_index + 1); + } uint8_t *ch = _channels.get(channel_index); if (ch == NULL) { - if (_channels[channel_index] != NULL) + if (_channels[channel_index] != NULL) { return; + } ch = memnew_arr(uint8_t, array.size()); _channels.set(channel_index, ch); @@ -530,13 +539,15 @@ PoolByteArray TerrainChunk::channel_get_compressed(const int channel_index) cons #ifdef MODULE_LZ4_ENABLED int size = _data_size_x * _data_size_z; - if (channel_index >= _channels.size()) + if (channel_index >= _channels.size()) { return arr; + } uint8_t *ch = _channels.get(channel_index); - if (ch == NULL) + if (ch == NULL) { return arr; + } int bound = LZ4Compressor::LZ4_compressBound(size); arr.resize(bound); @@ -552,19 +563,22 @@ PoolByteArray TerrainChunk::channel_get_compressed(const int channel_index) cons } void TerrainChunk::channel_set_compressed(const int channel_index, const PoolByteArray &data) { #ifdef MODULE_LZ4_ENABLED - if (data.size() == 0) + if (data.size() == 0) { return; + } int size = _data_size_x * _data_size_z; - if (_channels.size() <= channel_index) + if (_channels.size() <= channel_index) { channel_set_count(channel_index + 1); + } uint8_t *ch = _channels.get(channel_index); if (ch == NULL) { - if (_channels[channel_index] != NULL) + if (_channels[channel_index] != NULL) { return; + } ch = memnew_arr(uint8_t, size); _channels.set(channel_index, ch); @@ -604,13 +618,15 @@ void TerrainChunk::voxel_structure_add(const Ref<TerrainStructure> &structure) { _voxel_structures.push_back(structure); } void TerrainChunk::voxel_structure_remove(const Ref<TerrainStructure> &structure) { - if (!structure.is_valid()) + if (!structure.is_valid()) { return; + } int index = _voxel_structures.find(structure); - if (index != -1) + if (index != -1) { _voxel_structures.remove(index); + } } void TerrainChunk::voxel_structure_remove_index(const int index) { ERR_FAIL_INDEX(index, _voxel_structures.size()); @@ -692,19 +708,23 @@ void TerrainChunk::cancel_build() { } void TerrainChunk::bake_lights() { - if (has_method("_bake_lights")) + if (has_method("_bake_lights")) { call("_bake_lights"); + } } void TerrainChunk::bake_light(Ref<TerrainLight> light) { - if (!light.is_valid()) + if (!light.is_valid()) { return; + } - if (has_method("_bake_lights")) + if (has_method("_bake_lights")) { call("_bake_light", light); + } } void TerrainChunk::clear_baked_lights() { - if (has_method("_clear_baked_lights")) + if (has_method("_clear_baked_lights")) { call("_clear_baked_lights"); + } } #ifdef MODULE_PROPS_ENABLED @@ -775,8 +795,9 @@ int TerrainChunk::mesh_data_resource_addv(const Vector3 &local_data_pos, const R _mesh_data_resources.push_back(e); - if (has_method("_mesh_data_resource_added")) + if (has_method("_mesh_data_resource_added")) { call("_mesh_data_resource_added", index); + } return index; } @@ -977,37 +998,44 @@ void TerrainChunk::colliders_clear() { void TerrainChunk::enter_tree() { _is_in_tree = true; - if (has_method("_enter_tree")) + if (has_method("_enter_tree")) { call("_enter_tree"); + } } void TerrainChunk::exit_tree() { _is_in_tree = false; - if (has_method("_exit_tree")) + if (has_method("_exit_tree")) { call("_exit_tree"); + } } void TerrainChunk::process(const float delta) { - if (has_method("_process")) + if (has_method("_process")) { call("_process", delta); + } } void TerrainChunk::physics_process(const float delta) { - if (has_method("_physics_process")) + if (has_method("_physics_process")) { call("_physics_process", delta); + } } void TerrainChunk::world_transform_changed() { call("_world_transform_changed"); } void TerrainChunk::visibility_changed(const bool visible) { - if (has_method("_visibility_changed")) + if (has_method("_visibility_changed")) { call("_visibility_changed", _is_visible); + } } void TerrainChunk::world_light_added(const Ref<TerrainLight> &light) { - if (has_method("_world_light_added")) + if (has_method("_world_light_added")) { call("_world_light_added", light); + } } void TerrainChunk::world_light_removed(const Ref<TerrainLight> &light) { - if (has_method("_world_light_removed")) + if (has_method("_world_light_removed")) { call("_world_light_removed", light); + } } void TerrainChunk::generation_process(const float delta) { call("_generation_process", delta); @@ -1161,16 +1189,18 @@ void TerrainChunk::_generation_process(const float delta) { _THREAD_SAFE_METHOD_ - if (_current_job < 0 || _current_job >= _jobs.size()) + if (_current_job < 0 || _current_job >= _jobs.size()) { return; + } Ref<TerrainJob> job = _jobs[_current_job]; ERR_FAIL_COND(!job.is_valid()); if (job->get_build_phase_type() == TerrainJob::BUILD_PHASE_TYPE_PROCESS) { - if (!_voxel_world->can_chunk_do_build_step()) + if (!_voxel_world->can_chunk_do_build_step()) { return; + } job->process(delta); @@ -1186,16 +1216,18 @@ void TerrainChunk::_generation_physics_process(const float delta) { _THREAD_SAFE_METHOD_ - if (_current_job < 0 || _current_job >= _jobs.size()) + if (_current_job < 0 || _current_job >= _jobs.size()) { return; + } Ref<TerrainJob> job = _jobs[_current_job]; ERR_FAIL_COND(!job.is_valid()); if (job->get_build_phase_type() == TerrainJob::BUILD_PHASE_TYPE_PHYSICS_PROCESS) { - if (!_voxel_world->can_chunk_do_build_step()) + if (!_voxel_world->can_chunk_do_build_step()) { return; + } job->physics_process(delta); diff --git a/modules/terraman/world/terrain_world.cpp b/modules/terraman/world/terrain_world.cpp index 42f559c48..ec749b23e 100644 --- a/modules/terraman/world/terrain_world.cpp +++ b/modules/terraman/world/terrain_world.cpp @@ -123,8 +123,9 @@ void TerrainWorld::set_library(const Ref<TerrainLibrary> &library) { for (int i = 0; i < chunk_get_count(); ++i) { Ref<TerrainChunk> c = chunk_get_index(i); - if (!c.is_valid()) + if (!c.is_valid()) { continue; + } c->set_library(_library); } @@ -146,8 +147,9 @@ void TerrainWorld::set_voxel_scale(const float value) { for (int i = 0; i < chunk_get_count(); ++i) { Ref<TerrainChunk> c = chunk_get_index(i); - if (!c.is_valid()) + if (!c.is_valid()) { continue; + } c->set_voxel_scale(_voxel_scale); } @@ -209,13 +211,15 @@ void TerrainWorld::voxel_structure_add(const Ref<TerrainStructure> &structure) { _voxel_structures.push_back(structure); } void TerrainWorld::voxel_structure_remove(const Ref<TerrainStructure> &structure) { - if (!structure.is_valid()) + if (!structure.is_valid()) { return; + } int index = _voxel_structures.find(structure); - if (index != -1) + if (index != -1) { _voxel_structures.remove(index); + } } void TerrainWorld::voxel_structure_remove_index(const int index) { ERR_FAIL_INDEX(index, _voxel_structures.size()); @@ -263,14 +267,17 @@ void TerrainWorld::chunk_add(Ref<TerrainChunk> chunk, const int x, const int z) chunk->set_position(x, z); chunk->world_transform_changed(); - if (!_chunks.has(pos)) + if (!_chunks.has(pos)) { _chunks.set(pos, chunk); + } - if (_chunks_vector.find(chunk) == -1) + if (_chunks_vector.find(chunk) == -1) { _chunks_vector.push_back(chunk); + } - if (is_inside_tree()) + if (is_inside_tree()) { chunk->enter_tree(); + } if (has_method("_chunk_added")) { call("_chunk_added", chunk); @@ -284,8 +291,9 @@ bool TerrainWorld::chunk_has(const int x, const int z) const { Ref<TerrainChunk> TerrainWorld::chunk_get(const int x, const int z) { IntPos pos(x, z); - if (_chunks.has(pos)) + if (_chunks.has(pos)) { return _chunks.get(pos); + } return Ref<TerrainChunk>(); } @@ -474,11 +482,13 @@ void TerrainWorld::chunks_set(const Vector<Variant> &chunks) { for (int i = 0; i < chunks.size(); ++i) { Ref<TerrainChunk> chunk = Ref<TerrainChunk>(chunks[i]); - if (!chunk.is_valid()) + if (!chunk.is_valid()) { continue; + } - if (_chunks_vector.find(chunk) != -1) + if (_chunks_vector.find(chunk) != -1) { continue; + } chunk_add(chunk, chunk->get_position_x(), chunk->get_position_z()); } @@ -531,8 +541,9 @@ bool TerrainWorld::is_position_walkable(const Vector3 &p_pos) { Ref<TerrainChunk> c = chunk_get(x, z); - if (!c.is_valid()) + if (!c.is_valid()) { return false; + } return !c->get_is_generating(); } @@ -720,8 +731,9 @@ void TerrainWorld::lights_clear() { for (int i = 0; i < _lights.size(); ++i) { Ref<TerrainLight> light = _lights[i]; - if (!light.is_valid()) + if (!light.is_valid()) { continue; + } for (int j = 0; j < _chunks_vector.size(); ++j) { Ref<TerrainChunk> chunk = _chunks_vector[j]; @@ -768,8 +780,9 @@ uint8_t TerrainWorld::get_voxel_at_world_position(const Vector3 &world_position, Ref<TerrainChunk> chunk = chunk_get(x, z); - if (chunk.is_valid()) + if (chunk.is_valid()) { return chunk->get_voxel(bx, bz, channel_index); + } return 0; } @@ -797,16 +810,18 @@ void TerrainWorld::set_voxel_at_world_position(const Vector3 &world_position, co Ref<TerrainChunk> chunk = chunk_get_or_create(x - 1, z); chunk->set_voxel(data, get_chunk_size_x(), bz, channel_index); - if (rebuild) + if (rebuild) { chunk->build(); + } } if (bz == 0) { Ref<TerrainChunk> chunk = chunk_get_or_create(x, z - 1); chunk->set_voxel(data, bx, get_chunk_size_z(), channel_index); - if (rebuild) + if (rebuild) { chunk->build(); + } } } @@ -815,24 +830,27 @@ void TerrainWorld::set_voxel_at_world_position(const Vector3 &world_position, co Ref<TerrainChunk> chunk = chunk_get_or_create(x + 1, z); chunk->set_voxel(data, -1, bz, channel_index); - if (rebuild) + if (rebuild) { chunk->build(); + } } if (bz == get_chunk_size_z() - 1) { Ref<TerrainChunk> chunk = chunk_get_or_create(x, z + 1); chunk->set_voxel(data, bx, -1, channel_index); - if (rebuild) + if (rebuild) { chunk->build(); + } } } Ref<TerrainChunk> chunk = chunk_get_or_create(x, z); chunk->set_voxel(data, bx, bz, channel_index); - if (rebuild) + if (rebuild) { chunk->build(); + } } Ref<TerrainChunk> TerrainWorld::get_chunk_at_world_position(const Vector3 &world_position) { @@ -925,18 +943,21 @@ TerrainWorld ::~TerrainWorld() { void TerrainWorld::_generate_chunk(Ref<TerrainChunk> chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (_level_generator.is_valid()) + if (_level_generator.is_valid()) { _level_generator->generate_chunk(chunk); + } for (int i = 0; i < _voxel_structures.size(); ++i) { Ref<TerrainStructure> structure = _voxel_structures.get(i); - if (!structure.is_valid()) + if (!structure.is_valid()) { continue; + } if (structure->get_use_aabb()) { - if (structure->get_chunk_aabb().has_point(Vector3(chunk->get_position_x(), 1, chunk->get_position_z()))) + if (structure->get_chunk_aabb().has_point(Vector3(chunk->get_position_x(), 1, chunk->get_position_z()))) { structure->write_to_chunk(chunk); + } } else { structure->write_to_chunk(chunk); } @@ -952,8 +973,9 @@ void TerrainWorld::_notification(int p_what) { set_physics_process_internal(true); set_notify_transform(true); - if (_library.is_valid()) + if (_library.is_valid()) { _library->refresh_rects(); + } for (int i = 0; i < _chunks_vector.size(); ++i) { Ref<TerrainChunk> chunk = _chunks_vector[i]; @@ -1015,11 +1037,13 @@ void TerrainWorld::_notification(int p_what) { } } - if (_generating.size() >= _max_concurrent_generations) + if (_generating.size() >= _max_concurrent_generations) { return; + } - if (_generation_queue.size() == 0) + if (_generation_queue.size() == 0) { return; + } while (_generating.size() < _max_concurrent_generations && _generation_queue.size() != 0) { Ref<TerrainChunk> chunk = _generation_queue.get(0);