diff --git a/CocosDenshion/bada/SimpleAudioEngine.cpp b/CocosDenshion/bada/SimpleAudioEngine.cpp index 010b48cb21..e2a33c701d 100644 --- a/CocosDenshion/bada/SimpleAudioEngine.cpp +++ b/CocosDenshion/bada/SimpleAudioEngine.cpp @@ -48,6 +48,25 @@ static unsigned int _Hash(const char *key) return (hash); } +static string fullPathFromRelativePath(const char *pszRelativePath) +{ + string strRet=""; + int len = strlen(pszRelativePath); + if (pszRelativePath == NULL || len <= 0) + return NULL; + + if (len > 1 && pszRelativePath[0] == '/') + { + strRet = pszRelativePath; + } + else + { + strRet = s_strResourcePath; + strRet += pszRelativePath; + } + return strRet; +} + class MyPlayerEventListener : public IPlayerEventListener { @@ -189,7 +208,7 @@ static bool openMediaPlayer(Player*& pPlayer, const char* pszFilePath, bool bLoo } } - string strFilePath = s_strResourcePath+pszFilePath; + string strFilePath = fullPathFromRelativePath(pszFilePath); // OpenFile must use synchronous param, for after that it will playing. r = pPlayer->OpenFile(strFilePath.c_str(), false); if (IsFailed(r)) @@ -386,7 +405,7 @@ unsigned int SimpleAudioEngine::playEffect(const char* pszFilePath, bool bLoop/* long long curTick, oldTick; SystemTime::GetTicks(oldTick); result r = E_FAILURE; - string strFilePath = s_strResourcePath+pszFilePath; + string strFilePath = fullPathFromRelativePath(pszFilePath); unsigned int nRet = _Hash(strFilePath.c_str()); AppLog("play effect (%s)", pszFilePath); preloadEffect(pszFilePath); @@ -452,7 +471,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) { BREAK_IF(! pszFilePath); - string strFilePath = s_strResourcePath+pszFilePath; + string strFilePath = fullPathFromRelativePath(pszFilePath); nRet = _Hash(strFilePath.c_str()); @@ -482,7 +501,7 @@ void SimpleAudioEngine::preloadEffect(const char* pszFilePath) void SimpleAudioEngine::unloadEffect(const char* pszFilePath) { - string strFilePath = s_strResourcePath+pszFilePath; + string strFilePath = fullPathFromRelativePath(pszFilePath); unsigned int nSoundId = _Hash(strFilePath.c_str()); CCAudioOut*& pPlayer = s_List[nSoundId]; pPlayer->Reset(); diff --git a/HelloWorld/Classes/AppDelegate.cpp b/HelloWorld/Classes/AppDelegate.cpp index 30503e2932..dee1028525 100644 --- a/HelloWorld/Classes/AppDelegate.cpp +++ b/HelloWorld/Classes/AppDelegate.cpp @@ -74,6 +74,7 @@ bool AppDelegate::initInstance() { CCEGLView * pMainWnd = new CCEGLView(); CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320)); + pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE); CCFileUtils::setResourcePath("/Res/"); #endif // CC_PLATFORM_BADA @@ -94,9 +95,7 @@ bool AppDelegate::applicationDidFinishLaunching() { // turn on display FPS pDirector->setDisplayFPS(true); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA) - pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif + // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // set FPS. the default value is 1.0/60 if you don't call this diff --git a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp index c7202dd927..add8192f99 100644 --- a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp +++ b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp @@ -24,7 +24,9 @@ THE SOFTWARE. #include "CCAccelerometer_bada.h" #include "ccMacros.h" +#include "CCEGLView_bada.h" +using namespace Osp::Ui; using namespace Osp::Uix; NS_CC_BEGIN; @@ -75,7 +77,18 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Y, y); sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Z, z); - // only consider land postion, to be continued. + /* + * Because the axes are not swapped when the device's screen orientation changes. + * So we should swap it here. + */ + Orientation orientation = CCEGLView::sharedOpenGLView().GetOrientation(); + if (orientation == ORIENTATION_LANDSCAPE || orientation == ORIENTATION_LANDSCAPE_REVERSE) + { + float tmp = x; + x = -y; + y = tmp; + } + CCAcceleration AccValue; AccValue.x = -x; AccValue.y = -y; diff --git a/cocos2dx/platform/bada/CCApplication_bada.cpp b/cocos2dx/platform/bada/CCApplication_bada.cpp index e9cbfc0aec..c70809d146 100644 --- a/cocos2dx/platform/bada/CCApplication_bada.cpp +++ b/cocos2dx/platform/bada/CCApplication_bada.cpp @@ -27,13 +27,7 @@ CCApplication::~CCApplication() CCApplication::Orientation CCApplication::setOrientation(CCApplication::Orientation orientation) { - // swap width and height - CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView(); - if (pView) - { - return (Orientation)pView->setDeviceOrientation(orientation); - } - return (Orientation)CCDirector::sharedDirector()->getDeviceOrientation(); + return orientation; } CCRect CCApplication::statusBarFrame(CCRect * rect) diff --git a/cocos2dx/platform/bada/CCEGLView_bada.cpp b/cocos2dx/platform/bada/CCEGLView_bada.cpp index 5b47115334..c416b0a83f 100644 --- a/cocos2dx/platform/bada/CCEGLView_bada.cpp +++ b/cocos2dx/platform/bada/CCEGLView_bada.cpp @@ -183,7 +183,6 @@ CCEGLView::CCEGLView() , m_fScreenScaleFactor(1.0) , m_bCaptured(false) , m_pEGL(NULL) -, m_nowOrientation(ORIENTATION_PORTRAIT) { m_pTouch = new CCTouch; m_pSet = new CCSet; @@ -261,19 +260,11 @@ void CCEGLView::setContentScaleFactor(float contentScaleFactor) m_fScreenScaleFactor = contentScaleFactor; } -static int badaOrientation[4] = { - ORIENTATION_PORTRAIT, - ORIENTATION_PORTRAIT_REVERSE, - ORIENTATION_LANDSCAPE, - ORIENTATION_LANDSCAPE_REVERSE -}; - -int CCEGLView::setDeviceOrientation(int eOritation) +int CCEGLView::setDeviceOrientation(Orientation eOritation) { - m_nowOrientation = (Orientation)badaOrientation[eOritation]; - SetOrientation(m_nowOrientation); + SetOrientation(eOritation); - if (m_nowOrientation == ORIENTATION_PORTRAIT || m_nowOrientation == ORIENTATION_PORTRAIT_REVERSE) + if (eOritation == ORIENTATION_PORTRAIT || eOritation == ORIENTATION_PORTRAIT_REVERSE) { int width = MIN(m_sSizeInPixel.width, m_sSizeInPixel.height); m_sSizeInPixel.height = MAX(m_sSizeInPixel.width, m_sSizeInPixel.height); @@ -295,7 +286,6 @@ int CCEGLView::setDeviceOrientation(int eOritation) } return m_eInitOrientation; -// return eOritation; } void CCEGLView::setViewPortInPoints(float x, float y, float w, float h) diff --git a/cocos2dx/platform/bada/CCEGLView_bada.h b/cocos2dx/platform/bada/CCEGLView_bada.h index ec1a6e64f4..d2009ea2e7 100644 --- a/cocos2dx/platform/bada/CCEGLView_bada.h +++ b/cocos2dx/platform/bada/CCEGLView_bada.h @@ -57,7 +57,7 @@ public: bool canSetContentScaleFactor(); void setContentScaleFactor(float contentScaleFactor); - int setDeviceOrientation(int eOritation); + int setDeviceOrientation(Osp::Ui::Orientation eOritation); void setViewPortInPoints(float x, float y, float w, float h); void setScissorInPoints(float x, float y, float w, float h); diff --git a/cocos2dx/platform/bada/CCFileUtils_bada.cpp b/cocos2dx/platform/bada/CCFileUtils_bada.cpp index 3189001bc5..739e3b659b 100644 --- a/cocos2dx/platform/bada/CCFileUtils_bada.cpp +++ b/cocos2dx/platform/bada/CCFileUtils_bada.cpp @@ -30,7 +30,7 @@ using namespace std; NS_CC_BEGIN; // record the resource path -static string s_strResourcePath = "/Res/"; +static string s_strResourcePath = ""; void CCFileUtils::setResourcePath(const char* pszResourcePath) { @@ -40,19 +40,15 @@ void CCFileUtils::setResourcePath(const char* pszResourcePath) const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath) { + int len = strlen(pszRelativePath); + if (pszRelativePath == NULL || len <= 0) + return NULL; CCString * pRet = new CCString(); pRet->autorelease(); - if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':') - || pszRelativePath[0] == '/') + if (len > 1 && pszRelativePath[0] == '/') { pRet->m_sString = pszRelativePath; } - else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/') - { - char szDriver[3] = {s_strResourcePath[0], s_strResourcePath[1], 0}; - pRet->m_sString = szDriver; - pRet->m_sString += pszRelativePath; - } else { pRet->m_sString = s_strResourcePath; diff --git a/tests/AppDelegate.cpp b/tests/AppDelegate.cpp index 098bcfd233..95e12f2ae8 100644 --- a/tests/AppDelegate.cpp +++ b/tests/AppDelegate.cpp @@ -79,6 +79,7 @@ bool AppDelegate::initInstance() CCEGLView * pMainWnd = new CCEGLView(); CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320)); + pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE); CCFileUtils::setResourcePath("/Res/"); #endif // CC_PLATFORM_BADA @@ -93,9 +94,7 @@ bool AppDelegate::applicationDidFinishLaunching() // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA) - CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); -#endif + // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // pDirector->enableRetinaDisplay(true); diff --git a/tests/test.android/build_native.sh b/tests/test.android/build_native.sh index 555230edd8..f69d584f22 100644 --- a/tests/test.android/build_native.sh +++ b/tests/test.android/build_native.sh @@ -1,7 +1,7 @@ #!/bin/bash # set params -ANDROID_NDK_ROOT=/home/laschweinski/android/android-ndk-r5/ -COCOS2DX_ROOT=/home/laschweinski/git/cocos2d-x +ANDROID_NDK_ROOT=/cygdrive/e/android/android-ndk-r5 +COCOS2DX_ROOT=/cygdrive/f/Project/dumganhar/cocos2d-x TESTS_ROOT=$COCOS2DX_ROOT/tests/test.android # make sure assets is exist diff --git a/tests/test.android/default.properties b/tests/test.android/default.properties index 9d135cb85f..32299c258a 100644 --- a/tests/test.android/default.properties +++ b/tests/test.android/default.properties @@ -1,11 +1,2 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "build.properties", and override values to adapt the script to your -# project structure. - # Project target. -target=android-7 +target=android-8 diff --git a/tests/test.android/gen/org/cocos2dx/tests/R.java b/tests/test.android/gen/org/cocos2dx/tests/R.java index 298ffe08a6..3a5224563e 100644 --- a/tests/test.android/gen/org/cocos2dx/tests/R.java +++ b/tests/test.android/gen/org/cocos2dx/tests/R.java @@ -1,26 +1,26 @@ -/* AUTO-GENERATED FILE. DO NOT MODIFY. - * - * This class was automatically generated by the - * aapt tool from the resource data it found. It - * should not be modified by hand. - */ - -package org.cocos2dx.tests; - -public final class R { - public static final class attr { - } - public static final class drawable { - public static final int icon=0x7f020000; - } - public static final class id { - public static final int test_demo_gl_surfaceview=0x7f050001; - public static final int textField=0x7f050000; - } - public static final class layout { - public static final int test_demo=0x7f030000; - } - public static final class string { - public static final int app_name=0x7f040000; - } -} +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package org.cocos2dx.tests; + +public final class R { + public static final class attr { + } + public static final class drawable { + public static final int icon=0x7f020000; + } + public static final class id { + public static final int test_demo_gl_surfaceview=0x7f050001; + public static final int textField=0x7f050000; + } + public static final class layout { + public static final int test_demo=0x7f030000; + } + public static final class string { + public static final int app_name=0x7f040000; + } +} diff --git a/tests/tests/AccelerometerTest/AccelerometerTest.cpp b/tests/tests/AccelerometerTest/AccelerometerTest.cpp index accfce1449..fdfe280cfe 100644 --- a/tests/tests/AccelerometerTest/AccelerometerTest.cpp +++ b/tests/tests/AccelerometerTest/AccelerometerTest.cpp @@ -57,7 +57,7 @@ void AccelerometerTest::didAccelerate(CCAcceleration* pAccelerationValue) // } // // m_fLastTime = fNow; - + CCLog("acc x = %f, y=%f, z=%f", pAccelerationValue->x, pAccelerationValue->y, pAccelerationValue->z); CCDirector* pDir = CCDirector::sharedDirector(); CCSize winSize = pDir->getWinSize(); diff --git a/tests/tests/ChipmunkTest/cocos2dChipmunkDemo.cpp b/tests/tests/ChipmunkTest/cocos2dChipmunkDemo.cpp index fd1640421b..71c8bb8394 100644 --- a/tests/tests/ChipmunkTest/cocos2dChipmunkDemo.cpp +++ b/tests/tests/ChipmunkTest/cocos2dChipmunkDemo.cpp @@ -486,7 +486,7 @@ void ChipmunkTestLayer::onEnter() glMatrixMode(GL_PROJECTION); glLoadIdentity(); -#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE || CC_TARGET_PLATFORM == CC_PLATFORM_BADA) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) // portraint //glOrthof(-320/factor, 320/factor, -480/factor, 480/factor, -1.0f, 1.0f); // landscape diff --git a/tests/tests/DirectorTest/DirectorTest.cpp b/tests/tests/DirectorTest/DirectorTest.cpp index f116499896..2137052e84 100644 --- a/tests/tests/DirectorTest/DirectorTest.cpp +++ b/tests/tests/DirectorTest/DirectorTest.cpp @@ -9,7 +9,6 @@ CCLayer* restartDirectorTestCase(); static int sceneIdx=-1; static ccDeviceOrientation s_currentOrientation = CCDeviceOrientationPortrait; -static ccDeviceOrientation s_oldOrientation = CCDeviceOrientationPortrait; CCLayer* createTestCaseLayer(int index) { @@ -216,13 +215,12 @@ void DirectorTestScene::runThisTest() s_currentOrientation = CCDeviceOrientationPortrait; CCLayer* pLayer = nextDirectorTestCase(); addChild(pLayer); - s_oldOrientation = CCDirector::sharedDirector()->getDeviceOrientation(); - CCLog("s_oldOri = %d", s_oldOrientation); + CCDirector::sharedDirector()->replaceScene(this); } void DirectorTestScene::MainMenuCallback(CCObject* pSender) { - CCDirector::sharedDirector()->setDeviceOrientation(s_oldOrientation); + CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait); TestScene::MainMenuCallback(pSender); }