summaryrefslogtreecommitdiffhomepage
path: root/src/gestures.h
diff options
context:
space:
mode:
authorRay <[email protected]>2018-02-04 12:51:24 +0100
committerGitHub <[email protected]>2018-02-04 12:51:24 +0100
commitd50e291e8639de5cfb222bffc431f0f76151d48a (patch)
tree9637c6d00738ecc75195bd754bc9bc6daad642d2 /src/gestures.h
parent8380c488be90ed0c29a6446b490bfaca6574436e (diff)
parent6dc2f979ccbb4ec6f8166805b5f4f6377efbce70 (diff)
downloadraylib-d50e291e8639de5cfb222bffc431f0f76151d48a.tar.gz
raylib-d50e291e8639de5cfb222bffc431f0f76151d48a.zip
Merge pull request #458 from raysan5/develop
Integrate develop branch into 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;
}