Init.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using KYFramework;
  2. using KYFramework.Network;
  3. using Timer = KYFramework.Timer;
  4. namespace SimulationServer;
  5. public static class Init
  6. {
  7. public static int SimulationSpeed = 1;
  8. public static void Start()
  9. {
  10. try
  11. {
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Log.Error(e.ExceptionObject.ToString()); };
  13. SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
  14. Game.EventSystem.Add(typeof(Init).Assembly);
  15. Game.EventSystem.Add(typeof(Entity).Assembly);
  16. Game.EventSystem.Add(typeof(NetworkComponent).Assembly);
  17. Logger.Instance.ILog = new NLogger("Client", "./Config/NLog/NLog.config");
  18. Game.Scene.AddComponent<Timer>();
  19. Game.Scene.AddComponent<TimerComponent>();
  20. //Game.Scene.AddComponent<ConfigComponent>();
  21. //UDP
  22. //Game.Scene.AddComponent<MessageDispatcherComponent>();
  23. //TCP
  24. Game.Scene.AddComponent<OpcodeTypeComponent>();
  25. Game.Scene.AddComponent<MessageDispatcherComponent>();
  26. Game.Scene.AddComponent<ServerComponent, string>(File.ReadAllText("Config/ipconfig.txt"));
  27. Game.Scene.AddComponent<SessionComponent>();
  28. // 任务
  29. Game.Scene.AddComponent<TaskComponent>();
  30. Log.Info("服务器启动完成!");
  31. Game.EventSystem.Publish(new ServerStart());
  32. }
  33. catch (Exception e)
  34. {
  35. Console.WriteLine(e);
  36. }
  37. }
  38. public static void Update()
  39. {
  40. OneThreadSynchronizationContext.Instance.Update();
  41. Game.EventSystem.Update();
  42. }
  43. public static void LateUpdate()
  44. {
  45. Game.EventSystem.LateUpdate();
  46. }
  47. public static void OnApplicationQuit()
  48. {
  49. Game.Close();
  50. }
  51. }