area.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*************************************************************************/
  2. /* area.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 AREA_H
  31. #define AREA_H
  32. #include "core/vset.h"
  33. #include "scene/3d/collision_object.h"
  34. class Area : public CollisionObject {
  35. GDCLASS(Area, CollisionObject);
  36. public:
  37. enum SpaceOverride {
  38. SPACE_OVERRIDE_DISABLED,
  39. SPACE_OVERRIDE_COMBINE,
  40. SPACE_OVERRIDE_COMBINE_REPLACE,
  41. SPACE_OVERRIDE_REPLACE,
  42. SPACE_OVERRIDE_REPLACE_COMBINE
  43. };
  44. private:
  45. SpaceOverride space_override;
  46. Vector3 gravity_vec;
  47. real_t gravity;
  48. bool gravity_is_point;
  49. real_t gravity_distance_scale;
  50. real_t angular_damp;
  51. real_t linear_damp;
  52. uint32_t collision_mask;
  53. uint32_t collision_layer;
  54. int priority;
  55. bool monitoring;
  56. bool monitorable;
  57. bool locked;
  58. void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);
  59. void _body_enter_tree(ObjectID p_id);
  60. void _body_exit_tree(ObjectID p_id);
  61. struct ShapePair {
  62. int body_shape;
  63. int area_shape;
  64. bool operator<(const ShapePair &p_sp) const {
  65. if (body_shape == p_sp.body_shape)
  66. return area_shape < p_sp.area_shape;
  67. else
  68. return body_shape < p_sp.body_shape;
  69. }
  70. ShapePair() {}
  71. ShapePair(int p_bs, int p_as) {
  72. body_shape = p_bs;
  73. area_shape = p_as;
  74. }
  75. };
  76. struct BodyState {
  77. int rc;
  78. bool in_tree;
  79. VSet<ShapePair> shapes;
  80. };
  81. Map<ObjectID, BodyState> body_map;
  82. void _area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape);
  83. void _area_enter_tree(ObjectID p_id);
  84. void _area_exit_tree(ObjectID p_id);
  85. struct AreaShapePair {
  86. int area_shape;
  87. int self_shape;
  88. bool operator<(const AreaShapePair &p_sp) const {
  89. if (area_shape == p_sp.area_shape)
  90. return self_shape < p_sp.self_shape;
  91. else
  92. return area_shape < p_sp.area_shape;
  93. }
  94. AreaShapePair() {}
  95. AreaShapePair(int p_bs, int p_as) {
  96. area_shape = p_bs;
  97. self_shape = p_as;
  98. }
  99. };
  100. struct AreaState {
  101. int rc;
  102. bool in_tree;
  103. VSet<AreaShapePair> shapes;
  104. };
  105. Map<ObjectID, AreaState> area_map;
  106. void _clear_monitoring();
  107. bool audio_bus_override;
  108. StringName audio_bus;
  109. bool use_reverb_bus;
  110. StringName reverb_bus;
  111. float reverb_amount;
  112. float reverb_uniformity;
  113. void _validate_property(PropertyInfo &property) const;
  114. protected:
  115. void _notification(int p_what);
  116. static void _bind_methods();
  117. public:
  118. void set_space_override_mode(SpaceOverride p_mode);
  119. SpaceOverride get_space_override_mode() const;
  120. void set_gravity_is_point(bool p_enabled);
  121. bool is_gravity_a_point() const;
  122. void set_gravity_distance_scale(real_t p_scale);
  123. real_t get_gravity_distance_scale() const;
  124. void set_gravity_vector(const Vector3 &p_vec);
  125. Vector3 get_gravity_vector() const;
  126. void set_gravity(real_t p_gravity);
  127. real_t get_gravity() const;
  128. void set_angular_damp(real_t p_angular_damp);
  129. real_t get_angular_damp() const;
  130. void set_linear_damp(real_t p_linear_damp);
  131. real_t get_linear_damp() const;
  132. void set_priority(real_t p_priority);
  133. real_t get_priority() const;
  134. void set_monitoring(bool p_enable);
  135. bool is_monitoring() const;
  136. void set_monitorable(bool p_enable);
  137. bool is_monitorable() const;
  138. void set_collision_mask(uint32_t p_mask);
  139. uint32_t get_collision_mask() const;
  140. void set_collision_layer(uint32_t p_layer);
  141. uint32_t get_collision_layer() const;
  142. void set_collision_mask_bit(int p_bit, bool p_value);
  143. bool get_collision_mask_bit(int p_bit) const;
  144. void set_collision_layer_bit(int p_bit, bool p_value);
  145. bool get_collision_layer_bit(int p_bit) const;
  146. Array get_overlapping_bodies() const;
  147. Array get_overlapping_areas() const; //function for script
  148. bool overlaps_area(Node *p_area) const;
  149. bool overlaps_body(Node *p_body) const;
  150. void set_audio_bus_override(bool p_override);
  151. bool is_overriding_audio_bus() const;
  152. void set_audio_bus(const StringName &p_audio_bus);
  153. StringName get_audio_bus() const;
  154. void set_use_reverb_bus(bool p_enable);
  155. bool is_using_reverb_bus() const;
  156. void set_reverb_bus(const StringName &p_audio_bus);
  157. StringName get_reverb_bus() const;
  158. void set_reverb_amount(float p_amount);
  159. float get_reverb_amount() const;
  160. void set_reverb_uniformity(float p_uniformity);
  161. float get_reverb_uniformity() const;
  162. Area();
  163. ~Area();
  164. };
  165. VARIANT_ENUM_CAST(Area::SpaceOverride);
  166. #endif // AREA__H