Skip to content

Commit aab8dd6

Browse files
committed
Replace GridMap legacy use of List with LocalVector
Replaces GridMap legacy use of List with LocalVector.
1 parent 2d3bdca commit aab8dd6

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

modules/gridmap/editor/grid_map_editor_plugin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera3D
813813
for (const SetItem &si : set_items) {
814814
undo_redo->add_do_method(node, "set_cell_item", si.position, si.new_value, si.new_orientation);
815815
}
816-
for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
817-
const SetItem &si = E->get();
816+
for (uint32_t i = set_items.size(); i > 0; i--) {
817+
const SetItem &si = set_items[i - 1];
818818
undo_redo->add_undo_method(node, "set_cell_item", si.position, si.old_value, si.old_orientation);
819819
}
820820

@@ -1380,6 +1380,8 @@ GridMapEditor::GridMapEditor() {
13801380
toolbar->add_child(mode_buttons);
13811381
mode_buttons_group.instantiate();
13821382

1383+
viewport_shortcut_buttons.reserve(12);
1384+
13831385
transform_mode_button = memnew(Button);
13841386
transform_mode_button->set_theme_type_variation(SceneStringName(FlatButton));
13851387
transform_mode_button->set_toggle_mode(true);

modules/gridmap/editor/grid_map_editor_plugin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GridMapEditor : public VBoxContainer {
7474
double accumulated_floor_delta = 0.0;
7575

7676
HBoxContainer *toolbar = nullptr;
77-
List<BaseButton *> viewport_shortcut_buttons;
77+
TightLocalVector<BaseButton *> viewport_shortcut_buttons;
7878
Ref<ButtonGroup> mode_buttons_group;
7979
// mode
8080
Button *transform_mode_button = nullptr;
@@ -110,7 +110,7 @@ class GridMapEditor : public VBoxContainer {
110110
int old_orientation = 0;
111111
};
112112

113-
List<SetItem> set_items;
113+
LocalVector<SetItem> set_items;
114114

115115
GridMap *node = nullptr;
116116
Ref<MeshLibrary> mesh_library = nullptr;
@@ -139,7 +139,7 @@ class GridMapEditor : public VBoxContainer {
139139
RID instance;
140140
};
141141

142-
List<ClipboardItem> clipboard_items;
142+
LocalVector<ClipboardItem> clipboard_items;
143143

144144
Color default_color;
145145
Color erase_color;

modules/gridmap/grid_map.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/io/marshalls.h"
3434
#include "core/math/convex_hull.h"
35+
#include "core/templates/a_hash_map.h"
3536
#include "scene/resources/3d/box_shape_3d.h"
3637
#include "scene/resources/3d/capsule_shape_3d.h"
3738
#include "scene/resources/3d/concave_polygon_shape_3d.h"
@@ -619,7 +620,11 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
619620
* and set said multimesh bounding box to one containing all cells which have this item
620621
*/
621622

622-
HashMap<int, List<Pair<Transform3D, IndexKey>>> multimesh_items;
623+
struct MultiMeshItemPlacement {
624+
Transform3D transform;
625+
IndexKey index_key;
626+
};
627+
AHashMap<int, LocalVector<MultiMeshItemPlacement>> item_id_to_multimesh_item_placements;
623628

624629
for (const IndexKey &E : g.cells) {
625630
ERR_CONTINUE(!cell_map.has(E));
@@ -639,14 +644,14 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
639644
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
640645
if (baked_meshes.is_empty()) {
641646
if (mesh_library->get_item_mesh(c.item).is_valid()) {
642-
if (!multimesh_items.has(c.item)) {
643-
multimesh_items[c.item] = List<Pair<Transform3D, IndexKey>>();
647+
if (!item_id_to_multimesh_item_placements.has(c.item)) {
648+
item_id_to_multimesh_item_placements[c.item] = LocalVector<MultiMeshItemPlacement>();
644649
}
645650

646-
Pair<Transform3D, IndexKey> p;
647-
p.first = xform * mesh_library->get_item_mesh_transform(c.item);
648-
p.second = E;
649-
multimesh_items[c.item].push_back(p);
651+
MultiMeshItemPlacement p;
652+
p.transform = xform * mesh_library->get_item_mesh_transform(c.item);
653+
p.index_key = E;
654+
item_id_to_multimesh_item_placements[c.item].push_back(p);
650655
}
651656
}
652657

@@ -717,22 +722,23 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
717722

718723
//update multimeshes, only if not baked
719724
if (baked_meshes.is_empty()) {
720-
for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) {
725+
for (const KeyValue<int, LocalVector<MultiMeshItemPlacement>> &E : item_id_to_multimesh_item_placements) {
721726
Octant::MultimeshInstance mmi;
722727

723728
RID mm = RS::get_singleton()->multimesh_create();
724729
RS::get_singleton()->multimesh_allocate_data(mm, E.value.size(), RS::MULTIMESH_TRANSFORM_3D);
725730
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E.key)->get_rid());
726731

727732
int idx = 0;
728-
for (const Pair<Transform3D, IndexKey> &F : E.value) {
729-
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first);
733+
const LocalVector<MultiMeshItemPlacement> &mm_item_placements = E.value;
734+
for (const MultiMeshItemPlacement &mm_item_placement : mm_item_placements) {
735+
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, mm_item_placement.transform);
730736
#ifdef TOOLS_ENABLED
731737

732738
Octant::MultimeshInstance::Item it;
733739
it.index = idx;
734-
it.transform = F.first;
735-
it.key = F.second;
740+
it.transform = mm_item_placement.transform;
741+
it.key = mm_item_placement.index_key;
736742
mmi.items.push_back(it);
737743
#endif
738744

@@ -1089,17 +1095,19 @@ void GridMap::_update_octants_callback() {
10891095
return;
10901096
}
10911097

1092-
List<OctantKey> to_delete;
1098+
LocalVector<OctantKey> to_delete;
1099+
to_delete.reserve(octant_map.size());
10931100
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
10941101
if (_octant_update(E.key)) {
10951102
to_delete.push_back(E.key);
10961103
}
10971104
}
10981105

1099-
while (to_delete.front()) {
1100-
memdelete(octant_map[to_delete.front()->get()]);
1101-
octant_map.erase(to_delete.front()->get());
1102-
to_delete.pop_front();
1106+
while (!to_delete.is_empty()) {
1107+
const OctantKey &octantkey = to_delete[0];
1108+
memdelete(octant_map[octantkey]);
1109+
octant_map.erase(octantkey);
1110+
to_delete.remove_at_unordered(0);
11031111
}
11041112

11051113
_update_visibility();

0 commit comments

Comments
 (0)