Skip to content

Commit 15ba46b

Browse files
committed
Add exponential unit override, remove change to dynamic brake display to a future PR
1 parent 6c8095a commit 15ba46b

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,22 @@ Custom Display Units
791791

792792
Due to the wide variety of railroad equipment across the world, Open Rails may not
793793
provide the units of measure needed for a cabview control. In this case, the tokens
794-
`ORTSUnitsScaleFactor` and `ORTSUnitsOffset` can be added to the control block in
795-
the .cvf file to create the units of measure required for the cab view.
796-
797-
- ORTSUnitsScaleFactor ( x ): Multiplies the value shown by the cab view control
798-
by a factor of x, allowing for arbitrary conversion of units of measure. For
799-
example, a cab view control displaying MILES_PER_HOUR with ORTSUnitsScaleFactor ( 1.467 )
800-
would instead display a value equivalent to feet per second.
801-
- ORTSUnitsOffset ( x ): After applying the scale factor, adds x to the value shown
802-
by the cab view control. To subtract from the shown value, set x to a negative number.
794+
`ORTSUnitsExponent`, `ORTSUnitsScaleFactor`, and `ORTSUnitsOffset` can be added
795+
to the control block in the .cvf file to create the units of measure required for
796+
the cab view.
797+
798+
- ORTSUnitsExponent ( x ): Raises the value shown by the cab view control to the
799+
power of x, which may be used to calibrate nonlinear gauges or complete nonlinear
800+
conversions. Fractional and negative values are allowed. For example, an accelerometer
801+
gauge with ORTSUnitsExponent ( 0.5 ) would change the accelerometer to be more sensitive
802+
to small accelerations, but less sensitive to large acceleration. (However, the values
803+
shown would not be in any meaningful units.)
804+
- ORTSUnitsScaleFactor ( y ): After accounting for any exponent, multiplies the value
805+
shown by the cab view control by a factor of y, allowing for arbitrary conversion of
806+
units of measure. For example, a cab view control displaying MILES_PER_HOUR with
807+
ORTSUnitsScaleFactor ( 1.467 ) would instead display a value equivalent to feet per second.
808+
- ORTSUnitsOffset ( z ): After applying the scale factor, adds z to the value shown
809+
by the cab view control. To subtract from the shown value, set z to a negative number.
803810
For example, a cab view control with units of BAR and ORTSUnitsOffset ( 0.987 ) would show
804811
pressure as absolute pressure, rather than gauge pressure.
805812

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public class CabViewControl
470470
public CABViewControlStyles ControlStyle = CABViewControlStyles.NONE;
471471
public CABViewControlUnits Units = CABViewControlUnits.NONE;
472472

473+
public double UnitsExponent = 1.0f;
473474
public float UnitsScale = 1.0f;
474475
public float UnitsOffset;
475476

@@ -690,6 +691,7 @@ public CVCDial(STFReader stf, string basepath)
690691
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
691692
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
692693
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
694+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
693695
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
694696
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
695697
});
@@ -788,6 +790,7 @@ public CVCGauge(STFReader stf, string basepath)
788790
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
789791
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
790792
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
793+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
791794
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
792795
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
793796
});
@@ -932,6 +935,7 @@ public CVCDigital(STFReader stf, string basepath)
932935
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
933936
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
934937
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
938+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
935939
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
936940
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
937941
});
@@ -1190,6 +1194,7 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
11901194
new STFReader.TokenProcessor("ortsnewscreenpage", () => {ParseNewScreen(stf); }),
11911195
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
11921196
new STFReader.TokenProcessor("ortsparameter1", ()=>{ Parameter1 = stf.ReadFloatBlock(STFReader.UNITS.Any, 0); }),
1197+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
11931198
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
11941199
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
11951200
});
@@ -1438,6 +1443,7 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
14381443
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
14391444
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
14401445
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1446+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14411447
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14421448
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14431449
});
@@ -1490,6 +1496,7 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
14901496
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
14911497
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
14921498
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1499+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14931500
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14941501
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
14951502
});
@@ -1533,6 +1540,7 @@ public CVCScreen(STFReader stf, string basepath)
15331540
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
15341541
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
15351542
new STFReader.TokenProcessor("ortscabviewpoint", ()=>{ParseCabViewpoint(stf); }),
1543+
new STFReader.TokenProcessor("ortsunitsexponent", ()=>{ UnitsExponent = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
15361544
new STFReader.TokenProcessor("ortsunitsscalefactor", ()=>{ UnitsScale = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
15371545
new STFReader.TokenProcessor("ortsunitsoffset", ()=>{ UnitsOffset = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
15381546
});

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6133,7 +6133,10 @@ public virtual float GetDataOf(CabViewControl cvc)
61336133
data = Train.EOT.GetDataOf(cvc);
61346134
break;
61356135
}
6136-
6136+
// Don't waste time calculating exponents if one isn't set
6137+
// To avoid potential imaginary numbers, use data's absolute value
6138+
if (cvc.UnitsExponent != 1.0f)
6139+
data = Math.Sign(data)*(float)Math.Pow(Math.Abs(data), cvc.UnitsExponent);
61376140
data = cvc.UnitsOffset + (data * cvc.UnitsScale);
61386141

61396142
return data;

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ public virtual int GetDrawIndex()
21472147
{
21482148
if (Locomotive.CruiseControl != null)
21492149
{
2150-
if (Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority)
2150+
if ((Locomotive.CruiseControl.SpeedRegMode == Simulation.RollingStocks.SubSystems.CruiseControl.SpeedRegulatorMode.Auto && !Locomotive.CruiseControl.DynamicBrakePriority) || Locomotive.DynamicBrakeIntervention > 0)
21512151
{
21522152
index = 0;
21532153
}

0 commit comments

Comments
 (0)