Skip to content

Commit

Permalink
Refactoring patch by DevHC
Browse files Browse the repository at this point in the history
  • Loading branch information
Thilo Schulz committed Mar 5, 2011
1 parent 21668c0 commit fef4d12
Show file tree
Hide file tree
Showing 31 changed files with 60 additions and 98 deletions.
6 changes: 3 additions & 3 deletions code/botlib/be_aas_reach.c
Expand Up @@ -1556,7 +1556,7 @@ int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2
if (AAS_PointAreaNum(trace.endpos) == area2num)
{
//if not going through a cluster portal
numareas = AAS_TraceAreas(start, end, areas, NULL, sizeof(areas) / sizeof(int));
numareas = AAS_TraceAreas(start, end, areas, NULL, ARRAY_LEN(areas));
for (i = 0; i < numareas; i++)
if (AAS_AreaClusterPortal(areas[i]))
break;
Expand Down Expand Up @@ -2311,7 +2311,7 @@ int AAS_Reachability_Jump(int area1num, int area2num)
//because the predicted jump could have rushed through the area
VectorMA(move.endpos, -64, dir, teststart);
teststart[2] += 1;
numareas = AAS_TraceAreas(move.endpos, teststart, areas, NULL, sizeof(areas) / sizeof(int));
numareas = AAS_TraceAreas(move.endpos, teststart, areas, NULL, ARRAY_LEN(areas));
for (j = 0; j < numareas; j++)
{
if (areas[j] == area2num)
Expand Down Expand Up @@ -4254,7 +4254,7 @@ void AAS_Reachability_WalkOffLedge(int areanum)
break;
} //end if
//if not going through a cluster portal
numareas = AAS_TraceAreas(mid, testend, areas, NULL, sizeof(areas) / sizeof(int));
numareas = AAS_TraceAreas(mid, testend, areas, NULL, ARRAY_LEN(areas));
for (p = 0; p < numareas; p++)
if (AAS_AreaClusterPortal(areas[p]))
break;
Expand Down
4 changes: 2 additions & 2 deletions code/cgame/cg_consolecmds.c
Expand Up @@ -518,7 +518,7 @@ qboolean CG_ConsoleCommand( void ) {

cmd = CG_Argv(0);

for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
for ( i = 0 ; i < ARRAY_LEN( commands ) ; i++ ) {
if ( !Q_stricmp( cmd, commands[i].cmd ) ) {
commands[i].function();
return qtrue;
Expand All @@ -540,7 +540,7 @@ so it can perform tab completion
void CG_InitConsoleCommands( void ) {
int i;

for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) {
for ( i = 0 ; i < ARRAY_LEN( commands ) ; i++ ) {
trap_AddCommand( commands[i].cmd );
}

Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_main.c
Expand Up @@ -316,7 +316,7 @@ static cvarTable_t cvarTable[] = {
// { &cg_pmove_fixed, "cg_pmove_fixed", "0", CVAR_USERINFO | CVAR_ARCHIVE }
};

static int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] );
static int cvarTableSize = ARRAY_LEN( cvarTable );

/*
=================
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_servercmds.c
Expand Up @@ -44,7 +44,7 @@ static const orderTask_t validOrders[] = {
{ VOICECHAT_FOLLOWFLAGCARRIER, TEAMTASK_ESCORT }
};

static const int numValidOrders = sizeof(validOrders) / sizeof(orderTask_t);
static const int numValidOrders = ARRAY_LEN(validOrders);

#ifdef MISSIONPACK
static int CG_ValidOrder(const char *p) {
Expand Down
2 changes: 1 addition & 1 deletion code/game/bg_misc.c
Expand Up @@ -920,7 +920,7 @@ Only in One Flag CTF games
{NULL}
};

int bg_numItems = sizeof(bg_itemlist) / sizeof(bg_itemlist[0]) - 1;
int bg_numItems = ARRAY_LEN( bg_itemlist ) - 1;


/*
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_active.c
Expand Up @@ -469,7 +469,7 @@ void ClientTimerActions( gentity_t *ent, int msec ) {
if( bg_itemlist[client->ps.stats[STAT_PERSISTANT_POWERUP]].giTag == PW_AMMOREGEN ) {
int w, max, inc, t, i;
int weapList[]={WP_MACHINEGUN,WP_SHOTGUN,WP_GRENADE_LAUNCHER,WP_ROCKET_LAUNCHER,WP_LIGHTNING,WP_RAILGUN,WP_PLASMAGUN,WP_BFG,WP_NAILGUN,WP_PROX_LAUNCHER,WP_CHAINGUN};
int weapCount = sizeof(weapList) / sizeof(int);
int weapCount = ARRAY_LEN( weapList );
//
for (i = 0; i < weapCount; i++) {
w = weapList[i];
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_cmds.c
Expand Up @@ -1158,7 +1158,7 @@ void Cmd_GameCommand_f( gentity_t *ent ) {
if ( player < 0 || player >= MAX_CLIENTS ) {
return;
}
if ( order < 0 || order > sizeof(gc_orders)/sizeof(char *) ) {
if ( order < 0 || order > ARRAY_LEN( gc_orders ) ) {
return;
}
G_Say( ent, &g_entities[player], SAY_TELL, gc_orders[order] );
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_combat.c
Expand Up @@ -486,7 +486,7 @@ void player_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int
killerName = "<world>";
}

if ( meansOfDeath < 0 || meansOfDeath >= sizeof( modNames ) / sizeof( modNames[0] ) ) {
if ( meansOfDeath < 0 || meansOfDeath >= ARRAY_LEN( modNames ) ) {
obit = "<bad obituary>";
} else {
obit = modNames[meansOfDeath];
Expand Down
2 changes: 1 addition & 1 deletion code/game/g_main.c
Expand Up @@ -181,7 +181,7 @@ static cvarTable_t gameCvarTable[] = {

};

static int gameCvarTableSize = sizeof( gameCvarTable ) / sizeof( gameCvarTable[0] );
static int gameCvarTableSize = ARRAY_LEN( gameCvarTable );


void G_InitGame( int levelTime, int randomSeed, int restart );
Expand Down
7 changes: 4 additions & 3 deletions code/game/g_public.h
Expand Up @@ -54,7 +54,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


typedef struct {
entityState_t s; // communicated by server to clients
entityState_t unused; // apparently this field was put here accidentally
// (and is kept only for compatibility, as a struct pad)

qboolean linked; // qfalse if not in any good cluster
int linkcount;
Expand Down Expand Up @@ -83,8 +84,8 @@ typedef struct {
// when a trace call is made and passEntityNum != ENTITYNUM_NONE,
// an ent will be excluded from testing if:
// ent->s.number == passEntityNum (don't interact with self)
// ent->s.ownerNum = passEntityNum (don't interact with your own missiles)
// entity[ent->s.ownerNum].ownerNum = passEntityNum (don't interact with other missiles from owner)
// ent->r.ownerNum == passEntityNum (don't interact with your own missiles)
// entity[ent->r.ownerNum].r.ownerNum == passEntityNum (don't interact with other missiles from owner)
int ownerNum;
} entityShared_t;

Expand Down
2 changes: 1 addition & 1 deletion code/q3_ui/ui_main.c
Expand Up @@ -217,7 +217,7 @@ static cvarTable_t cvarTable[] = {
{ &ui_ioq3, "ui_ioq3", "1", CVAR_ROM }
};

static int cvarTableSize = sizeof(cvarTable) / sizeof(cvarTable[0]);
static int cvarTableSize = ARRAY_LEN( cvarTable );


/*
Expand Down
6 changes: 3 additions & 3 deletions code/q3_ui/ui_video.c
Expand Up @@ -318,7 +318,7 @@ static InitialVideoOptions_s s_ivo_templates[] =
}
};

#define NUM_IVO_TEMPLATES ( sizeof( s_ivo_templates ) / sizeof( s_ivo_templates[0] ) )
#define NUM_IVO_TEMPLATES ( ARRAY_LEN( s_ivo_templates ) )

static const char *builtinResolutions[ ] =
{
Expand Down Expand Up @@ -496,7 +496,7 @@ static void GraphicsOptions_GetResolutions( void )
{
char* s = resbuf;
unsigned int i = 0;
while( s && i < sizeof(detectedResolutions)/sizeof(detectedResolutions[0])-1)
while( s && i < ARRAY_LEN(detectedResolutions)-1 )
{
detectedResolutions[i++] = s;
s = strchr(s, ' ');
Expand Down Expand Up @@ -662,7 +662,7 @@ static void GraphicsOptions_ApplyChanges( void *unused, int notification )
// search for builtin mode that matches the detected mode
int mode;
if ( s_graphicsoptions.mode.curvalue == -1
|| s_graphicsoptions.mode.curvalue >= sizeof(detectedResolutions)/sizeof(detectedResolutions[0]) )
|| s_graphicsoptions.mode.curvalue >= ARRAY_LEN( detectedResolutions ) )
s_graphicsoptions.mode.curvalue = 0;

mode = GraphicsOptions_FindBuiltinResolution( s_graphicsoptions.mode.curvalue );
Expand Down
2 changes: 1 addition & 1 deletion code/qcommon/files.c
Expand Up @@ -3459,7 +3459,7 @@ void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames )
fs_serverReferencedPaks[i] = atoi( Cmd_Argv( i ) );
}

for (i = 0 ; i < sizeof(fs_serverReferencedPakNames) / sizeof(*fs_serverReferencedPakNames); i++)
for (i = 0 ; i < ARRAY_LEN(fs_serverReferencedPakNames); i++)
{
if(fs_serverReferencedPakNames[i])
Z_Free(fs_serverReferencedPakNames[i]);
Expand Down
8 changes: 4 additions & 4 deletions code/qcommon/msg.c
Expand Up @@ -895,7 +895,7 @@ void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entity
float fullFloat;
int *fromF, *toF;

numFields = sizeof(entityStateFields)/sizeof(entityStateFields[0]);
numFields = ARRAY_LEN( entityStateFields );

// all fields should be 32 bits to avoid any compiler packing issues
// the "number" field is not part of the field list
Expand Down Expand Up @@ -1040,7 +1040,7 @@ void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to,
return;
}

numFields = sizeof(entityStateFields)/sizeof(entityStateFields[0]);
numFields = ARRAY_LEN( entityStateFields );
lc = MSG_ReadByte(msg);

if ( lc > numFields || lc < 0 ) {
Expand Down Expand Up @@ -1210,7 +1210,7 @@ void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct p

c = msg->cursize;

numFields = sizeof( playerStateFields ) / sizeof( playerStateFields[0] );
numFields = ARRAY_LEN( playerStateFields );

lc = 0;
for ( i = 0, field = playerStateFields ; i < numFields ; i++, field++ ) {
Expand Down Expand Up @@ -1377,7 +1377,7 @@ void MSG_ReadDeltaPlayerstate (msg_t *msg, playerState_t *from, playerState_t *t
print = 0;
}

numFields = sizeof( playerStateFields ) / sizeof( playerStateFields[0] );
numFields = ARRAY_LEN( playerStateFields );
lc = MSG_ReadByte(msg);

if ( lc > numFields || lc < 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion code/qcommon/q_shared.h
Expand Up @@ -194,7 +194,7 @@ typedef int clipHandle_t;
#define MAX_QINT 0x7fffffff
#define MIN_QINT (-MAX_QINT-1)

#define ARRAY_LEN(x) (sizeof(x) / sizeof(*x))
#define ARRAY_LEN(x) (sizeof(x) / sizeof(*(x)))


// angle indexes
Expand Down
6 changes: 3 additions & 3 deletions code/qcommon/vm.c
Expand Up @@ -346,7 +346,7 @@ intptr_t QDECL VM_DllSyscall( intptr_t arg, ... ) {
args[0] = arg;

va_start(ap, arg);
for (i = 1; i < sizeof (args) / sizeof (args[i]); i++)
for (i = 1; i < ARRAY_LEN (args); i++)
args[i] = va_arg(ap, intptr_t);
va_end(ap);

Expand Down Expand Up @@ -756,7 +756,7 @@ intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) {
int args[10];
va_list ap;
va_start(ap, callnum);
for (i = 0; i < sizeof (args) / sizeof (args[i]); i++) {
for (i = 0; i < ARRAY_LEN(args); i++) {
args[i] = va_arg(ap, int);
}
va_end(ap);
Expand All @@ -781,7 +781,7 @@ intptr_t QDECL VM_Call( vm_t *vm, int callnum, ... ) {

a.callnum = callnum;
va_start(ap, callnum);
for (i = 0; i < sizeof (a.args) / sizeof (a.args[0]); i++) {
for (i = 0; i < ARRAY_LEN(a.args); i++) {
a.args[i] = va_arg(ap, int);
}
va_end(ap);
Expand Down
4 changes: 2 additions & 2 deletions code/qcommon/vm_powerpc.c
Expand Up @@ -690,7 +690,7 @@ static const long int gpr_list[] = {
r7, r8, r9, r10,
};
static const long int gpr_vstart = 8; /* position of first volatile register */
static const long int gpr_total = sizeof( gpr_list ) / sizeof( gpr_list[0] );
static const long int gpr_total = ARRAY_LEN( gpr_list );

static const long int fpr_list[] = {
/* static registers, normally none is used */
Expand All @@ -704,7 +704,7 @@ static const long int fpr_list[] = {
f12, f13,
};
static const long int fpr_vstart = 8;
static const long int fpr_total = sizeof( fpr_list ) / sizeof( fpr_list[0] );
static const long int fpr_total = ARRAY_LEN( fpr_list );

/*
* prepare some dummy structures and emit init code
Expand Down
6 changes: 1 addition & 5 deletions code/qcommon/vm_powerpc_asm.c
Expand Up @@ -389,8 +389,7 @@ static const struct powerpc_operand powerpc_operands[] =

};

static const unsigned int num_powerpc_operands =
(sizeof (powerpc_operands) / sizeof (powerpc_operands[0]));
static const unsigned int num_powerpc_operands = ARRAY_LEN (powerpc_operands);

/* The functions used to insert and extract complicated operands. */

Expand Down Expand Up @@ -1004,6 +1003,3 @@ static const struct powerpc_opcode powerpc_opcodes[] = {
{ "fsub", A(63,20,0), AFRC_MASK, PPCCOM, { FRT, FRA, FRB } },
{ "fneg", XRC(63,40,0), XRA_MASK, COM, { FRT, FRB } },
};

static const int powerpc_num_opcodes =
sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
4 changes: 2 additions & 2 deletions code/qcommon/vm_sparc.c
Expand Up @@ -259,7 +259,7 @@ static const struct sparc_opcode sparc_opcodes[] = {
{ "fbg", BFCC(0,6), { ARG_DISP22 }, },
{ "fble", BFCC(0,13), { ARG_DISP22 }, },
};
#define SPARC_NUM_OPCODES (sizeof(sparc_opcodes) / sizeof(sparc_opcodes[0]))
#define SPARC_NUM_OPCODES (ARRAY_LEN(sparc_opcodes))

#define RS1(X) (((X) & 0x1f) << 14)
#define RS2(X) (((X) & 0x1f) << 0)
Expand Down Expand Up @@ -320,7 +320,7 @@ static unsigned int sparc_assemble(enum sparc_iname iname, const int argc, const

#define IN(inst, args...) \
({ const int argv[] = { args }; \
const int argc = sizeof(argv) / sizeof(argv[0]); \
const int argc = ARRAY_LEN(argv); \
sparc_assemble(inst, argc, argv); \
})

Expand Down
12 changes: 6 additions & 6 deletions code/qcommon/vm_x86_64_assembler.c
Expand Up @@ -243,7 +243,7 @@ static void hash_add_label(const char* label, unsigned address)
unsigned i = hashkey(label, -1U);
int labellen;

i %= sizeof(labelhash)/sizeof(labelhash[0]);
i %= ARRAY_LEN(labelhash);
h = Z_Malloc(sizeof(struct hashentry));

labellen = strlen(label) + 1;
Expand All @@ -259,7 +259,7 @@ static unsigned lookup_label(const char* label)
{
struct hashentry* h;
unsigned i = hashkey(label, -1U);
i %= sizeof(labelhash)/sizeof(labelhash[0]);
i %= ARRAY_LEN(labelhash);
for(h = labelhash[i]; h; h = h->next )
{
if(!strcmp(h->label, label))
Expand All @@ -275,7 +275,7 @@ static void labelhash_free(void)
struct hashentry* h;
unsigned i;
unsigned z = 0, min = -1U, max = 0, t = 0;
for ( i = 0; i < sizeof(labelhash)/sizeof(labelhash[0]); ++i)
for ( i = 0; i < ARRAY_LEN(labelhash); ++i)
{
unsigned n = 0;
h = labelhash[i];
Expand All @@ -293,7 +293,7 @@ static void labelhash_free(void)
min = MIN(min, n);
max = MAX(max, n);
}
printf("total %u, hsize %"PRIu64", zero %u, min %u, max %u\n", t, sizeof(labelhash)/sizeof(labelhash[0]), z, min, max);
printf("total %u, hsize %"PRIu64", zero %u, min %u, max %u\n", t, ARRAY_LEN(labelhash), z, min, max);
memset(labelhash, 0, sizeof(labelhash));
}

Expand Down Expand Up @@ -1015,7 +1015,7 @@ static op_t* getop(const char* n)
#else
unsigned m, t, b;
int r;
t = sizeof(ops)/sizeof(ops[0])-1;
t = ARRAY_LEN(ops)-1;
b = 0;

while(b <= t)
Expand Down Expand Up @@ -1306,7 +1306,7 @@ void assembler_init(int pass)
if(!ops_sorted)
{
ops_sorted = 1;
qsort(ops, sizeof(ops)/sizeof(ops[0])-1, sizeof(ops[0]), opsort);
qsort(ops, ARRAY_LEN(ops)-1, sizeof(ops[0]), opsort);
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/renderer/tr_init.c
Expand Up @@ -286,7 +286,7 @@ vidmode_t r_vidModes[] =
{ "Mode 10: 2048x1536", 2048, 1536, 1 },
{ "Mode 11: 856x480 (wide)",856, 480, 1 }
};
static int s_numVidModes = ( sizeof( r_vidModes ) / sizeof( r_vidModes[0] ) );
static int s_numVidModes = ARRAY_LEN( r_vidModes );

qboolean R_GetModeInfo( int *width, int *height, float *windowAspect, int mode ) {
vidmode_t *vm;
Expand Down
3 changes: 0 additions & 3 deletions code/renderer/tr_local.h
Expand Up @@ -1062,7 +1062,6 @@ extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
extern cvar_t *r_picmip; // controls picmip values
extern cvar_t *r_finish;
extern cvar_t *r_drawBuffer;
extern cvar_t *r_glDriver;
extern cvar_t *r_swapInterval;
extern cvar_t *r_textureMode;
extern cvar_t *r_offsetFactor;
Expand Down Expand Up @@ -1115,8 +1114,6 @@ extern cvar_t *r_saveFontData;

extern cvar_t *r_marksOnTriangleMeshes;

extern cvar_t *r_GLlibCoolDownMsec;

//====================================================================

float R_NoiseGet4f( float x, float y, float z, float t );
Expand Down

0 comments on commit fef4d12

Please sign in to comment.