mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #105565 from smix8/gridmap_list
Replace GridMap legacy use of `List` with `LocalVector`
This commit is contained in:
commit
0ed1c192e8
3 changed files with 32 additions and 22 deletions
|
@ -815,8 +815,8 @@ EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera3D
|
||||||
for (const SetItem &si : set_items) {
|
for (const SetItem &si : set_items) {
|
||||||
undo_redo->add_do_method(node, "set_cell_item", si.position, si.new_value, si.new_orientation);
|
undo_redo->add_do_method(node, "set_cell_item", si.position, si.new_value, si.new_orientation);
|
||||||
}
|
}
|
||||||
for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
|
for (uint32_t i = set_items.size(); i > 0; i--) {
|
||||||
const SetItem &si = E->get();
|
const SetItem &si = set_items[i - 1];
|
||||||
undo_redo->add_undo_method(node, "set_cell_item", si.position, si.old_value, si.old_orientation);
|
undo_redo->add_undo_method(node, "set_cell_item", si.position, si.old_value, si.old_orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1387,6 +1387,8 @@ GridMapEditor::GridMapEditor() {
|
||||||
toolbar->add_child(mode_buttons);
|
toolbar->add_child(mode_buttons);
|
||||||
mode_buttons_group.instantiate();
|
mode_buttons_group.instantiate();
|
||||||
|
|
||||||
|
viewport_shortcut_buttons.reserve(12);
|
||||||
|
|
||||||
transform_mode_button = memnew(Button);
|
transform_mode_button = memnew(Button);
|
||||||
transform_mode_button->set_theme_type_variation(SceneStringName(FlatButton));
|
transform_mode_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||||
transform_mode_button->set_toggle_mode(true);
|
transform_mode_button->set_toggle_mode(true);
|
||||||
|
|
|
@ -74,7 +74,7 @@ class GridMapEditor : public VBoxContainer {
|
||||||
double accumulated_floor_delta = 0.0;
|
double accumulated_floor_delta = 0.0;
|
||||||
|
|
||||||
HBoxContainer *toolbar = nullptr;
|
HBoxContainer *toolbar = nullptr;
|
||||||
List<BaseButton *> viewport_shortcut_buttons;
|
TightLocalVector<BaseButton *> viewport_shortcut_buttons;
|
||||||
Ref<ButtonGroup> mode_buttons_group;
|
Ref<ButtonGroup> mode_buttons_group;
|
||||||
// mode
|
// mode
|
||||||
Button *transform_mode_button = nullptr;
|
Button *transform_mode_button = nullptr;
|
||||||
|
@ -110,7 +110,7 @@ class GridMapEditor : public VBoxContainer {
|
||||||
int old_orientation = 0;
|
int old_orientation = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
List<SetItem> set_items;
|
LocalVector<SetItem> set_items;
|
||||||
|
|
||||||
GridMap *node = nullptr;
|
GridMap *node = nullptr;
|
||||||
Ref<MeshLibrary> mesh_library = nullptr;
|
Ref<MeshLibrary> mesh_library = nullptr;
|
||||||
|
@ -139,7 +139,7 @@ class GridMapEditor : public VBoxContainer {
|
||||||
RID instance;
|
RID instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
List<ClipboardItem> clipboard_items;
|
LocalVector<ClipboardItem> clipboard_items;
|
||||||
|
|
||||||
Color default_color;
|
Color default_color;
|
||||||
Color erase_color;
|
Color erase_color;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
#include "core/io/marshalls.h"
|
#include "core/io/marshalls.h"
|
||||||
#include "core/math/convex_hull.h"
|
#include "core/math/convex_hull.h"
|
||||||
|
#include "core/templates/a_hash_map.h"
|
||||||
#include "scene/resources/3d/box_shape_3d.h"
|
#include "scene/resources/3d/box_shape_3d.h"
|
||||||
#include "scene/resources/3d/capsule_shape_3d.h"
|
#include "scene/resources/3d/capsule_shape_3d.h"
|
||||||
#include "scene/resources/3d/concave_polygon_shape_3d.h"
|
#include "scene/resources/3d/concave_polygon_shape_3d.h"
|
||||||
|
@ -644,7 +645,11 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||||
* and set said multimesh bounding box to one containing all cells which have this item
|
* and set said multimesh bounding box to one containing all cells which have this item
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HashMap<int, List<Pair<Transform3D, IndexKey>>> multimesh_items;
|
struct MultiMeshItemPlacement {
|
||||||
|
Transform3D transform;
|
||||||
|
IndexKey index_key;
|
||||||
|
};
|
||||||
|
AHashMap<int, LocalVector<MultiMeshItemPlacement>> item_id_to_multimesh_item_placements;
|
||||||
|
|
||||||
RID scenario;
|
RID scenario;
|
||||||
#ifndef NAVIGATION_3D_DISABLED
|
#ifndef NAVIGATION_3D_DISABLED
|
||||||
|
@ -676,14 +681,14 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||||
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
|
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
|
||||||
if (baked_meshes.is_empty()) {
|
if (baked_meshes.is_empty()) {
|
||||||
if (mesh_library->get_item_mesh(c.item).is_valid()) {
|
if (mesh_library->get_item_mesh(c.item).is_valid()) {
|
||||||
if (!multimesh_items.has(c.item)) {
|
if (!item_id_to_multimesh_item_placements.has(c.item)) {
|
||||||
multimesh_items[c.item] = List<Pair<Transform3D, IndexKey>>();
|
item_id_to_multimesh_item_placements[c.item] = LocalVector<MultiMeshItemPlacement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<Transform3D, IndexKey> p;
|
MultiMeshItemPlacement p;
|
||||||
p.first = xform * mesh_library->get_item_mesh_transform(c.item);
|
p.transform = xform * mesh_library->get_item_mesh_transform(c.item);
|
||||||
p.second = E;
|
p.index_key = E;
|
||||||
multimesh_items[c.item].push_back(p);
|
item_id_to_multimesh_item_placements[c.item].push_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,7 +759,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||||
|
|
||||||
//update multimeshes, only if not baked
|
//update multimeshes, only if not baked
|
||||||
if (baked_meshes.is_empty()) {
|
if (baked_meshes.is_empty()) {
|
||||||
for (const KeyValue<int, List<Pair<Transform3D, IndexKey>>> &E : multimesh_items) {
|
for (const KeyValue<int, LocalVector<MultiMeshItemPlacement>> &E : item_id_to_multimesh_item_placements) {
|
||||||
Octant::MultimeshInstance mmi;
|
Octant::MultimeshInstance mmi;
|
||||||
|
|
||||||
RID mm = RS::get_singleton()->multimesh_create();
|
RID mm = RS::get_singleton()->multimesh_create();
|
||||||
|
@ -762,14 +767,15 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||||
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E.key)->get_rid());
|
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E.key)->get_rid());
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const Pair<Transform3D, IndexKey> &F : E.value) {
|
const LocalVector<MultiMeshItemPlacement> &mm_item_placements = E.value;
|
||||||
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first);
|
for (const MultiMeshItemPlacement &mm_item_placement : mm_item_placements) {
|
||||||
|
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, mm_item_placement.transform);
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
||||||
Octant::MultimeshInstance::Item it;
|
Octant::MultimeshInstance::Item it;
|
||||||
it.index = idx;
|
it.index = idx;
|
||||||
it.transform = F.first;
|
it.transform = mm_item_placement.transform;
|
||||||
it.key = F.second;
|
it.key = mm_item_placement.index_key;
|
||||||
mmi.items.push_back(it);
|
mmi.items.push_back(it);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1131,17 +1137,19 @@ void GridMap::_update_octants_callback() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OctantKey> to_delete;
|
LocalVector<OctantKey> to_delete;
|
||||||
|
to_delete.reserve(octant_map.size());
|
||||||
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
|
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
|
||||||
if (_octant_update(E.key)) {
|
if (_octant_update(E.key)) {
|
||||||
to_delete.push_back(E.key);
|
to_delete.push_back(E.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (to_delete.front()) {
|
while (!to_delete.is_empty()) {
|
||||||
memdelete(octant_map[to_delete.front()->get()]);
|
const OctantKey &octantkey = to_delete[0];
|
||||||
octant_map.erase(to_delete.front()->get());
|
memdelete(octant_map[octantkey]);
|
||||||
to_delete.pop_front();
|
octant_map.erase(octantkey);
|
||||||
|
to_delete.remove_at_unordered(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_update_visibility();
|
_update_visibility();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue