area_2d.h
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 
32 #include "scene/2d/collision_object_2d.h"
33 #include "vset.h"
34 
35 class Area2D : public CollisionObject2D {
36 
37  OBJ_TYPE( Area2D, CollisionObject2D );
38 public:
39 
40  enum SpaceOverride {
41  SPACE_OVERRIDE_DISABLED,
42  SPACE_OVERRIDE_COMBINE,
43  SPACE_OVERRIDE_COMBINE_REPLACE,
44  SPACE_OVERRIDE_REPLACE,
45  SPACE_OVERRIDE_REPLACE_COMBINE
46  };
47 private:
48 
49 
50  SpaceOverride space_override;
51  Vector2 gravity_vec;
52  real_t gravity;
53  bool gravity_is_point;
54  real_t gravity_distance_scale;
55  real_t linear_damp;
56  real_t angular_damp;
57  uint32_t collision_mask;
58  uint32_t layer_mask;
59  int priority;
60  bool monitoring;
61  bool monitorable;
62  bool locked;
63 
64  void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
65 
66  void _body_enter_tree(ObjectID p_id);
67  void _body_exit_tree(ObjectID p_id);
68 
69  struct ShapePair {
70 
71  int body_shape;
72  int area_shape;
73  bool operator<(const ShapePair& p_sp) const {
74  if (body_shape==p_sp.body_shape)
75  return area_shape < p_sp.area_shape;
76  else
77  return body_shape < p_sp.body_shape;
78  }
79 
80  ShapePair() {}
81  ShapePair(int p_bs, int p_as) { body_shape=p_bs; area_shape=p_as; }
82  };
83 
84  struct BodyState {
85 
86  int rc;
87  bool in_tree;
88  VSet<ShapePair> shapes;
89  };
90 
91  Map<ObjectID,BodyState> body_map;
92 
93 
94 
95  void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
96 
97  void _area_enter_tree(ObjectID p_id);
98  void _area_exit_tree(ObjectID p_id);
99 
100  struct AreaShapePair {
101 
102  int area_shape;
103  int self_shape;
104  bool operator<(const AreaShapePair& p_sp) const {
105  if (area_shape==p_sp.area_shape)
106  return self_shape < p_sp.self_shape;
107  else
108  return area_shape < p_sp.area_shape;
109  }
110 
111  AreaShapePair() {}
112  AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
113  };
114 
115  struct AreaState {
116 
117  int rc;
118  bool in_tree;
119  VSet<AreaShapePair> shapes;
120  };
121 
122  Map<ObjectID,AreaState> area_map;
123  void _clear_monitoring();
124 
125 
126 protected:
127 
128  void _notification(int p_what);
129  static void _bind_methods();
130 public:
131 
132  void set_space_override_mode(SpaceOverride p_mode);
133  SpaceOverride get_space_override_mode() const;
134 
135  void set_gravity_is_point(bool p_enabled);
136  bool is_gravity_a_point() const;
137 
138  void set_gravity_distance_scale(real_t p_scale);
139  real_t get_gravity_distance_scale() const;
140 
141  void set_gravity_vector(const Vector2& p_vec);
142  Vector2 get_gravity_vector() const;
143 
144  void set_gravity(real_t p_gravity);
145  real_t get_gravity() const;
146 
147  void set_linear_damp(real_t p_linear_damp);
148  real_t get_linear_damp() const;
149 
150  void set_angular_damp(real_t p_angular_damp);
151  real_t get_angular_damp() const;
152 
153  void set_priority(real_t p_priority);
154  real_t get_priority() const;
155 
156  void set_enable_monitoring(bool p_enable);
157  bool is_monitoring_enabled() const;
158 
159  void set_monitorable(bool p_enable);
160  bool is_monitorable() const;
161 
162  void set_collision_mask(uint32_t p_mask);
163  uint32_t get_collision_mask() const;
164 
165  void set_layer_mask(uint32_t p_mask);
166  uint32_t get_layer_mask() const;
167 
168  void set_collision_mask_bit(int p_bit, bool p_value);
169  bool get_collision_mask_bit(int p_bit) const;
170 
171  void set_layer_mask_bit(int p_bit, bool p_value);
172  bool get_layer_mask_bit(int p_bit) const;
173 
174  Array get_overlapping_bodies() const; //function for script
175  Array get_overlapping_areas() const; //function for script
176 
177  bool overlaps_area(Node* p_area) const;
178  bool overlaps_body(Node* p_body) const;
179 
180  Area2D();
181  ~Area2D();
182 };
183 
184 VARIANT_ENUM_CAST(Area2D::SpaceOverride);
185 
186 #endif // AREA_2D_H
Definition: array.h:38
Definition: node.h:42
Definition: rid.h:47
Definition: math_2d.h:65
Definition: collision_object_2d.h:35
Definition: area_2d.h:35