/// <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) { TileHelper.Zoom zoom = loTiles ? TileHelper.Zoom.DMSmall : TileHelper.Zoom.Small; string path = loTiles ? this.lotilesPath : this.tilesPath; // Note, code is similar to ORTS.Viewer3D.TileManager.Load // Check for 1x1 or 8x8 tiles. TileHelper.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. TileHelper.Snap(ref tileX, ref tileZ, zoom - 1); newTile = new Tile(tilesPath, tileX, tileZ, zoom - 1, false); if (newTile.Loaded) { return(newTile); } } return(null); }
/// <summary> /// Make sure the Tile and its needed textures are loaded. This means checking if it is already loaded, (or at least tried to load) /// and if it is not loaded, load it. /// </summary> /// <param name="tileX">The cornerIndexX-value of the tile number</param> /// <param name="tileZ">The cornerIndexZ-value of the tile number</param> private void EnsureTileIsLoaded(int tileX, int tileZ) { uint index = this.locationTranslator.TileIndex(tileX, tileZ, 1); if (loadedTerrainTiles.Contains(index)) { return; } loadedTerrainTiles.Add(index); // whatever comes next, there is not need to reload this tile ever again. Tile newTile = LoadTile(tileX, tileZ, false); if (newTile == null) { newTile = LoadTile(tileX, tileZ, true); if (newTile == null) { return; } } uint storeIndex = this.locationTranslator.TileIndex(tileX, tileZ, newTile.Size); if (terrainTiles.ContainsKey(storeIndex)) { // this larger than 1x1 tile has already been loaded from a different tileX and tileZ return; } var newTerrainTile = new TerrainTile2D(newTile, textureManager, locationTranslator); terrainTiles.Add(storeIndex, newTerrainTile); SetTerrainReduction(); }