Quellcode durchsuchen

Changed Game::setMouseCapture and Platform::setMouseCapture to setMouseCaptured.
Updated the Platform to required optional attachToWindow to attach to or process the game loop independently removing bool loop.

setaylor vor 13 Jahren
Ursprung
Commit
635aa6cb3a

+ 2 - 2
gameplay/src/Game.cpp

@@ -72,9 +72,9 @@ bool Game::isMouseCaptured()
     return Platform::isMouseCaptured();
 }
 
-void Game::setMouseCapture(bool captured)
+void Game::setMouseCaptured(bool captured)
 {
-    Platform::setMouseCapture(captured);
+    Platform::setMouseCaptured(captured);
 }
 
 void Game::setCursorVisible(bool visible)

+ 2 - 2
gameplay/src/Game.h

@@ -100,9 +100,9 @@ public:
      *
      * @param captured true to enable mouse capture mode, false to disable it.
      *
-     * @see Platform::setMouseCapture(bool)
+     * @see Platform::setMouseCaptured(bool)
      */
-    static void setMouseCapture(bool captured);
+    static void setMouseCaptured(bool captured);
 
     /**
      * Sets the visibility of the platform cursor.

+ 2 - 2
gameplay/src/Joystick.cpp

@@ -105,9 +105,9 @@ bool Joystick::touchEvent(Touch::TouchEvent touchEvent, int x, int y, unsigned i
 
                 notifyListeners(Listener::PRESS);
 
-                _displacement.set(0.0f, 0.0f);
+                _displacement.set(dx, dy);
                 
-                Vector2 value(0.0f, 0.0f);
+                Vector2 value(dx, dy);
                 if (_value != value)
                 {
                     _value.set(value);

+ 6 - 9
gameplay/src/Platform.h

@@ -26,11 +26,11 @@ public:
      * Creates a platform for the specified game which is will interacte with.
      *
      * @param game The game to create a platform for.
-     * @param nativeWindow The native window handle to optionally attach to.
+     * @param attachToWindow The native window handle to optionally attach to.
      * 
      * @return The created platform interface.
      */
-    static Platform* create(Game* game, unsigned int nativeWindow = 0);
+    static Platform* create(Game* game, void* attachToWindow = NULL);
 
     /**
      * Begins processing the platform messages.
@@ -38,15 +38,12 @@ public:
      * This method handles all OS window messages and drives the game loop.
      * It normally does not return until the application is closed.
      * 
-     * If a nativeWindow is passed the game is started but not looped. 
-     * The user must pump the game along from the seperate window via
-     * game events and Platform::swapBuffers
-     * 
-     * @param loop true to run the game loop; false to not.
+     * If a attachToWindow is passed to Platform::create the message pump will instead attach
+     * to or allow the attachToWindow to drive the game loop on the platform.
      *
      * @return The platform message pump return code.
      */
-    int enterMessagePump(bool loop = true);
+    int enterMessagePump();
     
     /**
      * This method informs the platform that the game is shutting down 
@@ -134,7 +131,7 @@ public:
      *
      * @param captured True to enable mouse capture, false to disable it.
      */
-    static void setMouseCapture(bool captured);
+    static void setMouseCaptured(bool captured);
 
     /**
      * Determines if mouse capture is currently enabled.

+ 3 - 4
gameplay/src/PlatformAndroid.cpp

@@ -715,14 +715,13 @@ Platform::~Platform()
 {
 }
 
-Platform* Platform::create(Game* game, unsigned int nativeWindow)
+Platform* Platform::create(Game* game, void* attachToWindow)
 {
     Platform* platform = new Platform(game);
-    
     return platform;
 }
 
-int Platform::enterMessagePump(bool loop)
+int Platform::enterMessagePump()
 {
     GP_ASSERT(__state && __state->activity && __state->activity->vm);
 
@@ -930,7 +929,7 @@ bool Platform::hasMouse()
     return false;
 }
 
-void Platform::setMouseCapture(bool captured)
+void Platform::setMouseCaptured(bool captured)
 {
     // not supported
 }

+ 5 - 6
gameplay/src/PlatformMacOSX.mm

@@ -14,8 +14,6 @@
 using namespace std;
 using namespace gameplay;
 
-static unsigned int __nativeWindow = 0L;
-
 // Default to 720p
 static int __width = 1280;
 static int __height = 720;
@@ -37,6 +35,7 @@ static bool __otherMouseDown = false;
 static bool __shiftDown = false;
 static char* __title = NULL;
 static bool __fullscreen = false;
+static void* __attachToWindow = NULL;
 
 
 double getMachTimeInMilliseconds()
@@ -619,15 +618,15 @@ Platform::~Platform()
 {
 }
 
-Platform* Platform::create(Game* game, unsigned int nativeWindow)
+Platform* Platform::create(Game* game, void* attachToWindow)
 {
-	__nativeWindow = nativeWindow;
+	__attachToWindow = attachToWindow;
     Platform* platform = new Platform(game);
     
     return platform;
 }
 
-int Platform::enterMessagePump(bool loop)
+int Platform::enterMessagePump()
 {
     NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
     NSString* path = [bundlePath stringByAppendingString:@"/Contents/Resources/"];
@@ -764,7 +763,7 @@ bool Platform::hasMouse()
     return true;
 }
 
-void Platform::setMouseCapture(bool captured)
+void Platform::setMouseCaptured(bool captured)
 {
     // TODO: not implemented
 }

+ 3 - 4
gameplay/src/PlatformQNX.cpp

@@ -488,10 +488,9 @@ Platform::~Platform()
     }
 }
 
-Platform* Platform::create(Game* game, unsigned int nativeWindow)
+Platform* Platform::create(Game* game, void* attachToWindow)
 {
     FileSystem::setResourcePath("./app/native/");
-
     Platform* platform = new Platform(game);
 
     bps_initialize();
@@ -774,7 +773,7 @@ void mouseOrTouchEvent(Mouse::MouseEvent mouseEvent, Touch::TouchEvent touchEven
     }
 }
 
-int Platform::enterMessagePump(bool loop)
+int Platform::enterMessagePump()
 {
     GP_ASSERT(_game);
 
@@ -1126,7 +1125,7 @@ bool Platform::hasMouse()
     return false;
 }
 
-void Platform::setMouseCapture(bool captured)
+void Platform::setMouseCaptured(bool captured)
 {
     // not supported
 }

+ 8 - 7
gameplay/src/PlatformWin32.cpp

@@ -21,6 +21,7 @@ static bool __vsync = WINDOW_VSYNC;
 static float __roll;
 static float __pitch;
 static HINSTANCE __hinstance = 0;
+static HWND __attachToWindow = 0;
 static HWND __hwnd = 0;
 static HDC __hdc = 0;
 static HGLRC __hrc = 0;
@@ -539,18 +540,18 @@ bool initializeGL()
     return true;
 }
 
-Platform* Platform::create(Game* game, unsigned int nativeWindow)
+Platform* Platform::create(Game* game, void* attachToWindow)
 {
     GP_ASSERT(game);
 
     FileSystem::setResourcePath("./");
-
     Platform* platform = new Platform(game);
 
     // Get the application module handle.
     __hinstance = ::GetModuleHandle(NULL);
 
-    if (!nativeWindow)
+    __attachToWindow = (HWND)attachToWindow;
+    if (!__attachToWindow)
     {
         LPCTSTR windowClass = L"gameplay";
         std::wstring windowName;
@@ -655,7 +656,7 @@ Platform* Platform::create(Game* game, unsigned int nativeWindow)
     else
     {
         // Attach to a previous windows
-        __hwnd = (HWND)nativeWindow;
+        __hwnd = (HWND)__attachToWindow;
         __hdc = GetDC(__hwnd);
 
         SetWindowLongPtr(__hwnd, GWL_WNDPROC, (LONG)(WNDPROC)__WndProc);
@@ -672,7 +673,7 @@ error:
     return NULL;
 }
 
-int Platform::enterMessagePump(bool loop)
+int Platform::enterMessagePump()
 {
     GP_ASSERT(_game);
     int rc = 0;
@@ -695,7 +696,7 @@ int Platform::enterMessagePump(bool loop)
     if (_game->getState() != Game::RUNNING)
         _game->run();
 
-    if (!loop)
+    if (__attachToWindow)
         return 0;
 
     // Enter event dispatch loop.
@@ -791,7 +792,7 @@ bool Platform::hasMouse()
     return true;
 }
 
-void Platform::setMouseCapture(bool captured)
+void Platform::setMouseCaptured(bool captured)
 {
     if (captured != __mouseCaptured)
     {

+ 3 - 3
gameplay/src/PlatformiOS.mm

@@ -833,13 +833,13 @@ Platform::~Platform()
 {
 }
 
-Platform* Platform::create(Game* game, unsigned int nativeWindow)
+Platform* Platform::create(Game* game, void* attachToWindow)
 {
     Platform* platform = new Platform(game);
     return platform;
 }
 
-int Platform::enterMessagePump(bool loop)
+int Platform::enterMessagePump()
 {
     NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
     [AppDelegate load];
@@ -900,7 +900,7 @@ bool Platform::hasMouse()
     return false;
 }
 
-void Platform::setMouseCapture(bool captured)
+void Platform::setMouseCaptured(bool captured)
 {
     // not supported
 }