axmol/cocos2dx/platform/bada/CCApplication_bada.cpp

165 lines
3.3 KiB
C++
Raw Normal View History

2011-09-19 18:05:40 +08:00
#include "CCApplication_bada.h"
#include "CCDirector.h"
#include "Gbk_Unicode.h"
using namespace Osp::App;
using namespace Osp::System;
using namespace Osp::Base;
using namespace Osp::Base::Runtime;
2011-09-19 18:05:40 +08:00
NS_CC_BEGIN;
static CCApplication * s_pApplication = NULL;
static long long s_nAnimationInterval = 1000/60;
2011-09-19 18:05:40 +08:00
CCApplication::CCApplication() :
m_pTimer(null)
2011-09-19 18:05:40 +08:00
{
2011-09-19 18:17:19 +08:00
CCLog("CCApplication constructor...");
2011-09-19 18:05:40 +08:00
s_pApplication = this;
2011-09-19 18:05:40 +08:00
}
CCApplication::~CCApplication()
{
s_pApplication = NULL;
}
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();
}
CCRect CCApplication::statusBarFrame(CCRect * rect)
{
if (rect)
{
// bada doesn't have status bar.
*rect = CCRectMake(0, 0, 0, 0);
}
return *rect;
2011-09-19 18:05:40 +08:00
}
//////////////////////////////////////////////////////////////////////////
/// Implement static class member
//////////////////////////////////////////////////////////////////////////
CCApplication& CCApplication::sharedApplication()
{
CC_ASSERT(s_pApplication);
return *s_pApplication;
}
ccLanguageType CCApplication::getCurrentLanguage()
{
return kLanguageEnglish;
}
2011-09-19 18:05:40 +08:00
void CCApplication::setAnimationInterval(double interval)
{
s_nAnimationInterval = (long long)(interval * 1000);
2011-09-19 18:05:40 +08:00
}
bool CCApplication::OnAppInitializing(AppRegistry& appRegistry)
{
result r = E_FAILURE;
2011-09-20 02:19:26 +08:00
if (! initInstance() || !applicationDidFinishLaunching())
return false;
// m_pTimer = new Timer;
// if (null == m_pTimer)
// {
// return E_FAILURE;
// }
//
// r = m_pTimer->Construct(*this);
// if (IsFailed(r))
// {
// delete m_pTimer;
// m_pTimer = null;
// return E_FAILURE;
// }
// m_pTimer->Start(1);
// CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
// pView->SendUserEvent(1000, null);
2011-09-20 02:19:26 +08:00
return true;
2011-09-19 18:05:40 +08:00
}
bool CCApplication::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
{
// if (m_pTimer)
// {
// m_pTimer->Cancel();
// delete m_pTimer;
// m_pTimer = null;
// }
2011-09-19 18:05:40 +08:00
return true;
}
void CCApplication::OnForeground(void)
{
// if (m_pTimer)
// m_pTimer->Start(1);
2011-09-19 18:05:40 +08:00
}
void CCApplication::OnBackground(void)
{
// if (m_pTimer)
// m_pTimer->Cancel();
2011-09-19 18:05:40 +08:00
}
void CCApplication::OnLowMemory(void)
{
}
void CCApplication::OnBatteryLevelChanged(BatteryLevel batteryLevel)
{
}
void CCApplication::OnTimerExpired(Timer& timer)
{
// if (!m_pTimer)
// {
// return;
// }
//
// static long long oldTick = 0, curTick = 0;
// SystemTime::GetTicks(curTick);
// if (curTick - oldTick > s_nAnimationInterval)
// {
// CCDirector::sharedDirector()->mainLoop();
// SystemTime::GetTicks(oldTick);
// }
// m_pTimer->Start(1);
}
2011-09-19 18:05:40 +08:00
void CCApplication::OnUserEventReceivedN(RequestId requestId, Osp::Base::Collection::IList* pArgs)
{
static long long oldTick = 0, curTick = 0;
SystemTime::GetTicks(curTick);
if (curTick - oldTick > s_nAnimationInterval)
{
CCDirector::sharedDirector()->mainLoop();
CCEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
pView->SendUserEvent(1000, null);
SystemTime::GetTicks(oldTick);
}
else
{
Thread::Sleep(1);
}
}
2011-09-19 18:05:40 +08:00
NS_CC_END;