Program.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using CommandLine;
  6. using NLog;
  7. namespace ET
  8. {
  9. internal static class Program
  10. {
  11. private static void Main(string[] args)
  12. {
  13. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  14. {
  15. Log.Error(e.ExceptionObject.ToString());
  16. };
  17. ETTask.ExceptionHandler += Log.Error;
  18. // 异步方法全部会回掉到主线程
  19. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  20. try
  21. {
  22. Game.EventSystem.Add(typeof(Game).Assembly);
  23. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  24. ProtobufHelper.Init();
  25. MongoRegister.Init();
  26. // 命令行参数
  27. Options options = null;
  28. Parser.Default.ParseArguments<Options>(args)
  29. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  30. .WithParsed(o => { options = o; });
  31. Options.Instance = options;
  32. Log.ILog = new NLogger(Game.Options.AppType.ToString());
  33. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  34. Log.Info($"server start........................ {Game.Scene.Id}");
  35. Game.EventSystem.Publish(new EventType.AppStart()).Coroutine();
  36. while (true)
  37. {
  38. try
  39. {
  40. Thread.Sleep(1);
  41. Game.Update();
  42. Game.LateUpdate();
  43. Game.FrameFinish();
  44. }
  45. catch (Exception e)
  46. {
  47. Log.Error(e);
  48. }
  49. }
  50. }
  51. catch (Exception e)
  52. {
  53. Log.Error(e);
  54. }
  55. }
  56. }
  57. }