Program.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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(OneThreadSynchronizationContext.Instance);
  15. try
  16. {
  17. Game.EventSystem.Add(typeof(Game).Assembly);
  18. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  19. MongoHelper.Init();
  20. // 命令行参数
  21. Options options = null;
  22. Parser.Default.ParseArguments<Options>(args)
  23. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  24. .WithParsed(o => { options = o; });
  25. Game.Scene.AddComponent(options);
  26. IdGenerater.Process = options.Process;
  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. OneThreadSynchronizationContext.Instance.Update();
  36. Game.EventSystem.Update();
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e);
  41. }
  42. }
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e);
  47. }
  48. }
  49. }
  50. }