mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 06:19:02 +02:00
cleanup motionstate on EntityItem delete
This commit is contained in:
parent
1a094f2b51
commit
40b9416810
3 changed files with 16 additions and 4 deletions
|
@ -37,7 +37,7 @@ EntityTreeElement* EntityTree::createNewElement(unsigned char * octalCode) {
|
||||||
void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
|
void EntityTree::eraseAllOctreeElements(bool createNewRoot) {
|
||||||
// this would be a good place to clean up our entities...
|
// this would be a good place to clean up our entities...
|
||||||
foreach (EntityTreeElement* element, _entityToElementMap) {
|
foreach (EntityTreeElement* element, _entityToElementMap) {
|
||||||
element->cleanupEntities();
|
element->cleanupEntities(_physicsWorld);
|
||||||
}
|
}
|
||||||
_entityToElementMap.clear();
|
_entityToElementMap.clear();
|
||||||
Octree::eraseAllOctreeElements(createNewRoot);
|
Octree::eraseAllOctreeElements(createNewRoot);
|
||||||
|
@ -91,6 +91,7 @@ void EntityTree::addEntityItem(EntityItem* entityItem) {
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
|
|
||||||
// check to see if we need to simulate this entity..
|
// check to see if we need to simulate this entity..
|
||||||
|
// BOOKMARK -- add entity to physics engine here
|
||||||
changeEntityState(entityItem, EntityItem::Static, entityItem->getSimulationState());
|
changeEntityState(entityItem, EntityItem::Static, entityItem->getSimulationState());
|
||||||
|
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
@ -133,7 +134,9 @@ bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProp
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
|
|
||||||
EntityItem::SimulationState newState = existingEntity->getSimulationState();
|
EntityItem::SimulationState newState = existingEntity->getSimulationState();
|
||||||
changeEntityState(existingEntity, oldState, newState);
|
if (newState != oldState) {
|
||||||
|
changeEntityState(existingEntity, oldState, newState);
|
||||||
|
}
|
||||||
|
|
||||||
QString entityScriptAfter = existingEntity->getScript();
|
QString entityScriptAfter = existingEntity->getScript();
|
||||||
if (entityScriptBefore != entityScriptAfter) {
|
if (entityScriptBefore != entityScriptAfter) {
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
#include <FBXReader.h>
|
#include <FBXReader.h>
|
||||||
#include <GeometryUtil.h>
|
#include <GeometryUtil.h>
|
||||||
|
#include <PhysicsWorld.h>
|
||||||
|
|
||||||
|
#include "EntityMotionState.h"
|
||||||
#include "EntityTree.h"
|
#include "EntityTree.h"
|
||||||
#include "EntityTreeElement.h"
|
#include "EntityTreeElement.h"
|
||||||
|
|
||||||
|
@ -653,10 +655,16 @@ EntityItem* EntityTreeElement::getEntityWithEntityItemID(const EntityItemID& id)
|
||||||
return foundEntity;
|
return foundEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTreeElement::cleanupEntities() {
|
void EntityTreeElement::cleanupEntities(PhysicsWorld* physicsWorld) {
|
||||||
uint16_t numberOfEntities = _entityItems->size();
|
uint16_t numberOfEntities = _entityItems->size();
|
||||||
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
for (uint16_t i = 0; i < numberOfEntities; i++) {
|
||||||
EntityItem* entity = (*_entityItems)[i];
|
EntityItem* entity = (*_entityItems)[i];
|
||||||
|
EntityMotionState* motionState = entity->getMotionState();
|
||||||
|
if (motionState) {
|
||||||
|
assert(physicsWorld);
|
||||||
|
physicsWorld->removeEntity(static_cast<CustomMotionState*>(motionState));
|
||||||
|
entity->destroyMotionState();
|
||||||
|
}
|
||||||
delete entity;
|
delete entity;
|
||||||
}
|
}
|
||||||
_entityItems->clear();
|
_entityItems->clear();
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
class EntityTree;
|
class EntityTree;
|
||||||
class EntityTreeElement;
|
class EntityTreeElement;
|
||||||
|
class PhysicsWorld;
|
||||||
|
|
||||||
class EntityTreeUpdateArgs {
|
class EntityTreeUpdateArgs {
|
||||||
public:
|
public:
|
||||||
|
@ -175,7 +176,7 @@ public:
|
||||||
|
|
||||||
EntityItem* getEntityWithEntityItemID(const EntityItemID& id);
|
EntityItem* getEntityWithEntityItemID(const EntityItemID& id);
|
||||||
|
|
||||||
void cleanupEntities(); /// called by EntityTree on cleanup this will free all entities
|
void cleanupEntities(PhysicsWorld* physicsWorld);
|
||||||
bool removeEntityWithEntityItemID(const EntityItemID& id);
|
bool removeEntityWithEntityItemID(const EntityItemID& id);
|
||||||
bool removeEntityItem(EntityItem* entity);
|
bool removeEntityItem(EntityItem* entity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue