Beispiel #1
0
            public float GetHeight(WorldLocation location, TileManager tiles, SceneryDrawer scenery)
            {
                location.Normalize();

                // First, ensure we have the tile in question cached.
                var tile = Tiles.FirstOrDefault(t => t.TileX == location.TileX && t.TileZ == location.TileZ);

                if (tile == null)
                {
                    Tiles.Add(tile = new Tile(location.TileX, location.TileZ, Divisions));
                }

                // Remove excess entries.
                if (Tiles.Count > TileCount)
                {
                    Tiles.RemoveAt(0);
                }

                // Now calculate division to query.
                var x = (int)((location.Location.X + 1024) / BlockSize);
                var z = (int)((location.Location.Z + 1024) / BlockSize);

                // If we don't have it cached, load it.
                if (tile.Height[x, z] == float.MinValue)
                {
                    var position = new WorldLocation(location.TileX, location.TileZ, (x + 0.5f) * BlockSize - 1024, 0, (z + 0.5f) * BlockSize - 1024);
                    tile.Height[x, z] = Math.Max(tiles.GetElevation(position), scenery.GetBoundingBoxTop(position, BlockSize));
                    tile.Used++;
                }

                return(tile.Height[x, z]);
            }
Beispiel #2
0
 float Elevation(int x, int z)
 {
     return(TileManager.GetElevation(Tile, PatchX * 16 + x, PatchZ * 16 + z));
 }