static void RunServer() { try { TimeStat timeAll = new TimeStat(); LockTimer perfUpdateTimer = new LockTimer(60 * 1000); perfUpdateTimer.Trigger(); while (true) { timeAll.Start(); GameTime.Update(); OnTick?.Invoke(); GameTime.Update(); GUCTimer.Update(GameTime.Ticks); // move to new thread? //Run the dispatcher GUCDispatcher.Execute(); GameTime.Update(); GameServer.Update(); //process received packets GameTime.Update(); WorldObjects.World.ForEach(w => w.OnTick(GameTime.Ticks)); long elapsed = timeAll.Stop(); if (perfUpdateTimer.IsReady) { Logger.Log("Performance: {0:0}ms avg, {1:0}ms max. RAM: {2:0.0}MB", timeAll.Average, timeAll.Maximum, Process.GetCurrentProcess().PrivateMemorySize64 / 1000000d); timeAll.Reset(); } long diff = (updateRate - elapsed) / TimeSpan.TicksPerMillisecond; if (diff > 0) { Thread.Sleep((int)diff); } } } catch (Exception e) { Logger.LogError(e.Source + "<br>" + e.Message + "<br>" + e.StackTrace); } }
/// <inheritdoc /> public void RunOrEnqueue(Action action) => GUCDispatcher.RunOrEnqueue(action);
/// <inheritdoc /> public void EnqueueAction(Action action) => GUCDispatcher.EnqueueAction(action);
/// <inheritdoc /> public bool CheckAccess() => GUCDispatcher.CheckAccess();