summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_2d')
-rw-r--r--servers/physics_2d/area_2d_sw.cpp10
-rw-r--r--servers/physics_2d/area_2d_sw.h4
-rw-r--r--servers/physics_2d/body_2d_sw.cpp6
-rw-r--r--servers/physics_2d/body_2d_sw.h2
-rw-r--r--servers/physics_2d/collision_object_2d_sw.cpp2
-rw-r--r--servers/physics_2d/constraint_2d_sw.h2
-rw-r--r--servers/physics_2d/physics_2d_server_sw.cpp284
-rw-r--r--servers/physics_2d/physics_2d_server_sw.h19
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.cpp2
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.h10
-rw-r--r--servers/physics_2d/shape_2d_sw.h4
-rw-r--r--servers/physics_2d/space_2d_sw.cpp16
-rw-r--r--servers/physics_2d/space_2d_sw.h4
13 files changed, 181 insertions, 184 deletions
diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp
index 6f09041af8..c67d870b2a 100644
--- a/servers/physics_2d/area_2d_sw.cpp
+++ b/servers/physics_2d/area_2d_sw.cpp
@@ -175,7 +175,7 @@ void Area2DSW::set_monitorable(bool p_monitorable) {
void Area2DSW::call_queries() {
- if (monitor_callback_id && !monitored_bodies.empty()) {
+ if (monitor_callback_id.is_valid() && !monitored_bodies.empty()) {
Variant res[5];
Variant *resptr[5];
@@ -185,7 +185,7 @@ void Area2DSW::call_queries() {
Object *obj = ObjectDB::get_instance(monitor_callback_id);
if (!obj) {
monitored_bodies.clear();
- monitor_callback_id = 0;
+ monitor_callback_id = ObjectID();
return;
}
@@ -207,7 +207,7 @@ void Area2DSW::call_queries() {
monitored_bodies.clear();
- if (area_monitor_callback_id && !monitored_areas.empty()) {
+ if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
Variant res[5];
Variant *resptr[5];
@@ -217,7 +217,7 @@ void Area2DSW::call_queries() {
Object *obj = ObjectDB::get_instance(area_monitor_callback_id);
if (!obj) {
monitored_areas.clear();
- area_monitor_callback_id = 0;
+ area_monitor_callback_id = ObjectID();
return;
}
@@ -258,8 +258,6 @@ Area2DSW::Area2DSW() :
angular_damp = 1.0;
linear_damp = 0.1;
priority = 0;
- monitor_callback_id = 0;
- area_monitor_callback_id = 0;
monitorable = false;
}
diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h
index 31bc0f6f23..54ffd9763d 100644
--- a/servers/physics_2d/area_2d_sw.h
+++ b/servers/physics_2d/area_2d_sw.h
@@ -110,10 +110,10 @@ public:
//_FORCE_INLINE_ SpaceSW* get_owner() { return owner; }
void set_monitor_callback(ObjectID p_id, const StringName &p_method);
- _FORCE_INLINE_ bool has_monitor_callback() const { return monitor_callback_id; }
+ _FORCE_INLINE_ bool has_monitor_callback() const { return monitor_callback_id.is_valid(); }
void set_area_monitor_callback(ObjectID p_id, const StringName &p_method);
- _FORCE_INLINE_ bool has_area_monitor_callback() const { return area_monitor_callback_id; }
+ _FORCE_INLINE_ bool has_area_monitor_callback() const { return area_monitor_callback_id.is_valid(); }
_FORCE_INLINE_ void add_body_to_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
_FORCE_INLINE_ void remove_body_from_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape);
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 225aab3a92..4de52cacbd 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -610,7 +610,7 @@ void Body2DSW::call_queries() {
Object *obj = ObjectDB::get_instance(fi_callback->id);
if (!obj) {
- set_force_integration_callback(0, StringName());
+ set_force_integration_callback(ObjectID(), StringName());
} else {
Variant::CallError ce;
if (fi_callback->callback_udata.get_type() != Variant::NIL) {
@@ -653,7 +653,7 @@ void Body2DSW::set_force_integration_callback(ObjectID p_id, const StringName &p
fi_callback = NULL;
}
- if (p_id != 0) {
+ if (p_id.is_valid()) {
fi_callback = memnew(ForceIntegrationCallback);
fi_callback->id = p_id;
@@ -721,7 +721,7 @@ Variant Physics2DDirectBodyStateSW::get_contact_collider_shape_metadata(int p_co
return Variant();
}
- Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.get(body->contacts[p_contact_idx].collider);
+ Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.getornull(body->contacts[p_contact_idx].collider);
int sidx = body->contacts[p_contact_idx].collider_shape;
if (sidx < 0 || sidx >= other->get_shape_count()) {
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index 06cc447526..ea07b8260c 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -400,7 +400,7 @@ public:
return body->contacts[p_contact_idx].collider_pos;
}
virtual ObjectID get_contact_collider_id(int p_contact_idx) const {
- ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
+ ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, ObjectID());
return body->contacts[p_contact_idx].collider_instance_id;
}
virtual int get_contact_collider_shape(int p_contact_idx) const {
diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp
index 85f7b8467a..8fb3296be6 100644
--- a/servers/physics_2d/collision_object_2d_sw.cpp
+++ b/servers/physics_2d/collision_object_2d_sw.cpp
@@ -267,8 +267,6 @@ CollisionObject2DSW::CollisionObject2DSW(Type p_type) :
_static = true;
type = p_type;
space = NULL;
- instance_id = 0;
- canvas_instance_id = 0;
collision_mask = 1;
collision_layer = 1;
pickable = true;
diff --git a/servers/physics_2d/constraint_2d_sw.h b/servers/physics_2d/constraint_2d_sw.h
index f3314f0ffc..b5c994cbdd 100644
--- a/servers/physics_2d/constraint_2d_sw.h
+++ b/servers/physics_2d/constraint_2d_sw.h
@@ -33,7 +33,7 @@
#include "body_2d_sw.h"
-class Constraint2DSW : public RID_Data {
+class Constraint2DSW {
Body2DSW **_body_ptr;
int _body_count;
diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp
index 809c5c40e0..aa374aa6bc 100644
--- a/servers/physics_2d/physics_2d_server_sw.cpp
+++ b/servers/physics_2d/physics_2d_server_sw.cpp
@@ -126,28 +126,28 @@ RID Physics2DServerSW::concave_polygon_shape_create() {
void Physics2DServerSW::shape_set_data(RID p_shape, const Variant &p_data) {
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
shape->set_data(p_data);
};
void Physics2DServerSW::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
shape->set_custom_bias(p_bias);
}
Physics2DServer::ShapeType Physics2DServerSW::shape_get_type(RID p_shape) const {
- const Shape2DSW *shape = shape_owner.get(p_shape);
+ const Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, SHAPE_CUSTOM);
return shape->get_type();
};
Variant Physics2DServerSW::shape_get_data(RID p_shape) const {
- const Shape2DSW *shape = shape_owner.get(p_shape);
+ const Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, Variant());
ERR_FAIL_COND_V(!shape->is_configured(), Variant());
return shape->get_data();
@@ -155,7 +155,7 @@ Variant Physics2DServerSW::shape_get_data(RID p_shape) const {
real_t Physics2DServerSW::shape_get_custom_solver_bias(RID p_shape) const {
- const Shape2DSW *shape = shape_owner.get(p_shape);
+ const Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
return shape->get_custom_bias();
}
@@ -219,9 +219,9 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &
bool Physics2DServerSW::shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) {
- Shape2DSW *shape_A = shape_owner.get(p_shape_A);
+ Shape2DSW *shape_A = shape_owner.getornull(p_shape_A);
ERR_FAIL_COND_V(!shape_A, false);
- Shape2DSW *shape_B = shape_owner.get(p_shape_B);
+ Shape2DSW *shape_B = shape_owner.getornull(p_shape_B);
ERR_FAIL_COND_V(!shape_B, false);
if (p_result_max == 0) {
@@ -246,7 +246,7 @@ RID Physics2DServerSW::space_create() {
RID id = space_owner.make_rid(space);
space->set_self(id);
RID area_id = area_create();
- Area2DSW *area = area_owner.get(area_id);
+ Area2DSW *area = area_owner.getornull(area_id);
ERR_FAIL_COND_V(!area, RID());
space->set_default_area(area);
area->set_space(space);
@@ -257,7 +257,7 @@ RID Physics2DServerSW::space_create() {
void Physics2DServerSW::space_set_active(RID p_space, bool p_active) {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
if (p_active)
active_spaces.insert(space);
@@ -267,7 +267,7 @@ void Physics2DServerSW::space_set_active(RID p_space, bool p_active) {
bool Physics2DServerSW::space_is_active(RID p_space) const {
- const Space2DSW *space = space_owner.get(p_space);
+ const Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND_V(!space, false);
return active_spaces.has(space);
@@ -275,7 +275,7 @@ bool Physics2DServerSW::space_is_active(RID p_space) const {
void Physics2DServerSW::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
space->set_param(p_param, p_value);
@@ -283,35 +283,35 @@ void Physics2DServerSW::space_set_param(RID p_space, SpaceParameter p_param, rea
real_t Physics2DServerSW::space_get_param(RID p_space, SpaceParameter p_param) const {
- const Space2DSW *space = space_owner.get(p_space);
+ const Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND_V(!space, 0);
return space->get_param(p_param);
}
void Physics2DServerSW::space_set_debug_contacts(RID p_space, int p_max_contacts) {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
space->set_debug_contacts(p_max_contacts);
}
Vector<Vector2> Physics2DServerSW::space_get_contacts(RID p_space) const {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND_V(!space, Vector<Vector2>());
return space->get_debug_contacts();
}
int Physics2DServerSW::space_get_contact_count(RID p_space) const {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND_V(!space, 0);
return space->get_debug_contact_count();
}
Physics2DDirectSpaceState *Physics2DServerSW::space_get_direct_state(RID p_space) {
- Space2DSW *space = space_owner.get(p_space);
+ Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND_V(!space, NULL);
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification.");
@@ -328,12 +328,12 @@ RID Physics2DServerSW::area_create() {
void Physics2DServerSW::area_set_space(RID p_area, RID p_space) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
Space2DSW *space = NULL;
if (p_space.is_valid()) {
- space = space_owner.get(p_space);
+ space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
}
@@ -346,7 +346,7 @@ void Physics2DServerSW::area_set_space(RID p_area, RID p_space) {
RID Physics2DServerSW::area_get_space(RID p_area) const {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, RID());
Space2DSW *space = area->get_space();
@@ -357,7 +357,7 @@ RID Physics2DServerSW::area_get_space(RID p_area) const {
void Physics2DServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_space_override_mode(p_mode);
@@ -365,7 +365,7 @@ void Physics2DServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverri
Physics2DServer::AreaSpaceOverrideMode Physics2DServerSW::area_get_space_override_mode(RID p_area) const {
- const Area2DSW *area = area_owner.get(p_area);
+ const Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED);
return area->get_space_override_mode();
@@ -373,10 +373,10 @@ Physics2DServer::AreaSpaceOverrideMode Physics2DServerSW::area_get_space_overrid
void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform, bool p_disabled) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
area->add_shape(shape, p_transform, p_disabled);
@@ -384,10 +384,10 @@ void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2
void Physics2DServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
ERR_FAIL_COND(!shape->is_configured());
@@ -395,7 +395,7 @@ void Physics2DServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape)
}
void Physics2DServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_shape_transform(p_shape_idx, p_transform);
@@ -403,7 +403,7 @@ void Physics2DServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, co
void Physics2DServerSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
ERR_FAIL_INDEX(p_shape, area->get_shape_count());
FLUSH_QUERY_CHECK(area);
@@ -413,14 +413,14 @@ void Physics2DServerSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_
int Physics2DServerSW::area_get_shape_count(RID p_area) const {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, -1);
return area->get_shape_count();
}
RID Physics2DServerSW::area_get_shape(RID p_area, int p_shape_idx) const {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, RID());
Shape2DSW *shape = area->get_shape(p_shape_idx);
@@ -430,7 +430,7 @@ RID Physics2DServerSW::area_get_shape(RID p_area, int p_shape_idx) const {
}
Transform2D Physics2DServerSW::area_get_shape_transform(RID p_area, int p_shape_idx) const {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, Transform2D());
return area->get_shape_transform(p_shape_idx);
@@ -438,7 +438,7 @@ Transform2D Physics2DServerSW::area_get_shape_transform(RID p_area, int p_shape_
void Physics2DServerSW::area_remove_shape(RID p_area, int p_shape_idx) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->remove_shape(p_shape_idx);
@@ -446,7 +446,7 @@ void Physics2DServerSW::area_remove_shape(RID p_area, int p_shape_idx) {
void Physics2DServerSW::area_clear_shapes(RID p_area) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
while (area->get_shape_count())
@@ -456,59 +456,59 @@ void Physics2DServerSW::area_clear_shapes(RID p_area) {
void Physics2DServerSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_instance_id(p_id);
}
ObjectID Physics2DServerSW::area_get_object_instance_id(RID p_area) const {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
- ERR_FAIL_COND_V(!area, 0);
+ Area2DSW *area = area_owner.getornull(p_area);
+ ERR_FAIL_COND_V(!area, ObjectID());
return area->get_instance_id();
}
void Physics2DServerSW::area_attach_canvas_instance_id(RID p_area, ObjectID p_id) {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_canvas_instance_id(p_id);
}
ObjectID Physics2DServerSW::area_get_canvas_instance_id(RID p_area) const {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
- ERR_FAIL_COND_V(!area, 0);
+ Area2DSW *area = area_owner.getornull(p_area);
+ ERR_FAIL_COND_V(!area, ObjectID());
return area->get_canvas_instance_id();
}
void Physics2DServerSW::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_param(p_param, p_value);
};
void Physics2DServerSW::area_set_transform(RID p_area, const Transform2D &p_transform) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_transform(p_transform);
};
@@ -516,10 +516,10 @@ void Physics2DServerSW::area_set_transform(RID p_area, const Transform2D &p_tran
Variant Physics2DServerSW::area_get_param(RID p_area, AreaParameter p_param) const {
if (space_owner.owns(p_area)) {
- Space2DSW *space = space_owner.get(p_area);
+ Space2DSW *space = space_owner.getornull(p_area);
p_area = space->get_default_area()->get_self();
}
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, Variant());
return area->get_param(p_param);
@@ -527,7 +527,7 @@ Variant Physics2DServerSW::area_get_param(RID p_area, AreaParameter p_param) con
Transform2D Physics2DServerSW::area_get_transform(RID p_area) const {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND_V(!area, Transform2D());
return area->get_transform();
@@ -535,14 +535,14 @@ Transform2D Physics2DServerSW::area_get_transform(RID p_area) const {
void Physics2DServerSW::area_set_pickable(RID p_area, bool p_pickable) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_pickable(p_pickable);
}
void Physics2DServerSW::area_set_monitorable(RID p_area, bool p_monitorable) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
FLUSH_QUERY_CHECK(area);
@@ -551,7 +551,7 @@ void Physics2DServerSW::area_set_monitorable(RID p_area, bool p_monitorable) {
void Physics2DServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_collision_mask(p_mask);
@@ -559,7 +559,7 @@ void Physics2DServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) {
void Physics2DServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
area->set_collision_layer(p_layer);
@@ -567,18 +567,18 @@ void Physics2DServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) {
void Physics2DServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- area->set_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method);
+ area->set_monitor_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method);
}
void Physics2DServerSW::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
- Area2DSW *area = area_owner.get(p_area);
+ Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- area->set_area_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method);
+ area->set_area_monitor_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method);
}
/* BODY API */
@@ -593,11 +593,11 @@ RID Physics2DServerSW::body_create() {
void Physics2DServerSW::body_set_space(RID p_body, RID p_space) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
Space2DSW *space = NULL;
if (p_space.is_valid()) {
- space = space_owner.get(p_space);
+ space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
}
@@ -610,7 +610,7 @@ void Physics2DServerSW::body_set_space(RID p_body, RID p_space) {
RID Physics2DServerSW::body_get_space(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, RID());
Space2DSW *space = body->get_space();
@@ -621,7 +621,7 @@ RID Physics2DServerSW::body_get_space(RID p_body) const {
void Physics2DServerSW::body_set_mode(RID p_body, BodyMode p_mode) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
FLUSH_QUERY_CHECK(body);
@@ -630,7 +630,7 @@ void Physics2DServerSW::body_set_mode(RID p_body, BodyMode p_mode) {
Physics2DServer::BodyMode Physics2DServerSW::body_get_mode(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
return body->get_mode();
@@ -638,10 +638,10 @@ Physics2DServer::BodyMode Physics2DServerSW::body_get_mode(RID p_body) const {
void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform, bool p_disabled) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
body->add_shape(shape, p_transform, p_disabled);
@@ -649,10 +649,10 @@ void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2
void Physics2DServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- Shape2DSW *shape = shape_owner.get(p_shape);
+ Shape2DSW *shape = shape_owner.getornull(p_shape);
ERR_FAIL_COND(!shape);
ERR_FAIL_COND(!shape->is_configured());
@@ -660,7 +660,7 @@ void Physics2DServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape)
}
void Physics2DServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_shape_transform(p_shape_idx, p_transform);
@@ -668,28 +668,28 @@ void Physics2DServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, co
void Physics2DServerSW::body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant &p_metadata) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_shape_metadata(p_shape_idx, p_metadata);
}
Variant Physics2DServerSW::body_get_shape_metadata(RID p_body, int p_shape_idx) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, Variant());
return body->get_shape_metadata(p_shape_idx);
}
int Physics2DServerSW::body_get_shape_count(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, -1);
return body->get_shape_count();
}
RID Physics2DServerSW::body_get_shape(RID p_body, int p_shape_idx) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, RID());
Shape2DSW *shape = body->get_shape(p_shape_idx);
@@ -699,7 +699,7 @@ RID Physics2DServerSW::body_get_shape(RID p_body, int p_shape_idx) const {
}
Transform2D Physics2DServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, Transform2D());
return body->get_shape_transform(p_shape_idx);
@@ -707,7 +707,7 @@ Transform2D Physics2DServerSW::body_get_shape_transform(RID p_body, int p_shape_
void Physics2DServerSW::body_remove_shape(RID p_body, int p_shape_idx) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->remove_shape(p_shape_idx);
@@ -715,7 +715,7 @@ void Physics2DServerSW::body_remove_shape(RID p_body, int p_shape_idx) {
void Physics2DServerSW::body_clear_shapes(RID p_body) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
while (body->get_shape_count())
@@ -724,7 +724,7 @@ void Physics2DServerSW::body_clear_shapes(RID p_body) {
void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count());
FLUSH_QUERY_CHECK(body);
@@ -733,7 +733,7 @@ void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo
}
void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count());
FLUSH_QUERY_CHECK(body);
@@ -743,61 +743,61 @@ void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_sh
void Physics2DServerSW::body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_continuous_collision_detection_mode(p_mode);
}
Physics2DServerSW::CCDMode Physics2DServerSW::body_get_continuous_collision_detection_mode(RID p_body) const {
- const Body2DSW *body = body_owner.get(p_body);
+ const Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, CCD_MODE_DISABLED);
return body->get_continuous_collision_detection_mode();
}
-void Physics2DServerSW::body_attach_object_instance_id(RID p_body, uint32_t p_id) {
+void Physics2DServerSW::body_attach_object_instance_id(RID p_body, ObjectID p_id) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_instance_id(p_id);
};
-uint32_t Physics2DServerSW::body_get_object_instance_id(RID p_body) const {
+ObjectID Physics2DServerSW::body_get_object_instance_id(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
- ERR_FAIL_COND_V(!body, 0);
+ Body2DSW *body = body_owner.getornull(p_body);
+ ERR_FAIL_COND_V(!body, ObjectID());
return body->get_instance_id();
};
-void Physics2DServerSW::body_attach_canvas_instance_id(RID p_body, uint32_t p_id) {
+void Physics2DServerSW::body_attach_canvas_instance_id(RID p_body, ObjectID p_id) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_canvas_instance_id(p_id);
};
-uint32_t Physics2DServerSW::body_get_canvas_instance_id(RID p_body) const {
+ObjectID Physics2DServerSW::body_get_canvas_instance_id(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
- ERR_FAIL_COND_V(!body, 0);
+ Body2DSW *body = body_owner.getornull(p_body);
+ ERR_FAIL_COND_V(!body, ObjectID());
return body->get_canvas_instance_id();
};
void Physics2DServerSW::body_set_collision_layer(RID p_body, uint32_t p_layer) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_collision_layer(p_layer);
};
uint32_t Physics2DServerSW::body_get_collision_layer(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, 0);
return body->get_collision_layer();
@@ -805,14 +805,14 @@ uint32_t Physics2DServerSW::body_get_collision_layer(RID p_body) const {
void Physics2DServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_collision_mask(p_mask);
};
uint32_t Physics2DServerSW::body_get_collision_mask(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, 0);
return body->get_collision_mask();
@@ -820,7 +820,7 @@ uint32_t Physics2DServerSW::body_get_collision_mask(RID p_body) const {
void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_param(p_param, p_value);
@@ -828,7 +828,7 @@ void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t
real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, 0);
return body->get_param(p_param);
@@ -836,7 +836,7 @@ real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) cons
void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_state(p_state, p_variant);
@@ -844,7 +844,7 @@ void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Vari
Variant Physics2DServerSW::body_get_state(RID p_body, BodyState p_state) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, Variant());
return body->get_state(p_state);
@@ -852,7 +852,7 @@ Variant Physics2DServerSW::body_get_state(RID p_body, BodyState p_state) const {
void Physics2DServerSW::body_set_applied_force(RID p_body, const Vector2 &p_force) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_applied_force(p_force);
@@ -861,14 +861,14 @@ void Physics2DServerSW::body_set_applied_force(RID p_body, const Vector2 &p_forc
Vector2 Physics2DServerSW::body_get_applied_force(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, Vector2());
return body->get_applied_force();
};
void Physics2DServerSW::body_set_applied_torque(RID p_body, real_t p_torque) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_applied_torque(p_torque);
@@ -877,14 +877,14 @@ void Physics2DServerSW::body_set_applied_torque(RID p_body, real_t p_torque) {
real_t Physics2DServerSW::body_get_applied_torque(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, 0);
return body->get_applied_torque();
};
void Physics2DServerSW::body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->apply_central_impulse(p_impulse);
@@ -892,7 +892,7 @@ void Physics2DServerSW::body_apply_central_impulse(RID p_body, const Vector2 &p_
}
void Physics2DServerSW::body_apply_torque_impulse(RID p_body, real_t p_torque) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
@@ -902,7 +902,7 @@ void Physics2DServerSW::body_apply_torque_impulse(RID p_body, real_t p_torque) {
void Physics2DServerSW::body_apply_impulse(RID p_body, const Vector2 &p_pos, const Vector2 &p_impulse) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
@@ -912,7 +912,7 @@ void Physics2DServerSW::body_apply_impulse(RID p_body, const Vector2 &p_pos, con
};
void Physics2DServerSW::body_add_central_force(RID p_body, const Vector2 &p_force) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->add_central_force(p_force);
@@ -921,7 +921,7 @@ void Physics2DServerSW::body_add_central_force(RID p_body, const Vector2 &p_forc
void Physics2DServerSW::body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->add_force(p_offset, p_force);
@@ -929,7 +929,7 @@ void Physics2DServerSW::body_add_force(RID p_body, const Vector2 &p_offset, cons
};
void Physics2DServerSW::body_add_torque(RID p_body, real_t p_torque) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->add_torque(p_torque);
@@ -938,7 +938,7 @@ void Physics2DServerSW::body_add_torque(RID p_body, real_t p_torque) {
void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
@@ -953,7 +953,7 @@ void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2 &p_axis
void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->add_exception(p_body_b);
@@ -962,7 +962,7 @@ void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) {
void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->remove_exception(p_body_b);
@@ -971,7 +971,7 @@ void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b
void Physics2DServerSW::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
for (int i = 0; i < body->get_exceptions().size(); i++) {
@@ -981,20 +981,20 @@ void Physics2DServerSW::body_get_collision_exceptions(RID p_body, List<RID> *p_e
void Physics2DServerSW::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
};
real_t Physics2DServerSW::body_get_contacts_reported_depth_threshold(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, 0);
return 0;
};
void Physics2DServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_omit_force_integration(p_omit);
@@ -1002,35 +1002,35 @@ void Physics2DServerSW::body_set_omit_force_integration(RID p_body, bool p_omit)
bool Physics2DServerSW::body_is_omitting_force_integration(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, false);
return body->get_omit_force_integration();
};
void Physics2DServerSW::body_set_max_contacts_reported(RID p_body, int p_contacts) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_max_contacts_reported(p_contacts);
}
int Physics2DServerSW::body_get_max_contacts_reported(RID p_body) const {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, -1);
return body->get_max_contacts_reported();
}
void Physics2DServerSW::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata);
+ body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method, p_udata);
}
bool Physics2DServerSW::body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, false);
ERR_FAIL_INDEX_V(p_body_shape, body->get_shape_count(), false);
@@ -1039,14 +1039,14 @@ bool Physics2DServerSW::body_collide_shape(RID p_body, int p_body_shape, RID p_s
void Physics2DServerSW::body_set_pickable(RID p_body, bool p_pickable) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
body->set_pickable(p_pickable);
}
bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result, bool p_exclude_raycast_shapes) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, false);
ERR_FAIL_COND_V(!body->get_space(), false);
ERR_FAIL_COND_V(body->get_space()->is_locked(), false);
@@ -1058,7 +1058,7 @@ bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from,
int Physics2DServerSW::body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) {
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, false);
ERR_FAIL_COND_V(!body->get_space(), false);
ERR_FAIL_COND_V(body->get_space()->is_locked(), false);
@@ -1073,7 +1073,7 @@ Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) {
if (!body_owner.owns(p_body))
return NULL;
- Body2DSW *body = body_owner.get(p_body);
+ Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, NULL);
ERR_FAIL_COND_V(!body->get_space(), NULL);
ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification.");
@@ -1086,7 +1086,7 @@ Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) {
void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) {
- Joint2DSW *joint = joint_owner.get(p_joint);
+ Joint2DSW *joint = joint_owner.getornull(p_joint);
ERR_FAIL_COND(!joint);
switch (p_param) {
@@ -1098,7 +1098,7 @@ void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t
real_t Physics2DServerSW::joint_get_param(RID p_joint, JointParam p_param) const {
- const Joint2DSW *joint = joint_owner.get(p_joint);
+ const Joint2DSW *joint = joint_owner.getornull(p_joint);
ERR_FAIL_COND_V(!joint, -1);
switch (p_param) {
@@ -1111,7 +1111,7 @@ real_t Physics2DServerSW::joint_get_param(RID p_joint, JointParam p_param) const
}
void Physics2DServerSW::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
- Joint2DSW *joint = joint_owner.get(p_joint);
+ Joint2DSW *joint = joint_owner.getornull(p_joint);
ERR_FAIL_COND(!joint);
joint->disable_collisions_between_bodies(p_disable);
@@ -1131,7 +1131,7 @@ void Physics2DServerSW::joint_disable_collisions_between_bodies(RID p_joint, con
}
bool Physics2DServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
- const Joint2DSW *joint = joint_owner.get(p_joint);
+ const Joint2DSW *joint = joint_owner.getornull(p_joint);
ERR_FAIL_COND_V(!joint, true);
return joint->is_disabled_collisions_between_bodies();
@@ -1139,11 +1139,11 @@ bool Physics2DServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint)
RID Physics2DServerSW::pin_joint_create(const Vector2 &p_pos, RID p_body_a, RID p_body_b) {
- Body2DSW *A = body_owner.get(p_body_a);
+ Body2DSW *A = body_owner.getornull(p_body_a);
ERR_FAIL_COND_V(!A, RID());
Body2DSW *B = NULL;
if (body_owner.owns(p_body_b)) {
- B = body_owner.get(p_body_b);
+ B = body_owner.getornull(p_body_b);
ERR_FAIL_COND_V(!B, RID());
}
@@ -1156,10 +1156,10 @@ RID Physics2DServerSW::pin_joint_create(const Vector2 &p_pos, RID p_body_a, RID
RID Physics2DServerSW::groove_joint_create(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) {
- Body2DSW *A = body_owner.get(p_body_a);
+ Body2DSW *A = body_owner.getornull(p_body_a);
ERR_FAIL_COND_V(!A, RID());
- Body2DSW *B = body_owner.get(p_body_b);
+ Body2DSW *B = body_owner.getornull(p_body_b);
ERR_FAIL_COND_V(!B, RID());
Joint2DSW *joint = memnew(GrooveJoint2DSW(p_a_groove1, p_a_groove2, p_b_anchor, A, B));
@@ -1170,10 +1170,10 @@ RID Physics2DServerSW::groove_joint_create(const Vector2 &p_a_groove1, const Vec
RID Physics2DServerSW::damped_spring_joint_create(const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b) {
- Body2DSW *A = body_owner.get(p_body_a);
+ Body2DSW *A = body_owner.getornull(p_body_a);
ERR_FAIL_COND_V(!A, RID());
- Body2DSW *B = body_owner.get(p_body_b);
+ Body2DSW *B = body_owner.getornull(p_body_b);
ERR_FAIL_COND_V(!B, RID());
Joint2DSW *joint = memnew(DampedSpringJoint2DSW(p_anchor_a, p_anchor_b, A, B));
@@ -1184,7 +1184,7 @@ RID Physics2DServerSW::damped_spring_joint_create(const Vector2 &p_anchor_a, con
void Physics2DServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {
- Joint2DSW *j = joint_owner.get(p_joint);
+ Joint2DSW *j = joint_owner.getornull(p_joint);
ERR_FAIL_COND(!j);
ERR_FAIL_COND(j->get_type() != JOINT_PIN);
@@ -1193,7 +1193,7 @@ void Physics2DServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param,
}
real_t Physics2DServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
- Joint2DSW *j = joint_owner.get(p_joint);
+ Joint2DSW *j = joint_owner.getornull(p_joint);
ERR_FAIL_COND_V(!j, 0);
ERR_FAIL_COND_V(j->get_type() != JOINT_PIN, 0);
@@ -1203,7 +1203,7 @@ real_t Physics2DServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param
void Physics2DServerSW::damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value) {
- Joint2DSW *j = joint_owner.get(p_joint);
+ Joint2DSW *j = joint_owner.getornull(p_joint);
ERR_FAIL_COND(!j);
ERR_FAIL_COND(j->get_type() != JOINT_DAMPED_SPRING);
@@ -1213,7 +1213,7 @@ void Physics2DServerSW::damped_string_joint_set_param(RID p_joint, DampedStringP
real_t Physics2DServerSW::damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const {
- Joint2DSW *j = joint_owner.get(p_joint);
+ Joint2DSW *j = joint_owner.getornull(p_joint);
ERR_FAIL_COND_V(!j, 0);
ERR_FAIL_COND_V(j->get_type() != JOINT_DAMPED_SPRING, 0);
@@ -1223,7 +1223,7 @@ real_t Physics2DServerSW::damped_string_joint_get_param(RID p_joint, DampedStrin
Physics2DServer::JointType Physics2DServerSW::joint_get_type(RID p_joint) const {
- Joint2DSW *joint = joint_owner.get(p_joint);
+ Joint2DSW *joint = joint_owner.getornull(p_joint);
ERR_FAIL_COND_V(!joint, JOINT_PIN);
return joint->get_type();
@@ -1235,7 +1235,7 @@ void Physics2DServerSW::free(RID p_rid) {
if (shape_owner.owns(p_rid)) {
- Shape2DSW *shape = shape_owner.get(p_rid);
+ Shape2DSW *shape = shape_owner.getornull(p_rid);
while (shape->get_owners().size()) {
ShapeOwner2DSW *so = shape->get_owners().front()->key();
@@ -1246,7 +1246,7 @@ void Physics2DServerSW::free(RID p_rid) {
memdelete(shape);
} else if (body_owner.owns(p_rid)) {
- Body2DSW *body = body_owner.get(p_rid);
+ Body2DSW *body = body_owner.getornull(p_rid);
/*
if (body->get_state_query())
@@ -1268,7 +1268,7 @@ void Physics2DServerSW::free(RID p_rid) {
} else if (area_owner.owns(p_rid)) {
- Area2DSW *area = area_owner.get(p_rid);
+ Area2DSW *area = area_owner.getornull(p_rid);
/*
if (area->get_monitor_query())
@@ -1286,7 +1286,7 @@ void Physics2DServerSW::free(RID p_rid) {
memdelete(area);
} else if (space_owner.owns(p_rid)) {
- Space2DSW *space = space_owner.get(p_rid);
+ Space2DSW *space = space_owner.getornull(p_rid);
while (space->get_objects().size()) {
CollisionObject2DSW *co = (CollisionObject2DSW *)space->get_objects().front()->get();
@@ -1299,7 +1299,7 @@ void Physics2DServerSW::free(RID p_rid) {
memdelete(space);
} else if (joint_owner.owns(p_rid)) {
- Joint2DSW *joint = joint_owner.get(p_rid);
+ Joint2DSW *joint = joint_owner.getornull(p_rid);
joint_owner.free(p_rid);
memdelete(joint);
diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h
index c8f443e3b6..a95a2ea0dd 100644
--- a/servers/physics_2d/physics_2d_server_sw.h
+++ b/servers/physics_2d/physics_2d_server_sw.h
@@ -31,6 +31,7 @@
#ifndef PHYSICS_2D_SERVER_SW
#define PHYSICS_2D_SERVER_SW
+#include "core/rid_owner.h"
#include "joints_2d_sw.h"
#include "servers/physics_2d_server.h"
#include "shape_2d_sw.h"
@@ -61,11 +62,11 @@ class Physics2DServerSW : public Physics2DServer {
Physics2DDirectBodyStateSW *direct_state;
- mutable RID_Owner<Shape2DSW> shape_owner;
- mutable RID_Owner<Space2DSW> space_owner;
- mutable RID_Owner<Area2DSW> area_owner;
- mutable RID_Owner<Body2DSW> body_owner;
- mutable RID_Owner<Joint2DSW> joint_owner;
+ mutable RID_PtrOwner<Shape2DSW> shape_owner;
+ mutable RID_PtrOwner<Space2DSW> space_owner;
+ mutable RID_PtrOwner<Area2DSW> area_owner;
+ mutable RID_PtrOwner<Body2DSW> body_owner;
+ mutable RID_PtrOwner<Joint2DSW> joint_owner;
static Physics2DServerSW *singletonsw;
@@ -194,11 +195,11 @@ public:
virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled);
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin);
- virtual void body_attach_object_instance_id(RID p_body, uint32_t p_id);
- virtual uint32_t body_get_object_instance_id(RID p_body) const;
+ virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id);
+ virtual ObjectID body_get_object_instance_id(RID p_body) const;
- virtual void body_attach_canvas_instance_id(RID p_body, uint32_t p_id);
- virtual uint32_t body_get_canvas_instance_id(RID p_body) const;
+ virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id);
+ virtual ObjectID body_get_canvas_instance_id(RID p_body) const;
virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode);
virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const;
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp
index 995d763c6d..291693de39 100644
--- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp
+++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp
@@ -107,7 +107,7 @@ void Physics2DServerWrapMT::init() {
if (create_thread) {
- step_sem = Semaphore::create();
+ step_sem = SemaphoreOld::create();
//OS::get_singleton()->release_rendering_thread();
if (create_thread) {
thread = Thread::create(_thread_callback, this);
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h
index eec0a3933f..9a01344390 100644
--- a/servers/physics_2d/physics_2d_server_wrap_mt.h
+++ b/servers/physics_2d/physics_2d_server_wrap_mt.h
@@ -58,7 +58,7 @@ class Physics2DServerWrapMT : public Physics2DServer {
volatile bool step_thread_up;
bool create_thread;
- Semaphore *step_sem;
+ SemaphoreOld *step_sem;
int step_pending;
void thread_step(real_t p_delta);
void thread_flush();
@@ -199,11 +199,11 @@ public:
FUNC2(body_remove_shape, RID, int);
FUNC1(body_clear_shapes, RID);
- FUNC2(body_attach_object_instance_id, RID, uint32_t);
- FUNC1RC(uint32_t, body_get_object_instance_id, RID);
+ FUNC2(body_attach_object_instance_id, RID, ObjectID);
+ FUNC1RC(ObjectID, body_get_object_instance_id, RID);
- FUNC2(body_attach_canvas_instance_id, RID, uint32_t);
- FUNC1RC(uint32_t, body_get_canvas_instance_id, RID);
+ FUNC2(body_attach_canvas_instance_id, RID, ObjectID);
+ FUNC1RC(ObjectID, body_get_canvas_instance_id, RID);
FUNC2(body_set_continuous_collision_detection_mode, RID, CCDMode);
FUNC1RC(CCDMode, body_get_continuous_collision_detection_mode, RID);
diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h
index a336dcecf5..fa56f2a250 100644
--- a/servers/physics_2d/shape_2d_sw.h
+++ b/servers/physics_2d/shape_2d_sw.h
@@ -48,7 +48,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat
class Shape2DSW;
-class ShapeOwner2DSW : public RID_Data {
+class ShapeOwner2DSW {
public:
virtual void _shape_changed() = 0;
virtual void remove_shape(Shape2DSW *p_shape) = 0;
@@ -56,7 +56,7 @@ public:
virtual ~ShapeOwner2DSW() {}
};
-class Shape2DSW : public RID_Data {
+class Shape2DSW {
RID self;
Rect2 aabb;
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp
index 08a261da2a..83bcae4607 100644
--- a/servers/physics_2d/space_2d_sw.cpp
+++ b/servers/physics_2d/space_2d_sw.cpp
@@ -91,7 +91,7 @@ int Physics2DDirectSpaceStateSW::_intersect_point_impl(const Vector2 &p_point, S
continue;
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id != 0)
+ if (r_results[cc].collider_id.is_valid())
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
@@ -182,7 +182,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2 &p_from, const Vec
return false;
r_result.collider_id = res_obj->get_instance_id();
- if (r_result.collider_id != 0)
+ if (r_result.collider_id.is_valid())
r_result.collider = ObjectDB::get_instance(r_result.collider_id);
r_result.normal = res_normal;
r_result.metadata = res_obj->get_shape_metadata(res_shape);
@@ -198,7 +198,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans
if (p_result_max <= 0)
return 0;
- Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape);
+ Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
Rect2 aabb = p_xform.xform(shape->get_aabb());
@@ -226,7 +226,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans
continue;
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id != 0)
+ if (r_results[cc].collider_id.is_valid())
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
@@ -240,7 +240,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans
bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape);
+ Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, false);
Rect2 aabb = p_xform.xform(shape->get_aabb());
@@ -313,7 +313,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &
if (p_result_max <= 0)
return 0;
- Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape);
+ Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
Rect2 aabb = p_shape_xform.xform(shape->get_aabb());
@@ -404,7 +404,7 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B,
bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape);
+ Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
Rect2 aabb = p_shape_xform.xform(shape->get_aabb());
@@ -697,7 +697,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
//but is it right? who knows at this point..
if (r_result) {
- r_result->collider_id = 0;
+ r_result->collider_id = ObjectID();
r_result->collider_shape = 0;
}
Rect2 body_aabb;
diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h
index 94f8cf9d71..919c65d849 100644
--- a/servers/physics_2d/space_2d_sw.h
+++ b/servers/physics_2d/space_2d_sw.h
@@ -45,7 +45,7 @@ class Physics2DDirectSpaceStateSW : public Physics2DDirectSpaceState {
GDCLASS(Physics2DDirectSpaceStateSW, Physics2DDirectSpaceState);
- int _intersect_point_impl(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_point, bool p_filter_by_canvas = false, ObjectID p_canvas_instance_id = 0);
+ int _intersect_point_impl(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_point, bool p_filter_by_canvas = false, ObjectID p_canvas_instance_id = ObjectID());
public:
Space2DSW *space;
@@ -61,7 +61,7 @@ public:
Physics2DDirectSpaceStateSW();
};
-class Space2DSW : public RID_Data {
+class Space2DSW {
public:
enum ElapsedTime {