From ba226b9cb4ada063cbfd1d2b4a8fc9f26f878854 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 3 May 2016 13:40:05 -0700 Subject: [PATCH] promote priority immediately when already owned --- libraries/entities/src/EntityItem.cpp | 21 ++++++++++++++++++++- libraries/entities/src/EntityItem.h | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index dc017f81e6..efe01d3d82 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -655,7 +655,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (wantTerseEditLogging() && _simulationOwner != newSimOwner) { qCDebug(entities) << "sim ownership for" << getDebugName() << "is now" << newSimOwner; } - if (_simulationOwner.set(newSimOwner)) { + if (weOwnSimulation && newSimOwner.getID().isNull() && _simulationOwner.getPriority() != 0) { + // entity-server is trying to clear our ownership, probably at our own request, but we've + // changed our minds since we sent it, therefore we ignore the ownerhip part of this update. + } else if (_simulationOwner.set(newSimOwner)) { _dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID; somethingChanged = true; // recompute weOwnSimulation so that if this is the packet that tells use we are the owner, @@ -1112,6 +1115,22 @@ void EntityItem::getAllTerseUpdateProperties(EntityItemProperties& properties) c properties._accelerationChanged = true; } +void EntityItem::pokeSimulationOwnership() { + _dirtyFlags |= Simulation::DIRTY_SIMULATION_OWNERSHIP_FOR_POKE; + auto nodeList = DependencyManager::get(); + if (_simulationOwner.matchesValidID(nodeList->getSessionUUID())) { + _simulationOwner.promotePriority(SCRIPT_POKE_SIMULATION_PRIORITY); + } +} + +void EntityItem::grabSimulationOwnership() { + _dirtyFlags |= Simulation::DIRTY_SIMULATION_OWNERSHIP_FOR_GRAB; + auto nodeList = DependencyManager::get(); + if (_simulationOwner.matchesValidID(nodeList->getSessionUUID())) { + _simulationOwner.promotePriority(SCRIPT_POKE_SIMULATION_PRIORITY); + } +} + bool EntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 742ab337d0..661b25bbe8 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -373,8 +373,8 @@ public: void getAllTerseUpdateProperties(EntityItemProperties& properties) const; - void pokeSimulationOwnership() { _dirtyFlags |= Simulation::DIRTY_SIMULATION_OWNERSHIP_FOR_POKE; } - void grabSimulationOwnership() { _dirtyFlags |= Simulation::DIRTY_SIMULATION_OWNERSHIP_FOR_GRAB; } + void pokeSimulationOwnership(); + void grabSimulationOwnership(); void flagForMotionStateChange() { _dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; } bool addAction(EntitySimulation* simulation, EntityActionPointer action);