2012-08-02 13:02:59 +08:00
|
|
|
/*
|
|
|
|
* CCAplication_linux.cpp
|
|
|
|
*
|
|
|
|
* Created on: Aug 8, 2011
|
|
|
|
* Author: laschweinski
|
|
|
|
*/
|
|
|
|
#include "CCApplication.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
2012-08-03 13:56:18 +08:00
|
|
|
#include <string>
|
2012-08-02 13:02:59 +08:00
|
|
|
#include "CCDirector.h"
|
2013-01-28 11:56:56 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2012-08-02 13:02:59 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-08-03 13:56:18 +08:00
|
|
|
|
2012-08-02 13:02:59 +08:00
|
|
|
// sharedApplication pointer
|
|
|
|
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
|
|
|
|
|
|
|
static long getCurrentMillSecond() {
|
|
|
|
long lLastTime;
|
|
|
|
struct timeval stCurrentTime;
|
|
|
|
|
|
|
|
gettimeofday(&stCurrentTime,NULL);
|
|
|
|
lLastTime = stCurrentTime.tv_sec*1000+stCurrentTime.tv_usec*0.001; //millseconds
|
|
|
|
return lLastTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCApplication::CCApplication()
|
|
|
|
{
|
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCApplication::~CCApplication()
|
|
|
|
{
|
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
|
|
|
sm_pSharedApplication = NULL;
|
|
|
|
m_nAnimationInterval = 1.0f/60.0f*1000.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CCApplication::run()
|
|
|
|
{
|
|
|
|
// Initialize instance and cocos2d.
|
|
|
|
if (! applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
long iLastTime = getCurrentMillSecond();
|
|
|
|
CCDirector::sharedDirector()->mainLoop();
|
|
|
|
long iCurTime = getCurrentMillSecond();
|
|
|
|
if (iCurTime-iLastTime<m_nAnimationInterval){
|
|
|
|
usleep((m_nAnimationInterval - iCurTime+iLastTime)*1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
|
|
|
{
|
|
|
|
//TODO do something else
|
|
|
|
m_nAnimationInterval = interval*1000.0f;
|
|
|
|
}
|
|
|
|
|
2013-01-28 10:36:37 +08:00
|
|
|
void CCApplication::setResourceRootPath(const std::string& rootResDir)
|
2012-08-03 13:56:18 +08:00
|
|
|
{
|
2013-01-28 10:36:37 +08:00
|
|
|
m_resourceRootPath = rootResDir;
|
|
|
|
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
|
|
|
|
{
|
|
|
|
m_resourceRootPath += '/';
|
|
|
|
}
|
|
|
|
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
|
2013-01-29 09:56:38 +08:00
|
|
|
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
2013-01-28 10:36:37 +08:00
|
|
|
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
|
2013-01-29 09:56:38 +08:00
|
|
|
pFileUtils->setSearchPaths(searchPaths);
|
2012-08-03 13:56:18 +08:00
|
|
|
}
|
|
|
|
|
2013-01-28 10:36:37 +08:00
|
|
|
const std::string& CCApplication::getResourceRootPath(void)
|
2012-08-03 13:56:18 +08:00
|
|
|
{
|
2013-01-28 10:36:37 +08:00
|
|
|
return m_resourceRootPath;
|
2012-08-03 13:56:18 +08:00
|
|
|
}
|
2012-08-16 10:21:15 +08:00
|
|
|
|
|
|
|
TargetPlatform CCApplication::getTargetPlatform()
|
|
|
|
{
|
|
|
|
return kTargetLinux;
|
|
|
|
}
|
|
|
|
|
2012-08-02 13:02:59 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-08-21 15:28:43 +08:00
|
|
|
CCApplication* CCApplication::sharedApplication()
|
2012-08-02 13:02:59 +08:00
|
|
|
{
|
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2012-08-21 15:28:43 +08:00
|
|
|
return sm_pSharedApplication;
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ccLanguageType CCApplication::getCurrentLanguage()
|
|
|
|
{
|
2012-11-28 18:41:50 +08:00
|
|
|
char *pLanguageName = getenv("LANG");
|
|
|
|
ccLanguageType ret = kLanguageEnglish;
|
|
|
|
if (!pLanguageName)
|
|
|
|
{
|
|
|
|
return kLanguageEnglish;
|
|
|
|
}
|
|
|
|
strtok(pLanguageName, "_");
|
|
|
|
if (!pLanguageName)
|
|
|
|
{
|
|
|
|
return kLanguageEnglish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == strcmp("zh", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageChinese;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("en", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageEnglish;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("fr", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageFrench;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("it", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageItalian;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("de", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageGerman;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("es", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageSpanish;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("ru", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageRussian;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("ko", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageKorean;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("ja", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageJapanese;
|
|
|
|
}
|
2012-12-05 18:31:05 +08:00
|
|
|
else if (0 == strcmp("hu", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageHungarian;
|
|
|
|
}
|
2013-02-11 23:29:56 +08:00
|
|
|
else if (0 == strcmp("pt", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguagePortuguese;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp("ar", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageArabic;
|
|
|
|
}
|
2013-06-11 22:39:33 +08:00
|
|
|
else if (0 == strcmp("nb", pLanguageName))
|
|
|
|
{
|
|
|
|
ret = kLanguageNorwegian;
|
|
|
|
}
|
2012-11-28 18:41:50 +08:00
|
|
|
|
|
|
|
return ret;
|
2012-08-02 13:02:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|