From 8766769fd415d1785b22867f2565b266f6a5f0d9 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Tue, 13 Oct 2020 13:17:00 +0100 Subject: [PATCH] Move collision layer and mask into CollisionObject. --- doc/classes/Area.xml | 46 -------------------- doc/classes/Area2D.xml | 46 -------------------- doc/classes/CollisionObject.xml | 50 ++++++++++++++++++++++ doc/classes/CollisionObject2D.xml | 50 ++++++++++++++++++++++ doc/classes/PhysicsBody.xml | 50 ---------------------- doc/classes/PhysicsBody2D.xml | 50 +--------------------- scene/2d/area_2d.cpp | 64 ---------------------------- scene/2d/area_2d.h | 14 ------- scene/2d/collision_object_2d.cpp | 70 +++++++++++++++++++++++++++++-- scene/2d/collision_object_2d.h | 15 +++++++ scene/2d/physics_body_2d.cpp | 63 ---------------------------- scene/2d/physics_body_2d.h | 15 ------- scene/3d/area.cpp | 62 --------------------------- scene/3d/area.h | 14 ------- scene/3d/collision_object.cpp | 67 +++++++++++++++++++++++++++++ scene/3d/collision_object.h | 15 +++++++ scene/3d/physics_body.cpp | 64 ---------------------------- scene/3d/physics_body.h | 15 ------- 18 files changed, 265 insertions(+), 505 deletions(-) diff --git a/doc/classes/Area.xml b/doc/classes/Area.xml index 62068b851f1..0c52fd48c31 100644 --- a/doc/classes/Area.xml +++ b/doc/classes/Area.xml @@ -11,24 +11,6 @@ https://godotengine.org/asset-library/asset/127 - - - - - - - Returns an individual bit on the layer mask. - - - - - - - - - Returns an individual bit on the collision mask. - - @@ -64,28 +46,6 @@ The [code]body[/code] argument can either be a [PhysicsBody] or a [GridMap] instance (while GridMaps are not physics body themselves, they register their tiles with collision shapes as a virtual physics body). - - - - - - - - - Set/clear individual bits on the layer mask. This simplifies editing this [Area]'s layers. - - - - - - - - - - - Set/clear individual bits on the collision mask. This simplifies editing which [Area] layers this [Area] scans. - - @@ -98,12 +58,6 @@ If [code]true[/code], the area's audio bus overrides the default audio bus. - - The area's physics layer(s). Collidable objects can exist in any of 32 different layers. A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See also [member collision_mask]. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - The physics layers this area scans to determine collision detection. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The area's gravity intensity (ranges from -1024 to 1024). This value multiplies the gravity vector. This is useful to alter the force of gravity without altering its direction. diff --git a/doc/classes/Area2D.xml b/doc/classes/Area2D.xml index 136f65a86db..0436781a184 100644 --- a/doc/classes/Area2D.xml +++ b/doc/classes/Area2D.xml @@ -13,24 +13,6 @@ https://godotengine.org/asset-library/asset/120 - - - - - - - Returns an individual bit on the layer mask. Describes whether other areas will collide with this one on the given layer. - - - - - - - - - Returns an individual bit on the collision mask. Describes whether this area will collide with others on the given layer. - - @@ -66,28 +48,6 @@ The [code]body[/code] argument can either be a [PhysicsBody2D] or a [TileMap] instance (while TileMaps are not physics body themselves, they register their tiles with collision shapes as a virtual physics body). - - - - - - - - - Set/clear individual bits on the layer mask. This makes getting an area in/out of only one layer easier. - - - - - - - - - - - Set/clear individual bits on the collision mask. This makes selecting the areas scanned easier. - - @@ -100,12 +60,6 @@ If [code]true[/code], the area's audio bus overrides the default audio bus. - - The area's physics layer(s). Collidable objects can exist in any of 32 different layers. A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See also [member collision_mask]. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - The physics layers this area scans to determine collision detection. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The area's gravity intensity (ranges from -1024 to 1024). This value multiplies the gravity vector. This is useful to alter the force of gravity without altering its direction. diff --git a/doc/classes/CollisionObject.xml b/doc/classes/CollisionObject.xml index 2a861a9dfcc..574e5f2a5d4 100644 --- a/doc/classes/CollisionObject.xml +++ b/doc/classes/CollisionObject.xml @@ -35,6 +35,24 @@ Creates a new shape owner for the given object. Returns [code]owner_id[/code] of the new owner for future reference. + + + + + + + Returns whether or not the specified [code]bit[/code] of the [member collision_layer] is set. + + + + + + + + + Returns whether or not the specified [code]bit[/code] of the [member collision_mask] is set. + + @@ -67,6 +85,30 @@ Removes the given shape owner. + + + + + + + + + If [code]value[/value] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_layer]. + If [code]value[/value] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_layer]. + + + + + + + + + + + If [code]value[/value] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_mask]. + If [code]value[/value] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_mask]. + + @@ -180,6 +222,14 @@ + + The physics layers this CollisionObject3D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask]. + [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + + + The physics layers this CollisionObject3D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. + [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + If [code]true[/code], the [CollisionObject] will continue to receive input events as the mouse is dragged across its shapes. diff --git a/doc/classes/CollisionObject2D.xml b/doc/classes/CollisionObject2D.xml index 500150c346d..60934c91ad1 100644 --- a/doc/classes/CollisionObject2D.xml +++ b/doc/classes/CollisionObject2D.xml @@ -31,6 +31,24 @@ Creates a new shape owner for the given object. Returns [code]owner_id[/code] of the new owner for future reference. + + + + + + + Returns whether or not the specified [code]bit[/code] of the [member collision_layer] is set. + + + + + + + + + Returns whether or not the specified [code]bit[/code] of the [member collision_mask] is set. + + @@ -81,6 +99,30 @@ Removes the given shape owner. + + + + + + + + + If [code]value[/value] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_layer]. + If [code]value[/value] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_layer]. + + + + + + + + + + + If [code]value[/value] is [code]true[/code], sets the specified [code]bit[/code] in the the [member collision_mask]. + If [code]value[/value] is [code]false[/code], clears the specified [code]bit[/code] in the the [member collision_mask]. + + @@ -216,6 +258,14 @@ + + The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask]. + [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + + + The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. + [b]Note:[/b] A contact is detected if object A is in any of the layers that object B scans, or object B is in any layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + If [code]true[/code], this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least one [code]collision_layer[/code] bit to be set. diff --git a/doc/classes/PhysicsBody.xml b/doc/classes/PhysicsBody.xml index 15155193ab7..277d0876a16 100644 --- a/doc/classes/PhysicsBody.xml +++ b/doc/classes/PhysicsBody.xml @@ -26,24 +26,6 @@ Returns an array of nodes that were added as collision exceptions for this body. - - - - - - - Returns an individual bit on the [member collision_layer]. - - - - - - - - - Returns an individual bit on the [member collision_mask]. - - @@ -53,39 +35,7 @@ Removes a body from the list of bodies that this body can't collide with. - - - - - - - - - Sets individual bits on the [member collision_layer] bitmask. Use this if you only need to change one layer's value. - - - - - - - - - - - Sets individual bits on the [member collision_mask] bitmask. Use this if you only need to change one layer's value. - - - - - The physics layers this area is in. - Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property. - A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - diff --git a/doc/classes/PhysicsBody2D.xml b/doc/classes/PhysicsBody2D.xml index aeabeb62115..317c1fa6983 100644 --- a/doc/classes/PhysicsBody2D.xml +++ b/doc/classes/PhysicsBody2D.xml @@ -26,24 +26,6 @@ Returns an array of nodes that were added as collision exceptions for this body. - - - - - - - Returns an individual bit on the [member collision_layer]. - - - - - - - - - Returns an individual bit on the [member collision_mask]. - - @@ -53,41 +35,11 @@ Removes a body from the list of bodies that this body can't collide with. - - - - - - - - - Sets individual bits on the [member collision_layer] bitmask. Use this if you only need to change one layer's value. - - - - - - - - - - - Sets individual bits on the [member collision_mask] bitmask. Use this if you only need to change one layer's value. - - - - The physics layers this area is in. - Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property. - A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - Both [member collision_layer] and [member collision_mask]. Returns [member collision_layer] when accessed. Updates [member collision_layer] and [member collision_mask] when modified. + Both collision_layer and collision_mask. Returns collision_layer when accessed. Updates collision_layer and collision_mask when modified. diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 52259b57826..6be41a702c2 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -445,52 +445,6 @@ bool Area2D::overlaps_body(Node *p_body) const { return E->get().in_tree; } -void Area2D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; - Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); -} - -uint32_t Area2D::get_collision_mask() const { - return collision_mask; -} - -void Area2D::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; - Physics2DServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); -} - -uint32_t Area2D::get_collision_layer() const { - return collision_layer; -} - -void Area2D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); - if (p_value) { - mask |= 1 << p_bit; - } else { - mask &= ~(1 << p_bit); - } - set_collision_mask(mask); -} - -bool Area2D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); -} - -void Area2D::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t layer = get_collision_layer(); - if (p_value) { - layer |= 1 << p_bit; - } else { - layer &= ~(1 << p_bit); - } - set_collision_layer(layer); -} - -bool Area2D::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); -} - void Area2D::set_audio_bus_override(bool p_override) { audio_bus_override = p_override; } @@ -558,18 +512,6 @@ void Area2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area2D::set_priority); ClassDB::bind_method(D_METHOD("get_priority"), &Area2D::get_priority); - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area2D::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area2D::get_collision_mask); - - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area2D::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area2D::get_collision_layer); - - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area2D::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area2D::get_collision_mask_bit); - - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area2D::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area2D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area2D::set_monitoring); ClassDB::bind_method(D_METHOD("is_monitoring"), &Area2D::is_monitoring); @@ -614,10 +556,6 @@ void Area2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); - ADD_GROUP("Collision", "collision_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); - ADD_GROUP("Audio Bus", "audio_bus_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_bus_override"), "set_audio_bus_override", "is_overriding_audio_bus"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus_name", "get_audio_bus_name"); @@ -642,8 +580,6 @@ Area2D::Area2D() : priority = 0; monitoring = false; monitorable = false; - collision_mask = 1; - collision_layer = 1; audio_bus_override = false; set_monitoring(true); set_monitorable(true); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 8a0be9b4bb9..e4da1d64fd8 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -54,8 +54,6 @@ private: real_t gravity_distance_scale; real_t linear_damp; real_t angular_damp; - uint32_t collision_mask; - uint32_t collision_layer; int priority; bool monitoring; bool monitorable; @@ -163,18 +161,6 @@ public: void set_monitorable(bool p_enable); bool is_monitorable() const; - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; - - void set_collision_mask_bit(int p_bit, bool p_value); - bool get_collision_mask_bit(int p_bit) const; - - void set_collision_layer_bit(int p_bit, bool p_value); - bool get_collision_layer_bit(int p_bit) const; - Array get_overlapping_bodies() const; //function for script Array get_overlapping_areas() const; //function for script diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 886ba7e2464..e0a2d17ee7d 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -100,6 +100,60 @@ void CollisionObject2D::_notification(int p_what) { } } +void CollisionObject2D::set_collision_layer(uint32_t p_layer) { + collision_layer = p_layer; + if (area) { + Physics2DServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); + } else { + Physics2DServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); + } +} + +uint32_t CollisionObject2D::get_collision_layer() const { + return collision_layer; +} + +void CollisionObject2D::set_collision_mask(uint32_t p_mask) { + collision_mask = p_mask; + if (area) { + Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); + } else { + Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); + } +} + +uint32_t CollisionObject2D::get_collision_mask() const { + return collision_mask; +} + +void CollisionObject2D::set_collision_layer_bit(int p_bit, bool p_value) { + uint32_t collision_layer = get_collision_layer(); + if (p_value) { + collision_layer |= 1 << p_bit; + } else { + collision_layer &= ~(1 << p_bit); + } + set_collision_layer(collision_layer); +} + +bool CollisionObject2D::get_collision_layer_bit(int p_bit) const { + return get_collision_layer() & (1 << p_bit); +} + +void CollisionObject2D::set_collision_mask_bit(int p_bit, bool p_value) { + uint32_t mask = get_collision_mask(); + if (p_value) { + mask |= 1 << p_bit; + } else { + mask &= ~(1 << p_bit); + } + set_collision_mask(mask); +} + +bool CollisionObject2D::get_collision_mask_bit(int p_bit) const { + return get_collision_mask() & (1 << p_bit); +} + uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) { ShapeData sd; uint32_t id; @@ -374,7 +428,14 @@ String CollisionObject2D::get_configuration_warning() const { void CollisionObject2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid); - + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &CollisionObject2D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &CollisionObject2D::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &CollisionObject2D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &CollisionObject2D::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &CollisionObject2D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &CollisionObject2D::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &CollisionObject2D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &CollisionObject2D::get_collision_mask_bit); ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable); ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable); ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject2D::create_shape_owner); @@ -403,9 +464,12 @@ void CollisionObject2D::_bind_methods() { ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); - ADD_GROUP("Pickable", "input_"); + ADD_GROUP("Collision", "collision_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_GROUP("Input", "input_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pickable"), "set_pickable", "is_pickable"); - ADD_GROUP("", ""); } CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index c99c463a995..5877d171aa0 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -37,6 +37,9 @@ class CollisionObject2D : public Node2D { GDCLASS(CollisionObject2D, Node2D); + uint32_t collision_layer = 1; + uint32_t collision_mask = 1; + bool area; RID rid; bool pickable; @@ -82,6 +85,18 @@ protected: void set_only_update_transform_changes(bool p_enable); public: + void set_collision_layer(uint32_t p_layer); + uint32_t get_collision_layer() const; + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_layer_bit(int p_bit, bool p_value); + bool get_collision_layer_bit(int p_bit) const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + uint32_t create_shape_owner(Object *p_owner); void remove_shape_owner(uint32_t owner); void get_shape_owners(List *r_owners); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index b63d7faab4e..9fea3cc7243 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -52,80 +52,17 @@ uint32_t PhysicsBody2D::_get_layers() const { } void PhysicsBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody2D::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody2D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody2D::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody2D::get_collision_mask); - - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody2D::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody2D::get_collision_mask_bit); - - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody2D::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody2D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody2D::_set_layers); ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody2D::_get_layers); - ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions); ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with); ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody2D::remove_collision_exception_with); ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_2D_PHYSICS, "", 0), "_set_layers", "_get_layers"); //for backwards compat - - ADD_GROUP("Collision", "collision_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask"); -} - -void PhysicsBody2D::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; - Physics2DServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); -} - -uint32_t PhysicsBody2D::get_collision_layer() const { - return collision_layer; -} - -void PhysicsBody2D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; - Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); -} - -uint32_t PhysicsBody2D::get_collision_mask() const { - return collision_mask; -} - -void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); - if (p_value) { - mask |= 1 << p_bit; - } else { - mask &= ~(1 << p_bit); - } - set_collision_mask(mask); -} -bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); -} - -void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t collision_layer = get_collision_layer(); - if (p_value) { - collision_layer |= 1 << p_bit; - } else { - collision_layer &= ~(1 << p_bit); - } - set_collision_layer(collision_layer); -} - -bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D(Physics2DServer::get_singleton()->body_create(), false) { Physics2DServer::get_singleton()->body_set_mode(get_rid(), p_mode); - collision_layer = 1; - collision_mask = 1; set_pickable(false); } diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 1dbfef7a66d..911b8f6cee9 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -41,9 +41,6 @@ class KinematicCollision2D; class PhysicsBody2D : public CollisionObject2D { GDCLASS(PhysicsBody2D, CollisionObject2D); - uint32_t collision_layer; - uint32_t collision_mask; - void _set_layers(uint32_t p_mask); uint32_t _get_layers() const; @@ -54,18 +51,6 @@ protected: static void _bind_methods(); public: - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; - - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collision_mask_bit(int p_bit, bool p_value); - bool get_collision_mask_bit(int p_bit) const; - - void set_collision_layer_bit(int p_bit, bool p_value); - bool get_collision_layer_bit(int p_bit) const; - Array get_collision_exceptions(); void add_collision_exception_with(Node *p_node); //must be physicsbody void remove_collision_exception_with(Node *p_node); diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 9e4ae8d2c5e..d45bd2fe283 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -441,50 +441,6 @@ bool Area::overlaps_body(Node *p_body) const { } return E->get().in_tree; } -void Area::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; - PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); -} - -uint32_t Area::get_collision_mask() const { - return collision_mask; -} -void Area::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; - PhysicsServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); -} - -uint32_t Area::get_collision_layer() const { - return collision_layer; -} - -void Area::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); - if (p_value) { - mask |= 1 << p_bit; - } else { - mask &= ~(1 << p_bit); - } - set_collision_mask(mask); -} - -bool Area::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); -} - -void Area::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t layer = get_collision_layer(); - if (p_value) { - layer |= 1 << p_bit; - } else { - layer &= ~(1 << p_bit); - } - set_collision_layer(layer); -} - -bool Area::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); -} void Area::set_audio_bus_override(bool p_override) { audio_bus_override = p_override; @@ -585,18 +541,6 @@ void Area::_bind_methods() { ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority); ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority); - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area::get_collision_mask); - - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area::get_collision_layer); - - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area::get_collision_mask_bit); - - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable); ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable); @@ -653,10 +597,6 @@ void Area::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); - ADD_GROUP("Collision", "collision_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); - ADD_GROUP("Audio Bus", "audio_bus_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_bus_override"), "set_audio_bus_override", "is_overriding_audio_bus"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus", "get_audio_bus"); @@ -687,8 +627,6 @@ Area::Area() : priority = 0; monitoring = false; monitorable = false; - collision_mask = 1; - collision_layer = 1; set_monitoring(true); set_monitorable(true); diff --git a/scene/3d/area.h b/scene/3d/area.h index 923e368a58f..478ed0115ba 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -54,8 +54,6 @@ private: real_t gravity_distance_scale; real_t angular_damp; real_t linear_damp; - uint32_t collision_mask; - uint32_t collision_layer; int priority; bool monitoring; bool monitorable; @@ -169,18 +167,6 @@ public: void set_monitorable(bool p_enable); bool is_monitorable() const; - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; - - void set_collision_mask_bit(int p_bit, bool p_value); - bool get_collision_mask_bit(int p_bit) const; - - void set_collision_layer_bit(int p_bit, bool p_value); - bool get_collision_layer_bit(int p_bit) const; - Array get_overlapping_bodies() const; Array get_overlapping_areas() const; //function for script diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp index 1fabc11bce4..51736f2358a 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object.cpp @@ -83,6 +83,60 @@ void CollisionObject::_notification(int p_what) { } } +void CollisionObject::set_collision_layer(uint32_t p_layer) { + collision_layer = p_layer; + if (area) { + PhysicsServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); + } else { + PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); + } +} + +uint32_t CollisionObject::get_collision_layer() const { + return collision_layer; +} + +void CollisionObject::set_collision_mask(uint32_t p_mask) { + collision_mask = p_mask; + if (area) { + PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); + } else { + PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); + } +} + +uint32_t CollisionObject::get_collision_mask() const { + return collision_mask; +} + +void CollisionObject::set_collision_layer_bit(int p_bit, bool p_value) { + uint32_t collision_layer = get_collision_layer(); + if (p_value) { + collision_layer |= 1 << p_bit; + } else { + collision_layer &= ~(1 << p_bit); + } + set_collision_layer(collision_layer); +} + +bool CollisionObject::get_collision_layer_bit(int p_bit) const { + return get_collision_layer() & (1 << p_bit); +} + +void CollisionObject::set_collision_mask_bit(int p_bit, bool p_value) { + uint32_t mask = get_collision_mask(); + if (p_value) { + mask |= 1 << p_bit; + } else { + mask &= ~(1 << p_bit); + } + set_collision_mask(mask); +} + +bool CollisionObject::get_collision_mask_bit(int p_bit) const { + return get_collision_mask() & (1 << p_bit); +} + void CollisionObject::_input_event(Node *p_camera, const Ref &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); @@ -183,6 +237,14 @@ bool CollisionObject::is_ray_pickable() const { } void CollisionObject::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &CollisionObject::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &CollisionObject::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &CollisionObject::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &CollisionObject::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &CollisionObject::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &CollisionObject::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &CollisionObject::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &CollisionObject::get_collision_mask_bit); ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject::set_ray_pickable); ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject::is_ray_pickable); ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject::set_capture_input_on_drag); @@ -212,6 +274,11 @@ void CollisionObject::_bind_methods() { ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); + ADD_GROUP("Collision", "collision_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_GROUP("Input", "input_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_ray_pickable"), "set_ray_pickable", "is_ray_pickable"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_capture_on_drag"), "set_capture_input_on_drag", "get_capture_input_on_drag"); } diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object.h index 929ea59e042..14e285bbe76 100644 --- a/scene/3d/collision_object.h +++ b/scene/3d/collision_object.h @@ -37,6 +37,9 @@ class CollisionObject : public Spatial { GDCLASS(CollisionObject, Spatial); + uint32_t collision_layer = 1; + uint32_t collision_mask = 1; + bool area; RID rid; @@ -87,6 +90,18 @@ protected: void _clear_debug_shapes(); public: + void set_collision_layer(uint32_t p_layer); + uint32_t get_collision_layer() const; + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_layer_bit(int p_bit, bool p_value); + bool get_collision_layer_bit(int p_bit) const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + uint32_t create_shape_owner(Object *p_owner); void remove_shape_owner(uint32_t owner); void get_shape_owners(List *r_owners); diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index bea0f1a0c2c..3344128dda9 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -56,52 +56,6 @@ float PhysicsBody::get_inverse_mass() const { return 0; } -void PhysicsBody::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); -} - -uint32_t PhysicsBody::get_collision_layer() const { - return collision_layer; -} - -void PhysicsBody::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); -} - -uint32_t PhysicsBody::get_collision_mask() const { - return collision_mask; -} - -void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); - if (p_value) { - mask |= 1 << p_bit; - } else { - mask &= ~(1 << p_bit); - } - set_collision_mask(mask); -} - -bool PhysicsBody::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); -} - -void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_layer(); - if (p_value) { - mask |= 1 << p_bit; - } else { - mask &= ~(1 << p_bit); - } - set_collision_layer(mask); -} - -bool PhysicsBody::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); -} - Array PhysicsBody::get_collision_exceptions() { List exceptions; PhysicsServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); @@ -140,30 +94,12 @@ uint32_t PhysicsBody::_get_layers() const { } void PhysicsBody::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody::get_collision_layer); - - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody::get_collision_mask); - - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody::get_collision_mask_bit); - - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody::_set_layers); ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody::_get_layers); - - ADD_GROUP("Collision", "collision_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); } PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) : CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) { - collision_layer = 1; - collision_mask = 1; } #ifndef DISABLE_DEPRECATED diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index c0a9c315a8f..a0039f11f99 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -40,9 +40,6 @@ class PhysicsBody : public CollisionObject { GDCLASS(PhysicsBody, CollisionObject); - uint32_t collision_layer; - uint32_t collision_mask; - void _set_layers(uint32_t p_mask); uint32_t _get_layers() const; @@ -56,18 +53,6 @@ public: virtual Vector3 get_angular_velocity() const; virtual float get_inverse_mass() const; - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; - - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collision_layer_bit(int p_bit, bool p_value); - bool get_collision_layer_bit(int p_bit) const; - - void set_collision_mask_bit(int p_bit, bool p_value); - bool get_collision_mask_bit(int p_bit) const; - Array get_collision_exceptions(); void add_collision_exception_with(Node *p_node); //must be physicsbody void remove_collision_exception_with(Node *p_node);