Просмотр исходного кода

TimeInfo做成Singleton,更简洁
之前没有做成Singleton原因是有个update要每帧设置FrameTime,我之前以为赋值long型不是原子的,其实是原子的。

tanghai 2 лет назад
Родитель
Сommit
e601f5a24f
39 измененных файлов с 71 добавлено и 63 удалено
  1. 1 0
      DotNet/Loader/Init.cs
  2. 1 1
      Unity/Assets/Resources/GlobalConfig.asset
  3. 1 4
      Unity/Assets/Scripts/Core/Fiber/Fiber.cs
  4. 2 4
      Unity/Assets/Scripts/Core/Fiber/IdGenerater.cs
  5. 2 2
      Unity/Assets/Scripts/Core/Fiber/Module/Actor/ActorInnerComponentSystem.cs
  6. 1 1
      Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueue.cs
  7. 1 1
      Unity/Assets/Scripts/Core/Fiber/Module/Timer/TimerComponent.cs
  8. 1 0
      Unity/Assets/Scripts/Core/World/Module/Fiber/ThreadPoolScheduler.cs
  9. 8 0
      Unity/Assets/Scripts/Core/World/Module/TimeInfo.meta
  10. 4 3
      Unity/Assets/Scripts/Core/World/Module/TimeInfo/TimeInfo.cs
  11. 1 1
      Unity/Assets/Scripts/Core/World/Module/TimeInfo/TimeInfo.cs.meta
  12. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs
  13. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_XunLuo.cs
  14. 3 3
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Ping/PingComponentSystem.cs
  15. 2 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterCheckComponentSystem.cs
  16. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterHelper.cs
  17. 1 1
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientHelper.cs
  18. 2 2
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientUpdaterSystem.cs
  19. 2 2
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSReplayUpdaterSystem.cs
  20. 1 1
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSSceneChangeHelper.cs
  21. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs
  22. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Benchmark/C2G_BenchmarkHandler.cs
  23. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/C2G_PingHandler.cs
  24. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  25. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs
  26. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/LSServerUpdaterSystem.cs
  27. 6 6
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  28. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs
  29. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  30. 3 3
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorOuterComponentSystem.cs
  31. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  32. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs
  33. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterNodeSystem.cs
  34. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs
  35. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs
  36. 2 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs
  37. 1 0
      Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs
  38. 2 1
      Unity/Assets/Scripts/Model/Share/Entry.cs
  39. 3 3
      Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

+ 1 - 0
DotNet/Loader/Init.cs

@@ -32,6 +32,7 @@ namespace ET
 
 		public void Update()
 		{
+			TimeInfo.Instance.Update();
 			FiberManager.Instance.Update();
 		}
 

+ 1 - 1
Unity/Assets/Resources/GlobalConfig.asset

@@ -12,6 +12,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 36527db572638af47b03c805671cba75, type: 3}
   m_Name: GlobalConfig
   m_EditorClassIdentifier: 
-  CodeMode: 1
+  CodeMode: 3
   BuildType: 1
   AppType: 7

+ 1 - 4
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -34,7 +34,6 @@ namespace ET
         public int Process { get; }
         
         public EntitySystem EntitySystem { get; }
-        public TimeInfo TimeInfo { get; }
         public IdGenerater IdGenerater { get; private set; }
         public Mailboxes Mailboxes { get; private set; }
         public ThreadSynchronizationContext ThreadSynchronizationContext { get; }
@@ -86,8 +85,7 @@ namespace ET
             this.Process = process;
             this.Zone = zone;
             this.EntitySystem = new EntitySystem();
-            this.TimeInfo = new TimeInfo();
-            this.IdGenerater = new IdGenerater(process, this.TimeInfo);
+            this.IdGenerater = new IdGenerater(process);
             this.Mailboxes = new Mailboxes();
             this.ThreadSynchronizationContext = new ThreadSynchronizationContext();
             this.Root = new Scene(this, id, 1, sceneType, name);
@@ -97,7 +95,6 @@ namespace ET
         {
             try
             {
-                this.TimeInfo.Update();
                 this.EntitySystem.Update();
             }
             catch (Exception e)

+ 2 - 4
Unity/Assets/Scripts/Core/Fiber/IdGenerater.cs

@@ -91,15 +91,13 @@ namespace ET
         private uint value;
         private uint lastIdTime;
 
-        private readonly TimeInfo timeInfo;
         private readonly int process;
         
         private uint instanceIdValue;
         
-        public IdGenerater(int process, TimeInfo timeInfo)
+        public IdGenerater(int process)
         {
             this.process = process;
-            this.timeInfo = timeInfo;
             
             long epoch1970tick = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000;
             this.epoch2022 = new DateTime(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks / 10000 - epoch1970tick;
@@ -113,7 +111,7 @@ namespace ET
 
         private uint TimeSince2022()
         {
-            uint a = (uint)((this.timeInfo.FrameTime - this.epoch2022) / 1000);
+            uint a = (uint)((TimeInfo.Instance.FrameTime - this.epoch2022) / 1000);
             return a;
         }
         

+ 2 - 2
Unity/Assets/Scripts/Core/Fiber/Module/Actor/ActorInnerComponentSystem.cs

@@ -175,11 +175,11 @@ namespace ET
             
             Timeout().Coroutine();
             
-            long beginTime = fiber.TimeInfo.ServerFrameTime();
+            long beginTime = TimeInfo.Instance.ServerFrameTime();
 
             IActorResponse response = await tcs;
             
-            long endTime = fiber.TimeInfo.ServerFrameTime();
+            long endTime = TimeInfo.Instance.ServerFrameTime();
 
             long costTime = endTime - beginTime;
             if (costTime > 200)

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/Module/CoroutineLock/CoroutineLockQueue.cs

@@ -32,7 +32,7 @@ namespace ET
             self.queue.Enqueue(waitCoroutineLock);
             if (time > 0)
             {
-                long tillTime = self.Fiber().TimeInfo.ClientFrameTime() + time;
+                long tillTime = TimeInfo.Instance.ClientFrameTime() + time;
                 self.Root().GetComponent<TimerComponent>().NewOnceTimer(tillTime, TimerCoreInvokeType.CoroutineTimeout, waitCoroutineLock);
             }
             self.CurrentCoroutineLock = await waitCoroutineLock.Wait();

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/Module/Timer/TimerComponent.cs

@@ -130,7 +130,7 @@ namespace ET
 
         private static long GetNow(this TimerComponent self)
         {
-            return self.Fiber().TimeInfo.ClientFrameTime();
+            return TimeInfo.Instance.ClientFrameTime();
         }
 
         private static void Run(this TimerComponent self, TimerAction timerAction)

+ 1 - 0
Unity/Assets/Scripts/Core/World/Module/Fiber/ThreadPoolScheduler.cs

@@ -51,6 +51,7 @@ namespace ET
                 {
                     continue;
                 }
+                
                 SynchronizationContext.SetSynchronizationContext(fiber.ThreadSynchronizationContext);
                 fiber.Update();
                 fiber.LateUpdate();

+ 8 - 0
Unity/Assets/Scripts/Core/World/Module/TimeInfo.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 9d38a0632fed04241864c4345345c555
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 3
Unity/Assets/Scripts/Core/Fiber/TimeInfo.cs → Unity/Assets/Scripts/Core/World/Module/TimeInfo/TimeInfo.cs

@@ -2,7 +2,7 @@ using System;
 
 namespace ET
 {
-    public class TimeInfo
+    public class TimeInfo: Singleton<TimeInfo>, ISingletonAwake
     {
         private int timeZone;
         
@@ -25,8 +25,8 @@ namespace ET
         public long ServerMinusClientTime { private get; set; }
 
         public long FrameTime;
-
-        public TimeInfo()
+        
+        public void Awake()
         {
             this.dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
             this.dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
@@ -35,6 +35,7 @@ namespace ET
 
         public void Update()
         {
+            // 赋值long型是原子操作,线程安全
             this.FrameTime = this.ClientNow();
         }
         

+ 1 - 1
Unity/Assets/Scripts/Core/Fiber/TimeInfo.cs.meta → Unity/Assets/Scripts/Core/World/Module/TimeInfo/TimeInfo.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: c7d04a945232e574f9feb2e685b2c42f
+guid: a95f3e903236c5f45ad91a5cc6a9143e
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_Attack.cs

@@ -4,7 +4,7 @@ namespace ET.Client
     {
         public override int Check(AIComponent aiComponent, AIConfig aiConfig)
         {
-            long sec = aiComponent.Fiber().TimeInfo.ClientNow() / 1000 % 15;
+            long sec = TimeInfo.Instance.ClientNow() / 1000 % 15;
             if (sec >= 10)
             {
                 return 0;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/AI/AI_XunLuo.cs

@@ -6,7 +6,7 @@ namespace ET.Client
     {
         public override int Check(AIComponent aiComponent, AIConfig aiConfig)
         {
-            long sec = aiComponent.Fiber().TimeInfo.ClientNow() / 1000 % 15;
+            long sec = TimeInfo.Instance.ClientNow() / 1000 % 15;
             if (sec < 10)
             {
                 return 0;

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Ping/PingComponentSystem.cs

@@ -30,7 +30,7 @@ namespace ET.Client
                     return;
                 }
 
-                long time1 = self.Fiber().TimeInfo.ClientNow();
+                long time1 = TimeInfo.Instance.ClientNow();
                 try
                 {
                     C2G_Ping c2GPing = C2G_Ping.Create(true);
@@ -41,10 +41,10 @@ namespace ET.Client
                         return;
                     }
 
-                    long time2 = self.Fiber().TimeInfo.ClientNow();
+                    long time2 = TimeInfo.Instance.ClientNow();
                     self.Ping = time2 - time1;
                     
-                    fiber.TimeInfo.ServerMinusClientTime = response.Time + (time2 - time1) / 2 - time2;
+                    TimeInfo.Instance.ServerMinusClientTime = response.Time + (time2 - time1) / 2 - time2;
                     
                     await fiber.TimerComponent.WaitAsync(2000);
                 }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterCheckComponentSystem.cs

@@ -32,7 +32,7 @@ namespace ET.Client
                     return;
                 }
 
-                long time = self.Fiber().TimeInfo.ClientFrameTime();
+                long time = TimeInfo.Instance.ClientFrameTime();
 
                 if (time - session.LastRecvTime < 7 * 1000)
                 {
@@ -57,7 +57,7 @@ namespace ET.Client
                     
                     Log.Info($"get recvLocalConn ok: {root.Id} {routerAddress} {realAddress} {recvLocalConn} {localConn} {remoteConn}");
                     
-                    session.LastRecvTime = self.Fiber().TimeInfo.ClientNow();
+                    session.LastRecvTime = TimeInfo.Instance.ClientNow();
                     
                     session.AService.ChangeAddress(sessionId, routerAddress);
                 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/NetClient/Router/RouterHelper.cs

@@ -66,7 +66,7 @@ namespace ET.Client
             Fiber fiber = root.Fiber;
             while (true)
             {
-                long timeNow = fiber.TimeInfo.ClientFrameTime();
+                long timeNow = TimeInfo.Instance.ClientFrameTime();
                 if (timeNow - lastSendTimer > 300)
                 {
                     if (--count < 0)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientHelper.cs

@@ -118,7 +118,7 @@ namespace ET.Client
                 RunLSRollbackSystem(room);
             }
             
-            room.FixedTimeCounter.Reset(room.Fiber.TimeInfo.ServerFrameTime() - frame * LSConstValue.UpdateInterval, 0);
+            room.FixedTimeCounter.Reset(TimeInfo.Instance.ServerFrameTime() - frame * LSConstValue.UpdateInterval, 0);
 
             Log.Debug($"jump replay finish {frame}");
         }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientUpdaterSystem.cs

@@ -18,7 +18,7 @@ namespace ET.Client
         private static void Update(this LSClientUpdater self)
         {
             Room room = self.GetParent<Room>();
-            long timeNow = self.Fiber().TimeInfo.ServerNow();
+            long timeNow = TimeInfo.Instance.ServerNow();
             Scene root = room.Root();
 
             int i = 0;
@@ -48,7 +48,7 @@ namespace ET.Client
                 frameMessage.Input = self.Input;
                 root.GetComponent<ClientSenderCompnent>().Send(frameMessage);
                 
-                long timeNow2 = self.Fiber().TimeInfo.ServerNow();
+                long timeNow2 = TimeInfo.Instance.ServerNow();
                 if (timeNow2 - timeNow > 5)
                 {
                     break;

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSReplayUpdaterSystem.cs

@@ -17,7 +17,7 @@ namespace ET.Client
         {
             Room room = self.GetParent<Room>();
             Fiber fiber = self.Fiber();
-            long timeNow = fiber.TimeInfo.ServerNow();
+            long timeNow = TimeInfo.Instance.ServerNow();
 
             int i = 0;
             while (true)
@@ -39,7 +39,7 @@ namespace ET.Client
                 room.Update(oneFrameInputs);
                 room.SpeedMultiply = ++i;
 
-                long timeNow2 = fiber.TimeInfo.ServerNow();
+                long timeNow2 = TimeInfo.Instance.ServerNow();
                 if (timeNow2 - timeNow > 5)
                 {
                     break;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSSceneChangeHelper.cs

@@ -38,7 +38,7 @@ namespace ET.Client
             room.IsReplay = true;
             room.Replay = replay;
             room.LSWorld = new LSWorld(SceneType.LockStepClient);
-            room.Init(replay.UnitInfos, root.Fiber().TimeInfo.ServerFrameTime());
+            room.Init(replay.UnitInfos, TimeInfo.Instance.ServerFrameTime());
             
             // 等待表现层订阅的事件完成
             await EventSystem.Instance.PublishAsync(root, new EventType.LSSceneChangeStart() {Room = room});

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs

@@ -36,7 +36,7 @@ namespace ET.Client
                 return;
             }
 
-            session.LastRecvTime = self.Fiber().TimeInfo.ClientNow();
+            session.LastRecvTime = TimeInfo.Instance.ClientNow();
             
             switch (message)
             {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Benchmark/C2G_BenchmarkHandler.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             BenchmarkServerComponent benchmarkServerComponent = session.Scene().GetComponent<BenchmarkServerComponent>();
             if (benchmarkServerComponent.Count++ % 1000000 == 0)
             {
-                Log.Debug($"benchmark count: {benchmarkServerComponent.Count} {session.Fiber().TimeInfo.ClientNow()}");
+                Log.Debug($"benchmark count: {benchmarkServerComponent.Count} {TimeInfo.Instance.ClientNow()}");
             }
             await ETTask.CompletedTask;
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/C2G_PingHandler.cs

@@ -8,7 +8,7 @@ namespace ET.Server
 	{
 		protected override async ETTask Run(Session session, C2G_Ping request, G2C_Ping response)
 		{
-			response.Time = session.Fiber().TimeInfo.ServerNow();
+			response.Time = TimeInfo.Instance.ServerNow();
 			await ETTask.CompletedTask;
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs

@@ -21,7 +21,7 @@ namespace ET.Server
             
             await room.Fiber.TimerComponent.WaitAsync(1000);
 
-            Room2C_Start room2CStart = new() { StartTime = room.Fiber().TimeInfo.ServerFrameTime() };
+            Room2C_Start room2CStart = new() { StartTime = TimeInfo.Instance.ServerFrameTime() };
             foreach (RoomPlayer rp in roomServerComponent.Children.Values)
             {
                 room2CStart.UnitInfo.Add(new LockStepUnitInfo()

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs

@@ -14,7 +14,7 @@ namespace ET.Server
             if (message.Frame % (1000 / LSConstValue.UpdateInterval) == 0)
             {
                 long nowFrameTime = room.FixedTimeCounter.FrameTime(message.Frame);
-                int diffTime = (int)(nowFrameTime - room.Fiber().TimeInfo.ServerFrameTime());
+                int diffTime = (int)(nowFrameTime - TimeInfo.Instance.ServerFrameTime());
 
                 room.Root().GetComponent<ActorLocationSenderComponent>().Get(LocationType.GateSession).Send(message.PlayerId, new Room2C_AdjustUpdateTime() {DiffTime = diffTime});
             }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/LSServerUpdaterSystem.cs

@@ -17,7 +17,7 @@ namespace ET.Server
         private static void Update(this LSServerUpdater self)
         {
             Room room = self.GetParent<Room>();
-            long timeNow = room.Fiber().TimeInfo.ServerFrameTime();
+            long timeNow = TimeInfo.Instance.ServerFrameTime();
 
 
             int frame = room.AuthorityFrame + 1;

+ 6 - 6
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -44,7 +44,7 @@ namespace ET.Server
         {
             using (ListComponent<long> list = ListComponent<long>.Create())
             {
-                long timeNow = self.Fiber().TimeInfo.ServerNow();
+                long timeNow = TimeInfo.Instance.ServerNow();
                 foreach ((long key, Entity value) in self.Children)
                 {
                     ActorLocationSender actorLocationMessageSender = (ActorLocationSender) value;
@@ -105,7 +105,7 @@ namespace ET.Server
             
             if (actorLocationSender.ActorId != default)
             {
-                actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+                actorLocationSender.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
                 root.GetComponent<ActorSenderComponent>().Send(actorLocationSender.ActorId, message);
                 return;
             }
@@ -129,7 +129,7 @@ namespace ET.Server
                     }
                 }
                 
-                actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+                actorLocationSender.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
                 root.GetComponent<ActorSenderComponent>().Send(actorLocationSender.ActorId, message);
             }
         }
@@ -144,7 +144,7 @@ namespace ET.Server
             
             if (actorLocationSender.ActorId != default)
             {
-                actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+                actorLocationSender.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
                 return await root.GetComponent<ActorSenderComponent>().Call(actorLocationSender.ActorId, request);
             }
             
@@ -168,7 +168,7 @@ namespace ET.Server
                 }
             }
 
-            actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+            actorLocationSender.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
             return await root.GetComponent<ActorSenderComponent>().Call(actorLocationSender.ActorId, request);
         }
 
@@ -222,7 +222,7 @@ namespace ET.Server
         {
             int failTimes = 0;
             long instanceId = actorLocationSender.InstanceId;
-            actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+            actorLocationSender.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
             
             Scene root = self.Root();
             

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs

@@ -9,7 +9,7 @@ namespace ET.Server
         [EntitySystem]
         private static void Awake(this ActorLocationSender self)
         {
-            self.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
+            self.LastSendOrRecvTime = TimeInfo.Instance.ServerNow();
             self.ActorId = default;
             self.Error = 0;
         }

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -11,28 +11,28 @@ namespace ET.Server
 
         public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
         {
-            Log.Info($"location proxy add {key}, {actorId} {self.Fiber().TimeInfo.ServerNow()}");
+            Log.Info($"location proxy add {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
             await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectAddRequest() { Type = type, Key = key, ActorId = actorId });
         }
 
         public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
         {
-            Log.Info($"location proxy lock {key}, {actorId} {self.Fiber().TimeInfo.ServerNow()}");
+            Log.Info($"location proxy lock {key}, {actorId} {TimeInfo.Instance.ServerNow()}");
             await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectLockRequest() { Type = type, Key = key, ActorId = actorId, Time = time });
         }
 
         public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
         {
-            Log.Info($"location proxy unlock {key}, {newActorId} {self.Fiber().TimeInfo.ServerNow()}");
+            Log.Info($"location proxy unlock {key}, {newActorId} {TimeInfo.Instance.ServerNow()}");
             await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectUnLockRequest() { Type = type, Key = key, OldActorId = oldActorId, NewActorId = newActorId });
         }
 
         public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
         {
-            Log.Info($"location proxy add {key}, {self.Fiber().TimeInfo.ServerNow()}");
+            Log.Info($"location proxy add {key}, {TimeInfo.Instance.ServerNow()}");
             await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectRemoveRequest() { Type = type, Key = key });
         }

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorOuterComponentSystem.cs

@@ -49,7 +49,7 @@ namespace ET.Server
                 return;
             }
             
-            session.LastRecvTime = self.Fiber().TimeInfo.ClientFrameTime();
+            session.LastRecvTime = TimeInfo.Instance.ClientFrameTime();
 
             self.HandleMessage(actorId, message).Coroutine();
         }
@@ -228,11 +228,11 @@ namespace ET.Server
 
             Timeout().Coroutine();
 
-            long beginTime = fiber.TimeInfo.ServerFrameTime();
+            long beginTime = TimeInfo.Instance.ServerFrameTime();
 
             IActorResponse response = await tcs;
 
-            long endTime = fiber.TimeInfo.ServerFrameTime();
+            long endTime = TimeInfo.Instance.ServerFrameTime();
 
             long costTime = endTime - beginTime;
             if (costTime > 200)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -62,7 +62,7 @@ namespace ET.Server
             {
                 return;
             }
-            session.LastRecvTime = self.Fiber().TimeInfo.ClientNow();
+            session.LastRecvTime = TimeInfo.Instance.ClientNow();
             
             LogMsg.Instance.Debug(message);
 			

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs

@@ -46,7 +46,7 @@ namespace ET.Server
         [EntitySystem]
         private static void Update(this RouterComponent self)
         {
-            long timeNow = self.Fiber().TimeInfo.ClientNow();
+            long timeNow = TimeInfo.Instance.ClientNow();
             self.RecvOuter(timeNow);
             self.RecvInner(timeNow);
 
@@ -596,7 +596,7 @@ namespace ET.Server
             routerNode.InnerIpEndPoint = NetworkHelper.ToIPEndPoint(innerAddress);
             routerNode.SyncIpEndPoint = syncEndPoint;
             routerNode.InnerAddress = innerAddress;
-            routerNode.LastRecvInnerTime = self.Fiber().TimeInfo.ClientNow();
+            routerNode.LastRecvInnerTime = TimeInfo.Instance.ClientNow();
 
             self.ConnectIdNodes.Add(connectId, routerNode);
 

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterNodeSystem.cs

@@ -7,7 +7,7 @@
         [EntitySystem]
         private static void Awake(this RouterNode self)
         {
-            long timeNow = self.Fiber().TimeInfo.ServerNow();
+            long timeNow = TimeInfo.Instance.ServerNow();
             self.LastRecvInnerTime = timeNow;
             self.LastRecvOuterTime = timeNow;
             self.OuterIpEndPoint = null;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs

@@ -25,7 +25,7 @@ namespace ET
         [EntitySystem]
         private static void Awake(this SessionAcceptTimeoutComponent self)
         {
-            self.Timer = self.Fiber().TimerComponent.NewOnceTimer(self.Fiber().TimeInfo.ServerNow() + 5000, TimerInvokeType.SessionAcceptTimeout, self);
+            self.Timer = self.Fiber().TimerComponent.NewOnceTimer(TimeInfo.Instance.ServerNow() + 5000, TimerInvokeType.SessionAcceptTimeout, self);
         }
         
         [EntitySystem]

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs

@@ -39,7 +39,7 @@ namespace ET
         private static void Check(this SessionIdleCheckerComponent self)
         {
             Session session = self.GetParent<Session>();
-            long timeNow = self.Fiber().TimeInfo.ClientNow();
+            long timeNow = TimeInfo.Instance.ClientNow();
 
             if (timeNow - session.LastRecvTime < ConstValue.SessionTimeoutTime && timeNow - session.LastSendTime < ConstValue.SessionTimeoutTime)
             {

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs

@@ -110,7 +110,7 @@ namespace ET
         {
             Unit unit = self.GetParent<Unit>();
             
-            long timeNow = self.Fiber().TimeInfo.ClientNow();
+            long timeNow = TimeInfo.Instance.ClientNow();
             long moveTime = timeNow - self.StartTime;
 
             while (true)
@@ -178,7 +178,7 @@ namespace ET
 
         private static void StartMove(this MoveComponent self)
         {
-            self.BeginTime = self.Fiber().TimeInfo.ClientNow();
+            self.BeginTime = TimeInfo.Instance.ClientNow();
             self.StartTime = self.BeginTime;
             self.SetNextTarget();
 

+ 1 - 0
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -31,6 +31,7 @@ namespace ET
 
 		private void Update()
 		{
+			TimeInfo.Instance.Update();
 			FiberManager.Instance.Update();
 		}
 

+ 2 - 1
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -36,7 +36,8 @@ namespace ET
             
             MongoHelper.RegisterStruct<LSInput>();
             MongoHelper.Register();
-            
+
+            World.Instance.AddSingleton<TimeInfo>();
             World.Instance.AddSingleton<OpcodeType>();
             World.Instance.AddSingleton<IdValueGenerater>();
             World.Instance.AddSingleton<ObjectPool>();

+ 3 - 3
Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

@@ -25,7 +25,7 @@ namespace ET
         private static void Awake(this Session self, AService aService)
         {
             self.AService = aService;
-            long timeNow = self.Fiber().TimeInfo.ClientNow();
+            long timeNow = TimeInfo.Instance.ClientNow();
             self.LastRecvTime = timeNow;
             self.LastSendTime = timeNow;
 
@@ -44,7 +44,7 @@ namespace ET
                 responseCallback.Tcs.SetException(new RpcException(self.Error, $"session dispose: {self.Id} {self.RemoteAddress}"));
             }
 
-            Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {self.Fiber().TimeInfo.ClientNow()}");
+            Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeInfo.Instance.ClientNow()}");
             
             self.requestCallbacks.Clear();
         }
@@ -139,7 +139,7 @@ namespace ET
         
         public static void Send(this Session self, ActorId actorId, IMessage message)
         {
-            self.LastSendTime = self.Fiber().TimeInfo.ClientNow();
+            self.LastSendTime = TimeInfo.Instance.ClientNow();
             LogMsg.Instance.Debug(message);
             self.AService.Send(self.Id, actorId, message as MessageObject);
         }