瀏覽代碼

Fixes an issue where min and max macros were conflicting with std::min and std::max in Windows. Changed fmin and fminf to use the std equivalent.

Darryl Gough 14 年之前
父節點
當前提交
0bccee7b74

+ 2 - 2
gameplay-encoder/src/FBXSceneEncoder.cpp

@@ -694,8 +694,8 @@ void FBXSceneEncoder::loadSkin(KFbxMesh* fbxMesh, Model* model)
 
             MeshSkin* skin = new MeshSkin();
 
-            std::list<std::string> jointNames;
-            std::list<Node*> joints;
+            std::vector<std::string> jointNames;
+            std::vector<Node*> joints;
             std::vector<Matrix> bindPoses;
 
             const int clusterCount = fbxSkin->GetClusterCount();

+ 8 - 19
gameplay/src/Base.h

@@ -35,6 +35,8 @@ using std::isdigit;
 using std::toupper;
 using std::tolower;
 using std::size_t;
+using std::min;
+using std::max;
 
 // Common
 #ifndef NULL
@@ -148,6 +150,11 @@ extern void printError(const char* format, ...);
 #define M_1_PI                      0.31830988618379067154
 #endif
 
+// NOMINMAX makes sure that windef.h doesn't add macros min and max
+#ifdef WIN32
+    #define NOMINMAX
+#endif
+
 // Audio (OpenAL)
 #ifdef __QNX__
 #include <AL/al.h>
@@ -267,25 +274,7 @@ extern GLenum __gl_error_code;
 #define GL_LAST_ERROR() __gl_error_code
 
 
-#if defined(WIN32) || defined(__APPLE__)
-
-    inline float fminf(float a, float b)
-    {
-      return a < b ? a : b;
-    }
-    inline float fmin(float a, float b)
-    {
-      return a < b ? a : b;
-    }
-    inline float fmaxf(float a, float b)
-    {
-      return a > b ? a : b;
-    }
-    inline float fmax(float a, float b)
-    {
-      return a > b ? a : b;
-    }
-        
+#if defined(WIN32)
     #pragma warning( disable : 4172 )
     #pragma warning( disable : 4244 )
     #pragma warning( disable : 4311 )

+ 12 - 12
gameplay/src/BoundingBox.cpp

@@ -206,14 +206,14 @@ bool BoundingBox::isEmpty() const
 void BoundingBox::merge(const BoundingBox& box)
 {
     // Calculate the new minimum point.
-    min.x = fminf(min.x, box.min.x);
-    min.y = fminf(min.y, box.min.y);
-    min.z = fminf(min.z, box.min.z);
+    min.x = std::min(min.x, box.min.x);
+    min.y = std::min(min.y, box.min.y);
+    min.z = std::min(min.z, box.min.z);
 
     // Calculate the new maximum point.
-    max.x = fmaxf(max.x, box.max.x);
-    max.y = fmaxf(max.y, box.max.y);
-    max.z = fmaxf(max.z, box.max.z);
+    max.x = std::max(max.x, box.max.x);
+    max.y = std::max(max.y, box.max.y);
+    max.z = std::max(max.z, box.max.z);
 }
 
 void BoundingBox::merge(const BoundingSphere& sphere)
@@ -222,14 +222,14 @@ void BoundingBox::merge(const BoundingSphere& sphere)
     float radius = sphere.radius;
 
     // Calculate the new minimum point for the merged bounding box.
-    min.x = fminf(min.x, center.x - radius);
-    min.y = fminf(min.y, center.y - radius);
-    min.z = fminf(min.z, center.z - radius);
+    min.x = std::min(min.x, center.x - radius);
+    min.y = std::min(min.y, center.y - radius);
+    min.z = std::min(min.z, center.z - radius);
 
     // Calculate the new maximum point for the merged bounding box.
-    max.x = fmaxf(max.x, center.x + radius);
-    max.y = fmaxf(max.y, center.y + radius);
-    max.z = fmaxf(max.z, center.z + radius);
+    max.x = std::max(max.x, center.x + radius);
+    max.y = std::max(max.y, center.y + radius);
+    max.z = std::max(max.z, center.z + radius);
 }
 
 void BoundingBox::set(const Vector3& min, const Vector3& max)

+ 2 - 2
gameplay/src/BoundingSphere.cpp

@@ -290,8 +290,8 @@ void BoundingSphere::transform(const Matrix& matrix)
     // Calculate the sphere's new radius from the radii in each direction (take the largest).
     matrix.decompose(&translate, NULL, NULL);
     float r = radius * translate.x;
-    r = fmaxf(radius, radius * translate.y);
-    r = fmaxf(radius, radius * translate.z);
+    r = max(radius, radius * translate.y);
+    r = max(radius, radius * translate.z);
     radius = r;
 }
 

+ 1 - 1
gameplay/src/Model.cpp

@@ -218,7 +218,7 @@ void Model::setNode(Node* node)
 
 void Model::draw(bool wireframe)
 {
-    wireframe &= (_mesh->getPrimitiveType() == Mesh::TRIANGLES | _mesh->getPrimitiveType() == Mesh::TRIANGLE_STRIP);
+    wireframe &= (_mesh->getPrimitiveType() == Mesh::TRIANGLES) | (_mesh->getPrimitiveType() == Mesh::TRIANGLE_STRIP);
     unsigned int count = _mesh->getPartCount();
     if (count == 0)
     {

+ 2 - 2
gameplay/src/PlatformMacOS.mm

@@ -217,8 +217,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
         __pitch -= (float)(point.y - (WINDOW_HEIGHT - __ly)) * ACCELEROMETER_Y_FACTOR;
     
         // Clamp the values to the valid range.
-        __roll = fmaxf(fminf(__roll, 90.0), -90.0);
-        __pitch = fmaxf(fminf(__pitch, 90.0), -90.0);
+        __roll = max(min(__roll, 90.0f), -90.0f);
+        __pitch = max(min(__pitch, 90.0f), -90.0f);
     
         // Update the last X/Y values.
         __lx = point.x;

+ 2 - 4
gameplay/src/PlatformWin32.cpp

@@ -5,8 +5,6 @@
 #include "FileSystem.h"
 #include "Game.h"
 
-using namespace std;
-
 static long __timeTicksPerMillis;
 static long __timeStart;
 static long __timeAbsolute;
@@ -307,8 +305,8 @@ LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
             __pitch += (float)(HIWORD(lParam) - ly) * ACCELEROMETER_Y_FACTOR;
 
             // Clamp the values to the valid range.
-            __roll = max(min(__roll, 90.0), -90.0);
-            __pitch = max(min(__pitch, 90.0), -90.0);
+            __roll = max(min(__roll, 90.0f), -90.0f);
+            __pitch = max(min(__pitch, 90.0f), -90.0f);
 
             // Update the last X/Y values.
             lx = LOWORD(lParam);

+ 5 - 5
gameplay/src/Ray.cpp

@@ -94,11 +94,11 @@ float Ray::intersects(const Frustum& frustum) const
 
     // Otherwise, the intersection distance is the minimum positive intersection distance.
     float d = (nD > 0.0f) ? nD : 0.0f;
-    d = (fD > 0.0f) ? ( (d == 0.0f) ? fD : fminf(fD, d) ) : d;
-    d = (lD > 0.0f) ? ( (d == 0.0f) ? lD : fminf(lD, d) ) : d;
-    d = (rD > 0.0f) ? ( (d == 0.0f) ? rD : fminf(rD, d) ) : d;
-    d = (tD > 0.0f) ? ( (d == 0.0f) ? bD : fminf(bD, d) ) : d;
-    d = (bD > 0.0f) ? ( (d == 0.0f) ? tD : fminf(tD, d) ) : d;
+    d = (fD > 0.0f) ? ( (d == 0.0f) ? fD : min(fD, d) ) : d;
+    d = (lD > 0.0f) ? ( (d == 0.0f) ? lD : min(lD, d) ) : d;
+    d = (rD > 0.0f) ? ( (d == 0.0f) ? rD : min(rD, d) ) : d;
+    d = (tD > 0.0f) ? ( (d == 0.0f) ? bD : min(bD, d) ) : d;
+    d = (bD > 0.0f) ? ( (d == 0.0f) ? tD : min(tD, d) ) : d;
 
     return d;
 }

+ 8 - 8
gameplay/src/Rectangle.cpp

@@ -89,10 +89,10 @@ bool Rectangle::contains(const Rectangle& r) const
 
 bool Rectangle::intersects(float x, float y, float width, float height) const
 {
-    const float left   = fmaxf(this->x, x);
-    const float top    = fmaxf(this->y, y);
-    const float right  = fminf(x + width, x + width);
-    const float bottom = fminf(y + height, y + height);
+    const float left   = max(this->x, x);
+    const float top    = max(this->y, y);
+    const float right  = min(x + width, x + width);
+    const float bottom = min(y + height, y + height);
 
     return (right > left && bottom > top);
 }
@@ -104,10 +104,10 @@ bool Rectangle::intersects(const Rectangle& r) const
 
 void Rectangle::combine(const Rectangle& r1, const Rectangle& r2, Rectangle* dst)
 {
-    dst->x = fminf(r1.x, r2.x);
-    dst->y = fminf(r1.y, r2.y);
-    dst->width = fmaxf(r1.x + r1.width, r2.x + r2.width) - dst->x;
-    dst->height = fmaxf(r1.y + r1.height, r2.y + r2.height) - dst->y;
+    dst->x = min(r1.x, r2.x);
+    dst->y = min(r1.y, r2.y);
+    dst->width = max(r1.x + r1.width, r2.x + r2.width) - dst->x;
+    dst->height = max(r1.y + r1.height, r2.y + r2.height) - dst->y;
 }
 
 void Rectangle::inflate(float horizontalAmount, float verticalAmount)