Skip to content

Commit 97553e4

Browse files
authored
Merge pull request #508 from Csantucci/odometer-official
Blueprint https://blueprints.launchpad.net/or/+spec/odometer-cabview-controls
2 parents fab59f5 + 21fb5e9 commit 97553e4

File tree

6 files changed

+131
-28
lines changed

6 files changed

+131
-28
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,62 @@ ORTS_SIGNED_TRACTION_BRAKING, with the only difference that the braking
347347
force does include also the train brake force in addition to the dynamic
348348
brake force.
349349

350+
.. _cabs-odometer:
351+
352+
Odometer controls
353+
-----------------
354+
355+
Following cabview controls are available:
356+
357+
358+
- ORTS_ODOMETER: used to digitally display the odometer value
359+
- ORTS_ODOMETER_RESET: used to reset the odometer
360+
- ORTS_ODOMETER_DIRECTION_CHANGE: used to change direction (up/down) of the odometer.
361+
362+
Following units of measure are available for ORTS_ODOMETER:
363+
364+
- KILOMETRES
365+
- METRES
366+
- MILES
367+
- FEET
368+
- YARDS
369+
370+
The operation of the odometer is explained :ref:`here <driving-odometer>`.
371+
372+
Here is an example of use of the odometer control blocks within a .cvf file::
373+
374+
TwoState (
375+
Type ( ORTS_ODOMETER_RESET TWO_STATE )
376+
Position ( 320 70 24 22 )
377+
Graphic ( OdoResetButton.ace )
378+
NumFrames ( 2 2 1 )
379+
Style ( WHILE_PRESSED )
380+
MouseControl ( 1 )
381+
)
382+
TwoState (
383+
Type ( ORTS_ODOMETER_DIRECTION TWO_STATE)
384+
Position ( 320 100 13 15 )
385+
Graphic ( OdoDirectionSwitch.ace )
386+
NumFrames ( 2 2 1 )
387+
Style ( ONOFF )
388+
MouseControl ( 1 )
389+
)
390+
Digital (
391+
Type ( ORTS_ODOMETER DIGITAL)
392+
Position ( 377 100 26 17 )
393+
ScaleRange ( 0 100000 )
394+
Accuracy ( 0 )
395+
AccuracySwitch ( 0 )
396+
LeadingZeros ( 0 )
397+
Justification ( 1 )
398+
PositiveColour ( 1
399+
ControlColour ( 255 255 255 )
400+
)
401+
NegativeColour ( 0 )
402+
DecreaseColour ( 0 )
403+
Units ( FEET )
404+
)
405+
350406
Animated 2D Wipers
351407
------------------
352408

Source/Documentation/Manual/driving.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ camera's direction together with its latitude and longitude.
564564
To activate the compass window press the ``<0>`` key. To deactivate the
565565
compass window, press the ``<0>`` key a second time.
566566

567+
.. _driving-odometer:
567568

568569
Odometer
569570
--------
@@ -583,6 +584,9 @@ as the front of the train passes a location, then when it reaches zero you
583584
will know, without switching views, that the other end of the train has
584585
just reached the same point, e.g. the entrance to a siding, etc.
585586

587+
The odometer can be accessed also through cabview controls, if they are defined
588+
within the cabview, see :ref:`here <cabs-odometer>`.
589+
586590

587591
.. |uarr| unicode:: U+02191 .. UPWARDS ARROW
588592
.. |darr| unicode:: U+02193 .. DOWNWARDS ARROW

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ public enum CABViewControlTypes
253253
ORTS_TCS47,
254254
ORTS_TCS48,
255255
ORTS_ETCS,
256+
ORTS_ODOMETER,
257+
ORTS_ODOMETER_RESET,
258+
ORTS_ODOMETER_DIRECTION,
256259

257260
// Further CabViewControlTypes must be added above this line, to avoid their malfunction in 3DCabs
258261
EXTERNALWIPERS,
@@ -310,7 +313,13 @@ public enum CABViewControlUnits
310313
INCHES_OF_MERCURY,
311314
MILI_AMPS,
312315
RPM,
313-
LBS
316+
LBS,
317+
318+
KILOMETRES,
319+
METRES,
320+
MILES,
321+
FEET,
322+
YARDS
314323
}
315324

316325
public enum DiscreteStates

Source/Orts.Simulation/Common/Commands.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,6 @@ public ToggleOdometerCommand(CommandLog log)
15981598
public override void Redo()
15991599
{
16001600
Receiver.OdometerToggle();
1601-
// Report();
16021601
}
16031602

16041603
public override string ToString()
@@ -1608,20 +1607,19 @@ public override string ToString()
16081607
}
16091608

16101609
[Serializable()]
1611-
public sealed class ResetOdometerCommand : Command
1610+
public sealed class ResetOdometerCommand : BooleanCommand
16121611
{
16131612
public static MSTSLocomotive Receiver { get; set; }
16141613

1615-
public ResetOdometerCommand(CommandLog log)
1616-
: base(log)
1614+
public ResetOdometerCommand(CommandLog log, bool toState)
1615+
: base(log, toState)
16171616
{
16181617
Redo();
16191618
}
16201619

16211620
public override void Redo()
16221621
{
1623-
Receiver.OdometerReset();
1624-
// Report();
1622+
Receiver.OdometerReset(ToState);
16251623
}
16261624

16271625
public override string ToString()
@@ -1644,7 +1642,6 @@ public ToggleOdometerDirectionCommand(CommandLog log)
16441642
public override void Redo()
16451643
{
16461644
Receiver.OdometerToggleDirection();
1647-
// Report();
16481645
}
16491646

16501647
public override string ToString()

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

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public bool LargeEjectorSoundOn
313313
protected float OdometerResetPositionM = 0;
314314
protected bool OdometerCountingUp = true;
315315
protected bool OdometerCountingForwards = true;
316+
public bool OdometerResetButtonPressed = false;
316317

317318
public bool OdometerVisible { get; private set; }
318319
public float OdometerM
@@ -4059,32 +4060,35 @@ public void OdometerToggle()
40594060
/// Set odometer reference distance to actual travelled distance,
40604061
/// and set measuring direction to the actual direction
40614062
/// </summary>
4062-
public void OdometerReset()
4063+
public void OdometerReset(bool toState)
40634064
{
40644065
if (Train == null)
40654066
return;
4066-
4067-
if (OdometerCountingForwards != OdometerCountingUp ^ (Direction == Direction.Reverse))
4067+
if (toState)
40684068
{
4069-
OdometerCountingForwards = !OdometerCountingForwards;
4070-
}
4069+
if (OdometerCountingForwards != OdometerCountingUp ^ (Direction == Direction.Reverse))
4070+
{
4071+
OdometerCountingForwards = !OdometerCountingForwards;
4072+
}
40714073

4072-
if (Direction == Direction.Reverse)
4073-
{
4074-
if (OdometerCountingForwards)
4075-
OdometerResetPositionM = Train.DistanceTravelledM - Train.Length;
4076-
else
4077-
OdometerResetPositionM = Train.DistanceTravelledM;
4078-
}
4079-
else
4080-
{
4081-
if (OdometerCountingForwards)
4082-
OdometerResetPositionM = Train.DistanceTravelledM;
4074+
if (Direction == Direction.Reverse)
4075+
{
4076+
if (OdometerCountingForwards)
4077+
OdometerResetPositionM = Train.DistanceTravelledM - Train.Length;
4078+
else
4079+
OdometerResetPositionM = Train.DistanceTravelledM;
4080+
}
40834081
else
4084-
OdometerResetPositionM = Train.DistanceTravelledM + Train.Length;
4085-
}
4082+
{
4083+
if (OdometerCountingForwards)
4084+
OdometerResetPositionM = Train.DistanceTravelledM;
4085+
else
4086+
OdometerResetPositionM = Train.DistanceTravelledM + Train.Length;
4087+
}
40864088

4087-
Simulator.Confirmer.Confirm(CabControl.Odometer, CabSetting.On);
4089+
Simulator.Confirmer.Confirm(CabControl.Odometer, CabSetting.On);
4090+
}
4091+
OdometerResetButtonPressed = toState;
40884092
}
40894093

40904094
public void OdometerToggleDirection()
@@ -5077,6 +5081,34 @@ public virtual float GetDataOf(CabViewControl cvc)
50775081
data = LocomotivePowerSupply.ElectricTrainSupplyOn ? 1 : 0;
50785082
break;
50795083

5084+
case CABViewControlTypes.ORTS_ODOMETER:
5085+
switch (cvc.Units)
5086+
{
5087+
case CABViewControlUnits.KILOMETRES:
5088+
data = (float)Me.ToKiloM(OdometerM);
5089+
break;
5090+
case CABViewControlUnits.MILES:
5091+
data = (float)Me.ToMi(OdometerM);
5092+
break;
5093+
case CABViewControlUnits.FEET:
5094+
data = (float)Me.ToFt(OdometerM);
5095+
break;
5096+
case CABViewControlUnits.YARDS:
5097+
data = (float)Me.ToYd(OdometerM);
5098+
break;
5099+
case CABViewControlUnits.METRES:
5100+
default:
5101+
data = OdometerM;
5102+
break;
5103+
}
5104+
break;
5105+
case CABViewControlTypes.ORTS_ODOMETER_DIRECTION:
5106+
data = OdometerCountingUp ? 1 : 0;
5107+
break;
5108+
case CABViewControlTypes.ORTS_ODOMETER_RESET:
5109+
data = OdometerResetButtonPressed ? 1 : 0;
5110+
break;
5111+
50805112
default:
50815113
{
50825114
data = 0;

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public override void InitializeUserInputCommands()
176176
UserInputCommands.Add(UserCommand.ControlImmediateRefill, new Action[] { () => StopImmediateRefilling(Viewer.Log), () => ImmediateRefill() });
177177
UserInputCommands.Add(UserCommand.ControlWaterScoop, new Action[] { Noop, () => new ToggleWaterScoopCommand(Viewer.Log) });
178178
UserInputCommands.Add(UserCommand.ControlOdoMeterShowHide, new Action[] { Noop, () => new ToggleOdometerCommand(Viewer.Log) });
179-
UserInputCommands.Add(UserCommand.ControlOdoMeterReset, new Action[] { Noop, () => new ResetOdometerCommand(Viewer.Log) });
179+
UserInputCommands.Add(UserCommand.ControlOdoMeterReset, new Action[] { () => new ResetOdometerCommand(Viewer.Log, false), () => new ResetOdometerCommand(Viewer.Log, true) });
180180
UserInputCommands.Add(UserCommand.ControlOdoMeterDirection, new Action[] { Noop, () => new ToggleOdometerDirectionCommand(Viewer.Log) });
181181
UserInputCommands.Add(UserCommand.ControlCabRadio, new Action[] { Noop, () => new CabRadioCommand(Viewer.Log, !Locomotive.CabRadioOn) });
182182
UserInputCommands.Add(UserCommand.ControlDieselHelper, new Action[] { Noop, () => new ToggleHelpersEngineCommand(Viewer.Log) });
@@ -2041,6 +2041,8 @@ public int GetDrawIndex()
20412041
case CABViewControlTypes.ORTS_SERVICE_RETENTION_CANCELLATION_BUTTON:
20422042
case CABViewControlTypes.ORTS_ELECTRIC_TRAIN_SUPPLY_COMMAND_SWITCH:
20432043
case CABViewControlTypes.ORTS_ELECTRIC_TRAIN_SUPPLY_ON:
2044+
case CABViewControlTypes.ORTS_ODOMETER_DIRECTION:
2045+
case CABViewControlTypes.ORTS_ODOMETER_RESET:
20442046
index = (int)data;
20452047
break;
20462048

@@ -2284,6 +2286,9 @@ public void HandleUserInput()
22842286
case CABViewControlTypes.ORTS_ELECTRIC_TRAIN_SUPPLY_COMMAND_SWITCH:
22852287
new ElectricTrainSupplyCommand(Viewer.Log, ChangedValue(Locomotive.LocomotivePowerSupply.ElectricTrainSupplySwitch.CommandSwitch ? 1 : 0) > 0);
22862288
break;
2289+
case CABViewControlTypes.ORTS_ODOMETER_DIRECTION: if (ChangedValue(1) == 0) new ToggleOdometerDirectionCommand(Viewer.Log); break;
2290+
case CABViewControlTypes.ORTS_ODOMETER_RESET:
2291+
new ResetOdometerCommand(Viewer.Log, ChangedValue(Locomotive.OdometerResetButtonPressed ? 1 : 0) > 0); break;
22872292

22882293
// Train Control System controls
22892294
case CABViewControlTypes.ORTS_TCS1:

0 commit comments

Comments
 (0)