promote volunteer priority

also remove some cruft
change uint8_t to be quint8
This commit is contained in:
Andrew Meadows 2015-06-26 15:30:18 -07:00
parent d6c69e8fe6
commit e18506c77f
10 changed files with 49 additions and 28 deletions

View file

@ -1392,6 +1392,10 @@ void EntityItem::setSimulationOwner(const SimulationOwner& owner) {
_simulationOwner.set(owner);
}
void EntityItem::promoteSimulationPriority(quint8 priority) {
_simulationOwner.promotePriority(priority);
}
void EntityItem::updateSimulatorID(const QUuid& value) {
if (_simulationOwner.setID(value)) {
_dirtyFlags |= EntityItem::DIRTY_SIMULATOR_ID;

View file

@ -321,8 +321,9 @@ public:
const SimulationOwner& getSimulationOwner() const { return _simulationOwner; }
void setSimulationOwner(const QUuid& id, quint8 priority);
void setSimulationOwner(const SimulationOwner& owner);
void promoteSimulationPriority(quint8 priority);
quint8 getSimulatorPriority() const { return _simulationOwner.getPriority(); }
quint8 getSimulationPriority() const { return _simulationOwner.getPriority(); }
QUuid getSimulatorID() const { return _simulationOwner.getID(); }
void updateSimulatorID(const QUuid& value);
void clearSimulationOwnership();

View file

@ -163,7 +163,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, EntityItemProperties proper
// we re-assert our simulation ownership
properties.setSimulationOwner(myNodeID,
glm::max(entity->getSimulatorPriority(), SCRIPT_EDIT_SIMULATION_PRIORITY));
glm::max(entity->getSimulationPriority(), SCRIPT_EDIT_SIMULATION_PRIORITY));
} else {
// we make a bid for simulation ownership
properties.setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY);

View file

@ -169,7 +169,7 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI
// so we apply the rules for ownership change:
// (1) higher priority wins
// (2) equal priority wins if ownership filter has expired except...
uint8_t oldPriority = entity->getSimulatorPriority();
uint8_t oldPriority = entity->getSimulationPriority();
uint8_t newPriority = properties.getSimulationOwner().getPriority();
if (newPriority > oldPriority ||
(newPriority == oldPriority && properties.getSimulationOwner().hasExpired())) {
@ -208,6 +208,10 @@ bool EntityTree::updateEntityWithElement(EntityItemPointer entity, const EntityI
_simulation->lock();
_simulation->changeEntity(entity);
_simulation->unlock();
// always promote volunteer priority
if (entity->getSimulationPriority() == VOLUNTEER_SIMULATION_PRIORITY) {
entity->promoteSimulationPriority(RECRUIT_SIMULATION_PRIORITY);
}
}
} else {
// normally the _simulation clears ALL updateFlags, but since there is none we do it explicitly

View file

@ -48,16 +48,20 @@ void SimulationOwner::clear() {
void SimulationOwner::setPriority(quint8 priority) {
_priority = priority;
if (_priority == MAX_SIMULATION_PRIORITY) {
// we extend the the expiry whenever we set MAX_SIMULATION_PRIORITY
updateExpiry();
} else if (_priority == 0) {
if (_priority == 0) {
// when priority is zero we clear everything
_expiry = 0;
_id = QUuid();
}
}
void SimulationOwner::promotePriority(quint8 priority) {
if (priority > _priority) {
_priority = priority;
updateExpiry();
}
}
bool SimulationOwner::setID(const QUuid& id) {
if (_id != id) {
_id = id;

View file

@ -18,11 +18,19 @@
#include <SharedUtil.h>
#include <UUID.h>
// Simulation observers will bid to simulate unowned active objects at the lowest possible priority
// which is VOLUNTEER. If the server accepts a VOLUNTEER bid it will automatically bump it
// to RECRUIT priority so that other volunteers don't accidentally take over.
const quint8 VOLUNTEER_SIMULATION_PRIORITY = 0x01;
const quint8 PERSONAL_SIMULATION_PRIORITY = 0x7f;
const quint8 RECRUIT_SIMULATION_PRIORITY = VOLUNTEER_SIMULATION_PRIORITY + 1;
// When poking objects with scripts an observer will bid at SCRIPT_EDIT priority.
const quint8 SCRIPT_EDIT_SIMULATION_PRIORITY = 0x80;
const quint8 MAX_SIMULATION_PRIORITY = 0xff;
const quint8 ATTACHMENT_SIMULATION_PRIORITY = MAX_SIMULATION_PRIORITY;
// PERSONAL priority (needs a better name) is the level at which a simulation observer will bid for
// objects that collide its MyAvatar.
const quint8 PERSONAL_SIMULATION_PRIORITY = SCRIPT_EDIT_SIMULATION_PRIORITY - 1;
class SimulationOwner {
public:
@ -42,6 +50,7 @@ public:
void clear();
void setPriority(quint8 priority);
void promotePriority(quint8 priority);
// return true if id is changed
bool setID(const QUuid& id);

View file

@ -111,7 +111,7 @@ void EntityMotionState::handleEasyChanges(uint32_t flags, PhysicsEngine* engine)
_outgoingPriority = 0;
} else {
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
if (engine->getSessionID() == _entity->getSimulatorID() || _entity->getSimulatorPriority() > _outgoingPriority) {
if (engine->getSessionID() == _entity->getSimulatorID() || _entity->getSimulationPriority() > _outgoingPriority) {
// we own the simulation or our priority looses to remote
_outgoingPriority = 0;
}
@ -351,7 +351,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s
if (_entity->getSimulatorID() != sessionID) {
// we don't own the simulation, but maybe we should...
if (_outgoingPriority > 0) {
if (_outgoingPriority < _entity->getSimulatorPriority()) {
if (_outgoingPriority < _entity->getSimulationPriority()) {
// our priority looses to remote, so we don't bother to bid
_outgoingPriority = 0;
return false;
@ -453,7 +453,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
// else the ownership is not changing so we don't bother to pack it
} else {
// we don't own the simulation for this entity yet, but we're sending a bid for it
properties.setSimulationOwner(sessionID, glm::max<uint8_t>(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY));
properties.setSimulationOwner(sessionID, glm::max<quint8>(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY));
_nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS;
}
@ -493,9 +493,9 @@ uint32_t EntityMotionState::getAndClearIncomingDirtyFlags() {
}
// virtual
uint8_t EntityMotionState::getSimulatorPriority() const {
quint8 EntityMotionState::getSimulationPriority() const {
if (_entity) {
return _entity->getSimulatorPriority();
return _entity->getSimulationPriority();
}
return 0;
}
@ -510,10 +510,9 @@ QUuid EntityMotionState::getSimulatorID() const {
}
// virtual
void EntityMotionState::bump(uint8_t priority) {
void EntityMotionState::bump(quint8 priority) {
if (_entity) {
//uint8_t inheritedPriority = priority < 2 ? 1 : priority - 1;
uint8_t inheritedPriority = VOLUNTEER_SIMULATION_PRIORITY;
quint8 inheritedPriority = VOLUNTEER_SIMULATION_PRIORITY;
setOutgoingPriority(inheritedPriority);
}
}
@ -586,6 +585,6 @@ int16_t EntityMotionState::computeCollisionGroup() {
return COLLISION_GROUP_DEFAULT;
}
void EntityMotionState::setOutgoingPriority(uint8_t priority) {
_outgoingPriority = glm::max<uint8_t>(_outgoingPriority, priority);
void EntityMotionState::setOutgoingPriority(quint8 priority) {
_outgoingPriority = glm::max<quint8>(_outgoingPriority, priority);
}

View file

@ -68,9 +68,9 @@ public:
virtual const QUuid& getObjectID() const { return _entity->getID(); }
virtual uint8_t getSimulatorPriority() const;
virtual quint8 getSimulationPriority() const;
virtual QUuid getSimulatorID() const;
virtual void bump(uint8_t priority);
virtual void bump(quint8 priority);
EntityItemPointer getEntity() const { return _entity; }
@ -82,7 +82,7 @@ public:
virtual int16_t computeCollisionGroup();
// eternal logic can suggest a simuator priority bid for the next outgoing update
void setOutgoingPriority(uint8_t priority);
void setOutgoingPriority(quint8 priority);
friend class PhysicalEntitySimulation;
@ -116,7 +116,7 @@ protected:
quint8 _accelerationNearlyGravityCount;
quint64 _nextOwnershipBid = 0;
uint32_t _loopsWithoutOwner;
uint8_t _outgoingPriority = 0;
quint8 _outgoingPriority = 0;
};
#endif // hifi_EntityMotionState_h

View file

@ -119,9 +119,9 @@ public:
virtual const QUuid& getObjectID() const = 0;
virtual uint8_t getSimulatorPriority() const { return 0; }
virtual quint8 getSimulationPriority() const { return 0; }
virtual QUuid getSimulatorID() const = 0;
virtual void bump(uint8_t priority) {}
virtual void bump(quint8 priority) {}
virtual QString getName() { return ""; }

View file

@ -270,14 +270,14 @@ void PhysicsEngine::doOwnershipInfection(const btCollisionObject* objectA, const
// NOTE: we might own the simulation of a kinematic object (A)
// but we don't claim ownership of kinematic objects (B) based on collisions here.
if (!objectB->isStaticOrKinematicObject() && b->getSimulatorID() != _sessionID) {
quint8 priority = a ? a->getSimulatorPriority() : PERSONAL_SIMULATION_PRIORITY;
quint8 priority = a ? a->getSimulationPriority() : PERSONAL_SIMULATION_PRIORITY;
b->bump(priority);
}
} else if (a && ((b && b->getSimulatorID() == _sessionID && !objectB->isStaticObject()) || (objectB == characterObject))) {
// SIMILARLY: we might own the simulation of a kinematic object (B)
// but we don't claim ownership of kinematic objects (A) based on collisions here.
if (!objectA->isStaticOrKinematicObject() && a->getSimulatorID() != _sessionID) {
quint8 priority = b ? b->getSimulatorPriority() : PERSONAL_SIMULATION_PRIORITY;
quint8 priority = b ? b->getSimulationPriority() : PERSONAL_SIMULATION_PRIORITY;
a->bump(priority);
}
}