adjust simulation bid priority by props changed

This commit is contained in:
Andrew Meadows 2018-10-08 11:19:37 -07:00
parent 9bfa4a5267
commit 6558d539e4
3 changed files with 18 additions and 3 deletions

View file

@ -3326,6 +3326,20 @@ void EntityItemProperties::setSimulationOwner(const QByteArray& data) {
}
}
uint8_t EntityItemProperties::computeSimulationBidPriority() const {
uint8_t priority = 0;
if (_parentIDChanged || _parentJointIndexChanged) {
// we need higher simulation ownership priority to chang parenting info
priority = SCRIPT_GRAB_SIMULATION_PRIORITY;
} else if ( _positionChanged || _localPositionChanged
|| _rotationChanged || _localRotationChanged
|| _velocityChanged || _localVelocityChanged
|| _angularVelocityChanged || _localAngularVelocityChanged) {
priority = SCRIPT_POKE_SIMULATION_PRIORITY;
}
return priority;
}
QList<QString> EntityItemProperties::listChangedProperties() {
QList<QString> out;
if (containsPositionChange()) {

View file

@ -360,6 +360,7 @@ public:
void setSimulationOwner(const QUuid& id, uint8_t priority);
void setSimulationOwner(const QByteArray& data);
void setSimulationPriority(uint8_t priority) { _simulationOwner.setPriority(priority); }
uint8_t computeSimulationBidPriority() const;
void setActionDataDirty() { _actionDataChanged = true; }

View file

@ -562,14 +562,14 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
if (entity) {
if (properties.hasSimulationRestrictedChanges()) {
if (_bidOnSimulationOwnership) {
// flag for simulation ownership, or upgrade existing ownership priority
// (actual bids for simulation ownership are sent by the PhysicalEntitySimulation)
entity->upgradeScriptSimulationPriority(properties.computeSimulationBidPriority());
if (simulationOwner.getID() == sessionID) {
// we own the simulation --> copy ALL restricted properties
properties.copySimulationRestrictedProperties(entity);
} else {
// we don't own the simulation but think we would like to
// --> flag the object for simulation ownership at at least POKE
// (the bid for simulation ownership (if any) will be sent by the physics simulation)
entity->upgradeScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);
uint8_t desiredPriority = entity->getScriptSimulationPriority();
if (desiredPriority < simulationOwner.getPriority()) {