Program.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Threading;
  5. using CommandLine;
  6. using MongoDB.Bson;
  7. using NLog;
  8. namespace ET
  9. {
  10. internal static class Program
  11. {
  12. private static void Main(string[] args)
  13. {
  14. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  15. {
  16. Log.Error(e.ExceptionObject.ToString());
  17. };
  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. }