2014-01-07 11:25:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2014-01-31 08:51:43 +08:00
|
|
|
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCPlatformConfig.h"
|
2014-01-31 08:51:43 +08:00
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCApplication.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
2012-09-05 14:38:39 +08:00
|
|
|
#include <algorithm>
|
2014-05-17 05:36:00 +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()
|
2014-04-09 22:53:59 +08:00
|
|
|
: _instance(nullptr)
|
|
|
|
, _accelTable(nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-04-09 22:53:59 +08:00
|
|
|
_instance = GetModuleHandle(nullptr);
|
2013-06-15 14:03:30 +08:00
|
|
|
_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);
|
2014-07-10 00:45:27 +08:00
|
|
|
sm_pSharedApplication = nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Application::run()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
PVRFrameEnableControlWindow(false);
|
|
|
|
|
|
|
|
// Main message loop:
|
|
|
|
LARGE_INTEGER nFreq;
|
|
|
|
LARGE_INTEGER nLast;
|
|
|
|
LARGE_INTEGER nNow;
|
|
|
|
|
|
|
|
QueryPerformanceFrequency(&nFreq);
|
|
|
|
QueryPerformanceCounter(&nLast);
|
|
|
|
|
2014-08-22 16:22:16 +08:00
|
|
|
initGLContextAttrs();
|
2014-08-21 09:35:32 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Initialize instance and cocos2d.
|
2012-05-02 17:50:26 +08:00
|
|
|
if (!applicationDidFinishLaunching())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-24 08:04:11 +08:00
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto glview = director->getOpenGLView();
|
2014-03-14 18:40:04 +08:00
|
|
|
|
|
|
|
// Retain glview to avoid glview being released in the while loop
|
2014-03-14 16:00:51 +08:00
|
|
|
glview->retain();
|
2013-08-29 13:48:58 +08:00
|
|
|
|
2014-01-24 08:04:11 +08:00
|
|
|
while(!glview->windowShouldClose())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-20 13:57:15 +08:00
|
|
|
QueryPerformanceCounter(&nNow);
|
|
|
|
if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-20 13:57:15 +08:00
|
|
|
nLast.QuadPart = nNow.QuadPart;
|
2014-03-14 18:40:04 +08:00
|
|
|
|
|
|
|
director->mainLoop();
|
2014-03-15 00:10:39 +08:00
|
|
|
glview->pollEvents();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-08-20 13:57:15 +08:00
|
|
|
else
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-20 13:57:15 +08:00
|
|
|
Sleep(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:16:31 +08:00
|
|
|
|
2014-02-02 04:10:00 +08:00
|
|
|
// Director should still do a cleanup if the window was closed manually.
|
|
|
|
if (glview->isOpenGLReady())
|
|
|
|
{
|
|
|
|
director->end();
|
|
|
|
director->mainLoop();
|
|
|
|
director = nullptr;
|
|
|
|
}
|
2014-03-14 16:00:51 +08:00
|
|
|
glview->release();
|
2013-08-20 13:57:15 +08:00
|
|
|
return true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2014-01-26 04:38:15 +08:00
|
|
|
case LANG_DUTCH:
|
|
|
|
ret = LanguageType::DUTCH;
|
|
|
|
break;
|
2012-04-19 14:35:52 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-18 02:34:21 +08:00
|
|
|
const char * Application::getCurrentLanguageCode()
|
|
|
|
{
|
|
|
|
LANGID lid = GetUserDefaultUILanguage();
|
|
|
|
const LCID locale_id = MAKELCID(lid, SORT_DEFAULT);
|
|
|
|
static char code[3] = { 0 };
|
|
|
|
GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, code, sizeof(code));
|
|
|
|
code[2] = '\0';
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
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,
|
2014-07-10 00:45:27 +08:00
|
|
|
nullptr))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
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);
|
2014-07-10 00:45:27 +08:00
|
|
|
LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (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);
|
|
|
|
}
|
2014-01-31 08:51:43 +08:00
|
|
|
|
|
|
|
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|