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
290 290
291 entity->setLastBroadcast(usecTimestampNow());291 entity->setLastBroadcast(usecTimestampNow());
292 // since we're creating this object we will immediately volunteer to own its simulation292 // 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);
294 properties.setLastEdited(entity->getLastEdited());294 properties.setLastEdited(entity->getLastEdited());
295 } else {295 } else {
296 qCDebug(entities) << "script failed to add new Entity to local Octree";296 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
569 // TODO: figure out how to change simulation ownership priority569 // TODO: figure out how to change simulation ownership priority
570 //}570 //}
571 } else {571 } else {
572 // we don't own the simulation572 // 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
573 uint8_t desiredPriority = entity->getScriptSimulationPriority();577 uint8_t desiredPriority = entity->getScriptSimulationPriority();
574 if (desiredPriority < simulationOwner.getPriority()) {578 if (desiredPriority < simulationOwner.getPriority()) {
575 // we don't desire to own it --> clear restricted properties579 // the priority at which we'd like to own it is not high enough
580 // --> assume failure and clear all restricted property changes
576 properties.clearSimulationRestrictedProperties();581 properties.clearSimulationRestrictedProperties();
577 } else {582 } else {
578 // we want to own it --> copy ALL restricted properties583 // the priority at which we'd like to own it is high enough to win.
584 // --> assume success and copy ALL restricted properties
579 properties.copySimulationRestrictedProperties(entity);585 properties.copySimulationRestrictedProperties(entity);
580 // and also store our simulation
581 properties.setSimulationOwner(sessionID, desiredPriority);
582 }586 }
583 }587 }
584 } else if (!simulationOwner.getID().isNull()) {588 } else if (!simulationOwner.getID().isNull()) {
@@ -587,7 +591,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 2 unmodified lines
587 properties.clearSimulationRestrictedProperties();591 properties.clearSimulationRestrictedProperties();
588 }592 }
589 // clear the cached simulationPriority level593 // clear the cached simulationPriority level
590 entity->setScriptSimulationPriority(0);594 entity->upgradeScriptSimulationPriority(0);
591 }595 }
592 596
593 // set these to make EntityItemProperties::getScalesWithParent() work correctly597 // set these to make EntityItemProperties::getScalesWithParent() work correctly
@@ -1452,7 +1456,7 @@ QUuid EntityScriptingInterface::addAction(const QString& actionTypeString, · 858 unmodified lines
1452 }1456 }
1453 action->setIsMine(true);1457 action->setIsMine(true);
1454 success = entity->addAction(simulation, action);1458 success = entity->addAction(simulation, action);
1455 entity->setScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);1459 entity->upgradeScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
1456 return false; // Physics will cause a packet to be sent, so don't send from here.1460 return false; // Physics will cause a packet to be sent, so don't send from here.
1457 });1461 });
1458 if (success) {1462 if (success) {
@@ -1468,7 +1472,7 @@ bool EntityScriptingInterface::updateAction(const QUuid& entityID, const QUuid& · 9 unmodified lines
1468 return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {1472 return actionWorker(entityID, [&](EntitySimulationPointer simulation, EntityItemPointer entity) {
1469 bool success = entity->updateAction(simulation, actionID, arguments);1473 bool success = entity->updateAction(simulation, actionID, arguments);
1470 if (success) {1474 if (success) {
1471 entity->setScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);1475 entity->upgradeScriptSimulationPriority(SCRIPT_GRAB_SIMULATION_PRIORITY);
1472 }1476 }
1473 return success;1477 return success;
1474 });1478 });
@@ -1482,7 +1486,7 @@ bool EntityScriptingInterface::deleteAction(const QUuid& entityID, const QUuid& · 7 unmodified lines
1482 success = entity->removeAction(simulation, actionID);1486 success = entity->removeAction(simulation, actionID);
1483 if (success) {1487 if (success) {
1484 // reduce from grab to poke1488 // reduce from grab to poke
1485 entity->setScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);1489 entity->upgradeScriptSimulationPriority(SCRIPT_POKE_SIMULATION_PRIORITY);
1486 }1490 }
1487 return false; // Physics will cause a packet to be sent, so don't send from here.1491 return false; // Physics will cause a packet to be sent, so don't send from here.
1488 });1492 });