physics_server_sw.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*************************************************************************/
  2. /* physics_server_sw.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef PHYSICS_SERVER_SW
  30. #define PHYSICS_SERVER_SW
  31. #include "servers/physics_server.h"
  32. #include "shape_sw.h"
  33. #include "space_sw.h"
  34. #include "step_sw.h"
  35. #include "joints_sw.h"
  36. class PhysicsServerSW : public PhysicsServer {
  37. OBJ_TYPE( PhysicsServerSW, PhysicsServer );
  38. friend class PhysicsDirectSpaceStateSW;
  39. bool active;
  40. int iterations;
  41. bool doing_sync;
  42. real_t last_step;
  43. StepSW *stepper;
  44. Set<const SpaceSW*> active_spaces;
  45. PhysicsDirectBodyStateSW *direct_state;
  46. mutable RID_Owner<ShapeSW> shape_owner;
  47. mutable RID_Owner<SpaceSW> space_owner;
  48. mutable RID_Owner<AreaSW> area_owner;
  49. mutable RID_Owner<BodySW> body_owner;
  50. mutable RID_Owner<JointSW> joint_owner;
  51. // void _clear_query(QuerySW *p_query);
  52. public:
  53. virtual RID shape_create(ShapeType p_shape);
  54. virtual void shape_set_data(RID p_shape, const Variant& p_data);
  55. virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias);
  56. virtual ShapeType shape_get_type(RID p_shape) const;
  57. virtual Variant shape_get_data(RID p_shape) const;
  58. virtual real_t shape_get_custom_solver_bias(RID p_shape) const;
  59. /* SPACE API */
  60. virtual RID space_create();
  61. virtual void space_set_active(RID p_space,bool p_active);
  62. virtual bool space_is_active(RID p_space) const;
  63. virtual void space_set_param(RID p_space,SpaceParameter p_param, real_t p_value);
  64. virtual real_t space_get_param(RID p_space,SpaceParameter p_param) const;
  65. // this function only works on fixed process, errors and returns null otherwise
  66. virtual PhysicsDirectSpaceState* space_get_direct_state(RID p_space);
  67. /* AREA API */
  68. virtual RID area_create();
  69. virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode);
  70. virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const;
  71. virtual void area_set_space(RID p_area, RID p_space);
  72. virtual RID area_get_space(RID p_area) const;
  73. virtual void area_add_shape(RID p_area, RID p_shape, const Transform& p_transform=Transform());
  74. virtual void area_set_shape(RID p_area, int p_shape_idx,RID p_shape);
  75. virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform& p_transform);
  76. virtual int area_get_shape_count(RID p_area) const;
  77. virtual RID area_get_shape(RID p_area, int p_shape_idx) const;
  78. virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const;
  79. virtual void area_remove_shape(RID p_area, int p_shape_idx);
  80. virtual void area_clear_shapes(RID p_area);
  81. virtual void area_attach_object_instance_ID(RID p_area,ObjectID p_ID);
  82. virtual ObjectID area_get_object_instance_ID(RID p_area) const;
  83. virtual void area_set_param(RID p_area,AreaParameter p_param,const Variant& p_value);
  84. virtual void area_set_transform(RID p_area, const Transform& p_transform);
  85. virtual Variant area_get_param(RID p_parea,AreaParameter p_param) const;
  86. virtual Transform area_get_transform(RID p_area) const;
  87. virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method);
  88. /* BODY API */
  89. // create a body of a given type
  90. virtual RID body_create(BodyMode p_mode=BODY_MODE_RIGID,bool p_init_sleeping=false);
  91. virtual void body_set_space(RID p_body, RID p_space);
  92. virtual RID body_get_space(RID p_body) const;
  93. virtual void body_set_mode(RID p_body, BodyMode p_mode);
  94. virtual BodyMode body_get_mode(RID p_body, BodyMode p_mode) const;
  95. virtual void body_add_shape(RID p_body, RID p_shape, const Transform& p_transform=Transform());
  96. virtual void body_set_shape(RID p_body, int p_shape_idx,RID p_shape);
  97. virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform& p_transform);
  98. virtual int body_get_shape_count(RID p_body) const;
  99. virtual RID body_get_shape(RID p_body, int p_shape_idx) const;
  100. virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const;
  101. virtual void body_set_shape_as_trigger(RID p_body, int p_shape_idx,bool p_enable);
  102. virtual bool body_is_shape_set_as_trigger(RID p_body, int p_shape_idx) const;
  103. virtual void body_remove_shape(RID p_body, int p_shape_idx);
  104. virtual void body_clear_shapes(RID p_body);
  105. virtual void body_attach_object_instance_ID(RID p_body,uint32_t p_ID);
  106. virtual uint32_t body_get_object_instance_ID(RID p_body) const;
  107. virtual void body_set_enable_continuous_collision_detection(RID p_body,bool p_enable);
  108. virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const;
  109. virtual void body_set_user_flags(RID p_body, uint32_t p_flags);
  110. virtual uint32_t body_get_user_flags(RID p_body, uint32_t p_flags) const;
  111. virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value);
  112. virtual float body_get_param(RID p_body, BodyParameter p_param) const;
  113. //advanced simulation
  114. virtual void body_static_simulate_motion(RID p_body,const Transform& p_new_transform);
  115. virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant);
  116. virtual Variant body_get_state(RID p_body, BodyState p_state) const;
  117. virtual void body_set_applied_force(RID p_body, const Vector3& p_force);
  118. virtual Vector3 body_get_applied_force(RID p_body) const;
  119. virtual void body_set_applied_torque(RID p_body, const Vector3& p_torque);
  120. virtual Vector3 body_get_applied_torque(RID p_body) const;
  121. virtual void body_apply_impulse(RID p_body, const Vector3& p_pos, const Vector3& p_impulse);
  122. virtual void body_set_axis_velocity(RID p_body, const Vector3& p_axis_velocity);
  123. virtual void body_set_axis_lock(RID p_body,BodyAxisLock p_lock);
  124. virtual BodyAxisLock body_get_axis_lock(RID p_body) const;
  125. virtual void body_add_collision_exception(RID p_body, RID p_body_b);
  126. virtual void body_remove_collision_exception(RID p_body, RID p_body_b);
  127. virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions);
  128. virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold);
  129. virtual float body_get_contacts_reported_depth_treshold(RID p_body) const;
  130. virtual void body_set_omit_force_integration(RID p_body,bool p_omit);
  131. virtual bool body_is_omitting_force_integration(RID p_body) const;
  132. virtual void body_set_max_contacts_reported(RID p_body, int p_contacts);
  133. virtual int body_get_max_contacts_reported(RID p_body) const;
  134. virtual void body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata=Variant());
  135. /* JOINT API */
  136. #if 0
  137. virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value);
  138. virtual real_t joint_get_param(RID p_joint,JointParam p_param) const;
  139. virtual RID pin_joint_create(const Vector3& p_pos,RID p_body_a,RID p_body_b=RID());
  140. virtual RID groove_joint_create(const Vector3& p_a_groove1,const Vector3& p_a_groove2, const Vector3& p_b_anchor, RID p_body_a,RID p_body_b);
  141. virtual RID damped_spring_joint_create(const Vector3& p_anchor_a,const Vector3& p_anchor_b,RID p_body_a,RID p_body_b=RID());
  142. virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value);
  143. virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const;
  144. virtual JointType joint_get_type(RID p_joint) const;
  145. #endif
  146. /* MISC */
  147. virtual void free(RID p_rid);
  148. virtual void set_active(bool p_active);
  149. virtual void init();
  150. virtual void step(float p_step);
  151. virtual void sync();
  152. virtual void flush_queries();
  153. virtual void finish();
  154. PhysicsServerSW();
  155. ~PhysicsServerSW();
  156. };
  157. #endif