renaming and cleanup

This commit is contained in:
Andrew Meadows 2015-05-13 08:44:10 -07:00
parent 7e9e223b3e
commit fb34a5ba84
6 changed files with 39 additions and 42 deletions

View file

@ -2451,7 +2451,7 @@ void Application::update(float deltaTime) {
if (_physicsEngine.hasOutgoingChanges()) { if (_physicsEngine.hasOutgoingChanges()) {
_entitySimulation.lock(); _entitySimulation.lock();
_entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges()); _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
_entitySimulation.handleCollisionEvents(_physicsEngine.getCollisionEvents()); _entitySimulation.handleCollisionEvents(_physicsEngine.getCollisionEvents());
_entitySimulation.unlock(); _entitySimulation.unlock();
_physicsEngine.dumpStatsIfNecessary(); _physicsEngine.dumpStatsIfNecessary();

View file

@ -35,9 +35,9 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItem* entity
_serverGravity(0.0f), _serverGravity(0.0f),
_serverAcceleration(0.0f), _serverAcceleration(0.0f),
_accelerationNearlyGravityCount(0), _accelerationNearlyGravityCount(0),
_touchesOurSimulation(false), _candidateForOwnership(false),
_framesSinceSimulatorBid(0), _loopsSinceOwnershipBid(0),
_movingFramesWithoutSimulationOwner(0) _loopsWithoutOwner(0)
{ {
_type = MOTION_STATE_TYPE_ENTITY; _type = MOTION_STATE_TYPE_ENTITY;
assert(entity != nullptr); assert(entity != nullptr);
@ -65,9 +65,9 @@ void EntityMotionState::updateServerPhysicsVariables(uint32_t flags) {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
const QUuid& sessionID = nodeList->getSessionUUID(); const QUuid& sessionID = nodeList->getSessionUUID();
if (_entity->getSimulatorID() != sessionID) { if (_entity->getSimulatorID() != sessionID) {
_touchesOurSimulation = false; _candidateForOwnership = false;
_movingFramesWithoutSimulationOwner = 0; _loopsWithoutOwner = 0;
_framesSinceSimulatorBid = 0; _loopsSinceOwnershipBid = 0;
} }
} }
} }
@ -154,15 +154,15 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
_entity->setLastSimulated(usecTimestampNow()); _entity->setLastSimulated(usecTimestampNow());
if (_entity->getSimulatorID().isNull()) { if (_entity->getSimulatorID().isNull()) {
_movingFramesWithoutSimulationOwner++; _loopsWithoutOwner++;
const uint32_t ownershipClaimDelay = 50; // TODO -- how to pick this? based on meters from our characterController? const uint32_t OWNERSHIP_BID_DELAY = 50;
if (_movingFramesWithoutSimulationOwner > ownershipClaimDelay) { if (_loopsWithoutOwner > OWNERSHIP_BID_DELAY) {
//qDebug() << "Warning -- claiming something I saw moving." << getName(); //qDebug() << "Warning -- claiming something I saw moving." << getName();
_touchesOurSimulation = true; _candidateForOwnership = true;
} }
} else { } else {
_movingFramesWithoutSimulationOwner = 0; _loopsWithoutOwner = 0;
} }
#ifdef WANT_DEBUG #ifdef WANT_DEBUG
@ -184,12 +184,11 @@ void EntityMotionState::computeObjectShapeInfo(ShapeInfo& shapeInfo) {
// we alwasy resend packets for objects that have stopped moving up to some max limit. // we alwasy resend packets for objects that have stopped moving up to some max limit.
const int MAX_NUM_NON_MOVING_UPDATES = 5; const int MAX_NUM_NON_MOVING_UPDATES = 5;
bool EntityMotionState::doesNotNeedToSendUpdate(const QUuid& sessionID) const { bool EntityMotionState::isCandidateForOwnership(const QUuid& sessionID) const {
if (!_body || !_entity) { if (!_body || !_entity) {
return true; return false;
} }
return _candidateForOwnership || sessionID == _entity->getSimulatorID();
return (sessionID != _entity->getSimulatorID() && !_touchesOurSimulation);
} }
bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
@ -297,13 +296,13 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
return (fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT); return (fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT);
} }
bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame, const QUuid& sessionID) { bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& sessionID) {
// NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called // NOTE: we expect _entity and _body to be valid in this context, since shouldSendUpdate() is only called
// after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL. // after doesNotNeedToSendUpdate() returns false and that call should return 'true' if _entity or _body are NULL.
assert(_entity); assert(_entity);
assert(_body); assert(_body);
if (!remoteSimulationOutOfSync(simulationFrame)) { if (!remoteSimulationOutOfSync(simulationStep)) {
return false; return false;
} }
@ -313,9 +312,9 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame, const QUuid&
} }
const uint32_t FRAMES_BETWEEN_OWNERSHIP_CLAIMS = 30; const uint32_t FRAMES_BETWEEN_OWNERSHIP_CLAIMS = 30;
if (_touchesOurSimulation) { if (_candidateForOwnership) {
++_framesSinceSimulatorBid; ++_loopsSinceOwnershipBid;
if (_framesSinceSimulatorBid > FRAMES_BETWEEN_OWNERSHIP_CLAIMS) { if (_loopsSinceOwnershipBid > FRAMES_BETWEEN_OWNERSHIP_CLAIMS) {
// we don't own the simulation, but it's time to bid for it // we don't own the simulation, but it's time to bid for it
return true; return true;
} }
@ -411,7 +410,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
// we own the simulation but the entity has stopped, so we tell the server that we're clearing simulatorID // we own the simulation but the entity has stopped, so we tell the server that we're clearing simulatorID
// but we remember that we do still own it... and rely on the server to tell us that we don't // but we remember that we do still own it... and rely on the server to tell us that we don't
properties.setSimulatorID(QUuid()); properties.setSimulatorID(QUuid());
_touchesOurSimulation = false; _candidateForOwnership = false;
} else { } else {
// explicitly set the property's simulatorID so that it is flagged as changed and will be packed // explicitly set the property's simulatorID so that it is flagged as changed and will be packed
properties.setSimulatorID(sessionID); properties.setSimulatorID(sessionID);
@ -467,7 +466,7 @@ QUuid EntityMotionState::getSimulatorID() const {
// virtual // virtual
void EntityMotionState::bump() { void EntityMotionState::bump() {
_touchesOurSimulation = true; _candidateForOwnership = true;
} }
void EntityMotionState::resetMeasuredBodyAcceleration() { void EntityMotionState::resetMeasuredBodyAcceleration() {

View file

@ -46,10 +46,9 @@ public:
virtual void computeObjectShapeInfo(ShapeInfo& shapeInfo); virtual void computeObjectShapeInfo(ShapeInfo& shapeInfo);
// TODO: Andrew to rename doesNotNeedToSendUpdate() bool isCandidateForOwnership(const QUuid& sessionID) const;
bool doesNotNeedToSendUpdate(const QUuid& sessionID) const;
bool remoteSimulationOutOfSync(uint32_t simulationStep); bool remoteSimulationOutOfSync(uint32_t simulationStep);
bool shouldSendUpdate(uint32_t simulationFrame, const QUuid& sessionID); bool shouldSendUpdate(uint32_t simulationStep, const QUuid& sessionID);
void sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step); void sendUpdate(OctreeEditPacketSender* packetSender, const QUuid& sessionID, uint32_t step);
virtual uint32_t getAndClearIncomingDirtyFlags() const; virtual uint32_t getAndClearIncomingDirtyFlags() const;
@ -107,9 +106,9 @@ protected:
glm::vec3 _measuredAcceleration; glm::vec3 _measuredAcceleration;
quint8 _accelerationNearlyGravityCount; quint8 _accelerationNearlyGravityCount;
bool _touchesOurSimulation; bool _candidateForOwnership;
uint32_t _framesSinceOwnershipBid; uint32_t _loopsSinceOwnershipBid;
uint32_t _movingFramesWithoutSimulationOwner; uint32_t _loopsWithoutOwner;
}; };
#endif // hifi_EntityMotionState_h #endif // hifi_EntityMotionState_h

View file

@ -188,7 +188,7 @@ VectorOfMotionStates& PhysicalEntitySimulation::getObjectsToChange() {
return _tempVector; return _tempVector;
} }
void PhysicalEntitySimulation::handleOutgoingChanges(VectorOfMotionStates& motionStates) { void PhysicalEntitySimulation::handleOutgoingChanges(VectorOfMotionStates& motionStates, const QUuid& sessionID) {
// walk the motionStates looking for those that correspond to entities // walk the motionStates looking for those that correspond to entities
for (auto stateItr : motionStates) { for (auto stateItr : motionStates) {
ObjectMotionState* state = &(*stateItr); ObjectMotionState* state = &(*stateItr);
@ -196,7 +196,7 @@ void PhysicalEntitySimulation::handleOutgoingChanges(VectorOfMotionStates& motio
EntityMotionState* entityState = static_cast<EntityMotionState*>(state); EntityMotionState* entityState = static_cast<EntityMotionState*>(state);
EntityItem* entity = entityState->getEntity(); EntityItem* entity = entityState->getEntity();
if (entity) { if (entity) {
if (entity->isKnownID()) { if (entity->isKnownID() && entityState->isCandidateForOwnership(sessionID)) {
_outgoingChanges.insert(entityState); _outgoingChanges.insert(entityState);
} }
_entitiesToSort.insert(entityState->getEntity()); _entitiesToSort.insert(entityState->getEntity());
@ -204,23 +204,21 @@ void PhysicalEntitySimulation::handleOutgoingChanges(VectorOfMotionStates& motio
} }
} }
auto nodeList = DependencyManager::get<NodeList>();
const QUuid& sessionID = nodeList->getSessionUUID();
if (sessionID.isNull()) {
// no updates to send
_outgoingChanges.clear();
return;
}
// send outgoing packets
uint32_t numSubsteps = _physicsEngine->getNumSubsteps(); uint32_t numSubsteps = _physicsEngine->getNumSubsteps();
if (_lastStepSendPackets != numSubsteps) { if (_lastStepSendPackets != numSubsteps) {
_lastStepSendPackets = numSubsteps; _lastStepSendPackets = numSubsteps;
if (sessionID.isNull()) {
// usually don't get here, but if so --> nothing to do
_outgoingChanges.clear();
return;
}
// send outgoing packets
QSet<EntityMotionState*>::iterator stateItr = _outgoingChanges.begin(); QSet<EntityMotionState*>::iterator stateItr = _outgoingChanges.begin();
while (stateItr != _outgoingChanges.end()) { while (stateItr != _outgoingChanges.end()) {
EntityMotionState* state = *stateItr; EntityMotionState* state = *stateItr;
if (state->doesNotNeedToSendUpdate(sessionID)) { if (!state->isCandidateForOwnership(sessionID)) {
stateItr = _outgoingChanges.erase(stateItr); stateItr = _outgoingChanges.erase(stateItr);
} else if (state->shouldSendUpdate(numSubsteps, sessionID)) { } else if (state->shouldSendUpdate(numSubsteps, sessionID)) {
state->sendUpdate(_entityPacketSender, sessionID, numSubsteps); state->sendUpdate(_entityPacketSender, sessionID, numSubsteps);

View file

@ -48,7 +48,7 @@ public:
VectorOfMotionStates& getObjectsToAdd(); VectorOfMotionStates& getObjectsToAdd();
VectorOfMotionStates& getObjectsToChange(); VectorOfMotionStates& getObjectsToChange();
void handleOutgoingChanges(VectorOfMotionStates& motionStates); void handleOutgoingChanges(VectorOfMotionStates& motionStates, const QUuid& sessionID);
void handleCollisionEvents(CollisionEvents& collisionEvents); void handleCollisionEvents(CollisionEvents& collisionEvents);
private: private:

View file

@ -53,6 +53,7 @@ public:
void init(); void init();
void setSessionUUID(const QUuid& sessionID) { _sessionID = sessionID; } void setSessionUUID(const QUuid& sessionID) { _sessionID = sessionID; }
const QUuid& getSessionID() const { return _sessionID; }
void addObject(ObjectMotionState* motionState); void addObject(ObjectMotionState* motionState);
void removeObject(ObjectMotionState* motionState); void removeObject(ObjectMotionState* motionState);