Kaynağa Gözat

Merge pull request #513 from blackberry-gaming/next-sgrenier

Next sgrenier
Steve Grenier 13 yıl önce
ebeveyn
işleme
99ad4f3330

+ 25 - 0
gameplay/src/Game.cpp

@@ -63,6 +63,31 @@ void Game::setVsync(bool enable)
     Platform::setVsync(enable);
     Platform::setVsync(enable);
 }
 }
 
 
+bool Game::hasMouse()
+{
+    return Platform::hasMouse();
+}
+
+bool Game::isMouseCaptured()
+{
+    return Platform::isMouseCaptured();
+}
+
+void Game::setMouseCapture(bool captured)
+{
+    Platform::setMouseCapture(captured);
+}
+
+void Game::setCursorVisible(bool visible)
+{
+    Platform::setCursorVisible(visible);
+}
+
+bool Game::isCursorVisible()
+{
+    return Platform::isCursorVisible();
+}
+
 bool Game::isVsync()
 bool Game::isVsync()
 {
 {
     return Platform::isVsync();
     return Platform::isVsync();

+ 54 - 0
gameplay/src/Game.h

@@ -76,6 +76,53 @@ public:
      */
      */
     static void setVsync(bool enable);
     static void setVsync(bool enable);
 
 
+    /** 
+     * Gets whether the current platform supports mouse input.
+     *
+      * @return true if a mouse is supported, false otherwise.
+      */
+    static bool hasMouse();
+
+    /**
+     * Gets whether mouse input is currently captured.
+     *
+     * @see Platform::isMouseCaptured()
+     */
+    static bool isMouseCaptured();
+
+    /**
+     * Enables or disables mouse capture.
+     *
+     * On platforms that support a mouse, when mouse capture is enabled,
+     * the platform cursor will be hidden and the mouse will be warped
+     * to the center of the screen. While mouse capture is enabled,
+     * all mouse move events will then be delivered as deltas instead
+     * of absolute positions.
+     *
+     * @param captured true to enable mouse capture mode, false to disable it.
+     *
+     * @see Platform::setMouseCapture(bool)
+     */
+    static void setMouseCapture(bool captured);
+
+    /**
+     * Sets the visibility of the platform cursor.
+     *
+     * @param visible true to show the platform cursor, false to hide it.
+     *
+     * @see Platform::setCursorVisible(bool)
+     */
+    static void setCursorVisible(bool visible);
+
+    /**
+     * Determines whether the platform cursor is currently visible.
+     *
+     * @return true if the platform cursor is visible, false otherwise.
+     *
+     * @see Platform::isCursorVisible()
+     */
+    static bool isCursorVisible();
+
     /**
     /**
      * Gets the total absolute running time (in milliseconds) since Game::run().
      * Gets the total absolute running time (in milliseconds) since Game::run().
      * 
      * 
@@ -100,6 +147,13 @@ public:
      */
      */
     inline State getState() const;
     inline State getState() const;
 
 
+    /**
+     * Determines if the game has been initialized.
+     *
+     * @return true if the game initialization has completed, false otherwise.
+     */
+    inline bool isInitialized() const;
+
     /**
     /**
      * Returns the game configuration object.
      * Returns the game configuration object.
      *
      *

+ 5 - 0
gameplay/src/Game.inl

@@ -9,6 +9,11 @@ inline Game::State Game::getState() const
     return _state;
     return _state;
 }
 }
 
 
+inline bool Game::isInitialized() const
+{
+    return _initialized;
+}
+
 inline unsigned int Game::getFrameRate() const
 inline unsigned int Game::getFrameRate() const
 {
 {
     return _frameRate;
     return _frameRate;

+ 52 - 1
gameplay/src/Platform.h

@@ -91,7 +91,10 @@ public:
     static void setVsync(bool enable);
     static void setVsync(bool enable);
 
 
     /**
     /**
-     * Set if multi-touch is enabled on the platform
+     * Set if multi-touch is enabled on the platform.
+     *
+     * Note that this method does nothing on platforms that do not
+     * support multi-touch.
      */
      */
     static void setMultiTouch(bool enabled);
     static void setMultiTouch(bool enabled);
 
 
@@ -100,6 +103,54 @@ public:
     */
     */
     static bool isMultiTouch();
     static bool isMultiTouch();
 
 
+    /**
+     * Whether the platform has mouse support.
+     */
+    static bool hasMouse();
+    
+    /**
+     * Enables or disabled mouse capture.
+     *
+     * When mouse capture is enabled, the platform cursor is hidden
+     * and mouse event points are delivered as position deltas instead
+     * of absolute positions.
+     *
+     * This is useful for games that wish to provide uninhibited mouse
+     * movement, such as when implementing free/mouse look in an FPS
+     * game.
+     *
+     * Disabling mouse capture moves the mouse back to the center of the
+     * screen and shows the platform cursor.
+     *
+     * Note that this method does nothing on platforms that do not
+     * support a mouse.
+     *
+     * @param captured True to enable mouse capture, false to disable it.
+     */
+    static void setMouseCapture(bool captured);
+
+    /**
+     * Determines if mouse capture is currently enabled.
+     */
+    static bool isMouseCaptured();
+
+    /**
+     * Sets the visibility of the platform cursor.
+     *
+     * On platforms that support a visible cursor, this method
+     * toggles the visibility of the cursor.
+     *
+     * @param visible true to show the platform cursor, false to hide it.
+     */
+    static void setCursorVisible(bool visible);
+
+    /**
+     * Determines whether the platform cursor is currently visible.
+     *
+     * @return true if the platform cursor is visible, false otherwise.
+     */
+    static bool isCursorVisible();
+
     /**
     /**
      * Gets the platform accelerometer values.
      * Gets the platform accelerometer values.
      * 
      * 

+ 28 - 0
gameplay/src/PlatformAndroid.cpp

@@ -924,6 +924,34 @@ void Platform::getAccelerometerValues(float* pitch, float* roll)
     }
     }
 }
 }
 
 
+bool Platform::hasMouse()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setMouseCapture(bool captured)
+{
+    // not supported
+}
+
+bool Platform::isMouseCaptured()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setCursorVisible(bool visible)
+{
+    // not supported
+}
+
+bool Platform::isCursorVisible()
+{
+    // not supported
+    return false;
+}
+
 void Platform::swapBuffers()
 void Platform::swapBuffers()
 {
 {
     if (__eglDisplay && __eglSurface)
     if (__eglDisplay && __eglSurface)

Dosya farkı çok büyük olduğundan ihmal edildi
+ 802 - 775
gameplay/src/PlatformMacOSX.mm


+ 28 - 0
gameplay/src/PlatformQNX.cpp

@@ -1120,6 +1120,34 @@ void Platform::getAccelerometerValues(float* pitch, float* roll)
     }
     }
 }
 }
 
 
+bool Platform::hasMouse()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setMouseCapture(bool captured)
+{
+    // not supported
+}
+
+bool Platform::isMouseCaptured()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setCursorVisible(bool visible)
+{
+    // not supported
+}
+
+bool Platform::isCursorVisible()
+{
+    // not supported
+    return false;
+}
+
 void Platform::swapBuffers()
 void Platform::swapBuffers()
 {
 {
     if (__eglDisplay && __eglSurface)
     if (__eglDisplay && __eglSurface)

+ 78 - 2
gameplay/src/PlatformWin32.cpp

@@ -24,6 +24,9 @@ static HINSTANCE __hinstance = 0;
 static HWND __hwnd = 0;
 static HWND __hwnd = 0;
 static HDC __hdc = 0;
 static HDC __hdc = 0;
 static HGLRC __hrc = 0;
 static HGLRC __hrc = 0;
+static bool __mouseCaptured = false;
+static POINT __mouseCapturePoint = { 0, 0 };
+static bool __cursorVisible = true;
 
 
 static gameplay::Keyboard::Key getKey(WPARAM win32KeyCode, bool shiftDown)
 static gameplay::Keyboard::Key getKey(WPARAM win32KeyCode, bool shiftDown)
 {
 {
@@ -255,9 +258,18 @@ void UpdateCapture(LPARAM lParam)
         ReleaseCapture();
         ReleaseCapture();
 }
 }
 
 
+void WarpMouse(int clientX, int clientY)
+{
+    POINT p = { clientX, clientY };
+    ClientToScreen(__hwnd, &p);
+    SetCursorPos(p.x, p.y);
+}
+
 LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
 {
-    if (hwnd != __hwnd)
+    static gameplay::Game* game = gameplay::Game::getInstance();
+
+    if (!game->isInitialized() || hwnd != __hwnd)
     {
     {
         // Ignore messages that are not for our game window.
         // Ignore messages that are not for our game window.
         return DefWindowProc(hwnd, msg, wParam, lParam);
         return DefWindowProc(hwnd, msg, wParam, lParam);
@@ -335,6 +347,21 @@ LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
         int x = GET_X_LPARAM(lParam);
         int x = GET_X_LPARAM(lParam);
         int y = GET_Y_LPARAM(lParam);
         int y = GET_Y_LPARAM(lParam);
 
 
+        if (__mouseCaptured)
+        {
+            // If the incoming position is the mouse capture point, ignore this event
+            // since this is the event that warped the cursor back.
+            if (x == __mouseCapturePoint.x && y == __mouseCapturePoint.y)
+                break;
+
+            // Convert to deltas
+            x -= __mouseCapturePoint.x;
+            y -= __mouseCapturePoint.y;
+
+            // Warp mouse back to center of screen.
+            WarpMouse(__mouseCapturePoint.x, __mouseCapturePoint.y);
+        }
+
         // Allow Game::mouseEvent a chance to handle (and possibly consume) the event.
         // Allow Game::mouseEvent a chance to handle (and possibly consume) the event.
         if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, x, y, 0))
         if (!gameplay::Platform::mouseEventInternal(gameplay::Mouse::MOUSE_MOVE, x, y, 0))
         {
         {
@@ -690,7 +717,7 @@ unsigned int Platform::getDisplayHeight()
 {
 {
     return __height;
     return __height;
 }
 }
-    
+
 double Platform::getAbsoluteTime()
 double Platform::getAbsoluteTime()
 {
 {
     LARGE_INTEGER queryTime;
     LARGE_INTEGER queryTime;
@@ -719,6 +746,7 @@ void Platform::setVsync(bool enable)
 
 
 void Platform::setMultiTouch(bool enabled)
 void Platform::setMultiTouch(bool enabled)
 {
 {
+    // not supported
 }
 }
 
 
 bool Platform::isMultiTouch()
 bool Platform::isMultiTouch()
@@ -735,6 +763,54 @@ void Platform::getAccelerometerValues(float* pitch, float* roll)
     *roll = __roll;
     *roll = __roll;
 }
 }
 
 
+bool Platform::hasMouse()
+{
+    return true;
+}
+
+void Platform::setMouseCapture(bool captured)
+{
+    if (captured != __mouseCaptured)
+    {
+        if (captured)
+        {
+            // Hide the cursor and warp it to the center of the screen
+            __mouseCapturePoint.x = getDisplayWidth() / 2;
+            __mouseCapturePoint.y = getDisplayHeight() / 2;
+
+            ShowCursor(FALSE);
+            WarpMouse(__mouseCapturePoint.x, __mouseCapturePoint.y);
+        }
+        else
+        {
+            // Restore cursor
+            WarpMouse(__mouseCapturePoint.x, __mouseCapturePoint.y);
+            ShowCursor(TRUE);
+        }
+
+        __mouseCaptured = captured;
+    }
+}
+
+bool Platform::isMouseCaptured()
+{
+    return __mouseCaptured;
+}
+
+void Platform::setCursorVisible(bool visible)
+{
+    if (visible != __cursorVisible)
+    {
+        ShowCursor(visible ? TRUE : FALSE);
+        __cursorVisible = visible;
+    }
+}
+
+bool Platform::isCursorVisible()
+{
+    return __cursorVisible;
+}
+
 void Platform::swapBuffers()
 void Platform::swapBuffers()
 {
 {
     if (__hdc)
     if (__hdc)

+ 28 - 0
gameplay/src/PlatformiOS.mm

@@ -894,6 +894,34 @@ void Platform::getAccelerometerValues(float* pitch, float* roll)
     [__appDelegate getAccelerometerPitch:pitch roll:roll];
     [__appDelegate getAccelerometerPitch:pitch roll:roll];
 }
 }
 
 
+bool Platform::hasMouse()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setMouseCapture(bool captured)
+{
+    // not supported
+}
+
+bool Platform::isMouseCaptured()
+{
+    // not supported
+    return false;
+}
+
+void Platform::setCursorVisible(bool visible)
+{
+    // not supported
+}
+
+bool Platform::isCursorVisible()
+{
+    // not supported
+    return false;
+}
+
 void Platform::setMultiTouch(bool enabled) 
 void Platform::setMultiTouch(bool enabled) 
 {
 {
     __view.multipleTouchEnabled = enabled;
     __view.multipleTouchEnabled = enabled;

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor