Program.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  14. {
  15. Log.Error(e.ExceptionObject.ToString());
  16. };
  17. // 异步方法全部会回掉到主线程
  18. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  19. try
  20. {
  21. Game.EventSystem.Add(typeof(Game).Assembly);
  22. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  23. ProtobufHelper.Init();
  24. MongoHelper.Init();
  25. // 命令行参数
  26. Options options = null;
  27. Parser.Default.ParseArguments<Options>(args)
  28. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  29. .WithParsed(o => { options = o; });
  30. Game.Options = options;
  31. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  32. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  33. Log.Info($"server start........................ {Game.Scene.Id}");
  34. Game.EventSystem.Publish(new EventType.AppStart());
  35. while (true)
  36. {
  37. try
  38. {
  39. Thread.Sleep(1);
  40. Game.Update();
  41. Game.LateUpdate();
  42. Game.FrameFinish();
  43. }
  44. catch (Exception e)
  45. {
  46. Log.Error(e);
  47. }
  48. }
  49. }
  50. catch (Exception e)
  51. {
  52. Log.Error(e);
  53. }
  54. }
  55. }
  56. }