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

View file

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

View file

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

View file

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

View file

@ -9,8 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // 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 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 MotionState::setWorldTransform() put itself on _incomingChanges list
// TODO: make sure incoming and outgoing pipelines are connected
// TODO: give PhysicsEngine instance an _entityPacketSender // TODO: give PhysicsEngine instance an _entityPacketSender
// TODO: provide some sort of "reliable" send for "stopped" update // TODO: provide some sort of "reliable" send for "stopped" update
@ -38,16 +39,16 @@ PhysicsEngine::~PhysicsEngine() {
// begin EntitySimulation overrides // begin EntitySimulation overrides
void PhysicsEngine::updateEntitiesInternal(const quint64& now) { void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
QSet<ObjectMotionState*>::iterator stateItr = _outgoingPhysics.begin(); QSet<ObjectMotionState*>::iterator stateItr = _outgoingPackets.begin();
uint32_t frame = getFrameCount(); uint32_t frame = getFrameCount();
float subStepRemainder = getSubStepRemainder(); float subStepRemainder = getSubStepRemainder();
while (stateItr != _outgoingPhysics.end()) { while (stateItr != _outgoingPackets.end()) {
ObjectMotionState* state = *stateItr; ObjectMotionState* state = *stateItr;
if (state->shouldSendUpdate(frame, subStepRemainder)) { if (state->shouldSendUpdate(frame, subStepRemainder)) {
state->sendUpdate(_entityPacketSender); state->sendUpdate(_entityPacketSender);
++stateItr; ++stateItr;
} else if (state->isAtRest()) { } else if (state->isAtRest()) {
stateItr = _outgoingPhysics.erase(stateItr); stateItr = _outgoingPackets.erase(stateItr);
} else { } else {
++stateItr; ++stateItr;
} }
@ -106,7 +107,6 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
QSet<ObjectMotionState*>::iterator stateItr = _incomingChanges.begin(); QSet<ObjectMotionState*>::iterator stateItr = _incomingChanges.begin();
while (stateItr != _incomingChanges.end()) { while (stateItr != _incomingChanges.end()) {
ObjectMotionState* motionState = *stateItr; ObjectMotionState* motionState = *stateItr;
motionState->clearConflictingDirtyFlags();
uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS; uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS;
btRigidBody* body = motionState->_body; 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; ++stateItr;
} }
_incomingChanges.clear(); _incomingChanges.clear();

View file

@ -107,7 +107,7 @@ private:
// EntitySimulation stuff // EntitySimulation stuff
QSet<EntityMotionState*> _entityMotionStates; // all entities that we track QSet<EntityMotionState*> _entityMotionStates; // all entities that we track
QSet<ObjectMotionState*> _incomingChanges; // entities with pending physics changes by script or packet 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; EntityEditPacketSender* _entityPacketSender;