Program.cs 1.5 KB

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