2012-04-19 14:35:52 +08:00
|
|
|
#include "CCApplication.h"
|
2012-04-20 15:23:00 +08:00
|
|
|
#include "CCEGLView.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCDirector.h"
|
2012-09-05 14:38:39 +08:00
|
|
|
#include <algorithm>
|
2013-01-28 19:49:34 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
|
|
|
@brief This function change the PVRFrame show/hide setting in register.
|
|
|
|
@param bEnable If true show the PVRFrame window, otherwise hide.
|
|
|
|
*/
|
|
|
|
static void PVRFrameEnableControlWindow(bool bEnable);
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
// sharedApplication pointer
|
2013-06-20 14:13:12 +08:00
|
|
|
Application * Application::sm_pSharedApplication = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::Application()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _instance(NULL)
|
|
|
|
, _accelTable(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_instance = GetModuleHandle(NULL);
|
|
|
|
_animationInterval.QuadPart = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::~Application()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Application::run()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
PVRFrameEnableControlWindow(false);
|
|
|
|
|
|
|
|
// Main message loop:
|
|
|
|
MSG msg;
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
LARGE_INTEGER nLast;
|
|
|
|
LARGE_INTEGER nNow;
|
|
|
|
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
QueryPerformanceCounter(&nLast);
|
|
|
|
|
|
|
|
// Initialize instance and cocos2d.
|
2012-05-02 17:50:26 +08:00
|
|
|
if (!applicationDidFinishLaunching())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-12 13:11:21 +08:00
|
|
|
EGLView* pMainWnd = EGLView::getInstance();
|
2012-08-21 14:58:31 +08:00
|
|
|
pMainWnd->centerWindow();
|
|
|
|
ShowWindow(pMainWnd->getHWnd(), SW_SHOW);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
// Get current time tick.
|
|
|
|
QueryPerformanceCounter(&nNow);
|
|
|
|
|
|
|
|
// If it's the time to draw next frame, draw it, else sleep a while.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
nLast.QuadPart = nNow.QuadPart;
|
2013-07-12 11:50:36 +08:00
|
|
|
Director::getInstance()->mainLoop();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sleep(0);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WM_QUIT == msg.message)
|
|
|
|
{
|
|
|
|
// Quit message loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with windows message.
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _accelTable || ! TranslateAccelerator(msg.hwnd, _accelTable, &msg))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) msg.wParam;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Application::setAnimationInterval(double interval)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
2013-06-15 14:03:30 +08:00
|
|
|
_animationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2013-07-15 16:24:42 +08:00
|
|
|
Application* Application::getInstance()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2012-08-21 17:25:03 +08:00
|
|
|
return sm_pSharedApplication;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-15 16:37:38 +08:00
|
|
|
// @deprecated Use getInstance() instead
|
|
|
|
Application* Application::sharedApplication()
|
|
|
|
{
|
|
|
|
return Application::getInstance();
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
LanguageType Application::getCurrentLanguage()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-26 17:29:06 +08:00
|
|
|
LanguageType ret = LanguageType::ENGLISH;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
LCID localeID = GetUserDefaultLCID();
|
|
|
|
unsigned short primaryLanguageID = localeID & 0xFF;
|
|
|
|
|
|
|
|
switch (primaryLanguageID)
|
|
|
|
{
|
|
|
|
case LANG_CHINESE:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::CHINESE;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2012-10-18 15:57:18 +08:00
|
|
|
case LANG_ENGLISH:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ENGLISH;
|
2012-10-18 15:57:18 +08:00
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
case LANG_FRENCH:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::FRENCH;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case LANG_ITALIAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ITALIAN;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case LANG_GERMAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::GERMAN;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case LANG_SPANISH:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::SPANISH;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case LANG_RUSSIAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::RUSSIAN;
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
2012-10-18 15:57:18 +08:00
|
|
|
case LANG_KOREAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::KOREAN;
|
2012-10-18 15:57:18 +08:00
|
|
|
break;
|
2012-11-28 16:53:10 +08:00
|
|
|
case LANG_JAPANESE:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::JAPANESE;
|
2012-11-28 16:53:10 +08:00
|
|
|
break;
|
2012-12-05 18:31:05 +08:00
|
|
|
case LANG_HUNGARIAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::HUNGARIAN;
|
2012-12-05 18:31:05 +08:00
|
|
|
break;
|
2013-02-11 23:29:56 +08:00
|
|
|
case LANG_PORTUGUESE:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::PORTUGUESE;
|
2013-02-11 23:29:56 +08:00
|
|
|
break;
|
|
|
|
case LANG_ARABIC:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::ARABIC;
|
2013-02-11 23:29:56 +08:00
|
|
|
break;
|
2013-06-11 22:43:35 +08:00
|
|
|
case LANG_NORWEGIAN:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::NORWEGIAN;
|
2013-05-29 16:16:22 +08:00
|
|
|
break;
|
2013-06-11 22:46:38 +08:00
|
|
|
case LANG_POLISH:
|
2013-07-26 17:29:06 +08:00
|
|
|
ret = LanguageType::POLISH;
|
2013-06-11 22:46:38 +08:00
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
Application::Platform Application::getTargetPlatform()
|
2012-08-16 10:21:15 +08:00
|
|
|
{
|
2013-07-26 18:17:30 +08:00
|
|
|
return Platform::OS_WINDOWS;
|
2012-08-16 10:21:15 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Application::setResourceRootPath(const std::string& rootResDir)
|
2012-09-05 14:38:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_resourceRootPath = rootResDir;
|
|
|
|
std::replace(_resourceRootPath.begin(), _resourceRootPath.end(), '\\', '/');
|
|
|
|
if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
|
2012-09-05 14:38:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_resourceRootPath += '/';
|
2012-09-05 14:38:39 +08:00
|
|
|
}
|
2013-07-12 12:03:39 +08:00
|
|
|
FileUtils* pFileUtils = FileUtils::getInstance();
|
2013-01-29 09:56:38 +08:00
|
|
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
2013-06-15 14:03:30 +08:00
|
|
|
searchPaths.insert(searchPaths.begin(), _resourceRootPath);
|
2013-01-29 09:56:38 +08:00
|
|
|
pFileUtils->setSearchPaths(searchPaths);
|
2013-01-28 10:36:37 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
const std::string& Application::getResourceRootPath(void)
|
2013-01-28 10:36:37 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _resourceRootPath;
|
2012-09-05 14:38:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Application::setStartupScriptFilename(const std::string& startupScriptFile)
|
2012-09-05 14:38:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startupScriptFilename = startupScriptFile;
|
|
|
|
std::replace(_startupScriptFilename.begin(), _startupScriptFilename.end(), '\\', '/');
|
2012-09-05 14:38:39 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Local function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
static void PVRFrameEnableControlWindow(bool bEnable)
|
|
|
|
{
|
|
|
|
HKEY hKey = 0;
|
|
|
|
|
|
|
|
// Open PVRFrame control key, if not exist create it.
|
|
|
|
if(ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER,
|
|
|
|
L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
0,
|
|
|
|
&hKey,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-01 13:44:28 +08:00
|
|
|
const WCHAR* wszValue = L"hide_gui";
|
|
|
|
const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES";
|
|
|
|
WCHAR wszOldData[256] = {0};
|
|
|
|
DWORD dwSize = sizeof(wszOldData);
|
|
|
|
LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, NULL, (LPBYTE)wszOldData, &dwSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ERROR_FILE_NOT_FOUND == status // the key not exist
|
|
|
|
|| (ERROR_SUCCESS == status // or the hide_gui value is exist
|
2012-06-01 13:44:28 +08:00
|
|
|
&& 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-01 13:44:28 +08:00
|
|
|
dwSize = sizeof(WCHAR) * (wcslen(wszNewData) + 1);
|
|
|
|
RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE *)wszNewData, dwSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|