Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/system/ComponentManager.cpp
Show First 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | void CComponentManager::Script_RegisterComponentType_Common(ScriptInterface::CxPrivate* pCxPrivate, int iid, const std::string& cname, JS::HandleValue ctor, bool reRegister, bool systemComponent) | ||||
// Construct a new ComponentType, using the wrapper's alloc functions | // Construct a new ComponentType, using the wrapper's alloc functions | ||||
ComponentType ct{ | ComponentType ct{ | ||||
CT_Script, | CT_Script, | ||||
iid, | iid, | ||||
ctWrapper.alloc, | ctWrapper.alloc, | ||||
ctWrapper.dealloc, | ctWrapper.dealloc, | ||||
cname, | cname, | ||||
schema, | schema, | ||||
DefPersistentRooted<JS::Value>(cx, ctor) | std::unique_ptr<JS::PersistentRootedValue>(new JS::PersistentRootedValue(cx, ctor)) | ||||
}; | }; | ||||
componentManager->m_ComponentTypesById[cid] = std::move(ct); | componentManager->m_ComponentTypesById[cid] = std::move(ct); | ||||
componentManager->m_CurrentComponent = cid; // needed by Subscribe | componentManager->m_CurrentComponent = cid; // needed by Subscribe | ||||
// Find all the ctor prototype's On* methods, and subscribe to the appropriate messages: | // Find all the ctor prototype's On* methods, and subscribe to the appropriate messages: | ||||
std::vector<std::string> methods; | std::vector<std::string> methods; | ||||
▲ Show 20 Lines • Show All 265 Lines • ▼ Show 20 Lines | |||||
void CComponentManager::SetRNGSeed(u32 seed) | void CComponentManager::SetRNGSeed(u32 seed) | ||||
{ | { | ||||
m_RNG.seed(seed); | m_RNG.seed(seed); | ||||
} | } | ||||
void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, | void CComponentManager::RegisterComponentType(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, | ||||
const char* name, const std::string& schema) | const char* name, const std::string& schema) | ||||
{ | { | ||||
ComponentType c{ CT_Native, iid, alloc, dealloc, name, schema, DefPersistentRooted<JS::Value>() }; | ComponentType c{ CT_Native, iid, alloc, dealloc, name, schema, std::unique_ptr<JS::PersistentRootedValue>() }; | ||||
m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); | m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); | ||||
m_ComponentTypeIdsByName[name] = cid; | m_ComponentTypeIdsByName[name] = cid; | ||||
} | } | ||||
void CComponentManager::RegisterComponentTypeScriptWrapper(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, | void CComponentManager::RegisterComponentTypeScriptWrapper(InterfaceId iid, ComponentTypeId cid, AllocFunc alloc, | ||||
DeallocFunc dealloc, const char* name, const std::string& schema) | DeallocFunc dealloc, const char* name, const std::string& schema) | ||||
{ | { | ||||
ComponentType c{ CT_ScriptWrapper, iid, alloc, dealloc, name, schema, DefPersistentRooted<JS::Value>() }; | ComponentType c{ CT_ScriptWrapper, iid, alloc, dealloc, name, schema, std::unique_ptr<JS::PersistentRootedValue>() }; | ||||
m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); | m_ComponentTypesById.insert(std::make_pair(cid, std::move(c))); | ||||
m_ComponentTypeIdsByName[name] = cid; | m_ComponentTypeIdsByName[name] = cid; | ||||
// TODO: merge with RegisterComponentType | // TODO: merge with RegisterComponentType | ||||
} | } | ||||
void CComponentManager::MarkScriptedComponentForSystemEntity(CComponentManager::ComponentTypeId cid) | void CComponentManager::MarkScriptedComponentForSystemEntity(CComponentManager::ComponentTypeId cid) | ||||
{ | { | ||||
m_ScriptedSystemComponents.push_back(cid); | m_ScriptedSystemComponents.push_back(cid); | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTypeId cid) | ||||
} | } | ||||
std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid]; | std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid]; | ||||
// If this is a scripted component, construct the appropriate JS object first | // If this is a scripted component, construct the appropriate JS object first | ||||
JS::RootedValue obj(cx); | JS::RootedValue obj(cx); | ||||
if (ct.type == CT_Script) | if (ct.type == CT_Script) | ||||
{ | { | ||||
m_ScriptInterface.CallConstructor(ct.ctor.get(), JS::HandleValueArray::empty(), &obj); | m_ScriptInterface.CallConstructor(*ct.ctor, JS::HandleValueArray::empty(), &obj); | ||||
if (obj.isNull()) | if (obj.isNull()) | ||||
{ | { | ||||
LOGERROR("Script component constructor failed"); | LOGERROR("Script component constructor failed"); | ||||
return NULL; | return NULL; | ||||
} | } | ||||
} | } | ||||
// Construct the new component | // Construct the new component | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator