Debian Codegraph @

servers/physics_2d/physics_server_2d_extension.cpp

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