Forráskód Böngészése

Merge pull request #365 from 3dDeters/patch-2

Patch 2
Peter Robinson 9 éve
szülő
commit
88158d21c9

+ 3 - 2
engine/source/platformiOS/T2DView.mm

@@ -50,8 +50,9 @@ bool retinaEnabled;
 
 void ConvertToRetina(CGPoint *p)
 {
-    p->x *= 2;
-    p->y *= 2;
+    CGFloat screenScale = [[UIScreen mainScreen] scale];
+    p->x *= screenScale;
+    p->y *= screenScale;
 }
 
 @implementation T2DView

+ 1 - 1
engine/source/platformiOS/T2DViewController.mm

@@ -152,7 +152,7 @@ extern void _iOSGameInnerLoop();
     
     retinaEnabled = false;
     
-    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2)
+    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] > 1)
         retinaEnabled = true;
     
     UIApplication * application = [UIApplication sharedApplication];

+ 2 - 1
engine/source/platformiOS/iOSUtil.mm

@@ -108,6 +108,7 @@ void _iOSGameSetCurrentOrientation(int iOrientation)
 
 S32 _iOSGetPortraitTouchoffset()
 {
+// NOTE: This needs to be changed to acount for different retina sizes, but I am not sure what is going on with it yet
     S32 offset = 0;
     
     S32 deviceType = Con::getIntVariable("$pref::iOS::DeviceType");
@@ -285,4 +286,4 @@ ConsoleFunction(OpeniOSRadio, void, 2, 2, "Forces open the iOS radio if given a
             OpeniOSNetworkingAndConnectToTCPObject(NULL, argv[1]);
         }
     }
-}
+}

+ 28 - 50
engine/source/platformiOS/iOSWindow.mm

@@ -121,39 +121,36 @@ void Platform::setWindowTitle(const char *title)
 //------------------------------------------------------------------------------
 void Platform::init()
 {
-    // Create two variables that I use later to make the canvas the right size
+    // set the Platform to iOS
+    Con::setVariable("$platform", "iOS");
+    
+    // Calculate the size of the screen
     CGRect screenBounds = [[UIScreen mainScreen] bounds];
     CGFloat screenScale = [[UIScreen mainScreen] scale];
     
-    Con::setFloatVariable("$iOSwidth", screenBounds.size.width * screenScale);
-    Con::setFloatVariable("$iOSheight", screenBounds.size.height * screenScale);
-
-    Con::setVariable("$platform", "iOS");
+    // Set the screen size to a variable
+    Con::setFloatVariable("$pref::iOS::Width", screenBounds.size.width * screenScale);
+    Con::setFloatVariable("$pref::iOS::Height", screenBounds.size.height * screenScale);
     
-    if ([[UIScreen mainScreen] scale] == 2)
-        Con::setBoolVariable("$pref::iOS::RetinaEnabled", true);
-    else
-        Con::setBoolVariable("$pref::iOS::RetinaEnabled", false);
-
-    // Set the platform variable for the scripts
-    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-    {
+    // Set RetinaEnabled and the Scale
+    // NOTE: I think we could get rid of RetinaEnabled through out and just multiply directly by the scale or use RetinaScale > 1 when needed because with iPhone 6 Plus the screenScale is 3.
+    Con::setBoolVariable("$pref::iOS::RetinaEnabled", retinaEnabled);
+    Con::setBoolVariable("$pref::iOS::RetinaScale", screenScale);
+    
+    // Determine the Aspect Ratio and set the device type from that
+    float resolutionWidth = Con::getFloatVariable("$pref::iOS::Width");
+    float resolutionHeight = Con::getFloatVariable("$pref::iOS::Height");
+    
+    // NOTE: This does not work properly for portrate orientation yet, but I think the way portrate is handled over all needs a rework.
+    float Ratio = resolutionWidth/resolutionHeight;
+    
+    if (Ratio <= 1.4)// 1: iPad = 4:3
         Con::setIntVariable("$pref::iOS::DeviceType", 1);
-    }
-    else
-    {
-        F32 screenHeight = [[UIScreen mainScreen] bounds].size.height;
-        bool iPhone5 = (fabs((double)screenHeight - (double)568 ) < DBL_EPSILON);
-        if (iPhone5)
-        {
-            Con::setIntVariable("$pref::iOS::DeviceType", 2);
-            Con::setBoolVariable("$pref::iOS::RetinaEnabled", false);
-        }
-        else
-        {
-            Con::setIntVariable("$pref::iOS::DeviceType", 0);
-        }
-    }
+    else if (Ratio > 1.4 && Ratio <= 1.6)// 0: iPhone = 3:2
+        Con::setIntVariable("$pref::iOS::DeviceType", 0);
+    else if (Ratio > 1.6)// 2: iPhone 5 and up = 16:9
+        Con::setIntVariable("$pref::iOS::DeviceType", 2);
+    // Add more aspcet ratios if needed for future devices
 
     iOSConsole::create();
 
@@ -201,30 +198,11 @@ bool gScreenUpsideDown = true;
 //------------------------------------------------------------------------------
 void Platform::initWindow(const Point2I &initialSize, const char *name)
 {
-    S32 resolutionWidth = IOS_DEFAULT_RESOLUTION_X;
-    S32 resolutionHeight = IOS_DEFAULT_RESOLUTION_Y;
-
     // First fetch the values from the prefs.
-    U32 iDeviceType = (U32) Con::getIntVariable("$pref::iOS::DeviceType");
     U32 iDeviceOrientation = (U32) Con::getIntVariable("$pref::iOS::ScreenOrientation");
-    bool retinaEnabled = Con::getBoolVariable("$pref::iOS::RetinaEnabled");
-
-    // 0: iPhone
-    // 1: iPad
-    // 2: iPhone 5
-    if (iDeviceType == 2)
-    {
-        resolutionWidth = 1136;
-        resolutionHeight = 640;
-    }
-    else
-    {
-        U32 scaleFactor = retinaEnabled ? 2 : 1;
-
-        resolutionWidth = iDeviceType ? (1024 * scaleFactor) : (480 * scaleFactor);
-        resolutionHeight = iDeviceType ? (768 * scaleFactor) : (320 * scaleFactor);
-    }
-
+    S32 resolutionWidth = Con::getIntVariable("$pref::iOS::Width");
+    S32 resolutionHeight = Con::getIntVariable("$pref::iOS::Height");
+    
     Point2I startRes;
 
     if (!iDeviceOrientation)

+ 1 - 1
modules/AppCore/1/scripts/canvas.cs

@@ -46,7 +46,7 @@ function initializeCanvas(%windowName)
 
     if ($platform $= "iOS")
     {
-        %resolution = $iOSwidth SPC $iOSheight SPC "32";
+        %resolution = $pref::iOS::Width SPC $pref::iOS::Height SPC 32;
     }
     else if ($platform $= "Android")
     {