Program.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // 异步方法全部会回掉到主线程
  14. SynchronizationContext.SetSynchronizationContext(ThreadSynchronizationContext.Instance);
  15. try
  16. {
  17. Game.EventSystem.Add(typeof(Game).Assembly);
  18. Game.EventSystem.Add(DllHelper.GetHotfixAssembly());
  19. ProtobufHelper.Init();
  20. MongoHelper.Init();
  21. // 命令行参数
  22. Options options = null;
  23. Parser.Default.ParseArguments<Options>(args)
  24. .WithNotParsed(error => throw new Exception($"命令行格式错误!"))
  25. .WithParsed(o => { options = o; });
  26. Game.Options = options;
  27. Game.ILog = new NLogger(Game.Options.AppType.ToString());
  28. LogManager.Configuration.Variables["appIdFormat"] = $"{Game.Options.Process:000000}";
  29. Log.Info($"server start........................ {Game.Scene.Id}");
  30. Game.EventSystem.Publish(new EventType.AppStart());
  31. while (true)
  32. {
  33. try
  34. {
  35. Thread.Sleep(1);
  36. Game.Update();
  37. Game.LateUpdate();
  38. Game.FrameFinish();
  39. }
  40. catch (Exception e)
  41. {
  42. Log.Error(e);
  43. }
  44. }
  45. }
  46. catch (Exception e)
  47. {
  48. Log.Error(e);
  49. }
  50. }
  51. }
  52. }