Pārlūkot izejas kodu

Check for existence of sincosf / __sincosf instead of guessing. Closes #1294.

Lasse Öörni 9 gadi atpakaļ
vecāks
revīzija
e9b094c8d2

+ 11 - 0
Source/Urho3D/CMakeLists.txt

@@ -40,6 +40,17 @@ if (URHO3D_CLANG_TOOLS OR URHO3D_BINDINGS)
     endif ()
 endif ()
 
+# Check sincosf support
+include(CheckFunctionExists)
+CHECK_FUNCTION_EXISTS(sincosf HAVE_SINCOSF)
+CHECK_FUNCTION_EXISTS(__sincosf HAVE_UNDERSCORE_SINCOSF)
+if (HAVE_SINCOSF)
+    add_definitions (-DHAVE_SINCOSF)
+endif ()
+if (HAVE_UNDERSCORE_SINCOSF)
+    add_definitions (-DHAVE_UNDERSCORE_SINCOSF)
+endif ()
+
 add_definitions (-DURHO3D_IS_BUILDING)
 if (ODBC_VERSION AND NOT ODBC_VERSION VERSION_LESS 3)
     add_definitions (-DODBC_3_OR_LATER)

+ 45 - 0
Source/Urho3D/Math/MathDefs.cpp

@@ -0,0 +1,45 @@
+//
+// Copyright (c) 2008-2016 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "../Precompiled.h"
+
+#include "../Math/MathDefs.h"
+
+#include "../DebugNew.h"
+
+namespace Urho3D
+{
+
+void SinCos(float angle, float& sin, float& cos)
+{
+    float angleRadians = angle * M_DEGTORAD;
+#if defined(HAVE_SINCOSF)
+    sincosf(angleRadians, &sin, &cos);
+#elif defined(HAVE_UNDERSCORE_SINCOSF)
+    __sincosf(angleRadians, &sin, &cos);
+#else
+    sin = sinf(angleRadians);
+    cos = cosf(angleRadians);
+#endif
+}
+
+}

+ 3 - 17
Source/Urho3D/Math/MathDefs.h

@@ -163,23 +163,6 @@ template <class T>
 inline T Atan2(T y, T x) { return M_RADTODEG * atan2(y, x); }
 template <> inline float Atan2<float>(float y, float x) { return M_RADTODEG * atan2f(y, x); }
 
-/// Calculate both sine and cosine, with angle in degrees.
-inline void SinCos(float angle, float& sin, float& cos)
-{
-    float angleRadians = angle * M_DEGTORAD;
-    // glibc can be assumed to have the sincosf() function, while MSVC doesn't
-#ifndef __GNUC__
-    sin = sinf(angleRadians);
-    cos = cosf(angleRadians);
-#else
-    #ifdef __APPLE__
-        __sincosf(angleRadians, &sin, &cos);
-    #else
-        sincosf(angleRadians, &sin, &cos);
-    #endif
-#endif
-}
-
 /// Check whether an unsigned integer is a power of two.
 inline bool IsPowerOfTwo(unsigned value)
 {
@@ -273,6 +256,9 @@ inline float HalfToFloat(unsigned short value)
     return out;
 }
 
+/// Calculate both sine and cosine, with angle in degrees.
+URHO3D_API void SinCos(float angle, float& sin, float& cos);
+
 }
 
 #ifdef _MSC_VER