Exemple #1
0
void CGameWindow::startGame( IGame* pGame, HWND hWnd )
{
	MSG msg;
	ZeroMemory( &msg, sizeof( msg ));

	// local pointer to the currently running game
	m_pRunningGame = pGame;

	pGame->initGame( m_pDevice, hWnd );

	// Message-pumping loop
	while( msg.message != WM_QUIT )
	{
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ))
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else
		{
			// Ask the game to do some stuff - Render/Update, etc
			// This needs to follow the algorithm as per Fix Your Timestep! article @ gafferongames
			if( !isDeviceLost() )
			{
				pGame->update( 0.0f ); // just for illustration, atm
				pGame->render(); // just for illustration, atm
			}
		}
	}

	// If we get here, game window has recieved WM_QUIT message
	// Do some cleanup
	std::cout << "Game exiting, do some cleanup!" << std::endl;
	pGame->endGame();
}
bool Render2DDeviceImpl::begin()
{
	if (isDeviceLost())
	{
		return false; 
	}
	HRESULT hr = m_device->BeginScene();
	if (FAILED(hr))
	{
		return false;
	}
	return true;
}
Exemple #3
0
int D3DApp::run()
{
	MSG  msg;
    msg.message = WM_NULL;

	__int64 cntsPerSec = 0;
	QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
	float secsPerCnt = 1.0f / (float)cntsPerSec;

	__int64 prevTimeStamp = 0;
	QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

	while(msg.message != WM_QUIT)
	{
		// If there are Window messages then process them.
		if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
		{
            TranslateMessage( &msg );
            DispatchMessage( &msg );
		}
		// Otherwise, do animation/game stuff.
		else
        {	
			// If the application is paused then free some CPU cycles to other 
			// applications and then continue on to the next frame.
			if( mAppPaused )
			{
				//Sleep(20);
				//continue;
			}

			if( !isDeviceLost() )
			{
				__int64 currTimeStamp = 0;
				QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);
				float dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;

				updateScene(dt);
				drawScene();

				// Prepare for next iteration: The current time stamp becomes
				// the previous time stamp for the next iteration.
				prevTimeStamp = currTimeStamp;
			}
        }
    }
	return (int)msg.wParam;
}
	void D3D9Device::present(const D3D9RenderWindowCore* renderWindow)
	{		
		RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
		RenderWindowResources*	renderWindowResources = it->second;				

		// Skip present while current device state is invalid.
		if (mDeviceLost || 
			renderWindowResources->acquired == false || 
			isDeviceLost())		
			return;		


		HRESULT hr;

		if (isMultihead())
		{
			// Only the master will call present method results in synchronized
			// buffer swap for the rest of the implicit swap chain.
			if (getPrimaryWindow() == renderWindow)
				hr = mpDevice->Present( NULL, NULL, NULL, NULL );
			else
				hr = S_OK;
		}
		else
		{
			hr = renderWindowResources->swapChain->Present(NULL, NULL, NULL, NULL, 0);			
		}


		if(D3DERR_DEVICELOST == hr)
		{
			releaseRenderWindowResources(renderWindowResources);
			notifyDeviceLost();
		}
		else if( FAILED(hr) )
		{
			BS_EXCEPT(RenderingAPIException, "Error Presenting surfaces");
		}
	}