Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ComponentManager.cpp
Show All 18 Lines | |||||
#include "ComponentManager.h" | #include "ComponentManager.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/scripting/JSInterface_VFS.h" | #include "ps/scripting/JSInterface_VFS.h" | ||||
#include "renderer/RenderingOptions.h" | |||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/system/DynamicSubscription.h" | #include "simulation2/system/DynamicSubscription.h" | ||||
#include "simulation2/system/IComponent.h" | #include "simulation2/system/IComponent.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include "simulation2/system/SimContext.h" | #include "simulation2/system/SimContext.h" | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 426 Lines • ▼ Show 20 Lines | int CComponentManager::Script_AddEntity(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName) | ||||
std::wstring name(templateName.begin(), templateName.end()); | std::wstring name(templateName.begin(), templateName.end()); | ||||
// TODO: should validate the string to make sure it doesn't contain scary characters | // TODO: should validate the string to make sure it doesn't contain scary characters | ||||
// that will let it access non-component-template files | // that will let it access non-component-template files | ||||
entity_id_t ent = componentManager->AddEntity(name, componentManager->AllocateNewEntity()); | entity_id_t ent = componentManager->AddEntity(name, componentManager->AllocateNewEntity()); | ||||
return (int)ent; | return (int)ent; | ||||
} | } | ||||
std::vector<entity_id_t> CComponentManager::m_Corpses = std::vector<entity_id_t>(); | |||||
int CComponentManager::Script_AddLocalEntity(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName) | int CComponentManager::Script_AddLocalEntity(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
std::wstring name(templateName.begin(), templateName.end()); | std::wstring name(templateName.begin(), templateName.end()); | ||||
// TODO: should validate the string to make sure it doesn't contain scary characters | // TODO: should validate the string to make sure it doesn't contain scary characters | ||||
// that will let it access non-component-template files | // that will let it access non-component-template files | ||||
entity_id_t newEnt = INVALID_ENTITY; | |||||
bool isCorpse = templateName.find("corpse|") != std::string::npos; | |||||
if (isCorpse) | |||||
{ | |||||
int maxCorpses = g_RenderingOptions.GetMaxRagDolls(); | |||||
if (maxCorpses != -1 && m_Corpses.size() >= static_cast<size_t>(maxCorpses)) | |||||
return newEnt; | |||||
entity_id_t ent = componentManager->AddEntity(name, componentManager->AllocateNewLocalEntity()); | newEnt = componentManager->AllocateNewLocalEntity(); | ||||
return (int)ent; | m_Corpses.push_back(newEnt); | ||||
} | |||||
else | |||||
newEnt = componentManager->AllocateNewLocalEntity(); | |||||
return static_cast<int>(componentManager->AddEntity(name, newEnt)); | |||||
} | } | ||||
void CComponentManager::Script_DestroyEntity(ScriptInterface::CxPrivate* pCxPrivate, int ent) | void CComponentManager::Script_DestroyEntity(ScriptInterface::CxPrivate* pCxPrivate, int ent) | ||||
{ | { | ||||
CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); | ||||
componentManager->DestroyComponentsSoon(ent); | componentManager->DestroyComponentsSoon(ent); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | |||||
bool CComponentManager::EntityExists(entity_id_t ent) const | bool CComponentManager::EntityExists(entity_id_t ent) const | ||||
{ | { | ||||
return m_ComponentCaches.find(ent) != m_ComponentCaches.end(); | return m_ComponentCaches.find(ent) != m_ComponentCaches.end(); | ||||
} | } | ||||
void CComponentManager::DestroyComponentsSoon(entity_id_t ent) | void CComponentManager::DestroyComponentsSoon(entity_id_t ent) | ||||
{ | { | ||||
std::vector< entity_id_t>::iterator it = std::find(m_Corpses.begin(), m_Corpses.end(), static_cast <entity_id_t>(ent)); | |||||
if (it != m_Corpses.end()) | |||||
m_Corpses.erase(it); | |||||
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()) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator