mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:08:00 +02:00
more correct entity list maintenance
This commit is contained in:
parent
c5e923f091
commit
1c636fe6b2
1 changed files with 37 additions and 12 deletions
|
@ -653,7 +653,6 @@ void EntityTree::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::updateChangedEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
void EntityTree::updateChangedEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
||||||
// TODO: switch these to iterators so we can remove items that get deleted
|
|
||||||
foreach (EntityItem* thisEntity, _changedEntities) {
|
foreach (EntityItem* thisEntity, _changedEntities) {
|
||||||
// check to see if the lifetime has expired, for immortal entities this is always false
|
// check to see if the lifetime has expired, for immortal entities this is always false
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
|
@ -675,15 +674,17 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("_movingEntities");
|
PerformanceTimer perfTimer("_movingEntities");
|
||||||
|
|
||||||
// TODO: switch these to iterators so we can remove items that get deleted
|
QList<EntityItem*>::iterator item_itr = _movingEntities.begin();
|
||||||
for (int i = 0; i < _movingEntities.size(); i++) {
|
while (item_itr != _movingEntities.end()) {
|
||||||
EntityItem* thisEntity = _movingEntities[i];
|
EntityItem* thisEntity = *item_itr;
|
||||||
|
|
||||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
clearEntityState(thisEntity);
|
// remove thisEntity from the list
|
||||||
|
item_itr = _movingEntities.erase(item_itr);
|
||||||
|
thisEntity->setSimulationState(EntityItem::Static);
|
||||||
} else {
|
} else {
|
||||||
AACube oldCube = thisEntity->getMaximumAACube();
|
AACube oldCube = thisEntity->getMaximumAACube();
|
||||||
thisEntity->update(now);
|
thisEntity->update(now);
|
||||||
|
@ -694,10 +695,22 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
if (!domainBounds.touches(newCube)) {
|
if (!domainBounds.touches(newCube)) {
|
||||||
qDebug() << "Entity " << thisEntity->getEntityItemID() << " moved out of domain bounds.";
|
qDebug() << "Entity " << thisEntity->getEntityItemID() << " moved out of domain bounds.";
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
clearEntityState(thisEntity);
|
// remove thisEntity from the list
|
||||||
|
item_itr = _movingEntities.erase(item_itr);
|
||||||
|
thisEntity->setSimulationState(EntityItem::Static);
|
||||||
} else {
|
} else {
|
||||||
moveOperator.addEntityToMoveList(thisEntity, oldCube, newCube);
|
moveOperator.addEntityToMoveList(thisEntity, oldCube, newCube);
|
||||||
updateEntityState(thisEntity);
|
EntityItem::SimulationState newState = thisEntity->computeSimulationState();
|
||||||
|
if (newState != EntityItem::Moving) {
|
||||||
|
if (newState == EntityItem::Mortal) {
|
||||||
|
_mortalEntities.push_back(thisEntity);
|
||||||
|
}
|
||||||
|
// remove thisEntity from the list
|
||||||
|
item_itr = _movingEntities.erase(item_itr);
|
||||||
|
thisEntity->setSimulationState(newState);
|
||||||
|
} else {
|
||||||
|
++item_itr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -710,18 +723,30 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
void EntityTree::updateMortalEntities(quint64 now, QSet<EntityItemID>& entitiesToDelete) {
|
||||||
// TODO: switch these to iterators so we can remove items that get deleted
|
QList<EntityItem*>::iterator item_itr = _mortalEntities.begin();
|
||||||
for (int i = 0; i < _mortalEntities.size(); i++) {
|
while (item_itr != _mortalEntities.end()) {
|
||||||
EntityItem* thisEntity = _mortalEntities[i];
|
EntityItem* thisEntity = *item_itr;
|
||||||
thisEntity->update(now);
|
thisEntity->update(now);
|
||||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||||
if (thisEntity->lifetimeHasExpired()) {
|
if (thisEntity->lifetimeHasExpired()) {
|
||||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||||
entitiesToDelete << thisEntity->getEntityItemID();
|
entitiesToDelete << thisEntity->getEntityItemID();
|
||||||
clearEntityState(thisEntity);
|
// remove thisEntity from the list
|
||||||
|
item_itr = _mortalEntities.erase(item_itr);
|
||||||
|
thisEntity->setSimulationState(EntityItem::Static);
|
||||||
} else {
|
} else {
|
||||||
// check to see if this entity is no longer moving
|
// check to see if this entity is no longer moving
|
||||||
updateEntityState(thisEntity);
|
EntityItem::SimulationState newState = thisEntity->computeSimulationState();
|
||||||
|
if (newState != EntityItem::Mortal) {
|
||||||
|
if (newState == EntityItem::Moving) {
|
||||||
|
_movingEntities.push_back(thisEntity);
|
||||||
|
}
|
||||||
|
// remove thisEntity from the list
|
||||||
|
item_itr = _mortalEntities.erase(item_itr);
|
||||||
|
thisEntity->setSimulationState(newState);
|
||||||
|
} else {
|
||||||
|
++item_itr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue