Init.cs 1.4 KB

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