add entities to simulation after unpacking

This commit is contained in:
Andrew Meadows 2014-11-26 17:09:53 -08:00
parent d84f57fafa
commit 3781c23480
3 changed files with 11 additions and 25 deletions

View file

@ -76,25 +76,14 @@ EntityItem* EntityTree::getOrCreateEntityItem(const EntityItemID& entityID, cons
}
/// Adds a new entity item to the tree
void EntityTree::addEntityItem(EntityItem* entityItem) {
// You should not call this on existing entities that are already part of the tree! Call updateEntity()
EntityItemID entityID = entityItem->getEntityItemID();
EntityTreeElement* containingElement = getContainingElement(entityID);
if (containingElement) {
qDebug() << "UNEXPECTED!!!! don't call addEntityItem() on existing EntityItems. entityID=" << entityID;
return;
}
// Recurse the tree and store the entity in the correct tree element
AddEntityOperator theOperator(this, entityItem);
recurseTreeWithOperator(&theOperator);
void EntityTree::postAddEntity(EntityItem* entity) {
assert(entity);
// check to see if we need to simulate this entity..
if (_simulation) {
_simulation->addEntity(entityItem);
_simulation->addEntity(entity);
}
_isDirty = true;
emit addingEntity(entity->getEntityItemID());
}
bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties) {
@ -177,9 +166,11 @@ EntityItem* EntityTree::addEntity(const EntityItemID& entityID, const EntityItem
result = EntityTypes::constructEntityItem(type, entityID, properties);
if (result) {
// this does the actual adding of the entity
addEntityItem(result);
emitAddingEntity(entityID);
// Recurse the tree and store the entity in the correct tree element
AddEntityOperator theOperator(this, result);
recurseTreeWithOperator(&theOperator);
postAddEntity(result);
}
return result;
}
@ -199,10 +190,6 @@ void EntityTree::trackDeletedEntity(EntityItem* entity) {
}
}
void EntityTree::emitAddingEntity(const EntityItemID& entityItemID) {
emit addingEntity(entityItemID);
}
void EntityTree::emitEntityScriptChanging(const EntityItemID& entityItemID) {
emit entityScriptChanging(entityItemID);
}

View file

@ -79,7 +79,7 @@ public:
// The newer API...
EntityItem* getOrCreateEntityItem(const EntityItemID& entityID, const EntityItemProperties& properties);
void addEntityItem(EntityItem* entityItem);
void postAddEntity(EntityItem* entityItem);
EntityItem* addEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
bool updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties);
@ -142,7 +142,6 @@ public:
void trackDeletedEntity(EntityItem* entity);
void emitAddingEntity(const EntityItemID& entityItemID);
void emitEntityScriptChanging(const EntityItemID& entityItemID);
void setSimulation(EntitySimulation* simulation);

View file

@ -768,7 +768,7 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int
addEntityItem(entityItem); // add this new entity to this elements entities
entityItemID = entityItem->getEntityItemID();
_myTree->setContainingElement(entityItemID, this);
_myTree->emitAddingEntity(entityItemID); // we just added an entity
_myTree->postAddEntity(entityItem);
}
}
// Move the buffer forward to read more entities