mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +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) {
|
||||
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()) {
|
||||
const SetItem &si = E->get();
|
||||
for (uint32_t i = set_items.size(); i > 0; i--) {
|
||||
const SetItem &si = set_items[i - 1];
|
||||
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);
|
||||
mode_buttons_group.instantiate();
|
||||
|
||||
viewport_shortcut_buttons.reserve(12);
|
||||
|
||||
transform_mode_button = memnew(Button);
|
||||
transform_mode_button->set_theme_type_variation(SceneStringName(FlatButton));
|
||||
transform_mode_button->set_toggle_mode(true);
|
||||
|
|
|
@ -74,7 +74,7 @@ class GridMapEditor : public VBoxContainer {
|
|||
double accumulated_floor_delta = 0.0;
|
||||
|
||||
HBoxContainer *toolbar = nullptr;
|
||||
List<BaseButton *> viewport_shortcut_buttons;
|
||||
TightLocalVector<BaseButton *> viewport_shortcut_buttons;
|
||||
Ref<ButtonGroup> mode_buttons_group;
|
||||
// mode
|
||||
Button *transform_mode_button = nullptr;
|
||||
|
@ -110,7 +110,7 @@ class GridMapEditor : public VBoxContainer {
|
|||
int old_orientation = 0;
|
||||
};
|
||||
|
||||
List<SetItem> set_items;
|
||||
LocalVector<SetItem> set_items;
|
||||
|
||||
GridMap *node = nullptr;
|
||||
Ref<MeshLibrary> mesh_library = nullptr;
|
||||
|
@ -139,7 +139,7 @@ class GridMapEditor : public VBoxContainer {
|
|||
RID instance;
|
||||
};
|
||||
|
||||
List<ClipboardItem> clipboard_items;
|
||||
LocalVector<ClipboardItem> clipboard_items;
|
||||
|
||||
Color default_color;
|
||||
Color erase_color;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/io/marshalls.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/capsule_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
|
||||
*/
|
||||
|
||||
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;
|
||||
#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));
|
||||
if (baked_meshes.is_empty()) {
|
||||
if (mesh_library->get_item_mesh(c.item).is_valid()) {
|
||||
if (!multimesh_items.has(c.item)) {
|
||||
multimesh_items[c.item] = List<Pair<Transform3D, IndexKey>>();
|
||||
if (!item_id_to_multimesh_item_placements.has(c.item)) {
|
||||
item_id_to_multimesh_item_placements[c.item] = LocalVector<MultiMeshItemPlacement>();
|
||||
}
|
||||
|
||||
Pair<Transform3D, IndexKey> p;
|
||||
p.first = xform * mesh_library->get_item_mesh_transform(c.item);
|
||||
p.second = E;
|
||||
multimesh_items[c.item].push_back(p);
|
||||
MultiMeshItemPlacement p;
|
||||
p.transform = xform * mesh_library->get_item_mesh_transform(c.item);
|
||||
p.index_key = E;
|
||||
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
|
||||
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;
|
||||
|
||||
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());
|
||||
|
||||
int idx = 0;
|
||||
for (const Pair<Transform3D, IndexKey> &F : E.value) {
|
||||
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F.first);
|
||||
const LocalVector<MultiMeshItemPlacement> &mm_item_placements = E.value;
|
||||
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
|
||||
|
||||
Octant::MultimeshInstance::Item it;
|
||||
it.index = idx;
|
||||
it.transform = F.first;
|
||||
it.key = F.second;
|
||||
it.transform = mm_item_placement.transform;
|
||||
it.key = mm_item_placement.index_key;
|
||||
mmi.items.push_back(it);
|
||||
#endif
|
||||
|
||||
|
@ -1131,17 +1137,19 @@ void GridMap::_update_octants_callback() {
|
|||
return;
|
||||
}
|
||||
|
||||
List<OctantKey> to_delete;
|
||||
LocalVector<OctantKey> to_delete;
|
||||
to_delete.reserve(octant_map.size());
|
||||
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
|
||||
if (_octant_update(E.key)) {
|
||||
to_delete.push_back(E.key);
|
||||
}
|
||||
}
|
||||
|
||||
while (to_delete.front()) {
|
||||
memdelete(octant_map[to_delete.front()->get()]);
|
||||
octant_map.erase(to_delete.front()->get());
|
||||
to_delete.pop_front();
|
||||
while (!to_delete.is_empty()) {
|
||||
const OctantKey &octantkey = to_delete[0];
|
||||
memdelete(octant_map[octantkey]);
|
||||
octant_map.erase(octantkey);
|
||||
to_delete.remove_at_unordered(0);
|
||||
}
|
||||
|
||||
_update_visibility();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue