Changed the timing system to give the machine a rest only when it's OK to
This commit is contained in:
@@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Scene headers
|
//Scene headers
|
||||||
@@ -98,7 +101,7 @@ void ClientApplication::Proc() {
|
|||||||
//prepare the time system
|
//prepare the time system
|
||||||
typedef std::chrono::high_resolution_clock Clock;
|
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 simTime = Clock::now();
|
||||||
Clock::time_point realTime;
|
Clock::time_point realTime;
|
||||||
|
|
||||||
@@ -110,8 +113,10 @@ void ClientApplication::Proc() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the current time
|
//update the current time & give the computer as much of a break as possible
|
||||||
realTime = Clock::now();
|
while ((realTime = Clock::now()) < simTime) {
|
||||||
|
SDL_Delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
//simulate game time
|
//simulate game time
|
||||||
while (simTime < realTime) {
|
while (simTime < realTime) {
|
||||||
@@ -122,9 +127,6 @@ void ClientApplication::Proc() {
|
|||||||
|
|
||||||
//draw the game to the screen
|
//draw the game to the screen
|
||||||
activeScene->RenderFrame();
|
activeScene->RenderFrame();
|
||||||
|
|
||||||
//give the computer a break
|
|
||||||
SDL_Delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadScene();
|
UnloadScene();
|
||||||
|
|||||||
Reference in New Issue
Block a user