From 3e7a5b25f67fc84597e00c1df8e970c22b01733b Mon Sep 17 00:00:00 2001 From: Yan Jin Date: Thu, 9 Jan 2025 11:41:43 -0800 Subject: [PATCH 1/2] INTG-2356 1. Send to server by its own timestamp. 2. Add local time offset --- Runtime/Scripts/InworldClient.cs | 9 +++++---- Runtime/Scripts/Util/InworldDateTime.cs | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Runtime/Scripts/InworldClient.cs b/Runtime/Scripts/InworldClient.cs index 53356fb..1bc18a2 100644 --- a/Runtime/Scripts/InworldClient.cs +++ b/Runtime/Scripts/InworldClient.cs @@ -494,8 +494,9 @@ public virtual void SendPerceivedLatencyReport(float latencyPerceived, Precision /// /// Send PingPong Response for latency Test. /// - /// - public virtual void SendLatencyTestResponse(PacketId packetID) + /// the ping packet's packet ID. + /// the ping packet's timestamp + public virtual void SendLatencyTestResponse(PacketId packetID, string packetTimeStamp) { LatencyReportPacket latencyReport = new LatencyReportPacket { @@ -508,7 +509,7 @@ public virtual void SendLatencyTestResponse(PacketId packetID) { type = PingPongType.PONG, pingPacketId = packetID, - pingTimestamp = InworldDateTime.UtcNow + pingTimestamp = packetTimeStamp } } }; @@ -1165,7 +1166,7 @@ bool _HandleRawPackets(InworldPacket receivedPacket) if (latencyReportPacket.latencyReport is PingPongEvent) { m_PingpongLatency = InworldDateTime.ToLatency(receivedPacket.timestamp); - SendLatencyTestResponse(latencyReportPacket.packetId); + SendLatencyTestResponse(latencyReportPacket.packetId, receivedPacket.timestamp); } return false; } diff --git a/Runtime/Scripts/Util/InworldDateTime.cs b/Runtime/Scripts/Util/InworldDateTime.cs index f624bcb..d364a47 100644 --- a/Runtime/Scripts/Util/InworldDateTime.cs +++ b/Runtime/Scripts/Util/InworldDateTime.cs @@ -18,6 +18,7 @@ public class Duration } public static class InworldDateTime { + static TimeSpan s_TimeSpan = TimeSpan.Zero; // YAN: In Unity we use the first format. // And server will return the format with 9 digits. // However, DotNet can only process 7 digits at most. @@ -56,7 +57,12 @@ out DateTime outTime public static int ToLatency(string timeStamp) { DateTime receivedTime = ToDateTime(timeStamp); - TimeSpan delta = DateTime.UtcNow - receivedTime; + if (s_TimeSpan == TimeSpan.Zero) + { + s_TimeSpan = DateTime.UtcNow - receivedTime; + return 20; + } + TimeSpan delta = DateTime.UtcNow - s_TimeSpan - receivedTime; // YAN: Sometimes result can be even smaller than 0, due to the clock skew. // < 20ms is not able to be perceived. int result = delta.Seconds * 1000 + delta.Milliseconds; From b71c9339250848a9d831587e6351501eac603c08 Mon Sep 17 00:00:00 2001 From: Yan Jin Date: Thu, 9 Jan 2025 11:55:33 -0800 Subject: [PATCH 2/2] INTG-2332 Use DebugMode to toggle s2c logs --- Runtime/Scripts/Data/ScriptableObjects/InworldAI.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Runtime/Scripts/Data/ScriptableObjects/InworldAI.cs b/Runtime/Scripts/Data/ScriptableObjects/InworldAI.cs index acfe5ab..79da630 100644 --- a/Runtime/Scripts/Data/ScriptableObjects/InworldAI.cs +++ b/Runtime/Scripts/Data/ScriptableObjects/InworldAI.cs @@ -99,9 +99,17 @@ public static bool IsDebugMode /// public static Capabilities Capabilities { - get => Instance.m_Capabilities; + get + { + Instance.m_Capabilities.logs = IsDebugMode; + Instance.m_Capabilities.logs_debug = IsDebugMode; + Instance.m_Capabilities.logs_warning = IsDebugMode; + Instance.m_Capabilities.logs_info = IsDebugMode; + return Instance.m_Capabilities; + } set => Instance.m_Capabilities = value; } + /// /// The Input Action Asset that defines all the input controls utilized by the SDK. ///