Fix up ZLib a little more and remove more configuration into CMakeLists

This commit is contained in:
Jettford 2024-12-05 19:45:21 +00:00
parent 6c8bb743af
commit 6eea3f3662
4 changed files with 30 additions and 34 deletions

View File

@ -19,6 +19,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debuggi
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo, MinSizeRel")
set(DLU_CONFIG_DIR ${CMAKE_SOURCE_DIR}/build CACHE PATH "The directory where the server configuration files are stored")
# Read variables from file # Read variables from file
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
@ -89,10 +92,11 @@ elseif(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif() endif()
# Our output dir # Set the output directories
#set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) # unfortunately, forces all libraries to be built in series, which will slow down the build process # ./build/<platform + architecture (x64, x86, aarch64)>/<compiler>/<build_mode>/
set(CMAKE_BINARY_DIR ${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}/${CMAKE_CXX_COMPILER_ID}/${CMAKE_BUILD_TYPE})
# TODO make this not have to override the build type directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
@ -107,6 +111,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Get DLU config directory
if(DEFINED ENV{DLU_CONFIG_DIR})
set(DLU_CONFIG_DIR $ENV{DLU_CONFIG_DIR})
else()
set(DLU_CONFIG_DIR ${CMAKE_BINARY_DIR})
endif()
message(STATUS "Configuration Directory is ${DLU_CONFIG_DIR}, and the build directory is ${CMAKE_BINARY_DIR}")
find_package(MariaDB) find_package(MariaDB)
# Create a /resServer directory # Create a /resServer directory
@ -115,18 +128,11 @@ make_directory(${CMAKE_BINARY_DIR}/resServer)
# Create a /logs directory # Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs) make_directory(${CMAKE_BINARY_DIR}/logs)
# Get DLU config directory
if(DEFINED ENV{DLU_CONFIG_DIR})
set(DLU_CONFIG_DIR $ENV{DLU_CONFIG_DIR})
else()
set(DLU_CONFIG_DIR ${PROJECT_BINARY_DIR})
endif()
message(STATUS "Variable: DLU_CONFIG_DIR = ${DLU_CONFIG_DIR}")
# Copy resource files on first build # Copy resource files on first build
set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf") set(RESOURCE_FILES "sharedconfig.ini" "authconfig.ini" "chatconfig.ini" "worldconfig.ini" "masterconfig.ini" "blocklist.dcf")
message(STATUS "Checking resource file integrity") message(STATUS "Checking resource file integrity")
include(Utils) include(Utils)
UpdateConfigOption(${DLU_CONFIG_DIR}/authconfig.ini "port" "auth_server_port") UpdateConfigOption(${DLU_CONFIG_DIR}/authconfig.ini "port" "auth_server_port")
UpdateConfigOption(${DLU_CONFIG_DIR}/chatconfig.ini "port" "chat_server_port") UpdateConfigOption(${DLU_CONFIG_DIR}/chatconfig.ini "port" "chat_server_port")

View File

@ -11,9 +11,6 @@
"displayName": "Default configure step", "displayName": "Default configure step",
"description": "Use 'build' dir and Unix makefiles", "description": "Use 'build' dir and Unix makefiles",
"binaryDir": "${sourceDir}/build", "binaryDir": "${sourceDir}/build",
"environment": {
"DLU_CONFIG_DIR": "${sourceDir}/build"
},
"generator": "Unix Makefiles", "generator": "Unix Makefiles",
"hidden": true "hidden": true
@ -36,15 +33,13 @@
"name": "windows-msvc", "name": "windows-msvc",
"inherits": "windows-default", "inherits": "windows-default",
"displayName": "Windows (MSVC)", "displayName": "Windows (MSVC)",
"description": "Create a build using MSVC", "description": "Create a build using MSVC"
"binaryDir": "${sourceDir}/build/msvc"
}, },
{ {
"name": "windows-clang", "name": "windows-clang",
"inherits": "windows-default", "inherits": "windows-default",
"displayName": "EXPERIMENTAL - Windows (Clang)", "displayName": "EXPERIMENTAL - Windows (Clang)",
"description": "Create a build using Clang", "description": "Create a build using Clang",
"binaryDir": "${sourceDir}/build/windows-clang",
"toolset": "ClangCL" "toolset": "ClangCL"
}, },
@ -65,8 +60,7 @@
"toolchainFile": "${sourceDir}/cmake/toolchains/linux-clang.cmake", "toolchainFile": "${sourceDir}/cmake/toolchains/linux-clang.cmake",
"displayName": "Linux (Clang)", "displayName": "Linux (Clang)",
"description": "Create a build using the Clang toolchain for Linux", "description": "Create a build using the Clang toolchain for Linux"
"binaryDir": "${sourceDir}/build/linux-clang"
}, },
{ {
"name": "linux-gnu", "name": "linux-gnu",
@ -75,8 +69,7 @@
"toolchainFile": "${sourceDir}/cmake/toolchains/linux-gnu.cmake", "toolchainFile": "${sourceDir}/cmake/toolchains/linux-gnu.cmake",
"displayName": "Linux (GNU)", "displayName": "Linux (GNU)",
"description": "Create a build using the GNU toolchain for Linux", "description": "Create a build using the GNU toolchain for Linux"
"binaryDir": "${sourceDir}/build/gnu"
}, },
{ {
"name": "macos", "name": "macos",
@ -87,8 +80,7 @@
"type": "equals", "type": "equals",
"lhs": "${hostSystemName}", "lhs": "${hostSystemName}",
"rhs": "Darwin" "rhs": "Darwin"
}, }
"binaryDir": "${sourceDir}/build/macos"
} }
], ],
"testPresets": [ "testPresets": [

View File

@ -1,6 +1,6 @@
#include "ZCompression.h" #include "ZCompression.h"
#include "zlib.h" #include "zlib-ng.h"
namespace ZCompression { namespace ZCompression {
int32_t GetMaxCompressedLength(int32_t nLenSrc) { int32_t GetMaxCompressedLength(int32_t nLenSrc) {
@ -9,41 +9,41 @@ namespace ZCompression {
} }
int32_t Compress(const uint8_t* abSrc, int32_t nLenSrc, uint8_t* abDst, int32_t nLenDst) { int32_t Compress(const uint8_t* abSrc, int32_t nLenSrc, uint8_t* abDst, int32_t nLenDst) {
z_stream zInfo = { 0 }; zng_stream zInfo = { 0 };
zInfo.total_in = zInfo.avail_in = nLenSrc; zInfo.total_in = zInfo.avail_in = nLenSrc;
zInfo.total_out = zInfo.avail_out = nLenDst; zInfo.total_out = zInfo.avail_out = nLenDst;
zInfo.next_in = const_cast<Bytef*>(abSrc); zInfo.next_in = const_cast<Bytef*>(abSrc);
zInfo.next_out = abDst; zInfo.next_out = abDst;
int nErr, nRet = -1; int nErr, nRet = -1;
nErr = deflateInit(&zInfo, Z_DEFAULT_COMPRESSION); // zlib function nErr = zng_deflateInit(&zInfo, Z_DEFAULT_COMPRESSION); // zlib function
if (nErr == Z_OK) { if (nErr == Z_OK) {
nErr = deflate(&zInfo, Z_FINISH); // zlib function nErr = zng_deflate(&zInfo, Z_FINISH); // zlib function
if (nErr == Z_STREAM_END) { if (nErr == Z_STREAM_END) {
nRet = zInfo.total_out; nRet = zInfo.total_out;
} }
} }
deflateEnd(&zInfo); // zlib function zng_deflateEnd(&zInfo); // zlib function
return(nRet); return(nRet);
} }
int32_t Decompress(const uint8_t* abSrc, int32_t nLenSrc, uint8_t* abDst, int32_t nLenDst, int32_t& nErr) { int32_t Decompress(const uint8_t* abSrc, int32_t nLenSrc, uint8_t* abDst, int32_t nLenDst, int32_t& nErr) {
// Get the size of the decompressed data // Get the size of the decompressed data
z_stream zInfo = { 0 }; zng_stream zInfo = { 0 };
zInfo.total_in = zInfo.avail_in = nLenSrc; zInfo.total_in = zInfo.avail_in = nLenSrc;
zInfo.total_out = zInfo.avail_out = nLenDst; zInfo.total_out = zInfo.avail_out = nLenDst;
zInfo.next_in = const_cast<Bytef*>(abSrc); zInfo.next_in = const_cast<Bytef*>(abSrc);
zInfo.next_out = abDst; zInfo.next_out = abDst;
int nRet = -1; int nRet = -1;
nErr = inflateInit(&zInfo); // zlib function nErr = zng_inflateInit(&zInfo); // zlib function
if (nErr == Z_OK) { if (nErr == Z_OK) {
nErr = inflate(&zInfo, Z_FINISH); // zlib function nErr = zng_inflate(&zInfo, Z_FINISH); // zlib function
if (nErr == Z_STREAM_END) { if (nErr == Z_STREAM_END) {
nRet = zInfo.total_out; nRet = zInfo.total_out;
} }
} }
inflateEnd(&zInfo); // zlib function zng_inflateEnd(&zInfo); // zlib function
return(nRet); return(nRet);
} }
} }

View File

@ -4,8 +4,6 @@
#include "Game.h" #include "Game.h"
#include "Logger.h" #include "Logger.h"
#include "zlib.h"
AssetManager::AssetManager(const std::filesystem::path& path) { AssetManager::AssetManager(const std::filesystem::path& path) {
if (!std::filesystem::is_directory(path)) { if (!std::filesystem::is_directory(path)) {
throw std::runtime_error("Attempted to load asset bundle (" + path.string() + ") however it is not a valid directory."); throw std::runtime_error("Attempted to load asset bundle (" + path.string() + ") however it is not a valid directory.");