Merge pull request #5803 from dumganhar/develop

PollEvents should invoked before main loop and little improvement in CCApplication.cpp/.mm.
This commit is contained in:
James Chen 2014-03-14 20:02:04 +08:00
commit d91f5b9a68
3 changed files with 40 additions and 14 deletions

View File

@ -70,18 +70,27 @@ int Application::run()
return 0;
}
long lastTime = 0L;
long curTime = 0L;
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
// Retain glview to avoid glview being released in the while loop
glview->retain();
while (!glview->windowShouldClose())
{
long iLastTime = getCurrentMillSecond();
director->mainLoop();
lastTime = getCurrentMillSecond();
// Poll event before mainloop
glview->pollEvents();
long iCurTime = getCurrentMillSecond();
if (iCurTime-iLastTime<_animationInterval){
usleep((_animationInterval - iCurTime+iLastTime)*1000);
director->mainLoop();
curTime = getCurrentMillSecond();
if (curTime - lastTime < _animationInterval)
{
usleep((_animationInterval - curTime + lastTime)*1000);
}
}
/* Only work on Desktop

View File

@ -68,17 +68,28 @@ int Application::run()
{
return 0;
}
GLView* glview = Director::getInstance()->getOpenGLView();
long lastTime = 0L;
long curTime = 0L;
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
// Retain glview to avoid glview being released in the while loop
glview->retain();
while (!glview->windowShouldClose())
{
long iLastTime = getCurrentMillSecond();
Director::getInstance()->mainLoop();
lastTime = getCurrentMillSecond();
// Poll event before mainloop
glview->pollEvents();
long iCurTime = getCurrentMillSecond();
if (iCurTime-iLastTime<_animationInterval){
usleep(static_cast<useconds_t>((_animationInterval - iCurTime+iLastTime)*1000));
director->mainLoop();
curTime = getCurrentMillSecond();
if (curTime - lastTime < _animationInterval)
{
usleep(static_cast<useconds_t>((_animationInterval - curTime + lastTime)*1000));
}
}
@ -89,10 +100,12 @@ int Application::run()
*/
if (glview->isOpenGLReady())
{
Director::getInstance()->end();
Director::getInstance()->mainLoop();
director->end();
director->mainLoop();
}
glview->release();
return true;
}

View File

@ -78,6 +78,8 @@ int Application::run()
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
// Retain glview to avoid glview being released in the while loop
glview->retain();
while(!glview->windowShouldClose())
@ -86,8 +88,10 @@ int Application::run()
if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
{
nLast.QuadPart = nNow.QuadPart;
director->mainLoop();
// Poll event before mainloop
glview->pollEvents();
director->mainLoop();
}
else
{