mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
Merge pull request #9561 from thoys/entity-simulation-owner-fixes
Fix simulation owned entities not to go to origin after cache reload (+ small priority fix)
This commit is contained in:
commit
42098edbeb
4 changed files with 32 additions and 13 deletions
|
@ -688,6 +688,13 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
_simulationOwner.clearCurrentOwner();
|
_simulationOwner.clearCurrentOwner();
|
||||||
}
|
}
|
||||||
|
} else if (newSimOwner.matchesValidID(myNodeID) && !_hasBidOnSimulation) {
|
||||||
|
// entity-server tells us that we have simulation ownership while we never requested this for this EntityItem,
|
||||||
|
// this could happen when the user reloads the cache and entity tree.
|
||||||
|
_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
|
||||||
|
somethingChanged = true;
|
||||||
|
_simulationOwner.clearCurrentOwner();
|
||||||
|
weOwnSimulation = false;
|
||||||
} else if (_simulationOwner.set(newSimOwner)) {
|
} else if (_simulationOwner.set(newSimOwner)) {
|
||||||
_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
|
_dirtyFlags |= Simulation::DIRTY_SIMULATOR_ID;
|
||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
|
@ -1278,7 +1285,7 @@ void EntityItem::grabSimulationOwnership() {
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
if (_simulationOwner.matchesValidID(nodeList->getSessionUUID())) {
|
if (_simulationOwner.matchesValidID(nodeList->getSessionUUID())) {
|
||||||
// we already own it
|
// we already own it
|
||||||
_simulationOwner.promotePriority(SCRIPT_POKE_SIMULATION_PRIORITY);
|
_simulationOwner.promotePriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
|
||||||
} else {
|
} else {
|
||||||
// we don't own it yet
|
// we don't own it yet
|
||||||
_simulationOwner.setPendingPriority(SCRIPT_GRAB_SIMULATION_PRIORITY, usecTimestampNow());
|
_simulationOwner.setPendingPriority(SCRIPT_GRAB_SIMULATION_PRIORITY, usecTimestampNow());
|
||||||
|
@ -1889,6 +1896,10 @@ void EntityItem::setPendingOwnershipPriority(quint8 priority, const quint64& tim
|
||||||
_simulationOwner.setPendingPriority(priority, timestamp);
|
_simulationOwner.setPendingPriority(priority, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityItem::rememberHasSimulationOwnershipBid() const {
|
||||||
|
_hasBidOnSimulation = true;
|
||||||
|
}
|
||||||
|
|
||||||
QString EntityItem::actionsToDebugString() {
|
QString EntityItem::actionsToDebugString() {
|
||||||
QString result;
|
QString result;
|
||||||
QVector<QByteArray> serializedActions;
|
QVector<QByteArray> serializedActions;
|
||||||
|
|
|
@ -321,6 +321,7 @@ public:
|
||||||
void updateSimulationOwner(const SimulationOwner& owner);
|
void updateSimulationOwner(const SimulationOwner& owner);
|
||||||
void clearSimulationOwnership();
|
void clearSimulationOwnership();
|
||||||
void setPendingOwnershipPriority(quint8 priority, const quint64& timestamp);
|
void setPendingOwnershipPriority(quint8 priority, const quint64& timestamp);
|
||||||
|
void rememberHasSimulationOwnershipBid() const;
|
||||||
|
|
||||||
const QString& getMarketplaceID() const { return _marketplaceID; }
|
const QString& getMarketplaceID() const { return _marketplaceID; }
|
||||||
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
|
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
|
||||||
|
@ -497,16 +498,16 @@ protected:
|
||||||
mutable AABox _cachedAABox;
|
mutable AABox _cachedAABox;
|
||||||
mutable AACube _maxAACube;
|
mutable AACube _maxAACube;
|
||||||
mutable AACube _minAACube;
|
mutable AACube _minAACube;
|
||||||
mutable bool _recalcAABox = true;
|
mutable bool _recalcAABox { true };
|
||||||
mutable bool _recalcMinAACube = true;
|
mutable bool _recalcMinAACube { true };
|
||||||
mutable bool _recalcMaxAACube = true;
|
mutable bool _recalcMaxAACube { true };
|
||||||
|
|
||||||
float _localRenderAlpha;
|
float _localRenderAlpha;
|
||||||
float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3
|
float _density { ENTITY_ITEM_DEFAULT_DENSITY }; // kg/m^3
|
||||||
// NOTE: _volumeMultiplier is used to allow some mass properties code exist in the EntityItem base class
|
// NOTE: _volumeMultiplier is used to allow some mass properties code exist in the EntityItem base class
|
||||||
// rather than in all of the derived classes. If we ever collapse these classes to one we could do it a
|
// rather than in all of the derived classes. If we ever collapse these classes to one we could do it a
|
||||||
// different way.
|
// different way.
|
||||||
float _volumeMultiplier = 1.0f;
|
float _volumeMultiplier { 1.0f };
|
||||||
glm::vec3 _gravity;
|
glm::vec3 _gravity;
|
||||||
glm::vec3 _acceleration;
|
glm::vec3 _acceleration;
|
||||||
float _damping;
|
float _damping;
|
||||||
|
@ -562,8 +563,8 @@ protected:
|
||||||
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
uint32_t _dirtyFlags; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
|
||||||
|
|
||||||
// these backpointers are only ever set/cleared by friends:
|
// these backpointers are only ever set/cleared by friends:
|
||||||
EntityTreeElementPointer _element = nullptr; // set by EntityTreeElement
|
EntityTreeElementPointer _element { nullptr }; // set by EntityTreeElement
|
||||||
void* _physicsInfo = nullptr; // set by EntitySimulation
|
void* _physicsInfo { nullptr }; // set by EntitySimulation
|
||||||
bool _simulated; // set by EntitySimulation
|
bool _simulated; // set by EntitySimulation
|
||||||
|
|
||||||
bool addActionInternal(EntitySimulationPointer simulation, EntityActionPointer action);
|
bool addActionInternal(EntitySimulationPointer simulation, EntityActionPointer action);
|
||||||
|
@ -580,12 +581,15 @@ protected:
|
||||||
// are used to keep track of and work around this situation.
|
// are used to keep track of and work around this situation.
|
||||||
void checkWaitingToRemove(EntitySimulationPointer simulation = nullptr);
|
void checkWaitingToRemove(EntitySimulationPointer simulation = nullptr);
|
||||||
mutable QSet<QUuid> _actionsToRemove;
|
mutable QSet<QUuid> _actionsToRemove;
|
||||||
mutable bool _actionDataDirty = false;
|
mutable bool _actionDataDirty { false };
|
||||||
mutable bool _actionDataNeedsTransmit = false;
|
mutable bool _actionDataNeedsTransmit { false };
|
||||||
// _previouslyDeletedActions is used to avoid an action being re-added due to server round-trip lag
|
// _previouslyDeletedActions is used to avoid an action being re-added due to server round-trip lag
|
||||||
static quint64 _rememberDeletedActionTime;
|
static quint64 _rememberDeletedActionTime;
|
||||||
mutable QHash<QUuid, quint64> _previouslyDeletedActions;
|
mutable QHash<QUuid, quint64> _previouslyDeletedActions;
|
||||||
|
|
||||||
|
// per entity keep state if it ever bid on simulation, so that we can ignore false simulation ownership
|
||||||
|
mutable bool _hasBidOnSimulation { false };
|
||||||
|
|
||||||
QUuid _sourceUUID; /// the server node UUID we came from
|
QUuid _sourceUUID; /// the server node UUID we came from
|
||||||
|
|
||||||
bool _clientOnly { false };
|
bool _clientOnly { false };
|
||||||
|
|
|
@ -231,6 +231,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
// and make note of it now, so we can act on it right away.
|
// and make note of it now, so we can act on it right away.
|
||||||
propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
||||||
entity->setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
entity->setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
||||||
|
entity->rememberHasSimulationOwnershipBid();
|
||||||
}
|
}
|
||||||
|
|
||||||
entity->setLastBroadcast(usecTimestampNow());
|
entity->setLastBroadcast(usecTimestampNow());
|
||||||
|
@ -444,6 +445,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
// we make a bid for simulation ownership
|
// we make a bid for simulation ownership
|
||||||
properties.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
properties.setSimulationOwner(myNodeID, SCRIPT_POKE_SIMULATION_PRIORITY);
|
||||||
entity->pokeSimulationOwnership();
|
entity->pokeSimulationOwnership();
|
||||||
|
entity->rememberHasSimulationOwnershipBid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) {
|
if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) {
|
||||||
|
|
|
@ -582,6 +582,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
|
||||||
_nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS;
|
_nextOwnershipBid = now + USECS_BETWEEN_OWNERSHIP_BIDS;
|
||||||
// copy _outgoingPriority into pendingPriority...
|
// copy _outgoingPriority into pendingPriority...
|
||||||
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
_entity->setPendingOwnershipPriority(_outgoingPriority, now);
|
||||||
|
// don't forget to remember that we have made a bid
|
||||||
|
_entity->rememberHasSimulationOwnershipBid();
|
||||||
// ...then reset _outgoingPriority in preparation for the next frame
|
// ...then reset _outgoingPriority in preparation for the next frame
|
||||||
_outgoingPriority = 0;
|
_outgoingPriority = 0;
|
||||||
} else if (_outgoingPriority != _entity->getSimulationPriority()) {
|
} else if (_outgoingPriority != _entity->getSimulationPriority()) {
|
||||||
|
|
Loading…
Reference in a new issue