Skip to content

Commit 1ffe33b

Browse files
committed
Automatic merge of T1.5.1-972-g193ebe1d0 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 48aa537: 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 c296b32: Downloading route content (Github, zip) - Pull request #912 at df43405: 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 27fb483: Dynamic Brakes Behavior & Display Improvements
16 parents 0f90f83 + 193ebe1 + dfc715e + d00beb9 + f92de76 + 48aa537 + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + c296b32 + df43405 + 26cc6a8 + abe2e52 + 4c27204 + 27fb483 commit 1ffe33b

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,13 +1270,14 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
12701270
Positions.Add(0);
12711271
// We will need the FramesCount later!
12721272
// We use Positions only here
1273-
Positions.Add(FramesCount);
1273+
Positions.Add(FramesCount - 1);
12741274

12751275
// Fill empty Values
1276-
for (int i = 0; i < FramesCount; i++)
1276+
for (int i = 0; i < (FramesCount - 1); i++)
12771277
Values.Add(0);
12781278
Values[0] = MinValue;
12791279

1280+
// Add maximum value to the end
12801281
Values.Add(MaxValue);
12811282
}
12821283
else if (Values.Count == 2 && Values[0] == 0 && Values[1] < MaxValue && Positions[0] == 0 && Positions[1] == 1 && Values.Count < FramesCount)
@@ -1289,13 +1290,13 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
12891290
//Orientation ( 0 )
12901291
//DirIncrease ( 0 )
12911292
//ScaleRange ( 0 1 )
1292-
Positions.Add(FramesCount);
1293+
Positions.Add(FramesCount - 1);
12931294
// Fill empty Values
1294-
for (int i = Values.Count; i < FramesCount; i++)
1295+
for (int i = Values.Count; i < (FramesCount - 1); i++)
12951296
Values.Add(Values[1]);
1297+
// Add maximum value to the end
12961298
Values.Add(MaxValue);
12971299
}
1298-
12991300
else
13001301
{
13011302
//This if clause covers among others following cases:
@@ -1321,11 +1322,6 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
13211322
}
13221323
iValues++;
13231324
}
1324-
1325-
// Add the maximums to the end, the Value will be removed
1326-
// We use Positions only here
1327-
if (Values.Count > 0 && Values[0] <= Values[Values.Count - 1]) Values.Add(MaxValue);
1328-
else if (Values.Count > 0 && Values[0] > Values[Values.Count - 1]) Values.Add(MinValue);
13291325
}
13301326

13311327
// OK, we have a valid size of Positions and Values
@@ -1351,9 +1347,6 @@ public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
13511347
p = Positions[i];
13521348
}
13531349
}
1354-
1355-
// Don't need the MaxValue added before, remove it
1356-
Values.RemoveAt(Values.Count - 1);
13571350
}
13581351
}
13591352

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ public class CabViewDiscreteRenderer : CabViewControlRenderer, ICabViewMouseCont
20802080
float Scale = 1;
20812081
int OldFrameIndex = 0;
20822082
public bool ButtonState = false;
2083+
int SplitIndex = -1;
20832084

20842085
/// <summary>
20852086
/// Accumulated mouse movement. Used for controls with no assigned notch controllers, e.g. headlight and reverser.
@@ -2128,6 +2129,8 @@ public CabViewDiscreteRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCWith
21282129
};
21292130
break;
21302131
}
2132+
// The cab view control index shown when combined control is at the split position
2133+
SplitIndex = PercentToIndex(Locomotive.CombinedControlSplitPosition);
21312134
}
21322135

21332136
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
@@ -2233,21 +2236,12 @@ public virtual int GetDrawIndex()
22332236
index = PercentToIndex(dynBrakePercent);
22342237
break;
22352238
case CABViewControlTypes.CPH_DISPLAY:
2236-
if (Locomotive.CombinedControlType == MSTSLocomotive.CombinedControl.ThrottleDynamic && Locomotive.DynamicBrakeController?.CurrentValue > 0)
2237-
// TODO <CSComment> This is a sort of hack to allow MSTS-compliant operation of Dynamic brake indications in the standard USA case with 8 steps (e.g. Dash9)
2238-
// This hack returns to code of previous OR versions (e.g. release 1.0).
2239-
// The clean solution for MSTS compliance would be not to increment the percentage of the dynamic brake at first dynamic brake key pression, so that
2240-
// subsequent steps become of 12.5% as in MSTS instead of 11.11% as in OR. This requires changes in the physics logic </CSComment>
2241-
index = (int)((ControlDiscrete.FramesCount) * Locomotive.GetCombinedHandleValue(false));
2242-
else
2243-
index = PercentToIndex(Locomotive.GetCombinedHandleValue(false));
2244-
break;
22452239
case CABViewControlTypes.CP_HANDLE:
2246-
if (Locomotive.CombinedControlType == MSTSLocomotive.CombinedControl.ThrottleDynamic && Locomotive.DynamicBrakeController?.CurrentValue > 0
2247-
|| Locomotive.CombinedControlType == MSTSLocomotive.CombinedControl.ThrottleAir && Locomotive.TrainBrakeController?.CurrentValue > 0)
2248-
index = PercentToIndex(Locomotive.GetCombinedHandleValue(false));
2249-
else
2250-
index = PercentToIndex(Locomotive.GetCombinedHandleValue(false));
2240+
var combinedHandlePosition = Locomotive.GetCombinedHandleValue(false);
2241+
index = PercentToIndex(combinedHandlePosition);
2242+
// Make sure power indications are not shown when locomotive is in braking range
2243+
if (combinedHandlePosition > Locomotive.CombinedControlSplitPosition)
2244+
index = Math.Max(index, SplitIndex + 1);
22512245
break;
22522246
case CABViewControlTypes.ORTS_SELECTED_SPEED_DISPLAY:
22532247
if (Locomotive.CruiseControl == null)
@@ -2915,9 +2909,29 @@ protected int PercentToIndex(float percent)
29152909
{
29162910
try
29172911
{
2918-
var val = ControlDiscrete.Values[0] <= ControlDiscrete.Values[ControlDiscrete.Values.Count - 1] ?
2919-
ControlDiscrete.Values.Where(v => (float)v <= percent + 0.00001).Last() : ControlDiscrete.Values.Where(v => (float)v <= percent + 0.00001).First();
2920-
index = ControlDiscrete.Values.IndexOf(val);
2912+
// Binary search process to find the control value closest to percent
2913+
List<double> vals = ControlDiscrete.Values;
2914+
// Check if control values were defined in reverse, reverse them back for this calculation
2915+
// This is less efficient, so creators should be encouraged to not do this
2916+
bool reversed = ControlDiscrete.Values[0] > ControlDiscrete.Values[ControlDiscrete.Values.Count - 1];
2917+
if (reversed)
2918+
vals.Reverse();
2919+
2920+
// Returns index of first val larger than percent, or bitwise compliment of this index if percent isn't in the list
2921+
int checkIndex = vals.BinarySearch(percent);
2922+
2923+
if (checkIndex < 0)
2924+
checkIndex = ~checkIndex;
2925+
if (checkIndex > vals.Count - 1)
2926+
checkIndex = vals.Count - 1;
2927+
// Choose lower index if it is closer to percent
2928+
if (checkIndex > 0 && Math.Abs(vals[checkIndex - 1] - percent) < Math.Abs(vals[checkIndex] - percent))
2929+
checkIndex--;
2930+
// Re-reverse the index as needed
2931+
if (reversed)
2932+
checkIndex = (vals.Count - 1) - checkIndex;
2933+
2934+
index = checkIndex;
29212935
}
29222936
catch
29232937
{

0 commit comments

Comments
 (0)