From c2a6f7c2ee6245109c897ee23b093b5277a30594 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 20 Oct 2010 19:13:46 +0000 Subject: removes Static and Solid entity flags, corrects EntityDynamic motionstate sync --- src/core/entity.cc | 67 ++++++++++++++++++++++----------------------------- src/core/entity.h | 2 +- src/core/netserver.cc | 2 +- 3 files changed, 31 insertions(+), 40 deletions(-) (limited to 'src/core') diff --git a/src/core/entity.cc b/src/core/entity.cc index 2b37d95..c76b23a 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -523,11 +523,14 @@ void Entity::reset() entity_body->setActivationState(ISLAND_SLEEPING); if (zone()) - zone()->physics()->addRigidBody(entity_body); + zone()->physics()->addRigidBody(entity_body); } // transfer entity location to motion state - entity_body->setWorldTransform(t); + body()->setWorldTransform(t); + body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); + if (zone()) zone()->physics()->synchronizeSingleMotionState(entity_body); @@ -577,19 +580,22 @@ void EntityDynamic::set_keepalive_timeout(float timeout) void EntityDynamic::reset() { Entity::reset(); - - if ((entity_state == Docked) || (entity_state == Destroyed) || (!visible())){ - entity_body->activate(false); + + if (entity_state == Docked) { + body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); } else { - entity_body->activate(true); + body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f)); + body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f)); } } void EntityDynamic::frame(float seconds) { - if ((flags() & Static) == Static) + if (entity_state == Docked) { return; - + } + // transfer bullet state to entity state if (entity_body) { // this makes sure an update is sent if speed goes to 0 in the next step @@ -841,9 +847,6 @@ void EntityControlable::receive_server_update(std::istream &is) void EntityControlable::set_thrust(float thrust) { - if ((flags() & Static) == Static) - return; - if (thrust != target_thrust) { target_thrust = thrust; set_dirty(); @@ -852,9 +855,6 @@ void EntityControlable::set_thrust(float thrust) void EntityControlable::set_direction(float direction) { - if ((flags() & Static) == Static) - return; - if (target_direction != direction) { target_direction = direction; set_dirty(); @@ -863,9 +863,6 @@ void EntityControlable::set_direction(float direction) void EntityControlable::set_pitch(float pitch) { - if ((flags() & Static) == Static) - return; - if (target_pitch != pitch) { target_pitch = pitch; set_dirty(); @@ -874,9 +871,6 @@ void EntityControlable::set_pitch(float pitch) void EntityControlable::set_roll(float roll) { - if ((flags() & Static) == Static) - return; - if (target_roll != roll) { target_roll = roll; set_dirty(); @@ -885,9 +879,6 @@ void EntityControlable::set_roll(float roll) void EntityControlable::set_strafe(float strafe) { - if ((flags() & Static) == Static) - return; - if (target_strafe != strafe) { target_strafe = strafe; set_dirty(); @@ -896,9 +887,6 @@ void EntityControlable::set_strafe(float strafe) void EntityControlable::set_vstrafe(float vstrafe) { - if ((flags() & Static) == Static) - return; - if (target_vstrafe != vstrafe) { target_vstrafe = vstrafe; set_dirty(); @@ -907,9 +895,6 @@ void EntityControlable::set_vstrafe(float vstrafe) void EntityControlable::set_afterburner(float afterburner) { - if ((flags() & Static) == Static) - return; - if (target_afterburner != afterburner) { target_afterburner = afterburner; set_dirty(); @@ -979,19 +964,25 @@ void EntityControlable::reset() if (zone()) { entity_zone->physics()->addRigidBody(body()); entity_zone->physics()->addAction(entity_actioninterface); - - // transfer entity location to motion state - zone()->physics()->synchronizeSingleMotionState(entity_body); } } - - entity_body->setWorldTransform(t); - if ((entity_state == Docked) || (entity_state == Destroyed) || (!visible())){ - entity_body->activate(false); + + body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setWorldTransform(t); + + if (entity_state == Docked) { + body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); } else { - entity_body->activate(true); + body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f)); + body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f)); + } + + if (zone()) { + // transfer entity location to motion state + zone()->physics()->synchronizeSingleMotionState(entity_body); } - set_dirty(); } diff --git a/src/core/entity.h b/src/core/entity.h index f6ee1d7..8dd5644 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -44,7 +44,7 @@ public: /** * @brief entity flags */ - enum Flags {Static = 1, Solid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32}; + enum Flags {NonSolid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32}; /// Entity type constants enum Type {Default = 0, Dynamic = 1, Controlable = 2, Globe = 3}; diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 8d3e762..4769f68 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -366,7 +366,7 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp) // this entity has entered the zone send_entity_create(client, entity); - } else if (entity->dirty() && !(entity->flags() & Entity::Static)) { + } else if (entity->dirty()) { // FIXME only within visual range send_entity_update(client, entity); -- cgit v1.2.3