diff --git a/.drone.yml b/.drone.yml index fe5507f..ff1367e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -61,6 +61,5 @@ steps: - cmake --build build-release-windows --target all -- -j 4 - cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll /drone/src/build-release-windows/bin/ - cp /drone/src/build-release-windows/lib/libpkmnLib.so /drone/src/build-release-windows/bin/ - - cp /drone/src/build-release-windows/lib/libpkmnLib-angelscript.so /drone/src/build-release-windows/bin/ - export WINEARCH=win64 - wine build-release-windows/bin/pkmnLibTests.exe -s \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 57be2bc..7380e9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,12 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") endif(WINDOWS) - message(STATUS "Using: \t C ${CMAKE_C_COMPILER} \t C++ ${CMAKE_CXX_COMPILER} \t CXX ABI ${CMAKE_CXX_COMPILER_ABI} \t C++ Version ${CMAKE_CXX_STANDARD}") -message(STATUS "Script Provider: ${SCRIPT_PROVIDER}") if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.") @@ -39,7 +37,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} -o AngelScript:shared=True) + -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) @@ -54,42 +52,57 @@ foreach (_conanLib ${CONAN_LIBS}) endforeach() # Create Core library with files in src/Core -file(GLOB_RECURSE CORE_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "src/Library/*.cpp" "src/Library/*.hpp") +SET(FILE_SOURCE + "src/Battling/*.cpp" + "src/Battling/*.hpp" + "src/Library/*.cpp" + "src/Library/*.hpp" + ) +if (SCRIPT_PROVIDER STREQUAL "angelscript") + SET(FILE_SOURCE ${FILE_SOURCE} + "src/AngelScript/AngelScripResolver.cpp" + "src/AngelScript/AngelScripResolver.hpp" + "src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp" + "src/AngelScript/TypeRegistry/RegisterPokemonTypes.hpp" + "extern/angelscript_addons/*.cpp" + "extern/angelscript_addons/*.h" + ) +endif() +message(STATUS "${FILE_SOURCE}") +file(GLOB_RECURSE CORE_SRC_FILES ${FILE_SOURCE}) + add_library(pkmnLib SHARED ${CORE_SRC_FILES}) +foreach (_variableName ${CONAN_LIBS}) + message(STATUS "Lib: ${_variableName}") +endforeach() + SET(_LINKS CreatureLibCore CreatureLibLibrary CreatureLibBattling) SET(_TESTLINKS pkmnLib CreatureLibCore CreatureLibLibrary CreatureLibBattling) +if (SCRIPT_PROVIDER STREQUAL "angelscript") + SET(_LINKS angelscript ${_LINKS} ) + SET(_TESTLINKS angelscript ${_TESTLINKS} ) +endif() + if (WINDOWS) message(STATUS "Using Windows build.") - set(CMAKE_CXX_FLAGS "-L ${CMAKE_BINARY_DIR}/bin") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition") # Statically link libraries we need in Windows. SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++) SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++) endif (WINDOWS) -if (SCRIPT_PROVIDER STREQUAL "angelscript") - message(STATUS "Creating angelscript implementation.") - file(GLOB_RECURSE ANGELSCRIPT_SRC_FILES "src/AngelScript/*.cpp" "src/AngelScript/*.hpp" "extern/angelscript_addons/*.cpp" "extern/angelscript_addons/*.h") - add_library(pkmnLib-angelscript SHARED ${ANGELSCRIPT_SRC_FILES} ) - SET(SCRIPT_PROVIDER_LIB_NAME "pkmnLib-angelscript") - SET(_LINKS ${_LINKS} angelscript) -endif() - target_link_libraries(pkmnLib PUBLIC ${_LINKS}) -if (SCRIPT_PROVIDER STREQUAL "angelscript") - SET(GCC_COVERAGE_COMPILE_FLAGS "-fno-strict-aliasing") - target_link_libraries(pkmnLib-angelscript PUBLIC ${_LINKS}) -endif() - if (NOT DEFINED CONAN_EXPORTED) # Create Test executable file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp") add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp) - target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS} ${SCRIPT_PROVIDER_LIB_NAME}) + message(STATUS "${_TESTLINKS}") + target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS}) # Add a definition for the test library target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) @@ -100,3 +113,4 @@ endif () + diff --git a/conanfile.py b/conanfile.py index f9d89db..eecd1c0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,5 @@ from conans import ConanFile, CMake +from conans.errors import ConanInvalidConfiguration class PkmnLibConan(ConanFile): @@ -7,14 +8,11 @@ class PkmnLibConan(ConanFile): url = "https://git.p-epsilon.com/Deukhoofd/CreatureLib" description = "The core implementation for turn based battling using creatures." settings = "os", "compiler" - options = {"shared": [True, False]} - default_options = {"shared": True} + options = {"shared": [True, False], "script_handler": ["angelscript"]} + default_options = {"shared": True, "script_handler": "angelscript"} generators = "cmake" exports_sources = "*" compiler = "clang" - requires = \ - "CreatureLib/779f0b08cfc7d2b19ee0bd27c61a28807172bc1f@creaturelib/master", \ - "AngelScript/2.34@AngelScript/Deukhoofd" def build(self): cmake = CMake(self) @@ -33,3 +31,17 @@ class PkmnLibConan(ConanFile): def imports(self): if self.settings.os == "Windows": self.copy("*.dll", "bin", "bin") + + + def configure(self): + if self.options.script_handler == "angelscript": + self.options["AngelScript"].shared = True + if self.settings.os == "Windows": + self.options["AngelScript"].link_std_statically = True + + def requirements(self): + self.requires("CreatureLib/b02577554f4dfe2141318a440fc99c11de97daca@creaturelib/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/extern/angelscript_addons/scripthelper/scripthelper.cpp b/extern/angelscript_addons/scripthelper/scripthelper.cpp index 4af4fde..e70f075 100644 --- a/extern/angelscript_addons/scripthelper/scripthelper.cpp +++ b/extern/angelscript_addons/scripthelper/scripthelper.cpp @@ -975,7 +975,8 @@ string ScriptGetExceptionInfo() void RegisterExceptionRoutines(asIScriptEngine *engine) { - int r; + [[maybe_unused]] + int r; // The string type must be available assert(engine->GetTypeInfoByDecl("string")); diff --git a/extern/angelscript_addons/scriptstdstring/scriptstdstring_utils.cpp b/extern/angelscript_addons/scriptstdstring/scriptstdstring_utils.cpp index 54662aa..9b11243 100644 --- a/extern/angelscript_addons/scriptstdstring/scriptstdstring_utils.cpp +++ b/extern/angelscript_addons/scriptstdstring/scriptstdstring_utils.cpp @@ -112,7 +112,8 @@ static void StringJoin_Generic(asIScriptGeneric *gen) // The string type must have been registered first. void RegisterStdStringUtils(asIScriptEngine *engine) { - int r; + [[maybe_unused]] + int r; if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") ) { diff --git a/src/AngelScript/AngelScripResolver.cpp b/src/AngelScript/AngelScripResolver.cpp index 4c6f8cc..8ec1540 100644 --- a/src/AngelScript/AngelScripResolver.cpp +++ b/src/AngelScript/AngelScripResolver.cpp @@ -6,6 +6,7 @@ CreatureLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver(){ return new AngelScripResolver(); } + void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* library) { _engine = asCreateScriptEngine(); diff --git a/src/AngelScript/AngelScripResolver.hpp b/src/AngelScript/AngelScripResolver.hpp index 3c6ee40..8184903 100644 --- a/src/AngelScript/AngelScripResolver.hpp +++ b/src/AngelScript/AngelScripResolver.hpp @@ -4,9 +4,8 @@ #include #include "../Battling/Library/BattleLibrary.hpp" -#undef GetProperty +#define ANGELSCRIPT_DLL_LIBRARY_IMPORT #include -#include #include #include "AngelScriptScript.hpp" #include "AngelScriptTypeInfo.hpp" diff --git a/src/AngelScript/AngelScriptScript.cpp b/src/AngelScript/AngelScriptScript.cpp index 4afb7d5..97d92e6 100644 --- a/src/AngelScript/AngelScriptScript.cpp +++ b/src/AngelScript/AngelScriptScript.cpp @@ -1,2 +1 @@ -#undef GetProperty #include "AngelScriptScript.hpp" diff --git a/src/AngelScript/AngelScriptScript.hpp b/src/AngelScript/AngelScriptScript.hpp index 6504579..d3a9917 100644 --- a/src/AngelScript/AngelScriptScript.hpp +++ b/src/AngelScript/AngelScriptScript.hpp @@ -1,7 +1,7 @@ #ifndef PKMNLIB_ANGELSCRIPTSCRIPT_HPP #define PKMNLIB_ANGELSCRIPTSCRIPT_HPP #include -#undef GetProperty +#define ANGELSCRIPT_DLL_LIBRARY_IMPORT #include #include "AngelScriptTypeInfo.hpp" #include "ContextPool.hpp" @@ -15,20 +15,20 @@ private: public: AngelScriptScript(const std::string& name, AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool) - : CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) { - } + : CreatureLib::Battling::Script(name), _type(type), _ctxPool(ctxPool), _obj(obj) {} ~AngelScriptScript() override { _obj->Release(); } void InvokeMethod(const char* name) { auto func = _type->GetFunction(name); - if (func == nullptr) return; + if (func == nullptr) + return; auto ctx = _ctxPool->RequestContext(); ctx->Prepare(func); ctx->SetObject(_obj); auto result = ctx->Execute(); - if (result != asEXECUTION_FINISHED){ - if (result == asEXECUTION_EXCEPTION){ + if (result != asEXECUTION_FINISHED) { + if (result == asEXECUTION_EXCEPTION) { throw CreatureException(ctx->GetExceptionString()); } throw CreatureException("Function failed."); @@ -36,20 +36,16 @@ public: _ctxPool->ReturnContextToPool(ctx); } - asIScriptObject* GetScriptObject(){ - return _obj; - } + asIScriptObject* GetScriptObject() { return _obj; } - asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx){ + asIScriptFunction* PrepareMethod(const char* name, asIScriptContext* ctx) { auto func = _type->GetFunction(name); ctx->Prepare(func); ctx->SetObject(_obj); return func; } - ContextPool* GetContextPool(){ - return _ctxPool; - } + ContextPool* GetContextPool() { return _ctxPool; } }; #endif // PKMNLIB_ANGELSCRIPTSCRIPT_HPP diff --git a/src/AngelScript/AngelScriptTypeInfo.hpp b/src/AngelScript/AngelScriptTypeInfo.hpp index 6d15c9d..74a8e94 100644 --- a/src/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/AngelScript/AngelScriptTypeInfo.hpp @@ -1,6 +1,7 @@ #ifndef PKMNLIB_ANGELSCRIPTTYPEINFO_HPP #define PKMNLIB_ANGELSCRIPTTYPEINFO_HPP +#define ANGELSCRIPT_DLL_LIBRARY_IMPORT #include #include #include diff --git a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp index 6f59b96..e45537c 100644 --- a/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp +++ b/src/AngelScript/TypeRegistry/RegisterPokemonTypes.cpp @@ -8,13 +8,14 @@ void RegisterPokemonTypes::Register(asIScriptEngine* engine) { } void RegisterPokemonTypes::RegisterGenderEnum(asIScriptEngine* engine) { - int r = engine->RegisterEnum("Gender"); assert(r >= 0); + [[maybe_unused]] int r = engine->RegisterEnum("Gender"); assert(r >= 0); r = engine->RegisterEnumValue("Gender", "Male", 0); assert(r >= 0); r = engine->RegisterEnumValue("Gender", "Female", 1); assert(r >= 0); r = engine->RegisterEnumValue("Gender", "Genderless", 2); assert(r >= 0); } void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) { + [[maybe_unused]] int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); r = engine->RegisterObjectMethod("Species", "const string& get_Name() const property", @@ -32,5 +33,4 @@ void RegisterPokemonTypes::RegisterSpeciesType(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const", asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL); assert(r >= 0); - } diff --git a/src/Battling/Pokemon/CreatePokemon.cpp b/src/Battling/Pokemon/CreatePokemon.cpp index 0afdf3a..00f4282 100644 --- a/src/Battling/Pokemon/CreatePokemon.cpp +++ b/src/Battling/Pokemon/CreatePokemon.cpp @@ -1,5 +1,5 @@ #include "CreatePokemon.hpp" -#include "../../Library/Statistic.hpp" + PkmnLib::Battling::CreatePokemon* PkmnLib::Battling::CreatePokemon::WithRandomIndividualValues(CreatureLib::Core::Random rand) { _ivHp = rand.Get(0, 32); _ivAttack = rand.Get(0, 32); diff --git a/src/Battling/Pokemon/Pokemon.hpp b/src/Battling/Pokemon/Pokemon.hpp index b894617..23d4417 100644 --- a/src/Battling/Pokemon/Pokemon.hpp +++ b/src/Battling/Pokemon/Pokemon.hpp @@ -30,10 +30,10 @@ namespace PkmnLib::Battling { _individualValues(individualValues), _effortValues(effortValues), _nature(nature) {} const Library::Nature& GetNature() const; - const uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { + uint8_t GetIndividualValue(CreatureLib::Core::Statistic stat) const { return _individualValues.GetStat(stat); } - const uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); } + uint8_t GetEffortValue(CreatureLib::Core::Statistic stat) const { return _effortValues.GetStat(stat); } }; } diff --git a/tests/ScriptTests/ScriptResolverTests.cpp b/tests/ScriptTests/ScriptResolverTests.cpp index beed455..4b195a9 100644 --- a/tests/ScriptTests/ScriptResolverTests.cpp +++ b/tests/ScriptTests/ScriptResolverTests.cpp @@ -126,5 +126,4 @@ TEST_CASE("Test whether species object was properly registered.") { } - #endif \ No newline at end of file