From 4f862722ae030ed1aeceb6776fede32dbe23a5f3 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 17 May 2022 19:44:58 +0100 Subject: [PATCH] Removed usages of Map --- editor/vox/vox_mesh_importer.cpp | 4 +- editor/vox/vox_mesh_importer.h | 4 +- editor/vox/vox_scene_importer.cpp | 4 +- editor/vox/vox_scene_importer.h | 4 +- meshers/dmc/mesh_builder.h | 12 ++-- terrain/instancing/voxel_instance_library.cpp | 67 ++++++++++--------- terrain/instancing/voxel_instance_library.h | 14 ++-- terrain/variable_lod/voxel_lod_terrain.cpp | 65 +++++++++--------- terrain/variable_lod/voxel_lod_terrain.h | 3 +- .../voxel_lod_terrain_update_data.h | 3 +- .../voxel_lod_terrain_update_task.cpp | 27 ++++---- tests/test_octree.cpp | 29 ++++---- 12 files changed, 122 insertions(+), 114 deletions(-) diff --git a/editor/vox/vox_mesh_importer.cpp b/editor/vox/vox_mesh_importer.cpp index 401d5949..05c36184 100644 --- a/editor/vox/vox_mesh_importer.cpp +++ b/editor/vox/vox_mesh_importer.cpp @@ -57,7 +57,7 @@ void VoxelVoxMeshImporter::get_import_options(const String &p_path, List &p_options) const { + const String &p_path, const String &p_option, const HashMap &p_options) const { return true; } @@ -216,7 +216,7 @@ bool make_single_voxel_grid( } Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_save_path, - const Map &p_options, List *r_platform_variants, List *r_gen_files, + const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { // const bool p_store_colors_in_textures = p_options[VoxelStringNames::get_singleton().store_colors_in_texture]; diff --git a/editor/vox/vox_mesh_importer.h b/editor/vox/vox_mesh_importer.h index 64ea76a6..cf28e97a 100644 --- a/editor/vox/vox_mesh_importer.h +++ b/editor/vox/vox_mesh_importer.h @@ -20,9 +20,9 @@ public: //int get_import_order() const override; void get_import_options(const String &p_path, List *r_options, int p_preset = 0) const override; bool get_option_visibility( - const String &p_path, const String &p_option, const Map &p_options) const override; + const String &p_path, const String &p_option, const HashMap &p_options) const override; - Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, + Error import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata = nullptr) override; enum PivotMode { // diff --git a/editor/vox/vox_scene_importer.cpp b/editor/vox/vox_scene_importer.cpp index 05bf1f51..16f1db14 100644 --- a/editor/vox/vox_scene_importer.cpp +++ b/editor/vox/vox_scene_importer.cpp @@ -61,7 +61,7 @@ void VoxelVoxSceneImporter::get_import_options( } bool VoxelVoxSceneImporter::get_option_visibility( - const String &p_path, const String &p_option, const Map &p_options) const { + const String &p_path, const String &p_option, const HashMap &p_options) const { return true; } @@ -237,7 +237,7 @@ static Error process_scene_node_recursively(const Data &data, int node_id, Node3 // } Error VoxelVoxSceneImporter::import(const String &p_source_file, const String &p_save_path, - const Map &p_options, List *r_platform_variants, List *r_gen_files, + const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { ZN_PROFILE_SCOPE(); diff --git a/editor/vox/vox_scene_importer.h b/editor/vox/vox_scene_importer.h index 213d1d13..72f1fe53 100644 --- a/editor/vox/vox_scene_importer.h +++ b/editor/vox/vox_scene_importer.h @@ -20,9 +20,9 @@ public: //int get_import_order() const override; void get_import_options(const String &p_path, List *r_options, int p_preset = 0) const override; bool get_option_visibility( - const String &p_path, const String &p_option, const Map &p_options) const override; + const String &p_path, const String &p_option, const HashMap &p_options) const override; - Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, + Error import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata = nullptr) override; }; diff --git a/meshers/dmc/mesh_builder.h b/meshers/dmc/mesh_builder.h index 8e939c2c..f7ac225f 100644 --- a/meshers/dmc/mesh_builder.h +++ b/meshers/dmc/mesh_builder.h @@ -2,8 +2,8 @@ #define MESH_BUILDER_H #include "../../util/math/vector3f.h" -#include #include +#include #include namespace zylann::voxel::dmc { @@ -16,15 +16,15 @@ public: inline void add_vertex(Vector3f position, Vector3f normal) { int i = 0; - Map::Element *e = _position_to_index.find(position); + std::map::iterator it = _position_to_index.find(position); - if (e) { - i = e->get(); + if (it != _position_to_index.end()) { + i = it->second; ++_reused_vertices; } else { i = _positions.size(); - _position_to_index.insert(position, i); + _position_to_index.insert({ position, i }); _positions.push_back(position); _normals.push_back(normal); @@ -45,7 +45,7 @@ private: std::vector _positions; std::vector _normals; std::vector _indices; - Map _position_to_index; + std::map _position_to_index; int _reused_vertices; }; diff --git a/terrain/instancing/voxel_instance_library.cpp b/terrain/instancing/voxel_instance_library.cpp index e48934a3..63c9cbdc 100644 --- a/terrain/instancing/voxel_instance_library.cpp +++ b/terrain/instancing/voxel_instance_library.cpp @@ -9,35 +9,38 @@ namespace zylann::voxel { VoxelInstanceLibrary::~VoxelInstanceLibrary() { - for_each_item([this](int id, VoxelInstanceLibraryItem &item) { item.remove_listener(this, id); }); + for_each_item([this](int id, VoxelInstanceLibraryItem &item) { // + item.remove_listener(this, id); + }); } int VoxelInstanceLibrary::get_next_available_id() { - if (_items.is_empty()) { + if (_items.empty()) { return 1; } else { - return _items.back()->key() + 1; + // Get highest key and increment it + return _items.rbegin()->first + 1; } } void VoxelInstanceLibrary::add_item(int id, Ref item) { - ERR_FAIL_COND(_items.has(id)); + ERR_FAIL_COND_MSG(_items.find(id) != _items.end(), "An item with the same ID is already registered"); ERR_FAIL_COND(id < 0 || id >= MAX_ID); ERR_FAIL_COND(item.is_null()); - _items.insert(id, item); + _items.insert({ id, item }); item->add_listener(this, id); notify_listeners(id, VoxelInstanceLibraryItem::CHANGE_ADDED); notify_property_list_changed(); } void VoxelInstanceLibrary::remove_item(int id) { - Map>::Element *E = _items.find(id); - ERR_FAIL_COND(E == nullptr); - Ref item = E->value(); + auto it = _items.find(id); + ERR_FAIL_COND_MSG(it == _items.end(), "Cannot remove unregistered item"); + Ref item = it->second; if (item.is_valid()) { item->remove_listener(this, id); } - _items.erase(E); + _items.erase(it); notify_listeners(id, VoxelInstanceLibraryItem::CHANGE_REMOVED); notify_property_list_changed(); } @@ -51,11 +54,11 @@ void VoxelInstanceLibrary::clear() { } int VoxelInstanceLibrary::find_item_by_name(String name) const { - for (Map>::Element *E = _items.front(); E != nullptr; E = E->next()) { - const Ref &item = E->value(); + for (auto it = _items.begin(); it != _items.end(); ++it) { + const Ref &item = it->second; ERR_FAIL_COND_V(item.is_null(), -1); if (item->get_name() == name) { - return E->key(); + return it->first; } } return -1; @@ -65,19 +68,19 @@ int VoxelInstanceLibrary::get_item_count() const { return _items.size(); } -Ref VoxelInstanceLibrary::_b_get_item(int id) { - Map>::Element *E = _items.find(id); +Ref VoxelInstanceLibrary::_b_get_item(int id) const { + auto it = _items.find(id); Ref item; - if (E != nullptr) { - item = E->value(); + if (it != _items.end()) { + item = it->second; } return item; } VoxelInstanceLibraryItem *VoxelInstanceLibrary::get_item(int id) { - Map>::Element *E = _items.find(id); - if (E != nullptr) { - Ref &item = E->value(); + auto it = _items.find(id); + if (it != _items.end()) { + Ref &item = it->second; ERR_FAIL_COND_V(item.is_null(), nullptr); return *item; } @@ -85,9 +88,9 @@ VoxelInstanceLibraryItem *VoxelInstanceLibrary::get_item(int id) { } const VoxelInstanceLibraryItem *VoxelInstanceLibrary::get_item_const(int id) const { - const Map>::Element *E = _items.find(id); - if (E != nullptr) { - const Ref &item = E->value(); + auto it = _items.find(id); + if (it != _items.end()) { + const Ref &item = it->second; ERR_FAIL_COND_V(item.is_null(), nullptr); return *item; } @@ -125,20 +128,20 @@ bool VoxelInstanceLibrary::_set(const StringName &p_name, const Variant &p_value Ref item = p_value; ERR_FAIL_COND_V_MSG(item.is_null(), false, "Setting a null item is not allowed"); - Map>::Element *E = _items.find(id); + auto it = _items.find(id); - if (E == nullptr) { + if (it == _items.end()) { add_item(id, item); } else { // Replace - if (E->value() != item) { - Ref old_item = E->value(); + if (it->second != item) { + Ref old_item = it->second; if (old_item.is_valid()) { old_item->remove_listener(this, id); notify_listeners(id, VoxelInstanceLibraryItem::CHANGE_REMOVED); } - E->value() = item; + it->second = item; item->add_listener(this, id); notify_listeners(id, VoxelInstanceLibraryItem::CHANGE_ADDED); } @@ -153,9 +156,9 @@ bool VoxelInstanceLibrary::_get(const StringName &p_name, Variant &r_ret) const const String name = p_name; if (name.begins_with("item_")) { const int id = name.substr(5).to_int(); - const Map>::Element *E = _items.find(id); - if (E != nullptr) { - r_ret = E->value(); + auto it = _items.find(id); + if (it != _items.end()) { + r_ret = it->second; return true; } } @@ -163,8 +166,8 @@ bool VoxelInstanceLibrary::_get(const StringName &p_name, Variant &r_ret) const } void VoxelInstanceLibrary::_get_property_list(List *p_list) const { - for (Map>::Element *E = _items.front(); E != nullptr; E = E->next()) { - const String name = "item_" + itos(E->key()); + for (auto it = _items.begin(); it != _items.end(); ++it) { + const String name = "item_" + itos(it->first); p_list->push_back(PropertyInfo(Variant::OBJECT, name, PROPERTY_HINT_RESOURCE_TYPE, "VoxelInstanceLibraryItem")); } } diff --git a/terrain/instancing/voxel_instance_library.h b/terrain/instancing/voxel_instance_library.h index 148650e8..37c7eaa4 100644 --- a/terrain/instancing/voxel_instance_library.h +++ b/terrain/instancing/voxel_instance_library.h @@ -2,6 +2,7 @@ #define VOXEL_INSTANCE_MODEL_LIBRARY_H #include "voxel_instance_library_item.h" +#include namespace zylann::voxel { @@ -30,11 +31,12 @@ public: const VoxelInstanceLibraryItem *get_item_const(int id) const; VoxelInstanceLibraryItem *get_item(int id); + // f(int item_id, VoxelInstanceLibraryItem &item) template void for_each_item(F f) { - for (Map>::Element *E = _items.front(); E != nullptr; E = E->next()) { - CRASH_COND(E->value().is_null()); - f(E->key(), **E->value()); + for (auto it = _items.begin(); it != _items.end(); ++it) { + ZN_ASSERT(it->second.is_valid()); + f(it->first, **it->second); } } @@ -42,7 +44,7 @@ public: void remove_listener(IListener *listener); protected: - Ref _b_get_item(int id); + Ref _b_get_item(int id) const; bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -55,8 +57,8 @@ private: static void _bind_methods(); // ID => Item - // Using a Map keeps items ordered, so the last item has highest ID - Map> _items; + // Using a map keeps items ordered, so the last item has highest ID + std::map> _items; std::vector _listeners; }; diff --git a/terrain/variable_lod/voxel_lod_terrain.cpp b/terrain/variable_lod/voxel_lod_terrain.cpp index 65f3736a..11508461 100644 --- a/terrain/variable_lod/voxel_lod_terrain.cpp +++ b/terrain/variable_lod/voxel_lod_terrain.cpp @@ -433,9 +433,10 @@ void VoxelLodTerrain::set_mesh_block_size(unsigned int mesh_block_size) { // Reset LOD octrees LodOctree::NoDestroyAction nda; - for (Map::Element *E = state.lod_octrees.front(); E; - E = E->next()) { - VoxelLodTerrainUpdateData::OctreeItem &item = E->value(); + + for (std::map::iterator it = state.lod_octrees.begin(); + it != state.lod_octrees.end(); ++it) { + VoxelLodTerrainUpdateData::OctreeItem &item = it->second; item.octree.create(lod_count, nda); } @@ -498,10 +499,10 @@ void VoxelLodTerrain::set_mesh_block_active(VoxelMeshBlockVLT &block, bool activ if (block.fading_state != fading_state) { if (block.fading_state == VoxelMeshBlockVLT::FADING_NONE) { - Map &fading_blocks = _fading_blocks_per_lod[block.lod_index]; + std::map &fading_blocks = _fading_blocks_per_lod[block.lod_index]; // Must not have duplicates - ERR_FAIL_COND(fading_blocks.has(block.position)); - fading_blocks.insert(block.position, &block); + ERR_FAIL_COND(fading_blocks.find(block.position) != fading_blocks.end()); + fading_blocks.insert({ block.position, &block }); } block.fading_state = fading_state; block.fading_progress = initial_progress; @@ -812,9 +813,9 @@ void VoxelLodTerrain::_set_lod_count(int p_lod_count) { LodOctree::NoDestroyAction nda; - for (Map::Element *E = _update_data->state.lod_octrees.front(); E; - E = E->next()) { - VoxelLodTerrainUpdateData::OctreeItem &item = E->value(); + std::map &octrees = _update_data->state.lod_octrees; + for (auto it = octrees.begin(); it != octrees.end(); ++it) { + VoxelLodTerrainUpdateData::OctreeItem &item = it->second; item.octree.create(p_lod_count, nda); } @@ -1584,24 +1585,23 @@ void VoxelLodTerrain::process_fading_blocks(float delta) { const float speed = _lod_fade_duration < 0.001f ? 99999.f : delta / _lod_fade_duration; for (unsigned int lod_index = 0; lod_index < _fading_blocks_per_lod.size(); ++lod_index) { - Map &fading_blocks = _fading_blocks_per_lod[lod_index]; + std::map &fading_blocks = _fading_blocks_per_lod[lod_index]; + std::map::iterator it = fading_blocks.begin(); - Map::Element *e = fading_blocks.front(); - - while (e != nullptr) { - VoxelMeshBlockVLT *block = e->value(); + while (it != fading_blocks.end()) { + VoxelMeshBlockVLT *block = it->second; + ZN_ASSERT(block != nullptr); // The collection of fading blocks must only contain fading blocks ERR_FAIL_COND(block->fading_state == VoxelMeshBlockVLT::FADING_NONE); const bool finished = block->update_fading(speed); if (finished) { - Map::Element *next = e->next(); - fading_blocks.erase(e); - e = next; + // `erase` returns the next iterator + it = fading_blocks.erase(it); } else { - e = e->next(); + ++it; } } } @@ -1928,11 +1928,11 @@ Dictionary VoxelLodTerrain::debug_get_mesh_block_info(Vector3 fbpos, int lod_ind Array VoxelLodTerrain::debug_get_octree_positions() const { _update_data->wait_for_end_of_task(); Array positions; - const Map &octrees = _update_data->state.lod_octrees; + const std::map &octrees = _update_data->state.lod_octrees; positions.resize(octrees.size()); int i = 0; - for (Map::Element *e = octrees.front(); e; e = e->next()) { - positions[i++] = e->key(); + for (auto it = octrees.begin(); it != octrees.end(); ++it) { + positions[i++] = it->first; } return positions; } @@ -1992,15 +1992,15 @@ Array VoxelLodTerrain::debug_get_octrees_detailed() const { _update_data->wait_for_end_of_task(); - const Map &octrees = _update_data->state.lod_octrees; + const std::map &octrees = _update_data->state.lod_octrees; Array forest_data; - for (const Map::Element *e = octrees.front(); e; e = e->next()) { - const LodOctree &octree = e->value().octree; + for (auto it = octrees.begin(); it != octrees.end(); ++it) { + const LodOctree &octree = it->second.octree; const LodOctree::Node *root = octree.get_root(); Array root_data; - const Vector3i octree_pos = e->key(); + const Vector3i octree_pos = it->first; L::read_node(octree, root, octree_pos, get_lod_count() - 1, _update_data->state, root_data); forest_data.append(octree_pos); forest_data.append(root_data); @@ -2033,9 +2033,9 @@ void VoxelLodTerrain::update_gizmos() { if (_show_octree_bounds_gizmos) { const int octree_size = 1 << LodOctree::get_octree_size_po2(get_mesh_block_size_pow2(), get_lod_count()); const Basis local_octree_basis = Basis().scaled(Vector3(octree_size, octree_size, octree_size)); - for (Map::Element *e = state.lod_octrees.front(); e; - e = e->next()) { - const Transform3D local_transform(local_octree_basis, e->key() * octree_size); + + for (auto it = state.lod_octrees.begin(); it != state.lod_octrees.end(); ++it) { + const Transform3D local_transform(local_octree_basis, it->first * octree_size); dr.draw_box(parent_transform * local_transform, DebugColors::ID_OCTREE_BOUNDS); } } @@ -2044,6 +2044,7 @@ void VoxelLodTerrain::update_gizmos() { if (_show_volume_bounds_gizmos) { const Box3i bounds_in_voxels = get_voxel_bounds(); const float bounds_in_voxels_len = Vector3(bounds_in_voxels.size).length(); + if (bounds_in_voxels_len < 10000) { const Vector3 margin = Vector3(1, 1, 1) * bounds_in_voxels_len * 0.0025f; const Vector3 size = bounds_in_voxels.size; @@ -2058,11 +2059,11 @@ void VoxelLodTerrain::update_gizmos() { // That can be expensive to draw const int mesh_block_size = get_mesh_block_size(); const float lod_count_f = lod_count; - for (Map::Element *e = state.lod_octrees.front(); e; - e = e->next()) { - const LodOctree &octree = e->value().octree; - const Vector3i block_pos_maxlod = e->key(); + for (auto it = state.lod_octrees.begin(); it != state.lod_octrees.end(); ++it) { + const LodOctree &octree = it->second.octree; + + const Vector3i block_pos_maxlod = it->first; const Vector3i block_offset_lod0 = block_pos_maxlod << (lod_count - 1); octree.for_each_leaf([&dr, block_offset_lod0, mesh_block_size, parent_transform, lod_count_f]( diff --git a/terrain/variable_lod/voxel_lod_terrain.h b/terrain/variable_lod/voxel_lod_terrain.h index ab2cb7bb..9b9687b0 100644 --- a/terrain/variable_lod/voxel_lod_terrain.h +++ b/terrain/variable_lod/voxel_lod_terrain.h @@ -10,6 +10,7 @@ #include "voxel_lod_terrain_update_data.h" #include "voxel_mesh_block_vlt.h" +#include #include #ifdef TOOLS_ENABLED @@ -311,7 +312,7 @@ private: // Note, direct pointers to mesh blocks should be safe because these blocks are always destroyed from the same // thread that updates fading blocks. If a mesh block is destroyed, these maps should be updated at the same time. // TODO Optimization: use FlatMap? Need to check how many blocks get in there, probably not many - FixedArray, constants::MAX_LOD> _fading_blocks_per_lod; + FixedArray, constants::MAX_LOD> _fading_blocks_per_lod; VoxelInstancer *_instancer = nullptr; diff --git a/terrain/variable_lod/voxel_lod_terrain_update_data.h b/terrain/variable_lod/voxel_lod_terrain_update_data.h index 34fb2fa1..62181863 100644 --- a/terrain/variable_lod/voxel_lod_terrain_update_data.h +++ b/terrain/variable_lod/voxel_lod_terrain_update_data.h @@ -9,6 +9,7 @@ #include "../voxel_mesh_map.h" #include "lod_octree.h" +#include #include namespace zylann { @@ -140,7 +141,7 @@ struct VoxelLodTerrainUpdateData { // Indexed by a grid coordinate whose step is the size of the highest-LOD block. // Not using a pointer because Map storage is stable. // TODO Optimization: could be replaced with a grid data structure - Map lod_octrees; + std::map lod_octrees; Box3i last_octree_region_box; Vector3i local_viewer_pos_previous_octree_update; bool had_blocked_octree_nodes_previous_update = false; diff --git a/terrain/variable_lod/voxel_lod_terrain_update_task.cpp b/terrain/variable_lod/voxel_lod_terrain_update_task.cpp index 91668f0c..1e1f82c3 100644 --- a/terrain/variable_lod/voxel_lod_terrain_update_task.cpp +++ b/terrain/variable_lod/voxel_lod_terrain_update_task.cpp @@ -397,13 +397,13 @@ void process_octrees_sliding_box(VoxelLodTerrainUpdateData::State &state, Vector unsigned int lod_count; void operator()(const Vector3i &pos) { - Map::Element *E = state.lod_octrees.find(pos); - if (E == nullptr) { + std::map::iterator it = state.lod_octrees.find(pos); + if (it == state.lod_octrees.end()) { return; } - VoxelLodTerrainUpdateData::OctreeItem &item = E->value(); - const Vector3i block_pos_maxlod = E->key(); + VoxelLodTerrainUpdateData::OctreeItem &item = it->second; + const Vector3i block_pos_maxlod = it->first; const unsigned int last_lod_index = lod_count - 1; @@ -413,7 +413,7 @@ void process_octrees_sliding_box(VoxelLodTerrainUpdateData::State &state, Vector CleanOctreeAction a{ state, block_pos_maxlod << last_lod_index }; item.octree.clear(a); - state.lod_octrees.erase(E); + state.lod_octrees.erase(it); // Unload last lod from here, as it may extend a bit further than the others. // Other LODs are unloaded earlier using a sliding region. @@ -429,14 +429,14 @@ void process_octrees_sliding_box(VoxelLodTerrainUpdateData::State &state, Vector void operator()(const Vector3i &pos) { // That's a new cell we are entering, shouldn't be anything there - CRASH_COND(state.lod_octrees.has(pos)); + CRASH_COND(state.lod_octrees.find(pos) != state.lod_octrees.end()); // Create new octree // TODO Use ObjectPool to store them, deletion won't be cheap - Map::Element *E = - state.lod_octrees.insert(pos, VoxelLodTerrainUpdateData::OctreeItem()); - CRASH_COND(E == nullptr); - VoxelLodTerrainUpdateData::OctreeItem &item = E->value(); + std::pair::iterator, bool> p = + state.lod_octrees.insert({ pos, VoxelLodTerrainUpdateData::OctreeItem() }); + CRASH_COND(p.second == false); + VoxelLodTerrainUpdateData::OctreeItem &item = p.first->second; LodOctree::NoDestroyAction nda; item.octree.create(lod_count, nda); } @@ -824,8 +824,7 @@ static void process_octrees_fitting(VoxelLodTerrainUpdateData::State &state, unsigned int blocked_octree_nodes = 0; // TODO Maintain a vector to make iteration faster? - for (Map::Element *E = state.lod_octrees.front(); E; - E = E->next()) { + for (auto octree_it = state.lod_octrees.begin(); octree_it != state.lod_octrees.end(); ++octree_it) { ZN_PROFILE_SCOPE(); struct OctreeActions { @@ -969,7 +968,7 @@ static void process_octrees_fitting(VoxelLodTerrainUpdateData::State &state, } }; - const Vector3i block_pos_maxlod = E->key(); + const Vector3i block_pos_maxlod = octree_it->first; const Vector3i block_offset_lod0 = block_pos_maxlod << (settings.lod_count - 1); const Vector3 relative_viewer_pos = p_viewer_pos - Vector3(mesh_block_size * block_offset_lod0); @@ -983,7 +982,7 @@ static void process_octrees_fitting(VoxelLodTerrainUpdateData::State &state, lod_distance_octree_space, // relative_viewer_pos / octree_leaf_node_size }; - VoxelLodTerrainUpdateData::OctreeItem &item = E->value(); + VoxelLodTerrainUpdateData::OctreeItem &item = octree_it->second; item.octree.update(octree_actions); blocked_octree_nodes += octree_actions.blocked_count; diff --git a/tests/test_octree.cpp b/tests/test_octree.cpp index 4c177a71..6248fbca 100644 --- a/tests/test_octree.cpp +++ b/tests/test_octree.cpp @@ -6,7 +6,7 @@ #include "testing.h" #include -#include +#include #include #include @@ -22,13 +22,14 @@ void test_octree_update() { const int octree_size = block_size << (lod_count - 1); // Testing as an octree forest, as it is the way they are used in VoxelLodTerrain - Map octrees; + std::map octrees; const Box3i viewer_box_voxels = Box3i::from_center_extents(math::floor_to_int(viewer_pos), Vector3iUtil::create(view_distance)); const Box3i viewer_box_octrees = viewer_box_voxels.downscaled(octree_size); viewer_box_octrees.for_each_cell([&octrees](Vector3i pos) { - Map::Element *e = octrees.insert(pos, LodOctree()); - LodOctree &octree = e->value(); + std::pair::iterator, bool> p = octrees.insert({ pos, LodOctree() }); + ZN_ASSERT(p.second); + LodOctree &octree = p.first->second; LodOctree::NoDestroyAction nda; octree.create(lod_count, nda); }); @@ -70,10 +71,10 @@ void test_octree_update() { ProfilingClock profiling_clock; // Initial - for (Map::Element *e = octrees.front(); e; e = e->next()) { - LodOctree &octree = e->value(); + for (std::map::iterator it = octrees.begin(); it != octrees.end(); ++it) { + LodOctree &octree = it->second; - const Vector3i block_pos_maxlod = e->key(); + const Vector3i block_pos_maxlod = it->first; const Vector3i block_offset_lod0 = block_pos_maxlod << (lod_count - 1); const Vector3 relative_viewer_pos = viewer_pos - block_size_v * Vector3(block_offset_lod0); @@ -89,8 +90,8 @@ void test_octree_update() { const int time_init = profiling_clock.restart(); int initial_block_count_rec = 0; - for (Map::Element *e = octrees.front(); e; e = e->next()) { - const LodOctree &octree = e->value(); + for (std::map::iterator it = octrees.begin(); it != octrees.end(); ++it) { + const LodOctree &octree = it->second; initial_block_count_rec += octree.get_node_count(); } @@ -105,10 +106,10 @@ void test_octree_update() { profiling_clock.restart(); created_block_count = 0; - for (Map::Element *e = octrees.front(); e; e = e->next()) { - LodOctree &octree = e->value(); + for (std::map::iterator it = octrees.begin(); it != octrees.end(); ++it) { + LodOctree &octree = it->second; - const Vector3i block_pos_maxlod = e->key(); + const Vector3i block_pos_maxlod = it->first; const Vector3i block_offset_lod0 = block_pos_maxlod << (lod_count - 1); const Vector3 relative_viewer_pos = viewer_pos - block_size_v * Vector3(block_offset_lod0); @@ -131,8 +132,8 @@ void test_octree_update() { // Clearing int block_count = initial_block_count; - for (Map::Element *e = octrees.front(); e; e = e->next()) { - LodOctree &octree = e->value(); + for (std::map::iterator it = octrees.begin(); it != octrees.end(); ++it) { + LodOctree &octree = it->second; struct DestroyAction { int destroyed_blocks = 0;