From 899e1fbd94f697d95b9684e272de5410b08edc06 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 22 Nov 2017 22:47:57 +0100 Subject: Avoid duplicate definition of feature macro Feature macros need to be defined before #including any headers, preferably through the build system, but this is good enough. Fixes a compile error on my fork's Travis CI. --- src/gestures.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gestures.h') diff --git a/src/gestures.h b/src/gestures.h index f4d38dfb..2e343154 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -148,7 +148,10 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang 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 // Required for: timespec #include // Required for: clock_gettime() #endif -- cgit v1.2.3 From b2acff66dec7bce30e9704aa9b13070f7c3ffac1 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 22 Nov 2017 22:33:47 +0100 Subject: Fix macOS build of new rglfw.c approach There have been two problems: * GLFW itself was compiled with the definitions for compiling _against_ GLFW (fixed by removing requirement for external glfw) * rglfw.c was being compiled as C code, although it includes Objective C files. This _might_ break the Windows build, needs to be checked. Fixes #391, but as noted I'd prefer though a separate source directory and build script for GLFW. --- .travis.yml | 3 +-- src/CMakeLists.txt | 6 +++--- src/gestures.h | 6 +++--- src/rglfw.c | 2 +- utils.cmake | 7 ------- 5 files changed, 8 insertions(+), 16 deletions(-) (limited to 'src/gestures.h') diff --git a/.travis.yml b/.travis.yml index 7a5148ad..8b122c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,9 +25,8 @@ before_install: libopenal-dev libxcursor-dev libxinerama-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev libglew-dev; - wget 'https://github.com/a3f/GLFW-3.2.1-Debian-binary-package/releases/download/v3.2.1/GLFW-3.2.1-Linux.deb' && sudo dpkg -i GLFW-3.2.1-Linux.deb; fi - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; brew install glfw; export CC=clang; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; brew install glfw; fi - "$CC --version" script: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a398d665..f362b52f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,6 +20,7 @@ set(OPENGL_VERSION "3.3" CACHE STRING "OpenGL Version to build raylib with") set_property(CACHE OPENGL_VERSION PROPERTY STRINGS "3.3" "2.1" "1.1" "ES 2.0") ### Config options ### +include_directories(external/glfw/include) # Translate the config options to what raylib wants if(${PLATFORM} MATCHES "Desktop") @@ -40,6 +41,8 @@ if(${PLATFORM} MATCHES "Desktop") # See: https://github.com/raysan5/raylib/issues/341 if(APPLE) set(GRAPHICS "GRAPHICS_API_OPENGL_33") + set_source_files_properties(rglfw.c PROPERTIES COMPILE_FLAGS "-x objective-c") + link_libraries("-framework CoreFoundation -framework Cocoa -framework IOKit -framework CoreVideo") endif() elseif(${PLATFORM} MATCHES "Web") set(PLATFORM "PLATFORM_WEB") @@ -93,9 +96,6 @@ if(${PLATFORM} MATCHES "PLATFORM_DESKTOP") target_link_libraries(${RAYLIB} GL) endif() - # Add in GLFW as a linking target - target_link_libraries(${RAYLIB} glfw) - # Library file & Header set_target_properties(${RAYLIB} PROPERTIES PUBLIC_HEADER "raylib.h") install( diff --git a/src/gestures.h b/src/gestures.h index 2e343154..e2f004e2 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -140,9 +140,6 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #if defined(GESTURES_IMPLEMENTATION) -#include // Required for: atan2(), sqrt() -#include // Required for: uint64_t - #if defined(_WIN32) // Functions required to query time on Windows int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount); @@ -154,6 +151,9 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #endif #include // Required for: timespec #include // Required for: clock_gettime() + + #include // Required for: atan2(), sqrt() + #include // Required for: uint64_t #endif //---------------------------------------------------------------------------------- diff --git a/src/rglfw.c b/src/rglfw.c index b1b4eed7..83e0021b 100644 --- a/src/rglfw.c +++ b/src/rglfw.c @@ -86,5 +86,5 @@ #include "external/glfw/src/posix_thread.c" #include "external/glfw/src/nsgl_context.m" #include "external/glfw/src/egl_context.c" - #include "external/glfw/src/osmesa_context.c.m" + #include "external/glfw/src/osmesa_context.c" #endif diff --git a/utils.cmake b/utils.cmake index c902f60e..f260fa5e 100644 --- a/utils.cmake +++ b/utils.cmake @@ -6,10 +6,6 @@ if(UNIX AND NOT APPLE) set(LINUX TRUE) endif() -# Need GLFW 3.2.1 -find_package(glfw3 3.2.1 REQUIRED) - - # Linking for OS X -framework options # Will do nothing on other OSes function(link_os_x_frameworks binary) @@ -40,9 +36,6 @@ function(link_libraries_to_executable executable) # TODO windows endif() - # Add in GLFW as a linking target - target_link_libraries(${executable} glfw) - # And raylib target_link_libraries(${executable} raylib) endfunction() -- cgit v1.2.3 From c9722161d11b250006f17de62dd9ff17e46aeed4 Mon Sep 17 00:00:00 2001 From: Ray San Date: Mon, 27 Nov 2017 12:46:40 +0100 Subject: Support GetCurrentTime() on macOS --- src/gestures.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/gestures.h') diff --git a/src/gestures.h b/src/gestures.h index e2f004e2..68bdc11b 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -156,6 +156,11 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #include // Required for: uint64_t #endif +#if defined(__APPLE__) // macOS also defines __MACH__ + #include // Required for: clock_get_time() + #include // Required for: mach_timespec_t +#endif + //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- @@ -532,6 +537,22 @@ static double GetCurrentTime(void) time = ((double)nowTime/1000000.0); // Time in miliseconds #endif +#if defined(__APPLE__) + //#define CLOCK_REALTIME CALENDAR_CLOCK + //#define CLOCK_MONOTONIC SYSTEM_CLOCK + + 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; } -- cgit v1.2.3 From 5290390494c23055c689c183aea6d88039b0d5fb Mon Sep 17 00:00:00 2001 From: Ray San Date: Tue, 19 Dec 2017 14:06:54 +0100 Subject: Expose GetTime() function to users Monotonic time since InitWindow() could be retrieved with this function. --- src/core.c | 57 +++++++++++++++++++++++++++++---------------------------- src/gestures.h | 6 +++--- src/raylib.h | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) (limited to 'src/gestures.h') diff --git a/src/core.c b/src/core.c index 8a2e40b3..6468539f 100644 --- a/src/core.c +++ b/src/core.c @@ -150,11 +150,11 @@ #include // which are required for hiding mouse #endif //#include // OpenGL functions (GLFW3 already includes gl.h) - //#define GLFW_DLL // Using GLFW DLL on Windows -> No, we use static version! - + #if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32) - __stdcall unsigned int timeBeginPeriod(unsigned int uPeriod); - __stdcall unsigned int timeEndPeriod(unsigned int uPeriod); + // NOTE: Those functions require linking with winmm library + unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod); + unsigned int __stdcall timeEndPeriod(unsigned int uPeriod); #endif #endif @@ -351,7 +351,6 @@ extern void UnloadDefaultFont(void); // [Module: text] Unloads default fo static void InitGraphicsDevice(int width, int height); // Initialize graphics device static void SetupFramebufferSize(int displayWidth, int displayHeight); static void InitTimer(void); // Initialize timer -static double GetTime(void); // Returns time since InitTimer() was run static void Wait(float ms); // Wait for some milliseconds (stop program execution) static bool GetKeyStatus(int key); // Returns if a key has been pressed static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed @@ -421,6 +420,9 @@ void InitWindow(int width, int height, void *data) // Init graphics device (display device and OpenGL context) InitGraphicsDevice(width, height); + + // Init hi-res timer + InitTimer(); #if defined(SUPPORT_DEFAULT_FONT) // Load default font @@ -428,9 +430,6 @@ void InitWindow(int width, int height, void *data) LoadDefaultFont(); #endif - // Init hi-res timer - InitTimer(); - #if defined(PLATFORM_RPI) // Init raw input system InitMouse(); // Mouse init @@ -786,7 +785,7 @@ void ClearBackground(Color color) // Setup canvas (framebuffer) to start drawing void BeginDrawing(void) { - currentTime = GetTime(); // Number of elapsed seconds since InitTimer() was called + currentTime = GetTime(); // Number of elapsed seconds since InitTimer() updateTime = currentTime - previousTime; previousTime = currentTime; @@ -1060,6 +1059,24 @@ float GetFrameTime(void) return (float)frameTime; } +// Get elapsed time measure in seconds since InitTimer() +// NOTE: On PLATFORM_DESKTOP InitTimer() is called on InitWindow() +// NOTE: On PLATFORM_DESKTOP, timer is initialized on glfwInit() +double GetTime(void) +{ +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) + return glfwGetTime(); // Elapsed time since glfwInit() +#endif + +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; + + return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer() +#endif +} + // Converts Color to float array and normalizes float *ColorToFloat(Color color) { @@ -2118,22 +2135,6 @@ static void InitTimer(void) previousTime = GetTime(); // Get time as double } -// Get elapsed time measure (in seconds) -static double GetTime(void) -{ -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB) - return glfwGetTime(); // Elapsed time since glfwInit() -#endif - -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec; - - return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer() -#endif -} - // Wait for some milliseconds (stop program execution) // NOTE: Sleep() granularity could be around 10 ms, it means, Sleep() could // take longer than expected... for that reason we use the busy wait loop @@ -2602,6 +2603,9 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) { // Init graphics device (display device and OpenGL context) InitGraphicsDevice(screenWidth, screenHeight); + + // Init hi-res timer + InitTimer(); #if defined(SUPPORT_DEFAULT_FONT) // Load default font @@ -2624,9 +2628,6 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) } */ - // Init hi-res timer - InitTimer(); - // raylib logo appearing animation (if enabled) if (showLogo) { diff --git a/src/gestures.h b/src/gestures.h index 68bdc11b..58670ef5 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -522,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(¤tTime); time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds @@ -538,8 +538,8 @@ static double GetCurrentTime(void) #endif #if defined(__APPLE__) - //#define CLOCK_REALTIME CALENDAR_CLOCK - //#define CLOCK_MONOTONIC SYSTEM_CLOCK + //#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; diff --git a/src/raylib.h b/src/raylib.h index a581929e..4100cee1 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -722,7 +722,7 @@ RLAPI Matrix GetCameraMatrix(Camera camera); // Returns cam RLAPI void SetTargetFPS(int fps); // Set target FPS (maximum) RLAPI int GetFPS(void); // Returns current FPS RLAPI float GetFrameTime(void); // Returns time in seconds for last frame drawn -//RLAPI double GetCurrentTime(void); // Return current time in seconds +RLAPI double GetTime(void); // Returns elapsed time in seconds since InitWindow() // Color-related functions RLAPI int GetHexValue(Color color); // Returns hexadecimal value for a Color -- cgit v1.2.3 From 00c34a035c6cf32fb688dd06da39db32fa66bc70 Mon Sep 17 00:00:00 2001 From: Ray San Date: Wed, 20 Dec 2017 12:37:08 +0100 Subject: Updated copyright year --- src/gestures.h | 2 +- src/models.c | 2 +- src/shapes.c | 2 +- src/text.c | 2 +- src/utils.c | 2 +- src/utils.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/gestures.h') diff --git a/src/gestures.h b/src/gestures.h index 58670ef5..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. diff --git a/src/models.c b/src/models.c index 4b8a6731..002ffac3 100644 --- a/src/models.c +++ b/src/models.c @@ -17,7 +17,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. diff --git a/src/shapes.c b/src/shapes.c index 0b34f921..9f405419 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -13,7 +13,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. diff --git a/src/text.c b/src/text.c index f577be19..eaf450b0 100644 --- a/src/text.c +++ b/src/text.c @@ -17,7 +17,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. diff --git a/src/utils.c b/src/utils.c index aaa5bdb4..72d4f2da 100644 --- a/src/utils.c +++ b/src/utils.c @@ -25,7 +25,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. diff --git a/src/utils.h b/src/utils.h index a1801245..f4a1a01a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,7 +5,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. -- cgit v1.2.3 From 44eedf235d5530bf603e537afd5e2479160edf91 Mon Sep 17 00:00:00 2001 From: "maficccc@gmail.com" Date: Fri, 16 Mar 2018 14:15:32 +0100 Subject: Redundant assignment of 'angle' to itself --- src/gestures.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gestures.h') diff --git a/src/gestures.h b/src/gestures.h index 58f046cb..a4546eb1 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -493,7 +493,7 @@ float GetGesturePinchAngle(void) // Returns angle from two-points vector with X-axis static float Vector2Angle(Vector2 v1, Vector2 v2) { - float angle = angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI); + float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI); if (angle < 0) angle += 360.0f; -- cgit v1.2.3