area_bullet.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*************************************************************************/
  2. /* area_bullet.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 AREABULLET_H
  31. #define AREABULLET_H
  32. #include "collision_object_bullet.h"
  33. #include "core/vector.h"
  34. #include "servers/physics_server.h"
  35. #include "space_bullet.h"
  36. /**
  37. @author AndreaCatania
  38. */
  39. class btGhostObject;
  40. class AreaBullet : public RigidCollisionObjectBullet {
  41. friend void SpaceBullet::check_ghost_overlaps();
  42. public:
  43. struct InOutEventCallback {
  44. ObjectID event_callback_id;
  45. StringName event_callback_method;
  46. InOutEventCallback() :
  47. event_callback_id(0) {}
  48. };
  49. enum OverlapState {
  50. OVERLAP_STATE_DIRTY = 0, // Mark processed overlaps
  51. OVERLAP_STATE_INSIDE, // Mark old overlap
  52. OVERLAP_STATE_ENTER, // Mark just enter overlap
  53. OVERLAP_STATE_EXIT // Mark ended overlaps
  54. };
  55. struct OverlappingObjectData {
  56. CollisionObjectBullet *object;
  57. OverlapState state;
  58. OverlappingObjectData() :
  59. object(NULL),
  60. state(OVERLAP_STATE_ENTER) {}
  61. OverlappingObjectData(CollisionObjectBullet *p_object, OverlapState p_state) :
  62. object(p_object),
  63. state(p_state) {}
  64. OverlappingObjectData(const OverlappingObjectData &other) {
  65. operator=(other);
  66. }
  67. void operator=(const OverlappingObjectData &other) {
  68. object = other.object;
  69. state = other.state;
  70. }
  71. };
  72. private:
  73. // These are used by function callEvent. Instead to create this each call I create if one time.
  74. Variant call_event_res[5];
  75. Variant *call_event_res_ptr[5];
  76. btGhostObject *btGhost;
  77. Vector<OverlappingObjectData> overlappingObjects;
  78. bool monitorable;
  79. PhysicsServer::AreaSpaceOverrideMode spOv_mode;
  80. bool spOv_gravityPoint;
  81. real_t spOv_gravityPointDistanceScale;
  82. real_t spOv_gravityPointAttenuation;
  83. Vector3 spOv_gravityVec;
  84. real_t spOv_gravityMag;
  85. real_t spOv_linearDump;
  86. real_t spOv_angularDump;
  87. int spOv_priority;
  88. bool isScratched;
  89. InOutEventCallback eventsCallbacks[2];
  90. public:
  91. AreaBullet();
  92. ~AreaBullet();
  93. _FORCE_INLINE_ btGhostObject *get_bt_ghost() const { return btGhost; }
  94. int find_overlapping_object(CollisionObjectBullet *p_colObj);
  95. void set_monitorable(bool p_monitorable);
  96. _FORCE_INLINE_ bool is_monitorable() const { return monitorable; }
  97. bool is_monitoring() const;
  98. _FORCE_INLINE_ void set_spOv_mode(PhysicsServer::AreaSpaceOverrideMode p_mode) { spOv_mode = p_mode; }
  99. _FORCE_INLINE_ PhysicsServer::AreaSpaceOverrideMode get_spOv_mode() { return spOv_mode; }
  100. _FORCE_INLINE_ void set_spOv_gravityPoint(bool p_isGP) { spOv_gravityPoint = p_isGP; }
  101. _FORCE_INLINE_ bool is_spOv_gravityPoint() { return spOv_gravityPoint; }
  102. _FORCE_INLINE_ void set_spOv_gravityPointDistanceScale(real_t p_GPDS) { spOv_gravityPointDistanceScale = p_GPDS; }
  103. _FORCE_INLINE_ real_t get_spOv_gravityPointDistanceScale() { return spOv_gravityPointDistanceScale; }
  104. _FORCE_INLINE_ void set_spOv_gravityPointAttenuation(real_t p_GPA) { spOv_gravityPointAttenuation = p_GPA; }
  105. _FORCE_INLINE_ real_t get_spOv_gravityPointAttenuation() { return spOv_gravityPointAttenuation; }
  106. _FORCE_INLINE_ void set_spOv_gravityVec(Vector3 p_vec) { spOv_gravityVec = p_vec; }
  107. _FORCE_INLINE_ const Vector3 &get_spOv_gravityVec() const { return spOv_gravityVec; }
  108. _FORCE_INLINE_ void set_spOv_gravityMag(real_t p_gravityMag) { spOv_gravityMag = p_gravityMag; }
  109. _FORCE_INLINE_ real_t get_spOv_gravityMag() { return spOv_gravityMag; }
  110. _FORCE_INLINE_ void set_spOv_linearDump(real_t p_linearDump) { spOv_linearDump = p_linearDump; }
  111. _FORCE_INLINE_ real_t get_spOv_linearDamp() { return spOv_linearDump; }
  112. _FORCE_INLINE_ void set_spOv_angularDump(real_t p_angularDump) { spOv_angularDump = p_angularDump; }
  113. _FORCE_INLINE_ real_t get_spOv_angularDamp() { return spOv_angularDump; }
  114. _FORCE_INLINE_ void set_spOv_priority(int p_priority) { spOv_priority = p_priority; }
  115. _FORCE_INLINE_ int get_spOv_priority() { return spOv_priority; }
  116. virtual void main_shape_changed();
  117. virtual void reload_body();
  118. virtual void set_space(SpaceBullet *p_space);
  119. virtual void dispatch_callbacks();
  120. void call_event(CollisionObjectBullet *p_otherObject, PhysicsServer::AreaBodyStatus p_status);
  121. void set_on_state_change(ObjectID p_id, const StringName &p_method, const Variant &p_udata = Variant());
  122. void scratch();
  123. void clear_overlaps(bool p_notify);
  124. // Dispatch the callbacks and removes from overlapping list
  125. void remove_overlap(CollisionObjectBullet *p_object, bool p_notify);
  126. virtual void on_collision_filters_change();
  127. virtual void on_collision_checker_start() {}
  128. virtual void on_collision_checker_end() { isTransformChanged = false; }
  129. void add_overlap(CollisionObjectBullet *p_otherObject);
  130. void put_overlap_as_exit(int p_index);
  131. void put_overlap_as_inside(int p_index);
  132. void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value);
  133. Variant get_param(PhysicsServer::AreaParameter p_param) const;
  134. void set_event_callback(Type p_callbackObjectType, ObjectID p_id, const StringName &p_method);
  135. bool has_event_callback(Type p_callbackObjectType);
  136. virtual void on_enter_area(AreaBullet *p_area);
  137. virtual void on_exit_area(AreaBullet *p_area);
  138. };
  139. #endif