2024-02-01 00:14:32 +08:00
|
|
|
// TODO: Implement ReliabilityLayer.cpp
|
|
|
|
|
|
|
|
#include "ReliabilityLayer.h"
|
|
|
|
|
2024-04-14 22:10:48 +08:00
|
|
|
static const float PING_MULTIPLIER_TO_RESEND=3.0; // So internet ping variation doesn't cause needless resends
|
|
|
|
static const RakNetTime MIN_PING_TO_RESEND=30; // So system timer changes and CPU lag don't send needless resends
|
|
|
|
|
2024-02-01 00:14:32 +08:00
|
|
|
ReliabilityLayer::ReliabilityLayer()
|
|
|
|
{
|
|
|
|
// TODO: ReliabilityLayer::ReliabilityLayer
|
|
|
|
|
|
|
|
InitializeVariables();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReliabilityLayer::InitializeVariables( void )
|
|
|
|
{
|
|
|
|
// TODO: ReliabilityLayer::InitializeVariables
|
2024-04-14 22:23:30 +08:00
|
|
|
|
|
|
|
SetPing( 1000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------
|
|
|
|
// How long to wait between packet resends
|
|
|
|
//-------------------------------------------------------------------------------------------------------
|
|
|
|
void ReliabilityLayer::SetPing( RakNetTime i )
|
|
|
|
{
|
|
|
|
//assert(i < (RakNetTimeNS)timeoutTime*1000);
|
|
|
|
if (i > timeoutTime)
|
|
|
|
ping=500;
|
|
|
|
else
|
|
|
|
ping = i;
|
|
|
|
if (ping < 30)
|
|
|
|
ping=30; // Leave a buffer for variations in ping
|
|
|
|
#ifndef _RELEASE
|
|
|
|
if (ping < (RakNetTime)(minExtraPing+extraPingVariance)*2)
|
|
|
|
ping=(minExtraPing+extraPingVariance)*2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
UpdateNextActionTime();
|
2024-02-01 00:14:32 +08:00
|
|
|
}
|
2024-04-14 22:10:48 +08:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------
|
|
|
|
void ReliabilityLayer::UpdateNextActionTime(void)
|
|
|
|
{
|
|
|
|
//double multiple = log10(currentBandwidth/MINIMUM_SEND_BPS) / 0.30102999566398119521373889472449;
|
|
|
|
if (ping*(RakNetTime)PING_MULTIPLIER_TO_RESEND < MIN_PING_TO_RESEND)
|
|
|
|
ackTimeIncrement=(RakNetTimeNS)MIN_PING_TO_RESEND*1000;
|
|
|
|
else
|
|
|
|
ackTimeIncrement=(RakNetTimeNS)(ping*(RakNetTime)PING_MULTIPLIER_TO_RESEND)*1000;
|
|
|
|
}
|