Browse Source

Add CMake option to opt-in to DAPI

pull/7983/head
staphen 10 months ago
parent
commit
44cdd7a027
No known key found for this signature in database
GPG Key ID: E6D757EEF0CE235F
  1. 1
      CMake/Definitions.cmake
  2. 8
      CMake/Dependencies.cmake
  3. 3
      CMake/VcPkgManifestFeatures.cmake
  4. 2
      CMakeLists.txt
  5. 24
      CMakeSettings.json
  6. 4
      Packaging/windows/CMakePresets.json
  7. 69
      Source/CMakeLists.txt
  8. 11
      Source/diablo.cpp
  9. 8
      vcpkg.json

1
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

8
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()

3
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()

2
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.

24
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",

4
Packaging/windows/CMakePresets.json

@ -36,6 +36,10 @@
"DISABLE_LTO": {
"type": "BOOL",
"value": "ON"
},
"DAPI_SERVER": {
"type": "BOOL",
"value": "ON"
}
}
},

69
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 "$<BUILD_INTERFACE:${PROTO_BINARY_DIR}>")
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 "$<BUILD_INTERFACE:${PROTO_BINARY_DIR}>")
include_directories("${PROTO_BINARY_DIR}/dapi/Backend/Messages")
target_include_directories(libdevilutionx PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/dapi/Backend/DAPIBackendCore")
endif()

11
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();

8
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" ]

Loading…
Cancel
Save