mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
Merge pull request #3862 from AndrewMeadows/bispinor
more correct EntityItem list maintenance
This commit is contained in:
commit
969d178e44
2 changed files with 41 additions and 13 deletions
|
@ -96,6 +96,7 @@ function printVector(string, vector) {
|
|||
|
||||
function shootBullet(position, velocity) {
|
||||
var BULLET_SIZE = 0.01;
|
||||
var BULLET_LIFETIME = 20.0;
|
||||
var BULLET_GRAVITY = -0.02;
|
||||
Entities.addEntity(
|
||||
{ type: "Sphere",
|
||||
|
@ -103,6 +104,7 @@ function shootBullet(position, velocity) {
|
|||
dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE },
|
||||
color: { red: 10, green: 10, blue: 10 },
|
||||
velocity: velocity,
|
||||
lifetime: BULLET_LIFETIME,
|
||||
gravity: { x: 0, y: BULLET_GRAVITY, z: 0 },
|
||||
damping: 0 });
|
||||
|
||||
|
@ -118,6 +120,7 @@ function shootBullet(position, velocity) {
|
|||
function shootTarget() {
|
||||
var TARGET_SIZE = 0.25;
|
||||
var TARGET_GRAVITY = -0.6;
|
||||
var TARGET_LIFETIME = 300.0;
|
||||
var TARGET_UP_VELOCITY = 3.0;
|
||||
var TARGET_FWD_VELOCITY = 5.0;
|
||||
var DISTANCE_TO_LAUNCH_FROM = 3.0;
|
||||
|
@ -140,7 +143,7 @@ function shootTarget() {
|
|||
color: { red: 0, green: 200, blue: 200 },
|
||||
velocity: velocity,
|
||||
gravity: { x: 0, y: TARGET_GRAVITY, z: 0 },
|
||||
lifetime: 1000.0,
|
||||
lifetime: TARGET_LIFETIME,
|
||||
damping: 0.99 });
|
||||
|
||||
// Record start time
|
||||
|
|
|
@ -653,7 +653,6 @@ void EntityTree::update() {
|
|||
}
|
||||
|
||||
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) {
|
||||
// check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (thisEntity->lifetimeHasExpired()) {
|
||||
|
@ -675,15 +674,17 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
|||
{
|
||||
PerformanceTimer perfTimer("_movingEntities");
|
||||
|
||||
// TODO: switch these to iterators so we can remove items that get deleted
|
||||
for (int i = 0; i < _movingEntities.size(); i++) {
|
||||
EntityItem* thisEntity = _movingEntities[i];
|
||||
QList<EntityItem*>::iterator item_itr = _movingEntities.begin();
|
||||
while (item_itr != _movingEntities.end()) {
|
||||
EntityItem* thisEntity = *item_itr;
|
||||
|
||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (thisEntity->lifetimeHasExpired()) {
|
||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||
entitiesToDelete << thisEntity->getEntityItemID();
|
||||
clearEntityState(thisEntity);
|
||||
// remove thisEntity from the list
|
||||
item_itr = _movingEntities.erase(item_itr);
|
||||
thisEntity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
AACube oldCube = thisEntity->getMaximumAACube();
|
||||
thisEntity->update(now);
|
||||
|
@ -694,10 +695,22 @@ void EntityTree::updateMovingEntities(quint64 now, QSet<EntityItemID>& entitiesT
|
|||
if (!domainBounds.touches(newCube)) {
|
||||
qDebug() << "Entity " << thisEntity->getEntityItemID() << " moved out of domain bounds.";
|
||||
entitiesToDelete << thisEntity->getEntityItemID();
|
||||
clearEntityState(thisEntity);
|
||||
// remove thisEntity from the list
|
||||
item_itr = _movingEntities.erase(item_itr);
|
||||
thisEntity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
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) {
|
||||
// TODO: switch these to iterators so we can remove items that get deleted
|
||||
for (int i = 0; i < _mortalEntities.size(); i++) {
|
||||
EntityItem* thisEntity = _mortalEntities[i];
|
||||
QList<EntityItem*>::iterator item_itr = _mortalEntities.begin();
|
||||
while (item_itr != _mortalEntities.end()) {
|
||||
EntityItem* thisEntity = *item_itr;
|
||||
thisEntity->update(now);
|
||||
// always check to see if the lifetime has expired, for immortal entities this is always false
|
||||
if (thisEntity->lifetimeHasExpired()) {
|
||||
qDebug() << "Lifetime has expired for entity:" << thisEntity->getEntityItemID();
|
||||
entitiesToDelete << thisEntity->getEntityItemID();
|
||||
clearEntityState(thisEntity);
|
||||
// remove thisEntity from the list
|
||||
item_itr = _mortalEntities.erase(item_itr);
|
||||
thisEntity->setSimulationState(EntityItem::Static);
|
||||
} else {
|
||||
// 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