| 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 | |
| 31 | #ifndef AREA_3D_H |
| 32 | #define AREA_3D_H |
| 33 | |
| 34 | #include "core/templates/vset.h" |
| 35 | #include "scene/3d/collision_object_3d.h" |
| 36 | #include "scene/scene_string_names.h" |
| 37 | |
| 38 | class Area3D : public CollisionObject3D { |
| 39 | GDCLASS(Area3D, CollisionObject3D); |
| 40 | |
| 41 | public: |
| 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 | Vector3 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 angular_damp = 0.1; |
| 60 | real_t linear_damp = 0.1; |
| 61 | |
| 62 | int priority = 0; |
| 63 | |
| 64 | real_t wind_force_magnitude = 0.0; |
| 65 | real_t wind_attenuation_factor = 0.0; |
| 66 | NodePath wind_source_path; |
| 67 | |
| 68 | bool monitoring = false; |
| 69 | bool monitorable = false; |
| 70 | bool locked = false; |
| 71 | |
| 72 | void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape); |
| 73 | |
| 74 | void _body_enter_tree(ObjectID p_id); |
| 75 | void _body_exit_tree(ObjectID p_id); |
| 76 | |
| 77 | struct ShapePair { |
| 78 | int body_shape = 0; |
| 79 | int area_shape = 0; |
| 80 | bool operator<(const ShapePair &p_sp) const { |
| 81 | if (body_shape == p_sp.body_shape) { |
| 82 | return area_shape < p_sp.area_shape; |
| 83 | } else { |
| 84 | return body_shape < p_sp.body_shape; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | ShapePair() {} |
| 89 | ShapePair(int p_bs, int p_as) { |
| 90 | body_shape = p_bs; |
| 91 | area_shape = p_as; |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | struct BodyState { |
| 96 | RID rid; |
| 97 | int rc = 0; |
| 98 | bool in_tree = false; |
| 99 | VSet<ShapePair> shapes; |
| 100 | }; |
| 101 | |
| 102 | HashMap<ObjectID, BodyState> body_map; |
| 103 | |
| 104 | void _area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape); |
| 105 | |
| 106 | void _area_enter_tree(ObjectID p_id); |
| 107 | void _area_exit_tree(ObjectID p_id); |
| 108 | |
| 109 | struct AreaShapePair { |
| 110 | int area_shape = 0; |
| 111 | int self_shape = 0; |
| 112 | bool operator<(const AreaShapePair &p_sp) const { |
| 113 | if (area_shape == p_sp.area_shape) { |
| 114 | return self_shape < p_sp.self_shape; |
| 115 | } else { |
| 116 | return area_shape < p_sp.area_shape; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | AreaShapePair() {} |
| 121 | AreaShapePair(int p_bs, int p_as) { |
| 122 | area_shape = p_bs; |
| 123 | self_shape = p_as; |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | struct AreaState { |
| 128 | RID rid; |
| 129 | int rc = 0; |
| 130 | bool in_tree = false; |
| 131 | VSet<AreaShapePair> shapes; |
| 132 | }; |
| 133 | |
| 134 | HashMap<ObjectID, AreaState> area_map; |
| 135 | void _clear_monitoring(); |
| 136 | |
| 137 | bool audio_bus_override = false; |
| 138 | StringName audio_bus = SceneStringNames::get_singleton()->Master; |
| 139 | |
| 140 | bool use_reverb_bus = false; |
| 141 | StringName reverb_bus = SceneStringNames::get_singleton()->Master; |
| 142 | float reverb_amount = 0.0; |
| 143 | float reverb_uniformity = 0.0; |
| 144 | |
| 145 | void _initialize_wind(); |
| 146 | |
| 147 | protected: |
| 148 | void _notification(int p_what); |
| 149 | static void _bind_methods(); |
| 150 | void _validate_property(PropertyInfo &p_property) const; |
| 151 | |
| 152 | public: |
| 153 | void set_gravity_space_override_mode(SpaceOverride p_mode); |
| 154 | SpaceOverride get_gravity_space_override_mode() const; |
| 155 | |
| 156 | void set_gravity_is_point(bool p_enabled); |
| 157 | bool is_gravity_a_point() const; |
| 158 | |
| 159 | void set_gravity_point_unit_distance(real_t p_scale); |
| 160 | real_t get_gravity_point_unit_distance() const; |
| 161 | |
| 162 | void set_gravity_point_center(const Vector3 &p_center); |
| 163 | const Vector3 &get_gravity_point_center() const; |
| 164 | |
| 165 | void set_gravity_direction(const Vector3 &p_direction); |
| 166 | const Vector3 &get_gravity_direction() const; |
| 167 | |
| 168 | void set_gravity(real_t p_gravity); |
| 169 | real_t get_gravity() const; |
| 170 | |
| 171 | void set_linear_damp_space_override_mode(SpaceOverride p_mode); |
| 172 | SpaceOverride get_linear_damp_space_override_mode() const; |
| 173 | |
| 174 | void set_angular_damp_space_override_mode(SpaceOverride p_mode); |
| 175 | SpaceOverride get_angular_damp_space_override_mode() const; |
| 176 | |
| 177 | void set_angular_damp(real_t p_angular_damp); |
| 178 | real_t get_angular_damp() const; |
| 179 | |
| 180 | void set_linear_damp(real_t p_linear_damp); |
| 181 | real_t get_linear_damp() const; |
| 182 | |
| 183 | void set_priority(int p_priority); |
| 184 | int get_priority() const; |
| 185 | |
| 186 | void set_wind_force_magnitude(real_t p_wind_force_magnitude); |
| 187 | real_t get_wind_force_magnitude() const; |
| 188 | |
| 189 | void set_wind_attenuation_factor(real_t p_wind_attenuation_factor); |
| 190 | real_t get_wind_attenuation_factor() const; |
| 191 | |
| 192 | void set_wind_source_path(const NodePath &p_wind_source_path); |
| 193 | const NodePath &get_wind_source_path() const; |
| 194 | |
| 195 | void set_monitoring(bool p_enable); |
| 196 | bool is_monitoring() const; |
| 197 | |
| 198 | void set_monitorable(bool p_enable); |
| 199 | bool is_monitorable() const; |
| 200 | |
| 201 | TypedArray<Node3D> get_overlapping_bodies() const; |
| 202 | TypedArray<Area3D> get_overlapping_areas() const; //function for script |
| 203 | |
| 204 | bool has_overlapping_bodies() const; |
| 205 | bool has_overlapping_areas() const; |
| 206 | |
| 207 | bool overlaps_area(Node *p_area) const; |
| 208 | bool overlaps_body(Node *p_body) const; |
| 209 | |
| 210 | void set_audio_bus_override(bool p_override); |
| 211 | bool is_overriding_audio_bus() const; |
| 212 | |
| 213 | void set_audio_bus_name(const StringName &p_audio_bus); |
| 214 | StringName get_audio_bus_name() const; |
| 215 | |
| 216 | void set_use_reverb_bus(bool p_enable); |
| 217 | bool is_using_reverb_bus() const; |
| 218 | |
| 219 | void set_reverb_bus_name(const StringName &p_audio_bus); |
| 220 | StringName get_reverb_bus_name() const; |
| 221 | |
| 222 | void set_reverb_amount(float p_amount); |
| 223 | float get_reverb_amount() const; |
| 224 | |
| 225 | void set_reverb_uniformity(float p_uniformity); |
| 226 | float get_reverb_uniformity() const; |
| 227 | |
| 228 | Area3D(); |
| 229 | ~Area3D(); |
| 230 | }; |
| 231 | |
| 232 | VARIANT_ENUM_CAST(Area3D::SpaceOverride); |
| 233 | |
| 234 | #endif // AREA_3D_H |
| 235 | |