示例#1
0
        public BitmapSource GetTile(SymbolID symbolID, GameColor color, int tileSize)
        {
            var key = new TileKey(symbolID, color, tileSize);

            BitmapSource bmp;

            if (m_cache.TryGet(key, out bmp))
            {
                return(bmp);
            }

            int xOffset = GetTileXOffset(tileSize);
            int yOffset = GetTileYOffset(symbolID);

            bmp = new CroppedBitmap(this.Atlas, new Int32Rect(xOffset, yOffset, tileSize, tileSize));

            if (color != GameColor.None)
            {
                var rgb    = color.ToGameColorRGB();
                var wcolor = Color.FromRgb(rgb.R, rgb.G, rgb.B);
                bmp = ColorizeBitmap(bmp, wcolor);
            }

            bmp.Freeze();

            m_cache.Add(key, bmp);

            return(bmp);
        }
        public override void Do()
        {
            this.m_oldFocus = FPGA.FPGA.Instance.Current;
            Tile current = FPGA.FPGA.Instance.Current;

            Types.Direction direction = Types.ParseDirectionFromString(this.DirectionString);

            while (true)
            {
                TileKey targetKey = V5Navigator.GetDestination(current, direction, 1);
                if (!FPGA.FPGA.Instance.Contains(targetKey))
                {
                    throw new ArgumentException("Left FPGA during navigation from " + current + " in direction " + direction);
                }

                current = FPGA.FPGA.Instance.GetTile(targetKey);
                if (!FPGA.FPGA.Instance.Contains(current.TileKey))
                {
                    throw new ArgumentException("Leaving FPGA");
                }
                if (current.Location.StartsWith(this.TargetPrefix))
                {
                    FPGA.FPGA.Instance.Current = current;
                    break;
                }
            }
        }
示例#3
0
        GetUniqueTilesPositions(int[,] bitmap, int tilewidth, int tileheight)
        {
            int    w = bitmap.GetLength(0);
            int    h = bitmap.GetLength(1);
            int    l;
            Index2 extent = new Index2(tilewidth, tileheight);
            ConcurrentQueue <TileKey>           ts            = new ConcurrentQueue <TileKey>();
            ConcurrentDictionary <TileKey, int> remainingVals = new ConcurrentDictionary <TileKey, int>();
            Tuple <ConcurrentDictionary <TileKey, int>, ConcurrentDictionary <TileKey, TileKey> > ret = null;

            using (MemoryBuffer2D <int> bpbuffer = HardwareAcceleratorManager.GPUAccelerator.Allocate <int>(w, h))
            {
                bpbuffer.CopyFrom(bitmap, Index2.Zero, Index2.Zero, bpbuffer.Extent);
                w /= tilewidth;
                h /= tileheight;
                l  = w * h;
                Parallel.For(0, l, ind =>
                {
                    int i1     = ind % w;
                    int j1     = ind / w;
                    TileKey k1 = new TileKey(i1, j1, w);
                    if (!TileIsBlank.Execute(extent, bpbuffer, new Index2(i1 * tilewidth, j1 * tileheight)))
                    {
                        remainingVals.TryAdd(k1, ind);
                    }
                });

                ret = CheckRepeatedKernel.Execute(remainingVals, bpbuffer, extent.X, extent.Y);
            }

            return(ret);
        }
示例#4
0
        /// <summary>
        /// Computes the base value for placing a tile, that is, before multipliers or modifications.
        /// </summary>
        /// <param name="tileOrWallType">The tile type or wall.</param>
        /// <param name="miningTargetType">Type of tile data, either tile or wall.</param>
        /// <returns>Base value in generic units.</returns>
        public decimal GetBasePlacingValue(ushort tileOrWallType, TileSubTarget miningTargetType, string group)
        {
            var key = new TileKey(tileOrWallType, miningTargetType);

            //check group overrides first
            if (!string.IsNullOrWhiteSpace(group))
            {
                if (GroupPlacingOverrides.TryGetValue(group, out var groupPlacingOverride))
                {
                    if (groupPlacingOverride.TryGetValue(key, out var groupValueOverride))
                    {
                        return(groupValueOverride.Value);
                    }
                }
            }

            if (PlacingOverrides.TryGetValue(key, out var valueOverride))
            {
                return(valueOverride.Value);
            }
            else
            {
                return(DefaultPlacingValue);
            }
        }
示例#5
0
        protected override void DoCommandAction()
        {
            Tile ul = TileSelectionManager.Instance.GetSelectedTile(".*", FPGATypes.Placement.UpperLeft);
            Tile lr = TileSelectionManager.Instance.GetSelectedTile(".*", FPGATypes.Placement.LowerRight);

            for (int x = ul.TileKey.X; x <= lr.TileKey.X; x++)
            {
                for (int y = ul.TileKey.Y; y <= lr.TileKey.Y; y++)
                {
                    TileKey key = new TileKey(x, y);

                    // click done out of fpga range
                    if (!FPGA.FPGA.Instance.Contains(key))
                    {
                        continue;
                    }
                    // add if not added already
                    if (!TileSelectionManager.Instance.IsSelected(key))
                    {
                        TileSelectionManager.Instance.AddToSelection(key, false);
                    }
                }
            }

            TileSelectionManager.Instance.SelectionChanged();
        }
        public static IEnumerable <Location> GetDestinations(Tile start, Port port, bool forward)
        {
            //foreach (Wire wire in start.WireList.GetAllWires().Where(w => (forward ? w.LocalPipIsDriver : !w.LocalPipIsDriver) && w.LocalPip.Equals(port.Name)))
            foreach (Wire wire in start.WireList.GetAllWires(port).Where(w => (forward ? w.LocalPipIsDriver : !w.LocalPipIsDriver)))
            {
                TileKey targetKey = Navigator.GetTargetLocation(start, wire);
                if (FPGA.FPGA.Instance.Contains(targetKey))
                {
                    Tile     target = FPGA.FPGA.Instance.GetTile(targetKey);
                    Location loc    = new Location(target, new Port(wire.PipOnOtherTile));
                    yield return(loc);

                    // return stopovers such as NL1B0 -> NL1E_S0 that are not part of the switch matrix but are part of wire lists
                    foreach (Wire reverseWire in target.WireList.GetAllWires(wire.PipOnOtherTile).
                             Where(rw => !rw.PipOnOtherTile.Equals(port.Name) && !rw.LocalPipIsDriver && wire.XIncr + rw.XIncr == 0 && wire.YIncr + rw.YIncr == 0))
                    {
                        Location returnLoc = new Location(start, new Port(reverseWire.PipOnOtherTile));
                        yield return(returnLoc);
                    }

                    /*
                     * // return stopovers such as NL1B0 -> NL1E_S0 that are not part of the switch matrix but are part of wire lists
                     * foreach (Wire rw in target.WireList.GetAllWires())
                     * {
                     *  if (!rw.PipOnOtherTile.Equals(port.Name) && !rw.LocalPipIsDriver && rw.LocalPip.Equals(wire.PipOnOtherTile) && wire.XIncr + rw.XIncr == 0 && wire.YIncr + rw.YIncr == 0)
                     *  {
                     *      Location returnLoc = new Location(start, new Port(rw.PipOnOtherTile));
                     *      yield return returnLoc;
                     *  }
                     * }*/
                }
            }
        }
示例#7
0
    public List <GridTile> GetTilesAdjacent(TileKey key)
    {
        List <GridTile> AdjacentTiles = new List <GridTile>();

        GridTile _tile;

        _tile = GetTile(key + TileKey.north);
        if (_tile != null)
        {
            AdjacentTiles.Add(_tile);
        }

        _tile = GetTile(key + TileKey.east);
        if (_tile != null)
        {
            AdjacentTiles.Add(_tile);
        }

        _tile = GetTile(key + TileKey.south);
        if (_tile != null)
        {
            AdjacentTiles.Add(_tile);
        }

        _tile = GetTile(key + TileKey.west);
        if (_tile != null)
        {
            AdjacentTiles.Add(_tile);
        }


        return(AdjacentTiles);
    }
        public static TileKey GetDestination(Tile start, FPGATypes.Direction direction, int stepWidth)
        {
            TileKey targetKey;

            if (direction.Equals(FPGATypes.Direction.North))
            {
                targetKey = new TileKey(start.TileKey.X, start.TileKey.Y - stepWidth);
                return(targetKey);
                //return FPGA.FPGA.Instance.GetTile(targetKey);
            }
            else if (direction.Equals(FPGATypes.Direction.South))
            {
                targetKey = new TileKey(start.TileKey.X, start.TileKey.Y + stepWidth);
                return(targetKey);
                //return FPGA.FPGA.Instance.GetTile(targetKey);
            }
            else if (direction.Equals(FPGATypes.Direction.East))
            {
                targetKey = new TileKey(start.TileKey.X + stepWidth, start.TileKey.Y);
                return(targetKey);
                //return FPGA.FPGA.Instance.GetTile(targetKey);
            }
            else if (direction.Equals(FPGATypes.Direction.West))
            {
                targetKey = new TileKey(start.TileKey.X - stepWidth, start.TileKey.Y);
                return(targetKey);
                //return FPGA.FPGA.Instance.GetTile(targetKey);
            }
            else
            {
                throw new Exception("Unknown direction: " + direction);
            }
        }
示例#9
0
    public static TileKey GetDirection(TileKey from, TileKey to)
    {
        TileKey _return = to -= from;

        // needs to be abs?
        _return /= TileKey.Abs(to);
        return(_return);
    }
示例#10
0
    public void SetLocalPositionByKey(TileKey key)
    {
        Vector3 _newPosition = Vector3.zero;

        _newPosition.x = key.X;
        _newPosition.z = key.Z;

        transform.localPosition = _newPosition;
    }
示例#11
0
 public void Init(TileKey key)
 {
     this.Key = key;
     SetLocalPositionByKey(Key);
     if (TileRenderers.Length == 0)
     {
         TileRenderers = GetComponentsInChildren <MeshRenderer>();
     }
 }
示例#12
0
    public GridTile GetTile(TileKey key)
    {
        if (GridTiles.TryGetValue(key, out GridTile _returnTile))
        {
            return(_returnTile);
        }

        return(null);
    }
示例#13
0
    public GridTile AddTileAtKey(TileKey key)
    {
        GridTile _newTile = Instantiate(TilePrefab, transform);

        _newTile.Init(key);
        GridTiles.Add(key, _newTile);
        _newTile.UpdateSurroundingTiles(this);
        return(_newTile);
    }
        public void UpdateStatusStrip(TileKey selectedKey)
        {
            string statusString = "";

            if (FPGA.FPGA.Instance.Contains(selectedKey))
            {
                Tile selectedTile = FPGA.FPGA.Instance.GetTile(selectedKey);
                statusString = selectedTile.Location + " " + selectedKey.ToString();

                if (selectedTile.Slices.Count > 0)
                {
                    statusString += " (";

                    // only display up to to slice
                    int displayedSlices = Math.Min(2, selectedTile.Slices.Count);
                    for (int i = 0; i < displayedSlices; i++)
                    {
                        statusString += selectedTile.Slices[i].ToString();
                        if (i != selectedTile.Slices.Count - 1)
                        {
                            statusString += ",";
                        }
                    }

                    // add dots for tiles with more than two slices
                    if (selectedTile.Slices.Count > 2)
                    {
                        statusString += "...";
                    }

                    statusString += ") ";
                }
                // 2 element buffer
                m_lastClickedTile      = m_currentlyClickedTile;
                m_currentlyClickedTile = selectedTile;
            }

            // print selection info
            if (StoredPreferences.Instance.PrintSelectionResourceInfo)
            {
                statusString += "Selection contains ";
                statusString += TileSelectionManager.Instance.NumberOfSelectedTiles + " tiles, ";
                int clbs  = 0;
                int brams = 0;
                int dsps  = 0;
                TileSelectionManager.Instance.GetRessourcesInSelection(TileSelectionManager.Instance.GetSelectedTiles(), out clbs, out brams, out dsps);
                int others = TileSelectionManager.Instance.NumberOfSelectedTiles - (clbs + brams + dsps);
                statusString += clbs + " CLBs, ";
                statusString += brams + " BRAMs, and ";
                statusString += dsps + " DPS tiles, and ";
                statusString += others + " other tiles";
            }

            m_statusStripLabelSelectedTile.Text = statusString;
        }
示例#15
0
    public GridTile GetTile(int x, int z)
    {
        TileKey _key = new TileKey(x, z);

        if (GridTiles.TryGetValue(_key, out GridTile _returnTile))
        {
            return(_returnTile);
        }

        return(null);
    }
        private static TileKey GetTargetLocation(Tile start, Wire wire)
        {
            TileKey targetKey = new TileKey(start.TileKey.X + wire.XIncr, start.TileKey.Y + wire.YIncr);

            return(targetKey);

            /*
             * String locationPrefix = Regex.Split(start.Location, @"_X\d+Y\d+")[0];
             * String targetLocationString = locationPrefix + "_X" + (start.LocationX + wire.XIncr) + "Y" + (start.LocationY + wire.YIncr);
             * return targetLocationString;
             */
        }
        public static bool DestinationAndWireExists(Tile start, Wire wire)
        {
            TileKey targetKey = Navigator.GetTargetLocation(start, wire);

            if (!FPGA.FPGA.Instance.Contains(targetKey))
            {
                return(false);
            }

            Tile target = FPGA.FPGA.Instance.GetTile(targetKey);

            return(target.SwitchMatrix.Contains(wire.PipOnOtherTile));
        }
示例#18
0
    public static TileKey Abs(TileKey value)
    {
        if (value.X < 0)
        {
            value.X *= -1;
        }
        if (value.Z < 0)
        {
            value.Z *= -1;
        }

        return(value);
    }
示例#19
0
    public static int GetDirectionIndex(TileKey from, TileKey to)
    {
        TileKey _directionKey = GetDirection(from, to);

        TileKey[] Surroundingkeys = Types.SurroundingKeys;
        for (int i = 0; i < Surroundingkeys.Length; i++)
        {
            if (Surroundingkeys[i] == _directionKey)
            {
                return(i);
            }
        }
        return(-1);
    }
        public static Tile GetDestinationByWire(Tile start, Wire wire)
        {
            TileKey targetKey = Navigator.GetTargetLocation(start, wire);

            if (FPGA.FPGA.Instance.Contains(targetKey))
            {
                Tile target = FPGA.FPGA.Instance.GetTile(targetKey);
                return(target);
            }
            else
            {
                return(FPGA.FPGA.Instance.GetTile(new TileKey(0, 0)));
            }
        }
        private void m_zoomPictBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            TileKey clickedKey = GetClickedKey(e.X, e.Y);

            if (FPGA.FPGA.Instance.Contains(clickedKey))
            {
                OpenTileView cmd = new OpenTileView
                {
                    X = clickedKey.X,
                    Y = clickedKey.Y
                };
                CommandExecuter.Instance.Execute(cmd);
            }
        }
示例#22
0
        public static Tuple <ConcurrentDictionary <TileKey, int>, ConcurrentDictionary <TileKey, TileKey> > Execute(ConcurrentDictionary <TileKey, int> tiles, ArrayView2D <int> bpBuffer, int tilewidth, int tileheight)
        {
            int[,] ts = new int[tiles.Count, 3];
            int i = 0;

            foreach (var kvp in tiles)
            {
                ts[i, 0] = 0;
                ts[i, 1] = kvp.Key.X;
                ts[i, 2] = kvp.Key.Y;
                i++;
            }
            int tilesperRow = bpBuffer.Extent.X / tilewidth;

            using (MemoryBuffer2D <int> res = HardwareAcceleratorManager.GPUAccelerator.Allocate <int>(ts.GetLength(0), ts.GetLength(1)))
            {
                res.CopyFrom(ts, Index2.Zero, Index2.Zero, res.Extent);

                kernel(new Index2(tiles.Count, tiles.Count), bpBuffer, res, new Index2(tilewidth, tileheight), tilesperRow);
                HardwareAcceleratorManager.GPUAccelerator.Synchronize();

                res.CopyTo(ts, Index2.Zero, Index2.Zero, res.Extent);
            }
            ConcurrentDictionary <TileKey, int>     ret  = new ConcurrentDictionary <TileKey, int>();
            ConcurrentDictionary <TileKey, TileKey> ret2 = new ConcurrentDictionary <TileKey, TileKey>();

            Parallel.For(0, tiles.Count, x =>
            {
                if (ts[x, 0] == 0)
                {
                    ret.TryAdd(new TileKey(ts[x, 1], ts[x, 2], tilesperRow), -1);
                }
                ret2.TryAdd(new TileKey(ts[x, 1], ts[x, 2], tilesperRow), new TileKey((ts[x, 0] - 1) % tilesperRow, (ts[x, 0] - 1) / tilesperRow, tilesperRow));
            });

            foreach (var kvp in ret2)
            {
                if (kvp.Value.X >= 0)
                {
                    TileKey aux = kvp.Value;
                    while (aux.X >= 0)
                    {
                        ret2[kvp.Key] = aux;
                        aux           = ret2[aux];
                    }
                }
            }
            return(new Tuple <ConcurrentDictionary <TileKey, int>, ConcurrentDictionary <TileKey, TileKey> >(ret, ret2));
        }
        private static TileKey GetTargetLocation(Tile start, Wire wire, bool forward = true)
        {
            int x = wire.XIncr;
            int y = wire.YIncr;

            if (!forward)
            {
                x *= -1;
                y *= -1;
            }

            TileKey targetKey = new TileKey(start.TileKey.X + x, start.TileKey.Y + y);

            return(targetKey);
        }
示例#24
0
        protected override void DoCommandAction()
        {
            Tile ul = TileSelectionManager.Instance.GetUserSelectedTile("", UserSelectionType, FPGATypes.Placement.UpperLeft);
            Tile lr = TileSelectionManager.Instance.GetUserSelectedTile("", UserSelectionType, FPGATypes.Placement.LowerRight);

            List <Tile> fenceTiles = new List <Tile>();

            for (int x = ul.TileKey.X - Size; x <= lr.TileKey.X + Size; x++)
            {
                for (int y = ul.TileKey.Y - Size; y <= lr.TileKey.Y + Size; y++)
                {
                    TileKey key = new TileKey(x, y);

                    if (!TileSelectionManager.Instance.IsUserSelected(key, UserSelectionType) && FPGA.FPGA.Instance.Contains(x, y))
                    {
                        Tile t        = FPGA.FPGA.Instance.GetTile(key);
                        bool resMatch =
                            Objects.IdentifierManager.Instance.IsMatch(t.Location, Objects.IdentifierManager.RegexTypes.Interconnect) ||
                            Objects.IdentifierManager.Instance.IsMatch(t.Location, Objects.IdentifierManager.RegexTypes.CLB) ||
                            Objects.IdentifierManager.Instance.IsMatch(t.Location, Objects.IdentifierManager.RegexTypes.DSP) ||
                            Objects.IdentifierManager.Instance.IsMatch(t.Location, Objects.IdentifierManager.RegexTypes.BRAM);
                        // prevent RUG-Creation by only adding "well known" tiles
                        if (resMatch)
                        {
                            fenceTiles.Add(t);
                        }
                    }
                }
            }

            ClearSelection clearCmd = new ClearSelection();

            CommandExecuter.Instance.Execute(clearCmd);

            foreach (Tile t in fenceTiles)
            {
                AddToSelectionLoc addCmd = new AddToSelectionLoc();
                addCmd.Location = t.Location;
                CommandExecuter.Instance.Execute(addCmd);
            }

            ExpandSelection expandCmd = new ExpandSelection();

            CommandExecuter.Instance.Execute(expandCmd);
        }
        protected override void DoCommandAction()
        {
            Regex filter = new Regex(Filter);

            // run form min to max
            int startX = Math.Min(UpperLeftX, LowerRightX);
            int endX   = Math.Max(UpperLeftX, LowerRightX);

            int startY = Math.Min(UpperLeftY, LowerRightY);
            int endY   = Math.Max(UpperLeftY, LowerRightY);

            for (int x = startX; x <= endX; x++)
            {
                for (int y = startY; y <= endY; y++)
                {
                    // click done out of fpga range
                    if (!FPGA.FPGA.Instance.Contains(x, y))
                    {
                        continue;
                    }

                    TileKey key = new TileKey(x, y);

                    Tile t = FPGA.FPGA.Instance.GetTile(key);
                    if (!filter.IsMatch(t.Location))
                    {
                        continue;
                    }

                    //deselect or add the selected tile
                    if (TileSelectionManager.Instance.IsSelected(x, y))
                    {
                        TileSelectionManager.Instance.RemoveFromSelection(key, false);
                    }
                    else
                    {
                        TileSelectionManager.Instance.AddToSelection(key, false);
                    }
                }
            }

            TileSelectionManager.Instance.SelectionChanged();
        }
示例#26
0
    public void GenerateGrid()
    {
#if UNITY_EDITOR
        for (int xindex = 0; xindex < Xtiles; xindex++)
        {
            for (int zindex = 0; zindex < Ztiles; zindex++)
            {
                TileKey  _newKey  = new TileKey(xindex, zindex);
                GridTile _newTile = (GridTile)PrefabUtility.InstantiatePrefab(TilePrefab, transform);
                _newTile.Init(_newKey);
                GridTiles.Add(_newKey, _newTile);
            }
        }

        foreach (KeyValuePair <TileKey, GridTile> item in GridTiles)
        {
            item.Value.SetSurroundingTiles(this);
        }
#endif
    }
示例#27
0
    public void LoadGridFromWorld()
    {
        foreach (var item in GridTiles)
        {
            item.Value.ClearSurroundingTiles(this);
        }
        GridTiles.Clear();

        GridTile[] _tileArray = FindObjectsOfType <GridTile>();

        // inactive gridtiles should not be included in this fetch
        for (int i = _tileArray.Length - 1; i >= 0; i--)
        {
            GridTile _tile = _tileArray[i];

            TileKey _key = GetKeyFromVector(_tile.transform.position);
            if (GridTiles.ContainsKey(_key))
            {
                DestroyImmediate(_tile.gameObject);
                Debug.Log(_key + " destroyed");
                continue;
            }

            Vector3 _position = Vector3.zero;
            _position.x = Mathf.RoundToInt(_key.X);
            _position.z = Mathf.RoundToInt(_key.Z);
            _tile.transform.position = _position;
            _tile.transform.parent   = transform;
            _tile.name = _key.X + " " + _key.Z;
            _tile.Init(_key);

            GridTiles.Add(_key, _tile);
        }


        foreach (KeyValuePair <TileKey, GridTile> item in GridTiles)
        {
            item.Value.SetSurroundingTiles(this);
        }
        Debug.Log(GridTiles.Count);
    }
        public void DeriveTileKeyAndSliceNumber()
        {
            Tile tile = FPGA.FPGA.Instance.GetTile(Location);

            m_tileKey = tile.TileKey;
            // sideeffect with get!
            TileKey key = TileKey;

            Tile where = FPGA.FPGA.Instance.GetTile(Location);
            if (where.HasSlice(SliceName))
            {
                m_sliceNumber = where.GetSliceNumberByName(SliceName);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Warning: Can not find " + SliceName + " on tile " + where.Location);
                Console.ResetColor();
                m_sliceNumber = 0;
            }
        }
示例#29
0
        private FractalTile AllocateTile(TileKey key)
        {
            double edge;

            if (key.LOD < 0)
            {
                edge = 1.0 * ((long)1 << -key.LOD);
            }
            else
            {
                edge = 1.0 / ((long)1 << key.LOD);
            }

            var pos    = new double2(key.X, key.Y);
            var minima = new double2(key.X * edge, key.Y * edge);
            var maxima = new double2((key.X + 1) * edge, (key.Y + 1) * edge);

            var tile = new FractalTile(_fractal, _pool.Get(), minima, maxima, edge < 1e-5);

            _tileCache[key] = tile;
            return(tile);
        }
        public override void Do()
        {
            this.m_oldFocus = FPGA.FPGA.Instance.Current;
            Tile current = FPGA.FPGA.Instance.Current;
            Types.Direction direction = Types.ParseDirectionFromString(this.DirectionString);

            while (true)
            {
                TileKey targetKey = V5Navigator.GetDestination(current, direction, 1);
                if (!FPGA.FPGA.Instance.Contains(targetKey))
                    throw new ArgumentException("Left FPGA during navigation from " + current + " in direction " + direction);

                current = FPGA.FPGA.Instance.GetTile(targetKey);
                if (!FPGA.FPGA.Instance.Contains(current.TileKey))
                {
                    throw new ArgumentException("Leaving FPGA");
                }
                if (System.Text.RegularExpressions.Regex.IsMatch(current.Location, this.Regex))
                {
                    FPGA.FPGA.Instance.Current = current;
                    break;
                }
            }
        }