mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:01:09 +02:00
remove unowned 'dynamic' objects from kinematic integration
This commit is contained in:
parent
a689c5829a
commit
3d16c9014f
1 changed files with 65 additions and 32 deletions
|
@ -53,20 +53,29 @@ void SimpleEntitySimulation::updateEntitiesInternal(uint64_t now) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleEntitySimulation::addEntityInternal(EntityItemPointer entity) {
|
void SimpleEntitySimulation::addEntityInternal(EntityItemPointer entity) {
|
||||||
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
if (entity->getSimulatorID().isNull()) {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
_simpleKinematicEntities.insert(entity);
|
if (entity->getDynamic()) {
|
||||||
entity->setLastSimulated(usecTimestampNow());
|
// we don't allow dynamic objects to move without an owner so nothing to do here
|
||||||
}
|
} else if (entity->isMovingRelativeToParent()) {
|
||||||
if (!entity->getSimulatorID().isNull()) {
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
_entitiesWithSimulationOwner.insert(entity);
|
_entitiesWithSimulationOwner.insert(entity);
|
||||||
_nextStaleOwnershipExpiry = glm::min(_nextStaleOwnershipExpiry, entity->getSimulationOwnershipExpiry());
|
_nextStaleOwnershipExpiry = glm::min(_nextStaleOwnershipExpiry, entity->getSimulationOwnershipExpiry());
|
||||||
} else if (entity->getDynamic() && entity->hasLocalVelocity()) {
|
|
||||||
QMutexLocker lock(&_mutex);
|
if (entity->isMovingRelativeToParent()) {
|
||||||
_entitiesThatNeedSimulationOwner.insert(entity);
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
uint64_t expiry = entity->getLastChangedOnServer() + MAX_OWNERLESS_PERIOD;
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
_nextOwnerlessExpiry = glm::min(_nextOwnerlessExpiry, expiry);
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,32 +86,50 @@ void SimpleEntitySimulation::removeEntityInternal(EntityItemPointer entity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
void SimpleEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
||||||
{
|
uint32_t flags = entity->getDirtyFlags();
|
||||||
QMutexLocker lock(&_mutex);
|
if ((flags & Simulation::DIRTY_SIMULATOR_ID) || (flags & Simulation::DIRTY_VELOCITIES)) {
|
||||||
if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) {
|
if (entity->getSimulatorID().isNull()) {
|
||||||
int numKinematicEntities = _simpleKinematicEntities.size();
|
QMutexLocker lock(&_mutex);
|
||||||
_simpleKinematicEntities.insert(entity);
|
_entitiesWithSimulationOwner.remove(entity);
|
||||||
if (numKinematicEntities != _simpleKinematicEntities.size()) {
|
|
||||||
entity->setLastSimulated(usecTimestampNow());
|
if (entity->getDynamic()) {
|
||||||
|
// we don't allow dynamic objects to move without an owner
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.erase(itr);
|
||||||
|
}
|
||||||
|
} else if (entity->isMovingRelativeToParent()) {
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.erase(itr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_simpleKinematicEntities.remove(entity);
|
QMutexLocker lock(&_mutex);
|
||||||
|
_entitiesWithSimulationOwner.insert(entity);
|
||||||
|
_nextStaleOwnershipExpiry = glm::min(_nextStaleOwnershipExpiry, entity->getSimulationOwnershipExpiry());
|
||||||
|
_entitiesThatNeedSimulationOwner.remove(entity);
|
||||||
|
|
||||||
|
if (entity->isMovingRelativeToParent()) {
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.insert(entity);
|
||||||
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity->getSimulatorID().isNull()) {
|
|
||||||
QMutexLocker lock(&_mutex);
|
|
||||||
_entitiesWithSimulationOwner.remove(entity);
|
|
||||||
if (entity->getDynamic() && entity->hasLocalVelocity()) {
|
|
||||||
_entitiesThatNeedSimulationOwner.insert(entity);
|
|
||||||
uint64_t expiry = entity->getLastChangedOnServer() + MAX_OWNERLESS_PERIOD;
|
|
||||||
_nextOwnerlessExpiry = glm::min(_nextOwnerlessExpiry, expiry);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QMutexLocker lock(&_mutex);
|
|
||||||
_entitiesWithSimulationOwner.insert(entity);
|
|
||||||
_nextStaleOwnershipExpiry = glm::min(_nextStaleOwnershipExpiry, entity->getSimulationOwnershipExpiry());
|
|
||||||
_entitiesThatNeedSimulationOwner.remove(entity);
|
|
||||||
}
|
|
||||||
entity->clearDirtyFlags();
|
entity->clearDirtyFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +158,12 @@ void SimpleEntitySimulation::expireStaleOwnerships(uint64_t now) {
|
||||||
uint64_t expiry = entity->getSimulationOwnershipExpiry();
|
uint64_t expiry = entity->getSimulationOwnershipExpiry();
|
||||||
if (now > expiry) {
|
if (now > expiry) {
|
||||||
itemItr = _entitiesWithSimulationOwner.erase(itemItr);
|
itemItr = _entitiesWithSimulationOwner.erase(itemItr);
|
||||||
|
if (entity->getDynamic()) {
|
||||||
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
|
if (itr != _simpleKinematicEntities.end()) {
|
||||||
|
_simpleKinematicEntities.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// remove ownership and dirty all the tree elements that contain the it
|
// remove ownership and dirty all the tree elements that contain the it
|
||||||
entity->clearSimulationOwnership();
|
entity->clearSimulationOwnership();
|
||||||
|
|
Loading…
Reference in a new issue