setup test of lockout-period oafter simulator-owner-id change

This commit is contained in:
Seth Alves 2015-04-16 08:57:57 -07:00
parent 6c4d232ad9
commit df37b853f7
3 changed files with 16 additions and 1 deletions

View file

@ -75,6 +75,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) {
_dirtyFlags = 0;
_changedOnServer = 0;
_element = NULL;
_simulatorIDChangedTime = 0;
initFromEntityItemID(entityItemID);
}
@ -90,6 +91,7 @@ EntityItem::EntityItem(const EntityItemID& entityItemID, const EntityItemPropert
_dirtyFlags = 0;
_changedOnServer = 0;
_element = NULL;
_simulatorIDChangedTime = 0;
initFromEntityItemID(entityItemID);
setProperties(properties);
}

View file

@ -256,7 +256,8 @@ public:
void setUserData(const QString& value) { _userData = value; }
QString getSimulatorID() const { return _simulatorID; }
void setSimulatorID(const QString& id) { _simulatorID = id; }
void setSimulatorID(const QString& id) { _simulatorID = id; _simulatorIDChangedTime = usecTimestampNow(); }
quint64 getSimulatorIDChangedTime() const { return _simulatorIDChangedTime; }
const QString& getMarketplaceID() const { return _marketplaceID; }
void setMarketplaceID(const QString& value) { _marketplaceID = value; }
@ -352,6 +353,7 @@ protected:
bool _locked;
QString _userData;
QString _simulatorID; // id of Node which is currently responsible for simulating this Entity
quint64 _simulatorIDChangedTime; // when was _simulatorID last updated?
QString _marketplaceID;
// NOTE: Damping is applied like this: v *= pow(1 - damping, dt)

View file

@ -130,6 +130,17 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro
}
}
} else {
if (properties.simulatorIDChanged() &&
!entity->getSimulatorID().isEmpty() &&
properties.getSimulatorID() != entity->getSimulatorID()) {
// 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
qDebug() << "TOO SOON";
}
}
QString entityScriptBefore = entity->getScript();
uint32_t preFlags = entity->getDirtyFlags();
UpdateEntityOperator theOperator(this, containingElement, entity, properties);