mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-25 22:10:59 +00:00
adding compile time assertion support whenever possible
and convert some runtime which deserve to be evaluated earlier.
This commit is contained in:
parent
218ac53ce9
commit
ce3e9136a8
4 changed files with 8 additions and 3 deletions
|
@ -1011,7 +1011,7 @@ GL3_DrawParticles(void)
|
||||||
GLfloat dist;
|
GLfloat dist;
|
||||||
GLfloat color[4];
|
GLfloat color[4];
|
||||||
} part_vtx;
|
} part_vtx;
|
||||||
assert(sizeof(part_vtx)==9*sizeof(float)); // remember to update GL3_SurfInit() if this changes!
|
YQ2_STATIC_ASSERT(sizeof(part_vtx)==9*sizeof(float), "invalid part_vtx size"); // remember to update GL3_SurfInit() if this changes!
|
||||||
|
|
||||||
// Don't try to draw particles if there aren't any.
|
// Don't try to draw particles if there aren't any.
|
||||||
if (numParticles == 0)
|
if (numParticles == 0)
|
||||||
|
|
|
@ -189,7 +189,7 @@ DrawAliasFrameLerp(dmdl_t *paliashdr, entity_t* entity, vec3_t shadelight)
|
||||||
|
|
||||||
LerpVerts(colorOnly, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
|
LerpVerts(colorOnly, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
|
||||||
|
|
||||||
assert(sizeof(gl3_alias_vtx_t) == 9*sizeof(GLfloat));
|
YQ2_STATIC_ASSERT(sizeof(gl3_alias_vtx_t) == 9*sizeof(GLfloat), "invalid gl3_alias_vtx_t size");
|
||||||
|
|
||||||
// all the triangle fans and triangle strips of this model will be converted to
|
// all the triangle fans and triangle strips of this model will be converted to
|
||||||
// just triangles: the vertices stay the same and are batched in vtxBuf,
|
// just triangles: the vertices stay the same and are batched in vtxBuf,
|
||||||
|
|
|
@ -59,6 +59,7 @@ typedef unsigned char byte;
|
||||||
#define YQ2_ALIGNAS_TYPE(TYPE) _Alignas(TYPE)
|
#define YQ2_ALIGNAS_TYPE(TYPE) _Alignas(TYPE)
|
||||||
// must be used as prefix (YQ2_ATTR_NORETURN void bla();)!
|
// must be used as prefix (YQ2_ATTR_NORETURN void bla();)!
|
||||||
#define YQ2_ATTR_NORETURN _Noreturn
|
#define YQ2_ATTR_NORETURN _Noreturn
|
||||||
|
#define YQ2_STATIC_ASSERT(C, M) _Static_assert((C), M)
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define YQ2_ATTR_MALLOC __attribute__ ((__malloc__))
|
#define YQ2_ATTR_MALLOC __attribute__ ((__malloc__))
|
||||||
#define YQ2_ATTR_INLINE __attribute__((always_inline)) inline
|
#define YQ2_ATTR_INLINE __attribute__((always_inline)) inline
|
||||||
|
@ -77,6 +78,8 @@ typedef unsigned char byte;
|
||||||
#define YQ2_ATTR_NORETURN __attribute__ ((noreturn))
|
#define YQ2_ATTR_NORETURN __attribute__ ((noreturn))
|
||||||
#define YQ2_ATTR_MALLOC __attribute__ ((__malloc__))
|
#define YQ2_ATTR_MALLOC __attribute__ ((__malloc__))
|
||||||
#define YQ2_ATTR_INLINE __attribute__((always_inline)) inline
|
#define YQ2_ATTR_INLINE __attribute__((always_inline)) inline
|
||||||
|
// GCC supports this extension since 4.6
|
||||||
|
#define YQ2_STATIC_ASSERT(C, M) _Static_assert((C), M)
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
// Note: We prefer VS2019 16.8 or newer in C11 mode (/std:c11),
|
// Note: We prefer VS2019 16.8 or newer in C11 mode (/std:c11),
|
||||||
// then the __STDC_VERSION__ >= 201112L case above is used
|
// then the __STDC_VERSION__ >= 201112L case above is used
|
||||||
|
@ -95,6 +98,7 @@ typedef unsigned char byte;
|
||||||
#define YQ2_ATTR_NORETURN __declspec(noreturn)
|
#define YQ2_ATTR_NORETURN __declspec(noreturn)
|
||||||
#define YQ2_ATTR_MALLOC __declspec(restrict)
|
#define YQ2_ATTR_MALLOC __declspec(restrict)
|
||||||
#define YQ2_ATTR_INLINE __forceinline
|
#define YQ2_ATTR_INLINE __forceinline
|
||||||
|
#define YQ2_STATIC_ASSERT(C, M) assert((C) && M)
|
||||||
#else
|
#else
|
||||||
#warning "Please add a case for your compiler here to align correctly"
|
#warning "Please add a case for your compiler here to align correctly"
|
||||||
#define YQ2_ALIGNAS_SIZE(SIZE)
|
#define YQ2_ALIGNAS_SIZE(SIZE)
|
||||||
|
@ -102,6 +106,7 @@ typedef unsigned char byte;
|
||||||
#define YQ2_ATTR_NORETURN
|
#define YQ2_ATTR_NORETURN
|
||||||
#define YQ2_ATTR_MALLOC
|
#define YQ2_ATTR_MALLOC
|
||||||
#define YQ2_ATTR_INLINE inline
|
#define YQ2_ATTR_INLINE inline
|
||||||
|
#define YQ2_STATIC_ASSERT(C, M) assert((C) && M)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
|
|
|
@ -868,7 +868,7 @@ Swap_Init(void)
|
||||||
{
|
{
|
||||||
byte swaptest[2] = {1, 0};
|
byte swaptest[2] = {1, 0};
|
||||||
short swapTestShort;
|
short swapTestShort;
|
||||||
assert(sizeof(short) == 2);
|
YQ2_STATIC_ASSERT(sizeof(short) == 2, "invalid short size");
|
||||||
memcpy(&swapTestShort, swaptest, 2);
|
memcpy(&swapTestShort, swaptest, 2);
|
||||||
|
|
||||||
/* set the byte swapping variables in a portable manner */
|
/* set the byte swapping variables in a portable manner */
|
||||||
|
|
Loading…
Reference in a new issue