protected override void InitSimulation(int seed, LevelInfo level, PlayerInfo[] players, Slot[] slots) { simulation = new SecureSimulation(extensionPaths); // Settings aufbauen Setup settings = new Setup(); settings.Seed = seed; settings.Level = level.Type; settings.Player = new TypeInfo[AntMe.Level.MAX_SLOTS]; settings.Colors = new PlayerColor[AntMe.Level.MAX_SLOTS]; for (int i = 0; i < AntMe.Level.MAX_SLOTS; i++) { // Farben übertragen settings.Colors[i] = slots[i].ColorKey; // KIs einladen if (players[i] != null) { settings.Player[i] = players[i].Type; } } simulation.Start(settings); }
public void Cleanup() { if (sim != null) { sim.Dispose(); sim = null; } }
private void SimulationLoop() { running = true; Stopwatch watch = new Stopwatch(); watch.Restart(); while (running && simulation != null && simulation.State == Runtime.SimulationState.Running) { // Delay Thread.Sleep(1); // Check for Framerate if (!paused && watch.ElapsedMilliseconds > (1000 / frames)) { watch.Restart(); // TODO: Handle potential Problems var state = simulation.NextState(); SendSimulationState(state); } } // Dispose Simulation if (simulation != null) { simulation.Dispose(); simulation = null; } // Inform everybody SendSimulationChanged(this.frames); // Disconnect Thread simulationThread = null; }
public void Init() { sim = new SecureSimulation(); }
internal void StartSimulation(ISimulationService service) { ClientInfo client; if (clients.TryGetValue(service, out client)) { lock (simulationLock) { if (master != client.UserProfile) throw new InvalidOperationException("You are not the master"); // Check for running Simulations if (simulation != null) throw new InvalidOperationException("There is a running Simulation"); if (levelInfo == null) throw new InvalidOperationException("There is no level set"); Setup settings = new Setup() { Level = levelType }; int count = 0; for (int i = 0; i < Level.MAX_SLOTS; i++) { // Check Player if (slots[i].Profile != null) { count++; // Start Positions if (i > levelInfo.Map.StartPoints.Length) throw new InvalidOperationException("No Startpoint for Slot " + i + " on this map"); // Player File available if (!slots[i].PlayerInfo) throw new InvalidOperationException("Slot " + i + " has no Player File uploaded"); // Ready Flag enabled if (!slots[i].ReadyState) throw new InvalidOperationException("Slot " + i + " is not ready"); // Faction Filter if (levelInfo.FactionFilter.Where(f => f.SlotIndex == i).Count() > 0) { var playerInfo = playerInfos[i]; // TODO: Faction Filter } settings.Colors[i] = slots[i].ColorKey; settings.Teams[i] = slots[i].Team; settings.Player[i] = playerTypes[i]; } } // Min Playercount check if (count < levelInfo.LevelDescription.MinPlayerCount) throw new InvalidOperationException("Not enought player for this Map"); // Max Playercount check if (count > levelInfo.LevelDescription.MaxPlayerCount) throw new InvalidOperationException("Too many player for this Map"); simulation = new SecureSimulation(extensionPaths); simulation.Start(settings); // Start Simulation Loop simulationThread = new Thread(SimulationLoop); simulationThread.IsBackground = true; simulationThread.Priority = ThreadPriority.Lowest; simulationThread.Start(); } // Inform everbody SendSimulationChanged(frames); } else { throw new InvalidOperationException("Client not registered"); } }
protected override void FinalizeSimulation() { simulation.Stop(); simulation.Dispose(); simulation = null; }
internal void StartSimulation(ISimulationService service) { ClientInfo client; if (clients.TryGetValue(service, out client)) { lock (simulationLock) { if (master != client.UserProfile) { throw new InvalidOperationException("You are not the master"); } // Check for running Simulations if (simulation != null) { throw new InvalidOperationException("There is a running Simulation"); } if (levelInfo == null) { throw new InvalidOperationException("There is no level set"); } Setup settings = new Setup() { Level = levelType }; int count = 0; for (int i = 0; i < Level.MAX_SLOTS; i++) { // Check Player if (slots[i].Profile != null) { count++; // Start Positions if (i > levelInfo.Map.StartPoints.Length) { throw new InvalidOperationException("No Startpoint for Slot " + i + " on this map"); } // Player File available if (!slots[i].PlayerInfo) { throw new InvalidOperationException("Slot " + i + " has no Player File uploaded"); } // Ready Flag enabled if (!slots[i].ReadyState) { throw new InvalidOperationException("Slot " + i + " is not ready"); } // Faction Filter if (levelInfo.FactionFilter.Where(f => f.SlotIndex == i).Count() > 0) { var playerInfo = playerInfos[i]; // TODO: Faction Filter } settings.Colors[i] = slots[i].ColorKey; settings.Teams[i] = slots[i].Team; settings.Player[i] = playerTypes[i]; } } // Min Playercount check if (count < levelInfo.LevelDescription.MinPlayerCount) { throw new InvalidOperationException("Not enought player for this Map"); } // Max Playercount check if (count > levelInfo.LevelDescription.MaxPlayerCount) { throw new InvalidOperationException("Too many player for this Map"); } simulation = new SecureSimulation(extensionPaths); simulation.Start(settings); // Start Simulation Loop simulationThread = new Thread(SimulationLoop); simulationThread.IsBackground = true; simulationThread.Priority = ThreadPriority.Lowest; simulationThread.Start(); } // Inform everbody SendSimulationChanged(frames); } else { throw new InvalidOperationException("Client not registered"); } }