Skip to content

Commit

Permalink
Fix console colors not working before an iwad has been selected
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jan 6, 2025
1 parent 1825562 commit fc895a4
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 127 deletions.
1 change: 1 addition & 0 deletions src/common/engine/i_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct WadStuff

extern FString endoomName;
extern bool batchrun;
extern bool RunningAsTool;
extern float menuBlurAmount;
extern bool generic_ui;
extern bool special_i;
Expand Down
36 changes: 36 additions & 0 deletions src/common/fonts/v_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "texturemanager.h"
#include "printf.h"
#include "palentry.h"
#include "i_interface.h"

#include "fontinternals.h"

Expand Down Expand Up @@ -784,6 +785,41 @@ static void CalcDefaultTranslation(FFont* base, int index)

PalEntry V_LogColorFromColorRange (EColorRange range)
{
// Console wants to use colors before we loaded anything and we can't retroactively apply them like we can for the console in the game
if (RunningAsTool)
{
static std::vector<PalEntry> colors =
{
0x00cc3333,
0x00d2b48c,
0x00cccccc,
0x0000cc00,
0x00996633,
0x00ffcc00,
0x00ff5566,
0x009999ff,
0x00ffaa00,
0x00dfdfdf,
0x00eeee33,
0x00dfdfdf,
0x00000000,
0x0033eeff,
0x00ffcc99,
0x00d1d8a8,
0x00008c00,
0x00800000,
0x00663333,
0x009966cc,
0x00808080,
0x0000dddd,
0x007c7c98,
0x00d57604,
0x00506cfc,
0x00236773,
};
return (size_t)range >= colors.size() ? DEFAULT_LOG_COLOR : colors[range];
}

if ((unsigned int)range >= TranslationColors.Size())
{ // Return default color
return DEFAULT_LOG_COLOR;
Expand Down
37 changes: 33 additions & 4 deletions src/common/platform/posix/cocoa/i_main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
EXTERN_CVAR(Bool, vid_vsync )

int GameMain();

extern bool RunningAsTool = false;

// ---------------------------------------------------------------------------


Expand Down Expand Up @@ -528,9 +531,7 @@ void ReleaseApplicationController()
}
}

} // unnamed namespace

int I_GameMain(int argc, char** argv)
void InitArgs(int argc, char** argv)
{
for (int i = 0; i < argc; ++i)
{
Expand All @@ -549,6 +550,13 @@ int I_GameMain(int argc, char** argv)

s_argv.Push(argument);
}
}

} // unnamed namespace

int I_GameMain(int argc, char** argv)
{
InitArgs(argc, argv);

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

Expand All @@ -574,7 +582,28 @@ int I_GameMain(int argc, char** argv)
return EXIT_SUCCESS;
}

// Note: no idea if this actually works as I don't have a macOS machine nowadays.
// It is possible this function should do exactly the same as the linux/posix version.
// Not really sure how Cocoa initialization and macOS bundles affects console applications on macOS, if at all.
int I_ToolMain(int argc, char** argv)
{
return I_GameMain(argc, argv);
RunningAsTool = true;

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

seteuid(getuid());

// Set LC_NUMERIC environment variable in case some library decides to
// clear the setlocale call at least this will be correct.
// Note that the LANG environment variable is overridden by LC_*
setenv("LC_NUMERIC", "C", 1);
setlocale(LC_ALL, "C");

Args = new FArgs(argc, argv);

NSString* exePath = [[NSBundle mainBundle] executablePath];
progdir = [[exePath stringByDeletingLastPathComponent] UTF8String];
progdir += "/";

return GameMain();
}
2 changes: 1 addition & 1 deletion src/common/platform/posix/cocoa/i_system.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CalculateCPUSpeed()
PerfToSec = 1.0 / frequency;
PerfToMillisec = 1000.0 / frequency;

if (!batchrun)
if (!batchrun && !RunningAsTool)
{
Printf("CPU speed: %.0f MHz\n", 0.001 / PerfToMillisec);
}
Expand Down
89 changes: 49 additions & 40 deletions src/common/platform/posix/sdl/i_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@
#include "i_interface.h"
#include "printf.h"

// MACROS ------------------------------------------------------------------

// TYPES -------------------------------------------------------------------

// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------

extern "C" int cc_install_handlers(int, char**, int, int*, const char*, int(*)(char*, char*));
extern bool RunningAsTool;

#ifdef __APPLE__
void Mac_I_FatalError(const char* errortext);
Expand All @@ -69,26 +64,11 @@ void Mac_I_FatalError(const char* errortext);
void Linux_I_FatalError(const char* errortext);
#endif

// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
int GameMain();

// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

// PUBLIC DATA DEFINITIONS -------------------------------------------------
FString sys_ostype;

// The command line arguments.
FArgs *Args;

// PRIVATE DATA DEFINITIONS ------------------------------------------------


// CODE --------------------------------------------------------------------



static int GetCrashInfo (char *buffer, char *end)
{
if (sysCallbacks.CrashInfo) sysCallbacks.CrashInfo(buffer, end - buffer, "\n");
Expand Down Expand Up @@ -146,43 +126,44 @@ void I_DetectOS()

void I_StartupJoysticks();

int I_GameMain(int argc, char** argv)
void InitCrashReporter()
{
#if !defined (__APPLE__)
{
int s[4] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS };
cc_install_handlers(argc, argv, 4, s, GAMENAMELOWERCASE "-crash.log", GetCrashInfo);
}
#endif // !__APPLE__
}

printf(GAMENAME" %s - %s - SDL version\nCompiled on %s\n",
GetVersionString(), GetGitTime(), __DATE__);
void SetEffectiveUser()
{
seteuid(getuid());
}

seteuid (getuid ());
void InitLocale()
{
// Set LC_NUMERIC environment variable in case some library decides to
// clear the setlocale call at least this will be correct.
// Note that the LANG environment variable is overridden by LC_*
setenv ("LC_NUMERIC", "C", 1);

setlocale (LC_ALL, "C");

if (SDL_Init (0) < 0)
{
fprintf (stderr, "Could not initialize SDL:\n%s\n", SDL_GetError());
return -1;
}

printf("\n");
setenv("LC_NUMERIC", "C", 1);
setlocale(LC_ALL, "C");
}

void InitArgs(int argc, char** argv)
{
Args = new FArgs(argc, argv);
}

void InitExePath()
{
#ifdef PROGDIR
progdir = PROGDIR;
#else
char program[PATH_MAX];
if (realpath (argv[0], program) == NULL)
strcpy (program, argv[0]);
char *slash = strrchr (program, '/');
if (realpath(argv[0], program) == NULL)
strcpy(program, argv[0]);
char* slash = strrchr(program, '/');
if (slash != NULL)
{
*(slash + 1) = '\0';
Expand All @@ -193,6 +174,26 @@ int I_GameMain(int argc, char** argv)
progdir = "./";
}
#endif
}

int I_GameMain(int argc, char** argv)
{
InitCrashReporter();
SetEffectiveUser();
InitLocale();

printf(GAMENAME" %s - %s - SDL version\nCompiled on %s\n", GetVersionString(), GetGitTime(), __DATE__);

if (SDL_Init (0) < 0)
{
fprintf (stderr, "Could not initialize SDL:\n%s\n", SDL_GetError());
return -1;
}

printf("\n");

InitArgs(argc, argv);
InitExePath();

I_StartupJoysticks();

Expand All @@ -205,5 +206,13 @@ int I_GameMain(int argc, char** argv)

int I_ToolMain(int argc, char** argv)
{
return I_GameMain(argc, argv);
RunningAsTool = true;

InitCrashReporter();
SetEffectiveUser();
InitLocale();
InitArgs(argc, argv);
InitExePath();

return GameMain();
}
2 changes: 1 addition & 1 deletion src/common/platform/posix/sdl/i_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void CalculateCPUSpeed()
PerfAvailable = true;
PerfToSec = .000001/mhz;
PerfToMillisec = PerfToSec*1000.;
if (!batchrun) Printf("CPU speed: %.0f MHz\n", mhz);
if (!batchrun && !RunningAsTool) Printf("CPU speed: %.0f MHz\n", mhz);
close(fd);
#endif
}
Expand Down
Loading

0 comments on commit fc895a4

Please sign in to comment.