/// <summary> /// Start the server and be ready to manage the bots. /// </summary> /// <param name="port">The port that the manager listens to for the Python clients.</param> public void Start(int port) { CommandServer = new BotCommandServer(); CommandServer.EnvironmentInitializedEvent += eventArgs => GameInterface.Start(eventArgs.DllDirectory); CommandServer.AddBotEvent += eventArgs => AddBot(eventArgs.Name, eventArgs.Team, eventArgs.PlayerIndex); CommandServer.RemoveBotEvent += eventArgs => RemoveBot(eventArgs.PlayerIndex); CommandServer.Start(port); // Ensure best available resolution before starting the main loop to reduce CPU usage TimerResolutionInterop.Query(out int minRes, out _, out int currRes); if (currRes > minRes) { TimerResolutionInterop.SetResolution(minRes); } MainBotLoop(); }
/// <summary> /// Start the server and be ready to manage the bots. /// </summary> /// <param name="port">The port that the manager listens to for the Python clients.</param> public void Start(int port) { BotManagerServer server = new BotManagerServer(); server.BotReceivedEvent += OnBotReceived; serverThread = new Thread(() => server.Start(port)); serverThread.Start(); // Don't start main loop until botProcesses has at least 1 bot while (botProcesses.Count == 0) { Thread.Sleep(16); } // Ensure best available resolution before starting the main loop to reduce CPU usage TimerResolutionInterop.Query(out int minRes, out _, out int currRes); if (currRes > minRes) { TimerResolutionInterop.SetResolution(minRes); } MainBotLoop(); }