update a motionstate's idea of what the entity-server thinks when an incoming update packet arrives

This commit is contained in:
Seth Alves 2015-05-06 16:05:05 -07:00
parent c63b8a93ec
commit b0ccabe38e
3 changed files with 35 additions and 2 deletions

View file

@ -47,6 +47,34 @@ EntityMotionState::~EntityMotionState() {
assert(!_entity); assert(!_entity);
} }
void EntityMotionState::updateServerPhysicsVariables(uint32_t flags) {
if (flags & EntityItem::DIRTY_POSITION) {
_sentPosition = _entity->getPosition();
}
if (flags & EntityItem::DIRTY_ROTATION) {
_sentRotation = _entity->getRotation();
}
if (flags & EntityItem::DIRTY_LINEAR_VELOCITY) {
_sentVelocity = _entity->getVelocity();
}
if (flags & EntityItem::DIRTY_ANGULAR_VELOCITY) {
_sentAngularVelocity = _entity->getAngularVelocity();
}
}
// virtual
void EntityMotionState::handleEasyChanges(uint32_t flags) {
updateServerPhysicsVariables(flags);
ObjectMotionState::handleEasyChanges(flags);
}
// virtual
void EntityMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine) {
updateServerPhysicsVariables(flags);
ObjectMotionState::handleHardAndEasyChanges(flags, engine);
}
void EntityMotionState::clearEntity() { void EntityMotionState::clearEntity() {
_entity = nullptr; _entity = nullptr;
} }

View file

@ -28,6 +28,10 @@ public:
EntityMotionState(btCollisionShape* shape, EntityItem* item); EntityMotionState(btCollisionShape* shape, EntityItem* item);
virtual ~EntityMotionState(); virtual ~EntityMotionState();
void updateServerPhysicsVariables(uint32_t flags);
virtual void handleEasyChanges(uint32_t flags);
virtual void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine);
/// \return MOTION_TYPE_DYNAMIC or MOTION_TYPE_STATIC based on params set in EntityItem /// \return MOTION_TYPE_DYNAMIC or MOTION_TYPE_STATIC based on params set in EntityItem
virtual MotionType computeObjectMotionType() const; virtual MotionType computeObjectMotionType() const;
@ -88,6 +92,7 @@ protected:
bool _sentMoving; // true if last update was moving bool _sentMoving; // true if last update was moving
int _numNonMovingUpdates; // RELIABLE_SEND_HACK for "not so reliable" resends of packets for non-moving objects int _numNonMovingUpdates; // RELIABLE_SEND_HACK for "not so reliable" resends of packets for non-moving objects
// TODO XXX rename _sent* to _server*
uint32_t _sentStep; uint32_t _sentStep;
glm::vec3 _sentPosition; // in simulation-frame (not world-frame) glm::vec3 _sentPosition; // in simulation-frame (not world-frame)
glm::quat _sentRotation;; glm::quat _sentRotation;;

View file

@ -68,8 +68,8 @@ public:
ObjectMotionState(btCollisionShape* shape); ObjectMotionState(btCollisionShape* shape);
~ObjectMotionState(); ~ObjectMotionState();
void handleEasyChanges(uint32_t flags); virtual void handleEasyChanges(uint32_t flags);
void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine); virtual void handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* engine);
virtual void updateBodyMaterialProperties(); virtual void updateBodyMaterialProperties();
virtual void updateBodyVelocities(); virtual void updateBodyVelocities();