don't update _simulatorIDChangedTime unless the value is different than the current one. if a script changes an entity, attempt to claim ownership

This commit is contained in:
Seth Alves 2015-04-16 12:03:34 -07:00
parent df37b853f7
commit b30b9a0a30
4 changed files with 20 additions and 8 deletions

View file

@ -1196,3 +1196,10 @@ void EntityItem::updateLifetime(float value) {
_dirtyFlags |= EntityItem::DIRTY_LIFETIME;
}
}
void EntityItem::setSimulatorID(const QString& value) {
if (_simulatorID != value) {
_simulatorID = value;
_simulatorIDChangedTime = usecTimestampNow();
}
}

View file

@ -256,7 +256,7 @@ public:
void setUserData(const QString& value) { _userData = value; }
QString getSimulatorID() const { return _simulatorID; }
void setSimulatorID(const QString& id) { _simulatorID = id; _simulatorIDChangedTime = usecTimestampNow(); }
void setSimulatorID(const QString& value);
quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; }
const QString& getMarketplaceID() const { return _marketplaceID; }

View file

@ -66,13 +66,10 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro
uint32_t creatorTokenID = EntityItemID::getNextCreatorTokenID();
// This Node is creating a new object. If it's in motion, set this Node as the simulator.
auto nodeList = DependencyManager::get<NodeList>();
const QString myNodeID = nodeList->getSessionUUID().toString();
EntityItemProperties propertiesWithSimID = properties;
// if this object is moving, set this Node as the simulation owner
if (properties.velocityChanged() || properties.rotationChanged()) {
auto nodeList = DependencyManager::get<NodeList>();
const QString myNodeID = nodeList->getSessionUUID().toString();
propertiesWithSimID.setSimulatorID(myNodeID);
}
@ -148,12 +145,20 @@ EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const E
entityID.isKnownID = true;
}
}
// If this node is changing a physics-related property, claim simulation ownership
EntityItemProperties propertiesWithSimID = properties;
if (properties.velocityChanged() || properties.rotationChanged()) {
auto nodeList = DependencyManager::get<NodeList>();
const QString myNodeID = nodeList->getSessionUUID().toString();
propertiesWithSimID.setSimulatorID(myNodeID);
}
// If we have a local entity tree set, then also update it. We can do this even if we don't know
// the actual id, because we can edit out local entities just with creatorTokenID
if (_entityTree) {
_entityTree->lockForWrite();
_entityTree->updateEntity(entityID, properties, canAdjustLocks());
_entityTree->updateEntity(entityID, propertiesWithSimID, canAdjustLocks());
_entityTree->unlock();
}

View file

@ -136,7 +136,7 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
// A Node is trying to take ownership of the simulation of this entity from another Node. Only allow this
// if ownership hasn't recently changed.
quint64 now = usecTimestampNow();
if (now - entity->getSimulatorIDChangedTime() < 0.1 * USECS_PER_SECOND) { // XXX pick time and put in constant
if (now - entity->getSimulatorIDChangedTime() < 2 * USECS_PER_SECOND) { // XXX pick time and put in constant
qDebug() << "TOO SOON";
}
}