summaryrefslogtreecommitdiff
path: root/scene/2d/area_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/area_2d.cpp')
-rw-r--r--scene/2d/area_2d.cpp64
1 files changed, 0 insertions, 64 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 8ba334bc67..90af1ff274 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -35,27 +35,22 @@
#include "servers/physics_server_2d.h"
void Area2D::set_space_override_mode(SpaceOverride p_mode) {
-
space_override = p_mode;
PhysicsServer2D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer2D::AreaSpaceOverrideMode(p_mode));
}
Area2D::SpaceOverride Area2D::get_space_override_mode() const {
-
return space_override;
}
void Area2D::set_gravity_is_point(bool p_enabled) {
-
gravity_is_point = p_enabled;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_IS_POINT, p_enabled);
}
bool Area2D::is_gravity_a_point() const {
-
return gravity_is_point;
}
void Area2D::set_gravity_distance_scale(real_t p_scale) {
-
gravity_distance_scale = p_scale;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
}
@@ -65,58 +60,47 @@ real_t Area2D::get_gravity_distance_scale() const {
}
void Area2D::set_gravity_vector(const Vector2 &p_vec) {
-
gravity_vec = p_vec;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, p_vec);
}
Vector2 Area2D::get_gravity_vector() const {
-
return gravity_vec;
}
void Area2D::set_gravity(real_t p_gravity) {
-
gravity = p_gravity;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_GRAVITY, p_gravity);
}
real_t Area2D::get_gravity() const {
-
return gravity;
}
void Area2D::set_linear_damp(real_t p_linear_damp) {
-
linear_damp = p_linear_damp;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
}
real_t Area2D::get_linear_damp() const {
-
return linear_damp;
}
void Area2D::set_angular_damp(real_t p_angular_damp) {
-
angular_damp = p_angular_damp;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, p_angular_damp);
}
real_t Area2D::get_angular_damp() const {
-
return angular_damp;
}
void Area2D::set_priority(real_t p_priority) {
-
priority = p_priority;
PhysicsServer2D::get_singleton()->area_set_param(get_rid(), PhysicsServer2D::AREA_PARAM_PRIORITY, p_priority);
}
real_t Area2D::get_priority() const {
-
return priority;
}
void Area2D::_body_enter_tree(ObjectID p_id) {
-
Object *obj = ObjectDB::get_instance(p_id);
Node *node = Object::cast_to<Node>(obj);
ERR_FAIL_COND(!node);
@@ -128,13 +112,11 @@ void Area2D::_body_enter_tree(ObjectID p_id) {
E->get().in_tree = true;
emit_signal(SceneStringNames::get_singleton()->body_entered, node);
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
}
void Area2D::_body_exit_tree(ObjectID p_id) {
-
Object *obj = ObjectDB::get_instance(p_id);
Node *node = Object::cast_to<Node>(obj);
ERR_FAIL_COND(!node);
@@ -144,13 +126,11 @@ void Area2D::_body_exit_tree(ObjectID p_id) {
E->get().in_tree = false;
emit_signal(SceneStringNames::get_singleton()->body_exited, node);
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
}
void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape) {
-
bool body_in = p_status == PhysicsServer2D::AREA_BODY_ADDED;
ObjectID objid = p_instance;
@@ -167,7 +147,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
if (body_in) {
if (!E) {
-
E = body_map.insert(objid, BodyState());
E->get().rc = 0;
E->get().in_tree = node && node->is_inside_tree();
@@ -188,7 +167,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
} else {
-
E->get().rc--;
if (node)
@@ -197,7 +175,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
bool eraseit = false;
if (E->get().rc == 0) {
-
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree));
@@ -219,7 +196,6 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
void Area2D::_area_enter_tree(ObjectID p_id) {
-
Object *obj = ObjectDB::get_instance(p_id);
Node *node = Object::cast_to<Node>(obj);
ERR_FAIL_COND(!node);
@@ -231,13 +207,11 @@ void Area2D::_area_enter_tree(ObjectID p_id) {
E->get().in_tree = true;
emit_signal(SceneStringNames::get_singleton()->area_entered, node);
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
}
void Area2D::_area_exit_tree(ObjectID p_id) {
-
Object *obj = ObjectDB::get_instance(p_id);
Node *node = Object::cast_to<Node>(obj);
ERR_FAIL_COND(!node);
@@ -247,13 +221,11 @@ void Area2D::_area_exit_tree(ObjectID p_id) {
E->get().in_tree = false;
emit_signal(SceneStringNames::get_singleton()->area_exited, node);
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
}
void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape) {
-
bool area_in = p_status == PhysicsServer2D::AREA_BODY_ADDED;
ObjectID objid = p_instance;
@@ -269,7 +241,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
if (area_in) {
if (!E) {
-
E = area_map.insert(objid, AreaState());
E->get().rc = 0;
E->get().in_tree = node && node->is_inside_tree();
@@ -290,7 +261,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
} else {
-
E->get().rc--;
if (node)
@@ -299,7 +269,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
bool eraseit = false;
if (E->get().rc == 0) {
-
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree));
@@ -321,7 +290,6 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
void Area2D::_clear_monitoring() {
-
ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal.");
{
@@ -330,7 +298,6 @@ void Area2D::_clear_monitoring() {
//disconnect all monitored stuff
for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) {
-
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
@@ -344,7 +311,6 @@ void Area2D::_clear_monitoring() {
continue;
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
@@ -353,13 +319,11 @@ void Area2D::_clear_monitoring() {
}
{
-
Map<ObjectID, AreaState> bmcopy = area_map;
area_map.clear();
//disconnect all monitored stuff
for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) {
-
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
@@ -373,7 +337,6 @@ void Area2D::_clear_monitoring() {
continue;
for (int i = 0; i < E->get().shapes.size(); i++) {
-
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
@@ -383,18 +346,14 @@ void Area2D::_clear_monitoring() {
}
void Area2D::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_EXIT_TREE: {
-
_clear_monitoring();
} break;
}
}
void Area2D::set_monitoring(bool p_enable) {
-
if (p_enable == monitoring)
return;
ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false).");
@@ -402,7 +361,6 @@ void Area2D::set_monitoring(bool p_enable) {
monitoring = p_enable;
if (monitoring) {
-
PhysicsServer2D::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout);
PhysicsServer2D::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout);
@@ -414,12 +372,10 @@ void Area2D::set_monitoring(bool p_enable) {
}
bool Area2D::is_monitoring() const {
-
return monitoring;
}
void Area2D::set_monitorable(bool p_enable) {
-
ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer2D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false).");
if (p_enable == monitorable)
@@ -431,12 +387,10 @@ void Area2D::set_monitorable(bool p_enable) {
}
bool Area2D::is_monitorable() const {
-
return monitorable;
}
TypedArray<Node2D> Area2D::get_overlapping_bodies() const {
-
ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off.");
TypedArray<Node2D> ret;
ret.resize(body_map.size());
@@ -454,7 +408,6 @@ TypedArray<Node2D> Area2D::get_overlapping_bodies() const {
}
TypedArray<Area2D> Area2D::get_overlapping_areas() const {
-
ERR_FAIL_COND_V_MSG(!monitoring, Array(), "Can't find overlapping bodies when monitoring is off.");
TypedArray<Area2D> ret;
ret.resize(area_map.size());
@@ -472,7 +425,6 @@ TypedArray<Area2D> Area2D::get_overlapping_areas() const {
}
bool Area2D::overlaps_area(Node *p_area) const {
-
ERR_FAIL_NULL_V(p_area, false);
const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id());
if (!E)
@@ -481,7 +433,6 @@ bool Area2D::overlaps_area(Node *p_area) const {
}
bool Area2D::overlaps_body(Node *p_body) const {
-
ERR_FAIL_NULL_V(p_body, false);
const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id());
if (!E)
@@ -490,29 +441,24 @@ bool Area2D::overlaps_body(Node *p_body) const {
}
void Area2D::set_collision_mask(uint32_t p_mask) {
-
collision_mask = p_mask;
PhysicsServer2D::get_singleton()->area_set_collision_mask(get_rid(), p_mask);
}
uint32_t Area2D::get_collision_mask() const {
-
return collision_mask;
}
void Area2D::set_collision_layer(uint32_t p_layer) {
-
collision_layer = p_layer;
PhysicsServer2D::get_singleton()->area_set_collision_layer(get_rid(), p_layer);
}
uint32_t Area2D::get_collision_layer() const {
-
return collision_layer;
}
void Area2D::set_collision_mask_bit(int p_bit, bool p_value) {
-
uint32_t mask = get_collision_mask();
if (p_value)
mask |= 1 << p_bit;
@@ -522,12 +468,10 @@ void Area2D::set_collision_mask_bit(int p_bit, bool p_value) {
}
bool Area2D::get_collision_mask_bit(int p_bit) const {
-
return get_collision_mask() & (1 << p_bit);
}
void Area2D::set_collision_layer_bit(int p_bit, bool p_value) {
-
uint32_t layer = get_collision_layer();
if (p_value)
layer |= 1 << p_bit;
@@ -537,27 +481,22 @@ void Area2D::set_collision_layer_bit(int p_bit, bool p_value) {
}
bool Area2D::get_collision_layer_bit(int p_bit) const {
-
return get_collision_layer() & (1 << p_bit);
}
void Area2D::set_audio_bus_override(bool p_override) {
-
audio_bus_override = p_override;
}
bool Area2D::is_overriding_audio_bus() const {
-
return audio_bus_override;
}
void Area2D::set_audio_bus_name(const StringName &p_audio_bus) {
-
audio_bus = p_audio_bus;
}
StringName Area2D::get_audio_bus_name() const {
-
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) {
return audio_bus;
@@ -567,9 +506,7 @@ StringName Area2D::get_audio_bus_name() const {
}
void Area2D::_validate_property(PropertyInfo &property) const {
-
if (property.name == "audio_bus_name") {
-
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
if (i > 0)
@@ -677,7 +614,6 @@ void Area2D::_bind_methods() {
Area2D::Area2D() :
CollisionObject2D(PhysicsServer2D::get_singleton()->area_create(), true) {
-
space_override = SPACE_OVERRIDE_DISABLED;
set_gravity(98);
set_gravity_vector(Vector2(0, 1));