Network/ENetHost: Fix service time precision

This commit is contained in:
Lynix 2017-11-20 21:04:50 +01:00
parent 7eff1f34f1
commit f2506ee918
3 changed files with 14 additions and 5 deletions

View File

@ -19,6 +19,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/MemoryPool.hpp>
#include <Nazara/Network/ENetCompressor.hpp>
#include <Nazara/Network/ENetPeer.hpp>
@ -95,6 +96,8 @@ namespace Nz
void ThrottleBandwidth();
inline void UpdateServiceTime();
static std::size_t GetCommandSize(UInt8 commandNumber);
static bool Initialize();
static void Uninitialize();

View File

@ -73,6 +73,12 @@ namespace Nz
return ref;
}
inline void ENetHost::UpdateServiceTime()
{
// Compute service time as microseconds for extra precision
m_serviceTime = static_cast<UInt32>(GetElapsedMicroseconds() / 1000);
}
}
#include <Nazara/Network/DebugOff.hpp>

View File

@ -13,7 +13,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/ENetHost.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Network/Algorithm.hpp>
#include <Nazara/Network/ENetPeer.hpp>
@ -199,7 +198,7 @@ namespace Nz
void ENetHost::Flush()
{
m_serviceTime = GetElapsedMilliseconds();
UpdateServiceTime();
SendOutgoingCommands(nullptr, false);
}
@ -216,7 +215,8 @@ namespace Nz
return 1;
}
m_serviceTime = GetElapsedMilliseconds();
UpdateServiceTime();
timeout += m_serviceTime;
do
@ -279,7 +279,7 @@ namespace Nz
for (;;)
{
m_serviceTime = GetElapsedMilliseconds();
UpdateServiceTime();
if (ENetTimeGreaterEqual(m_serviceTime, timeout))
return 0;
@ -288,7 +288,7 @@ namespace Nz
break;
}
m_serviceTime = GetElapsedMilliseconds();
UpdateServiceTime();
}
while (m_poller.IsReadyToRead(m_socket));