int Application::run() { PVRFrameEnableControlWindow(false); // Main message loop: LARGE_INTEGER nLast; LARGE_INTEGER nNow; QueryPerformanceCounter(&nLast); initGLContextAttrs(); // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) { return 1; } auto director = Director::getInstance(); auto glview = director->getOpenGLView(); // Retain glview to avoid glview being released in the while loop glview->retain(); timeBeginPeriod(1); while(!glview->windowShouldClose()) { if (!s_fullSpeedMode) { QueryPerformanceCounter(&nNow); if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart) { nLast.QuadPart = nNow.QuadPart - (nNow.QuadPart % _animationInterval.QuadPart); director->mainLoop(); glview->pollEvents(); } else { Sleep(1); // Do Nothing, Sleep(1); } } else { director->mainLoop(); glview->pollEvents(); } } timeEndPeriod(1); // Director should still do a cleanup if the window was closed manually. if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); return 0; }
void CocosApp::AfterRun() { auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); }
int Application::runAndLink() { initGLContextAttrs(); // Initialize instance and cocos2d. if (! applicationDidFinishLaunching()) { 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()) { lastTime = getCurrentMillSecond(); director->mainLoop(); glview->pollEvents(); curTime = getCurrentMillSecond(); return 1; if (curTime - lastTime < _animationInterval) { usleep((_animationInterval - curTime + lastTime)*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 */ if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); return EXIT_SUCCESS; }
MFCAppDelegate::~MFCAppDelegate() { auto director = Director::getInstance(); auto glview = director->getOpenGLView(); // Director should still do a cleanup if the window was closed manually. if (glview) { if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); } }
int Application::run() { PVRFrameEnableControlWindow(false); #if CC_WIN_TIMER1 == 1 UINT TARGET_RESOLUTION = 1; // 1-millisecond target resolution TIMECAPS tc; UINT wTimerRes; if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { // Error; application can't continue. } wTimerRes = std::min(std::max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax); timeBeginPeriod(wTimerRes); #endif // Main message loop: LARGE_INTEGER nLast; LARGE_INTEGER nNow; QueryPerformanceCounter(&nLast); initGLContextAttrs(); // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) { return 1; } auto director = Director::getInstance(); auto glview = director->getOpenGLView(); // Retain glview to avoid glview being released in the while loop glview->retain(); #if CC_USE_VSYNC == 1 glview->setSwapInterval(1); #endif while(!glview->windowShouldClose()) { QueryPerformanceCounter(&nNow); if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart) { nLast.QuadPart = nNow.QuadPart - (nNow.QuadPart % _animationInterval.QuadPart); director->mainLoop(); //glview->pollEvents(); } else { #if CC_SLEEP_1_MSEC == 1 Sleep(1); #endif } } // Director should still do a cleanup if the window was closed manually. if (glview->isOpenGLReady()) { director->end(); director->mainLoop(); director = nullptr; } glview->release(); #if CC_WIN_TIMER1 == 1 wTimerRes = std::min(std::max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax); timeEndPeriod(wTimerRes); #endif return 0; }