using NETCoreTest.Framework; using System; using System.Collections.Generic; namespace ET { public class RunTimeComponentAwakeSystem : AwakeSystem { public override void Awake(RunTimeComponent self) { RunTimeComponent.inst = self; self.Load(); } } //public class RunTimeComponentLoadSystem : LoadSystem //{ // public override void Load(RunTimeComponent self) // { // self.Load(); // } //} public class RunTimeComponentUpdateSystem : UpdateSystem { public override void Update(RunTimeComponent self) { self.FixedUpdate.Tick(); } } public class RunTimeComponentDestroySystem : DestroySystem { public override void Destroy(RunTimeComponent self) { TimerComponent.Instance.Remove(self.timerId); } } public static class RunTimeComponentSystem { private const int TicksPerMillisecond = 1; private const int TicksPerSecond = 1000; private const int TicksPerMinute = TicksPerSecond * 60; private const int TicksPerHour = TicksPerMinute * 60; private const int TicksPerDay = TicksPerHour * 24; private const int Max_FRAME = 30; private const int Coefficient = 2; private static int frame = 0; private static bool isTouchPer1MinuteOfDay; private static int updateFrame = 0; const int FRAME = 30; public static void Load(this RunTimeComponent self) { self.FixedUpdate = new FixedUpdate(); self.FixedUpdate.TargetElapsedTime = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / FRAME); self.FixedUpdate.UpdateCallback += self.FixedUpdateRun; self.timerId = TimerComponent.Instance.NewRepeatedTimer(1 * 1000,()=> { Update1SecondOfDay(self); }); } public static void FixedUpdateRun(this RunTimeComponent self) { //var now = TimeHelper.ClientNow(); if (frame % (Max_FRAME * Coefficient) == 0) { //Game.EventSystem.Publish(new EventType.UpdateMaxFrame {Frame =Max_FRAME, now = now }).Coroutine(); if (AppConfig.inst.showFPS) Log.Debug($"update FPS:{updateFrame * 1f / Coefficient:f1}"); updateFrame = 0; } frame++; } private static void Update1SecondOfDay(RunTimeComponent self) { long now = TimeHelper.ClientNow(); //!判断1分钟 long timeOf1Minute = now % TicksPerMinute; if (!isTouchPer1MinuteOfDay && timeOf1Minute < 1000) { isTouchPer1MinuteOfDay = true; //!判断5分钟 long timeOf5Minute = now % (5 * TicksPerMinute); if (timeOf5Minute < 10000) { //!判断30分钟 long timeOf30Minute = now % (30 * TicksPerMinute); if (timeOf30Minute < 10000) { //!判断1小时 long timeOf1Hour = now % TicksPerHour; if (timeOf1Hour < 10000) { //!判断1天 long timeOf1Day = now % TicksPerDay; if (timeOf1Day < 100000) { Game.EventSystem.Publish(new EventType.UpdatePer1DayOfMonth { now = now,zone =self.DomainZone()}).Coroutine(); } Game.EventSystem.Publish(new EventType.UpdatePer1HourOfDay { now = now }).Coroutine(); } Game.EventSystem.Publish(new EventType.UpdatePer30MinuteOfDay { now = now }).Coroutine(); } Game.EventSystem.Publish(new EventType.UpdatePer5MinuteOfDay { now = now }).Coroutine(); } Game.EventSystem.Publish(new EventType.UpdatePer1MinuteOfDay { now = now }).Coroutine(); } else if (timeOf1Minute > 1000) { isTouchPer1MinuteOfDay = false; } Game.EventSystem.Publish(new EventType.UpdatePer1Second { now = now }).Coroutine(); } } public class RunTimeComponent : Entity { public static RunTimeComponent inst { get; set; } public FixedUpdate FixedUpdate { get; set; } public long timerId; } }