فهرست منبع

Added methods to Platform to support returning the native display resolution

Sean Paul Taylor 14 سال پیش
والد
کامیت
aafa932d20

+ 0 - 4
gameplay/src/Base.h

@@ -180,10 +180,6 @@ extern void printError(const char* format, ...);
 #define WINDOW_VSYNC        1
 #define WINDOW_FULLSCREEN   0
 
-// Display Properties
-extern const int WINDOW_WIDTH;
-extern const int WINDOW_HEIGHT;
-
 // Graphics (OpenGL)
 #if defined (__QNX__) || defined(__ANDROID__)
     #include <EGL/egl.h>

+ 9 - 2
gameplay/src/Game.cpp

@@ -68,8 +68,15 @@ int Game::run(int width, int height)
     if (_state != UNINITIALIZED)
         return -1;
 
-    _width = width;
-    _height = height;
+    if (width == -1)
+        _width = Platform::getDisplayWidth();
+    else
+        _width = width;
+    
+    if (height == -1)
+        _height = Platform::getDisplayHeight();
+    else
+        _height = height;
 
     // Start up game systems.
     if (!startup())

+ 2 - 2
gameplay/src/Game.h

@@ -96,8 +96,8 @@ public:
     /**
      * Call this method to initialize the game, and begin running the game.
      *
-     * @param width The width of the game window to run at.
-     * @param height The height of the game window to run at.
+     * @param width The width of the game window to run at. Default is -1 meaning native resolution width.
+     * @param height The height of the game window to run at. Default is -1 meaning native resolution height.
      * 
      * @return Zero for normal termination, or non-zero if an error occurred.
      */

+ 14 - 0
gameplay/src/Platform.h

@@ -36,6 +36,20 @@ public:
      * @return The platform message pump return code.
      */
     int enterMessagePump();
+    
+    /**
+     * Gets the display width.
+     * 
+     * @return The display width.
+     */
+    static unsigned int getDisplayWidth();
+    
+    /**
+     * Gets the display height.
+     * 
+     * @return The display height.
+     */
+    static unsigned int getDisplayHeight();
 
     /**
      * Gets the absolute platform time starting from when the message pump was started.

+ 11 - 1
gameplay/src/PlatformAndroid.cpp

@@ -766,7 +766,17 @@ int Platform::enterMessagePump()
         gameplay::displayKeyboard(__state, __displayKeyboard);
     }
 }
-
+   
+unsigned int Platform::getDisplayWidth()
+{
+    return __width;
+}
+    
+unsigned int Platform::getDisplayHeight()
+{
+    return __height;
+}
+    
 long Platform::getAbsoluteTime()
 {
     clock_gettime(CLOCK_REALTIME, &__timespec);

+ 15 - 1
gameplay/src/PlatformMacOS.mm

@@ -13,6 +13,10 @@
 using namespace std;
 using namespace gameplay;
 
+// Default to 720p
+#define WINDOW_WIDTH    1280
+#define WINDOW_HEIGHT   720
+
 static const float ACCELEROMETER_X_FACTOR = 90.0f / WINDOW_WIDTH;
 static const float ACCELEROMETER_Y_FACTOR = 90.0f / WINDOW_HEIGHT;
 
@@ -621,7 +625,17 @@ int Platform::enterMessagePump()
     [pool release];
     return EXIT_SUCCESS;
 }
-    
+
+unsigned int Platform::getDisplayWidth()
+{
+    return WINDOW_WIDTH;
+}
+
+unsigned int Platform::getDisplayHeight()
+{
+    return WINDOW_HEIGHT;
+}
+
 long Platform::getAbsoluteTime()
 {
     __timeAbsolute = getMachTimeInMilliseconds();

+ 10 - 0
gameplay/src/PlatformQNX.cpp

@@ -962,6 +962,16 @@ int Platform::enterMessagePump()
 
     return 0;
 }
+    
+unsigned int Platform::getDisplayWidth()
+{
+    return __screenWindowSize[0];
+}
+
+unsigned int Platform::getDisplayHeight()
+{
+    return __screenWindowSize[1];
+}
 
 long Platform::getAbsoluteTime()
 {

+ 14 - 0
gameplay/src/PlatformWin32.cpp

@@ -6,6 +6,10 @@
 #include "Game.h"
 #include <GL/wglew.h>
 
+// Default to 720p
+#define WINDOW_WIDTH    1280
+#define WINDOW_HEIGHT   720
+
 static long __timeTicksPerMillis;
 static long __timeStart;
 static long __timeAbsolute;
@@ -570,6 +574,16 @@ int Platform::enterMessagePump()
     return msg.wParam;
 }
 
+unsigned int Platform::getDisplayWidth()
+{
+    return WINDOW_WIDTH;
+}
+
+unsigned int Platform::getDisplayHeight()
+{
+    return WINDOW_HEIGHT;
+}
+    
 long Platform::getAbsoluteTime()
 {
        LARGE_INTEGER queryTime;

+ 15 - 0
gameplay/src/PlatformiOS.mm

@@ -18,6 +18,11 @@
 using namespace std;
 using namespace gameplay;
 
+// UIScreen bounds are provided as if device was in portrait mode
+// Gameplay defaults to landscape
+extern const int WINDOW_WIDTH  = [[UIScreen mainScreen] bounds].size.height;
+extern const int WINDOW_HEIGHT = [[UIScreen mainScreen] bounds].size.width;
+
 static const float ACCELEROMETER_X_FACTOR = 90.0f / WINDOW_WIDTH;
 static const float ACCELEROMETER_Y_FACTOR = 90.0f / WINDOW_HEIGHT;
 
@@ -782,6 +787,16 @@ int Platform::enterMessagePump()
     [pool release];
     return EXIT_SUCCESS;
 }
+    
+unsigned int Platform::getDisplayWidth()
+{
+    return WINDOW_WIDTH;
+}
+
+unsigned int Platform::getDisplayHeight()
+{
+    return WINDOW_HEIGHT;
+}
 
 long Platform::getAbsoluteTime()
 {

+ 0 - 5
gameplay/src/gameplay-main-ios.mm

@@ -1,14 +1,9 @@
 #ifdef __APPLE__
 
-#import <UIKit/UIKit.h>
 #include "gameplay.h"
 
 using namespace gameplay;
 
-// UIScreen bounds are provided as if device was in portrait mode
-// Gameplay defaults to landscape
-extern const int WINDOW_WIDTH  = [[UIScreen mainScreen] bounds].size.height;
-extern const int WINDOW_HEIGHT = [[UIScreen mainScreen] bounds].size.width;
 
 /**
  * Main entry point.

+ 0 - 3
gameplay/src/gameplay-main-macos.mm

@@ -4,9 +4,6 @@
 
 using namespace gameplay;
 
-extern const int WINDOW_WIDTH  = 960;
-extern const int WINDOW_HEIGHT = 640;
-
 /**
  * Main entry point.
  */

+ 0 - 2
gameplay/src/gameplay-main-qnx.cpp

@@ -4,8 +4,6 @@
 
 using namespace gameplay;
 
-extern const int WINDOW_WIDTH  = 1024;
-extern const int WINDOW_HEIGHT = 600;
 
 /**
  * Main entry point.

+ 0 - 3
gameplay/src/gameplay-main-win32.cpp

@@ -9,9 +9,6 @@ using namespace gameplay;
     #include <windows.h>
 #endif
 
-extern const int WINDOW_WIDTH  = 1024;
-extern const int WINDOW_HEIGHT = 600;
-
 /**
  * Main entry point.
  */