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 ETModel
  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 = (byte) options.Process;
  27. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Scene.Id:0000}";
  28. Log.Info($"server start........................ {Game.Scene.Id}");
  29. // 先加这里,后面删掉
  30. Game.EventSystem.Run(EventIdType.AfterScenesAdd);
  31. while (true)
  32. {
  33. try
  34. {
  35. Thread.Sleep(1);
  36. OneThreadSynchronizationContext.Instance.Update();
  37. Game.EventSystem.Update();
  38. }
  39. catch (Exception e)
  40. {
  41. Log.Error(e);
  42. }
  43. }
  44. }
  45. catch (Exception e)
  46. {
  47. Log.Error(e);
  48. }
  49. }
  50. }
  51. }