From 9753f8367fa64b7d02bdf910bddceb51c42fd1e7 Mon Sep 17 00:00:00 2001 From: Jacob Coby Date: Tue, 23 Apr 2024 08:30:47 -0400 Subject: [PATCH 1/2] Enable console logging if MONO or LOGGER is defined Re-enable console logging on linux and mac builds with the -DMONO option. Rename overloaded Debug_ConsolePrintf function to Debug_ConsolePrintfAt to fix macro expansion. Adds -DLOGGER alias for -DMONO. Implements #157 --- CMakeLists.txt | 4 ++-- lib/debug.h | 4 ++-- lib/mono.h | 6 +++--- linux/lnxmono.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78f276f50..6d008e130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,13 +54,13 @@ endif() if(UNIX AND NOT APPLE) message("Building for Linux") - add_definitions( -D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -D__32BIT__ -DHAVEALLOCA_H -D_USE_OGL_ACTIVE_TEXTURES) + add_definitions( -D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -D__32BIT__ -DHAVEALLOCA_H -D_USE_OGL_ACTIVE_TEXTURES -DLOGGER) set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR}) endif() if(APPLE) message("Building for MAC OSX") - add_definitions(-D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -DMACOSX=1 -D_USE_OGL_ACTIVE_TEXTURES) + add_definitions(-D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -DMACOSX=1 -D_USE_OGL_ACTIVE_TEXTURES -DLOGGER) set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR} "/usr/X11/include") endif() diff --git a/lib/debug.h b/lib/debug.h index 58a3541d8..52dd81608 100644 --- a/lib/debug.h +++ b/lib/debug.h @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -166,7 +166,7 @@ bool Debug_ConsoleInit(); void Debug_ConsoleOpen(int n, int row, int col, int width, int height, char *title); void Debug_ConsoleClose(int n); void Debug_ConsolePrintf(int n, char *format, ...); -void Debug_ConsolePrintf(int n, int row, int col, char *format, ...); +void Debug_ConsolePrintfAt(int n, int row, int col, char *format, ...); void Debug_ConsoleRedirectMessages(int virtual_window, int physical_window); // DEBUGGING MACROS // Break into the debugger, if this feature was enabled in Debug_init() diff --git a/lib/mono.h b/lib/mono.h index c5b657072..a287c579d 100644 --- a/lib/mono.h +++ b/lib/mono.h @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -66,12 +66,12 @@ #include "debug.h" void nw_InitTCPLogging(char *ip, unsigned short port); void nw_TCPPrintf(int n, char *format, ...); -#if (!defined(RELEASE)) && defined(MONO) +#if (!defined(RELEASE)) && (defined(MONO) || defined(LOGGER)) extern bool Debug_print_block; // Prints a formatted string to the debug window #define mprintf(args) Debug_ConsolePrintf args // Prints a formatted string on window n at row, col. -#define mprintf_at(args) Debug_ConsolePrintf args +#define mprintf_at(args) Debug_ConsolePrintfAt args #define DebugBlockPrint(args) \ do { \ if (Debug_print_block) \ diff --git a/linux/lnxmono.cpp b/linux/lnxmono.cpp index 8ebf1ac6a..d25c437e7 100644 --- a/linux/lnxmono.cpp +++ b/linux/lnxmono.cpp @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -554,7 +554,7 @@ void Debug_ConsolePrintf(int n, char *format, ...) { } } -void Debug_ConsolePrintf(int n, int row, int col, char *format, ...) { +void Debug_ConsolePrintfAt(int n, int row, int col, char *format, ...) { if (!Mono_initialized) return; From 96ce6d2c73703d90fc3935f621308094ea0c9281 Mon Sep 17 00:00:00 2001 From: Jacob Coby Date: Tue, 23 Apr 2024 13:53:00 -0400 Subject: [PATCH 2/2] Logging updates: * Adds CMake Option * Adds LOGGER to the README * Removes MONO define in favor of LOGGER --- CMakeLists.txt | 11 +++++++++-- Descent3/init.cpp | 6 +++--- README.md | 6 +++--- lib/mono.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d008e130..34a1224f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ if(NOT MSVC) # GCC/clang or compatible, hopefully option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF) endif() +option(LOGGER "Enable logging to the terminal" OFF) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -54,13 +56,13 @@ endif() if(UNIX AND NOT APPLE) message("Building for Linux") - add_definitions( -D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -D__32BIT__ -DHAVEALLOCA_H -D_USE_OGL_ACTIVE_TEXTURES -DLOGGER) + add_definitions( -D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -D__32BIT__ -DHAVEALLOCA_H -D_USE_OGL_ACTIVE_TEXTURES) set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR}) endif() if(APPLE) message("Building for MAC OSX") - add_definitions(-D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -DMACOSX=1 -D_USE_OGL_ACTIVE_TEXTURES -DLOGGER) + add_definitions(-D_DEBUG -D__LINUX__ -DLINUX -D_MAX_PATH=260 -D_MAX_FNAME=256 -D_REENRANT -DMACOSX=1 -D_USE_OGL_ACTIVE_TEXTURES) set(PLATFORM_INCLUDES "lib/linux" ${SDL_INCLUDE_DIR} "/usr/X11/include") endif() @@ -97,6 +99,11 @@ if(WIN32) endif() endif() +if(LOGGER) + message("Enabling Logging") + add_definitions(-DLOGGER) +endif() + include_directories("lib" "Descent3" ${PLATFORM_INCLUDES}) # file(GLOB_RECURSE INCS "*.h") diff --git a/Descent3/init.cpp b/Descent3/init.cpp index abdad5878..da83633f3 100644 --- a/Descent3/init.cpp +++ b/Descent3/init.cpp @@ -1,5 +1,5 @@ /* -* Descent 3 +* Descent 3 * Copyright (C) 2024 Parallax Software * * This program is free software: you can redistribute it and/or modify @@ -1153,7 +1153,7 @@ void PreInitD3Systems() { debugging = (FindArg("-debug") != 0); -#ifdef MONO +#ifdef LOGGER console_output = true; #endif #ifndef MACINTOSH @@ -2151,7 +2151,7 @@ void InitD3Systems1(bool editor) { #if 0 //CD Check goes here //#if ( defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE)) ) - if( (!FindArg("-dedicated")) ) + if( (!FindArg("-dedicated")) ) PreGameCdCheck(); #endif diff --git a/README.md b/README.md index e3d20d71a..b66852cb7 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,14 @@ Build steps below assume you have already cloned the repository and entered it l Requires Visual Studio C++ Tools (cmake and nmake) ```sh cmake --preset win -cmake --build --preset win --config [Debug/Release] +cmake --build --preset win --config [Debug/Release] -D LOGGER=[ON|OFF] ``` #### Building - MacOS ```sh brew bundle install cmake --preset mac -cmake --build --preset mac --config [Debug/Release] +cmake --build --preset mac --config [Debug/Release] -D LOGGER=[ON|OFF] ``` #### Building - Linux @@ -44,7 +44,7 @@ sudo dpkg --add-architecture i386 sudo apt update sudo apt install -y --no-install-recommends ninja-build cmake g++ libsdl1.2-dev libsdl-image1.2-dev libncurses-dev libxext6:i386 cmake --preset linux -cmake --build --preset linux --config [Debug/Release] +cmake --build --preset linux --config [Debug/Release] -D LOGGER=[ON|OFF] ``` ## Contributing diff --git a/lib/mono.h b/lib/mono.h index a287c579d..89c1706ad 100644 --- a/lib/mono.h +++ b/lib/mono.h @@ -66,7 +66,7 @@ #include "debug.h" void nw_InitTCPLogging(char *ip, unsigned short port); void nw_TCPPrintf(int n, char *format, ...); -#if (!defined(RELEASE)) && (defined(MONO) || defined(LOGGER)) +#if (!defined(RELEASE)) && defined(LOGGER) extern bool Debug_print_block; // Prints a formatted string to the debug window #define mprintf(args) Debug_ConsolePrintf args