clarification of what outgoing flags are about

This commit is contained in:
Andrew Meadows 2014-12-11 12:07:53 -08:00
parent cc0e82b97f
commit 572ceb75a4
6 changed files with 31 additions and 30 deletions

View file

@ -52,25 +52,22 @@ void EntityMotionState::getWorldTransform (btTransform &worldTrans) const {
// This callback is invoked by the physics simulation at the end of each simulation frame...
// iff the corresponding RigidBody is DYNAMIC and has moved.
void EntityMotionState::setWorldTransform (const btTransform &worldTrans) {
uint32_t dirytFlags = _entity->getDirtyFlags();
if (! (dirytFlags & EntityItem::DIRTY_POSITION)) {
glm::vec3 pos;
bulletToGLM(worldTrans.getOrigin(), pos);
_entity->setPositionInMeters(pos + ObjectMotionState::getWorldOffset());
glm::quat rot;
bulletToGLM(worldTrans.getRotation(), rot);
_entity->setRotation(rot);
}
glm::vec3 pos;
bulletToGLM(worldTrans.getOrigin(), pos);
_entity->setPositionInMeters(pos + ObjectMotionState::getWorldOffset());
if (! (dirytFlags & EntityItem::DIRTY_VELOCITY)) {
glm::vec3 v;
getVelocity(v);
_entity->setVelocityInMeters(v);
getAngularVelocity(v);
_entity->setAngularVelocity(v);
}
_outgoingDirtyFlags = OUTGOING_DIRTY_PHYSICS_FLAGS;
glm::quat rot;
bulletToGLM(worldTrans.getRotation(), rot);
_entity->setRotation(rot);
glm::vec3 v;
getVelocity(v);
_entity->setVelocityInMeters(v);
getAngularVelocity(v);
_entity->setAngularVelocity(v);
_outgoingPacketFlags = DIRTY_PHYSICS_FLAGS;
}
#endif // USE_BULLET_PHYSICS

View file

@ -56,7 +56,6 @@ public:
uint32_t getIncomingDirtyFlags() const { return _entity->getDirtyFlags(); }
void clearIncomingDirtyFlags(uint32_t flags) { _entity->clearDirtyFlags(flags); }
void clearConflictingDirtyFlags() { _outgoingDirtyFlags &= ~_entity->getDirtyFlags(); }
protected:
EntityItem* _entity;

View file

@ -52,7 +52,7 @@ ObjectMotionState::ObjectMotionState() :
_body(NULL),
_sentMoving(false),
_weKnowRecipientHasReceivedNotMoving(false),
_outgoingDirtyFlags(0),
_outgoingPacketFlags(0),
_sentFrame(0),
_sentPosition(0.0f),
_sentRotation(),

View file

@ -81,8 +81,7 @@ public:
virtual uint32_t getIncomingDirtyFlags() const = 0;
virtual void clearIncomingDirtyFlags(uint32_t flags) = 0;
void clearOutgoingDirtyFlags(uint32_t flags) { _outgoingDirtyFlags &= ~flags; }
virtual void clearConflictingDirtyFlags() = 0;
void clearOutgoingPacketFlags(uint32_t flags) { _outgoingPacketFlags &= ~flags; }
bool isAtRest() const { return !(_body->isActive()) && _weKnowRecipientHasReceivedNotMoving; }
virtual bool shouldSendUpdate(uint32_t simulationFrame, float subStepRemainder) const;
@ -105,7 +104,7 @@ protected:
bool _sentMoving; // true if last update was moving
bool _weKnowRecipientHasReceivedNotMoving;
uint32_t _outgoingDirtyFlags;
uint32_t _outgoingPacketFlags;
uint32_t _sentFrame;
glm::vec3 _sentPosition;
glm::quat _sentRotation;;

View file

@ -9,8 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// TODO DONE: make _incomingChanges to be list of MotionState*'s.
// TODO: make MotionState able to clear incoming flags
// TODO DONE: make MotionState able to clear incoming flags
// TODO: make MotionState::setWorldTransform() put itself on _incomingChanges list
// TODO: make sure incoming and outgoing pipelines are connected
// TODO: give PhysicsEngine instance an _entityPacketSender
// TODO: provide some sort of "reliable" send for "stopped" update
@ -38,16 +39,16 @@ PhysicsEngine::~PhysicsEngine() {
// begin EntitySimulation overrides
void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPhysics.begin();
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPackets.begin();
uint32_t frame = getFrameCount();
float subStepRemainder = getSubStepRemainder();
while (stateItr != _outgoingPhysics.end()) {
while (stateItr != _outgoingPackets.end()) {
ObjectMotionState* state = *stateItr;
if (state->shouldSendUpdate(frame, subStepRemainder)) {
state->sendUpdate(_entityPacketSender);
++stateItr;
} else if (state->isAtRest()) {
stateItr = _outgoingPhysics.erase(stateItr);
stateItr = _outgoingPackets.erase(stateItr);
} else {
++stateItr;
}
@ -106,7 +107,6 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
QSet<ObjectMotionState*>::iterator stateItr = _incomingChanges.begin();
while (stateItr != _incomingChanges.end()) {
ObjectMotionState* motionState = *stateItr;
motionState->clearConflictingDirtyFlags();
uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS;
btRigidBody* body = motionState->_body;
@ -121,7 +121,13 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
}
}
motionState->clearIncomingDirtyFlags(flags);
// NOTE: the order of operations is:
// (1) relayIncomingChanges()
// (2) step simulation
// (3) send outgoing packets
// This means incoming changes here (step (1)) should trump corresponding outgoing changes
motionState->clearOutgoingPacketFlags(flags); // trump
motionState->clearIncomingDirtyFlags(flags); // processed
++stateItr;
}
_incomingChanges.clear();

View file

@ -107,7 +107,7 @@ private:
// EntitySimulation stuff
QSet<EntityMotionState*> _entityMotionStates; // all entities that we track
QSet<ObjectMotionState*> _incomingChanges; // entities with pending physics changes by script or packet
QSet<ObjectMotionState*> _outgoingPhysics; // MotionStates with pending transform changes from physics simulation
QSet<ObjectMotionState*> _outgoingPackets; // MotionStates with pending changes that need to be sent over wire
EntityEditPacketSender* _entityPacketSender;