java-topology/defects/godot/patch/godot-0003-physics3d-body-area-hashmap.patch

52 lines
1.6 KiB
Diff

# UNDF: UNDF-2026-000000085
--- a/modules/godot_physics_3d/godot_body_3d.h
+++ b/modules/godot_physics_3d/godot_body_3d.h
@@ -114,6 +114,7 @@ class GodotBody3D : public GodotCollisionObject3D {
// ...
Vector<AreaCMP> areas;
+ HashMap<RID, int> area_index; // O(1) area lookup by RID — shadow index
// ...
@@ -156,19 +157,24 @@ public:
_FORCE_INLINE_ void add_area(GodotArea3D *p_area) {
- int index = areas.find(AreaCMP(p_area));
- if (index > -1) {
- areas.write[index].refCount += 1;
+ // FIX godot-0003: identical to godot-0002, 3D physics variant
+ RID rid = p_area->get_self();
+ HashMap<RID, int>::Iterator it = area_index.find(rid);
+ if (it != area_index.end()) {
+ areas.write[it->value].refCount += 1;
} else {
- areas.ordered_insert(AreaCMP(p_area));
+ areas.ordered_insert(AreaCMP(p_area));
+ area_index.clear();
+ for (int i = 0; i < areas.size(); i++) {
+ area_index[areas[i].area->get_self()] = i;
+ }
}
}
_FORCE_INLINE_ void remove_area(GodotArea3D *p_area) {
- int index = areas.find(AreaCMP(p_area));
- if (index > -1) {
- areas.write[index].refCount -= 1;
- if (areas[index].refCount < 1) {
- areas.remove_at(index);
+ // FIX godot-0003: identical to godot-0002, 3D physics variant
+ RID rid = p_area->get_self();
+ HashMap<RID, int>::Iterator it = area_index.find(rid);
+ if (it != area_index.end()) {
+ int index = it->value;
+ areas.write[index].refCount -= 1;
+ if (areas[index].refCount < 1) {
+ areas.remove_at(index);
+ area_index.clear();
+ for (int i = 0; i < areas.size(); i++) {
+ area_index[areas[i].area->get_self()] = i;
+ }
}
}
}