コード例 #1
0
        private float[] GetTile(int tx, int ty)
        {
            var key = new Id(tx, ty);

            if (!Cache.ContainsKey(key))
            {
                var data = GetValues(tx * TileSize, ty * TileSize);

                if (Cache.Count() == Capacity)
                {
                    // Evict least recently used tile if cache is full
                    Cache.RemoveFirst();
                }

                // Create tile, put it at the end of tileCache
                var tile = new Tile(tx, ty, data);

                Cache.AddLast(key, tile);

                return(data);
            }
            else
            {
                var tile = Cache.Get(key);

                Cache.Remove(key);
                Cache.AddLast(key, tile);

                return(tile.Data);
            }
        }
コード例 #2
0
ファイル: InputMap.cs プロジェクト: zameran/SpaceW
        private float[] GetTile(int tx, int ty)
        {
            var key = new Id(tx, ty);

            // TODO : Cache initialization...
            if (Cache == null)
            {
                Cache = new DictionaryQueue <Id, Tile>(new EqualityComparerID());
            }

            if (!Cache.ContainsKey(key))
            {
                var data = GetValues(tx * (int)TileSize.x, ty * (int)TileSize.y);

                if (Cache.Count() == Capacity)
                {
                    // Evict least recently used tile if cache is full
                    Cache.RemoveFirst();
                }

                // Create tile, put it at the end of tileCache
                var tile = new Tile(tx, ty, data);

                Cache.AddLast(key, tile);

                return(data);
            }
            else
            {
                var tile = Cache.Get(key);

                Cache.Remove(key);
                Cache.AddLast(key, tile);

                return(tile.Data);
            }
        }