Init.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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<ObjectPool>();
  24. World.Instance.AddSingleton<WorldActor>();
  25. World.Instance.AddSingleton<CodeLoader>();
  26. World.Instance.AddSingleton<VProcessManager>();
  27. VProcessManager.ThreadPoolScheduler threadPoolScheduler = World.Instance.AddSingleton<VProcessManager.ThreadPoolScheduler>();
  28. threadPoolScheduler.ThreadCount = 10;
  29. int vProcessId = VProcessManager.Instance.Create();
  30. WorldActor.Instance.Send(vProcessId, null);
  31. Log.Console($"{Parser.Default.FormatCommandLine(Options.Instance)}");
  32. }
  33. catch (Exception e)
  34. {
  35. Log.Error(e);
  36. }
  37. }
  38. }
  39. }