fix #3478 - Changed sendIntervalCounter increment logic (#3480)

Changed sendIntervalCounter logic to fix the issue where if sendIntervalMultiplier = 1, NT will send every frame instead of every send interval.
This is due to sendIntervalCounter being initialised to 1 instead of 0, after NT has triggered it's send.
This commit is contained in:
ninjakickja 2023-05-09 12:57:09 +08:00 committed by GitHub
parent 8a0accc60b
commit 337a0affee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,13 +64,20 @@ void LateUpdate()
protected virtual void CheckLastSendTime()
{
// timeAsDouble not available in older Unity versions.
if (AccurateInterval.Elapsed(NetworkTime.localTime, NetworkServer.sendInterval, ref lastSendIntervalTime))
{
if (sendIntervalCounter == sendIntervalMultiplier)
sendIntervalCounter = 0;
sendIntervalCounter++;
}
// We check interval every frame, and then send if interval is reached.
// So by the time sendIntervalCounter == sendIntervalMultiplier, data is sent,
// thus we reset the counter here.
// This fixes previous issue of, if sendIntervalMultiplier = 1, we send every frame,
// because intervalCounter is always = 1 in the previous version.
if (sendIntervalCounter == sendIntervalMultiplier)
sendIntervalCounter = 0;
// timeAsDouble not available in older Unity versions.
if (AccurateInterval.Elapsed(NetworkTime.localTime, NetworkServer.sendInterval, ref lastSendIntervalTime))
{
sendIntervalCounter++;
}
}
void UpdateServerBroadcast()