1/**************************************************************************/
2/* physics_server_2d_extension.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_server_2d_extension.h"
32
33bool PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query(const RID &p_body) const {
34 return exclude && exclude->has(p_body);
35}
36
37thread_local const HashSet<RID> *PhysicsDirectSpaceState2DExtension::exclude = nullptr;
38
39void PhysicsDirectSpaceState2DExtension::_bind_methods() {
40 ClassDB::bind_method(D_METHOD("is_body_excluded_from_query", "body"), &PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query);
41
42 GDVIRTUAL_BIND(_intersect_ray, "from", "to", "collision_mask", "collide_with_bodies", "collide_with_areas", "hit_from_inside", "result");
43 GDVIRTUAL_BIND(_intersect_point, "position", "canvas_instance_id", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results");
44 GDVIRTUAL_BIND(_intersect_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "result", "max_results");
45 GDVIRTUAL_BIND(_cast_motion, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "closest_safe", "closest_unsafe");
46 GDVIRTUAL_BIND(_collide_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results", "result_count");
47 GDVIRTUAL_BIND(_rest_info, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "rest_info");
48}
49
50PhysicsDirectSpaceState2DExtension::PhysicsDirectSpaceState2DExtension() {
51}
52
53void PhysicsDirectBodyState2DExtension::_bind_methods() {
54 GDVIRTUAL_BIND(_get_total_gravity);
55 GDVIRTUAL_BIND(_get_total_linear_damp);
56 GDVIRTUAL_BIND(_get_total_angular_damp);
57
58 GDVIRTUAL_BIND(_get_center_of_mass);
59 GDVIRTUAL_BIND(_get_center_of_mass_local);
60 GDVIRTUAL_BIND(_get_inverse_mass);
61 GDVIRTUAL_BIND(_get_inverse_inertia);
62
63 GDVIRTUAL_BIND(_set_linear_velocity, "velocity");
64 GDVIRTUAL_BIND(_get_linear_velocity);
65
66 GDVIRTUAL_BIND(_set_angular_velocity, "velocity");
67 GDVIRTUAL_BIND(_get_angular_velocity);
68
69 GDVIRTUAL_BIND(_set_transform, "transform");
70 GDVIRTUAL_BIND(_get_transform);
71
72 GDVIRTUAL_BIND(_get_velocity_at_local_position, "local_position");
73
74 GDVIRTUAL_BIND(_apply_central_impulse, "impulse");
75 GDVIRTUAL_BIND(_apply_impulse, "impulse", "position");
76 GDVIRTUAL_BIND(_apply_torque_impulse, "impulse");
77
78 GDVIRTUAL_BIND(_apply_central_force, "force");
79 GDVIRTUAL_BIND(_apply_force, "force", "position");
80 GDVIRTUAL_BIND(_apply_torque, "torque");
81
82 GDVIRTUAL_BIND(_add_constant_central_force, "force");
83 GDVIRTUAL_BIND(_add_constant_force, "force", "position");
84 GDVIRTUAL_BIND(_add_constant_torque, "torque");
85
86 GDVIRTUAL_BIND(_set_constant_force, "force");
87 GDVIRTUAL_BIND(_get_constant_force);
88
89 GDVIRTUAL_BIND(_set_constant_torque, "torque");
90 GDVIRTUAL_BIND(_get_constant_torque);
91
92 GDVIRTUAL_BIND(_set_sleep_state, "enabled");
93 GDVIRTUAL_BIND(_is_sleeping);
94
95 GDVIRTUAL_BIND(_get_contact_count);
96
97 GDVIRTUAL_BIND(_get_contact_local_position, "contact_idx");
98 GDVIRTUAL_BIND(_get_contact_local_normal, "contact_idx");
99 GDVIRTUAL_BIND(_get_contact_local_shape, "contact_idx");
100 GDVIRTUAL_BIND(_get_contact_local_velocity_at_position, "contact_idx");
101 GDVIRTUAL_BIND(_get_contact_collider, "contact_idx");
102 GDVIRTUAL_BIND(_get_contact_collider_position, "contact_idx");
103 GDVIRTUAL_BIND(_get_contact_collider_id, "contact_idx");
104 GDVIRTUAL_BIND(_get_contact_collider_object, "contact_idx");
105 GDVIRTUAL_BIND(_get_contact_collider_shape, "contact_idx");
106 GDVIRTUAL_BIND(_get_contact_collider_velocity_at_position, "contact_idx");
107 GDVIRTUAL_BIND(_get_contact_impulse, "contact_idx");
108
109 GDVIRTUAL_BIND(_get_step);
110 GDVIRTUAL_BIND(_integrate_forces);
111
112 GDVIRTUAL_BIND(_get_space_state);
113}
114
115PhysicsDirectBodyState2DExtension::PhysicsDirectBodyState2DExtension() {
116}
117
118thread_local const HashSet<RID> *PhysicsServer2DExtension::exclude_bodies = nullptr;
119thread_local const HashSet<ObjectID> *PhysicsServer2DExtension::exclude_objects = nullptr;
120
121bool PhysicsServer2DExtension::body_test_motion_is_excluding_body(RID p_body) const {
122 return exclude_bodies && exclude_bodies->has(p_body);
123}
124
125bool PhysicsServer2DExtension::body_test_motion_is_excluding_object(ObjectID p_object) const {
126 return exclude_objects && exclude_objects->has(p_object);
127}
128
129void PhysicsServer2DExtension::_bind_methods() {
130 /* SHAPE API */
131
132 GDVIRTUAL_BIND(_world_boundary_shape_create);
133 GDVIRTUAL_BIND(_separation_ray_shape_create);
134 GDVIRTUAL_BIND(_segment_shape_create);
135 GDVIRTUAL_BIND(_circle_shape_create);
136 GDVIRTUAL_BIND(_rectangle_shape_create);
137 GDVIRTUAL_BIND(_capsule_shape_create);
138 GDVIRTUAL_BIND(_convex_polygon_shape_create);
139 GDVIRTUAL_BIND(_concave_polygon_shape_create);
140
141 GDVIRTUAL_BIND(_shape_set_data, "shape", "data");
142 GDVIRTUAL_BIND(_shape_set_custom_solver_bias, "shape", "bias");
143
144 GDVIRTUAL_BIND(_shape_get_type, "shape");
145 GDVIRTUAL_BIND(_shape_get_data, "shape");
146 GDVIRTUAL_BIND(_shape_get_custom_solver_bias, "shape");
147 GDVIRTUAL_BIND(_shape_collide, "shape_A", "xform_A", "motion_A", "shape_B", "xform_B", "motion_B", "results", "result_max", "result_count");
148
149 /* SPACE API */
150
151 GDVIRTUAL_BIND(_space_create);
152 GDVIRTUAL_BIND(_space_set_active, "space", "active");
153 GDVIRTUAL_BIND(_space_is_active, "space");
154
155 GDVIRTUAL_BIND(_space_set_param, "space", "param", "value");
156 GDVIRTUAL_BIND(_space_get_param, "space", "param");
157
158 GDVIRTUAL_BIND(_space_get_direct_state, "space");
159
160 GDVIRTUAL_BIND(_space_set_debug_contacts, "space", "max_contacts");
161 GDVIRTUAL_BIND(_space_get_contacts, "space");
162 GDVIRTUAL_BIND(_space_get_contact_count, "space");
163
164 /* AREA API */
165
166 GDVIRTUAL_BIND(_area_create);
167
168 GDVIRTUAL_BIND(_area_set_space, "area", "space");
169 GDVIRTUAL_BIND(_area_get_space, "area");
170
171 GDVIRTUAL_BIND(_area_add_shape, "area", "shape", "transform", "disabled");
172 GDVIRTUAL_BIND(_area_set_shape, "area", "shape_idx", "shape");
173 GDVIRTUAL_BIND(_area_set_shape_transform, "area", "shape_idx", "transform");
174 GDVIRTUAL_BIND(_area_set_shape_disabled, "area", "shape_idx", "disabled");
175
176 GDVIRTUAL_BIND(_area_get_shape_count, "area");
177 GDVIRTUAL_BIND(_area_get_shape, "area", "shape_idx");
178 GDVIRTUAL_BIND(_area_get_shape_transform, "area", "shape_idx");
179
180 GDVIRTUAL_BIND(_area_remove_shape, "area", "shape_idx");
181 GDVIRTUAL_BIND(_area_clear_shapes, "area");
182
183 GDVIRTUAL_BIND(_area_attach_object_instance_id, "area", "id");
184 GDVIRTUAL_BIND(_area_get_object_instance_id, "area");
185
186 GDVIRTUAL_BIND(_area_attach_canvas_instance_id, "area", "id");
187 GDVIRTUAL_BIND(_area_get_canvas_instance_id, "area");
188
189 GDVIRTUAL_BIND(_area_set_param, "area", "param", "value");
190 GDVIRTUAL_BIND(_area_set_transform, "area", "transform");
191
192 GDVIRTUAL_BIND(_area_get_param, "area", "param");
193 GDVIRTUAL_BIND(_area_get_transform, "area");
194
195 GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer");
196 GDVIRTUAL_BIND(_area_get_collision_layer, "area");
197
198 GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask");
199 GDVIRTUAL_BIND(_area_get_collision_mask, "area");
200
201 GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable");
202 GDVIRTUAL_BIND(_area_set_pickable, "area", "pickable");
203
204 GDVIRTUAL_BIND(_area_set_monitor_callback, "area", "callback");
205 GDVIRTUAL_BIND(_area_set_area_monitor_callback, "area", "callback");
206
207 /* BODY API */
208
209 ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_body", "body"), &PhysicsServer2DExtension::body_test_motion_is_excluding_body);
210 ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_object", "object"), &PhysicsServer2DExtension::body_test_motion_is_excluding_object);
211
212 GDVIRTUAL_BIND(_body_create);
213
214 GDVIRTUAL_BIND(_body_set_space, "body", "space");
215 GDVIRTUAL_BIND(_body_get_space, "body");
216
217 GDVIRTUAL_BIND(_body_set_mode, "body", "mode");
218 GDVIRTUAL_BIND(_body_get_mode, "body");
219
220 GDVIRTUAL_BIND(_body_add_shape, "body", "shape", "transform", "disabled");
221 GDVIRTUAL_BIND(_body_set_shape, "body", "shape_idx", "shape");
222 GDVIRTUAL_BIND(_body_set_shape_transform, "body", "shape_idx", "transform");
223
224 GDVIRTUAL_BIND(_body_get_shape_count, "body");
225 GDVIRTUAL_BIND(_body_get_shape, "body", "shape_idx");
226 GDVIRTUAL_BIND(_body_get_shape_transform, "body", "shape_idx");
227
228 GDVIRTUAL_BIND(_body_set_shape_disabled, "body", "shape_idx", "disabled");
229 GDVIRTUAL_BIND(_body_set_shape_as_one_way_collision, "body", "shape_idx", "enable", "margin");
230
231 GDVIRTUAL_BIND(_body_remove_shape, "body", "shape_idx");
232 GDVIRTUAL_BIND(_body_clear_shapes, "body");
233
234 GDVIRTUAL_BIND(_body_attach_object_instance_id, "body", "id");
235 GDVIRTUAL_BIND(_body_get_object_instance_id, "body");
236
237 GDVIRTUAL_BIND(_body_attach_canvas_instance_id, "body", "id");
238 GDVIRTUAL_BIND(_body_get_canvas_instance_id, "body");
239
240 GDVIRTUAL_BIND(_body_set_continuous_collision_detection_mode, "body", "mode");
241 GDVIRTUAL_BIND(_body_get_continuous_collision_detection_mode, "body");
242
243 GDVIRTUAL_BIND(_body_set_collision_layer, "body", "layer");
244 GDVIRTUAL_BIND(_body_get_collision_layer, "body");
245
246 GDVIRTUAL_BIND(_body_set_collision_mask, "body", "mask");
247 GDVIRTUAL_BIND(_body_get_collision_mask, "body");
248
249 GDVIRTUAL_BIND(_body_set_collision_priority, "body", "priority");
250 GDVIRTUAL_BIND(_body_get_collision_priority, "body");
251
252 GDVIRTUAL_BIND(_body_set_param, "body", "param", "value");
253 GDVIRTUAL_BIND(_body_get_param, "body", "param");
254
255 GDVIRTUAL_BIND(_body_reset_mass_properties, "body");
256
257 GDVIRTUAL_BIND(_body_set_state, "body", "state", "value");
258 GDVIRTUAL_BIND(_body_get_state, "body", "state");
259
260 GDVIRTUAL_BIND(_body_apply_central_impulse, "body", "impulse");
261 GDVIRTUAL_BIND(_body_apply_torque_impulse, "body", "impulse");
262 GDVIRTUAL_BIND(_body_apply_impulse, "body", "impulse", "position");
263
264 GDVIRTUAL_BIND(_body_apply_central_force, "body", "force");
265 GDVIRTUAL_BIND(_body_apply_force, "body", "force", "position");
266 GDVIRTUAL_BIND(_body_apply_torque, "body", "torque");
267
268 GDVIRTUAL_BIND(_body_add_constant_central_force, "body", "force");
269 GDVIRTUAL_BIND(_body_add_constant_force, "body", "force", "position");
270 GDVIRTUAL_BIND(_body_add_constant_torque, "body", "torque");
271
272 GDVIRTUAL_BIND(_body_set_constant_force, "body", "force");
273 GDVIRTUAL_BIND(_body_get_constant_force, "body");
274
275 GDVIRTUAL_BIND(_body_set_constant_torque, "body", "torque");
276 GDVIRTUAL_BIND(_body_get_constant_torque, "body");
277
278 GDVIRTUAL_BIND(_body_set_axis_velocity, "body", "axis_velocity");
279
280 GDVIRTUAL_BIND(_body_add_collision_exception, "body", "excepted_body");
281 GDVIRTUAL_BIND(_body_remove_collision_exception, "body", "excepted_body");
282 GDVIRTUAL_BIND(_body_get_collision_exceptions, "body");
283
284 GDVIRTUAL_BIND(_body_set_max_contacts_reported, "body", "amount");
285 GDVIRTUAL_BIND(_body_get_max_contacts_reported, "body");
286
287 GDVIRTUAL_BIND(_body_set_contacts_reported_depth_threshold, "body", "threshold");
288 GDVIRTUAL_BIND(_body_get_contacts_reported_depth_threshold, "body");
289
290 GDVIRTUAL_BIND(_body_set_omit_force_integration, "body", "enable");
291 GDVIRTUAL_BIND(_body_is_omitting_force_integration, "body");
292
293 GDVIRTUAL_BIND(_body_set_state_sync_callback, "body", "callable");
294 GDVIRTUAL_BIND(_body_set_force_integration_callback, "body", "callable", "userdata");
295
296 GDVIRTUAL_BIND(_body_collide_shape, "body", "body_shape", "shape", "shape_xform", "motion", "results", "result_max", "result_count");
297
298 GDVIRTUAL_BIND(_body_set_pickable, "body", "pickable");
299
300 GDVIRTUAL_BIND(_body_get_direct_state, "body");
301
302 GDVIRTUAL_BIND(_body_test_motion, "body", "from", "motion", "margin", "collide_separation_ray", "recovery_as_collision", "result");
303
304 /* JOINT API */
305
306 GDVIRTUAL_BIND(_joint_create);
307 GDVIRTUAL_BIND(_joint_clear, "joint");
308
309 GDVIRTUAL_BIND(_joint_set_param, "joint", "param", "value");
310 GDVIRTUAL_BIND(_joint_get_param, "joint", "param");
311
312 GDVIRTUAL_BIND(_joint_disable_collisions_between_bodies, "joint", "disable");
313 GDVIRTUAL_BIND(_joint_is_disabled_collisions_between_bodies, "joint");
314
315 GDVIRTUAL_BIND(_joint_make_pin, "joint", "anchor", "body_a", "body_b");
316 GDVIRTUAL_BIND(_joint_make_groove, "joint", "a_groove1", "a_groove2", "b_anchor", "body_a", "body_b");
317 GDVIRTUAL_BIND(_joint_make_damped_spring, "joint", "anchor_a", "anchor_b", "body_a", "body_b");
318
319 GDVIRTUAL_BIND(_pin_joint_set_param, "joint", "param", "value");
320 GDVIRTUAL_BIND(_pin_joint_get_param, "joint", "param");
321
322 GDVIRTUAL_BIND(_damped_spring_joint_set_param, "joint", "param", "value");
323 GDVIRTUAL_BIND(_damped_spring_joint_get_param, "joint", "param");
324
325 GDVIRTUAL_BIND(_joint_get_type, "joint");
326
327 /* MISC */
328
329 GDVIRTUAL_BIND(_free_rid, "rid");
330
331 GDVIRTUAL_BIND(_set_active, "active");
332
333 GDVIRTUAL_BIND(_init);
334 GDVIRTUAL_BIND(_step, "step");
335 GDVIRTUAL_BIND(_sync);
336 GDVIRTUAL_BIND(_flush_queries);
337 GDVIRTUAL_BIND(_end_sync);
338 GDVIRTUAL_BIND(_finish);
339
340 GDVIRTUAL_BIND(_is_flushing_queries);
341 GDVIRTUAL_BIND(_get_process_info, "process_info");
342}
343
344PhysicsServer2DExtension::PhysicsServer2DExtension() {
345}
346
347PhysicsServer2DExtension::~PhysicsServer2DExtension() {
348}
349