private static void StopSimulation() { Util.ConnectionToServer.SendSimulationStatus(SimulationRun); //GameTimer = null; //GameThread.Interrupt(); //GameThread.Abort(); DisplayInfo(); Car someItem; while (graph.ListPath.Count > 0) { graph.ListPath.First().RemovePath(); } while (!Cars.IsEmpty) { Cars.TryTake(out someItem); } foreach (var c in Containers) { c.Reset(); } Tools.Message(MessageStatus.Info, Localization.GetText("Text14")); OnSimulationStop?.Invoke(); }
/// <summary> /// Stops the simulation /// </summary> public void Stop() { if (!(GameMode?.AnyRespawn() ?? true)) { return; } OnSimulationStop?.Invoke(); GameMode?.EmitSimulationStop(this); _state = SimulationState.ShuttingDown; }
public void Step() { if (!Simulating) { return; } StepsQueued++; lock (EntitiesBuffer) { _stepTimes.Enqueue(DateTime.UtcNow); // Make array to avoid concurrent modification exception; Make temporary clone to be able to modify the original Entities = EntitiesBuffer.Keys.ToArray(); Parallel.ForEach(Entities, e => e.Step()); float maxVelocity = Entities.Length > 0 ? Entities.Max(e => (e.Velocity.X * e.Velocity.X) + (e.Velocity.Y * e.Velocity.Y)) : 0; StepsFinished++; if (!Entities.All(x => x is Player)) { return; } if (maxVelocity < Config.PhysicalEnvironment.MovementThreshold) { FramesSinceMovementTresholdMet++; } else { FramesSinceMovementTresholdMet = 0; } if (FramesSinceMovementTresholdMet < Config.PhysicalEnvironment.MovementThresholdMinDuration) { return; } Simulating = false; OnSimulationStop?.Invoke(); } }