From 4ade8f0dca0b9f6f2c38521accb6f6457dec77c9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 26 Mar 2021 15:28:24 +0100 Subject: [PATCH] Adds Angelscript functions for getting a battle side, and swapping positions on it. --- CMakeLists.txt | 18 ++++++------------ CmakeConanSetup.cmake | 2 +- .../Battling/RegisterBattleClass.cpp | 18 ++++++++++++++++++ .../Battling/RegisterBattleClass.hpp | 1 + 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ad410b..c02a742 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project(pkmnLib) add_compile_options(-Wall -Wextra -Werror) # We like new stuff, so set the c++ standard to c++20. set(CMAKE_CXX_STANDARD 20) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(WINDOWS "Whether the build target is Windows or not." OFF) option(SHARED "Whether we should build a shared library, instead of a static one." OFF) @@ -135,26 +136,19 @@ if (WINDOWS) endif (WINDOWS) if (NOT WINDOWS) - set(_LINKS ${_LINKS} -ldw) + set(_LINKS ${_LINKS} -lbfd -ldl) endif () -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) - if (STATICC) + set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") message(STATUS "Linking C library statically") - if (NOT UNIX AND NOT APPLE OR WINDOWS) - SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) - SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) - else() - SET(_LINKS ${_LINKS} Threads::Threads -static-libgcc -static-libstdc++) - SET(_TESTLINKS ${_TESTLINKS} Threads::Threads -static-libgcc -static-libstdc++) - endif() + set(_LINKS ${_LINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lm -lstdc++ -lpthread) + SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread) else() SET(_LINKS ${_LINKS} Threads::Threads) endif() -target_link_libraries(pkmnLib PUBLIC ${_LINKS}) +target_link_libraries(pkmnLib ${_LINKS}) if (TESTS) # Create Test executable diff --git a/CmakeConanSetup.cmake b/CmakeConanSetup.cmake index f338db9..7a4068e 100644 --- a/CmakeConanSetup.cmake +++ b/CmakeConanSetup.cmake @@ -10,7 +10,7 @@ function(SetupConan) endif (STATICC) if (NOT WINDOWS) - execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build outdated + execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build=missing -s compiler=clang -s compiler.libcxx=libstdc++11 -o *:shared=True diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index a5ffc76..f9d3c53 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -1,11 +1,13 @@ #include "RegisterBattleClass.hpp" #include +#include #include "../../../../Battling/Battle/Battle.hpp" #include "../HelperFile.hpp" void RegisterBattleClass::Register(asIScriptEngine* engine) { RegisterChoiceQueue(engine); RegisterBattleRandom(engine); + RegisterBattleSide(engine); RegisterBattle(engine); } @@ -44,6 +46,19 @@ void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) { BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Battle, CreatureLib::Battling::ChoiceQueue, GetCurrentTurnQueue); +CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* battle, u8 index) { + return battle->GetSides()[index]; +} + +void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { + int r = engine->RegisterObjectType("BattleSide", 0, asOBJ_REF | asOBJ_NOCOUNT); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("BattleSide", "bool SwapPositions(uint8 a, uint8 b)", + asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool), + asCALL_THISCALL); + Ensure(r >= 0); +} + void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); @@ -82,4 +97,7 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { "Battle", "const constString& GetWeatherName() const", asMETHODPR(PkmnLib::Battling::Battle, GetWeatherName, (), const ArbUt::StringView&), asCALL_THISCALL); Ensure(r >= 0); + r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)", + asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.hpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.hpp index bfa991e..030d221 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.hpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.hpp @@ -5,6 +5,7 @@ class RegisterBattleClass { static void RegisterChoiceQueue(asIScriptEngine* engine); static void RegisterBattle(asIScriptEngine* engine); + static void RegisterBattleSide(asIScriptEngine* engine); static void RegisterBattleRandom(asIScriptEngine* engine); public: