mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
Merge pull request #12090 from AndrewMeadows/simulation-ownership-003
more stable simulation ownership
This commit is contained in:
commit
487dab641f
2 changed files with 15 additions and 8 deletions
|
@ -355,11 +355,11 @@ bool EntityTree::updateEntity(EntityItemPointer entity, const EntityItemProperti
|
||||||
} else if (submittedID == senderID) {
|
} else if (submittedID == senderID) {
|
||||||
// the sender is trying to take or continue ownership
|
// the sender is trying to take or continue ownership
|
||||||
if (entity->getSimulatorID().isNull()) {
|
if (entity->getSimulatorID().isNull()) {
|
||||||
// the sender it taking ownership
|
// the sender is taking ownership
|
||||||
properties.promoteSimulationPriority(RECRUIT_SIMULATION_PRIORITY);
|
properties.promoteSimulationPriority(RECRUIT_SIMULATION_PRIORITY);
|
||||||
simulationBlocked = false;
|
simulationBlocked = false;
|
||||||
} else if (entity->getSimulatorID() == senderID) {
|
} else if (entity->getSimulatorID() == senderID) {
|
||||||
// the sender is asserting ownership
|
// the sender is asserting ownership, maybe changing priority
|
||||||
simulationBlocked = false;
|
simulationBlocked = false;
|
||||||
} else {
|
} else {
|
||||||
// the sender is trying to steal ownership from another simulator
|
// the sender is trying to steal ownership from another simulator
|
||||||
|
|
|
@ -155,7 +155,7 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
// (1) we own it but may need to change the priority OR...
|
// (1) we own it but may need to change the priority OR...
|
||||||
// (2) we don't own it but should bid (because a local script has been changing physics properties)
|
// (2) we don't own it but should bid (because a local script has been changing physics properties)
|
||||||
uint8_t newPriority = isLocallyOwned() ? _entity->getSimulationOwner().getPriority() : _entity->getSimulationOwner().getPendingPriority();
|
uint8_t newPriority = isLocallyOwned() ? _entity->getSimulationOwner().getPriority() : _entity->getSimulationOwner().getPendingPriority();
|
||||||
_outgoingPriority = glm::max(_outgoingPriority, newPriority);
|
upgradeOutgoingPriority(newPriority);
|
||||||
|
|
||||||
// reset bid expiry so that we bid ASAP
|
// reset bid expiry so that we bid ASAP
|
||||||
_nextOwnershipBid = 0;
|
_nextOwnershipBid = 0;
|
||||||
|
@ -403,7 +403,8 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_entity->dynamicDataNeedsTransmit()) {
|
if (_entity->dynamicDataNeedsTransmit()) {
|
||||||
_outgoingPriority = _entity->hasActions() ? SCRIPT_GRAB_SIMULATION_PRIORITY : SCRIPT_POKE_SIMULATION_PRIORITY;
|
uint8_t priority = _entity->hasActions() ? SCRIPT_GRAB_SIMULATION_PRIORITY : SCRIPT_POKE_SIMULATION_PRIORITY;
|
||||||
|
upgradeOutgoingPriority(priority);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,17 +503,21 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
|
||||||
// we don't own the simulation
|
// we don't own the simulation
|
||||||
|
|
||||||
// NOTE: we do not volunteer to own kinematic or static objects
|
// NOTE: we do not volunteer to own kinematic or static objects
|
||||||
uint8_t insufficientPriority = _body->isStaticOrKinematicObject() ? VOLUNTEER_SIMULATION_PRIORITY : 0;
|
uint8_t volunteerPriority = _body->isStaticOrKinematicObject() ? VOLUNTEER_SIMULATION_PRIORITY : 0;
|
||||||
|
|
||||||
bool shouldBid = _outgoingPriority > insufficientPriority && // but we would like to own it AND
|
bool shouldBid = _outgoingPriority > volunteerPriority && // but we would like to own it AND
|
||||||
usecTimestampNow() > _nextOwnershipBid; // it is time to bid again
|
usecTimestampNow() > _nextOwnershipBid; // it is time to bid again
|
||||||
if (shouldBid && _outgoingPriority < _entity->getSimulationPriority()) {
|
if (shouldBid && _outgoingPriority < _entity->getSimulationPriority()) {
|
||||||
// we are insufficiently interested so clear our interest
|
// we are insufficiently interested so clear _outgoingPriority
|
||||||
// and reset the bid expiry
|
// and reset the bid expiry
|
||||||
_outgoingPriority = 0;
|
_outgoingPriority = 0;
|
||||||
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
|
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
|
||||||
}
|
}
|
||||||
return shouldBid;
|
return shouldBid;
|
||||||
|
} else {
|
||||||
|
// When we own the simulation: make sure _outgoingPriority is not less than current owned priority
|
||||||
|
// because: an _outgoingPriority of zero indicates that we should drop ownership when we have it.
|
||||||
|
upgradeOutgoingPriority(_entity->getSimulationPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
return remoteSimulationOutOfSync(simulationStep);
|
return remoteSimulationOutOfSync(simulationStep);
|
||||||
|
@ -618,8 +623,10 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
||||||
// don't forget to remember that we have made a bid
|
// don't forget to remember that we have made a bid
|
||||||
_entity->rememberHasSimulationOwnershipBid();
|
_entity->rememberHasSimulationOwnershipBid();
|
||||||
// ...then reset _outgoingPriority in preparation for the next frame
|
// ...then reset _outgoingPriority
|
||||||
_outgoingPriority = 0;
|
_outgoingPriority = 0;
|
||||||
|
// _outgoingPrioriuty will be re-computed before next bid,
|
||||||
|
// or will be set to agree with ownership priority should we win the bid
|
||||||
} else if (_outgoingPriority != _entity->getSimulationPriority()) {
|
} else if (_outgoingPriority != _entity->getSimulationPriority()) {
|
||||||
// we own the simulation but our desired priority has changed
|
// we own the simulation but our desired priority has changed
|
||||||
if (_outgoingPriority == 0) {
|
if (_outgoingPriority == 0) {
|
||||||
|
|
Loading…
Reference in a new issue