diff --git a/CMake/Definitions.cmake b/CMake/Definitions.cmake index ab85b1f8f..1db7245be 100644 --- a/CMake/Definitions.cmake +++ b/CMake/Definitions.cmake @@ -19,6 +19,7 @@ foreach( DEVILUTIONX_RESAMPLER_SDL DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT SCREEN_READER_INTEGRATION + DAPI_SERVER UNPACKED_MPQS UNPACKED_SAVES DEVILUTIONX_WINDOWS_NO_WCHAR diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 030781d8c..0968a42f2 100644 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -276,7 +276,9 @@ if(GPERF) message("INFO: ${GPERFTOOLS_LIBRARIES}") endif() -find_package(SFML 3.0 COMPONENTS Network CONFIG QUIET) -if(NOT SFML_FOUND) - add_subdirectory(3rdParty/sfml) +if(DAPI_SERVER) + find_package(SFML 3.0 COMPONENTS Network CONFIG QUIET) + if(NOT SFML_FOUND) + add_subdirectory(3rdParty/sfml) + endif() endif() diff --git a/CMake/VcPkgManifestFeatures.cmake b/CMake/VcPkgManifestFeatures.cmake index de7359fa8..0ce00f29b 100644 --- a/CMake/VcPkgManifestFeatures.cmake +++ b/CMake/VcPkgManifestFeatures.cmake @@ -10,6 +10,9 @@ endif() if(USE_GETTEXT_FROM_VCPKG) list(APPEND VCPKG_MANIFEST_FEATURES "translations") endif() +if(DAPI_SERVER) + list(APPEND VCPKG_MANIFEST_FEATURES "dapi") +endif() if(BUILD_TESTING) list(APPEND VCPKG_MANIFEST_FEATURES "tests") endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index d750b0a3e..d98f610cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,8 @@ cmake_dependent_option(PACKET_ENCRYPTION "Encrypt network packets" ON "NOT NONET if(CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg.cmake$") option(USE_GETTEXT_FROM_VCPKG "Add vcpkg dependency for gettext[tools] for compiling translations" OFF) endif() +option(DAPI_SERVER "Build with DAPI server component for gameplay automation" OFF) +mark_as_advanced(DAPI_SERVER) option(BUILD_TESTING "Build tests." ON) # These must be included after the options above but before the `project` call. diff --git a/CMakeSettings.json b/CMakeSettings.json index 2041366d8..9a13ba0e0 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -12,7 +12,7 @@ "variables": [ { "name": "DISCORD_INTEGRATION", - "value": "False", + "value": "True", "type": "BOOL" } ] @@ -39,6 +39,28 @@ } ] }, + { + "name": "x64-Debug-DAPI", + "generator": "Ninja", + "configurationType": "Debug", + "buildRoot": "${workspaceRoot}\\build\\${name}", + "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", + "inheritEnvironments": [ "msvc_x64" ], + "intelliSenseMode": "windows-msvc-x64", + "enableClangTidyCodeAnalysis": true, + "variables": [ + { + "name": "DISCORD_INTEGRATION", + "value": "False", + "type": "BOOL" + }, + { + "name": "DAPI_SERVER", + "value": "True", + "type": "BOOL" + } + ] + }, { "name": "x64-Debug-SDL1", "generator": "Ninja", diff --git a/Packaging/windows/CMakePresets.json b/Packaging/windows/CMakePresets.json index c59a2c30c..55b092cfa 100644 --- a/Packaging/windows/CMakePresets.json +++ b/Packaging/windows/CMakePresets.json @@ -36,6 +36,10 @@ "DISABLE_LTO": { "type": "BOOL", "value": "ON" + }, + "DAPI_SERVER": { + "type": "BOOL", + "value": "ON" } } }, diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 09b565d48..83f4d2e67 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -649,14 +649,16 @@ if(DISCORD_INTEGRATION) ) endif() -list(APPEND libdevilutionx_SRCS - dapi/Server.cpp - dapi/Backend/DAPIBackendCore/DAPIProtoClient.cpp - dapi/Backend/Messages/command.proto - dapi/Backend/Messages/data.proto - dapi/Backend/Messages/game.proto - dapi/Backend/Messages/init.proto - dapi/Backend/Messages/message.proto) +if(DAPI_SERVER) + list(APPEND libdevilutionx_SRCS + dapi/Server.cpp + dapi/Backend/DAPIBackendCore/DAPIProtoClient.cpp + dapi/Backend/Messages/command.proto + dapi/Backend/Messages/data.proto + dapi/Backend/Messages/game.proto + dapi/Backend/Messages/init.proto + dapi/Backend/Messages/message.proto) +endif() if(SCREEN_READER_INTEGRATION) list(APPEND libdevilutionx_SRCS @@ -684,7 +686,6 @@ target_link_dependencies(libdevilutionx PUBLIC libsmackerdec ${LUA_LIBRARIES} sol2::sol2 - SFML::Network tl unordered_dense::unordered_dense libdevilutionx_assets @@ -752,6 +753,10 @@ if(DISCORD_INTEGRATION) target_link_libraries(libdevilutionx PRIVATE discord discord_game_sdk) endif() +if(DAPI_SERVER) + target_link_libraries(libdevilutionx PRIVATE SFML::Network) +endif() + if(SCREEN_READER_INTEGRATION) if(WIN32) target_compile_definitions(libdevilutionx PRIVATE Tolk) @@ -807,25 +812,27 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") endif() endif() -find_package(Protobuf REQUIRED) - -target_link_libraries(libdevilutionx PUBLIC protobuf::libprotobuf-lite) -find_package(absl REQUIRED) -set(PROTO_BINARY_DIR "${CMAKE_BINARY_DIR}/generated") - -file(MAKE_DIRECTORY ${PROTO_BINARY_DIR}) - -target_include_directories(libdevilutionx PRIVATE ${Protobuf_INCLUDE_DIRS}) - -# Generate the protobuf files into the 'generated' directory within the build tree -protobuf_generate( - TARGET libdevilutionx - IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dapi/Backend/Messages" - PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" -) - -# Make sure the generated protobuf files are correctly included in the build -target_include_directories(libdevilutionx PUBLIC "$") -include_directories("${PROTO_BINARY_DIR}/dapi/Backend/Messages") - -target_include_directories(libdevilutionx PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dapi/Backend/DAPIBackendCore") +if(DAPI_SERVER) + find_package(Protobuf REQUIRED) + + target_link_libraries(libdevilutionx PUBLIC protobuf::libprotobuf-lite) + find_package(absl REQUIRED) + set(PROTO_BINARY_DIR "${CMAKE_BINARY_DIR}/generated") + + file(MAKE_DIRECTORY ${PROTO_BINARY_DIR}) + + target_include_directories(libdevilutionx PRIVATE ${Protobuf_INCLUDE_DIRS}) + + # Generate the protobuf files into the 'generated' directory within the build tree + protobuf_generate( + TARGET libdevilutionx + IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/dapi/Backend/Messages" + PROTOC_OUT_DIR "${PROTO_BINARY_DIR}" + ) + + # Make sure the generated protobuf files are correctly included in the build + target_include_directories(libdevilutionx PUBLIC "$") + include_directories("${PROTO_BINARY_DIR}/dapi/Backend/Messages") + + target_include_directories(libdevilutionx PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dapi/Backend/DAPIBackendCore") +endif() diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 1aea08810..3cbb64f89 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -26,7 +26,6 @@ #include "controls/keymapper.hpp" #include "controls/plrctrls.h" #include "controls/remap_keyboard.h" -#include "dapi/Server.h" #include "diablo.h" #include "diablo_msg.hpp" #include "discord/discord.h" @@ -108,6 +107,10 @@ #include "controls/touch/renderers.h" #endif +#ifdef DAPI_SERVER +#include "dapi/Server.h" +#endif + #ifdef __vita__ #include "platform/vita/touch.h" #endif @@ -133,7 +136,9 @@ clicktype sgbMouseDown; uint16_t gnTickDelay = 50; char gszProductName[64] = "DevilutionX vUnknown"; +#ifdef DAPI_SERVER DAPI::Server dapiServer; +#endif #ifdef _DEBUG bool DebugDisableNetworkTimeout = false; @@ -1459,11 +1464,15 @@ void UpdateMonsterLights() void GameLogic() { if (!ProcessInput()) { +#ifdef DAPI_SERVER if (gmenu_is_active()) dapiServer.update(); // For game menu commands +#endif return; } +#ifdef DAPI_SERVER dapiServer.update(); +#endif if (gbProcessPlayers) { gGameLogicStep = GameLogicStep::ProcessPlayers; ProcessPlayers(); diff --git a/vcpkg.json b/vcpkg.json index 759e23cce..5136ac7a7 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -4,9 +4,7 @@ "dependencies": [ "fmt", "bzip2", - "lua", - "protobuf", - "sfml" + "lua" ], "builtin-baseline": "533a5fda5c0646d1771345fb572e759283444d5f", "features": { @@ -31,6 +29,10 @@ } ] }, + "dapi": { + "description": "Build DAPI server for gameplay automation", + "dependencies": [ "protobuf", "sfml" ] + }, "tests": { "description": "Build tests", "dependencies": [ "gtest", "benchmark" ]