2020-01-11 21:30:23 +00:00
|
|
|
#ifndef PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
|
|
|
#define PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
|
|
|
|
|
|
|
#include <Battling/ScriptHandling/ScriptResolver.hpp>
|
|
|
|
#include "../Battling/Library/BattleLibrary.hpp"
|
|
|
|
|
2020-01-12 17:20:59 +00:00
|
|
|
#define ANGELSCRIPT_DLL_LIBRARY_IMPORT
|
2020-01-11 21:30:23 +00:00
|
|
|
#include <angelscript.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "AngelScriptScript.hpp"
|
|
|
|
#include "AngelScriptTypeInfo.hpp"
|
|
|
|
|
|
|
|
class AngelScripResolver : public CreatureLib::Battling::ScriptResolver {
|
|
|
|
private:
|
|
|
|
asIScriptEngine* _engine = nullptr;
|
|
|
|
asIScriptModule* _mainModule = nullptr;
|
|
|
|
ContextPool* _contextPool = nullptr;
|
|
|
|
const char* (*_loadFunc)(const char*) = nullptr;
|
|
|
|
std::unordered_map<std::string, AngelScriptTypeInfo*> _types;
|
|
|
|
|
|
|
|
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
|
|
|
static void Print(const std::string& str) { std::cout << str << std::endl; }
|
|
|
|
AngelScriptTypeInfo* GetTypeInfo(const std::string& name);
|
|
|
|
|
|
|
|
public:
|
|
|
|
~AngelScripResolver() override {
|
|
|
|
delete _contextPool;
|
|
|
|
for (const auto& type : _types) {
|
|
|
|
delete type.second;
|
|
|
|
}
|
|
|
|
_types.clear();
|
|
|
|
_engine->ShutDownAndRelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Initialize(CreatureLib::Battling::BattleLibrary* library) override;
|
|
|
|
|
|
|
|
void SetCreateFunction(const char* (*loadFunc)(const char* scriptName)) { _loadFunc = loadFunc; }
|
|
|
|
|
|
|
|
void CreateScript(const char* scriptName);
|
|
|
|
|
|
|
|
void FinalizeModule();
|
|
|
|
|
|
|
|
CreatureLib::Battling::Script* LoadScript(ScriptCategory category, const std::string& scriptName) override;
|
|
|
|
};
|
|
|
|
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|