2018-11-16 16:32:16 +03:00
|
|
|
/*
|
|
|
|
sys_sdl.c - SDL2 system utils
|
|
|
|
Copyright (C) 2018 a1batross
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
#include "platform/platform.h"
|
2022-06-02 03:01:58 +03:00
|
|
|
#include "events.h"
|
2018-11-16 16:32:16 +03:00
|
|
|
|
|
|
|
#if XASH_TIMER == TIMER_SDL
|
|
|
|
double Platform_DoubleTime( void )
|
|
|
|
{
|
2025-01-22 15:09:18 +03:00
|
|
|
static Uint64 g_PerformanceFrequency;
|
|
|
|
static Uint64 g_ClockStart;
|
|
|
|
Uint64 CurrentTime;
|
2018-11-16 16:32:16 +03:00
|
|
|
|
|
|
|
if( !g_PerformanceFrequency )
|
|
|
|
{
|
|
|
|
g_PerformanceFrequency = SDL_GetPerformanceFrequency();
|
|
|
|
g_ClockStart = SDL_GetPerformanceCounter();
|
|
|
|
}
|
|
|
|
CurrentTime = SDL_GetPerformanceCounter();
|
|
|
|
return (double)( CurrentTime - g_ClockStart ) / (double)( g_PerformanceFrequency );
|
|
|
|
}
|
2025-02-28 13:14:47 +03:00
|
|
|
|
|
|
|
void Platform_Sleep( int msec )
|
|
|
|
{
|
|
|
|
SDL_Delay( msec );
|
|
|
|
}
|
2024-12-04 18:32:03 +03:00
|
|
|
#endif // XASH_TIMER == TIMER_SDL
|
2018-11-16 16:32:16 +03:00
|
|
|
|
2019-10-26 04:36:43 +03:00
|
|
|
#if XASH_MESSAGEBOX == MSGBOX_SDL
|
2019-05-01 19:44:48 +03:00
|
|
|
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow )
|
|
|
|
{
|
|
|
|
SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR, title, message, parentMainWindow ? host.hWnd : NULL );
|
|
|
|
}
|
2019-10-26 04:36:43 +03:00
|
|
|
#endif // XASH_MESSAGEBOX == MSGBOX_SDL
|
2023-06-16 07:32:19 +03:00
|
|
|
|
2025-01-08 10:10:41 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-23 10:22:53 +03:00
|
|
|
void SDLash_Init( const char *basedir )
|
2020-02-08 23:00:39 +07:00
|
|
|
{
|
2025-01-19 22:00:45 -06:00
|
|
|
#if XASH_APPLE
|
2025-01-23 10:22:53 +03:00
|
|
|
char *path = SDL_GetBasePath();
|
|
|
|
if( path != NULL )
|
|
|
|
{
|
|
|
|
char buf[MAX_VA_STRING];
|
|
|
|
|
2025-01-26 13:08:35 -06:00
|
|
|
Q_snprintf( buf, sizeof( buf ), "%s%s/extras.pk3", path, basedir );
|
2025-01-23 10:22:53 +03:00
|
|
|
setenv( "XASH3D_EXTRAS_PAK1", buf, true );
|
|
|
|
}
|
2025-01-19 22:00:45 -06:00
|
|
|
#endif
|
|
|
|
|
2025-01-08 10:10:41 +03:00
|
|
|
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 );
|
|
|
|
|
2020-02-08 23:00:39 +07:00
|
|
|
#ifndef SDL_INIT_EVENTS
|
|
|
|
#define SDL_INIT_EVENTS 0
|
2020-02-08 23:38:19 +07:00
|
|
|
#endif
|
2020-02-08 23:00:39 +07:00
|
|
|
if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) )
|
|
|
|
{
|
|
|
|
Sys_Warn( "SDL_Init failed: %s", SDL_GetError() );
|
|
|
|
host.type = HOST_DEDICATED;
|
|
|
|
}
|
|
|
|
|
2025-02-28 13:14:47 +03:00
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
SDL_SetHint( SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0" );
|
|
|
|
SDL_SetHint( SDL_HINT_MOUSE_TOUCH_EVENTS, "0" );
|
|
|
|
SDL_SetHint( SDL_HINT_TOUCH_MOUSE_EVENTS, "0" );
|
|
|
|
|
2020-02-08 23:00:39 +07:00
|
|
|
SDL_StopTextInput();
|
|
|
|
#endif // XASH_SDL == 2
|
2023-02-09 05:59:30 +03:00
|
|
|
|
2022-05-30 03:33:03 +03:00
|
|
|
SDLash_InitCursors();
|
2020-02-08 23:48:52 +07:00
|
|
|
}
|
|
|
|
|
2023-06-16 07:32:19 +03:00
|
|
|
void SDLash_Shutdown( void )
|
2020-02-08 23:48:52 +07:00
|
|
|
{
|
2022-05-30 03:33:03 +03:00
|
|
|
SDLash_FreeCursors();
|
2024-12-04 16:14:56 +03:00
|
|
|
|
|
|
|
SDL_Quit();
|
2022-05-30 03:33:03 +03:00
|
|
|
}
|