Move script name to type.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
13a8228a44
commit
98e17a1eb8
|
@ -38,7 +38,7 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
endif()
|
endif()
|
||||||
if (NOT WINDOWS)
|
if (NOT WINDOWS)
|
||||||
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
|
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()
|
else()
|
||||||
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
|
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)
|
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows)
|
||||||
|
|
14
conanfile.py
14
conanfile.py
|
@ -34,8 +34,8 @@ class PkmnLibConan(ConanFile):
|
||||||
|
|
||||||
|
|
||||||
def imports(self):
|
def imports(self):
|
||||||
if self.settings.os == "Windows":
|
if self.settings.os == "Windows":
|
||||||
self.copy("*.dll", "bin", "bin")
|
self.copy("*.dll", "bin", "bin")
|
||||||
|
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
|
@ -45,8 +45,8 @@ class PkmnLibConan(ConanFile):
|
||||||
self.options["AngelScript"].link_std_statically = True
|
self.options["AngelScript"].link_std_statically = True
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("CreatureLib/latest@epsilon/master")
|
self.requires("CreatureLib/latest@epsilon/master")
|
||||||
if self.options.script_handler == "angelscript":
|
if self.options.script_handler == "angelscript":
|
||||||
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
||||||
else:
|
else:
|
||||||
raise ConanInvalidConfiguration("Invalid Script Handler was specified: " + self.options.script_handler)
|
raise ConanInvalidConfiguration("Invalid Script Handler was specified: " + self.options.script_handler)
|
|
@ -6,8 +6,6 @@
|
||||||
namespace PkmnLib::Battling{
|
namespace PkmnLib::Battling{
|
||||||
class PkmnScript : public CreatureLib::Battling::Script{
|
class PkmnScript : public CreatureLib::Battling::Script{
|
||||||
public:
|
public:
|
||||||
PkmnScript(const std::string& name) : Script(name) {}
|
|
||||||
|
|
||||||
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
|
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
|
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
|
||||||
};
|
};
|
||||||
|
|
|
@ -85,18 +85,18 @@ void AngelScripResolver::RegisterTypes() {
|
||||||
BasicScriptClass::Register(_engine);
|
BasicScriptClass::Register(_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name) {
|
AngelScriptTypeInfo* AngelScripResolver::GetTypeInfo(const std::string& name, const std::string& decl) {
|
||||||
auto find = _types.find(name);
|
auto find = _types.find(decl);
|
||||||
if (find != _types.end()) {
|
if (find != _types.end()) {
|
||||||
return find->second;
|
return find->second;
|
||||||
}
|
}
|
||||||
auto type = _mainModule->GetTypeInfoByDecl(name.c_str());
|
auto type = _mainModule->GetTypeInfoByDecl(decl.c_str());
|
||||||
if (type == nullptr) {
|
if (type == nullptr) {
|
||||||
_types.insert({name, nullptr});
|
_types.insert({decl, nullptr});
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto typeinfo = new AngelScriptTypeInfo(type);
|
auto typeinfo = new AngelScriptTypeInfo(name, type);
|
||||||
_types.insert({name, typeinfo});
|
_types.insert({decl, typeinfo});
|
||||||
return typeinfo;
|
return typeinfo;
|
||||||
}
|
}
|
||||||
void AngelScripResolver::MessageCallback(const asSMessageInfo* msg, void* param) {
|
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) {
|
CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory category, const std::string& scriptName) {
|
||||||
std::stringstream decl;
|
std::stringstream decl;
|
||||||
decl << GetCategoryNamespace(category) << "::" << scriptName;
|
decl << GetCategoryNamespace(category) << "::" << scriptName;
|
||||||
auto typeInfo = GetTypeInfo(decl.str());
|
auto typeInfo = GetTypeInfo(scriptName, decl.str());
|
||||||
if (typeInfo == nullptr)
|
if (typeInfo == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto ctx = _contextPool->RequestContext();
|
auto ctx = _contextPool->RequestContext();
|
||||||
auto obj = typeInfo->Instantiate(ctx);
|
auto obj = typeInfo->Instantiate(ctx);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
return new AngelScriptScript(scriptName, typeInfo, obj, _contextPool);
|
return new AngelScriptScript(typeInfo, obj, _contextPool);
|
||||||
}
|
}
|
||||||
void AngelScripResolver::FinalizeModule() {
|
void AngelScripResolver::FinalizeModule() {
|
||||||
int r = _builder.BuildModule();
|
int r = _builder.BuildModule();
|
||||||
|
|
|
@ -21,7 +21,7 @@ private:
|
||||||
|
|
||||||
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
||||||
static void Print(const std::string& str) { std::cout << str << std::endl; }
|
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();
|
void RegisterTypes();
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,13 @@ private:
|
||||||
asIScriptObject* _obj = nullptr;
|
asIScriptObject* _obj = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
AngelScriptScript(AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
||||||
: PkmnLib::Battling::PkmnScript(name), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
: _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||||
|
|
||||||
~AngelScriptScript() override { _obj->Release(); }
|
~AngelScriptScript() override { _obj->Release(); }
|
||||||
|
|
||||||
|
[[nodiscard]] const std::string& GetName() const override { return _type->GetName(); }
|
||||||
|
|
||||||
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
|
asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) {
|
||||||
auto func = _type->GetFunction(name);
|
auto func = _type->GetFunction(name);
|
||||||
ctx->Prepare(func);
|
ctx->Prepare(func);
|
||||||
|
|
|
@ -6,11 +6,13 @@
|
||||||
#include <angelscript.h>
|
#include <angelscript.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class AngelScriptTypeInfo {
|
class AngelScriptTypeInfo {
|
||||||
private:
|
private:
|
||||||
asITypeInfo* _type = nullptr;
|
asITypeInfo* _type = nullptr;
|
||||||
std::unordered_map<std::string, asIScriptFunction*> _functions;
|
std::unordered_map<std::string, asIScriptFunction*> _functions;
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
struct FunctionInfo {
|
struct FunctionInfo {
|
||||||
bool Exists = false;
|
bool Exists = false;
|
||||||
|
@ -29,7 +31,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AngelScriptTypeInfo(asITypeInfo* type) : _type(type) {}
|
explicit AngelScriptTypeInfo(std::string name, asITypeInfo* type) : _type(type), _name(std::move(name)) {}
|
||||||
~AngelScriptTypeInfo() {
|
~AngelScriptTypeInfo() {
|
||||||
for (const auto& f : _functions) {
|
for (const auto& f : _functions) {
|
||||||
f.second->Release();
|
f.second->Release();
|
||||||
|
@ -37,6 +39,10 @@ public:
|
||||||
_functions.clear();
|
_functions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& GetName() const{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
asIScriptFunction* GetFunction(const std::string& functionName) {
|
asIScriptFunction* GetFunction(const std::string& functionName) {
|
||||||
auto find = _functions.find(functionName);
|
auto find = _functions.find(functionName);
|
||||||
if (find != _functions.end()) {
|
if (find != _functions.end()) {
|
||||||
|
|
Loading…
Reference in New Issue