2022-05-14 09:48:27 +00:00
|
|
|
#include "WebAssemblyBattleScript.hpp"
|
|
|
|
#include "WebAssemblyFunctionCall.hpp"
|
|
|
|
#include "WebAssemblyScriptResolver.hpp"
|
|
|
|
|
|
|
|
WebAssemblyBattleScript::~WebAssemblyBattleScript() {
|
|
|
|
// Ensure the WebAssembly library can clear up its own junk
|
|
|
|
auto funcOpt = _resolver->GetFunction<1, 0>("destroy_script");
|
|
|
|
if (funcOpt.has_value()) {
|
|
|
|
auto& func = funcOpt.value();
|
|
|
|
func.Loadi32(0, _wasmPtr);
|
|
|
|
func.Call();
|
|
|
|
}
|
|
|
|
// Remove the backwards lookup to this script.
|
|
|
|
_resolver->RemoveRegisteredScript(_wasmPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define WASM_CALL(capability, script_name, args_count, return_count, parameter_setup) \
|
|
|
|
if (!HasCapability(WebAssemblyScriptCapabilities::capability)) { \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
auto funcOpt = _resolver->GetFunction<args_count, return_count>(script_name); \
|
|
|
|
if (!funcOpt.has_value()) { \
|
|
|
|
return; \
|
|
|
|
} \
|
2022-05-22 11:00:53 +00:00
|
|
|
auto& func = funcOpt.value(); \
|
2022-05-14 09:48:27 +00:00
|
|
|
parameter_setup; \
|
|
|
|
func.Call();
|
|
|
|
|
|
|
|
void WebAssemblyBattleScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library,
|
2022-05-22 11:00:53 +00:00
|
|
|
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
|
|
|
|
WASM_CALL(Initialize, "script_on_initialize", 3, 0, {
|
2022-05-14 09:48:27 +00:00
|
|
|
func.Loadi32(0, _wasmPtr);
|
|
|
|
func.LoadExternRef(1, library);
|
2022-05-22 11:00:53 +00:00
|
|
|
func.LoadExternRef(2, ¶meters);
|
2022-05-14 09:48:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
CreatureLib::Battling::BattleScript* WebAssemblyBattleScript::Clone(const ArbUt::OptionalBorrowedPtr<void>&) {
|
|
|
|
// FIXME: Implement
|
|
|
|
return nullptr;
|
|
|
|
}
|