From 98e17a1eb8a513c1830a80b08b155309c90b6a57 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 23 Feb 2020 16:02:27 +0100 Subject: [PATCH] Move script name to type. --- CMakeLists.txt | 2 +- conanfile.py | 14 +++++++------- src/Battling/PkmnScript.hpp | 2 -- .../AngelScript/AngelScripResolver.cpp | 16 ++++++++-------- .../AngelScript/AngelScripResolver.hpp | 2 +- .../AngelScript/AngelScriptScript.hpp | 6 ++++-- .../AngelScript/AngelScriptTypeInfo.hpp | 8 +++++++- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c296068..c031596 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) endif() if (NOT WINDOWS) execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing - -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s build_type=Debug) + -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION}) else() execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing -s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows) diff --git a/conanfile.py b/conanfile.py index a67f642..24c6d3b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -34,8 +34,8 @@ class PkmnLibConan(ConanFile): def imports(self): - if self.settings.os == "Windows": - self.copy("*.dll", "bin", "bin") + if self.settings.os == "Windows": + self.copy("*.dll", "bin", "bin") def configure(self): @@ -45,8 +45,8 @@ class PkmnLibConan(ConanFile): self.options["AngelScript"].link_std_statically = True def requirements(self): - self.requires("CreatureLib/latest@epsilon/master") - if self.options.script_handler == "angelscript": - self.requires("AngelScript/2.34@AngelScript/Deukhoofd") - else: - raise ConanInvalidConfiguration("Invalid Script Handler was specified: " + self.options.script_handler) \ No newline at end of file + self.requires("CreatureLib/latest@epsilon/master") + if self.options.script_handler == "angelscript": + self.requires("AngelScript/2.34@AngelScript/Deukhoofd") + else: + raise ConanInvalidConfiguration("Invalid Script Handler was specified: " + self.options.script_handler) \ No newline at end of file diff --git a/src/Battling/PkmnScript.hpp b/src/Battling/PkmnScript.hpp index 8f3e3b6..b4bdc9c 100644 --- a/src/Battling/PkmnScript.hpp +++ b/src/Battling/PkmnScript.hpp @@ -6,8 +6,6 @@ namespace PkmnLib::Battling{ class PkmnScript : public CreatureLib::Battling::Script{ public: - PkmnScript(const std::string& name) : Script(name) {} - virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){}; }; diff --git a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp index fcc5abc..9e1b991 100644 --- a/src/ScriptResolving/AngelScript/AngelScripResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScripResolver.cpp @@ -85,18 +85,18 @@ void AngelScripResolver::RegisterTypes() { BasicScriptClass::Register(_engine); } -AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name) { - auto find = _types.find(name); +AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name, const std::string& decl) { + auto find = _types.find(decl); if (find != _types.end()) { return find->second; } - auto type = _mainModule->GetTypeInfoByDecl(name.c_str()); + auto type = _mainModule->GetTypeInfoByDecl(decl.c_str()); if (type == nullptr) { - _types.insert({name, nullptr}); + _types.insert({decl, nullptr}); return nullptr; } - auto typeinfo = new AngelScriptTypeInfo(type); - _types.insert({name, typeinfo}); + auto typeinfo = new AngelScriptTypeInfo(name, type); + _types.insert({decl, typeinfo}); return typeinfo; } void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) { @@ -123,13 +123,13 @@ static constexpr const char* GetCategoryNamespace(ScriptCategory category) { CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) { std::stringstream decl; decl << GetCategoryNamespace(category) << "::" << scriptName; - auto typeInfo = GetTypeInfo(decl.str()); + auto typeInfo = GetTypeInfo(scriptName, decl.str()); if (typeInfo == nullptr) return nullptr; auto ctx = _contextPool->RequestContext(); auto obj = typeInfo->Instantiate(ctx); _contextPool->ReturnContextToPool(ctx); - return new AngelScriptScript(scriptName, typeInfo, obj, _contextPool); + return new AngelScriptScript(typeInfo, obj, _contextPool); } void AngelScripResolver::FinalizeModule() { int r = _builder.BuildModule(); diff --git a/src/ScriptResolving/AngelScript/AngelScripResolver.hpp b/src/ScriptResolving/AngelScript/AngelScripResolver.hpp index 5346924..f314009 100644 --- a/src/ScriptResolving/AngelScript/AngelScripResolver.hpp +++ b/src/ScriptResolving/AngelScript/AngelScripResolver.hpp @@ -21,7 +21,7 @@ private: 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); + AngelScriptTypeInfo* GetTypeInfo(const std::string& name, const std::string& decl); void RegisterTypes(); diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index c1314d1..693e242 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -16,11 +16,13 @@ private: asIScriptObject* _obj = nullptr; public: - AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool) - : PkmnLib::Battling::PkmnScript(name), _type(type), _ctxPool(ctxPool), _obj(obj) {} + AngelScriptScript(AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool) + : _type(type), _ctxPool(ctxPool), _obj(obj) {} ~AngelScriptScript() override { _obj->Release(); } + [[nodiscard]] const std::string& GetName() const override { return _type->GetName(); } + asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) { auto func = _type->GetFunction(name); ctx->Prepare(func); diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index 8dfe6b4..dcb4c58 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -6,11 +6,13 @@ #include #include #include +#include class AngelScriptTypeInfo { private: asITypeInfo* _type = nullptr; std::unordered_map _functions; + std::string _name; struct FunctionInfo { bool Exists = false; @@ -29,7 +31,7 @@ private: } public: - explicit AngelScriptTypeInfo(asITypeInfo* type) : _type(type) {} + explicit AngelScriptTypeInfo(std::string name, asITypeInfo* type) : _type(type), _name(std::move(name)) {} ~AngelScriptTypeInfo() { for (const auto& f : _functions) { f.second->Release(); @@ -37,6 +39,10 @@ public: _functions.clear(); } + const std::string& GetName() const{ + return _name; + } + asIScriptFunction* GetFunction(const std::string& functionName) { auto find = _functions.find(functionName); if (find != _functions.end()) {