2018-04-13 18:56:43 +02:00
|
|
|
// basic typedefs
|
|
|
|
#ifndef XASH_TYPES_H
|
|
|
|
#define XASH_TYPES_H
|
2019-02-23 19:49:46 +01:00
|
|
|
|
2021-12-23 16:46:40 +01:00
|
|
|
#include "build.h"
|
|
|
|
|
2023-01-14 07:35:30 +01:00
|
|
|
#if XASH_IRIX
|
|
|
|
#include <port.h>
|
|
|
|
#endif
|
|
|
|
|
2021-12-23 16:46:40 +01:00
|
|
|
#if XASH_WIN32
|
2019-03-19 23:18:26 +01:00
|
|
|
#include <wchar.h> // off_t
|
2019-02-24 16:45:27 +01:00
|
|
|
#endif // _WIN32
|
|
|
|
|
2019-03-19 23:18:26 +01:00
|
|
|
#include <sys/types.h> // off_t
|
2020-04-19 11:56:16 +02:00
|
|
|
#include STDINT_H
|
2022-09-20 20:55:28 +02:00
|
|
|
#include <assert.h>
|
2019-03-19 23:18:26 +01:00
|
|
|
|
2018-04-13 18:56:43 +02:00
|
|
|
typedef unsigned char byte;
|
|
|
|
typedef int sound_t;
|
|
|
|
typedef float vec_t;
|
|
|
|
typedef vec_t vec2_t[2];
|
|
|
|
typedef vec_t vec3_t[3];
|
|
|
|
typedef vec_t vec4_t[4];
|
|
|
|
typedef vec_t quat_t[4];
|
|
|
|
typedef byte rgba_t[4]; // unsigned byte colorpack
|
|
|
|
typedef byte rgb_t[3]; // unsigned byte colorpack
|
|
|
|
typedef vec_t matrix3x4[3][4];
|
|
|
|
typedef vec_t matrix4x4[4][4];
|
2022-12-19 16:36:31 +01:00
|
|
|
|
2021-06-01 18:28:52 +02:00
|
|
|
typedef uint32_t poolhandle_t;
|
2018-04-13 18:56:43 +02:00
|
|
|
|
|
|
|
#undef true
|
|
|
|
#undef false
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
typedef enum { false, true } qboolean;
|
|
|
|
#else
|
|
|
|
typedef int qboolean;
|
|
|
|
#endif
|
|
|
|
|
2020-04-19 11:56:16 +02:00
|
|
|
typedef uint64_t longtime_t;
|
2019-02-23 19:49:46 +01:00
|
|
|
|
|
|
|
#define MAX_STRING 256 // generic string
|
|
|
|
#define MAX_INFO_STRING 256 // infostrings are transmitted across network
|
|
|
|
#define MAX_SERVERINFO_STRING 512 // server handles too many settings. expand to 1024?
|
|
|
|
#define MAX_LOCALINFO_STRING 32768 // localinfo used on server and not sended to the clients
|
|
|
|
#define MAX_SYSPATH 1024 // system filepath
|
2023-03-11 03:20:34 +01:00
|
|
|
#define MAX_VA_STRING 1024 // string length returned by va()
|
2019-02-23 19:49:46 +01:00
|
|
|
#define MAX_PRINT_MSG 8192 // how many symbols can handle single call of Con_Printf or Con_DPrintf
|
|
|
|
#define MAX_TOKEN 2048 // parse token length
|
|
|
|
#define MAX_MODS 512 // environment games that engine can keep visible
|
|
|
|
#define MAX_USERMSG_LENGTH 2048 // don't modify it's relies on a client-side definitions
|
|
|
|
|
2019-05-02 18:05:09 +02:00
|
|
|
#define BIT( n ) ( 1U << ( n ))
|
2023-10-30 20:24:13 +01:00
|
|
|
#define BIT64( n ) ( 1ULL << ( n ))
|
2019-02-23 19:49:46 +01:00
|
|
|
#define SetBits( iBitVector, bits ) ((iBitVector) = (iBitVector) | (bits))
|
|
|
|
#define ClearBits( iBitVector, bits ) ((iBitVector) = (iBitVector) & ~(bits))
|
|
|
|
#define FBitSet( iBitVector, bit ) ((iBitVector) & (bit))
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
#ifdef NULL
|
|
|
|
#undef NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// color strings
|
|
|
|
#define IsColorString( p ) ( p && *( p ) == '^' && *(( p ) + 1) && *(( p ) + 1) >= '0' && *(( p ) + 1 ) <= '9' )
|
|
|
|
#define ColorIndex( c ) ((( c ) - '0' ) & 7 )
|
|
|
|
|
2024-04-28 02:56:02 +02:00
|
|
|
#if defined( __GNUC__ )
|
|
|
|
#if defined( __i386__ )
|
|
|
|
#define EXPORT __attribute__(( visibility( "default" ), force_align_arg_pointer ))
|
|
|
|
#define GAME_EXPORT __attribute(( force_align_arg_pointer ))
|
2022-05-28 16:57:43 +02:00
|
|
|
#else
|
2024-04-28 02:56:02 +02:00
|
|
|
#define EXPORT __attribute__(( visibility ( "default" )))
|
2022-05-28 16:57:43 +02:00
|
|
|
#define GAME_EXPORT
|
|
|
|
#endif
|
2024-04-28 02:56:02 +02:00
|
|
|
|
|
|
|
#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 )))
|
2024-06-09 06:03:55 +02:00
|
|
|
#define NO_ASAN __attribute__(( no_sanitize( "address" )))
|
2024-04-28 02:56:02 +02:00
|
|
|
#define RENAME_SYMBOL( x ) asm( x )
|
2019-03-20 00:38:37 +01:00
|
|
|
#else
|
2024-04-28 02:56:02 +02:00
|
|
|
#if defined( _MSC_VER )
|
|
|
|
#define EXPORT __declspec( dllexport )
|
2024-06-09 06:03:55 +02:00
|
|
|
#define NO_ASAN __declspec( no_sanitize_address )
|
2024-04-28 02:56:02 +02:00
|
|
|
#else
|
|
|
|
#define EXPORT
|
2024-06-09 06:03:55 +02:00
|
|
|
#define NO_ASAN
|
2024-04-28 02:56:02 +02:00
|
|
|
#endif
|
2022-05-28 16:57:43 +02:00
|
|
|
#define GAME_EXPORT
|
|
|
|
#define NORETURN
|
2023-10-22 15:20:15 +02:00
|
|
|
#define NONNULL
|
2024-04-28 02:56:02 +02:00
|
|
|
#define _format( x )
|
|
|
|
#define ALLOC_CHECK( x )
|
|
|
|
#define RENAME_SYMBOL( x )
|
2019-02-23 19:49:46 +01:00
|
|
|
#endif
|
|
|
|
|
2024-06-09 08:16:07 +02:00
|
|
|
#if __GNUC__ >= 3
|
2024-04-28 02:56:02 +02:00
|
|
|
#define unlikely( x ) __builtin_expect( x, 0 )
|
|
|
|
#define likely( x ) __builtin_expect( x, 1 )
|
2024-06-09 08:16:07 +02:00
|
|
|
#elif defined( __has_builtin )
|
|
|
|
#if __has_builtin( __builtin_expect ) // this must be after defined() check
|
|
|
|
#define unlikely( x ) __builtin_expect( x, 0 )
|
|
|
|
#define likely( x ) __builtin_expect( x, 1 )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined( unlikely ) || !defined( likely )
|
2024-04-28 02:56:02 +02:00
|
|
|
#define unlikely( x ) ( x )
|
|
|
|
#define likely( x ) ( x )
|
2022-06-29 02:50:50 +02:00
|
|
|
#endif
|
2022-06-29 01:36:39 +02:00
|
|
|
|
2024-01-12 21:00:56 +01:00
|
|
|
#if __STDC_VERSION__ >= 202311L || __cplusplus >= 201103L // C23 or C++ static_assert is a keyword
|
|
|
|
#define STATIC_ASSERT_( ignore, x, y ) static_assert( x, y )
|
2023-12-28 15:31:30 +01:00
|
|
|
#define STATIC_ASSERT static_assert
|
2024-01-12 21:00:56 +01:00
|
|
|
#elif __STDC_VERSION__ >= 201112L // in C11 it's _Static_assert
|
|
|
|
#define STATIC_ASSERT_( ignore, x, y ) _Static_assert( x, y )
|
2023-12-28 15:31:30 +01:00
|
|
|
#define STATIC_ASSERT _Static_assert
|
2022-09-20 20:55:28 +02:00
|
|
|
#else
|
2023-12-28 15:31:30 +01:00
|
|
|
#define STATIC_ASSERT_( id, x, y ) extern int id[( x ) ? 1 : -1]
|
2024-01-12 21:00:56 +01:00
|
|
|
// need these to correctly expand the line macro
|
|
|
|
#define STATIC_ASSERT_3( line, x, y ) STATIC_ASSERT_( static_assert_ ## line, x, y )
|
|
|
|
#define STATIC_ASSERT_2( line, x, y ) STATIC_ASSERT_3( line, x, y )
|
|
|
|
#define STATIC_ASSERT( x, y ) STATIC_ASSERT_2( __LINE__, x, y )
|
2022-09-20 20:55:28 +02:00
|
|
|
#endif
|
2019-02-23 19:49:46 +01:00
|
|
|
|
2024-08-21 10:59:02 +02:00
|
|
|
// at least, statically check size of some public structures
|
|
|
|
#if XASH_64BIT
|
|
|
|
#define STATIC_CHECK_SIZEOF( type, size32, size64 ) \
|
|
|
|
STATIC_ASSERT( sizeof( type ) == size64, #type " unexpected size" )
|
|
|
|
#else
|
|
|
|
#define STATIC_CHECK_SIZEOF( type, size32, size64 ) \
|
|
|
|
STATIC_ASSERT( sizeof( type ) == size32, #type " unexpected size" )
|
|
|
|
#endif
|
|
|
|
|
2024-05-26 22:11:07 +02:00
|
|
|
#if !defined( __cplusplus ) && __STDC_VERSION__ >= 199101L // not C++ and C99 or newer
|
|
|
|
#define XASH_RESTRICT restrict
|
|
|
|
#elif _MSC_VER || __GNUC__ || __clang__ // compiler-specific extensions
|
|
|
|
#define XASH_RESTRICT __restrict
|
|
|
|
#else
|
|
|
|
#define XASH_RESTRICT // nothing
|
|
|
|
#endif
|
|
|
|
|
2019-02-23 19:49:46 +01:00
|
|
|
#ifdef XASH_BIG_ENDIAN
|
|
|
|
#define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255))
|
|
|
|
#define LittleLongSW(x) (x = LittleLong(x) )
|
|
|
|
#define LittleShort(x) ((short)( (((short)(x) >> 8) & 255) + (((short)(x) & 255) << 8)))
|
|
|
|
#define LittleShortSW(x) (x = LittleShort(x) )
|
|
|
|
_inline float LittleFloat( float f )
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
unsigned char b[4];
|
|
|
|
} dat1, dat2;
|
|
|
|
|
|
|
|
dat1.f = f;
|
|
|
|
dat2.b[0] = dat1.b[3];
|
|
|
|
dat2.b[1] = dat1.b[2];
|
|
|
|
dat2.b[2] = dat1.b[1];
|
|
|
|
dat2.b[3] = dat1.b[0];
|
|
|
|
|
|
|
|
return dat2.f;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define LittleLong(x) (x)
|
|
|
|
#define LittleLongSW(x)
|
|
|
|
#define LittleShort(x) (x)
|
|
|
|
#define LittleShortSW(x)
|
|
|
|
#define LittleFloat(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-06-19 05:46:08 +02:00
|
|
|
typedef unsigned int dword;
|
|
|
|
typedef unsigned int uint;
|
|
|
|
typedef unsigned long ulong;
|
2019-02-23 19:49:46 +01:00
|
|
|
typedef char string[MAX_STRING];
|
|
|
|
typedef struct file_s file_t; // normal file
|
|
|
|
typedef struct stream_s stream_t; // sound stream for background music playing
|
|
|
|
typedef off_t fs_offset_t;
|
2021-12-22 23:21:33 +01:00
|
|
|
#if XASH_WIN32
|
|
|
|
typedef int fs_size_t; // return type of _read, _write funcs
|
|
|
|
#else /* !XASH_WIN32 */
|
|
|
|
typedef ssize_t fs_size_t;
|
|
|
|
#endif /* !XASH_WIN32 */
|
2019-02-23 19:49:46 +01:00
|
|
|
|
|
|
|
typedef struct dllfunc_s
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
void **func;
|
|
|
|
} dllfunc_t;
|
|
|
|
|
|
|
|
typedef struct dll_info_s
|
|
|
|
{
|
|
|
|
const char *name; // name of library
|
|
|
|
const dllfunc_t *fcts; // list of dll exports
|
|
|
|
qboolean crash; // crash if dll not found
|
|
|
|
void *link; // hinstance of loading library
|
|
|
|
} dll_info_t;
|
|
|
|
|
2022-05-29 03:22:43 +02:00
|
|
|
typedef void (*setpair_t)( const char *key, const void *value, const void *buffer, void *numpairs );
|
2023-10-31 19:25:11 +01:00
|
|
|
typedef void *(*pfnCreateInterface_t)( const char *, int * );
|
2019-02-23 19:49:46 +01:00
|
|
|
|
2019-03-16 05:15:06 +01:00
|
|
|
// config strings are a general means of communication from
|
|
|
|
// the server to all connected clients.
|
|
|
|
// each config string can be at most CS_SIZE characters.
|
2019-11-04 16:34:08 +01:00
|
|
|
#if XASH_LOW_MEMORY == 0
|
2019-03-16 05:15:06 +01:00
|
|
|
#define MAX_QPATH 64 // max length of a game pathname
|
2019-11-04 16:34:08 +01:00
|
|
|
#elif XASH_LOW_MEMORY == 2
|
2019-11-04 13:58:45 +01:00
|
|
|
#define MAX_QPATH 32 // should be enough for singleplayer
|
|
|
|
#elif XASH_LOW_MEMORY == 1
|
|
|
|
#define MAX_QPATH 48
|
2019-10-29 05:30:57 +01:00
|
|
|
#endif
|
2019-03-16 05:15:06 +01:00
|
|
|
#define MAX_OSPATH 260 // max length of a filesystem pathname
|
|
|
|
#define CS_SIZE 64 // size of one config string
|
|
|
|
#define CS_TIME 16 // size of time string
|
|
|
|
|
2018-04-13 18:56:43 +02:00
|
|
|
#endif // XASH_TYPES_H
|