Fixed a derp with the time
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user