area_2d.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*************************************************************************/
  2. /* area_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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_2D_H
  31. #define AREA_2D_H
  32. #include "scene/2d/collision_object_2d.h"
  33. #include "vset.h"
  34. class Area2D : public CollisionObject2D {
  35. GDCLASS(Area2D, CollisionObject2D);
  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. Vector2 gravity_vec;
  47. real_t gravity;
  48. bool gravity_is_point;
  49. real_t gravity_distance_scale;
  50. real_t linear_damp;
  51. real_t angular_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. protected:
  110. void _notification(int p_what);
  111. static void _bind_methods();
  112. void _validate_property(PropertyInfo &property) const;
  113. public:
  114. void set_space_override_mode(SpaceOverride p_mode);
  115. SpaceOverride get_space_override_mode() const;
  116. void set_gravity_is_point(bool p_enabled);
  117. bool is_gravity_a_point() const;
  118. void set_gravity_distance_scale(real_t p_scale);
  119. real_t get_gravity_distance_scale() const;
  120. void set_gravity_vector(const Vector2 &p_vec);
  121. Vector2 get_gravity_vector() const;
  122. void set_gravity(real_t p_gravity);
  123. real_t get_gravity() const;
  124. void set_linear_damp(real_t p_linear_damp);
  125. real_t get_linear_damp() const;
  126. void set_angular_damp(real_t p_angular_damp);
  127. real_t get_angular_damp() const;
  128. void set_priority(real_t p_priority);
  129. real_t get_priority() const;
  130. void set_monitoring(bool p_enable);
  131. bool is_monitoring() const;
  132. void set_monitorable(bool p_enable);
  133. bool is_monitorable() const;
  134. void set_collision_mask(uint32_t p_mask);
  135. uint32_t get_collision_mask() const;
  136. void set_collision_layer(uint32_t p_layer);
  137. uint32_t get_collision_layer() const;
  138. void set_collision_mask_bit(int p_bit, bool p_value);
  139. bool get_collision_mask_bit(int p_bit) const;
  140. void set_collision_layer_bit(int p_bit, bool p_value);
  141. bool get_collision_layer_bit(int p_bit) const;
  142. Array get_overlapping_bodies() const; //function for script
  143. Array get_overlapping_areas() const; //function for script
  144. bool overlaps_area(Node *p_area) const;
  145. bool overlaps_body(Node *p_body) const;
  146. void set_audio_bus_override(bool p_override);
  147. bool is_overriding_audio_bus() const;
  148. void set_audio_bus_name(const StringName &p_audio_bus);
  149. StringName get_audio_bus_name() const;
  150. Area2D();
  151. ~Area2D();
  152. };
  153. VARIANT_ENUM_CAST(Area2D::SpaceOverride);
  154. #endif // AREA_2D_H