Skip to content

Commit 195b52b

Browse files
committed
Automatic merge of T1.5.1-974-g2634ac3be and 14 pull requests
- Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at 537db1a: Blueprint/train car operations UI window - Pull request #891 at 9a1d6b2: Auto save - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #900 at c27f32d: DMI updates - Pull request #903 at 3e390b8: Downloading route content (Github, zip) - Pull request #912 at cda1d74: New Triple Valve Features Vol. 2 - Pull request #919 at 26cc6a8: Added mouse wheel support for controls which can be moved by pressing t… - Pull request #922 at abe2e52: Autopilot for timetable mode - Pull request #923 at 4c27204: Add curve squeal to route - Pull request #943 at 8745029: Dynamic Brakes Behavior & Display Improvements
16 parents d535343 + 2634ac3 + dfc715e + d00beb9 + f92de76 + 537db1a + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + 3e390b8 + cda1d74 + 26cc6a8 + abe2e52 + 4c27204 + 8745029 commit 195b52b

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,14 +1131,25 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
11311131
Positions[i] = i;
11321132
}
11331133

1134-
// Check if eligible for filling
1134+
// Possible that positions were defined in reverse, eg: 3DTrains Surfliner trains
1135+
// Ensure positions are sorted from least to greatest before proceeding
1136+
if (Positions.Count > 0 && Positions[0] > Positions[Positions.Count - 1])
1137+
{
1138+
Reversed ^= true;
1139+
// Recalculate positions in reverse
1140+
for (int i = 0; i < Positions.Count; i++)
1141+
Positions[i] = (FramesCount - 1) - Positions[i];
1142+
}
11351143

1136-
if (Positions.Count > 1 && Positions[0] != 0) CanFill = false;
1144+
// Check if eligible for filling
1145+
if (Positions.Count > 1 && Positions[0] != 0)
1146+
CanFill = false;
11371147
else
11381148
{
11391149
for (var iPos = 1; iPos <= Positions.Count - 1; iPos++)
11401150
{
1141-
if (Positions[iPos] > Positions[iPos-1]) continue;
1151+
if (Positions[iPos] > Positions[iPos-1])
1152+
continue;
11421153
CanFill = false;
11431154
break;
11441155
}
@@ -1276,14 +1287,16 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
12761287
// Fill empty Values
12771288
for (int i = 0; i < (FramesCount - 1); i++)
12781289
Values.Add(0);
1290+
// Offset for min and max values to achieve equal frame spacing
1291+
double offset = 1.0 / (2.0 * FramesCount);
12791292
// Some dummy controls will have only one frame
12801293
if (Values.Count > 0)
1281-
Values[0] = MinValue;
1294+
Values[0] = MinValue + offset;
12821295
else
1283-
Values.Add(MinValue);
1296+
Values.Add(MinValue + offset);
12841297

12851298
// Add maximum value to the end
1286-
Values.Add(MaxValue);
1299+
Values.Add(MaxValue - offset);
12871300
}
12881301
else if (Values.Count == 2 && Values[0] == 0 && Values[1] < MaxValue && Positions[0] == 0 && Positions[1] == 1 && Values.Count < FramesCount)
12891302
{
@@ -1295,12 +1308,15 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
12951308
//Orientation ( 0 )
12961309
//DirIncrease ( 0 )
12971310
//ScaleRange ( 0 1 )
1311+
// Add missing positions
12981312
Positions.Add(FramesCount - 1);
12991313
// Fill empty Values
13001314
for (int i = Values.Count; i < (FramesCount - 1); i++)
1301-
Values.Add(Values[1]);
1315+
Values.Add(0);
1316+
// Offset for min and max values to achieve equal frame spacing
1317+
double offset = 1.0 / (2.0 * FramesCount);
13021318
// Add maximum value to the end
1303-
Values.Add(MaxValue);
1319+
Values.Add(MaxValue - offset);
13041320
}
13051321
else
13061322
{
@@ -1387,7 +1403,7 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
13871403
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
13881404
// Assume values have been entered in reverse order if final value is less than initial value
13891405
if (Values.Count > 0 && Values[0] > Values[Values.Count - 1])
1390-
Reversed = true;
1406+
Reversed ^= true;
13911407
// Force sort values from least to greatest
13921408
Values.Sort();
13931409

@@ -1442,9 +1458,8 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
14421458
; }),
14431459
});}),
14441460
});
1445-
if (Values.Count > 0) MaxValue = Values.Last();
1446-
for (int i = Values.Count; i < FramesCount; i++)
1447-
Values.Add(-10000);
1461+
if (Values.Count > 0)
1462+
MaxValue = Values.Max();
14481463
}),
14491464
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
14501465
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
@@ -1457,7 +1472,10 @@ public CVCMultiStateDisplay(STFReader stf, string basepath)
14571472
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
14581473
// Assume values have been entered in reverse order if final value is less than initial value
14591474
if (Values.Count > 0 && Values[0] > Values[Values.Count - 1])
1460-
Reversed = true;
1475+
Reversed ^= true;
1476+
// Fill in missing values
1477+
for (int i = Values.Count; i < FramesCount; i++)
1478+
Values.Add(Values[Values.Count - 1]);
14611479
// Force sort values from least to greatest
14621480
Values.Sort();
14631481
}
@@ -1502,9 +1520,8 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
15021520
; }),
15031521
});}),
15041522
});
1505-
if (Values.Count > 0) MaxValue = Values.Last();
1506-
for (int i = Values.Count; i < FramesCount; i++)
1507-
Values.Add(-10000);
1523+
if (Values.Count > 0)
1524+
MaxValue = Values.Max();
15081525
}),
15091526
new STFReader.TokenProcessor("ortsdisplay", ()=>{ParseDisplay(stf); }),
15101527
new STFReader.TokenProcessor("ortsscreenpage", () => {ParseScreen(stf); }),
@@ -1517,7 +1534,10 @@ public CVCAnimatedDisplay(STFReader stf, string basepath)
15171534
// Ensure resulting set of values has the correct format (sorted least to greatest) and resort
15181535
// Assume values have been entered in reverse order if final value is less than initial value
15191536
if (Values.Count > 0 && Values[0] > Values[Values.Count - 1])
1520-
Reversed = true;
1537+
Reversed ^= true;
1538+
// Fill in missing values
1539+
for (int i = Values.Count; i < FramesCount; i++)
1540+
Values.Add(Values[Values.Count - 1]);
15211541
// Force sort values from least to greatest
15221542
Values.Sort();
15231543
}

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,8 +2129,18 @@ public CabViewDiscreteRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCWith
21292129
};
21302130
break;
21312131
}
2132-
// The cab view control index shown when combined control is at the split position
2133-
SplitIndex = PercentToIndex(Locomotive.CombinedControlSplitPosition);
2132+
// Determine the cab view control index shown when combined control is at the split position
2133+
// Find the index of the next value LARGER than the split value
2134+
int splitIndex = ControlDiscrete.Values.BinarySearch(Locomotive.CombinedControlSplitPosition);
2135+
// Account for any edge cases
2136+
if (splitIndex < 0)
2137+
splitIndex = ~splitIndex;
2138+
if (splitIndex > ControlDiscrete.Values.Count - 1)
2139+
splitIndex = ControlDiscrete.Values.Count - 1;
2140+
if (ControlDiscrete.Reversed)
2141+
splitIndex = (ControlDiscrete.Values.Count - 1) - splitIndex;
2142+
2143+
SplitIndex = splitIndex;
21342144
}
21352145

21362146
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
@@ -2239,13 +2249,14 @@ public virtual int GetDrawIndex()
22392249
case CABViewControlTypes.CP_HANDLE:
22402250
var combinedHandlePosition = Locomotive.GetCombinedHandleValue(false);
22412251
index = PercentToIndex(combinedHandlePosition);
2242-
// Make sure power indications are not shown when locomotive is in braking range
2243-
if (combinedHandlePosition > Locomotive.CombinedControlSplitPosition)
2252+
// Make sure any deviation from the split position gives a different index
2253+
int handleRelativePos = combinedHandlePosition.CompareTo(Locomotive.CombinedControlSplitPosition);
2254+
if (handleRelativePos != 0)
22442255
{
2245-
if (ControlDiscrete.Reversed)
2246-
index = Math.Min(index, SplitIndex - 1);
2247-
else
2256+
if (handleRelativePos == (ControlDiscrete.Reversed ? - 1 : 1))
22482257
index = Math.Max(index, SplitIndex + 1);
2258+
else
2259+
index = Math.Min(index, SplitIndex - 1);
22492260
}
22502261
break;
22512262
case CABViewControlTypes.ORTS_SELECTED_SPEED_DISPLAY:

0 commit comments

Comments
 (0)