Compare commits

...

37 Commits

Author SHA1 Message Date
Alibek Omarov
71b715875a scripts: gha: try to update vitaGL 2025-02-05 14:48:24 +03:00
Alibek Omarov
54b0cf9991 ref: gl: check OES NPOT texture extension in BigGL mode 2025-02-05 14:00:44 +03:00
Alibek Omarov
3ebcb08a97 ref: gl: add cvar r_large_lightmaps to enable larger lightmap sizes, opt-in, yields better performance with VBO renderer 2025-02-05 13:02:37 +03:00
Alibek Omarov
23940f8590 readme: remove fontconfig from dependencies list, we aren't using it anymore [skip ci] 2025-02-04 21:00:42 +03:00
Alibek Omarov
687fb0123f engine: implement basic gamepad gyroscope calibration
Called on game controller becoming active or by user request.
Exposes current calibration state by read-only console variable.
2025-02-03 13:14:51 +03:00
Alibek Omarov
6c91fdb0cd ref: gl: gl2_shim: fix int vs GLuint 2025-02-02 20:57:37 +03:00
Alibek Omarov
4832232fd6 ci: attempt to fix flatpak upload 2025-02-02 20:31:51 +03:00
Alibek Omarov
185bce0489 engine: common: remove unused D_ enum used for MsgDev in old engine. Make sure all enums and structs here are not anonymous 2025-02-02 20:26:07 +03:00
Alibek Omarov
f460aa63b0 engine: platform: posix: don't forget to print backtrace to stderr too 2025-02-02 19:20:54 +03:00
Alibek Omarov
22f8b6f9c3 engine: platform: enable crash handler for macOS 2025-02-02 18:30:41 +03:00
Alibek Omarov
0cb034afc2 engine: wscript: improve execinfo and GNU backtrace() check 2025-02-02 18:18:26 +03:00
Alibek Omarov
d0464ef602 engine: platform: posix: use glibc-based backtrace implementation for crash handling, if execinfo.h can be found 2025-02-02 18:06:18 +03:00
Alibek Omarov
c3ebb84b97 ci: bump SDL2 to 2.30.12 2025-02-02 08:14:24 +03:00
Alibek Omarov
11742efbc3 engine: fix player move on dedicated servers 2025-02-02 08:08:15 +03:00
Alibek Omarov
95af635ab4 engine: client: add command replaybufferdat to aid in debugging protocol errors by parsing buffer.dat 2025-02-02 05:22:46 +03:00
Alibek Omarov
1abec80191 engine: client: set codepage to 0 if con_charset value is unknown 2025-02-02 02:34:08 +03:00
Alibek Omarov
93ebddfba3 public: utflib: simplify Q_EncodeUTF8 2025-02-02 02:31:56 +03:00
Alibek Omarov
5378494199 wscript: enable main() function for Android port, which was forgotten after last refactoring 2025-02-01 18:26:20 +03:00
Alibek Omarov
1b44d7733e engine: platform: add improved Platform_Vibrate2 function, that allows to control vibration strength 2025-02-01 18:08:53 +03:00
Alibek Omarov
694c630b44 engine: zone: don't error when trying to free NULL pointer, like standard C free() and C++ delete 2025-02-01 17:51:02 +03:00
Alibek Omarov
7df1d4b9e2 engine: platform: sdl: remove useless for us game controller events 2025-01-31 19:48:33 +03:00
Alibek Omarov
b16037eabf engine: drop raw SDL joystick API, always use GameController instead. Implement actually working rumble, ensure we're freeing up all resources related to gamepads 2025-01-31 17:50:19 +03:00
Alibek Omarov
bff7299f9b gha: publish binaries even if flatpak fails 2025-01-31 10:37:41 +03:00
Alibek Omarov
de196b1c58 common: xash3d_types: avoid defining true and false in C23 2025-01-31 10:36:27 +03:00
Alibek Omarov
a0eec8b85d scripts: waifulib: add special_install_path for platform-specific executable formats that create post link stage (was nro_install_path) 2025-01-31 10:25:02 +03:00
Alibek Omarov
c7e8ea2ffa scripts: gha: linux: build smaller SDL2 (without 2D renderer) for Linux as well 2025-01-31 10:02:19 +03:00
Alibek Omarov
1c1cf3d646 scripts: waifulib: psvita: make sce_sys truly optional in apply_vpk 2025-01-31 10:02:19 +03:00
Alibek Omarov
9759b80b78 scripts: waifulib: psvita: set default title id and app name to just test 2025-01-31 09:10:39 +03:00
Alibek Omarov
94b2c0b443 scripts: gha: build render-less SDL2 for PSVita 2025-01-31 09:10:09 +03:00
Alibek Omarov
ff8d17a5a8 scripts: waifulib: psvita: add missing cprogram attributes 2025-01-31 09:04:40 +03:00
Alibek Omarov
aa23196a55 scripts: waifulib: support vpk and nro pass for pure C programs, just in case 2025-01-30 20:51:01 +03:00
Alibek Omarov
83b488c37e wscript: let building client and dedicated server in the same configuration 2025-01-30 20:23:12 +03:00
Alibek Omarov
77abf621d7 ref: gl: make GL_Support and GL_MaxTextureUnits functions inlined 2025-01-30 19:02:53 +03:00
Alibek Omarov
f9d4ac2771 ref: gl: fix ugly seam at the skybox, thanks Spoike for help 2025-01-30 18:53:31 +03:00
Alibek Omarov
f076d84975 engine: platform: android: move dlsym-weak hack from C++ to C 2025-01-30 18:07:35 +03:00
Alibek Omarov
faf0b32a94 ref: gl: fix massive frame drop caused by ripples code rendering same texture multiple times in the frame 2025-01-29 20:15:21 +03:00
Alibek Omarov
feb80e5997 engine: platform: sdl: read gamecontrollerdb.txt from extras.pk3 2025-01-29 13:43:10 +03:00
38 changed files with 973 additions and 772 deletions

View File

@@ -66,7 +66,7 @@ jobs:
targetos: apple
targetarch: amd64
env:
SDL_VERSION: 2.30.11
SDL_VERSION: 2.30.12
GH_CPU_ARCH: ${{ matrix.targetarch }}
GH_CROSSCOMPILING: ${{ matrix.cross }}
steps:
@@ -87,6 +87,7 @@ jobs:
path: artifacts/*
flatpak:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
include:
@@ -100,7 +101,7 @@ jobs:
with:
submodules: recursive
- name: Build flatpak (Compat.i386)
uses: FWGS/flatpak-github-actions/flatpak-builder@v6.3
uses: FWGS/flatpak-github-actions/flatpak-builder@v6.3-fix
with:
bundle: ${{ matrix.app }}.flatpak
manifest-path: scripts/flatpak/${{ matrix.app }}.yml

View File

@@ -65,21 +65,21 @@ This repository contains our fork of HLSDK and restored source code for Half-Lif
* Only for 32-bit engine on 64-bit x86 operating system:
* Enable i386 on your system: `$ sudo dpkg --add-architecture i386`.
* Install `aptitude` ([why?](https://github.com/FWGS/xash3d-fwgs/issues/1828#issuecomment-2415131759)): `$ sudo apt update && sudo apt upgrade && sudo apt install aptitude`
* Install development tools: `$ sudo aptitude --without-recommends install git build-essential gcc-multilib g++-multilib libsdl2-dev:i386 libfontconfig-dev:i386 libfreetype-dev:i386 libopus-dev:i386 libbz2-dev:i386`.
* Install development tools: `$ sudo aptitude --without-recommends install git build-essential gcc-multilib g++-multilib libsdl2-dev:i386 libfreetype-dev:i386 libopus-dev:i386 libbz2-dev:i386`.
* Set PKG_CONFIG_PATH environment variable to point at 32-bit libraries: `$ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig`.
* For 64-bit engine on 64-bit x86 and other non-x86 systems:
* Install development tools: `$ sudo apt install git build-essential python libsdl2-dev libfontconfig-dev libfreetype6-dev libopus-dev libbz2-dev`.
* Install development tools: `$ sudo apt install git build-essential python libsdl2-dev libfreetype6-dev libopus-dev libbz2-dev`.
* Clone this repostory: `$ git clone --recursive https://github.com/FWGS/xash3d-fwgs`.
##### RedHat/Fedora
* Only for 32-bit engine on 64-bit x86 operating system:
* Install development tools: `$ sudo dnf install git gcc gcc-c++ glibc-devel.i686 SDL2-devel.i686 opus-devel.i686 fontconfig-devel.i686 freetype-devel.i686 bzip2-devel.i686`.
* Install development tools: `$ sudo dnf install git gcc gcc-c++ glibc-devel.i686 SDL2-devel.i686 opus-devel.i686 freetype-devel.i686 bzip2-devel.i686`.
* Set PKG_CONFIG_PATH environment variable to point at 32-bit libraries: `$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig`.
* For 64-bit engine on 64-bit x86 and other non-x86 systems:
* Install development tools: `$ sudo dnf install git gcc gcc-c++ SDL2-devel opus-devel fontconfig-devel freetype-devel bzip2-devel`.
* Install development tools: `$ sudo dnf install git gcc gcc-c++ SDL2-devel opus-devel freetype-devel bzip2-devel`.
* Clone this repostory: `$ git clone --recursive https://github.com/FWGS/xash3d-fwgs`.

View File

@@ -31,11 +31,11 @@ typedef uint32_t poolhandle_t;
#undef true
#undef false
#ifndef __cplusplus
typedef enum { false, true } qboolean;
#else
typedef int qboolean;
// true and false are keywords in C++ and C23
#if !__cplusplus && __STDC_VERSION__ < 202311L
enum { false, true };
#endif
typedef int qboolean;
#define MAX_STRING 256 // generic string
#define MAX_VA_STRING 1024 // compatibility macro

View File

@@ -198,3 +198,44 @@ void CL_WriteMessageHistory( void )
CL_WriteErrorMessage( old->starting_offset, msg );
cls_message_debug.parsing = false;
}
void CL_ReplayBufferDat_f( void )
{
file_t *f = FS_Open( Cmd_Argv( 1 ), "rb", true );
sizebuf_t msg;
char buffer[NET_MAX_MESSAGE];
int starting_count, current_count, protocol;
fs_offset_t len;
if( !f )
return;
FS_Read( f, &starting_count, sizeof( starting_count ));
FS_Read( f, &current_count, sizeof( current_count ));
FS_Read( f, &protocol, sizeof( protocol ));
cls.legacymode = protocol;
len = FS_Read( f, buffer, sizeof( buffer ));
FS_Close( f );
MSG_Init( &msg, __func__, buffer, len );
Delta_Shutdown();
Delta_Init();
clgame.maxEntities = MAX_EDICTS;
clgame.entities = Mem_Calloc( clgame.mempool, sizeof( *clgame.entities ) * clgame.maxEntities );
// ad-hoc implement
#if 0
{
const int message_pos = 12; // put real number here
MSG_SeekToBit( &msg, ( message_pos - 12 + 1 ) << 3, SEEK_SET );
CL_ParseYourMom( &msg, protocol );
}
#endif
Sys_Quit( __func__ );
}

View File

@@ -3489,6 +3489,8 @@ static void CL_InitLocal( void )
Cmd_AddCommand ("fullserverinfo", CL_FullServerinfo_f, "sent by server when serverinfo changes" );
Cmd_AddCommand ("upload", CL_BeginUpload_f, "uploading file to the server" );
Cmd_AddRestrictedCommand( "replaybufferdat", CL_ReplayBufferDat_f, "development and debugging tool" );
Cmd_AddRestrictedCommand ("quit", CL_Quit_f, "quit from game" );
Cmd_AddRestrictedCommand ("exit", CL_Quit_f, "quit from game" );

View File

@@ -737,6 +737,7 @@ void CL_ClearResourceLists( void );
//
// cl_debug.c
//
void CL_ReplayBufferDat_f( void );
void CL_Parse_Debug( qboolean enable );
void CL_Parse_RecordCommand( int cmd, int startoffset );
void CL_ResetFrame( frame_t *frame );

View File

@@ -622,7 +622,7 @@ int Con_UtfProcessCharForce( int in )
// TODO: get rid of global state where possible
static utfstate_t state = { 0 };
int ch = Q_DecodeUTF8( &state, in );
uint32_t ch = Q_DecodeUTF8( &state, in );
if( g_codepage == 1251 )
return Q_UnicodeToCP1251( ch );
@@ -2092,10 +2092,7 @@ void Con_RunConsole( void )
}
else
{
Con_Printf( S_WARN "Unknown charset %s, defaulting to cp1252", con_charset.string );
Cvar_DirectSet( &con_charset, "cp1252" );
g_codepage = 1252;
g_codepage = 0;
}
cls.accept_utf8 = !Q_stricmp( cl_charset.string, "utf-8" );

View File

@@ -43,7 +43,6 @@ static struct joy_axis_s
short val;
short prevval;
} joyaxis[MAX_AXES] = { 0 };
static byte currentbinding; // add posibility to remap keys, to place it in joykeys[]
static qboolean joy_initialized;
static CVAR_DEFINE_AUTO( joy_pitch, "100.0", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "joystick pitch sensitivity" );
@@ -60,9 +59,9 @@ static CVAR_DEFINE_AUTO( joy_pitch_deadzone, DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE
static CVAR_DEFINE_AUTO( joy_yaw_deadzone, DEFAULT_JOY_DEADZONE, FCVAR_ARCHIVE | FCVAR_FILTERABLE, "yaw axis deadzone. Value from 0 to 32767" );
static CVAR_DEFINE_AUTO( joy_axis_binding, "sfpyrl", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "axis hardware id to engine inner axis binding, "
"s - side, f - forward, y - yaw, p - pitch, r - left trigger, l - right trigger" );
static CVAR_DEFINE_AUTO( joy_found, "0", FCVAR_READ_ONLY, "is joystick is connected" );
static CVAR_DEFINE_AUTO( joy_index, "0", FCVAR_READ_ONLY, "current active joystick" );
CVAR_DEFINE_AUTO( joy_enable, "1", FCVAR_ARCHIVE | FCVAR_FILTERABLE, "enable joystick" );
static CVAR_DEFINE_AUTO( joy_have_gyro, "0", FCVAR_READ_ONLY, "tells whether current active gamepad has gyroscope or not" );
static CVAR_DEFINE_AUTO( joy_calibrated, "0", FCVAR_READ_ONLY, "tells whether current active gamepad gyroscope has been calibrated or not" );
/*
============
@@ -71,7 +70,30 @@ Joy_IsActive
*/
qboolean Joy_IsActive( void )
{
return joy_found.value && joy_enable.value;
return joy_enable.value;
}
/*
===========
Joy_SetCapabilities
===========
*/
void Joy_SetCapabilities( qboolean have_gyro )
{
Cvar_FullSet( joy_have_gyro.name, have_gyro ? "1" : "0", joy_have_gyro.flags );
}
/*
===========
Joy_SetCalibrationState
===========
*/
void Joy_SetCalibrationState( joy_calibration_state_t state )
{
if( (int)joy_calibrated.value == state )
return;
Cvar_FullSet( joy_calibrated.name, va( "%d", state ), joy_calibrated.flags );
}
/*
@@ -81,7 +103,7 @@ Joy_HatMotionEvent
DPad events
============
*/
void Joy_HatMotionEvent( byte hat, byte value )
static void Joy_HatMotionEvent( int value )
{
struct
{
@@ -96,9 +118,6 @@ void Joy_HatMotionEvent( byte hat, byte value )
};
int i;
if( !joy_found.value )
return;
for( i = 0; i < ARRAYSIZE( keys ); i++ )
{
if( value & keys[i].mask )
@@ -225,7 +244,7 @@ static void Joy_ProcessStick( const engineAxis_t engineAxis, short value )
val |= Joy_GetHatValueForAxis( JOY_AXIS_SIDE );
val |= Joy_GetHatValueForAxis( JOY_AXIS_FWD );
Joy_HatMotionEvent( 0, val );
Joy_HatMotionEvent( val );
}
}
@@ -236,23 +255,9 @@ Joy_AxisMotionEvent
Axis events
=============
*/
void Joy_AxisMotionEvent( byte axis, short value )
void Joy_AxisMotionEvent( engineAxis_t engineAxis, short value )
{
if( !joy_found.value )
return;
if( axis >= MAX_AXES )
{
Con_Reportf( "Only 6 axes is supported\n" );
return;
}
Joy_KnownAxisMotionEvent( joyaxesmap[axis], value );
}
void Joy_KnownAxisMotionEvent( engineAxis_t engineAxis, short value )
{
if( engineAxis == JOY_AXIS_NULL )
if( engineAxis >= JOY_AXIS_NULL )
return;
if( value == joyaxis[engineAxis].val )
@@ -266,66 +271,14 @@ void Joy_KnownAxisMotionEvent( engineAxis_t engineAxis, short value )
/*
=============
Joy_BallMotionEvent
Joy_GyroEvent
Trackball events. UNDONE
Gyroscope events
=============
*/
void Joy_BallMotionEvent( byte ball, short xrel, short yrel )
void Joy_GyroEvent( vec3_t data )
{
//if( !joy_found.value )
// return;
}
/*
=============
Joy_ButtonEvent
Button events
=============
*/
void Joy_ButtonEvent( byte button, byte down )
{
if( !joy_found.value )
return;
// generic game button code.
if( button > 32 )
{
int origbutton = button;
button = ( button & 31 ) + K_AUX1;
Con_Reportf( "Only 32 joybuttons is supported, converting %i button ID to %s\n", origbutton, Key_KeynumToString( button ) );
}
else button += K_AUX1;
Key_Event( button, down );
}
/*
=============
Joy_RemoveEvent
Called when joystick is removed. For future expansion
=============
*/
void Joy_RemoveEvent( void )
{
if( joy_found.value )
Cvar_FullSet( "joy_found", "0", FCVAR_READ_ONLY );
}
/*
=============
Joy_RemoveEvent
Called when joystick is removed. For future expansion
=============
*/
void Joy_AddEvent( void )
{
if( joy_enable.value && !joy_found.value )
Cvar_FullSet( "joy_found", "1", FCVAR_READ_ONLY );
}
/*
@@ -364,14 +317,19 @@ void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw )
*fw -= joy_forward.value * (float)joyaxis[JOY_AXIS_FWD ].val/(float)SHRT_MAX; // must be form -1.0 to 1.0
*side += joy_side.value * (float)joyaxis[JOY_AXIS_SIDE].val/(float)SHRT_MAX;
#if !defined(XASH_SDL)
*dpitch += joy_pitch.value * (float)joyaxis[JOY_AXIS_PITCH].val/(float)SHRT_MAX * host.realframetime; // abs axis rotate is frametime related
*dyaw -= joy_yaw.value * (float)joyaxis[JOY_AXIS_YAW ].val/(float)SHRT_MAX * host.realframetime;
#else
// HACKHACK: SDL have inverted look axis.
*dpitch -= joy_pitch.value * (float)joyaxis[JOY_AXIS_PITCH].val/(float)SHRT_MAX * host.realframetime;
*dyaw += joy_yaw.value * (float)joyaxis[JOY_AXIS_YAW ].val/(float)SHRT_MAX * host.realframetime;
#endif
}
static void Joy_CalibrateGyro_f( void )
{
if( !joy_have_gyro.value )
{
Con_Printf( "Current active gamepad doesn't have gyroscope\n" );
return;
}
Platform_CalibrateGamepadGyro();
}
/*
@@ -383,6 +341,8 @@ Main init procedure
*/
void Joy_Init( void )
{
Cmd_AddRestrictedCommand( "joy_calibrate_gyro", Joy_CalibrateGyro_f, "calibrate gamepad gyroscope. You must to put gamepad on stationary surface" );
Cvar_RegisterVariable( &joy_pitch );
Cvar_RegisterVariable( &joy_yaw );
Cvar_RegisterVariable( &joy_side );
@@ -402,11 +362,9 @@ void Joy_Init( void )
Cvar_RegisterVariable( &joy_yaw_deadzone );
Cvar_RegisterVariable( &joy_axis_binding );
Cvar_RegisterVariable( &joy_found );
// we doesn't loaded config.cfg yet, so this cvar is not archive.
// change by +set joy_index in cmdline
Cvar_RegisterVariable( &joy_index );
Cvar_RegisterVariable( &joy_have_gyro );
Cvar_RegisterVariable( &joy_calibrated );
Cvar_RegisterVariable( &joy_enable );
// renamed from -nojoy to -noenginejoy to not conflict with
@@ -417,7 +375,7 @@ void Joy_Init( void )
return;
}
Cvar_FullSet( "joy_found", va( "%d", Platform_JoyInit( joy_index.value )), FCVAR_READ_ONLY );
Platform_JoyInit();
joy_initialized = true;
}
@@ -431,8 +389,5 @@ Shutdown joystick code
*/
void Joy_Shutdown( void )
{
if( joy_initialized )
{
Cvar_FullSet( "joy_found", 0, FCVAR_READ_ONLY );
}
Platform_JoyShutdown();
}

View File

@@ -104,18 +104,21 @@ typedef enum engineAxis_e
JOY_AXIS_NULL
} engineAxis_t;
typedef enum joy_calibration_state_s
{
JOY_NOT_CALIBRATED = 0,
JOY_CALIBRATING,
JOY_FAILED_TO_CALIBRATE,
JOY_CALIBRATED
} joy_calibration_state_t;
qboolean Joy_IsActive( void );
void Joy_HatMotionEvent( byte hat, byte value );
void Joy_AxisMotionEvent( byte axis, short value );
void Joy_KnownAxisMotionEvent( engineAxis_t engineAxis, short value );
void Joy_BallMotionEvent( byte ball, short xrel, short yrel );
void Joy_ButtonEvent( byte button, byte down );
void Joy_AddEvent( void );
void Joy_RemoveEvent( void );
void Joy_SetCapabilities( qboolean have_gyro );
void Joy_SetCalibrationState( joy_calibration_state_t state );
void Joy_AxisMotionEvent( engineAxis_t engineAxis, short value );
void Joy_GyroEvent( vec3_t data );
void Joy_FinalizeMove( float *fw, float *side, float *dpitch, float *dyaw );
void Joy_Init( void );
void Joy_Shutdown( void );
void Joy_EnableTextInput(qboolean enable, qboolean force);
#endif//INPUT_H

View File

@@ -1107,7 +1107,7 @@ static qboolean OSK_KeyEvent( int key, int down )
/*
=============
Joy_EnableTextInput
OSK_EnableTextInput
Enables built-in IME
=============

View File

@@ -76,23 +76,14 @@ XASH SPECIFIC - sort of hack that works only in Xash3D not in GoldSrc
#define HACKS_RELATED_HLMODS // some HL-mods works differently under Xash and can't be fixed without some hacks at least at current time
enum
enum dev_level_e
{
DEV_NONE = 0,
DEV_NORMAL,
DEV_EXTENDED
};
enum
{
D_INFO = 1, // "-dev 1", shows various system messages
D_WARN, // "-dev 2", shows not critical system warnings
D_ERROR, // "-dev 3", shows critical warnings
D_REPORT, // "-dev 4", special case for game reports
D_NOTE // "-dev 5", show system notifications for engine developers
};
typedef enum
typedef enum instance_e
{
HOST_NORMAL, // listen server, singleplayer
HOST_DEDICATED,
@@ -194,7 +185,7 @@ GAMEINFO stuff
internal shared gameinfo structure (readonly for engine parts)
========================================================================
*/
typedef enum
typedef enum host_status_e
{
HOST_INIT = 0, // initalize operations
HOST_FRAME, // host running
@@ -205,7 +196,7 @@ typedef enum
HOST_CRASHED // an exception handler called
} host_status_t;
typedef enum
typedef enum host_state_e
{
STATE_RUNFRAME = 0,
STATE_LOAD_LEVEL,
@@ -214,7 +205,7 @@ typedef enum
STATE_GAME_SHUTDOWN,
} host_state_t;
typedef struct
typedef struct game_status_e
{
host_state_t curstate;
host_state_t nextstate;
@@ -225,7 +216,7 @@ typedef struct
qboolean newGame; // unload the server.dll before start a new map
} game_status_t;
typedef enum
typedef enum keydest_e
{
key_console = 0,
key_game,
@@ -233,7 +224,7 @@ typedef enum
key_message
} keydest_t;
typedef enum
typedef enum rdtype_e
{
RD_NONE = 0,
RD_CLIENT,
@@ -243,7 +234,7 @@ typedef enum
#include "net_ws.h"
// console field
typedef struct
typedef struct field_e
{
string buffer;
int cursor;
@@ -261,7 +252,7 @@ typedef struct host_redirect_s
int lines;
} host_redirect_t;
typedef struct
typedef struct soundlist_e
{
char name[MAX_QPATH];
short entnum;
@@ -302,7 +293,7 @@ typedef struct host_parm_s
host_status_t status; // global host state
game_status_t game; // game manager
uint type; // running at
instance_t type; // running at
poolhandle_t mempool; // static mempool for misc allocations
poolhandle_t imagepool; // imagelib mempool
poolhandle_t soundpool; // soundlib mempool
@@ -496,7 +487,7 @@ internal sound format
typically expanded to wav buffer
========================================================================
*/
typedef enum
typedef enum sndformat_e
{
WF_UNKNOWN = 0,
WF_PCMDATA,
@@ -507,7 +498,7 @@ typedef enum
} sndformat_t;
// wavdata output flags
typedef enum
typedef enum sndFlags_e
{
// wavdata->flags
SOUND_LOOPED = BIT( 0 ), // this is looped sound (contain cue markers)
@@ -517,7 +508,7 @@ typedef enum
SOUND_RESAMPLE = BIT( 12 ), // resample sound to specified rate
} sndFlags_t;
typedef struct
typedef struct wavdata_s
{
size_t size; // for bounds checking
uint loopStart; // offset at this point sound will be looping while playing more than only once
@@ -733,7 +724,7 @@ qboolean UI_CreditsActive( void );
int CL_GetMaxClients( void );
#else
static inline qboolean CL_Initialized( void ) { return false; }
static inline qboolean CL_IsInGame( void ) { return false; }
static inline qboolean CL_IsInGame( void ) { return true; } // always true for dedicated
static inline qboolean CL_IsInConsole( void ) { return false; }
static inline qboolean CL_IsIntermission( void ) { return false; }
static inline qboolean CL_DisableVisibility( void ) { return false; }

View File

@@ -201,7 +201,6 @@ static void Sys_PrintUsage( const char *exename )
O("-daemonize ", "run engine as a daemon")
#endif
#if XASH_SDL == 2
O("-sdl_joy_old_api ","use SDL legacy joystick API")
O("-sdl_renderer <n> ","use alternative SDL_Renderer for software")
#endif // XASH_SDL
#if XASH_ANDROID && !XASH_SDL

View File

@@ -231,10 +231,7 @@ static void Mem_FreeBlock( memheader_t *mem, const char *filename, int fileline
void _Mem_Free( void *data, const char *filename, int fileline )
{
if( data == NULL )
{
Sys_Error( "%s: data == NULL (called at %s:%i)\n", __func__, filename, fileline );
return;
}
Mem_FreeBlock((memheader_t *)((byte *)data - sizeof( memheader_t )), filename, fileline );
}

View File

@@ -32,7 +32,7 @@
#include <android/log.h>
#include "linker.h"
static const Elf_Sym *soinfo_elf_lookup( const soinfo *si, unsigned hash, const char *name )
static const Elf_Sym *soinfo_elf_lookup( const struct soinfo *si, unsigned hash, const char *name )
{
const Elf_Sym *symtab = si->symtab;
const char *strtab = si->strtab;
@@ -87,14 +87,14 @@ static unsigned elfhash( const unsigned char *name )
Binary Interface) where in Chapter 5 it discuss resolving "Shared
Object Dependencies" in breadth first search order.
*/
static const Elf_Sym *dlsym_handle_lookup( const soinfo *si, const char *name )
static const Elf_Sym *dlsym_handle_lookup( const struct soinfo *si, const char *name )
{
return soinfo_elf_lookup( si, elfhash((const unsigned char *)name ), name );
}
extern "C" void *dlsym_weak( void *handle, const char *symbol )
void *dlsym_weak( void *handle, const char *symbol )
{
const soinfo *found = (soinfo *)handle;
const struct soinfo *found = (struct soinfo *)handle;
const Elf_Sym *sym = dlsym_handle_lookup( found, symbol );
if( sym != NULL )

View File

@@ -31,10 +31,8 @@
#include <unistd.h>
#include <sys/types.h>
// #include <elf.h>
#include <stdbool.h>
#include <linux/elf.h>
// #include <sys/exec_elf.h>
// #include <link.h>
// a1ba: we don't really need custom linker on Android 64, because
// it's only intended to workaround bug which persist on Android < 4.4
@@ -69,8 +67,8 @@ struct link_map_t {
uintptr_t l_addr;
char *l_name;
uintptr_t l_ld;
link_map_t *l_next;
link_map_t *l_prev;
struct link_map_t *l_next;
struct link_map_t *l_prev;
};
// Values for r_debug->state
@@ -85,7 +83,7 @@ enum {
#define SOINFO_NAME_LEN 128
typedef void (*linker_function_t)();
typedef void (*linker_function_t)( void );
// Android uses REL for 32-bit but only uses RELA for 64-bit.
#if defined( __LP64__ )
@@ -93,7 +91,6 @@ typedef void (*linker_function_t)();
#endif
struct soinfo {
public:
char name[SOINFO_NAME_LEN];
const Elf_Phdr *phdr;
size_t phnum;
@@ -112,7 +109,7 @@ public:
uint32_t unused3; // DO NOT USE, maintained for compatibility
#endif
soinfo *next;
struct soinfo *next;
unsigned flags;
const char *strtab;
@@ -164,8 +161,8 @@ public:
unsigned mips_gotsym;
#endif
size_t ref_count;
link_map_t link_map;
size_t ref_count;
struct link_map_t link_map;
bool constructors_called;
@@ -177,14 +174,6 @@ public:
bool has_text_relocations;
#endif
bool has_DT_SYMBOLIC;
void CallConstructors();
void CallDestructors();
void CallPreInitConstructors();
private:
void CallArray( const char *array_name, linker_function_t *functions, size_t count, bool reverse );
void CallFunction( const char *function_name, linker_function_t function );
};
#endif

View File

@@ -91,11 +91,6 @@ void GAME_EXPORT Platform_SetMousePos(int x, int y)
}
int Platform_JoyInit( int numjoy )
{
return 0;
}
void Platform_EnableTextInput( qboolean enable )
{
keystate.chars = enable;

View File

@@ -281,13 +281,8 @@ void GAME_EXPORT Platform_SetMousePos(int x, int y)
}
void Platform_Vibrate(float life, char flags)
void Platform_Vibrate( float life, char flags )
{
}
int Platform_JoyInit( int numjoy )
{
return 0;
}
#endif

View File

@@ -178,7 +178,7 @@ static inline void Platform_Sleep( int msec )
#endif
}
#if XASH_WIN32 || XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX
#if XASH_WIN32 || XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX || XASH_APPLE
void Sys_SetupCrashHandler( void );
void Sys_RestoreCrashHandler( void );
#else
@@ -199,7 +199,8 @@ static inline void Sys_RestoreCrashHandler( void )
==============================================================================
*/
void Platform_Vibrate( float life, char flags );
void Platform_Vibrate( float life, char flags ); // left for compatibility
void Platform_Vibrate2( float time, int low_freq, int high_freq, uint flags );
/*
==============================================================================
@@ -209,7 +210,27 @@ void Platform_Vibrate( float life, char flags );
==============================================================================
*/
// Gamepad support
int Platform_JoyInit( int numjoy ); // returns number of connected gamepads, negative if error
#if XASH_SDL
int Platform_JoyInit( void ); // returns number of connected gamepads, negative if error
void Platform_JoyShutdown( void );
void Platform_CalibrateGamepadGyro( void );
#else
static inline int Platform_JoyInit( void )
{
return 0;
}
static inline void Platform_JoyShutdown( void )
{
}
static inline void Platform_CalibrateGamepadGyro( void )
{
}
#endif
// Text input
void Platform_EnableTextInput( qboolean enable );
key_modifier_t Platform_GetKeyModifiers( void );

View File

@@ -0,0 +1,85 @@
/*
crashhandler.c - advanced crashhandler
Copyright (C) 2016 Mittorn
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.
*/
// on Glibc (which potentially might not be only Linux) systems we
// have backtrace() and backtrace_symbols() calls, which replace for us
// platform-specific code
#if HAVE_EXECINFO
#include "common.h"
#include <execinfo.h>
#include <signal.h>
void Sys_Crash( int signal, siginfo_t *si, void *context )
{
char message[8192];
int len, logfd, i = 0;
int size;
void *addrs[16];
char **syms;
// safe actions first, stack and memory may be corrupted
len = Q_snprintf( message, sizeof( message ), "Ver: " XASH_ENGINE_NAME " " XASH_VERSION " (build %i-%s, %s-%s)\n",
Q_buildnum(), g_buildcommit, Q_buildos(), Q_buildarch() );
#if !XASH_FREEBSD && !XASH_NETBSD && !XASH_OPENBSD && !XASH_APPLE // they don't have si_ptr
len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p %p\n", signal, si->si_errno, si->si_code, si->si_addr, si->si_ptr );
#else
len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p\n", signal, si->si_errno, si->si_code, si->si_addr );
#endif
write( STDERR_FILENO, message, len );
// flush buffers before writing directly to descriptors
fflush( stdout );
fflush( stderr );
// now get log fd and write trace directly to log
logfd = Sys_LogFileNo();
write( logfd, message, len );
size = backtrace( addrs, sizeof( addrs ) / sizeof( addrs[0] ));
syms = backtrace_symbols( addrs, size );
for( i = 0; i < size && syms; i++ )
{
size_t symlen = Q_strlen( syms[i] );
char ch = '\n';
write( logfd, syms[i], symlen );
write( logfd, &ch, 1 );
write( STDERR_FILENO, syms[i], symlen );
write( STDERR_FILENO, &ch, 1 );
len += Q_snprintf( message + len, sizeof( message ) - len, "%2d: %s\n", i, syms[i] );
}
// put MessageBox as Sys_Error
Msg( "%s\n", message );
#ifdef XASH_SDL
SDL_SetWindowGrab( host.hWnd, SDL_FALSE );
#endif
host.crashed = true;
Platform_MessageBox( "Xash Error", message, false );
// log saved, now we can try to save configs and close log correctly, it may crash
if( host.type == HOST_NORMAL )
CL_Crashed();
host.status = HOST_CRASHED;
Sys_Quit( "crashed" );
}
#endif // HAVE_EXECINFO

View File

@@ -18,7 +18,8 @@ GNU General Public License for more details.
// while this is mostly POSIX-compatible functions
// the contents of ucontext_t is platform-dependent
// before adding new OS here, check platform.h
#if XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX
#define _XOPEN_SOURCE 1 // required for ucontext
#if XASH_FREEBSD || XASH_NETBSD || XASH_OPENBSD || XASH_ANDROID || XASH_LINUX || XASH_APPLE
#ifndef XASH_OPENBSD
#include <ucontext.h>
#endif
@@ -26,6 +27,11 @@ GNU General Public License for more details.
#include <sys/mman.h>
#include "library.h"
void Sys_Crash( int signal, siginfo_t *si, void *context );
static struct sigaction oldFilter;
#if !HAVE_EXECINFO
#define STACK_BACKTRACE_STR "Stack backtrace:\n"
#define STACK_DUMP_STR "Stack dump:\n"
@@ -33,8 +39,6 @@ GNU General Public License for more details.
#define STACK_DUMP_STR_LEN ( sizeof( STACK_DUMP_STR ) - 1 )
#define ALIGN( x, y ) (((uintptr_t) ( x ) + (( y ) - 1 )) & ~(( y ) - 1 ))
static struct sigaction oldFilter;
static int Sys_PrintFrame( char *buf, int len, int i, void *addr )
{
Dl_info dlinfo;
@@ -53,7 +57,7 @@ static int Sys_PrintFrame( char *buf, int len, int i, void *addr )
return Q_snprintf( buf, len, "%2d: %p\n", i, addr ); // print only address
}
static void Sys_Crash( int signal, siginfo_t *si, void *context)
void Sys_Crash( int signal, siginfo_t *si, void *context )
{
void *pc = NULL, **bp = NULL, **sp = NULL; // this must be set for every OS!
char message[8192];
@@ -115,7 +119,7 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
len = Q_snprintf( message, sizeof( message ), "Ver: " XASH_ENGINE_NAME " " XASH_VERSION " (build %i-%s, %s-%s)\n",
Q_buildnum(), g_buildcommit, Q_buildos(), Q_buildarch() );
#if !XASH_FREEBSD && !XASH_NETBSD && !XASH_OPENBSD
#if !XASH_FREEBSD && !XASH_NETBSD && !XASH_OPENBSD && !XASH_APPLE
len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p %p\n", signal, si->si_errno, si->si_code, si->si_addr, si->si_ptr );
#else
len += Q_snprintf( message + len, sizeof( message ) - len, "Crash: signal %d errno %d with code %d at %p\n", signal, si->si_errno, si->si_code, si->si_addr );
@@ -200,6 +204,8 @@ static void Sys_Crash( int signal, siginfo_t *si, void *context)
Sys_Quit( "crashed" );
}
#endif // !HAVE_EXECINFO
void Sys_SetupCrashHandler( void )
{
struct sigaction act = { 0 };

View File

@@ -88,52 +88,8 @@ GNU General Public License for more details.
#define SDL_SCANCODE_PRINTSCREEN SDLK_PRINT
#define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN
#define SDL_GetScancodeName( x ) "unknown"
#define SDL_JoystickID Uint8
#endif
static int SDLash_GameControllerButtonMapping[] =
{
#if XASH_NSWITCH // devkitPro/SDL has inverted Nintendo layout for SDL_GameController
K_B_BUTTON, K_A_BUTTON, K_Y_BUTTON, K_X_BUTTON,
#else
K_A_BUTTON, K_B_BUTTON, K_X_BUTTON, K_Y_BUTTON,
#endif
K_BACK_BUTTON, K_MODE_BUTTON, K_START_BUTTON,
K_LSTICK, K_RSTICK,
K_L1_BUTTON, K_R1_BUTTON,
K_DPAD_UP, K_DPAD_DOWN, K_DPAD_LEFT, K_DPAD_RIGHT,
K_MISC_BUTTON,
K_PADDLE1_BUTTON, K_PADDLE2_BUTTON, K_PADDLE3_BUTTON, K_PADDLE4_BUTTON,
K_TOUCHPAD,
};
// Swap axis to follow default axis binding:
// LeftX, LeftY, RightX, RightY, TriggerRight, TriggerLeft
static int SDLash_GameControllerAxisMapping[] =
{
JOY_AXIS_SIDE, // SDL_CONTROLLER_AXIS_LEFTX,
JOY_AXIS_FWD, // SDL_CONTROLLER_AXIS_LEFTY,
JOY_AXIS_PITCH, // SDL_CONTROLLER_AXIS_RIGHTX,
JOY_AXIS_YAW, // SDL_CONTROLLER_AXIS_RIGHTY,
JOY_AXIS_LT, // SDL_CONTROLLER_AXIS_TRIGGERLEFT,
JOY_AXIS_RT, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
};
static qboolean SDLash_IsInstanceIDAGameController( SDL_JoystickID joyId )
{
#if !SDL_VERSION_ATLEAST( 2, 0, 4 )
// HACKHACK: if we're not initialized g_joy, then we're probably using gamecontroller api
// so return true
if( !g_joy )
return true;
return false;
#else
if( SDL_GameControllerFromInstanceID( joyId ) != NULL )
return true;
return false;
#endif
}
/*
=============
SDLash_KeyEvent
@@ -408,50 +364,6 @@ static void SDLash_ActiveEvent( int gain )
}
}
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
static size_t num_open_game_controllers = 0;
static void SDLash_GameController_Add( int index )
{
extern convar_t joy_enable; // private to input system
SDL_GameController *controller;
if( !joy_enable.value )
return;
controller = SDL_GameControllerOpen( index );
if( !controller )
{
Con_Reportf( "Failed to open SDL GameController %d: %s\n", index, SDL_GetError( ) );
SDL_ClearError( );
return;
}
#if SDL_VERSION_ATLEAST( 2, 0, 6 )
Con_Reportf( "Added controller: %s (%i:%i:%i)\n",
SDL_GameControllerName( controller ),
SDL_GameControllerGetVendor( controller ),
SDL_GameControllerGetProduct( controller ),
SDL_GameControllerGetProductVersion( controller ));
#endif // SDL_VERSION_ATLEAST( 2, 0, 6 )
++num_open_game_controllers;
if( num_open_game_controllers == 1 )
Joy_AddEvent( );
}
static void SDLash_GameController_Remove( SDL_JoystickID joystick_id )
{
Con_Reportf( "Removed controller %i\n", joystick_id );
// `Joy_RemoveEvent` sets `joy_found` to `0`.
// We only want to do this when all the game controllers have been removed.
--num_open_game_controllers;
if( num_open_game_controllers == 0 )
Joy_RemoveEvent( );
}
#endif
/*
=============
SDLash_EventFilter
@@ -479,28 +391,6 @@ static void SDLash_EventHandler( SDL_Event *event )
SDLash_KeyEvent( event->key );
break;
/* Joystick events */
case SDL_JOYAXISMOTION:
if ( !SDLash_IsInstanceIDAGameController( event->jaxis.which ))
Joy_AxisMotionEvent( event->jaxis.axis, event->jaxis.value );
break;
case SDL_JOYBALLMOTION:
if ( !SDLash_IsInstanceIDAGameController( event->jball.which ))
Joy_BallMotionEvent( event->jball.ball, event->jball.xrel, event->jball.yrel );
break;
case SDL_JOYHATMOTION:
if ( !SDLash_IsInstanceIDAGameController( event->jhat.which ))
Joy_HatMotionEvent( event->jhat.hat, event->jhat.value );
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
if ( !SDLash_IsInstanceIDAGameController( event->jbutton.which ))
Joy_ButtonEvent( event->jbutton.button, event->jbutton.state );
break;
case SDL_QUIT:
Sys_Quit( "caught SDL_QUIT" );
break;
@@ -568,46 +458,17 @@ static void SDLash_EventHandler( SDL_Event *event )
SDLash_InputEvent( event->text );
break;
case SDL_JOYDEVICEADDED:
Joy_AddEvent();
break;
case SDL_JOYDEVICEREMOVED:
Joy_RemoveEvent();
break;
/* GameController API */
case SDL_CONTROLLERAXISMOTION:
{
if( !Joy_IsActive( ))
break;
if( event->caxis.axis >= 0 && event->caxis.axis < ARRAYSIZE( SDLash_GameControllerAxisMapping ))
{
Joy_KnownAxisMotionEvent( SDLash_GameControllerAxisMapping[event->caxis.axis], event->caxis.value );
}
break;
}
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
{
if( !Joy_IsActive( ))
break;
// TODO: Use joyinput funcs, for future multiple gamepads support
if( event->cbutton.button >= 0 && event->cbutton.button < ARRAYSIZE( SDLash_GameControllerButtonMapping ))
{
Key_Event( SDLash_GameControllerButtonMapping[event->cbutton.button], event->cbutton.state );
}
break;
}
case SDL_CONTROLLERDEVICEADDED:
SDLash_GameController_Add( event->cdevice.which );
break;
case SDL_CONTROLLERDEVICEREMOVED:
SDLash_GameController_Remove( event->cdevice.which );
case SDL_CONTROLLERTOUCHPADDOWN:
case SDL_CONTROLLERTOUCHPADMOTION:
case SDL_CONTROLLERTOUCHPADUP:
case SDL_CONTROLLERSENSORUPDATE:
SDLash_HandleGameControllerEvent( event );
break;
case SDL_WINDOWEVENT:

View File

@@ -28,14 +28,16 @@ void GL_InitExtensions( void );
qboolean GL_DeleteContext( void );
void VID_SaveWindowSize( int width, int height, qboolean maximized );
// joystick events
extern SDL_Joystick *g_joy;
//
// in_sdl.c
//
void SDLash_InitCursors( void );
void SDLash_FreeCursors( void );
//
// joy_sdl.c
//
void SDLash_HandleGameControllerEvent( SDL_Event *ev );
#endif // XASH_SDL
#endif // KEYWRAPPER_H

View File

@@ -1,6 +1,6 @@
/*
vid_sdl.c - SDL input component
Copyright (C) 2018 a1batross
in_sdl.c - SDL input component
Copyright (C) 2018-2025 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
@@ -12,7 +12,6 @@ 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.
*/
#if !XASH_DEDICATED
#include <SDL.h>
#include "common.h"
@@ -24,7 +23,6 @@ GNU General Public License for more details.
#include "sound.h"
#include "vid_common.h"
SDL_Joystick *g_joy = NULL;
#if !SDL_VERSION_ATLEAST( 2, 0, 0 )
#define SDL_WarpMouseInWindow( win, x, y ) SDL_WarpMouse( ( x ), ( y ) )
#else
@@ -126,20 +124,6 @@ void Platform_SetClipboardText( const char *buffer )
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
}
/*
=============
Platform_Vibrate
=============
*/
void Platform_Vibrate( float time, char flags )
{
#if SDL_VERSION_ATLEAST( 2, 0, 9 )
if( g_joy )
SDL_JoystickRumble( g_joy, 0xFFFF, 0xFFFF, time * 1000.0f );
#endif // SDL_VERSION_ATLEAST( 2, 0, 9 )
}
#if !XASH_PSVITA
/*
@@ -157,120 +141,6 @@ void Platform_EnableTextInput( qboolean enable )
#endif // !XASH_PSVITA
/*
=============
SDLash_JoyInit_Old
=============
*/
static int SDLash_JoyInit_Old( int numjoy )
{
int num;
int i;
Con_Reportf( "Joystick: SDL\n" );
if( SDL_WasInit( SDL_INIT_JOYSTICK ) != SDL_INIT_JOYSTICK &&
SDL_InitSubSystem( SDL_INIT_JOYSTICK ) )
{
Con_Reportf( "Failed to initialize SDL Joysitck: %s\n", SDL_GetError() );
return 0;
}
if( g_joy )
{
SDL_JoystickClose( g_joy );
}
num = SDL_NumJoysticks();
if( num > 0 )
Con_Reportf( "%i joysticks found:\n", num );
else
{
Con_Reportf( "No joystick found.\n" );
return 0;
}
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
for( i = 0; i < num; i++ )
Con_Reportf( "%i\t: %s\n", i, SDL_JoystickNameForIndex( i ) );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Pass +set joy_index N to command line, where N is number, to select active joystick\n" );
g_joy = SDL_JoystickOpen( numjoy );
if( !g_joy )
{
Con_Reportf( "Failed to select joystick: %s\n", SDL_GetError( ) );
return 0;
}
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
Con_Reportf( "Selected joystick: %s\n"
"\tAxes: %i\n"
"\tHats: %i\n"
"\tButtons: %i\n"
"\tBalls: %i\n",
SDL_JoystickName( g_joy ), SDL_JoystickNumAxes( g_joy ), SDL_JoystickNumHats( g_joy ),
SDL_JoystickNumButtons( g_joy ), SDL_JoystickNumBalls( g_joy ) );
SDL_GameControllerEventState( SDL_DISABLE );
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
SDL_JoystickEventState( SDL_ENABLE );
return num;
}
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
/*
=============
SDLash_JoyInit_New
=============
*/
static int SDLash_JoyInit_New( int numjoy )
{
int count, numJoysticks, i;
Con_Reportf( "Joystick: SDL GameController API\n" );
if( SDL_WasInit( SDL_INIT_GAMECONTROLLER ) != SDL_INIT_GAMECONTROLLER &&
SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER ) )
{
Con_Reportf( "Failed to initialize SDL GameController API: %s\n", SDL_GetError() );
return 0;
}
SDL_GameControllerAddMappingsFromFile( "controllermappings.txt" );
count = 0;
numJoysticks = SDL_NumJoysticks();
for ( i = 0; i < numJoysticks; i++ )
if( SDL_IsGameController( i ) )
++count;
return count;
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
/*
=============
Platform_JoyInit
=============
*/
int Platform_JoyInit( int numjoy )
{
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
// SDL_Joystick is now an old API
// SDL_GameController is preferred
if( !Sys_CheckParm( "-sdl_joy_old_api" ) )
return SDLash_JoyInit_New(numjoy);
#endif // SDL_VERSION_ATLEAST( 2, 0, 0 )
return SDLash_JoyInit_Old(numjoy);
}
/*
========================
SDLash_InitCursors
@@ -418,5 +288,3 @@ key_modifier_t Platform_GetKeyModifiers( void )
return KeyModifier_None;
#endif
}
#endif // XASH_DEDICATED

View File

@@ -0,0 +1,391 @@
/*
joy_sdl.c - SDL gamepads
Copyright (C) 2018-2025 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>
#if SDL_VERSION_ATLEAST( 2, 0, 0 )
#include "common.h"
#include "keydefs.h"
#include "input.h"
#include "client.h"
#include "events.h"
static const int g_button_mapping[] =
{
#if XASH_NSWITCH // devkitPro/SDL has inverted Nintendo layout for SDL_GameController
K_B_BUTTON, K_A_BUTTON, K_Y_BUTTON, K_X_BUTTON,
#else
K_A_BUTTON, K_B_BUTTON, K_X_BUTTON, K_Y_BUTTON,
#endif
K_BACK_BUTTON, K_MODE_BUTTON, K_START_BUTTON,
K_LSTICK, K_RSTICK,
K_L1_BUTTON, K_R1_BUTTON,
K_DPAD_UP, K_DPAD_DOWN, K_DPAD_LEFT, K_DPAD_RIGHT,
K_MISC_BUTTON,
K_PADDLE1_BUTTON, K_PADDLE2_BUTTON, K_PADDLE3_BUTTON, K_PADDLE4_BUTTON,
K_TOUCHPAD,
};
// Swap axis to follow default axis binding:
static const engineAxis_t g_axis_mapping[] =
{
JOY_AXIS_SIDE, // SDL_CONTROLLER_AXIS_LEFTX,
JOY_AXIS_FWD, // SDL_CONTROLLER_AXIS_LEFTY,
JOY_AXIS_PITCH, // SDL_CONTROLLER_AXIS_RIGHTX,
JOY_AXIS_YAW, // SDL_CONTROLLER_AXIS_RIGHTY,
JOY_AXIS_LT, // SDL_CONTROLLER_AXIS_TRIGGERLEFT,
JOY_AXIS_RT, // SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
};
static SDL_JoystickID g_current_gamepad_id = -1; // used to send rumble to
static SDL_GameController *g_current_gamepad;
static SDL_GameController **g_gamepads;
static size_t g_num_gamepads;
#define CALIBRATION_TIME 10.0f
static struct
{
float time;
vec3_t data;
vec3_t calibrated_values;
int samples;
} gyrocal;
static void SDLash_RestartCalibration( void )
{
Joy_SetCalibrationState( JOY_NOT_CALIBRATED );
memset( &gyrocal, 0, sizeof( gyrocal ));
gyrocal.time = host.realtime + CALIBRATION_TIME;
Con_Printf( "Starting gyroscope calibration...\n" );
}
static void SDLash_FinalizeCalibration( void )
{
float data_rate = 10.0f; // let's say we're polling at 10Hz?
int min_samples;
#if SDL_VERSION_ATLEAST( 2, 0, 16 )
data_rate = SDL_GameControllerGetSensorDataRate( g_current_gamepad, SDL_SENSOR_GYRO );
if( !data_rate )
data_rate = 10.0f;
#endif
min_samples = Q_rint( CALIBRATION_TIME * data_rate * 0.75f );
// we waited for few seconds and got too few samples
if( gyrocal.samples <= min_samples )
{
Joy_SetCalibrationState( JOY_FAILED_TO_CALIBRATE );
return;
}
VectorScale( gyrocal.data, 1.0f / gyrocal.samples, gyrocal.calibrated_values );
Joy_SetCalibrationState( JOY_CALIBRATED );
Con_Printf( "Calibration done. Result: %f %f %f\n", gyrocal.calibrated_values[0], gyrocal.calibrated_values[1], gyrocal.calibrated_values[2] );
gyrocal.time = 0.0f;
}
static void SDLash_GameControllerAddMappings( const char *name )
{
fs_offset_t len = 0;
byte *p = FS_LoadFile( name, &len, false );
if( !p )
return;
if( len > 0 && len < INT32_MAX ) // function accepts int, SDL3 fixes this
{
SDL_RWops *rwops = SDL_RWFromConstMem( p, (int)len );
SDL_GameControllerAddMappingsFromRW( rwops, true );
}
Mem_Free( p );
}
static void SDLash_SetActiveGameController( SDL_JoystickID id )
{
SDL_GameController *oldgc;
if( g_current_gamepad_id == id )
return;
g_current_gamepad_id = id;
oldgc = g_current_gamepad;
#if SDL_VERSION_ATLEAST( 2, 0, 14 )
SDL_GameControllerSetSensorEnabled( oldgc, SDL_SENSOR_GYRO, SDL_FALSE );
#endif // SDL_VERSION_ATLEAST( 2, 0, 14 )
if( id < 0 )
{
g_current_gamepad = NULL;
Joy_SetCapabilities( false );
Joy_SetCalibrationState( JOY_NOT_CALIBRATED );
}
else
{
qboolean have_gyro = false;
g_current_gamepad = SDL_GameControllerFromInstanceID( id );
#if SDL_VERSION_ATLEAST( 2, 0, 14 )
have_gyro = SDL_GameControllerHasSensor( g_current_gamepad, SDL_SENSOR_GYRO );
if( have_gyro )
{
SDL_GameControllerSetSensorEnabled( g_current_gamepad, SDL_SENSOR_GYRO, SDL_TRUE );
SDLash_RestartCalibration();
}
#endif // SDL_VERSION_ATLEAST( 2, 0, 14 )
Joy_SetCapabilities( have_gyro );
}
}
static void SDLash_GameControllerAdded( int device_index )
{
SDL_GameController *gc;
SDL_GameController **list;
gc = SDL_GameControllerOpen( device_index );
if( !gc )
{
Con_Printf( S_ERROR "SDL_GameControllerOpen: %s\n", SDL_GetError( ));
return;
}
list = Mem_Realloc( host.mempool, g_gamepads, sizeof( *list ) * ( g_num_gamepads + 1 ));
list[g_num_gamepads++] = gc;
g_gamepads = list;
// set as current device if none other set
if( g_current_gamepad_id < 0 )
{
SDL_Joystick *joy = SDL_GameControllerGetJoystick( gc );
if( joy )
SDLash_SetActiveGameController( SDL_JoystickInstanceID( joy ));
}
Con_Printf( "Detected \"%s\" game controller.\nMapping string: %s\n", SDL_GameControllerName( gc ), SDL_GameControllerMapping( gc ));
}
static void SDLash_GameControllerRemoved( SDL_JoystickID id )
{
size_t i;
if( id == g_current_gamepad_id )
SDLash_SetActiveGameController( -1 );
// now close the device
for( i = 0; i < g_num_gamepads; i++ )
{
SDL_GameController *gc = g_gamepads[i];
SDL_Joystick *joy;
if( !gc )
continue;
joy = SDL_GameControllerGetJoystick( gc );
if( !joy )
continue;
if( SDL_JoystickInstanceID( joy ) == id )
{
Con_Printf( "Game controller \"%s\" was disconnected\n", SDL_GameControllerName( gc ));
SDL_GameControllerClose( gc );
g_gamepads[i] = NULL;
}
}
}
static void SDLash_GameControllerSensorUpdate( SDL_ControllerSensorEvent sensor )
{
vec3_t data;
if( sensor.which != g_current_gamepad_id )
return;
if( sensor.sensor != SDL_SENSOR_GYRO )
return;
if( gyrocal.time != 0.0f )
{
if( host.realtime > gyrocal.time )
SDLash_FinalizeCalibration();
VectorAdd( gyrocal.data, sensor.data, gyrocal.data );
gyrocal.samples++;
Joy_SetCalibrationState( JOY_CALIBRATING );
return;
}
VectorSubtract( sensor.data, gyrocal.calibrated_values, data );
Joy_GyroEvent( data );
}
void SDLash_HandleGameControllerEvent( SDL_Event *ev )
{
int x;
switch( ev->type )
{
case SDL_CONTROLLERAXISMOTION:
SDLash_SetActiveGameController( ev->caxis.which );
x = ev->caxis.axis;
if( x >= 0 && x < ARRAYSIZE( g_axis_mapping ))
Joy_AxisMotionEvent( g_axis_mapping[x], ev->caxis.value );
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
SDLash_SetActiveGameController( ev->cbutton.which );
x = ev->cbutton.button;
if( x >= 0 && x < ARRAYSIZE( g_button_mapping ))
Key_Event( g_button_mapping[x], ev->cbutton.state );
break;
case SDL_CONTROLLERDEVICEREMOVED:
SDLash_GameControllerRemoved( ev->cdevice.which );
break;
case SDL_CONTROLLERDEVICEADDED:
SDLash_GameControllerAdded( ev->cdevice.which );
break;
#if SDL_VERSION_ATLEAST( 2, 0, 14 )
case SDL_CONTROLLERSENSORUPDATE:
SDLash_GameControllerSensorUpdate( ev->csensor );
break;
#endif
}
}
void Platform_CalibrateGamepadGyro( void )
{
SDLash_RestartCalibration();
}
void Platform_Vibrate2( float time, int val1, int val2, uint flags )
{
#if SDL_VERSION_ATLEAST( 2, 0, 9 )
SDL_GameController *gc = g_current_gamepad;
Uint32 ms;
if( g_current_gamepad_id < 0 || !gc )
return;
if( val1 < 0 )
val1 = COM_RandomLong( 0x7FFF, 0xFFFF );
if( val2 < 0 )
val2 = COM_RandomLong( 0x7FFF, 0xFFFF );
ms = (Uint32)ceil( time );
SDL_GameControllerRumble( gc, val1, val2, ms );
#endif // SDL_VERSION_ATLEAST( 2, 0, 9 )
}
/*
=============
Platform_Vibrate
=============
*/
void Platform_Vibrate( float time, char flags )
{
Platform_Vibrate2( time, -1, -1, flags );
}
/*
=============
Platform_JoyInit
=============
*/
int Platform_JoyInit( void )
{
int count, numJoysticks, i;
Con_Reportf( "Joystick: SDL GameController API\n" );
if( SDL_WasInit( SDL_INIT_GAMECONTROLLER ) != SDL_INIT_GAMECONTROLLER &&
SDL_InitSubSystem( SDL_INIT_GAMECONTROLLER ))
{
Con_Reportf( "Failed to initialize SDL GameController API: %s\n", SDL_GetError( ));
return 0;
}
SDLash_GameControllerAddMappings( "gamecontrollerdb.txt" ); // shipped in extras.pk3
SDLash_GameControllerAddMappings( "controllermappings.txt" );
count = 0;
numJoysticks = SDL_NumJoysticks();
for ( i = 0; i < numJoysticks; i++ )
{
if( SDL_IsGameController( i ))
++count;
}
return count;
}
/*
=============
Platform_JoyShutdown
=============
*/
void Platform_JoyShutdown( void )
{
size_t i;
SDLash_SetActiveGameController( -1 );
for( i = 0; i < g_num_gamepads; i++ )
{
if( !g_gamepads[i] )
continue;
SDL_GameControllerClose( g_gamepads[i] );
g_gamepads[i] = NULL;
}
Mem_Free( g_gamepads );
g_gamepads = NULL;
g_num_gamepads = 0;
SDL_QuitSubSystem( SDL_INIT_GAMECONTROLLER );
}
#else // SDL_VERSION_ATLEAST( 2, 0, 0 )
void Platform_Vibrate( float time, char flags )
{
}
int Platform_JoyInit( void )
{
return 0;
}
void Platform_JoyShutdown( void )
{
}
#endif

View File

@@ -5,9 +5,19 @@
from waflib import Logs
from waflib.extras import pthread
import os
from copy import copy
top = '.'
EXECINFO_TEST = '''#include <execinfo.h>
int main(int argc, char **argv)
{
backtrace(0, 0);
backtrace_symbols(0, 0);
return 0;
}
'''
def options(opt):
grp = opt.add_option_group('Engine options')
@@ -37,98 +47,85 @@ def options(opt):
opt.load('sdl2')
def find_sdl(conf):
err_msg = '%s not available! If you want to build dedicated server, specify --dedicated'
if conf.env.DEST_OS in ['nswitch', 'psvita']:
err_msg = '%s not available!'
conf.load('sdl2')
if conf.options.SDL3:
if not conf.env.HAVE_SDL3:
conf.fatal(err_msg % 'SDL3')
conf.env.XASH_SDL = 3
else:
if not conf.env.HAVE_SDL2:
conf.fatal(err_msg % 'SDL2')
conf.env.XASH_SDL = 2
def configure(conf):
# check for dedicated server build
if conf.options.DEDICATED:
conf.define('XASH_DEDICATED', 1)
# Common dependencies, will be linked to both dedicated server and client
if conf.env.DEST_OS == 'linux':
conf.check_cc(lib='rt')
if conf.env.MAGX:
conf.define('XASH_CRASHHANDLER', 0)
elif conf.env.DEST_OS == 'haiku':
conf.env.LIB_HAIKU = ['network']
conf.env.LIBPATH_HAIKU = ['/boot/system/lib']
elif conf.env.DEST_OS == 'wasi':
conf.options.NO_ASYNC_RESOLVE = True
conf.env.CFLAGS += ['-mllvm', '-wasm-enable-sjlj']
elif conf.env.DEST_OS == 'sunos':
conf.check_cc(lib='socket')
elif conf.env.DEST_OS == 'dos':
conf.options.STATIC = True
conf.options.NO_ASYNC_RESOLVE = True
if not conf.check_cc( fragment='int main(){ int i = socket();}', lib = 'wattcpwl', mandatory=False ):
conf.define('XASH_NO_NETWORK',1)
elif conf.env.DEST_OS == 'nswitch':
# re-enable undefined reference errors
conf.env.CXXFLAGS += ['-Wl,--no-undefined']
conf.env.CFLAGS += ['-Wl,--no-undefined']
# allow the SDL2 sanity check to complete properly by linking in lm normally
conf.env.LDFLAGS += ['-lm']
conf.load('sdl2')
if not conf.env.HAVE_SDL2:
conf.fatal('SDL2 not availiable! Install switch-sdl2!')
conf.define('XASH_SDL', 2)
# then remove them to avoid them getting linked to shared objects
conf.env.LIB_SDL2.remove('stdc++') # remove libstdc++ linking from SDL2, we link it later
conf.env.LDFLAGS.remove('-lm')
elif conf.env.DEST_OS == 'psvita':
# allow the SDL2 sanity check to complete properly by linking in some deps missing from the pkg-config file
extra_libs = ['-lstdc++', '-lm', '-lSceShaccCgExt', '-lSceShaccCg_stub', '-ltaihen_stub', '-lSceKernelDmacMgr_stub']
conf.env.LDFLAGS += extra_libs
conf.load('sdl2')
if not conf.env.HAVE_SDL2:
conf.fatal('SDL2 not availiable! Install switch-sdl2!')
conf.define('XASH_SDL', 2)
# then remove them to avoid them getting linked to shared objects
for lib in extra_libs:
conf.env.LDFLAGS.remove(lib)
elif conf.options.FBDEV_SW:
# unused, XASH_LINUX without XASH_SDL gives fbdev & alsa support
# conf.define('XASH_FBDEV', 1)
conf.check_cc( lib = 'asound' )
elif conf.options.SDL12:
conf.define('XASH_SDL', 12)
conf.check_cfg(package='sdl', args='--cflags --libs', uselib_store='SDL2' )
conf.env.HAVE_SDL2 = True
else:
conf.load('sdl2')
if conf.options.SDL3:
if not conf.env.HAVE_SDL3:
conf.fatal('SDL3 not available! If you want to build dedicated server, specify --dedicated')
conf.define('XASH_SDL', 3)
else:
if not conf.env.HAVE_SDL2:
conf.fatal('SDL2 not available! If you want to build dedicated server, specify --dedicated')
conf.define('XASH_SDL', 2)
if conf.env.DEST_OS == 'haiku':
conf.env.LIB_HAIKU = ['network']
conf.env.LIBPATH_HAIKU = ['/boot/system/lib']
if conf.env.DEST_OS == 'wasi':
conf.options.NO_ASYNC_RESOLVE = True
conf.env.append_unique('CFLAGS', '-mllvm')
conf.env.append_unique('CFLAGS', '-wasm-enable-sjlj')
if conf.env.DEST_OS == 'sunos':
conf.check_cc(lib='socket')
if conf.options.STATIC:
conf.env.STATIC = True
conf.define('XASH_NO_LIBDL',1)
if not conf.env.DEST_OS in ['win32', 'android'] and not conf.options.NO_ASYNC_RESOLVE:
conf.check_pthreads(mode='c')
if conf.env.DEST_OS == 'linux':
conf.check_cc(lib='rt')
if hasattr(conf.options, 'DLLEMU'):
conf.define_cond('XASH_DLL_LOADER', conf.options.DLLEMU)
if conf.env.MAGX:
conf.define('XASH_CRASHHANDLER', 0)
conf.env.ENGINE_TESTS = conf.options.ENGINE_TESTS
if conf.options.ENGINE_FUZZ:
conf.env.append_unique('CFLAGS', '-fsanitize=fuzzer-no-link')
conf.env.append_unique('LINKFLAGS', '-fsanitize=fuzzer')
conf.define('ENGINE_DLL', 1)
# Client-only dependencies
if conf.env.CLIENT:
if conf.env.DEST_OS in ['nswitch', 'psvita']:
extra_libs = ['-lm']
if conf.env.DEST_OS == 'psvita':
extra_libs = ['-lstdc++', '-lm', '-lSceShaccCgExt', '-lSceShaccCg_stub', '-ltaihen_stub', '-lSceKernelDmacMgr_stub']
conf.define_cond('XASH_ENGINE_TESTS', conf.env.ENGINE_TESTS)
conf.env.append_unique('CXXFLAGS', ['-Wl,--no-undefined'])
conf.env.append_unique('CFLAGS', ['-Wl,--no-undefined'])
conf.env.LDFLAGS += extra_libs
find_sdl(conf)
for lib in extra_libs: conf.env.LDFLAGS.remove(lib)
if conf.env.DEST_OS == 'nswitch': # remove libstdc++ linking from SDL2, we link it later
conf.env.LIB_SDL2.remove('stdc++')
elif conf.env.DEST_OS == 'linux' and conf.options.FBDEV_SW:
conf.check_cc(lib='asound')
elif conf.options.SDL12: # TODO: move to sdl2.py
conf.check_cfg(package='sdl', args='--cflags --libs', uselib_store='SDL2')
conf.env.XASH_SDL = 12
conf.env.HAVE_SDL2 = True
else:
find_sdl(conf)
if conf.options.STATIC:
conf.env.STATIC = True
conf.define('XASH_NO_LIBDL', 1)
if not conf.env.DEST_OS in ['win32', 'android'] and not conf.options.NO_ASYNC_RESOLVE:
conf.check_pthreads(mode='c')
if hasattr(conf.options, 'DLLEMU'):
conf.define_cond('XASH_DLL_LOADER', conf.options.DLLEMU)
conf.check_cc(fragment=EXECINFO_TEST, msg='Checking for glibc backtrace()', mandatory=False, define_name='HAVE_EXECINFO')
conf.define('ENGINE_DLL', 1)
conf.define_cond('XASH_ENGINE_TESTS', conf.options.ENGINE_TESTS)
conf.define_cond('XASH_STATIC_LIBS', conf.env.STATIC_LINKING)
conf.define_cond('XASH_CUSTOM_SWAP', conf.options.CUSTOM_SWAP)
conf.define_cond('XASH_ENABLE_MAIN', conf.env.DISABLE_LAUNCHER)
conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', conf.options.NO_ASYNC_RESOLVE)
conf.define_cond('PSAPI_VERSION', conf.env.DEST_OS == 'win32') # will be defined as 1
@@ -139,140 +136,103 @@ def build(bld):
# public includes for renderers and utils use
bld(name = 'engine_includes', export_includes = '. common common/imagelib', use = 'filesystem_includes')
is_cxx_link = False
libs = [ 'engine_includes', 'public', 'dllemu', 'werror' ]
libs = ['engine_includes', 'public', 'dllemu', 'werror']
includes = ['server', 'client', 'client/vgui', 'common/soundlib']
# basic build: dedicated only
source = bld.path.ant_glob([
'common/*.c',
'common/imagelib/*.c',
'common/soundlib/*.c',
'server/*.c'])
source = bld.path.ant_glob(['common/*.c', 'common/imagelib/*.c', 'common/soundlib/*.c', 'server/*.c'])
if bld.env.ENGINE_TESTS:
source += bld.path.ant_glob(['tests/*.c'])
# include platform-specific sources, this shall not fail if directory doesn't exist
source += bld.path.ant_glob('platform/%s/*.c' % bld.env.DEST_OS)
# Android _is_ Linux based, after all
if bld.env.DEST_OS == 'android':
source += bld.path.ant_glob('platform/linux/*.c')
# include common POSIX conformant code
if bld.env.DEST_OS not in ['win32', 'dos']:
source += bld.path.ant_glob('platform/posix/*.c')
# include sources for optional features
if bld.get_define('XASH_CUSTOM_SWAP'):
source += ['platform/misc/kmalloc.c', 'platform/misc/sbrk.c']
if bld.get_define('XASH_STATIC_LIBS'):
source += ['platform/misc/lib_static.c']
if bld.env.DEST_OS == 'win32':
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32' ]
source += bld.path.ant_glob(['platform/win32/*.c'])
elif bld.env.DEST_OS not in ['dos', 'nswitch', 'psvita']: #posix
libs += [ 'M', 'RT', 'PTHREAD', 'ASOUND']
if not bld.env.STATIC:
libs += ['DL']
source += bld.path.ant_glob(['platform/posix/*.c'])
if bld.env.DEST_OS == 'linux':
source += bld.path.ant_glob(['platform/linux/*.c'])
if bld.env.DEST_OS == 'irix':
source += bld.path.ant_glob(['platform/irix/*.c'])
if bld.env.DEST_OS == 'dos':
source += bld.path.ant_glob(['platform/dos/*.c'])
source += bld.path.ant_glob(['platform/stub/s_stub.c'])
if bld.env.DEST_OS == 'haiku':
libs.append('HAIKU')
if bld.get_define('XASH_CUSTOM_SWAP'):
source += bld.path.ant_glob(['platform/misc/kmalloc.c', 'platform/misc/sbrk.c'])
if bld.env.STATIC_LINKING:
source += bld.path.ant_glob(['platform/misc/lib_static.c'])
is_cxx_link = True
if bld.env.HAVE_SDL2 or bld.env.HAVE_SDL3:
libs.append('SDL3' if bld.env.HAVE_SDL3 else 'SDL2')
source += bld.path.ant_glob(['platform/sdl/*.c'])
if bld.env.MAGX:
libs.append('MAGX')
is_cxx_link = True
if bld.env.DEST_OS == 'android':
libs += ['LOG']
source += bld.path.ant_glob(['platform/android/*.cpp', 'platform/android/*.c', 'platform/linux/*.c'])
if bld.env.DEST_OS == 'nswitch':
libs += [ 'SOLDER' ]
source += bld.path.ant_glob(['platform/posix/*.c'])
source += bld.path.ant_glob(['platform/nswitch/*.c'])
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32']
elif bld.env.DEST_OS == 'nswitch':
libs += ['SOLDER']
# HACK: link in the entirety of libstdc++ so that dynamic libs could use all of it without manual exporting
# we can't do this right away because std::filesystem will complain about not having pathconf(),
# which we have defined in sys_nswitch.c
bld.env.LDFLAGS += ['-v', '-Wl,--whole-archive', '-lstdc++', '-Wl,--no-whole-archive', '-lm']
if bld.env.DEST_OS == 'psvita':
libs += [ 'VRTLD' ]
source += bld.path.ant_glob(['platform/posix/*.c'])
source += bld.path.ant_glob(['platform/psvita/*.c'])
elif bld.env.DEST_OS == 'psvita':
libs += ['VRTLD']
# HACK: link in the entirety of libstdc++ so that dynamic libs could use all of it without manual exporting
# also link in all the funky dependencies that aren't in SDL2's LDFLAGS
bld.env.LDFLAGS += [
'-Wl,--whole-archive',
'-lstdc++',
'-lpthread',
'-Wl,--no-whole-archive',
'-lm',
'-lSceShaccCgExt',
'-lkubridge_stub',
'-ltaihen_stub',
'-lSceShaccCg_stub',
'-lSceKernelModulemgr_stub',
'-lSceSblSsMgr_stub',
'-lSceVshBridge_stub',
'-lSceKernelDmacMgr_stub'
bld.env.LDFLAGS += ['-Wl,--whole-archive', '-lstdc++', '-lpthread', '-Wl,--no-whole-archive',
'-lm', '-lSceShaccCgExt', '-lkubridge_stub', '-ltaihen_stub', '-lSceShaccCg_stub', '-lSceKernelModulemgr_stub', '-lSceSblSsMgr_stub', '-lSceVshBridge_stub', '-lSceKernelDmacMgr_stub',
]
else: # POSIX
libs += ['M', 'RT', 'PTHREAD', 'ASOUND', 'HAIKU', 'MAGX', 'LOG', 'SOCKET']
if not bld.env.STATIC:
libs += ['DL']
if bld.env.DEST_OS == 'sunos':
libs.append('SOCKET')
if bld.env.SERVER:
# TODO: avoid possible name collision when client is built without launcher
# but dedicated server is enabled. They're both called 'xash' in this case
bld.program(
source = copy(source),
target = 'xash',
use = copy(libs),
includes = includes,
defines = 'XASH_ENABLE_MAIN=1 XASH_DEDICATED=1',
rpath = bld.env.DEFAULT_RPATH,
install_path = bld.env.BINDIR,
)
# add client files
if not bld.env.DEDICATED:
source += bld.path.ant_glob([
'client/*.c',
'client/vgui/*.c',
'client/avi/*.c',
'client/soundlib/*.c',
'client/soundlib/libmpg/*.c',
])
is_cxx_link = True
libs += ['bzip2', 'MultiEmulator', 'opus', 'opusfile', 'vorbis', 'vorbisfile']
if bld.env.CLIENT:
defines = []
if bld.env.XASH_SDL:
libs += ['SDL3' if bld.env.HAVE_SDL3 else 'SDL2']
source += bld.path.ant_glob(['platform/sdl/*.c'])
defines += ['XASH_SDL=%d' % bld.env.XASH_SDL]
rpath = bld.env.DEFAULT_RPATH
# add client files
if not bld.env.DEDICATED:
source += bld.path.ant_glob('client/**/*.c')
libs += ['bzip2', 'MultiEmulator', 'opus', 'opusfile', 'vorbis', 'vorbisfile']
# Switch and PSVita have custom parameters
if bld.env.DEST_OS in ['nswitch', 'psvita']:
rpath = None
install_path = None
features = 'cxx c cxxprogram cprogram'
# Always build as shared library on Android
elif bld.env.DISABLE_LAUNCHER and bld.env.DEST_OS != 'android':
install_path = bld.env.BINDIR
if bld.env.STATIC:
features = 'cxx c cxxprogram_static cprogram_static'
elif is_cxx_link:
features = 'cxx c cxxprogram cprogram'
# Android port is linked differently
if bld.env.DEST_OS == 'android':
f = bld.shlib
install_path = bld.env.LIBDIR
defines += ['XASH_ENABLE_MAIN=1', 'XASH_SDLMAIN=1']
elif not bld.env.LAUNCHER:
f = bld.program
install_path = bld.env.BINDIR
defines += ['XASH_ENABLE_MAIN=1']
else:
features = 'c cprogram'
else:
install_path = bld.env.LIBDIR
if is_cxx_link:
features = 'cxx c cxxshlib cshlib'
else:
features = 'c cshlib'
f = bld.shlib
install_path = bld.env.LIBDIR
bld(source = source,
target = 'xash',
features = features,
includes = 'server client client/vgui common/soundlib',
use = libs,
install_path = install_path,
nro_install_path = bld.env.BINDIR,
nacp = 'platform/nswitch/xash3d-fwgs.nacp',
icon = 'platform/nswitch/icon.jpg',
sce_sys = 'platform/psvita/sce_sys',
title_id = 'XASH10000',
app_name = 'xash3d-fwgs',
rpath = rpath,
)
if bld.env.DEST_OS in ['nswitch', 'psvita']:
install_path = None
f(source = source,
target = 'xash',
includes = includes,
features = 'cxx c',
use = libs,
defines = defines,
install_path = install_path,
special_install_path = bld.env.BINDIR,
nacp = 'platform/nswitch/xash3d-fwgs.nacp',
icon = 'platform/nswitch/icon.jpg',
sce_sys = 'platform/psvita/sce_sys',
title_id = 'XASH10000',
app_name = 'xash3d-fwgs',
rpath = bld.env.DEFAULT_RPATH,
)

View File

@@ -114,27 +114,35 @@ uint32_t Q_DecodeUTF16( utfstate_t *s, uint32_t in )
return 0;
}
size_t Q_EncodeUTF8( char dst[4], uint32_t ch )
static size_t Q_CodepointLength( uint32_t ch )
{
if( ch <= 0x7fu )
return 1;
else if( ch <= 0x7ffu )
return 2;
else if( ch <= 0xffffu )
return 3;
return 4;
}
size_t Q_EncodeUTF8( char dst[4], uint32_t ch )
{
switch( Q_CodepointLength( ch ))
{
case 1:
dst[0] = ch;
return 1;
}
else if( ch <= 0x7ffu )
{
case 2:
dst[0] = 0xc0u | (( ch >> 6 ) & 0x1fu );
dst[1] = 0x80u | (( ch ) & 0x3fu );
return 2;
}
else if( ch <= 0xffffu )
{
case 3:
dst[0] = 0xe0u | (( ch >> 12 ) & 0x0fu );
dst[1] = 0x80u | (( ch >> 6 ) & 0x3fu );
dst[2] = 0x80u | (( ch ) & 0x3fu );
return 3;
}
dst[0] = 0xf0u | (( ch >> 18 ) & 0x07u );
dst[1] = 0x80u | (( ch >> 12 ) & 0x3fu );
dst[2] = 0x80u | (( ch >> 6 ) & 0x3fu );
@@ -163,18 +171,6 @@ size_t Q_UTF8Length( const char *s )
return len;
}
static size_t Q_CodepointLength( uint32_t ch )
{
if( ch <= 0x7fu )
return 1;
else if( ch <= 0x7ffu )
return 2;
else if( ch <= 0xffffu )
return 3;
return 4;
}
size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize )
{
utfstate_t state = { 0 };

View File

@@ -192,7 +192,7 @@ static void APIENTRY GL2_BindTexture( GLenum tex, GLuint obj )
static char *GL_PrintInfoLog( GLhandleARB object, qboolean program )
{
static char msg[8192];
int maxLength = 0;
GLuint maxLength = 0;
if( program && pglGetProgramiv )
pglGetProgramiv( object, GL_OBJECT_INFO_LOG_LENGTH_ARB, &maxLength );
@@ -282,8 +282,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type )
static gl2wrap_prog_t *GL2_GetProg( const GLuint flags )
{
int i, loc, status;
GLuint vp, fp, glprog;
int i, loc;
GLuint status = 0, vp, fp, glprog;
gl2wrap_prog_t *prog;
// try to find existing prog matching this feature set
@@ -352,6 +352,7 @@ static gl2wrap_prog_t *GL2_GetProg( const GLuint flags )
pglGetProgramiv( glprog, GL_OBJECT_LINK_STATUS_ARB, &status );
else
pglGetObjectParameterivARB( glprog, GL_OBJECT_LINK_STATUS_ARB, &status );
if( status == GL_FALSE )
{
gEngfuncs.Con_Reportf( S_ERROR "%s: Failed linking progs for 0x%04x!\n%s\n", __func__, prog->flags, GL_PrintInfoLog( glprog, true ));

View File

@@ -555,8 +555,6 @@ void CL_AddCustomBeam( cl_entity_t *pEnvBeam );
#define GL_CheckForErrors() GL_CheckForErrors_( __FILE__, __LINE__ )
void GL_CheckForErrors_( const char *filename, const int fileline );
const char *GL_ErrorString( int err );
qboolean GL_Support( int r_ext );
int GL_MaxTextureUnits( void );
//
// gl_triapi.c
@@ -756,6 +754,22 @@ static inline uint LinearGammaTable( uint b )
return !FBitSet( gp_host->features, ENGINE_LINEAR_GAMMA_SPACE ) ? tr.lineargammatable[b] : b;
}
static inline qboolean GL_Support( int r_ext )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
return glConfig.extension[r_ext] ? true : false;
gEngfuncs.Con_Printf( S_ERROR "%s: invalid extension %d\n", __func__, r_ext );
return false;
}
static inline int GL_MaxTextureUnits( void )
{
if( GL_Support( GL_SHADER_GLSL100_EXT ))
return Q_min( Q_max( glConfig.max_texture_coords, glConfig.max_teximage_units ), MAX_TEXTURE_UNITS );
return glConfig.max_texture_units;
}
#define WORLDMODEL (gp_cl->models[1])
//
@@ -798,6 +812,7 @@ extern convar_t r_shadows;
extern convar_t r_ripple;
extern convar_t r_ripple_updatetime;
extern convar_t r_ripple_spawntime;
extern convar_t r_large_lightmaps;
//
// engine shared convars

View File

@@ -37,6 +37,7 @@ CVAR_DEFINE( r_vbo_overbrightmode, "gl_vbo_overbrightmode", "0", FCVAR_GLCONFIG,
CVAR_DEFINE_AUTO( r_ripple, "0", FCVAR_GLCONFIG, "enable software-like water texture ripple simulation" );
CVAR_DEFINE_AUTO( r_ripple_updatetime, "0.05", FCVAR_GLCONFIG, "how fast ripple simulation is" );
CVAR_DEFINE_AUTO( r_ripple_spawntime, "0.1", FCVAR_GLCONFIG, "how fast new ripples spawn" );
CVAR_DEFINE_AUTO( r_large_lightmaps, "0", FCVAR_GLCONFIG|FCVAR_LATCH, "enable larger lightmap atlas textures (might break custom renderer mods)" );
DEFINE_ENGINE_SHARED_CVAR_LIST()
@@ -464,32 +465,6 @@ static void GL_SetExtension( int r_ext, int enable )
else gEngfuncs.Con_Printf( S_ERROR "%s: invalid extension %d\n", __func__, r_ext );
}
/*
=================
GL_Support
=================
*/
qboolean GL_Support( int r_ext )
{
if( r_ext >= 0 && r_ext < GL_EXTCOUNT )
return glConfig.extension[r_ext] ? true : false;
gEngfuncs.Con_Printf( S_ERROR "%s: invalid extension %d\n", __func__, r_ext );
return false;
}
/*
=================
GL_MaxTextureUnits
=================
*/
int GL_MaxTextureUnits( void )
{
if( GL_Support( GL_SHADER_GLSL100_EXT ))
return Q_min( Q_max( glConfig.max_texture_coords, glConfig.max_teximage_units ), MAX_TEXTURE_UNITS );
return glConfig.max_texture_units;
}
/*
=================
GL_CheckExtension
@@ -931,7 +906,13 @@ static void GL_InitExtensionsBigGL( void )
GL_CheckExtension( "GL_ARB_seamless_cube_map", NULL, 0, "gl_texture_cubemap_seamless", GL_ARB_SEAMLESS_CUBEMAP, 0 );
}
GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, 0, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT, 0 );
// NPOT textures support
if( !GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, 0, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT, 0 ))
{
// vitaGL exposes OES extension
GL_CheckExtension( "GL_OES_texture_npot", NULL, 0, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT, 0 );
}
GL_CheckExtension( "GL_ARB_texture_compression", texturecompressionfuncs, ARRAYSIZE( texturecompressionfuncs ), "gl_texture_dxt_compression", GL_TEXTURE_COMPRESSION_EXT, 0 );
if( !GL_CheckExtension( "GL_EXT_texture_edge_clamp", NULL, 0, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT, 2.0 )) // present in ES2
GL_CheckExtension( "GL_SGIS_texture_edge_clamp", NULL, 0, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT, 0 );
@@ -1173,6 +1154,7 @@ static void GL_InitCommands( void )
gEngfuncs.Cvar_RegisterVariable( &r_vbo_dlightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_overbrightmode );
gEngfuncs.Cvar_RegisterVariable( &r_vbo_detail );
gEngfuncs.Cvar_RegisterVariable( &r_large_lightmaps );
gEngfuncs.Cvar_RegisterVariable( &gl_extensions );
gEngfuncs.Cvar_RegisterVariable( &gl_texture_nearest );

View File

@@ -3858,7 +3858,7 @@ void GL_BuildLightmaps( void )
memset( &RI, 0, sizeof( RI ));
// update the lightmap blocksize
if( FBitSet( gp_host->features, ENGINE_LARGE_LIGHTMAPS ) || tr.world->version == QBSP2_VERSION )
if( FBitSet( gp_host->features, ENGINE_LARGE_LIGHTMAPS ) || tr.world->version == QBSP2_VERSION || r_large_lightmaps.value )
tr.block_size = BLOCK_SIZE_MAX;
else tr.block_size = BLOCK_SIZE_DEFAULT;

View File

@@ -247,8 +247,16 @@ static void MakeSkyVec( float s, float t, int axis )
s = (s + 1.0f) * 0.5f;
t = (t + 1.0f) * 0.5f;
s = bound( 1.0f / 512.0f, s, 511.0f / 512.0f );
t = bound( 1.0f / 512.0f, t, 511.0f / 512.0f );
if( GL_Support( GL_CLAMPTOEDGE_EXT ))
{
s = bound( 0.0f, s, 1.0f );
t = bound( 0.0f, t, 1.0f );
}
else
{
s = bound( 1.0f / 512.0f, s, 511.0f / 512.0f );
t = bound( 1.0f / 512.0f, t, 511.0f / 512.0f );
}
t = 1.0f - t;
@@ -720,12 +728,32 @@ void R_AnimateRipples( void )
R_RunRipplesAnimation( g_ripple.oldbuf, g_ripple.curbuf );
}
static void R_GetRippleTextureSize( const texture_t *image, int *width, int *height )
{
// try to preserve aspect ratio
if( image->width > image->height )
{
*width = RIPPLES_CACHEWIDTH;
*height = (float)image->height / image->width * RIPPLES_CACHEWIDTH;
}
else if( image->width < image->height )
{
*width = (float)image->width / image->height * RIPPLES_CACHEWIDTH;
*height = RIPPLES_CACHEWIDTH;
}
else
{
*width = *height = RIPPLES_CACHEWIDTH;
}
}
qboolean R_UploadRipples( texture_t *image )
{
const gl_texture_t *glt;
const uint32_t *pixels;
int y;
int width, height, size;
qboolean update = g_ripple.update;
if( !r_ripple.value )
{
@@ -735,24 +763,19 @@ qboolean R_UploadRipples( texture_t *image )
// discard unuseful textures
glt = R_GetTexture( image->gl_texturenum );
if( !glt || !glt->original || !glt->original->buffer || !FBitSet( glt->flags, TF_EXPAND_SOURCE ))
if( !glt || !glt->original || !glt->original->buffer )
{
GL_Bind( XASH_TEXTURE0, image->gl_texturenum );
return false;
}
// try to preserve aspect ratio
width = height = RIPPLES_CACHEWIDTH; // always render at maximum size
if( image->width > image->height )
height = (float)image->height / image->width * width;
else if( image->width < image->height )
width = (float)image->width / image->height * height;
if( !image->fb_texturenum )
{
rgbdata_t pic = { 0 };
string name;
Q_snprintf( name, sizeof( name ), "*rippletex_%s", image->name );
R_GetRippleTextureSize( image, &width, &height );
pic.width = width;
pic.height = height;
@@ -765,14 +788,22 @@ qboolean R_UploadRipples( texture_t *image )
memset( pic.buffer, 0, pic.size );
image->fb_texturenum = GL_LoadTextureInternal( name, &pic, TF_NOMIPMAP | TF_ALLOW_NEAREST );
update = true;
image->dt_texturenum = ( tr.framecount - 1 ) & 0xFFFF;
}
GL_Bind( XASH_TEXTURE0, image->fb_texturenum );
// no updates this frame
if( !g_ripple.update )
if( !update || image->dt_texturenum == ( tr.framecount & 0xFFFF ))
return true;
// prevent rendering texture multiple times in frame
image->dt_texturenum = tr.framecount & 0xFFFF;
R_GetRippleTextureSize( image, &width, &height );
size = r_ripple.value == 1.0f ? 64 : RIPPLES_CACHEWIDTH;
pixels = (const uint32_t *)glt->original->buffer;

View File

@@ -42,7 +42,7 @@ build_sdl2()
# let's enable everything we can
mkdir -p build || die
pushd build || die
cmake ../ -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$BUILDDIR"/SDL2_linux -DCMAKE_C_FLAGS=-O3 -DSDL_STATIC=OFF || die
cmake ../ -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$BUILDDIR"/SDL2_linux -DCMAKE_C_FLAGS=-O3 -DSDL_STATIC=OFF -DSDL_RENDER=OFF || die
ninja install -j$((N+1)) || die
popd || die
}

View File

@@ -37,7 +37,7 @@ popd
echo "Building SDL..."
pushd SDL || die
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DVIDEO_VITA_VGL=ON || die_configure
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=${VITASDK}/share/vita.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DVIDEO_VITA_VGL=ON -DSDL_RENDER=OFF || die_configure
cmake --build build -- -j2 || die
cmake --install build || die
popd

View File

@@ -6,7 +6,7 @@ echo "Downloading vitasdk..."
export VITASDK=/usr/local/vitasdk
VITAGL_SRCREV="064db9efb15833e18777a3e768b8b1fb2abee78f" # lock vitaGL version to avoid compilation errors
VITAGL_SRCREV="4d3ab1053424abe3b2164a50d15c5e355e33ed99" # lock vitaGL version to avoid compilation errors
install_package()
{

View File

@@ -31,7 +31,7 @@ class elf2nro(Task.Task):
return '%sConverting to NRO' % Logs.colors_lst['CYAN']
return 'Converting to NRO'
@TaskGen.feature('cxxprogram')
@TaskGen.feature('cxxprogram', 'cprogram')
@TaskGen.after_method('apply_link')
def apply_nro(self):
elffile = self.link_task.outputs[0]
@@ -58,7 +58,7 @@ def apply_nro(self):
tsk = self.nro_task = self.create_task('elf2nro', nodes)
self.nro_task.set_outputs(nodes[0].change_ext('.nro'))
inst_to = getattr(self, 'nro_install_path', None)
inst_to = getattr(self, 'special_install_path', None)
if inst_to:
self.add_install_files(install_to=inst_to,
install_from=tsk.outputs[:], chmod=Utils.O755, task=tsk)

View File

@@ -30,6 +30,8 @@ def configure(conf):
conf.find_program('vita-mksfoex', var='MKSFOEX')
conf.find_program('vita-pack-vpk', var='PACKVPK')
conf.env.SCESYS_ST = '-a%s=sce_sys'
class mkvelf(Task.Task):
color = 'CYAN'
run_str = '${ELF_CREATE} -g ${YMLFILE} ${ELFFILE} ${TGT}'
@@ -45,9 +47,9 @@ class mksfoex(Task.Task):
class mkvpk(Task.Task):
color = 'CYAN'
run_str = '${PACKVPK} -s ${SFOFILE} -b ${FSELFFILE} -a ${SCESYS}=sce_sys ${TGT}'
run_str = '${PACKVPK} -s ${SFOFILE} -b ${FSELFFILE} ${SCESYS_ST:SCESYS} ${TGT}'
@TaskGen.feature('cxxprogram')
@TaskGen.feature('cxxprogram', 'cprogram')
@TaskGen.after_method('apply_link')
def apply_velf(self):
elffile = self.link_task.outputs[0]
@@ -64,7 +66,7 @@ def apply_velf(self):
self.velf_task = self.create_task('mkvelf', in_nodes)
self.velf_task.set_outputs(out_nodes)
@TaskGen.feature('cxxprogram')
@TaskGen.feature('cxxprogram', 'cprogram')
@TaskGen.after_method('apply_velf')
def apply_fself(self):
velffile = self.velf_task.outputs[0]
@@ -78,13 +80,13 @@ def apply_fself(self):
self.fself_task = self.create_task('mkfself', in_nodes)
self.fself_task.set_outputs(out_nodes)
@TaskGen.feature('cxxprogram')
@TaskGen.feature('cxxprogram', 'cprogram')
@TaskGen.after_method('apply_fself')
def apply_sfo(self):
fselffile = self.fself_task.outputs[0]
in_nodes = [fselffile]
scetitleid = getattr(self, 'title_id', None)
sceappname = getattr(self, 'app_name', None)
scetitleid = getattr(self, 'title_id', 'TEST10000')
sceappname = getattr(self, 'app_name', 'test')
sfofile = fselffile.change_ext('.sfo')
out_nodes = [sfofile]
@@ -96,7 +98,7 @@ def apply_sfo(self):
self.sfo_task = self.create_task('mksfoex', in_nodes)
self.sfo_task.set_outputs(out_nodes)
@TaskGen.feature('cxxprogram')
@TaskGen.feature('cxxprogram', 'cprogram')
@TaskGen.after_method('apply_sfo')
def apply_vpk(self):
fselffile = self.fself_task.outputs[0]
@@ -107,8 +109,14 @@ def apply_vpk(self):
vpkfile = sfofile.change_ext('.vpk')
out_nodes = [vpkfile]
if scesysdir: self.env.SCESYS = str(scesysdir)
if scesysdir:
self.env.SCESYS = [str(scesysdir)]
self.env.VPKFILE = str(vpkfile)
self.vpk_task = self.create_task('mkvpk', in_nodes)
tsk = self.vpk_task = self.create_task('mkvpk', in_nodes)
self.vpk_task.set_outputs(out_nodes)
inst_to = getattr(self, 'special_install_path', None)
if inst_to:
self.add_install_files(install_to=inst_to,
install_from=tsk.outputs[:], chmod=Utils.O755, task=tsk)

58
wscript
View File

@@ -86,24 +86,24 @@ SUBDIRS = [
Subproject('dllemu'),
# disable only by engine feature, makes no sense to even parse subprojects in dedicated mode
Subproject('3rdparty/extras', lambda x: not x.env.DEDICATED and x.env.DEST_OS != 'android'),
Subproject('3rdparty/nanogl', lambda x: not x.env.DEDICATED and x.env.NANOGL),
Subproject('3rdparty/gl-wes-v2', lambda x: not x.env.DEDICATED and x.env.GLWES),
Subproject('3rdparty/gl4es', lambda x: not x.env.DEDICATED and x.env.GL4ES),
Subproject('ref/gl', lambda x: not x.env.DEDICATED and (x.env.GL or x.env.NANOGL or x.env.GLWES or x.env.GL4ES)),
Subproject('ref/soft', lambda x: not x.env.DEDICATED and x.env.SOFT),
Subproject('ref/null', lambda x: not x.env.DEDICATED and x.env.NULL),
Subproject('3rdparty/bzip2', lambda x: not x.env.DEDICATED and not x.env.HAVE_SYSTEM_BZ2),
Subproject('3rdparty/opus', lambda x: not x.env.DEDICATED and not x.env.HAVE_SYSTEM_OPUS),
Subproject('3rdparty/libogg', lambda x: not x.env.DEDICATED and not x.env.HAVE_SYSTEM_OGG),
Subproject('3rdparty/vorbis', lambda x: not x.env.DEDICATED and (not x.env.HAVE_SYSTEM_VORBIS or not x.env.HAVE_SYSTEM_VORBISFILE)),
Subproject('3rdparty/opusfile', lambda x: not x.env.DEDICATED and not x.env.HAVE_SYSTEM_OPUSFILE),
Subproject('3rdparty/mainui', lambda x: not x.env.DEDICATED),
Subproject('3rdparty/vgui_support', lambda x: not x.env.DEDICATED),
Subproject('3rdparty/MultiEmulator',lambda x: not x.env.DEDICATED),
# Subproject('3rdparty/freevgui', lambda x: not x.env.DEDICATED),
Subproject('stub/client', lambda x: not x.env.DEDICATED),
Subproject('game_launch', lambda x: not x.env.DISABLE_LAUNCHER),
Subproject('3rdparty/extras', lambda x: x.env.CLIENT and x.env.DEST_OS != 'android'),
Subproject('3rdparty/nanogl', lambda x: x.env.CLIENT and x.env.NANOGL),
Subproject('3rdparty/gl-wes-v2', lambda x: x.env.CLIENT and x.env.GLWES),
Subproject('3rdparty/gl4es', lambda x: x.env.CLIENT and x.env.GL4ES),
Subproject('ref/gl', lambda x: x.env.CLIENT and (x.env.GL or x.env.NANOGL or x.env.GLWES or x.env.GL4ES)),
Subproject('ref/soft', lambda x: x.env.CLIENT and x.env.SOFT),
Subproject('ref/null', lambda x: x.env.CLIENT and x.env.NULL),
Subproject('3rdparty/bzip2', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_BZ2),
Subproject('3rdparty/opus', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OPUS),
Subproject('3rdparty/libogg', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OGG),
Subproject('3rdparty/vorbis', lambda x: x.env.CLIENT and (not x.env.HAVE_SYSTEM_VORBIS or not x.env.HAVE_SYSTEM_VORBISFILE)),
Subproject('3rdparty/opusfile', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OPUSFILE),
Subproject('3rdparty/mainui', lambda x: x.env.CLIENT),
Subproject('3rdparty/vgui_support', lambda x: x.env.CLIENT),
Subproject('3rdparty/MultiEmulator',lambda x: x.env.CLIENT),
# Subproject('3rdparty/freevgui', lambda x: x.env.CLIENT),
Subproject('stub/client', lambda x: x.env.CLIENT),
Subproject('game_launch', lambda x: x.env.LAUNCHER),
Subproject('engine'), # keep latest for static linking
# enabled optionally
@@ -131,7 +131,10 @@ def options(opt):
grp = opt.add_option_group('Common options')
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
help = 'build Xash Dedicated Server [default: %(default)s]')
help = 'only build Xash Dedicated Server [default: %(default)s]')
grp.add_option('--enable-dedicated', action = 'store_true', dest = 'ENABLE_DEDICATED', default = False,
help = 'enable building Xash Dedicated Server alongside client [default: %(default)s]')
grp.add_option('--gamedir', action = 'store', dest = 'GAMEDIR', default = 'valve',
help = 'engine default (base) game directory [default: %(default)s]')
@@ -236,14 +239,12 @@ def configure(conf):
conf.options.GL4ES = True
conf.options.GLES3COMPAT = True
conf.options.GL = False
conf.define('XASH_SDLMAIN', 1)
elif conf.env.MAGX:
conf.options.SDL12 = True
conf.options.NO_VGUI = True
conf.options.GL = False
conf.options.LOW_MEMORY = 1
conf.options.NO_ASYNC_RESOLVE = True
conf.define('XASH_SDLMAIN', 1)
enforce_pic = False
elif conf.env.DEST_OS == 'nswitch':
conf.options.NO_VGUI = True
@@ -395,13 +396,18 @@ def configure(conf):
conf.env.ENABLE_UTILS = conf.options.ENABLE_UTILS
conf.env.ENABLE_XAR = conf.options.ENABLE_XAR
conf.env.ENABLE_FUZZER = conf.options.ENABLE_FUZZER
conf.env.DEDICATED = conf.options.DEDICATED
if not conf.options.DEDICATED:
conf.env.SERVER = conf.options.ENABLE_DEDICATED
conf.env.CLIENT = True
conf.env.LAUNCHER = conf.env.DEST_OS not in ['android', 'nswitch', 'psvita', 'dos'] and not conf.env.MAGX and not conf.env.STATIC_LINKING
else:
conf.env.SERVER = True
conf.env.CLIENT = False
conf.env.LAUNCHER = False
conf.define_cond('SUPPORT_HL25_EXTENDED_STRUCTS', conf.options.SUPPORT_HL25_EXTENDED_STRUCTS)
# disable game_launch compiling on platform where it's not needed
conf.env.DISABLE_LAUNCHER = conf.env.DEST_OS in ['android', 'nswitch', 'psvita', 'dos'] or conf.env.MAGX or conf.env.DEDICATED or conf.env.STATIC_LINKING
if conf.env.SAILFISH == 'aurora':
conf.env.DEFAULT_RPATH = '/usr/share/su.xash.Engine/lib'
elif conf.env.DEST_OS == 'darwin':
@@ -410,6 +416,8 @@ def configure(conf):
# OpenBSD requires -z origin to enable $ORIGIN expansion in RPATH
conf.env.RPATH_ST = '-Wl,-z,origin,-rpath,%s'
conf.env.DEFAULT_RPATH = '$ORIGIN'
elif conf.env.DEST_OS in ['nswitch', 'psvita']:
conf.env.DEFAULT_RPATH = None
else:
conf.env.DEFAULT_RPATH = '$ORIGIN'