add latency simulation

This commit is contained in:
_nebula 2023-08-08 11:45:10 +01:00
parent 52f698ea5c
commit 2d25316637
2 changed files with 26 additions and 2 deletions

View File

@ -68,6 +68,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
private (TransportError error, string reason) _lastTransportError = (TransportError.Unexpected, "transport did not give an error. uh oh"); private (TransportError error, string reason) _lastTransportError = (TransportError.Unexpected, "transport did not give an error. uh oh");
private static LatencySimulation _latencyTransport;
private static kcp2k.KcpTransport _kcpTransport; private static kcp2k.KcpTransport _kcpTransport;
private static EosTransport _eosTransport; private static EosTransport _eosTransport;
@ -78,6 +79,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
{ {
_kcpTransport = gameObject.AddComponent<kcp2k.KcpTransport>(); _kcpTransport = gameObject.AddComponent<kcp2k.KcpTransport>();
} }
{ {
// https://dev.epicgames.com/portal/en-US/qsb/sdk/credentials/qsb // https://dev.epicgames.com/portal/en-US/qsb/sdk/credentials/qsb
var eosApiKey = ScriptableObject.CreateInstance<EosApiKey>(); var eosApiKey = ScriptableObject.CreateInstance<EosApiKey>();
@ -95,7 +97,16 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
_eosTransport = gameObject.AddComponent<EosTransport>(); _eosTransport = gameObject.AddComponent<EosTransport>();
} }
transport = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
{
_latencyTransport = gameObject.AddComponent<LatencySimulation>();
_latencyTransport.reliableLatency = QSBCore.DebugSettings.LatencySimulation;
_latencyTransport.wrap = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
}
transport = QSBCore.DebugSettings.LatencySimulation > 0
? _latencyTransport
: QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
gameObject.SetActive(true); gameObject.SetActive(true);
@ -164,10 +175,20 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
{ {
return; return;
} }
if (singleton != null) if (singleton != null)
{ {
singleton.transport = Transport.active = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport; if (QSBCore.DebugSettings.LatencySimulation > 0)
{
_latencyTransport.wrap = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
singleton.transport = Transport.active = _latencyTransport;
}
else
{
singleton.transport = Transport.active = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
}
} }
if (MenuManager.Instance != null) if (MenuManager.Instance != null)
{ {
MenuManager.Instance.OnLanguageChanged(); // hack to update text MenuManager.Instance.OnLanguageChanged(); // hack to update text

View File

@ -26,6 +26,9 @@ public class DebugSettings
[JsonProperty("disableLoopDeath")] [JsonProperty("disableLoopDeath")]
public bool DisableLoopDeath; public bool DisableLoopDeath;
[JsonProperty("latencySimulation")]
public int LatencySimulation;
[JsonProperty("debugMode")] [JsonProperty("debugMode")]
public bool DebugMode; public bool DebugMode;