From 945262b8635232e91e0a20d7dc663f539b1c875e Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Mon, 10 Jan 2011 10:35:40 +0000 Subject: [PATCH] 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 --- Quake/cl_main.c | 8 ++++---- Quake/cl_parse.c | 2 +- Quake/common.h | 12 ++++++++++-- Quake/console.c | 8 ++++---- Quake/gl_draw.c | 2 +- Quake/gl_fog.c | 6 +++--- Quake/gl_model.c | 16 ++++++++-------- Quake/gl_refrag.c | 2 +- Quake/gl_sky.c | 2 +- Quake/gl_texmgr.c | 6 +++--- Quake/host.c | 2 +- Quake/host_cmd.c | 2 +- Quake/mathlib.h | 23 ----------------------- Quake/menu.c | 2 +- Quake/r_part.c | 2 +- Quake/sbar.c | 6 +++--- Quake/snd_dma.c | 2 +- Quake/snd_mp3.c | 2 +- Quake/sv_main.c | 2 +- Quake/view.c | 4 ++-- Quake/zone.c | 2 +- 21 files changed, 49 insertions(+), 64 deletions(-) diff --git a/Quake/cl_main.c b/Quake/cl_main.c index 3a3fde11..1a5d34fc 100644 --- a/Quake/cl_main.c +++ b/Quake/cl_main.c @@ -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 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 diff --git a/Quake/cl_parse.c b/Quake/cl_parse.c index c38bd971..1dc8ca8d 100644 --- a/Quake/cl_parse.c +++ b/Quake/cl_parse.c @@ -1037,7 +1037,7 @@ void CL_ParseServerMessage (void) for (j=0; j (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 diff --git a/Quake/console.c b/Quake/console.c index 30dc1178..aac61683 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -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; diff --git a/Quake/gl_draw.c b/Quake/gl_draw.c index 321da1c7..154db163 100644 --- a/Quake/gl_draw.c +++ b/Quake/gl_draw.c @@ -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); diff --git a/Quake/gl_fog.c b/Quake/gl_fog.c index cb6f12ba..4909e6fa 100644 --- a/Quake/gl_fog.c +++ b/Quake/gl_fog.c @@ -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, diff --git a/Quake/gl_model.c b/Quake/gl_model.c index 9c1b3b0c..91721075 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -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) diff --git a/Quake/gl_refrag.c b/Quake/gl_refrag.c index 20a6a044..36b0035c 100644 --- a/Quake/gl_refrag.c +++ b/Quake/gl_refrag.c @@ -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); } /* diff --git a/Quake/gl_sky.c b/Quake/gl_sky.c index 0658a904..d56e3259 100644 --- a/Quake/gl_sky.c +++ b/Quake/gl_sky.c @@ -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; diff --git a/Quake/gl_texmgr.c b/Quake/gl_texmgr.c index 9f0b626a..00d6a537 100644 --- a/Quake/gl_texmgr.c +++ b/Quake/gl_texmgr.c @@ -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) diff --git a/Quake/host.c b/Quake/host.c index 2bd4ad3e..fedcd06f 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -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 diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index b0b78d67..657c583c 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -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 diff --git a/Quake/mathlib.h b/Quake/mathlib.h index e2f83820..0e85a023 100644 --- a/Quake/mathlib.h +++ b/Quake/mathlib.h @@ -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 diff --git a/Quake/menu.c b/Quake/menu.c index e26508e2..5b47f942 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -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); diff --git a/Quake/r_part.c b/Quake/r_part.c index e957fb9c..af65669b 100644 --- a/Quake/r_part.c +++ b/Quake/r_part.c @@ -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; } diff --git a/Quake/sbar.c b/Quake/sbar.c index aa6fcea0..dab24f8a 100644 --- a/Quake/sbar.c +++ b/Quake/sbar.c @@ -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; ispeed); samps = shm->samples >> (shm->channels - 1); - endtime = min(endtime, (unsigned int)(soundtime + samps)); + endtime = q_min(endtime, (unsigned int)(soundtime + samps)); S_PaintChannels (endtime); diff --git a/Quake/snd_mp3.c b/Quake/snd_mp3.c index 3b114962..79710677 100644 --- a/Quake/snd_mp3.c +++ b/Quake/snd_mp3.c @@ -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) { diff --git a/Quake/sv_main.c b/Quake/sv_main.c index aef4b675..b76f5a87 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -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 } diff --git a/Quake/view.c b/Quake/view.c index 85154933..2df8d174 100644 --- a/Quake/view.c +++ b/Quake/view.c @@ -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); diff --git a/Quake/zone.c b/Quake/zone.c index 7bf330c9..4c1b708a 100644 --- a/Quake/zone.c +++ b/Quake/zone.c @@ -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; }