Go to the documentation of this file.
18 #ifndef INCLUDED_COMPONENT
19 #define INCLUDED_COMPONENT
30 #define REGISTER_COMPONENT_TYPE(cname) \
31 void RegisterComponentType_##cname(CComponentManager& mgr) \
33 mgr.RegisterComponentType(CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, #cname, CCmp##cname::GetSchema()); \
34 CCmp##cname::ClassInit(mgr); \
37 #define REGISTER_COMPONENT_SCRIPT_WRAPPER(cname) \
38 void RegisterComponentType_##cname(CComponentManager& mgr) \
40 mgr.RegisterComponentTypeScriptWrapper(CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, #cname, CCmp##cname::GetSchema()); \
41 CCmp##cname::ClassInit(mgr); \
44 #define DEFAULT_COMPONENT_ALLOCATOR(cname) \
45 static IComponent* Allocate(ScriptInterface&, jsval) { return new CCmp##cname(); } \
46 static void Deallocate(IComponent* cmp) { delete static_cast<CCmp##cname*> (cmp); } \
48 #define DEFAULT_SCRIPT_WRAPPER(cname) \
49 static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \
50 static IComponent* Allocate(ScriptInterface& scriptInterface, jsval instance) \
52 return new CCmp##cname(scriptInterface, instance); \
54 static void Deallocate(IComponent* cmp) \
56 delete static_cast<CCmp##cname*> (cmp); \
58 CCmp##cname(ScriptInterface& scriptInterface, jsval instance) : m_Script(scriptInterface, instance) { } \
59 static std::string GetSchema() \
61 return "<a:component type='script-wrapper'/><empty/>"; \
63 virtual void Init(const CParamNode& paramNode) \
65 m_Script.Init(paramNode, GetEntityId()); \
67 virtual void Deinit() \
71 virtual void HandleMessage(const CMessage& msg, bool global) \
73 m_Script.HandleMessage(msg, global); \
75 virtual void Serialize(ISerializer& serialize) \
77 m_Script.Serialize(serialize); \
79 virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) \
81 m_Script.Deserialize(paramNode, deserialize, GetEntityId()); \
83 virtual jsval GetJSInstance() const \
85 return m_Script.GetInstance(); \
88 CComponentTypeScript m_Script; \
91 #define DEFAULT_MOCK_COMPONENT() \
92 virtual void Init(const CParamNode& UNUSED(paramNode)) \
95 virtual void Deinit() \
98 virtual void Serialize(ISerializer& UNUSED(serialize)) \
101 virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& UNUSED(deserialize)) \
105 #endif // INCLUDED_COMPONENT