From 73125589fe6208f6d5642d680c10a4d8785799f2 Mon Sep 17 00:00:00 2001 From: "Alecio Furanze (Ale)" Date: Fri, 5 Jul 2024 22:20:05 +0200 Subject: [PATCH] update rudp update manager --- src/rudp/partials/utils/RUDP.Connection.cs | 42 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/rudp/partials/utils/RUDP.Connection.cs b/src/rudp/partials/utils/RUDP.Connection.cs index 7b94d7b..447b170 100644 --- a/src/rudp/partials/utils/RUDP.Connection.cs +++ b/src/rudp/partials/utils/RUDP.Connection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Net.Sockets; using System.Threading.Tasks; @@ -278,12 +279,43 @@ private void Update() if (_isUpdating) return; _isUpdating = true; + var updateReliableStopwatch = new Stopwatch(); + var sendPingStopwatch = new Stopwatch(); + + const int updateReliableTimerMs = 10; + const int sendPingTimerMs = 75; + while (_isUpdating) { try { UpdateInjection(); - UpdateReliable(); + } + catch (Exception e) + { + NetlyEnvironment.Logger.Create(e); + } + + try + { + if (updateReliableStopwatch.ElapsedMilliseconds >= updateReliableTimerMs) + { + UpdateReliable(); + updateReliableStopwatch.Restart(); + } + } + catch (Exception e) + { + NetlyEnvironment.Logger.Create(e); + } + + try + { + if (sendPingStopwatch.ElapsedMilliseconds >= sendPingTimerMs) + { + SendPing(); + sendPingStopwatch.Restart(); + } } catch (Exception e) { @@ -291,9 +323,17 @@ private void Update() } } + // LOOP END! + + updateReliableStopwatch.Stop(); + sendPingStopwatch.Stop(); _isUpdating = false; } + private void SendPing() + { + } + private void UpdateInjection() { byte[][] buffers;