Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(typeof(Unit).Assembly);
  22. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  23. Game.EventSystem.LoadAllAssembliesType();
  24. ProtobufHelper.Init();
  25. MongoHelper.Register(Game.EventSystem.GetTypes());
  26. // 命令行参数
  27. Options options = null;
  28. Parser.Default.ParseArguments<Options>(args)
  29. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  30. .WithParsed(o => { options = o; });
  31. Options.Instance = options;
  32. Log.ILog = new NLogger(Game.Options.AppType.ToString());
  33. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  34. Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Game.Options)} ");
  35. Game.EventSystem.Publish(Game.Scene, new EventType.AppStart());
  36. while (true)
  37. {
  38. try
  39. {
  40. Thread.Sleep(1);
  41. Game.Update();
  42. Game.LateUpdate();
  43. Game.FrameFinish();
  44. }
  45. catch (Exception e)
  46. {
  47. Log.Error(e);
  48. }
  49. }
  50. }
  51. catch (Exception e)
  52. {
  53. Log.Error(e);
  54. }
  55. }
  56. }
  57. }