Skip to content

Commit 50511f1

Browse files
committed
xrCore/xrCore.cpp: setup SDL log callback
xrCore/xrDebug.cpp: a bit of formatting
1 parent 49bba13 commit 50511f1

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

src/xrCore/xrCore.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "stdafx.h"
44
#pragma hdrstop
55

6+
#include <SDL.h>
7+
68
#if defined(WINDOWS)
79
#include <mmsystem.h>
810
#include <objbase.h>
@@ -52,6 +54,107 @@ void PrintCI()
5254
#endif
5355
}
5456

57+
void SDLLogOutput(void* /*userdata*/,
58+
int category,
59+
SDL_LogPriority priority,
60+
const char* message)
61+
{
62+
pcstr from;
63+
switch (category)
64+
{
65+
case SDL_LOG_CATEGORY_APPLICATION:
66+
from = "application";
67+
break;
68+
69+
case SDL_LOG_CATEGORY_ERROR:
70+
from = "error";
71+
break;
72+
73+
case SDL_LOG_CATEGORY_ASSERT:
74+
from = "assert";
75+
break;
76+
77+
case SDL_LOG_CATEGORY_SYSTEM:
78+
from = "system";
79+
break;
80+
81+
case SDL_LOG_CATEGORY_AUDIO:
82+
from = "audio";
83+
break;
84+
85+
case SDL_LOG_CATEGORY_VIDEO:
86+
from = "video";
87+
break;
88+
89+
case SDL_LOG_CATEGORY_RENDER:
90+
from = "render";
91+
break;
92+
93+
case SDL_LOG_CATEGORY_INPUT:
94+
from = "input";
95+
break;
96+
97+
case SDL_LOG_CATEGORY_TEST:
98+
from = "test";
99+
break;
100+
101+
case SDL_LOG_CATEGORY_CUSTOM:
102+
from = "custom";
103+
break;
104+
105+
default:
106+
from = "unknown";
107+
break;
108+
}
109+
110+
char mark;
111+
pcstr type;
112+
switch (priority)
113+
{
114+
case SDL_LOG_PRIORITY_VERBOSE:
115+
mark = '%';
116+
type = "verbose";
117+
break;
118+
119+
case SDL_LOG_PRIORITY_DEBUG:
120+
mark = '#';
121+
type = "debug";
122+
break;
123+
124+
case SDL_LOG_PRIORITY_INFO:
125+
mark = '=';
126+
type = "info";
127+
break;
128+
129+
case SDL_LOG_PRIORITY_WARN:
130+
mark = '~';
131+
type = "warn";
132+
break;
133+
134+
case SDL_LOG_PRIORITY_ERROR:
135+
mark = '!';
136+
type = "error";
137+
break;
138+
139+
case SDL_LOG_PRIORITY_CRITICAL:
140+
mark = '$';
141+
type = "critical";
142+
break;
143+
144+
default:
145+
mark = ' ';
146+
type = "unknown";
147+
break;
148+
}
149+
150+
constexpr pcstr format = "%c [sdl][%s][%s]: %s";
151+
const size_t size = sizeof(mark) + sizeof(from) + sizeof(type) + sizeof(format) + sizeof(message);
152+
pstr buf = (pstr)_alloca(size);
153+
154+
xr_sprintf(buf, size, format, mark, from, type, message);
155+
Log(buf);
156+
}
157+
55158
void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pcstr fs_fname, bool plugin)
56159
{
57160
xr_strcpy(ApplicationName, _ApplicationName);
@@ -106,6 +209,7 @@ void xrCore::Initialize(pcstr _ApplicationName, LogCallback cb, bool init_fs, pc
106209

107210
Memory._initialize();
108211

212+
SDL_LogSetOutputFunction(SDLLogOutput, nullptr);
109213
Msg("%s %s build %d, %s\n", "OpenXRay", GetBuildConfiguration(), buildId, buildDate);
110214
PrintCI();
111215
Msg("command line %s\n", Params);

src/xrCore/xrDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int xrDebug::ShowMessage(pcstr title, pcstr message, bool simple)
173173
}
174174

175175
SDL_AssertState SDLAssertionHandler(const SDL_AssertData* data,
176-
void* userdata)
176+
void* /*userdata*/)
177177
{
178178
if (data->always_ignore)
179179
return SDL_ASSERTION_ALWAYS_IGNORE;

0 commit comments

Comments
 (0)