entity-server will automatically clear simulation-owner ID if it doesn't get an update for 2 seconds

This commit is contained in:
Seth Alves 2015-04-15 10:58:56 -07:00
parent 27e1eb7c7d
commit afca5440f0
3 changed files with 30 additions and 1 deletions

View file

@ -323,7 +323,7 @@ protected:
quint64 _lastEdited; // last official local or remote edit time
quint64 _lastEditedFromRemote; // last time we received and edit from the server
quint64 _lastEditedFromRemoteInRemoteTime; // last time we received and edit from the server (in server-time-frame)
quint64 _lastEditedFromRemoteInRemoteTime; // last time we received an edit from the server (in server-time-frame)
quint64 _created;
quint64 _changedOnServer;

View file

@ -13,8 +13,12 @@
#include "EntityItem.h"
#include "SimpleEntitySimulation.h"
#include "EntitiesLogging.h"
const quint64 AUTO_REMOVE_SIMULATION_OWNER_USEC = 2000000;
void SimpleEntitySimulation::updateEntitiesInternal(const quint64& now) {
// now is usecTimestampNow()
QSet<EntityItem*>::iterator itemItr = _movingEntities.begin();
while (itemItr != _movingEntities.end()) {
EntityItem* entity = *itemItr;
@ -27,6 +31,22 @@ void SimpleEntitySimulation::updateEntitiesInternal(const quint64& now) {
++itemItr;
}
}
// If an Entity has a simulation owner and we don't get an update for some amount of time,
// clear the owner. This guards against an interface failing to release the Entity when it
// has finished simulating it.
itemItr = _hasSimulationOwnerEntities.begin();
while (itemItr != _hasSimulationOwnerEntities.end()) {
EntityItem* entity = *itemItr;
if (!entity->getSimulatorID().isEmpty() &&
usecTimestampNow() - entity->getLastChangedOnServer() >= AUTO_REMOVE_SIMULATION_OWNER_USEC) {
qCDebug(entities) << "auto-removing simulation owner" << entity->getSimulatorID();
entity->setSimulatorID("");
itemItr = _hasSimulationOwnerEntities.erase(itemItr);
} else {
++itemItr;
}
}
}
void SimpleEntitySimulation::addEntityInternal(EntityItem* entity) {
@ -35,11 +55,15 @@ void SimpleEntitySimulation::addEntityInternal(EntityItem* entity) {
} else if (entity->getCollisionsWillMove()) {
_movableButStoppedEntities.insert(entity);
}
if (!entity->getSimulatorID().isEmpty()) {
_hasSimulationOwnerEntities.insert(entity);
}
}
void SimpleEntitySimulation::removeEntityInternal(EntityItem* entity) {
_movingEntities.remove(entity);
_movableButStoppedEntities.remove(entity);
_hasSimulationOwnerEntities.remove(entity);
}
const int SIMPLE_SIMULATION_DIRTY_FLAGS = EntityItem::DIRTY_VELOCITY | EntityItem::DIRTY_MOTION_TYPE;
@ -55,6 +79,9 @@ void SimpleEntitySimulation::entityChangedInternal(EntityItem* entity) {
_movingEntities.remove(entity);
_movableButStoppedEntities.remove(entity);
}
if (!entity->getSimulatorID().isEmpty()) {
_hasSimulationOwnerEntities.insert(entity);
}
}
entity->clearDirtyFlags();
}
@ -62,5 +89,6 @@ void SimpleEntitySimulation::entityChangedInternal(EntityItem* entity) {
void SimpleEntitySimulation::clearEntitiesInternal() {
_movingEntities.clear();
_movableButStoppedEntities.clear();
_hasSimulationOwnerEntities.clear();
}

View file

@ -30,6 +30,7 @@ protected:
QSet<EntityItem*> _movingEntities;
QSet<EntityItem*> _movableButStoppedEntities;
QSet<EntityItem*> _hasSimulationOwnerEntities;
};
#endif // hifi_SimpleEntitySimulation_h