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-06-20 14:13:12 +08:00
|
|
|
EGLView* pMainWnd = EGLView::sharedOpenGLView();
|
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-06-20 14:13:12 +08:00
|
|
|
Application* Application::sharedApplication()
|
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-06-20 14:13:12 +08:00
|
|
|
ccLanguageType Application::getCurrentLanguage()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
|
|
|
|
LCID localeID = GetUserDefaultLCID();
|
|
|
|
unsigned short primaryLanguageID = localeID & 0xFF;
|
|
|
|
|
|
|
|
switch (primaryLanguageID)
|
|
|
|
{
|
|
|
|
case LANG_CHINESE:
|
|
|
|
ret = kLanguageChinese;
|
|
|
|
break;
|
2012-10-18 15:57:18 +08:00
|
|
|
case LANG_ENGLISH:
|
|
|
|
ret = kLanguageEnglish;
|
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
case LANG_FRENCH:
|
|
|
|
ret = kLanguageFrench;
|
|
|
|
break;
|
|
|
|
case LANG_ITALIAN:
|
|
|
|
ret = kLanguageItalian;
|
|
|
|
break;
|
|
|
|
case LANG_GERMAN:
|
|
|
|
ret = kLanguageGerman;
|
|
|
|
break;
|
|
|
|
case LANG_SPANISH:
|
|
|
|
ret = kLanguageSpanish;
|
|
|
|
break;
|
|
|
|
case LANG_RUSSIAN:
|
|
|
|
ret = kLanguageRussian;
|
|
|
|
break;
|
2012-10-18 15:57:18 +08:00
|
|
|
case LANG_KOREAN:
|
|
|
|
ret = kLanguageKorean;
|
|
|
|
break;
|
2012-11-28 16:53:10 +08:00
|
|
|
case LANG_JAPANESE:
|
|
|
|
ret = kLanguageJapanese;
|
|
|
|
break;
|
2012-12-05 18:31:05 +08:00
|
|
|
case LANG_HUNGARIAN:
|
|
|
|
ret = kLanguageHungarian;
|
|
|
|
break;
|
2013-02-11 23:29:56 +08:00
|
|
|
case LANG_PORTUGUESE:
|
|
|
|
ret = kLanguagePortuguese;
|
|
|
|
break;
|
|
|
|
case LANG_ARABIC:
|
|
|
|
ret = kLanguageArabic;
|
|
|
|
break;
|
2013-06-11 22:43:35 +08:00
|
|
|
case LANG_NORWEGIAN:
|
2013-05-29 16:16:22 +08:00
|
|
|
ret = kLanguageNorwegian;
|
|
|
|
break;
|
2013-06-11 22:46:38 +08:00
|
|
|
case LANG_POLISH:
|
|
|
|
ret = kLanguagePolish;
|
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TargetPlatform Application::getTargetPlatform()
|
2012-08-16 10:21:15 +08:00
|
|
|
{
|
|
|
|
return kTargetWindows;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|