| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/vset.h" |
| 34 |
#include "scene/3d/physics/collision_object_3d.h" |
| 35 |
|
| 36 |
class Area3D : public CollisionObject3D { |
| 37 |
GDCLASS(Area3D, CollisionObject3D); |
| 38 |
|
| 39 |
public: |
| 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 |
|
| 48 |
private: |
| 49 |
SpaceOverride gravity_space_override = SPACE_OVERRIDE_DISABLED; |
| 50 |
Vector3 gravity_vec; |
| 51 |
real_t gravity = 0.0; |
| 52 |
bool gravity_is_point = false; |
| 53 |
real_t gravity_point_unit_distance = 0.0; |
| 54 |
|
| 55 |
SpaceOverride linear_damp_space_override = SPACE_OVERRIDE_DISABLED; |
| 56 |
SpaceOverride angular_damp_space_override = SPACE_OVERRIDE_DISABLED; |
| 57 |
real_t angular_damp = 0.1; |
| 58 |
real_t linear_damp = 0.1; |
| 59 |
|
| 60 |
int priority = 0; |
| 61 |
|
| 62 |
real_t wind_force_magnitude = 0.0; |
| 63 |
real_t wind_attenuation_factor = 0.0; |
| 64 |
NodePath wind_source_path; |
| 65 |
|
| 66 |
bool monitoring = false; |
| 67 |
bool monitorable = false; |
| 68 |
bool locked = false; |
| 69 |
|
| 70 |
void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape); |
| 71 |
|
| 72 |
void _body_enter_tree(ObjectID p_id); |
| 73 |
void _body_exit_tree(ObjectID p_id); |
| 74 |
|
| 75 |
struct ShapePair { |
| 76 |
int body_shape = 0; |
| 77 |
int area_shape = 0; |
| 78 |
bool operator<(const ShapePair &p_sp) const { |
| 79 |
if (body_shape == p_sp.body_shape) { |
| 80 |
return area_shape < p_sp.area_shape; |
| 81 |
} else { |
| 82 |
return body_shape < p_sp.body_shape; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
ShapePair() {} |
| 87 |
ShapePair(int p_bs, int p_as) { |
| 88 |
body_shape = p_bs; |
| 89 |
area_shape = p_as; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
struct BodyState { |
| 94 |
RID rid; |
| 95 |
int rc = 0; |
| 96 |
bool in_tree = false; |
| 97 |
VSet<ShapePair> shapes; |
| 98 |
}; |
| 99 |
|
| 100 |
HashMap<ObjectID, BodyState> body_map; |
| 101 |
|
| 102 |
void _area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape); |
| 103 |
|
| 104 |
void _area_enter_tree(ObjectID p_id); |
| 105 |
void _area_exit_tree(ObjectID p_id); |
| 106 |
|
| 107 |
struct AreaShapePair { |
| 108 |
int area_shape = 0; |
| 109 |
int self_shape = 0; |
| 110 |
bool operator<(const AreaShapePair &p_sp) const { |
| 111 |
if (area_shape == p_sp.area_shape) { |
| 112 |
return self_shape < p_sp.self_shape; |
| 113 |
} else { |
| 114 |
return area_shape < p_sp.area_shape; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
AreaShapePair() {} |
| 119 |
AreaShapePair(int p_bs, int p_as) { |
| 120 |
area_shape = p_bs; |
| 121 |
self_shape = p_as; |
| 122 |
} |
| 123 |
}; |
| 124 |
|
| 125 |
struct AreaState { |
| 126 |
RID rid; |
| 127 |
int rc = 0; |
| 128 |
bool in_tree = false; |
| 129 |
VSet<AreaShapePair> shapes; |
| 130 |
}; |
| 131 |
|
| 132 |
HashMap<ObjectID, AreaState> area_map; |
| 133 |
void _clear_monitoring(); |
| 134 |
|
| 135 |
bool audio_bus_override = false; |
| 136 |
StringName audio_bus; |
| 137 |
|
| 138 |
bool use_reverb_bus = false; |
| 139 |
StringName reverb_bus; |
| 140 |
float reverb_amount = 0.0; |
| 141 |
float reverb_uniformity = 0.0; |
| 142 |
|
| 143 |
void _initialize_wind(); |
| 144 |
|
| 145 |
protected: |
| 146 |
void _notification(int p_what); |
| 147 |
static void _bind_methods(); |
| 148 |
void _validate_property(PropertyInfo &p_property) const; |
| 149 |
|
| 150 |
virtual void _space_changed(const RID &p_new_space) override; |
| 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; |
| 203 |
|
| 204 |
bool has_overlapping_bodies() const; |
| 205 |
bool has_overlapping_areas() const; |
| 206 |
|
| 207 |
bool overlaps_area(RequiredParam<Node> rp_area) const; |
| 208 |
bool overlaps_body(RequiredParam<Node> rp_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); |