Redid timers.

This commit is contained in:
Jocke
2016-03-12 21:38:46 +01:00
parent f8f536802f
commit b7d88808e2
4 changed files with 32 additions and 27 deletions
+11 -9
View File
@@ -5,8 +5,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
, m_ServerlistRequest(13)
{
ConfigFile* config = ResourceManager::Load<ConfigFile>("Config.ini");
snapshotInterval = 1000 * config->Get<float>("Networking.SnapshotInterval", 0.05f);
pingIntervalMs = config->Get<float>("Networking.PingIntervalMs", 1000);
snapshotInterval = config->Get<float>("Networking.SnapshotInterval", 0.05);
pingInterval = config->Get<float>("Networking.PingIntervalMs", 1000) / 1000.0;
m_ServerName = config->Get<std::string>("Networking.Name", "Unnamed");
// Subscribe to events
@@ -87,22 +87,24 @@ void Server::Update(double dt)
}
m_PlayersToDisconnect.clear();
std::clock_t currentTime = std::clock();
// Send snapshot
if (snapshotInterval < (1000 * (currentTime - previousSnapshotMessage) / (double)CLOCKS_PER_SEC)) {
previousSnapshotMessage += dt;
if (snapshotInterval < previousSnapshotMessage) {
sendSnapshot();
previousSnapshotMessage = currentTime;
previousSnapshotMessage = 0;
}
// Send pings each
if (pingIntervalMs < (1000 * (currentTime - previousePingMessage) / (double)CLOCKS_PER_SEC)) {
previousePingMessage += dt;
if (pingInterval < previousePingMessage) {
sendPing();
previousePingMessage = currentTime;
previousePingMessage = 0;
}
// Time out logic
if (checkTimeOutInterval < (1000 * (currentTime - timOutTimer) / (double)CLOCKS_PER_SEC)) {
timOutTimer += dt;
if (checkTimeOutInterval < timOutTimer) {
checkForTimeOuts();
timOutTimer = currentTime;
timOutTimer = 0;
}
m_EventBroker->Process<Server>();
if (isReadingData) {