From 367c203cc6a6222bf70e5698c040d113be057b24 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 16 Apr 2020 17:10:04 +0200 Subject: [PATCH] Added lots of const qualifiers to world and chunk. --- world/voxel_chunk.cpp | 100 +++++++++++++++++++-------------------- world/voxel_chunk.h | 106 +++++++++++++++++++++--------------------- world/voxel_world.cpp | 28 +++++------ world/voxel_world.h | 32 ++++++------- 4 files changed, 133 insertions(+), 133 deletions(-) diff --git a/world/voxel_chunk.cpp b/world/voxel_chunk.cpp index 4ca5a35..541a60c 100644 --- a/world/voxel_chunk.cpp +++ b/world/voxel_chunk.cpp @@ -68,40 +68,40 @@ void VoxelChunk::set_visible(const bool value) { _FORCE_INLINE_ bool VoxelChunk::get_is_generating() const { return _is_generating; } -_FORCE_INLINE_ void VoxelChunk::set_is_generating(bool value) { +_FORCE_INLINE_ void VoxelChunk::set_is_generating(const bool value) { _is_generating = value; } _FORCE_INLINE_ bool VoxelChunk::get_dirty() const { return _dirty; } -_FORCE_INLINE_ void VoxelChunk::set_dirty(bool value) { +_FORCE_INLINE_ void VoxelChunk::set_dirty(const bool value) { _dirty = value; } _FORCE_INLINE_ int VoxelChunk::get_state() const { return _state; } -_FORCE_INLINE_ void VoxelChunk::set_state(int value) { +_FORCE_INLINE_ void VoxelChunk::set_state(const int value) { _state = value; } -_FORCE_INLINE_ int VoxelChunk::get_position_x() { +_FORCE_INLINE_ int VoxelChunk::get_position_x() const { return _position_x; } -void VoxelChunk::set_position_x(int value) { +void VoxelChunk::set_position_x(const int value) { _position_x = value; } -_FORCE_INLINE_ int VoxelChunk::get_position_y() { +_FORCE_INLINE_ int VoxelChunk::get_position_y() const { return _position_y; } -void VoxelChunk::set_position_y(int value) { +void VoxelChunk::set_position_y(const int value) { _position_y = value; } -_FORCE_INLINE_ int VoxelChunk::get_position_z() { +_FORCE_INLINE_ int VoxelChunk::get_position_z() const { return _position_z; } -void VoxelChunk::set_position_z(int value) { +void VoxelChunk::set_position_z(const int value) { _position_z = value; } @@ -109,23 +109,23 @@ _FORCE_INLINE_ Vector3 VoxelChunk::get_position() const { return Vector3(_position_x, _position_y, _position_z); } -_FORCE_INLINE_ int VoxelChunk::get_size_x() { +_FORCE_INLINE_ int VoxelChunk::get_size_x() const { return _size_x; } -_FORCE_INLINE_ int VoxelChunk::get_size_y() { +_FORCE_INLINE_ int VoxelChunk::get_size_y() const { return _size_y; } -_FORCE_INLINE_ int VoxelChunk::get_size_z() { +_FORCE_INLINE_ int VoxelChunk::get_size_z() const { return _size_z; } -_FORCE_INLINE_ void VoxelChunk::set_size_x(int value) { +_FORCE_INLINE_ void VoxelChunk::set_size_x(const int value) { _size_x = value; } -_FORCE_INLINE_ void VoxelChunk::set_size_y(int value) { +_FORCE_INLINE_ void VoxelChunk::set_size_y(const int value) { _size_y = value; } -_FORCE_INLINE_ void VoxelChunk::set_size_z(int value) { +_FORCE_INLINE_ void VoxelChunk::set_size_z(const int value) { _size_z = value; } @@ -133,27 +133,27 @@ _FORCE_INLINE_ Vector3 VoxelChunk::get_size() const { return Vector3(_size_x, _size_y, _size_z); } -_FORCE_INLINE_ int VoxelChunk::get_data_size_x() { +_FORCE_INLINE_ int VoxelChunk::get_data_size_x() const { return _data_size_x; } -_FORCE_INLINE_ int VoxelChunk::get_data_size_y() { +_FORCE_INLINE_ int VoxelChunk::get_data_size_y() const { return _data_size_y; } -_FORCE_INLINE_ int VoxelChunk::get_data_size_z() { +_FORCE_INLINE_ int VoxelChunk::get_data_size_z() const { return _data_size_z; } -_FORCE_INLINE_ void VoxelChunk::set_data_size_x(int value) { +_FORCE_INLINE_ void VoxelChunk::set_data_size_x(const int value) { _data_size_x = value; } -_FORCE_INLINE_ void VoxelChunk::set_data_size_y(int value) { +_FORCE_INLINE_ void VoxelChunk::set_data_size_y(const int value) { _data_size_y = value; } -_FORCE_INLINE_ void VoxelChunk::set_data_size_z(int value) { +_FORCE_INLINE_ void VoxelChunk::set_data_size_z(const int value) { _data_size_z = value; } -void VoxelChunk::set_position(int x, int y, int z) { +void VoxelChunk::set_position(const int x, const int y, const int z) { _position_x = x; _position_y = y; _position_z = z; @@ -166,10 +166,10 @@ _FORCE_INLINE_ int VoxelChunk::get_margin_end() const { return _margin_end; } -_FORCE_INLINE_ void VoxelChunk::set_margin_start(int value) { +_FORCE_INLINE_ void VoxelChunk::set_margin_start(const int value) { _margin_start = value; } -_FORCE_INLINE_ void VoxelChunk::set_margin_end(int value) { +_FORCE_INLINE_ void VoxelChunk::set_margin_end(const int value) { _margin_end = value; } @@ -183,7 +183,7 @@ void VoxelChunk::set_library(const Ref &value) { float VoxelChunk::get_voxel_scale() const { return _voxel_scale; } -void VoxelChunk::set_voxel_scale(float value) { +void VoxelChunk::set_voxel_scale(const float value) { _voxel_scale = value; for (int i = 0; i < _meshers.size(); ++i) { @@ -215,20 +215,20 @@ Ref VoxelChunk::get_mesher(int index) const { return _meshers.get(index); } -void VoxelChunk::set_mesher(int index, Ref mesher) { +void VoxelChunk::set_mesher(int index, const Ref &mesher) { ERR_FAIL_INDEX(index, _meshers.size()); _meshers.set(index, mesher); } -void VoxelChunk::remove_mesher(int index) { +void VoxelChunk::remove_mesher(const int index) { ERR_FAIL_INDEX(index, _meshers.size()); _meshers.remove(index); } -void VoxelChunk::add_mesher(Ref mesher) { +void VoxelChunk::add_mesher(const Ref &mesher) { _meshers.push_back(mesher); } -int VoxelChunk::get_mesher_count() { +int VoxelChunk::get_mesher_count() const { return _meshers.size(); } @@ -239,7 +239,7 @@ void VoxelChunk::setup_channels() { call("_setup_channels"); } -void VoxelChunk::set_size(int size_x, int size_y, int size_z, int margin_start, int margin_end) { +void VoxelChunk::set_size(const int size_x, const int size_y, const int size_z, const int margin_start, const int margin_end) { if (_size_x == size_x && _size_y == size_y && _size_z == size_z && _margin_start == margin_start && _margin_end == margin_end) { return; } @@ -266,11 +266,11 @@ void VoxelChunk::set_size(int size_x, int size_y, int size_z, int margin_start, _margin_end = margin_end; } -bool VoxelChunk::validate_channel_data_position(int x, int y, int z) const { +bool VoxelChunk::validate_channel_data_position(const int x, const int y, const int z) const { return x < _data_size_x && y < _data_size_y && z < _data_size_z; } -uint8_t VoxelChunk::get_voxel(int p_x, int p_y, int p_z, int p_channel_index) const { +uint8_t VoxelChunk::get_voxel(const int p_x, const int p_y, const int p_z, const int p_channel_index) const { int x = p_x + _margin_start; int y = p_y + _margin_start; int z = p_z + _margin_start; @@ -285,7 +285,7 @@ uint8_t VoxelChunk::get_voxel(int p_x, int p_y, int p_z, int p_channel_index) co return ch[get_data_index(x, y, z)]; } -void VoxelChunk::set_voxel(uint8_t p_value, int p_x, int p_y, int p_z, int p_channel_index) { +void VoxelChunk::set_voxel(const uint8_t p_value, const int p_x, const int p_y, const int p_z, const int p_channel_index) { int x = p_x + _margin_start; int y = p_y + _margin_start; int z = p_z + _margin_start; @@ -298,11 +298,11 @@ void VoxelChunk::set_voxel(uint8_t p_value, int p_x, int p_y, int p_z, int p_cha ch[get_data_index(x, y, z)] = p_value; } -int VoxelChunk::get_channel_count() { +int VoxelChunk::get_channel_count() const { return _channels.size(); } -void VoxelChunk::set_channel_count(int count) { +void VoxelChunk::set_channel_count(const int count) { if (count == _channels.size()) return; @@ -326,7 +326,7 @@ void VoxelChunk::set_channel_count(int count) { _channels.set(i, NULL); } } -void VoxelChunk::allocate_channel(int channel_index, uint8_t default_value) { +void VoxelChunk::allocate_channel(const int channel_index, const uint8_t default_value) { ERR_FAIL_INDEX(channel_index, _channels.size()); if (_channels[channel_index] != NULL) @@ -339,7 +339,7 @@ void VoxelChunk::allocate_channel(int channel_index, uint8_t default_value) { _channels.set(channel_index, ch); } -void VoxelChunk::fill_channel(uint8_t value, int channel_index) { +void VoxelChunk::fill_channel(const uint8_t value, const int channel_index) { ERR_FAIL_INDEX(channel_index, _channels.size()); uint8_t *ch = _channels.get(channel_index); @@ -355,7 +355,7 @@ void VoxelChunk::fill_channel(uint8_t value, int channel_index) { ch[i] = value; } } -void VoxelChunk::dealloc_channel(int channel_index) { +void VoxelChunk::dealloc_channel(const int channel_index) { ERR_FAIL_INDEX(channel_index, _channels.size()); uint8_t *ch = _channels.get(channel_index); @@ -367,12 +367,12 @@ void VoxelChunk::dealloc_channel(int channel_index) { } } -uint8_t *VoxelChunk::get_channel(int channel_index) { +uint8_t *VoxelChunk::get_channel(const int channel_index) { ERR_FAIL_INDEX_V(channel_index, _channels.size(), NULL); return _channels.get(channel_index); } -uint8_t *VoxelChunk::get_valid_channel(int channel_index, uint8_t default_value) { +uint8_t *VoxelChunk::get_valid_channel(const int channel_index, const uint8_t default_value) { ERR_FAIL_INDEX_V(channel_index, _channels.size(), 0); uint8_t *ch = _channels.get(channel_index); @@ -386,7 +386,7 @@ uint8_t *VoxelChunk::get_valid_channel(int channel_index, uint8_t default_value) return ch; } -PoolByteArray VoxelChunk::get_channel_array(int channel_index) const { +PoolByteArray VoxelChunk::get_channel_array(const int channel_index) const { PoolByteArray arr; uint32_t size = _data_size_x * _data_size_y * _data_size_z; @@ -407,7 +407,7 @@ PoolByteArray VoxelChunk::get_channel_array(int channel_index) const { return arr; } -void VoxelChunk::set_channel_array(int channel_index, const PoolByteArray &array) { +void VoxelChunk::set_channel_array(const int channel_index, const PoolByteArray &array) { if (array.size() == 0) return; @@ -429,7 +429,7 @@ void VoxelChunk::set_channel_array(int channel_index, const PoolByteArray &array } } -PoolByteArray VoxelChunk::get_channel_compressed(int channel_index) const { +PoolByteArray VoxelChunk::get_channel_compressed(const int channel_index) const { PoolByteArray arr; int size = _data_size_x * _data_size_y * _data_size_z; @@ -458,7 +458,7 @@ PoolByteArray VoxelChunk::get_channel_compressed(int channel_index) const { return arr; } -void VoxelChunk::set_channel_compressed(int channel_index, const PoolByteArray &data) { +void VoxelChunk::set_channel_compressed(const int channel_index, const PoolByteArray &data) { if (data.size() == 0) return; @@ -575,7 +575,7 @@ Array VoxelChunk::merge_mesh_array(Array arr) const { return arr; } -Array VoxelChunk::bake_mesh_array_uv(Array arr, Ref tex, float mul_color) const { +Array VoxelChunk::bake_mesh_array_uv(Array arr, Ref tex, const float mul_color) const { ERR_FAIL_COND_V(arr.size() != VisualServer::ARRAY_MAX, arr); ERR_FAIL_COND_V(!tex.is_valid(), arr); @@ -641,10 +641,10 @@ Ref VoxelChunk::get_prop(int index) { return _props.get(index); } -int VoxelChunk::get_prop_count() { +int VoxelChunk::get_prop_count() const { return _props.size(); } -void VoxelChunk::remove_prop(int index) { +void VoxelChunk::remove_prop(const int index) { ERR_FAIL_INDEX(index, _props.size()); Ref prop = _props.get(index); @@ -673,18 +673,18 @@ void VoxelChunk::exit_tree() { if (has_method("_exit_tree")) call("_exit_tree"); } -void VoxelChunk::process(float delta) { +void VoxelChunk::process(const float delta) { if (has_method("_process")) call("_process", delta); } -void VoxelChunk::physics_process(float delta) { +void VoxelChunk::physics_process(const float delta) { if (has_method("_physics_process")) call("_physics_process", delta); } void VoxelChunk::world_transform_changed() { call("_world_transform_changed"); } -void VoxelChunk::visibility_changed(bool visible) { +void VoxelChunk::visibility_changed(const bool visible) { if (has_method("_visibility_changed")) call("_visibility_changed", _is_visible); } diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 5ef3ea7..3ffda87 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -82,94 +82,94 @@ public: void set_visible(const bool value); bool get_is_generating() const; - void set_is_generating(bool value); + void set_is_generating(const bool value); bool get_dirty() const; - void set_dirty(bool value); + void set_dirty(const bool value); int get_state() const; void set_state(int value); - int get_position_x(); - void set_position_x(int value); - int get_position_y(); - void set_position_y(int value); - int get_position_z(); - void set_position_z(int value); + int get_position_x() const; + void set_position_x(const int value); + int get_position_y() const; + void set_position_y(const int value); + int get_position_z() const; + void set_position_z(const int value); - int get_size_x(); - int get_size_y(); - int get_size_z(); - void set_size_x(int value); - void set_size_y(int value); - void set_size_z(int value); + int get_size_x() const; + int get_size_y() const; + int get_size_z() const; + void set_size_x(const int value); + void set_size_y(const int value); + void set_size_z(const int value); - int get_data_size_x(); - int get_data_size_y(); - int get_data_size_z(); - void set_data_size_x(int value); - void set_data_size_y(int value); - void set_data_size_z(int value); + int get_data_size_x() const; + int get_data_size_y() const; + int get_data_size_z() const; + void set_data_size_x(const int value); + void set_data_size_y(const int value); + void set_data_size_z(const int value); Vector3 get_position() const; Vector3 get_size() const; - void set_position(int x, int y, int z); + void set_position(const int x, const int y, const int z); int get_margin_start() const; int get_margin_end() const; - void set_margin_start(int value); - void set_margin_end(int value); + void set_margin_start(const int value); + void set_margin_end(const int value); Ref get_library(); void set_library(const Ref &value); float get_voxel_scale() const; - void set_voxel_scale(float value); + void set_voxel_scale(const float value); VoxelWorld *get_voxel_world() const; void set_voxel_world(VoxelWorld *world); void set_voxel_world_bind(Node *world); //Meshers - Ref get_mesher(int index) const; - void set_mesher(int index, Ref mesher); - void remove_mesher(int index); - void add_mesher(Ref mesher); - int get_mesher_count(); + Ref get_mesher(const int index) const; + void set_mesher(const int index, const Ref &mesher); + void remove_mesher(const int index); + void add_mesher(const Ref &mesher); + int get_mesher_count() const; //Channels void setup_channels(); - void set_size(int size_x, int size_y, int size_z, int margin_start = 0, int margin_end = 0); + void set_size(const int size_x, const int size_y, const int size_z, const int margin_start = 0, const int margin_end = 0); - bool validate_channel_data_position(int x, int y, int z) const; + bool validate_channel_data_position(const int x, const int y, const int z) const; - uint8_t get_voxel(int p_x, int p_y, int p_z, int p_channel_index) const; - void set_voxel(uint8_t p_value, int p_x, int p_y, int p_z, int p_channel_index); + uint8_t get_voxel(const int p_x, const int p_y, const int p_z, const int p_channel_index) const; + void set_voxel(const uint8_t p_value, const int p_x, const int p_y, const int p_z, const int p_channel_index); - int get_channel_count(); - void set_channel_count(int count); + int get_channel_count() const; + void set_channel_count(const int count); - void allocate_channel(int channel_index, uint8_t default_value = 0); - void fill_channel(uint8_t value, int channel_index); - void dealloc_channel(int channel_index); + void allocate_channel(const int channel_index, const uint8_t default_value = 0); + void fill_channel(const uint8_t value, const int channel_index); + void dealloc_channel(const int channel_index); - uint8_t *get_channel(int channel_index); - uint8_t *get_valid_channel(int channel_index, uint8_t default_value = 0); + uint8_t *get_channel(const int channel_index); + uint8_t *get_valid_channel(const int channel_index, const uint8_t default_value = 0); - PoolByteArray get_channel_array(int channel_index) const; - void set_channel_array(int channel_index, const PoolByteArray &array); + PoolByteArray get_channel_array(const int channel_index) const; + void set_channel_array(const int channel_index, const PoolByteArray &array); - PoolByteArray get_channel_compressed(int channel_index) const; - void set_channel_compressed(int channel_index, const PoolByteArray &data); + PoolByteArray get_channel_compressed(const int channel_index) const; + void set_channel_compressed(const int channel_index, const PoolByteArray &data); - int get_index(int x, int y, int z) const; - int get_data_index(int x, int y, int z) const; + int get_index(const int x, const int y, const int z) const; + int get_data_index(const int x, const int y, const int z) const; int get_data_size() const; //Meshing void create_meshers(); - void build(bool immediate = false); + void build(const bool immediate = false); void clear(); Array merge_mesh_array(Array arr) const; @@ -182,18 +182,18 @@ public: //props void add_prop(Ref prop); - Ref get_prop(int index); - int get_prop_count(); - void remove_prop(int index); + Ref get_prop(const int index); + int get_prop_count() const; + void remove_prop(const int index); void clear_props(); //handlers void enter_tree(); void exit_tree(); - void process(float delta); - void physics_process(float delta); + void process(const float delta); + void physics_process(const float delta); void world_transform_changed(); - void visibility_changed(bool visible); + void visibility_changed(const bool visible); void world_light_added(const Ref &light); void world_light_removed(const Ref &light); diff --git a/world/voxel_world.cpp b/world/voxel_world.cpp index c6794de..61c9b75 100644 --- a/world/voxel_world.cpp +++ b/world/voxel_world.cpp @@ -81,10 +81,10 @@ void VoxelWorld::set_current_seed(const int value) { _current_seed = value; } -bool VoxelWorld::get_use_threads() { +bool VoxelWorld::get_use_threads() const { return _use_threads; } -void VoxelWorld::set_use_threads(bool value) { +void VoxelWorld::set_use_threads(const bool value) { _use_threads = OS::get_singleton()->can_use_threads() ? value : false; } @@ -105,14 +105,14 @@ void VoxelWorld::set_max_frame_chunk_build_steps(const int value) { Ref VoxelWorld::get_library() { return _library; } -void VoxelWorld::set_library(const Ref library) { +void VoxelWorld::set_library(const Ref &library) { _library = library; } Ref VoxelWorld::get_level_generator() const { return _level_generator; } -void VoxelWorld::set_level_generator(const Ref level_generator) { +void VoxelWorld::set_level_generator(const Ref &level_generator) { _level_generator = level_generator; } @@ -130,11 +130,11 @@ void VoxelWorld::set_chunk_spawn_range(const int value) { _chunk_spawn_range = value; } -NodePath VoxelWorld::get_player_path() { +NodePath VoxelWorld::get_player_path() const { return _player_path; } -void VoxelWorld::set_player_path(NodePath player_path) { +void VoxelWorld::set_player_path(const NodePath &player_path) { _player_path = player_path; } @@ -302,7 +302,7 @@ int VoxelWorld::get_chunk_count() const { return _chunks_vector.size(); } -void VoxelWorld::add_to_generation_queue(Ref chunk) { +void VoxelWorld::add_to_generation_queue(const Ref &chunk) { ERR_FAIL_COND(!chunk.is_valid()); set_process_internal(true); @@ -319,26 +319,26 @@ void VoxelWorld::remove_generation_queue_index(int index) { _generation_queue.remove(index); } -int VoxelWorld::get_generation_queue_size() { +int VoxelWorld::get_generation_queue_size() const { return _generation_queue.size(); } -void VoxelWorld::add_to_generation(Ref chunk) { +void VoxelWorld::add_to_generation(const Ref &chunk) { ERR_FAIL_COND(!chunk.is_valid()); _generating.push_back(chunk); } -Ref VoxelWorld::get_generation_index(int index) { +Ref VoxelWorld::get_generation_index(const int index) { ERR_FAIL_INDEX_V(index, _generating.size(), NULL); return _generating.get(index); } -void VoxelWorld::remove_generation_index(int index) { +void VoxelWorld::remove_generation_index(const int index) { ERR_FAIL_INDEX(index, _generating.size()); _generating.remove(index); } -int VoxelWorld::get_generation_size() { +int VoxelWorld::get_generation_size() const { return _generating.size(); } @@ -365,12 +365,12 @@ Ref VoxelWorld::get_or_create_chunk(int x, int y, int z) { return chunk; } -Ref VoxelWorld::create_chunk(int x, int y, int z) { +Ref VoxelWorld::create_chunk(const int x, const int y, const int z) { Ref c = call("_create_chunk", x, y, z, Ref()); return c; } -Ref VoxelWorld::_create_chunk(int x, int y, int z, Ref chunk) { +Ref VoxelWorld::_create_chunk(const int x, const int y, const int z, Ref chunk) { if (!chunk.is_valid()) { chunk.instance(); } diff --git a/world/voxel_world.h b/world/voxel_world.h index 165df0c..e82c43b 100644 --- a/world/voxel_world.h +++ b/world/voxel_world.h @@ -74,8 +74,8 @@ public: int get_current_seed() const; void set_current_seed(const int value); - bool get_use_threads(); - void set_use_threads(bool value); + bool get_use_threads() const; + void set_use_threads(const bool value); int get_max_concurrent_generations() const; void set_max_concurrent_generations(const int value); @@ -84,10 +84,10 @@ public: void set_max_frame_chunk_build_steps(const int value); Ref get_library(); - void set_library(const Ref library); + void set_library(const Ref &library); Ref get_level_generator() const; - void set_level_generator(const Ref level_generator); + void set_level_generator(const Ref &level_generator); float get_voxel_scale() const; void set_voxel_scale(const float value); @@ -95,8 +95,8 @@ public: int get_chunk_spawn_range() const; void set_chunk_spawn_range(const int value); - NodePath get_player_path(); - void set_player_path(NodePath player_path); + NodePath get_player_path() const; + void set_player_path(const NodePath &player_path); Spatial *get_player() const; void set_player(Spatial *player); @@ -131,20 +131,20 @@ public: int get_chunk_count() const; - void add_to_generation_queue(Ref chunk); - Ref get_generation_queue_index(int index); - void remove_generation_queue_index(int index); - int get_generation_queue_size(); + void add_to_generation_queue(const Ref &chunk); + Ref get_generation_queue_index(const int index); + void remove_generation_queue_index(const int index); + int get_generation_queue_size() const; - void add_to_generation(Ref chunk); - Ref get_generation_index(int index); - void remove_generation_index(int index); - int get_generation_size(); + void add_to_generation(const Ref &chunk); + Ref get_generation_index(const int index); + void remove_generation_index(const int index); + int get_generation_size() const; void clear_chunks(); - Ref get_or_create_chunk(int x, int y, int z); - Ref create_chunk(int x, int y, int z); + Ref get_or_create_chunk(const int x, const int y, const int z); + Ref create_chunk(const int x, const int y, const int z); void generate_chunk(Ref chunk);