Fixed a derp with the time

This commit is contained in:
Kayne Ruse
2013-06-24 12:18:36 +10:00
parent 0ca84a8653
commit 6a32599a69
2 changed files with 16 additions and 8 deletions
+16 -2
View File
@@ -23,6 +23,7 @@
#include <stdexcept>
#include <iostream>
#include <chrono>
using namespace std;
@@ -84,17 +85,30 @@ void ServerApplication::Init() {
}
void ServerApplication::Proc() {
Clock::duration delta = Clock::now() - lastTick;
lastTick = Clock::now();
typedef chrono::high_resolution_clock Clock;
Clock::time_point lastTick = Clock::now();
Clock::duration delta;
while(running) {
try {
//process all packets on the network queue
while(HandlePacket(popNetworkPacket()));
}
catch(exception& e) {
//handle any errors
cerr << "Network Error: " << e.what() << endl;
continue;
}
//get the time since last update
delta = Clock::now() - lastTick;
lastTick = Clock::now();
//update the world
UpdateWorld(double(delta.count()) / Clock::duration::period::den);
//give the machine a break
SDL_Delay(10);
}
}
-6
View File
@@ -37,12 +37,8 @@
#include "SDL/SDL_thread.h"
#include <map>
#include <chrono>
#include <string>
//lazy
typedef std::chrono::high_resolution_clock Clock;
class ServerApplication {
public:
ServerApplication();
@@ -68,8 +64,6 @@ private:
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
//members
Clock::time_point lastTick = Clock::now();
std::map<int, ClientEntry> clients;
std::map<int, PlayerEntry> players;