Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/scripting/ScriptComponent.h
/* Copyright (C) 2022 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 26 Lines | class CComponentTypeScript | ||||
NONCOPYABLE(CComponentTypeScript); | NONCOPYABLE(CComponentTypeScript); | ||||
public: | public: | ||||
CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance); | CComponentTypeScript(const ScriptInterface& scriptInterface, JS::HandleValue instance); | ||||
JS::Value GetInstance() const { return m_Instance.get(); } | JS::Value GetInstance() const { return m_Instance.get(); } | ||||
void Init(const CParamNode& paramNode, entity_id_t ent); | void Init(const CParamNode& paramNode, entity_id_t ent); | ||||
void Deinit(); | void Deinit(); | ||||
void Update(const CParamNode& paramNode); | |||||
void HandleMessage(const CMessage& msg, bool global); | void HandleMessage(const CMessage& msg, bool global); | ||||
void Serialize(ISerializer& serialize); | void Serialize(ISerializer& serialize); | ||||
void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize, entity_id_t ent); | void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize, entity_id_t ent); | ||||
template<typename R, typename... Ts> | template<typename R, typename... Ts> | ||||
R Call(const char* funcname, const Ts&... params) const | R Call(const char* funcname, const Ts&... params) const | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | #define DEFAULT_SCRIPT_WRAPPER(cname) \ | ||||
void Init(const CParamNode& paramNode) override \ | void Init(const CParamNode& paramNode) override \ | ||||
{ \ | { \ | ||||
m_Script.Init(paramNode, GetEntityId()); \ | m_Script.Init(paramNode, GetEntityId()); \ | ||||
} \ | } \ | ||||
void Deinit() override \ | void Deinit() override \ | ||||
{ \ | { \ | ||||
m_Script.Deinit(); \ | m_Script.Deinit(); \ | ||||
} \ | } \ | ||||
void Update(const CParamNode& paramNode) override \ | |||||
{ \ | |||||
m_Script.Update(paramNode); \ | |||||
} \ | |||||
void HandleMessage(const CMessage& msg, bool global) override \ | void HandleMessage(const CMessage& msg, bool global) override \ | ||||
{ \ | { \ | ||||
m_Script.HandleMessage(msg, global); \ | m_Script.HandleMessage(msg, global); \ | ||||
} \ | } \ | ||||
void Serialize(ISerializer& serialize) override \ | void Serialize(ISerializer& serialize) override \ | ||||
{ \ | { \ | ||||
m_Script.Serialize(serialize); \ | m_Script.Serialize(serialize); \ | ||||
} \ | } \ | ||||
Show All 17 Lines |
Wildfire Games · Phabricator