mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 13:35:06 +02:00
use a flag to indicate that simulation ownership should be grabbed
This commit is contained in:
parent
88f289f3c1
commit
08d300afcd
5 changed files with 21 additions and 7 deletions
|
@ -76,6 +76,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
|
|||
_changedOnServer = 0;
|
||||
_element = NULL;
|
||||
_simulatorIDChangedTime = 0;
|
||||
_shouldClaimSimulationOwnership = false;
|
||||
initFromEntityItemID(entityItemID);
|
||||
}
|
||||
|
||||
|
|
|
@ -259,6 +259,8 @@ public:
|
|||
QUuid getSimulatorID() const { return _simulatorID; }
|
||||
void setSimulatorID(const QUuid& value);
|
||||
quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; }
|
||||
void setShouldClaimSimulationOwnership(bool value) { _shouldClaimSimulationOwnership = value; }
|
||||
bool getShouldClaimSimulationOwnership() { return _shouldClaimSimulationOwnership; }
|
||||
|
||||
const QString& getMarketplaceID() const { return _marketplaceID; }
|
||||
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
|
||||
|
@ -355,6 +357,7 @@ protected:
|
|||
QString _userData;
|
||||
QUuid _simulatorID; // id of Node which is currently responsible for simulating this Entity
|
||||
quint64 _simulatorIDChangedTime; // when was _simulatorID last updated?
|
||||
bool _shouldClaimSimulationOwnership;
|
||||
QString _marketplaceID;
|
||||
|
||||
// NOTE: Damping is applied like this: v *= pow(1 - damping, dt)
|
||||
|
|
|
@ -147,6 +147,8 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
|
|||
properties.setPositionChanged(false);
|
||||
properties.setVelocityChanged(false);
|
||||
properties.setAccelerationChanged(false);
|
||||
} else {
|
||||
qCDebug(entities) << "allowing simulatorID change";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -191,6 +191,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (_entity->getShouldClaimSimulationOwnership()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
const QUuid& myNodeID = nodeList->getSessionUUID();
|
||||
const QUuid& simulatorID = _entity->getSimulatorID();
|
||||
|
@ -262,7 +266,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
|||
QUuid myNodeID = nodeList->getSessionUUID();
|
||||
QUuid simulatorID = _entity->getSimulatorID();
|
||||
|
||||
if (simulatorID.isNull() && !(zeroSpeed && zeroSpin)) {
|
||||
if (_entity->getShouldClaimSimulationOwnership()) {
|
||||
_entity->setSimulatorID(myNodeID);
|
||||
properties.setSimulatorID(myNodeID);
|
||||
_entity->setShouldClaimSimulationOwnership(false);
|
||||
}
|
||||
else if (simulatorID.isNull() && !(zeroSpeed && zeroSpin)) {
|
||||
// The object is moving and nobody thinks they own the motion. set this Node as the simulator
|
||||
_entity->setSimulatorID(myNodeID);
|
||||
properties.setSimulatorID(myNodeID);
|
||||
|
|
|
@ -397,20 +397,19 @@ void PhysicsEngine::computeCollisionEvents() {
|
|||
_contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset);
|
||||
|
||||
// if our character capsule is colliding with something dynamic, claim simulation ownership.
|
||||
// do this by setting the entity's simulator-id to NULL, thereby causing EntityMotionState::sendUpdate
|
||||
// to set ownership to us.
|
||||
// see EntityMotionState::sendUpdate
|
||||
if (objectA == characterCollisionObject && !objectB->isStaticOrKinematicObject() && b) {
|
||||
EntityItem* entityB = static_cast<EntityMotionState*>(b)->getEntity();
|
||||
if (!entityB->getSimulatorID().isNull() && entityB->getSimulatorID() != myNodeID) {
|
||||
if (entityB->getSimulatorID() != myNodeID && !entityB->getShouldClaimSimulationOwnership()) {
|
||||
qDebug() << "CLAIMING B";
|
||||
entityB->setSimulatorID(NULL);
|
||||
entityB->setShouldClaimSimulationOwnership(true);
|
||||
}
|
||||
}
|
||||
if (objectB == characterCollisionObject && !objectA->isStaticOrKinematicObject() && a) {
|
||||
EntityItem* entityA = static_cast<EntityMotionState*>(a)->getEntity();
|
||||
if (!entityA->getSimulatorID().isNull() && entityA->getSimulatorID() != myNodeID) {
|
||||
if (entityA->getSimulatorID() != myNodeID && !entityA->getShouldClaimSimulationOwnership()) {
|
||||
qDebug() << "CLAIMING A";
|
||||
entityA->setSimulatorID(NULL);
|
||||
entityA->setShouldClaimSimulationOwnership(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue