Fixed a derp with the time
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -84,17 +85,30 @@ void ServerApplication::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::Proc() {
|
void ServerApplication::Proc() {
|
||||||
Clock::duration delta = Clock::now() - lastTick;
|
typedef chrono::high_resolution_clock Clock;
|
||||||
lastTick = Clock::now();
|
|
||||||
|
Clock::time_point lastTick = Clock::now();
|
||||||
|
Clock::duration delta;
|
||||||
|
|
||||||
while(running) {
|
while(running) {
|
||||||
try {
|
try {
|
||||||
//process all packets on the network queue
|
//process all packets on the network queue
|
||||||
while(HandlePacket(popNetworkPacket()));
|
while(HandlePacket(popNetworkPacket()));
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
|
//handle any errors
|
||||||
cerr << "Network Error: " << e.what() << endl;
|
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);
|
UpdateWorld(double(delta.count()) / Clock::duration::period::den);
|
||||||
|
|
||||||
|
//give the machine a break
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,8 @@
|
|||||||
#include "SDL/SDL_thread.h"
|
#include "SDL/SDL_thread.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <chrono>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//lazy
|
|
||||||
typedef std::chrono::high_resolution_clock Clock;
|
|
||||||
|
|
||||||
class ServerApplication {
|
class ServerApplication {
|
||||||
public:
|
public:
|
||||||
ServerApplication();
|
ServerApplication();
|
||||||
@@ -68,8 +64,6 @@ private:
|
|||||||
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
UDPNetworkUtility* netUtil = Singleton<UDPNetworkUtility>::Get();
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Clock::time_point lastTick = Clock::now();
|
|
||||||
|
|
||||||
std::map<int, ClientEntry> clients;
|
std::map<int, ClientEntry> clients;
|
||||||
std::map<int, PlayerEntry> players;
|
std::map<int, PlayerEntry> players;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user