From 4453d63bb0ce6ef891da3f0131e212ae54bde12c Mon Sep 17 00:00:00 2001 From: Ricardo Buring Date: Wed, 23 Nov 2022 18:32:30 +0100 Subject: [PATCH] Update remaining physics exclude parameters to use TypedArray Also update the documentation to refer to the get_rid() method. --- doc/classes/PhysicsPointQueryParameters2D.xml | 2 +- doc/classes/PhysicsPointQueryParameters3D.xml | 4 +- doc/classes/PhysicsRayQueryParameters2D.xml | 2 +- doc/classes/PhysicsRayQueryParameters3D.xml | 2 +- doc/classes/PhysicsShapeQueryParameters2D.xml | 2 +- doc/classes/PhysicsShapeQueryParameters3D.xml | 4 +- doc/classes/PhysicsTestMotionParameters2D.xml | 4 +- doc/classes/PhysicsTestMotionParameters3D.xml | 6 +-- servers/physics_server_2d.cpp | 6 +-- servers/physics_server_2d.h | 4 +- servers/physics_server_3d.cpp | 40 +++++++++---------- servers/physics_server_3d.h | 16 ++++---- 12 files changed, 46 insertions(+), 46 deletions(-) diff --git a/doc/classes/PhysicsPointQueryParameters2D.xml b/doc/classes/PhysicsPointQueryParameters2D.xml index a6cbe2d574d..e49d2a9f5f8 100644 --- a/doc/classes/PhysicsPointQueryParameters2D.xml +++ b/doc/classes/PhysicsPointQueryParameters2D.xml @@ -22,7 +22,7 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The list of objects or object [RID]s that will be excluded from collisions. + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject2D.get_rid] to get the [RID] associated with a [CollisionObject2D]-derived node. The position being queried for, in global coordinates. diff --git a/doc/classes/PhysicsPointQueryParameters3D.xml b/doc/classes/PhysicsPointQueryParameters3D.xml index bedf05ce996..3270d3686d9 100644 --- a/doc/classes/PhysicsPointQueryParameters3D.xml +++ b/doc/classes/PhysicsPointQueryParameters3D.xml @@ -18,8 +18,8 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - The list of objects or object [RID]s that will be excluded from collisions. + + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject3D.get_rid] to get the [RID] associated with a [CollisionObject3D]-derived node. The position being queried for, in global coordinates. diff --git a/doc/classes/PhysicsRayQueryParameters2D.xml b/doc/classes/PhysicsRayQueryParameters2D.xml index d6a2662adca..cf5c31d9ec4 100644 --- a/doc/classes/PhysicsRayQueryParameters2D.xml +++ b/doc/classes/PhysicsRayQueryParameters2D.xml @@ -35,7 +35,7 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The list of objects or object [RID]s that will be excluded from collisions. + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject2D.get_rid] to get the [RID] associated with a [CollisionObject2D]-derived node. The starting point of the ray being queried for, in global coordinates. diff --git a/doc/classes/PhysicsRayQueryParameters3D.xml b/doc/classes/PhysicsRayQueryParameters3D.xml index 03d6939e6d2..4f70eedb218 100644 --- a/doc/classes/PhysicsRayQueryParameters3D.xml +++ b/doc/classes/PhysicsRayQueryParameters3D.xml @@ -35,7 +35,7 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The list of objects or object [RID]s that will be excluded from collisions. + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject3D.get_rid] to get the [RID] associated with a [CollisionObject3D]-derived node. The starting point of the ray being queried for, in global coordinates. diff --git a/doc/classes/PhysicsShapeQueryParameters2D.xml b/doc/classes/PhysicsShapeQueryParameters2D.xml index 8dcb329e7ee..a73e60c6f51 100644 --- a/doc/classes/PhysicsShapeQueryParameters2D.xml +++ b/doc/classes/PhysicsShapeQueryParameters2D.xml @@ -19,7 +19,7 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - The list of objects or object [RID]s that will be excluded from collisions. + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject2D.get_rid] to get the [RID] associated with a [CollisionObject2D]-derived node. The collision margin for the shape. diff --git a/doc/classes/PhysicsShapeQueryParameters3D.xml b/doc/classes/PhysicsShapeQueryParameters3D.xml index 64100f847b7..a3ff1765f9e 100644 --- a/doc/classes/PhysicsShapeQueryParameters3D.xml +++ b/doc/classes/PhysicsShapeQueryParameters3D.xml @@ -18,8 +18,8 @@ The physics layers the query will detect (as a bitmask). By default, all collision layers are detected. See [url=$DOCS_URL/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - The list of objects or object [RID]s that will be excluded from collisions. + + The list of object [RID]s that will be excluded from collisions. Use [method CollisionObject3D.get_rid] to get the [RID] associated with a [CollisionObject3D]-derived node. The collision margin for the shape. diff --git a/doc/classes/PhysicsTestMotionParameters2D.xml b/doc/classes/PhysicsTestMotionParameters2D.xml index 5b969ea869f..be5e5a36179 100644 --- a/doc/classes/PhysicsTestMotionParameters2D.xml +++ b/doc/classes/PhysicsTestMotionParameters2D.xml @@ -14,9 +14,9 @@ If set to [code]false[/code], shapes of type [constant PhysicsServer2D.SHAPE_SEPARATION_RAY] are only used for separation when overlapping with other bodies. That's the main use for separation ray shapes. - Optional array of body [RID] to exclude from collision. + Optional array of body [RID] to exclude from collision. Use [method CollisionObject2D.get_rid] to get the [RID] associated with a [CollisionObject2D]-derived node. - + Optional array of object unique instance ID to exclude from collision. See [method Object.get_instance_id]. diff --git a/doc/classes/PhysicsTestMotionParameters3D.xml b/doc/classes/PhysicsTestMotionParameters3D.xml index ea9bca6a35c..be7d05691ee 100644 --- a/doc/classes/PhysicsTestMotionParameters3D.xml +++ b/doc/classes/PhysicsTestMotionParameters3D.xml @@ -13,10 +13,10 @@ If set to [code]true[/code], shapes of type [constant PhysicsServer3D.SHAPE_SEPARATION_RAY] are used to detect collisions and can stop the motion. Can be useful when snapping to the ground. If set to [code]false[/code], shapes of type [constant PhysicsServer3D.SHAPE_SEPARATION_RAY] are only used for separation when overlapping with other bodies. That's the main use for separation ray shapes. - - Optional array of body [RID] to exclude from collision. + + Optional array of body [RID] to exclude from collision. Use [method CollisionObject3D.get_rid] to get the [RID] associated with a [CollisionObject3D]-derived node. - + Optional array of object unique instance ID to exclude from collision. See [method Object.get_instance_id]. diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index 21be3116379..c5a93cc390b 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -479,8 +479,8 @@ void PhysicsTestMotionParameters2D::set_exclude_bodies(const TypedArray &p_ } } -Array PhysicsTestMotionParameters2D::get_exclude_objects() const { - Array exclude; +TypedArray PhysicsTestMotionParameters2D::get_exclude_objects() const { + TypedArray exclude; exclude.resize(parameters.exclude_objects.size()); int object_index = 0; @@ -491,7 +491,7 @@ Array PhysicsTestMotionParameters2D::get_exclude_objects() const { return exclude; } -void PhysicsTestMotionParameters2D::set_exclude_objects(const Array &p_exclude) { +void PhysicsTestMotionParameters2D::set_exclude_objects(const TypedArray &p_exclude) { for (int i = 0; i < p_exclude.size(); ++i) { ObjectID object_id = p_exclude[i]; ERR_CONTINUE(object_id.is_null()); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index 95425e72e8b..8b4b5ae4def 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -732,8 +732,8 @@ public: TypedArray get_exclude_bodies() const; void set_exclude_bodies(const TypedArray &p_exclude); - Array get_exclude_objects() const; - void set_exclude_objects(const Array &p_exclude); + TypedArray get_exclude_objects() const; + void set_exclude_objects(const TypedArray &p_exclude); bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; } void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; } diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 35833341f22..aecb687d5f0 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -187,7 +187,7 @@ TypedArray PhysicsRayQueryParameters3D::get_exclude() const { } void PhysicsRayQueryParameters3D::_bind_methods() { - ClassDB::bind_static_method("PhysicsRayQueryParameters3D", D_METHOD("create", "from", "to", "collision_mask", "exclude"), &PhysicsRayQueryParameters3D::create, DEFVAL(UINT32_MAX), DEFVAL(Vector())); + ClassDB::bind_static_method("PhysicsRayQueryParameters3D", D_METHOD("create", "from", "to", "collision_mask", "exclude"), &PhysicsRayQueryParameters3D::create, DEFVAL(UINT32_MAX), DEFVAL(TypedArray())); ClassDB::bind_method(D_METHOD("set_from", "from"), &PhysicsRayQueryParameters3D::set_from); ClassDB::bind_method(D_METHOD("get_from"), &PhysicsRayQueryParameters3D::get_from); @@ -235,19 +235,19 @@ Ref PhysicsRayQueryParameters3D::create(Vector3 p_f return params; } -void PhysicsPointQueryParameters3D::set_exclude(const Vector &p_exclude) { +void PhysicsPointQueryParameters3D::set_exclude(const TypedArray &p_exclude) { parameters.exclude.clear(); for (int i = 0; i < p_exclude.size(); i++) { parameters.exclude.insert(p_exclude[i]); } } -Vector PhysicsPointQueryParameters3D::get_exclude() const { - Vector ret; +TypedArray PhysicsPointQueryParameters3D::get_exclude() const { + TypedArray ret; ret.resize(parameters.exclude.size()); int idx = 0; for (const RID &E : parameters.exclude) { - ret.write[idx++] = E; + ret[idx++] = E; } return ret; } @@ -290,19 +290,19 @@ void PhysicsShapeQueryParameters3D::set_shape_rid(const RID &p_shape) { } } -void PhysicsShapeQueryParameters3D::set_exclude(const Vector &p_exclude) { +void PhysicsShapeQueryParameters3D::set_exclude(const TypedArray &p_exclude) { parameters.exclude.clear(); for (int i = 0; i < p_exclude.size(); i++) { parameters.exclude.insert(p_exclude[i]); } } -Vector PhysicsShapeQueryParameters3D::get_exclude() const { - Vector ret; +TypedArray PhysicsShapeQueryParameters3D::get_exclude() const { + TypedArray ret; ret.resize(parameters.exclude.size()); int idx = 0; for (const RID &E : parameters.exclude) { - ret.write[idx++] = E; + ret[idx++] = E; } return ret; } @@ -482,37 +482,37 @@ void PhysicsDirectSpaceState3D::_bind_methods() { /////////////////////////////// -Vector PhysicsTestMotionParameters3D::get_exclude_bodies() const { - Vector exclude; +TypedArray PhysicsTestMotionParameters3D::get_exclude_bodies() const { + TypedArray exclude; exclude.resize(parameters.exclude_bodies.size()); int body_index = 0; - for (RID body : parameters.exclude_bodies) { - exclude.write[body_index++] = body; + for (const RID &body : parameters.exclude_bodies) { + exclude[body_index++] = body; } return exclude; } -void PhysicsTestMotionParameters3D::set_exclude_bodies(const Vector &p_exclude) { - for (RID body : p_exclude) { - parameters.exclude_bodies.insert(body); +void PhysicsTestMotionParameters3D::set_exclude_bodies(const TypedArray &p_exclude) { + for (int i = 0; i < p_exclude.size(); i++) { + parameters.exclude_bodies.insert(p_exclude[i]); } } -Array PhysicsTestMotionParameters3D::get_exclude_objects() const { - Array exclude; +TypedArray PhysicsTestMotionParameters3D::get_exclude_objects() const { + TypedArray exclude; exclude.resize(parameters.exclude_objects.size()); int object_index = 0; - for (ObjectID object_id : parameters.exclude_objects) { + for (const ObjectID &object_id : parameters.exclude_objects) { exclude[object_index++] = object_id; } return exclude; } -void PhysicsTestMotionParameters3D::set_exclude_objects(const Array &p_exclude) { +void PhysicsTestMotionParameters3D::set_exclude_objects(const TypedArray &p_exclude) { for (int i = 0; i < p_exclude.size(); ++i) { ObjectID object_id = p_exclude[i]; ERR_CONTINUE(object_id.is_null()); diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index de6645f27e9..5335bc31091 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -873,8 +873,8 @@ public: void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; } bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; } - void set_exclude(const Vector &p_exclude); - Vector get_exclude() const; + void set_exclude(const TypedArray &p_exclude); + TypedArray get_exclude() const; }; class PhysicsShapeQueryParameters3D : public RefCounted { @@ -914,8 +914,8 @@ public: void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; } bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; } - void set_exclude(const Vector &p_exclude); - Vector get_exclude() const; + void set_exclude(const TypedArray &p_exclude); + TypedArray get_exclude() const; }; class PhysicsTestMotionParameters3D : public RefCounted { @@ -944,11 +944,11 @@ public: bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; } void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; } - Vector get_exclude_bodies() const; - void set_exclude_bodies(const Vector &p_exclude); + TypedArray get_exclude_bodies() const; + void set_exclude_bodies(const TypedArray &p_exclude); - Array get_exclude_objects() const; - void set_exclude_objects(const Array &p_exclude); + TypedArray get_exclude_objects() const; + void set_exclude_objects(const TypedArray &p_exclude); bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; } void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }