Removed usages of Map

This commit is contained in:
Marc Gilleron 2022-05-17 19:44:58 +01:00
parent 3026f6b5a3
commit 4f862722ae
12 changed files with 122 additions and 114 deletions

View File

@ -57,7 +57,7 @@ void VoxelVoxMeshImporter::get_import_options(const String &p_path, List<ImportO
}
bool VoxelVoxMeshImporter::get_option_visibility(
const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
const String &p_path, const String &p_option, const HashMap<StringName, Variant> &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<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files,
const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files,
Variant *r_metadata) {
//
const bool p_store_colors_in_textures = p_options[VoxelStringNames::get_singleton().store_colors_in_texture];

View File

@ -20,9 +20,9 @@ public:
//int get_import_order() const override;
void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
bool get_option_visibility(
const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options,
Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options,
List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata = nullptr) override;
enum PivotMode { //

View File

@ -61,7 +61,7 @@ void VoxelVoxSceneImporter::get_import_options(
}
bool VoxelVoxSceneImporter::get_option_visibility(
const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
const String &p_path, const String &p_option, const HashMap<StringName, Variant> &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<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files,
const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files,
Variant *r_metadata) {
ZN_PROFILE_SCOPE();

View File

@ -20,9 +20,9 @@ public:
//int get_import_order() const override;
void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
bool get_option_visibility(
const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options,
Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options,
List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata = nullptr) override;
};

View File

@ -2,8 +2,8 @@
#define MESH_BUILDER_H
#include "../../util/math/vector3f.h"
#include <core/templates/map.h>
#include <core/variant/array.h>
#include <map>
#include <vector>
namespace zylann::voxel::dmc {
@ -16,15 +16,15 @@ public:
inline void add_vertex(Vector3f position, Vector3f normal) {
int i = 0;
Map<Vector3f, int>::Element *e = _position_to_index.find(position);
std::map<Vector3f, int>::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<Vector3f> _positions;
std::vector<Vector3f> _normals;
std::vector<int> _indices;
Map<Vector3f, int> _position_to_index;
std::map<Vector3f, int> _position_to_index;
int _reused_vertices;
};

View File

@ -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<VoxelInstanceLibraryItem> 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<int, Ref<VoxelInstanceLibraryItem>>::Element *E = _items.find(id);
ERR_FAIL_COND(E == nullptr);
Ref<VoxelInstanceLibraryItem> item = E->value();
auto it = _items.find(id);
ERR_FAIL_COND_MSG(it == _items.end(), "Cannot remove unregistered item");
Ref<VoxelInstanceLibraryItem> 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<int, Ref<VoxelInstanceLibraryItem>>::Element *E = _items.front(); E != nullptr; E = E->next()) {
const Ref<VoxelInstanceLibraryItem> &item = E->value();
for (auto it = _items.begin(); it != _items.end(); ++it) {
const Ref<VoxelInstanceLibraryItem> &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<VoxelInstanceLibraryItem> VoxelInstanceLibrary::_b_get_item(int id) {
Map<int, Ref<VoxelInstanceLibraryItem>>::Element *E = _items.find(id);
Ref<VoxelInstanceLibraryItem> VoxelInstanceLibrary::_b_get_item(int id) const {
auto it = _items.find(id);
Ref<VoxelInstanceLibraryItem> item;
if (E != nullptr) {
item = E->value();
if (it != _items.end()) {
item = it->second;
}
return item;
}
VoxelInstanceLibraryItem *VoxelInstanceLibrary::get_item(int id) {
Map<int, Ref<VoxelInstanceLibraryItem>>::Element *E = _items.find(id);
if (E != nullptr) {
Ref<VoxelInstanceLibraryItem> &item = E->value();
auto it = _items.find(id);
if (it != _items.end()) {
Ref<VoxelInstanceLibraryItem> &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<int, Ref<VoxelInstanceLibraryItem>>::Element *E = _items.find(id);
if (E != nullptr) {
const Ref<VoxelInstanceLibraryItem> &item = E->value();
auto it = _items.find(id);
if (it != _items.end()) {
const Ref<VoxelInstanceLibraryItem> &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<VoxelInstanceLibraryItem> item = p_value;
ERR_FAIL_COND_V_MSG(item.is_null(), false, "Setting a null item is not allowed");
Map<int, Ref<VoxelInstanceLibraryItem>>::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<VoxelInstanceLibraryItem> old_item = E->value();
if (it->second != item) {
Ref<VoxelInstanceLibraryItem> 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<int, Ref<VoxelInstanceLibraryItem>>::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<PropertyInfo> *p_list) const {
for (Map<int, Ref<VoxelInstanceLibraryItem>>::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"));
}
}

View File

@ -2,6 +2,7 @@
#define VOXEL_INSTANCE_MODEL_LIBRARY_H
#include "voxel_instance_library_item.h"
#include <map>
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 <typename F>
void for_each_item(F f) {
for (Map<int, Ref<VoxelInstanceLibraryItem>>::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<VoxelInstanceLibraryItem> _b_get_item(int id);
Ref<VoxelInstanceLibraryItem> _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<int, Ref<VoxelInstanceLibraryItem>> _items;
// Using a map keeps items ordered, so the last item has highest ID
std::map<int, Ref<VoxelInstanceLibraryItem>> _items;
std::vector<IListener *> _listeners;
};

View File

@ -433,9 +433,10 @@ void VoxelLodTerrain::set_mesh_block_size(unsigned int mesh_block_size) {
// Reset LOD octrees
LodOctree::NoDestroyAction nda;
for (Map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::Element *E = state.lod_octrees.front(); E;
E = E->next()) {
VoxelLodTerrainUpdateData::OctreeItem &item = E->value();
for (std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelMeshBlockVLT *> &fading_blocks = _fading_blocks_per_lod[block.lod_index];
std::map<Vector3i, VoxelMeshBlockVLT *> &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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::Element *E = _update_data->state.lod_octrees.front(); E;
E = E->next()) {
VoxelLodTerrainUpdateData::OctreeItem &item = E->value();
std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem> &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<Vector3i, VoxelMeshBlockVLT *> &fading_blocks = _fading_blocks_per_lod[lod_index];
std::map<Vector3i, VoxelMeshBlockVLT *> &fading_blocks = _fading_blocks_per_lod[lod_index];
std::map<Vector3i, VoxelMeshBlockVLT *>::iterator it = fading_blocks.begin();
Map<Vector3i, VoxelMeshBlockVLT *>::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<Vector3i, VoxelMeshBlockVLT *>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem> &octrees = _update_data->state.lod_octrees;
const std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem> &octrees = _update_data->state.lod_octrees;
positions.resize(octrees.size());
int i = 0;
for (Map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem> &octrees = _update_data->state.lod_octrees;
const std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem> &octrees = _update_data->state.lod_octrees;
Array forest_data;
for (const Map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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](

View File

@ -10,6 +10,7 @@
#include "voxel_lod_terrain_update_data.h"
#include "voxel_mesh_block_vlt.h"
#include <map>
#include <unordered_set>
#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<Map<Vector3i, VoxelMeshBlockVLT *>, constants::MAX_LOD> _fading_blocks_per_lod;
FixedArray<std::map<Vector3i, VoxelMeshBlockVLT *>, constants::MAX_LOD> _fading_blocks_per_lod;
VoxelInstancer *_instancer = nullptr;

View File

@ -9,6 +9,7 @@
#include "../voxel_mesh_map.h"
#include "lod_octree.h"
#include <map>
#include <unordered_set>
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<Vector3i, OctreeItem> lod_octrees;
std::map<Vector3i, OctreeItem> lod_octrees;
Box3i last_octree_region_box;
Vector3i local_viewer_pos_previous_octree_update;
bool had_blocked_octree_nodes_previous_update = false;

View File

@ -397,13 +397,13 @@ void process_octrees_sliding_box(VoxelLodTerrainUpdateData::State &state, Vector
unsigned int lod_count;
void operator()(const Vector3i &pos) {
Map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::Element *E = state.lod_octrees.find(pos);
if (E == nullptr) {
std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::Element *E =
state.lod_octrees.insert(pos, VoxelLodTerrainUpdateData::OctreeItem());
CRASH_COND(E == nullptr);
VoxelLodTerrainUpdateData::OctreeItem &item = E->value();
std::pair<std::map<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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<Vector3i, VoxelLodTerrainUpdateData::OctreeItem>::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;

View File

@ -6,7 +6,7 @@
#include "testing.h"
#include <core/string/print_string.h>
#include <core/templates/map.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
@ -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<Vector3i, LodOctree> octrees;
std::map<Vector3i, LodOctree> 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<Vector3i, LodOctree>::Element *e = octrees.insert(pos, LodOctree());
LodOctree &octree = e->value();
std::pair<std::map<Vector3i, LodOctree>::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<Vector3i, LodOctree>::Element *e = octrees.front(); e; e = e->next()) {
LodOctree &octree = e->value();
for (std::map<Vector3i, LodOctree>::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<Vector3i, LodOctree>::Element *e = octrees.front(); e; e = e->next()) {
const LodOctree &octree = e->value();
for (std::map<Vector3i, LodOctree>::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<Vector3i, LodOctree>::Element *e = octrees.front(); e; e = e->next()) {
LodOctree &octree = e->value();
for (std::map<Vector3i, LodOctree>::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<Vector3i, LodOctree>::Element *e = octrees.front(); e; e = e->next()) {
LodOctree &octree = e->value();
for (std::map<Vector3i, LodOctree>::iterator it = octrees.begin(); it != octrees.end(); ++it) {
LodOctree &octree = it->second;
struct DestroyAction {
int destroyed_blocks = 0;