mirror of https://github.com/axmolengine/axmol.git
more fixes for new GLView API
This commit is contained in:
parent
8ecaf49f93
commit
2b92ba75b4
|
@ -38,61 +38,62 @@ NS_CC_BEGIN
|
|||
Application * Application::sm_pSharedApplication = 0;
|
||||
|
||||
static long getCurrentMillSecond() {
|
||||
long lLastTime;
|
||||
struct timeval stCurrentTime;
|
||||
long lLastTime;
|
||||
struct timeval stCurrentTime;
|
||||
|
||||
gettimeofday(&stCurrentTime,NULL);
|
||||
lLastTime = stCurrentTime.tv_sec*1000+stCurrentTime.tv_usec*0.001; //millseconds
|
||||
return lLastTime;
|
||||
gettimeofday(&stCurrentTime,NULL);
|
||||
lLastTime = stCurrentTime.tv_sec*1000+stCurrentTime.tv_usec*0.001; //millseconds
|
||||
return lLastTime;
|
||||
}
|
||||
|
||||
Application::Application()
|
||||
{
|
||||
CC_ASSERT(! sm_pSharedApplication);
|
||||
sm_pSharedApplication = this;
|
||||
CC_ASSERT(! sm_pSharedApplication);
|
||||
sm_pSharedApplication = this;
|
||||
}
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
CC_ASSERT(this == sm_pSharedApplication);
|
||||
sm_pSharedApplication = NULL;
|
||||
_animationInterval = 1.0f/60.0f*1000.0f;
|
||||
CC_ASSERT(this == sm_pSharedApplication);
|
||||
sm_pSharedApplication = NULL;
|
||||
_animationInterval = 1.0f/60.0f*1000.0f;
|
||||
}
|
||||
|
||||
int Application::run()
|
||||
{
|
||||
// Initialize instance and cocos2d.
|
||||
if (! applicationDidFinishLaunching())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
EGLView* pMainWnd = EGLView::getInstance();
|
||||
|
||||
while (!pMainWnd->windowShouldClose())
|
||||
// Initialize instance and cocos2d.
|
||||
if (! applicationDidFinishLaunching())
|
||||
{
|
||||
long iLastTime = getCurrentMillSecond();
|
||||
Director::getInstance()->mainLoop();
|
||||
pMainWnd->pollEvents();
|
||||
long iCurTime = getCurrentMillSecond();
|
||||
if (iCurTime-iLastTime<_animationInterval){
|
||||
usleep((_animationInterval - iCurTime+iLastTime)*1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
|
||||
while (!glview->windowShouldClose())
|
||||
{
|
||||
long iLastTime = getCurrentMillSecond();
|
||||
director->mainLoop();
|
||||
glview->pollEvents();
|
||||
long iCurTime = getCurrentMillSecond();
|
||||
if (iCurTime-iLastTime<_animationInterval){
|
||||
usleep((_animationInterval - iCurTime+iLastTime)*1000);
|
||||
}
|
||||
}
|
||||
/* Only work on Desktop
|
||||
* Director::mainLoop is really one frame logic
|
||||
* when we want to close the window, we should call Director::end();
|
||||
* then call Director::mainLoop to do release of internal resources
|
||||
*/
|
||||
Director::getInstance()->end();
|
||||
Director::getInstance()->mainLoop();
|
||||
return -1;
|
||||
director->end();
|
||||
director->mainLoop();
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Application::setAnimationInterval(double interval)
|
||||
{
|
||||
//TODO do something else
|
||||
_animationInterval = interval*1000.0f;
|
||||
//TODO do something else
|
||||
_animationInterval = interval*1000.0f;
|
||||
}
|
||||
|
||||
void Application::setResourceRootPath(const std::string& rootResDir)
|
||||
|
@ -123,8 +124,8 @@ Application::Platform Application::getTargetPlatform()
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
Application* Application::getInstance()
|
||||
{
|
||||
CC_ASSERT(sm_pSharedApplication);
|
||||
return sm_pSharedApplication;
|
||||
CC_ASSERT(sm_pSharedApplication);
|
||||
return sm_pSharedApplication;
|
||||
}
|
||||
|
||||
// @deprecated Use getInstance() instead
|
||||
|
@ -135,76 +136,76 @@ Application* Application::sharedApplication()
|
|||
|
||||
LanguageType Application::getCurrentLanguage()
|
||||
{
|
||||
char *pLanguageName = getenv("LANG");
|
||||
LanguageType ret = LanguageType::ENGLISH;
|
||||
if (!pLanguageName)
|
||||
{
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
strtok(pLanguageName, "_");
|
||||
if (!pLanguageName)
|
||||
{
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
|
||||
if (0 == strcmp("zh", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::CHINESE;
|
||||
}
|
||||
else if (0 == strcmp("en", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::ENGLISH;
|
||||
}
|
||||
else if (0 == strcmp("fr", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::FRENCH;
|
||||
}
|
||||
else if (0 == strcmp("it", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::ITALIAN;
|
||||
}
|
||||
else if (0 == strcmp("de", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::GERMAN;
|
||||
}
|
||||
else if (0 == strcmp("es", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::SPANISH;
|
||||
}
|
||||
else if (0 == strcmp("ru", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::RUSSIAN;
|
||||
}
|
||||
else if (0 == strcmp("ko", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::KOREAN;
|
||||
}
|
||||
else if (0 == strcmp("ja", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::JAPANESE;
|
||||
}
|
||||
else if (0 == strcmp("hu", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::HUNGARIAN;
|
||||
}
|
||||
char *pLanguageName = getenv("LANG");
|
||||
LanguageType ret = LanguageType::ENGLISH;
|
||||
if (!pLanguageName)
|
||||
{
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
strtok(pLanguageName, "_");
|
||||
if (!pLanguageName)
|
||||
{
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
|
||||
if (0 == strcmp("zh", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::CHINESE;
|
||||
}
|
||||
else if (0 == strcmp("en", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::ENGLISH;
|
||||
}
|
||||
else if (0 == strcmp("fr", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::FRENCH;
|
||||
}
|
||||
else if (0 == strcmp("it", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::ITALIAN;
|
||||
}
|
||||
else if (0 == strcmp("de", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::GERMAN;
|
||||
}
|
||||
else if (0 == strcmp("es", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::SPANISH;
|
||||
}
|
||||
else if (0 == strcmp("ru", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::RUSSIAN;
|
||||
}
|
||||
else if (0 == strcmp("ko", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::KOREAN;
|
||||
}
|
||||
else if (0 == strcmp("ja", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::JAPANESE;
|
||||
}
|
||||
else if (0 == strcmp("hu", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::HUNGARIAN;
|
||||
}
|
||||
else if (0 == strcmp("pt", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::PORTUGUESE;
|
||||
}
|
||||
{
|
||||
ret = LanguageType::PORTUGUESE;
|
||||
}
|
||||
else if (0 == strcmp("ar", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::ARABIC;
|
||||
}
|
||||
else if (0 == strcmp("nb", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::NORWEGIAN;
|
||||
}
|
||||
else if (0 == strcmp("pl", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::POLISH;
|
||||
}
|
||||
|
||||
return ret;
|
||||
{
|
||||
ret = LanguageType::ARABIC;
|
||||
}
|
||||
else if (0 == strcmp("nb", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::NORWEGIAN;
|
||||
}
|
||||
else if (0 == strcmp("pl", pLanguageName))
|
||||
{
|
||||
ret = LanguageType::POLISH;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -72,16 +72,17 @@ int Application::run()
|
|||
return 0;
|
||||
}
|
||||
|
||||
EGLView* pMainWnd = EGLView::getInstance();
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
|
||||
while(!pMainWnd->windowShouldClose())
|
||||
while(!glview->windowShouldClose())
|
||||
{
|
||||
QueryPerformanceCounter(&nNow);
|
||||
if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
|
||||
{
|
||||
nLast.QuadPart = nNow.QuadPart;
|
||||
Director::getInstance()->mainLoop();
|
||||
pMainWnd->pollEvents();
|
||||
director->mainLoop();
|
||||
glview->pollEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -94,8 +95,8 @@ int Application::run()
|
|||
* when we want to close the window, we should call Director::end();
|
||||
* then call Director::mainLoop to do release of internal resources
|
||||
*/
|
||||
Director::getInstance()->end();
|
||||
Director::getInstance()->mainLoop();
|
||||
director->end();
|
||||
director->mainLoop();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
director->setOpenGLView(EGLView::getInstance());
|
||||
auto glview = EGLView::create("Assets Manager");
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// turn on display FPS
|
||||
//director->setDisplayStats(true);
|
||||
|
@ -45,17 +46,17 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
|
||||
|
||||
|
||||
|
||||
sc->start();
|
||||
|
||||
|
||||
auto scene = Scene::create();
|
||||
auto updateLayer = new UpdateLayer();
|
||||
scene->addChild(updateLayer);
|
||||
updateLayer->release();
|
||||
|
||||
|
||||
director->runWithScene(scene);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching() {
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto eglView = EGLView::getInstance();
|
||||
auto glview = EGLView::create("My Game");
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
director->setOpenGLView(eglView);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
|
|
|
@ -26,15 +26,16 @@ AppDelegate::~AppDelegate()
|
|||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
Director *director = Director::getInstance();
|
||||
director->setOpenGLView(EGLView::getInstance());
|
||||
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::create("My Game");
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
|
@ -44,11 +45,11 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->start();
|
||||
|
||||
|
||||
ScriptEngineProtocol *engine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
||||
ScriptingCore::getInstance()->runScript("cocos2d-jsb.js");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
director->setOpenGLView(EGLView::getInstance());
|
||||
auto glview = EGLView::create("My Game");
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
||||
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
@ -32,7 +33,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// register lua engine
|
||||
auto engine = LuaEngine::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
||||
|
||||
|
||||
std::string path = FileUtils::getInstance()->fullPathForFilename("hello.lua");
|
||||
engine->executeScriptFile(path.c_str());
|
||||
|
||||
|
|
Loading…
Reference in New Issue