Exemplo n.º 1
0
    protected bool TryLoadFromCache(Tile tile)
    {
        if (!cacheElevations)
        {
            return(false);
        }

        byte[] data = OnlineMapsCache.Get(tile.GetCacheKey(cachePrefix));
        if (data == null || data.Length != tileWidth * tileHeight * 2)
        {
            return(false);
        }

        short[,] elevations = new short[tileWidth, tileHeight];
        int dataIndex = 0;

        for (int y = 0; y < tileHeight; y++)
        {
            for (int x = 0; x < tileWidth; x++)
            {
                elevations[x, y] = (short)((data[dataIndex + 1] << 8) + data[dataIndex]);
                dataIndex       += 2;
            }
        }

        SetElevationData(tile, elevations);
        return(true);
    }