summaryrefslogtreecommitdiffhomepage
path: root/src/gestures.h
diff options
context:
space:
mode:
authorvictorfisac <[email protected]>2018-03-10 19:10:37 +0100
committervictorfisac <[email protected]>2018-03-10 19:10:37 +0100
commit8f1d6f38506ff6449866913c6d88b0f25ca2d8f4 (patch)
tree659719ef12dbdedd9a51c85af0e43ac327c84b40 /src/gestures.h
parentdd50348b4dffe59be03538bdbaf2a3d084426e1f (diff)
parentdf50eada531b54d6771eff81cbe140f9453d54d9 (diff)
downloadraylib-8f1d6f38506ff6449866913c6d88b0f25ca2d8f4.tar.gz
raylib-8f1d6f38506ff6449866913c6d88b0f25ca2d8f4.zip
Merge branch 'master' of github.com:raysan5/raylib into fork/master
Diffstat (limited to 'src/gestures.h')
-rw-r--r--src/gestures.h36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/gestures.h b/src/gestures.h
index f4d38dfb..58f046cb 100644
--- a/src/gestures.h
+++ b/src/gestures.h
@@ -24,7 +24,7 @@
*
* LICENSE: zlib/libpng
*
-* Copyright (c) 2014-2017 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
*
* 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.
@@ -140,17 +140,25 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
#if defined(GESTURES_IMPLEMENTATION)
-#include <math.h> // Required for: atan2(), sqrt()
-#include <stdint.h> // Required for: uint64_t
-
#if defined(_WIN32)
// Functions required to query time on Windows
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
#elif defined(__linux__)
- #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
+ #if _POSIX_C_SOURCE < 199309L
+ #undef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
+ #endif
#include <sys/time.h> // Required for: timespec
#include <time.h> // Required for: clock_gettime()
+
+ #include <math.h> // Required for: atan2(), sqrt()
+ #include <stdint.h> // Required for: uint64_t
+#endif
+
+#if defined(__APPLE__) // macOS also defines __MACH__
+ #include <mach/clock.h> // Required for: clock_get_time()
+ #include <mach/mach.h> // Required for: mach_timespec_t
#endif
//----------------------------------------------------------------------------------
@@ -514,7 +522,7 @@ static double GetCurrentTime(void)
#if defined(_WIN32)
unsigned long long int clockFrequency, currentTime;
- QueryPerformanceFrequency(&clockFrequency);
+ QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation!
QueryPerformanceCounter(&currentTime);
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
@@ -529,6 +537,22 @@ static double GetCurrentTime(void)
time = ((double)nowTime/1000000.0); // Time in miliseconds
#endif
+#if defined(__APPLE__)
+ //#define CLOCK_REALTIME CALENDAR_CLOCK // returns UTC time since 1970-01-01
+ //#define CLOCK_MONOTONIC SYSTEM_CLOCK // returns the time since boot time
+
+ clock_serv_t cclock;
+ mach_timespec_t now;
+ host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
+
+ // NOTE: OS X does not have clock_gettime(), using clock_get_time()
+ clock_get_time(cclock, &now);
+ mach_port_deallocate(mach_task_self(), cclock);
+ uint64_t nowTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; // Time in nanoseconds
+
+ time = ((double)nowTime/1000000.0); // Time in miliseconds
+#endif
+
return time;
}