Created
October 5, 2014 00:56
-
-
Save yjpark/e3695ab3bbab60dedf97 to your computer and use it in GitHub Desktop.
Hacky fix on android device might have wrong orientation (IwGame 0.40, Marmalade 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// | |
// IwGame - Cross Platform Multi-purpose Game Engine using the Marmalade SDK | |
// | |
// Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk | |
// | |
// For updates, tutorials and more details check out my blog at www.drmop.com | |
// | |
// This code is provided free of charge and without any warranty whatsoever. The only restriction to its usage is that this header must remain intact and visible in all IwGame engine Displays. | |
// If you use this engine in your product then please ensure that you credit IwGame's usage appropriately. Please see http://www.drmop.com/index.php/iwgame-engine/ for licensing details and support | |
// | |
// | |
#include "Marm/IwGamePlatformDisplayMarm.h" | |
#include "IwGx.h" | |
#include "IwGL.h" | |
#include "Iw2D.h" | |
// | |
// Marmalade Display system | |
// | |
/* PettyFun Changes Begin */ | |
void CIwGamePlatformDisplayMarm_checkAndroidLandscapeScreenBug() { | |
IwGxScreenOrient orient = IwGxGetScreenOrient(); | |
int screen_width = IwGxGetScreenWidth(); | |
int screen_height = IwGxGetScreenHeight(); | |
int32 orientationLock = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_ORIENTATION_LOCK); | |
bool landscapeOnly = false; | |
bool portraitOnly = false; | |
if (orientationLock == S3E_SURFACE_LANDSCAPE or orientationLock == S3E_SURFACE_LANDSCAPE_FIXED) { | |
landscapeOnly = true; | |
} else if (orientationLock == S3E_SURFACE_PORTRAIT or orientationLock == S3E_SURFACE_PORTRAIT_FIXED) { | |
portraitOnly = true; | |
} | |
//Check the Android problem, the fix here is to sleep a while, reinitialise the IwGx, | |
//then try again, To make it more safer, the maximun amount of waiting time here is | |
//2s, seems in most of the tests, one sleep did the trick properly. | |
//Note: not testing on the DEVICE_OS here, might cause problem for some other devices. | |
s3eDebugOutputString("System Information: Android Landscape Screen Bug: Detected, Sleeping..."); | |
int sleepCount = 0; | |
while (sleepCount <= 20 && landscapeOnly && orient == IW_GX_ORIENT_NONE && screen_width < screen_height) { | |
sleepCount ++; | |
s3eDeviceYield(100); | |
IwGxTerminate(); | |
IwGxInit(); | |
orient = IwGxGetScreenOrient(); | |
screen_width = IwGxGetScreenWidth(); | |
screen_height = IwGxGetScreenHeight(); | |
} | |
} | |
/* PettyFun Changes End */ | |
int CIwGamePlatformDisplayMarm::Init(bool use_gl) | |
{ | |
IwGxInit(); | |
/* PettyFun Changes Begin */ | |
int32 device_os = s3eDeviceGetInt(S3E_DEVICE_OS); | |
if (device_os == S3E_OS_ID_ANDROID) { | |
CIwGamePlatformDisplayMarm_checkAndroidLandscapeScreenBug(); | |
} | |
/* PettyFun Changes End */ | |
Iw2DInit(); | |
Iw2DSetUseMipMapping(false); | |
if (use_gl) | |
IwGLInit(); | |
UseGL = use_gl; | |
return 1; | |
} | |
void CIwGamePlatformDisplayMarm::Release() | |
{ | |
if (UseGL) | |
IwGLTerminate(); | |
Iw2DTerminate(); | |
IwGxTerminate(); | |
} | |
int CIwGamePlatformDisplayMarm::getCurrentWidth() | |
{ | |
/* PettyFun Changes Begin | |
return IwGxGetScreenWidth(); | |
*/ | |
int screen_width = IwGxGetScreenWidth(); | |
int screen_height = IwGxGetScreenHeight(); | |
int32 orientationLock = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_ORIENTATION_LOCK); | |
if (orientationLock == S3E_SURFACE_LANDSCAPE or orientationLock == S3E_SURFACE_LANDSCAPE_FIXED) { | |
return MAX(screen_width, screen_height); | |
} else if (orientationLock == S3E_SURFACE_PORTRAIT or orientationLock == S3E_SURFACE_PORTRAIT_FIXED) { | |
return MIN(screen_width, screen_height); | |
} else { | |
return screen_width; | |
} | |
/* PettyFun Changes End */ | |
} | |
int CIwGamePlatformDisplayMarm::getCurrentHeight() | |
{ | |
/* PettyFun Changes Begin | |
return IwGxGetScreenHeight(); | |
*/ | |
int screen_width = IwGxGetScreenWidth(); | |
int screen_height = IwGxGetScreenHeight(); | |
int32 orientationLock = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_ORIENTATION_LOCK); | |
if (orientationLock == S3E_SURFACE_LANDSCAPE or orientationLock == S3E_SURFACE_LANDSCAPE_FIXED) { | |
return MIN(screen_width, screen_height); | |
} else if (orientationLock == S3E_SURFACE_PORTRAIT or orientationLock == S3E_SURFACE_PORTRAIT_FIXED) { | |
return MAX(screen_width, screen_height); | |
} else { | |
return screen_height; | |
} | |
/* PettyFun Changes End */ | |
} | |
void CIwGamePlatformDisplayMarm::setColour(int r, int g, int b, int a) | |
{ | |
IwGxSetColClear(r, g, b, a); | |
} | |
void CIwGamePlatformDisplayMarm::Clear() | |
{ | |
// Clear the screen | |
if (UseGL) | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
else | |
IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); | |
} | |
void CIwGamePlatformDisplayMarm::Swap() | |
{ | |
// Flush IwGx | |
IwGxFlush(); | |
// Display the rendered frame | |
if (UseGL) | |
IwGLSwapBuffers(); | |
else | |
IwGxSwapBuffers(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment