diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index ae89d01ed963064eb53e53fbdd02541bde7f1fc4..d13a116fb8e4dfc11928c6c60b826606b9dfe7a8 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -48,8 +48,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl { public class VehicleContainer : LoggingObject, IVehicleContainer { - internal readonly SortedList<int, VectoSimulationComponent> Components = - new SortedList<int, VectoSimulationComponent>(); + private List<Tuple<int, VectoSimulationComponent>> _components = + new List<Tuple<int, VectoSimulationComponent>>(); internal IEngineInfo Engine; internal IGearboxInfo Gearbox; @@ -227,7 +227,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl commitPriority = 3; }); - Components.Add(-commitPriority, component); + _components.Add(Tuple.Create(commitPriority, component)); + _components = _components.OrderBy(x => x.Item1).Reverse().ToList(); } @@ -236,8 +237,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time, ExecutionMode == ExecutionMode.EngineOnly ? null : Distance, VehicleSpeed); - foreach (var component in Components) { - component.Value.CommitSimulationStep(ModData); + foreach (var component in _components) { + component.Item2.CommitSimulationStep(ModData); } if (ModData != null) { @@ -261,7 +262,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl public IReadOnlyCollection<VectoSimulationComponent> SimulationComponents() { - return new ReadOnlyCollection<VectoSimulationComponent>(Components.Select(x => x.Value).ToList()); + return new ReadOnlyCollection<VectoSimulationComponent>(_components.Select(x => x.Item2).ToList()); } public Meter Distance diff --git a/VectoCore/VectoCoreTest/Models/Simulation/FactoryTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/FactoryTest.cs index 8eaad5afbeb6962133942a6e14a92bf70b9090d7..3546a59338edcb4862173be5a444cef9b2f88fd3 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/FactoryTest.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/FactoryTest.cs @@ -60,7 +60,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var run = factory.SimulationRuns().First(); var vehicleContainer = (VehicleContainer)run.GetContainer(); - Assert.AreEqual(11, vehicleContainer.Components.Count); + Assert.AreEqual(11, vehicleContainer.SimulationComponents().Count); Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed"); Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed"); @@ -112,7 +112,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var run = factory.SimulationRuns().First(); var vehicleContainer = (VehicleContainer)run.GetContainer(); - Assert.AreEqual(11, vehicleContainer.Components.Count); + Assert.AreEqual(11, vehicleContainer.SimulationComponents().Count); Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed"); Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed"); diff --git a/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs index 2c7db66943cf61b79853fc346e7bffefe5891bff..767ddfa82f95a085a3788760722927af69167151 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs @@ -65,7 +65,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var powerTrain = builder.Build(runData); Assert.IsInstanceOfType(powerTrain, typeof(IVehicleContainer)); - Assert.AreEqual(11, powerTrain.Components.Count); + Assert.AreEqual(11, powerTrain.SimulationComponents().Count); Assert.IsInstanceOfType(powerTrain.Engine, typeof(CombustionEngine)); Assert.IsInstanceOfType(powerTrain.Gearbox, typeof(Gearbox));