Skip to content

Commit

Permalink
Automatic merge of T1.4-rc5-14-g6ccf85e65 and 6 pull requests
Browse files Browse the repository at this point in the history
- Pull request #480 at 6bc94a9: Blueprint https://blueprints.launchpad.net/or/+spec/digital-alignment-in-3dcabs
- Pull request #503 at 69a70cb: Update derailment functionality
- Pull request #507 at 80b98a3: Correct an issue with independent brake not working
- Pull request #508 at ed80ad6: Blueprint https://blueprints.launchpad.net/or/+spec/odometer-cabview-controls
- Pull request #510 at d4d3256: Add performance monitoring for diesel mechanic locomotives and new parameters
- Pull request #512 at 3aae640: Fixed dynamic brake being applied during standstill when dynamic brake blending is enabled
  • Loading branch information
openrails-bot committed Oct 3, 2021
8 parents f9a60c6 + 6ccf85e + 6bc94a9 + 69a70cb + 80b98a3 + ed80ad6 + d4d3256 + 3aae640 commit 5355a90
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 37 deletions.
12 changes: 2 additions & 10 deletions Source/Orts.Formats.Msts/LightCollection.cs
Expand Up @@ -31,7 +31,7 @@ namespace Orts.Formats.Msts
public class LightState
{
public float Duration;
public uint Color;
public Color Color;
public Vector3 Position;
public float Radius;
public Vector3 Azimuth;
Expand All @@ -44,22 +44,14 @@ public LightState(STFReader stf)
stf.MustMatch("(");
stf.ParseBlock(new[] {
new STFReader.TokenProcessor("duration", ()=>{ Duration = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
new STFReader.TokenProcessor("lightcolour", ()=>{ Color = stf.ReadHexBlock(null); }),
new STFReader.TokenProcessor("lightcolour", ()=>{ Color = stf.ReadColorBlock(null); }),
new STFReader.TokenProcessor("position", ()=>{ Position = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
new STFReader.TokenProcessor("radius", ()=>{ Radius = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }),
new STFReader.TokenProcessor("azimuth", ()=>{ Azimuth = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
new STFReader.TokenProcessor("elevation", ()=>{ Elevation = stf.ReadVector3Block(STFReader.UNITS.None, Vector3.Zero); }),
new STFReader.TokenProcessor("transition", ()=>{ Transition = 1 <= stf.ReadFloatBlock(STFReader.UNITS.None, 0); }),
new STFReader.TokenProcessor("angle", ()=>{ Angle = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
});
// Color byte order changed in XNA 4 from BGRA to RGBA
Color = new Color()
{
B = (byte)(Color),
G = (byte)(Color >> 8),
R = (byte)(Color >> 16),
A = (byte)(Color >> 24)
}.PackedValue;
}

public LightState(LightState state, bool reverse)
Expand Down
14 changes: 14 additions & 0 deletions Source/Orts.Parsers.Msts/STFReader.cs
Expand Up @@ -1182,6 +1182,20 @@ public string ReadStringBlock(string defaultValue)
return defaultValue;
}

/// <summary>Read a hexadecimal encoded color from the STF format '( {color_constant} ... )'
/// </summary>
/// <param name="defaultValue">the default value if the constant is not found in the block.</param>
/// <returns>The STF block with the first {item} converted to a color constant.</returns>
public Color ReadColorBlock(Color? defaultValue)
{
var hex = this.ReadHexBlock(STFReader.SwapColorBytes(defaultValue.GetValueOrDefault(Color.Black).PackedValue));
return new Color() { PackedValue = STFReader.SwapColorBytes(hex) };
}

static uint SwapColorBytes(uint color) {
return (color & 0xFF00FF00) + (byte)(color >> 16) + (uint)((byte)color << 16);
}

/// <summary>Read an hexidecimal encoded number from the STF format '( {int_constant} ... )'
/// </summary>
/// <param name="defaultValue">the default value if the constant is not found in the block.</param>
Expand Down
Expand Up @@ -1586,7 +1586,7 @@ protected void CorrectBrakingParams()
/// </summary>
public void DynamicBrakeBlending(float elapsedClockSeconds)
{
if (airPipeSystem != null && ((airPipeSystem is EPBrakeSystem && Train.BrakeLine4 > 0f) || airPipeSystem.BrakeLine1PressurePSI < TrainBrakeController.MaxPressurePSI - 1f)
if (SpeedMpS > DynamicBrakeSpeed1MpS && airPipeSystem != null && ((airPipeSystem is EPBrakeSystem && Train.BrakeLine4 > 0f) || airPipeSystem.BrakeLine1PressurePSI < TrainBrakeController.MaxPressurePSI - 1f)
&& ThrottleController.CurrentValue == 0f && !(DynamicBrakeController != null && DynamicBrakeBlendingOverride && DynamicBrakeController.CurrentValue > 0f)
/* && (!DynamicBrakeBlendingLeverOverride && DynamicBrakeController != null && DynamicBrakeIntervention < DynamicBrakeController.CurrentValue)*/)
{
Expand Down
Expand Up @@ -852,8 +852,8 @@ public virtual void Parse(STFReader stf)
case "maxexhaust": MaxExhaust = stf.ReadFloatBlock(STFReader.UNITS.None, 0);initLevel |= SettingsFlags.MaxExhaust; break;
case "exhaustdynamics": ExhaustAccelIncrease = stf.ReadFloatBlock(STFReader.UNITS.None, 0); initLevel |= SettingsFlags.ExhaustDynamics; break;
case "exhaustdynamicsdown": ExhaustDecelReduction = stf.ReadFloatBlock(STFReader.UNITS.None, null); initLevel |= SettingsFlags.ExhaustDynamics; break;
case "exhaustcolor": ExhaustSteadyColor.PackedValue = stf.ReadHexBlock(Color.Gray.PackedValue); initLevel |= SettingsFlags.ExhaustColor; break;
case "exhausttransientcolor": ExhaustTransientColor.PackedValue = stf.ReadHexBlock(Color.Black.PackedValue);initLevel |= SettingsFlags.ExhaustTransientColor; break;
case "exhaustcolor": ExhaustSteadyColor = stf.ReadColorBlock(Color.Gray); initLevel |= SettingsFlags.ExhaustColor; break;
case "exhausttransientcolor": ExhaustTransientColor = stf.ReadColorBlock(Color.Black);initLevel |= SettingsFlags.ExhaustTransientColor; break;
case "dieselpowertab": DieselPowerTab = new Interpolator(stf);initLevel |= SettingsFlags.DieselPowerTab; break;
case "dieselconsumptiontab": DieselConsumptionTab = new Interpolator(stf);initLevel |= SettingsFlags.DieselConsumptionTab; break;
case "throttlerpmtab":
Expand Down
6 changes: 3 additions & 3 deletions Source/RunActivity/Viewer3D/Lights.cs
Expand Up @@ -202,7 +202,7 @@ public static void CalculateLightCone(LightState lightState, out Vector3 positio
angle = MathHelper.ToRadians(lightState.Angle) / 2;
radius = lightState.Radius / 2;
distance = (float)(radius / Math.Sin(angle));
color = new Color() { PackedValue = lightState.Color }.ToVector4();
color = lightState.Color.ToVector4();
}

#if DEBUG_LIGHT_STATES
Expand Down Expand Up @@ -535,11 +535,11 @@ public LightGlowPrimitive(LightViewer lightViewer, RenderProcess renderProcess,
var position1 = state1.Position; position1.Z *= -1;
var normal1 = Vector3.Transform(Vector3.Transform(-Vector3.UnitZ, Matrix.CreateRotationX(MathHelper.ToRadians(-state1.Elevation.Y))), Matrix.CreateRotationY(MathHelper.ToRadians(-state1.Azimuth.Y)));
var color1 = new Color() { PackedValue = state1.Color }.ToVector4();
var color1 = state1.Color.ToVector4();
var position2 = state2.Position; position2.Z *= -1;
var normal2 = Vector3.Transform(Vector3.Transform(-Vector3.UnitZ, Matrix.CreateRotationX(MathHelper.ToRadians(-state2.Elevation.Y))), Matrix.CreateRotationY(MathHelper.ToRadians(-state2.Azimuth.Y)));
var color2 = new Color() { PackedValue = state2.Color }.ToVector4();
var color2 = state2.Color.ToVector4();
vertexData[6 * state + 0] = new LightGlowVertex(new Vector2(1, 1), position1, position2, normal1, normal2, color1, color2, state1.Radius, state2.Radius);
vertexData[6 * state + 1] = new LightGlowVertex(new Vector2(0, 0), position1, position2, normal1, normal2, color1, color2, state1.Radius, state2.Radius);
Expand Down
53 changes: 32 additions & 21 deletions Source/RunActivity/Viewer3D/Popups/TrainDrivingWindow.cs
Expand Up @@ -1178,47 +1178,58 @@ void AddLabel(ListLabel label)
}

//Derailment Coefficient. Changed the float value output by a text label.
var maxDerailCoeff = 0.0f;
var carIDerailCoeff = "";
var carDerailPossible = false;
var carDerailExpected = false;

for (var i = 0; i < train.Cars.Count; i++)
{
var carDerailCoeff = train.Cars[i].DerailmentCoefficient;
carDerailCoeff = float.IsInfinity(carDerailCoeff) || float.IsNaN(carDerailCoeff) ? 0 : carDerailCoeff;
if (carDerailCoeff > maxDerailCoeff)

carIDerailCoeff = train.Cars[i].CarID;

// Only record the first car that has derailed, stop looking for other derailed cars
carDerailExpected = train.Cars[i].DerailExpected;
if (carDerailExpected)
{
break;
}

// Only record first instance of a possible car derailment (warning)
if (train.Cars[i].DerailPossible && !carDerailPossible)
{
maxDerailCoeff = carDerailCoeff;
carIDerailCoeff = train.Cars[i].CarID;
carDerailPossible = train.Cars[i].DerailPossible;
}
}

if (maxDerailCoeff > 0.66)
if (carDerailPossible || carDerailExpected)
{
derailLabelVisible = true;
clockDerailTime = Owner.Viewer.Simulator.ClockTime;
}

if (maxDerailCoeff > 0.66)
// The most extreme instance of the derail coefficient will only be displayed in the TDW
if (carDerailExpected)
{
if (maxDerailCoeff > 1)
AddLabel(new ListLabel
{
AddLabel(new ListLabel
{
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Derailed")} {carIDerailCoeff}" + ColorCode[Color.OrangeRed],
});
}
else if (maxDerailCoeff < 1 && maxDerailCoeff > 0.66)
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Derailed")} {carIDerailCoeff}" + ColorCode[Color.OrangeRed],
});
}
else if (carDerailPossible)
{
AddLabel(new ListLabel
{
AddLabel(new ListLabel
{
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Warning")} {carIDerailCoeff}" + ColorCode[Color.Yellow],
});
}
FirstCol = Viewer.Catalog.GetString("DerailCoeff"),
LastCol = $"{Viewer.Catalog.GetString("Warning")} {carIDerailCoeff}" + ColorCode[Color.Yellow],
});
}

else
{
// delay to hide the derailcoeff label
// delay to hide the derailcoeff label if normal
if (derailLabelVisible && clockDerailTime + 3 < Owner.Viewer.Simulator.ClockTime)
derailLabelVisible = false;

Expand Down

0 comments on commit 5355a90

Please sign in to comment.