Init.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Threading;
  3. using CommandLine;
  4. namespace ET
  5. {
  6. internal static class Init
  7. {
  8. private static void Main(string[] args)
  9. {
  10. try
  11. {
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. // 异步方法全部会回掉到主线程
  17. Game.AddSingleton<MainThreadSynchronizationContext>();
  18. // 命令行参数
  19. Parser.Default.ParseArguments<Options>(args)
  20. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  21. .WithParsed(Game.AddSingleton);
  22. Game.AddSingleton<TimeInfo>();
  23. Game.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  24. Game.AddSingleton<ObjectPool>();
  25. Game.AddSingleton<IdGenerater>();
  26. Game.AddSingleton<EventSystem>();
  27. Game.AddSingleton<TimerComponent>();
  28. Game.AddSingleton<CoroutineLockComponent>();
  29. ETTask.ExceptionHandler += Log.Error;
  30. Game.AddSingleton<CodeLoader>().Start();
  31. Log.Console($"app start: {Root.Instance.Scene.Id} options: {JsonHelper.ToJson(Options.Instance)} ");
  32. while (true)
  33. {
  34. try
  35. {
  36. Thread.Sleep(1);
  37. Game.Update();
  38. Game.LateUpdate();
  39. Game.FrameFinishUpdate();
  40. }
  41. catch (Exception e)
  42. {
  43. Log.Error(e);
  44. }
  45. }
  46. }
  47. catch (Exception e)
  48. {
  49. Log.Error(e);
  50. }
  51. }
  52. }
  53. }