summaryrefslogtreecommitdiff
path: root/servers/physics_2d/body_2d_sw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_2d/body_2d_sw.cpp')
-rw-r--r--servers/physics_2d/body_2d_sw.cpp148
1 files changed, 74 insertions, 74 deletions
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 863b422996..79388ffe93 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -30,7 +30,7 @@
#include "body_2d_sw.h"
#include "area_2d_sw.h"
-#include "physics_2d_server_sw.h"
+#include "physics_server_2d_sw.h"
#include "space_2d_sw.h"
void Body2DSW::_update_inertia() {
@@ -45,7 +45,7 @@ void Body2DSW::update_inertias() {
switch (mode) {
- case Physics2DServer::BODY_MODE_RIGID: {
+ case PhysicsServer2D::BODY_MODE_RIGID: {
if (user_inertia) {
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
@@ -86,13 +86,13 @@ void Body2DSW::update_inertias() {
_inv_mass = 0;
} break;
- case Physics2DServer::BODY_MODE_KINEMATIC:
- case Physics2DServer::BODY_MODE_STATIC: {
+ case PhysicsServer2D::BODY_MODE_KINEMATIC:
+ case PhysicsServer2D::BODY_MODE_STATIC: {
_inv_inertia = 0;
_inv_mass = 0;
} break;
- case Physics2DServer::BODY_MODE_CHARACTER: {
+ case PhysicsServer2D::BODY_MODE_CHARACTER: {
_inv_inertia = 0;
_inv_mass = 1.0 / mass;
@@ -114,7 +114,7 @@ void Body2DSW::set_active(bool p_active) {
if (get_space())
get_space()->body_remove_from_active_list(&active_list);
} else {
- if (mode == Physics2DServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC)
return; //static bodies can't become active
if (get_space())
get_space()->body_add_to_active_list(&active_list);
@@ -134,24 +134,24 @@ void Body2DSW::set_active(bool p_active) {
*/
}
-void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, real_t p_value) {
+void Body2DSW::set_param(PhysicsServer2D::BodyParameter p_param, real_t p_value) {
switch (p_param) {
- case Physics2DServer::BODY_PARAM_BOUNCE: {
+ case PhysicsServer2D::BODY_PARAM_BOUNCE: {
bounce = p_value;
} break;
- case Physics2DServer::BODY_PARAM_FRICTION: {
+ case PhysicsServer2D::BODY_PARAM_FRICTION: {
friction = p_value;
} break;
- case Physics2DServer::BODY_PARAM_MASS: {
+ case PhysicsServer2D::BODY_PARAM_MASS: {
ERR_FAIL_COND(p_value <= 0);
mass = p_value;
_update_inertia();
} break;
- case Physics2DServer::BODY_PARAM_INERTIA: {
+ case PhysicsServer2D::BODY_PARAM_INERTIA: {
if (p_value <= 0) {
user_inertia = false;
_update_inertia();
@@ -161,14 +161,14 @@ void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, real_t p_value)
_inv_inertia = 1.0 / p_value;
}
} break;
- case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: {
+ case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: {
gravity_scale = p_value;
} break;
- case Physics2DServer::BODY_PARAM_LINEAR_DAMP: {
+ case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
linear_damp = p_value;
} break;
- case Physics2DServer::BODY_PARAM_ANGULAR_DAMP: {
+ case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP: {
angular_damp = p_value;
} break;
@@ -177,31 +177,31 @@ void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, real_t p_value)
}
}
-real_t Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const {
+real_t Body2DSW::get_param(PhysicsServer2D::BodyParameter p_param) const {
switch (p_param) {
- case Physics2DServer::BODY_PARAM_BOUNCE: {
+ case PhysicsServer2D::BODY_PARAM_BOUNCE: {
return bounce;
}
- case Physics2DServer::BODY_PARAM_FRICTION: {
+ case PhysicsServer2D::BODY_PARAM_FRICTION: {
return friction;
}
- case Physics2DServer::BODY_PARAM_MASS: {
+ case PhysicsServer2D::BODY_PARAM_MASS: {
return mass;
}
- case Physics2DServer::BODY_PARAM_INERTIA: {
+ case PhysicsServer2D::BODY_PARAM_INERTIA: {
return inertia;
}
- case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: {
+ case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: {
return gravity_scale;
}
- case Physics2DServer::BODY_PARAM_LINEAR_DAMP: {
+ case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
return linear_damp;
}
- case Physics2DServer::BODY_PARAM_ANGULAR_DAMP: {
+ case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP: {
return angular_damp;
}
@@ -212,28 +212,28 @@ real_t Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const {
return 0;
}
-void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) {
+void Body2DSW::set_mode(PhysicsServer2D::BodyMode p_mode) {
- Physics2DServer::BodyMode prev = mode;
+ PhysicsServer2D::BodyMode prev = mode;
mode = p_mode;
switch (p_mode) {
//CLEAR UP EVERYTHING IN CASE IT NOT WORKS!
- case Physics2DServer::BODY_MODE_STATIC:
- case Physics2DServer::BODY_MODE_KINEMATIC: {
+ case PhysicsServer2D::BODY_MODE_STATIC:
+ case PhysicsServer2D::BODY_MODE_KINEMATIC: {
_set_inv_transform(get_transform().affine_inverse());
_inv_mass = 0;
_inv_inertia = 0;
- _set_static(p_mode == Physics2DServer::BODY_MODE_STATIC);
- set_active(p_mode == Physics2DServer::BODY_MODE_KINEMATIC && contacts.size());
+ _set_static(p_mode == PhysicsServer2D::BODY_MODE_STATIC);
+ set_active(p_mode == PhysicsServer2D::BODY_MODE_KINEMATIC && contacts.size());
linear_velocity = Vector2();
angular_velocity = 0;
- if (mode == Physics2DServer::BODY_MODE_KINEMATIC && prev != mode) {
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && prev != mode) {
first_time_kinematic = true;
}
} break;
- case Physics2DServer::BODY_MODE_RIGID: {
+ case PhysicsServer2D::BODY_MODE_RIGID: {
_inv_mass = mass > 0 ? (1.0 / mass) : 0;
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
@@ -241,7 +241,7 @@ void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) {
set_active(true);
} break;
- case Physics2DServer::BODY_MODE_CHARACTER: {
+ case PhysicsServer2D::BODY_MODE_CHARACTER: {
_inv_mass = mass > 0 ? (1.0 / mass) : 0;
_inv_inertia = 0;
@@ -250,7 +250,7 @@ void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) {
angular_velocity = 0;
} break;
}
- if (p_mode == Physics2DServer::BODY_MODE_RIGID && _inv_inertia == 0) {
+ if (p_mode == PhysicsServer2D::BODY_MODE_RIGID && _inv_inertia == 0) {
_update_inertia();
}
/*
@@ -258,7 +258,7 @@ void Body2DSW::set_mode(Physics2DServer::BodyMode p_mode) {
_update_queries();
*/
}
-Physics2DServer::BodyMode Body2DSW::get_mode() const {
+PhysicsServer2D::BodyMode Body2DSW::get_mode() const {
return mode;
}
@@ -269,12 +269,12 @@ void Body2DSW::_shapes_changed() {
wakeup_neighbours();
}
-void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant &p_variant) {
+void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_variant) {
switch (p_state) {
- case Physics2DServer::BODY_STATE_TRANSFORM: {
+ case PhysicsServer2D::BODY_STATE_TRANSFORM: {
- if (mode == Physics2DServer::BODY_MODE_KINEMATIC) {
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
new_transform = p_variant;
//wakeup_neighbours();
@@ -284,7 +284,7 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant &p_va
_set_inv_transform(get_transform().affine_inverse());
first_time_kinematic = false;
}
- } else if (mode == Physics2DServer::BODY_MODE_STATIC) {
+ } else if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
_set_transform(p_variant);
_set_inv_transform(get_transform().affine_inverse());
wakeup_neighbours();
@@ -300,28 +300,28 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant &p_va
wakeup();
} break;
- case Physics2DServer::BODY_STATE_LINEAR_VELOCITY: {
+ case PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY: {
/*
- if (mode==Physics2DServer::BODY_MODE_STATIC)
+ if (mode==PhysicsServer2D::BODY_MODE_STATIC)
break;
*/
linear_velocity = p_variant;
wakeup();
} break;
- case Physics2DServer::BODY_STATE_ANGULAR_VELOCITY: {
+ case PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY: {
/*
- if (mode!=Physics2DServer::BODY_MODE_RIGID)
+ if (mode!=PhysicsServer2D::BODY_MODE_RIGID)
break;
*/
angular_velocity = p_variant;
wakeup();
} break;
- case Physics2DServer::BODY_STATE_SLEEPING: {
+ case PhysicsServer2D::BODY_STATE_SLEEPING: {
//?
- if (mode == Physics2DServer::BODY_MODE_STATIC || mode == Physics2DServer::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
break;
bool do_sleep = p_variant;
if (do_sleep) {
@@ -331,34 +331,34 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant &p_va
//biased_angular_velocity=Vector3();
set_active(false);
} else {
- if (mode != Physics2DServer::BODY_MODE_STATIC)
+ if (mode != PhysicsServer2D::BODY_MODE_STATIC)
set_active(true);
}
} break;
- case Physics2DServer::BODY_STATE_CAN_SLEEP: {
+ case PhysicsServer2D::BODY_STATE_CAN_SLEEP: {
can_sleep = p_variant;
- if (mode == Physics2DServer::BODY_MODE_RIGID && !active && !can_sleep)
+ if (mode == PhysicsServer2D::BODY_MODE_RIGID && !active && !can_sleep)
set_active(true);
} break;
}
}
-Variant Body2DSW::get_state(Physics2DServer::BodyState p_state) const {
+Variant Body2DSW::get_state(PhysicsServer2D::BodyState p_state) const {
switch (p_state) {
- case Physics2DServer::BODY_STATE_TRANSFORM: {
+ case PhysicsServer2D::BODY_STATE_TRANSFORM: {
return get_transform();
}
- case Physics2DServer::BODY_STATE_LINEAR_VELOCITY: {
+ case PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY: {
return linear_velocity;
}
- case Physics2DServer::BODY_STATE_ANGULAR_VELOCITY: {
+ case PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY: {
return angular_velocity;
}
- case Physics2DServer::BODY_STATE_SLEEPING: {
+ case PhysicsServer2D::BODY_STATE_SLEEPING: {
return !is_active();
}
- case Physics2DServer::BODY_STATE_CAN_SLEEP: {
+ case PhysicsServer2D::BODY_STATE_CAN_SLEEP: {
return can_sleep;
}
}
@@ -418,7 +418,7 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
void Body2DSW::integrate_forces(real_t p_step) {
- if (mode == Physics2DServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC)
return;
Area2DSW *def_area = get_space()->get_default_area();
@@ -435,20 +435,20 @@ void Body2DSW::integrate_forces(real_t p_step) {
const AreaCMP *aa = &areas[0];
// damp_area = aa[ac-1].area;
for (int i = ac - 1; i >= 0 && !stopped; i--) {
- Physics2DServer::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
+ PhysicsServer2D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
switch (mode) {
- case Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE:
- case Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE: {
_compute_area_gravity_and_dampenings(aa[i].area);
- stopped = mode == Physics2DServer::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
+ stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_COMBINE_REPLACE;
} break;
- case Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE:
- case Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE:
+ case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
gravity = Vector2(0, 0);
area_angular_damp = 0;
area_linear_damp = 0;
_compute_area_gravity_and_dampenings(aa[i].area);
- stopped = mode == Physics2DServer::AREA_SPACE_OVERRIDE_REPLACE;
+ stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
} break;
default: {
}
@@ -478,7 +478,7 @@ void Body2DSW::integrate_forces(real_t p_step) {
Vector2 motion;
bool do_motion = false;
- if (mode == Physics2DServer::BODY_MODE_KINEMATIC) {
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
//compute motion, angular and etc. velocities from prev transform
motion = new_transform.get_origin() - get_transform().get_origin();
@@ -521,7 +521,7 @@ void Body2DSW::integrate_forces(real_t p_step) {
angular_velocity += _inv_inertia * torque * p_step;
}
- if (continuous_cd_mode != Physics2DServer::CCD_MODE_DISABLED) {
+ if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED) {
motion = linear_velocity * p_step;
do_motion = true;
@@ -545,13 +545,13 @@ void Body2DSW::integrate_forces(real_t p_step) {
void Body2DSW::integrate_velocities(real_t p_step) {
- if (mode == Physics2DServer::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC)
return;
if (fi_callback)
get_space()->body_add_to_state_query_list(&direct_state_query_list);
- if (mode == Physics2DServer::BODY_MODE_KINEMATIC) {
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
@@ -566,10 +566,10 @@ void Body2DSW::integrate_velocities(real_t p_step) {
real_t angle = get_transform().get_rotation() + total_angular_velocity * p_step;
Vector2 pos = get_transform().get_origin() + total_linear_velocity * p_step;
- _set_transform(Transform2D(angle, pos), continuous_cd_mode == Physics2DServer::CCD_MODE_DISABLED);
+ _set_transform(Transform2D(angle, pos), continuous_cd_mode == PhysicsServer2D::CCD_MODE_DISABLED);
_set_inv_transform(get_transform().inverse());
- if (continuous_cd_mode != Physics2DServer::CCD_MODE_DISABLED)
+ if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED)
new_transform = get_transform();
//_update_inertia_tensor();
@@ -588,7 +588,7 @@ void Body2DSW::wakeup_neighbours() {
if (i == E->get())
continue;
Body2DSW *b = n[i];
- if (b->mode != Physics2DServer::BODY_MODE_RIGID)
+ if (b->mode != PhysicsServer2D::BODY_MODE_RIGID)
continue;
if (!b->is_active())
@@ -626,9 +626,9 @@ void Body2DSW::call_queries() {
bool Body2DSW::sleep_test(real_t p_step) {
- if (mode == Physics2DServer::BODY_MODE_STATIC || mode == Physics2DServer::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
return true; //
- else if (mode == Physics2DServer::BODY_MODE_CHARACTER)
+ else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER)
return !active; // characters and kinematic bodies don't sleep unless asked to sleep
else if (!can_sleep)
return false;
@@ -668,7 +668,7 @@ Body2DSW::Body2DSW() :
inertia_update_list(this),
direct_state_query_list(this) {
- mode = Physics2DServer::BODY_MODE_RIGID;
+ mode = PhysicsServer2D::BODY_MODE_RIGID;
active = true;
angular_velocity = 0;
biased_angular_velocity = 0;
@@ -695,7 +695,7 @@ Body2DSW::Body2DSW() :
first_integration = false;
still_time = 0;
- continuous_cd_mode = Physics2DServer::CCD_MODE_DISABLED;
+ continuous_cd_mode = PhysicsServer2D::CCD_MODE_DISABLED;
can_sleep = true;
fi_callback = NULL;
}
@@ -708,7 +708,7 @@ Body2DSW::~Body2DSW() {
Physics2DDirectBodyStateSW *Physics2DDirectBodyStateSW::singleton = NULL;
-Physics2DDirectSpaceState *Physics2DDirectBodyStateSW::get_space_state() {
+PhysicsDirectSpaceState2D *Physics2DDirectBodyStateSW::get_space_state() {
return body->get_space()->get_direct_state();
}
@@ -717,11 +717,11 @@ Variant Physics2DDirectBodyStateSW::get_contact_collider_shape_metadata(int p_co
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Variant());
- if (!Physics2DServerSW::singletonsw->body_owner.owns(body->contacts[p_contact_idx].collider)) {
+ if (!PhysicsServer2DSW::singletonsw->body_owner.owns(body->contacts[p_contact_idx].collider)) {
return Variant();
}
- Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.getornull(body->contacts[p_contact_idx].collider);
+ Body2DSW *other = PhysicsServer2DSW::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()) {