/// <summary> /// Load the information for a single tile (as in parse the needed .t -file. /// </summary> /// <param name="tileX">The cornerIndexX-value of the tile number</param> /// <param name="tileZ">The cornerIndexZ-value of the tile number</param> /// <param name="loTiles">Loading LO tile (Distant Mountain) or not</param> /// <returns>The tile information as a 'Tile' object</returns> private Tile LoadTile(int tileX, int tileZ, bool loTiles) { TileName.Zoom zoom = loTiles ? TileName.Zoom.DMSmall : TileName.Zoom.Small; string path = loTiles ? this.lotilesPath : this.tilesPath; // Note, code is similar to ORTS.Viewer3D.TileManager.Load // Check for 1x1 or 8x8 tiles. TileName.Snap(ref tileX, ref tileZ, zoom); // we set visible to false to make sure errors are loaded Tile newTile = new Tile(path, tileX, tileZ, zoom, false); if (newTile.Loaded) { return(newTile); } else { // Check for 2x2 or 16x16 tiles. TileName.Snap(ref tileX, ref tileZ, zoom - 1); newTile = new Tile(tilesPath, tileX, tileZ, zoom - 1, false); if (newTile.Loaded) { return(newTile); } } return(null); }
public Tile(string filePath, int tileX, int tileZ, TileName.Zoom zoom, bool visible) { TileX = tileX; TileZ = tileZ; Size = 1 << (15 - (int)zoom); var fileName = filePath + TileName.FromTileXZ(tileX, tileZ, zoom); if (!File.Exists(fileName + ".t")) { // Many tiles adjacent to the visible tile may not be modelled, so a warning is not helpful; // ignore a missing .t file unless it is the currently visible tile. if (visible) { Trace.TraceWarning("Ignoring missing tile {0}.t", fileName); } return; } // T and Y files are expected to exist; F files are optional. try { TFile = new TerrainFile(fileName + ".t"); } catch (Exception error) { Trace.WriteLine(new FileLoadException(fileName + ".t", error)); } try { YFile = new TerrainAltitudeFile(fileName + "_y.raw", SampleCount); } catch (Exception error) { Trace.WriteLine(new FileLoadException(fileName + "_y.raw", error)); } try { if (File.Exists(fileName + "_f.raw")) { FFile = new TerrainFlagsFile(fileName + "_f.raw", SampleCount); } } catch (Exception error) { Trace.WriteLine(new FileLoadException(fileName + "_f.raw", error)); } }
/// <summary> /// Constructs a new TileManager for loading tiles from a specific path, either at high-resolution or low-resolution. /// </summary> /// <param name="filePath">Path of the directory containing the MSTS tiles</param> /// <param name="loTiles">Flag indicating whether the tiles loaded should be high-resolution (2KM and 4KM square) or low-resolution (16KM and 32KM square, for distant mountains)</param> public TileManager(string filePath, bool loTiles) { FilePath = filePath; Zoom = loTiles ? TileName.Zoom.DMSmall : TileName.Zoom.Small; }