Skip to content

Instantly share code, notes, and snippets.

@leper
Created September 19, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leper/3196050457a8b74ba2e4 to your computer and use it in GitHub Desktop.
Save leper/3196050457a8b74ba2e4 to your computer and use it in GitHub Desktop.
Index: build/premake/extern_libs4.lua
===================================================================
--- build/premake/extern_libs4.lua (revision 15764)
+++ build/premake/extern_libs4.lua (working copy)
@@ -235,7 +235,8 @@
-- Suppress all the Boost warnings on OS X by including it as a system directory
buildoptions { "-isystem../" .. libraries_dir .. "boost/include" }
end
- if os.getversion().description == "OpenBSD" then
+-- if os.getversion().description == "OpenBSD" then
+ if os.is("bsd") then
includedirs { "/usr/local/include" }
end
end,
@@ -347,6 +348,8 @@
elseif os.is("macosx") then
add_default_include_paths("iconv")
defines { "LIBICONV_STATIC" }
+ elseif os.getversion().description == "FreeBSD" then
+ defines { "HAVE_ICONV_CONST" }
end
end,
link_settings = function()
@@ -357,6 +360,7 @@
win_names = { "libiconv" },
-- TODO: glibc provides symbols for this, so we should only include that (and depend on libiconv) on non-glibc unix
osx_names = { "iconv" },
+ bsd_names = { "iconv" },
dbg_suffix = "",
})
end,
Index: build/premake/premake4.lua
===================================================================
--- build/premake/premake4.lua (revision 15764)
+++ build/premake/premake4.lua (working copy)
@@ -37,6 +37,13 @@
dofile("extern_libs4.lua")
+cc = os.getenv("CC")
+if cc == nil or cc == "" then
+ -- TODO check if gcc exists and not on OS X
+ -- also include the OSX hack from below
+ cc = "gcc"
+end
+
-- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM)
arch = "x86"
if _OPTIONS["android"] then
@@ -50,7 +57,7 @@
if arch == "x86_64" or arch == "amd64" then
arch = "amd64"
else
- os.execute("gcc -dumpmachine > .gccmachine.tmp")
+ os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
local f = io.open(".gccmachine.tmp", "r")
local machine = f:read("*line")
f:close()
@@ -108,7 +115,7 @@
-- It's too late to do this test by the time we start compiling the PCH file, so
-- do the test in this build script instead (which is kind of ugly - please fix if
-- you have a better idea)
- if not _OPTIONS["icc"] then
+ if not _OPTIONS["icc"] and cc == "gcc" then
os.execute("gcc -dumpversion > .gccver.tmp")
local f = io.open(".gccver.tmp", "r")
major, dot, minor = f:read(1, 1, 1)
@@ -395,6 +402,8 @@
includedirs {
"/usr/X11R6/include/X11",
"/usr/X11R6/include",
+ "/usr/local/include/X11",
+ "/usr/local/include",
"/usr/include/X11"
}
libdirs { "/usr/X11R6/lib" }
Index: libraries/source/fcollada/include/FUtils/FUStringBuilder.hpp
===================================================================
--- libraries/source/fcollada/include/FUtils/FUStringBuilder.hpp (revision 15764)
+++ libraries/source/fcollada/include/FUtils/FUStringBuilder.hpp (working copy)
@@ -26,63 +26,6 @@
#define SAFE_DELETE_ARRAY(ptr) if (ptr != NULL) { delete [] ptr; ptr = NULL; }
#endif
-template <class Char, class FloatType>
-void FloatToString(FloatType f, Char* sz)
-{
- Char* buffer = sz + 1;
- static const int digitCount = 6;
- int decimal, sign;
-
- // ecvt rounds the string for us: http://www.datafocus.com/docs/man3/ecvt.3.asp
- char* end = ecvt(f, digitCount, &decimal, &sign);
-
- if (sign != 0) (*buffer++) = '-';
- int count = digitCount;
- if (decimal > digitCount)
- {
- // We use the scientific notation: P.MeX
- (*buffer++) = (*end++); // P is one character.
- (*buffer++) = '.';
-
- // Mantissa (cleaned for zeroes)
- for (--count; count > 0; --count) if (end[count - 1] != '0') break;
- for (int i = 0; i < count; ++i) (*buffer++) = (*end++);
- if (buffer[-1] == '.') --buffer;
-
- // Exponent
- (*buffer++) = 'e';
- uint32 exponent = decimal - 1; // X
- if (exponent >= 10) (*buffer++) = (Char) ('0' + (exponent / 10));
- (*buffer++) = (Char) ('0' + (exponent % 10));
- (*buffer) = 0;
- return;
- }
- else if (decimal > 0)
- {
- // Simple number: A.B
- for (int i = 0; i < decimal; ++i) (*buffer++) = (*end++);
- if (decimal < digitCount) (*buffer++) = '.';
- count = digitCount - decimal;
- }
- else if (decimal < -digitCount)
- {
- // What case is this?
- decimal = count = 0;
- }
- else if (decimal < 0 || (decimal == 0 && *end != '0'))
- {
- // Tiny number: 0.Me-X
- (*buffer++) = '0'; (*buffer++) = '.';
- for (int i = 0; i < -decimal; ++i) (*buffer++) = '0';
- count = digitCount + decimal;
- }
- for (; count > 0; --count) if (end[count - 1] != '0') break;
- for (int i = 0; i < count; ++i) (*buffer++) = (*end++);
- if (decimal == 0 && count == 0) (*buffer++) = '0';
- if (buffer[-1] == '.') --buffer;
- (*buffer) = 0;
-}
-
template <class Char>
FUStringBuilderT<Char>::FUStringBuilderT(const String& sz)
{
@@ -234,53 +177,50 @@
template <class Char>
void FUStringBuilderT<Char>::append(float f)
{
-#ifdef WIN32
- // use <float.h> _isnan method to detect the 1.#IND00 NaN.
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN() && !_isnan((double)f))
-#else
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN())
-#endif
- {
- if (IsEquivalent(f, 0.0f, std::numeric_limits<float>::epsilon())) append((Char)'0');
- else
- {
- Char sz[128];
- FloatToString(f, sz);
- append(sz + 1);
- }
- }
- else if (f == std::numeric_limits<float>::infinity())
- { append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else if (f == -std::numeric_limits<float>::infinity())
- { append((Char)'-'); append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else
- { append((Char)'N'); append((Char)'a'); append((Char)'N'); }
+ append((double)f);
}
template <class Char>
void FUStringBuilderT<Char>::append(double f)
{
-#ifdef WIN32
- // use <float.h> _isnan method to detect the .#IND00 NaN.
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN() && !_isnan(f))
-#else
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN())
-#endif
- {
- if (IsEquivalent(f, 0.0, std::numeric_limits<double>::epsilon())) append((Char)'0');
- else
- {
- Char sz[128];
- FloatToString(f, sz);
- append(sz + 1);
- }
+ if (f == -std::numeric_limits<double>::infinity()) {
+ append("-INF");
+ return;
+ } else if (f == std::numeric_limits<double>::infinity()) {
+ append("INF");
+ return;
+ } else if (f != f) {
+ append("NaN");
+ return;
+ } else if (-std::numeric_limits<double>::epsilon() < f && f < std::numeric_limits<double>::epsilon()) {
+ append("0.0E0");
+ return;
}
- else if (f == std::numeric_limits<double>::infinity())
- { append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else if (f == -std::numeric_limits<double>::infinity())
- { append((Char)'-'); append((Char)'I'); append((Char)'N'); append((Char)'F'); }
+
+ if (f < 0.0) {
+ f = -f;
+ append('-');
+ }
+
+ int e = 0;
+// e = floor(log10(f));
+// f = f / pow(10.0, e);
+
+ if (f < 1.0)
+ for (; f < 1.0; f *= 10.0)
+ e--;
else
- { append((Char)'N'); append((Char)'a'); append((Char)'N'); }
+ for (; f >= 10.0; f /= 10.0)
+ e++;
+
+ char tmp[10];
+ sprintf(tmp, "%.6g", f);
+ append(tmp);
+ if (tmp[1] == 0) // only one digit, add missing part according canonical representation
+ append(".0");
+
+ sprintf(tmp, "E%d", e);
+ append(tmp);
}
template <class Char>
Index: libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.hpp
===================================================================
--- libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.hpp (revision 15764)
+++ libraries/source/fcollada/src/FCollada/FUtils/FUStringBuilder.hpp (working copy)
@@ -26,63 +26,6 @@
#define SAFE_DELETE_ARRAY(ptr) if (ptr != NULL) { delete [] ptr; ptr = NULL; }
#endif
-template <class Char, class FloatType>
-void FloatToString(FloatType f, Char* sz)
-{
- Char* buffer = sz + 1;
- static const int digitCount = 6;
- int decimal, sign;
-
- // ecvt rounds the string for us: http://www.datafocus.com/docs/man3/ecvt.3.asp
- char* end = ecvt(f, digitCount, &decimal, &sign);
-
- if (sign != 0) (*buffer++) = '-';
- int count = digitCount;
- if (decimal > digitCount)
- {
- // We use the scientific notation: P.MeX
- (*buffer++) = (*end++); // P is one character.
- (*buffer++) = '.';
-
- // Mantissa (cleaned for zeroes)
- for (--count; count > 0; --count) if (end[count - 1] != '0') break;
- for (int i = 0; i < count; ++i) (*buffer++) = (*end++);
- if (buffer[-1] == '.') --buffer;
-
- // Exponent
- (*buffer++) = 'e';
- uint32 exponent = decimal - 1; // X
- if (exponent >= 10) (*buffer++) = (Char) ('0' + (exponent / 10));
- (*buffer++) = (Char) ('0' + (exponent % 10));
- (*buffer) = 0;
- return;
- }
- else if (decimal > 0)
- {
- // Simple number: A.B
- for (int i = 0; i < decimal; ++i) (*buffer++) = (*end++);
- if (decimal < digitCount) (*buffer++) = '.';
- count = digitCount - decimal;
- }
- else if (decimal < -digitCount)
- {
- // What case is this?
- decimal = count = 0;
- }
- else if (decimal < 0 || (decimal == 0 && *end != '0'))
- {
- // Tiny number: 0.Me-X
- (*buffer++) = '0'; (*buffer++) = '.';
- for (int i = 0; i < -decimal; ++i) (*buffer++) = '0';
- count = digitCount + decimal;
- }
- for (; count > 0; --count) if (end[count - 1] != '0') break;
- for (int i = 0; i < count; ++i) (*buffer++) = (*end++);
- if (decimal == 0 && count == 0) (*buffer++) = '0';
- if (buffer[-1] == '.') --buffer;
- (*buffer) = 0;
-}
-
template <class Char>
FUStringBuilderT<Char>::FUStringBuilderT(const String& sz)
{
@@ -234,53 +177,50 @@
template <class Char>
void FUStringBuilderT<Char>::append(float f)
{
-#ifdef WIN32
- // use <float.h> _isnan method to detect the 1.#IND00 NaN.
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN() && !_isnan((double)f))
-#else
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN())
-#endif
- {
- if (IsEquivalent(f, 0.0f, std::numeric_limits<float>::epsilon())) append((Char)'0');
- else
- {
- Char sz[128];
- FloatToString(f, sz);
- append(sz + 1);
- }
- }
- else if (f == std::numeric_limits<float>::infinity())
- { append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else if (f == -std::numeric_limits<float>::infinity())
- { append((Char)'-'); append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else
- { append((Char)'N'); append((Char)'a'); append((Char)'N'); }
+ append((double)f);
}
template <class Char>
void FUStringBuilderT<Char>::append(double f)
{
-#ifdef WIN32
- // use <float.h> _isnan method to detect the .#IND00 NaN.
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN() && !_isnan(f))
-#else
- if (f != std::numeric_limits<float>::infinity() && f != -std::numeric_limits<float>::infinity() && f != std::numeric_limits<float>::quiet_NaN() && f != std::numeric_limits<float>::signaling_NaN())
-#endif
- {
- if (IsEquivalent(f, 0.0, std::numeric_limits<double>::epsilon())) append((Char)'0');
- else
- {
- Char sz[128];
- FloatToString(f, sz);
- append(sz + 1);
- }
+ if (f == -std::numeric_limits<double>::infinity()) {
+ append("-INF");
+ return;
+ } else if (f == std::numeric_limits<double>::infinity()) {
+ append("INF");
+ return;
+ } else if (f != f) {
+ append("NaN");
+ return;
+ } else if (-std::numeric_limits<double>::epsilon() < f && f < std::numeric_limits<double>::epsilon()) {
+ append("0.0E0");
+ return;
}
- else if (f == std::numeric_limits<double>::infinity())
- { append((Char)'I'); append((Char)'N'); append((Char)'F'); }
- else if (f == -std::numeric_limits<double>::infinity())
- { append((Char)'-'); append((Char)'I'); append((Char)'N'); append((Char)'F'); }
+
+ if (f < 0.0) {
+ f = -f;
+ append('-');
+ }
+
+ int e = 0;
+// e = floor(log10(f));
+// f = f / pow(10.0, e);
+
+ if (f < 1.0)
+ for (; f < 1.0; f *= 10.0)
+ e--;
else
- { append((Char)'N'); append((Char)'a'); append((Char)'N'); }
+ for (; f >= 10.0; f /= 10.0)
+ e++;
+
+ char tmp[10];
+ sprintf(tmp, "%.6g", f);
+ append(tmp);
+ if (tmp[1] == 0) // only one digit, add missing part according canonical representation
+ append(".0");
+
+ sprintf(tmp, "E%d", e);
+ append(tmp);
}
template <class Char>
Index: libraries/source/fcollada/src/FCollada/FUtils/FUStringConversion.cpp
===================================================================
--- libraries/source/fcollada/src/FCollada/FUtils/FUStringConversion.cpp (revision 15764)
+++ libraries/source/fcollada/src/FCollada/FUtils/FUStringConversion.cpp (working copy)
@@ -16,6 +16,8 @@
#include "FUStringConversion.h"
#ifndef __APPLE__
#include "FUStringConversion.hpp"
+#else
+# error "fuuu"
#endif // __APPLE__
//
@@ -247,6 +249,7 @@
template FMVector4 FUStringConversion::ToVector4<char>(const char**);
template bool FUStringConversion::ToBoolean<char>(const char*);
+template int FUStringConversion::ToInt32<char>(const char**);
template unsigned int FUStringConversion::ToUInt32<char>(const char**);
template unsigned int FUStringConversion::HexToUInt32<char>(const char**, unsigned int);
Index: source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
===================================================================
--- source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp (revision 15764)
+++ source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp (working copy)
@@ -158,7 +158,7 @@
wxString x(xmlData->GetNodeContent());
unsigned long xTmp = 0;
x.ToULong(&xTmp);
- wxASSERT(xTmp <= (unsigned long)UINT32_MAX);
+ wxASSERT(xTmp <= (unsigned long)std::numeric_limits<unsigned int>::max());
actorSeed = xTmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment