本文整理汇总了C++中CComponentManager::SubscribeGloballyToMessageType方法的典型用法代码示例。如果您正苦于以下问题:C++ CComponentManager::SubscribeGloballyToMessageType方法的具体用法?C++ CComponentManager::SubscribeGloballyToMessageType怎么用?C++ CComponentManager::SubscribeGloballyToMessageType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComponentManager
的用法示例。
在下文中一共展示了CComponentManager::SubscribeGloballyToMessageType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClassInit
static void ClassInit(CComponentManager& componentManager)
{
componentManager.SubscribeGloballyToMessageType(MT_OwnershipChanged);
componentManager.SubscribeGloballyToMessageType(MT_PositionChanged);
componentManager.SubscribeGloballyToMessageType(MT_ValueModification);
componentManager.SubscribeToMessageType(MT_TerrainChanged);
componentManager.SubscribeToMessageType(MT_Update);
componentManager.SubscribeToMessageType(MT_Interpolate);
componentManager.SubscribeToMessageType(MT_RenderSubmit);
}
示例2: Script_RegisterComponentType
//.........这里部分代码省略.........
}
}
// Remove the old component type's message subscriptions
std::map<MessageTypeId, std::vector<ComponentTypeId> >::iterator it;
for (it = componentManager->m_LocalMessageSubscriptions.begin(); it != componentManager->m_LocalMessageSubscriptions.end(); ++it)
{
std::vector<ComponentTypeId>& types = it->second;
std::vector<ComponentTypeId>::iterator ctit = find(types.begin(), types.end(), cid);
if (ctit != types.end())
types.erase(ctit);
}
for (it = componentManager->m_GlobalMessageSubscriptions.begin(); it != componentManager->m_GlobalMessageSubscriptions.end(); ++it)
{
std::vector<ComponentTypeId>& types = it->second;
std::vector<ComponentTypeId>::iterator ctit = find(types.begin(), types.end(), cid);
if (ctit != types.end())
types.erase(ctit);
}
mustReloadComponents = true;
}
std::string schema = "<empty/>";
{
CScriptValRooted prototype;
if (componentManager->m_ScriptInterface.GetProperty(ctor.get(), "prototype", prototype) &&
componentManager->m_ScriptInterface.HasProperty(prototype.get(), "Schema"))
{
componentManager->m_ScriptInterface.GetProperty(prototype.get(), "Schema", schema);
}
}
// Construct a new ComponentType, using the wrapper's alloc functions
ComponentType ct = {
CT_Script,
iid,
ctWrapper.alloc,
ctWrapper.dealloc,
cname,
schema,
CScriptValRooted(componentManager->m_ScriptInterface.GetContext(), ctor)
};
componentManager->m_ComponentTypesById[cid] = ct;
componentManager->m_CurrentComponent = cid; // needed by Subscribe
// Find all the ctor prototype's On* methods, and subscribe to the appropriate messages:
CScriptVal proto;
if (!componentManager->m_ScriptInterface.GetProperty(ctor.get(), "prototype", proto))
return; // error
std::vector<std::string> methods;
if (!componentManager->m_ScriptInterface.EnumeratePropertyNamesWithPrefix(proto.get(), "On", methods))
return; // error
for (std::vector<std::string>::const_iterator it = methods.begin(); it != methods.end(); ++it)
{
std::string name = (*it).substr(2); // strip the "On" prefix
// Handle "OnGlobalFoo" functions specially
bool isGlobal = false;
if (name.substr(0, 6) == "Global")
{
isGlobal = true;
name = name.substr(6);
}
std::map<std::string, MessageTypeId>::const_iterator mit = componentManager->m_MessageTypeIdsByName.find(name);
if (mit == componentManager->m_MessageTypeIdsByName.end())
{
std::string msg = "Registered component has unrecognised '" + *it + "' message handler method";
componentManager->m_ScriptInterface.ReportError(msg.c_str());
return;
}
if (isGlobal)
componentManager->SubscribeGloballyToMessageType(mit->second);
else
componentManager->SubscribeToMessageType(mit->second);
}
componentManager->m_CurrentComponent = CID__Invalid;
if (mustReloadComponents)
{
// For every script component with this cid, we need to switch its
// prototype from the old constructor's prototype property to the new one's
const std::map<entity_id_t, IComponent*>& comps = componentManager->m_ComponentsByTypeId[cid];
std::map<entity_id_t, IComponent*>::const_iterator eit = comps.begin();
for (; eit != comps.end(); ++eit)
{
jsval instance = eit->second->GetJSInstance();
if (!JSVAL_IS_NULL(instance))
componentManager->m_ScriptInterface.SetPrototype(instance, proto.get());
}
}
}
示例3: ClassInit
static void ClassInit(CComponentManager& componentManager)
{
componentManager.SubscribeGloballyToMessageType(MT_TechnologyModification);
}
示例4: ClassInit
static void ClassInit(CComponentManager& componentManager)
{
componentManager.SubscribeGloballyToMessageType(MT_Destroy);
}
示例5: Script_RegisterComponentType_Common
//.........这里部分代码省略.........
std::vector<ComponentTypeId>& types = it->second;
std::vector<ComponentTypeId>::iterator ctit = find(types.begin(), types.end(), cid);
if (ctit != types.end())
types.erase(ctit);
}
for (it = componentManager->m_GlobalMessageSubscriptions.begin(); it != componentManager->m_GlobalMessageSubscriptions.end(); ++it)
{
std::vector<ComponentTypeId>& types = it->second;
std::vector<ComponentTypeId>::iterator ctit = find(types.begin(), types.end(), cid);
if (ctit != types.end())
types.erase(ctit);
}
mustReloadComponents = true;
}
std::string schema = "<empty/>";
{
JS::RootedValue prototype(cx);
if (componentManager->m_ScriptInterface.GetProperty(ctor, "prototype", &prototype) &&
componentManager->m_ScriptInterface.HasProperty(prototype, "Schema"))
{
componentManager->m_ScriptInterface.GetProperty(prototype, "Schema", schema);
}
}
// Construct a new ComponentType, using the wrapper's alloc functions
ComponentType ct(
CT_Script,
iid,
ctWrapper.alloc,
ctWrapper.dealloc,
cname,
schema,
DefPersistentRooted<JS::Value>(cx, ctor)
);
componentManager->m_ComponentTypesById[cid] = std::move(ct);
componentManager->m_CurrentComponent = cid; // needed by Subscribe
// Find all the ctor prototype's On* methods, and subscribe to the appropriate messages:
JS::RootedValue protoVal(cx);
if (!componentManager->m_ScriptInterface.GetProperty(ctor, "prototype", &protoVal))
return; // error
std::vector<std::string> methods;
JS::RootedObject proto(cx);
if (!protoVal.isObjectOrNull())
return; // error
proto = protoVal.toObjectOrNull();
if (!componentManager->m_ScriptInterface.EnumeratePropertyNamesWithPrefix(protoVal, "On", methods))
return; // error
for (std::vector<std::string>::const_iterator it = methods.begin(); it != methods.end(); ++it)
{
std::string name = (*it).substr(2); // strip the "On" prefix
// Handle "OnGlobalFoo" functions specially
bool isGlobal = false;
if (name.substr(0, 6) == "Global")
{
isGlobal = true;
name = name.substr(6);
}
std::map<std::string, MessageTypeId>::const_iterator mit = componentManager->m_MessageTypeIdsByName.find(name);
if (mit == componentManager->m_MessageTypeIdsByName.end())
{
std::string msg("Registered component has unrecognised '" + *it + "' message handler method");
componentManager->m_ScriptInterface.ReportError(msg.c_str());
return;
}
if (isGlobal)
componentManager->SubscribeGloballyToMessageType(mit->second);
else
componentManager->SubscribeToMessageType(mit->second);
}
componentManager->m_CurrentComponent = CID__Invalid;
if (mustReloadComponents)
{
// For every script component with this cid, we need to switch its
// prototype from the old constructor's prototype property to the new one's
const std::map<entity_id_t, IComponent*>& comps = componentManager->m_ComponentsByTypeId[cid];
std::map<entity_id_t, IComponent*>::const_iterator eit = comps.begin();
for (; eit != comps.end(); ++eit)
{
JS::RootedValue instance(cx, eit->second->GetJSInstance());
if (!instance.isNull())
{
componentManager->m_ScriptInterface.SetPrototype(instance, protoVal);
}
}
}
}