mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 15:14:33 +02:00
track entities added to PhysicsEngine
also fix for RigidBody's not going dynamic and a fix for changed entities staying on changed list
This commit is contained in:
parent
6e88ab15f9
commit
29d0d10103
2 changed files with 18 additions and 2 deletions
|
@ -52,6 +52,7 @@ void PhysicsEngine::updateEntities(QSet<EntityItem*>& entitiesToDelete) {
|
||||||
entity->clearUpdateFlags();
|
entity->clearUpdateFlags();
|
||||||
++item_itr;
|
++item_itr;
|
||||||
}
|
}
|
||||||
|
_changedEntities.clear();
|
||||||
|
|
||||||
// hunt for entities who have expired
|
// hunt for entities who have expired
|
||||||
// TODO: make EntityItems use an expiry to make this work faster.
|
// TODO: make EntityItems use an expiry to make this work faster.
|
||||||
|
@ -64,6 +65,7 @@ void PhysicsEngine::updateEntities(QSet<EntityItem*>& entitiesToDelete) {
|
||||||
entitiesToDelete.insert(entity);
|
entitiesToDelete.insert(entity);
|
||||||
// remove entity from the list
|
// remove entity from the list
|
||||||
item_itr = _mortalEntities.erase(item_itr);
|
item_itr = _mortalEntities.erase(item_itr);
|
||||||
|
_entities.remove(entity);
|
||||||
} else if (entity->isImmortal()) {
|
} else if (entity->isImmortal()) {
|
||||||
// remove entity from the list
|
// remove entity from the list
|
||||||
item_itr = _mortalEntities.erase(item_itr);
|
item_itr = _mortalEntities.erase(item_itr);
|
||||||
|
@ -80,6 +82,8 @@ void PhysicsEngine::addEntity(EntityItem* entity) {
|
||||||
assert(entity);
|
assert(entity);
|
||||||
void* physicsInfo = entity->getPhysicsInfo();
|
void* physicsInfo = entity->getPhysicsInfo();
|
||||||
if (!physicsInfo) {
|
if (!physicsInfo) {
|
||||||
|
assert(!_entities.contains(entity));
|
||||||
|
_entities.insert(entity);
|
||||||
if (entity->isMortal()) {
|
if (entity->isMortal()) {
|
||||||
_mortalEntities.insert(entity);
|
_mortalEntities.insert(entity);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +107,7 @@ void PhysicsEngine::removeEntity(EntityItem* entity) {
|
||||||
removeObject(motionState);
|
removeObject(motionState);
|
||||||
entity->setPhysicsInfo(NULL);
|
entity->setPhysicsInfo(NULL);
|
||||||
}
|
}
|
||||||
|
_entities.remove(entity);
|
||||||
_mortalEntities.remove(entity);
|
_mortalEntities.remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +118,17 @@ void PhysicsEngine::entityChanged(EntityItem* entity) {
|
||||||
|
|
||||||
void PhysicsEngine::clearEntities() {
|
void PhysicsEngine::clearEntities() {
|
||||||
// For now we assume this would only be called on shutdown in which case we can just let the memory get lost.
|
// For now we assume this would only be called on shutdown in which case we can just let the memory get lost.
|
||||||
|
QSet<EntityItem*>::const_iterator entityItr = _entities.begin();
|
||||||
|
for (entityItr = _entities.begin(); entityItr != _entities.end(); ++entityItr) {
|
||||||
|
void* physicsInfo = (*entityItr)->getPhysicsInfo();
|
||||||
|
if (physicsInfo) {
|
||||||
|
CustomMotionState* motionState = static_cast<CustomMotionState*>(physicsInfo);
|
||||||
|
removeObject(motionState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_entities.clear();
|
||||||
|
_changedEntities.clear();
|
||||||
|
_mortalEntities.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
|
@ -356,8 +372,7 @@ void PhysicsEngine::updateObjectHard(btRigidBody* body, CustomMotionState* motio
|
||||||
body->setMassProps(mass, inertia);
|
body->setMassProps(mass, inertia);
|
||||||
body->updateInertiaTensor();
|
body->updateInertiaTensor();
|
||||||
}
|
}
|
||||||
bool forceActivation = true;
|
body->forceActivationState(ACTIVE_TAG);
|
||||||
body->activate(forceActivation);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -129,6 +129,7 @@ private:
|
||||||
btHashMap<PositionHashKey, VoxelObject> _voxels;
|
btHashMap<PositionHashKey, VoxelObject> _voxels;
|
||||||
|
|
||||||
// EntitySimulation stuff
|
// EntitySimulation stuff
|
||||||
|
QSet<EntityItem*> _entities;
|
||||||
QSet<EntityItem*> _changedEntities;
|
QSet<EntityItem*> _changedEntities;
|
||||||
QSet<EntityItem*> _mortalEntities;
|
QSet<EntityItem*> _mortalEntities;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue