Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ComponentManager.cpp
Show First 20 Lines • Show All 892 Lines • ▼ Show 20 Lines | entity_id_t CComponentManager::AddEntity(const std::wstring& templateName, entity_id_t ent) | ||||
CMessageCreate msg(ent); | CMessageCreate msg(ent); | ||||
PostMessage(ent, msg); | PostMessage(ent, msg); | ||||
return ent; | return ent; | ||||
} | } | ||||
void CComponentManager::DestroyComponentsSoon(entity_id_t ent) | void CComponentManager::DestroyComponentsSoon(entity_id_t ent) | ||||
{ | { | ||||
if (ent == INVALID_ENTITY) | |||||
return; | |||||
m_DestructionQueue.push_back(ent); | m_DestructionQueue.push_back(ent); | ||||
} | } | ||||
void CComponentManager::FlushDestroyedComponents() | 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); | ||||
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); | ||||
vladislavbelov: The `GetComponentCache` function doesn't look like a valid check of aliveness. Because the… | |||||
Not Done Inline ActionsBut such a function would be just checking that handle.m_ComponentCache is allocated, no? So it would be equivalent in terms of logic, and it's easier to use m_ComponentCaches from the manager and keep CEntityHandle slim IMO. Itms: But such a function would be just checking that `handle.m_ComponentCache` is allocated, no? So… | |||||
// Flatten all the dynamic subscriptions to ensure there are no dangling | // Flatten all the dynamic subscriptions to ensure there are no dangling | ||||
// references in the 'removed' lists to components we're going to delete | // references in the 'removed' lists to components we're going to delete | ||||
// Some components may have dynamically unsubscribed following the Destroy message | // Some components may have dynamically unsubscribed following the Destroy message | ||||
FlattenDynamicSubscriptions(); | 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(); | ||||
▲ Show 20 Lines • Show All 248 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
The GetComponentCache function doesn't look like a valid check of aliveness. Because the condition may change. Shouldn't we add a method like CEntityHandle::IsAlive?