From 4f4ab3bd20315d40072683df0b0ec8b0b537f08a Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 15 Sep 2024 23:24:07 +0300 Subject: [PATCH 1/3] Isolate module submodule --- Descent3/osiris_dll.h | 5 ++--- Descent3/sdlmain.cpp | 4 ++++ Descent3/tests/CMakeLists.txt | 1 + lib/directplay.h | 5 ++++- module/CMakeLists.txt | 12 ++++++++++-- {lib => module}/module.h | 0 netcon/descent3onlineclient/CMakeLists.txt | 1 + netcon/lanclient/CMakeLists.txt | 1 + netcon/mtclient/CMakeLists.txt | 1 + netgames/dmfc/CMakeLists.txt | 1 + networking/CMakeLists.txt | 1 + networking/networking.cpp | 20 ++++++-------------- physics/CMakeLists.txt | 1 + renderer/CMakeLists.txt | 1 + scripts/CMakeLists.txt | 1 + 15 files changed, 35 insertions(+), 20 deletions(-) rename {lib => module}/module.h (100%) diff --git a/Descent3/osiris_dll.h b/Descent3/osiris_dll.h index 50947cc9..a9684b72 100644 --- a/Descent3/osiris_dll.h +++ b/Descent3/osiris_dll.h @@ -112,11 +112,10 @@ #ifndef __OSIRIS_H_ #define __OSIRIS_H_ -#include "pstypes.h" +#include "cfile.h" +#include "module.h" #include "object_external_struct.h" #include "osiris_share.h" -#include "module.h" -#include "cfile.h" extern uint32_t Osiris_game_checksum; extern tOSIRISModuleInit Osiris_module_init; diff --git a/Descent3/sdlmain.cpp b/Descent3/sdlmain.cpp index 00539174..e44a5db5 100644 --- a/Descent3/sdlmain.cpp +++ b/Descent3/sdlmain.cpp @@ -55,6 +55,10 @@ #include "dedicated_server.h" #include "init.h" +#ifdef WIN32 +#include "debug.h" +#endif + std::filesystem::path orig_pwd; static volatile char already_tried_signal_cleanup = 0; diff --git a/Descent3/tests/CMakeLists.txt b/Descent3/tests/CMakeLists.txt index 5e820bdf..20bb30de 100644 --- a/Descent3/tests/CMakeLists.txt +++ b/Descent3/tests/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable( target_link_libraries( porting-tests + module GTest::gtest_main ) diff --git a/lib/directplay.h b/lib/directplay.h index 2f87450b..408ca47c 100644 --- a/lib/directplay.h +++ b/lib/directplay.h @@ -44,8 +44,11 @@ #ifndef _OUTRAGE_DIRECTPLAY_HEADER #define _OUTRAGE_DIRECTPLAY_HEADER +#include + #include "dplay.h" #include "dplobby.h" +#include "networking.h" struct modem_list { char name[200]; @@ -80,7 +83,7 @@ int dp_DirectPlaySend(network_address *who_to, uint8_t *data, int len, bool reli void dp_DirectPlayDispatch(); // Initialize stuff -int dp_InitDirectPlay(char *conn_name, void *parms = NULL, int num_elements = 0); +int dp_InitDirectPlay(char *conn_name, void *parms = nullptr, int num_elements = 0); // Shutdown things void dp_ShutdownDirectPlay(); diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index 714b4b87..8bc96153 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -1,8 +1,16 @@ -set(HEADERS) +set(HEADERS + module.h +) set(CPPS - module.cpp) + module.cpp +) add_library(module STATIC ${HEADERS} ${CPPS}) target_link_libraries(module PRIVATE ddebug ) +target_include_directories(module PUBLIC + $ +) \ No newline at end of file diff --git a/lib/module.h b/module/module.h similarity index 100% rename from lib/module.h rename to module/module.h diff --git a/netcon/descent3onlineclient/CMakeLists.txt b/netcon/descent3onlineclient/CMakeLists.txt index 3c3ebcc0..2fcdd697 100644 --- a/netcon/descent3onlineclient/CMakeLists.txt +++ b/netcon/descent3onlineclient/CMakeLists.txt @@ -18,6 +18,7 @@ target_link_libraries(Descent3_Online_TCP_IP PRIVATE ddio inetfile misc + module ui $<$:ws2_32> ) diff --git a/netcon/lanclient/CMakeLists.txt b/netcon/lanclient/CMakeLists.txt index deae8140..f6237c66 100644 --- a/netcon/lanclient/CMakeLists.txt +++ b/netcon/lanclient/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries(Direct_TCP_IP PRIVATE ddio inetfile misc + module ui $<$:ws2_32> ) diff --git a/netcon/mtclient/CMakeLists.txt b/netcon/mtclient/CMakeLists.txt index 0bbfb5cd..5a85ad0a 100644 --- a/netcon/mtclient/CMakeLists.txt +++ b/netcon/mtclient/CMakeLists.txt @@ -21,6 +21,7 @@ target_link_libraries(Parallax_Online PRIVATE ddio inetfile misc + module ui $<$:ws2_32> ) diff --git a/netgames/dmfc/CMakeLists.txt b/netgames/dmfc/CMakeLists.txt index 25a6fb41..0d1784c8 100644 --- a/netgames/dmfc/CMakeLists.txt +++ b/netgames/dmfc/CMakeLists.txt @@ -30,5 +30,6 @@ add_library(dmfc STATIC ${HEADERS} ${CPPS}) target_link_libraries(dmfc PUBLIC grtext misc + module physics ) diff --git a/networking/CMakeLists.txt b/networking/CMakeLists.txt index 966f12ea..39b87f45 100644 --- a/networking/CMakeLists.txt +++ b/networking/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(networking PRIVATE ddio mem misc + module ${PLATFORM_LIBS} plog::plog ) diff --git a/networking/networking.cpp b/networking/networking.cpp index 31807915..b3084eb0 100644 --- a/networking/networking.cpp +++ b/networking/networking.cpp @@ -290,6 +290,11 @@ #include #include #include + +#include "directplay.h" +#include "dplay.h" +#include "dplobby.h" + typedef int socklen_t; #endif #include @@ -311,36 +316,23 @@ typedef int socklen_t; #define LPSTR char * #endif -#ifdef WIN32 -#include "dplay.h" -#include "dplobby.h" -#endif - #include "descent.h" #include "appdatabase.h" - -#include "pstypes.h" #include "pserror.h" #include "log.h" #include "networking.h" #include "ddio.h" #include "mem.h" +#include "module.h" #include "game.h" #include "args.h" #include "byteswap.h" - -#ifdef WIN32 -#include "directplay.h" -#endif - #include "pstring.h" #ifndef WIN32 bool Use_DirectPlay = false; #endif -#include "module.h" //for some nice defines to use below - #define MAX_CONNECT_TRIES 50 #define MAX_RECEIVE_BUFSIZE 32768 //(1<<16) // 16 K, eh? diff --git a/physics/CMakeLists.txt b/physics/CMakeLists.txt index fb452f1e..3a3cc73d 100644 --- a/physics/CMakeLists.txt +++ b/physics/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(physics PRIVATE mem misc model + module rtperformance sndlib plog::plog diff --git a/renderer/CMakeLists.txt b/renderer/CMakeLists.txt index 00401bf4..da47d419 100644 --- a/renderer/CMakeLists.txt +++ b/renderer/CMakeLists.txt @@ -40,5 +40,6 @@ target_link_libraries(renderer PRIVATE ddio mem misc + module rtperformance ) diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 50c259bd..4de4ddfa 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -79,6 +79,7 @@ foreach(SCRIPT ${SCRIPTS}) target_link_libraries(${SCRIPT} fix misc + module ) set_target_properties(${SCRIPT} PROPERTIES PREFIX "") set_target_properties(${SCRIPT} PROPERTIES CXX_VISIBILITY_PRESET "hidden") From dc0cd880e40c946fd940fe8b1ec687967530cbab Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 10 Sep 2024 12:40:19 +0300 Subject: [PATCH 2/3] Add logger module Implementing separated logger module. --- 2dlib/CMakeLists.txt | 2 +- AudioEncode/CMakeLists.txt | 2 +- CMakeLists.txt | 1 + Descent3/CMakeLists.txt | 33 +++++++++++++++++++-- Descent3/sdlmain.cpp | 44 +--------------------------- bitmap/CMakeLists.txt | 2 +- cfile/CMakeLists.txt | 2 +- dd_grwin32/CMakeLists.txt | 2 +- ddio/CMakeLists.txt | 2 +- grtext/CMakeLists.txt | 2 +- linux/CMakeLists.txt | 2 +- logger/CMakeLists.txt | 16 +++++++++++ logger/log.cpp | 56 ++++++++++++++++++++++++++++++++++++ {lib => logger}/log.h | 8 ++++++ manage/CMakeLists.txt | 2 +- mem/CMakeLists.txt | 2 +- model/CMakeLists.txt | 2 +- module/CMakeLists.txt | 1 + module/module.cpp | 10 +++---- music/CMakeLists.txt | 2 +- networking/CMakeLists.txt | 2 +- physics/CMakeLists.txt | 2 +- renderer/CMakeLists.txt | 2 +- rtperformance/CMakeLists.txt | 2 +- sndlib/CMakeLists.txt | 2 +- stream_audio/CMakeLists.txt | 2 +- ui/CMakeLists.txt | 2 +- win32/CMakeLists.txt | 2 +- 28 files changed, 138 insertions(+), 71 deletions(-) create mode 100644 logger/CMakeLists.txt create mode 100644 logger/log.cpp rename {lib => logger}/log.h (79%) diff --git a/2dlib/CMakeLists.txt b/2dlib/CMakeLists.txt index 38b84c8a..8577875d 100644 --- a/2dlib/CMakeLists.txt +++ b/2dlib/CMakeLists.txt @@ -15,9 +15,9 @@ set(CPPS add_library(2dlib STATIC ${HEADERS} ${CPPS}) target_link_libraries(2dlib PRIVATE cfile + logger mem misc - plog::plog ) target_include_directories(2dlib PUBLIC $:/DEBUG:FULL>) diff --git a/Descent3/sdlmain.cpp b/Descent3/sdlmain.cpp index e44a5db5..dca8161e 100644 --- a/Descent3/sdlmain.cpp +++ b/Descent3/sdlmain.cpp @@ -33,20 +33,9 @@ #include #endif -#ifdef WIN32 -#include -#include -#include "debug.h" -#endif - #include -// We use direct plog includes instead of log.h for logger instance initialization -#include -#include -#include #include "appdatabase.h" -#include "ddio.h" #include "application.h" #include "args.h" #include "d3_version.h" @@ -54,6 +43,7 @@ #include "descent.h" #include "dedicated_server.h" #include "init.h" +#include "log.h" #ifdef WIN32 #include "debug.h" @@ -216,38 +206,6 @@ int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event) { return (1); } -/** - * Initialize logger facility. - * @param log_level desired log level (for example, plog::debug) - * @param enable_filelog enable logging into Descent.log - * @param enable_win_console enable console windows for WIN32 (no-op for POSIX systems) - */ -void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console) { - std::filesystem::path log_file = "Descent3.log"; - static plog::ColorConsoleAppender consoleAppender; - static plog::RollingFileAppender fileAppender(log_file.u8string().c_str()); - -#ifdef WIN32 - if (enable_win_console) { - // Open console window - AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - } -#endif - - plog::init(log_level, &consoleAppender); - if (enable_filelog) { - if (std::filesystem::is_regular_file(log_file)) { - // Delete old log - std::error_code ec; - std::filesystem::remove(log_file, ec); - plog::get()->addAppender(&fileAppender); - } - } -} - // --------------------------------------------------------------------------- // Main // creates all the OS objects and then runs Descent 3. diff --git a/bitmap/CMakeLists.txt b/bitmap/CMakeLists.txt index 531bb21a..12b05735 100644 --- a/bitmap/CMakeLists.txt +++ b/bitmap/CMakeLists.txt @@ -15,9 +15,9 @@ target_link_libraries(bitmap PRIVATE cfile ddebug ddio + logger mem misc - plog::plog stb ) target_include_directories(bitmap PUBLIC diff --git a/cfile/CMakeLists.txt b/cfile/CMakeLists.txt index a249fdcf..2deebbdc 100644 --- a/cfile/CMakeLists.txt +++ b/cfile/CMakeLists.txt @@ -11,9 +11,9 @@ set(CPPS add_library(cfile STATIC ${HEADERS} ${CPPS}) target_link_libraries(cfile PRIVATE ddio + logger mem misc - plog::plog ) target_include_directories(cfile PUBLIC $ +) diff --git a/logger/log.cpp b/logger/log.cpp new file mode 100644 index 00000000..7bc81075 --- /dev/null +++ b/logger/log.cpp @@ -0,0 +1,56 @@ +/* + * Descent 3 + * Copyright (C) 2024 Descent Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#ifdef WIN32 +#include +#include +#include "debug.h" +#endif + +#include "log.h" + +void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console) { + std::filesystem::path log_file = "Descent3.log"; + static plog::ColorConsoleAppender consoleAppender; + static plog::RollingFileAppender fileAppender(log_file.u8string().c_str()); + +#ifdef WIN32 + if (enable_win_console) { + // Open console window + AllocConsole(); + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + } +#endif + + plog::init(log_level, &consoleAppender); + if (enable_filelog) { + if (std::filesystem::is_regular_file(log_file)) { + // Delete old log + std::error_code ec; + std::filesystem::remove(log_file, ec); + } + plog::get()->addAppender(&fileAppender); + } +} \ No newline at end of file diff --git a/lib/log.h b/logger/log.h similarity index 79% rename from lib/log.h rename to logger/log.h index 53a278f2..0d5b6cfc 100644 --- a/lib/log.h +++ b/logger/log.h @@ -32,3 +32,11 @@ In case of swapping to another solution here should be redefined following macro #define LOG_FATAL PLOG(plog::fatal) */ + +/** + * Initialize logger facility. + * @param log_level desired log level (for example, plog::debug) + * @param enable_filelog enable logging into Descent.log + * @param enable_win_console enable console windows for WIN32 (no-op for POSIX systems) + */ +void InitLog(plog::Severity log_level, bool enable_filelog, bool enable_win_console); diff --git a/manage/CMakeLists.txt b/manage/CMakeLists.txt index 8fd38cdb..262309fa 100644 --- a/manage/CMakeLists.txt +++ b/manage/CMakeLists.txt @@ -25,10 +25,10 @@ add_library(manage STATIC ${HEADERS} ${CPPS}) target_link_libraries(manage PRIVATE cfile ddio + logger mem misc model sndlib stream_audio - plog::plog ) diff --git a/mem/CMakeLists.txt b/mem/CMakeLists.txt index 8be9a709..7e72ae84 100644 --- a/mem/CMakeLists.txt +++ b/mem/CMakeLists.txt @@ -6,8 +6,8 @@ target_compile_definitions(mem PUBLIC $<$:MEM_USE_RTL> ) target_link_libraries(mem PRIVATE + logger misc - plog::plog ) target_include_directories(mem PUBLIC $handle = dlopen(modfilename.u8string().c_str(), f); if (!handle->handle) { - mprintf(0, "Module Load Err: %s\n", dlerror()); + LOG_ERROR.printf("Module Load Err: %s", dlerror()); ModLastError = MODERR_MODNOTFOUND; return false; } diff --git a/music/CMakeLists.txt b/music/CMakeLists.txt index 154ffa3b..0b82370c 100644 --- a/music/CMakeLists.txt +++ b/music/CMakeLists.txt @@ -12,11 +12,11 @@ target_link_libraries(music AudioEncode cfile ddio + logger mem misc sndlib stream_audio - plog::plog ) target_include_directories(music PUBLIC $ Date: Sun, 15 Sep 2024 23:35:00 +0300 Subject: [PATCH 3/3] module: use cf_FindRealFileNameCaseInsensitive() instead duplicated In mod_GetRealModuleName() there was error - arguments of mod_FindRealFileNameCaseInsensitive() is misplaced. --- module/CMakeLists.txt | 1 + module/module.cpp | 48 ++----------------------------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index 2add3641..fb0f406a 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -7,6 +7,7 @@ set(CPPS add_library(module STATIC ${HEADERS} ${CPPS}) target_link_libraries(module PRIVATE + cfile ddebug logger ) diff --git a/module/module.cpp b/module/module.cpp index 16e56541..6442b854 100644 --- a/module/module.cpp +++ b/module/module.cpp @@ -101,55 +101,11 @@ #include #endif +#include "cfile.h" #include "crossplat.h" #include "log.h" #include "module.h" -/** - * Returns fixed case file name to actual case on disk for case-sensitive filesystems (Linux). - * This is actually copy of cf_FindRealFileNameCaseInsensitive() from CFILE. - * @param fname the fixed case name to map to reality - * @param directory optional directory to search within (default - current path) - * @return filename with actual case name or empty path if there no mapping in filesystem - * @note This function returns only filename without directory part, i.e. - * mod_FindRealFileNameCaseInsensitive("test/test.txt") will return only "test.txt" on success. - */ -std::filesystem::path mod_FindRealFileNameCaseInsensitive(const std::filesystem::path &fname, - const std::filesystem::path &directory = ".") { - // Dumb check, maybe there already all ok? - if (std::filesystem::exists((directory / fname))) { - return fname.filename(); - } - - std::filesystem::path result, search_path, search_file; - - search_path = directory / fname.parent_path(); - search_file = fname.filename(); - - // If directory does not exist, nothing to search. - if (!std::filesystem::is_directory(search_path) || search_file.empty()) { - return {}; - } - - // Search component in search_path - auto const &it = std::filesystem::directory_iterator(search_path); - - auto found = std::find_if(it, end(it), [&search_file, &search_path, &result](const auto &dir_entry) { - return stricmp(dir_entry.path().filename().u8string().c_str(), search_file.u8string().c_str()) == 0; - }); - - if (found != end(it)) { - // Match, append to result - result = found->path(); - search_path = result; - } else { - // Component not found, mission failed - return {}; - } - - return result.filename(); -} - int ModLastError = MODERR_NOERROR; std::filesystem::path mod_GetRealModuleName(const std::filesystem::path &mod_filename) { @@ -228,7 +184,7 @@ bool mod_LoadModule(module *handle, const std::filesystem::path &imodfilename, i if (!handle->handle) { // ok we couldn't find the given name...try other ways std::filesystem::path parent_path = modfilename.parent_path(); - std::filesystem::path new_filename = mod_FindRealFileNameCaseInsensitive(parent_path, modfilename.filename()); + std::filesystem::path new_filename = cf_FindRealFileNameCaseInsensitive(modfilename.filename(), parent_path); if (new_filename.empty()) { LOG_ERROR.printf("Module Load Err: %s", dlerror());