area_2d.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*************************************************************************/
  2. /* area_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef AREA_2D_H
  30. #define AREA_2D_H
  31. #include "scene/2d/collision_object_2d.h"
  32. #include "vset.h"
  33. class Area2D : public CollisionObject2D {
  34. OBJ_TYPE( Area2D, CollisionObject2D );
  35. public:
  36. enum SpaceOverride {
  37. SPACE_OVERRIDE_DISABLED,
  38. SPACE_OVERRIDE_COMBINE,
  39. SPACE_OVERRIDE_COMBINE_REPLACE,
  40. SPACE_OVERRIDE_REPLACE,
  41. SPACE_OVERRIDE_REPLACE_COMBINE
  42. };
  43. private:
  44. SpaceOverride space_override;
  45. Vector2 gravity_vec;
  46. real_t gravity;
  47. bool gravity_is_point;
  48. real_t gravity_distance_scale;
  49. real_t linear_damp;
  50. real_t angular_damp;
  51. uint32_t collision_mask;
  52. uint32_t layer_mask;
  53. int priority;
  54. bool monitoring;
  55. bool monitorable;
  56. bool locked;
  57. void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
  58. void _body_enter_tree(ObjectID p_id);
  59. void _body_exit_tree(ObjectID p_id);
  60. struct ShapePair {
  61. int body_shape;
  62. int area_shape;
  63. bool operator<(const ShapePair& p_sp) const {
  64. if (body_shape==p_sp.body_shape)
  65. return area_shape < p_sp.area_shape;
  66. else
  67. return body_shape < p_sp.body_shape;
  68. }
  69. ShapePair() {}
  70. ShapePair(int p_bs, int p_as) { body_shape=p_bs; area_shape=p_as; }
  71. };
  72. struct BodyState {
  73. int rc;
  74. bool in_tree;
  75. VSet<ShapePair> shapes;
  76. };
  77. Map<ObjectID,BodyState> body_map;
  78. void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
  79. void _area_enter_tree(ObjectID p_id);
  80. void _area_exit_tree(ObjectID p_id);
  81. struct AreaShapePair {
  82. int area_shape;
  83. int self_shape;
  84. bool operator<(const AreaShapePair& p_sp) const {
  85. if (area_shape==p_sp.area_shape)
  86. return self_shape < p_sp.self_shape;
  87. else
  88. return area_shape < p_sp.area_shape;
  89. }
  90. AreaShapePair() {}
  91. AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
  92. };
  93. struct AreaState {
  94. int rc;
  95. bool in_tree;
  96. VSet<AreaShapePair> shapes;
  97. };
  98. Map<ObjectID,AreaState> area_map;
  99. void _clear_monitoring();
  100. protected:
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. public:
  104. void set_space_override_mode(SpaceOverride p_mode);
  105. SpaceOverride get_space_override_mode() const;
  106. void set_gravity_is_point(bool p_enabled);
  107. bool is_gravity_a_point() const;
  108. void set_gravity_distance_scale(real_t p_scale);
  109. real_t get_gravity_distance_scale() const;
  110. void set_gravity_vector(const Vector2& p_vec);
  111. Vector2 get_gravity_vector() const;
  112. void set_gravity(real_t p_gravity);
  113. real_t get_gravity() const;
  114. void set_linear_damp(real_t p_linear_damp);
  115. real_t get_linear_damp() const;
  116. void set_angular_damp(real_t p_angular_damp);
  117. real_t get_angular_damp() const;
  118. void set_priority(real_t p_priority);
  119. real_t get_priority() const;
  120. void set_enable_monitoring(bool p_enable);
  121. bool is_monitoring_enabled() const;
  122. void set_monitorable(bool p_enable);
  123. bool is_monitorable() const;
  124. void set_collision_mask(uint32_t p_mask);
  125. uint32_t get_collision_mask() const;
  126. void set_layer_mask(uint32_t p_mask);
  127. uint32_t get_layer_mask() const;
  128. void set_collision_mask_bit(int p_bit, bool p_value);
  129. bool get_collision_mask_bit(int p_bit) const;
  130. void set_layer_mask_bit(int p_bit, bool p_value);
  131. bool get_layer_mask_bit(int p_bit) const;
  132. Array get_overlapping_bodies() const; //function for script
  133. Array get_overlapping_areas() const; //function for script
  134. bool overlaps_area(Node* p_area) const;
  135. bool overlaps_body(Node* p_body) const;
  136. Area2D();
  137. ~Area2D();
  138. };
  139. VARIANT_ENUM_CAST(Area2D::SpaceOverride);
  140. #endif // AREA_2D_H