[SDL] Add global helper to setup the library.

Call to SDLHelper::Prepare() is needed before first SDL_InitSubSystem().
- Sets hints (SDL configuration vars).
- Configures logging.
This commit is contained in:
Joel Linn
2020-04-23 12:14:53 +02:00
committed by Rick Gibbed
parent 5463798631
commit 6267c73c4c
10 changed files with 149 additions and 42 deletions

View File

@@ -119,40 +119,6 @@ void XELOGFS(const char* format, const Args&... args) {
xe::logging::AppendLogLineFormat(xe::LogLevel::Info, 'F', format, args...);
}
// Redirect SDL_Log* output (internal library stuff) to our log system.
// Can't execute this code here without linking SDL2 into all projects.
// Use this macro everywhere SDL_InitSubSystem() is called.
#define XELOG_SDL_INIT() \
{ \
SDL_LogSetOutputFunction( \
[](void* userdata, int category, SDL_LogPriority priority, \
const char* message) { \
const char* msg_fmt = "SDL: {}"; \
switch (priority) { \
case SDL_LOG_PRIORITY_VERBOSE: \
case SDL_LOG_PRIORITY_DEBUG: \
XELOGD(msg_fmt, message); \
break; \
case SDL_LOG_PRIORITY_INFO: \
XELOGI(msg_fmt, message); \
break; \
case SDL_LOG_PRIORITY_WARN: \
XELOGW(msg_fmt, message); \
break; \
case SDL_LOG_PRIORITY_ERROR: \
case SDL_LOG_PRIORITY_CRITICAL: \
XELOGE(msg_fmt, message); \
break; \
default: \
XELOGI(msg_fmt, message); \
assert_always("SDL: Unknown log priority"); \
break; \
} \
}, \
nullptr); \
SDL_LogSetAllPriority(SDL_LogPriority::SDL_LOG_PRIORITY_VERBOSE); \
}
#else
#define XELOGDUMMY \
@@ -169,8 +135,6 @@ void XELOGFS(const char* format, const Args&... args) {
#define XELOGKERNEL(...) XELOGDUMMY
#define XELOGFS(...) XELOGDUMMY
#define XELOG_SDL_INIT() XELOGDUMMY
#undef XELOGDUMMY
#endif // ENABLE_LOGGING