mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 19:45:05 +08:00
Compare commits
36 Commits
continuous
...
continuous
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68f1a8bdc2 | ||
|
|
da1669ddf7 | ||
|
|
67af41cce8 | ||
|
|
e2c96e62e1 | ||
|
|
2ecae442fc | ||
|
|
a1060b0eb5 | ||
|
|
ddd8de888f | ||
|
|
a758dffbc1 | ||
|
|
87775faeca | ||
|
|
ef0fc46ed8 | ||
|
|
138b4fa247 | ||
|
|
47d1f3459c | ||
|
|
4712aae834 | ||
|
|
2900ee1cde | ||
|
|
c6c4178dd2 | ||
|
|
a3ce0e6b1b | ||
|
|
0b1ad3b7f0 | ||
|
|
37fb46f092 | ||
|
|
bc8bf9a9fb | ||
|
|
9e28c98911 | ||
|
|
0a1269d52d | ||
|
|
2e5bc31c9e | ||
|
|
1b335fd945 | ||
|
|
0c8b2d007a | ||
|
|
9ee1b32e2d | ||
|
|
953ad98a16 | ||
|
|
1357057bd8 | ||
|
|
35c9323de6 | ||
|
|
13a0afef06 | ||
|
|
c7ad8e4bf6 | ||
|
|
f1754bdd5f | ||
|
|
c462a1c500 | ||
|
|
0bba184994 | ||
|
|
178602ea1f | ||
|
|
2eb8f88a20 | ||
|
|
96d11df06c |
@@ -14,3 +14,4 @@ When `-bugcomp` is specified with argument, it interpreted as flags separated wi
|
||||
| ------- | ----------- | ---------------------------- |
|
||||
| `peoei` | Reverts `pfnPEntityOfEntIndex` behavior to GoldSrc, where it returns NULL for last player due to incorrect player index comparison | * Counter-Strike: Condition Zero - Deleted Scenes |
|
||||
| `gsmrf` | Rewrites message at the moment when Game DLL attempts to write an internal engine message, usually specific to GoldSrc protocol. Right now only supports `svc_spawnstaticsound`, more messages added by request. | * MetaMod/AMXModX based mods |
|
||||
| `sp_attn_none` | Makes sounds with attenuation zero spatialized, i.e. have a stereo effect. | Possibly, every game that was made for GoldSrc. |
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
****/
|
||||
#ifndef CONST_H
|
||||
#define CONST_H
|
||||
|
||||
#include <stddef.h> // ptrdiff_t
|
||||
|
||||
//
|
||||
// Constants shared by the engine and dlls
|
||||
// This header file included by engine files and DLL files.
|
||||
@@ -724,7 +721,7 @@ enum
|
||||
};
|
||||
|
||||
typedef int func_t;
|
||||
typedef ptrdiff_t string_t;
|
||||
typedef int string_t;
|
||||
|
||||
typedef unsigned short word;
|
||||
|
||||
|
||||
@@ -79,11 +79,22 @@ typedef uint64_t longtime_t;
|
||||
#define GAME_EXPORT
|
||||
#endif
|
||||
|
||||
#define MALLOC __attribute__(( malloc ))
|
||||
|
||||
// added in GCC 11
|
||||
#if __GNUC__ >= 11
|
||||
// might want to set noclone due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116893
|
||||
// but it's easier to not force mismatched-dealloc to error yet
|
||||
#define MALLOC_LIKE( x, y ) __attribute__(( malloc( x, y )))
|
||||
#else
|
||||
#define MALLOC_LIKE( x, y ) MALLOC
|
||||
#endif
|
||||
#define NORETURN __attribute__(( noreturn ))
|
||||
#define NONNULL __attribute__(( nonnull ))
|
||||
#define _format( x ) __attribute__(( format( printf, x, x + 1 )))
|
||||
#define ALLOC_CHECK( x ) __attribute__(( alloc_size( x )))
|
||||
#define NO_ASAN __attribute__(( no_sanitize( "address" )))
|
||||
#define WARN_UNUSED_RESULT __attribute__(( warn_unused_result ))
|
||||
#define RENAME_SYMBOL( x ) asm( x )
|
||||
#else
|
||||
#if defined( _MSC_VER )
|
||||
@@ -99,6 +110,9 @@ typedef uint64_t longtime_t;
|
||||
#define _format( x )
|
||||
#define ALLOC_CHECK( x )
|
||||
#define RENAME_SYMBOL( x )
|
||||
#define MALLOC
|
||||
#define MALLOC_LIKE( x, y )
|
||||
#define WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
|
||||
@@ -274,6 +274,13 @@ void CL_GenericShot_f( void )
|
||||
string checkname;
|
||||
int i;
|
||||
|
||||
// allow overriding screenshot by users request
|
||||
if( Cmd_Argc() > 1 )
|
||||
{
|
||||
Q_strncpy( cls.shotname, Cmd_Argv( 1 ), sizeof( cls.shotname ));
|
||||
break;
|
||||
}
|
||||
|
||||
if( type == scrshot_snapshot )
|
||||
{
|
||||
fmt = "../%s_%04d.png";
|
||||
|
||||
@@ -1147,7 +1147,7 @@ static void CL_CheckForResend( void )
|
||||
if(( host.realtime - cls.connect_time ) < resendTime )
|
||||
return;
|
||||
|
||||
res = NET_StringToAdrNB( cls.servername, &adr );
|
||||
res = NET_StringToAdrNB( cls.servername, &adr, false );
|
||||
|
||||
if( res == NET_EAI_NONAME )
|
||||
{
|
||||
|
||||
@@ -388,7 +388,6 @@ void CL_ParseStaticDecal( sizebuf_t *msg )
|
||||
{
|
||||
vec3_t origin;
|
||||
int decalIndex, entityIndex, modelIndex;
|
||||
cl_entity_t *ent = NULL;
|
||||
float scale;
|
||||
int flags;
|
||||
|
||||
@@ -1181,17 +1180,16 @@ CL_ParseBaseline
|
||||
*/
|
||||
void CL_ParseBaseline( sizebuf_t *msg, qboolean legacy )
|
||||
{
|
||||
int i, newnum;
|
||||
entity_state_t nullstate;
|
||||
qboolean player;
|
||||
cl_entity_t *ent;
|
||||
const entity_state_t nullstate = { 0 };
|
||||
|
||||
Delta_InitClient (); // finalize client delta's
|
||||
|
||||
memset( &nullstate, 0, sizeof( nullstate ));
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
cl_entity_t *ent;
|
||||
qboolean player;
|
||||
int newnum;
|
||||
|
||||
if( legacy )
|
||||
{
|
||||
newnum = MSG_ReadWord( msg );
|
||||
@@ -1207,10 +1205,10 @@ void CL_ParseBaseline( sizebuf_t *msg, qboolean legacy )
|
||||
Host_Error( "%s: no free edicts\n", __func__ );
|
||||
|
||||
ent = CL_EDICT_NUM( newnum );
|
||||
memset( &ent->prevstate, 0, sizeof( ent->prevstate ));
|
||||
ent->prevstate = nullstate;
|
||||
ent->index = newnum;
|
||||
|
||||
MSG_ReadDeltaEntity( msg, &ent->prevstate, &ent->baseline, newnum, player, 1.0f );
|
||||
MSG_ReadDeltaEntity( msg, &nullstate, &ent->baseline, newnum, player, 1.0f );
|
||||
|
||||
if( legacy )
|
||||
{
|
||||
@@ -1220,11 +1218,13 @@ void CL_ParseBaseline( sizebuf_t *msg, qboolean legacy )
|
||||
|
||||
if( !legacy )
|
||||
{
|
||||
int i;
|
||||
|
||||
cl.instanced_baseline_count = MSG_ReadUBitLong( msg, 6 );
|
||||
|
||||
for( i = 0; i < cl.instanced_baseline_count; i++ )
|
||||
{
|
||||
newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
|
||||
int newnum = MSG_ReadUBitLong( msg, MAX_ENTITY_BITS );
|
||||
MSG_ReadDeltaEntity( msg, &nullstate, &cl.instanced_baseline[i], newnum, false, 1.0f );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1269,6 +1269,73 @@ void GAME_EXPORT R_Sprite_Smoke( TEMPENTITY *pTemp, float scale )
|
||||
pTemp->entity.curstate.scale = scale;
|
||||
}
|
||||
|
||||
static void R_Spray_Generic( const char *func, const vec3_t pos, const vec3_t dir, int modelIndex, int count, int speed, int spread, int rendermode, qboolean sprite_spray )
|
||||
{
|
||||
model_t *mod = CL_ModelHandle( modelIndex );
|
||||
float noise = spread / 100.0f;
|
||||
float znoise = noise * 1.5f;
|
||||
int i;
|
||||
|
||||
znoise = Q_min( 1.0f, znoise );
|
||||
|
||||
if( !mod )
|
||||
{
|
||||
Con_Reportf( "%s: No model %d!\n", func, modelIndex );
|
||||
return;
|
||||
}
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
TEMPENTITY *tent = CL_TempEntAlloc( pos, mod );
|
||||
float rand_speed;
|
||||
vec3_t noise_vec, vout;
|
||||
|
||||
if( !tent )
|
||||
break;
|
||||
|
||||
tent->flags |= FTENT_SLOWGRAVITY;
|
||||
tent->entity.curstate.rendermode = rendermode;
|
||||
tent->entity.curstate.renderamt = 255;
|
||||
tent->entity.baseline.renderamt = 255;
|
||||
tent->entity.curstate.renderfx = kRenderFxNoDissipation;
|
||||
|
||||
noise_vec[0] = COM_RandomFloat( -noise, noise );
|
||||
noise_vec[1] = COM_RandomFloat( -noise, noise );
|
||||
noise_vec[2] = COM_RandomFloat( 0.0f, znoise );
|
||||
rand_speed = COM_RandomFloat( speed * 0.8f, speed * 1.2f );
|
||||
|
||||
VectorAdd( dir, noise_vec, vout );
|
||||
VectorScale( vout, rand_speed, tent->entity.baseline.origin );
|
||||
|
||||
if( sprite_spray ) // if TE_SPRITE_SPRAY
|
||||
{
|
||||
tent->flags |= FTENT_FADEOUT;
|
||||
tent->fadeSpeed = 2.0f;
|
||||
|
||||
tent->entity.curstate.framerate = 0.5f;
|
||||
tent->die = cl.time + 0.35;
|
||||
tent->entity.curstate.frame = COM_RandomLong( 0, tent->frameMax ); // frameMax inclusive
|
||||
}
|
||||
else
|
||||
{
|
||||
tent->flags |= FTENT_COLLIDEWORLD;
|
||||
|
||||
if( tent->frameMax > 1 )
|
||||
{
|
||||
tent->flags |= FTENT_SPRANIMATE;
|
||||
tent->entity.curstate.framerate = 10.0f;
|
||||
tent->die = cl.time + tent->frameMax * 0.1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tent->entity.curstate.framerate = 1.0f;
|
||||
tent->die = cl.time + 0.35;
|
||||
}
|
||||
tent->entity.curstate.frame = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
R_Spray
|
||||
@@ -1278,61 +1345,7 @@ Throws a shower of sprites or models
|
||||
*/
|
||||
void GAME_EXPORT R_Spray( const vec3_t pos, const vec3_t dir, int modelIndex, int count, int speed, int spread, int rendermode )
|
||||
{
|
||||
TEMPENTITY *pTemp;
|
||||
float noise;
|
||||
float znoise;
|
||||
model_t *pmodel;
|
||||
int i;
|
||||
|
||||
if(( pmodel = CL_ModelHandle( modelIndex )) == NULL )
|
||||
{
|
||||
Con_Reportf( "No model %d!\n", modelIndex );
|
||||
return;
|
||||
}
|
||||
|
||||
noise = (float)spread / 100.0f;
|
||||
|
||||
// more vertical displacement
|
||||
znoise = Q_min( 1.0f, noise * 1.5f );
|
||||
|
||||
for( i = 0; i < count; i++ )
|
||||
{
|
||||
pTemp = CL_TempEntAlloc( pos, pmodel );
|
||||
if( !pTemp ) return;
|
||||
|
||||
pTemp->entity.curstate.rendermode = rendermode;
|
||||
pTemp->entity.baseline.renderamt = pTemp->entity.curstate.renderamt = 255;
|
||||
pTemp->entity.curstate.renderfx = kRenderFxNoDissipation;
|
||||
|
||||
if( rendermode != kRenderGlow )
|
||||
{
|
||||
// spray
|
||||
pTemp->flags |= FTENT_COLLIDEWORLD | FTENT_SLOWGRAVITY;
|
||||
|
||||
if( pTemp->frameMax > 1 )
|
||||
{
|
||||
pTemp->flags |= FTENT_COLLIDEWORLD | FTENT_SLOWGRAVITY | FTENT_SPRANIMATE;
|
||||
pTemp->die = cl.time + (pTemp->frameMax * 0.1f);
|
||||
pTemp->entity.curstate.framerate = 10;
|
||||
}
|
||||
else pTemp->die = cl.time + 0.35f;
|
||||
}
|
||||
else
|
||||
{
|
||||
// sprite spray
|
||||
pTemp->entity.curstate.frame = COM_RandomLong( 0, pTemp->frameMax );
|
||||
pTemp->flags |= FTENT_FADEOUT | FTENT_SLOWGRAVITY;
|
||||
pTemp->entity.curstate.framerate = 0.5;
|
||||
pTemp->die = cl.time + 0.35f;
|
||||
pTemp->fadeSpeed = 2.0;
|
||||
}
|
||||
|
||||
// make the spittle fly the direction indicated, but mix in some noise.
|
||||
pTemp->entity.baseline.origin[0] = dir[0] + COM_RandomFloat( -noise, noise );
|
||||
pTemp->entity.baseline.origin[1] = dir[1] + COM_RandomFloat( -noise, noise );
|
||||
pTemp->entity.baseline.origin[2] = dir[2] + COM_RandomFloat( 0, znoise );
|
||||
VectorScale( pTemp->entity.baseline.origin, COM_RandomFloat(( speed * 0.8f ), ( speed * 1.2f )), pTemp->entity.baseline.origin );
|
||||
}
|
||||
R_Spray_Generic( __func__, pos, dir, modelIndex, count, speed, spread, rendermode, false );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1344,7 +1357,7 @@ Spray of alpha sprites
|
||||
*/
|
||||
void GAME_EXPORT R_Sprite_Spray( const vec3_t pos, const vec3_t dir, int modelIndex, int count, int speed, int spread )
|
||||
{
|
||||
R_Spray( pos, dir, modelIndex, count, speed, spread, kRenderGlow );
|
||||
R_Spray_Generic( __func__, pos, dir, modelIndex, count, speed, spread, kRenderTransAlpha, true );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3113,4 +3126,3 @@ void CL_ClearEffects( void )
|
||||
CL_ClearParticles ();
|
||||
CL_ClearLightStyles ();
|
||||
}
|
||||
|
||||
|
||||
@@ -524,6 +524,12 @@ static void SND_Spatialize( channel_t *ch )
|
||||
dist = VectorNormalizeLength( source_vec );
|
||||
dot = DotProduct( s_listener.right, source_vec );
|
||||
|
||||
if( !FBitSet( host.bugcomp, BUGCOMP_SPATIALIZE_SOUND_WITH_ATTN_NONE ))
|
||||
{
|
||||
// don't pan sounds with no attenuation
|
||||
if( ch->dist_mult <= 0.0f ) dot = 0.0f;
|
||||
}
|
||||
|
||||
// fill out channel volumes for single location
|
||||
S_SpatializeChannel( &ch->leftvol, &ch->rightvol, ch->master_vol, gain, dot, dist * ch->dist_mult );
|
||||
|
||||
|
||||
@@ -112,6 +112,9 @@ typedef enum
|
||||
#include "con_nprint.h"
|
||||
#include "crclib.h"
|
||||
#include "ref_api.h"
|
||||
#define FSCALLBACK_OVERRIDE_OPEN
|
||||
#define FSCALLBACK_OVERRIDE_LOADFILE
|
||||
#define FSCALLBACK_OVERRIDE_MALLOC_LIKE
|
||||
#include "fscallback.h"
|
||||
|
||||
// PERFORMANCE INFO
|
||||
@@ -273,6 +276,9 @@ typedef enum bugcomp_e
|
||||
// rewrites mod's attempts to write GoldSrc-specific messages into Xash protocol
|
||||
// (new wrappers are added by request)
|
||||
BUGCOMP_MESSAGE_REWRITE_FACILITY_FLAG = BIT( 1 ),
|
||||
|
||||
// makes sound with no attenuation spatialized, like in GoldSrc
|
||||
BUGCOMP_SPATIALIZE_SOUND_WITH_ATTN_NONE = BIT( 2 ),
|
||||
} bugcomp_t;
|
||||
|
||||
typedef struct host_parm_s
|
||||
@@ -359,12 +365,49 @@ extern host_parm_t host;
|
||||
|
||||
typedef void (*xcommand_t)( void );
|
||||
|
||||
//
|
||||
// zone.c
|
||||
//
|
||||
void Memory_Init( void );
|
||||
void _Mem_Free( void *data, const char *filename, int fileline );
|
||||
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 3 ) WARN_UNUSED_RESULT;
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline )
|
||||
WARN_UNUSED_RESULT;
|
||||
void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline );
|
||||
void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline );
|
||||
void _Mem_Check( const char *filename, int fileline );
|
||||
qboolean Mem_IsAllocatedExt( poolhandle_t poolptr, void *data );
|
||||
void Mem_PrintList( size_t minallocationsize );
|
||||
void Mem_PrintStats( void );
|
||||
|
||||
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Realloc( pool, ptr, size ) _Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_AllocPool( name ) _Mem_AllocPool( name, __FILE__, __LINE__ )
|
||||
#define Mem_FreePool( pool ) _Mem_FreePool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_EmptyPool( pool ) _Mem_EmptyPool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_IsAllocated( mem ) Mem_IsAllocatedExt( NULL, mem )
|
||||
#define Mem_Check() _Mem_Check( __FILE__, __LINE__ )
|
||||
|
||||
//
|
||||
// filesystem_engine.c
|
||||
//
|
||||
void FS_Init( const char *basedir );
|
||||
void FS_Shutdown( void );
|
||||
void *FS_GetNativeObject( const char *obj );
|
||||
int FS_Close( file_t *file );
|
||||
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly )
|
||||
MALLOC_LIKE( FS_Close, 1 ) WARN_UNUSED_RESULT;
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
|
||||
//
|
||||
// cmd.c
|
||||
@@ -397,30 +440,6 @@ void Cmd_ExecuteString( const char *text );
|
||||
void Cmd_ForwardToServer( void );
|
||||
void Cmd_Escape( char *newCommand, const char *oldCommand, int len );
|
||||
|
||||
//
|
||||
// zone.c
|
||||
//
|
||||
void Memory_Init( void );
|
||||
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
|
||||
poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline );
|
||||
void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline );
|
||||
void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline );
|
||||
void _Mem_Free( void *data, const char *filename, int fileline );
|
||||
void _Mem_Check( const char *filename, int fileline );
|
||||
qboolean Mem_IsAllocatedExt( poolhandle_t poolptr, void *data );
|
||||
void Mem_PrintList( size_t minallocationsize );
|
||||
void Mem_PrintStats( void );
|
||||
|
||||
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Realloc( pool, ptr, size ) _Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_AllocPool( name ) _Mem_AllocPool( name, __FILE__, __LINE__ )
|
||||
#define Mem_FreePool( pool ) _Mem_FreePool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_EmptyPool( pool ) _Mem_EmptyPool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_IsAllocated( mem ) Mem_IsAllocatedExt( NULL, mem )
|
||||
#define Mem_Check() _Mem_Check( __FILE__, __LINE__ )
|
||||
|
||||
//
|
||||
// imagelib
|
||||
@@ -431,10 +450,10 @@ void Image_Setup( void );
|
||||
void Image_Init( void );
|
||||
void Image_Shutdown( void );
|
||||
void Image_AddCmdFlags( uint flags );
|
||||
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size );
|
||||
qboolean FS_SaveImage( const char *filename, rgbdata_t *pix );
|
||||
rgbdata_t *FS_CopyImage( rgbdata_t *in );
|
||||
void FS_FreeImage( rgbdata_t *pack );
|
||||
rgbdata_t *FS_LoadImage( const char *filename, const byte *buffer, size_t size ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
||||
qboolean FS_SaveImage( const char *filename, rgbdata_t *pix );
|
||||
rgbdata_t *FS_CopyImage( rgbdata_t *in ) MALLOC_LIKE( FS_FreeImage, 1 ) WARN_UNUSED_RESULT;
|
||||
extern const bpc_desc_t PFDesc[]; // image get pixelformat
|
||||
qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, float reserved );
|
||||
void Image_PaletteHueReplace( byte *palSrc, int newHue, int start, int end, int pal_size );
|
||||
@@ -489,14 +508,14 @@ typedef struct
|
||||
//
|
||||
void Sound_Init( void );
|
||||
void Sound_Shutdown( void );
|
||||
wavdata_t *FS_LoadSound( const char *filename, const byte *buffer, size_t size );
|
||||
void FS_FreeSound( wavdata_t *pack );
|
||||
stream_t *FS_OpenStream( const char *filename );
|
||||
void FS_FreeStream( stream_t *stream );
|
||||
wavdata_t *FS_LoadSound( const char *filename, const byte *buffer, size_t size ) MALLOC_LIKE( FS_FreeSound, 1 ) WARN_UNUSED_RESULT;
|
||||
stream_t *FS_OpenStream( const char *filename ) MALLOC_LIKE( FS_FreeStream, 1 ) WARN_UNUSED_RESULT;
|
||||
wavdata_t *FS_StreamInfo( stream_t *stream );
|
||||
int FS_ReadStream( stream_t *stream, int bytes, void *buffer );
|
||||
int FS_SetStreamPos( stream_t *stream, int newpos );
|
||||
int FS_GetStreamPos( stream_t *stream );
|
||||
void FS_FreeStream( stream_t *stream );
|
||||
qboolean Sound_Process( wavdata_t **wav, int rate, int width, int channels, uint flags );
|
||||
uint Sound_GetApproxWavePlayLen( const char *filepath );
|
||||
qboolean Sound_SupportedFileFormat( const char *fileext );
|
||||
@@ -561,7 +580,7 @@ qboolean SV_Active( void );
|
||||
char *COM_MemFgets( byte *pMemFile, int fileSize, int *filePos, char *pBuffer, int bufferSize );
|
||||
void COM_HexConvert( const char *pszInput, int nInputLength, byte *pOutput );
|
||||
int COM_SaveFile( const char *filename, const void *data, int len );
|
||||
byte* COM_LoadFileForMe( const char *filename, int *pLength );
|
||||
byte *COM_LoadFileForMe( const char *filename, int *pLength ) MALLOC_LIKE( free, 1 );
|
||||
qboolean COM_IsSafeFileToDownload( const char *filename );
|
||||
cvar_t *pfnCVarGetPointer( const char *szVarName );
|
||||
int pfnDrawConsoleString( int x, int y, char *string );
|
||||
@@ -664,7 +683,7 @@ char *CL_Userinfo( void );
|
||||
void CL_LegacyUpdateInfo( void );
|
||||
void CL_CharEvent( int key );
|
||||
qboolean CL_DisableVisibility( void );
|
||||
byte *COM_LoadFile( const char *filename, int usehunk, int *pLength );
|
||||
byte *COM_LoadFile( const char *filename, int usehunk, int *pLength ) MALLOC_LIKE( free, 1 );
|
||||
struct cmd_s *Cmd_GetFirstFunctionHandle( void );
|
||||
struct cmd_s *Cmd_GetNextFunctionHandle( struct cmd_s *cmd );
|
||||
struct cmdalias_s *Cmd_AliasGetList( void );
|
||||
|
||||
@@ -272,6 +272,15 @@ static qboolean Cvar_ValidateVarName( const char *s, qboolean isvalue )
|
||||
return true;
|
||||
}
|
||||
|
||||
static void Cvar_Free( convar_t *var )
|
||||
{
|
||||
freestring( var->name );
|
||||
freestring( var->string );
|
||||
freestring( var->def_string );
|
||||
freestring( var->desc );
|
||||
Mem_Free( var );
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_UnlinkVar
|
||||
@@ -311,17 +320,13 @@ static int Cvar_UnlinkVar( const char *var_name, int group )
|
||||
#endif
|
||||
|
||||
// unlink variable from list
|
||||
freestring( var->string );
|
||||
*prev = var->next;
|
||||
|
||||
// only allocated cvars can throw these fields
|
||||
if( FBitSet( var->flags, FCVAR_ALLOCATED ))
|
||||
{
|
||||
freestring( var->name );
|
||||
freestring( var->def_string );
|
||||
freestring( var->desc );
|
||||
Mem_Free( var );
|
||||
}
|
||||
Cvar_Free( var );
|
||||
else
|
||||
freestring( var->string );
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -1217,6 +1222,20 @@ static void Cvar_List_f( void )
|
||||
Con_Printf( "\n%i cvars\n", count );
|
||||
}
|
||||
|
||||
static qboolean Cvar_ValidateUnlinkGroup( int group )
|
||||
{
|
||||
if( FBitSet( group, FCVAR_EXTDLL ) && !Cvar_VariableInteger( "host_gameloaded" ))
|
||||
return false;
|
||||
|
||||
if( FBitSet( group, FCVAR_CLIENTDLL ) && !Cvar_VariableInteger( "host_clientloaded" ))
|
||||
return false;
|
||||
|
||||
if( FBitSet( group, FCVAR_GAMEUIDLL ) && !Cvar_VariableInteger( "host_gameuiloaded" ))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_Unlink
|
||||
@@ -1228,19 +1247,88 @@ void Cvar_Unlink( int group )
|
||||
{
|
||||
int count;
|
||||
|
||||
if( Cvar_VariableInteger( "host_gameloaded" ) && FBitSet( group, FCVAR_EXTDLL ))
|
||||
return;
|
||||
|
||||
if( Cvar_VariableInteger( "host_clientloaded" ) && FBitSet( group, FCVAR_CLIENTDLL ))
|
||||
return;
|
||||
|
||||
if( Cvar_VariableInteger( "host_gameuiloaded" ) && FBitSet( group, FCVAR_GAMEUIDLL ))
|
||||
if( !Cvar_ValidateUnlinkGroup( group ))
|
||||
return;
|
||||
|
||||
count = Cvar_UnlinkVar( NULL, group );
|
||||
Con_Reportf( "unlink %i cvars\n", count );
|
||||
}
|
||||
|
||||
pending_cvar_t *Cvar_PrepareToUnlink( int group )
|
||||
{
|
||||
pending_cvar_t *list = NULL;
|
||||
convar_t *cv;
|
||||
|
||||
for( cv = cvar_vars; cv != NULL; cv = cv->next )
|
||||
{
|
||||
size_t namelen;
|
||||
pending_cvar_t *p;
|
||||
|
||||
if( !FBitSet( cv->flags, group ))
|
||||
continue;
|
||||
|
||||
namelen = Q_strlen( cv->name ) + 1;
|
||||
p = Mem_Malloc( host.mempool, sizeof( *list ) + namelen );
|
||||
p->next = list;
|
||||
p->cv_cur = cv;
|
||||
p->cv_next = cv->next;
|
||||
p->cv_allocated = FBitSet( cv->flags, FCVAR_ALLOCATED ) ? true : false;
|
||||
Q_strncpy( p->cv_name, cv->name, namelen );
|
||||
list = p;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void Cvar_UnlinkPendingCvars( pending_cvar_t *list )
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while( list != NULL )
|
||||
{
|
||||
pending_cvar_t *next = list->next;
|
||||
convar_t *cv_prev, *cv;
|
||||
|
||||
for( cv_prev = NULL, cv = cvar_vars; cv != NULL; cv_prev = cv, cv = cv->next )
|
||||
{
|
||||
if( cv == list->cv_cur )
|
||||
break;
|
||||
}
|
||||
|
||||
if( cv == NULL )
|
||||
{
|
||||
Con_Reportf( "%s: can't find %s in variable list\n", __func__, list->cv_name );
|
||||
Mem_Free( list );
|
||||
list = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
// unlink cvar from list
|
||||
BaseCmd_Remove( HM_CVAR, list->cv_name );
|
||||
if( cv_prev != NULL )
|
||||
cv_prev->next = list->cv_next;
|
||||
else cvar_vars = list->cv_next;
|
||||
|
||||
if( list->cv_allocated )
|
||||
Cvar_Free( list->cv_cur );
|
||||
else
|
||||
{
|
||||
// TODO: can't free cvar string here because
|
||||
// it's not safe to access cv_cur and
|
||||
// can't save string pointer because it could've been changed
|
||||
// and pointer to it is already lost
|
||||
// freestring( list->cv_string );
|
||||
}
|
||||
|
||||
// now free pending cvar
|
||||
Mem_Free( list );
|
||||
list = next;
|
||||
count++;
|
||||
}
|
||||
|
||||
Con_Reportf( "unlink %i cvars\n", count );
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Cvar_Init
|
||||
|
||||
@@ -18,6 +18,18 @@ GNU General Public License for more details.
|
||||
|
||||
#include "cvardef.h"
|
||||
|
||||
// As some mods dynamically allocate cvars and free them without notifying the engine
|
||||
// let's construct a list of cvars that must be removed
|
||||
typedef struct pending_cvar_s
|
||||
{
|
||||
struct pending_cvar_s *next;
|
||||
|
||||
convar_t *cv_cur; // preserve the data that might get freed
|
||||
convar_t *cv_next;
|
||||
qboolean cv_allocated; // if it's allocated by us, it's safe to access cv_cur
|
||||
char cv_name[];
|
||||
} pending_cvar_t;
|
||||
|
||||
cvar_t *Cvar_GetList( void );
|
||||
#define Cvar_FindVar( name ) Cvar_FindVarExt( name, 0 )
|
||||
convar_t *Cvar_FindVarExt( const char *var_name, int ignore_group );
|
||||
@@ -43,4 +55,7 @@ void Cvar_Init( void );
|
||||
void Cvar_PostFSInit( void );
|
||||
void Cvar_Unlink( int group );
|
||||
|
||||
pending_cvar_t *Cvar_PrepareToUnlink( int group );
|
||||
void Cvar_UnlinkPendingCvars( pending_cvar_t *pending_cvars );
|
||||
|
||||
#endif//CVAR_H
|
||||
|
||||
@@ -27,6 +27,31 @@ fs_globals_t *FI;
|
||||
static pfnCreateInterface_t fs_pfnCreateInterface;
|
||||
static HINSTANCE fs_hInstance;
|
||||
|
||||
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
|
||||
{
|
||||
return g_fsapi.Search( pattern, caseinsensitive, gamedironly );
|
||||
}
|
||||
|
||||
int FS_Close( file_t *file )
|
||||
{
|
||||
return g_fsapi.Close( file );
|
||||
}
|
||||
|
||||
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly )
|
||||
{
|
||||
return g_fsapi.Open( filepath, mode, gamedironly );
|
||||
}
|
||||
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
{
|
||||
return g_fsapi.LoadFile( path, filesizeptr, gamedironly );
|
||||
}
|
||||
|
||||
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
|
||||
{
|
||||
return g_fsapi.LoadDirectFile( path, filesizeptr );
|
||||
}
|
||||
|
||||
static void COM_StripDirectorySlash( char *pname )
|
||||
{
|
||||
size_t len;
|
||||
|
||||
@@ -73,6 +73,7 @@ static feature_message_t bugcomp_features[] =
|
||||
{
|
||||
{ BUGCOMP_PENTITYOFENTINDEX_FLAG, "pfnPEntityOfEntIndex bugfix revert", "peoei" },
|
||||
{ BUGCOMP_MESSAGE_REWRITE_FACILITY_FLAG, "GoldSrc Message Rewrite Facility", "gsmrf" },
|
||||
{ BUGCOMP_SPATIALIZE_SOUND_WITH_ATTN_NONE, "spatialize sounds with zero attenuation", "sp_attn_none" },
|
||||
};
|
||||
|
||||
static feature_message_t engine_features[] =
|
||||
|
||||
@@ -110,7 +110,7 @@ void Image_Reset( void )
|
||||
image.size = 0;
|
||||
}
|
||||
|
||||
static rgbdata_t *ImagePack( void )
|
||||
static MALLOC_LIKE( FS_FreeImage, 1 ) rgbdata_t *ImagePack( void )
|
||||
{
|
||||
rgbdata_t *pack;
|
||||
|
||||
@@ -547,7 +547,7 @@ static void Test_CheckImage( const char *name, rgbdata_t *rgb )
|
||||
TASSERT( load->size == rgb->size )
|
||||
TASSERT( memcmp(load->buffer, rgb->buffer, rgb->size ) == 0 )
|
||||
|
||||
Mem_Free( load );
|
||||
FS_FreeImage( load );
|
||||
}
|
||||
|
||||
void Test_RunImagelib( void )
|
||||
|
||||
@@ -126,20 +126,14 @@ dll_user_t *FS_FindLibrary( const char *dllname, qboolean directpath )
|
||||
=============================================================================
|
||||
*/
|
||||
|
||||
static void COM_GenerateCommonLibraryName( const char *name, const char *ext, const char *suffix, char *out, size_t size )
|
||||
static void COM_GenerateCommonLibraryName( const char *name, const char *ext, char *out, size_t size )
|
||||
{
|
||||
#if ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) && XASH_X86
|
||||
if( suffix )
|
||||
Q_snprintf( out, size, "%s_%s.%s", name, suffix, ext );
|
||||
else Q_snprintf( out, size, "%s.%s", name, ext );
|
||||
Q_snprintf( out, size, "%s.%s", name, ext );
|
||||
#elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE )
|
||||
if( suffix )
|
||||
Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildarch(), suffix, ext );
|
||||
else Q_snprintf( out, size, "%s_%s.%s", name, Q_buildarch(), ext );
|
||||
Q_snprintf( out, size, "%s_%s.%s", name, Q_buildarch(), ext );
|
||||
#else
|
||||
if( suffix )
|
||||
Q_snprintf( out, size, "%s_%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), suffix, ext );
|
||||
else Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), ext );
|
||||
Q_snprintf( out, size, "%s_%s_%s.%s", name, Q_buildos(), Q_buildarch(), ext );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -160,7 +154,7 @@ static void COM_GenerateClientLibraryPath( const char *name, char *out, size_t s
|
||||
// we don't have any library prefixes, so we can safely append dll_path here
|
||||
Q_snprintf( dllpath, sizeof( dllpath ), "%s/%s", GI->dll_path, name );
|
||||
|
||||
COM_GenerateCommonLibraryName( dllpath, OS_LIB_EXT, NULL, out, size );
|
||||
COM_GenerateCommonLibraryName( dllpath, OS_LIB_EXT, out, size );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -217,13 +211,7 @@ static void COM_GenerateServerLibraryPath( char *out, size_t size )
|
||||
COM_StripExtension( dllpath );
|
||||
COM_StripIntelSuffix( dllpath );
|
||||
|
||||
#if XASH_ARCH_USES_ONLY_ABI2
|
||||
COM_GenerateCommonLibraryName( dllpath, ext, NULL, out, size );
|
||||
#elif XASH_64BIT
|
||||
COM_GenerateCommonLibraryName( dllpath, ext, "st64", out, size );
|
||||
#else
|
||||
COM_GenerateCommonLibraryName( dllpath, ext, NULL, out, size );
|
||||
#endif
|
||||
COM_GenerateCommonLibraryName( dllpath, ext, out, size );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ typedef struct master_s
|
||||
struct master_s *next;
|
||||
qboolean sent; // TODO: get rid of this internal state
|
||||
qboolean save;
|
||||
qboolean v6only;
|
||||
string address;
|
||||
netadr_t adr; // temporary, rewritten after each send
|
||||
|
||||
@@ -45,7 +46,7 @@ NET_GetMasterHostByName
|
||||
*/
|
||||
static net_gai_state_t NET_GetMasterHostByName( master_t *m )
|
||||
{
|
||||
net_gai_state_t res = NET_StringToAdrNB( m->address, &m->adr );
|
||||
net_gai_state_t res = NET_StringToAdrNB( m->address, &m->adr, m->v6only );
|
||||
|
||||
if( res == NET_EAI_OK )
|
||||
return res;
|
||||
@@ -251,7 +252,7 @@ NET_AddMaster
|
||||
Add master to the list
|
||||
========================
|
||||
*/
|
||||
static void NET_AddMaster( const char *addr, qboolean save )
|
||||
static void NET_AddMaster( const char *addr, qboolean save, qboolean v6only )
|
||||
{
|
||||
master_t *master, *last;
|
||||
|
||||
@@ -261,10 +262,11 @@ static void NET_AddMaster( const char *addr, qboolean save )
|
||||
return;
|
||||
}
|
||||
|
||||
master = Mem_Malloc( host.mempool, sizeof( master_t ) );
|
||||
master = Mem_Malloc( host.mempool, sizeof( *master ) );
|
||||
Q_strncpy( master->address, addr, sizeof( master->address ));
|
||||
master->sent = false;
|
||||
master->save = save;
|
||||
master->v6only = v6only;
|
||||
master->next = NULL;
|
||||
master->adr.type = 0;
|
||||
|
||||
@@ -283,7 +285,7 @@ static void NET_AddMaster_f( void )
|
||||
return;
|
||||
}
|
||||
|
||||
NET_AddMaster( Cmd_Argv( 1 ), true ); // save them into config
|
||||
NET_AddMaster( Cmd_Argv( 1 ), true, false ); // save them into config
|
||||
ml.modified = true; // save config
|
||||
}
|
||||
|
||||
@@ -316,15 +318,14 @@ static void NET_ListMasters_f( void )
|
||||
master_t *list;
|
||||
int i;
|
||||
|
||||
Msg( "Master servers\n=============\n" );
|
||||
|
||||
Con_Printf( "Master servers:\n" );
|
||||
|
||||
for( i = 1, list = ml.list; list; i++, list = list->next )
|
||||
{
|
||||
Msg( "%d\t%s", i, list->address );
|
||||
Con_Printf( "%d\t%s", i, list->address );
|
||||
if( list->adr.type != 0 )
|
||||
Msg( "\t%s\n", NET_AdrToString( list->adr ));
|
||||
else Msg( "\n" );
|
||||
Con_Printf( "\t%s\n", NET_AdrToString( list->adr ));
|
||||
else Con_Printf( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,11 +355,15 @@ static void NET_LoadMasters( void )
|
||||
// format: master <addr>\n
|
||||
while( ( pfile = COM_ParseFile( pfile, token, sizeof( token ) ) ) )
|
||||
{
|
||||
if( !Q_strcmp( token, "master" ) ) // load addr
|
||||
if( !Q_strcmp( token, "master" )) // load addr
|
||||
{
|
||||
pfile = COM_ParseFile( pfile, token, sizeof( token ) );
|
||||
|
||||
NET_AddMaster( token, true );
|
||||
NET_AddMaster( token, true, false );
|
||||
}
|
||||
else if( !Q_strcmp( token, "master6" ))
|
||||
{
|
||||
pfile = COM_ParseFile( pfile, token, sizeof( token ) );
|
||||
NET_AddMaster( token, true, true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +401,7 @@ void NET_SaveMasters( void )
|
||||
for( m = ml.list; m; m = m->next )
|
||||
{
|
||||
if( m->save )
|
||||
FS_Printf( f, "master %s\n", m->address );
|
||||
FS_Printf( f, "%s %s\n", m->v6only ? "master6" : "master", m->address );
|
||||
}
|
||||
|
||||
FS_Close( f );
|
||||
@@ -418,10 +423,10 @@ void NET_InitMasters( void )
|
||||
Cvar_RegisterVariable( &sv_verbose_heartbeats );
|
||||
|
||||
// keep main master always there
|
||||
NET_AddMaster( MASTERSERVER_ADR, false );
|
||||
NET_AddMaster( "aaaa.mentality.rip:27010", false ); // IPv6-only
|
||||
NET_AddMaster( "mentality.rip:27011", false ); // testing server, might be offline
|
||||
NET_AddMaster( "aaaa.mentality.rip:27011", false ); // IPv6-only, testing server, might be offline
|
||||
NET_AddMaster( MASTERSERVER_ADR, false, false );
|
||||
NET_AddMaster( "aaaa.mentality.rip:27010", false, true ); // IPv6-only
|
||||
NET_AddMaster( "mentality.rip:27011", false, false ); // testing server, might be offline
|
||||
NET_AddMaster( "aaaa.mentality.rip:27011", false, true ); // IPv6-only, testing server, might be offline
|
||||
|
||||
NET_LoadMasters( );
|
||||
}
|
||||
|
||||
@@ -30,13 +30,6 @@ GNU General Public License for more details.
|
||||
|
||||
#define MIPTEX_CUSTOM_PALETTE_SIZE_BYTES ( sizeof( int16_t ) + 768 )
|
||||
|
||||
typedef struct wadlist_s
|
||||
{
|
||||
char wadnames[MAX_MAP_WADS][32];
|
||||
int wadusage[MAX_MAP_WADS];
|
||||
int count;
|
||||
} wadlist_t;
|
||||
|
||||
typedef struct leaflist_s
|
||||
{
|
||||
int count;
|
||||
@@ -136,7 +129,6 @@ typedef struct
|
||||
dclipnode32_t *clipnodes_out; // temporary 32-bit array to hold clipnodes
|
||||
|
||||
// misc stuff
|
||||
wadlist_t wadlist;
|
||||
int lightmap_samples; // samples per lightmap (1 or 3)
|
||||
int version; // model version
|
||||
qboolean isworld;
|
||||
@@ -1835,7 +1827,7 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||
world.generator[0] = '\0';
|
||||
world.compiler[0] = '\0';
|
||||
world.message[0] = '\0';
|
||||
bmod->wadlist.count = 0;
|
||||
world.wadlist.count = 0;
|
||||
|
||||
// parse all the wads for loading textures in right ordering
|
||||
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
|
||||
@@ -1878,12 +1870,12 @@ static void Mod_LoadEntities( model_t *mod, dbspmodel_t *bmod )
|
||||
// make sure that wad is really exist
|
||||
if( FS_FileExists( va( "%s.wad", token ), false ))
|
||||
{
|
||||
int num = bmod->wadlist.count++;
|
||||
Q_strncpy( bmod->wadlist.wadnames[num], token, sizeof( bmod->wadlist.wadnames[0] ));
|
||||
bmod->wadlist.wadusage[num] = 0;
|
||||
int num = world.wadlist.count++;
|
||||
Q_strncpy( world.wadlist.wadnames[num], token, sizeof( world.wadlist.wadnames[0] ));
|
||||
world.wadlist.wadusage[num] = 0;
|
||||
}
|
||||
|
||||
if( bmod->wadlist.count >= MAX_MAP_WADS )
|
||||
if( world.wadlist.count >= MAX_MAP_WADS )
|
||||
break; // too many wads...
|
||||
}
|
||||
}
|
||||
@@ -2030,24 +2022,35 @@ static void Mod_LoadMarkSurfaces( model_t *mod, dbspmodel_t *bmod )
|
||||
|
||||
if( bmod->version == QBSP2_VERSION )
|
||||
{
|
||||
dmarkface32_t *in = bmod->markfaces32;
|
||||
const dmarkface32_t *in = bmod->markfaces32;
|
||||
|
||||
for( i = 0; i < bmod->nummarkfaces; i++, in++ )
|
||||
for( i = 0; i < bmod->nummarkfaces; i++ )
|
||||
{
|
||||
if( *in < 0 || *in >= mod->numsurfaces )
|
||||
Host_Error( "%s: bad surface number in '%s'\n", __func__, mod->name );
|
||||
out[i] = mod->surfaces + *in;
|
||||
if( in[i] < 0 || in[i] >= mod->numsurfaces )
|
||||
Host_Error( "%s: bad surface number %i at %i (max %i) in '%s'\n", __func__, in[i], i, mod->numsurfaces, mod->name );
|
||||
out[i] = mod->surfaces + in[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dmarkface_t *in = bmod->markfaces;
|
||||
const dmarkface_t *in = bmod->markfaces;
|
||||
|
||||
for( i = 0; i < bmod->nummarkfaces; i++, in++ )
|
||||
for( i = 0; i < bmod->nummarkfaces; i++ )
|
||||
{
|
||||
if( *in < 0 || *in >= mod->numsurfaces )
|
||||
Host_Error( "%s: bad surface number in '%s'\n", __func__, mod->name );
|
||||
out[i] = mod->surfaces + *in;
|
||||
// NOTE: some of the buggy compilers have written a broken BSP file
|
||||
// with marksurface pointing at negative surface, for example darkf6.bsp
|
||||
// and darkf26.bsp in darkfuture mod. GoldSrc straight up writes
|
||||
// invalid pointer to a surface. Try to fix up these cases...
|
||||
if( mod->numsurfaces <= INT16_MAX && (int16_t)in[i] < 0 )
|
||||
{
|
||||
Con_Printf( S_WARN "%s: fixing up bad surface number %i at %i (max %i) in '%s'\n", __func__, in[i], i, mod->numsurfaces, mod->name );
|
||||
out[i] = mod->surfaces;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( in[i] < 0 || in[i] >= mod->numsurfaces )
|
||||
Host_Error( "%s: bad surface number %i at %i (max %i) in '%s'\n", __func__, in[i], i, mod->numsurfaces, mod->name );
|
||||
out[i] = mod->surfaces + in[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2309,9 +2312,9 @@ static void Mod_LoadTextureData( model_t *mod, dbspmodel_t *bmod, int textureInd
|
||||
}
|
||||
|
||||
// Try WAD texture (force while r_wadtextures is 1)
|
||||
if( !texture->gl_texturenum && (( r_wadtextures.value && bmod->wadlist.count > 0 ) || mipTex->offsets[0] <= 0 ))
|
||||
if( !texture->gl_texturenum && (( r_wadtextures.value && world.wadlist.count > 0 ) || mipTex->offsets[0] <= 0 ))
|
||||
{
|
||||
int wadIndex = Mod_FindTextureInWadList( &bmod->wadlist, mipTex->name, texpath, sizeof( texpath ));
|
||||
int wadIndex = Mod_FindTextureInWadList( &world.wadlist, mipTex->name, texpath, sizeof( texpath ));
|
||||
|
||||
if( wadIndex >= 0 )
|
||||
{
|
||||
@@ -2319,7 +2322,7 @@ static void Mod_LoadTextureData( model_t *mod, dbspmodel_t *bmod, int textureInd
|
||||
if( !Host_IsDedicated( ))
|
||||
texture->gl_texturenum = ref.dllFuncs.GL_LoadTexture( texpath, NULL, 0, txFlags );
|
||||
#endif // !XASH_DEDICATED
|
||||
bmod->wadlist.wadusage[wadIndex]++;
|
||||
world.wadlist.wadusage[wadIndex]++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2377,12 +2380,12 @@ static void Mod_LoadTextureData( model_t *mod, dbspmodel_t *bmod, int textureInd
|
||||
// doesn't exist there. The original texture is already loaded, but cannot be modified.
|
||||
// Instead, load the original texture again and convert it to luma.
|
||||
|
||||
wadIndex = Mod_FindTextureInWadList( &bmod->wadlist, texture->name, texpath, sizeof( texpath ));
|
||||
wadIndex = Mod_FindTextureInWadList( &world.wadlist, texture->name, texpath, sizeof( texpath ));
|
||||
|
||||
if( wadIndex >= 0 )
|
||||
{
|
||||
src = FS_LoadFile( texpath, &srcSize, false );
|
||||
bmod->wadlist.wadusage[wadIndex]++;
|
||||
world.wadlist.wadusage[wadIndex]++;
|
||||
}
|
||||
|
||||
// OK, loading it from wad or hi-res version
|
||||
@@ -3415,18 +3418,14 @@ static qboolean Mod_LoadBmodelLumps( model_t *mod, const byte *mod_base, qboolea
|
||||
Mod_CalcPHS( mod );
|
||||
}
|
||||
|
||||
for( i = 0; i < bmod->wadlist.count; i++ )
|
||||
for( i = 0; i < world.wadlist.count; i++ )
|
||||
{
|
||||
string wadname;
|
||||
|
||||
if( !bmod->wadlist.wadusage[i] )
|
||||
if( !world.wadlist.wadusage[i] )
|
||||
continue;
|
||||
|
||||
Q_snprintf( wadname, sizeof( wadname ), "%s.wad", bmod->wadlist.wadnames[i] );
|
||||
|
||||
// a1ba: automatically precache used wad files so client will download it
|
||||
if( SV_Active( ))
|
||||
SV_GenericIndex( wadname );
|
||||
Q_snprintf( wadname, sizeof( wadname ), "%s.wad", world.wadlist.wadnames[i] );
|
||||
|
||||
if( !wadlist_warn )
|
||||
{
|
||||
|
||||
@@ -83,6 +83,12 @@ typedef struct
|
||||
uint num_polys;
|
||||
} hull_model_t;
|
||||
|
||||
typedef struct wadlist_s
|
||||
{
|
||||
char wadnames[MAX_MAP_WADS][32];
|
||||
int wadusage[MAX_MAP_WADS];
|
||||
int count;
|
||||
} wadlist_t;
|
||||
|
||||
typedef struct world_static_s
|
||||
{
|
||||
@@ -119,6 +125,8 @@ typedef struct world_static_s
|
||||
// Potentially Hearable Set
|
||||
byte *compressed_phs;
|
||||
size_t *phsofs;
|
||||
|
||||
wadlist_t wadlist;
|
||||
} world_static_t;
|
||||
|
||||
#ifndef REF_DLL
|
||||
|
||||
@@ -988,7 +988,7 @@ compare fields by offsets
|
||||
assume from and to is valid
|
||||
=====================
|
||||
*/
|
||||
static qboolean Delta_CompareField( delta_t *pField, void *from, void *to, double timebase )
|
||||
static qboolean Delta_CompareField( delta_t *pField, const void *from, const void *to )
|
||||
{
|
||||
int signbit = ( pField->flags & DT_SIGNED ) ? 1 : 0;
|
||||
float val_a, val_b;
|
||||
@@ -1109,7 +1109,7 @@ Delta_TestBaseline
|
||||
compare baselines to find optimal
|
||||
=====================
|
||||
*/
|
||||
int Delta_TestBaseline( entity_state_t *from, entity_state_t *to, qboolean player, double timebase )
|
||||
int Delta_TestBaseline( const entity_state_t *from, const entity_state_t *to, qboolean player, double timebase )
|
||||
{
|
||||
delta_info_t *dt = NULL;
|
||||
delta_t *pField;
|
||||
@@ -1145,7 +1145,7 @@ int Delta_TestBaseline( entity_state_t *from, entity_state_t *to, qboolean playe
|
||||
// flag about field change (sets always)
|
||||
countBits++;
|
||||
|
||||
if( !Delta_CompareField( pField, from, to, timebase ))
|
||||
if( !Delta_CompareField( pField, from, to ))
|
||||
{
|
||||
// strings are handled differently
|
||||
if( FBitSet( pField->flags, DT_STRING ))
|
||||
@@ -1166,7 +1166,7 @@ write fields by offsets
|
||||
assume from and to is valid
|
||||
=====================
|
||||
*/
|
||||
static qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase )
|
||||
static qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, const void *from, const void *to, double timebase )
|
||||
{
|
||||
int signbit = FBitSet( pField->flags, DT_SIGNED ) ? 1 : 0;
|
||||
float flValue, flAngle;
|
||||
@@ -1174,7 +1174,7 @@ static qboolean Delta_WriteField( sizebuf_t *msg, delta_t *pField, void *from, v
|
||||
int dt;
|
||||
const char *pStr;
|
||||
|
||||
if( Delta_CompareField( pField, from, to, timebase ))
|
||||
if( Delta_CompareField( pField, from, to ))
|
||||
{
|
||||
MSG_WriteOneBit( msg, 0 ); // unchanged
|
||||
return false;
|
||||
@@ -1264,7 +1264,7 @@ Delta_CopyField
|
||||
|
||||
====================
|
||||
*/
|
||||
static void Delta_CopyField( delta_t *pField, void *from, void *to, double timebase )
|
||||
static void Delta_CopyField( delta_t *pField, const void *from, void *to, double timebase )
|
||||
{
|
||||
qboolean bSigned = FBitSet( pField->flags, DT_SIGNED );
|
||||
uint8_t *to_field = (uint8_t *)to + pField->offset;
|
||||
@@ -1313,7 +1313,7 @@ read fields by offsets
|
||||
assume 'from' and 'to' is valid
|
||||
=====================
|
||||
*/
|
||||
static qboolean Delta_ReadField( sizebuf_t *msg, delta_t *pField, void *from, void *to, double timebase )
|
||||
static qboolean Delta_ReadField( sizebuf_t *msg, delta_t *pField, const void *from, void *to, double timebase )
|
||||
{
|
||||
qboolean bSigned = ( pField->flags & DT_SIGNED ) ? true : false;
|
||||
float flValue, flAngle, flTime;
|
||||
@@ -1425,7 +1425,7 @@ usercmd_t communication
|
||||
MSG_WriteDeltaUsercmd
|
||||
=====================
|
||||
*/
|
||||
void MSG_WriteDeltaUsercmd( sizebuf_t *msg, usercmd_t *from, usercmd_t *to )
|
||||
void MSG_WriteDeltaUsercmd( sizebuf_t *msg, const usercmd_t *from, const usercmd_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1452,7 +1452,7 @@ void MSG_WriteDeltaUsercmd( sizebuf_t *msg, usercmd_t *from, usercmd_t *to )
|
||||
MSG_ReadDeltaUsercmd
|
||||
=====================
|
||||
*/
|
||||
void MSG_ReadDeltaUsercmd( sizebuf_t *msg, usercmd_t *from, usercmd_t *to )
|
||||
void MSG_ReadDeltaUsercmd( sizebuf_t *msg, const usercmd_t *from, usercmd_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1487,7 +1487,7 @@ event_args_t communication
|
||||
MSG_WriteDeltaEvent
|
||||
=====================
|
||||
*/
|
||||
void MSG_WriteDeltaEvent( sizebuf_t *msg, event_args_t *from, event_args_t *to )
|
||||
void MSG_WriteDeltaEvent( sizebuf_t *msg, const event_args_t *from, const event_args_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1514,7 +1514,7 @@ void MSG_WriteDeltaEvent( sizebuf_t *msg, event_args_t *from, event_args_t *to )
|
||||
MSG_ReadDeltaEvent
|
||||
=====================
|
||||
*/
|
||||
void MSG_ReadDeltaEvent( sizebuf_t *msg, event_args_t *from, event_args_t *to )
|
||||
void MSG_ReadDeltaEvent( sizebuf_t *msg, const event_args_t *from, event_args_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1542,7 +1542,7 @@ movevars_t communication
|
||||
|
||||
=============================================================================
|
||||
*/
|
||||
qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, movevars_t *from, movevars_t *to )
|
||||
qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, const movevars_t *from, const movevars_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1578,7 +1578,7 @@ qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, movevars_t *from, movevars_t *t
|
||||
return true;
|
||||
}
|
||||
|
||||
void MSG_ReadDeltaMovevars( sizebuf_t *msg, movevars_t *from, movevars_t *to )
|
||||
void MSG_ReadDeltaMovevars( sizebuf_t *msg, const movevars_t *from, movevars_t *to )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1614,7 +1614,7 @@ Writes current client data only for local client
|
||||
Other clients can grab the client state from entity_state_t
|
||||
==================
|
||||
*/
|
||||
void MSG_WriteClientData( sizebuf_t *msg, clientdata_t *from, clientdata_t *to, double timebase )
|
||||
void MSG_WriteClientData( sizebuf_t *msg, const clientdata_t *from, const clientdata_t *to, double timebase )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1654,7 +1654,7 @@ MSG_ReadClientData
|
||||
Read the clientdata
|
||||
==================
|
||||
*/
|
||||
void MSG_ReadClientData( sizebuf_t *msg, clientdata_t *from, clientdata_t *to, double timebase )
|
||||
void MSG_ReadClientData( sizebuf_t *msg, const clientdata_t *from, clientdata_t *to, double timebase )
|
||||
{
|
||||
#if !XASH_DEDICATED
|
||||
delta_t *pField;
|
||||
@@ -1695,7 +1695,7 @@ Writes current client data only for local client
|
||||
Other clients can grab the client state from entity_state_t
|
||||
==================
|
||||
*/
|
||||
void MSG_WriteWeaponData( sizebuf_t *msg, weapon_data_t *from, weapon_data_t *to, double timebase, int index )
|
||||
void MSG_WriteWeaponData( sizebuf_t *msg, const weapon_data_t *from, const weapon_data_t *to, double timebase, int index )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1734,7 +1734,7 @@ MSG_ReadWeaponData
|
||||
Read the clientdata
|
||||
==================
|
||||
*/
|
||||
void MSG_ReadWeaponData( sizebuf_t *msg, weapon_data_t *from, weapon_data_t *to, double timebase )
|
||||
void MSG_ReadWeaponData( sizebuf_t *msg, const weapon_data_t *from, weapon_data_t *to, double timebase )
|
||||
{
|
||||
delta_t *pField;
|
||||
delta_info_t *dt;
|
||||
@@ -1771,7 +1771,7 @@ If force is not set, then nothing at all will be generated if the entity is
|
||||
identical, under the assumption that the in-order delta code will catch it.
|
||||
==================
|
||||
*/
|
||||
void MSG_WriteDeltaEntity( entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, int delta_type, double timebase, int baseline )
|
||||
void MSG_WriteDeltaEntity( const entity_state_t *from, const entity_state_t *to, sizebuf_t *msg, qboolean force, int delta_type, double timebase, int baseline )
|
||||
{
|
||||
delta_info_t *dt = NULL;
|
||||
delta_t *pField;
|
||||
@@ -1873,7 +1873,7 @@ If the delta removes the entity, entity_state_t->number will be set to MAX_EDICT
|
||||
Can go from either a baseline or a previous packet_entity
|
||||
==================
|
||||
*/
|
||||
qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, entity_state_t *from, entity_state_t *to, int number, int delta_type, double timebase )
|
||||
qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, const entity_state_t *from, entity_state_t *to, int number, int delta_type, double timebase )
|
||||
{
|
||||
#if !XASH_DEDICATED
|
||||
delta_info_t *dt = NULL;
|
||||
|
||||
@@ -96,18 +96,18 @@ struct event_args_s;
|
||||
struct movevars_s;
|
||||
struct clientdata_s;
|
||||
struct weapon_data_s;
|
||||
void MSG_WriteDeltaUsercmd( sizebuf_t *msg, struct usercmd_s *from, struct usercmd_s *to );
|
||||
void MSG_ReadDeltaUsercmd( sizebuf_t *msg, struct usercmd_s *from, struct usercmd_s *to );
|
||||
void MSG_WriteDeltaEvent( sizebuf_t *msg, struct event_args_s *from, struct event_args_s *to );
|
||||
void MSG_ReadDeltaEvent( sizebuf_t *msg, struct event_args_s *from, struct event_args_s *to );
|
||||
qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, struct movevars_s *from, struct movevars_s *to );
|
||||
void MSG_ReadDeltaMovevars( sizebuf_t *msg, struct movevars_s *from, struct movevars_s *to );
|
||||
void MSG_WriteClientData( sizebuf_t *msg, struct clientdata_s *from, struct clientdata_s *to, double timebase );
|
||||
void MSG_ReadClientData( sizebuf_t *msg, struct clientdata_s *from, struct clientdata_s *to, double timebase );
|
||||
void MSG_WriteWeaponData( sizebuf_t *msg, struct weapon_data_s *from, struct weapon_data_s *to, double timebase, int index );
|
||||
void MSG_ReadWeaponData( sizebuf_t *msg, struct weapon_data_s *from, struct weapon_data_s *to, double timebase );
|
||||
void MSG_WriteDeltaEntity( struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, qboolean force, int type, double timebase, int ofs );
|
||||
qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, struct entity_state_s *from, struct entity_state_s *to, int num, int type, double timebase );
|
||||
int Delta_TestBaseline( struct entity_state_s *from, struct entity_state_s *to, qboolean player, double timebase );
|
||||
void MSG_WriteDeltaUsercmd( sizebuf_t *msg, const struct usercmd_s *from, const struct usercmd_s *to );
|
||||
void MSG_ReadDeltaUsercmd( sizebuf_t *msg, const struct usercmd_s *from, struct usercmd_s *to );
|
||||
void MSG_WriteDeltaEvent( sizebuf_t *msg, const struct event_args_s *from, const struct event_args_s *to );
|
||||
void MSG_ReadDeltaEvent( sizebuf_t *msg, const struct event_args_s *from, struct event_args_s *to );
|
||||
qboolean MSG_WriteDeltaMovevars( sizebuf_t *msg, const struct movevars_s *from, const struct movevars_s *to );
|
||||
void MSG_ReadDeltaMovevars( sizebuf_t *msg, const struct movevars_s *from, struct movevars_s *to );
|
||||
void MSG_WriteClientData( sizebuf_t *msg, const struct clientdata_s *from, const struct clientdata_s *to, double timebase );
|
||||
void MSG_ReadClientData( sizebuf_t *msg, const struct clientdata_s *from, struct clientdata_s *to, double timebase );
|
||||
void MSG_WriteWeaponData( sizebuf_t *msg, const struct weapon_data_s *from, const struct weapon_data_s *to, double timebase, int index );
|
||||
void MSG_ReadWeaponData( sizebuf_t *msg, const struct weapon_data_s *from, struct weapon_data_s *to, double timebase );
|
||||
void MSG_WriteDeltaEntity( const struct entity_state_s *from, const struct entity_state_s *to, sizebuf_t *msg, qboolean force, int type, double timebase, int ofs );
|
||||
qboolean MSG_ReadDeltaEntity( sizebuf_t *msg, const struct entity_state_s *from, struct entity_state_s *to, int num, int type, double timebase );
|
||||
int Delta_TestBaseline( const struct entity_state_s *from, const struct entity_state_s *to, qboolean player, double timebase );
|
||||
|
||||
#endif//NET_ENCODE_H
|
||||
|
||||
@@ -18,16 +18,20 @@ GNU General Public License for more details.
|
||||
#include "netchan.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
#include "ipv6text.h"
|
||||
#if XASH_WIN32
|
||||
#include "platform/win32/net.h"
|
||||
#elif defined XASH_NO_NETWORK
|
||||
|
||||
#if XASH_NO_NETWORK
|
||||
#include "platform/stub/net_stub.h"
|
||||
#elif XASH_WIN32
|
||||
#include "platform/win32/net.h"
|
||||
#elif XASH_PSVITA
|
||||
#include "platform/psvita/net_psvita.h"
|
||||
static const struct in6_addr in6addr_any;
|
||||
#else
|
||||
#include "platform/posix/net.h"
|
||||
#endif
|
||||
#if XASH_PSVITA
|
||||
#include "platform/psvita/net_psvita.h"
|
||||
static const struct in6_addr in6addr_any;
|
||||
|
||||
#if XASH_SDL == 2
|
||||
#include <SDL_thread.h>
|
||||
#endif
|
||||
|
||||
#define NET_USE_FRAGMENTS
|
||||
@@ -115,6 +119,7 @@ static CVAR_DEFINE( net_ipclientport, "ip_clientport", "0", FCVAR_READ_ONLY, "ne
|
||||
static CVAR_DEFINE( net_clientport, "clientport", "0", FCVAR_READ_ONLY, "network default client port" );
|
||||
static CVAR_DEFINE( net_fakelag, "fakelag", "0", FCVAR_PRIVILEGED, "lag all incoming network data (including loopback) by xxx ms." );
|
||||
static CVAR_DEFINE( net_fakeloss, "fakeloss", "0", FCVAR_PRIVILEGED, "act like we dropped the packet this % of the time." );
|
||||
static CVAR_DEFINE_AUTO( net_resolve_debug, "0", FCVAR_PRIVILEGED, "print resolve thread debug messages" );
|
||||
CVAR_DEFINE( net_clockwindow, "clockwindow", "0.5", FCVAR_PRIVILEGED, "timewindow to execute client moves" );
|
||||
|
||||
netadr_t net_local;
|
||||
@@ -126,6 +131,8 @@ static CVAR_DEFINE( net_ip6hostport, "ip6_hostport", "0", FCVAR_READ_ONLY, "netw
|
||||
static CVAR_DEFINE( net_ip6clientport, "ip6_clientport", "0", FCVAR_READ_ONLY, "network ip6 client port" );
|
||||
static CVAR_DEFINE_AUTO( net6_address, "0", FCVAR_PRIVILEGED|FCVAR_READ_ONLY, "contain local IPv6 address of current client" );
|
||||
|
||||
static void NET_ClearLagData( qboolean bClient, qboolean bServer );
|
||||
|
||||
/*
|
||||
====================
|
||||
NET_ErrorString
|
||||
@@ -192,7 +199,7 @@ static char *NET_ErrorString( void )
|
||||
#endif
|
||||
}
|
||||
|
||||
_inline socklen_t NET_SockAddrLen( const struct sockaddr_storage *addr )
|
||||
static inline socklen_t NET_SockAddrLen( const struct sockaddr_storage *addr )
|
||||
{
|
||||
switch ( addr->ss_family )
|
||||
{
|
||||
@@ -205,7 +212,7 @@ _inline socklen_t NET_SockAddrLen( const struct sockaddr_storage *addr )
|
||||
}
|
||||
}
|
||||
|
||||
_inline qboolean NET_IsSocketError( int retval )
|
||||
static inline qboolean NET_IsSocketError( int retval )
|
||||
{
|
||||
#if XASH_WIN32 || XASH_DOS4GW
|
||||
return retval == SOCKET_ERROR ? true : false;
|
||||
@@ -214,7 +221,7 @@ _inline qboolean NET_IsSocketError( int retval )
|
||||
#endif
|
||||
}
|
||||
|
||||
_inline qboolean NET_IsSocketValid( int socket )
|
||||
static inline qboolean NET_IsSocketValid( int socket )
|
||||
{
|
||||
#if XASH_WIN32 || XASH_DOS4GW
|
||||
return socket != INVALID_SOCKET;
|
||||
@@ -249,40 +256,27 @@ static void NET_NetadrToSockadr( netadr_t *a, struct sockaddr_storage *s )
|
||||
|
||||
if( a->type == NA_BROADCAST )
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
s->ss_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = INADDR_BROADCAST;
|
||||
}
|
||||
else if( a->type == NA_IP )
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
s->ss_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = a->ip4;
|
||||
}
|
||||
else if( a->type6 == NA_IP6 )
|
||||
{
|
||||
struct in6_addr ip6;
|
||||
|
||||
NET_NetadrToIP6Bytes( ip6.s6_addr, a );
|
||||
|
||||
if( IN6_IS_ADDR_V4MAPPED( &ip6 ))
|
||||
{
|
||||
((struct sockaddr_in *)s)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)s)->sin_addr.s_addr = *(uint32_t *)(ip6.s6_addr + 12);
|
||||
((struct sockaddr_in *)s)->sin_port = a->port;
|
||||
}
|
||||
else
|
||||
{
|
||||
((struct sockaddr_in6 *)s)->sin6_family = AF_INET6;
|
||||
memcpy( &((struct sockaddr_in6 *)s)->sin6_addr, &ip6, sizeof( struct in6_addr ));
|
||||
((struct sockaddr_in6 *)s)->sin6_port = a->port;
|
||||
}
|
||||
s->ss_family = AF_INET6;
|
||||
((struct sockaddr_in6 *)s)->sin6_port = a->port;
|
||||
NET_NetadrToIP6Bytes(((struct sockaddr_in6 *)s)->sin6_addr.s6_addr, a );
|
||||
}
|
||||
else if( a->type6 == NA_MULTICAST_IP6 )
|
||||
{
|
||||
((struct sockaddr_in6 *)s)->sin6_family = AF_INET6;
|
||||
memcpy(((struct sockaddr_in6 *)s)->sin6_addr.s6_addr, k_ipv6Bytes_LinkLocalAllNodes, sizeof( struct in6_addr ));
|
||||
s->ss_family = AF_INET6;
|
||||
((struct sockaddr_in6 *)s)->sin6_port = a->port;
|
||||
memcpy(((struct sockaddr_in6 *)s)->sin6_addr.s6_addr, k_ipv6Bytes_LinkLocalAllNodes, sizeof( struct in6_addr ));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,13 +295,8 @@ static void NET_SockadrToNetadr( const struct sockaddr_storage *s, netadr_t *a )
|
||||
}
|
||||
else if( s->ss_family == AF_INET6 )
|
||||
{
|
||||
a->type6 = NA_IP6;
|
||||
NET_IP6BytesToNetadr( a, ((struct sockaddr_in6 *)s)->sin6_addr.s6_addr );
|
||||
|
||||
if( IN6_IS_ADDR_V4MAPPED( &((struct sockaddr_in6 *)s)->sin6_addr ))
|
||||
a->type = NA_IP;
|
||||
else
|
||||
a->type6 = NA_IP6;
|
||||
|
||||
a->port = ((struct sockaddr_in6 *)s)->sin6_port;
|
||||
}
|
||||
}
|
||||
@@ -324,6 +313,11 @@ static qboolean NET_GetHostByName( const char *hostname, int family, struct sock
|
||||
struct addrinfo hints;
|
||||
qboolean ret = false;
|
||||
|
||||
#if XASH_NO_IPV6_RESOLVE
|
||||
if( family == AF_INET6 )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
memset( &hints, 0, sizeof( hints ));
|
||||
hints.ai_family = family;
|
||||
|
||||
@@ -346,6 +340,12 @@ static qboolean NET_GetHostByName( const char *hostname, int family, struct sock
|
||||
return ret;
|
||||
#else
|
||||
struct hostent *h;
|
||||
|
||||
#if XASH_NO_IPV6_RESOLVE
|
||||
if( family == AF_INET6 )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if(!( h = gethostbyname( hostname )))
|
||||
return false;
|
||||
|
||||
@@ -363,27 +363,44 @@ static qboolean NET_GetHostByName( const char *hostname, int family, struct sock
|
||||
#ifdef CAN_ASYNC_NS_RESOLVE
|
||||
static void NET_ResolveThread( void );
|
||||
|
||||
#if !XASH_WIN32
|
||||
#if XASH_SDL == 2
|
||||
#define mutex_create( x ) (( x ) = SDL_CreateMutex() )
|
||||
#define mutex_destroy( x ) SDL_DestroyMutex(( x ))
|
||||
#define mutex_lock( x ) SDL_LockMutex(( x ))
|
||||
#define mutex_unlock( x ) SDL_UnlockMutex(( x ))
|
||||
#define create_thread( thread, pfn ) (( thread ) = SDL_CreateThread(( pfn ), "DNS resolver thread", NULL ))
|
||||
#define detach_thread( x ) SDL_DetachThread(( x ))
|
||||
typedef SDL_mutex *mutex_t;
|
||||
typedef SDL_Thread *thread_t;
|
||||
static int NET_ThreadStart( void *ununsed )
|
||||
{
|
||||
NET_ResolveThread();
|
||||
return 0;
|
||||
}
|
||||
#elif !XASH_WIN32
|
||||
#include <pthread.h>
|
||||
#define mutex_lock pthread_mutex_lock
|
||||
#define mutex_unlock pthread_mutex_unlock
|
||||
#define exit_thread( x ) pthread_exit(x)
|
||||
#define create_thread( pfn ) !pthread_create( &nsthread.thread, NULL, (pfn), NULL )
|
||||
#define detach_thread( x ) pthread_detach(x)
|
||||
#define mutex_t pthread_mutex_t
|
||||
#define thread_t pthread_t
|
||||
#define mutex_create( x ) pthread_mutex_init( &( x ), NULL )
|
||||
#define mutex_destroy( x ) pthread_mutex_destroy( &( x ))
|
||||
#define mutex_lock( x ) pthread_mutex_lock( &( x ))
|
||||
#define mutex_unlock( x ) pthread_mutex_unlock( &( x ))
|
||||
#define create_thread( thread, pfn ) !pthread_create( &( thread ), NULL, ( pfn ), NULL )
|
||||
#define detach_thread( x ) pthread_detach( x )
|
||||
typedef pthread_mutex_t mutex_t;
|
||||
typedef pthread_t thread_t;
|
||||
static void *NET_ThreadStart( void *unused )
|
||||
{
|
||||
NET_ResolveThread();
|
||||
return NULL;
|
||||
}
|
||||
#else // WIN32
|
||||
#define mutex_lock EnterCriticalSection
|
||||
#define mutex_unlock LeaveCriticalSection
|
||||
#define detach_thread( x ) CloseHandle(x)
|
||||
#define create_thread( pfn ) ( nsthread.thread = CreateThread( NULL, 0, pfn, NULL, 0, NULL ))
|
||||
#define mutex_t CRITICAL_SECTION
|
||||
#define thread_t HANDLE
|
||||
#define mutex_create( x ) InitializeCriticalSection( &( x ))
|
||||
#define mutex_destroy( x ) DeleteCriticalSection( &( x ))
|
||||
#define mutex_lock( x ) EnterCriticalSection( &( x ))
|
||||
#define mutex_unlock( x ) LeaveCriticalSection( &( x ))
|
||||
#define create_thread( thread, pfn ) (( thread ) = CreateThread( NULL, 0, ( pfn ), NULL, 0, NULL ))
|
||||
#define detach_thread( x ) CloseHandle(( x ))
|
||||
typedef CRITICAL_SECTION mutex_t;
|
||||
typedef HANDLE thread_t;
|
||||
DWORD WINAPI NET_ThreadStart( LPVOID unused )
|
||||
{
|
||||
NET_ResolveThread();
|
||||
@@ -392,38 +409,42 @@ DWORD WINAPI NET_ThreadStart( LPVOID unused )
|
||||
}
|
||||
#endif // !_WIN32
|
||||
|
||||
#ifdef DEBUG_RESOLVE
|
||||
#define RESOLVE_DBG(x) Sys_PrintLog(x)
|
||||
#else
|
||||
#define RESOLVE_DBG(x)
|
||||
#endif // DEBUG_RESOLVE
|
||||
#define RESOLVE_DBG( x ) do { if( net_resolve_debug.value ) Sys_PrintLog(( x )); } while( 0 )
|
||||
|
||||
static struct nsthread_s
|
||||
{
|
||||
mutex_t mutexns;
|
||||
mutex_t mutexres;
|
||||
mutex_t mutexns;
|
||||
mutex_t mutexres;
|
||||
thread_t thread;
|
||||
int result;
|
||||
string hostname;
|
||||
int family;
|
||||
int result;
|
||||
string hostname;
|
||||
int family;
|
||||
struct sockaddr_storage addr;
|
||||
qboolean busy;
|
||||
} nsthread
|
||||
#if !XASH_WIN32
|
||||
= { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER }
|
||||
#endif
|
||||
;
|
||||
} nsthread;
|
||||
|
||||
static void NET_InitializeCriticalSections( void )
|
||||
{
|
||||
net.threads_initialized = true;
|
||||
#if XASH_WIN32
|
||||
InitializeCriticalSection( &nsthread.mutexns );
|
||||
InitializeCriticalSection( &nsthread.mutexres );
|
||||
#endif
|
||||
|
||||
mutex_create( nsthread.mutexns );
|
||||
mutex_create( nsthread.mutexres );
|
||||
}
|
||||
|
||||
void NET_ResolveThread( void )
|
||||
static void NET_DeleteCriticalSections( void )
|
||||
{
|
||||
if( net.threads_initialized )
|
||||
{
|
||||
mutex_destroy( nsthread.mutexns );
|
||||
mutex_destroy( nsthread.mutexres );
|
||||
|
||||
net.threads_initialized = false;
|
||||
}
|
||||
|
||||
memset( &nsthread, 0, sizeof( nsthread ));
|
||||
}
|
||||
|
||||
static void NET_ResolveThread( void )
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
qboolean res;
|
||||
@@ -440,12 +461,12 @@ void NET_ResolveThread( void )
|
||||
RESOLVE_DBG( "[resolve thread] success\n" );
|
||||
else
|
||||
RESOLVE_DBG( "[resolve thread] failed\n" );
|
||||
mutex_lock( &nsthread.mutexres );
|
||||
mutex_lock( nsthread.mutexres );
|
||||
nsthread.addr = addr;
|
||||
nsthread.busy = false;
|
||||
nsthread.result = res ? NET_EAI_OK : NET_EAI_NONAME;
|
||||
RESOLVE_DBG( "[resolve thread] returning result\n" );
|
||||
mutex_unlock( &nsthread.mutexres );
|
||||
mutex_unlock( nsthread.mutexres );
|
||||
RESOLVE_DBG( "[resolve thread] exiting thread\n" );
|
||||
}
|
||||
#endif // CAN_ASYNC_NS_RESOLVE
|
||||
@@ -510,11 +531,11 @@ static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_stor
|
||||
#ifdef CAN_ASYNC_NS_RESOLVE
|
||||
if( net.threads_initialized && nonblocking )
|
||||
{
|
||||
mutex_lock( &nsthread.mutexres );
|
||||
mutex_lock( nsthread.mutexres );
|
||||
|
||||
if( nsthread.busy )
|
||||
{
|
||||
mutex_unlock( &nsthread.mutexres );
|
||||
mutex_unlock( nsthread.mutexres );
|
||||
return NET_EAI_AGAIN;
|
||||
}
|
||||
|
||||
@@ -535,28 +556,24 @@ static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_stor
|
||||
Q_strncpy( nsthread.hostname, copy, sizeof( nsthread.hostname ));
|
||||
nsthread.family = family;
|
||||
nsthread.busy = true;
|
||||
mutex_unlock( &nsthread.mutexres );
|
||||
mutex_unlock( nsthread.mutexres );
|
||||
|
||||
if( create_thread( NET_ThreadStart ))
|
||||
if( create_thread( nsthread.thread, NET_ThreadStart ))
|
||||
{
|
||||
asyncfailed = false;
|
||||
return NET_EAI_AGAIN;
|
||||
}
|
||||
else // failed to create thread
|
||||
{
|
||||
Con_Reportf( S_ERROR "%s: failed to create thread!\n", __func__ );
|
||||
nsthread.busy = false;
|
||||
}
|
||||
|
||||
Con_Reportf( S_ERROR "%s: failed to create thread!\n", __func__ );
|
||||
nsthread.busy = false;
|
||||
}
|
||||
|
||||
mutex_unlock( &nsthread.mutexres );
|
||||
mutex_unlock( nsthread.mutexres );
|
||||
}
|
||||
#endif // CAN_ASYNC_NS_RESOLVE
|
||||
|
||||
if( asyncfailed )
|
||||
{
|
||||
ret = NET_GetHostByName( copy, family, &temp );
|
||||
}
|
||||
|
||||
if( !ret )
|
||||
{
|
||||
@@ -570,16 +587,9 @@ static net_gai_state_t NET_StringToSockaddr( const char *s, struct sockaddr_stor
|
||||
sadr->ss_family = temp.ss_family;
|
||||
|
||||
if( temp.ss_family == AF_INET )
|
||||
{
|
||||
((struct sockaddr_in *)sadr)->sin_addr =
|
||||
((struct sockaddr_in*)&temp)->sin_addr;
|
||||
}
|
||||
((struct sockaddr_in *)sadr)->sin_addr = ((struct sockaddr_in*)&temp)->sin_addr;
|
||||
else if( temp.ss_family == AF_INET6 )
|
||||
{
|
||||
memcpy(&((struct sockaddr_in6 *)sadr)->sin6_addr,
|
||||
&((struct sockaddr_in6*)&temp)->sin6_addr,
|
||||
sizeof( struct in6_addr ));
|
||||
}
|
||||
((struct sockaddr_in6 *)sadr)->sin6_addr = ((struct sockaddr_in6*)&temp)->sin6_addr;
|
||||
}
|
||||
|
||||
return NET_EAI_OK;
|
||||
@@ -1042,19 +1052,20 @@ qboolean NET_StringToAdr( const char *string, netadr_t *adr )
|
||||
return NET_StringToAdrEx( string, adr, AF_UNSPEC );
|
||||
}
|
||||
|
||||
net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr )
|
||||
net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr, qboolean v6only )
|
||||
{
|
||||
struct sockaddr_storage s;
|
||||
net_gai_state_t res;
|
||||
|
||||
memset( adr, 0, sizeof( netadr_t ));
|
||||
|
||||
if( !Q_stricmp( string, "localhost" ) || !Q_stricmp( string, "loopback" ))
|
||||
{
|
||||
adr->type = NA_LOOPBACK;
|
||||
return NET_EAI_OK;
|
||||
}
|
||||
|
||||
res = NET_StringToSockaddr( string, &s, true, AF_UNSPEC );
|
||||
res = NET_StringToSockaddr( string, &s, true, v6only ? AF_INET6 : AF_UNSPEC );
|
||||
|
||||
if( res == NET_EAI_OK )
|
||||
NET_SockadrToNetadr( &s, adr );
|
||||
@@ -1735,7 +1746,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
|
||||
|
||||
if( COM_CheckStringEmpty( net_iface ) && Q_stricmp( net_iface, "localhost" ))
|
||||
NET_StringToSockaddr( net_iface, &addr, false, AF_INET6 );
|
||||
else memcpy(((struct sockaddr_in6 *)&addr)->sin6_addr.s6_addr, &in6addr_any, sizeof( struct in6_addr ));
|
||||
else ((struct sockaddr_in6 *)&addr)->sin6_addr = in6addr_any;
|
||||
|
||||
if( port == PORT_ANY ) ((struct sockaddr_in6 *)&addr)->sin6_port = 0;
|
||||
else ((struct sockaddr_in6 *)&addr)->sin6_port = htons((short)port);
|
||||
@@ -2068,7 +2079,7 @@ NET_ClearLagData
|
||||
clear fakelag list
|
||||
====================
|
||||
*/
|
||||
void NET_ClearLagData( qboolean bClient, qboolean bServer )
|
||||
static void NET_ClearLagData( qboolean bClient, qboolean bServer )
|
||||
{
|
||||
if( bClient ) NET_ClearLaggedList( &net.lagdata[NS_CLIENT] );
|
||||
if( bServer ) NET_ClearLaggedList( &net.lagdata[NS_SERVER] );
|
||||
@@ -2094,6 +2105,7 @@ void NET_Init( void )
|
||||
Cvar_RegisterVariable( &net_clientport );
|
||||
Cvar_RegisterVariable( &net_fakelag );
|
||||
Cvar_RegisterVariable( &net_fakeloss );
|
||||
Cvar_RegisterVariable( &net_resolve_debug );
|
||||
|
||||
Q_snprintf( cmd, sizeof( cmd ), "%i", PORT_SERVER );
|
||||
Cvar_FullSet( "hostport", cmd, FCVAR_READ_ONLY );
|
||||
@@ -2167,6 +2179,11 @@ void NET_Shutdown( void )
|
||||
NET_ClearLagData( true, true );
|
||||
|
||||
NET_Config( false, false );
|
||||
|
||||
#ifdef CAN_ASYNC_NS_RESOLVE
|
||||
NET_DeleteCriticalSections();
|
||||
#endif
|
||||
|
||||
#if XASH_WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
@@ -66,7 +66,7 @@ qboolean NET_IsReservedAdr( netadr_t a );
|
||||
qboolean NET_CompareClassBAdr( const netadr_t a, const netadr_t b );
|
||||
qboolean NET_StringToAdr( const char *string, netadr_t *adr );
|
||||
qboolean NET_StringToFilterAdr( const char *s, netadr_t *adr, uint *prefixlen );
|
||||
net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr );
|
||||
net_gai_state_t NET_StringToAdrNB( const char *string, netadr_t *adr, qboolean v6only );
|
||||
int NET_CompareAdrSort( const void *_a, const void *_b );
|
||||
qboolean NET_CompareAdr( const netadr_t a, const netadr_t b );
|
||||
qboolean NET_CompareBaseAdr( const netadr_t a, const netadr_t b );
|
||||
@@ -74,7 +74,6 @@ qboolean NET_CompareAdrByMask( const netadr_t a, const netadr_t b, uint prefixle
|
||||
qboolean NET_GetPacket( netsrc_t sock, netadr_t *from, byte *data, size_t *length );
|
||||
void NET_SendPacket( netsrc_t sock, size_t length, const void *data, netadr_t to );
|
||||
void NET_SendPacketEx( netsrc_t sock, size_t length, const void *data, netadr_t to, size_t splitsize );
|
||||
void NET_ClearLagData( qboolean bClient, qboolean bServer );
|
||||
void NET_IP6BytesToNetadr( netadr_t *adr, const uint8_t *ip6 );
|
||||
void NET_NetadrToIP6Bytes( uint8_t *ip6, const netadr_t *adr );
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ static void Sound_Reset( void )
|
||||
sound.size = 0;
|
||||
}
|
||||
|
||||
static wavdata_t *SoundPack( void )
|
||||
static MALLOC_LIKE( FS_FreeSound, 1 ) wavdata_t *SoundPack( void )
|
||||
{
|
||||
wavdata_t *pack = Mem_Calloc( host.soundpool, sizeof( wavdata_t ));
|
||||
|
||||
|
||||
@@ -230,13 +230,20 @@ static void Sys_PrintLogfile( const int fd, const char *logtime, const char *msg
|
||||
|
||||
if( p == NULL )
|
||||
{
|
||||
write( fd, msg, Q_strlen( msg ));
|
||||
if( write( fd, msg, Q_strlen( msg )) < 0 )
|
||||
{
|
||||
// don't call engine Msg, might cause recursion
|
||||
fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if( IsColorString( p ))
|
||||
{
|
||||
if( p != msg )
|
||||
write( fd, msg, p - msg );
|
||||
{
|
||||
if( write( fd, msg, p - msg ) < 0 )
|
||||
fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno ));
|
||||
}
|
||||
msg = p + 2;
|
||||
|
||||
if( colorize )
|
||||
@@ -244,7 +251,8 @@ static void Sys_PrintLogfile( const int fd, const char *logtime, const char *msg
|
||||
}
|
||||
else
|
||||
{
|
||||
write( fd, msg, p - msg + 1 );
|
||||
if( write( fd, msg, p - msg + 1 ) < 0 )
|
||||
fprintf( stderr, "%s: write failed: %s\n", __func__, strerror( errno ));
|
||||
msg = p + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ typedef struct enginefuncs_s
|
||||
void (*pfnAngleVectors)( const float *rgflVector, float *forward, float *right, float *up );
|
||||
edict_t* (*pfnCreateEntity)( void );
|
||||
void (*pfnRemoveEntity)( edict_t* e );
|
||||
edict_t* (*pfnCreateNamedEntity)( string_t className );
|
||||
edict_t* (*pfnCreateNamedEntity)( int className );
|
||||
void (*pfnMakeStatic)( edict_t *ent );
|
||||
int (*pfnEntIsOnFloor)( edict_t *e );
|
||||
int (*pfnDropToFloor)( edict_t* e );
|
||||
@@ -168,8 +168,8 @@ typedef struct enginefuncs_s
|
||||
void* (*pfnPvAllocEntPrivateData)( edict_t *pEdict, long cb );
|
||||
void* (*pfnPvEntPrivateData)( edict_t *pEdict );
|
||||
void (*pfnFreeEntPrivateData)( edict_t *pEdict );
|
||||
const char *(*pfnSzFromIndex)( string_t iString );
|
||||
string_t (*pfnAllocString)( const char *szValue );
|
||||
const char *(*pfnSzFromIndex)( int iString );
|
||||
int (*pfnAllocString)( const char *szValue );
|
||||
struct entvars_s *(*pfnGetVarsOfEnt)( edict_t *pEdict );
|
||||
edict_t* (*pfnPEntityOfEntOffset)( int iEntOffset );
|
||||
int (*pfnEntOffsetOfPEntity)( const edict_t *pEdict );
|
||||
|
||||
@@ -18,8 +18,10 @@ GNU General Public License for more details.
|
||||
#define NET_PSVITA_H
|
||||
|
||||
#include <vitasdk.h>
|
||||
#include "platform/posix/net.h"
|
||||
|
||||
/* we're missing IPv6 support; define some trash */
|
||||
#define XASH_NO_IPV6_RESOLVE 1
|
||||
|
||||
#ifndef IN6_IS_ADDR_V4MAPPED
|
||||
#define IN6_IS_ADDR_V4MAPPED( p ) ( 0 )
|
||||
|
||||
@@ -85,8 +85,8 @@ typedef struct entvars_s
|
||||
int modelindex;
|
||||
|
||||
string_t model;
|
||||
string_t viewmodel; // player's viewmodel
|
||||
string_t weaponmodel; // what other players see
|
||||
int viewmodel; // player's viewmodel
|
||||
int weaponmodel; // what other players see
|
||||
|
||||
vec3_t absmin; // BB max translated to world coord
|
||||
vec3_t absmax; // BB max translated to world coord
|
||||
@@ -144,7 +144,7 @@ typedef struct entvars_s
|
||||
int flags;
|
||||
|
||||
int colormap; // lowbyte topcolor, highbyte bottomcolor
|
||||
string_t team;
|
||||
int team;
|
||||
|
||||
float max_health;
|
||||
float teleport_time;
|
||||
|
||||
@@ -389,10 +389,13 @@ typedef struct ref_api_s
|
||||
int (*pfnGetStudioModelInterface)( int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio );
|
||||
|
||||
// memory
|
||||
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
|
||||
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline )
|
||||
WARN_UNUSED_RESULT;
|
||||
void (*_Mem_FreePool)( poolhandle_t *poolptr, const char *filename, int fileline );
|
||||
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
|
||||
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
|
||||
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) WARN_UNUSED_RESULT;
|
||||
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 3 ) WARN_UNUSED_RESULT;
|
||||
void (*_Mem_Free)( void *data, const char *filename, int fileline );
|
||||
|
||||
// library management
|
||||
|
||||
@@ -3000,6 +3000,25 @@ static void *GAME_EXPORT pfnPvEntPrivateData( edict_t *pEdict )
|
||||
}
|
||||
|
||||
|
||||
#ifdef XASH_64BIT
|
||||
static struct str64_s
|
||||
{
|
||||
size_t maxstringarray;
|
||||
qboolean allowdup;
|
||||
char *staticstringarray;
|
||||
char *pstringarray;
|
||||
char *pstringarraystatic;
|
||||
char *pstringbase;
|
||||
char *poldstringbase;
|
||||
char *plast;
|
||||
qboolean dynamic;
|
||||
size_t maxalloc;
|
||||
size_t numdups;
|
||||
size_t numoverflows;
|
||||
size_t totalalloc;
|
||||
} str64;
|
||||
#endif
|
||||
|
||||
/*
|
||||
==================
|
||||
SV_EmptyStringPool
|
||||
@@ -3009,7 +3028,17 @@ Free strings on server stop. Reset string pointer on 64 bits
|
||||
*/
|
||||
void SV_EmptyStringPool( void )
|
||||
{
|
||||
#ifdef XASH_64BIT
|
||||
if( str64.dynamic ) // switch only after array fill (more space for multiplayer games)
|
||||
str64.pstringbase = str64.pstringarray;
|
||||
else
|
||||
{
|
||||
str64.pstringbase = str64.poldstringbase = str64.pstringarraystatic;
|
||||
str64.plast = str64.pstringbase + 1;
|
||||
}
|
||||
#else
|
||||
Mem_EmptyPool( svgame.stringspool );
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3023,8 +3052,23 @@ this helps not to lose strings that belongs to static game part
|
||||
*/
|
||||
void SV_SetStringArrayMode( qboolean dynamic )
|
||||
{
|
||||
#ifdef XASH_64BIT
|
||||
Con_Reportf( "%s(%d) %d\n", __func__, dynamic, str64.dynamic );
|
||||
|
||||
if( dynamic == str64.dynamic )
|
||||
return;
|
||||
|
||||
str64.dynamic = dynamic;
|
||||
|
||||
SV_EmptyStringPool();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if XASH_AMD64 && XASH_LINUX && !XASH_ANDROID
|
||||
#define USE_MMAP
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
==================
|
||||
SV_AllocStringPool
|
||||
@@ -3037,13 +3081,104 @@ this case need patched game dll with MAKE_STRING checking ptrdiff size
|
||||
*/
|
||||
static void SV_AllocStringPool( void )
|
||||
{
|
||||
#ifdef XASH_64BIT
|
||||
void *ptr = NULL;
|
||||
string lenstr;
|
||||
|
||||
Con_Reportf( "%s()\n", __func__ );
|
||||
if( Sys_GetParmFromCmdLine( "-str64alloc", lenstr ) )
|
||||
{
|
||||
str64.maxstringarray = Q_atoi( lenstr );
|
||||
if( str64.maxstringarray < 1024 || str64.maxstringarray >= INT_MAX )
|
||||
str64.maxstringarray = 65536;
|
||||
}
|
||||
else str64.maxstringarray = 65536;
|
||||
if( Sys_CheckParm( "-str64dup" ) )
|
||||
str64.allowdup = true;
|
||||
|
||||
#ifdef USE_MMAP
|
||||
{
|
||||
uint flags;
|
||||
size_t pagesize = sysconf( _SC_PAGESIZE );
|
||||
int arrlen = (str64.maxstringarray * 2) & ~(pagesize - 1);
|
||||
void *base = svgame.dllFuncs.pfnGameInit;
|
||||
void *start = svgame.hInstance - arrlen;
|
||||
|
||||
#if defined(MAP_ANON)
|
||||
flags = MAP_ANON | MAP_PRIVATE;
|
||||
#elif defined(MAP_ANONYMOUS)
|
||||
flags = MAP_ANONYMOUS | MAP_PRIVATE;
|
||||
#endif
|
||||
|
||||
while( start - base > INT_MIN )
|
||||
{
|
||||
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
|
||||
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
|
||||
{
|
||||
ptr = mapptr;
|
||||
break;
|
||||
}
|
||||
if( mapptr ) munmap( mapptr, arrlen );
|
||||
start -= arrlen;
|
||||
}
|
||||
|
||||
if( !ptr )
|
||||
{
|
||||
start = base;
|
||||
while( start - base < INT_MAX )
|
||||
{
|
||||
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
|
||||
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
|
||||
{
|
||||
ptr = mapptr;
|
||||
break;
|
||||
}
|
||||
if( mapptr ) munmap( mapptr, arrlen );
|
||||
start += arrlen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( ptr )
|
||||
{
|
||||
Con_Reportf( "%s: Allocated string array near the server library: %p %p\n", __func__, base, ptr );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Con_Reportf( "%s: Failed to allocate string array near the server library!\n", __func__ );
|
||||
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
|
||||
}
|
||||
}
|
||||
#else
|
||||
ptr = str64.staticstringarray = Mem_Calloc( host.mempool, str64.maxstringarray * 2 );
|
||||
#endif
|
||||
|
||||
str64.pstringarray = ptr;
|
||||
str64.pstringarraystatic = (byte*)ptr + str64.maxstringarray;
|
||||
str64.pstringbase = str64.poldstringbase = ptr;
|
||||
str64.plast = (byte*)ptr + 1;
|
||||
svgame.globals->pStringBase = ptr;
|
||||
#else
|
||||
svgame.stringspool = Mem_AllocPool( "Server Strings" );
|
||||
svgame.globals->pStringBase = "";
|
||||
#endif
|
||||
}
|
||||
|
||||
static void SV_FreeStringPool( void )
|
||||
{
|
||||
#ifdef XASH_64BIT
|
||||
Con_Reportf( "%s()\n", __func__ );
|
||||
|
||||
#ifdef USE_MMAP
|
||||
if( str64.pstringarray != str64.staticstringarray )
|
||||
munmap( str64.pstringarray, (str64.maxstringarray * 2) & ~(sysconf( _SC_PAGESIZE ) - 1) );
|
||||
else
|
||||
#endif
|
||||
Mem_Free( str64.staticstringarray );
|
||||
#else
|
||||
Mem_FreePool( &svgame.stringspool );
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3114,6 +3249,9 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
|
||||
{
|
||||
char *newString = NULL;
|
||||
uint len;
|
||||
#ifdef XASH_64BIT
|
||||
int cmp;
|
||||
#endif
|
||||
|
||||
if( svgame.physFuncs.pfnAllocString != NULL )
|
||||
{
|
||||
@@ -3129,16 +3267,67 @@ string_t GAME_EXPORT SV_AllocString( const char *szValue )
|
||||
return i;
|
||||
}
|
||||
|
||||
#ifdef XASH_64BIT
|
||||
cmp = 1;
|
||||
|
||||
if( !str64.allowdup )
|
||||
{
|
||||
for( newString = str64.poldstringbase + 1;
|
||||
newString < str64.plast && ( cmp = Q_strcmp( newString, szValue ) );
|
||||
newString += Q_strlen( newString ) + 1 );
|
||||
}
|
||||
|
||||
if( cmp )
|
||||
{
|
||||
uint len = SV_ProcessString( NULL, szValue );
|
||||
|
||||
if( str64.plast - str64.poldstringbase + len + 1 > str64.maxstringarray )
|
||||
{
|
||||
str64.plast = str64.pstringbase + 1;
|
||||
str64.poldstringbase = str64.pstringbase;
|
||||
str64.numoverflows++;
|
||||
}
|
||||
|
||||
//MsgDev( D_NOTE, "SV_AllocString: %ld %s\n", str64.plast - svgame.globals->pStringBase, szValue );
|
||||
SV_ProcessString( str64.plast, szValue );
|
||||
str64.totalalloc += len;
|
||||
|
||||
newString = str64.plast;
|
||||
str64.plast += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
str64.numdups++;
|
||||
//MsgDev( D_NOTE, "SV_AllocString: dup %ld %s\n", newString - svgame.globals->pStringBase, szValue );
|
||||
}
|
||||
|
||||
if( newString - str64.pstringarray > str64.maxalloc )
|
||||
str64.maxalloc = newString - str64.pstringarray;
|
||||
|
||||
return newString - svgame.globals->pStringBase;
|
||||
#else
|
||||
len = SV_ProcessString( NULL, szValue );
|
||||
newString = Mem_Malloc( svgame.stringspool, len );
|
||||
SV_ProcessString( newString, szValue );
|
||||
|
||||
return newString - svgame.globals->pStringBase;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SV_PrintStr64Stats_f( void )
|
||||
{
|
||||
#ifdef XASH_64BIT
|
||||
Con_Printf( "====================\n" );
|
||||
Con_Printf( "64 bit string pool statistics\n" );
|
||||
Con_Printf( "====================\n" );
|
||||
Con_Printf( "string array size: %lu\n", str64.maxstringarray );
|
||||
Con_Printf( "total alloc %lu\n", str64.totalalloc );
|
||||
Con_Printf( "maximum array usage: %lu\n", str64.maxalloc );
|
||||
Con_Printf( "overflow counter: %lu\n", str64.numoverflows );
|
||||
Con_Printf( "dup string counter: %lu\n", str64.numdups );
|
||||
#else
|
||||
Con_Printf( "Not implemented\n" );
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3152,8 +3341,17 @@ string_t SV_MakeString( const char *szValue )
|
||||
{
|
||||
if( svgame.physFuncs.pfnMakeString != NULL )
|
||||
return svgame.physFuncs.pfnMakeString( szValue );
|
||||
|
||||
#ifdef XASH_64BIT
|
||||
{
|
||||
long long ptrdiff = szValue - svgame.globals->pStringBase;
|
||||
if( ptrdiff > INT_MAX || ptrdiff < INT_MIN )
|
||||
return SV_AllocString(szValue);
|
||||
else
|
||||
return (int)ptrdiff;
|
||||
}
|
||||
#else
|
||||
return szValue - svgame.globals->pStringBase;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4917,6 +5115,8 @@ void SV_SpawnEntities( const char *mapname )
|
||||
|
||||
void SV_UnloadProgs( void )
|
||||
{
|
||||
pending_cvar_t *pending_cvars_list;
|
||||
|
||||
if( !svgame.hInstance )
|
||||
return;
|
||||
|
||||
@@ -4926,6 +5126,8 @@ void SV_UnloadProgs( void )
|
||||
/// SV_UnloadProgs will be disabled
|
||||
//Mod_ClearUserData ();
|
||||
|
||||
pending_cvars_list = Cvar_PrepareToUnlink( FCVAR_EXTDLL );
|
||||
|
||||
if( svgame.dllFuncs2.pfnGameShutdown != NULL )
|
||||
svgame.dllFuncs2.pfnGameShutdown ();
|
||||
|
||||
@@ -4943,7 +5145,7 @@ void SV_UnloadProgs( void )
|
||||
|
||||
// must unlink all game cvars,
|
||||
// before pointers on them will be lost...
|
||||
Cvar_Unlink( FCVAR_EXTDLL );
|
||||
Cvar_UnlinkPendingCvars( pending_cvars_list );
|
||||
Cmd_Unlink( CMD_SERVERDLL );
|
||||
|
||||
SV_FreeStringPool();
|
||||
|
||||
@@ -363,6 +363,7 @@ loads external resource list
|
||||
static void SV_CreateGenericResources( void )
|
||||
{
|
||||
string filename;
|
||||
int i;
|
||||
|
||||
Q_strncpy( filename, sv.model_precache[1], sizeof( filename ));
|
||||
COM_ReplaceExtension( filename, ".res", sizeof( filename ));
|
||||
@@ -370,6 +371,16 @@ static void SV_CreateGenericResources( void )
|
||||
|
||||
SV_ReadResourceList( filename );
|
||||
SV_ReadResourceList( "reslist.txt" );
|
||||
|
||||
for( i = 0; i < world.wadlist.count; i++ )
|
||||
{
|
||||
if( world.wadlist.wadusage[i] > 0 )
|
||||
{
|
||||
string wadname;
|
||||
Q_snprintf( wadname, sizeof( wadname ), "%s.wad", world.wadlist.wadnames[i] );
|
||||
SV_GenericIndex( wadname );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -125,6 +125,16 @@ static void FS_BackupFileName( file_t *file, const char *path, uint options ) {}
|
||||
static void FS_InitMemory( void );
|
||||
static void FS_Purge( file_t* file );
|
||||
|
||||
void _Mem_Free( void *data, const char *filename, int fileline )
|
||||
{
|
||||
g_engfuncs._Mem_Free( data, filename, fileline );
|
||||
}
|
||||
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
{
|
||||
return g_engfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline );
|
||||
}
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
@@ -1412,34 +1422,34 @@ static qboolean FS_FindLibrary( const char *dllname, qboolean directpath, fs_dll
|
||||
return true;
|
||||
}
|
||||
|
||||
static poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline )
|
||||
static poolhandle_t Mem_AllocPoolStub( const char *name, const char *filename, int fileline )
|
||||
{
|
||||
return (poolhandle_t)0xDEADC0DE;
|
||||
}
|
||||
|
||||
static void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline )
|
||||
static void Mem_FreePoolStub( poolhandle_t *poolptr, const char *filename, int fileline )
|
||||
{
|
||||
// stub
|
||||
}
|
||||
|
||||
static void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
static void *Mem_AllocStub( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
{
|
||||
void *ptr = malloc( size );
|
||||
if( clear ) memset( ptr, 0, size );
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
static void *Mem_ReallocStub( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
{
|
||||
return realloc( memptr, size );
|
||||
}
|
||||
|
||||
static void _Mem_Free( void *data, const char *filename, int fileline )
|
||||
static void Mem_FreeStub( void *data, const char *filename, int fileline )
|
||||
{
|
||||
free( data );
|
||||
}
|
||||
|
||||
static void _Con_Printf( const char *fmt, ... )
|
||||
static void Con_PrintfStub( const char *fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@@ -1448,7 +1458,7 @@ static void _Con_Printf( const char *fmt, ... )
|
||||
va_end( ap );
|
||||
}
|
||||
|
||||
static void _Sys_Error( const char *fmt, ... )
|
||||
static void Sys_ErrorStub( const char *fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@@ -1459,7 +1469,7 @@ static void _Sys_Error( const char *fmt, ... )
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
static void *Sys_GetNativeObject_stub( const char *object )
|
||||
static void *Sys_GetNativeObjectStub( const char *object )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -2524,7 +2534,7 @@ byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean ga
|
||||
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
{
|
||||
return FS_LoadFile_( path, filesizeptr, gamedironly, g_engfuncs._Mem_Alloc != _Mem_Alloc );
|
||||
return FS_LoadFile_( path, filesizeptr, gamedironly, true );
|
||||
}
|
||||
|
||||
qboolean CRC32_File( dword *crcvalue, const char *filename )
|
||||
@@ -2936,14 +2946,6 @@ search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
|
||||
return search;
|
||||
}
|
||||
|
||||
static const char *FS_ArchivePath( file_t *f )
|
||||
{
|
||||
if( f->searchpath )
|
||||
return f->searchpath->filename;
|
||||
|
||||
return "plain";
|
||||
}
|
||||
|
||||
static qboolean FS_IsArchiveExtensionSupported( const char *ext, uint flags )
|
||||
{
|
||||
int i;
|
||||
@@ -2971,16 +2973,16 @@ void FS_InitMemory( void )
|
||||
|
||||
fs_interface_t g_engfuncs =
|
||||
{
|
||||
_Con_Printf,
|
||||
_Con_Printf,
|
||||
_Con_Printf,
|
||||
_Sys_Error,
|
||||
_Mem_AllocPool,
|
||||
_Mem_FreePool,
|
||||
_Mem_Alloc,
|
||||
_Mem_Realloc,
|
||||
_Mem_Free,
|
||||
Sys_GetNativeObject_stub
|
||||
Con_PrintfStub,
|
||||
Con_PrintfStub,
|
||||
Con_PrintfStub,
|
||||
Sys_ErrorStub,
|
||||
Mem_AllocPoolStub,
|
||||
Mem_FreePoolStub,
|
||||
Mem_AllocStub,
|
||||
Mem_ReallocStub,
|
||||
Mem_FreeStub,
|
||||
Sys_GetNativeObjectStub,
|
||||
};
|
||||
|
||||
static qboolean FS_InitInterface( int version, const fs_interface_t *engfuncs )
|
||||
|
||||
@@ -217,8 +217,10 @@ typedef struct fs_interface_t
|
||||
// memory
|
||||
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
|
||||
void (*_Mem_FreePool)( poolhandle_t *poolptr, const char *filename, int fileline );
|
||||
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 2 );
|
||||
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) ALLOC_CHECK( 3 );
|
||||
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) WARN_UNUSED_RESULT;
|
||||
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 3 ) WARN_UNUSED_RESULT;
|
||||
void (*_Mem_Free)( void *data, const char *filename, int fileline );
|
||||
|
||||
// platform
|
||||
|
||||
@@ -19,6 +19,7 @@ GNU General Public License for more details.
|
||||
#ifndef FILESYSTEM_INTERNAL_H
|
||||
#define FILESYSTEM_INTERNAL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "xash3d_types.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
@@ -129,10 +130,10 @@ extern const fs_archive_t g_archives[];
|
||||
|
||||
#define GI FI.GameInfo
|
||||
|
||||
#define Mem_Malloc( pool, size ) g_engfuncs._Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) g_engfuncs._Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Realloc( pool, ptr, size ) g_engfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) g_engfuncs._Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_AllocPool( name ) g_engfuncs._Mem_AllocPool( name, __FILE__, __LINE__ )
|
||||
#define Mem_FreePool( pool ) g_engfuncs._Mem_FreePool( pool, __FILE__, __LINE__ )
|
||||
|
||||
@@ -148,6 +149,9 @@ extern const fs_archive_t g_archives[];
|
||||
qboolean FS_InitStdio( qboolean caseinsensitive, const char *rootdir, const char *basedir, const char *gamedir, const char *rodir );
|
||||
void FS_ShutdownStdio( void );
|
||||
searchpath_t *FS_AddArchive_Fullpath( const fs_archive_t *archive, const char *file, int flags );
|
||||
void _Mem_Free( void *data, const char *filename, int fileline );
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
|
||||
// search path utils
|
||||
void FS_Rescan( void );
|
||||
@@ -155,7 +159,8 @@ void FS_ClearSearchPath( void );
|
||||
void FS_AllowDirectPaths( qboolean enable );
|
||||
void FS_AddGameDirectory( const char *dir, uint flags );
|
||||
void FS_AddGameHierarchy( const char *dir, uint flags );
|
||||
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly );
|
||||
search_t *FS_Search( const char *pattern, int caseinsensitive, int gamedironly )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
int FS_SetCurrentDirectory( const char *path );
|
||||
void FS_Path_f( void );
|
||||
|
||||
@@ -163,14 +168,15 @@ void FS_Path_f( void );
|
||||
void FS_LoadGameInfo( const char *rootfolder );
|
||||
|
||||
// file ops
|
||||
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly );
|
||||
int FS_Close( file_t *file );
|
||||
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly )
|
||||
MALLOC_LIKE( FS_Close, 1 ) WARN_UNUSED_RESULT;
|
||||
fs_offset_t FS_Write( file_t *file, const void *data, size_t datasize );
|
||||
fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize );
|
||||
int FS_Seek( file_t *file, fs_offset_t offset, int whence );
|
||||
fs_offset_t FS_Tell( file_t *file );
|
||||
qboolean FS_Eof( file_t *file );
|
||||
int FS_Flush( file_t *file );
|
||||
int FS_Close( file_t *file );
|
||||
int FS_Gets( file_t *file, char *string, size_t bufsize );
|
||||
int FS_UnGetc( file_t *file, char c );
|
||||
int FS_Getc( file_t *file );
|
||||
@@ -181,9 +187,12 @@ fs_offset_t FS_FileLength( file_t *f );
|
||||
qboolean FS_FileCopy( file_t *pOutput, file_t *pInput, int fileSize );
|
||||
|
||||
// file buffer ops
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly );
|
||||
byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly );
|
||||
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr );
|
||||
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
byte *FS_LoadFileMalloc( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly )
|
||||
MALLOC_LIKE( free, 1 ) WARN_UNUSED_RESULT;
|
||||
byte *FS_LoadDirectFile( const char *path, fs_offset_t *filesizeptr )
|
||||
MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len );
|
||||
|
||||
// file hashing
|
||||
|
||||
@@ -36,7 +36,9 @@ extern fs_globals_t *FI;
|
||||
#define FS_AllowDirectPaths (*g_fsapi.AllowDirectPaths)
|
||||
#define FS_AddGameDirectory (*g_fsapi.AddGameDirectory)
|
||||
#define FS_AddGameHierarchy (*g_fsapi.AddGameHierarchy)
|
||||
#ifndef FSCALLBACK_OVERRIDE_MALLOC_LIKE
|
||||
#define FS_Search (*g_fsapi.Search)
|
||||
#endif
|
||||
#define FS_SetCurrentDirectory (*g_fsapi.SetCurrentDirectory)
|
||||
#define FS_Path_f (*g_fsapi.Path_f)
|
||||
|
||||
@@ -44,14 +46,16 @@ extern fs_globals_t *FI;
|
||||
#define FS_LoadGameInfo (*g_fsapi.LoadGameInfo)
|
||||
|
||||
// file ops
|
||||
#ifndef FSCALLBACK_OVERRIDE_MALLOC_LIKE
|
||||
#define FS_Open (*g_fsapi.Open)
|
||||
#define FS_Close (*g_fsapi.Close)
|
||||
#endif
|
||||
#define FS_Write (*g_fsapi.Write)
|
||||
#define FS_Read (*g_fsapi.Read)
|
||||
#define FS_Seek (*g_fsapi.Seek)
|
||||
#define FS_Tell (*g_fsapi.Tell)
|
||||
#define FS_Eof (*g_fsapi.Eof)
|
||||
#define FS_Flush (*g_fsapi.Flush)
|
||||
#define FS_Close (*g_fsapi.Close)
|
||||
#define FS_Gets (*g_fsapi.Gets)
|
||||
#define FS_UnGetc (*g_fsapi.UnGetc)
|
||||
#define FS_Getc (*g_fsapi.Getc)
|
||||
@@ -62,8 +66,10 @@ extern fs_globals_t *FI;
|
||||
#define FS_FileCopy (*g_fsapi.FileCopy)
|
||||
|
||||
// file buffer ops
|
||||
#ifndef FSCALLBACK_OVERRIDE_MALLOC_LIKE
|
||||
#define FS_LoadFile (*g_fsapi.LoadFile)
|
||||
#define FS_LoadDirectFile (*g_fsapi.LoadDirectFile)
|
||||
#endif
|
||||
#define FS_WriteFile (*g_fsapi.WriteFile)
|
||||
|
||||
// file hashing
|
||||
|
||||
@@ -299,7 +299,6 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
|
||||
if( error )
|
||||
*error = ZIP_LOAD_BAD_HEADER;
|
||||
|
||||
Mem_Free( info );
|
||||
FS_CloseZIP( zip );
|
||||
return NULL;
|
||||
}
|
||||
@@ -316,7 +315,6 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
|
||||
if( error )
|
||||
*error = ZIP_LOAD_CORRUPTED;
|
||||
|
||||
Mem_Free( info );
|
||||
FS_CloseZIP( zip );
|
||||
return NULL;
|
||||
}
|
||||
@@ -364,7 +362,6 @@ static zip_t *FS_LoadZip( const char *zipfile, int *error )
|
||||
if( error )
|
||||
*error = ZIP_LOAD_CORRUPTED;
|
||||
|
||||
Mem_Free( info );
|
||||
FS_CloseZIP( zip );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,6 @@ const char* Q_timestamp( int format )
|
||||
static string timestamp;
|
||||
time_t crt_time;
|
||||
const struct tm *crt_tm;
|
||||
string timestring;
|
||||
|
||||
time( &crt_time );
|
||||
crt_tm = localtime( &crt_time );
|
||||
@@ -297,33 +296,31 @@ const char* Q_timestamp( int format )
|
||||
{
|
||||
case TIME_FULL:
|
||||
// Build the full timestamp (ex: "Apr03 2007 [23:31.55]");
|
||||
strftime( timestring, sizeof( timestring ), "%b%d %Y [%H:%M.%S]", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%b%d %Y [%H:%M.%S]", crt_tm );
|
||||
break;
|
||||
case TIME_DATE_ONLY:
|
||||
// Build the date stamp only (ex: "Apr03 2007");
|
||||
strftime( timestring, sizeof( timestring ), "%b%d %Y", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%b%d %Y", crt_tm );
|
||||
break;
|
||||
case TIME_TIME_ONLY:
|
||||
// Build the time stamp only (ex: "23:31.55");
|
||||
strftime( timestring, sizeof( timestring ), "%H:%M.%S", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%H:%M.%S", crt_tm );
|
||||
break;
|
||||
case TIME_NO_SECONDS:
|
||||
// Build the time stamp exclude seconds (ex: "13:46");
|
||||
strftime( timestring, sizeof( timestring ), "%H:%M", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%H:%M", crt_tm );
|
||||
break;
|
||||
case TIME_YEAR_ONLY:
|
||||
// Build the date stamp year only (ex: "2006");
|
||||
strftime( timestring, sizeof( timestring ), "%Y", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%Y", crt_tm );
|
||||
break;
|
||||
case TIME_FILENAME:
|
||||
// Build a timestamp that can use for filename (ex: "Nov2006-26 (19.14.28)");
|
||||
strftime( timestring, sizeof( timestring ), "%b%Y-%d_%H.%M.%S", crt_tm );
|
||||
strftime( timestamp, sizeof( timestamp ), "%b%Y-%d_%H.%M.%S", crt_tm );
|
||||
break;
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
Q_strncpy( timestamp, timestring, sizeof( timestamp ));
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,6 @@ GNU General Public License for more details.
|
||||
#include "com_model.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
|
||||
const matrix3x4 m_matrix3x4_identity =
|
||||
{
|
||||
{ 1, 0, 0, 0 }, // PITCH [forward], org[0]
|
||||
{ 0, 1, 0, 0 }, // YAW [right] , org[1]
|
||||
{ 0, 0, 1, 0 }, // ROLL [up] , org[2]
|
||||
};
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
@@ -225,14 +218,6 @@ void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const ve
|
||||
VectorAdd( worldCenter, worldExtents, absmax );
|
||||
}
|
||||
|
||||
const matrix4x4 m_matrix4x4_identity =
|
||||
{
|
||||
{ 1, 0, 0, 0 }, // PITCH
|
||||
{ 0, 1, 0, 0 }, // YAW
|
||||
{ 0, 0, 1, 0 }, // ROLL
|
||||
{ 0, 0, 0, 1 }, // ORIGIN
|
||||
};
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "crtlib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int Test_ExtractFilePath( void )
|
||||
static int Test_ExtractFilePath( void )
|
||||
{
|
||||
char dst[64];
|
||||
const char *strings[] =
|
||||
|
||||
@@ -18,15 +18,14 @@ GNU General Public License for more details.
|
||||
#include "com_model.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
#include "eiface.h"
|
||||
#include "studio.h"
|
||||
|
||||
#define NUM_HULL_ROUNDS ARRAYSIZE( hull_table )
|
||||
#define HULL_PRECISION 4
|
||||
|
||||
vec3_t vec3_origin = { 0, 0, 0 };
|
||||
static const word hull_table[] = { 2, 4, 6, 8, 12, 16, 18, 24, 28, 32, 36, 40, 48, 54, 56, 60, 64, 72, 80, 112, 120, 128, 140, 176 };
|
||||
|
||||
static word hull_table[] = { 2, 4, 6, 8, 12, 16, 18, 24, 28, 32, 36, 40, 48, 54, 56, 60, 64, 72, 80, 112, 120, 128, 140, 176 };
|
||||
|
||||
int boxpnt[6][4] =
|
||||
const int boxpnt[6][4] =
|
||||
{
|
||||
{ 0, 4, 6, 2 }, // +X
|
||||
{ 0, 1, 5, 4 }, // +Y
|
||||
@@ -42,18 +41,7 @@ const float m_bytenormals[NUMVERTEXNORMALS][3] =
|
||||
#include "anorms.h"
|
||||
};
|
||||
|
||||
/*
|
||||
=================
|
||||
anglemod
|
||||
=================
|
||||
*/
|
||||
float anglemod( float a )
|
||||
{
|
||||
a = (360.0f / 65536) * ((int)(a*(65536/360.0f)) & 65535);
|
||||
return a;
|
||||
}
|
||||
|
||||
word FloatToHalf( float v )
|
||||
uint16_t FloatToHalf( float v )
|
||||
{
|
||||
unsigned int i = FloatAsUint( v );
|
||||
unsigned int e = (i >> 23) & 0x00ff;
|
||||
@@ -69,7 +57,7 @@ word FloatToHalf( float v )
|
||||
return h;
|
||||
}
|
||||
|
||||
float HalfToFloat( word h )
|
||||
float HalfToFloat( uint16_t h )
|
||||
{
|
||||
unsigned int f = (h << 16) & 0x80000000;
|
||||
unsigned int em = h & 0x7fff;
|
||||
@@ -151,57 +139,6 @@ void RoundUpHullSize( vec3_t size )
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
SignbitsForPlane
|
||||
|
||||
fast box on planeside test
|
||||
=================
|
||||
*/
|
||||
int SignbitsForPlane( const vec3_t normal )
|
||||
{
|
||||
int bits, i;
|
||||
|
||||
for( bits = i = 0; i < 3; i++ )
|
||||
if( normal[i] < 0.0f ) bits |= 1<<i;
|
||||
return bits;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
PlaneTypeForNormal
|
||||
=================
|
||||
*/
|
||||
int PlaneTypeForNormal( const vec3_t normal )
|
||||
{
|
||||
if( normal[0] == 1.0f )
|
||||
return PLANE_X;
|
||||
if( normal[1] == 1.0f )
|
||||
return PLANE_Y;
|
||||
if( normal[2] == 1.0f )
|
||||
return PLANE_Z;
|
||||
return PLANE_NONAXIAL;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
NearestPOW
|
||||
=================
|
||||
*/
|
||||
int NearestPOW( int value, qboolean roundDown )
|
||||
{
|
||||
int n = 1;
|
||||
|
||||
if( value <= 0 ) return 1;
|
||||
while( n < value ) n <<= 1;
|
||||
|
||||
if( roundDown )
|
||||
{
|
||||
if( n > value ) n >>= 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
rsqrt
|
||||
@@ -224,43 +161,6 @@ float rsqrt( float number )
|
||||
return y;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
VectorCompareEpsilon
|
||||
|
||||
==============
|
||||
*/
|
||||
qboolean VectorCompareEpsilon( const vec3_t vec1, const vec3_t vec2, vec_t epsilon )
|
||||
{
|
||||
vec_t ax, ay, az;
|
||||
|
||||
ax = fabs( vec1[0] - vec2[0] );
|
||||
ay = fabs( vec1[1] - vec2[1] );
|
||||
az = fabs( vec1[2] - vec2[2] );
|
||||
|
||||
if(( ax <= epsilon ) && ( ay <= epsilon ) && ( az <= epsilon ))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
float VectorNormalizeLength2( const vec3_t v, vec3_t out )
|
||||
{
|
||||
float length, ilength;
|
||||
|
||||
length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
||||
length = sqrt( length );
|
||||
|
||||
if( length )
|
||||
{
|
||||
ilength = 1.0f / length;
|
||||
out[0] = v[0] * ilength;
|
||||
out[1] = v[1] * ilength;
|
||||
out[2] = v[2] * ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up )
|
||||
{
|
||||
float d;
|
||||
@@ -276,42 +176,6 @@ void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up )
|
||||
VectorNormalize( up );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
AngleVectors
|
||||
|
||||
=================
|
||||
*/
|
||||
void GAME_EXPORT AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up )
|
||||
{
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
SinCos( DEG2RAD( angles[YAW] ), &sy, &cy );
|
||||
SinCos( DEG2RAD( angles[PITCH] ), &sp, &cp );
|
||||
SinCos( DEG2RAD( angles[ROLL] ), &sr, &cr );
|
||||
|
||||
if( forward )
|
||||
{
|
||||
forward[0] = cp * cy;
|
||||
forward[1] = cp * sy;
|
||||
forward[2] = -sp;
|
||||
}
|
||||
|
||||
if( right )
|
||||
{
|
||||
right[0] = (-1.0f * sr * sp * cy + -1.0f * cr * -sy );
|
||||
right[1] = (-1.0f * sr * sp * sy + -1.0f * cr * cy );
|
||||
right[2] = (-1.0f * sr * cp);
|
||||
}
|
||||
|
||||
if( up )
|
||||
{
|
||||
up[0] = (cr * sp * cy + -sr * -sy );
|
||||
up[1] = (cr * sp * sy + -sr * cy );
|
||||
up[2] = (cr * cp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
VectorAngles
|
||||
@@ -384,39 +248,6 @@ void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, v
|
||||
//
|
||||
// bounds operations
|
||||
//
|
||||
/*
|
||||
=================
|
||||
AddPointToBounds
|
||||
=================
|
||||
*/
|
||||
void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs )
|
||||
{
|
||||
float val;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
val = v[i];
|
||||
if( val < mins[i] ) mins[i] = val;
|
||||
if( val > maxs[i] ) maxs[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
ExpandBounds (not used anywhere?)
|
||||
=================
|
||||
*/
|
||||
void ExpandBounds( vec3_t mins, vec3_t maxs, float offset )
|
||||
{
|
||||
mins[0] -= offset;
|
||||
mins[1] -= offset;
|
||||
mins[2] -= offset;
|
||||
maxs[0] += offset;
|
||||
maxs[1] += offset;
|
||||
maxs[2] += offset;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
SphereIntersect
|
||||
@@ -457,67 +288,9 @@ void PlaneIntersect( const mplane_t *plane, const vec3_t p0, const vec3_t p1, ve
|
||||
VectorMA( p0, sect, p1, out );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
RadiusFromBounds
|
||||
=================
|
||||
*/
|
||||
float RadiusFromBounds( const vec3_t mins, const vec3_t maxs )
|
||||
{
|
||||
vec3_t corner;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
corner[i] = fabs( mins[i] ) > fabs( maxs[i] ) ? fabs( mins[i] ) : fabs( maxs[i] );
|
||||
}
|
||||
return VectorLength( corner );
|
||||
}
|
||||
|
||||
//
|
||||
// studio utils
|
||||
//
|
||||
/*
|
||||
====================
|
||||
AngleQuaternion
|
||||
|
||||
====================
|
||||
*/
|
||||
void AngleQuaternion( const vec3_t angles, vec4_t q, qboolean studio )
|
||||
{
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
if( studio )
|
||||
{
|
||||
SinCos( angles[ROLL] * 0.5f, &sy, &cy );
|
||||
SinCos( angles[YAW] * 0.5f, &sp, &cp );
|
||||
SinCos( angles[PITCH] * 0.5f, &sr, &cr );
|
||||
}
|
||||
else
|
||||
{
|
||||
SinCos( DEG2RAD( angles[YAW] ) * 0.5f, &sy, &cy );
|
||||
SinCos( DEG2RAD( angles[PITCH] ) * 0.5f, &sp, &cp );
|
||||
SinCos( DEG2RAD( angles[ROLL] ) * 0.5f, &sr, &cr );
|
||||
}
|
||||
|
||||
q[0] = sr * cp * cy - cr * sp * sy; // X
|
||||
q[1] = cr * sp * cy + sr * cp * sy; // Y
|
||||
q[2] = cr * cp * sy - sr * sp * cy; // Z
|
||||
q[3] = cr * cp * cy + sr * sp * sy; // W
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
QuaternionAngle
|
||||
|
||||
====================
|
||||
*/
|
||||
void QuaternionAngle( const vec4_t q, vec3_t angles )
|
||||
{
|
||||
matrix3x4 mat;
|
||||
Matrix3x4_FromOriginQuat( mat, q, vec3_origin );
|
||||
Matrix3x4_AnglesFromMatrix( mat, angles );
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
@@ -680,25 +453,6 @@ int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const mplane_t *p )
|
||||
return sides;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
StudioSlerpBones
|
||||
|
||||
====================
|
||||
*/
|
||||
void R_StudioSlerpBones( int numbones, vec4_t q1[], float pos1[][3], const vec4_t q2[], const float pos2[][3], float s )
|
||||
{
|
||||
int i;
|
||||
|
||||
s = bound( 0.0f, s, 1.0f );
|
||||
|
||||
for( i = 0; i < numbones; i++ )
|
||||
{
|
||||
QuaternionSlerp( q1[i], q2[i], s, q1[i] );
|
||||
VectorLerp( pos1[i], s, pos2[i], pos1[i] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
StudioCalcBoneQuaternion
|
||||
|
||||
@@ -23,74 +23,65 @@ GNU General Public License for more details.
|
||||
|
||||
#include "build.h"
|
||||
#include "xash3d_types.h"
|
||||
#include "const.h"
|
||||
#include "com_model.h"
|
||||
#include "studio.h"
|
||||
|
||||
/*
|
||||
===========================
|
||||
|
||||
CONSTANTS AND HELPER MACROS
|
||||
|
||||
===========================
|
||||
*/
|
||||
|
||||
// euler angle order
|
||||
#define PITCH 0
|
||||
#define YAW 1
|
||||
#define ROLL 2
|
||||
#define PITCH 0
|
||||
#define YAW 1
|
||||
#define ROLL 2
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI (double)3.14159265358979323846
|
||||
#define M_PI (double)3.14159265358979323846
|
||||
#endif
|
||||
|
||||
#ifndef M_PI2
|
||||
#define M_PI2 ((double)(M_PI * 2))
|
||||
#endif
|
||||
#define M_PI2 ((double)(M_PI * 2))
|
||||
#define M_PI_F ((float)(M_PI))
|
||||
#define M_PI2_F ((float)(M_PI2))
|
||||
|
||||
#define M_PI_F ((float)(M_PI))
|
||||
#define M_PI2_F ((float)(M_PI2))
|
||||
#define RAD2DEG( x ) ((double)(x) * (double)(180.0 / M_PI))
|
||||
#define DEG2RAD( x ) ((double)(x) * (double)(M_PI / 180.0))
|
||||
|
||||
#define RAD2DEG( x ) ((double)(x) * (double)(180.0 / M_PI))
|
||||
#define DEG2RAD( x ) ((double)(x) * (double)(M_PI / 180.0))
|
||||
#define NUMVERTEXNORMALS 162
|
||||
|
||||
#define NUMVERTEXNORMALS 162
|
||||
#define BOGUS_RANGE ((vec_t)114032.64) // world.size * 1.74
|
||||
|
||||
#define BOGUS_RANGE ((vec_t)114032.64) // world.size * 1.74
|
||||
#define SIDE_FRONT 0
|
||||
#define SIDE_BACK 1
|
||||
#define SIDE_ON 2
|
||||
#define SIDE_CROSS -2
|
||||
|
||||
#define SIDE_FRONT 0
|
||||
#define SIDE_BACK 1
|
||||
#define SIDE_ON 2
|
||||
#define SIDE_CROSS -2
|
||||
#define PLANE_X 0 // 0 - 2 are axial planes
|
||||
#define PLANE_Y 1 // 3 needs alternate calc
|
||||
#define PLANE_Z 2
|
||||
#define PLANE_NONAXIAL 3
|
||||
|
||||
#define PLANE_X 0 // 0 - 2 are axial planes
|
||||
#define PLANE_Y 1 // 3 needs alternate calc
|
||||
#define PLANE_Z 2
|
||||
#define PLANE_NONAXIAL 3
|
||||
#define EQUAL_EPSILON 0.001f
|
||||
#define STOP_EPSILON 0.1f
|
||||
#define ON_EPSILON 0.1f
|
||||
|
||||
#define EQUAL_EPSILON 0.001f
|
||||
#define STOP_EPSILON 0.1f
|
||||
#define ON_EPSILON 0.1f
|
||||
#define RAD_TO_STUDIO (32768.0 / M_PI)
|
||||
#define STUDIO_TO_RAD (M_PI / 32768.0)
|
||||
|
||||
#define RAD_TO_STUDIO (32768.0 / M_PI)
|
||||
#define STUDIO_TO_RAD (M_PI / 32768.0)
|
||||
#define INV127F ( 1.0f / 127.0f )
|
||||
#define INV255F ( 1.0f / 255.0f )
|
||||
#define MAKE_SIGNED( x ) ((( x ) * INV127F ) - 1.0f )
|
||||
|
||||
#define INV127F ( 1.0f / 127.0f )
|
||||
#define INV255F ( 1.0f / 255.0f )
|
||||
#define MAKE_SIGNED( x ) ((( x ) * INV127F ) - 1.0f )
|
||||
|
||||
#define Q_min( a, b ) (((a) < (b)) ? (a) : (b))
|
||||
#define Q_max( a, b ) (((a) > (b)) ? (a) : (b))
|
||||
#define Q_min( a, b ) (((a) < (b)) ? (a) : (b))
|
||||
#define Q_max( a, b ) (((a) > (b)) ? (a) : (b))
|
||||
#define Q_equal_e( a, b, e ) (((a) >= ((b) - (e))) && ((a) <= ((b) + (e))))
|
||||
#define Q_equal( a, b ) Q_equal_e( a, b, EQUAL_EPSILON )
|
||||
#define Q_recip( a ) ((float)(1.0f / (float)(a)))
|
||||
#define Q_floor( a ) ((float)(int)(a))
|
||||
#define Q_ceil( a ) ((float)(int)((a) + 1))
|
||||
#define Q_round( x, y ) (floor( x / y + 0.5f ) * y )
|
||||
#define Q_rint(x) ((x) < 0.0f ? ((int)((x)-0.5f)) : ((int)((x)+0.5f)))
|
||||
|
||||
#ifdef XASH_IRIX
|
||||
#undef isnan
|
||||
#endif
|
||||
#ifdef isnan // check for C99 isnan
|
||||
#define IS_NAN isnan
|
||||
#else
|
||||
#define IS_NAN(x) (((*(int *)&x) & (255<<23)) == (255<<23))
|
||||
#endif
|
||||
|
||||
#define ALIGN( x, a ) ((( x ) + (( size_t )( a ) - 1 )) & ~(( size_t )( a ) - 1 ))
|
||||
#define Q_floor( a ) ((float)(int)(a))
|
||||
#define Q_ceil( a ) ((float)(int)((a) + 1))
|
||||
#define Q_round( x, y ) (floor( x / y + 0.5f ) * y )
|
||||
#define Q_rint(x) ((x) < 0.0f ? ((int)((x)-0.5f)) : ((int)((x)+0.5f)))
|
||||
#define ALIGN( x, a ) ((( x ) + (( size_t )( a ) - 1 )) & ~(( size_t )( a ) - 1 ))
|
||||
|
||||
#define VectorIsNAN(v) (IS_NAN(v[0]) || IS_NAN(v[1]) || IS_NAN(v[2]))
|
||||
#define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
|
||||
@@ -118,8 +109,11 @@ GNU General Public License for more details.
|
||||
#define Vector2Average(a,b,o) ((o)[0]=((a)[0]+(b)[0])*0.5f,(o)[1]=((a)[1]+(b)[1])*0.5f)
|
||||
#define VectorAverage(a,b,o) ((o)[0]=((a)[0]+(b)[0])*0.5f,(o)[1]=((a)[1]+(b)[1])*0.5f,(o)[2]=((a)[2]+(b)[2])*0.5f)
|
||||
#define Vector2Set(v, x, y) ((v)[0]=(x),(v)[1]=(y))
|
||||
#define Vector2Unpack(v, x, y) ((x)=(v)[0],(y)=(v)[1])
|
||||
#define VectorSet(v, x, y, z) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z))
|
||||
#define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3] = (d))
|
||||
#define VectorUnpack(v, x, y, z) ((x)=(v)[0],(y)=(v)[1],(z)=(v)[2])
|
||||
#define Vector4Set(v, a, b, c, d) ((v)[0]=(a),(v)[1]=(b),(v)[2]=(c),(v)[3]=(d))
|
||||
#define Vector4Unpack(v, a, b, c, d) ((a)=(v)[0],(b)=(v)[1],(c)=(v)[2],(d)=(v)[3])
|
||||
#define VectorClear(x) ((x)[0]=(x)[1]=(x)[2]=0)
|
||||
#define Vector2Lerp( v1, lerp, v2, c ) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]))
|
||||
#define VectorLerp( v1, lerp, v2, c ) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]))
|
||||
@@ -138,9 +132,95 @@ GNU General Public License for more details.
|
||||
#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist)
|
||||
#define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min))
|
||||
|
||||
/*
|
||||
===========================
|
||||
|
||||
CONSTANTS GLOBALS
|
||||
|
||||
===========================
|
||||
*/
|
||||
// a1ba: we never return pointers to these globals
|
||||
// so help compiler optimize constants away
|
||||
#define vec3_origin ((vec3_t){ 0.0f, 0.0f, 0.0f })
|
||||
#define m_matrix3x4_identity ((matrix3x4) { \
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f }, \
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f }, \
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f }} )
|
||||
#define m_matrix4x4_identity ((matrix4x4) { \
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f }, \
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f }, \
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f }, \
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f }} )
|
||||
|
||||
extern const int boxpnt[6][4];
|
||||
extern const float m_bytenormals[NUMVERTEXNORMALS][3];
|
||||
|
||||
|
||||
/*
|
||||
===========================
|
||||
|
||||
MATH FUNCTIONS
|
||||
|
||||
===========================
|
||||
*/
|
||||
typedef struct mplane_s mplane_t;
|
||||
typedef struct mstudiobone_s mstudiobone_t;
|
||||
typedef struct mstudioanim_s mstudioanim_t;
|
||||
|
||||
float rsqrt( float number );
|
||||
uint16_t FloatToHalf( float v );
|
||||
float HalfToFloat( uint16_t h );
|
||||
void RoundUpHullSize( vec3_t size );
|
||||
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up );
|
||||
void VectorAngles( const float *forward, float *angles );
|
||||
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles );
|
||||
void PlaneIntersect( const mplane_t *plane, const vec3_t p0, const vec3_t p1, vec3_t out );
|
||||
qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir );
|
||||
void QuaternionSlerp( const vec4_t p, const vec4_t q, float t, vec4_t qt );
|
||||
void R_StudioCalcBoneQuaternion( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const float *adj, vec4_t q );
|
||||
void R_StudioCalcBonePosition( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const vec3_t adj, vec3_t pos );
|
||||
int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const mplane_t *p );
|
||||
#define BOX_ON_PLANE_SIDE( emins, emaxs, p ) \
|
||||
((( p )->type < 3 ) ? \
|
||||
( \
|
||||
((p)->dist <= (emins)[(p)->type]) ? 1 : \
|
||||
( \
|
||||
((p)->dist >= (emaxs)[(p)->type] ) ? 2 : 3 \
|
||||
) \
|
||||
) : BoxOnPlaneSide(( emins ), ( emaxs ), ( p )))
|
||||
|
||||
//
|
||||
// matrixlib.c
|
||||
//
|
||||
#define Matrix3x4_LoadIdentity( mat ) Matrix3x4_Copy( mat, m_matrix3x4_identity )
|
||||
#define Matrix3x4_Copy( out, in ) memcpy( out, in, sizeof( matrix3x4 ))
|
||||
void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 );
|
||||
void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec3_t origin );
|
||||
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale );
|
||||
void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const vec3_t maxs, vec3_t absmin, vec3_t absmax );
|
||||
void Matrix3x4_AnglesFromMatrix( const matrix3x4 in, vec3_t out );
|
||||
|
||||
#define Matrix4x4_LoadIdentity( mat ) Matrix4x4_Copy( mat, m_matrix4x4_identity )
|
||||
#define Matrix4x4_Copy( out, in ) memcpy( out, in, sizeof( matrix4x4 ))
|
||||
void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 );
|
||||
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale );
|
||||
void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist );
|
||||
void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin );
|
||||
void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 );
|
||||
qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 );
|
||||
|
||||
// horrible cast but helps not breaking strict aliasing in mathlib
|
||||
// as union type punning should be fine in C but not in C++
|
||||
// so don't carry over this to C++ code
|
||||
#ifndef __cplusplus
|
||||
typedef union
|
||||
{
|
||||
float fl;
|
||||
@@ -173,28 +253,98 @@ static inline float UintAsFloat( uint32_t u )
|
||||
bits.u = u;
|
||||
return bits.fl;
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
// isnan implementation is broken on IRIX as reported in https://github.com/FWGS/xash3d-fwgs/pull/1211
|
||||
#if defined( XASH_IRIX ) || !defined( isnan )
|
||||
static inline int IS_NAN( float x )
|
||||
{
|
||||
int32_t i = FloatAsInt( x ); // only C
|
||||
return i & ( 255 << 23 ) == ( 255 << 23 );
|
||||
}
|
||||
#else
|
||||
#define IS_NAN isnan
|
||||
#endif
|
||||
|
||||
static inline float anglemod( float a )
|
||||
{
|
||||
a = (360.0f / 65536) * ((int)(a*(65536/360.0f)) & 65535);
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline void SinCos( float radians, float *sine, float *cosine )
|
||||
{
|
||||
*sine = sin(radians);
|
||||
*cosine = cos(radians);
|
||||
*sine = sin( radians );
|
||||
*cosine = cos( radians );
|
||||
}
|
||||
|
||||
float rsqrt( float number );
|
||||
float anglemod( float a );
|
||||
word FloatToHalf( float v );
|
||||
float HalfToFloat( word h );
|
||||
void RoundUpHullSize( vec3_t size );
|
||||
int SignbitsForPlane( const vec3_t normal );
|
||||
int PlaneTypeForNormal( const vec3_t normal );
|
||||
int NearestPOW( int value, qboolean roundDown );
|
||||
float VectorNormalizeLength2( const vec3_t v, vec3_t out );
|
||||
qboolean VectorCompareEpsilon( const vec3_t vec1, const vec3_t vec2, vec_t epsilon );
|
||||
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up );
|
||||
void VectorAngles( const float *forward, float *angles );
|
||||
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up );
|
||||
void VectorsAngles( const vec3_t forward, const vec3_t right, const vec3_t up, vec3_t angles );
|
||||
void PlaneIntersect( const struct mplane_s *plane, const vec3_t p0, const vec3_t p1, vec3_t out );
|
||||
static inline int NearestPOW( int value, qboolean roundDown )
|
||||
{
|
||||
int n = 1;
|
||||
|
||||
if( value <= 0 ) return 1;
|
||||
while( n < value ) n <<= 1;
|
||||
|
||||
if( roundDown )
|
||||
{
|
||||
if( n > value ) n >>= 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline qboolean VectorCompareEpsilon( const vec3_t vec1, const vec3_t vec2, vec_t epsilon )
|
||||
{
|
||||
vec_t ax = fabs( vec1[0] - vec2[0] );
|
||||
vec_t ay = fabs( vec1[1] - vec2[1] );
|
||||
vec_t az = fabs( vec1[2] - vec2[2] );
|
||||
|
||||
return ( ax <= epsilon ) && ( ay <= epsilon ) && ( az <= epsilon ) ? true : false;
|
||||
}
|
||||
|
||||
static inline float VectorNormalizeLength2( const vec3_t v, vec3_t out )
|
||||
{
|
||||
float length = VectorLength( v );
|
||||
|
||||
if( length )
|
||||
{
|
||||
float ilength = 1.0f / length;
|
||||
out[0] = v[0] * ilength;
|
||||
out[1] = v[1] * ilength;
|
||||
out[2] = v[2] * ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline void GAME_EXPORT AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up )
|
||||
{
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
SinCos( DEG2RAD( angles[YAW] ), &sy, &cy );
|
||||
SinCos( DEG2RAD( angles[PITCH] ), &sp, &cp );
|
||||
SinCos( DEG2RAD( angles[ROLL] ), &sr, &cr );
|
||||
|
||||
if( forward )
|
||||
{
|
||||
forward[0] = cp * cy;
|
||||
forward[1] = cp * sy;
|
||||
forward[2] = -sp;
|
||||
}
|
||||
|
||||
if( right )
|
||||
{
|
||||
right[0] = (-1.0f * sr * sp * cy + -1.0f * cr * -sy );
|
||||
right[1] = (-1.0f * sr * sp * sy + -1.0f * cr * cy );
|
||||
right[2] = (-1.0f * sr * cp);
|
||||
}
|
||||
|
||||
if( up )
|
||||
{
|
||||
up[0] = (cr * sp * cy + -sr * -sy );
|
||||
up[1] = (cr * sp * sy + -sr * cy );
|
||||
up[2] = (cr * cp);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ClearBounds( vec3_t mins, vec3_t maxs )
|
||||
{
|
||||
@@ -221,20 +371,85 @@ static inline qboolean BoundsAndSphereIntersect( const vec3_t mins, const vec3_t
|
||||
return true;
|
||||
}
|
||||
|
||||
void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
|
||||
qboolean SphereIntersect( const vec3_t vSphereCenter, float fSphereRadiusSquared, const vec3_t vLinePt, const vec3_t vLineDir );
|
||||
float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
|
||||
void ExpandBounds( vec3_t mins, vec3_t maxs, float offset );
|
||||
static inline float RadiusFromBounds( const vec3_t mins, const vec3_t maxs )
|
||||
{
|
||||
vec3_t corner;
|
||||
int i;
|
||||
|
||||
void AngleQuaternion( const vec3_t angles, vec4_t q, qboolean studio );
|
||||
void QuaternionAngle( const vec4_t q, vec3_t angles );
|
||||
void QuaternionSlerp( const vec4_t p, const vec4_t q, float t, vec4_t qt );
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
float a = fabs( mins[i] );
|
||||
float b = fabs( maxs[i] );
|
||||
corner[i] = Q_max( a, b );
|
||||
}
|
||||
|
||||
//
|
||||
// matrixlib.c
|
||||
//
|
||||
#define Matrix3x4_LoadIdentity( mat ) Matrix3x4_Copy( mat, m_matrix3x4_identity )
|
||||
#define Matrix3x4_Copy( out, in ) memcpy( out, in, sizeof( matrix3x4 ))
|
||||
return VectorLength( corner );
|
||||
}
|
||||
|
||||
static inline void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 0; i < 3; i++ )
|
||||
{
|
||||
float val = v[i];
|
||||
if( val < mins[i] ) mins[i] = val;
|
||||
if( val > maxs[i] ) maxs[i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ExpandBounds( vec3_t mins, vec3_t maxs, float offset )
|
||||
{
|
||||
mins[0] -= offset;
|
||||
mins[1] -= offset;
|
||||
mins[2] -= offset;
|
||||
maxs[0] += offset;
|
||||
maxs[1] += offset;
|
||||
maxs[2] += offset;
|
||||
}
|
||||
|
||||
static inline int SignbitsForPlane( const vec3_t normal )
|
||||
{
|
||||
int bits, i;
|
||||
|
||||
for( bits = i = 0; i < 3; i++ )
|
||||
if( normal[i] < 0.0f ) bits |= 1<<i;
|
||||
return bits;
|
||||
}
|
||||
|
||||
static inline int PlaneTypeForNormal( const vec3_t normal )
|
||||
{
|
||||
if( normal[0] == 1.0f )
|
||||
return PLANE_X;
|
||||
if( normal[1] == 1.0f )
|
||||
return PLANE_Y;
|
||||
if( normal[2] == 1.0f )
|
||||
return PLANE_Z;
|
||||
return PLANE_NONAXIAL;
|
||||
}
|
||||
|
||||
static inline void AngleQuaternion( const vec3_t angles, vec4_t q, qboolean studio )
|
||||
{
|
||||
float sr, sp, sy, cr, cp, cy;
|
||||
|
||||
if( studio )
|
||||
{
|
||||
SinCos( angles[ROLL] * 0.5f, &sy, &cy );
|
||||
SinCos( angles[YAW] * 0.5f, &sp, &cp );
|
||||
SinCos( angles[PITCH] * 0.5f, &sr, &cr );
|
||||
}
|
||||
else
|
||||
{
|
||||
SinCos( DEG2RAD( angles[YAW] ) * 0.5f, &sy, &cy );
|
||||
SinCos( DEG2RAD( angles[PITCH] ) * 0.5f, &sp, &cp );
|
||||
SinCos( DEG2RAD( angles[ROLL] ) * 0.5f, &sr, &cr );
|
||||
}
|
||||
|
||||
q[0] = sr * cp * cy - cr * sp * sy; // X
|
||||
q[1] = cr * sp * cy + sr * cp * sy; // Y
|
||||
q[2] = cr * cp * sy - sr * sp * cy; // Z
|
||||
q[3] = cr * cp * cy + sr * sp * sy; // W
|
||||
}
|
||||
|
||||
static inline void Matrix3x4_SetOrigin( matrix3x4 out, float x, float y, float z )
|
||||
{
|
||||
@@ -250,56 +465,23 @@ static inline void Matrix3x4_OriginFromMatrix( const matrix3x4 in, float *out )
|
||||
out[2] = in[2][3];
|
||||
}
|
||||
|
||||
void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] );
|
||||
void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 );
|
||||
void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec3_t origin );
|
||||
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale );
|
||||
void Matrix3x4_TransformAABB( const matrix3x4 world, const vec3_t mins, const vec3_t maxs, vec3_t absmin, vec3_t absmax );
|
||||
void Matrix3x4_AnglesFromMatrix( const matrix3x4 in, vec3_t out );
|
||||
static inline void QuaternionAngle( const vec4_t q, vec3_t angles )
|
||||
{
|
||||
matrix3x4 mat;
|
||||
Matrix3x4_FromOriginQuat( mat, q, vec3_origin );
|
||||
Matrix3x4_AnglesFromMatrix( mat, angles );
|
||||
}
|
||||
|
||||
#define Matrix4x4_LoadIdentity( mat ) Matrix4x4_Copy( mat, m_matrix4x4_identity )
|
||||
#define Matrix4x4_Copy( out, in ) memcpy( out, in, sizeof( matrix4x4 ))
|
||||
static inline void R_StudioSlerpBones( int numbones, vec4_t q1[], float pos1[][3], const vec4_t q2[], const float pos2[][3], float s )
|
||||
{
|
||||
int i;
|
||||
s = bound( 0.0f, s, 1.0f );
|
||||
|
||||
void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] );
|
||||
void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 );
|
||||
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale );
|
||||
void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist );
|
||||
void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin );
|
||||
void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 );
|
||||
qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 );
|
||||
|
||||
void R_StudioSlerpBones( int numbones, vec4_t q1[], float pos1[][3], const vec4_t q2[], const float pos2[][3], float s );
|
||||
void R_StudioCalcBoneQuaternion( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const float *adj, vec4_t q );
|
||||
void R_StudioCalcBonePosition( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const vec3_t adj, vec3_t pos );
|
||||
|
||||
int BoxOnPlaneSide( const vec3_t emins, const vec3_t emaxs, const mplane_t *p );
|
||||
#define BOX_ON_PLANE_SIDE( emins, emaxs, p ) \
|
||||
((( p )->type < 3 ) ? \
|
||||
( \
|
||||
((p)->dist <= (emins)[(p)->type]) ? \
|
||||
1 \
|
||||
: \
|
||||
( \
|
||||
((p)->dist >= (emaxs)[(p)->type]) ? \
|
||||
2 \
|
||||
: \
|
||||
3 \
|
||||
) \
|
||||
) \
|
||||
: \
|
||||
BoxOnPlaneSide(( emins ), ( emaxs ), ( p )))
|
||||
|
||||
extern vec3_t vec3_origin;
|
||||
extern int boxpnt[6][4];
|
||||
extern const matrix3x4 m_matrix3x4_identity;
|
||||
extern const matrix4x4 m_matrix4x4_identity;
|
||||
extern const float m_bytenormals[NUMVERTEXNORMALS][3];
|
||||
for( i = 0; i < numbones; i++ )
|
||||
{
|
||||
QuaternionSlerp( q1[i], q2[i], s, q1[i] );
|
||||
VectorLerp( pos1[i], s, pos2[i], pos1[i] );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // XASH3D_MATHLIB_H
|
||||
|
||||
|
||||
@@ -27,6 +27,16 @@ ref_globals_t *gpGlobals;
|
||||
ref_client_t *gp_cl;
|
||||
ref_host_t *gp_host;
|
||||
|
||||
void _Mem_Free( void *data, const char *filename, int fileline )
|
||||
{
|
||||
gEngfuncs._Mem_Free( data, filename, fileline );
|
||||
}
|
||||
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
{
|
||||
return gEngfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline );
|
||||
}
|
||||
|
||||
static void R_ClearScreen( void )
|
||||
{
|
||||
pglClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
|
||||
@@ -782,10 +782,14 @@ DECLARE_ENGINE_SHARED_CVAR_LIST()
|
||||
//
|
||||
#include "crtlib.h"
|
||||
|
||||
#define Mem_Malloc( pool, size ) gEngfuncs._Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) gEngfuncs._Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
void _Mem_Free( void *data, const char *filename, int fileline );
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
|
||||
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Realloc( pool, ptr, size ) gEngfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) gEngfuncs._Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ )
|
||||
#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ )
|
||||
|
||||
@@ -23,6 +23,17 @@ gl_globals_t tr;
|
||||
ref_speeds_t r_stats;
|
||||
poolhandle_t r_temppool;
|
||||
viddef_t vid;
|
||||
|
||||
void _Mem_Free( void *data, const char *filename, int fileline )
|
||||
{
|
||||
gEngfuncs._Mem_Free( data, filename, fileline );
|
||||
}
|
||||
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
{
|
||||
return gEngfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT R_ClearScreen( void )
|
||||
{
|
||||
|
||||
|
||||
@@ -1237,10 +1237,14 @@ void R_SetUpWorldTransform (void);
|
||||
#include "crtlib.h"
|
||||
#include "crclib.h"
|
||||
#if 1
|
||||
#define Mem_Malloc( pool, size ) gEngfuncs._Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) gEngfuncs._Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
void _Mem_Free( void *data, const char *filename, int fileline );
|
||||
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
|
||||
ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT;
|
||||
|
||||
#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ )
|
||||
#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Realloc( pool, ptr, size ) gEngfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) gEngfuncs._Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ )
|
||||
#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ )
|
||||
#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ )
|
||||
#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ )
|
||||
|
||||
7
wscript
7
wscript
@@ -81,6 +81,7 @@ SUBDIRS = [
|
||||
Subproject('ref/null', lambda x: not x.env.DEDICATED and x.env.NULL),
|
||||
Subproject('3rdparty/mainui', lambda x: not x.env.DEDICATED),
|
||||
Subproject('3rdparty/vgui_support', 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),
|
||||
|
||||
@@ -227,12 +228,10 @@ def configure(conf):
|
||||
elif conf.env.DEST_OS == 'nswitch':
|
||||
conf.options.NO_VGUI = True
|
||||
conf.options.GL = True
|
||||
conf.options.NO_ASYNC_RESOLVE = True
|
||||
conf.options.USE_STBTT = True
|
||||
elif conf.env.DEST_OS == 'psvita':
|
||||
conf.options.NO_VGUI = True
|
||||
conf.options.GL = True
|
||||
conf.options.NO_ASYNC_RESOLVE = True
|
||||
conf.options.USE_STBTT = True
|
||||
# we'll specify -fPIC by hand for shared libraries only
|
||||
enforce_pic = False
|
||||
@@ -307,9 +306,10 @@ def configure(conf):
|
||||
'-Werror=alloc-size',
|
||||
'-Werror=bool-compare',
|
||||
'-Werror=bool-operation',
|
||||
'-Werror=cast-align=strict',
|
||||
# '-Werror=cast-align=strict',
|
||||
'-Werror=duplicated-cond',
|
||||
'-Werror=format-extra-args',
|
||||
'-Werror=free-nonheap-object',
|
||||
'-Werror=implicit-fallthrough=2',
|
||||
'-Werror=logical-op',
|
||||
'-Werror=nonnull',
|
||||
@@ -334,6 +334,7 @@ def configure(conf):
|
||||
'-Wformat=2',
|
||||
'-Winit-self',
|
||||
'-Wmisleading-indentation',
|
||||
'-Wmismatched-dealloc',
|
||||
'-Wstringop-overflow',
|
||||
'-Wunintialized',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user