summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/src
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bx/src')
-rw-r--r--3rdparty/bx/src/allocator.cpp2
-rw-r--r--3rdparty/bx/src/amalgamated.cpp2
-rw-r--r--3rdparty/bx/src/bx.cpp91
-rw-r--r--3rdparty/bx/src/bx_p.h2
-rw-r--r--3rdparty/bx/src/commandline.cpp4
-rw-r--r--3rdparty/bx/src/crtnone.cpp6
-rw-r--r--3rdparty/bx/src/debug.cpp13
-rw-r--r--3rdparty/bx/src/dtoa.cpp2
-rw-r--r--3rdparty/bx/src/easing.cpp2
-rw-r--r--3rdparty/bx/src/file.cpp395
-rw-r--r--3rdparty/bx/src/filepath.cpp203
-rw-r--r--3rdparty/bx/src/hash.cpp2
-rw-r--r--3rdparty/bx/src/math.cpp383
-rw-r--r--3rdparty/bx/src/mutex.cpp3
-rw-r--r--3rdparty/bx/src/os.cpp40
-rw-r--r--3rdparty/bx/src/process.cpp6
-rw-r--r--3rdparty/bx/src/semaphore.cpp2
-rw-r--r--3rdparty/bx/src/settings.cpp2
-rw-r--r--3rdparty/bx/src/sort.cpp2
-rw-r--r--3rdparty/bx/src/string.cpp44
-rw-r--r--3rdparty/bx/src/thread.cpp70
-rw-r--r--3rdparty/bx/src/timer.cpp2
-rw-r--r--3rdparty/bx/src/url.cpp2
23 files changed, 734 insertions, 546 deletions
diff --git a/3rdparty/bx/src/allocator.cpp b/3rdparty/bx/src/allocator.cpp
index c26677edb25..50c1505874c 100644
--- a/3rdparty/bx/src/allocator.cpp
+++ b/3rdparty/bx/src/allocator.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/amalgamated.cpp b/3rdparty/bx/src/amalgamated.cpp
index d3f896b1416..e274b69019d 100644
--- a/3rdparty/bx/src/amalgamated.cpp
+++ b/3rdparty/bx/src/amalgamated.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/bx.cpp b/3rdparty/bx/src/bx.cpp
index 659cb5917cf..ab28bc25d2f 100644
--- a/3rdparty/bx/src/bx.cpp
+++ b/3rdparty/bx/src/bx.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -44,29 +44,29 @@ namespace bx
#endif // BX_CRT_NONE
}
- void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch)
+ void memCopy(
+ void* _dst
+ , uint32_t _dstStride
+ , const void* _src
+ , uint32_t _srcStride
+ , uint32_t _stride
+ , uint32_t _num
+ )
{
- const uint8_t* src = (const uint8_t*)_src;
- uint8_t* dst = (uint8_t*)_dst;
-
- for (uint32_t ii = 0; ii < _num; ++ii)
+ if (_stride == _srcStride
+ && _stride == _dstStride)
{
- memCopy(dst, src, _size);
- src += _srcPitch;
- dst += _dstPitch;
+ memCopy(_dst, _src, _stride*_num);
+ return;
}
- }
- ///
- void gather(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch)
- {
- memCopy(_dst, _src, _size, _num, _srcPitch, _size);
- }
+ const uint8_t* src = (const uint8_t*)_src;
+ uint8_t* dst = (uint8_t*)_dst;
- ///
- void scatter(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _dstPitch)
- {
- memCopy(_dst, _src, _size, _num, _size, _dstPitch);
+ for (uint32_t ii = 0; ii < _num; ++ii, src += _srcStride, dst += _dstStride)
+ {
+ memCopy(dst, src, _stride);
+ }
}
void memMoveRef(void* _dst, const void* _src, size_t _numBytes)
@@ -102,6 +102,31 @@ namespace bx
#endif // BX_CRT_NONE
}
+ void memMove(
+ void* _dst
+ , uint32_t _dstStride
+ , const void* _src
+ , uint32_t _srcStride
+ , uint32_t _stride
+ , uint32_t _num
+ )
+ {
+ if (_stride == _srcStride
+ && _stride == _dstStride)
+ {
+ memMove(_dst, _src, _stride*_num);
+ return;
+ }
+
+ const uint8_t* src = (const uint8_t*)_src;
+ uint8_t* dst = (uint8_t*)_dst;
+
+ for (uint32_t ii = 0; ii < _num; ++ii, src += _srcStride, dst += _dstStride)
+ {
+ memMove(dst, src, _stride);
+ }
+ }
+
void memSetRef(void* _dst, uint8_t _ch, size_t _numBytes)
{
uint8_t* dst = (uint8_t*)_dst;
@@ -121,6 +146,22 @@ namespace bx
#endif // BX_CRT_NONE
}
+ void memSet(void* _dst, uint32_t _dstStride, uint8_t _ch, uint32_t _stride, uint32_t _num)
+ {
+ if (_stride == _dstStride)
+ {
+ memSet(_dst, _ch, _stride*_num);
+ return;
+ }
+
+ uint8_t* dst = (uint8_t*)_dst;
+
+ for (uint32_t ii = 0; ii < _num; ++ii, dst += _dstStride)
+ {
+ memSet(dst, _ch, _stride);
+ }
+ }
+
int32_t memCmpRef(const void* _lhs, const void* _rhs, size_t _numBytes)
{
const char* lhs = (const char*)_lhs;
@@ -144,4 +185,16 @@ namespace bx
#endif // BX_CRT_NONE
}
+ ///
+ void gather(void* _dst, const void* _src, uint32_t _srcStride, uint32_t _stride, uint32_t _num)
+ {
+ memMove(_dst, _stride, _src, _srcStride, _stride, _num);
+ }
+
+ ///
+ void scatter(void* _dst, uint32_t _dstStride, const void* _src, uint32_t _stride, uint32_t _num)
+ {
+ memMove(_dst, _dstStride, _src, _stride, _num, _stride);
+ }
+
} // namespace bx
diff --git a/3rdparty/bx/src/bx_p.h b/3rdparty/bx/src/bx_p.h
index d4b00084de3..de02ccce2da 100644
--- a/3rdparty/bx/src/bx_p.h
+++ b/3rdparty/bx/src/bx_p.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/commandline.cpp b/3rdparty/bx/src/commandline.cpp
index df322560b56..d9f6fb4e8de 100644
--- a/3rdparty/bx/src/commandline.cpp
+++ b/3rdparty/bx/src/commandline.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -39,7 +39,7 @@ namespace bx
switch (state)
{
case SkipWhitespace:
- for (; isSpace(*curr); ++curr) {}; // skip whitespace
+ for (; isSpace(*curr) && *curr!=_term; ++curr) {}; // skip whitespace
state = SetTerm;
break;
diff --git a/3rdparty/bx/src/crtnone.cpp b/3rdparty/bx/src/crtnone.cpp
index 93579515c7f..72dd8747eaa 100644
--- a/3rdparty/bx/src/crtnone.cpp
+++ b/3rdparty/bx/src/crtnone.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -75,7 +75,7 @@ extern "C" char* strcat(char* _dst, const char* _src)
extern "C" const char* strchr(const char* _str, int _ch)
{
- return bx::strFind(_str, _ch);
+ return bx::strFind(_str, _ch).getPtr();
}
extern "C" int32_t strcmp(const char* _lhs, const char* _rhs)
@@ -95,7 +95,7 @@ extern "C" int32_t strcasecmp(const char* _lhs, const char* _rhs)
extern "C" const char* strstr(const char* _str, const char* _find)
{
- return bx::strFind(_str, _find);
+ return bx::strFind(_str, _find).getPtr();
}
extern "C" void qsort(void* _base, size_t _num, size_t _size, bx::ComparisonFn _fn)
diff --git a/3rdparty/bx/src/debug.cpp b/3rdparty/bx/src/debug.cpp
index 8e8bae122a6..623a2213b47 100644
--- a/3rdparty/bx/src/debug.cpp
+++ b/3rdparty/bx/src/debug.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -24,8 +24,8 @@ extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char* _
# include <CoreFoundation/CFString.h>
extern "C" void NSLog(CFStringRef _format, ...);
# endif // defined(__OBJC__)
-#elif 0 // BX_PLATFORM_EMSCRIPTEN
-# include <emscripten.h>
+#elif BX_PLATFORM_EMSCRIPTEN
+# include <emscripten/emscripten.h>
#else
# include <stdio.h> // fputs, fflush
#endif // BX_PLATFORM_WINDOWS
@@ -43,6 +43,11 @@ namespace bx
// NaCl doesn't like int 3:
// NativeClient: NaCl module load failed: Validation failure. File violates Native Client safety rules.
__asm__ ("int $3");
+#elif BX_PLATFORM_EMSCRIPTEN
+ emscripten_log(EM_LOG_CONSOLE | EM_LOG_ERROR | EM_LOG_C_STACK | EM_LOG_JS_STACK | EM_LOG_DEMANGLE, "debugBreak!");
+ // Doing emscripten_debugger() disables asm.js validation due to an emscripten bug
+ //emscripten_debugger();
+ EM_ASM({ debugger; });
#else // cross platform implementation
int* int3 = (int*)3L;
*int3 = 3;
@@ -69,7 +74,7 @@ namespace bx
# else
NSLog(__CFStringMakeConstantString("%s"), _out);
# endif // defined(__OBJC__)
-#elif 0 // BX_PLATFORM_EMSCRIPTEN
+#elif BX_PLATFORM_EMSCRIPTEN
emscripten_log(EM_LOG_CONSOLE, "%s", _out);
#else
fputs(_out, stdout);
diff --git a/3rdparty/bx/src/dtoa.cpp b/3rdparty/bx/src/dtoa.cpp
index 3c23ea516e1..686d5c6a12d 100644
--- a/3rdparty/bx/src/dtoa.cpp
+++ b/3rdparty/bx/src/dtoa.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/easing.cpp b/3rdparty/bx/src/easing.cpp
index e9f82b280de..8984abccd0c 100644
--- a/3rdparty/bx/src/easing.cpp
+++ b/3rdparty/bx/src/easing.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/file.cpp b/3rdparty/bx/src/file.cpp
index 8a282cab91f..aea285ea23f 100644
--- a/3rdparty/bx/src/file.cpp
+++ b/3rdparty/bx/src/file.cpp
@@ -1,24 +1,34 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#include "bx_p.h"
#include <bx/file.h>
+#ifndef BX_CONFIG_CRT_FILE_READER_WRITER
+# define BX_CONFIG_CRT_FILE_READER_WRITER !BX_CRT_NONE
+#endif // BX_CONFIG_CRT_FILE_READER_WRITER
+
+#ifndef BX_CONFIG_CRT_DIRECTORY_READER
+# define BX_CONFIG_CRT_DIRECTORY_READER (BX_PLATFORM_OS_DESKTOP && !BX_CRT_NONE)
+#endif // BX_CONFIG_CRT_DIRECTORY_READER
+
#if BX_CRT_NONE
# include "crt0.h"
#else
-# include <stdio.h>
-# include <sys/stat.h>
+# if BX_CONFIG_CRT_DIRECTORY_READER
+# include <dirent.h>
+# endif // BX_CONFIG_CRT_DIRECTORY_READER
+# include <stdio.h> // remove
+# include <sys/stat.h> // stat, mkdir
+# if BX_CRT_MSVC
+# include <direct.h> // _getcwd
+# else
+# include <unistd.h> // getcwd
+# endif // BX_CRT_MSVC
#endif // !BX_CRT_NONE
-#ifndef BX_CONFIG_CRT_FILE_READER_WRITER
-# define BX_CONFIG_CRT_FILE_READER_WRITER !(0 \
- || BX_CRT_NONE \
- )
-#endif // BX_CONFIG_CRT_FILE_READER_WRITER
-
namespace bx
{
class NoopWriterImpl : public FileWriterI
@@ -64,6 +74,7 @@ namespace bx
# elif 0 \
|| BX_PLATFORM_ANDROID \
|| BX_PLATFORM_BSD \
+ || BX_PLATFORM_HAIKU \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX
# define fseeko64 fseeko
@@ -97,7 +108,7 @@ namespace bx
return false;
}
- m_file = fopen(_filePath.get(), "rb");
+ m_file = fopen(_filePath.getCPtr(), "rb");
if (NULL == m_file)
{
BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "FileReader: Failed to open file.");
@@ -177,7 +188,7 @@ namespace bx
return false;
}
- m_file = fopen(_filePath.get(), _append ? "ab" : "wb");
+ m_file = fopen(_filePath.getCPtr(), _append ? "ab" : "wb");
if (NULL == m_file)
{
@@ -553,18 +564,193 @@ namespace bx
return impl->write(_data, _size, _err);
}
- bool stat(const FilePath& _filePath, FileInfo& _outFileInfo)
+#if BX_CONFIG_CRT_DIRECTORY_READER
+
+ class DirectoryReaderImpl : public ReaderOpenI, public CloserI, public ReaderI
+ {
+ public:
+ DirectoryReaderImpl()
+ : m_dir(NULL)
+ , m_pos(0)
+ {
+ }
+
+ virtual ~DirectoryReaderImpl()
+ {
+ close();
+ }
+
+ virtual bool open(const FilePath& _filePath, Error* _err) override
+ {
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ m_dir = opendir(_filePath.getCPtr() );
+
+ if (NULL == m_dir)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "DirectoryReader: Failed to open directory.");
+ return false;
+ }
+
+ m_pos = 0;
+
+ return true;
+ }
+
+ virtual void close() override
+ {
+ if (NULL != m_dir)
+ {
+ closedir(m_dir);
+ m_dir = NULL;
+ }
+ }
+
+ virtual int32_t read(void* _data, int32_t _size, Error* _err) override
+ {
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+
+ int32_t total = 0;
+
+ uint8_t* out = (uint8_t*)_data;
+
+ while (0 < _size)
+ {
+ if (0 == m_pos)
+ {
+ if (!fetch(m_cache, m_dir) )
+ {
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "DirectoryReader: EOF.");
+ return total;
+ }
+ }
+
+ const uint8_t* src = (const uint8_t*)&m_cache;
+ int32_t size = min<int32_t>(_size, sizeof(m_cache)-m_pos);
+ memCopy(&out[total], &src[m_pos], size);
+ total += size;
+ _size -= size;
+
+ m_pos += size;
+ m_pos %= sizeof(m_cache);
+ }
+
+ return total;
+ }
+
+ static bool fetch(FileInfo& _out, DIR* _dir)
+ {
+ for (;;)
+ {
+ const dirent* item = readdir(_dir);
+
+ if (NULL == item)
+ {
+ break;
+ }
+
+ if (0 != (item->d_type & DT_DIR) )
+ {
+ _out.type = FileType::Dir;
+ _out.size = UINT64_MAX;
+ _out.filePath.set(item->d_name);
+ return true;
+ }
+
+ if (0 != (item->d_type & DT_REG) )
+ {
+ _out.type = FileType::File;
+ _out.size = UINT64_MAX;
+ _out.filePath.set(item->d_name);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ FileInfo m_cache;
+ DIR* m_dir;
+ int32_t m_pos;
+ };
+
+#else
+
+ class DirectoryReaderImpl : public ReaderOpenI, public CloserI, public ReaderI
+ {
+ public:
+ DirectoryReaderImpl()
+ {
+ }
+
+ virtual ~DirectoryReaderImpl()
+ {
+ }
+
+ virtual bool open(const FilePath& _filePath, Error* _err) override
+ {
+ BX_UNUSED(_filePath);
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_OPEN, "DirectoryReader: Failed to open directory.");
+ return false;
+ }
+
+ virtual void close() override
+ {
+ }
+
+ virtual int32_t read(void* _data, int32_t _size, Error* _err) override
+ {
+ BX_UNUSED(_data, _size);
+ BX_CHECK(NULL != _err, "Reader/Writer interface calling functions must handle errors.");
+ BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "DirectoryReader: EOF.");
+ return 0;
+ }
+ };
+
+#endif // BX_CONFIG_CRT_DIRECTORY_READER
+
+ DirectoryReader::DirectoryReader()
+ {
+ BX_STATIC_ASSERT(sizeof(DirectoryReaderImpl) <= sizeof(m_internal) );
+ BX_PLACEMENT_NEW(m_internal, DirectoryReaderImpl);
+ }
+
+ DirectoryReader::~DirectoryReader()
+ {
+ DirectoryReaderImpl* impl = reinterpret_cast<DirectoryReaderImpl*>(m_internal);
+ impl->~DirectoryReaderImpl();
+ }
+
+ bool DirectoryReader::open(const FilePath& _filePath, Error* _err)
+ {
+ DirectoryReaderImpl* impl = reinterpret_cast<DirectoryReaderImpl*>(m_internal);
+ return impl->open(_filePath, _err);
+ }
+
+ void DirectoryReader::close()
+ {
+ DirectoryReaderImpl* impl = reinterpret_cast<DirectoryReaderImpl*>(m_internal);
+ impl->close();
+ }
+
+ int32_t DirectoryReader::read(void* _data, int32_t _size, Error* _err)
+ {
+ DirectoryReaderImpl* impl = reinterpret_cast<DirectoryReaderImpl*>(m_internal);
+ return impl->read(_data, _size, _err);
+ }
+
+ bool stat(FileInfo& _outFileInfo, const FilePath& _filePath)
{
#if BX_CRT_NONE
BX_UNUSED(_filePath, _outFileInfo);
return false;
#else
- _outFileInfo.m_size = 0;
- _outFileInfo.m_type = FileInfo::Count;
+ _outFileInfo.size = 0;
+ _outFileInfo.type = FileType::Count;
# if BX_COMPILER_MSVC
struct ::_stat64 st;
- int32_t result = ::_stat64(_filePath.get(), &st);
+ int32_t result = ::_stat64(_filePath.getCPtr(), &st);
if (0 != result)
{
@@ -573,15 +759,15 @@ namespace bx
if (0 != (st.st_mode & _S_IFREG) )
{
- _outFileInfo.m_type = FileInfo::Regular;
+ _outFileInfo.type = FileType::File;
}
else if (0 != (st.st_mode & _S_IFDIR) )
{
- _outFileInfo.m_type = FileInfo::Directory;
+ _outFileInfo.type = FileType::Dir;
}
# else
struct ::stat st;
- int32_t result = ::stat(_filePath.get(), &st);
+ int32_t result = ::stat(_filePath.getCPtr(), &st);
if (0 != result)
{
return false;
@@ -589,18 +775,185 @@ namespace bx
if (0 != (st.st_mode & S_IFREG) )
{
- _outFileInfo.m_type = FileInfo::Regular;
+ _outFileInfo.type = FileType::File;
}
else if (0 != (st.st_mode & S_IFDIR) )
{
- _outFileInfo.m_type = FileInfo::Directory;
+ _outFileInfo.type = FileType::Dir;
}
# endif // BX_COMPILER_MSVC
- _outFileInfo.m_size = st.st_size;
+ _outFileInfo.size = st.st_size;
return true;
#endif // BX_CRT_NONE
}
+ bool make(const FilePath& _filePath, Error* _err)
+ {
+ BX_ERROR_SCOPE(_err);
+
+ if (!_err->isOk() )
+ {
+ return false;
+ }
+
+#if BX_CRT_MSVC
+ int32_t result = ::_mkdir(_filePath.getCPtr() );
+#elif BX_CRT_MINGW
+ int32_t result = ::mkdir(_filePath.getCPtr());
+#elif BX_CRT_NONE
+ BX_UNUSED(_filePath);
+ int32_t result = -1;
+#else
+ int32_t result = ::mkdir(_filePath.getCPtr(), 0700);
+#endif // BX_CRT_MSVC
+
+ if (0 != result)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
+ return false;
+ }
+
+ return true;
+ }
+
+ bool makeAll(const FilePath& _filePath, Error* _err)
+ {
+ BX_ERROR_SCOPE(_err);
+
+ if (!_err->isOk() )
+ {
+ return false;
+ }
+
+ FileInfo fi;
+
+ if (stat(fi, _filePath) )
+ {
+ if (FileType::Dir == fi.type)
+ {
+ return true;
+ }
+
+ BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
+ return false;
+ }
+
+ const StringView dir = strRTrim(_filePath, "/");
+ const StringView slash = strRFind(dir, '/');
+
+ if (!slash.isEmpty()
+ && slash.getPtr() - dir.getPtr() > 1)
+ {
+ if (!makeAll(StringView(dir.getPtr(), slash.getPtr() ), _err) )
+ {
+ return false;
+ }
+ }
+
+ FilePath path(dir);
+ return make(path, _err);
+ }
+
+ bool remove(const FilePath& _filePath, Error* _err)
+ {
+ BX_ERROR_SCOPE(_err);
+
+ if (!_err->isOk() )
+ {
+ return false;
+ }
+
+#if BX_CRT_MSVC
+ int32_t result = -1;
+ FileInfo fi;
+ if (stat(fi, _filePath) )
+ {
+ if (FileType::Dir == fi.type)
+ {
+ result = ::_rmdir(_filePath.getCPtr() );
+ }
+ else
+ {
+ result = ::remove(_filePath.getCPtr() );
+ }
+ }
+#elif BX_CRT_NONE
+ BX_UNUSED(_filePath);
+ int32_t result = -1;
+#else
+ int32_t result = ::remove(_filePath.getCPtr() );
+#endif // BX_CRT_MSVC
+
+ if (0 != result)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
+ return false;
+ }
+
+ return true;
+ }
+
+ bool removeAll(const FilePath& _filePath, Error* _err)
+ {
+ BX_ERROR_SCOPE(_err);
+
+ if (remove(_filePath, _err) )
+ {
+ return true;
+ }
+
+ _err->reset();
+
+ FileInfo fi;
+
+ if (!stat(fi, _filePath) )
+ {
+ BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
+ return false;
+ }
+
+ if (FileType::Dir != fi.type)
+ {
+ BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
+ return false;
+ }
+
+ Error err;
+ DirectoryReader dr;
+
+ if (!bx::open(&dr, _filePath) )
+ {
+ BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
+ return false;
+ }
+
+ while (err.isOk() )
+ {
+ bx::read(&dr, fi, &err);
+
+ if (err.isOk() )
+ {
+ if (0 == strCmp(fi.filePath, ".")
+ || 0 == strCmp(fi.filePath, "..") )
+ {
+ continue;
+ }
+
+ FilePath path(_filePath);
+ path.join(fi.filePath);
+ if (!removeAll(path, _err) )
+ {
+ _err->reset();
+ break;
+ }
+ }
+ }
+
+ bx::close(&dr);
+
+ return remove(_filePath, _err);
+ }
+
} // namespace bx
diff --git a/3rdparty/bx/src/filepath.cpp b/3rdparty/bx/src/filepath.cpp
index 0ee2fc171ad..28149403aba 100644
--- a/3rdparty/bx/src/filepath.cpp
+++ b/3rdparty/bx/src/filepath.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -9,16 +9,12 @@
#include <bx/readerwriter.h>
#if !BX_CRT_NONE
-# include <stdio.h> // remove
-# include <dirent.h> // opendir
-
# if BX_CRT_MSVC
# include <direct.h> // _getcwd
# else
-# include <sys/stat.h> // mkdir
# include <unistd.h> // getcwd
# endif // BX_CRT_MSVC
-#endif // 0
+#endif // !BX_CRT_NONE
#if BX_PLATFORM_WINDOWS
extern "C" __declspec(dllimport) unsigned long __stdcall GetTempPathA(unsigned long _max, char* _ptr);
@@ -154,7 +150,7 @@ namespace bx
return size;
}
- static bool getEnv(char* _out, uint32_t* _inOutSize, const StringView& _name, FileInfo::Enum _type)
+ static bool getEnv(char* _out, uint32_t* _inOutSize, const StringView& _name, FileType::Enum _type)
{
uint32_t len = *_inOutSize;
*_out = '\0';
@@ -162,8 +158,8 @@ namespace bx
if (getEnv(_out, &len, _name) )
{
FileInfo fi;
- if (stat(_out, fi)
- && _type == fi.m_type)
+ if (stat(fi, _out)
+ && _type == fi.type)
{
*_inOutSize = len;
return true;
@@ -204,9 +200,9 @@ namespace bx
{
return false
#if BX_PLATFORM_WINDOWS
- || getEnv(_out, _inOutSize, "USERPROFILE", FileInfo::Directory)
+ || getEnv(_out, _inOutSize, "USERPROFILE", FileType::Dir)
#endif // BX_PLATFORM_WINDOWS
- || getEnv(_out, _inOutSize, "HOME", FileInfo::Directory)
+ || getEnv(_out, _inOutSize, "HOME", FileType::Dir)
;
}
@@ -232,7 +228,7 @@ namespace bx
{
uint32_t len = *_inOutSize;
*_out = '\0';
- bool ok = getEnv(_out, &len, *tmp, FileInfo::Directory);
+ bool ok = getEnv(_out, &len, *tmp, FileType::Dir);
if (ok
&& len != 0
@@ -244,8 +240,8 @@ namespace bx
}
FileInfo fi;
- if (stat("/tmp", fi)
- && FileInfo::Directory == fi.m_type)
+ if (stat(fi, "/tmp")
+ && FileType::Dir == fi.type)
{
strCopy(_out, *_inOutSize, "/tmp");
*_inOutSize = 4;
@@ -336,7 +332,12 @@ namespace bx
set(tmp);
}
- const char* FilePath::get() const
+ FilePath::operator StringView() const
+ {
+ return StringView(m_filePath, strLen(m_filePath) );
+ }
+
+ const char* FilePath::getCPtr() const
{
return m_filePath;
}
@@ -360,7 +361,7 @@ namespace bx
return StringView(fileName.getPtr()+1);
}
- return get();
+ return getCPtr();
}
StringView FilePath::getBaseName() const
@@ -385,7 +386,8 @@ namespace bx
const StringView fileName = getFileName();
if (!fileName.isEmpty() )
{
- return strFind(fileName, '.');
+ const StringView dot = strFind(fileName, '.');
+ return StringView(dot.getPtr(), fileName.getTerm() );
}
return StringView();
@@ -403,171 +405,4 @@ namespace bx
return 0 == strCmp(m_filePath, ".");
}
- bool make(const FilePath& _filePath, Error* _err)
- {
- BX_ERROR_SCOPE(_err);
-
- if (!_err->isOk() )
- {
- return false;
- }
-
-#if BX_CRT_MSVC
- int32_t result = ::_mkdir(_filePath.get() );
-#elif BX_CRT_MINGW
- int32_t result = ::mkdir(_filePath.get());
-#elif BX_CRT_NONE
- BX_UNUSED(_filePath);
- int32_t result = -1;
-#else
- int32_t result = ::mkdir(_filePath.get(), 0700);
-#endif // BX_CRT_MSVC
-
- if (0 != result)
- {
- BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
- return false;
- }
-
- return true;
- }
-
- bool makeAll(const FilePath& _filePath, Error* _err)
- {
- BX_ERROR_SCOPE(_err);
-
- if (!_err->isOk() )
- {
- return false;
- }
-
- FileInfo fi;
-
- if (stat(_filePath, fi) )
- {
- if (FileInfo::Directory == fi.m_type)
- {
- return true;
- }
-
- BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
- return false;
- }
-
- const StringView dir = strRTrim(_filePath.get(), "/");
- const StringView slash = strRFind(dir, '/');
-
- if (!slash.isEmpty()
- && slash.getPtr() - dir.getPtr() > 1)
- {
- if (!makeAll(StringView(dir.getPtr(), slash.getPtr() ), _err) )
- {
- return false;
- }
- }
-
- FilePath path(dir);
- return make(path, _err);
- }
-
- bool remove(const FilePath& _filePath, Error* _err)
- {
- BX_ERROR_SCOPE(_err);
-
- if (!_err->isOk() )
- {
- return false;
- }
-
-#if BX_CRT_MSVC
- int32_t result = -1;
- FileInfo fi;
- if (stat(_filePath, fi) )
- {
- if (FileInfo::Directory == fi.m_type)
- {
- result = ::_rmdir(_filePath.get() );
- }
- else
- {
- result = ::remove(_filePath.get() );
- }
- }
-#elif BX_CRT_NONE
- BX_UNUSED(_filePath);
- int32_t result = -1;
-#else
- int32_t result = ::remove(_filePath.get() );
-#endif // BX_CRT_MSVC
-
- if (0 != result)
- {
- BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
- return false;
- }
-
- return true;
- }
-
- bool removeAll(const FilePath& _filePath, Error* _err)
- {
- BX_ERROR_SCOPE(_err);
-
- if (remove(_filePath, _err) )
- {
- return true;
- }
-
- _err->reset();
-
- FileInfo fi;
-
- if (!stat(_filePath, fi) )
- {
- BX_ERROR_SET(_err, BX_ERROR_ACCESS, "The parent directory does not allow write permission to the process.");
- return false;
- }
-
- if (FileInfo::Directory != fi.m_type)
- {
- BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
- return false;
- }
-
-#if BX_CRT_NONE
- BX_UNUSED(_filePath);
- return false;
-#elif BX_PLATFORM_WINDOWS \
- || BX_PLATFORM_LINUX \
- || BX_PLATFORM_OSX
- DIR* dir = opendir(_filePath.get() );
- if (NULL == dir)
- {
- BX_ERROR_SET(_err, BX_ERROR_NOT_DIRECTORY, "File already exist, and is not directory.");
- return false;
- }
-
- for (dirent* item = readdir(dir); NULL != item; item = readdir(dir) )
- {
- if (0 == strCmp(item->d_name, ".")
- || 0 == strCmp(item->d_name, "..") )
- {
- continue;
- }
-
- FilePath path(_filePath);
- path.join(item->d_name);
- if (!removeAll(path, _err) )
- {
- _err->reset();
- break;
- }
- }
-
- closedir(dir);
-#endif // !BX_CRT_NONE
-
- return remove(_filePath, _err);
- }
-
} // namespace bx
diff --git a/3rdparty/bx/src/hash.cpp b/3rdparty/bx/src/hash.cpp
index 7ae5e39cc80..d48a1e22f28 100644
--- a/3rdparty/bx/src/hash.cpp
+++ b/3rdparty/bx/src/hash.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/math.cpp b/3rdparty/bx/src/math.cpp
index ba0676e96bf..4e3380a3774 100644
--- a/3rdparty/bx/src/math.cpp
+++ b/3rdparty/bx/src/math.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -239,87 +239,53 @@ namespace bx
return result;
}
- BX_CONST_FUNC float floor(float _a)
+ void mtxLookAt(float* _result, const Vec3& _eye, const Vec3& _at, const Vec3& _up, Handness::Enum _handness)
{
- if (_a < 0.0f)
- {
- const float fr = fract(-_a);
- const float result = -_a - fr;
-
- return -(0.0f != fr
- ? result + 1.0f
- : result)
- ;
- }
-
- return _a - fract(_a);
- }
-
- static void mtxLookAtImpl(float* _result, const Vec3& _eye, const Vec3& _view, const Vec3& _up)
- {
- const Vec3 uxv = cross(_up, _view);
+ const Vec3 view = normalize(
+ Handness::Right == _handness
+ ? sub(_eye, _at)
+ : sub(_at, _eye)
+ );
+ const Vec3 uxv = cross(_up, view);
const Vec3 right = normalize(uxv);
- const Vec3 up = cross(_view, right);
+ const Vec3 up = cross(view, right);
memSet(_result, 0, sizeof(float)*16);
_result[ 0] = right.x;
_result[ 1] = up.x;
- _result[ 2] = _view.x;
+ _result[ 2] = view.x;
_result[ 4] = right.y;
_result[ 5] = up.y;
- _result[ 6] = _view.y;
+ _result[ 6] = view.y;
_result[ 8] = right.z;
_result[ 9] = up.z;
- _result[10] = _view.z;
+ _result[10] = view.z;
_result[12] = -dot(right, _eye);
- _result[13] = -dot(up, _eye);
- _result[14] = -dot(_view, _eye);
+ _result[13] = -dot(up, _eye);
+ _result[14] = -dot(view, _eye);
_result[15] = 1.0f;
}
- void mtxLookAtLh(float* _result, const Vec3& _eye, const Vec3& _at, const Vec3& _up)
- {
- const Vec3 tmp = sub(_at, _eye);
- const Vec3 view = normalize(tmp);
-
- mtxLookAtImpl(_result, _eye, view, _up);
- }
-
- void mtxLookAtRh(float* _result, const Vec3& _eye, const Vec3& _at, const Vec3& _up)
- {
- const Vec3 tmp = sub(_eye, _at);
- const Vec3 view = normalize(tmp);
-
- mtxLookAtImpl(_result, _eye, view, _up);
- }
-
- void mtxLookAt(float* _result, const Vec3& _eye, const Vec3& _at, const Vec3& _up)
- {
- mtxLookAtLh(_result, _eye, _at, _up);
- }
-
- template<Handness::Enum HandnessT>
- void mtxProjXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, float _far, bool _oglNdc)
+ static void mtxProjXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, float _far, bool _homogeneousNdc, Handness::Enum _handness)
{
const float diff = _far-_near;
- const float aa = _oglNdc ? ( _far+_near)/diff : _far/diff;
- const float bb = _oglNdc ? (2.0f*_far*_near)/diff : _near*aa;
+ const float aa = _homogeneousNdc ? ( _far+_near)/diff : _far/diff;
+ const float bb = _homogeneousNdc ? (2.0f*_far*_near)/diff : _near*aa;
memSet(_result, 0, sizeof(float)*16);
_result[ 0] = _width;
_result[ 5] = _height;
- _result[ 8] = (Handness::Right == HandnessT) ? _x : -_x;
- _result[ 9] = (Handness::Right == HandnessT) ? _y : -_y;
- _result[10] = (Handness::Right == HandnessT) ? -aa : aa;
- _result[11] = (Handness::Right == HandnessT) ? -1.0f : 1.0f;
+ _result[ 8] = (Handness::Right == _handness) ? _x : -_x;
+ _result[ 9] = (Handness::Right == _handness) ? _y : -_y;
+ _result[10] = (Handness::Right == _handness) ? -aa : aa;
+ _result[11] = (Handness::Right == _handness) ? -1.0f : 1.0f;
_result[14] = -bb;
}
- template<Handness::Enum HandnessT>
- void mtxProjImpl(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc)
+ void mtxProj(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _homogeneousNdc, Handness::Enum _handness)
{
const float invDiffRl = 1.0f/(_rt - _lt);
const float invDiffUd = 1.0f/(_ut - _dt);
@@ -327,96 +293,47 @@ namespace bx
const float height = 2.0f*_near * invDiffUd;
const float xx = (_rt + _lt) * invDiffRl;
const float yy = (_ut + _dt) * invDiffUd;
- mtxProjXYWH<HandnessT>(_result, xx, yy, width, height, _near, _far, _oglNdc);
+ mtxProjXYWH(_result, xx, yy, width, height, _near, _far, _homogeneousNdc, _handness);
}
- template<Handness::Enum HandnessT>
- void mtxProjImpl(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc)
+ void mtxProj(float* _result, const float _fov[4], float _near, float _far, bool _homogeneousNdc, Handness::Enum _handness)
{
- mtxProjImpl<HandnessT>(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _far, _oglNdc);
+ mtxProj(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _far, _homogeneousNdc, _handness);
}
- template<Handness::Enum HandnessT>
- void mtxProjImpl(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc)
+ void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far, bool _homogeneousNdc, Handness::Enum _handness)
{
const float height = 1.0f/tan(toRad(_fovy)*0.5f);
const float width = height * 1.0f/_aspect;
- mtxProjXYWH<HandnessT>(_result, 0.0f, 0.0f, width, height, _near, _far, _oglNdc);
+ mtxProjXYWH(_result, 0.0f, 0.0f, width, height, _near, _far, _homogeneousNdc, _handness);
}
- void mtxProj(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _ut, _dt, _lt, _rt, _near, _far, _oglNdc);
- }
-
- void mtxProj(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _fov, _near, _far, _oglNdc);
- }
-
- void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _fovy, _aspect, _near, _far, _oglNdc);
- }
-
- void mtxProjLh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _ut, _dt, _lt, _rt, _near, _far, _oglNdc);
- }
-
- void mtxProjLh(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _fov, _near, _far, _oglNdc);
- }
-
- void mtxProjLh(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Left>(_result, _fovy, _aspect, _near, _far, _oglNdc);
- }
-
- void mtxProjRh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Right>(_result, _ut, _dt, _lt, _rt, _near, _far, _oglNdc);
- }
-
- void mtxProjRh(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Right>(_result, _fov, _near, _far, _oglNdc);
- }
-
- void mtxProjRh(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc)
- {
- mtxProjImpl<Handness::Right>(_result, _fovy, _aspect, _near, _far, _oglNdc);
- }
-
- template<NearFar::Enum NearFarT, Handness::Enum HandnessT>
- void mtxProjInfXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, bool _oglNdc)
+ static void mtxProjInfXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, bool _homogeneousNdc, Handness::Enum _handness, NearFar::Enum _nearFar)
{
float aa;
float bb;
- if (BX_ENABLED(NearFar::Reverse == NearFarT) )
+ if (NearFar::Reverse == _nearFar)
{
- aa = _oglNdc ? -1.0f : 0.0f;
- bb = _oglNdc ? -2.0f*_near : -_near;
+ aa = _homogeneousNdc ? -1.0f : 0.0f;
+ bb = _homogeneousNdc ? -2.0f*_near : -_near;
}
else
{
aa = 1.0f;
- bb = _oglNdc ? 2.0f*_near : _near;
+ bb = _homogeneousNdc ? 2.0f*_near : _near;
}
memSet(_result, 0, sizeof(float)*16);
_result[ 0] = _width;
_result[ 5] = _height;
- _result[ 8] = (Handness::Right == HandnessT) ? _x : -_x;
- _result[ 9] = (Handness::Right == HandnessT) ? _y : -_y;
- _result[10] = (Handness::Right == HandnessT) ? -aa : aa;
- _result[11] = (Handness::Right == HandnessT) ? -1.0f : 1.0f;
+ _result[ 8] = (Handness::Right == _handness) ? _x : -_x;
+ _result[ 9] = (Handness::Right == _handness) ? _y : -_y;
+ _result[10] = (Handness::Right == _handness) ? -aa : aa;
+ _result[11] = (Handness::Right == _handness) ? -1.0f : 1.0f;
_result[14] = -bb;
}
- template<NearFar::Enum NearFarT, Handness::Enum HandnessT>
- void mtxProjInfImpl(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
+ void mtxProjInf(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _homogeneousNdc, Handness::Enum _handness, NearFar::Enum _nearFar)
{
const float invDiffRl = 1.0f/(_rt - _lt);
const float invDiffUd = 1.0f/(_ut - _dt);
@@ -424,107 +341,29 @@ namespace bx
const float height = 2.0f*_near * invDiffUd;
const float xx = (_rt + _lt) * invDiffRl;
const float yy = (_ut + _dt) * invDiffUd;
- mtxProjInfXYWH<NearFarT,HandnessT>(_result, xx, yy, width, height, _near, _oglNdc);
+ mtxProjInfXYWH(_result, xx, yy, width, height, _near, _homogeneousNdc, _handness, _nearFar);
}
- template<NearFar::Enum NearFarT, Handness::Enum HandnessT>
- void mtxProjInfImpl(float* _result, const float _fov[4], float _near, bool _oglNdc)
+ void mtxProjInf(float* _result, const float _fov[4], float _near, bool _homogeneousNdc, Handness::Enum _handness, NearFar::Enum _nearFar)
{
- mtxProjInfImpl<NearFarT,HandnessT>(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _oglNdc);
+ mtxProjInf(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _homogeneousNdc, _handness, _nearFar);
}
- template<NearFar::Enum NearFarT, Handness::Enum HandnessT>
- void mtxProjInfImpl(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
+ void mtxProjInf(float* _result, float _fovy, float _aspect, float _near, bool _homogeneousNdc, Handness::Enum _handness, NearFar::Enum _nearFar)
{
const float height = 1.0f/tan(toRad(_fovy)*0.5f);
const float width = height * 1.0f/_aspect;
- mtxProjInfXYWH<NearFarT,HandnessT>(_result, 0.0f, 0.0f, width, height, _near, _oglNdc);
- }
-
- void mtxProjInf(float* _result, const float _fov[4], float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _fov, _near, _oglNdc);
- }
-
- void mtxProjInf(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _ut, _dt, _lt, _rt, _near, _oglNdc);
+ mtxProjInfXYWH(_result, 0.0f, 0.0f, width, height, _near, _homogeneousNdc, _handness, _nearFar);
}
- void mtxProjInf(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _fovy, _aspect, _near, _oglNdc);
- }
-
- void mtxProjInfLh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _ut, _dt, _lt, _rt, _near, _oglNdc);
- }
-
- void mtxProjInfLh(float* _result, const float _fov[4], float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _fov, _near, _oglNdc);
- }
-
- void mtxProjInfLh(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Left>(_result, _fovy, _aspect, _near, _oglNdc);
- }
-
- void mtxProjInfRh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Right>(_result, _ut, _dt, _lt, _rt, _near, _oglNdc);
- }
-
- void mtxProjInfRh(float* _result, const float _fov[4], float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Right>(_result, _fov, _near, _oglNdc);
- }
-
- void mtxProjInfRh(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Default,Handness::Right>(_result, _fovy, _aspect, _near, _oglNdc);
- }
-
- void mtxProjRevInfLh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Left>(_result, _ut, _dt, _lt, _rt, _near, _oglNdc);
- }
-
- void mtxProjRevInfLh(float* _result, const float _fov[4], float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Left>(_result, _fov, _near, _oglNdc);
- }
-
- void mtxProjRevInfLh(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Left>(_result, _fovy, _aspect, _near, _oglNdc);
- }
-
- void mtxProjRevInfRh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Right>(_result, _ut, _dt, _lt, _rt, _near, _oglNdc);
- }
-
- void mtxProjRevInfRh(float* _result, const float _fov[4], float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Right>(_result, _fov, _near, _oglNdc);
- }
-
- void mtxProjRevInfRh(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc)
- {
- mtxProjInfImpl<NearFar::Reverse,Handness::Right>(_result, _fovy, _aspect, _near, _oglNdc);
- }
-
- template<Handness::Enum HandnessT>
- void mtxOrthoImpl(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset, bool _oglNdc)
+ void mtxOrtho(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset, bool _homogeneousNdc, Handness::Enum _handness)
{
const float aa = 2.0f/(_right - _left);
const float bb = 2.0f/(_top - _bottom);
- const float cc = (_oglNdc ? 2.0f : 1.0f) / (_far - _near);
+ const float cc = (_homogeneousNdc ? 2.0f : 1.0f) / (_far - _near);
const float dd = (_left + _right )/(_left - _right);
const float ee = (_top + _bottom)/(_bottom - _top );
- const float ff = _oglNdc
+ const float ff = _homogeneousNdc
? (_near + _far)/(_near - _far)
: _near /(_near - _far)
;
@@ -532,28 +371,13 @@ namespace bx
memSet(_result, 0, sizeof(float)*16);
_result[ 0] = aa;
_result[ 5] = bb;
- _result[10] = (Handness::Right == HandnessT) ? -cc : cc;
+ _result[10] = Handness::Right == _handness ? -cc : cc;
_result[12] = dd + _offset;
_result[13] = ee;
_result[14] = ff;
_result[15] = 1.0f;
}
- void mtxOrtho(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset, bool _oglNdc)
- {
- mtxOrthoImpl<Handness::Left>(_result, _left, _right, _bottom, _top, _near, _far, _offset, _oglNdc);
- }
-
- void mtxOrthoLh(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset, bool _oglNdc)
- {
- mtxOrthoImpl<Handness::Left>(_result, _left, _right, _bottom, _top, _near, _far, _offset, _oglNdc);
- }
-
- void mtxOrthoRh(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset, bool _oglNdc)
- {
- mtxOrthoImpl<Handness::Right>(_result, _left, _right, _bottom, _top, _near, _far, _offset, _oglNdc);
- }
-
void mtxRotateX(float* _result, float _ax)
{
const float sx = sin(_ax);
@@ -694,15 +518,15 @@ namespace bx
void mtx3Inverse(float* _result, const float* _a)
{
- float xx = _a[0];
- float xy = _a[1];
- float xz = _a[2];
- float yx = _a[3];
- float yy = _a[4];
- float yz = _a[5];
- float zx = _a[6];
- float zy = _a[7];
- float zz = _a[8];
+ const float xx = _a[0];
+ const float xy = _a[1];
+ const float xz = _a[2];
+ const float yx = _a[3];
+ const float yy = _a[4];
+ const float yz = _a[5];
+ const float zx = _a[6];
+ const float zy = _a[7];
+ const float zz = _a[8];
float det = 0.0f;
det += xx * (yy*zz - yz*zy);
@@ -726,22 +550,22 @@ namespace bx
void mtxInverse(float* _result, const float* _a)
{
- float xx = _a[ 0];
- float xy = _a[ 1];
- float xz = _a[ 2];
- float xw = _a[ 3];
- float yx = _a[ 4];
- float yy = _a[ 5];
- float yz = _a[ 6];
- float yw = _a[ 7];
- float zx = _a[ 8];
- float zy = _a[ 9];
- float zz = _a[10];
- float zw = _a[11];
- float wx = _a[12];
- float wy = _a[13];
- float wz = _a[14];
- float ww = _a[15];
+ const float xx = _a[ 0];
+ const float xy = _a[ 1];
+ const float xz = _a[ 2];
+ const float xw = _a[ 3];
+ const float yx = _a[ 4];
+ const float yy = _a[ 5];
+ const float yz = _a[ 6];
+ const float yw = _a[ 7];
+ const float zx = _a[ 8];
+ const float zy = _a[ 9];
+ const float zz = _a[10];
+ const float zw = _a[11];
+ const float wx = _a[12];
+ const float wy = _a[13];
+ const float wz = _a[14];
+ const float ww = _a[15];
float det = 0.0f;
det += xx * (yy*(zz*ww - zw*wz) - yz*(zy*ww - zw*wy) + yw*(zy*wz - zz*wy) );
@@ -772,6 +596,71 @@ namespace bx
_result[15] = +(xx*(yy*zz - zy*yz) - xy*(yx*zz - zx*yz) + xz*(yx*zy - zx*yy) ) * invDet;
}
+ void mtx3Cofactor(float* _result, const float* _a)
+ {
+ const float xx = _a[0];
+ const float xy = _a[1];
+ const float xz = _a[2];
+ const float yx = _a[3];
+ const float yy = _a[4];
+ const float yz = _a[5];
+ const float zx = _a[6];
+ const float zy = _a[7];
+ const float zz = _a[8];
+
+ _result[0] = +(yy*zz - yz * zy);
+ _result[1] = -(yx*zz - yz * zx);
+ _result[2] = +(yx*zy - yy * zx);
+
+ _result[3] = -(xy*zz - xz * zy);
+ _result[4] = +(xx*zz - xz * zx);
+ _result[5] = -(xx*zy - xy * zx);
+
+ _result[6] = +(xy*yz - xz * yy);
+ _result[7] = -(xx*yz - xz * yx);
+ _result[8] = +(xx*yy - xy * yx);
+ }
+
+ void mtxCofactor(float* _result, const float* _a)
+ {
+ const float xx = _a[0];
+ const float xy = _a[1];
+ const float xz = _a[2];
+ const float xw = _a[3];
+ const float yx = _a[4];
+ const float yy = _a[5];
+ const float yz = _a[6];
+ const float yw = _a[7];
+ const float zx = _a[8];
+ const float zy = _a[9];
+ const float zz = _a[10];
+ const float zw = _a[11];
+ const float wx = _a[12];
+ const float wy = _a[13];
+ const float wz = _a[14];
+ const float ww = _a[15];
+
+ _result[ 0] = +(yy*(zz*ww - wz * zw) - yz * (zy*ww - wy * zw) + yw * (zy*wz - wy * zz) );
+ _result[ 1] = -(yx*(zz*ww - wz * zw) - yz * (zx*ww - wx * zw) + yw * (zx*wz - wx * zz) );
+ _result[ 2] = +(yx*(zy*ww - wy * zw) - yy * (zx*ww - wx * zw) + yw * (zx*wy - wx * zy) );
+ _result[ 3] = -(yx*(zy*wz - wy * zz) - yy * (zx*wz - wx * zz) + yz * (zx*wy - wx * zy) );
+
+ _result[ 4] = -(xy*(zz*ww - wz * zw) - xz * (zy*ww - wy * zw) + xw * (zy*wz - wy * zz) );
+ _result[ 5] = +(xx*(zz*ww - wz * zw) - xz * (zx*ww - wx * zw) + xw * (zx*wz - wx * zz) );
+ _result[ 6] = -(xx*(zy*ww - wy * zw) - xy * (zx*ww - wx * zw) + xw * (zx*wy - wx * zy) );
+ _result[ 7] = +(xx*(zy*wz - wy * zz) - xy * (zx*wz - wx * zz) + xz * (zx*wy - wx * zy) );
+
+ _result[ 8] = +(xy*(yz*ww - wz * yw) - xz * (yy*ww - wy * yw) + xw * (yy*wz - wy * yz) );
+ _result[ 9] = -(xx*(yz*ww - wz * yw) - xz * (yx*ww - wx * yw) + xw * (yx*wz - wx * yz) );
+ _result[10] = +(xx*(yy*ww - wy * yw) - xy * (yx*ww - wx * yw) + xw * (yx*wy - wx * yy) );
+ _result[11] = -(xx*(yy*wz - wy * yz) - xy * (yx*wz - wx * yz) + xz * (yx*wy - wx * yy) );
+
+ _result[12] = -(xy*(yz*zw - zz * yw) - xz * (yy*zw - zy * yw) + xw * (yy*zz - zy * yz) );
+ _result[13] = +(xx*(yz*zw - zz * yw) - xz * (yx*zw - zx * yw) + xw * (yx*zz - zx * yz) );
+ _result[14] = -(xx*(yy*zw - zy * yw) - xy * (yx*zw - zx * yw) + xw * (yx*zy - zx * yy) );
+ _result[15] = +(xx*(yy*zz - zy * yz) - xy * (yx*zz - zx * yz) + xz * (yx*zy - zx * yy) );
+ }
+
void calcLinearFit2D(float _result[2], const void* _points, uint32_t _stride, uint32_t _numPoints)
{
float sumX = 0.0f;
diff --git a/3rdparty/bx/src/mutex.cpp b/3rdparty/bx/src/mutex.cpp
index 27c6b63b709..48f09d0be3e 100644
--- a/3rdparty/bx/src/mutex.cpp
+++ b/3rdparty/bx/src/mutex.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -12,6 +12,7 @@
# include <bx/cpu.h>
# include "crt0.h"
#elif BX_PLATFORM_ANDROID \
+ || BX_PLATFORM_HAIKU \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX \
diff --git a/3rdparty/bx/src/os.cpp b/3rdparty/bx/src/os.cpp
index 0e925bb2f90..ab5d6bd0935 100644
--- a/3rdparty/bx/src/os.cpp
+++ b/3rdparty/bx/src/os.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -18,21 +18,23 @@
# include <windows.h>
# include <psapi.h>
#elif BX_PLATFORM_ANDROID \
- || BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_BSD \
+ || BX_PLATFORM_EMSCRIPTEN \
+ || BX_PLATFORM_HAIKU \
|| BX_PLATFORM_HURD \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_LINUX \
+ || BX_PLATFORM_NX \
|| BX_PLATFORM_OSX \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_RPI \
- || BX_PLATFORM_STEAMLINK \
- || BX_PLATFORM_NX
+ || BX_PLATFORM_STEAMLINK
# include <sched.h> // sched_yield
-# if BX_PLATFORM_BSD \
- || BX_PLATFORM_IOS \
- || BX_PLATFORM_OSX \
- || BX_PLATFORM_PS4 \
+# if BX_PLATFORM_BSD \
+ || BX_PLATFORM_HAIKU \
+ || BX_PLATFORM_IOS \
+ || BX_PLATFORM_OSX \
+ || BX_PLATFORM_PS4 \
|| BX_PLATFORM_STEAMLINK
# include <pthread.h> // mach_port_t
# endif // BX_PLATFORM_*
@@ -50,6 +52,9 @@
# include <stdio.h> // fopen
# include <unistd.h> // syscall
# include <sys/syscall.h>
+# elif BX_PLATFORM_HAIKU
+# include <stdio.h> // fopen
+# include <unistd.h> // syscall
# elif BX_PLATFORM_OSX
# include <mach/mach.h> // mach_task_basic_info
# elif BX_PLATFORM_HURD
@@ -62,7 +67,6 @@
namespace bx
{
-
void sleep(uint32_t _ms)
{
#if BX_PLATFORM_WINDOWS
@@ -174,7 +178,7 @@ namespace bx
void* dlopen(const FilePath& _filePath)
{
#if BX_PLATFORM_WINDOWS
- return (void*)::LoadLibraryA(_filePath.get() );
+ return (void*)::LoadLibraryA(_filePath.getCPtr() );
#elif BX_PLATFORM_EMSCRIPTEN \
|| BX_PLATFORM_PS4 \
|| BX_PLATFORM_XBOXONE \
@@ -183,7 +187,7 @@ namespace bx
BX_UNUSED(_filePath);
return NULL;
#else
- return ::dlopen(_filePath.get(), RTLD_LOCAL|RTLD_LAZY);
+ return ::dlopen(_filePath.getCPtr(), RTLD_LOCAL|RTLD_LAZY);
#endif // BX_PLATFORM_
}
@@ -233,9 +237,10 @@ namespace bx
bool result = len != 0 && len < *_inOutSize;
*_inOutSize = len;
return result;
-#elif BX_PLATFORM_PS4 \
- || BX_PLATFORM_XBOXONE \
- || BX_PLATFORM_WINRT \
+#elif BX_PLATFORM_EMSCRIPTEN \
+ || BX_PLATFORM_PS4 \
+ || BX_PLATFORM_XBOXONE \
+ || BX_PLATFORM_WINRT \
|| BX_CRT_NONE
BX_UNUSED(name, _out, _inOutSize);
return false;
@@ -275,9 +280,10 @@ namespace bx
#if BX_PLATFORM_WINDOWS
::SetEnvironmentVariableA(name, value);
-#elif BX_PLATFORM_PS4 \
- || BX_PLATFORM_XBOXONE \
- || BX_PLATFORM_WINRT \
+#elif BX_PLATFORM_EMSCRIPTEN \
+ || BX_PLATFORM_PS4 \
+ || BX_PLATFORM_XBOXONE \
+ || BX_PLATFORM_WINRT \
|| BX_CRT_NONE
BX_UNUSED(name, value);
#else
diff --git a/3rdparty/bx/src/process.cpp b/3rdparty/bx/src/process.cpp
index 90d663b3f5a..b079bbc77e5 100644
--- a/3rdparty/bx/src/process.cpp
+++ b/3rdparty/bx/src/process.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -48,7 +48,7 @@ namespace bx
}
char tmp[kMaxFilePath*2] = "\"";
- strCat(tmp, BX_COUNTOF(tmp), _filePath.get() );
+ strCat(tmp, BX_COUNTOF(tmp), _filePath);
strCat(tmp, BX_COUNTOF(tmp), "\" ");
strCat(tmp, BX_COUNTOF(tmp), _args);
@@ -119,7 +119,7 @@ namespace bx
}
char tmp[kMaxFilePath*2] = "\"";
- strCat(tmp, BX_COUNTOF(tmp), _filePath.get() );
+ strCat(tmp, BX_COUNTOF(tmp), _filePath);
strCat(tmp, BX_COUNTOF(tmp), "\" ");
strCat(tmp, BX_COUNTOF(tmp), _args);
diff --git a/3rdparty/bx/src/semaphore.cpp b/3rdparty/bx/src/semaphore.cpp
index 3663fe767b5..f4e99c66637 100644
--- a/3rdparty/bx/src/semaphore.cpp
+++ b/3rdparty/bx/src/semaphore.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/settings.cpp b/3rdparty/bx/src/settings.cpp
index e09e11f687f..49bcc596817 100644
--- a/3rdparty/bx/src/settings.cpp
+++ b/3rdparty/bx/src/settings.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/sort.cpp b/3rdparty/bx/src/sort.cpp
index 515b33f24f1..56cb7d48a98 100644
--- a/3rdparty/bx/src/sort.cpp
+++ b/3rdparty/bx/src/sort.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/string.cpp b/3rdparty/bx/src/string.cpp
index 7710028ae6d..678af6664ce 100644
--- a/3rdparty/bx/src/string.cpp
+++ b/3rdparty/bx/src/string.cpp
@@ -1,12 +1,12 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#include "bx_p.h"
#include <bx/allocator.h>
+#include <bx/file.h>
#include <bx/hash.h>
-#include <bx/readerwriter.h>
#include <bx/string.h>
namespace bx
@@ -188,7 +188,12 @@ namespace bx
}
}
- return 0 == max && _lhsMax == _rhsMax ? 0 : fn(*_lhs) - fn(*_rhs);
+ if (0 == max)
+ {
+ return _lhsMax == _rhsMax ? 0 : _lhsMax > _rhsMax ? 1 : -1;
+ }
+
+ return fn(*_lhs) - fn(*_rhs);
}
int32_t strCmp(const StringView& _lhs, const StringView& _rhs, int32_t _max)
@@ -370,7 +375,7 @@ namespace bx
inline const char* strRFindUnsafe(const char* _str, int32_t _len, char _ch)
{
- for (int32_t ii = _len; 0 <= ii; --ii)
+ for (int32_t ii = _len-1; 0 <= ii; --ii)
{
if (_str[ii] == _ch)
{
@@ -687,9 +692,10 @@ namespace bx
return StringView(_str.getTerm(), _str.getTerm() );
}
- StringView findIdentifierMatch(const StringView& _str, const char** _words)
+ StringView findIdentifierMatch(const StringView& _str, const char** _words, int32_t _num)
{
- for (StringView word = *_words; !word.isEmpty(); ++_words, word = *_words)
+ int32_t ii = 0;
+ for (StringView word = *_words; ii < _num && !word.isEmpty(); ++ii, ++_words, word = *_words)
{
StringView match = findIdentifierMatch(_str, word);
if (!match.isEmpty() )
@@ -1147,10 +1153,10 @@ namespace bx
SizerWriter sizer;
va_list argListCopy;
va_copy(argListCopy, _argList);
- int32_t size = write(&sizer, _format, argListCopy, &err);
+ int32_t total = write(&sizer, _format, argListCopy, &err);
va_end(argListCopy);
- return size;
+ return total;
}
int32_t snprintf(char* _out, int32_t _max, const char* _format, ...)
@@ -1159,6 +1165,28 @@ namespace bx
va_start(argList, _format);
int32_t total = vsnprintf(_out, _max, _format, argList);
va_end(argList);
+
+ return total;
+ }
+
+ int32_t vprintf(const char* _format, va_list _argList)
+ {
+ Error err;
+ va_list argListCopy;
+ va_copy(argListCopy, _argList);
+ int32_t total = write(getStdOut(), _format, argListCopy, &err);
+ va_end(argListCopy);
+
+ return total;
+ }
+
+ int32_t printf(const char* _format, ...)
+ {
+ va_list argList;
+ va_start(argList, _format);
+ int32_t total = vprintf(_format, argList);
+ va_end(argList);
+
return total;
}
diff --git a/3rdparty/bx/src/thread.cpp b/3rdparty/bx/src/thread.cpp
index f52e0bdcbf4..7969d7852ae 100644
--- a/3rdparty/bx/src/thread.cpp
+++ b/3rdparty/bx/src/thread.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
@@ -8,9 +8,14 @@
#if BX_CONFIG_SUPPORTS_THREADING
+#if BX_PLATFORM_WINDOWS && !BX_CRT_NONE
+# include <bx/string.h>
+#endif
+
#if BX_CRT_NONE
# include "crt0.h"
#elif BX_PLATFORM_ANDROID \
+ || BX_PLATFORM_HAIKU \
|| BX_PLATFORM_LINUX \
|| BX_PLATFORM_IOS \
|| BX_PLATFORM_OSX \
@@ -240,33 +245,46 @@ namespace bx
# else
pthread_set_name_np(ti->m_handle, _name);
# endif // defined(__NetBSD__)
-#elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC
-# pragma pack(push, 8)
- struct ThreadName
- {
- DWORD type;
- LPCSTR name;
- DWORD id;
- DWORD flags;
- };
-# pragma pack(pop)
- ThreadName tn;
- tn.type = 0x1000;
- tn.name = _name;
- tn.id = ti->m_threadId;
- tn.flags = 0;
-
- __try
- {
- RaiseException(0x406d1388
- , 0
- , sizeof(tn)/4
- , reinterpret_cast<ULONG_PTR*>(&tn)
- );
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
+#elif BX_PLATFORM_WINDOWS
+ // Try to use the new thread naming API from Win10 Creators update onwards if we have it
+ typedef HRESULT (WINAPI *SetThreadDescriptionProc)(HANDLE, PCWSTR);
+ SetThreadDescriptionProc SetThreadDescription = (SetThreadDescriptionProc)(GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetThreadDescription"));
+ if (SetThreadDescription)
{
+ uint32_t length = (uint32_t)bx::strLen(_name)+1;
+ uint32_t size = length*sizeof(wchar_t);
+ wchar_t* name = (wchar_t*)alloca(size);
+ mbstowcs(name, _name, size-2);
+ SetThreadDescription(ti->m_handle, name);
}
+# if BX_COMPILER_MSVC
+# pragma pack(push, 8)
+ struct ThreadName
+ {
+ DWORD type;
+ LPCSTR name;
+ DWORD id;
+ DWORD flags;
+ };
+# pragma pack(pop)
+ ThreadName tn;
+ tn.type = 0x1000;
+ tn.name = _name;
+ tn.id = ti->m_threadId;
+ tn.flags = 0;
+
+ __try
+ {
+ RaiseException(0x406d1388
+ , 0
+ , sizeof(tn)/4
+ , reinterpret_cast<ULONG_PTR*>(&tn)
+ );
+ }
+ __except(EXCEPTION_EXECUTE_HANDLER)
+ {
+ }
+# endif // BX_COMPILER_MSVC
#else
BX_UNUSED(_name);
#endif // BX_PLATFORM_
diff --git a/3rdparty/bx/src/timer.cpp b/3rdparty/bx/src/timer.cpp
index 8cfebdda7f5..80bc28a8448 100644
--- a/3rdparty/bx/src/timer.cpp
+++ b/3rdparty/bx/src/timer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
diff --git a/3rdparty/bx/src/url.cpp b/3rdparty/bx/src/url.cpp
index f58ecf5a9c3..b64a50b43b3 100644
--- a/3rdparty/bx/src/url.cpp
+++ b/3rdparty/bx/src/url.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bnet#license-bsd-2-clause
*/