Skip to content

Commit 5f7e609

Browse files
authored
Merge pull request #841 from Csantucci/animate-trainset-windows
https://blueprints.launchpad.net/or/+spec/animating-trainset-windows
2 parents 2be1faa + ce3bc1f commit 5f7e609

File tree

18 files changed

+527
-25
lines changed

18 files changed

+527
-25
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ and the mirrors.
819819
The control blocks are like the one shown for the cab light. The Type strings
820820
are ORTS_LEFTDOOR, ORTS_RIGHTDOOR and ORTS_MIRRORS.
821821

822+
Animation for 2D cab windows is described :ref:`here <features-windows>` .
823+
822824
.. _cabs-generic-items:
823825

824826
Cab controls for generic items
@@ -1025,6 +1027,7 @@ Rotation may be applied, with the same syntax, also to DigitalClock cab controls
10251027

10261028
Display and animation of cabview controls in side views of 2D cabs
10271029
------------------------------------------------------------------
1030+
.. _cabs-side-views:
10281031

10291032
This is possible adding after the CabViewControls ( ) compound block an
10301033
ORTSCabviewControls ( ) compound block, that has the same format as the
@@ -1211,6 +1214,7 @@ Development Rules
12111214
font. If no ace is specified, the default will be used.
12121215
- Mirrors and doors can be operated from 3D cabs. The names used are
12131216
``LEFTDOOR``, ``RIGHTDOOR`` and ``MIRRORS``.
1217+
- Animation for 3D cab windows is described :ref:`here <features-windows>` .
12141218
- like the 2D cabs, also 3D cabs can have a night version. Night textures, named like the
12151219
corresponding day textures, must be located within a ``NIGHT`` subfolder of the
12161220
``CABVIEW3D`` folder. To enable night cabs an ``.sd`` file with the same name as the

Source/Documentation/Manual/driving.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,10 +1091,24 @@ More information on connecting brakes and manipulating the brake hose
10911091
connections can be found :ref:`here <physics-hud-brake>` and
10921092
:ref:`here <driving-car-operations>`.
10931093

1094-
Doors and Mirror Commands
1095-
-------------------------
1096-
1097-
Note that the standard keys in OR for these commands are different from
1094+
Doors, Mirror and Windows Commands
1095+
----------------------------------
1096+
.. _driving-anim-commands:
1097+
1098+
Note that these commands are active only if the trainset is equipped with
1099+
the related animations.
1100+
1101+
=================== =====================================
1102+
Command Function
1103+
=================== =====================================
1104+
``<Q>`` Door left open/close
1105+
``<Shift+Q>`` Door right open/close
1106+
``<Shift+V>`` Mirror rotate clock/counterclockwise
1107+
``<Ctrl+Q>`` Window left open/close
1108+
``<Ctrl+Shift+Q>`` Window right open/close
1109+
=================== =====================================
1110+
1111+
Note that the standard keys for doors and mirror in OR are different from
10981112
those of MSTS.
10991113

11001114
Wheelslip Reset

Source/Documentation/Manual/features-rollingstock.rst

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,181 @@ ENG or WAG file::
12341234
)
12351235

12361236

1237+
.. _features-windows:
1238+
1239+
Trainset windows
1240+
================
1241+
1242+
1243+
Left and right 2D- or 3D-cab windows can be animated, showing the animation both in cabview and in
1244+
external views. For locomotives also two windows for the rear cab can be defined.
1245+
1246+
The external sounds and the track sound are reproduced unattenuated with open window.
1247+
To have a volume difference, two lines as follows must be added to the wagon section of the .eng or .wag file::
1248+
1249+
ORTSExternalSoundPassedThroughPercent ( 30 )
1250+
ORTSTrackSoundPassedThroughPercent ( 25 )
1251+
1252+
Numbers in parenthesis may vary from 0 (no sound heard internally) to 100 (sound heard unattenuated).
1253+
Note that, if these two lines aren't added, but audio option "% of external sound heard internally" is set
1254+
to a value lower than 100, the above effect will be still available with external sounds, but not with
1255+
the track sound.
1256+
1257+
Keyboard commands to toggle window state are listed :ref:`here <driving-anim-commands>` .
1258+
1259+
Names of the animations are as follows.
1260+
1261+
Names for the windows animations as seen from the external camera views (the ones to be inserted in the .s
1262+
file of the trainset) must start with following strings::
1263+
1264+
LEFTWINDOWFRONT
1265+
RIGHTWINDOWFRONT
1266+
LEFTWINDOWREAR
1267+
RIGHTWINDOWREAR
1268+
1269+
In case of carriages, only the first two apply.
1270+
1271+
Names for the windows animations as seen from within a 2D cab (same names are valid for
1272+
front and rear cab); left and right are considered as seen from the related cab::
1273+
1274+
ORTS_2DEXTERNALLEFTWINDOW
1275+
ORTS_2DEXTERNALRIGHTTWINDOW
1276+
1277+
Note that in general the lateral windows will be located in the side views of the 2D cab.
1278+
Therefore the related control blocks in the .cvf file will have to be located as described
1279+
:ref:`here <cabs-side-views>` .
1280+
1281+
Names for the window animations as seen from within a 3D cab (the ones to be inserted in the .s
1282+
file of the 3D cab); Left and right are considered
1283+
as seen in the forward direction of the first cab. The convention difference between 2D and
1284+
3D cabs is due to the difference in the handling of the cabs. NOTE: these 4 controls are not
1285+
needed in the .cvf file (same applies also for wipers, doors and so on as seen from within a
1286+
3D cab)::
1287+
1288+
ORTS_EXTERNALLEFTWINDOWFRONT
1289+
ORTS_EXTERNALRIGHTWINDOWFRONT
1290+
ORTS_EXTERNALLEFTWINDOWREAR
1291+
ORTS_EXTERNALRIGHTWINDOWREAR
1292+
1293+
LEFTWINDOW and RIGHTWINDOW are the names of the controls that can be inserted in the
1294+
.cvf file and in the 3Dcab .s file to command the state change with the mouse.
1295+
1296+
Here is an example of the animation of the left window in a 2D cab::
1297+
1298+
ORTSCabViewControls
1299+
( 1
1300+
ORTSAnimatedDisplay (
1301+
Type ( ORTS_2DEXTERNALLEFTWINDOW MULTI_STATE_DISPLAY )
1302+
Position ( 101 69 235 365 )
1303+
Graphic ( ../../Common.Cab/CabE464/FinestraSX.ace )
1304+
ORTSCycleTime ( 0.6 )
1305+
States ( 16 4 4
1306+
State (
1307+
Style ( 0 )
1308+
SwitchVal ( 0 )
1309+
)
1310+
State (
1311+
Style ( 0 )
1312+
SwitchVal ( 0.0625 )
1313+
)
1314+
State (
1315+
Style ( 0 )
1316+
SwitchVal ( 0.125 )
1317+
)
1318+
State (
1319+
Style ( 0 )
1320+
SwitchVal ( 0.1875 )
1321+
)
1322+
State (
1323+
Style ( 0 )
1324+
SwitchVal ( 0.25 )
1325+
)
1326+
State (
1327+
Style ( 0 )
1328+
SwitchVal ( 0.3125 )
1329+
)
1330+
State (
1331+
Style ( 0 )
1332+
SwitchVal ( 0.375 )
1333+
)
1334+
State (
1335+
Style ( 0 )
1336+
SwitchVal ( 0.4375 )
1337+
)
1338+
State (
1339+
Style ( 0 )
1340+
SwitchVal ( 0.5 )
1341+
)
1342+
State (
1343+
Style ( 0 )
1344+
SwitchVal ( 0.5625 )
1345+
)
1346+
State (
1347+
Style ( 0 )
1348+
SwitchVal ( 0.625 )
1349+
)
1350+
State (
1351+
Style ( 0 )
1352+
SwitchVal ( 0.6875 )
1353+
)
1354+
State (
1355+
Style ( 0 )
1356+
SwitchVal ( 0.75 )
1357+
)
1358+
State (
1359+
Style ( 0 )
1360+
SwitchVal ( 0.825 )
1361+
)
1362+
State (
1363+
Style ( 0 )
1364+
SwitchVal ( 0.88 )
1365+
)
1366+
State (
1367+
Style ( 0 )
1368+
SwitchVal ( 0.94 )
1369+
)
1370+
)
1371+
ORTSCabviewpoint ( 1 )
1372+
)
1373+
)
1374+
1375+
FinestraSX.ace contains the various frames, from window fully close to window fully open.
1376+
ORTSCycleTime means that the opening/closing time of the window is 0.6 seconds. If one wants to use higher times,
1377+
more frames are needed to get a smooth animation. Note that, as explained above,
1378+
the control is within the ORTSCabviewControls block, which is skipped by MSTS and older OR versions to avoid
1379+
error messages, and note that the ORTSCabviewpoint ( 1 ) line specifies that that animation is in the left cabview.
1380+
1381+
A simple control block to move a window by clicking the mouse can be as follows::
1382+
1383+
TwoState (
1384+
Type ( ORTS_LEFTWINDOW TWO_STATE )
1385+
Position ( 120 425 30 21 )
1386+
Graphic ( cab.ace )
1387+
NumFrames ( 2 2 1 )
1388+
Style ( ONOFF )
1389+
MouseControl ( 1 )
1390+
)
1391+
1392+
If there is no specific window control in the real cab, you can locate this control on the window itself,
1393+
using a transparent graphic. So, clicking on the window, you change its state. This can be applied
1394+
both to 2D and 3D cabs.
1395+
1396+
Sound triggers for windows animation are listed :ref:`here <sound-windows>` .
1397+
1398+
Specifics for carriage window animations
1399+
----------------------------------------
1400+
1401+
One window to the left and one window to the right of the carriage may be animated.
1402+
They can be opened and closed only via keyboard (Ctrl-Q for left window and
1403+
Ctrl-Shift-Q for right window, as for locomotives).
1404+
1405+
Note that the carriage must have only the main shape file (no passenger view shape file).
1406+
This main shape file can include also the inside structure of the carriage; note that when
1407+
a .wag or .eng file has an Inside block defined, and such block doesn't include a line
1408+
specifying the .s file, OR will use the main shape file to display the
1409+
inside. So such shape file will display the window animation both with
1410+
the passenger camera (inside view) and with the external cameras (outside views).
1411+
12371412
C# engine scripting
12381413
===================
12391414
.. _features-scripting-csharp:

Source/Documentation/Manual/sound.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ Trigger Function
406406
Trigger 252 is activated when the braking system detects an
407407
emergency brake application and starts venting air from the Brake Pipe.
408408

409+
Following triggers are related to windows animation:
410+
411+
.. _sound-windows:
412+
413+
========= =====================================
414+
Trigger Function
415+
========= =====================================
416+
260 WindowClosing
417+
261 WindowOpening
418+
========= =====================================
419+
409420
Variable Triggers
410421
-----------------
411422

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public enum UserCommand
163163
[GetString("Control Pantograph 2")] ControlPantograph2,
164164
[GetString("Control Pantograph 3")] ControlPantograph3,
165165
[GetString("Control Pantograph 4")] ControlPantograph4,
166+
[GetString("Control Window Left")] ControlWindowLeft,
167+
[GetString("Control Window Right")] ControlWindowRight,
166168
[GetString("Control Battery Close")] ControlBatterySwitchClose,
167169
[GetString("Control Battery Open")] ControlBatterySwitchOpen,
168170
[GetString("Control Master Key")] ControlMasterKey,

Source/ORTS.Settings/InputSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ static void InitializeCommands(UserCommandInput[] Commands)
375375
Commands[(int)UserCommand.ControlDieselPlayer] = new UserCommandKeyInput(0x15, KeyModifiers.Shift);
376376
Commands[(int)UserCommand.ControlDoorLeft] = new UserCommandKeyInput(0x10);
377377
Commands[(int)UserCommand.ControlDoorRight] = new UserCommandKeyInput(0x10, KeyModifiers.Shift);
378+
Commands[(int)UserCommand.ControlWindowLeft] = new UserCommandKeyInput(0x10, KeyModifiers.Control);
379+
Commands[(int)UserCommand.ControlWindowRight] = new UserCommandKeyInput(0x10, KeyModifiers.Control | KeyModifiers.Shift);
378380
Commands[(int)UserCommand.ControlDynamicBrakeDecrease] = new UserCommandKeyInput(0x33);
379381
Commands[(int)UserCommand.ControlDynamicBrakeIncrease] = new UserCommandKeyInput(0x34);
380382
Commands[(int)UserCommand.ControlElectricTrainSupply] = new UserCommandKeyInput(0x30, KeyModifiers.Alt);

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public enum CABViewControlTypes
184184
ORTS_MIRRORS,
185185
ORTS_PANTOGRAPH3,
186186
ORTS_PANTOGRAPH4,
187+
ORTS_LEFTWINDOW,
188+
ORTS_RIGHTWINDOW,
187189
ORTS_LARGE_EJECTOR,
188190
ORTS_WATER_SCOOP,
189191
ORTS_HOURDIAL,
@@ -206,6 +208,8 @@ public enum CABViewControlTypes
206208
ORTS_ELECTRIC_TRAIN_SUPPLY_COMMAND_SWITCH,
207209
ORTS_ELECTRIC_TRAIN_SUPPLY_ON,
208210
ORTS_2DEXTERNALWIPERS,
211+
ORTS_2DEXTERNALLEFTWINDOW,
212+
ORTS_2DEXTERNALRIGHTWINDOW,
209213
ORTS_GENERIC_ITEM1,
210214
ORTS_GENERIC_ITEM2,
211215
ORTS_SCREEN_SELECT,
@@ -273,6 +277,10 @@ public enum CABViewControlTypes
273277
ORTS_ITEM2CONTINUOUS,
274278
ORTS_ITEM1TWOSTATE,
275279
ORTS_ITEM2TWOSTATE,
280+
ORTS_EXTERNALLEFTWINDOWFRONT,
281+
ORTS_EXTERNALRIGHTWINDOWFRONT,
282+
ORTS_EXTERNALLEFTWINDOWREAR,
283+
ORTS_EXTERNALRIGHTWINDOWREAR,
276284
}
277285

278286
public enum CABViewControlStyles

Source/Orts.Simulation/Common/Commands.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,47 @@ public override void Redo()
12431243
}
12441244
}
12451245

1246+
[Serializable()]
1247+
public sealed class ToggleWindowLeftCommand : Command
1248+
{
1249+
public static MSTSWagon Receiver { get; set; }
1250+
1251+
public ToggleWindowLeftCommand(CommandLog log)
1252+
: base(log)
1253+
{
1254+
Redo();
1255+
}
1256+
1257+
public override void Redo()
1258+
{
1259+
if (Receiver is MSTSLocomotive locomotive && locomotive.UsingRearCab)
1260+
locomotive.ToggleWindow(rear: true, left: false);
1261+
else
1262+
Receiver.ToggleWindow(rear: false, left: true);
1263+
}
1264+
}
1265+
1266+
[Serializable()]
1267+
public sealed class ToggleWindowRightCommand : Command
1268+
{
1269+
public static MSTSWagon Receiver { get; set; }
1270+
1271+
public ToggleWindowRightCommand(CommandLog log)
1272+
: base(log)
1273+
{
1274+
Redo();
1275+
}
1276+
1277+
public override void Redo()
1278+
{
1279+
if (Receiver is MSTSLocomotive locomotive && locomotive.UsingRearCab)
1280+
locomotive.ToggleWindow(rear: true, left: true);
1281+
else
1282+
Receiver.ToggleWindow(rear: false, left: false);
1283+
}
1284+
}
1285+
1286+
12461287
[Serializable()]
12471288
public sealed class ToggleBatterySwitchCommand : BooleanCommand
12481289
{

Source/Orts.Simulation/Common/Events.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public enum Event
198198
VigilanceAlarmReset,
199199
WaterScoopDown,
200200
WaterScoopUp,
201+
WindowClosing,
202+
WindowOpening,
203+
WindowsClosed,
204+
WindowsOpen,
201205
WiperOff,
202206
WiperOn,
203207
_HeadlightDim,
@@ -526,6 +530,11 @@ public static Event From(Source source, int eventID)
526530
case 251: return Event.OverchargeBrakingOff;
527531
case 252: return Event.EmergencyVentValveOn;
528532

533+
case 260: return Event.WindowClosing;
534+
case 261: return Event.WindowOpening;
535+
case 262: return Event.WindowsClosed;
536+
case 263: return Event.WindowsOpen;
537+
529538
// Cruise Control
530539
case 298: return Event.LeverFromZero;
531540
case 299: return Event.LeverToZero;

0 commit comments

Comments
 (0)