Beispiel #1
0
int CCApplication::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    MSG msg;
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nLast;
    LARGE_INTEGER nNow;

    QueryPerformanceFrequency(&nFreq);
    QueryPerformanceCounter(&nLast);

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();
    mainWnd.centerWindow();
    ShowWindow(mainWnd.getHWnd(), SW_SHOW);

    while (1)
    {
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // Get current time tick.
            QueryPerformanceCounter(&nNow);

            // If it's the time to draw next frame, draw it, else sleep a while.
            if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
            {
                nLast.QuadPart = nNow.QuadPart;
                CCDirector::sharedDirector()->mainLoop();
            }
            else
            {
                Sleep(0);
            }
            continue;
        }

        if (WM_QUIT == msg.message)
        {
            // Quit message loop.
            break;
        }

        // Deal with windows message.
        if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}
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;
}
Beispiel #3
0
void CocosApp::PostRun()
{
	PVRFrameEnableControlWindow(false);
	initGLContextAttrs();
	applicationDidFinishLaunching();
	auto director = Director::getInstance();
	auto glview = director->getOpenGLView();
	glview->retain();
}
int CCApplication::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    MSG msg;
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nStart;
    LARGE_INTEGER nEnd;
    LONGLONG deltaQuadPart;
    DOUBLE sleepTime = 0;

    QueryPerformanceFrequency(&nFreq);

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    CCEGLView* pMainWnd = CCEGLView::sharedOpenGLView();
    ShowWindow(pMainWnd->getHWnd(), SW_SHOW);

    while (1)
    {
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            QueryPerformanceCounter(&nStart);
            CCDirector::sharedDirector()->mainLoop();
            QueryPerformanceCounter(&nEnd);

            deltaQuadPart = m_nAnimationInterval.QuadPart - (nEnd.QuadPart - nStart.QuadPart);
            if (deltaQuadPart > 0)
            {
                sleepTime += 1000.0 * deltaQuadPart / nFreq.QuadPart;
                Sleep((int)sleepTime);
                sleepTime -= (int)sleepTime;
            }
            continue;
        }

        if (WM_QUIT == msg.message)
        {
            // Quit message loop.
            break;
        }

        // Deal with windows message.
        if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}
Beispiel #5
0
int Application::run()
{
    PVRFrameEnableControlWindow(false);

    // Main message loop:
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nLast;
    LARGE_INTEGER nNow;

    QueryPerformanceFrequency(&nFreq);
    QueryPerformanceCounter(&nLast);

    // Initialize instance and cocos2d.
    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    EGLView* pMainWnd = EGLView::getInstance();

    while(!pMainWnd->windowShouldClose())
    {
        QueryPerformanceCounter(&nNow);
        if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
        {
            nLast.QuadPart = nNow.QuadPart;
            Director::getInstance()->mainLoop();
            pMainWnd->pollEvents();
        }
        else
        {
            Sleep(0);
        }
    }

    /* 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 true;
}
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;
}
int CCApplication::run()
{
    PVRFrameEnableControlWindow(false);
	CCLog("--- INTO CCApplication::run \n");

    // Main message loop:
    
    // Initialize instance and cocos2d.
    if (! initInstance() || ! applicationDidFinishLaunching())
    {
        return 0;
    }
    
    SDL_Joystick *joystick = SDL_JoystickOpen(0);
	
    CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();
    mainWnd.centerWindow();
   CCLog(" --- BEFORE EVENT LOOP\n");
	 SDL_Event Event;
	 while (1) {
        bool gotEvent;
        
        // without the inner while loop, input performance gets really laggy    	        
		while ( SDL_PollEvent(&Event) ) {  
//		  CCLog("--- GOT NEW EVENT .... \n");
		 switch (Event.type) {
                case SDL_KEYDOWN:
                    switch (Event.key.keysym.sym) {
                        case PDLK_GESTURE_BACK: /* also maps to ESC */
                            if (PDL_GetPDKVersion() >= 200) {
                                // standard behavior is to minimize to a card when you perform a back
                                // gesture at the top level of the app
                                PDL_Minimize();
                            }
                            break;
                            case PDLK_GESTURE_DISMISS_KEYBOARD:{
                                CCDirector::sharedDirector()->getOpenGLView()->setIMEKeyboardState(false);
                            }
                            break;
                            case SDLK_BACKSPACE: {
                                CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
                            }
                            break;
                        default:
                        {
                            CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(SDL_GetKeyName(Event.key.keysym.sym), 1); 
                        }
                        break;
                    }
                    break;
                case SDL_MOUSEBUTTONDOWN:
//					CCLog(" --- GOT NEW EVENT (SDL_MOUSEBUTTONDOWN).... \n");
					mainWnd.WindowProc(SDL_MOUSEBUTTONDOWN,Event);
					break;
				case SDL_MOUSEBUTTONUP:
//					CCLog("--- GOT NEW EVENT (SDL_MOUSEBUTTONUP).... \n");
					mainWnd.WindowProc(SDL_MOUSEBUTTONUP,Event);
					break;
				case SDL_MOUSEMOTION:
					mainWnd.WindowProc(SDL_MOUSEMOTION,Event);
					break;
				case SDL_QUIT:
                    // We exit anytime we get a request to quit the app
                    // all shutdown code is registered via atexit() so this is clean.
                    exit(0);
                    break;
                case SDL_JOYAXISMOTION:
                	CCAccelerometer::sharedAccelerometer()->update(joystick, time(NULL));
                	break;
                case SDL_ACTIVEEVENT:
                      switch(Event.active.gain)
                      {
                        case 1:
                            {
                                applicationWillEnterForeground();
                                break;
                            }
                        default:
                        {
                            applicationDidEnterBackground();
                            break;
                        }
                      }
                    break;
                default:
                    break;
            }
        }   
		   // Get current time tick.
            // If it's the time to draw next frame, draw it, else sleep a while.
            CCDirector::sharedDirector()->mainLoop();
     }

    return (int) 0;
}
Beispiel #8
0
int CCApplication::run()
{
	LARGE_INTEGER nFreq;
	LARGE_INTEGER nLast;
	LARGE_INTEGER nNow;

	QueryPerformanceFrequency(&nFreq);

#if !CC_USE_GLFW_WINDOW

	PVRFrameEnableControlWindow(true);

	// 初始化窗口和游戏引擎,由子类实现
	if (!initInstance() || !applicationDidFinishLaunching())
	{
		return 0;
	}

	CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();
	mainWnd.centerWindow();
	ShowWindow(mainWnd.getHWnd(), SW_SHOW);

	MSG msg;
	QueryPerformanceCounter(&nLast);

	while(1)
	{
		if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			QueryPerformanceCounter(&nNow);
			if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
			{
				nLast.QuadPart = nNow.QuadPart;
				CCDirector::sharedDirector()->mainLoop();
			}
			else
			{
				Sleep(0);
			}
			continue;
		}

		if (WM_QUIT == msg.message)
		{
			break;
		}

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;

#else

	// 初始化窗口和游戏引擎,由子类实现
	if (!initInstance() || !applicationDidFinishLaunching())
	{
		return 0;
	}

	while(1)
	{
		QueryPerformanceCounter(&nLast);
		CCDirector::sharedDirector()->mainLoop();
		QueryPerformanceCounter(&nNow);
		if (nNow.QuadPart - nLast.QuadPart < m_nAnimationInterval.QuadPart)
		{
			LONGLONG diff = (m_nAnimationInterval.QuadPart - nNow.QuadPart + nLast.QuadPart) * 1000 / nFreq.QuadPart;
			Sleep((DWORD)diff);
		}
	}

#endif
}
//程序运行  
int CCApplication::run()  
{  
    //设置注册表PVRFrame隐藏  
    PVRFrameEnableControlWindow(false);  
    //主消息循环  
    MSG msg;  
    LARGE_INTEGER nFreq;  
    LARGE_INTEGER nLast;  
    LARGE_INTEGER nNow;  
//WINDOWS高精度定时器的用法,先获取频率  
QueryPerformanceFrequency(&nFreq);  
//获取当前的计数值,即频率x当前时间  
    QueryPerformanceCounter(&nLast);  
	//initInstance函数为虚函数,由派生类AppDelegate进行了重载。此段代码在调用AppDelegate重载的initInstance函数之后调用applicationDidFinishLaunching函数完成一些初始化处理。  
	//注:AppDelegate重载initInstance函数做了什么我们暂且只先认为它如平时我们WINDOWS基本框架程序一样创建了一个Windows窗口。【伏笔1后面会有讲解】。  
    if (! initInstance() || ! applicationDidFinishLaunching())  
    {  
        return 0;  
    }  
//取得当前使用的OPENGL窗口管理实例对象  
CCEGLView& mainWnd = CCEGLView::sharedOpenGLView();  
//将窗口居中显示  
    mainWnd.centerWindow();  
    ShowWindow(mainWnd.getHWnd(), SW_SHOW);  
//非常熟悉!进入WINDOWS消息循环  
    while (1)  
{  
   //如果没有获取到WINDOWS消息  
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))  
        {  
            // 取得当前的计数值,即频率x当前时间  
            QueryPerformanceCounter(&nNow);  
            //m_nAnimationInterval.QuadPart的值 为setAnimationInterval函数进行设置的固定值。此处是为了判断时间流逝了多久,是否应该更新显示设备  
            if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)  
            {  
  //如果时间流逝达到了设定的FPS时间差,则更新计数值。  
                nLast.QuadPart = nNow.QuadPart;  
  //这里是设备渲染场景的函数,【伏笔2后面会有讲解】   
                CCDirector::sharedDirector()->mainLoop();  
            }  
            else  
            {  
  //sleep0秒的意义是让CPU做下时间片切换,防止死循环而使系统其它程序得不到响应。  
                Sleep(0);  
            }  
            continue;  
        }  
   //有消息获取到  
        if (WM_QUIT == msg.message)  
        {  
   // 如果获取的消息是退出则退出循环。  
            break;  
        }  
        // 如果没有定义加速键或者处理完加速键信息  
        if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))  
        {  
   //处理Windows消息  
            TranslateMessage(&msg);  
            DispatchMessage(&msg);  
        }  
    }  
    return (int) msg.wParam;  
}