mirror of
https://github.com/FWGS/xash3d-fwgs
synced 2024-12-22 08:52:32 +01:00
common: add macro for simultaneously checking data type size for ILP32 and LP64
This commit is contained in:
parent
7fc9ee154a
commit
842e494fa6
@ -543,14 +543,8 @@ typedef struct
|
||||
#define MAX_CLIENT_SPRITES 512 // SpriteTextures (0-256 hud, 256-512 client)
|
||||
#define MAX_REQUESTS 64
|
||||
|
||||
#if ! XASH_64BIT
|
||||
STATIC_ASSERT( sizeof( mextrasurf_t ) == 324, "mextrasurf_t unexpected size" );
|
||||
STATIC_ASSERT( sizeof( decal_t ) == 60, "decal_t unexpected size");
|
||||
STATIC_ASSERT( sizeof( mfaceinfo_t ) == 176, "mfaceinfo_t unexpected size");
|
||||
#else
|
||||
STATIC_ASSERT( sizeof( mextrasurf_t) == 496, "mextrasurf_t unexpected size");
|
||||
STATIC_ASSERT( sizeof( decal_t ) == 88, "decal_t unexpected size");
|
||||
STATIC_ASSERT( sizeof( mfaceinfo_t ) == 304, "mfaceinfo_t unexpected size");
|
||||
#endif
|
||||
STATIC_CHECK_SIZEOF( mextrasurf_t, 324, 496 );
|
||||
STATIC_CHECK_SIZEOF( decal_t, 60, 88 );
|
||||
STATIC_CHECK_SIZEOF( mfaceinfo_t, 176, 304 );
|
||||
|
||||
#endif//COM_MODEL_H
|
||||
|
@ -30,6 +30,6 @@ typedef struct
|
||||
int state; // low bit is down state
|
||||
} kbutton_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( kbutton_t ) == 12, "kbutton_t isn't 12 bytes!" );
|
||||
STATIC_CHECK_SIZEOF( kbutton_t, 12, 12 );
|
||||
|
||||
#endif // KBUTTON_H
|
||||
|
@ -69,6 +69,6 @@ typedef struct netadr_s
|
||||
} netadr_t;
|
||||
#pragma pack( pop )
|
||||
|
||||
STATIC_ASSERT( sizeof( netadr_t ) == 20, "netadr_t isn't 20 bytes!" );
|
||||
STATIC_CHECK_SIZEOF( netadr_t, 20, 20 );
|
||||
|
||||
#endif // NET_ADR_H
|
||||
|
@ -130,6 +130,15 @@ typedef uint64_t longtime_t;
|
||||
#define STATIC_ASSERT( x, y ) STATIC_ASSERT_2( __LINE__, x, y )
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
#if !defined( __cplusplus ) && __STDC_VERSION__ >= 199101L // not C++ and C99 or newer
|
||||
#define XASH_RESTRICT restrict
|
||||
#elif _MSC_VER || __GNUC__ || __clang__ // compiler-specific extensions
|
||||
|
@ -74,7 +74,7 @@ typedef struct
|
||||
float size;
|
||||
} daliashdr_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliashdr_t ) == 84, "invalid daliashdr_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliashdr_t, 84, 84 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -83,7 +83,7 @@ typedef struct
|
||||
int32_t t;
|
||||
} stvert_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( stvert_t ) == 12, "invalid stvert_t size" );
|
||||
STATIC_CHECK_SIZEOF( stvert_t, 12, 12 );
|
||||
|
||||
typedef struct dtriangle_s
|
||||
{
|
||||
@ -91,7 +91,7 @@ typedef struct dtriangle_s
|
||||
int32_t vertindex[3];
|
||||
} dtriangle_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dtriangle_t ) == 16, "invalid dtriangle_t size" );
|
||||
STATIC_CHECK_SIZEOF( dtriangle_t, 16, 16 );
|
||||
|
||||
#define DT_FACES_FRONT 0x0010
|
||||
#define ALIAS_ONSEAM 0x0020
|
||||
@ -103,7 +103,7 @@ typedef struct
|
||||
char name[16]; // frame name from grabbing
|
||||
} daliasframe_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasframe_t ) == 24, "invalid daliasframe_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasframe_t, 24, 24 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -112,41 +112,41 @@ typedef struct
|
||||
trivertex_t bboxmax; // lightnormal isn't used
|
||||
} daliasgroup_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasgroup_t ) == 12, "invalid daliasgrou_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasgroup_t, 12, 12 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t numskins;
|
||||
} daliasskingroup_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasskingroup_t ) == 4, "invalid daliasskingroup_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasskingroup_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float interval;
|
||||
} daliasinterval_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasinterval_t ) == 4, "invalid daliasinterval_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasinterval_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float interval;
|
||||
} daliasskininterval_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasskininterval_t ) == 4, "invalid daliasskininterval_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasskininterval_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type; // was aliasframetype_t
|
||||
} daliasframetype_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasframetype_t ) == 4, "invalid daliasframetype_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasframetype_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type; // was aliasskintype_t
|
||||
} daliasskintype_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( daliasskintype_t ) == 4, "invalid daliasskintype_t size" );
|
||||
STATIC_CHECK_SIZEOF( daliasskintype_t, 4, 4 );
|
||||
|
||||
#endif//ALIAS_H
|
||||
|
@ -67,7 +67,7 @@ typedef struct dresource_s
|
||||
} dresource_t;
|
||||
#pragma pack( pop )
|
||||
|
||||
STATIC_ASSERT( sizeof( dresource_t ) == 136, "invalid dresource_t size, HPAKs won't be compatible (no custom logo in multiplayer!)" );
|
||||
STATIC_CHECK_SIZEOF( dresource_t, 136, 136 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -76,7 +76,7 @@ typedef struct
|
||||
int infotableofs;
|
||||
} hpak_header_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( hpak_header_t ) == 12, "invalid hpak_header_t size" );
|
||||
STATIC_CHECK_SIZEOF( hpak_header_t, 12, 12 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -85,7 +85,7 @@ typedef struct
|
||||
int disksize;
|
||||
} hpak_lump_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( hpak_lump_t ) == 144, "invalid hpak_lump_t size" );
|
||||
STATIC_CHECK_SIZEOF( hpak_lump_t, 144, 144 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -25,8 +25,7 @@ typedef struct did3v2_header_s
|
||||
uint8_t flags;
|
||||
uint32_t length; // size of extended header, padding and frames
|
||||
} did3v2_header_t;
|
||||
STATIC_ASSERT( sizeof( did3v2_header_t ) == 10,
|
||||
"invalid did3v2_header_t size" );
|
||||
STATIC_CHECK_SIZEOF( did3v2_header_t, 10, 10 );
|
||||
|
||||
typedef struct did3v2_extended_header_s
|
||||
{
|
||||
@ -34,8 +33,7 @@ typedef struct did3v2_extended_header_s
|
||||
uint8_t flags_length;
|
||||
uint8_t flags[1];
|
||||
} did3v2_extended_header_t;
|
||||
STATIC_ASSERT( sizeof( did3v2_extended_header_t ) == 6,
|
||||
"invalid did3v2_extended_header_t size" );
|
||||
STATIC_CHECK_SIZEOF( did3v2_extended_header_t, 6, 6 );
|
||||
|
||||
typedef struct did3v2_frame_s
|
||||
{
|
||||
@ -43,8 +41,7 @@ typedef struct did3v2_frame_s
|
||||
uint32_t length;
|
||||
uint8_t flags[2];
|
||||
} did3v2_frame_t;
|
||||
STATIC_ASSERT( sizeof( did3v2_frame_t ) == 10,
|
||||
"invalid did3v2_frame_t size" );
|
||||
STATIC_CHECK_SIZEOF( did3v2_frame_t, 10, 10 );
|
||||
#pragma pack( pop )
|
||||
|
||||
typedef enum did3v2_header_flags_e
|
||||
|
@ -95,12 +95,7 @@ typedef struct customization_s
|
||||
#define FCUST_WIPEDATA ( 1<<1 )
|
||||
#define FCUST_IGNOREINIT ( 1<<2 )
|
||||
|
||||
#if !XASH_64BIT
|
||||
STATIC_ASSERT( sizeof( customization_t ) == 164, "invalid customization_t size, broken API" );
|
||||
STATIC_ASSERT( sizeof( resource_t ) == 136, "invalid resource_t size, broken API" );
|
||||
#else
|
||||
STATIC_ASSERT( sizeof( customization_t ) == 192, "invalid customization_t size, broken API" );
|
||||
STATIC_ASSERT( sizeof( resource_t ) == 144, "invalid resource_t size, broken API" );
|
||||
#endif
|
||||
STATIC_CHECK_SIZEOF( customization_t, 164, 192 );
|
||||
STATIC_CHECK_SIZEOF( resource_t, 136, 144 );
|
||||
|
||||
#endif // CUSTOM_H
|
||||
|
@ -72,7 +72,7 @@ typedef struct
|
||||
int32_t version; // current version 2
|
||||
} dsprite_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dsprite_t ) == 8, "invalid dsprite_t size" );
|
||||
STATIC_CHECK_SIZEOF( dsprite_t, 8, 8 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -86,7 +86,7 @@ typedef struct
|
||||
uint32_t synctype; // animation synctype, was synctype_t
|
||||
} dsprite_q1_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dsprite_q1_t ) == 36, "invalid dsprite_q1_t size" );
|
||||
STATIC_CHECK_SIZEOF( dsprite_q1_t, 36, 36 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -101,7 +101,7 @@ typedef struct
|
||||
uint32_t synctype; // animation synctype, was synctype_t
|
||||
} dsprite_hl_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dsprite_hl_t ) == 40, "invalid dsprite_hl_t size" );
|
||||
STATIC_CHECK_SIZEOF( dsprite_hl_t, 40, 40 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -110,27 +110,27 @@ typedef struct
|
||||
int32_t height;
|
||||
} dspriteframe_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dspriteframe_t ) == 16, "invalid dspriteframe_t size" );
|
||||
STATIC_CHECK_SIZEOF( dspriteframe_t, 16, 16 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t numframes;
|
||||
} dspritegroup_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dspritegroup_t ) == 4, "invalid dspritegroup_t size" );
|
||||
STATIC_CHECK_SIZEOF( dspritegroup_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float interval;
|
||||
} dspriteinterval_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dspriteinterval_t ) == 4, "invalid dspriteinterval_t size" );
|
||||
STATIC_CHECK_SIZEOF( dspriteinterval_t, 4, 4 );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type; // was frametype_t
|
||||
} dframetype_t;
|
||||
|
||||
STATIC_ASSERT( sizeof( dframetype_t ) == 4, "invalid dframetype_t size" );
|
||||
STATIC_CHECK_SIZEOF( dframetype_t, 4, 4 );
|
||||
|
||||
#endif//SPRITE_H
|
||||
|
Loading…
Reference in New Issue
Block a user