private void UpdatePingVal(float deltaTime) { _pingTimer += deltaTime; if (_pingTimer > 0.5f) { _pingTimer = 0; DelayVal = (int)(_delays.Sum() / LMath.Max(_delays.Count, 1)); _delays.Clear(); PingVal = (int)(_pings.Sum() / LMath.Max(_pings.Count, 1)); _pings.Clear(); if (_minPing < _historyMinPing && _simulatorService._gameStartTimestampMs != -1) { _historyMinPing = _minPing; #if UNITY_EDITOR Debug.LogWarning( $"Recalc _gameStartTimestampMs {_simulatorService._gameStartTimestampMs} _guessServerStartTimestamp:{_guessServerStartTimestamp}"); #endif _simulatorService._gameStartTimestampMs = LMath.Min(_guessServerStartTimestamp, _simulatorService._gameStartTimestampMs); } _minPing = Int64.MaxValue; _maxPing = Int64.MinValue; } }
public void DoUpdate(float deltaTime) { _timer += deltaTime; if (_timer > _checkInterval) { _timer = 0; if (!hasMissTick) { var preSend = _cmdBuffer._maxPing * 1.0f / NetworkDefine.UPDATE_DELTATIME; _targetPreSendTick = _targetPreSendTick * _oldPercent + preSend * (1 - _oldPercent); var targetPreSendTick = LMath.Clamp((int)System.Math.Ceiling(_targetPreSendTick), 1, 60); #if UNITY_EDITOR //if (targetPreSendTick != _simulatorService.PreSendInputCount) { Debug.LogWarning( $"Shrink preSend buffer old:{_simulatorService.PreSendInputCount} new:{_targetPreSendTick} " + $"PING: min:{_cmdBuffer._minPing} max:{_cmdBuffer._maxPing} avg:{_cmdBuffer.PingVal}"); } #endif _simulatorService.PreSendInputCount = targetPreSendTick; } hasMissTick = false; } if (missTick != -1) { var delayTick = _simulatorService.TargetTick - missTick; var targetPreSendTick = _simulatorService.PreSendInputCount + (int)System.Math.Ceiling(delayTick * _incPercent); targetPreSendTick = LMath.Clamp(targetPreSendTick, 1, 60); #if UNITY_EDITOR Debug.LogWarning( $"Expend preSend buffer old:{_simulatorService.PreSendInputCount} new:{targetPreSendTick}"); #endif _simulatorService.PreSendInputCount = targetPreSendTick; nextCheckMissTick = _simulatorService.TargetTick; missTick = -1; hasMissTick = true; } }