Program.cs 1.6 KB

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