Пример #1
0
        private void SwitchMode(GameModeScreen screen)
        {
            // Stop runnung Clients
            if (CurrentClient != null)
            {
                // Stop Simulation
                CurrentClient.StopSimulation();

                // Dispose Viewer
                mainPanel.Controls.Remove(Renderer);
                Renderer.Dispose();
                Renderer = null;

                // Dispose Client
                CurrentClient.Dispose();
                CurrentClient = null;
            }

            // Close open Modes
            if (CurrentMode != null)
            {
                // Dispose Mode
                mainPanel.Controls.Remove(CurrentMode);
                CurrentMode.Dispose();
                CurrentMode = null;
            }

            // Create new Mode
            CurrentMode = screen;
            mainPanel.Controls.Add(CurrentMode);
            CurrentMode.Dock = DockStyle.Fill;
        }
Пример #2
0
        private void startToolButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Create Client
                CurrentClient                      = CurrentMode.StartSimulation();
                CurrentClient.OnError             += CurrentClient_OnError;
                CurrentClient.OnSimulationChanged += CurrentClient_OnSimulationChanged;

                // Dispose Mode
                mainPanel.Controls.Remove(CurrentMode);
                CurrentMode.Dispose();
                CurrentMode = null;

                // Start Simulation
                Renderer = new RenderControl();
                mainPanel.Controls.Add(Renderer);
                Renderer.Dock = DockStyle.Fill;
                Renderer.SetSimulation(CurrentClient);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
 private void Simulation_OnSimulationState(ISimulationClient client, LevelState levelState)
 {
     if (currentState == null)
     {
         SetScale(levelState.Map.GetCellCount());
         foreach (var faction in levelState.Factions)
         {
             slotPens[faction.SlotIndex] = itemFactionPens[(int)faction.PlayerColor];
         }
     }
     currentState = levelState;
 }
Пример #4
0
        public void DefaultScenarioSameThreadTest()
        {
            SimulationServer.Start("AntMeTest", SimulationServer.DEFAULTPORT);

            byte[]     file   = File.ReadAllBytes(@".\AntMe.Levelpack.dll");
            LoaderInfo loader = AntMe.Runtime.ExtensionLoader.SecureAnalyseExtension(file, true, true);

            loader.Levels[0].Type.AssemblyFile  = file;
            loader.Players[0].Type.AssemblyFile = file;
            int lastRound = -1;

            // Client 1
            ISimulationClient client1 = SimulationClient.CreateNamedPipe("AntMeTest");

            client1.OnLevelChanged += (c, l) =>
            {
                if (l != null)
                {
                    Task t = new Task(() =>
                    {
                        c.UploadPlayer(loader.Players[0].Type);
                        c.SetPlayerState(0, PlayerColor.Green, 0, true);
                    });
                    t.Start();
                }
            };
            client1.Open("Client 1");

            // Client 2
            ISimulationClient client2 = SimulationClient.CreateNamedPipe("AntMeTest");

            client2.OnPlayerChanged += (c, s) =>
            {
                var slot = c.Slots[s];
                if (slot.ReadyState && slot.PlayerInfo)
                {
                    Task t = new Task(() => { c.StartSimulation(); });
                    t.Start();
                }
            };
            client2.OnSimulationState += (c, s) =>
            {
                lastRound = s.Round;
            };
            client2.Open("Client 2");
            client2.AquireMaster();
            client2.UploadLevel(loader.Levels[0].Type);

            Thread.Sleep(10000);
            Assert.IsTrue(lastRound > 0);

            SimulationServer.Stop();
        }
Пример #5
0
        public void SetSimulation(ISimulationClient client)
        {
            // Unattach old Simulation
            if (simulation != null)
            {
                simulation.OnSimulationState -= Simulation_OnSimulationState;
                simulation   = null;
                currentState = null;
            }

            // Attach new Simulation
            if (client != null)
            {
                simulation = client;
                simulation.OnSimulationState += Simulation_OnSimulationState;
            }
        }
Пример #6
0
        public override ISimulationClient StartSimulation()
        {
            string[] extensionPaths = new string[] {
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Extensions",
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\AntMe\\Extensions"
            };

            ISimulationClient result = SimulationClient.CreateUnsecure(extensionPaths, ExtensionLoader.DefaultTypeResolver);

            result.AquireMaster();
            result.UploadLevel(level.Type);
            for (byte i = 0; i < 8; i++)
            {
                if (slots[i] != null)
                {
                    result.UploadMaster(i, slots[i].Type);
                    result.SetMasterState(i, (PlayerColor)i, i, true);
                }
            }
            result.StartSimulation();
            return(result);
        }
 public void AddClient(ISimulationClient client)
 {
     clients.Add(client.Id, client);
 }
Пример #8
0
        public void SetSimulation(ISimulationClient client)
        {
            // Unattach old Simulation
            if (simulation != null)
            {
                simulation.OnSimulationState -= Simulation_OnSimulationState;
                simulation = null;
                currentState = null;
            }

            // Attach new Simulation
            if (client != null)
            {
                simulation = client;
                simulation.OnSimulationState += Simulation_OnSimulationState;
            }
        }
Пример #9
0
 private void Simulation_OnSimulationState(ISimulationClient client, LevelState levelState)
 {
     if (currentState == null)
     {
         SetScale(levelState.Map.GetCellCount());
         foreach (var faction in levelState.Factions)
             slotPens[faction.SlotIndex] = itemFactionPens[(int)faction.PlayerColor];
     }
     currentState = levelState;
 }
Пример #10
0
 private void CurrentClient_OnError(ISimulationClient client, string message)
 {
     MessageBox.Show(message);
 }
Пример #11
0
 private void CurrentClient_OnSimulationChanged(ISimulationClient client, SimulationState simulationState, byte frames)
 {
     framesToolButton.Text = string.Format("{0} fps", frames);
     // throw new NotImplementedException();
 }