2018-10-21 22:52:14 +02:00
|
|
|
/*
|
|
|
|
platform.h - common platform-dependent function defines
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#ifndef PLATFORM_H
|
|
|
|
#define PLATFORM_H
|
|
|
|
|
2018-11-16 14:32:16 +01:00
|
|
|
#include "common.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "defaults.h"
|
2022-04-22 19:31:10 +02:00
|
|
|
#include "cursor_type.h"
|
2022-04-22 19:33:07 +02:00
|
|
|
#include "key_modifiers.h"
|
2018-11-16 14:32:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
SYSTEM UTILS
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
double Platform_DoubleTime( void );
|
|
|
|
void Platform_Sleep( int msec );
|
2019-05-01 18:21:47 +02:00
|
|
|
void Platform_ShellExecute( const char *path, const char *parms );
|
2019-05-01 18:44:48 +02:00
|
|
|
void Platform_MessageBox( const char *title, const char *message, qboolean parentMainWindow );
|
2023-06-16 07:43:16 +02:00
|
|
|
void Platform_SetStatus( const char *status );
|
2024-02-27 03:17:01 +01:00
|
|
|
qboolean Platform_DebuggerPresent( void );
|
2023-06-16 07:43:16 +02:00
|
|
|
|
2023-10-27 13:25:16 +02:00
|
|
|
// legacy iOS port functions
|
|
|
|
#if TARGET_OS_IOS
|
|
|
|
const char *IOS_GetDocsDir( void );
|
2023-12-30 21:45:17 +01:00
|
|
|
void IOS_LaunchDialog( void );
|
2023-10-27 13:25:16 +02:00
|
|
|
#endif // TARGET_OS_IOS
|
|
|
|
|
2023-06-16 07:43:16 +02:00
|
|
|
#if XASH_WIN32 || XASH_LINUX
|
|
|
|
#define XASH_PLATFORM_HAVE_STATUS 1
|
|
|
|
#else
|
|
|
|
#undef XASH_PLATFORM_HAVE_STATUS
|
|
|
|
#endif
|
2018-11-16 14:32:16 +01:00
|
|
|
|
2023-06-16 06:32:19 +02:00
|
|
|
#if XASH_POSIX
|
|
|
|
void Posix_Daemonize( void );
|
2024-10-07 21:25:23 +02:00
|
|
|
void Posix_SetupSigtermHandling( void );
|
2023-06-16 06:32:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if XASH_SDL
|
|
|
|
void SDLash_Init( void );
|
|
|
|
void SDLash_Shutdown( void );
|
|
|
|
#endif
|
|
|
|
|
2019-11-24 01:52:08 +01:00
|
|
|
#if XASH_ANDROID
|
2019-05-02 17:07:03 +02:00
|
|
|
const char *Android_GetAndroidID( void );
|
|
|
|
const char *Android_LoadID( void );
|
|
|
|
void Android_SaveID( const char *id );
|
2023-06-05 20:35:58 +02:00
|
|
|
void Android_Init( void );
|
|
|
|
void *Android_GetNativeObject( const char *name );
|
2023-12-01 16:46:02 +01:00
|
|
|
int Android_GetKeyboardHeight( void );
|
|
|
|
void Android_Shutdown( void );
|
2019-05-02 17:07:03 +02:00
|
|
|
#endif
|
|
|
|
|
2022-04-06 14:06:16 +02:00
|
|
|
#if XASH_WIN32
|
2024-06-12 08:50:28 +02:00
|
|
|
void Wcon_CreateConsole( qboolean con_showalways );
|
2023-06-16 06:32:19 +02:00
|
|
|
void Wcon_DestroyConsole( void );
|
2024-07-21 01:06:51 +02:00
|
|
|
void Wcon_InitConsoleCommands( void );
|
|
|
|
void Wcon_ShowConsole( qboolean show );
|
|
|
|
void Wcon_DisableInput( void );
|
|
|
|
char *Wcon_Input( void );
|
|
|
|
void Wcon_WinPrint( const char *pMsg );
|
2023-06-05 19:29:05 +02:00
|
|
|
#endif
|
2022-04-06 14:06:16 +02:00
|
|
|
|
2023-02-05 02:09:32 +01:00
|
|
|
#if XASH_NSWITCH
|
|
|
|
void NSwitch_Init( void );
|
|
|
|
void NSwitch_Shutdown( void );
|
|
|
|
#endif
|
|
|
|
|
2023-02-13 20:53:17 +01:00
|
|
|
#if XASH_PSVITA
|
|
|
|
void PSVita_Init( void );
|
|
|
|
void PSVita_Shutdown( void );
|
|
|
|
qboolean PSVita_GetBasePath( char *buf, const size_t buflen );
|
2023-03-23 17:06:53 +01:00
|
|
|
int PSVita_GetArgv( int in_argc, char **in_argv, char ***out_argv );
|
2023-03-06 22:38:12 +01:00
|
|
|
void PSVita_InputUpdate( void );
|
2023-02-13 20:53:17 +01:00
|
|
|
#endif
|
|
|
|
|
2023-06-16 06:32:19 +02:00
|
|
|
#if XASH_DOS
|
|
|
|
void DOS_Init( void );
|
|
|
|
void DOS_Shutdown( void );
|
|
|
|
#endif
|
|
|
|
|
2023-06-16 07:43:16 +02:00
|
|
|
#if XASH_LINUX
|
|
|
|
void Linux_Init( void );
|
|
|
|
void Linux_Shutdown( void );
|
2023-12-24 05:46:09 +01:00
|
|
|
void Linux_SetTimer( float time );
|
2024-11-18 08:07:10 +01:00
|
|
|
int Linux_GetProcessID( void );
|
2023-06-16 07:43:16 +02:00
|
|
|
#endif
|
|
|
|
|
2024-06-12 08:50:28 +02:00
|
|
|
static inline void Platform_Init( qboolean con_showalways )
|
2023-06-16 06:32:19 +02:00
|
|
|
{
|
|
|
|
#if XASH_POSIX
|
2023-06-16 07:43:16 +02:00
|
|
|
// daemonize as early as possible, because we need to close our file descriptors
|
2023-06-16 06:32:19 +02:00
|
|
|
Posix_Daemonize( );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if XASH_SDL
|
|
|
|
SDLash_Init( );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if XASH_ANDROID
|
|
|
|
Android_Init( );
|
|
|
|
#elif XASH_NSWITCH
|
|
|
|
NSwitch_Init( );
|
|
|
|
#elif XASH_PSVITA
|
|
|
|
PSVita_Init( );
|
|
|
|
#elif XASH_DOS
|
|
|
|
DOS_Init( );
|
2023-06-16 07:43:16 +02:00
|
|
|
#elif XASH_WIN32
|
2024-06-12 08:50:28 +02:00
|
|
|
Wcon_CreateConsole( con_showalways );
|
2023-06-16 07:43:16 +02:00
|
|
|
#elif XASH_LINUX
|
|
|
|
Linux_Init( );
|
2023-06-16 06:32:19 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void Platform_Shutdown( void )
|
|
|
|
{
|
|
|
|
#if XASH_NSWITCH
|
|
|
|
NSwitch_Shutdown( );
|
|
|
|
#elif XASH_PSVITA
|
|
|
|
PSVita_Shutdown( );
|
|
|
|
#elif XASH_DOS
|
|
|
|
DOS_Shutdown( );
|
2023-06-16 07:43:16 +02:00
|
|
|
#elif XASH_WIN32
|
|
|
|
Wcon_DestroyConsole( );
|
|
|
|
#elif XASH_LINUX
|
|
|
|
Linux_Shutdown( );
|
2023-06-16 06:32:19 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if XASH_SDL
|
|
|
|
SDLash_Shutdown( );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-02-27 03:17:01 +01:00
|
|
|
static inline qboolean Sys_DebuggerPresent( void )
|
|
|
|
{
|
|
|
|
#if XASH_LINUX || XASH_WIN32
|
|
|
|
return Platform_DebuggerPresent();
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-10-07 21:25:23 +02:00
|
|
|
static inline void Platform_SetupSigtermHandling( void )
|
|
|
|
{
|
|
|
|
#if XASH_POSIX
|
|
|
|
Posix_SetupSigtermHandling( );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
MOBILE API
|
|
|
|
|
|
|
|
==============================================================================
|
2018-10-21 22:52:14 +02:00
|
|
|
*/
|
|
|
|
void Platform_Vibrate( float life, char flags );
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
INPUT
|
|
|
|
|
|
|
|
==============================================================================
|
2018-10-21 22:52:14 +02:00
|
|
|
*/
|
|
|
|
// Gamepad support
|
|
|
|
int Platform_JoyInit( int numjoy ); // returns number of connected gamepads, negative if error
|
|
|
|
// Text input
|
|
|
|
void Platform_EnableTextInput( qboolean enable );
|
2022-04-22 19:33:07 +02:00
|
|
|
key_modifier_t Platform_GetKeyModifiers( void );
|
2018-10-21 22:52:14 +02:00
|
|
|
// System events
|
|
|
|
void Platform_RunEvents( void );
|
2018-10-22 00:09:43 +02:00
|
|
|
// Mouse
|
|
|
|
void Platform_GetMousePos( int *x, int *y );
|
|
|
|
void Platform_SetMousePos( int x, int y );
|
2019-09-26 21:14:47 +02:00
|
|
|
void Platform_PreCreateMove( void );
|
2020-02-08 17:00:39 +01:00
|
|
|
void Platform_MouseMove( float *x, float *y );
|
2022-04-27 20:32:20 +02:00
|
|
|
void Platform_SetCursorType( VGUI_DefaultCursor type );
|
2018-10-22 00:25:29 +02:00
|
|
|
// Clipboard
|
2022-04-22 19:28:19 +02:00
|
|
|
int Platform_GetClipboardText( char *buffer, size_t size );
|
|
|
|
void Platform_SetClipboardText( const char *buffer );
|
2019-05-02 17:07:03 +02:00
|
|
|
|
2019-10-26 03:36:43 +02:00
|
|
|
#if XASH_SDL == 12
|
|
|
|
#define SDL_SetWindowGrab( wnd, state ) SDL_WM_GrabInput( (state) )
|
|
|
|
#define SDL_MinimizeWindow( wnd ) SDL_WM_IconifyWindow()
|
|
|
|
#define SDL_IsTextInputActive() host.textmode
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !XASH_SDL
|
|
|
|
#define SDL_VERSION_ATLEAST( x, y, z ) 0
|
|
|
|
#endif
|
|
|
|
|
2024-01-27 20:12:36 +01:00
|
|
|
static inline void Platform_SetTimer( float time )
|
2023-12-24 05:46:09 +01:00
|
|
|
{
|
|
|
|
#if XASH_LINUX
|
|
|
|
Linux_SetTimer( time );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
WINDOW MANAGEMENT
|
|
|
|
|
|
|
|
==============================================================================
|
2018-10-21 22:52:14 +02:00
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
rserr_ok,
|
|
|
|
rserr_invalid_fullscreen,
|
|
|
|
rserr_invalid_mode,
|
|
|
|
rserr_unknown
|
|
|
|
} rserr_t;
|
|
|
|
|
2019-10-26 14:42:00 +02:00
|
|
|
struct vidmode_s;
|
2023-10-10 13:11:06 +02:00
|
|
|
typedef enum window_mode_e window_mode_t;
|
2018-10-21 22:52:14 +02:00
|
|
|
// Window
|
2019-03-22 14:36:46 +01:00
|
|
|
qboolean R_Init_Video( const int type );
|
2018-10-21 22:52:14 +02:00
|
|
|
void R_Free_Video( void );
|
|
|
|
qboolean VID_SetMode( void );
|
2023-10-10 13:11:06 +02:00
|
|
|
rserr_t R_ChangeDisplaySettings( int width, int height, window_mode_t window_mode );
|
2019-10-05 01:07:49 +02:00
|
|
|
int R_MaxVideoModes( void );
|
2019-10-26 14:42:00 +02:00
|
|
|
struct vidmode_s *R_GetVideoMode( int num );
|
2018-10-21 22:52:14 +02:00
|
|
|
void* GL_GetProcAddress( const char *name ); // RenderAPI requirement
|
2019-03-11 15:37:58 +01:00
|
|
|
void GL_UpdateSwapInterval( void );
|
2019-03-16 03:15:32 +01:00
|
|
|
int GL_SetAttribute( int attr, int val );
|
|
|
|
int GL_GetAttribute( int attr, int *val );
|
2019-10-05 01:07:49 +02:00
|
|
|
void GL_SwapBuffers( void );
|
|
|
|
void *SW_LockBuffer( void );
|
|
|
|
void SW_UnlockBuffer( void );
|
2019-03-24 21:24:31 +01:00
|
|
|
qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b );
|
2018-10-21 22:52:14 +02:00
|
|
|
|
2019-10-21 20:41:44 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// in_evdev.c
|
|
|
|
//
|
2023-03-27 16:28:19 +02:00
|
|
|
#if XASH_USE_EVDEV
|
2019-10-21 20:41:44 +02:00
|
|
|
void Evdev_SetGrab( qboolean grab );
|
|
|
|
void Evdev_Shutdown( void );
|
|
|
|
void Evdev_Init( void );
|
|
|
|
void IN_EvdevMove( float *yaw, float *pitch );
|
|
|
|
void IN_EvdevFrame ( void );
|
|
|
|
#endif // XASH_USE_EVDEV
|
2019-01-07 02:07:01 +01:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
AUDIO INPUT/OUTPUT
|
2018-10-21 22:52:14 +02:00
|
|
|
|
2019-01-07 02:07:01 +01:00
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
// initializes cycling through a DMA buffer and returns information on it
|
2019-07-11 23:32:09 +02:00
|
|
|
qboolean SNDDMA_Init( void );
|
2019-01-07 02:07:01 +01:00
|
|
|
void SNDDMA_Shutdown( void );
|
|
|
|
void SNDDMA_BeginPainting( void );
|
|
|
|
void SNDDMA_Submit( void );
|
|
|
|
void SNDDMA_Activate( qboolean active ); // pause audio
|
|
|
|
// void SNDDMA_PrintDeviceName( void ); // unused
|
|
|
|
// void SNDDMA_LockSound( void ); // unused
|
|
|
|
// void SNDDMA_UnlockSound( void ); // unused
|
2022-08-31 05:50:06 +02:00
|
|
|
|
2021-05-09 15:32:53 +02:00
|
|
|
qboolean VoiceCapture_Init( void );
|
2022-08-20 02:17:51 +02:00
|
|
|
void VoiceCapture_Shutdown( void );
|
2022-08-31 05:50:06 +02:00
|
|
|
qboolean VoiceCapture_Activate( qboolean activate );
|
|
|
|
qboolean VoiceCapture_Lock( qboolean lock );
|
2018-10-21 22:52:14 +02:00
|
|
|
|
2023-12-01 16:46:02 +01:00
|
|
|
// this allows to make break in current line, without entering libc code
|
|
|
|
// libc built with -fomit-frame-pointer may just eat stack frame (hello, glibc), making entering libc even more useless
|
|
|
|
// calling syscalls directly allows to make break like if it was asm("int $3") on x86
|
|
|
|
#if XASH_LINUX && XASH_X86
|
|
|
|
#define INLINE_RAISE(x) asm volatile( "int $3;" );
|
|
|
|
#define INLINE_NANOSLEEP1() // nothing!
|
|
|
|
#elif XASH_LINUX && XASH_ARM && !XASH_64BIT
|
2024-11-18 08:07:10 +01:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
2023-12-01 16:46:02 +01:00
|
|
|
#define INLINE_RAISE(x) do \
|
|
|
|
{ \
|
|
|
|
int raise_pid = getpid(); \
|
2024-11-18 08:07:10 +01:00
|
|
|
pid_t raise_tid = Linux_GetProcessID(); \
|
2023-12-01 16:46:02 +01:00
|
|
|
int raise_sig = (x); \
|
|
|
|
__asm__ volatile ( \
|
|
|
|
"mov r7,#268\n\t" \
|
|
|
|
"mov r0,%0\n\t" \
|
|
|
|
"mov r1,%1\n\t" \
|
|
|
|
"mov r2,%2\n\t" \
|
|
|
|
"svc 0\n\t" \
|
|
|
|
: \
|
|
|
|
: "r"(raise_pid), "r"(raise_tid), "r"(raise_sig) \
|
2024-02-27 02:59:44 +01:00
|
|
|
: "r0", "r1", "r2", "r7", "memory" \
|
2023-12-01 16:46:02 +01:00
|
|
|
); \
|
|
|
|
} while( 0 )
|
|
|
|
#define INLINE_NANOSLEEP1() do \
|
|
|
|
{ \
|
|
|
|
struct timespec ns_t1 = {1, 0}; \
|
|
|
|
struct timespec ns_t2 = {0, 0}; \
|
|
|
|
__asm__ volatile ( \
|
|
|
|
"mov r7,#162\n\t" \
|
|
|
|
"mov r0,%0\n\t" \
|
|
|
|
"mov r1,%1\n\t" \
|
|
|
|
"svc 0\n\t" \
|
|
|
|
: \
|
|
|
|
: "r"(&ns_t1), "r"(&ns_t2) \
|
|
|
|
: "r0", "r1", "r7", "memory" \
|
|
|
|
); \
|
|
|
|
} while( 0 )
|
|
|
|
#elif XASH_LINUX && XASH_ARM && XASH_64BIT
|
2024-11-18 08:07:10 +01:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
2023-12-01 16:46:02 +01:00
|
|
|
#define INLINE_RAISE(x) do \
|
|
|
|
{ \
|
|
|
|
int raise_pid = getpid(); \
|
2024-11-18 08:07:10 +01:00
|
|
|
pid_t raise_tid = Linux_GetProcessID(); \
|
2023-12-01 16:46:02 +01:00
|
|
|
int raise_sig = (x); \
|
|
|
|
__asm__ volatile ( \
|
|
|
|
"mov x8,#131\n\t" \
|
|
|
|
"mov x0,%0\n\t" \
|
|
|
|
"mov x1,%1\n\t" \
|
|
|
|
"mov x2,%2\n\t" \
|
|
|
|
"svc 0\n\t" \
|
|
|
|
: \
|
|
|
|
: "r"(raise_pid), "r"(raise_tid), "r"(raise_sig) \
|
|
|
|
: "x0", "x1", "x2", "x8", "memory", "cc" \
|
|
|
|
); \
|
|
|
|
} while( 0 )
|
|
|
|
#define INLINE_NANOSLEEP1() do \
|
|
|
|
{ \
|
|
|
|
struct timespec ns_t1 = {1, 0}; \
|
|
|
|
struct timespec ns_t2 = {0, 0}; \
|
|
|
|
__asm__ volatile ( \
|
|
|
|
"mov x8,#101\n\t" \
|
|
|
|
"mov x0,%0\n\t" \
|
|
|
|
"mov x1,%1\n\t" \
|
|
|
|
"svc 0\n\t" \
|
|
|
|
: \
|
|
|
|
: "r"(&ns_t1), "r"(&ns_t2) \
|
|
|
|
: "x0", "x1", "x8", "memory", "cc" \
|
|
|
|
); \
|
|
|
|
} while( 0 )
|
|
|
|
#elif XASH_LINUX
|
2024-11-18 08:07:10 +01:00
|
|
|
#if defined( __NR_tgkill )
|
|
|
|
#define INLINE_RAISE(x) syscall( __NR_tgkill, getpid(), Linux_GetProcessID(), x )
|
2023-12-01 16:46:02 +01:00
|
|
|
#else // __NR_tgkill
|
|
|
|
#define INLINE_RAISE(x) raise(x)
|
|
|
|
#endif // __NR_tgkill
|
|
|
|
#define INLINE_NANOSLEEP1() do \
|
|
|
|
{ \
|
|
|
|
struct timespec ns_t1 = {1, 0}; \
|
|
|
|
struct timespec ns_t2 = {0, 0}; \
|
|
|
|
nanosleep( &ns_t1, &ns_t2 ); \
|
|
|
|
} while( 0 )
|
|
|
|
#else // generic
|
|
|
|
#define INLINE_RAISE(x) raise(x)
|
|
|
|
#define INLINE_NANOSLEEP1() sleep(1)
|
|
|
|
#endif // generic
|
|
|
|
|
2018-10-21 22:52:14 +02:00
|
|
|
#endif // PLATFORM_H
|