From ed4fe1e2bd60188c8b1b91ad083503dd59cc902f Mon Sep 17 00:00:00 2001 From: VolTer Date: Fri, 9 Sep 2022 23:26:14 +0200 Subject: Implement Area.has_overlapping_* --- doc/classes/Area2D.xml | 16 +++++++++++++++- doc/classes/Area3D.xml | 16 +++++++++++++++- scene/2d/area_2d.cpp | 13 +++++++++++++ scene/2d/area_2d.h | 3 +++ scene/3d/area_3d.cpp | 13 +++++++++++++ scene/3d/area_3d.h | 3 +++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/doc/classes/Area2D.xml b/doc/classes/Area2D.xml index f1e40d4979..29592f133d 100644 --- a/doc/classes/Area2D.xml +++ b/doc/classes/Area2D.xml @@ -25,10 +25,24 @@ - Returns a list of intersecting [PhysicsBody2D]s. The overlapping body's [member CollisionObject2D.collision_layer] must be part of this area's [member CollisionObject2D.collision_mask] in order to be detected. + Returns a list of intersecting [PhysicsBody2D]s and [TileMap]s. The overlapping body's [member CollisionObject2D.collision_layer] must be part of this area's [member CollisionObject2D.collision_mask] in order to be detected. For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + + + Returns [code]true[/code] if intersecting any [Area2D]s, otherwise returns [code]false[/code]. The overlapping area's [member CollisionObject2D.collision_layer] must be part of this area's [member CollisionObject2D.collision_mask] in order to be detected. + For performance reasons (collisions are all processed at the same time) the list of overlapping areas is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + + + + + Returns [code]true[/code] if intersecting any [PhysicsBody2D]s or [TileMap]s, otherwise returns [code]false[/code]. The overlapping body's [member CollisionObject2D.collision_layer] must be part of this area's [member CollisionObject2D.collision_mask] in order to be detected. + For performance reasons (collisions are all processed at the same time) the list of overlapping bodies is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + diff --git a/doc/classes/Area3D.xml b/doc/classes/Area3D.xml index 14081918cf..ce49be9bc1 100644 --- a/doc/classes/Area3D.xml +++ b/doc/classes/Area3D.xml @@ -23,10 +23,24 @@ - Returns a list of intersecting [PhysicsBody3D]s. The overlapping body's [member CollisionObject3D.collision_layer] must be part of this area's [member CollisionObject3D.collision_mask] in order to be detected. + Returns a list of intersecting [PhysicsBody3D]s and [GridMap]s. The overlapping body's [member CollisionObject3D.collision_layer] must be part of this area's [member CollisionObject3D.collision_mask] in order to be detected. For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + + + Returns [code]true[/code] if intersecting any [Area3D]s, otherwise returns [code]false[/code]. The overlapping area's [member CollisionObject3D.collision_layer] must be part of this area's [member CollisionObject3D.collision_mask] in order to be detected. + For performance reasons (collisions are all processed at the same time) the list of overlapping areas is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + + + + + Returns [code]true[/code] if intersecting any [PhysicsBody3D]s or [GridMap]s, otherwise returns [code]false[/code]. The overlapping body's [member CollisionObject3D.collision_layer] must be part of this area's [member CollisionObject3D.collision_mask] in order to be detected. + For performance reasons (collisions are all processed at the same time) the list of overlapping bodies is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. + + diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 3def41eaa5..b3f80b5e43 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -459,6 +459,16 @@ TypedArray Area2D::get_overlapping_areas() const { return ret; } +bool Area2D::has_overlapping_bodies() const { + ERR_FAIL_COND_V_MSG(!monitoring, false, "Can't find overlapping bodies when monitoring is off."); + return !body_map.is_empty(); +} + +bool Area2D::has_overlapping_areas() const { + ERR_FAIL_COND_V_MSG(!monitoring, false, "Can't find overlapping areas when monitoring is off."); + return !area_map.is_empty(); +} + bool Area2D::overlaps_area(Node *p_area) const { ERR_FAIL_NULL_V(p_area, false); HashMap::ConstIterator E = area_map.find(p_area->get_instance_id()); @@ -578,6 +588,9 @@ void Area2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area2D::get_overlapping_bodies); ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area2D::get_overlapping_areas); + ClassDB::bind_method(D_METHOD("has_overlapping_bodies"), &Area2D::has_overlapping_bodies); + ClassDB::bind_method(D_METHOD("has_overlapping_areas"), &Area2D::has_overlapping_areas); + ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area2D::overlaps_body); ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area2D::overlaps_area); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 3d8d77eabb..f70f1dfc3d 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -180,6 +180,9 @@ public: TypedArray get_overlapping_bodies() const; //function for script TypedArray get_overlapping_areas() const; //function for script + bool has_overlapping_bodies() const; + bool has_overlapping_areas() const; + bool overlaps_area(Node *p_area) const; bool overlaps_body(Node *p_body) const; diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp index f118080009..cefa9eceff 100644 --- a/scene/3d/area_3d.cpp +++ b/scene/3d/area_3d.cpp @@ -489,6 +489,11 @@ TypedArray Area3D::get_overlapping_bodies() const { return ret; } +bool Area3D::has_overlapping_bodies() const { + ERR_FAIL_COND_V_MSG(!monitoring, false, "Can't find overlapping bodies when monitoring is off."); + return !body_map.is_empty(); +} + void Area3D::set_monitorable(bool p_enable) { ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer3D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); @@ -521,6 +526,11 @@ TypedArray Area3D::get_overlapping_areas() const { return ret; } +bool Area3D::has_overlapping_areas() const { + ERR_FAIL_COND_V_MSG(!monitoring, false, "Can't find overlapping areas when monitoring is off."); + return !area_map.is_empty(); +} + bool Area3D::overlaps_area(Node *p_area) const { ERR_FAIL_NULL_V(p_area, false); HashMap::ConstIterator E = area_map.find(p_area->get_instance_id()); @@ -686,6 +696,9 @@ void Area3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area3D::get_overlapping_bodies); ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area3D::get_overlapping_areas); + ClassDB::bind_method(D_METHOD("has_overlapping_bodies"), &Area3D::has_overlapping_bodies); + ClassDB::bind_method(D_METHOD("has_overlapping_areas"), &Area3D::has_overlapping_areas); + ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area3D::overlaps_body); ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area3D::overlaps_area); diff --git a/scene/3d/area_3d.h b/scene/3d/area_3d.h index 48364739b7..0f0bcc7ce0 100644 --- a/scene/3d/area_3d.h +++ b/scene/3d/area_3d.h @@ -201,6 +201,9 @@ public: TypedArray get_overlapping_bodies() const; TypedArray get_overlapping_areas() const; //function for script + bool has_overlapping_bodies() const; + bool has_overlapping_areas() const; + bool overlaps_area(Node *p_area) const; bool overlaps_body(Node *p_body) const; -- cgit v1.2.3