From 25c1eeee5cdf8e0903f9f3cf232ab56968758856 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Wed, 3 Aug 2022 13:54:26 +0300 Subject: [PATCH] Add display monitor improvements (#29) --- src/display_monitor.cc | 72 ++++++++++++++++++++++++++++++++++++++++++ src/sfall_config.cc | 1 + src/sfall_config.h | 1 + 3 files changed, 74 insertions(+) diff --git a/src/display_monitor.cc b/src/display_monitor.cc index 2077740..eadca6a 100644 --- a/src/display_monitor.cc +++ b/src/display_monitor.cc @@ -10,11 +10,14 @@ #include "geometry.h" #include "interface.h" #include "memory.h" +#include "sfall_config.h" #include "text_font.h" #include "window_manager.h" #include +#include + // The maximum number of lines display monitor can hold. Once this value // is reached earlier messages are thrown away. #define DISPLAY_MONITOR_LINES_CAPACITY (100) @@ -40,6 +43,12 @@ static void displayMonitorScrollUpOnMouseEnter(int btn, int keyCode); static void displayMonitorScrollDownOnMouseEnter(int btn, int keyCode); static void displayMonitorOnMouseExit(int btn, int keyCode); +static void consoleFileInit(); +static void consoleFileReset(); +static void consoleFileExit(); +static void consoleFileAddMessage(const char* message); +static void consoleFileFlush(); + // 0x51850C static bool gDisplayMonitorInitialized = false; @@ -86,6 +95,9 @@ static int _disp_start; // 0x56FB58 static unsigned int gDisplayMonitorLastBeepTimestamp; +static std::ofstream gConsoleFileStream; +static int gConsoleFilePrintCount = 0; + // 0x431610 int displayMonitorInit() { @@ -176,6 +188,9 @@ int displayMonitorInit() _disp_curr = 0; displayMonitorRefresh(); + + // SFALL + consoleFileInit(); } return 0; @@ -192,6 +207,9 @@ int displayMonitorReset() _disp_start = 0; _disp_curr = 0; displayMonitorRefresh(); + + // SFALL + consoleFileReset(); } return 0; } @@ -200,6 +218,9 @@ int displayMonitorReset() void displayMonitorExit() { if (gDisplayMonitorInitialized) { + // SFALL + consoleFileExit(); + internal_free(gDisplayMonitorBackgroundFrmData); gDisplayMonitorInitialized = false; } @@ -212,6 +233,9 @@ void displayMonitorAddMessage(char* str) return; } + // SFALL + consoleFileAddMessage(str); + int oldFont = fontGetCurrent(); fontSetCurrent(DISPLAY_MONITOR_FONT); @@ -389,3 +413,51 @@ void displayMonitorEnable() gDisplayMonitorEnabled = true; } } + +static void consoleFileInit() +{ + char* consoleFilePath; + configGetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONSOLE_OUTPUT_FILE_KEY, &consoleFilePath); + if (consoleFilePath != NULL && *consoleFilePath == '\0') { + consoleFilePath = NULL; + } + + if (consoleFilePath != NULL) { + gConsoleFileStream.open(consoleFilePath); + } +} + +static void consoleFileReset() +{ + if (gConsoleFileStream.is_open()) { + gConsoleFilePrintCount = 0; + gConsoleFileStream.flush(); + } +} + +static void consoleFileExit() +{ + if (gConsoleFileStream.is_open()) { + gConsoleFileStream.close(); + } +} + +static void consoleFileAddMessage(const char* message) +{ + if (gConsoleFileStream.is_open()) { + gConsoleFileStream << message << '\n'; + + gConsoleFilePrintCount++; + if (gConsoleFilePrintCount >= 20) { + consoleFileFlush(); + } + } +} + +static void consoleFileFlush() +{ + if (gConsoleFileStream.is_open()) { + gConsoleFilePrintCount = 0; + gConsoleFileStream.flush(); + } +} diff --git a/src/sfall_config.cc b/src/sfall_config.cc index 57b0e65..1e73ea9 100644 --- a/src/sfall_config.cc +++ b/src/sfall_config.cc @@ -39,6 +39,7 @@ bool sfallConfigInit(int argc, char** argv) configSetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_REMOVE_CRITICALS_TIME_LIMITS_KEY, false); configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_BOOKS_FILE_KEY, ""); configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_ELEVATORS_FILE_KEY, ""); + configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_CONSOLE_OUTPUT_FILE_KEY, ""); char path[COMPAT_MAX_PATH]; char* executable = argv[0]; diff --git a/src/sfall_config.h b/src/sfall_config.h index de8266d..f66652b 100644 --- a/src/sfall_config.h +++ b/src/sfall_config.h @@ -27,6 +27,7 @@ #define SFALL_CONFIG_REMOVE_CRITICALS_TIME_LIMITS_KEY "RemoveCriticalTimelimits" #define SFALL_CONFIG_BOOKS_FILE_KEY "BooksFile" #define SFALL_CONFIG_ELEVATORS_FILE_KEY "ElevatorsFile" +#define SFALL_CONFIG_CONSOLE_OUTPUT_FILE_KEY "ConsoleOutputPath" extern bool gSfallConfigInitialized; extern Config gSfallConfig;