From a49b0eb1fe1483793455c800a73d16a0cb569c95 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 26 Jun 2013 23:52:31 +1000 Subject: [PATCH] Changed the timing system to give the machine a rest only when it's OK to --- client/client_application.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index d107b1c..086911d 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -23,6 +23,9 @@ #include #include +#include + using std::cout; + using std::endl; //------------------------- //Scene headers @@ -98,7 +101,7 @@ void ClientApplication::Proc() { //prepare the time system typedef std::chrono::high_resolution_clock Clock; - Clock::duration delta(16 * Clock::duration::period::den / std::milli::den); + Clock::duration delta(5 * Clock::duration::period::den / std::milli::den); Clock::time_point simTime = Clock::now(); Clock::time_point realTime; @@ -110,8 +113,10 @@ void ClientApplication::Proc() { continue; } - //update the current time - realTime = Clock::now(); + //update the current time & give the computer as much of a break as possible + while ((realTime = Clock::now()) < simTime) { + SDL_Delay(1); + } //simulate game time while (simTime < realTime) { @@ -122,9 +127,6 @@ void ClientApplication::Proc() { //draw the game to the screen activeScene->RenderFrame(); - - //give the computer a break - SDL_Delay(10); } UnloadScene();