Skip to content

Commit

Permalink
Merge pull request #95374 from raulsntos/gdextension/expose-property-…
Browse files Browse the repository at this point in the history
…accessors/ShapeCast

Expose `ShapeCast{2D,3D}::get_collision_result`
  • Loading branch information
akien-mga committed Aug 16, 2024
2 parents 886d586 + e47ff98 commit 987635b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/classes/ShapeCast2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be detected.
</member>
<member name="collision_result" type="Array" setter="" getter="_get_collision_result" default="[]">
<member name="collision_result" type="Array" setter="" getter="get_collision_result" default="[]">
Returns the complete collision information from the collision sweep. The data returned is the same as in the [method PhysicsDirectSpaceState2D.get_rest_info] method.
</member>
<member name="enabled" type="bool" setter="set_enabled" getter="is_enabled" default="true">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/ShapeCast3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask" default="1">
The shape's collision mask. Only objects in at least one collision layer enabled in the mask will be 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.
</member>
<member name="collision_result" type="Array" setter="" getter="_get_collision_result" default="[]">
<member name="collision_result" type="Array" setter="" getter="get_collision_result" default="[]">
Returns the complete collision information from the collision sweep. The data returned is the same as in the [method PhysicsDirectSpaceState3D.get_rest_info] method.
</member>
<member name="debug_shape_custom_color" type="Color" setter="set_debug_shape_custom_color" getter="get_debug_shape_custom_color" default="Color(0, 0, 0, 1)">
Expand Down
7 changes: 7 additions & 0 deletions misc/extension_api_validation/4.3-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ should instead be used to justify these changes and describe how users should wo
Add new entries at the end of the file.

## Changes between 4.3-stable and 4.4-stable

GH-95374
--------
Validate extension JSON: Error: Field 'classes/ShapeCast2D/properties/collision_result': getter changed value in new API, from "_get_collision_result" to &"get_collision_result".
Validate extension JSON: Error: Field 'classes/ShapeCast3D/properties/collision_result': getter changed value in new API, from "_get_collision_result" to &"get_collision_result".

These getters have been renamed to expose them. GDExtension language bindings couldn't have exposed these properties before.
6 changes: 3 additions & 3 deletions scene/2d/physics/shape_cast_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool ShapeCast2D::is_collide_with_bodies_enabled() const {
return collide_with_bodies;
}

Array ShapeCast2D::_get_collision_result() const {
Array ShapeCast2D::get_collision_result() const {
Array ret;

for (int i = 0; i < result.size(); ++i) {
Expand Down Expand Up @@ -464,7 +464,7 @@ void ShapeCast2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &ShapeCast2D::set_collide_with_bodies);
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &ShapeCast2D::is_collide_with_bodies_enabled);

ClassDB::bind_method(D_METHOD("_get_collision_result"), &ShapeCast2D::_get_collision_result);
ClassDB::bind_method(D_METHOD("get_collision_result"), &ShapeCast2D::get_collision_result);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
Expand All @@ -473,7 +473,7 @@ void ShapeCast2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01,suffix:px"), "set_margin", "get_margin");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_results"), "set_max_results", "get_max_results");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "_get_collision_result");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "get_collision_result");
ADD_GROUP("Collide With", "collide_with");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/physics/shape_cast_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class ShapeCast2D : public Node2D {
real_t collision_safe_fraction = 1.0;
real_t collision_unsafe_fraction = 1.0;

Array _get_collision_result() const;
void _shape_changed();

protected:
Expand Down Expand Up @@ -102,6 +101,7 @@ class ShapeCast2D : public Node2D {
void force_shapecast_update();
bool is_colliding() const;

Array get_collision_result() const;
int get_collision_count() const;
Object *get_collider(int p_idx) const;
RID get_collider_rid(int p_idx) const;
Expand Down
6 changes: 3 additions & 3 deletions scene/3d/physics/shape_cast_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void ShapeCast3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &ShapeCast3D::set_collide_with_bodies);
ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &ShapeCast3D::is_collide_with_bodies_enabled);

ClassDB::bind_method(D_METHOD("_get_collision_result"), &ShapeCast3D::_get_collision_result);
ClassDB::bind_method(D_METHOD("get_collision_result"), &ShapeCast3D::get_collision_result);

ClassDB::bind_method(D_METHOD("set_debug_shape_custom_color", "debug_shape_custom_color"), &ShapeCast3D::set_debug_shape_custom_color);
ClassDB::bind_method(D_METHOD("get_debug_shape_custom_color"), &ShapeCast3D::get_debug_shape_custom_color);
Expand All @@ -169,7 +169,7 @@ void ShapeCast3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01,suffix:m"), "set_margin", "get_margin");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_results"), "set_max_results", "get_max_results");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "_get_collision_result");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "collision_result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "", "get_collision_result");

ADD_GROUP("Collide With", "collide_with");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_areas", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_areas", "is_collide_with_areas_enabled");
Expand Down Expand Up @@ -475,7 +475,7 @@ bool ShapeCast3D::is_collide_with_bodies_enabled() const {
return collide_with_bodies;
}

Array ShapeCast3D::_get_collision_result() const {
Array ShapeCast3D::get_collision_result() const {
Array ret;

for (int i = 0; i < result.size(); ++i) {
Expand Down
3 changes: 1 addition & 2 deletions scene/3d/physics/shape_cast_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class ShapeCast3D : public Node3D {
real_t collision_safe_fraction = 1.0;
real_t collision_unsafe_fraction = 1.0;

Array _get_collision_result() const;

RID debug_instance;
Ref<ArrayMesh> debug_mesh;

Expand Down Expand Up @@ -123,6 +121,7 @@ class ShapeCast3D : public Node3D {

Ref<StandardMaterial3D> get_debug_material();

Array get_collision_result() const;
int get_collision_count() const;
Object *get_collider(int p_idx) const;
RID get_collider_rid(int p_idx) const;
Expand Down

0 comments on commit 987635b

Please sign in to comment.