physics_server_2d_dummy.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /**************************************************************************/
  2. /* physics_server_2d_dummy.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. #ifndef PHYSICS_SERVER_2D_DUMMY_H
  31. #define PHYSICS_SERVER_2D_DUMMY_H
  32. #include "physics_server_2d.h"
  33. class PhysicsDirectBodyState2DDummy : public PhysicsDirectBodyState2D {
  34. GDCLASS(PhysicsDirectBodyState2DDummy, PhysicsDirectBodyState2D);
  35. PhysicsDirectSpaceState2D *space_state_dummy = nullptr;
  36. public:
  37. virtual Vector2 get_total_gravity() const override { return Vector2(); }
  38. virtual real_t get_total_linear_damp() const override { return 0; }
  39. virtual real_t get_total_angular_damp() const override { return 0; }
  40. virtual Vector2 get_center_of_mass() const override { return Vector2(); }
  41. virtual Vector2 get_center_of_mass_local() const override { return Vector2(); }
  42. virtual real_t get_inverse_mass() const override { return 0; }
  43. virtual real_t get_inverse_inertia() const override { return 0; }
  44. virtual void set_linear_velocity(const Vector2 &p_velocity) override {}
  45. virtual Vector2 get_linear_velocity() const override { return Vector2(); }
  46. virtual void set_angular_velocity(real_t p_velocity) override {}
  47. virtual real_t get_angular_velocity() const override { return 0; }
  48. virtual void set_transform(const Transform2D &p_transform) override {}
  49. virtual Transform2D get_transform() const override { return Transform2D(); }
  50. virtual Vector2 get_velocity_at_local_position(const Vector2 &p_position) const override { return Vector2(); }
  51. virtual void apply_central_impulse(const Vector2 &p_impulse) override {}
  52. virtual void apply_torque_impulse(real_t p_torque) override {}
  53. virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {}
  54. virtual void apply_central_force(const Vector2 &p_force) override {}
  55. virtual void apply_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
  56. virtual void apply_torque(real_t p_torque) override {}
  57. virtual void add_constant_central_force(const Vector2 &p_force) override {}
  58. virtual void add_constant_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
  59. virtual void add_constant_torque(real_t p_torque) override {}
  60. virtual void set_constant_force(const Vector2 &p_force) override {}
  61. virtual Vector2 get_constant_force() const override { return Vector2(); }
  62. virtual void set_constant_torque(real_t p_torque) override {}
  63. virtual real_t get_constant_torque() const override { return 0; }
  64. virtual void set_sleep_state(bool p_enable) override {}
  65. virtual bool is_sleeping() const override { return false; }
  66. virtual int get_contact_count() const override { return 0; }
  67. virtual Vector2 get_contact_local_position(int p_contact_idx) const override { return Vector2(); }
  68. virtual Vector2 get_contact_local_normal(int p_contact_idx) const override { return Vector2(); }
  69. virtual int get_contact_local_shape(int p_contact_idx) const override { return 0; }
  70. virtual Vector2 get_contact_local_velocity_at_position(int p_contact_idx) const override { return Vector2(); }
  71. virtual RID get_contact_collider(int p_contact_idx) const override { return RID(); }
  72. virtual Vector2 get_contact_collider_position(int p_contact_idx) const override { return Vector2(); }
  73. virtual ObjectID get_contact_collider_id(int p_contact_idx) const override { return ObjectID(); }
  74. virtual Object *get_contact_collider_object(int p_contact_idx) const override { return nullptr; }
  75. virtual int get_contact_collider_shape(int p_contact_idx) const override { return 0; }
  76. virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const override { return Vector2(); }
  77. virtual Vector2 get_contact_impulse(int p_contact_idx) const override { return Vector2(); }
  78. virtual real_t get_step() const override { return 0; }
  79. virtual void integrate_forces() override {}
  80. virtual PhysicsDirectSpaceState2D *get_space_state() override { return space_state_dummy; }
  81. PhysicsDirectBodyState2DDummy(PhysicsDirectSpaceState2D *p_space_state_dummy) {
  82. space_state_dummy = p_space_state_dummy;
  83. }
  84. };
  85. class PhysicsDirectSpaceState2DDummy : public PhysicsDirectSpaceState2D {
  86. GDCLASS(PhysicsDirectSpaceState2DDummy, PhysicsDirectSpaceState2D);
  87. public:
  88. virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override { return false; }
  89. virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
  90. virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
  91. virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) override { return false; }
  92. virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; }
  93. virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override { return false; }
  94. };
  95. class PhysicsServer2DDummy : public PhysicsServer2D {
  96. GDCLASS(PhysicsServer2DDummy, PhysicsServer2D);
  97. PhysicsDirectSpaceState2DDummy *space_state_dummy = nullptr;
  98. PhysicsDirectBodyState2DDummy *body_state_dummy = nullptr;
  99. public:
  100. virtual RID world_boundary_shape_create() override { return RID(); }
  101. virtual RID separation_ray_shape_create() override { return RID(); }
  102. virtual RID segment_shape_create() override { return RID(); }
  103. virtual RID circle_shape_create() override { return RID(); }
  104. virtual RID rectangle_shape_create() override { return RID(); }
  105. virtual RID capsule_shape_create() override { return RID(); }
  106. virtual RID convex_polygon_shape_create() override { return RID(); }
  107. virtual RID concave_polygon_shape_create() override { return RID(); }
  108. virtual void shape_set_data(RID p_shape, const Variant &p_data) override {}
  109. virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override {}
  110. virtual ShapeType shape_get_type(RID p_shape) const override { return ShapeType::SHAPE_CIRCLE; }
  111. virtual Variant shape_get_data(RID p_shape) const override { return Variant(); }
  112. virtual real_t shape_get_custom_solver_bias(RID p_shape) const override { return 0; }
  113. virtual bool shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; }
  114. /* SPACE API */
  115. virtual RID space_create() override { return RID(); }
  116. virtual void space_set_active(RID p_space, bool p_active) override {}
  117. virtual bool space_is_active(RID p_space) const override { return false; }
  118. virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override {}
  119. virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override { return 0; }
  120. virtual PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) override { return space_state_dummy; }
  121. virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override {}
  122. virtual Vector<Vector2> space_get_contacts(RID p_space) const override { return Vector<Vector2>(); }
  123. virtual int space_get_contact_count(RID p_space) const override { return 0; }
  124. /* AREA API */
  125. virtual RID area_create() override { return RID(); }
  126. virtual void area_set_space(RID p_area, RID p_space) override {}
  127. virtual RID area_get_space(RID p_area) const override { return RID(); }
  128. virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {}
  129. virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override {}
  130. virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) override {}
  131. virtual int area_get_shape_count(RID p_area) const override { return 0; }
  132. virtual RID area_get_shape(RID p_area, int p_shape_idx) const override { return RID(); }
  133. virtual Transform2D area_get_shape_transform(RID p_area, int p_shape_idx) const override { return Transform2D(); }
  134. virtual void area_remove_shape(RID p_area, int p_shape_idx) override {}
  135. virtual void area_clear_shapes(RID p_area) override {}
  136. virtual void area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) override {}
  137. virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override {}
  138. virtual ObjectID area_get_object_instance_id(RID p_area) const override { return ObjectID(); }
  139. virtual void area_attach_canvas_instance_id(RID p_area, ObjectID p_id) override {}
  140. virtual ObjectID area_get_canvas_instance_id(RID p_area) const override { return ObjectID(); }
  141. virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override {}
  142. virtual void area_set_transform(RID p_area, const Transform2D &p_transform) override {}
  143. virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const override { return Variant(); }
  144. virtual Transform2D area_get_transform(RID p_area) const override { return Transform2D(); }
  145. virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override {}
  146. virtual uint32_t area_get_collision_layer(RID p_area) const override { return 0; }
  147. virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override {}
  148. virtual uint32_t area_get_collision_mask(RID p_area) const override { return 0; }
  149. virtual void area_set_monitorable(RID p_area, bool p_monitorable) override {}
  150. virtual void area_set_pickable(RID p_area, bool p_pickable) override {}
  151. virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) override {}
  152. virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) override {}
  153. /* BODY API */
  154. virtual RID body_create() override { return RID(); }
  155. virtual void body_set_space(RID p_body, RID p_space) override {}
  156. virtual RID body_get_space(RID p_body) const override { return RID(); }
  157. virtual void body_set_mode(RID p_body, BodyMode p_mode) override {}
  158. virtual BodyMode body_get_mode(RID p_body) const override { return BodyMode::BODY_MODE_STATIC; }
  159. virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {}
  160. virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override {}
  161. virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) override {}
  162. virtual int body_get_shape_count(RID p_body) const override { return 0; }
  163. virtual RID body_get_shape(RID p_body, int p_shape_idx) const override { return RID(); }
  164. virtual Transform2D body_get_shape_transform(RID p_body, int p_shape_idx) const override { return Transform2D(); }
  165. virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) override {}
  166. virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, real_t p_margin = 0) override {}
  167. virtual void body_remove_shape(RID p_body, int p_shape_idx) override {}
  168. virtual void body_clear_shapes(RID p_body) override {}
  169. virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override {}
  170. virtual ObjectID body_get_object_instance_id(RID p_body) const override { return ObjectID(); }
  171. virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id) override {}
  172. virtual ObjectID body_get_canvas_instance_id(RID p_body) const override { return ObjectID(); }
  173. virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) override {}
  174. virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const override { return CCDMode::CCD_MODE_DISABLED; }
  175. virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override {}
  176. virtual uint32_t body_get_collision_layer(RID p_body) const override { return 0; }
  177. virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override {}
  178. virtual uint32_t body_get_collision_mask(RID p_body) const override { return 0; }
  179. virtual void body_set_collision_priority(RID p_body, real_t p_priority) override {}
  180. virtual real_t body_get_collision_priority(RID p_body) const override { return 0; }
  181. virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) override {}
  182. virtual Variant body_get_param(RID p_body, BodyParameter p_param) const override { return Variant(); }
  183. virtual void body_reset_mass_properties(RID p_body) override {}
  184. virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override {}
  185. virtual Variant body_get_state(RID p_body, BodyState p_state) const override { return Variant(); }
  186. virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) override {}
  187. virtual void body_apply_torque_impulse(RID p_body, real_t p_torque) override {}
  188. virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {}
  189. virtual void body_apply_central_force(RID p_body, const Vector2 &p_force) override {}
  190. virtual void body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
  191. virtual void body_apply_torque(RID p_body, real_t p_torque) override {}
  192. virtual void body_add_constant_central_force(RID p_body, const Vector2 &p_force) override {}
  193. virtual void body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
  194. virtual void body_add_constant_torque(RID p_body, real_t p_torque) override {}
  195. virtual void body_set_constant_force(RID p_body, const Vector2 &p_force) override {}
  196. virtual Vector2 body_get_constant_force(RID p_body) const override { return Vector2(); }
  197. virtual void body_set_constant_torque(RID p_body, real_t p_torque) override {}
  198. virtual real_t body_get_constant_torque(RID p_body) const override { return 0; }
  199. virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) override {}
  200. virtual void body_add_collision_exception(RID p_body, RID p_body_b) override {}
  201. virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override {}
  202. virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {}
  203. virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override {}
  204. virtual int body_get_max_contacts_reported(RID p_body) const override { return 0; }
  205. virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) override {}
  206. virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const override { return 0; }
  207. virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override {}
  208. virtual bool body_is_omitting_force_integration(RID p_body) const override { return false; }
  209. virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) override {}
  210. virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) override {}
  211. virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; }
  212. virtual void body_set_pickable(RID p_body, bool p_pickable) override {}
  213. virtual PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) override { return body_state_dummy; }
  214. virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { return false; }
  215. /* JOINT API */
  216. virtual RID joint_create() override { return RID(); }
  217. virtual void joint_clear(RID p_joint) override {}
  218. virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) override {}
  219. virtual real_t joint_get_param(RID p_joint, JointParam p_param) const override { return 0; }
  220. virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) override {}
  221. virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override { return false; }
  222. virtual void joint_make_pin(RID p_joint, const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) override {}
  223. virtual void joint_make_groove(RID p_joint, const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) override {}
  224. virtual void joint_make_damped_spring(RID p_joint, const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b = RID()) override {}
  225. virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) override {}
  226. virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const override { return 0; }
  227. virtual void pin_joint_set_flag(RID p_joint, PinJointFlag p_flag, bool p_enabled) override {}
  228. virtual bool pin_joint_get_flag(RID p_joint, PinJointFlag p_flag) const override { return false; }
  229. virtual void damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) override {}
  230. virtual real_t damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const override { return 0; }
  231. virtual JointType joint_get_type(RID p_joint) const override { return JointType::JOINT_TYPE_PIN; }
  232. /* MISC */
  233. virtual void free(RID p_rid) override {}
  234. virtual void set_active(bool p_active) override {}
  235. virtual void init() override {
  236. space_state_dummy = memnew(PhysicsDirectSpaceState2DDummy);
  237. body_state_dummy = memnew(PhysicsDirectBodyState2DDummy(space_state_dummy));
  238. }
  239. virtual void step(real_t p_step) override {}
  240. virtual void sync() override {}
  241. virtual void flush_queries() override {}
  242. virtual void end_sync() override {}
  243. virtual void finish() override {
  244. memdelete(body_state_dummy);
  245. memdelete(space_state_dummy);
  246. }
  247. virtual bool is_flushing_queries() const override { return false; }
  248. virtual int get_process_info(ProcessInfo p_info) override { return 0; }
  249. };
  250. #endif // PHYSICS_SERVER_2D_DUMMY_H