2011-05-05 11:51:13 +08:00
|
|
|
// #define COCOS2D_DEBUG 1
|
|
|
|
|
2011-03-09 17:28:35 +08:00
|
|
|
#include "CCApplication_wophone.h"
|
2011-03-02 17:45:04 +08:00
|
|
|
|
2010-12-04 18:16:09 +08:00
|
|
|
#include "ssBackLightControl.h"
|
2011-05-05 14:00:36 +08:00
|
|
|
//#include "ssKeyLockControl.h"
|
2010-12-04 18:16:09 +08:00
|
|
|
|
2011-03-02 17:45:04 +08:00
|
|
|
#include "CCScheduler.h"
|
2011-02-21 16:14:13 +08:00
|
|
|
|
2011-03-02 17:45:04 +08:00
|
|
|
NS_CC_BEGIN;
|
2011-02-21 16:14:13 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
static const Int32 CC_ON_APPLICATION_IDLE = (EVENT_FirstUser + EVENT_LastUser) / 2;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2011-01-20 10:49:30 +08:00
|
|
|
#ifdef _TRANZDA_VM_
|
|
|
|
static LARGE_INTEGER s_nAnimationInterval;
|
|
|
|
static LARGE_INTEGER s_nFreq;
|
|
|
|
static LARGE_INTEGER s_nLast;
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
static long long s_nAnimationInterval;
|
|
|
|
static long long s_nLast;
|
|
|
|
static long long getTimeOfDayMicroSecond()
|
|
|
|
{
|
|
|
|
timeval val;
|
|
|
|
gettimeofday(&val, NULL);
|
|
|
|
return (long long)val.tv_sec * 1000 * 1000 + val.tv_usec;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication::CCApplication()
|
2011-05-18 11:08:18 +08:00
|
|
|
: m_bRunning(false)
|
|
|
|
, m_bNeedStop(false)
|
|
|
|
, m_bInBackground(false)
|
|
|
|
, m_bEnterBackgroundCalled(false)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
|
|
|
memset(&m_tMsg, 0, sizeof(m_tMsg));
|
|
|
|
SS_GetCurrentGTID(&m_tMsg.gtid);
|
2011-03-07 18:20:48 +08:00
|
|
|
m_tMsg.type = CC_ON_APPLICATION_IDLE;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Sys_RegisterMessageCallBack(CC_ON_APPLICATION_IDLE, CCApplication::_OnAppIdle, (UInt32)this);
|
2011-01-18 10:14:44 +08:00
|
|
|
|
|
|
|
memset(m_AppDataPath, 0, sizeof(char) * EOS_FILE_MAX_PATH);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
TUChar AppID[EOS_FILE_MAX_PATH] = {0};
|
|
|
|
UInt32 nCmdType = 0;
|
|
|
|
Int32 nRet = SS_AppRequest_GetAppName(AppID, &nCmdType);
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(nRet < 0);
|
2011-01-18 10:14:44 +08:00
|
|
|
|
2011-04-22 10:57:46 +08:00
|
|
|
#ifndef _TRANZDA_VM_
|
|
|
|
char *pszDriver = "";
|
|
|
|
#else
|
|
|
|
char *pszDriver = "D:/Work7";
|
|
|
|
#endif
|
|
|
|
|
2011-05-09 10:03:43 +08:00
|
|
|
TUChar AppPath[EOS_FILE_MAX_PATH] = {0};
|
|
|
|
char DataPath[EOS_FILE_MAX_PATH] = {0};
|
|
|
|
|
|
|
|
// get the const data path of the application and record it
|
|
|
|
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_CONST, AppPath);
|
|
|
|
TUString::StrUnicodeToStrUtf8((Char*) DataPath, AppPath);
|
2011-04-22 10:57:46 +08:00
|
|
|
strcpy(m_AppDataPath, pszDriver);
|
|
|
|
strcat(m_AppDataPath, DataPath);
|
2011-05-09 10:03:43 +08:00
|
|
|
|
|
|
|
// get the writable data path of the application and record it
|
|
|
|
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_DATA, AppPath);
|
|
|
|
TUString::StrUnicodeToStrUtf8((Char*) DataPath, AppPath);
|
|
|
|
strcpy(m_AppWritablePath, pszDriver);
|
|
|
|
strcat(m_AppWritablePath, DataPath);
|
2011-01-18 10:14:44 +08:00
|
|
|
} while (0);
|
2011-03-02 17:45:04 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
2011-03-02 17:45:04 +08:00
|
|
|
sm_pSharedApplication = this;
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication::~CCApplication()
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
Sys_RegisterMessageCallBack(CC_ON_APPLICATION_IDLE, NULL, NULL);
|
2011-03-02 17:45:04 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
2011-03-02 17:45:04 +08:00
|
|
|
sm_pSharedApplication = NULL;
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Boolean CCApplication::EventHandler(EventType* pEvent)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-02-17 14:31:52 +08:00
|
|
|
Boolean bHandled = FALSE;
|
|
|
|
|
|
|
|
switch(pEvent->eType)
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
case EVENT_AppLoad:
|
2011-03-02 17:45:04 +08:00
|
|
|
if (! initInstance() || ! applicationDidFinishLaunching())
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
CCScheduler::purgeSharedScheduler();
|
|
|
|
SendStopEvent();
|
|
|
|
}
|
2011-01-20 10:49:30 +08:00
|
|
|
#ifdef _TRANZDA_VM_
|
|
|
|
QueryPerformanceFrequency(&s_nFreq);
|
|
|
|
QueryPerformanceCounter(&s_nLast);
|
|
|
|
#else
|
|
|
|
s_nLast = getTimeOfDayMicroSecond();
|
|
|
|
#endif
|
2010-12-02 18:44:13 +08:00
|
|
|
bHandled = TRUE;
|
|
|
|
break;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
case EVENT_AppStopNotify:
|
|
|
|
break;
|
2011-02-17 14:31:52 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
case EVENT_AppActiveNotify:
|
|
|
|
if (pEvent->sParam1 == 0)
|
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
CCLOG("EVENT_AppActiveNotify false");
|
2011-01-20 13:41:58 +08:00
|
|
|
if (!m_bInBackground)
|
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
if (! m_bEnterBackgroundCalled)
|
|
|
|
{
|
|
|
|
applicationDidEnterBackground();
|
|
|
|
m_bEnterBackgroundCalled = true;
|
|
|
|
}
|
2011-01-20 13:41:58 +08:00
|
|
|
m_bInBackground = true;
|
|
|
|
}
|
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
if (CCDirector::sharedDirector()->isPaused())
|
2010-09-25 11:54:33 +08:00
|
|
|
{
|
2011-02-17 14:31:52 +08:00
|
|
|
StopMainLoop();
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
2011-05-05 11:51:13 +08:00
|
|
|
|
|
|
|
// restore back light open mode
|
|
|
|
if (CfgGetBackLightStatus())
|
|
|
|
{
|
|
|
|
CfgTurnOnBackLightEx(SYS_BACK_LIGHT_MODE_TIME_LONG);
|
|
|
|
CCLOG("AppActiveNotify::TurnOnBackLight:MODE_TIME_LONG");
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
else if (pEvent->sParam1 > 0)
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
CCLOG("EVENT_AppActiveNotify true");
|
2011-01-20 13:41:58 +08:00
|
|
|
if (m_bInBackground)
|
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
if (m_bEnterBackgroundCalled)
|
|
|
|
{
|
|
|
|
applicationWillEnterForeground();
|
|
|
|
m_bEnterBackgroundCalled = false;
|
|
|
|
}
|
2011-01-20 13:41:58 +08:00
|
|
|
m_bInBackground = false;
|
|
|
|
}
|
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
StartMainLoop();
|
2011-02-17 14:31:52 +08:00
|
|
|
|
2011-05-05 11:51:13 +08:00
|
|
|
// modify back light open mode
|
|
|
|
if (CfgGetBackLightStatus())
|
|
|
|
{
|
2011-05-09 16:59:26 +08:00
|
|
|
// Why doesn't use CfgTurnOnBackLightEx(SYS_BACK_LIGHT_MODE_TIME_ALWAYS)?
|
|
|
|
// MODE_TIME_ALWAYS cause phone can't sleep when power button pressed.
|
2011-05-05 11:51:13 +08:00
|
|
|
CfgTurnOnBackLightDelay(0x7fffffff);
|
|
|
|
CCLOG("AppActiveNotify::TurnOnBackLight:0x7fffffff");
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
break;
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
2011-02-17 14:31:52 +08:00
|
|
|
if (FALSE == bHandled)
|
2010-08-05 10:29:29 +08:00
|
|
|
{
|
2011-02-17 14:31:52 +08:00
|
|
|
return TApplication::EventHandler(pEvent);
|
2010-08-05 10:29:29 +08:00
|
|
|
}
|
2011-02-17 14:31:52 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
return bHandled;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-02-17 14:31:52 +08:00
|
|
|
#ifdef _TRANZDA_VM_
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
s_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
|
|
|
|
#else
|
|
|
|
s_nAnimationInterval = (long long)(interval * 1000 * 1000);
|
|
|
|
#endif
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication::Orientation CCApplication::setOrientation(CCApplication::Orientation orientation)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-05-09 16:59:26 +08:00
|
|
|
return sm_OrientationTable[sm_uDesignOrientation][orientation];
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCApplication::statusBarFrame(CCRect * rect)
|
2011-02-17 14:31:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
const char* CCApplication::getAppDataPath()
|
2011-02-17 14:31:52 +08:00
|
|
|
{
|
|
|
|
return m_AppDataPath;
|
|
|
|
}
|
|
|
|
|
2011-05-09 10:03:43 +08:00
|
|
|
const char* CCApplication::getAppWritablePath()
|
|
|
|
{
|
|
|
|
return m_AppWritablePath;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCApplication::switchNotify(int nTurnOn)
|
2011-02-17 14:31:52 +08:00
|
|
|
{
|
|
|
|
bool bInBack = isInBackground();
|
|
|
|
|
2011-05-05 11:51:13 +08:00
|
|
|
// set the auto close screen and auto key lock status
|
|
|
|
|
2011-02-17 14:31:52 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// if the app have be in background,don't handle this message
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_BREAK_IF(bInBack);
|
2011-02-17 14:31:52 +08:00
|
|
|
|
|
|
|
if (! nTurnOn) // turn off screen
|
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
if (! m_bEnterBackgroundCalled)
|
|
|
|
{
|
|
|
|
applicationDidEnterBackground();
|
|
|
|
m_bEnterBackgroundCalled = true;
|
|
|
|
}
|
2011-02-17 14:31:52 +08:00
|
|
|
StopMainLoop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-05 11:51:13 +08:00
|
|
|
// modify back light open mode
|
2011-05-09 16:59:26 +08:00
|
|
|
// Why doesn't use CfgTurnOnBackLightEx(SYS_BACK_LIGHT_MODE_TIME_ALWAYS)?
|
|
|
|
// MODE_TIME_ALWAYS cause phone can't sleep when power button pressed.
|
2011-05-05 11:51:13 +08:00
|
|
|
CfgTurnOnBackLightDelay(0x7fffffff);
|
|
|
|
CCLOG("AppActiveNotify::TurnOnBackLight:0x7fffffff");
|
|
|
|
|
2011-05-18 11:08:18 +08:00
|
|
|
if (m_bEnterBackgroundCalled)
|
|
|
|
{
|
|
|
|
applicationWillEnterForeground();
|
|
|
|
m_bEnterBackgroundCalled = false;
|
|
|
|
}
|
2011-02-17 14:31:52 +08:00
|
|
|
StartMainLoop();
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
bool CCApplication::isInBackground()
|
2011-02-17 14:31:52 +08:00
|
|
|
{
|
|
|
|
return m_bInBackground;
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCApplication::StartMainLoop()
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
m_bNeedStop = FALSE;
|
2010-12-02 18:44:13 +08:00
|
|
|
if (m_bRunning)
|
2010-08-10 12:03:05 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
return;
|
2010-08-10 12:03:05 +08:00
|
|
|
}
|
2011-05-18 11:08:18 +08:00
|
|
|
CCLOG("Post StartMainLoop");
|
2010-12-02 18:44:13 +08:00
|
|
|
Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &m_tMsg);
|
|
|
|
}
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
void CCApplication::StopMainLoop()
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
|
|
|
m_bNeedStop = TRUE;
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
Int32 CCApplication::_OnAppIdle(MESSAGE_t * pMsg, UInt32 uData)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication& rThis = (CCApplication&) CCApplication::sharedApplication();
|
|
|
|
CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
|
2011-05-18 11:08:18 +08:00
|
|
|
if (pView)
|
2010-08-05 10:29:29 +08:00
|
|
|
{
|
2011-02-17 14:31:52 +08:00
|
|
|
if (rThis.m_bNeedStop)
|
2010-12-02 18:44:13 +08:00
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
CCLOG("_OnAppIdle: Stop");
|
2011-02-17 14:31:52 +08:00
|
|
|
rThis.m_bNeedStop = FALSE;
|
|
|
|
rThis.m_bRunning = FALSE;
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-18 11:08:18 +08:00
|
|
|
rThis.m_bRunning = TRUE;
|
2011-01-20 10:49:30 +08:00
|
|
|
#ifdef _TRANZDA_VM_
|
|
|
|
LARGE_INTEGER nNow;
|
|
|
|
QueryPerformanceCounter(&nNow);
|
|
|
|
if (nNow.QuadPart - s_nLast.QuadPart >= s_nAnimationInterval.QuadPart)
|
|
|
|
{
|
|
|
|
pView->UpdateWindow(0);
|
|
|
|
s_nLast.QuadPart = nNow.QuadPart;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
long long nNow = getTimeOfDayMicroSecond();
|
|
|
|
if (nNow - s_nLast >= s_nAnimationInterval)
|
|
|
|
{
|
|
|
|
pView->UpdateWindow(0);
|
|
|
|
s_nLast = nNow;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
2011-05-06 18:00:43 +08:00
|
|
|
Sys_SchedYield();
|
2011-01-20 10:49:30 +08:00
|
|
|
}
|
2011-02-17 14:31:52 +08:00
|
|
|
Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &rThis.m_tMsg);
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-08-05 10:29:29 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2011-03-02 17:45:04 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2011-05-09 16:59:26 +08:00
|
|
|
|
|
|
|
// shared application
|
|
|
|
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
|
|
|
|
2011-03-07 18:20:48 +08:00
|
|
|
CCApplication& CCApplication::sharedApplication()
|
2011-03-02 17:45:04 +08:00
|
|
|
{
|
2011-03-07 18:20:48 +08:00
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2011-03-02 17:45:04 +08:00
|
|
|
return *sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
2011-05-09 16:59:26 +08:00
|
|
|
// rotate device support
|
|
|
|
static const CCApplication::Orientation s_OrientationModeNormal[] =
|
|
|
|
{
|
|
|
|
CCApplication::kOrientationPortrait,
|
|
|
|
CCApplication::kOrientationPortraitUpsideDown,
|
|
|
|
CCApplication::kOrientationLandscapeLeft,
|
|
|
|
CCApplication::kOrientationLandscapeRight,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CCApplication::Orientation s_OrientationModeCW[] =
|
|
|
|
{
|
|
|
|
CCApplication::kOrientationLandscapeLeft,
|
|
|
|
CCApplication::kOrientationLandscapeRight,
|
|
|
|
CCApplication::kOrientationPortraitUpsideDown,
|
|
|
|
CCApplication::kOrientationPortrait,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CCApplication::Orientation s_OrientationModeUD[] =
|
|
|
|
{
|
|
|
|
CCApplication::kOrientationPortraitUpsideDown,
|
|
|
|
CCApplication::kOrientationPortrait,
|
|
|
|
CCApplication::kOrientationLandscapeRight,
|
|
|
|
CCApplication::kOrientationLandscapeLeft,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CCApplication::Orientation s_OrientationModeCCW[] =
|
|
|
|
{
|
|
|
|
CCApplication::kOrientationLandscapeRight,
|
|
|
|
CCApplication::kOrientationLandscapeLeft,
|
|
|
|
CCApplication::kOrientationPortrait,
|
|
|
|
CCApplication::kOrientationPortraitUpsideDown,
|
|
|
|
};
|
|
|
|
|
|
|
|
const CCApplication::Orientation * const CCApplication::sm_OrientationTable[] =
|
|
|
|
{
|
|
|
|
s_OrientationModeNormal,
|
|
|
|
s_OrientationModeCW,
|
|
|
|
s_OrientationModeUD,
|
|
|
|
s_OrientationModeCCW,
|
|
|
|
};
|
|
|
|
|
|
|
|
UInt32 CCApplication::sm_uDesignOrientation = WM_WINDOW_ROTATE_MODE_NORMAL;
|
|
|
|
|
|
|
|
void CCApplication::setDesignOrientation(UInt32 uOrientation)
|
|
|
|
{
|
|
|
|
sm_uDesignOrientation = uOrientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt32 CCApplication::getDesignOrientation()
|
|
|
|
{
|
|
|
|
return sm_uDesignOrientation;
|
|
|
|
}
|
|
|
|
|
2011-03-02 17:45:04 +08:00
|
|
|
NS_CC_END;
|