Skip to content

Commit 759b1a1

Browse files
committed
Add support for DynaTrax
1 parent 20e879b commit 759b1a1

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

Source/Orts.Formats.Msts/TrackSectionsFile.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,18 @@ public SectionIdx(STFReader stf)
182182
STFException.TraceWarning(stf, "Invalid track section " + token);
183183
}
184184
stf.SkipRestOfBlock();
185-
}
186-
public uint NoSections;
185+
}
186+
public SectionIdx(TrackPath path)
187+
{
188+
X = 0;
189+
Y = 0;
190+
Z = 0;
191+
A = 0;
192+
NoSections = path.NoSections;
193+
TrackSections = path.TrackSections;
194+
}
195+
196+
public uint NoSections;
187197
public double X,Y,Z; // Offset
188198
public double A; // Angular offset
189199
public uint[] TrackSections;

Source/RunActivity/Viewer3D/SuperElevation.cs

+19-7
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,35 @@ public static bool DecomposeStaticSuperElevation(Viewer viewer, TrackObj trackOb
6161

6262
TrackShape shape;
6363

64+
bool dontRender = false; // Should this shape be left as a static object?
65+
SectionIdx[] SectionIdxs;
66+
6467
try
6568
{
6669
shape = viewer.Simulator.TSectionDat.TrackShapes.Get(trackObj.SectionIdx);
6770

68-
if (shape.RoadShape == true)
71+
if (shape.RoadShape)
6972
return false; // Roads don't use superelevation, no use in processing them.
73+
74+
// Can't render superelevation on tunnel shapes
75+
dontRender = shape.TunnelShape;
76+
SectionIdxs = shape.SectionIdxs;
7077
}
7178
catch (Exception)
7279
{
73-
return false; // Won't be able to render with superelevation
80+
// Some route-specific shapes (DynaTrax) won't be populated in the TrackShapes list, check the TrackPaths list
81+
if (viewer.Simulator.TSectionDat.TSectionIdx.TrackPaths.TryGetValue(trackObj.SectionIdx, out TrackPath path))
82+
{
83+
// Translate given data into a SectionIdx object that the rest of the method can interpret
84+
// Assumptions: Each piece of DynaTrax is a single section with origin 0, 0, 0 and 0 angle,
85+
// and the entire section of DynaTrax is defined by the track sections given in the track path
86+
SectionIdxs = new SectionIdx[1];
87+
SectionIdxs[0] = new SectionIdx(path);
88+
}
89+
else
90+
return false; // Not enough info, won't be able to render with superelevation
7491
}
7592

76-
SectionIdx[] SectionIdxs = shape.SectionIdxs;
77-
78-
// Can't render superelevation on tunnel shapes
79-
// NOTE: Even if we don't render superelevation, we still need to run through processing to remove superelevation from track sections
80-
bool dontRender = shape.TunnelShape;
8193
// Sometimes junctions get caught here, physics superelevation should be removed for those as well
8294
bool removePhys = false;
8395
// 0 = centered, positive = rotation axis moves to inside of curve, negative = moves to outside of curve

0 commit comments

Comments
 (0)