Skip to content

Commit 7a41709

Browse files
committed
Force "TrProfile" to be default profile, improve track profile selection
1 parent 23cff01 commit 7a41709

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)