Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/system/ComponentManager.cpp
Show First 20 Lines • Show All 903 Lines • ▼ Show 20 Lines | void CComponentManager::FlushDestroyedComponents() | ||||
PROFILE2("Flush Destroyed Components"); | PROFILE2("Flush Destroyed Components"); | ||||
while (!m_DestructionQueue.empty()) | while (!m_DestructionQueue.empty()) | ||||
{ | { | ||||
// Make a copy of the destruction queue, so that the iterators won't be invalidated if the | // Make a copy of the destruction queue, so that the iterators won't be invalidated if the | ||||
// CMessageDestroy handlers try to destroy more entities themselves | // CMessageDestroy handlers try to destroy more entities themselves | ||||
std::vector<entity_id_t> queue; | std::vector<entity_id_t> queue; | ||||
queue.swap(m_DestructionQueue); | queue.swap(m_DestructionQueue); | ||||
// Flatten all the dynamic subscriptions to ensure there are no dangling | |||||
// references in the 'removed' lists to components we're going to delete | |||||
FlattenDynamicSubscriptions(); | |||||
for (std::vector<entity_id_t>::iterator it = queue.begin(); it != queue.end(); ++it) | for (std::vector<entity_id_t>::iterator it = queue.begin(); it != queue.end(); ++it) | ||||
{ | { | ||||
entity_id_t ent = *it; | entity_id_t ent = *it; | ||||
CEntityHandle handle = LookupEntityHandle(ent); | CEntityHandle handle = LookupEntityHandle(ent); | ||||
CMessageDestroy msg(ent); | CMessageDestroy msg(ent); | ||||
PostMessage(ent, msg); | PostMessage(ent, msg); | ||||
// Flatten all the dynamic subscriptions to ensure there are no dangling | |||||
// references in the 'removed' lists to components we're going to delete | |||||
// Some components may have dynamically unsubscribed following the Destroy message | |||||
FlattenDynamicSubscriptions(); | |||||
// Destroy the components, and remove from m_ComponentsByTypeId: | // Destroy the components, and remove from m_ComponentsByTypeId: | ||||
std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::iterator iit = m_ComponentsByTypeId.begin(); | std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::iterator iit = m_ComponentsByTypeId.begin(); | ||||
for (; iit != m_ComponentsByTypeId.end(); ++iit) | for (; iit != m_ComponentsByTypeId.end(); ++iit) | ||||
{ | { | ||||
std::map<entity_id_t, IComponent*>::iterator eit = iit->second.find(ent); | std::map<entity_id_t, IComponent*>::iterator eit = iit->second.find(ent); | ||||
if (eit != iit->second.end()) | if (eit != iit->second.end()) | ||||
{ | { | ||||
eit->second->Deinit(); | eit->second->Deinit(); | ||||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator