diff --git a/src/aurora_gpads.cpp b/src/aurora_gpads.cpp index e6c377c9..9e38cfcf 100644 --- a/src/aurora_gpads.cpp +++ b/src/aurora_gpads.cpp @@ -1,16 +1,30 @@ #include #include "GLFW/glfw3.h" +static bool TryReadFile(const AuString &path, AuString &out) +{ + if (!AuFS::FileExists(path)) + { + return false; + } + + return AuFS::ReadString(path, out); +} + extern "C" void _glfwInitAdditionalGamepads(void) { AuString file; - if (AuFS::ReadString("~/SDLGamepad.keys", file) || - AuFS::ReadString("!/SDLGamepad.keys", file)) + if (TryReadFile("~/SDLGamepad.keys", file) || + TryReadFile("!/SDLGamepad.keys", file)) { if (GLFW_TRUE != glfwUpdateGamepadMappings(file.c_str())) { AuLogWarn("Couldn't parse gamepad mappings."); } } + else + { + AuLogVerbose("No additional SDL gamepad database files loaded!"); + } } \ No newline at end of file diff --git a/src/aurora_thread.cpp b/src/aurora_thread.cpp new file mode 100644 index 00000000..fe9f1220 --- /dev/null +++ b/src/aurora_thread.cpp @@ -0,0 +1,46 @@ +#include + +extern "C" +{ + int _glfwPlatformCreateTls(void *tls) + { + new (tls) AuTLSVariable(); + return 1; + } + + void _glfwPlatformDestroyTls(void *tls) + { + ((AuTLSVariable *)tls)->~TLSVariable(); + } + + void *_glfwPlatformGetTls(void *tls) + { + return ((AuTLSVariable *)tls)->operator void *&(); + } + + void _glfwPlatformSetTls(void *tls, void *value) + { + ((AuTLSVariable *)tls)->operator void *&() = value; + } + + int _glfwPlatformCreateMutex(void *mutex) + { + new (mutex) AuMutex(); + return 1; + } + + void _glfwPlatformDestroyMutex(void *mutex) + { + ((AuMutex *)mutex)->~AuMutex(); + } + + void _glfwPlatformLockMutex(void *mutex) + { + ((AuMutex *)mutex)->AsPointer()->Lock(); + } + + void _glfwPlatformUnlockMutex(void *mutex) + { + ((AuMutex *)mutex)->AsPointer()->Unlock(); + } +} \ No newline at end of file diff --git a/src/aurora_time.cpp b/src/aurora_time.cpp index 9514deef..b0256e91 100644 --- a/src/aurora_time.cpp +++ b/src/aurora_time.cpp @@ -1,23 +1,19 @@ -#include +#include -namespace Aurora::Time +extern "C" { - uint64_ct SteadyClockMS(); - uint64_ct SteadyClock(); - uint64_ct SteadyClockJiffies(); -} + void _glfwPlatformInitTimer(void) + { -extern "C" void _glfwPlatformInitTimer(void) -{ + } -} + AuUInt64 _glfwPlatformGetTimerValue(void) + { + return Aurora::Time::SteadyClock(); + } -extern "C" uint64_ct _glfwPlatformGetTimerValue(void) -{ - return Aurora::Time::SteadyClock(); -} - -extern "C" uint64_ct _glfwPlatformGetTimerFrequency(void) -{ - return Aurora::Time::SteadyClockJiffies(); + AuUInt64 _glfwPlatformGetTimerFrequency(void) + { + return Aurora::Time::SteadyClockJiffies(); + } } \ No newline at end of file diff --git a/src/internal.h b/src/internal.h index f0249f09..be964650 100644 --- a/src/internal.h +++ b/src/internal.h @@ -698,16 +698,14 @@ struct _GLFWjoystick // struct _GLFWtls { - // This is defined in platform.h - GLFW_PLATFORM_TLS_STATE + char tls[32]; }; // Mutex structure // struct _GLFWmutex { - // This is defined in platform.h - GLFW_PLATFORM_MUTEX_STATE + char mutex[32]; }; // Platform API structure diff --git a/src/platform.h b/src/platform.h index d7c4e011..713c8306 100644 --- a/src/platform.h +++ b/src/platform.h @@ -162,16 +162,6 @@ #define GLFW_BUILD_POSIX_THREAD #endif -#if defined(GLFW_BUILD_WIN32_THREAD) - #include "win32_thread.h" - #define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE - #define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE -#elif defined(GLFW_BUILD_POSIX_THREAD) - #include "posix_thread.h" - #define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE - #define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE -#endif - #if defined(_WIN32) #define GLFW_BUILD_WIN32_TIMER #elif defined(__APPLE__) diff --git a/src/posix_thread.c b/src/posix_thread.c deleted file mode 100644 index 4ce55526..00000000 --- a/src/posix_thread.c +++ /dev/null @@ -1,109 +0,0 @@ -//======================================================================== -// GLFW 3.4 POSIX - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2017 Camilla Löwy -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== -// It is fine to use C99 in this file because it will not be built with VS -//======================================================================== - -#include "internal.h" - -#if defined(GLFW_BUILD_POSIX_THREAD) - -#include -#include - - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - -GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) -{ - assert(tls->posix.allocated == GLFW_FALSE); - - if (pthread_key_create(&tls->posix.key, NULL) != 0) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "POSIX: Failed to create context TLS"); - return GLFW_FALSE; - } - - tls->posix.allocated = GLFW_TRUE; - return GLFW_TRUE; -} - -void _glfwPlatformDestroyTls(_GLFWtls* tls) -{ - if (tls->posix.allocated) - pthread_key_delete(tls->posix.key); - memset(tls, 0, sizeof(_GLFWtls)); -} - -void* _glfwPlatformGetTls(_GLFWtls* tls) -{ - assert(tls->posix.allocated == GLFW_TRUE); - return pthread_getspecific(tls->posix.key); -} - -void _glfwPlatformSetTls(_GLFWtls* tls, void* value) -{ - assert(tls->posix.allocated == GLFW_TRUE); - pthread_setspecific(tls->posix.key, value); -} - -GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) -{ - assert(mutex->posix.allocated == GLFW_FALSE); - - if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); - return GLFW_FALSE; - } - - return mutex->posix.allocated = GLFW_TRUE; -} - -void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) -{ - if (mutex->posix.allocated) - pthread_mutex_destroy(&mutex->posix.handle); - memset(mutex, 0, sizeof(_GLFWmutex)); -} - -void _glfwPlatformLockMutex(_GLFWmutex* mutex) -{ - assert(mutex->posix.allocated == GLFW_TRUE); - pthread_mutex_lock(&mutex->posix.handle); -} - -void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) -{ - assert(mutex->posix.allocated == GLFW_TRUE); - pthread_mutex_unlock(&mutex->posix.handle); -} - -#endif // GLFW_BUILD_POSIX_THREAD - diff --git a/src/posix_thread.h b/src/posix_thread.h deleted file mode 100644 index 5a5d7b7c..00000000 --- a/src/posix_thread.h +++ /dev/null @@ -1,49 +0,0 @@ -//======================================================================== -// GLFW 3.4 POSIX - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2017 Camilla Löwy -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== - -#include - -#define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix; -#define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix; - - -// POSIX-specific thread local storage data -// -typedef struct _GLFWtlsPOSIX -{ - GLFWbool allocated; - pthread_key_t key; -} _GLFWtlsPOSIX; - -// POSIX-specific mutex data -// -typedef struct _GLFWmutexPOSIX -{ - GLFWbool allocated; - pthread_mutex_t handle; -} _GLFWmutexPOSIX; - diff --git a/src/win32_thread.c b/src/win32_thread.c deleted file mode 100644 index db997915..00000000 --- a/src/win32_thread.c +++ /dev/null @@ -1,102 +0,0 @@ -//======================================================================== -// GLFW 3.4 Win32 - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2017 Camilla Löwy -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== -// Please use C89 style variable declarations in this file because VS 2010 -//======================================================================== - -#include "internal.h" - -#if defined(GLFW_BUILD_WIN32_THREAD) - -#include - - -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// - -GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) -{ - assert(tls->win32.allocated == GLFW_FALSE); - - tls->win32.index = TlsAlloc(); - if (tls->win32.index == TLS_OUT_OF_INDEXES) - { - _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); - return GLFW_FALSE; - } - - tls->win32.allocated = GLFW_TRUE; - return GLFW_TRUE; -} - -void _glfwPlatformDestroyTls(_GLFWtls* tls) -{ - if (tls->win32.allocated) - TlsFree(tls->win32.index); - memset(tls, 0, sizeof(_GLFWtls)); -} - -void* _glfwPlatformGetTls(_GLFWtls* tls) -{ - assert(tls->win32.allocated == GLFW_TRUE); - return TlsGetValue(tls->win32.index); -} - -void _glfwPlatformSetTls(_GLFWtls* tls, void* value) -{ - assert(tls->win32.allocated == GLFW_TRUE); - TlsSetValue(tls->win32.index, value); -} - -GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) -{ - assert(mutex->win32.allocated == GLFW_FALSE); - InitializeCriticalSection(&mutex->win32.section); - return mutex->win32.allocated = GLFW_TRUE; -} - -void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) -{ - if (mutex->win32.allocated) - DeleteCriticalSection(&mutex->win32.section); - memset(mutex, 0, sizeof(_GLFWmutex)); -} - -void _glfwPlatformLockMutex(_GLFWmutex* mutex) -{ - assert(mutex->win32.allocated == GLFW_TRUE); - EnterCriticalSection(&mutex->win32.section); -} - -void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) -{ - assert(mutex->win32.allocated == GLFW_TRUE); - LeaveCriticalSection(&mutex->win32.section); -} - -#endif // GLFW_BUILD_WIN32_THREAD - diff --git a/src/win32_thread.h b/src/win32_thread.h deleted file mode 100644 index 4b5a696f..00000000 --- a/src/win32_thread.h +++ /dev/null @@ -1,48 +0,0 @@ -//======================================================================== -// GLFW 3.4 Win32 - www.glfw.org -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2017 Camilla Löwy -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== - -#include - -#define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; -#define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32; - -// Win32-specific thread local storage data -// -typedef struct _GLFWtlsWin32 -{ - GLFWbool allocated; - DWORD index; -} _GLFWtlsWin32; - -// Win32-specific mutex data -// -typedef struct _GLFWmutexWin32 -{ - GLFWbool allocated; - CRITICAL_SECTION section; -} _GLFWmutexWin32; -