History

set script-triggerd sim ownership priority correctly

Andrew Meadows committed 8 years ago

Commit 1a685d21 parent ce81ab14 files · +24 −15Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 4 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+14−10
@@ -290,7 +290,7 @@ bool EntityScriptingInterface::addLocalEntityCopy(EntityItemProperties& properti · 289 unmodified lines
290290
291291 entity->setLastBroadcast(usecTimestampNow());
292292 // since we're creating this object we will immediately volunteer to own its simulation
293− entity->setScriptSimulationPriority(VOLUNTEER_SIMULATION_PRIORITY);
293+ entity->upgradeScriptSimulationPriority(VOLUNTEER_SIMULATION_PRIORITY);
294294 properties.setLastEdited(entity->getLastEdited());
295295 } else {
296296 qCDebug(entities) << "script failed to add new Entity to local Octree";
@@ -569,16 +569,20 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 272 unmodified lines
569569 // TODO: figure out how to change simulation ownership priority
570570 //}
571571 } else {
572− // we don't own the simulation
572+ // we don't own the simulation but think we would like to
573+ // --> flag the object for simulation ownership at at least POKE
574+ // (the bid for simulation ownership (if any) will be sent by the physics simulation)
575+ entity->upgradeScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);
576+
573577 uint8_t desiredPriority = entity->getScriptSimulationPriority();
574578 if (desiredPriority < simulationOwner.getPriority()) {
575− // we don't desire to own it --> clear restricted properties
579+ // the priority at which we'd like to own it is not high enough
580+ // --> assume failure and clear all restricted property changes
576581 properties.clearSimulationRestrictedProperties();
577582 } else {
578− // we want to own it --> copy ALL restricted properties
583+ // the priority at which we'd like to own it is high enough to win.
584+ // --> assume success and copy ALL restricted properties
579585 properties.copySimulationRestrictedProperties(entity);
580− // and also store our simulation
581− properties.setSimulationOwner(sessionID, desiredPriority);
582586 }
583587 }
584588 } else if (!simulationOwner.getID().isNull()) {
@@ -587,7 +591,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 2 unmodified lines
587591 properties.clearSimulationRestrictedProperties();
588592 }
589593 // clear the cached simulationPriority level
590− entity->setScriptSimulationPriority(0);
594+ entity->upgradeScriptSimulationPriority(0);
591595 }
592596
593597 // set these to make EntityItemProperties::getScalesWithParent() work correctly
@@ -1452,7 +1456,7 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, · 858 unmodified lines
14521456 }
14531457 action->setIsMine(true);
14541458 success = entity->addAction(simulation, action);
1455− entity->setScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
1459+ entity->upgradeScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
14561460 return false; // Physics will cause a packet to be sent, so don't send from here.
14571461 });
14581462 if (success) {
@@ -1468,7 +1472,7 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& · 9 unmodified lines
14681472 return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
14691473 bool success = entity->updateAction(simulation, actionID, arguments);
14701474 if (success) {
1471− entity->setScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
1475+ entity->upgradeScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
14721476 }
14731477 return success;
14741478 });
@@ -1482,7 +1486,7 @@ bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& · 7 unmodified lines
14821486 success = entity->removeAction(simulation, actionID);
14831487 if (success) {
14841488 // reduce from grab to poke
1485− entity->setScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);
1489+ entity->upgradeScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);
14861490 }
14871491 return false; // Physics will cause a packet to be sent, so don't send from here.
14881492 });