summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-09-02 13:53:28 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-02 13:53:28 +0200
commit4fa3675ffa96b1a3c1c9e4aa46fe6f2bebcbb4f7 (patch)
treed8a0e3ed744c7818b9a991cb42b099c0512a08eb /scene/3d
parentfe2cf6e406a0dfc02516ac3d03911d8863f0dce4 (diff)
parentfdfe11d4b3003de7e105c51e000d456a661a10b2 (diff)
Merge pull request #65218 from xX-Void-Xx/area2d/3d-optimization
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/area_3d.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index db7c3233f6..92e6d53139 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -473,19 +473,19 @@ bool Area3D::is_monitoring() const {
}
TypedArray<Node3D> Area3D::get_overlapping_bodies() const {
- ERR_FAIL_COND_V(!monitoring, Array());
- Array ret;
+ TypedArray<Node3D> ret;
+ ERR_FAIL_COND_V_MSG(!monitoring, ret, "Can't find overlapping bodies when monitoring is off.");
ret.resize(body_map.size());
int idx = 0;
for (const KeyValue<ObjectID, BodyState> &E : body_map) {
Object *obj = ObjectDB::get_instance(E.key);
- if (!obj) {
- ret.resize(ret.size() - 1); //ops
- } else {
- ret[idx++] = obj;
+ if (obj) {
+ ret[idx] = obj;
+ idx++;
}
}
+ ret.resize(idx);
return ret;
}
@@ -506,19 +506,18 @@ bool Area3D::is_monitorable() const {
}
TypedArray<Area3D> Area3D::get_overlapping_areas() const {
- ERR_FAIL_COND_V(!monitoring, Array());
- Array ret;
+ TypedArray<Area3D> ret;
+ ERR_FAIL_COND_V_MSG(!monitoring, ret, "Can't find overlapping areas when monitoring is off.");
ret.resize(area_map.size());
int idx = 0;
for (const KeyValue<ObjectID, AreaState> &E : area_map) {
Object *obj = ObjectDB::get_instance(E.key);
- if (!obj) {
- ret.resize(ret.size() - 1); //ops
- } else {
- ret[idx++] = obj;
+ if (obj) {
+ ret[idx] = obj;
+ idx++;
}
}
-
+ ret.resize(idx);
return ret;
}