Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using CommandLine;
  6. using NLog;
  7. namespace ET
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. // 异步方法全部会回掉到主线程
  14. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  15. try
  16. {
  17. Game.EventSystem.Add(typeof(Game).Assembly);
  18. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  19. ProtobufHelper.Init();
  20. MongoHelper.Init();
  21. // 命令行参数
  22. Options options = null;
  23. Parser.Default.ParseArguments<Options>(args)
  24. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  25. .WithParsed(o => { options = o; });
  26. Game.Options = options;
  27. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";
  28. Log.Info($"server start........................ {Game.Scene.Id}");
  29. Game.EventSystem.Publish(new EventType.AppStart());
  30. while (true)
  31. {
  32. try
  33. {
  34. Thread.Sleep(1);
  35. ThreadSynchronizationContext.Instance.Update();
  36. Game.Update();
  37. Game.LateUpdate();
  38. Game.FrameFinish();
  39. }
  40. catch (Exception e)
  41. {
  42. Log.Error(e);
  43. }
  44. }
  45. }
  46. catch (Exception e)
  47. {
  48. Log.Error(e);
  49. }
  50. }
  51. }
  52. }