2010-08-03 11:23:12 +08:00
|
|
|
#include "CCXApplication_uphone.h"
|
|
|
|
|
2010-12-04 18:16:09 +08:00
|
|
|
#include "ssBackLightControl.h"
|
|
|
|
#include "ssKeyLockControl.h"
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
#include "CCDirector.h"
|
2010-11-11 11:18:58 +08:00
|
|
|
#include "CCScheduler.h"
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-08-31 16:53:25 +08:00
|
|
|
// #include "CCXGLExtFunc.h"
|
|
|
|
#include <GLES/glext.h>
|
2010-08-16 12:29:06 +08:00
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
static const Int32 CCX_ON_APPLICATION_IDLE = (EVENT_FirstUser + EVENT_LastUser) / 2;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
CCXApplication::CCXApplication()
|
|
|
|
: m_bRunning(FALSE)
|
|
|
|
, m_bNeedStop(FALSE)
|
|
|
|
{
|
|
|
|
memset(&m_tMsg, 0, sizeof(m_tMsg));
|
|
|
|
SS_GetCurrentGTID(&m_tMsg.gtid);
|
|
|
|
m_tMsg.type = CCX_ON_APPLICATION_IDLE;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
Sys_RegisterMessageCallBack(CCX_ON_APPLICATION_IDLE, CCXApplication::_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);
|
|
|
|
CCX_BREAK_IF(nRet < 0);
|
|
|
|
|
|
|
|
TUChar AppPath[EOS_FILE_MAX_PATH] = {0};
|
|
|
|
SS_GetApplicationPath(AppID, SS_APP_PATH_TYPE_EXECUTABLE, AppPath);
|
|
|
|
TUString::StrUnicodeToStrUtf8((Char*) m_AppDataPath, AppPath);
|
|
|
|
} while (0);
|
2010-12-02 18:44:13 +08:00
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
CCXApplication::~CCXApplication()
|
|
|
|
{
|
|
|
|
Sys_RegisterMessageCallBack(CCX_ON_APPLICATION_IDLE, NULL, NULL);
|
|
|
|
}
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
Boolean CCXApplication::EventHandler(EventType * pEvent)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
if (! applicationDidFinishLaunching())
|
2010-08-03 11:23:12 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
CCScheduler::purgeSharedScheduler();
|
|
|
|
SendStopEvent();
|
|
|
|
}
|
|
|
|
bHandled = TRUE;
|
|
|
|
break;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
case EVENT_AppStopNotify:
|
2010-08-03 11:23:12 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
break;
|
|
|
|
case EVENT_AppActiveNotify:
|
|
|
|
if (pEvent->sParam1 == 0)
|
|
|
|
{
|
|
|
|
applicationDidEnterBackground();
|
|
|
|
if (CCDirector::sharedDirector()->isPaused())
|
2010-09-25 11:54:33 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
StopMainLoop();
|
2010-09-25 11:54:33 +08:00
|
|
|
}
|
2010-12-09 11:41:32 +08:00
|
|
|
CfgTurnOnBackLight();
|
2010-12-04 18:16:09 +08:00
|
|
|
EnableKeyLock();
|
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
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
applicationWillEnterForeground();
|
|
|
|
StartMainLoop();
|
2010-12-04 18:16:09 +08:00
|
|
|
|
2010-12-09 11:41:32 +08:00
|
|
|
CfgTurnOnBackLightDelay(0x7fffffff);
|
2010-12-04 18:16:09 +08:00
|
|
|
// if KeyLock disactived, disable it.
|
|
|
|
if (! CfgKeyLock_GetActive())
|
|
|
|
{
|
|
|
|
DisableKeyLock();
|
|
|
|
}
|
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
|
|
|
}
|
2010-08-05 10:29:29 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
if (! bHandled)
|
2010-08-05 10:29:29 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
bHandled = TApplication::EventHandler(pEvent);
|
2010-08-05 10:29:29 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
return bHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccDeviceOrientation CCXApplication::setDeviceOrientation(ccDeviceOrientation eOritation)
|
|
|
|
{
|
|
|
|
return eOritation;
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
CGRect CCXApplication::statusBarFrame()
|
|
|
|
{
|
|
|
|
CGRect rc;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCXApplication::StartMainLoop()
|
|
|
|
{
|
|
|
|
if (m_bRunning)
|
2010-08-10 12:03:05 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
m_bNeedStop = FALSE;
|
|
|
|
return;
|
2010-08-10 12:03:05 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &m_tMsg);
|
|
|
|
m_bRunning = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCXApplication::StopMainLoop()
|
|
|
|
{
|
|
|
|
m_bNeedStop = TRUE;
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2010-12-02 18:44:13 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
/// Implement static class member
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CCXApplication * CCXApplication::sharedApplication()
|
|
|
|
{
|
|
|
|
return (CCXApplication *)TApplication::GetCurrentApplication();
|
|
|
|
}
|
|
|
|
|
|
|
|
Int32 CCXApplication::_OnAppIdle(MESSAGE_t * pMsg, UInt32 uData)
|
|
|
|
{
|
|
|
|
CCXApplication * pThis = CCXApplication::sharedApplication();
|
|
|
|
CCXEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
|
|
|
|
if (pThis && pView && pThis->m_bRunning)
|
2010-08-05 10:29:29 +08:00
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
if (pThis->m_bNeedStop)
|
|
|
|
{
|
|
|
|
pThis->m_bNeedStop = FALSE;
|
|
|
|
pThis->m_bRunning = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pView->UpdateWindow(0);
|
|
|
|
Sys_PostMessage2(MESSAGE_PRIOR_LOWEST, &pThis->m_tMsg);
|
|
|
|
}
|
2010-08-05 10:29:29 +08:00
|
|
|
}
|
2010-12-02 18:44:13 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2010-08-10 12:03:05 +08:00
|
|
|
|
2011-01-18 10:14:44 +08:00
|
|
|
const char* CCXApplication::getAppDataPath()
|
|
|
|
{
|
|
|
|
return m_AppDataPath;
|
|
|
|
}
|
|
|
|
|
2011-01-19 22:29:57 +08:00
|
|
|
void CCXApplication::setAnimationInterval(double interval)
|
|
|
|
{
|
|
|
|
// tbd
|
|
|
|
}
|
|
|
|
|
2010-08-03 11:23:12 +08:00
|
|
|
}
|
2011-01-19 22:29:57 +08:00
|
|
|
|