Skip to content

Commit

Permalink
Add display monitor improvements (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Aug 3, 2022
1 parent f5060c3 commit 25c1eee
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/display_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>

#include <fstream>

// 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)
Expand All @@ -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;

Expand Down Expand Up @@ -86,6 +95,9 @@ static int _disp_start;
// 0x56FB58
static unsigned int gDisplayMonitorLastBeepTimestamp;

static std::ofstream gConsoleFileStream;
static int gConsoleFilePrintCount = 0;

// 0x431610
int displayMonitorInit()
{
Expand Down Expand Up @@ -176,6 +188,9 @@ int displayMonitorInit()
_disp_curr = 0;

displayMonitorRefresh();

// SFALL
consoleFileInit();
}

return 0;
Expand All @@ -192,6 +207,9 @@ int displayMonitorReset()
_disp_start = 0;
_disp_curr = 0;
displayMonitorRefresh();

// SFALL
consoleFileReset();
}
return 0;
}
Expand All @@ -200,6 +218,9 @@ int displayMonitorReset()
void displayMonitorExit()
{
if (gDisplayMonitorInitialized) {
// SFALL
consoleFileExit();

internal_free(gDisplayMonitorBackgroundFrmData);
gDisplayMonitorInitialized = false;
}
Expand All @@ -212,6 +233,9 @@ void displayMonitorAddMessage(char* str)
return;
}

// SFALL
consoleFileAddMessage(str);

int oldFont = fontGetCurrent();
fontSetCurrent(DISPLAY_MONITOR_FONT);

Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/sfall_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions src/sfall_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 25c1eee

Please sign in to comment.