From 24841e9a185f5f55f8ce7d68d60e0e58ab09922a Mon Sep 17 00:00:00 2001 From: Cory Petkovsek <632766+tinmanjuggernaut@users.noreply.github.com> Date: Thu, 13 Feb 2020 21:49:11 +0800 Subject: [PATCH 1/2] fix gcc warnings --- generators/voxel_generator_test.cpp | 1 + meshers/blocky/voxel_mesher_blocky.cpp | 4 ++-- .../transvoxel/voxel_mesher_transvoxel.cpp | 10 ++++---- streams/voxel_stream_region_files.cpp | 2 +- terrain/voxel_lod_terrain.cpp | 24 +++++++++---------- terrain/voxel_terrain.cpp | 2 +- voxel_buffer.cpp | 6 ++--- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/generators/voxel_generator_test.cpp b/generators/voxel_generator_test.cpp index 48ad6bd1..bdfe3999 100644 --- a/generators/voxel_generator_test.cpp +++ b/generators/voxel_generator_test.cpp @@ -44,6 +44,7 @@ void VoxelGeneratorTest::generate_block(VoxelBlockRequest &input) { generate_block_flat(**input.voxel_buffer, input.origin_in_voxels, input.lod); break; + default: case MODE_WAVES: generate_block_waves(**input.voxel_buffer, input.origin_in_voxels, input.lod); break; diff --git a/meshers/blocky/voxel_mesher_blocky.cpp b/meshers/blocky/voxel_mesher_blocky.cpp index 8935d519..ecf5d8ae 100644 --- a/meshers/blocky/voxel_mesher_blocky.cpp +++ b/meshers/blocky/voxel_mesher_blocky.cpp @@ -390,7 +390,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelMesher::In ArraySlice raw_channel; if (!voxels.get_channel_raw(channel, raw_channel)) { - // _ + /* _ // | \ // /\ \\ // / /|\\\ @@ -399,7 +399,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelMesher::In // | | ) // \ | | // \ / - // + */ // Case supposedly handled before... ERR_PRINT("Something wrong happened"); return; diff --git a/meshers/transvoxel/voxel_mesher_transvoxel.cpp b/meshers/transvoxel/voxel_mesher_transvoxel.cpp index d2f4703f..8e341b3b 100644 --- a/meshers/transvoxel/voxel_mesher_transvoxel.cpp +++ b/meshers/transvoxel/voxel_mesher_transvoxel.cpp @@ -102,7 +102,7 @@ inline uint8_t get_border_mask(const Vector3i &pos, const Vector3i &block_size) // 16: -Z // 32: +Z - for (int i = 0; i < Vector3i::AXIS_COUNT; i++) { + for (unsigned int i = 0; i < Vector3i::AXIS_COUNT; i++) { // Close to negative face. if (pos[i] == 0) { mask |= (1 << (i * 2)); @@ -908,20 +908,20 @@ void VoxelMesherTransvoxel::build_transition(const VoxelBuffer &p_voxels, unsign void VoxelMesherTransvoxel::reset_reuse_cells(Vector3i block_size) { _block_size = block_size; unsigned int deck_area = block_size.x * block_size.y; - for (int i = 0; i < _cache.size(); ++i) { + for (unsigned int i = 0; i < _cache.size(); ++i) { std::vector &deck = _cache[i]; deck.resize(deck_area); - for (int j = 0; j < deck.size(); ++j) { + for (long unsigned int j = 0; j < deck.size(); ++j) { deck[j].vertices.fill(-1); } } } void VoxelMesherTransvoxel::reset_reuse_cells_2d(Vector3i block_size) { - for (int i = 0; i < _cache_2d.size(); ++i) { + for (unsigned int i = 0; i < _cache_2d.size(); ++i) { std::vector &row = _cache_2d[i]; row.resize(block_size.x); - for (int j = 0; j < row.size(); ++j) { + for (long unsigned int j = 0; j < row.size(); ++j) { row[j].vertices.fill(-1); } } diff --git a/streams/voxel_stream_region_files.cpp b/streams/voxel_stream_region_files.cpp index bd75904b..38425f11 100644 --- a/streams/voxel_stream_region_files.cpp +++ b/streams/voxel_stream_region_files.cpp @@ -880,7 +880,7 @@ void VoxelStreamRegionFiles::_convert_files(Meta new_meta) { int lod; }; - ERR_FAIL_COND(old_stream->load_meta() != OK); + ERR_FAIL_COND(old_stream->load_meta() != (int)OK); std::vector old_region_list; Meta old_meta = old_stream->_meta; diff --git a/terrain/voxel_lod_terrain.cpp b/terrain/voxel_lod_terrain.cpp index daf6ccc1..c8640b39 100644 --- a/terrain/voxel_lod_terrain.cpp +++ b/terrain/voxel_lod_terrain.cpp @@ -280,7 +280,7 @@ void VoxelLodTerrain::stop_updater() { _blocks_pending_main_thread_update.clear(); - for (int i = 0; i < _lods.size(); ++i) { + for (unsigned int i = 0; i < _lods.size(); ++i) { Lod &lod = _lods[i]; lod.blocks_pending_update.clear(); @@ -307,7 +307,7 @@ void VoxelLodTerrain::stop_streamer() { _stream_thread = nullptr; } - for (int i = 0; i < _lods.size(); ++i) { + for (unsigned int i = 0; i < _lods.size(); ++i) { Lod &lod = _lods[i]; lod.blocks_to_load.clear(); } @@ -337,7 +337,7 @@ float VoxelLodTerrain::get_lod_split_scale() const { void VoxelLodTerrain::set_lod_count(int p_lod_count) { - ERR_FAIL_COND(p_lod_count >= VoxelConstants::MAX_LOD); + ERR_FAIL_COND(p_lod_count >= (int)VoxelConstants::MAX_LOD); ERR_FAIL_COND(p_lod_count < 1); if (get_lod_count() != p_lod_count) { @@ -347,7 +347,7 @@ void VoxelLodTerrain::set_lod_count(int p_lod_count) { void VoxelLodTerrain::_set_lod_count(int p_lod_count) { - CRASH_COND(p_lod_count >= VoxelConstants::MAX_LOD); + CRASH_COND(p_lod_count >= (int)VoxelConstants::MAX_LOD); CRASH_COND(p_lod_count < 1); _lod_count = p_lod_count; @@ -365,7 +365,7 @@ void VoxelLodTerrain::_set_lod_count(int p_lod_count) { void VoxelLodTerrain::reset_maps() { // Clears all blocks and reconfigures maps to account for new LOD count and block sizes - for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) { + for (int lod_index = 0; lod_index < (int)_lods.size(); ++lod_index) { Lod &lod = _lods[lod_index]; @@ -447,7 +447,7 @@ void VoxelLodTerrain::_notification(int p_what) { case NOTIFICATION_ENTER_WORLD: { World *world = *get_world(); - for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) { + for (unsigned int lod_index = 0; lod_index < _lods.size(); ++lod_index) { if (_lods[lod_index].map.is_valid()) { _lods[lod_index].map->for_all_blocks([world](VoxelBlock *block) { block->set_world(world); @@ -457,7 +457,7 @@ void VoxelLodTerrain::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) { + for (unsigned int lod_index = 0; lod_index < _lods.size(); ++lod_index) { if (_lods[lod_index].map.is_valid()) { _lods[lod_index].map->for_all_blocks([](VoxelBlock *block) { block->set_world(nullptr); @@ -468,7 +468,7 @@ void VoxelLodTerrain::_notification(int p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { bool visible = is_visible(); - for (int lod_index = 0; lod_index < _lods.size(); ++lod_index) { + for (unsigned int lod_index = 0; lod_index < _lods.size(); ++lod_index) { if (_lods[lod_index].map.is_valid()) { _lods[lod_index].map->for_all_blocks([visible](VoxelBlock *block) { block->set_parent_visible(visible); @@ -1212,7 +1212,7 @@ void VoxelLodTerrain::_process() { { VOXEL_PROFILE_SCOPE(profile_process_receive_mesh_updates_block_update_transitions); - for (int dir = 0; dir < mesh_data.transition_surfaces.size(); ++dir) { + for (unsigned int dir = 0; dir < mesh_data.transition_surfaces.size(); ++dir) { Ref transition_mesh = build_mesh( mesh_data.transition_surfaces[dir], @@ -1429,7 +1429,7 @@ uint8_t VoxelLodTerrain::get_transition_mask(Vector3i block_pos, int lod_index) uint8_t transition_mask = 0; - if (lod_index + 1 >= _lods.size()) { + if (lod_index + 1 >= (int)_lods.size()) { return transition_mask; } @@ -1489,7 +1489,7 @@ uint8_t VoxelLodTerrain::get_transition_mask(Vector3i block_pos, int lod_index) // There are always 4 on each side, checking any is enough Vector3i upper_neighbor_pos = upper_pos; - for (int i = 0; i < Vector3i::AXIS_COUNT; ++i) { + for (unsigned int i = 0; i < Vector3i::AXIS_COUNT; ++i) { if (side_normal[i] == -1) { --upper_neighbor_pos[i]; } else if (side_normal[i] == 1) { @@ -1574,7 +1574,7 @@ Array VoxelLodTerrain::debug_get_last_unexpected_block_drops() const { Array drops; drops.resize(lod.debug_unexpected_block_drops.size()); - for (int j = 0; j < lod.debug_unexpected_block_drops.size(); ++j) { + for (unsigned int j = 0; j < lod.debug_unexpected_block_drops.size(); ++j) { drops[j] = lod.debug_unexpected_block_drops[j].to_vec3(); } diff --git a/terrain/voxel_terrain.cpp b/terrain/voxel_terrain.cpp index 857db004..6712833d 100644 --- a/terrain/voxel_terrain.cpp +++ b/terrain/voxel_terrain.cpp @@ -905,7 +905,7 @@ void VoxelTerrain::_process() { if ( block->voxels->is_uniform(VoxelBuffer::CHANNEL_TYPE) && block->voxels->is_uniform(VoxelBuffer::CHANNEL_SDF) && - block->voxels->get_voxel(0, 0, 0, VoxelBuffer::CHANNEL_TYPE) == air_type) { + block->voxels->get_voxel(0, 0, 0, VoxelBuffer::CHANNEL_TYPE) == (uint64_t)air_type) { // If we got here, it must have been because of scheduling an update CRASH_COND(block->get_mesh_state() != VoxelBlock::MESH_UPDATE_NOT_SENT); diff --git a/voxel_buffer.cpp b/voxel_buffer.cpp index 388f392b..c5576c1f 100644 --- a/voxel_buffer.cpp +++ b/voxel_buffer.cpp @@ -360,19 +360,19 @@ void VoxelBuffer::fill_area(uint64_t defval, Vector3i min, Vector3i max, unsigne break; case DEPTH_16_BIT: - for (unsigned int i = 0; i < area_size.y; ++i) { + for (int i = 0; i < area_size.y; ++i) { ((uint16_t *)channel.data)[dst_ri + i] = defval; } break; case DEPTH_32_BIT: - for (unsigned int i = 0; i < area_size.y; ++i) { + for (int i = 0; i < area_size.y; ++i) { ((uint32_t *)channel.data)[dst_ri + i] = defval; } break; case DEPTH_64_BIT: - for (unsigned int i = 0; i < area_size.y; ++i) { + for (int i = 0; i < area_size.y; ++i) { ((uint64_t *)channel.data)[dst_ri + i] = defval; } break; From 40e3fdc87868cfc1b552280cae7b0dd0b40c8805 Mon Sep 17 00:00:00 2001 From: Cory Petkovsek <632766+tinmanjuggernaut@users.noreply.github.com> Date: Sat, 15 Feb 2020 03:46:10 +0800 Subject: [PATCH 2/2] Adjust PR --- generators/voxel_generator_test.cpp | 5 ++++- meshers/transvoxel/voxel_mesher_transvoxel.cpp | 4 ++-- streams/voxel_stream_region_files.cpp | 2 +- terrain/voxel_terrain.cpp | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/generators/voxel_generator_test.cpp b/generators/voxel_generator_test.cpp index bdfe3999..90bb7799 100644 --- a/generators/voxel_generator_test.cpp +++ b/generators/voxel_generator_test.cpp @@ -44,10 +44,13 @@ void VoxelGeneratorTest::generate_block(VoxelBlockRequest &input) { generate_block_flat(**input.voxel_buffer, input.origin_in_voxels, input.lod); break; - default: case MODE_WAVES: generate_block_waves(**input.voxel_buffer, input.origin_in_voxels, input.lod); break; + + default: + CRASH_NOW_MSG("Mode is unrecognized."); + break; } } diff --git a/meshers/transvoxel/voxel_mesher_transvoxel.cpp b/meshers/transvoxel/voxel_mesher_transvoxel.cpp index 8e341b3b..2e45fd27 100644 --- a/meshers/transvoxel/voxel_mesher_transvoxel.cpp +++ b/meshers/transvoxel/voxel_mesher_transvoxel.cpp @@ -911,7 +911,7 @@ void VoxelMesherTransvoxel::reset_reuse_cells(Vector3i block_size) { for (unsigned int i = 0; i < _cache.size(); ++i) { std::vector &deck = _cache[i]; deck.resize(deck_area); - for (long unsigned int j = 0; j < deck.size(); ++j) { + for (size_t j = 0; j < deck.size(); ++j) { deck[j].vertices.fill(-1); } } @@ -921,7 +921,7 @@ void VoxelMesherTransvoxel::reset_reuse_cells_2d(Vector3i block_size) { for (unsigned int i = 0; i < _cache_2d.size(); ++i) { std::vector &row = _cache_2d[i]; row.resize(block_size.x); - for (long unsigned int j = 0; j < row.size(); ++j) { + for (size_t j = 0; j < row.size(); ++j) { row[j].vertices.fill(-1); } } diff --git a/streams/voxel_stream_region_files.cpp b/streams/voxel_stream_region_files.cpp index 38425f11..ab4a634e 100644 --- a/streams/voxel_stream_region_files.cpp +++ b/streams/voxel_stream_region_files.cpp @@ -880,7 +880,7 @@ void VoxelStreamRegionFiles::_convert_files(Meta new_meta) { int lod; }; - ERR_FAIL_COND(old_stream->load_meta() != (int)OK); + ERR_FAIL_COND(old_stream->load_meta() != VOXEL_FILE_OK); std::vector old_region_list; Meta old_meta = old_stream->_meta; diff --git a/terrain/voxel_terrain.cpp b/terrain/voxel_terrain.cpp index 6712833d..468892cc 100644 --- a/terrain/voxel_terrain.cpp +++ b/terrain/voxel_terrain.cpp @@ -901,11 +901,11 @@ void VoxelTerrain::_process() { } else { CRASH_COND(block->voxels.is_null()); - int air_type = 0; + uint64_t air_type = 0; if ( block->voxels->is_uniform(VoxelBuffer::CHANNEL_TYPE) && block->voxels->is_uniform(VoxelBuffer::CHANNEL_SDF) && - block->voxels->get_voxel(0, 0, 0, VoxelBuffer::CHANNEL_TYPE) == (uint64_t)air_type) { + block->voxels->get_voxel(0, 0, 0, VoxelBuffer::CHANNEL_TYPE) == air_type) { // If we got here, it must have been because of scheduling an update CRASH_COND(block->get_mesh_state() != VoxelBlock::MESH_UPDATE_NOT_SENT);