Init.cs 1.4 KB

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