area_3d.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**************************************************************************/
  2. /* area_3d.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_3D_H
  31. #define AREA_3D_H
  32. #include "core/templates/vset.h"
  33. #include "scene/3d/collision_object_3d.h"
  34. #include "scene/scene_string_names.h"
  35. class Area3D : public CollisionObject3D {
  36. GDCLASS(Area3D, CollisionObject3D);
  37. public:
  38. enum SpaceOverride {
  39. SPACE_OVERRIDE_DISABLED,
  40. SPACE_OVERRIDE_COMBINE,
  41. SPACE_OVERRIDE_COMBINE_REPLACE,
  42. SPACE_OVERRIDE_REPLACE,
  43. SPACE_OVERRIDE_REPLACE_COMBINE
  44. };
  45. private:
  46. SpaceOverride gravity_space_override = SPACE_OVERRIDE_DISABLED;
  47. Vector3 gravity_vec;
  48. real_t gravity = 0.0;
  49. bool gravity_is_point = false;
  50. real_t gravity_point_unit_distance = 0.0;
  51. SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
  52. SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
  53. real_t angular_damp = 0.1;
  54. real_t linear_damp = 0.1;
  55. int priority = 0;
  56. real_t wind_force_magnitude = 0.0;
  57. real_t wind_attenuation_factor = 0.0;
  58. NodePath wind_source_path;
  59. bool monitoring = false;
  60. bool monitorable = false;
  61. bool locked = false;
  62. void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape);
  63. void _body_enter_tree(ObjectID p_id);
  64. void _body_exit_tree(ObjectID p_id);
  65. struct ShapePair {
  66. int body_shape = 0;
  67. int area_shape = 0;
  68. bool operator<(const ShapePair &p_sp) const {
  69. if (body_shape == p_sp.body_shape) {
  70. return area_shape < p_sp.area_shape;
  71. } else {
  72. return body_shape < p_sp.body_shape;
  73. }
  74. }
  75. ShapePair() {}
  76. ShapePair(int p_bs, int p_as) {
  77. body_shape = p_bs;
  78. area_shape = p_as;
  79. }
  80. };
  81. struct BodyState {
  82. RID rid;
  83. int rc = 0;
  84. bool in_tree = false;
  85. VSet<ShapePair> shapes;
  86. };
  87. HashMap<ObjectID, BodyState> body_map;
  88. void _area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape);
  89. void _area_enter_tree(ObjectID p_id);
  90. void _area_exit_tree(ObjectID p_id);
  91. struct AreaShapePair {
  92. int area_shape = 0;
  93. int self_shape = 0;
  94. bool operator<(const AreaShapePair &p_sp) const {
  95. if (area_shape == p_sp.area_shape) {
  96. return self_shape < p_sp.self_shape;
  97. } else {
  98. return area_shape < p_sp.area_shape;
  99. }
  100. }
  101. AreaShapePair() {}
  102. AreaShapePair(int p_bs, int p_as) {
  103. area_shape = p_bs;
  104. self_shape = p_as;
  105. }
  106. };
  107. struct AreaState {
  108. RID rid;
  109. int rc = 0;
  110. bool in_tree = false;
  111. VSet<AreaShapePair> shapes;
  112. };
  113. HashMap<ObjectID, AreaState> area_map;
  114. void _clear_monitoring();
  115. bool audio_bus_override = false;
  116. StringName audio_bus = SceneStringNames::get_singleton()->Master;
  117. bool use_reverb_bus = false;
  118. StringName reverb_bus = SceneStringNames::get_singleton()->Master;
  119. float reverb_amount = 0.0;
  120. float reverb_uniformity = 0.0;
  121. void _initialize_wind();
  122. protected:
  123. void _notification(int p_what);
  124. static void _bind_methods();
  125. void _validate_property(PropertyInfo &p_property) const;
  126. public:
  127. void set_gravity_space_override_mode(SpaceOverride p_mode);
  128. SpaceOverride get_gravity_space_override_mode() const;
  129. void set_gravity_is_point(bool p_enabled);
  130. bool is_gravity_a_point() const;
  131. void set_gravity_point_unit_distance(real_t p_scale);
  132. real_t get_gravity_point_unit_distance() const;
  133. void set_gravity_point_center(const Vector3 &p_center);
  134. const Vector3 &get_gravity_point_center() const;
  135. void set_gravity_direction(const Vector3 &p_direction);
  136. const Vector3 &get_gravity_direction() const;
  137. void set_gravity(real_t p_gravity);
  138. real_t get_gravity() const;
  139. void set_linear_damp_space_override_mode(SpaceOverride p_mode);
  140. SpaceOverride get_linear_damp_space_override_mode() const;
  141. void set_angular_damp_space_override_mode(SpaceOverride p_mode);
  142. SpaceOverride get_angular_damp_space_override_mode() const;
  143. void set_angular_damp(real_t p_angular_damp);
  144. real_t get_angular_damp() const;
  145. void set_linear_damp(real_t p_linear_damp);
  146. real_t get_linear_damp() const;
  147. void set_priority(int p_priority);
  148. int get_priority() const;
  149. void set_wind_force_magnitude(real_t p_wind_force_magnitude);
  150. real_t get_wind_force_magnitude() const;
  151. void set_wind_attenuation_factor(real_t p_wind_attenuation_factor);
  152. real_t get_wind_attenuation_factor() const;
  153. void set_wind_source_path(const NodePath &p_wind_source_path);
  154. const NodePath &get_wind_source_path() const;
  155. void set_monitoring(bool p_enable);
  156. bool is_monitoring() const;
  157. void set_monitorable(bool p_enable);
  158. bool is_monitorable() const;
  159. TypedArray<Node3D> get_overlapping_bodies() const;
  160. TypedArray<Area3D> get_overlapping_areas() const; //function for script
  161. bool has_overlapping_bodies() const;
  162. bool has_overlapping_areas() const;
  163. bool overlaps_area(Node *p_area) const;
  164. bool overlaps_body(Node *p_body) const;
  165. void set_audio_bus_override(bool p_override);
  166. bool is_overriding_audio_bus() const;
  167. void set_audio_bus_name(const StringName &p_audio_bus);
  168. StringName get_audio_bus_name() const;
  169. void set_use_reverb_bus(bool p_enable);
  170. bool is_using_reverb_bus() const;
  171. void set_reverb_bus_name(const StringName &p_audio_bus);
  172. StringName get_reverb_bus_name() const;
  173. void set_reverb_amount(float p_amount);
  174. float get_reverb_amount() const;
  175. void set_reverb_uniformity(float p_uniformity);
  176. float get_reverb_uniformity() const;
  177. Area3D();
  178. ~Area3D();
  179. };
  180. VARIANT_ENUM_CAST(Area3D::SpaceOverride);
  181. #endif // AREA_3D_H