engine: platform: sdl: set up our custom log output function to catch all SDL errors in engine log file

This commit is contained in:
Alibek Omarov 2025-01-08 10:10:41 +03:00
parent 80bac157eb
commit ceb603488a

View file

@ -41,8 +41,54 @@ void Platform_MessageBox( const char *title, const char *message, qboolean paren
}
#endif // XASH_MESSAGEBOX == MSGBOX_SDL
static const char *SDLash_CategoryToString( int category )
{
switch( category )
{
case SDL_LOG_CATEGORY_APPLICATION: return "App";
case SDL_LOG_CATEGORY_ERROR: return "Error";
case SDL_LOG_CATEGORY_ASSERT: return "Assert";
case SDL_LOG_CATEGORY_SYSTEM: return "System";
case SDL_LOG_CATEGORY_AUDIO: return "Audio";
case SDL_LOG_CATEGORY_VIDEO: return "Video";
case SDL_LOG_CATEGORY_RENDER: return "Render";
case SDL_LOG_CATEGORY_INPUT: return "Input";
case SDL_LOG_CATEGORY_TEST: return "Test";
default: return "Unknown";
}
}
static void SDLCALL SDLash_LogOutputFunction( void *userdata, int category, SDL_LogPriority priority, const char *message )
{
switch( priority )
{
case SDL_LOG_PRIORITY_CRITICAL:
case SDL_LOG_PRIORITY_ERROR:
Con_Printf( S_ERROR S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", SDLash_CategoryToString( category ), message );
break;
case SDL_LOG_PRIORITY_WARN:
Con_DPrintf( S_WARN S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", SDLash_CategoryToString( category ), message );
break;
case SDL_LOG_PRIORITY_INFO:
Con_Reportf( S_NOTE S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", SDLash_CategoryToString( category ), message );
break;
default:
Con_Reportf( S_BLUE "SDL" S_DEFAULT ": [%s] %s\n", SDLash_CategoryToString( category ), message );
break;
}
}
void SDLash_Init( void )
{
SDL_LogSetOutputFunction( SDLash_LogOutputFunction, NULL );
if( host_developer.value >= 2 )
SDL_LogSetAllPriority( SDL_LOG_PRIORITY_VERBOSE );
else if( host_developer.value >= 1 )
SDL_LogSetAllPriority( SDL_LOG_PRIORITY_WARN );
else
SDL_LogSetAllPriority( SDL_LOG_PRIORITY_ERROR );
#ifndef SDL_INIT_EVENTS
#define SDL_INIT_EVENTS 0
#endif