diff --git a/CInterface/AngelScript/AngelScriptResolver.cpp b/CInterface/AngelScript/AngelScriptResolver.cpp index 4fb5b27..105dfc0 100644 --- a/CInterface/AngelScript/AngelScriptResolver.cpp +++ b/CInterface/AngelScript/AngelScriptResolver.cpp @@ -52,8 +52,10 @@ export uint8_t PkmnLib_AngelScriptResolver_RegisterGlobalMethod(AngelScriptResol } export void PkmnLib_AngelScriptResolver_DefineWord(AngelScriptResolver* p, const char* word) { p->DefineWord(word); } +#ifdef ANGELSCRIPT_DEBUGGER export void PkmnLib_AngelScriptResolver_AddDebugger(AngelScriptResolver* p, u16 port) { auto* d = new AngelscriptDebugger(); d->Run(port); p->SetDebugger(d); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cc0ffb..e226e64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ 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." ON) option(PKMNLIB_TESTS "Whether the test executable should be build as well." OFF) option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF) +option(ANGELSCRIPT_DEBUGGER "Include the angelscript debug server in the build." OFF) set(SCRIPT_PROVIDER "angelscript" CACHE STRING "Which script provider to use.") set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Can be 8") @@ -147,8 +148,10 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript") "extern/angelscript_addons/*.h" "CInterface/AngelScript/*.cpp" "CInterface/AngelScript/*.hpp" - "extern/AngelscriptDebuggerServer/src/*.cpp" ) + if (ANGELSCRIPT_DEBUGGER) + SET(FILE_SOURCE ${FILE_SOURCE} "extern/AngelscriptDebuggerServer/src/*.cpp") + endif() ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1) endif () @@ -173,6 +176,9 @@ if (SCRIPT_PROVIDER STREQUAL "angelscript") ADD_DEFINITIONS(-D ANGELSCRIPT=1) SET(_LINKS ${_LINKS} angelscript) SET(_TESTLINKS ${_TESTLINKS} angelscript) + if (ANGELSCRIPT_DEBUGGER) + ADD_DEFINITIONS(-D ANGELSCRIPT_DEBUGGER=1) + endif() endif () # If we are building for Windows we need to set some specific variables. @@ -186,8 +192,8 @@ if (WINDOWS) if (SHARED) set_target_properties(pkmnLib PROPERTIES SUFFIX ".dll") endif (SHARED) - set(_LINKS ${_LINKS} -Wl,-Bstatic -lws2_32 -lpthread -Wl,-Bdynamic) - set(_TESTLINKS ${_TESTLINKS} -Wl,-Bstatic -lws2_32 -lpthread -Wl,-Bdynamic) + set(_LINKS ${_LINKS} -Wl,-Bstatic -lws2_32 -Wl,-Bdynamic) + set(_TESTLINKS ${_TESTLINKS} -Wl,-Bstatic -lws2_32 -Wl,-Bdynamic) endif (WINDOWS) if (NOT WINDOWS) @@ -199,8 +205,6 @@ if (STATICC) message(STATUS "Linking C library statically") set(_LINKS ${_LINKS} -static-libstdc++ -Wl,-Bstatic -lm -lgcc -lstdc++ -Wl,-Bdynamic) SET(_TESTLINKS ${_TESTLINKS} -Wl,-Bstatic -lm -lgcc -lstdc++ -Wl,-Bdynamic) -else () - SET(_LINKS ${_LINKS} -Wl,--whole-archive -Wl,--no-whole-archive) endif () target_link_libraries(pkmnLib PRIVATE ${_LINKS}) @@ -219,4 +223,6 @@ if (PKMNLIB_TESTS) target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) endif () -include_directories(extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include) +if (ANGELSCRIPT_DEBUGGER) + include_directories(extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include) +endif() diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp index 432459a..25a6275 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.hpp @@ -3,7 +3,9 @@ #include #include +#ifdef ANGELSCRIPT_DEBUGGER #include "../../../extern/AngelscriptDebuggerServer/src/AngelscriptDebugger.hpp" +#endif #include "../../../extern/angelscript_addons/scriptbuilder/scriptbuilder.h" #include "../../Battling/Library/BattleLibrary.hpp" #include "AngelScriptEvolutionScript.hpp" @@ -26,7 +28,9 @@ private: CScriptBuilder _builder = {}; std::string _sourceDirectory = {}; AngelscriptUserdata* _userData; +#ifdef ANGELSCRIPT_DEBUGGER ArbUt::OptionalUniquePtr _debugger; +#endif ArbUt::Dictionary> _typeDatabase; ArbUt::Dictionary _baseTypes; @@ -113,8 +117,10 @@ public: inline asIScriptEngine* GetEngine() const noexcept { return _engine; } inline AngelscriptUserdata* GetUserdata() const noexcept { return _userData; } +#ifdef ANGELSCRIPT_DEBUGGER inline ArbUt::OptionalBorrowedPtr GetDebugger() const noexcept { return _debugger.GetValue(); } inline void SetDebugger(AngelscriptDebugger* debugger) noexcept { _debugger = debugger; } +#endif asITypeInfo* GetScriptOwnerType(ScriptCategory category) { auto tryget = _scriptOwnerTypes.TryGet(category); diff --git a/src/ScriptResolving/AngelScript/ContextPool.hpp b/src/ScriptResolving/AngelScript/ContextPool.hpp index 5527915..c14601c 100644 --- a/src/ScriptResolving/AngelScript/ContextPool.hpp +++ b/src/ScriptResolving/AngelScript/ContextPool.hpp @@ -53,9 +53,11 @@ public: ctx = _resolver->GetEngine()->CreateContext(); ctx->SetUserData(_userData); } +#ifdef ANGELSCRIPT_DEBUGGER if (_resolver->GetDebugger().HasValue()) { _resolver->GetDebugger().GetValue()->RegisterContext(ctx); } +#endif return ctx; }