18#ifndef INCLUDED_SCRIPTCOMPONENT
19#define INCLUDED_SCRIPTCOMPONENT
49 template<
typename R,
typename... Ts>
50 R
Call(
const char* funcname,
const Ts&... params)
const
56 LOGERROR(
"Error calling component script function %s", funcname);
61 template<
typename R,
typename... Ts>
62 void CallRef(
const char* funcname, R ret,
const Ts&... params)
const
66 LOGERROR(
"Error calling component script function %s", funcname);
69 template<
typename... Ts>
70 void CallVoid(
const char* funcname,
const Ts&... params)
const
74 LOGERROR(
"Error calling component script function %s", funcname);
82#define REGISTER_COMPONENT_SCRIPT_WRAPPER(cname) \
83 void RegisterComponentType_##cname(CComponentManager& mgr) \
85 IComponent::RegisterComponentTypeScriptWrapper(mgr, CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, #cname, CCmp##cname::GetSchema()); \
86 CCmp##cname::ClassInit(mgr); \
90#define DEFAULT_SCRIPT_WRAPPER(cname) \
91 static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \
92 static IComponent* Allocate(const ScriptInterface& scriptInterface, JS::HandleValue instance) \
94 return new CCmp##cname(scriptInterface, instance); \
96 static void Deallocate(IComponent* cmp) \
98 delete static_cast<CCmp##cname*> (cmp); \
100 CCmp##cname(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \
101 static std::string GetSchema() \
103 return "<a:component type='script-wrapper'/><empty/>"; \
105 void Init(const CParamNode& paramNode) override \
107 m_Script.Init(paramNode, GetEntityId()); \
109 void Deinit() override \
113 void HandleMessage(const CMessage& msg, bool global) override \
115 m_Script.HandleMessage(msg, global); \
117 void Serialize(ISerializer& serialize) override \
119 m_Script.Serialize(serialize); \
121 void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) override \
123 m_Script.Deserialize(paramNode, deserialize, GetEntityId()); \
125 JS::Value GetJSInstance() const override \
127 return m_Script.GetInstance(); \
129 int GetComponentTypeId() const override \
131 return CID_##cname; \
134 CComponentTypeScript m_Script; \
#define LOGERROR(...)
Definition: CLogger.h:37
Definition: ScriptComponent.h:35
void Deinit()
Definition: ScriptComponent.cpp:43
JS::PersistentRootedValue m_Instance
Definition: ScriptComponent.h:79
JS::Value GetInstance() const
Definition: ScriptComponent.h:40
const ScriptInterface & m_ScriptInterface
Definition: ScriptComponent.h:78
void HandleMessage(const CMessage &msg, bool global)
Definition: ScriptComponent.cpp:49
NONCOPYABLE(CComponentTypeScript)
void CallVoid(const char *funcname, const Ts &... params) const
Definition: ScriptComponent.h:70
void Serialize(ISerializer &serialize)
Definition: ScriptComponent.cpp:61
void Init(const CParamNode ¶mNode, entity_id_t ent)
Definition: ScriptComponent.cpp:35
CComponentTypeScript(const ScriptInterface &scriptInterface, JS::HandleValue instance)
Definition: ScriptComponent.cpp:29
void CallRef(const char *funcname, R ret, const Ts &... params) const
Definition: ScriptComponent.h:62
R Call(const char *funcname, const Ts &... params) const
Definition: ScriptComponent.h:50
void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize, entity_id_t ent)
Definition: ScriptComponent.cpp:81
An entity initialisation parameter node.
Definition: ParamNode.h:151
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:35
Serialization interface; see serialization overview.
Definition: ISerializer.h:121
static bool CallVoid(const ScriptRequest &rq, JS::HandleValue val, const char *name, const Args &... args)
Call a JS function name, property of object val, with the arguments args.
Definition: FunctionWrapper.h:357
static bool Call(const ScriptRequest &rq, JS::HandleValue val, const char *name, R &ret, const Args &... args)
Call a JS function name, property of object val, with the arguments args.
Definition: FunctionWrapper.h:340
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
Spidermonkey maintains some 'local' state via the JSContext* object.
Definition: ScriptRequest.h:60
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29