From c33f7155e9aff9573c20d86e10c8158425a3d67a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 18 May 2020 17:46:25 -0700 Subject: [PATCH] Fix conflicts with std::min/max. --- public/mathlib/mathlib.h | 17 ++++++++--------- public/minmax.h | 8 ++++---- public/studio.h | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/public/mathlib/mathlib.h b/public/mathlib/mathlib.h index e8880761..a62706a8 100644 --- a/public/mathlib/mathlib.h +++ b/public/mathlib/mathlib.h @@ -350,12 +350,12 @@ FORCEINLINE void VectorClear(vec_t *a) FORCEINLINE float VectorMaximum(const vec_t *v) { - return max( v[0], max( v[1], v[2] ) ); + return V_max( v[0], V_max( v[1], v[2] ) ); } FORCEINLINE float VectorMaximum(const Vector& v) { - return max( v.x, max( v.y, v.z ) ); + return V_max( v.x, V_max( v.y, v.z ) ); } FORCEINLINE void VectorScale (const float* in, vec_t scale, float* out) @@ -380,7 +380,7 @@ inline void VectorNegate(vec_t *a) } -//#define VectorMaximum(a) ( max( (a)[0], max( (a)[1], (a)[2] ) ) ) +//#define VectorMaximum(a) ( V_max( (a)[0], V_max( (a)[1], (a)[2] ) ) ) #define Vector2Clear(x) {(x)[0]=(x)[1]=0;} #define Vector2Negate(x) {(x)[0]=-((x)[0]);(x)[1]=-((x)[1]);} #define Vector2Copy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];} @@ -1491,7 +1491,7 @@ FORCEINLINE unsigned char LinearToLightmap( float f ) FORCEINLINE void ColorClamp( Vector& color ) { - float maxc = max( color.x, max( color.y, color.z ) ); + float maxc = V_max( color.x, V_max( color.y, color.z ) ); if ( maxc > 1.0f ) { float ooMax = 1.0f / maxc; @@ -1987,10 +1987,10 @@ FORCEINLINE unsigned int * PackNormal_SHORT2( float nx, float ny, float nz, unsi ny *= 16384.0f; // '0' and '32768' values are invalid encodings - nx = max( nx, 1.0f ); // Make sure there are no zero values - ny = max( ny, 1.0f ); - nx = min( nx, 32767.0f ); // Make sure there are no 32768 values - ny = min( ny, 32767.0f ); + nx = V_max( nx, 1.0f ); // Make sure there are no zero values + ny = V_max( ny, 1.0f ); + nx = V_min( nx, 32767.0f ); // Make sure there are no 32768 values + ny = V_min( ny, 32767.0f ); if ( nz < 0.0f ) nx = -nx; // Set the sign bit for z @@ -2181,6 +2181,5 @@ inline bool AlmostEqual( const Vector &a, const Vector &b, int maxUlps = 10) AlmostEqual( a.z, b.z, maxUlps ); } - #endif // MATH_BASE_H diff --git a/public/minmax.h b/public/minmax.h index 4ebd498c..c302e4cd 100644 --- a/public/minmax.h +++ b/public/minmax.h @@ -8,11 +8,11 @@ #ifndef MINMAX_H #define MINMAX_H -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) +#ifndef V_min +#define V_min(a,b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) +#ifndef V_max +#define V_max(a,b) (((a) > (b)) ? (a) : (b)) #endif #endif // MINMAX_H diff --git a/public/studio.h b/public/studio.h index 9ead50fb..ced6bec6 100644 --- a/public/studio.h +++ b/public/studio.h @@ -1771,7 +1771,7 @@ struct thinModelVertices_t { Assert( ( m_numBoneInfluences >= 1 ) && ( m_numBoneInfluences <= 3 ) ); Assert( ( boneWeights.numbones >= 1 ) && ( boneWeights.numbones <= m_numBoneInfluences ) ); - int numStoredWeights = max( 0, ( m_numBoneInfluences - 1 ) ); + int numStoredWeights = V_max( 0, ( m_numBoneInfluences - 1 ) ); float *pBaseWeight = m_boneWeights + vertIndex*numStoredWeights; char *pBaseIndex = m_boneIndices + vertIndex*m_numBoneInfluences; for ( int i = 0; i < m_numBoneInfluences; i++ ) @@ -1841,7 +1841,7 @@ private: Assert( pBoneWeights ); Assert( ( m_numBoneInfluences <= 1 ) || ( m_boneWeights != NULL ) ); Assert( ( m_numBoneInfluences <= 0 ) || ( m_boneIndices != NULL ) ); - int numStoredWeights = max( 0, ( m_numBoneInfluences - 1 ) ); + int numStoredWeights = V_max( 0, ( m_numBoneInfluences - 1 ) ); float *pBaseWeight = m_boneWeights + vertIndex*numStoredWeights; char *pBaseIndex = m_boneIndices + vertIndex*m_numBoneInfluences; float sum = 0.0f;