Skip to content

Commit

Permalink
Automatic merge of T1.5.1-440-g0914a53e4 and 11 pull requests
Browse files Browse the repository at this point in the history
- Pull request #570 at 7269d24: Experimental glTF 2.0 support with PBR lighting
- Pull request #757 at d9d75f4: Unify RailDriver code implementations
- Pull request #799 at dc03850: Consolidated wind simulation
- Pull request #813 at 7fdad38: Refactored garbage generators
- Pull request #821 at e0fa5a8: Adds suppression of safety valves
- Pull request #829 at 434af02: Improvements for air brakes #3 - Emergency valves
- Pull request #830 at ce2726a: Electric locomotive hot start
- Pull request #835 at 4c9375e: Correct Brake Shoe Force Calculation
- Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters
- Pull request #840 at daca020: Bug fix for sanding max speed not working
- Pull request #841 at 65eeaa7: https://blueprints.launchpad.net/or/+spec/animating-trainset-windows
  • Loading branch information
openrails-bot committed Jun 12, 2023
13 parents 719b80b + 0914a53 + 7269d24 + d9d75f4 + dc03850 + 7fdad38 + e0fa5a8 + 434af02 + ce2726a + 4c9375e + d00beb9 + daca020 + 65eeaa7 commit 633f1b9
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Source/ORTS.Common/Input/UserCommand.cs
Expand Up @@ -163,6 +163,8 @@ public enum UserCommand
[GetString("Control Pantograph 2")] ControlPantograph2,
[GetString("Control Pantograph 3")] ControlPantograph3,
[GetString("Control Pantograph 4")] ControlPantograph4,
[GetString("Control Window Left")] ControlWindowLeft,
[GetString("Control Window Right")] ControlWindowRight,
[GetString("Control Battery Close")] ControlBatterySwitchClose,
[GetString("Control Battery Open")] ControlBatterySwitchOpen,
[GetString("Control Master Key")] ControlMasterKey,
Expand Down
2 changes: 2 additions & 0 deletions Source/ORTS.Settings/InputSettings.cs
Expand Up @@ -374,6 +374,8 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.ControlDieselPlayer] = new UserCommandKeyInput(0x15, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlDoorLeft] = new UserCommandKeyInput(0x10);
Commands[(int)UserCommand.ControlDoorRight] = new UserCommandKeyInput(0x10, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlWindowLeft] = new UserCommandKeyInput(0x10, KeyModifiers.Control);
Commands[(int)UserCommand.ControlWindowRight] = new UserCommandKeyInput(0x10, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.ControlDynamicBrakeDecrease] = new UserCommandKeyInput(0x33);
Commands[(int)UserCommand.ControlDynamicBrakeIncrease] = new UserCommandKeyInput(0x34);
Commands[(int)UserCommand.ControlElectricTrainSupply] = new UserCommandKeyInput(0x30, KeyModifiers.Alt);
Expand Down
8 changes: 8 additions & 0 deletions Source/Orts.Formats.Msts/CabViewFile.cs
Expand Up @@ -184,6 +184,8 @@ public enum CABViewControlTypes
ORTS_MIRRORS,
ORTS_PANTOGRAPH3,
ORTS_PANTOGRAPH4,
ORTS_LEFTWINDOW,
ORTS_RIGHTWINDOW,
ORTS_LARGE_EJECTOR,
ORTS_WATER_SCOOP,
ORTS_HOURDIAL,
Expand All @@ -206,6 +208,8 @@ public enum CABViewControlTypes
ORTS_ELECTRIC_TRAIN_SUPPLY_COMMAND_SWITCH,
ORTS_ELECTRIC_TRAIN_SUPPLY_ON,
ORTS_2DEXTERNALWIPERS,
ORTS_2DEXTERNALLEFTWINDOW,
ORTS_2DEXTERNALRIGHTWINDOW,
ORTS_GENERIC_ITEM1,
ORTS_GENERIC_ITEM2,
ORTS_SCREEN_SELECT,
Expand Down Expand Up @@ -273,6 +277,10 @@ public enum CABViewControlTypes
ORTS_ITEM2CONTINUOUS,
ORTS_ITEM1TWOSTATE,
ORTS_ITEM2TWOSTATE,
ORTS_EXTERNALLEFTWINDOWFRONT,
ORTS_EXTERNALRIGHTWINDOWFRONT,
ORTS_EXTERNALLEFTWINDOWREAR,
ORTS_EXTERNALRIGHTWINDOWREAR,
}

public enum CABViewControlStyles
Expand Down
41 changes: 41 additions & 0 deletions Source/Orts.Simulation/Common/Commands.cs
Expand Up @@ -1243,6 +1243,47 @@ public override void Redo()
}
}

[Serializable()]
public sealed class ToggleWindowLeftCommand : Command
{
public static MSTSWagon Receiver { get; set; }

public ToggleWindowLeftCommand(CommandLog log)
: base(log)
{
Redo();
}

public override void Redo()
{
if (Receiver is MSTSLocomotive locomotive && locomotive.UsingRearCab)
locomotive.ToggleWindow(rear: true, left: false);
else
Receiver.ToggleWindow(rear: false, left: true);
}
}

[Serializable()]
public sealed class ToggleWindowRightCommand : Command
{
public static MSTSWagon Receiver { get; set; }

public ToggleWindowRightCommand(CommandLog log)
: base(log)
{
Redo();
}

public override void Redo()
{
if (Receiver is MSTSLocomotive locomotive && locomotive.UsingRearCab)
locomotive.ToggleWindow(rear: true, left: true);
else
Receiver.ToggleWindow(rear: false, left: false);
}
}


[Serializable()]
public sealed class ToggleBatterySwitchCommand : BooleanCommand
{
Expand Down
9 changes: 9 additions & 0 deletions Source/Orts.Simulation/Common/Events.cs
Expand Up @@ -198,6 +198,10 @@ public enum Event
VigilanceAlarmReset,
WaterScoopDown,
WaterScoopUp,
WindowClosing,
WindowOpening,
WindowsClosed,
WindowsOpen,
WiperOff,
WiperOn,
_HeadlightDim,
Expand Down Expand Up @@ -526,6 +530,11 @@ public static Event From(Source source, int eventID)
case 251: return Event.OverchargeBrakingOff;
case 252: return Event.EmergencyVentValveOn;

case 260: return Event.WindowClosing;
case 261: return Event.WindowOpening;
case 262: return Event.WindowsClosed;
case 263: return Event.WindowsOpen;

// Cruise Control
case 298: return Event.LeverFromZero;
case 299: return Event.LeverToZero;
Expand Down
8 changes: 6 additions & 2 deletions Source/Orts.Simulation/Simulation/Confirmer.cs
Expand Up @@ -107,6 +107,8 @@ public enum CabControl {
, DoorsLeft
, DoorsRight
, Mirror
, WindowLeft
, WindowRight
// Track Devices
, SwitchAhead
, SwitchBehind
Expand Down Expand Up @@ -243,7 +245,7 @@ public Confirmer(Simulator simulator, double defaultDurationS)
, new string [] { GetString("Bell"), GetString("off"), null, GetString("ring") }
, new string [] { GetString("Headlight"), GetString("off"), GetString("dim"), GetString("bright") }
, new string [] { GetString("Cab Light"), GetString("off"), null, GetString("on") }
, new string [] { GetString("Wipers"), GetString("off"), null, GetString("on") }
, new string [] { GetString("Wipers"), GetString("off"), null, GetString("on") }
, new string [] { GetString("Cab"), null, null, GetParticularString("Cab", "change"), null, null, GetString("changing is not available"), GetString("changing disabled. Close throttle, set reverser to neutral, stop train then re-try.") }
, new string [] { GetString("Odometer"), null, null, GetParticularString("Odometer", "reset"), GetParticularString("Odometer", "counting down"), GetParticularString("Odometer", "counting up") }
, new string [] { GetString("Battery"), GetString("off"), null, GetString("on") }
Expand All @@ -254,7 +256,9 @@ public Confirmer(Simulator simulator, double defaultDurationS)
// Train Devices
, new string [] { GetString("Doors Left"), GetString("close"), null, GetString("open") }
, new string [] { GetString("Doors Right"), GetString("close"), null, GetString("open") }
, new string [] { GetString("Mirror"), GetString("retract"), null, GetString("extend") }
, new string [] { GetString("Mirror"), GetString("retract"), null, GetString("extend") }
, new string [] { GetString("Window Left"), GetString("closing"), null, GetString("opening") }
, new string [] { GetString("Window Right"), GetString("closing"), null, GetString("opening") }
// Track Devices
, new string [] { GetString("Switch Ahead"), null, null, GetParticularString("Switch", "change"), null, null, GetString("locked. Use Control+M to change signals to manual mode then re-try.") }
, new string [] { GetString("Switch Behind"), null, null, GetParticularString("Switch", "change"), null, null, GetString("locked. Use Control+M to change signals to manual mode then re-try.") }
Expand Down
10 changes: 10 additions & 0 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs
Expand Up @@ -5722,6 +5722,16 @@ public virtual float GetDataOf(CabViewControl cvc)
data = state >= DoorState.Opening ? 1 : 0;
}
break;
case CABViewControlTypes.ORTS_LEFTWINDOW:
case CABViewControlTypes.ORTS_2DEXTERNALLEFTWINDOW:
data = UsingRearCab ? (WindowStates[RightWindowRearIndex] == WindowState.Closing || WindowStates[RightWindowRearIndex] == WindowState.Opening ? 1 : 0) :
(WindowStates[LeftWindowFrontIndex] == WindowState.Closing || WindowStates[LeftWindowFrontIndex] == WindowState.Opening ? 1 : 0);
break;
case CABViewControlTypes.ORTS_RIGHTWINDOW:
case CABViewControlTypes.ORTS_2DEXTERNALRIGHTWINDOW:
data = UsingRearCab ? (WindowStates[LeftWindowRearIndex] == WindowState.Closing || WindowStates[LeftWindowRearIndex] == WindowState.Opening ? 1 : 0) :
(WindowStates[RightWindowFrontIndex] == WindowState.Closing || WindowStates[RightWindowFrontIndex] == WindowState.Opening ? 1 : 0);
break;
case CABViewControlTypes.ORTS_MIRRORS:
data = MirrorOpen ? 1 : 0;
break;
Expand Down
41 changes: 41 additions & 0 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs
Expand Up @@ -72,6 +72,23 @@ public class MSTSWagon : TrainCar
public Doors Doors;
public Door RightDoor => Doors.RightDoor;
public Door LeftDoor => Doors.LeftDoor;

public enum WindowState
// Don't change the order of entries within this enum
{
Closed,
Closing,
Opening,
Open,
}

public static int LeftWindowFrontIndex = 0;
public static int RightWindowFrontIndex = 1;
public static int LeftWindowRearIndex = 2;
public static int RightWindowRearIndex = 3;
public WindowState[] WindowStates = new WindowState[4];
public float[] SoundHeardInternallyCorrection = new float[2];

public bool MirrorOpen;
public bool UnloadingPartsOpen;
public bool WaitForAnimationReady; // delay counter to start loading/unliading is on;
Expand Down Expand Up @@ -1812,6 +1829,10 @@ public override void Save(BinaryWriter outf)
outf.Write(DerailPossible);
outf.Write(DerailExpected);
outf.Write(DerailElapsedTimeS);
for (int index = 0; index < 4; index++)
{
outf.Write((int)WindowStates[index]);
}

LocomotiveAxles.Save(outf);

Expand Down Expand Up @@ -1867,6 +1888,10 @@ public override void Restore(BinaryReader inf)
DerailPossible = inf.ReadBoolean();
DerailExpected = inf.ReadBoolean();
DerailElapsedTimeS = inf.ReadSingle();
for (int index = 0; index < 4; index++)
{
WindowStates[index] = (WindowState)inf.ReadInt32();
}

MoveParamsToAxle();
LocomotiveAxles.Restore(inf);
Expand Down Expand Up @@ -3496,6 +3521,22 @@ public void ToggleMirrors()
if (Simulator.PlayerLocomotive == this) Simulator.Confirmer.Confirm(CabControl.Mirror, MirrorOpen ? CabSetting.On : CabSetting.Off);
}

public void ToggleWindow(bool rear, bool left)
{
var open = false;
var index = (left ? 0 : 1) + 2 * (rear ? 1 : 0);
if (WindowStates[index] == WindowState.Closed || WindowStates[index] == WindowState.Closing)
WindowStates[index] = WindowState.Opening;
else if (WindowStates[index] == WindowState.Open || WindowStates[index] == WindowState.Opening)
WindowStates[index] = WindowState.Closing;
if (WindowStates[index] == WindowState.Opening) open = true;


if (open) SignalEvent(Event.WindowOpening); // hook for sound trigger
else SignalEvent(Event.WindowClosing);
if (Simulator.PlayerLocomotive == this) Simulator.Confirmer.Confirm(left ^ rear ? CabControl.WindowLeft : CabControl.WindowRight, open ? CabSetting.On : CabSetting.Off);
}

public void FindControlActiveLocomotive()
{
// Find the active locomotive associated with a control car
Expand Down
2 changes: 2 additions & 0 deletions Source/Orts.Simulation/Simulation/Simulator.cs
Expand Up @@ -699,6 +699,8 @@ public void SetCommandReceivers()
ToggleDoorsLeftCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
ToggleDoorsRightCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
ToggleMirrorsCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
ToggleWindowLeftCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
ToggleWindowRightCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
CabRadioCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
ToggleHelpersEngineCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
BatterySwitchCommand.Receiver = (PlayerLocomotive as MSTSLocomotive).LocomotivePowerSupply;
Expand Down
10 changes: 10 additions & 0 deletions Source/RunActivity/Viewer3D/AnimatedPart.cs
Expand Up @@ -160,6 +160,16 @@ public void UpdateState(bool state, ElapsedTime elapsedTime)
SetFrameClamp(AnimationKey + (state ? 1 : -1) * elapsedTime.ClockSeconds);
}

/// <summary>
/// Updates an animated part that toggles between two states and returns relative value of
/// animation key (between 0 and 1).
/// </summary>
public float UpdateAndReturnState(bool state, ElapsedTime elapsedTime)
{
SetFrameClamp(AnimationKey + (state ? 1 : -1) * elapsedTime.ClockSeconds);
return AnimationKey / FrameCount;
}

/// <summary>
/// Updates an animated part that loops (e.g. running gear), changing by the given amount.
/// </summary>
Expand Down

0 comments on commit 633f1b9

Please sign in to comment.