Ejemplo n.º 1
0
 public CellInfoLayerPool(Map map)
 {
     defaultLayer =
         CellLayer <CellInfo> .CreateInstance(
             mpos => new CellInfo(int.MaxValue, int.MaxValue, mpos.ToCPos(map), CellStatus.Unvisited),
             new Size(map.MapSize.X, map.MapSize.Y),
             map.Grid.Type);
 }
Ejemplo n.º 2
0
        public CellLayer <CellInfo> NewLayer(Map map)
        {
            CellLayer <CellInfo> result = null;
            var mapSize = new Size(map.MapSize.X, map.MapSize.Y);

            // HACK: Uses a static cache so that double-ended searches (which have two PathSearch instances)
            // can implicitly share data.  The PathFinder should allocate the CellInfo array and pass it
            // explicitly to the things that need to share it.
            while (cellInfoPool.Count > 0)
            {
                var cellInfo = GetFromPool();
                if (cellInfo.Size != mapSize || cellInfo.Shape != map.TileShape)
                {
                    Log.Write("debug", "Discarding old pooled CellInfo of wrong size.");
                    continue;
                }

                result = cellInfo;
                break;
            }

            if (result == null)
            {
                result = new CellLayer <CellInfo>(map);
            }

            lock (defaultCellInfoLayerSync)
            {
                if (defaultCellInfoLayer == null ||
                    defaultCellInfoLayer.Size != mapSize ||
                    defaultCellInfoLayer.Shape != map.TileShape)
                {
                    defaultCellInfoLayer =
                        CellLayer <CellInfo> .CreateInstance(
                            mpos => new CellInfo(int.MaxValue, int.MaxValue, mpos.ToCPos(map), CellStatus.Unvisited),
                            new Size(map.MapSize.X, map.MapSize.Y),
                            map.TileShape);
                }

                result.CopyValuesFrom(defaultCellInfoLayer);
            }

            return(result);
        }