int LEDSpeed = -1; // speed in tenths displayed on RailDriver LED /// <summary> /// Updates speed display on RailDriver LED /// </summary> /// <param name="playerLoco"></param> public void Update(TrainCar playerLoco) { if (!Active || playerLoco == null || Device == null) { return; } float speed = 10 * MpS.FromMpS(playerLoco.SpeedMpS, false); int s = (int)(speed >= 0 ? speed + .5 : -speed + .5); if (s != LEDSpeed) { if (s < 100) { SetLEDs(LEDDigits[s % 10], LEDDigitsPoint[s / 10], 0); } else if (s < 1000) { SetLEDs(LEDDigits[s % 10], LEDDigitsPoint[(s / 10) % 10], LEDDigits[(s / 100) % 10]); } else if (s < 10000) { SetLEDs(LEDDigitsPoint[(s / 10) % 10], LEDDigits[(s / 100) % 10], LEDDigits[(s / 1000) % 10]); } LEDSpeed = s; } }
void RecordSteamPerformance() { MSTSSteamLocomotive steamloco = (MSTSSteamLocomotive)Viewer.PlayerLocomotive; float SteamspeedMpH = MpS.ToMpH(steamloco.SpeedMpS); if (SteamspeedMpH >= previousLoggedSteamSpeedMpH + 5) // Add a new record every time speed increases by 5 mph { previousLoggedSteamSpeedMpH = (float)(int)SteamspeedMpH; // Keep speed records close to whole numbers Logger.Data(MpS.FromMpS(Viewer.PlayerLocomotive.SpeedMpS, false).ToString("F0")); Logger.Data(S.ToM(steamloco.SteamPerformanceTimeS).ToString("F1")); Logger.Data(Viewer.PlayerLocomotive.ThrottlePercent.ToString("F0")); Logger.Data(Viewer.PlayerTrain.MUReverserPercent.ToString("F0")); Logger.Data(N.ToLbf(Viewer.PlayerLocomotive.MotiveForceN).ToString("F0")); Logger.Data(steamloco.IndicatedHorsePowerHP.ToString("F0")); Logger.Data(steamloco.DrawBarPullLbsF.ToString("F0")); Logger.Data(steamloco.DrawbarHorsePowerHP.ToString("F0")); Logger.Data(N.ToLbf(steamloco.LocomotiveCouplerForceN).ToString("F0")); Logger.Data(N.ToLbf(steamloco.LocoTenderFrictionForceN).ToString("F0")); Logger.Data(N.ToLbf(steamloco.TotalFrictionForceN).ToString("F0")); Logger.Data(Kg.ToTUK(steamloco.TrainLoadKg).ToString("F0")); Logger.Data(steamloco.BoilerPressurePSI.ToString("F0")); Logger.Data(steamloco.LogSteamChestPressurePSI.ToString("F0")); Logger.Data(steamloco.LogInitialPressurePSI.ToString("F0")); Logger.Data(steamloco.LogCutoffPressurePSI.ToString("F0")); Logger.Data(steamloco.LogReleasePressurePSI.ToString("F0")); Logger.Data(steamloco.LogBackPressurePSI.ToString("F0")); Logger.Data(steamloco.MeanEffectivePressurePSI.ToString("F0")); Logger.Data(steamloco.CurrentSuperheatTempF.ToString("F0")); Logger.Data(pS.TopH(steamloco.CylinderSteamUsageLBpS).ToString("F0")); Logger.Data(pS.TopH(steamloco.WaterConsumptionLbpS).ToString("F0")); Logger.Data(Kg.ToLb(pS.TopH(steamloco.FuelBurnRateSmoothedKGpS)).ToString("F0")); Logger.Data(steamloco.SuperheaterSteamUsageFactor.ToString("F2")); Logger.Data(steamloco.CumulativeCylinderSteamConsumptionLbs.ToString("F0")); Logger.Data(steamloco.CumulativeWaterConsumptionLbs.ToString("F0")); Logger.Data(steamloco.CutoffPressureDropRatio.ToString("F2")); Logger.Data(steamloco.HPCylinderMEPPSI.ToString("F0")); Logger.Data(steamloco.LogLPInitialPressurePSI.ToString("F0")); Logger.Data(steamloco.LogLPCutoffPressurePSI.ToString("F0")); Logger.Data(steamloco.LogLPReleasePressurePSI.ToString("F0")); Logger.Data(steamloco.LogLPBackPressurePSI.ToString("F0")); Logger.Data(steamloco.CutoffPressureDropRatio.ToString("F2")); Logger.Data(steamloco.LPCylinderMEPPSI.ToString("F0")); Logger.End(); } }
public static void MultiUnitConversions() { Assert.Equal(1.2f, MpS.FromMpS(MpS.FromKpH(1.2f), true), RequestedAccuracy); Assert.Equal(1.2f, MpS.FromMpS(MpS.FromMpH(1.2f), false), RequestedAccuracy); Assert.Equal(1.2f, MpS.ToMpS(MpS.ToKpH(1.2f), true), RequestedAccuracy); Assert.Equal(1.2f, MpS.ToMpS(MpS.ToMpH(1.2f), false), RequestedAccuracy); Assert.Equal(1.2f, KPa.FromKPa(1.2f, PressureUnit.KPa), RequestedAccuracy); Assert.Equal(1.2f, KPa.FromBar(KPa.FromKPa(1.2f, PressureUnit.Bar)), RequestedAccuracy); Assert.Equal(1.2f, KPa.FromInHg(KPa.FromKPa(1.2f, PressureUnit.InHg)), RequestedAccuracy); Assert.Equal(1.2f, KPa.FromKgfpCm2(KPa.FromKPa(1.2f, PressureUnit.KgfpCm2)), RequestedAccuracy); Assert.Equal(1.2f, KPa.FromPSI(KPa.FromKPa(1.2f, PressureUnit.PSI)), RequestedAccuracy); Assert.Throws <ArgumentOutOfRangeException>(() => KPa.FromKPa(1.2f, PressureUnit.None)); Assert.Equal(1.2f, KPa.ToKPa(1.2f, PressureUnit.KPa), RequestedAccuracy); Assert.Equal(1.2f, KPa.ToBar(KPa.ToKPa(1.2f, PressureUnit.Bar)), RequestedAccuracy); Assert.Equal(1.2f, KPa.ToInHg(KPa.ToKPa(1.2f, PressureUnit.InHg)), RequestedAccuracy); Assert.Equal(1.2f, KPa.ToKgfpCm2(KPa.ToKPa(1.2f, PressureUnit.KgfpCm2)), RequestedAccuracy); Assert.Equal(1.2f, KPa.ToPSI(KPa.ToKPa(1.2f, PressureUnit.PSI)), RequestedAccuracy); Assert.Throws <ArgumentOutOfRangeException>(() => KPa.ToKPa(1.2f, PressureUnit.None)); }
public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) { FrameNumber++; if (Viewer.RealTime - LastUpdateRealTime >= 0.25) { double elapsedRealSeconds = Viewer.RealTime - LastUpdateRealTime; LastUpdateRealTime = Viewer.RealTime; Profile(elapsedRealSeconds); } #if DEBUG_DUMP_STEAM_POWER_CURVE if (IsRecordingSteamPowerCurve) { RecordSteamPowerCurve(); } else { #endif if (IsRecordingSteamPerformance) { RecordSteamPerformance(); } else //Here's where the logger stores the data from each frame if (Viewer.Settings.DataLogger) { Logger.Separator = (DataLogger.Separators)Enum.Parse(typeof(DataLogger.Separators), Viewer.Settings.DataLoggerSeparator); if (Viewer.Settings.DataLogPerformance) { Logger.Data(VersionInfo.Version); Logger.Data(FrameNumber.ToString("F0")); Logger.Data(GetWorkingSetSize().ToString("F0")); Logger.Data(GC.GetTotalMemory(false).ToString("F0")); Logger.Data(GC.CollectionCount(0).ToString("F0")); Logger.Data(GC.CollectionCount(1).ToString("F0")); Logger.Data(GC.CollectionCount(2).ToString("F0")); Logger.Data(ProcessorCount.ToString("F0")); Logger.Data(Viewer.RenderProcess.FrameRate.Value.ToString("F0")); Logger.Data(Viewer.RenderProcess.FrameTime.Value.ToString("F6")); Logger.Data(Viewer.RenderProcess.ShadowPrimitivePerFrame.Sum().ToString("F0")); Logger.Data(Viewer.RenderProcess.PrimitivePerFrame.Sum().ToString("F0")); Logger.Data(Viewer.RenderProcess.Profiler.Wall.Value.ToString("F0")); Logger.Data(Viewer.UpdaterProcess.Profiler.Wall.Value.ToString("F0")); Logger.Data(Viewer.LoaderProcess.Profiler.Wall.Value.ToString("F0")); Logger.Data(Viewer.SoundProcess.Profiler.Wall.Value.ToString("F0")); } if (Viewer.Settings.DataLogPhysics) { Logger.Data(FormatStrings.FormatPreciseTime(Viewer.Simulator.ClockTime)); Logger.Data(Viewer.PlayerLocomotive.Direction.ToString()); Logger.Data(Viewer.PlayerTrain.MUReverserPercent.ToString("F0")); Logger.Data(Viewer.PlayerLocomotive.ThrottlePercent.ToString("F0")); Logger.Data(Viewer.PlayerLocomotive.MotiveForceN.ToString("F0")); Logger.Data(Viewer.PlayerLocomotive.BrakeForceN.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).LocomotiveAxle.AxleForceN.ToString("F2")); Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).LocomotiveAxle.SlipSpeedPercent.ToString("F1")); switch (Viewer.Settings.DataLogSpeedUnits) { case "route": Logger.Data(FormatStrings.FormatSpeed(Viewer.PlayerLocomotive.SpeedMpS, Viewer.MilepostUnitsMetric)); break; case "mps": Logger.Data(Viewer.PlayerLocomotive.SpeedMpS.ToString("F1")); break; case "mph": Logger.Data(MpS.FromMpS(Viewer.PlayerLocomotive.SpeedMpS, false).ToString("F1")); break; case "kmph": Logger.Data(MpS.FromMpS(Viewer.PlayerLocomotive.SpeedMpS, true).ToString("F1")); break; default: Logger.Data(FormatStrings.FormatSpeed(Viewer.PlayerLocomotive.SpeedMpS, Viewer.MilepostUnitsMetric)); break; } Logger.Data((Viewer.PlayerLocomotive.DistanceM.ToString("F0"))); Logger.Data((Viewer.PlayerLocomotive.GravityForceN.ToString("F0"))); if ((Viewer.PlayerLocomotive as MSTSLocomotive).TrainBrakeController != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).TrainBrakeController.CurrentValue.ToString("F2")); } else { Logger.Data("null"); } if ((Viewer.PlayerLocomotive as MSTSLocomotive).EngineBrakeController != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).EngineBrakeController.CurrentValue.ToString("F2")); } else { Logger.Data("null"); } Logger.Data(Viewer.PlayerLocomotive.BrakeSystem.GetCylPressurePSI().ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).MainResPressurePSI.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSLocomotive).CompressorIsOn.ToString()); #if GEARBOX_DEBUG_LOG if (Viewer.PlayerLocomotive.GetType() == typeof(MSTSDieselLocomotive)) { Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].RealRPM.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].DemandedRPM.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].LoadPercent.ToString("F0")); if ((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines.HasGearBox) { Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].GearBox.CurrentGearIndex.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].GearBox.NextGearIndex.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselEngines[0].GearBox.ClutchPercent.ToString()); } else { Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); } Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselFlowLps.ToString("F2")); Logger.Data((Viewer.PlayerLocomotive as MSTSDieselLocomotive).DieselLevelL.ToString("F0")); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); } if (Viewer.PlayerLocomotive.GetType() == typeof(MSTSElectricLocomotive)) { Logger.Data((Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs[1].CommandUp.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs[2].CommandUp.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs.List.Count > 2 ? (Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs[3].CommandUp.ToString() : null); Logger.Data((Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs.List.Count > 3 ? (Viewer.PlayerLocomotive as MSTSElectricLocomotive).Pantographs[4].CommandUp.ToString() : null); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); Logger.Data("null"); } if (Viewer.PlayerLocomotive.GetType() == typeof(MSTSSteamLocomotive)) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).BlowerSteamUsageLBpS.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).BoilerPressurePSI.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).CylinderCocksAreOpen.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).CylinderCompoundOn.ToString()); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).EvaporationLBpS.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).FireMassKG.ToString("F0")); Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).CylinderSteamUsageLBpS.ToString("F0")); if ((Viewer.PlayerLocomotive as MSTSSteamLocomotive).BlowerController != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).BlowerController.CurrentValue.ToString("F0")); } else { Logger.Data("null"); } if ((Viewer.PlayerLocomotive as MSTSSteamLocomotive).DamperController != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).DamperController.CurrentValue.ToString("F0")); } else { Logger.Data("null"); } if ((Viewer.PlayerLocomotive as MSTSSteamLocomotive).FiringRateController != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).FiringRateController.CurrentValue.ToString("F0")); } else { Logger.Data("null"); } if ((Viewer.PlayerLocomotive as MSTSSteamLocomotive).Injector1Controller != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).Injector1Controller.CurrentValue.ToString("F0")); } else { Logger.Data("null"); } if ((Viewer.PlayerLocomotive as MSTSSteamLocomotive).Injector2Controller != null) { Logger.Data((Viewer.PlayerLocomotive as MSTSSteamLocomotive).Injector2Controller.CurrentValue.ToString("F0")); } else { Logger.Data("null"); } } #endif } Logger.End(); #if DEBUG_DUMP_STEAM_POWER_CURVE } #endif } }