axmol/cocos2dx/platform/win32/CCXApplication_win32.cpp

101 lines
2.1 KiB
C++
Raw Normal View History

#include "CCXApplication_win32.h"
#include "CCDirector.h"
namespace cocos2d {
2010-10-09 17:41:42 +08:00
static CCXApplication * s_pApplication;
2010-10-09 17:41:42 +08:00
CCXApplication::CCXApplication()
: m_hAccelTable(NULL)
2010-10-09 17:41:42 +08:00
{
m_hInstance = GetModuleHandle(NULL);
s_pApplication = this;
}
2010-10-09 17:41:42 +08:00
CCXApplication::~CCXApplication()
{
s_pApplication = NULL;
2010-10-09 17:41:42 +08:00
}
ccDeviceOrientation CCXApplication::setDeviceOrientation(ccDeviceOrientation eOritation)
2010-10-09 17:41:42 +08:00
{
// swap width and height
CCXEGLView * pView = CCDirector::sharedDirector()->getOpenGLView();
if (pView)
{
return (ccDeviceOrientation)pView->setDeviceOrientation(eOritation);
}
return CCDirector::sharedDirector()->getDeviceOrientation();
2010-10-09 17:41:42 +08:00
}
CGRect CCXApplication::statusBarFrame()
{
CGRect rc;
return rc;
2010-10-09 17:41:42 +08:00
}
int CCXApplication::Run()
{
// Main message loop:
MSG msg;
2011-01-19 17:59:20 +08:00
LARGE_INTEGER nFreq;
LARGE_INTEGER nLast;
LARGE_INTEGER nNow;
QueryPerformanceFrequency(&nFreq);
QueryPerformanceCounter(&nLast);
if ( !applicationDidFinishLaunching() )
{
return 0;
}
while (1)
2010-10-09 17:41:42 +08:00
{
if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
2011-01-19 17:59:20 +08:00
QueryPerformanceCounter(&nNow);
2011-01-20 10:49:30 +08:00
if (nNow.QuadPart - nLast.QuadPart >= m_nAnimationInterval.QuadPart)
{
2011-01-19 17:59:20 +08:00
nLast.QuadPart = nNow.QuadPart;
CCDirector::sharedDirector()->mainLoop();
}
else
{
Sleep(0);
}
2010-10-09 17:41:42 +08:00
continue;
}
if (WM_QUIT == msg.message)
{
break;
}
if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//////////////////////////////////////////////////////////////////////////
/// Implement static class member
//////////////////////////////////////////////////////////////////////////
2010-11-16 15:12:09 +08:00
CCXApplication * CCXApplication::sharedApplication()
2010-10-09 17:41:42 +08:00
{
return s_pApplication;
2010-10-09 17:41:42 +08:00
}
2011-01-19 17:59:20 +08:00
void CCXApplication::setAnimationInterval(double interval)
{
LARGE_INTEGER nFreq;
QueryPerformanceFrequency(&nFreq);
m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
2011-01-19 17:59:20 +08:00
}
}