Skip to content

Commit

Permalink
[Shared] Rename min/max macro to Q_min/Q_max
Browse files Browse the repository at this point in the history
Should hopefully remove some warnings and build errors...
  • Loading branch information
xycaleth committed Feb 8, 2015
1 parent ec97ad1 commit e6464f3
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 42 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,21 @@ set(SharedDir ${CMAKE_SOURCE_DIR}/shared)

# Common settings
if(WIN32)
set(SharedDefines "NOMINMAX")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") # enable parallel compilation
endif(MSVC)
if(WIN64)
set(SharedDefines ${SharedDefines} "WIN64")
if(MSVC)
set(SharedDefines "WIN64" "_CRT_SECURE_NO_WARNINGS")
set(SharedDefines ${SharedDefines} "_CRT_SECURE_NO_WARNINGS")
else()
set(SharedDefines "WIN64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
endif()
else()
if(MSVC)
set(SharedDefines "_CRT_SECURE_NO_WARNINGS")
set(SharedDefines ${SharedDefines} "_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
endif()
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ qboolean CG_Credits_Draw( void )
int iYpos = SCREEN_HEIGHT + (CreditLine.iLine * iFontHeight);
iYpos-= (int) (fPixelsPerSecond * fSecondsElapsed);

int iTextLinesThisItem = (std::max)( (int)CreditLine.vstrText.size(), 1);
int iTextLinesThisItem = Q_max( (int)CreditLine.vstrText.size(), 1);
if (iYpos + (iTextLinesThisItem * iFontHeight) < 0)
{
// scrolled off top of screen, so erase it...
Expand Down
2 changes: 1 addition & 1 deletion code/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6064,7 +6064,7 @@ static void UpdateEAXListener()
float flSin = (float)sin(-flTheta);
float flCos = (float)cos(-flTheta);

for (i = 0; i < min(s_NumFXSlots,s_lNumEnvironments); i++)
for (i = 0; i < Q_min(s_NumFXSlots,s_lNumEnvironments); i++)
{
if (s_FXSlotInfo[i].lEnvID == s_EnvironmentID)
{
Expand Down
8 changes: 2 additions & 6 deletions code/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,8 @@ typedef unsigned long ulong;
typedef enum { qfalse=0, qtrue } qboolean;
#define qboolean int //don't want strict type checking on the qboolean

#ifndef min
#define min(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef max
#define max(x,y) ((x)>(y)?(x):(y))
#endif
#define Q_min(x,y) ((x)<(y)?(x):(y))
#define Q_max(x,y) ((x)>(y)?(x):(y))

#if defined (_MSC_VER) && (_MSC_VER >= 1600)

Expand Down
2 changes: 1 addition & 1 deletion code/rd-vanilla/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static void InitOpenGL( void )
qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.maxTextureSize );

// stubbed or broken drivers may have reported 0...
glConfig.maxTextureSize = max(0, glConfig.maxTextureSize);
glConfig.maxTextureSize = Q_max(0, glConfig.maxTextureSize);

// initialize extensions
GLimp_InitExtensions( );
Expand Down
22 changes: 11 additions & 11 deletions code/ui/ui_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const cha
// now print the cursor as well...
//
char sTemp[1024];
int iCopyCount = min((int)strlen(text), cursorPos);
iCopyCount = min(iCopyCount,(int)sizeof(sTemp));
int iCopyCount = Q_min((int)strlen(text), cursorPos);
iCopyCount = Q_min(iCopyCount,(int)sizeof(sTemp));

// copy text into temp buffer for pixel measure...
//
Expand Down Expand Up @@ -4601,15 +4601,15 @@ static void UI_DemoSetForceLevels( void )

if (pState)
{//i am carrying over from a previous level, so get the increased power! (non-core only)
uiInfo.forcePowerLevel[FP_HEAL] = max(pState->forcePowerLevel[FP_HEAL], uiInfo.forcePowerLevel[FP_HEAL]);
uiInfo.forcePowerLevel[FP_TELEPATHY]=max(pState->forcePowerLevel[FP_TELEPATHY], uiInfo.forcePowerLevel[FP_TELEPATHY]);
uiInfo.forcePowerLevel[FP_GRIP]=max(pState->forcePowerLevel[FP_GRIP], uiInfo.forcePowerLevel[FP_GRIP]);
uiInfo.forcePowerLevel[FP_LIGHTNING]=max(pState->forcePowerLevel[FP_LIGHTNING], uiInfo.forcePowerLevel[FP_LIGHTNING]);
uiInfo.forcePowerLevel[FP_PROTECT]=max(pState->forcePowerLevel[FP_PROTECT], uiInfo.forcePowerLevel[FP_PROTECT]);

uiInfo.forcePowerLevel[FP_ABSORB]=max(pState->forcePowerLevel[FP_ABSORB], uiInfo.forcePowerLevel[FP_ABSORB]);
uiInfo.forcePowerLevel[FP_DRAIN]=max(pState->forcePowerLevel[FP_DRAIN], uiInfo.forcePowerLevel[FP_DRAIN]);
uiInfo.forcePowerLevel[FP_RAGE]=max(pState->forcePowerLevel[FP_RAGE], uiInfo.forcePowerLevel[FP_RAGE]);
uiInfo.forcePowerLevel[FP_HEAL] = Q_max(pState->forcePowerLevel[FP_HEAL], uiInfo.forcePowerLevel[FP_HEAL]);
uiInfo.forcePowerLevel[FP_TELEPATHY]=Q_max(pState->forcePowerLevel[FP_TELEPATHY], uiInfo.forcePowerLevel[FP_TELEPATHY]);
uiInfo.forcePowerLevel[FP_GRIP]=Q_max(pState->forcePowerLevel[FP_GRIP], uiInfo.forcePowerLevel[FP_GRIP]);
uiInfo.forcePowerLevel[FP_LIGHTNING]=Q_max(pState->forcePowerLevel[FP_LIGHTNING], uiInfo.forcePowerLevel[FP_LIGHTNING]);
uiInfo.forcePowerLevel[FP_PROTECT]=Q_max(pState->forcePowerLevel[FP_PROTECT], uiInfo.forcePowerLevel[FP_PROTECT]);

uiInfo.forcePowerLevel[FP_ABSORB]=Q_max(pState->forcePowerLevel[FP_ABSORB], uiInfo.forcePowerLevel[FP_ABSORB]);
uiInfo.forcePowerLevel[FP_DRAIN]=Q_max(pState->forcePowerLevel[FP_DRAIN], uiInfo.forcePowerLevel[FP_DRAIN]);
uiInfo.forcePowerLevel[FP_RAGE]=Q_max(pState->forcePowerLevel[FP_RAGE], uiInfo.forcePowerLevel[FP_RAGE]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion codeJK2/cgame/cg_credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ qboolean CG_Credits_Draw( void )
int iYpos = SCREEN_HEIGHT + (CreditLine.iLine * iFontHeight);
iYpos-= (int) (fPixelsPerSecond * fSecondsElapsed);

int iTextLinesThisItem = (std::max)( (int)CreditLine.vstrText.size(), 1);
int iTextLinesThisItem = Q_max( (int)CreditLine.vstrText.size(), 1);
if (iYpos + (iTextLinesThisItem * iFontHeight) < 0)
{
// scrolled off top of screen, so erase it...
Expand Down
4 changes: 2 additions & 2 deletions codemp/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,8 +2104,8 @@ void CL_Frame ( int msec ) {
// if recording an avi, lock to a fixed fps
if ( CL_VideoRecording( ) && cl_aviFrameRate->integer && msec) {
if ( cls.state == CA_ACTIVE || cl_forceavidemo->integer) {
float fps = min(cl_aviFrameRate->value * com_timescale->value, 1000.0f);
float frameDuration = max(1000.0f / fps, 1.0f) + clc.aviVideoFrameRemainder;
float fps = Q_min(cl_aviFrameRate->value * com_timescale->value, 1000.0f);
float frameDuration = Q_max(1000.0f / fps, 1.0f) + clc.aviVideoFrameRemainder;
takeVideoFrame = qtrue;

msec = (int)frameDuration;
Expand Down
6 changes: 3 additions & 3 deletions codemp/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2773,8 +2773,8 @@ void S_GetSoundtime(void)

if( CL_VideoRecording( ) )
{
float fps = min(cl_aviFrameRate->value, 1000.0f);
float frameDuration = max(dma.speed / fps, 1.0f) + clc.aviSoundFrameRemainder;
float fps = Q_min(cl_aviFrameRate->value, 1000.0f);
float frameDuration = Q_max(dma.speed / fps, 1.0f) + clc.aviSoundFrameRemainder;
int msec = (int)frameDuration;
s_soundtime += msec;
clc.aviSoundFrameRemainder = frameDuration - msec;
Expand Down Expand Up @@ -6037,7 +6037,7 @@ void UpdateEAXListener()
float flSin = (float)sin(-flTheta);
float flCos = (float)cos(-flTheta);

for (i = 0; i < min(s_NumFXSlots,s_lNumEnvironments); i++)
for (i = 0; i < Q_min(s_NumFXSlots,s_lNumEnvironments); i++)
{
if (s_FXSlotInfo[i].lEnvID == s_EnvironmentID)
{
Expand Down
8 changes: 2 additions & 6 deletions codemp/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ typedef unsigned long ulong;

typedef enum qboolean_e { qfalse=0, qtrue } qboolean;

#ifndef min
#define min(x,y) ((x)<(y)?(x):(y))
#endif
#ifndef max
#define max(x,y) ((x)>(y)?(x):(y))
#endif
#define Q_min(x,y) ((x)<(y)?(x):(y))
#define Q_max(x,y) ((x)>(y)?(x):(y))

#if defined (_MSC_VER) && (_MSC_VER >= 1600)

Expand Down
4 changes: 2 additions & 2 deletions codemp/rd-dedicated/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ void R_Init( void ) {
}
R_Register();

max_polys = (std::min)( r_maxpolys->integer, DEFAULT_MAX_POLYS );
max_polyverts = (std::min)( r_maxpolyverts->integer, DEFAULT_MAX_POLYVERTS );
max_polys = Q_min( r_maxpolys->integer, DEFAULT_MAX_POLYS );
max_polyverts = Q_min( r_maxpolyverts->integer, DEFAULT_MAX_POLYVERTS );

ptr = (byte *)Hunk_Alloc( sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys + sizeof(polyVert_t) * max_polyverts, h_low);
backEndData = (backEndData_t *) ptr;
Expand Down
4 changes: 2 additions & 2 deletions codemp/rd-vanilla/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,8 +1694,8 @@ void R_Init( void ) {
R_NoiseInit();
R_Register();

max_polys = (std::min)( r_maxpolys->integer, DEFAULT_MAX_POLYS );
max_polyverts = (std::min)( r_maxpolyverts->integer, DEFAULT_MAX_POLYVERTS );
max_polys = Q_min( r_maxpolys->integer, DEFAULT_MAX_POLYS );
max_polyverts = Q_min( r_maxpolyverts->integer, DEFAULT_MAX_POLYVERTS );

ptr = (byte *)Hunk_Alloc( sizeof( *backEndData ) + sizeof(srfPoly_t) * max_polys + sizeof(polyVert_t) * max_polyverts, h_low);
backEndData = (backEndData_t *) ptr;
Expand Down
4 changes: 2 additions & 2 deletions shared/sdl/sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ void WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte bl
{
for( i = 0 ; i < 128 ; i++ )
{
table[j][i] = min(table[j][i], (128 + i) << 8);
table[j][i] = Q_min(table[j][i], (128 + i) << 8);
}

table[j][127] = min(table[j][127], 254 << 8);
table[j][127] = Q_min(table[j][127], 254 << 8);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared/sys/sys_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static const char *GetErrorString( DWORD error ) {
NULL, error, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPTSTR)&lpMsgBuf, 0, NULL );
if ( bufLen ) {
LPCSTR lpMsgStr = (LPCSTR)lpMsgBuf;
Q_strncpyz( buf, lpMsgStr, min( (size_t)(lpMsgStr + bufLen), sizeof(buf) ) );
Q_strncpyz( buf, lpMsgStr, Q_min( (size_t)(lpMsgStr + bufLen), sizeof(buf) ) );
LocalFree( lpMsgBuf );
}
}
Expand Down

0 comments on commit e6464f3

Please sign in to comment.