Example #1
0
File: widget.cpp Project: keitee/kb
void Widget::closeEvent(QCloseEvent *event)
{
    if (windowShouldClose())
        event->accept();
    else
        event->ignore();
}
int Application::run()
{
    // Initialize instance and cocos2d.
    if (! applicationDidFinishLaunching())
    {
        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->end();
    director->mainLoop();
    return -1;
}
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;
}
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;
}
Example #5
0
void
Context::startLoop()
{
  Info() << "Context initializing renderloop.";
  m_loop->initialize(*this);

  Info() << "Starting render loop.";
  do {
    m_loop->render();
    swapBuffers();
    pollEvents();
  } while (!windowShouldClose());

  Info() << "Renderloop exited.";
}
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;
}
Example #7
0
bool System::shouldContinue()
{
	return !windowShouldClose();
}