Skip to content

Commit 26643c4

Browse files
committed
Add PhysicsDirectSpaceState2D::get_rest_info_no_alloc
1 parent 8a9ee62 commit 26643c4

7 files changed

Lines changed: 178 additions & 0 deletions

doc/classes/PhysicsDirectSpaceState2D.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
If the shape did not intersect anything, then an empty dictionary is returned instead.
6565
</description>
6666
</method>
67+
<method name="get_rest_info_no_alloc">
68+
<return type="bool" />
69+
<param index="0" name="parameters" type="PhysicsShapeQueryParameters2D" />
70+
<param index="1" name="result" type="PhysicsGetRestInfoResult2D" />
71+
<description>
72+
Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters2D] object, against the space.
73+
If the shape collides with one or more shapes, this method returns [code]true[/code] and writes the nearest collision information into the [PhysicsGetRestInfoResult2D] object passed in [param result]. If no collisions occur, it returns [code]false[/code].
74+
</description>
75+
</method>
6776
<method name="intersect_point">
6877
<return type="Dictionary[]" />
6978
<param index="0" name="parameters" type="PhysicsPointQueryParameters2D" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="PhysicsGetRestInfoResult2D" inherits="RefCounted" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Stores the nearest collision information of a shape query.
5+
</brief_description>
6+
<description>
7+
This class contains the collision data computed by [method PhysicsDirectSpaceState2D.get_rest_info_no_alloc].
8+
If the shape collides with multiple objects, only the nearest collision is stored.
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
<members>
13+
<member name="collider_id" type="int" setter="" getter="get_collider_id" default="0">
14+
The unique ID of the colliding shape.
15+
</member>
16+
<member name="collider_rid" type="RID" setter="" getter="get_collider_rid" default="RID()">
17+
The [RID] of the colliding shape.
18+
</member>
19+
<member name="collider_shape" type="int" setter="" getter="get_collider_shape" default="0">
20+
The shape index of the colliding shape.
21+
</member>
22+
<member name="collider_velocity" type="Vector2" setter="" getter="get_collider_velocity" default="Vector2(0, 0)">
23+
The linear velocity of the colliding object. If the object is an [Area2D], the result is [code]Vector2(0, 0)[/code].
24+
</member>
25+
<member name="normal" type="Vector2" setter="" getter="get_normal" default="Vector2(0, 0)">
26+
The collision normal at the intersection point, pointing away from the colliding shape.
27+
</member>
28+
<member name="point" type="Vector2" setter="" getter="get_point" default="Vector2(0, 0)">
29+
The collision point on the colliding shape.
30+
</member>
31+
</members>
32+
</class>

servers/physics_2d/direct_states/physics_direct_space_state_2d.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ bool PhysicsDirectSpaceState2D::_collide_shape_no_alloc(RequiredParam<PhysicsSha
192192
return collide_shape(p_shape_query->get_parameters(), p_result->result.ptrw(), p_result->get_max_collisions(), p_result->collision_count);
193193
}
194194

195+
bool PhysicsDirectSpaceState2D::_get_rest_info_no_alloc(RequiredParam<PhysicsShapeQueryParameters2D> rp_shape_query, RequiredParam<PhysicsGetRestInfoResult2D> rp_result) {
196+
EXTRACT_PARAM_OR_FAIL_V(p_shape_query, rp_shape_query, false);
197+
EXTRACT_PARAM_OR_FAIL_V(p_result, rp_result, false);
198+
199+
return rest_info(p_shape_query->get_parameters(), &p_result->result);
200+
}
201+
195202
PhysicsDirectSpaceState2D::PhysicsDirectSpaceState2D() {
196203
}
197204

@@ -208,4 +215,5 @@ void PhysicsDirectSpaceState2D::_bind_methods() {
208215
ClassDB::bind_method(D_METHOD("intersect_shape_no_alloc", "parameters", "result"), &PhysicsDirectSpaceState2D::_intersect_shape_no_alloc);
209216
ClassDB::bind_method(D_METHOD("cast_motion_no_alloc", "parameters", "result"), &PhysicsDirectSpaceState2D::_cast_motion_no_alloc);
210217
ClassDB::bind_method(D_METHOD("collide_shape_no_alloc", "parameters", "result"), &PhysicsDirectSpaceState2D::_collide_shape_no_alloc);
218+
ClassDB::bind_method(D_METHOD("get_rest_info_no_alloc", "parameters", "result"), &PhysicsDirectSpaceState2D::_get_rest_info_no_alloc);
211219
}

servers/physics_2d/direct_states/physics_direct_space_state_2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "servers/physics_2d/physics_server_2d_types.h"
3535
#include "servers/physics_2d/queries/physics_cast_motion_result_2d.h"
3636
#include "servers/physics_2d/queries/physics_collide_shape_result_2d.h"
37+
#include "servers/physics_2d/queries/physics_get_rest_info_result_2d.h"
3738
#include "servers/physics_2d/queries/physics_intersect_point_result_2d.h"
3839
#include "servers/physics_2d/queries/physics_intersect_ray_result_2d.h"
3940
#include "servers/physics_2d/queries/physics_intersect_shape_result_2d.h"
@@ -56,6 +57,7 @@ class PhysicsDirectSpaceState2D : public Object {
5657
bool _intersect_shape_no_alloc(RequiredParam<PhysicsShapeQueryParameters2D> rp_shape_query, RequiredParam<PhysicsIntersectShapeResult2D> rp_result);
5758
bool _cast_motion_no_alloc(RequiredParam<PhysicsShapeQueryParameters2D> rp_shape_query, RequiredParam<PhysicsCastMotionResult2D> rp_result);
5859
bool _collide_shape_no_alloc(RequiredParam<PhysicsShapeQueryParameters2D> rp_shape_query, RequiredParam<PhysicsCollideShapeResult2D> rp_result);
60+
bool _get_rest_info_no_alloc(RequiredParam<PhysicsShapeQueryParameters2D> rp_shape_query, RequiredParam<PhysicsGetRestInfoResult2D> rp_result);
5961

6062
protected:
6163
static void _bind_methods();
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**************************************************************************/
2+
/* physics_get_rest_info_result_2d.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "physics_get_rest_info_result_2d.h"
32+
33+
#include "core/object/class_db.h"
34+
35+
Vector2 PhysicsGetRestInfoResult2D::get_point() const {
36+
return result.point;
37+
}
38+
39+
Vector2 PhysicsGetRestInfoResult2D::get_normal() const {
40+
return result.normal;
41+
}
42+
43+
RID PhysicsGetRestInfoResult2D::get_collider_rid() const {
44+
return result.rid;
45+
}
46+
47+
ObjectID PhysicsGetRestInfoResult2D::get_collider_id() const {
48+
return result.collider_id;
49+
}
50+
51+
int PhysicsGetRestInfoResult2D::get_collider_shape() const {
52+
return result.shape;
53+
}
54+
55+
Vector2 PhysicsGetRestInfoResult2D::get_collider_velocity() const {
56+
return result.linear_velocity;
57+
}
58+
59+
void PhysicsGetRestInfoResult2D::_bind_methods() {
60+
ClassDB::bind_method(D_METHOD("get_point"), &PhysicsGetRestInfoResult2D::get_point);
61+
ClassDB::bind_method(D_METHOD("get_normal"), &PhysicsGetRestInfoResult2D::get_normal);
62+
ClassDB::bind_method(D_METHOD("get_collider_rid"), &PhysicsGetRestInfoResult2D::get_collider_rid);
63+
ClassDB::bind_method(D_METHOD("get_collider_id"), &PhysicsGetRestInfoResult2D::get_collider_id);
64+
ClassDB::bind_method(D_METHOD("get_collider_shape"), &PhysicsGetRestInfoResult2D::get_collider_shape);
65+
ClassDB::bind_method(D_METHOD("get_collider_velocity"), &PhysicsGetRestInfoResult2D::get_collider_velocity);
66+
67+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "point"), "", "get_point");
68+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "normal"), "", "get_normal");
69+
ADD_PROPERTY(PropertyInfo(Variant::RID, "collider_rid"), "", "get_collider_rid");
70+
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_id"), "", "get_collider_id");
71+
ADD_PROPERTY(PropertyInfo(Variant::INT, "collider_shape"), "", "get_collider_shape");
72+
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "collider_velocity"), "", "get_collider_velocity");
73+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**************************************************************************/
2+
/* physics_get_rest_info_result_2d.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "core/object/ref_counted.h"
34+
#include "servers/physics_2d/physics_server_2d_types.h"
35+
36+
class PhysicsGetRestInfoResult2D : public RefCounted {
37+
GDCLASS(PhysicsGetRestInfoResult2D, RefCounted);
38+
39+
friend class PhysicsDirectSpaceState2D;
40+
41+
PS2DT::ShapeRestInfo result;
42+
43+
protected:
44+
static void _bind_methods();
45+
46+
public:
47+
Vector2 get_point() const;
48+
Vector2 get_normal() const;
49+
RID get_collider_rid() const;
50+
ObjectID get_collider_id() const;
51+
int get_collider_shape() const;
52+
Vector2 get_collider_velocity() const;
53+
};

servers/register_server_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ void register_server_types() {
311311
GDREGISTER_CLASS(PhysicsIntersectShapeResult2D);
312312
GDREGISTER_CLASS(PhysicsCastMotionResult2D);
313313
GDREGISTER_CLASS(PhysicsCollideShapeResult2D);
314+
GDREGISTER_CLASS(PhysicsGetRestInfoResult2D);
314315
GDREGISTER_CLASS(PhysicsTestMotionParameters2D);
315316
GDREGISTER_CLASS(PhysicsTestMotionResult2D);
316317

0 commit comments

Comments
 (0)