when in serverless mode, short-circuit simulation ownership bids

This commit is contained in:
Seth Alves 2018-05-08 18:49:55 -07:00
parent d8e6ecba35
commit db03265a6b
6 changed files with 21 additions and 25 deletions

View file

@ -73,7 +73,6 @@ void EntityEditPacketSender::queueEditAvatarEntityMessage(PacketType type,
_myAvatar->updateAvatarEntity(entityItemID, binaryProperties); _myAvatar->updateAvatarEntity(entityItemID, binaryProperties);
entity->setLastBroadcast(usecTimestampNow()); entity->setLastBroadcast(usecTimestampNow());
return;
} }
@ -81,10 +80,6 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
EntityTreePointer entityTree, EntityTreePointer entityTree,
EntityItemID entityItemID, EntityItemID entityItemID,
const EntityItemProperties& properties) { const EntityItemProperties& properties) {
if (!_shouldSend) {
return; // bail early
}
if (properties.getClientOnly() && properties.getOwningAvatarID() == _myAvatar->getID()) { if (properties.getClientOnly() && properties.getOwningAvatarID() == _myAvatar->getID()) {
// this is an avatar-based entity --> update our avatar-data rather than sending to the entity-server // this is an avatar-based entity --> update our avatar-data rather than sending to the entity-server
queueEditAvatarEntityMessage(type, entityTree, entityItemID, properties); queueEditAvatarEntityMessage(type, entityTree, entityItemID, properties);
@ -143,9 +138,6 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type,
} }
void EntityEditPacketSender::queueEraseEntityMessage(const EntityItemID& entityItemID) { void EntityEditPacketSender::queueEraseEntityMessage(const EntityItemID& entityItemID) {
if (!_shouldSend) {
return; // bail early
}
// in case this was a clientOnly entity: // in case this was a clientOnly entity:
if(_myAvatar) { if(_myAvatar) {

View file

@ -22,7 +22,6 @@ const int OctreeEditPacketSender::DEFAULT_MAX_PENDING_MESSAGES = PacketSender::D
OctreeEditPacketSender::OctreeEditPacketSender() : OctreeEditPacketSender::OctreeEditPacketSender() :
_shouldSend(true),
_maxPendingMessages(DEFAULT_MAX_PENDING_MESSAGES), _maxPendingMessages(DEFAULT_MAX_PENDING_MESSAGES),
_releaseQueuedMessagesPending(false) _releaseQueuedMessagesPending(false)
{ {
@ -145,10 +144,6 @@ void OctreeEditPacketSender::queuePendingPacketToNodes(std::unique_ptr<NLPacket>
} }
void OctreeEditPacketSender::queuePacketToNodes(std::unique_ptr<NLPacket> packet) { void OctreeEditPacketSender::queuePacketToNodes(std::unique_ptr<NLPacket> packet) {
if (!_shouldSend) {
return; // bail early
}
assert(serversExist()); // we must have servers to be here!! assert(serversExist()); // we must have servers to be here!!
auto node = DependencyManager::get<NodeList>()->soloNodeOfType(getMyNodeType()); auto node = DependencyManager::get<NodeList>()->soloNodeOfType(getMyNodeType());
@ -161,10 +156,6 @@ void OctreeEditPacketSender::queuePacketToNodes(std::unique_ptr<NLPacket> packet
// NOTE: editMessage - is JUST the octcode/color and does not contain the packet header // NOTE: editMessage - is JUST the octcode/color and does not contain the packet header
void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, QByteArray& editMessage) { void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, QByteArray& editMessage) {
if (!_shouldSend) {
return; // bail early
}
// If we don't have servers, then we will simply queue up all of these packets and wait till we have // If we don't have servers, then we will simply queue up all of these packets and wait till we have
// servers for processing // servers for processing
if (!serversExist()) { if (!serversExist()) {

View file

@ -41,12 +41,10 @@ public:
/// are we in sending mode. If we're not in sending mode then all packets and messages will be ignored and /// are we in sending mode. If we're not in sending mode then all packets and messages will be ignored and
/// not queued and not sent /// not queued and not sent
bool getShouldSend() const { return _shouldSend; }
/// set sending mode. By default we are set to shouldSend=TRUE and packets will be sent. If shouldSend=FALSE, then we'll /// set sending mode. By default we are set to shouldSend=TRUE and packets will be sent. If shouldSend=FALSE, then we'll
/// switch to not sending mode, and all packets and messages will be ignored, not queued, and not sent. This might be used /// switch to not sending mode, and all packets and messages will be ignored, not queued, and not sent. This might be used
/// in an application like interface when all octree features are disabled. /// in an application like interface when all octree features are disabled.
void setShouldSend(bool shouldSend) { _shouldSend = shouldSend; }
/// if you're running in non-threaded mode, you must call this method regularly /// if you're running in non-threaded mode, you must call this method regularly
virtual bool process() override; virtual bool process() override;
@ -76,7 +74,6 @@ public slots:
protected: protected:
using EditMessagePair = std::pair<PacketType, QByteArray>; using EditMessagePair = std::pair<PacketType, QByteArray>;
bool _shouldSend;
void queuePacketToNode(const QUuid& nodeID, std::unique_ptr<NLPacket> packet); void queuePacketToNode(const QUuid& nodeID, std::unique_ptr<NLPacket> packet);
void queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr<NLPacketList> packetList); void queuePacketListToNode(const QUuid& nodeUUID, std::unique_ptr<NLPacketList> packetList);

View file

@ -348,7 +348,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
if (_numInactiveUpdates > 0) { if (_numInactiveUpdates > 0) {
const uint8_t MAX_NUM_INACTIVE_UPDATES = 20; const uint8_t MAX_NUM_INACTIVE_UPDATES = 20;
if (_numInactiveUpdates > MAX_NUM_INACTIVE_UPDATES) { if (_numInactiveUpdates > MAX_NUM_INACTIVE_UPDATES || isServerlessMode()) {
// clear local ownership (stop sending updates) and let the server clear itself // clear local ownership (stop sending updates) and let the server clear itself
_entity->clearSimulationOwnership(); _entity->clearSimulationOwnership();
return false; return false;
@ -827,3 +827,9 @@ void EntityMotionState::clearObjectVelocities() const {
} }
_entity->setAcceleration(glm::vec3(0.0f)); _entity->setAcceleration(glm::vec3(0.0f));
} }
bool EntityMotionState::isServerlessMode() {
EntityTreeElementPointer element = _entity->getElement();
EntityTreePointer tree = element ? element->getTree() : nullptr;
return tree ? tree->isServerlessMode() : false;
}

View file

@ -156,6 +156,8 @@ protected:
uint8_t _numInactiveUpdates { 1 }; uint8_t _numInactiveUpdates { 1 };
uint8_t _bidPriority { 0 }; uint8_t _bidPriority { 0 };
bool _serverVariablesSet { false }; bool _serverVariablesSet { false };
bool isServerlessMode();
}; };
#endif // hifi_EntityMotionState_h #endif // hifi_EntityMotionState_h

View file

@ -327,10 +327,18 @@ void PhysicalEntitySimulation::handleChangedMotionStates(const VectorOfMotionSta
} }
void PhysicalEntitySimulation::addOwnershipBid(EntityMotionState* motionState) { void PhysicalEntitySimulation::addOwnershipBid(EntityMotionState* motionState) {
motionState->initForBid(); if (getEntityTree()->isServerlessMode()) {
motionState->sendBid(_entityPacketSender, _physicsEngine->getNumSubsteps()); EntityItemPointer entity = motionState->getEntity();
_bids.push_back(motionState); auto nodeList = DependencyManager::get<NodeList>();
_nextBidExpiry = glm::min(_nextBidExpiry, motionState->getNextBidExpiry()); auto sessionID = nodeList->getSessionUUID();
entity->setSimulationOwner(SimulationOwner(sessionID, SCRIPT_GRAB_SIMULATION_PRIORITY));
_owned.push_back(motionState);
} else {
motionState->initForBid();
motionState->sendBid(_entityPacketSender, _physicsEngine->getNumSubsteps());
_bids.push_back(motionState);
_nextBidExpiry = glm::min(_nextBidExpiry, motionState->getNextBidExpiry());
}
} }
void PhysicalEntitySimulation::addOwnership(EntityMotionState* motionState) { void PhysicalEntitySimulation::addOwnership(EntityMotionState* motionState) {