示例#1
0
void client_render_main()
{
	Uint32 start;
	int interval;

	client_render_init();
	printf("ClientRenderModule started\n");

	while ( cl.state == PLAYING )
	{
		/* render frame */
		start = SDL_GetTicks();
		renderSingleFrame();

		/* handle user actions */
		if ( w.checkMessages() ){	cl.state = GONE;	break;		}

		/* limit frames per second */
		interval = SDL_GetTicks() - start;
		assert( interval > 0 && interval < 100000 );
		if( cl.render_delay > interval ) SDL_Delay( cl.render_delay - interval );

		/* compute frames per second average */
		frame_render_interval = interval * ( 1 - cl.fps_average_param )	+ frame_render_interval * cl.fps_average_param;
	}

	client_render_quit();
}
//----------------------------------------------------------------------------//
bool CEGuiD3D9BaseApplication::execute_impl(CEGuiSample* sampleApp)
{
    sampleApp->initialiseSample();

    //
    //  This is basically a modified Win32 message pump
    //
    bool idle;
    HRESULT coop;

    while (Win32AppHelper::doWin32Events(idle))
    {
        if (idle)
        {
            CEGUI::System& guiSystem = CEGUI::System::getSingleton();

            // do time based updates
            DWORD thisTime = GetTickCount();
            const float elapsed =
                static_cast<float>(thisTime - d_lastFrameTime) / 1000.0f;
            d_lastFrameTime = thisTime;

            // handle D3D lost device stuff
            coop = pimpl->d_3DDevice->TestCooperativeLevel();

            if (coop == D3DERR_DEVICELOST)
            {
                Sleep(500);
                continue;
            }
            else if (coop == D3DERR_DEVICENOTRESET)
            {
                if (!resetDirect3D())
                {
                    continue;
                }
            }

            Win32AppHelper::doDirectInputEvents(pimpl->d_directInput);

            // draw display
            if (FAILED(pimpl->d_3DDevice->BeginScene()))
                continue;

            renderSingleFrame(elapsed);
        }

        // check if the application is quitting, and break the loop next time
        // around if so.
        if (isQuitting())
            PostQuitMessage(0);
    }

    return true;
}
//----------------------------------------------------------------------------//
void CEGuiD3D11BaseApplication::run()
{
    d_sampleApp->initialise();
    Win32AppHelper::setSampleBrowser(d_sampleApp);

    float clear_colour[4] = {0.0f, 0.0f, 0.0f, 0.0f};

    //
    //  This is basically a modified Win32 message pump
    //
    bool idle;

    while (Win32AppHelper::doWin32Events(idle))
    {
        if (idle)
        {
            CEGUI::System& guiSystem = CEGUI::System::getSingleton();

            // do time based updates
            const DWORD thisTime = GetTickCount();
            const float elapsed =
                static_cast<float>(thisTime - d_lastFrameTime) / 1000.0f;
            d_lastFrameTime = thisTime;

            Win32AppHelper::doDirectInputEvents(pimpl->d_directInput);

            // get render target view
            // this is a bit wasteful, but done like this for now since the
            // resize code can change the view from under us.
            ID3D11RenderTargetView* rtview;
            pimpl->d_context->OMGetRenderTargets(1, &rtview, 0);

            // clear display
            pimpl->d_context->ClearRenderTargetView(rtview, clear_colour);

            renderSingleFrame(elapsed);

            pimpl->d_swapChain->Present(0, 0);
            rtview->Release();
        }

        // check if the application is quitting, and break the loop next time
        // around if so.
        if (d_sampleApp->isQuitting())
            PostQuitMessage(0);
    }
}
示例#4
0
void ClientRenderModule::run()
{
    Uint32 start,stop,interval;

//	printf("ClientRenderModule started\n");

    if ( client_data->has_GUI ) initGraphics();

    while ( client_data->state != GONE )
    {
        if ( client_data->has_GUI )
        {
            /* render frame */
            start = SDL_GetTicks();
            renderSingleFrame();

            /* handle user actions */
            if ( w.checkMessages() )
            {
                client_data->state = WAITING_LEAVE;
                break;
            }

            /* limit frames per second */
            stop = SDL_GetTicks();
            interval = stop - start;
            if ( interval < RENDER_DELAY ) SDL_Delay( RENDER_DELAY - interval );

            /* compute frames per second average */
            interval = SDL_GetTicks() - start;
            frame_render_interval = interval * ( 1 - client_data->fps_average_param )
                                    + frame_render_interval * client_data->fps_average_param;

        } else SDL_Delay(RENDER_DELAY);
    }

    /* wait for client to reach GONE state */
    SDL_LockMutex(client_data->term_mutex);
    while ( client_data->state != GONE )
        SDL_CondWait(client_data->term_cond, client_data->term_mutex);
    SDL_UnlockMutex(client_data->term_mutex);

    if ( client_data->has_GUI ) endGraphics();
}