When I first started coding, especially when I first did C++, there was a lot of confusion about where exactly the ‘game’ was, and more specifically, what a main game loop looks like. Because these days, all you hip kids code in Unity or Gamemaker or MyFirstIDE or some other colorful beginners IDE for the under 5s*, you never actually see your game loop, and have no idea where it is, let alone what it does., However, us real-men who code from the ground up have to write one. Here is mine from the PC version of Democracy 3. There are few comments, because in my godlike knowledge, I understand it all at a glance.
======================================================================================
void APP_Game::GameProc()
{
HRESULT result = GetD3DEngine()->GetDevice()->TestCooperativeLevel();
if(FAILED(result))
{
if (result == D3DERR_DEVICELOST )
{
Sleep( 50 );
return;
}
else if(result == D3DERR_DEVICENOTRESET)
{
if (!GetD3DEngine()->Restore())
{
// Device is lost still
Sleep( 50 );
return;
}
Restore3D();
}
else
{
Sleep( 50 );
return;
}
}
GTimer looptimer;
looptimer.StartTimer();
#ifndef _GOG_
GetSteam()->Process();
#endif //_GOG_
GetInput()->Process();
GUI_GetCursor()->SetCursorStyle(GUI_Cursor::DEFAULT); //reset each frame...
if(BActive)
{
GUI_GetMusic()->Process();
GUI_GetSounds()->Process();
if(PCurrentMode)
{
PCurrentMode->ProcessInput();
}
SIM_GetThreadManager()->ProcessFrame();
GetTextureHistory()->Reset();
LOCKRENDERTHREAD;
GetD3DEngine()->BeginRender();
if(PCurrentMode)
{
PCurrentMode->Draw();
}
GUI_GetTransition()->Draw();
GetD3DEngine()->EndRender();
RenderFont();
#ifdef _DEBUG
if(GetInput()->KeyDown(VK_LSHIFT))
{
GetTextureHistory()->Draw();
}
#endif //_DEBUG
GetD3DEngine()->Flip();
RELEASERENDERTHREAD;
looptimer.Update();
if(looptimer.GetElapsed() < 16.0f)
{
looptimer.Update();
if(looptimer.GetElapsed() < 16.0f)
{
Sleep(0);
}
}
}
else
{
ReleaseResources();
}
if(BRestartPending)
{
BRestartPending = false;
SilentRestart();
}
}
======================================================================================
*yeah I’m mocking different IDEs. deal with it :D This is sarcasm. There is no proven link between masculinity and choice of game development environment.**
**yet.