Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/ScriptComponent.h
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
private: | private: | ||||
const ScriptInterface& m_ScriptInterface; | const ScriptInterface& m_ScriptInterface; | ||||
JS::PersistentRootedValue m_Instance; | JS::PersistentRootedValue m_Instance; | ||||
}; | }; | ||||
#define REGISTER_COMPONENT_SCRIPT_WRAPPER(cname) \ | #define REGISTER_COMPONENT_SCRIPT_WRAPPER(cname) \ | ||||
void RegisterComponentType_##cname(CComponentManager& mgr) \ | void RegisterComponentType_##cname(CComponentManager& mgr) \ | ||||
{ \ | { \ | ||||
IComponent::RegisterComponentTypeScriptWrapper(mgr, CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, #cname, CCmp##cname::GetSchema()); \ | IComponent::RegisterComponentTypeScriptWrapper(mgr, CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, sizeof(CCmp##cname), alignof(CCmp##cname), #cname, CCmp##cname::GetSchema()); \ | ||||
CCmp##cname::ClassInit(mgr); \ | CCmp##cname::ClassInit(mgr); \ | ||||
} | } | ||||
#define DEFAULT_SCRIPT_WRAPPER(cname) \ | #define DEFAULT_SCRIPT_WRAPPER(cname) \ | ||||
static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \ | static void ClassInit(CComponentManager& UNUSED(componentManager)) { } \ | ||||
static IComponent* Allocate(const ScriptInterface& scriptInterface, JS::HandleValue instance) \ | static IComponent* Allocate(void* slot, const ScriptInterface& scriptInterface, JS::HandleValue instance) \ | ||||
{ \ | { \ | ||||
return new CCmp##cname(scriptInterface, instance); \ | return new (slot) CCmp##cname(scriptInterface, instance); \ | ||||
} \ | } \ | ||||
static void Deallocate(IComponent* cmp) \ | static void Deallocate(IComponent* cmp) \ | ||||
{ \ | { \ | ||||
delete static_cast<CCmp##cname*> (cmp); \ | static_cast<CCmp##cname*>(cmp)->~CCmp##cname(); \ | ||||
} \ | } \ | ||||
CCmp##cname(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \ | CCmp##cname(const ScriptInterface& scriptInterface, JS::HandleValue instance) : m_Script(scriptInterface, instance) { } \ | ||||
static std::string GetSchema() \ | static std::string GetSchema() \ | ||||
{ \ | { \ | ||||
return "<a:component type='script-wrapper'/><empty/>"; \ | return "<a:component type='script-wrapper'/><empty/>"; \ | ||||
} \ | } \ | ||||
void Init(const CParamNode& paramNode) override \ | void Init(const CParamNode& paramNode) override \ | ||||
{ \ | { \ | ||||
Show All 31 Lines |
Wildfire Games · Phabricator