Init.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  20. .WithParsed(World.Instance.AddSingleton);
  21. World.Instance.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  22. ETTask.ExceptionHandler += Log.Error;
  23. World.Instance.AddSingleton<IdValueGenerater>();
  24. World.Instance.AddSingleton<ObjectPool>();
  25. World.Instance.AddSingleton<WorldActor>();
  26. World.Instance.AddSingleton<CodeLoader>();
  27. World.Instance.AddSingleton<VProcessManager>();
  28. VProcessManager.ThreadPoolScheduler threadPoolScheduler = World.Instance.AddSingleton<VProcessManager.ThreadPoolScheduler>();
  29. threadPoolScheduler.ThreadCount = 10;
  30. int vProcessId = VProcessManager.Instance.Create();
  31. WorldActor.Instance.Send(vProcessId, null);
  32. Log.Console($"{Parser.Default.FormatCommandLine(Options.Instance)}");
  33. }
  34. catch (Exception e)
  35. {
  36. Log.Error(e);
  37. }
  38. }
  39. }
  40. }