mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:28:09 +02:00
add EntityMotionState::isLocallyOwned() for cleaner logic
This commit is contained in:
parent
c56a6c44f8
commit
e34f979ed9
3 changed files with 11 additions and 5 deletions
|
@ -84,7 +84,7 @@ EntityMotionState::~EntityMotionState() {
|
||||||
|
|
||||||
void EntityMotionState::updateServerPhysicsVariables() {
|
void EntityMotionState::updateServerPhysicsVariables() {
|
||||||
assert(entityTreeIsLocked());
|
assert(entityTreeIsLocked());
|
||||||
if (_entity->getSimulatorID() == Physics::getSessionUUID()) {
|
if (isLocallyOwned()) {
|
||||||
// don't slam these values if we are the simulation owner
|
// don't slam these values if we are the simulation owner
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
|
_nextOwnershipBid = usecTimestampNow() + USECS_BETWEEN_OWNERSHIP_BIDS;
|
||||||
}
|
}
|
||||||
_loopsWithoutOwner = 0;
|
_loopsWithoutOwner = 0;
|
||||||
} else if (_entity->getSimulatorID() == Physics::getSessionUUID()) {
|
} else if (isLocallyOwned()) {
|
||||||
// we just inherited ownership, make sure our desired priority matches what we have
|
// we just inherited ownership, make sure our desired priority matches what we have
|
||||||
upgradeOutgoingPriority(_entity->getSimulationPriority());
|
upgradeOutgoingPriority(_entity->getSimulationPriority());
|
||||||
} else {
|
} else {
|
||||||
|
@ -315,7 +315,7 @@ bool EntityMotionState::isCandidateForOwnership() const {
|
||||||
assert(_entity);
|
assert(_entity);
|
||||||
assert(entityTreeIsLocked());
|
assert(entityTreeIsLocked());
|
||||||
return _outgoingPriority != 0
|
return _outgoingPriority != 0
|
||||||
|| Physics::getSessionUUID() == _entity->getSimulatorID()
|
|| isLocallyOwned()
|
||||||
|| _entity->dynamicDataNeedsTransmit();
|
|| _entity->dynamicDataNeedsTransmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_entity->getSimulatorID() != Physics::getSessionUUID()) {
|
if (!isLocallyOwned()) {
|
||||||
// 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
|
||||||
|
@ -597,7 +597,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
properties.clearSimulationOwner();
|
properties.clearSimulationOwner();
|
||||||
_outgoingPriority = 0;
|
_outgoingPriority = 0;
|
||||||
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
||||||
} else if (Physics::getSessionUUID() != _entity->getSimulatorID()) {
|
} else if (!isLocallyOwned()) {
|
||||||
// we don't own the simulation for this entity yet, but we're sending a bid for it
|
// we don't own the simulation for this entity yet, but we're sending a bid for it
|
||||||
quint8 bidPriority = glm::max<uint8_t>(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY);
|
quint8 bidPriority = glm::max<uint8_t>(_outgoingPriority, VOLUNTEER_SIMULATION_PRIORITY);
|
||||||
properties.setSimulationOwner(Physics::getSessionUUID(), bidPriority);
|
properties.setSimulationOwner(Physics::getSessionUUID(), bidPriority);
|
||||||
|
@ -786,6 +786,10 @@ void EntityMotionState::computeCollisionGroupAndMask(int16_t& group, int16_t& ma
|
||||||
_entity->computeCollisionGroupAndFinalMask(group, mask);
|
_entity->computeCollisionGroupAndFinalMask(group, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EntityMotionState::isLocallyOwned() const {
|
||||||
|
return _entity->getSimulatorID() == Physics::getSessionUUID();
|
||||||
|
}
|
||||||
|
|
||||||
bool EntityMotionState::shouldBeLocallyOwned() const {
|
bool EntityMotionState::shouldBeLocallyOwned() const {
|
||||||
return (_outgoingPriority > VOLUNTEER_SIMULATION_PRIORITY && _outgoingPriority > _entity->getSimulationPriority()) ||
|
return (_outgoingPriority > VOLUNTEER_SIMULATION_PRIORITY && _outgoingPriority > _entity->getSimulationPriority()) ||
|
||||||
_entity->getSimulatorID() == Physics::getSessionUUID();
|
_entity->getSimulatorID() == Physics::getSessionUUID();
|
||||||
|
|
|
@ -79,6 +79,7 @@ public:
|
||||||
|
|
||||||
virtual void computeCollisionGroupAndMask(int16_t& group, int16_t& mask) const override;
|
virtual void computeCollisionGroupAndMask(int16_t& group, int16_t& mask) const override;
|
||||||
|
|
||||||
|
bool isLocallyOwned() const override;
|
||||||
bool shouldBeLocallyOwned() const override;
|
bool shouldBeLocallyOwned() const override;
|
||||||
|
|
||||||
friend class PhysicalEntitySimulation;
|
friend class PhysicalEntitySimulation;
|
||||||
|
|
|
@ -146,6 +146,7 @@ public:
|
||||||
void dirtyInternalKinematicChanges() { _hasInternalKinematicChanges = true; }
|
void dirtyInternalKinematicChanges() { _hasInternalKinematicChanges = true; }
|
||||||
void clearInternalKinematicChanges() { _hasInternalKinematicChanges = false; }
|
void clearInternalKinematicChanges() { _hasInternalKinematicChanges = false; }
|
||||||
|
|
||||||
|
virtual bool isLocallyOwned() const { return false; }
|
||||||
virtual bool shouldBeLocallyOwned() const { return false; }
|
virtual bool shouldBeLocallyOwned() const { return false; }
|
||||||
|
|
||||||
friend class PhysicsEngine;
|
friend class PhysicsEngine;
|
||||||
|
|
Loading…
Reference in a new issue