diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-25 17:08:55 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-25 17:08:55 +0200 |
commit | ef266183598401d89482c5d2035d7e4cd3f64cb9 (patch) | |
tree | 6f5e436482cd0ed33415f1799945ae84a20b52ac | |
parent | d456dce8af77572ec5c9bec87cf1477fa52ea318 (diff) | |
parent | efd4dc20a3e88cfb90acc2bbb27f941872fbcc72 (diff) |
Merge pull request #66290 from 4d49/physics2d-area-methods
add `area_get_collision_layer` &`area_get_collision_mask`
-rw-r--r-- | doc/classes/PhysicsServer2D.xml | 14 | ||||
-rw-r--r-- | doc/classes/PhysicsServer2DExtension.xml | 12 | ||||
-rw-r--r-- | doc/classes/PhysicsServer3D.xml | 14 | ||||
-rw-r--r-- | doc/classes/PhysicsServer3DExtension.xml | 12 | ||||
-rw-r--r-- | servers/extensions/physics_server_2d_extension.cpp | 3 | ||||
-rw-r--r-- | servers/extensions/physics_server_2d_extension.h | 5 | ||||
-rw-r--r-- | servers/extensions/physics_server_3d_extension.cpp | 3 | ||||
-rw-r--r-- | servers/extensions/physics_server_3d_extension.h | 5 | ||||
-rw-r--r-- | servers/physics_2d/godot_physics_server_2d.cpp | 20 | ||||
-rw-r--r-- | servers/physics_2d/godot_physics_server_2d.h | 6 | ||||
-rw-r--r-- | servers/physics_3d/godot_physics_server_3d.cpp | 14 | ||||
-rw-r--r-- | servers/physics_3d/godot_physics_server_3d.h | 5 | ||||
-rw-r--r-- | servers/physics_server_2d.cpp | 3 | ||||
-rw-r--r-- | servers/physics_server_2d.h | 5 | ||||
-rw-r--r-- | servers/physics_server_2d_wrap_mt.h | 5 | ||||
-rw-r--r-- | servers/physics_server_3d.cpp | 3 | ||||
-rw-r--r-- | servers/physics_server_3d.h | 5 | ||||
-rw-r--r-- | servers/physics_server_3d_wrap_mt.h | 5 |
18 files changed, 128 insertions, 11 deletions
diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index 4b588033c0..18ac8a11df 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -53,6 +53,20 @@ <description> </description> </method> + <method name="area_get_collision_layer" qualifiers="const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + Returns the physics layer or layers an area belongs to. + </description> + </method> + <method name="area_get_collision_mask" qualifiers="const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + Returns the physics layer or layers an area can contact with. + </description> + </method> <method name="area_get_object_instance_id" qualifiers="const"> <return type="int" /> <param index="0" name="area" type="RID" /> diff --git a/doc/classes/PhysicsServer2DExtension.xml b/doc/classes/PhysicsServer2DExtension.xml index 518862bb28..9bb11e0d89 100644 --- a/doc/classes/PhysicsServer2DExtension.xml +++ b/doc/classes/PhysicsServer2DExtension.xml @@ -47,6 +47,18 @@ <description> </description> </method> + <method name="_area_get_collision_layer" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_collision_mask" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> <method name="_area_get_object_instance_id" qualifiers="virtual const"> <return type="int" /> <param index="0" name="area" type="RID" /> diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index da9e10c420..95f7fb69a2 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -40,6 +40,20 @@ Creates an [Area3D]. </description> </method> + <method name="area_get_collision_layer" qualifiers="const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + Returns the physics layer or layers an area belongs to. + </description> + </method> + <method name="area_get_collision_mask" qualifiers="const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + Returns the physics layer or layers an area can contact with. + </description> + </method> <method name="area_get_object_instance_id" qualifiers="const"> <return type="int" /> <param index="0" name="area" type="RID" /> diff --git a/doc/classes/PhysicsServer3DExtension.xml b/doc/classes/PhysicsServer3DExtension.xml index ab00f63359..1e9df54de5 100644 --- a/doc/classes/PhysicsServer3DExtension.xml +++ b/doc/classes/PhysicsServer3DExtension.xml @@ -34,6 +34,18 @@ <description> </description> </method> + <method name="_area_get_collision_layer" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> + <method name="_area_get_collision_mask" qualifiers="virtual const"> + <return type="int" /> + <param index="0" name="area" type="RID" /> + <description> + </description> + </method> <method name="_area_get_object_instance_id" qualifiers="virtual const"> <return type="int" /> <param index="0" name="area" type="RID" /> diff --git a/servers/extensions/physics_server_2d_extension.cpp b/servers/extensions/physics_server_2d_extension.cpp index 769315daa7..e5920c78d4 100644 --- a/servers/extensions/physics_server_2d_extension.cpp +++ b/servers/extensions/physics_server_2d_extension.cpp @@ -189,7 +189,10 @@ void PhysicsServer2DExtension::_bind_methods() { GDVIRTUAL_BIND(_area_get_transform, "area"); GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer"); + GDVIRTUAL_BIND(_area_get_collision_layer, "area"); + GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask"); + GDVIRTUAL_BIND(_area_get_collision_mask, "area"); GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable"); GDVIRTUAL_BIND(_area_set_pickable, "area", "pickable"); diff --git a/servers/extensions/physics_server_2d_extension.h b/servers/extensions/physics_server_2d_extension.h index a6dbe35264..573b51ee12 100644 --- a/servers/extensions/physics_server_2d_extension.h +++ b/servers/extensions/physics_server_2d_extension.h @@ -268,8 +268,11 @@ public: EXBIND2RC(Variant, area_get_param, RID, AreaParameter) EXBIND1RC(Transform2D, area_get_transform, RID) - EXBIND2(area_set_collision_mask, RID, uint32_t) EXBIND2(area_set_collision_layer, RID, uint32_t) + EXBIND1RC(uint32_t, area_get_collision_layer, RID) + + EXBIND2(area_set_collision_mask, RID, uint32_t) + EXBIND1RC(uint32_t, area_get_collision_mask, RID) EXBIND2(area_set_monitorable, RID, bool) EXBIND2(area_set_pickable, RID, bool) diff --git a/servers/extensions/physics_server_3d_extension.cpp b/servers/extensions/physics_server_3d_extension.cpp index 4785fa33fb..27f9ed2cb3 100644 --- a/servers/extensions/physics_server_3d_extension.cpp +++ b/servers/extensions/physics_server_3d_extension.cpp @@ -192,7 +192,10 @@ void PhysicsServer3DExtension::_bind_methods() { GDVIRTUAL_BIND(_area_get_transform, "area"); GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer"); + GDVIRTUAL_BIND(_area_get_collision_layer, "area"); + GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask"); + GDVIRTUAL_BIND(_area_get_collision_mask, "area"); GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable"); GDVIRTUAL_BIND(_area_set_ray_pickable, "area", "enable"); diff --git a/servers/extensions/physics_server_3d_extension.h b/servers/extensions/physics_server_3d_extension.h index f1e522aca8..57f2a2d790 100644 --- a/servers/extensions/physics_server_3d_extension.h +++ b/servers/extensions/physics_server_3d_extension.h @@ -271,8 +271,11 @@ public: EXBIND2RC(Variant, area_get_param, RID, AreaParameter) EXBIND1RC(Transform3D, area_get_transform, RID) - EXBIND2(area_set_collision_mask, RID, uint32_t) EXBIND2(area_set_collision_layer, RID, uint32_t) + EXBIND1RC(uint32_t, area_get_collision_layer, RID) + + EXBIND2(area_set_collision_mask, RID, uint32_t) + EXBIND1RC(uint32_t, area_get_collision_mask, RID) EXBIND2(area_set_monitorable, RID, bool) EXBIND2(area_set_ray_pickable, RID, bool) diff --git a/servers/physics_2d/godot_physics_server_2d.cpp b/servers/physics_2d/godot_physics_server_2d.cpp index 11f6bd9c1e..6ce8175e6c 100644 --- a/servers/physics_2d/godot_physics_server_2d.cpp +++ b/servers/physics_2d/godot_physics_server_2d.cpp @@ -485,6 +485,20 @@ void GodotPhysicsServer2D::area_set_monitorable(RID p_area, bool p_monitorable) area->set_monitorable(p_monitorable); } +void GodotPhysicsServer2D::area_set_collision_layer(RID p_area, uint32_t p_layer) { + GodotArea2D *area = area_owner.get_or_null(p_area); + ERR_FAIL_COND(!area); + + area->set_collision_layer(p_layer); +} + +uint32_t GodotPhysicsServer2D::area_get_collision_layer(RID p_area) const { + GodotArea2D *area = area_owner.get_or_null(p_area); + ERR_FAIL_COND_V(!area, 0); + + return area->get_collision_layer(); +} + void GodotPhysicsServer2D::area_set_collision_mask(RID p_area, uint32_t p_mask) { GodotArea2D *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); @@ -492,11 +506,11 @@ void GodotPhysicsServer2D::area_set_collision_mask(RID p_area, uint32_t p_mask) area->set_collision_mask(p_mask); } -void GodotPhysicsServer2D::area_set_collision_layer(RID p_area, uint32_t p_layer) { +uint32_t GodotPhysicsServer2D::area_get_collision_mask(RID p_area) const { GodotArea2D *area = area_owner.get_or_null(p_area); - ERR_FAIL_COND(!area); + ERR_FAIL_COND_V(!area, 0); - area->set_collision_layer(p_layer); + return area->get_collision_mask(); } void GodotPhysicsServer2D::area_set_monitor_callback(RID p_area, const Callable &p_callback) { diff --git a/servers/physics_2d/godot_physics_server_2d.h b/servers/physics_2d/godot_physics_server_2d.h index c780ef3b66..b96677700c 100644 --- a/servers/physics_2d/godot_physics_server_2d.h +++ b/servers/physics_2d/godot_physics_server_2d.h @@ -151,8 +151,12 @@ public: virtual Variant area_get_param(RID p_area, AreaParameter p_param) const override; virtual Transform2D area_get_transform(RID p_area) const override; virtual void area_set_monitorable(RID p_area, bool p_monitorable) override; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; + virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override; + virtual uint32_t area_get_collision_layer(RID p_area) const override; + + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; + virtual uint32_t area_get_collision_mask(RID p_area) const override; virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) override; virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) override; diff --git a/servers/physics_3d/godot_physics_server_3d.cpp b/servers/physics_3d/godot_physics_server_3d.cpp index 7f2ec72921..f3a589d469 100644 --- a/servers/physics_3d/godot_physics_server_3d.cpp +++ b/servers/physics_3d/godot_physics_server_3d.cpp @@ -387,6 +387,13 @@ void GodotPhysicsServer3D::area_set_collision_layer(RID p_area, uint32_t p_layer area->set_collision_layer(p_layer); } +uint32_t GodotPhysicsServer3D::area_get_collision_layer(RID p_area) const { + GodotArea3D *area = area_owner.get_or_null(p_area); + ERR_FAIL_COND_V(!area, 0); + + return area->get_collision_layer(); +} + void GodotPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) { GodotArea3D *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); @@ -394,6 +401,13 @@ void GodotPhysicsServer3D::area_set_collision_mask(RID p_area, uint32_t p_mask) area->set_collision_mask(p_mask); } +uint32_t GodotPhysicsServer3D::area_get_collision_mask(RID p_area) const { + GodotArea3D *area = area_owner.get_or_null(p_area); + ERR_FAIL_COND_V(!area, 0); + + return area->get_collision_mask(); +} + void GodotPhysicsServer3D::area_set_monitorable(RID p_area, bool p_monitorable) { GodotArea3D *area = area_owner.get_or_null(p_area); ERR_FAIL_COND(!area); diff --git a/servers/physics_3d/godot_physics_server_3d.h b/servers/physics_3d/godot_physics_server_3d.h index 6dc9330caf..e3e649da57 100644 --- a/servers/physics_3d/godot_physics_server_3d.h +++ b/servers/physics_3d/godot_physics_server_3d.h @@ -148,8 +148,11 @@ public: virtual void area_set_ray_pickable(RID p_area, bool p_enable) override; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override; + virtual uint32_t area_get_collision_layer(RID p_area) const override; + + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; + virtual uint32_t area_get_collision_mask(RID p_area) const override; virtual void area_set_monitorable(RID p_area, bool p_monitorable) override; diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index abaa473017..21be311637 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -652,7 +652,10 @@ void PhysicsServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer2D::area_clear_shapes); ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer2D::area_set_collision_layer); + ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer2D::area_get_collision_layer); + ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer2D::area_set_collision_mask); + ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer2D::area_get_collision_mask); ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer2D::area_set_param); ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer2D::area_set_transform); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index bd57a6a375..a3feb97d5d 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -332,8 +332,11 @@ public: virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0; virtual Transform2D area_get_transform(RID p_area) const = 0; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0; virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0; + virtual uint32_t area_get_collision_layer(RID p_area) const = 0; + + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0; + virtual uint32_t area_get_collision_mask(RID p_area) const = 0; virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0; virtual void area_set_pickable(RID p_area, bool p_pickable) = 0; diff --git a/servers/physics_server_2d_wrap_mt.h b/servers/physics_server_2d_wrap_mt.h index 1353d8de6d..14a6a5c2a1 100644 --- a/servers/physics_server_2d_wrap_mt.h +++ b/servers/physics_server_2d_wrap_mt.h @@ -156,8 +156,11 @@ public: FUNC2RC(Variant, area_get_param, RID, AreaParameter); FUNC1RC(Transform2D, area_get_transform, RID); - FUNC2(area_set_collision_mask, RID, uint32_t); FUNC2(area_set_collision_layer, RID, uint32_t); + FUNC1RC(uint32_t, area_get_collision_layer, RID); + + FUNC2(area_set_collision_mask, RID, uint32_t); + FUNC1RC(uint32_t, area_get_collision_mask, RID); FUNC2(area_set_monitorable, RID, bool); FUNC2(area_set_pickable, RID, bool); diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index b4f30d7649..24cc7e8459 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -720,7 +720,10 @@ void PhysicsServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("area_clear_shapes", "area"), &PhysicsServer3D::area_clear_shapes); ClassDB::bind_method(D_METHOD("area_set_collision_layer", "area", "layer"), &PhysicsServer3D::area_set_collision_layer); + ClassDB::bind_method(D_METHOD("area_get_collision_layer", "area"), &PhysicsServer3D::area_get_collision_layer); + ClassDB::bind_method(D_METHOD("area_set_collision_mask", "area", "mask"), &PhysicsServer3D::area_set_collision_mask); + ClassDB::bind_method(D_METHOD("area_get_collision_mask", "area"), &PhysicsServer3D::area_get_collision_mask); ClassDB::bind_method(D_METHOD("area_set_param", "area", "param", "value"), &PhysicsServer3D::area_set_param); ClassDB::bind_method(D_METHOD("area_set_transform", "area", "transform"), &PhysicsServer3D::area_set_transform); diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index 2151d84e40..b21c4e9249 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -364,8 +364,11 @@ public: virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0; virtual Transform3D area_get_transform(RID p_area) const = 0; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0; virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0; + virtual uint32_t area_get_collision_layer(RID p_area) const = 0; + + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0; + virtual uint32_t area_get_collision_mask(RID p_area) const = 0; virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0; diff --git a/servers/physics_server_3d_wrap_mt.h b/servers/physics_server_3d_wrap_mt.h index 9b07e19e50..1d5fa95bfb 100644 --- a/servers/physics_server_3d_wrap_mt.h +++ b/servers/physics_server_3d_wrap_mt.h @@ -157,8 +157,11 @@ public: FUNC2RC(Variant, area_get_param, RID, AreaParameter); FUNC1RC(Transform3D, area_get_transform, RID); - FUNC2(area_set_collision_mask, RID, uint32_t); FUNC2(area_set_collision_layer, RID, uint32_t); + FUNC1RC(uint32_t, area_get_collision_layer, RID); + + FUNC2(area_set_collision_mask, RID, uint32_t); + FUNC1RC(uint32_t, area_get_collision_mask, RID); FUNC2(area_set_monitorable, RID, bool); FUNC2(area_set_ray_pickable, RID, bool); |