min/max macros: renamed them to q_min and q_max, moved them common.h.

removed the inline versions which only handled integers.  moved CLAMP
macro to common.h.  Adjusted all places for the renamed macros.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@386 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2011-01-10 10:35:40 +00:00
parent fb42d29443
commit 945262b863
21 changed files with 49 additions and 64 deletions

View file

@ -632,13 +632,13 @@ int CL_ReadFromServer (void)
if (cl_numvisedicts > 256 && dev_peakstats.visedicts <= 256)
Con_Warning ("%i visedicts exceeds standard limit of 256.\n", cl_numvisedicts);
dev_stats.visedicts = cl_numvisedicts;
dev_peakstats.visedicts = max(cl_numvisedicts, dev_peakstats.visedicts);
dev_peakstats.visedicts = q_max(cl_numvisedicts, dev_peakstats.visedicts);
//temp entities
if (num_temp_entities > 64 && dev_peakstats.tempents <= 64)
Con_Warning ("%i tempentities exceeds standard limit of 64.\n", num_temp_entities);
dev_stats.tempents = num_temp_entities;
dev_peakstats.tempents = max(num_temp_entities, dev_peakstats.tempents);
dev_peakstats.tempents = q_max(num_temp_entities, dev_peakstats.tempents);
//beams
for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
@ -647,7 +647,7 @@ int CL_ReadFromServer (void)
if (num_beams > 24 && dev_peakstats.beams <= 24)
Con_Warning ("%i beams exceeded standard limit of 24.\n", num_beams);
dev_stats.beams = num_beams;
dev_peakstats.beams = max(num_beams, dev_peakstats.beams);
dev_peakstats.beams = q_max(num_beams, dev_peakstats.beams);
//dlights
for (i=0, l=cl_dlights ; i<MAX_DLIGHTS ; i++, l++)
@ -656,7 +656,7 @@ int CL_ReadFromServer (void)
if (num_dlights > 32 && dev_peakstats.dlights <= 32)
Con_Warning ("%i dlights exceeded standard limit of 32.\n", num_dlights);
dev_stats.dlights = num_dlights;
dev_peakstats.dlights = max(num_dlights, dev_peakstats.dlights);
dev_peakstats.dlights = q_max(num_dlights, dev_peakstats.dlights);
//johnfitz

View file

@ -1037,7 +1037,7 @@ void CL_ParseServerMessage (void)
for (j=0; j<cl_lightstyle[i].length; j++)
{
total += cl_lightstyle[i].map[j] - 'a';
cl_lightstyle[i].peak = max(cl_lightstyle[i].peak, cl_lightstyle[i].map[j]);
cl_lightstyle[i].peak = q_max(cl_lightstyle[i].peak, cl_lightstyle[i].map[j]);
}
cl_lightstyle[i].average = total / cl_lightstyle[i].length + 'a';
}

View file

@ -36,11 +36,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* 'var' : conversion from 'size_t' to 'type',
possible loss of data (/Wp64 warning) */
/* MSC doesn't have fmin() / fmax(), use the min/max macros: */
#define fmax max
#define fmin min
#define fmax q_max
#define fmin q_min
#endif /* _MSC_VER */
#endif /* _WIN32 */
#undef min
#undef max
#define q_min(a, b) (((a) < (b)) ? (a) : (b))
#define q_max(a, b) (((a) > (b)) ? (a) : (b))
#define CLAMP(_minval, x, _maxval) \
((x) < (_minval) ? (_minval) : \
(x) > (_maxval) ? (_maxval) : (x))
typedef struct sizebuf_s
{
qboolean allowoverflow; // if false, do a Sys_Error

View file

@ -80,8 +80,8 @@ const char *Con_Quakebar (int len)
static char bar[42];
int i;
len = min(len, sizeof(bar) - 2);
len = min(len, con_linewidth);
len = q_min(len, sizeof(bar) - 2);
len = q_min(len, con_linewidth);
bar[0] = '\35';
for (i = 1; i < len - 1; i++)
@ -331,7 +331,7 @@ void Con_Init (void)
{
//johnfitz -- user settable console buffer size
if (COM_CheckParm("-consize"))
con_buffersize = max(CON_MINSIZE,Q_atoi(com_argv[COM_CheckParm("-consize")+1])*1024);
con_buffersize = q_max(CON_MINSIZE,Q_atoi(com_argv[COM_CheckParm("-consize")+1])*1024);
else
con_buffersize = CON_TEXTSIZE;
//johnfitz
@ -642,7 +642,7 @@ void Con_CenterPrintf (int linewidth, const char *fmt, ...)
q_vsnprintf (msg, sizeof(msg), fmt, argptr);
va_end (argptr);
linewidth = min (linewidth, con_linewidth);
linewidth = q_min(linewidth, con_linewidth);
for (src = msg; *src; )
{
dst = line;

View file

@ -756,7 +756,7 @@ void GL_SetCanvas (canvastype newcanvas)
glViewport (glx, gly, glwidth, glheight);
break;
case CANVAS_MENU:
s = min ((float)glwidth / 320.0, (float)glheight / 200.0);
s = q_min((float)glwidth / 320.0, (float)glheight / 200.0);
s = CLAMP (1.0, scr_menuscale.value, s);
glOrtho (0, 320, 200, 0, -99999, 99999);
glViewport (glx + (glwidth - 320*s) / 2, gly + (glheight - 200*s) / 2, 320*s, 200*s);

View file

@ -96,7 +96,7 @@ void Fog_ParseServerMessage (void)
red = MSG_ReadByte() / 255.0;
green = MSG_ReadByte() / 255.0;
blue = MSG_ReadByte() / 255.0;
time = max(0.0, MSG_ReadShort() / 100.0);
time = q_max(0.0, MSG_ReadShort() / 100.0);
Fog_Update (density, red, green, blue, time);
}
@ -125,14 +125,14 @@ void Fog_FogCommand_f (void)
Con_Printf(" \"blue\" is \"%f\"\n", fog_blue);
break;
case 2:
Fog_Update(max(0.0, atof(Cmd_Argv(1))),
Fog_Update(q_max(0.0, atof(Cmd_Argv(1))),
fog_red,
fog_green,
fog_blue,
0.0);
break;
case 3: //TEST
Fog_Update(max(0.0, atof(Cmd_Argv(1))),
Fog_Update(q_max(0.0, atof(Cmd_Argv(1))),
fog_red,
fog_green,
fog_blue,

View file

@ -1501,21 +1501,21 @@ void Mod_BoundsFromClipNode (model_t *mod, int hull, int nodenum)
case PLANE_X:
if (plane->signbits == 1)
mod->clipmins[0] = min (mod->clipmins[0], -plane->dist - mod->hulls[hull].clip_mins[0]);
mod->clipmins[0] = q_min(mod->clipmins[0], -plane->dist - mod->hulls[hull].clip_mins[0]);
else
mod->clipmaxs[0] = max (mod->clipmaxs[0], plane->dist - mod->hulls[hull].clip_maxs[0]);
mod->clipmaxs[0] = q_max(mod->clipmaxs[0], plane->dist - mod->hulls[hull].clip_maxs[0]);
break;
case PLANE_Y:
if (plane->signbits == 2)
mod->clipmins[1] = min (mod->clipmins[1], -plane->dist - mod->hulls[hull].clip_mins[1]);
mod->clipmins[1] = q_min(mod->clipmins[1], -plane->dist - mod->hulls[hull].clip_mins[1]);
else
mod->clipmaxs[1] = max (mod->clipmaxs[1], plane->dist - mod->hulls[hull].clip_maxs[1]);
mod->clipmaxs[1] = q_max(mod->clipmaxs[1], plane->dist - mod->hulls[hull].clip_maxs[1]);
break;
case PLANE_Z:
if (plane->signbits == 4)
mod->clipmins[2] = min (mod->clipmins[2], -plane->dist - mod->hulls[hull].clip_mins[2]);
mod->clipmins[2] = q_min(mod->clipmins[2], -plane->dist - mod->hulls[hull].clip_mins[2]);
else
mod->clipmaxs[2] = max (mod->clipmaxs[2], plane->dist - mod->hulls[hull].clip_maxs[2]);
mod->clipmaxs[2] = q_max(mod->clipmaxs[2], plane->dist - mod->hulls[hull].clip_maxs[2]);
break;
default:
//skip nonaxial planes; don't need them
@ -1953,8 +1953,8 @@ void Mod_CalcAliasBounds (aliashdr_t *a)
for (k=0; k<3;k++)
{
loadmodel->mins[k] = min (loadmodel->mins[k], v[k]);
loadmodel->maxs[k] = max (loadmodel->maxs[k], v[k]);
loadmodel->mins[k] = q_min(loadmodel->mins[k], v[k]);
loadmodel->maxs[k] = q_max(loadmodel->maxs[k], v[k]);
}
dist = v[0] * v[0] + v[1] * v[1];
if (yawradius < dist)

View file

@ -180,7 +180,7 @@ void R_CheckEfrags (void)
Con_Warning ("%i efrags exceeds standard limit of 640.\n", count);
dev_stats.efrags = count;
dev_peakstats.efrags = max(count, dev_peakstats.efrags);
dev_peakstats.efrags = q_max(count, dev_peakstats.efrags);
}
/*

View file

@ -896,7 +896,7 @@ void Sky_DrawFace (int axis)
VectorSubtract(verts[2],verts[3],vup);
VectorSubtract(verts[2],verts[1],vright);
di = max((int)r_sky_quality.value, 1);
di = q_max((int)r_sky_quality.value, 1);
qi = 1.0 / di;
dj = (axis < 4) ? di*2 : di; //subdivide vertically more than horizontally on skybox sides
qj = 1.0 / dj;

View file

@ -630,8 +630,8 @@ int TexMgr_SafeTextureSize (int s)
{
s = TexMgr_Pad(s);
if ((int)gl_max_size.value > 0)
s = min(TexMgr_Pad((int)gl_max_size.value), s);
s = min(gl_hardware_maxsize, s);
s = q_min(TexMgr_Pad((int)gl_max_size.value), s);
s = q_min(gl_hardware_maxsize, s);
return s;
}
@ -972,7 +972,7 @@ void TexMgr_LoadImage32 (gltexture_t *glt, unsigned *data)
glt->height = TexMgr_Pad(glt->height);
// mipmap down
picmip = (glt->flags & TEXPREF_NOPICMIP) ? 0 : max ((int)gl_picmip.value, 0);
picmip = (glt->flags & TEXPREF_NOPICMIP) ? 0 : q_max((int)gl_picmip.value, 0);
mipwidth = TexMgr_SafeTextureSize (glt->width >> picmip);
mipheight = TexMgr_SafeTextureSize (glt->height >> picmip);
while (glt->width > mipwidth)

View file

@ -639,7 +639,7 @@ void Host_ServerFrame (void)
if (active > 600 && dev_peakstats.edicts <= 600)
Con_Warning ("%i edicts exceeds standard limit of 600.\n", active);
dev_stats.edicts = active;
dev_peakstats.edicts = max(active, dev_peakstats.edicts);
dev_peakstats.edicts = q_max(active, dev_peakstats.edicts);
}
//johnfitz

View file

@ -981,7 +981,7 @@ void Host_SavegameComment (char *text)
for (i = 0; i < SAVEGAME_COMMENT_LENGTH; i++)
text[i] = ' ';
memcpy (text, cl.levelname, min(strlen(cl.levelname),22)); //johnfitz -- only copy 22 chars.
memcpy (text, cl.levelname, q_min(strlen(cl.levelname),22)); //johnfitz -- only copy 22 chars.
sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
memcpy (text+22, kills, strlen(kills));
// convert space to _ to make stdio happy

View file

@ -40,8 +40,6 @@ extern vec3_t vec3_origin;
#define nanmask (255<<23) /* 7F800000 */
#define IS_NAN(x) (((*(int *) &x) & nanmask) == nanmask)
#define CLAMP(_minval, x, _maxval) ((x) < (_minval) ? (_minval) : (x) > (_maxval) ? (_maxval) : (x))
#define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) //johnfitz -- from joequake
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
@ -63,27 +61,6 @@ extern vec3_t vec3_origin;
}\
}
// kristian - missing math functions
#if !defined(max)
#define max q_max
static inline int q_max (int x, int y)
{
if (x > y)
return x;
return y;
}
#endif
#if !defined(min)
#define min q_min
static inline int q_min (int x, int y)
{
if (x < y)
return x;
return y;
}
#endif
// kristian
void TurnVector (vec3_t out, const vec3_t forward, const vec3_t side, float angle); //johnfitz
void VectorAngles (const vec3_t forward, vec3_t angles); //johnfitz

View file

@ -1605,7 +1605,7 @@ void M_Quit_Draw (void) //johnfitz -- modified for new quit message
//okay, this is kind of fucked up. M_DrawTextBox will always act as if
//width is even. Also, the width and lines values are for the interior of the box,
//but the x and y values include the border.
boxlen = max(strlen(msg1),max((sizeof(msg2)-1),(sizeof(msg3)-1))) + 1;
boxlen = q_max(strlen(msg1), q_max((sizeof(msg2)-1),(sizeof(msg3)-1))) + 1;
if (boxlen & 1) boxlen++;
M_DrawTextBox (160-4*(boxlen+2), 76, boxlen, 4);

View file

@ -58,7 +58,7 @@ int R_ParticleTextureLookup (int x, int y, int sharpness)
r = x * x + y * y;
r = r > 255 ? 255 : r;
a = sharpness * (255 - r);
a = min(a,255);
a = q_min(a,255);
return a;
}

View file

@ -386,7 +386,7 @@ void Sbar_DrawNum (int x, int y, int num, int digits, int color)
char *ptr;
int l, frame;
num = min(999,num); //johnfitz -- cap high values rather than truncating number
num = q_min(999,num); //johnfitz -- cap high values rather than truncating number
l = Sbar_itoa (num, str);
ptr = str;
@ -666,7 +666,7 @@ void Sbar_DrawInventory (void)
// ammo counts
for (i=0 ; i<4 ; i++)
{
sprintf (num, "%3i", min(999,cl.stats[STAT_SHELLS+i])); //johnfitz -- cap displayed value to 999
sprintf (num, "%3i", q_min(999,cl.stats[STAT_SHELLS+i])); //johnfitz -- cap displayed value to 999
if (num[0] != ' ')
Sbar_DrawCharacter ( (6*i+1)*8 + 2, -24, 18 + num[0] - '0');
if (num[1] != ' ')
@ -777,7 +777,7 @@ void Sbar_DrawFrags (void)
Sbar_SortFrags ();
// draw the text
numscores = min (scoreboardlines, 4);
numscores = q_min(scoreboardlines, 4);
for (i=0, x=184; i<numscores; i++, x+=32)
{

View file

@ -934,7 +934,7 @@ static void S_Update_ (void)
// mix ahead of current position
endtime = soundtime + (unsigned int)(_snd_mixahead.value * shm->speed);
samps = shm->samples >> (shm->channels - 1);
endtime = min(endtime, (unsigned int)(soundtime + samps));
endtime = q_min(endtime, (unsigned int)(soundtime + samps));
S_PaintChannels (endtime);

View file

@ -278,7 +278,7 @@ static int mp3_decode(snd_stream_t *stream, byte *buf, int len)
do
{
x = (p->Synth.pcm.length - p->cursamp) * stream->info.channels;
donow = min(len, x);
donow = q_min(len, x);
i = 0;
while (i < donow)
{

View file

@ -694,7 +694,7 @@ stats:
if (msg->cursize > 1024 && dev_peakstats.packetsize <= 1024)
Con_Warning ("%i byte packet exceeds standard limit of 1024.\n", msg->cursize);
dev_stats.packetsize = msg->cursize;
dev_peakstats.packetsize = max(msg->cursize, dev_peakstats.packetsize);
dev_peakstats.packetsize = q_max(msg->cursize, dev_peakstats.packetsize);
//johnfitz
}

View file

@ -806,9 +806,9 @@ void V_CalcRefdef (void)
delta = (v_punchangles[0][i]-v_punchangles[1][i]) * host_frametime * 10;
if (delta > 0)
punch[i] = min(punch[i]+delta, v_punchangles[0][i]);
punch[i] = q_min(punch[i]+delta, v_punchangles[0][i]);
else if (delta < 0)
punch[i] = max(punch[i]+delta, v_punchangles[0][i]);
punch[i] = q_max(punch[i]+delta, v_punchangles[0][i]);
}
VectorAdd (r_refdef.viewangles, punch, r_refdef.viewangles);

View file

@ -237,7 +237,7 @@ void *Z_Realloc(void *ptr, int size)
Sys_Error ("Z_Realloc: failed on allocation of %i bytes", size);
if (ptr != old_ptr)
memmove (ptr, old_ptr, min (old_size, size));
memmove (ptr, old_ptr, q_min(old_size, size));
return ptr;
}