@@ -376,20 +376,22 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
376376 // We might not have found the junction node; if so, fall back to the static track shape.
377377 if ( trJunctionNode != null )
378378 {
379+ // Handle superelevation on junctions (usually this means disabling it)
379380 if ( viewer . Simulator . UseSuperElevation )
380- SuperElevationManager . DecomposeStaticSuperElevation ( viewer , dTrackList , trackObj , worldMatrix , TileX , TileZ , shapeFilePath ) ;
381+ SuperElevationManager . PrepareStaticSuperElevation ( viewer , trackObj , TileX , TileZ , shapeFilePath ) ;
381382 sceneryObjects . Add ( new SwitchTrackShape ( viewer , shapeFilePath , worldMatrix , trJunctionNode ) ) ;
382383 }
383384 else
384385 {
385- //if want to use super elevation, we will generate tracks using dynamic tracks
386+ // See if superelevation should be used on this piece of track
386387 if ( viewer . Simulator . UseSuperElevation
387- && SuperElevationManager . DecomposeStaticSuperElevation ( viewer , dTrackList , trackObj , worldMatrix , TileX , TileZ , shapeFilePath ) )
388+ && SuperElevationManager . PrepareStaticSuperElevation ( viewer , trackObj , TileX , TileZ , shapeFilePath ) )
388389 {
389- // No need to add shapes for this segment of track
390+ // Don't add scenery for this section of track, dynamic superelevated track will be created instead
390391 }
391- //otherwise, use shapes
392- else if ( ! containsMovingTable ) sceneryObjects . Add ( new StaticTrackShape ( viewer , shapeFilePath , worldMatrix ) ) ;
392+ // No superelevation, use shapes
393+ else if ( ! containsMovingTable )
394+ sceneryObjects . Add ( new StaticTrackShape ( viewer , shapeFilePath , worldMatrix ) ) ;
393395 else
394396 {
395397 var found = false ;
@@ -429,22 +431,24 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
429431 }
430432 else if ( worldObject . GetType ( ) == typeof ( DyntrackObj ) )
431433 {
434+ // Dynamic track will require track profiles, set up track profiles if not yet set
432435 if ( viewer . TRPs == null )
433436 {
434- // First to need a track profile creates it
435437 Trace . Write ( " TRP" ) ;
436- // Creates profile and loads materials into SceneryMaterials
438+ // Creates profile(s) and loads materials into SceneryMaterials
437439 TRPFile . CreateTrackProfile ( viewer , viewer . Simulator . RoutePath , out viewer . TRPs ) ;
438440 }
439441
440442 if ( viewer . Simulator . Settings . Wire == true && viewer . Simulator . TRK . Tr_RouteFile . Electrified == true )
441443 Wire . DecomposeDynamicWire ( viewer , dTrackList , ( DyntrackObj ) worldObject , worldMatrix ) ;
442444 // Add DyntrackDrawers for individual subsections
443- if ( viewer . Simulator . UseSuperElevation && SuperElevationManager . UseSuperElevationDyn ( viewer , dTrackList , ( DyntrackObj ) worldObject , worldMatrix ) )
445+ if ( viewer . Simulator . UseSuperElevation && SuperElevationManager . UseSuperElevationDyn ( ( DyntrackObj ) worldObject ) )
444446 SuperElevationManager . DecomposeDynamicSuperElevation ( viewer , dTrackList , ( DyntrackObj ) worldObject , worldMatrix ) ;
445- else DynamicTrack . Decompose ( viewer , dTrackList , ( DyntrackObj ) worldObject , worldMatrix ) ;
447+ else
448+ DynamicTrack . Decompose ( viewer , dTrackList , ( DyntrackObj ) worldObject , worldMatrix ) ;
446449
447- } // end else if DyntrackObj
450+ }
451+ // Objects other than tracks
448452 else if ( worldObject . GetType ( ) == typeof ( ForestObj ) )
449453 {
450454 if ( ! ( worldObject as ForestObj ) . IsYard )
@@ -593,8 +597,9 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
593597 }
594598 }
595599
596- if ( viewer . Simulator . UseSuperElevation ) SuperElevationManager . DecomposeStaticSuperElevation ( Viewer , dTrackList , TileX , TileZ ) ;
597- if ( Viewer . World . Sounds != null ) Viewer . World . Sounds . AddByTile ( TileX , TileZ ) ;
600+ if ( viewer . Simulator . UseSuperElevation )
601+ SuperElevationManager . DecomposeTileSuperElevation ( Viewer , dTrackList , TileX , TileZ ) ;
602+ Viewer . World . Sounds ? . AddByTile ( TileX , TileZ ) ;
598603 }
599604
600605 /// <summary>
0 commit comments