@@ -300,6 +300,14 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
300300 }
301301 }
302302
303+ // Generate track profiles if none have been set up yet
304+ if ( viewer . TRPs == null )
305+ {
306+ Trace . Write ( " TRP" ) ;
307+ // Creates profile and loads materials into SceneryMaterials
308+ TRPFile . CreateTrackProfile ( viewer , viewer . Simulator . RoutePath , out viewer . TRPs ) ;
309+ }
310+
303311 // create all the individual scenery objects specified in the WFile
304312 foreach ( var worldObject in WFile . Tr_Worldfile )
305313 {
@@ -369,25 +377,15 @@ public WorldFile(Viewer viewer, int tileX, int tileZ, bool visible)
369377 {
370378 if ( viewer . Simulator . UseSuperElevation > 0 )
371379 SuperElevationManager . DecomposeStaticSuperElevation ( viewer , dTrackList , trackObj , worldMatrix , TileX , TileZ , shapeFilePath ) ;
372- var newScenery = new SwitchTrackShape ( viewer , shapeFilePath , worldMatrix , trJunctionNode ) ;
373- sceneryObjects . Add ( newScenery ) ;
374-
375- string newShapeName = Path . GetFileName ( newScenery . SharedShape . FilePath ) ;
376- if ( ! viewer . TrackProfileIndicies . ContainsKey ( newShapeName ) )
377- viewer . TrackProfileIndicies . Add ( newShapeName , GetBestTrackProfile ( viewer , newScenery . SharedShape ) ) ;
380+ sceneryObjects . Add ( new SwitchTrackShape ( viewer , shapeFilePath , worldMatrix , trJunctionNode ) ) ;
378381 }
379382 else
380383 {
381384 //if want to use super elevation, we will generate tracks using dynamic tracks
382385 if ( viewer . Simulator . UseSuperElevation > 0
383386 && SuperElevationManager . DecomposeStaticSuperElevation ( viewer , dTrackList , trackObj , worldMatrix , TileX , TileZ , shapeFilePath ) )
384387 {
385- // Need to load the static shape file to determine which track profile to use
386- var superelevatedShape = viewer . ShapeManager . Get ( shapeFilePath ) ;
387-
388- string newShapeName = Path . GetFileName ( superelevatedShape . FilePath ) ;
389- if ( ! viewer . TrackProfileIndicies . ContainsKey ( newShapeName ) )
390- viewer . TrackProfileIndicies . Add ( newShapeName , GetBestTrackProfile ( viewer , superelevatedShape ) ) ;
388+ // No need to add shapes for this segment of track
391389 }
392390 //otherwise, use shapes
393391 else if ( ! containsMovingTable ) sceneryObjects . Add ( new StaticTrackShape ( viewer , shapeFilePath , worldMatrix ) ) ;
@@ -664,52 +662,6 @@ public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
664662 forest . PrepareFrame ( frame , elapsedTime ) ;
665663 }
666664
667- /// <summary>
668- /// Determines the index of the track profile that would be the most suitable replacement
669- /// for the given shared shape object.
670- /// </summary>
671- public static int GetBestTrackProfile ( Viewer viewer , SharedShape shape )
672- {
673- if ( viewer . TRPs == null )
674- {
675- // First to need a track profile creates it
676- Trace . Write ( " TRP" ) ;
677- // Creates profile and loads materials into SceneryMaterials
678- TRPFile . CreateTrackProfile ( viewer , viewer . Simulator . RoutePath , out viewer . TRPs ) ;
679- }
680-
681- float score = float . NegativeInfinity ;
682- int bestIndex = - 1 ;
683- for ( int i = 0 ; i < viewer . TRPs . Count ; i ++ )
684- {
685- float prevScore = score ;
686- score = 0 ;
687- // Default behavior: Attempt to match track shape to track profile using texture names alone
688- foreach ( string image in viewer . TRPs [ i ] . TrackProfile . Images )
689- {
690- if ( shape . ImageNames . Contains ( image , StringComparer . InvariantCultureIgnoreCase ) )
691- score ++ ;
692- else // Slight bias against track profiles with extra textures defined
693- score -= 0.05f ;
694- }
695- foreach ( string image in shape . ImageNames )
696- {
697- // Strong bias against track profiles that are missing textures
698- if ( ! viewer . TRPs [ i ] . TrackProfile . Images . Contains ( image , StringComparer . InvariantCultureIgnoreCase ) )
699- score -= 0.25f ;
700- }
701- if ( score > prevScore )
702- bestIndex = i ;
703- else
704- score = prevScore ;
705- }
706-
707- if ( bestIndex < 0 )
708- return 0 ;
709- else
710- return bestIndex ;
711- }
712-
713665 /// <summary>
714666 /// MSTS WFiles represent some location with a position, quaternion and tile coordinates
715667 /// This converts it to the ORTS WorldPosition representation
0 commit comments