16
General / Taking the time control approach - questions
« on: April 11, 2010, 06:06:54 pm »
Sure...
Code: [Select]
#define FPSRATE 1.f/65.f //It has to be this, otherwise the game runs at half speed. It hates 60.f
...
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP, LOOP!!!!!!!!
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float countor = 0.f;
sf::Clock clocky;
while (bGameGoing && App.IsOpened())
{ GameInputClass& playerInput = GameInputClass::GetInput(); //Keyboard recognized...
playerInput.GetGameplayKeys();
//Escape goes to exit
//-------------------------------------------------------------------------------------
if (playerInput.bEscKey)
{ bGameGoing = false;
gameState = 1;
}
countor += clocky.GetElapsedTime();
while (countor >= FPSRATE)
{ countor -= FPSRATE;
GameLogic();
}
GameRender();
countor += clocky.GetElapsedTime();
if (countor < FPSRATE)
{ sf::Sleep(FPSRATE - countor);
countor = FPSRATE;
}
clocky.Reset();
frameRate = 1.f / frameClock.GetElapsedTime();
frameClock.Reset();
//Wait to get a proper time in-between frames...
//-------------------------------------------------------------------------------------
}