Skip to content

Commit 8870ed2

Browse files
committed
Automatic merge of T1.5.1-997-gb5992851e1 and 19 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 b3f83ed: Blueprint/train car operations UI window - Pull request #885 at 56c17fb: feat: Add notifications to Menu - 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 359cfee: New Triple Valve Features Vol. 2 - Pull request #922 at abe2e52: Autopilot for timetable mode - Pull request #946 at 66f836c: Advanced track sounds - Pull request #949 at 1985cbe: Oil Burning Locomotive - Pull request #950 at a98ff62: Ctrl-F5 showing yellow rectangles where mouse left button is active - Pull request #951 at 486081b: fix: Fix watchdog process state name - Pull request #952 at b2af1f5: Investigation - Pulsing graphics part 1 - Pull request #953 at 9b0ec01: Fix Lights Crash on Corrupt Shapes - Pull request #954 at 7a41709: Add Support for Multiple Track Profiles
21 parents 1e312c4 + b599285 + dfc715e + d00beb9 + f92de76 + b3f83ed + 56c17fb + 9a1d6b2 + 1f5ba4c + 5866028 + c27f32d + 3e390b8 + 359cfee + abe2e52 + 66f836c + 1985cbe + a98ff62 + 486081b + b2af1f5 + 9b0ec01 + 7a41709 commit 8870ed2

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

Source/RunActivity/Viewer3D/DynamicTrack.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ public class TRPFile
249249
//public RenderProcess RenderProcess; // TODO: Pass this along in function calls
250250

251251
/// <summary>
252-
/// Creates a TRPFile instance from a track profile file (XML or STF) or canned.
253-
/// (Precedence is XML [.XML], STF [.DAT], default [canned]).
252+
/// Creates a List<TRPFile></TRPFile> instance from a set of track profile file(s)
253+
/// (XML or STF) or canned. (Precedence is XML [.XML], STF [.DAT], default [canned]).
254254
/// </summary>
255255
/// <param name="viewer">Viewer.</param>
256256
/// <param name="routePath">Path to route.</param>
@@ -263,14 +263,36 @@ public static void CreateTrackProfile(Viewer viewer, string routePath, out List<
263263

264264
if (Directory.Exists(path))
265265
{
266+
// The file called "TrProfile" should be used as the default track profile, if present
267+
string xmlDefault = path + @"\TrProfile.xml";
268+
string stfDefault = path + @"\TrProfile.stf";
269+
270+
if (File.Exists(xmlDefault))
271+
{
272+
trpFiles.Add(new TRPFile(viewer, xmlDefault));
273+
profileNames.Add(Path.GetFileNameWithoutExtension(xmlDefault));
274+
}
275+
else if (File.Exists(stfDefault))
276+
{
277+
trpFiles.Add(new TRPFile(viewer, stfDefault));
278+
profileNames.Add(Path.GetFileNameWithoutExtension(stfDefault));
279+
}
280+
else // Add the canned (Kuju) track profile if no default is given
281+
trpFiles.Add(new TRPFile(viewer, ""));
282+
266283
// Get all .xml/.stf files that start with "TrProfile"
267284
string[] xmlProfiles = Directory.GetFiles(path, "TrProfile*.xml");
268285
string[] stfProfiles = Directory.GetFiles(path, "TrProfile*.stf");
269286

270287
foreach (string xmlProfile in xmlProfiles)
271288
{
272-
trpFiles.Add(new TRPFile(viewer, xmlProfile));
273-
profileNames.Add(Path.GetFileNameWithoutExtension(xmlProfile));
289+
string xmlName = Path.GetFileNameWithoutExtension(xmlProfile);
290+
// Don't try to add the default track profile twice
291+
if (!profileNames.Contains(xmlName))
292+
{
293+
trpFiles.Add(new TRPFile(viewer, xmlProfile));
294+
profileNames.Add(xmlName);
295+
}
274296
}
275297
foreach (string stfProfile in stfProfiles)
276298
{
@@ -284,7 +306,7 @@ public static void CreateTrackProfile(Viewer viewer, string routePath, out List<
284306
}
285307
}
286308

287-
// Add default profile only if no other profiles were added
309+
// Add canned profile if no profiles were found
288310
if (trpFiles.Count <= 0)
289311
trpFiles.Add(new TRPFile(viewer, ""));
290312

Source/RunActivity/Viewer3D/Scenery.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,28 +678,30 @@ public static int GetBestTrackProfile(Viewer viewer, SharedShape shape)
678678
TRPFile.CreateTrackProfile(viewer, viewer.Simulator.RoutePath, out viewer.TRPs);
679679
}
680680

681-
float score = 0;
681+
float score = float.NegativeInfinity;
682682
int bestIndex = -1;
683683
for (int i = 0; i < viewer.TRPs.Count; i++)
684684
{
685-
686685
float prevScore = score;
686+
score = 0;
687687
// Default behavior: Attempt to match track shape to track profile using texture names alone
688688
foreach (string image in viewer.TRPs[i].TrackProfile.Images)
689689
{
690690
if (shape.ImageNames.Contains(image, StringComparer.InvariantCultureIgnoreCase))
691691
score++;
692-
else // Slight bias to prefer track profiles with more textures defined
693-
score += 0.05f;
692+
else // Slight bias against track profiles with extra textures defined
693+
score -= 0.05f;
694694
}
695695
foreach (string image in shape.ImageNames)
696696
{
697-
// Bias against track profiles that are missing textures
697+
// Strong bias against track profiles that are missing textures
698698
if (!viewer.TRPs[i].TrackProfile.Images.Contains(image, StringComparer.InvariantCultureIgnoreCase))
699699
score -= 0.25f;
700700
}
701701
if (score > prevScore)
702702
bestIndex = i;
703+
else
704+
score = prevScore;
703705
}
704706

705707
if (bestIndex < 0)

0 commit comments

Comments
 (0)