fix standards violations

master
an 2019-12-03 02:02:24 -05:00
parent da538dc69f
commit c47de412bd
9 changed files with 133 additions and 161 deletions

View File

@ -516,65 +516,55 @@ float Q_atof(const char *str)
============================================================================
*/
bool host_bigendian;
bool host_bigendian;
int16_t (*BigShort)(int16_t l);
int16_t (*LittleShort)(int16_t l);
int32_t (*BigLong)(int32_t l);
float (*BigFloat)(float l);
int16_t (*LittleShort)(int16_t l);
int32_t (*LittleLong)(int32_t l);
float (*BigFloat)(float l);
float (*LittleFloat)(float l);
float (*LittleFloat)(float l);
int16_t ShortSwap(int16_t l)
static int16_t ShortSwap(int16_t l)
{
byte b1, b2;
b1 = l & 255;
b2 = (l >> 8) & 255;
return (b1 << 8) + b2;
int32_t copy;
((byte *)&copy)[0] = ((byte *)&l)[1];
((byte *)&copy)[1] = ((byte *)&l)[0];
return copy;
}
int16_t ShortNoSwap(int16_t l)
static int16_t ShortNoSwap(int16_t l)
{
return l;
}
int32_t LongSwap(int32_t l)
static int32_t LongSwap(int32_t l)
{
byte b1, b2, b3, b4;
b1 = l & 255;
b2 = (l >> 8) & 255;
b3 = (l >> 16) & 255;
b4 = (l >> 24) & 255;
return ((int32_t)b1 << 24) + ((int32_t)b2 << 16) + ((int32_t)b3 << 8) + b4;
int32_t copy;
((byte *)&copy)[0] = ((byte *)&l)[3];
((byte *)&copy)[1] = ((byte *)&l)[2];
((byte *)&copy)[2] = ((byte *)&l)[1];
((byte *)&copy)[3] = ((byte *)&l)[0];
return copy;
}
int32_t LongNoSwap(int32_t l)
static int32_t LongNoSwap(int32_t l)
{
return l;
}
float FloatSwap(float f)
static float FloatSwap(float f)
{
union
{
float f;
byte 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;
float copy;
((byte *)&copy)[0] = ((byte *)&f)[3];
((byte *)&copy)[1] = ((byte *)&f)[2];
((byte *)&copy)[2] = ((byte *)&f)[1];
((byte *)&copy)[3] = ((byte *)&f)[0];
return copy;
}
float FloatNoSwap(float f)
static float FloatNoSwap(float f)
{
return f;
}
@ -1294,41 +1284,30 @@ COM_Init
void COM_Init(void)
{
int32_t i = 0x12345678;
/* U N I X */
/*
BE_ORDER: 12 34 56 78
U N I X
LE_ORDER: 78 56 34 12
X I N U
PDP_ORDER: 34 12 78 56
N U X I
*/
if(*(char *)&i == 0x12)
if(*(byte *)&i == 0x12)
host_bigendian = true;
else if(*(char *)&i == 0x78)
else if(*(byte *)&i == 0x78)
host_bigendian = false;
else /* if ( *(char *)&i == 0x34 ) */
Sys_Error("Unsupported endianism.");
else
Sys_Error("Unsupported endianness");
if(host_bigendian)
{
BigShort = ShortNoSwap;
BigShort = ShortNoSwap;
BigLong = LongNoSwap;
BigFloat = FloatNoSwap;
LittleShort = ShortSwap;
BigLong = LongNoSwap;
LittleLong = LongSwap;
BigFloat = FloatNoSwap;
LittleLong = LongSwap;
LittleFloat = FloatSwap;
}
else /* assumed LITTLE_ENDIAN. */
else
{
BigShort = ShortSwap;
BigShort = ShortSwap;
BigLong = LongSwap;
BigFloat = FloatSwap;
LittleShort = ShortNoSwap;
BigLong = LongSwap;
LittleLong = LongNoSwap;
BigFloat = FloatSwap;
LittleLong = LongNoSwap;
LittleFloat = FloatNoSwap;
}
}

View File

@ -66,12 +66,13 @@ void InsertLinkAfter(link_t *l, link_t *after);
extern bool host_bigendian;
extern int16_t (*BigShort)(int16_t l);
extern int16_t (*LittleShort)(int16_t l);
extern int32_t (*BigLong)(int32_t l);
extern int32_t (*LittleLong)(int32_t l);
extern float (*BigFloat)(float l);
extern float (*LittleFloat)(float l);
extern int16_t (*BigShort)(int16_t l);
extern int32_t (*BigLong)(int32_t l);
extern float (*BigFloat)(float l);
extern int16_t (*LittleShort)(int16_t l);
extern int32_t (*LittleLong)(int32_t l);
extern float (*LittleFloat)(float l);
//============================================================================

View File

@ -44,17 +44,18 @@ extern vec3_t vec3_origin;
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
//johnfitz -- courtesy of lordhavoc
// QuakeSpasm: To avoid strict aliasing violations, use a float/int32_t union instead of type punning.
#define VectorNormalizeFast(_v)\
{\
union { float f; int32_t i; } _y, _number;\
_number.f = DotProduct(_v, _v);\
if (_number.f != 0.0)\
{\
_y.i = 0x5f3759df - (_number.i >> 1);\
_y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f));\
VectorScale(_v, _y.f, _v);\
}\
// QS: To avoid strict aliasing violations, use a float/int32_t union instead of type punning.
// [agw] NO YOU FOOL THAT'S UNDEFINED BEHAVIOUR
#define VectorNormalizeFast(_v) \
{ \
union { float f; uint32_t i; } _y, _number; \
_number.f = DotProduct(_v, _v); \
if(_number.f != 0.0) \
{ \
_y.i = 0x5f3759df - (_number.i >> 1); \
_y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f)); \
VectorScale(_v, _y.f, _v); \
} \
}
void TurnVector(vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz

View File

@ -1674,7 +1674,7 @@ static void PF_fixme(void)
}
static builtin_t pr_builtin[] =
builtin_t pr_builtins[] =
{
PF_fixme,
PF_makevectors, // void(entity e) makevectors = #1
@ -1765,6 +1765,5 @@ static builtin_t pr_builtin[] =
PF_setspawnparms
};
builtin_t *pr_builtins = pr_builtin;
int32_t pr_numbuiltins = arraysizeof(pr_builtin);
int32_t pr_numbuiltins = arraysizeof(pr_builtins);

View File

@ -22,7 +22,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef spingle__pr_comp_h
#define spingle__pr_comp_h
// this file is shared by the game and qcc
#define OFS_NULL 0
#define OFS_RETURN 1
#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors
#define OFS_PARM1 7
#define OFS_PARM2 10
#define OFS_PARM3 13
#define OFS_PARM4 16
#define OFS_PARM5 19
#define OFS_PARM6 22
#define OFS_PARM7 25
#define DEF_SAVEGLOBAL (1 << 15)
#define MAX_PARMS 8
#define PROG_VERSION 6
typedef int32_t func_t;
typedef int32_t string_t;
@ -40,18 +55,6 @@ typedef enum
ev_pointer
} etype_t;
#define OFS_NULL 0
#define OFS_RETURN 1
#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors
#define OFS_PARM1 7
#define OFS_PARM2 10
#define OFS_PARM3 13
#define OFS_PARM4 16
#define OFS_PARM5 19
#define OFS_PARM6 22
#define OFS_PARM7 25
enum
{
OP_DONE,
@ -144,10 +147,6 @@ typedef struct
int32_t s_name;
} ddef_t;
#define DEF_SAVEGLOBAL (1 << 15)
#define MAX_PARMS 8
typedef struct
{
int32_t first_statement; // negative numbers are builtins
@ -163,7 +162,6 @@ typedef struct
byte parm_size[MAX_PARMS];
} dfunction_t;
#define PROG_VERSION 6
typedef struct
{
int32_t version;

View File

@ -23,43 +23,43 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "q_defs.h"
dprograms_t *progs;
dfunction_t *pr_functions;
dprograms_t *progs;
dfunction_t *pr_functions;
static char *pr_strings;
static int32_t pr_stringssize;
static const char **pr_knownstrings;
static int32_t pr_maxknownstrings;
static int32_t pr_numknownstrings;
static ddef_t *pr_fielddefs;
static ddef_t *pr_globaldefs;
static char *pr_strings;
static int32_t pr_stringssize;
static const char **pr_knownstrings;
static int32_t pr_maxknownstrings;
static int32_t pr_numknownstrings;
static ddef_t *pr_fielddefs;
static ddef_t *pr_globaldefs;
bool pr_alpha_supported; //johnfitz
bool pr_alpha_supported; //johnfitz
dstatement_t *pr_statements;
globalvars_t *pr_global_struct;
float *pr_globals; // same as pr_global_struct
int32_t pr_edict_size; // in bytes
dstatement_t *pr_statements;
globalvars_t *pr_global_struct;
float *pr_globals; // same as pr_global_struct
int32_t pr_edict_size; // in bytes
uint16_t pr_crc;
uint16_t pr_crc;
int32_t type_size[8] =
static int32_t type_size[] =
{
1, // ev_void
1, // sizeof(string_t) / 4 // ev_string
1, // ev_float
3, // ev_vector
1, // ev_entity
1, // ev_field
1, // sizeof(func_t) / 4 // ev_function
1 // sizeof(void *) / 4 // ev_pointer
[ev_void] = 1,
[ev_string] = 1,
[ev_float] = 1,
[ev_vector] = 3,
[ev_entity] = 1,
[ev_field] = 1,
[ev_function] = 1,
[ev_pointer] = 1,
};
static ddef_t *ED_FieldAtOfs(int32_t ofs);
static bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
static ddef_t *ED_FieldAtOfs(int32_t ofs);
static bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 2
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 2
typedef struct
{
@ -73,17 +73,17 @@ static gefv_cache gefvCache[GEFV_CACHESIZE] =
{ NULL, "" }
};
cvar_t nomonsters = {"nomonsters", "0", CVAR_NONE};
cvar_t gamecfg = {"gamecfg", "0", CVAR_NONE};
cvar_t scratch1 = {"scratch1", "0", CVAR_NONE};
cvar_t scratch2 = {"scratch2", "0", CVAR_NONE};
cvar_t scratch3 = {"scratch3", "0", CVAR_NONE};
cvar_t scratch4 = {"scratch4", "0", CVAR_NONE};
cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
cvar_t nomonsters = {"nomonsters", "0", CVAR_NONE};
cvar_t gamecfg = {"gamecfg", "0", CVAR_NONE};
cvar_t scratch1 = {"scratch1", "0", CVAR_NONE};
cvar_t scratch2 = {"scratch2", "0", CVAR_NONE};
cvar_t scratch3 = {"scratch3", "0", CVAR_NONE};
cvar_t scratch4 = {"scratch4", "0", CVAR_NONE};
cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
/*
=================
@ -1050,7 +1050,7 @@ PR_LoadProgs
*/
void PR_LoadProgs(void)
{
int32_t i;
int32_t i;
// flush the non-C variable lookup cache
for(i = 0; i < GEFV_CACHESIZE; i++)
@ -1100,9 +1100,9 @@ void PR_LoadProgs(void)
for(i = 0; i < progs->numstatements; i++)
{
pr_statements[i].op = LittleShort(pr_statements[i].op);
pr_statements[i].a = LittleShort(pr_statements[i].a);
pr_statements[i].b = LittleShort(pr_statements[i].b);
pr_statements[i].c = LittleShort(pr_statements[i].c);
pr_statements[i].a = LittleShort(pr_statements[i].a);
pr_statements[i].b = LittleShort(pr_statements[i].b);
pr_statements[i].c = LittleShort(pr_statements[i].c);
}
for(i = 0; i < progs->numfunctions; i++)

View File

@ -55,7 +55,7 @@ typedef struct edict_s
byte fields[];
} edict_t;
#define EDICT_FROM_AREA(l) (edict_t *)((byte *)l - offsetof(edict_t, area))
#define EDICT_FROM_AREA(l) (edict_t *)((byte *)(l) - offsetof(edict_t, area))
//============================================================================
@ -91,17 +91,13 @@ const char *ED_ParseGlobals(const char *data);
void ED_LoadFromFile(const char *data);
/*
#define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
#define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts) / pr_edict_size)
*/
edict_t *EDICT_NUM(int32_t n);
int32_t NUM_FOR_EDICT(edict_t *e);
#define NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size))
#define NEXT_EDICT(e) ((edict_t *)((byte *)(e) + pr_edict_size))
#define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
#define EDICT_TO_PROG(e) ((byte *)(e) - (byte *)sv.edicts)
#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + (e)))
#define G_FLOAT(o) (pr_globals[o])
#define G_INT(o) (*(int32_t *)&pr_globals[o])
@ -111,19 +107,18 @@ int32_t NUM_FOR_EDICT(edict_t *e);
#define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o]))
#define G_FUNCTION(o) (*(func_t *)&pr_globals[o])
extern int32_t type_size[8];
typedef void (*builtin_t)(void);
extern builtin_t *pr_builtins;
extern int32_t pr_numbuiltins;
extern int32_t pr_argc;
extern builtin_t pr_builtins[];
extern int32_t pr_numbuiltins;
extern bool pr_trace;
extern dfunction_t *pr_xfunction;
extern int32_t pr_xstatement;
extern int32_t pr_argc;
extern uint16_t pr_crc;
extern bool pr_trace;
extern dfunction_t *pr_xfunction;
extern int32_t pr_xstatement;
extern uint16_t pr_crc;
noreturn void PR_RunError(const char *error, ...) FUNC_PRINTF(1, 2);

View File

@ -72,7 +72,6 @@ typedef struct entity_s
int32_t dlightframe; // dynamic lighting
int32_t dlightbits;
// FIXME: could turn these into a union
int32_t trivial_accept;
struct mnode_s *topnode; // for bmodels, first world node
// that splits bmodel, or NULL if

View File

@ -322,7 +322,7 @@ static int32_t mp3_decode(snd_stream_t *stream, byte *buf, int32_t len)
*buf++ = (sample >> 8) & 0xFF;
*buf++ = sample & 0xFF;
}
else /* assumed LITTLE_ENDIAN. */
else
{
*buf++ = sample & 0xFF;
*buf++ = (sample >> 8) & 0xFF;