Adds a lot more WASM type registry
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
9adbd27358
commit
a4ac678154
|
@ -0,0 +1,13 @@
|
||||||
|
#include "WASMAbilityRegistry.hpp"
|
||||||
|
#include "../WASMHelperFile.hpp"
|
||||||
|
#include "wasm.h"
|
||||||
|
|
||||||
|
using namespace CreatureLib::Library;
|
||||||
|
using namespace PkmnLib::Library;
|
||||||
|
|
||||||
|
void WASMAbilityRegistry::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
|
WebAssemblyScriptResolver* resolver) {
|
||||||
|
REGISTER_GETTER("ability_get_name", Talent, GetName, resolver);
|
||||||
|
REGISTER_GETTER("ability_get_effect", Talent, GetEffect, resolver);
|
||||||
|
REGISTER_GETTER("ability_get_parameters", Talent, GetParameters, resolver);
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef PKMNLIB_WASMABILITYREGISTRY_HPP
|
||||||
|
#define PKMNLIB_WASMABILITYREGISTRY_HPP
|
||||||
|
#include "../../WebAssemblyScriptResolver.hpp"
|
||||||
|
|
||||||
|
class WASMAbilityRegistry {
|
||||||
|
public:
|
||||||
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PKMNLIB_WASMABILITYREGISTRY_HPP
|
|
@ -0,0 +1,16 @@
|
||||||
|
#include "WASMEffectParameter.hpp"
|
||||||
|
#include "../../../../Battling/Library/BattleLibrary.hpp"
|
||||||
|
#include "../../WebAssemblyScriptResolver.hpp"
|
||||||
|
#include "../WASMHelperFile.hpp"
|
||||||
|
#include "wasm.h"
|
||||||
|
|
||||||
|
using namespace CreatureLib::Library;
|
||||||
|
|
||||||
|
void WASMEffectParameter::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
|
WebAssemblyScriptResolver* resolver) {
|
||||||
|
REGISTER_GETTER("effect_parameter_get_type", EffectParameter, GetType, resolver)
|
||||||
|
REGISTER_GETTER("effect_parameter_as_bool", EffectParameter, AsBool, resolver)
|
||||||
|
REGISTER_GETTER("effect_parameter_as_int", EffectParameter, AsInt, resolver)
|
||||||
|
REGISTER_GETTER("effect_parameter_as_float", EffectParameter, AsFloat, resolver)
|
||||||
|
REGISTER_GETTER("effect_parameter_as_string", EffectParameter, AsString, resolver)
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef PKMNLIB_WASMEFFECTPARAMETER_HPP
|
||||||
|
#define PKMNLIB_WASMEFFECTPARAMETER_HPP
|
||||||
|
#include "../../WebAssemblyScriptResolver.hpp"
|
||||||
|
|
||||||
|
class WASMEffectParameter {
|
||||||
|
public:
|
||||||
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PKMNLIB_WASMEFFECTPARAMETER_HPP
|
|
@ -7,8 +7,7 @@ class WebAssemblyScriptResolver;
|
||||||
|
|
||||||
class WASMFormeRegistry {
|
class WASMFormeRegistry {
|
||||||
public:
|
public:
|
||||||
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver);
|
||||||
WebAssemblyScriptResolver* resolver);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PKMNLIB_WASMFORMEREGISTRY_HPP
|
#endif // PKMNLIB_WASMFORMEREGISTRY_HPP
|
||||||
|
|
|
@ -5,11 +5,14 @@
|
||||||
#include "../WebAssemblyScriptResolver.hpp"
|
#include "../WebAssemblyScriptResolver.hpp"
|
||||||
#include "Arbutils/Collections/Dictionary.hpp"
|
#include "Arbutils/Collections/Dictionary.hpp"
|
||||||
#include "Library/LibraryMethods.hpp"
|
#include "Library/LibraryMethods.hpp"
|
||||||
|
#include "Library/WASMAbilityRegistry.hpp"
|
||||||
|
#include "Library/WASMEffectParameter.hpp"
|
||||||
|
#include "Library/WASMFormeRegistry.hpp"
|
||||||
#include "Library/WASMItemRegistry.hpp"
|
#include "Library/WASMItemRegistry.hpp"
|
||||||
#include "Library/WASMMoveDataRegistry.hpp"
|
#include "Library/WASMMoveDataRegistry.hpp"
|
||||||
#include "Library/WASMSpeciesRegistry.hpp"
|
#include "Library/WASMSpeciesRegistry.hpp"
|
||||||
#include "Library/WASMFormeRegistry.hpp"
|
|
||||||
#include "WASMCoreMethods.hpp"
|
#include "WASMCoreMethods.hpp"
|
||||||
|
#include "WASMListRegistry.hpp"
|
||||||
#include "WASMStringView.hpp"
|
#include "WASMStringView.hpp"
|
||||||
|
|
||||||
class TypeRegistry {
|
class TypeRegistry {
|
||||||
|
@ -17,12 +20,15 @@ public:
|
||||||
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver) {
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver) {
|
||||||
WASMCoreMethods::Register(externs, resolver);
|
WASMCoreMethods::Register(externs, resolver);
|
||||||
WASMStringView::Register(externs, resolver);
|
WASMStringView::Register(externs, resolver);
|
||||||
|
WASMListRegistry::Register(externs, resolver);
|
||||||
|
|
||||||
LibraryMethods::Register(externs, resolver);
|
LibraryMethods::Register(externs, resolver);
|
||||||
|
WASMEffectParameter::Register(externs, resolver);
|
||||||
WASMMoveDataRegistry::Register(externs, resolver);
|
WASMMoveDataRegistry::Register(externs, resolver);
|
||||||
WASMItemRegistry::Register(externs, resolver);
|
WASMItemRegistry::Register(externs, resolver);
|
||||||
WASMSpeciesRegistry::Register(externs, resolver);
|
WASMSpeciesRegistry::Register(externs, resolver);
|
||||||
WASMFormeRegistry::Register(externs, resolver);
|
WASMFormeRegistry::Register(externs, resolver);
|
||||||
|
WASMAbilityRegistry::Register(externs, resolver);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef PKMNLIB_HELPERFILE_H
|
#ifndef PKMNLIB_HELPERFILE_H
|
||||||
#define PKMNLIB_HELPERFILE_H
|
#define PKMNLIB_HELPERFILE_H
|
||||||
#include <Arbutils/Memory/Memory.hpp>
|
#include <Arbutils/Memory/Memory.hpp>
|
||||||
|
#include <cxxabi.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -122,8 +123,10 @@ private:
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same<T, const ArbUt::StringView&>()) {
|
} else if constexpr (std::is_same<T, const ArbUt::StringView&>()) {
|
||||||
return wasm_valtype_new_i64();
|
return wasm_valtype_new_i64();
|
||||||
|
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
||||||
|
return wasm_valtype_new_i64();
|
||||||
}
|
}
|
||||||
THROW("Unhandled value type: ", std::string(typeid(T).name()));
|
THROW("Unhandled value type: ", std::string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> inline static wasm_val_t ToVal(const T& val) {
|
template <typename T> inline static wasm_val_t ToVal(const T& val) {
|
||||||
|
@ -150,6 +153,9 @@ private:
|
||||||
} else if constexpr (std::is_same<T, const ArbUt::StringView&>()) {
|
} else if constexpr (std::is_same<T, const ArbUt::StringView&>()) {
|
||||||
auto v = &val;
|
auto v = &val;
|
||||||
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
||||||
|
} else if constexpr (is_specialization<T, ArbUt::List>()) {
|
||||||
|
auto v = &val;
|
||||||
|
return WASM_I64_VAL(reinterpret_cast<i64>(v));
|
||||||
}
|
}
|
||||||
THROW("Unhandled value type: ", typeid(T).name());
|
THROW("Unhandled value type: ", typeid(T).name());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include "WASMListRegistry.hpp"
|
||||||
|
#include "WASMHelperFile.hpp"
|
||||||
|
|
||||||
|
wasm_func_t* List_GetLength(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<size_t, const ArbUt::List<void*>*>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list) -> size_t { return list->Count(); }});
|
||||||
|
}
|
||||||
|
|
||||||
|
wasm_func_t* List_GetValue(WebAssemblyScriptResolver* resolver) {
|
||||||
|
return WasmHelpers::CreateFunc<void*, const ArbUt::List<void*>*, size_t>(
|
||||||
|
resolver, {[](WebAssemblyScriptResolver*, const ArbUt::List<void*>* list, size_t index) -> void* {
|
||||||
|
return list->At(index);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
void WASMListRegistry::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
|
WebAssemblyScriptResolver* resolver) {
|
||||||
|
externs.Insert("list_get_length", List_GetLength(resolver));
|
||||||
|
externs.Insert("list_get_at", List_GetValue(resolver));
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef PKMNLIB_WASMLISTREGISTRY_HPP
|
||||||
|
#define PKMNLIB_WASMLISTREGISTRY_HPP
|
||||||
|
#include "../WebAssemblyScriptResolver.hpp"
|
||||||
|
|
||||||
|
class WASMListRegistry {
|
||||||
|
public:
|
||||||
|
static void Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs, WebAssemblyScriptResolver* resolver);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PKMNLIB_WASMLISTREGISTRY_HPP
|
|
@ -23,6 +23,6 @@ wasm_func_t* ConstString_GetStr(WebAssemblyScriptResolver* resolver) {
|
||||||
|
|
||||||
void WASMStringView::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
void WASMStringView::Register(ArbUt::Dictionary<std::string, wasm_func_t*>& externs,
|
||||||
WebAssemblyScriptResolver* resolver) {
|
WebAssemblyScriptResolver* resolver) {
|
||||||
externs.Insert("arbutils_const_string_get_hash", ConstString_GetHash(resolver));
|
externs.Insert("const_string_get_hash", ConstString_GetHash(resolver));
|
||||||
externs.Insert("arbutils_const_string_get_str", ConstString_GetStr(resolver));
|
externs.Insert("const_string_get_str", ConstString_GetStr(resolver));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// This file documents the entire interface API currently used by the WebAssembly script resolver.
|
// This file documents the entire Host interface API currently used by the WebAssembly script resolver, so the methods
|
||||||
|
// that can be used from the client wasm.
|
||||||
// Currently, we only define a bunch of functions, but in the future when interface types are actually implemented,
|
// Currently, we only define a bunch of functions, but in the future when interface types are actually implemented,
|
||||||
// we'd like to implement those as well.
|
// we'd like to implement those as well.
|
||||||
|
|
||||||
|
@ -11,10 +12,15 @@ _print: function(i32 message_pointer, s32 message_length)
|
||||||
|
|
||||||
// StringView class
|
// StringView class
|
||||||
type const_string = u64;
|
type const_string = u64;
|
||||||
arbutils_const_string_get_hash: function(const_string ptr) -> u32
|
const_string_get_hash: function(const_string ptr) -> u32
|
||||||
// Returns a pointer to the WASM memory where the string can be found.
|
// Returns a pointer to the WASM memory where the string can be found.
|
||||||
// NOTE: This requires us to copy the string into WASM memory.
|
// NOTE: This requires us to copy the string into WASM memory.
|
||||||
arbutils_const_string_get_str: function(const_string ptr) -> s32
|
const_string_get_str: function(const_string ptr) -> s32
|
||||||
|
|
||||||
|
// List class
|
||||||
|
type list = u64
|
||||||
|
list_get_length: function(list) -> u64
|
||||||
|
list_get_at: function(list, u64) -> u64
|
||||||
|
|
||||||
// Library types
|
// Library types
|
||||||
type pokemon_library = u64
|
type pokemon_library = u64
|
||||||
|
@ -149,5 +155,4 @@ forme_get_hidden_ability_count: function(forme) -> u64
|
||||||
forme_get_ability: function(forme, bool hidden, u8 index) -> ability
|
forme_get_ability: function(forme, bool hidden, u8 index) -> ability
|
||||||
forme_has_flag_by_hash: function(forme, u32) -> bool
|
forme_has_flag_by_hash: function(forme, u32) -> bool
|
||||||
|
|
||||||
|
// Ability class
|
||||||
|
|
|
@ -27,10 +27,11 @@ WebAssemblyBattleScript::~WebAssemblyBattleScript() {
|
||||||
func.Call();
|
func.Call();
|
||||||
|
|
||||||
void WebAssemblyBattleScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library,
|
void WebAssemblyBattleScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library,
|
||||||
const ArbUt::List<CreatureLib::Library::EffectParameter*>&) {
|
const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
|
||||||
WASM_CALL(Initialize, "script_on_initialize", 2, 0, {
|
WASM_CALL(Initialize, "script_on_initialize", 3, 0, {
|
||||||
func.Loadi32(0, _wasmPtr);
|
func.Loadi32(0, _wasmPtr);
|
||||||
func.LoadExternRef(1, library);
|
func.LoadExternRef(1, library);
|
||||||
|
func.LoadExternRef(2, ¶meters);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue