Debian Codegraph @

scene/2d/physics/area_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* area_2d.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
31 #pragma once
32
33 #include "core/templates/vset.h"
34 #include "scene/2d/physics/collision_object_2d.h"
35
36 class Area2D : public CollisionObject2D {
37 GDCLASS(Area2D, CollisionObject2D);
38
39 public:
40 static constexpr AncestralClass static_ancestral_class = AncestralClass::AREA_2D;
41
42 enum SpaceOverride {
43 SPACE_OVERRIDE_DISABLED,
44 SPACE_OVERRIDE_COMBINE,
45 SPACE_OVERRIDE_COMBINE_REPLACE,
46 SPACE_OVERRIDE_REPLACE,
47 SPACE_OVERRIDE_REPLACE_COMBINE
48 };
49
50 private:
51 SpaceOverride gravity_space_override = SPACE_OVERRIDE_DISABLED;
52 Vector2 gravity_vec;
53 real_t gravity = 0.0;
54 bool gravity_is_point = false;
55 real_t gravity_point_unit_distance = 0.0;
56
57 SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED;
58 SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED;
59 real_t linear_damp = 0.1;
60 real_t angular_damp = 1.0;
61
62 int priority = 0;
63
64 bool monitoring = false;
65 bool monitorable = false;
66 bool locked = false;
67
68 void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape);
69
70 void _body_enter_tree(ObjectID p_id);
71 void _body_exit_tree(ObjectID p_id);
72
73 struct ShapePair {
74 int body_shape = 0;
75 int area_shape = 0;
76 bool operator<(const ShapePair &p_sp) const {
77 if (body_shape == p_sp.body_shape) {
78 return area_shape < p_sp.area_shape;
79 } else {
80 return body_shape < p_sp.body_shape;
81 }
82 }
83
84 ShapePair() {}
85 ShapePair(int p_bs, int p_as) {
86 body_shape = p_bs;
87 area_shape = p_as;
88 }
89 };
90
91 struct BodyState {
92 RID rid;
93 int rc = 0;
94 bool in_tree = false;
95 VSet<ShapePair> shapes;
96 };
97
98 HashMap<ObjectID, BodyState> body_map;
99
100 void _area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape);
101
102 void _area_enter_tree(ObjectID p_id);
103 void _area_exit_tree(ObjectID p_id);
104
105 struct AreaShapePair {
106 int area_shape = 0;
107 int self_shape = 0;
108 bool operator<(const AreaShapePair &p_sp) const {
109 if (area_shape == p_sp.area_shape) {
110 return self_shape < p_sp.self_shape;
111 } else {
112 return area_shape < p_sp.area_shape;
113 }
114 }
115
116 AreaShapePair() {}
117 AreaShapePair(int p_bs, int p_as) {
118 area_shape = p_bs;
119 self_shape = p_as;
120 }
121 };
122
123 struct AreaState {
124 RID rid;
125 int rc = 0;
126 bool in_tree = false;
127 VSet<AreaShapePair> shapes;
128 };
129
130 HashMap<ObjectID, AreaState> area_map;
131 void _clear_monitoring();
132
133 bool audio_bus_override = false;
134 StringName audio_bus;
135
136 protected:
137 static void _bind_methods();
138 void _validate_property(PropertyInfo &p_property) const;
139
140 virtual void _space_changed(const RID &p_new_space) override;
141
142 public:
143 void set_gravity_space_override_mode(SpaceOverride p_mode);
144 SpaceOverride get_gravity_space_override_mode() const;
145
146 void set_gravity_is_point(bool p_enabled);
147 bool is_gravity_a_point() const;
148
149 void set_gravity_point_unit_distance(real_t p_scale);
150 real_t get_gravity_point_unit_distance() const;
151
152 void set_gravity_point_center(const Vector2 &p_center);
153 const Vector2 &get_gravity_point_center() const;
154
155 void set_gravity_direction(const Vector2 &p_direction);
156 const Vector2 &get_gravity_direction() const;
157
158 void set_gravity(real_t p_gravity);
159 real_t get_gravity() const;
160
161 void set_linear_damp_space_override_mode(SpaceOverride p_mode);
162 SpaceOverride get_linear_damp_space_override_mode() const;
163
164 void set_angular_damp_space_override_mode(SpaceOverride p_mode);
165 SpaceOverride get_angular_damp_space_override_mode() const;
166
167 void set_linear_damp(real_t p_linear_damp);
168 real_t get_linear_damp() const;
169
170 void set_angular_damp(real_t p_angular_damp);
171 real_t get_angular_damp() const;
172
173 void set_priority(int p_priority);
174 int get_priority() const;
175
176 void set_monitoring(bool p_enable);
177 bool is_monitoring() const;
178
179 void set_monitorable(bool p_enable);
180 bool is_monitorable() const;
181
182 TypedArray<Node2D> get_overlapping_bodies() const; //function for script
183 TypedArray<Area2D> get_overlapping_areas() const; //function for script
184
185 bool has_overlapping_bodies() const;
186 bool has_overlapping_areas() const;
187
188 bool overlaps_area(RequiredParam<Node> rp_area) const;
189 bool overlaps_body(RequiredParam<Node> rp_body) const;
190
191 void set_audio_bus_override(bool p_override);
192 bool is_overriding_audio_bus() const;
193
194 void set_audio_bus_name(const StringName &p_audio_bus);
195 StringName get_audio_bus_name() const;
196
197 Area2D();
198 ~Area2D();
199 };
200
201 VARIANT_ENUM_CAST(Area2D::SpaceOverride);