From de6eb385168871178ae2e863ebc2b2435465d8c3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 13 Jan 2015 01:34:59 +1100 Subject: [PATCH] Reduced CPU load of the client --- client/client_application.cpp | 16 +++++++++++----- server/server_logic.cpp | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/client_application.cpp b/client/client_application.cpp index f2dcd8a..70957fe 100644 --- a/client/client_application.cpp +++ b/client/client_application.cpp @@ -137,11 +137,17 @@ void ClientApplication::Proc() { realTime = Clock::now(); //simulate game time - while (simTime < realTime) { - //call each user defined function - activeScene->RunFrame(); - //~60 FPS - simTime += std::chrono::duration(16); + if (simTime < realTime) { + while (simTime < realTime) { + //call each user defined function + activeScene->RunFrame(); + //~60 FPS + simTime += std::chrono::duration(16); + } + } + else { + //give the machine a break + SDL_Delay(10); } //draw the game to the screen diff --git a/server/server_logic.cpp b/server/server_logic.cpp index d4d96fa..802c8c9 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -187,7 +187,7 @@ void ServerApplication::Proc() { std::cerr << "Client dropped: " << disconnected << std::endl; } - //give the computer a break + //give the machine a break SDL_Delay(10); } delete reinterpret_cast(packetBuffer);