From 86f2d4b9f9df7514e3f15d8f2a5e92db6ac3c0ba Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 28 Apr 2017 00:29:50 +0200 Subject: Commented pointer lock on web --- src/core.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index ee069d97..1bad2369 100644 --- a/src/core.c +++ b/src/core.c @@ -2719,6 +2719,8 @@ static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboar // Register mouse input events static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { + /* + // Lock mouse pointer when click on screen if (eventType == EMSCRIPTEN_EVENT_CLICK) { EmscriptenPointerlockChangeEvent plce; @@ -2732,6 +2734,7 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent //if (plce.isActive) TraceLog(WARNING, "Pointer lock exit did not work!"); } } + */ return 0; } -- cgit v1.2.3 From e197665e1dc3ec895b14b901884fee058dc1b4e9 Mon Sep 17 00:00:00 2001 From: victorfisac Date: Tue, 2 May 2017 15:04:32 +0200 Subject: Added function to set window minimum dimensions... useful when using FLAG_WINDOW_RESIZABLE. --- src/core.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 1bad2369..d7cf1f79 100644 --- a/src/core.c +++ b/src/core.c @@ -629,6 +629,15 @@ void SetWindowMonitor(int monitor) #endif } +// Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) +void SetWindowMinSize(int width, int height) +{ +#if defined(PLATFORM_DESKTOP) + const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + glfwSetWindowSizeLimits(window, width, height, mode->width, mode->height); +#endif +} + // Get current screen width int GetScreenWidth(void) { -- cgit v1.2.3 From 39732d04ec8ce71cde457ec3a89b3b5aca578e8d Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 00:55:26 +0200 Subject: Comments review --- src/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index d7cf1f79..1241b3c1 100644 --- a/src/core.c +++ b/src/core.c @@ -5,11 +5,10 @@ * PLATFORMS SUPPORTED: * - Windows (win32/Win64) * - Linux (tested on Ubuntu) -* - Mac (OSX) -* - Android (API Level 9 or greater) +* - OSX (Mac) +* - Android (ARM or ARM64) * - Raspberry Pi (Raspbian) * - HTML5 (Chrome, Firefox) -* - Oculus Rift CV1 * * CONFIGURATION: * -- cgit v1.2.3 From 83aba22e494ffbc78cb9cda6a8e39e82963026f4 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 02:37:37 +0200 Subject: Improved hi-res timer on Win32 --- src/core.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 1241b3c1..459b99fb 100644 --- a/src/core.c +++ b/src/core.c @@ -41,6 +41,9 @@ * #define SUPPORT_MOUSE_GESTURES * Mouse gestures are directly mapped like touches and processed by gestures system. * +* #define SUPPORT_BUSY_WAIT_LOOP +* Use busy wait loop for timming sync, if not defined, a high-resolution timer is setup and used +* * DEPENDENCIES: * GLFW3 - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX) * raymath - 3D math functionality (Vector3, Matrix, Quaternion) @@ -75,6 +78,7 @@ #define SUPPORT_MOUSE_GESTURES #define SUPPORT_CAMERA_SYSTEM #define SUPPORT_GESTURES_SYSTEM +#define SUPPORT_BUSY_WAIT_LOOP //------------------------------------------------- #include "raylib.h" @@ -104,9 +108,9 @@ #include // Required for: strrchr(), strcmp() //#include // Macros for reporting and retrieving error conditions through error codes -#if defined __linux__ || defined(PLATFORM_WEB) +#if defined(__linux__) || defined(PLATFORM_WEB) #include // Required for: timespec, nanosleep(), select() - POSIX -#elif defined __APPLE__ +#elif defined(__APPLE__) #include // Required for: usleep() #endif @@ -114,13 +118,19 @@ //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management - #ifdef __linux__ + #ifdef(__linux__) #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window #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) + // NOTE: Those functions require linking with winmm library + __stdcall unsigned int timeBeginPeriod(unsigned int uPeriod); + __stdcall unsigned int timeEndPeriod(unsigned int uPeriod); + #endif #endif #if defined(PLATFORM_ANDROID) @@ -506,6 +516,10 @@ void CloseWindow(void) glfwTerminate(); #endif +#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32) + timeEndPeriod(1); // Restore time period +#endif + #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) // Close surface, context and display if (display != EGL_NO_DISPLAY) @@ -2042,6 +2056,10 @@ static void SetupFramebufferSize(int displayWidth, int displayHeight) static void InitTimer(void) { srand(time(NULL)); // Initialize random seed + +#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32) + timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms) +#endif #if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) struct timespec now; @@ -2078,7 +2096,6 @@ static double GetTime(void) // http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected static void Wait(float ms) { -#define SUPPORT_BUSY_WAIT_LOOP #if defined(SUPPORT_BUSY_WAIT_LOOP) double prevTime = GetTime(); double nextTime = 0.0; @@ -2086,9 +2103,9 @@ static void Wait(float ms) // Busy wait loop while ((nextTime - prevTime) < ms/1000.0f) nextTime = GetTime(); #else - #if defined _WIN32 + #if defined(_WIN32) Sleep((unsigned int)ms); - #elif defined __linux__ || defined(PLATFORM_WEB) + #elif defined(__linux__) || defined(PLATFORM_WEB) struct timespec req = { 0 }; time_t sec = (int)(ms/1000.0f); ms -= (sec*1000); @@ -2097,7 +2114,7 @@ static void Wait(float ms) // NOTE: Use nanosleep() on Unix platforms... usleep() it's deprecated. while (nanosleep(&req, &req) == -1) continue; - #elif defined __APPLE__ + #elif defined(__APPLE__) usleep(ms*1000.0f); #endif #endif -- cgit v1.2.3 From 822c2ddad59e9839aeb029f5a3dc26681188612b Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 02:47:44 +0200 Subject: Some defines tweaks for consistency --- src/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 459b99fb..1448743f 100644 --- a/src/core.c +++ b/src/core.c @@ -118,7 +118,7 @@ //#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3 #include // GLFW3 library: Windows, OpenGL context and Input management - #ifdef(__linux__) + #if defined(__linux__) #define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting #define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window #include // which are required for hiding mouse @@ -668,7 +668,7 @@ int GetScreenHeight(void) void ShowCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux__ + #if defined(__linux__) XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window)); #else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); @@ -681,7 +681,7 @@ void ShowCursor() void HideCursor() { #if defined(PLATFORM_DESKTOP) - #ifdef __linux__ + #if defined(__linux__) XColor col; const char nil[] = {0}; @@ -1679,7 +1679,7 @@ static void InitGraphicsDevice(int width, int height) glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // Choose OpenGL minor version (just hint) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above! // Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE -#ifdef __APPLE__ +#if defined(__APPLE__) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires #else glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above! @@ -1964,7 +1964,7 @@ static void InitGraphicsDevice(int width, int height) // Set viewport parameters static void SetupViewport(void) { -#ifdef __APPLE__ +#if defined(__APPLE__) // Get framebuffer size of current window // NOTE: Required to handle HighDPI display correctly on OSX because framebuffer // is automatically reasized to adapt to new DPI. @@ -3279,7 +3279,7 @@ static void *GamepadThread(void *arg) // Plays raylib logo appearing animation static void LogoAnimation(void) { -#ifndef PLATFORM_WEB +#if !defined(PLATFORM_WEB) int logoPositionX = screenWidth/2 - 128; int logoPositionY = screenHeight/2 - 128; -- cgit v1.2.3 From fd1fe3ac14adbd4bdc8ed409a65aad9d7d7133ca Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 21:03:48 +0200 Subject: Lock cursor on first person camera --- src/core.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 1448743f..508049c9 100644 --- a/src/core.c +++ b/src/core.c @@ -286,6 +286,10 @@ static int gamepadAxisCount = 0; // Register number of available game static Vector2 mousePosition; // Mouse position on screen +#if defined(PLATFORM_WEB) +static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click +#endif + #if defined(SUPPORT_GESTURES_SYSTEM) static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen #endif @@ -708,6 +712,9 @@ void EnableCursor() { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); +#endif +#if defined(PLATFORM_WEB) + toggleCursorLock = true; #endif cursorHidden = false; } @@ -717,6 +724,9 @@ void DisableCursor() { #if defined(PLATFORM_DESKTOP) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); +#endif +#if defined(PLATFORM_WEB) + toggleCursorLock = true; #endif cursorHidden = true; } @@ -1821,12 +1831,13 @@ static void InitGraphicsDevice(int width, int height) const EGLint framebufferAttribs[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI? - //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android! + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // Type of context support -> Required on RPI? + //EGL_SURFACE_TYPE, EGL_WINDOW_BIT, // Don't use it on Android! EGL_RED_SIZE, 8, // RED color bit depth (alternative: 5) EGL_GREEN_SIZE, 8, // GREEN color bit depth (alternative: 6) EGL_BLUE_SIZE, 8, // BLUE color bit depth (alternative: 5) //EGL_ALPHA_SIZE, 8, // ALPHA bit depth + //EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB, // Request transparent framebuffer EGL_DEPTH_SIZE, 16, // Depth buffer size (Required to use Depth testing!) //EGL_STENCIL_SIZE, 8, // Stencil buffer size EGL_SAMPLE_BUFFERS, sampleBuffer, // Activate MSAA @@ -2744,9 +2755,8 @@ static EM_BOOL EmscriptenKeyboardCallback(int eventType, const EmscriptenKeyboar // Register mouse input events static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) { - /* // Lock mouse pointer when click on screen - if (eventType == EMSCRIPTEN_EVENT_CLICK) + if ((eventType == EMSCRIPTEN_EVENT_CLICK) && toggleCursorLock) { EmscriptenPointerlockChangeEvent plce; emscripten_get_pointerlock_status(&plce); @@ -2758,8 +2768,9 @@ static EM_BOOL EmscriptenMouseCallback(int eventType, const EmscriptenMouseEvent emscripten_get_pointerlock_status(&plce); //if (plce.isActive) TraceLog(WARNING, "Pointer lock exit did not work!"); } + + toggleCursorLock = false; } - */ return 0; } -- cgit v1.2.3