area_bullet.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**************************************************************************/
  2. /* area_bullet.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 AREA_BULLET_H
  31. #define AREA_BULLET_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. public:
  42. struct InOutEventCallback {
  43. ObjectID event_callback_id;
  44. StringName event_callback_method;
  45. InOutEventCallback() :
  46. event_callback_id(0) {}
  47. };
  48. enum OverlapState {
  49. OVERLAP_STATE_DIRTY = 0, // Mark processed overlaps
  50. OVERLAP_STATE_INSIDE, // Mark old overlap
  51. OVERLAP_STATE_ENTER, // Mark just enter overlap
  52. OVERLAP_STATE_EXIT // Mark ended overlaps
  53. };
  54. struct OverlappingShapeData {
  55. CollisionObjectBullet *other_object = nullptr;
  56. OverlapState state = OVERLAP_STATE_DIRTY;
  57. uint32_t other_shape_id = 0;
  58. uint32_t our_shape_id = 0;
  59. OverlappingShapeData() {}
  60. OverlappingShapeData(CollisionObjectBullet *p_other_object, OverlapState p_state, uint32_t p_other_shape_id, uint32_t p_our_shape_id) :
  61. other_object(p_other_object),
  62. state(p_state),
  63. other_shape_id(p_other_shape_id),
  64. our_shape_id(p_our_shape_id) {}
  65. };
  66. private:
  67. // These are used by function callEvent. Instead to create this each call I create if one time.
  68. Variant call_event_res[5];
  69. Variant *call_event_res_ptr[5];
  70. btGhostObject *btGhost;
  71. Vector<OverlappingShapeData> overlapping_shapes;
  72. int _overlapping_shape_count(CollisionObjectBullet *p_other_object);
  73. int _find_overlapping_shape(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id);
  74. bool monitorable;
  75. PhysicsServer::AreaSpaceOverrideMode spOv_mode;
  76. bool spOv_gravityPoint;
  77. real_t spOv_gravityPointDistanceScale;
  78. real_t spOv_gravityPointAttenuation;
  79. Vector3 spOv_gravityVec;
  80. real_t spOv_gravityMag;
  81. real_t spOv_linearDump;
  82. real_t spOv_angularDump;
  83. int spOv_priority;
  84. bool isScratched;
  85. InOutEventCallback eventsCallbacks[2];
  86. public:
  87. AreaBullet();
  88. ~AreaBullet();
  89. _FORCE_INLINE_ btGhostObject *get_bt_ghost() const { return btGhost; }
  90. void set_monitorable(bool p_monitorable);
  91. _FORCE_INLINE_ bool is_monitorable() const { return monitorable; }
  92. bool is_monitoring() const;
  93. _FORCE_INLINE_ void set_spOv_mode(PhysicsServer::AreaSpaceOverrideMode p_mode) { spOv_mode = p_mode; }
  94. _FORCE_INLINE_ PhysicsServer::AreaSpaceOverrideMode get_spOv_mode() { return spOv_mode; }
  95. _FORCE_INLINE_ void set_spOv_gravityPoint(bool p_isGP) { spOv_gravityPoint = p_isGP; }
  96. _FORCE_INLINE_ bool is_spOv_gravityPoint() { return spOv_gravityPoint; }
  97. _FORCE_INLINE_ void set_spOv_gravityPointDistanceScale(real_t p_GPDS) { spOv_gravityPointDistanceScale = p_GPDS; }
  98. _FORCE_INLINE_ real_t get_spOv_gravityPointDistanceScale() { return spOv_gravityPointDistanceScale; }
  99. _FORCE_INLINE_ void set_spOv_gravityPointAttenuation(real_t p_GPA) { spOv_gravityPointAttenuation = p_GPA; }
  100. _FORCE_INLINE_ real_t get_spOv_gravityPointAttenuation() { return spOv_gravityPointAttenuation; }
  101. _FORCE_INLINE_ void set_spOv_gravityVec(Vector3 p_vec) { spOv_gravityVec = p_vec; }
  102. _FORCE_INLINE_ const Vector3 &get_spOv_gravityVec() const { return spOv_gravityVec; }
  103. _FORCE_INLINE_ void set_spOv_gravityMag(real_t p_gravityMag) { spOv_gravityMag = p_gravityMag; }
  104. _FORCE_INLINE_ real_t get_spOv_gravityMag() { return spOv_gravityMag; }
  105. _FORCE_INLINE_ void set_spOv_linearDump(real_t p_linearDump) { spOv_linearDump = p_linearDump; }
  106. _FORCE_INLINE_ real_t get_spOv_linearDamp() { return spOv_linearDump; }
  107. _FORCE_INLINE_ void set_spOv_angularDump(real_t p_angularDump) { spOv_angularDump = p_angularDump; }
  108. _FORCE_INLINE_ real_t get_spOv_angularDamp() { return spOv_angularDump; }
  109. _FORCE_INLINE_ void set_spOv_priority(int p_priority) { spOv_priority = p_priority; }
  110. _FORCE_INLINE_ int get_spOv_priority() { return spOv_priority; }
  111. virtual void main_shape_changed();
  112. virtual void reload_body();
  113. virtual void set_space(SpaceBullet *p_space);
  114. virtual void dispatch_callbacks();
  115. void call_event(const OverlappingShapeData &p_overlapping_shape, PhysicsServer::AreaBodyStatus p_status);
  116. virtual void on_collision_filters_change();
  117. virtual void on_collision_checker_start() {}
  118. virtual void on_collision_checker_end() { updated = false; }
  119. void mark_all_overlaps_dirty();
  120. void mark_object_overlaps_inside(CollisionObjectBullet *p_other_object);
  121. void set_overlap(CollisionObjectBullet *p_other_object, uint32_t p_other_shape_id, uint32_t p_our_shape_id);
  122. void mark_all_dirty_overlaps_as_exit();
  123. void remove_object_overlaps(CollisionObjectBullet *p_object);
  124. void clear_overlaps();
  125. void set_param(PhysicsServer::AreaParameter p_param, const Variant &p_value);
  126. Variant get_param(PhysicsServer::AreaParameter p_param) const;
  127. void set_event_callback(Type p_callbackObjectType, ObjectID p_id, const StringName &p_method);
  128. bool has_event_callback(Type p_callbackObjectType);
  129. virtual void on_enter_area(AreaBullet *p_area);
  130. virtual void on_exit_area(AreaBullet *p_area);
  131. };
  132. #endif // AREA_BULLET_H