コード例 #1
0
        //private TiledTexture(DeviceResources deviceResources, int _tilesCount)
        //{
        //    this.deviceResources = deviceResources;
        //    cd16 = (_tilesCount + 15) / 16;
        //    tilesCount = _tilesCount;
        //}

        public TiledTexture(DeviceResources deviceResources, byte[] data, byte[] offsetsData)
        {
            this.deviceResources = deviceResources;
            tilesCount           = offsetsData.Length / 8;
            TilesList            = new List <Vector2Int>(tilesCount);
            if (tilesCount == 0)
            {
                return;
            }
            for (int i = 0; i < tilesCount; i++)
            {
                Vector2Int vector2 = new Vector2Int()
                {
                    x = System.BitConverter.ToInt32(offsetsData, i * 8),
                    y = System.BitConverter.ToInt32(offsetsData, i * 8 + 4)
                };
                TilesList.Add(vector2);
            }
            BlocksData        = new ComputeBuffer(deviceResources, tilesCount, 1024, data);
            BlocksOffsetsData = new ComputeBuffer(deviceResources, tilesCount, 8, offsetsData);
            tileRect          = new TileRect(TilesList);
            TilesStatus       = new TileIndexCollection(tileRect);
            for (int i = 0; i < TilesList.Count; i++)
            {
                TilesStatus.Add(TilesList[i], i);
            }
        }
コード例 #2
0
        public TiledTexture(TiledTexture tiledTexture, List <Vector2Int> tiles)
        {
            deviceResources = tiledTexture.deviceResources;
            tilesCount      = tiles.Count;
            TilesList       = new List <Vector2Int>(tiles);
            List <int> indexs = new List <int>();

            if (tilesCount == 0)
            {
                return;
            }
            //for (int i = 0; i < tilesCount; i++)
            //{
            //    TilesStatus.Add(TilesList[i], i);
            //}

            for (int i = 0; i < tilesCount; i++)
            {
                //if (tiledTexture.TilesStatus.TryGetValue(tiles[i], out int tIndex))
                //{
                //    indexs.Add(tIndex);
                //}
                //else
                //{
                //    indexs.Add(magicNumber);
                //}
                int tIndex = tiledTexture.TilesStatus[tiles[i]];
                if (tIndex != -1)
                {
                    indexs.Add(tIndex);
                }
                else
                {
                    indexs.Add(magicNumber);
                }
            }
            BlocksOffsetsData = new ComputeBuffer(deviceResources, tilesCount, 8, tiles.ToArray());
            BlocksData        = new ComputeBuffer(deviceResources, tilesCount, 1024);
            if (tiledTexture.BlocksData != null)
            {
                ComputeBuffer indicates = new ComputeBuffer(deviceResources, tilesCount, 4, indexs.ToArray());
                TTPartCopy.SetBuffer(tiledTexture.BlocksData, 0);
                TTPartCopy.SetBuffer(indicates, 1);
                TTPartCopy.SetUAVBuffer(BlocksData, 0);

                TTPartCopy.Dispatch(1, 1, tilesCount);
                indicates.Dispose();
            }
            tileRect    = new TileRect(TilesList);
            TilesStatus = new TileIndexCollection(tileRect);
            for (int i = 0; i < TilesList.Count; i++)
            {
                TilesStatus.Add(TilesList[i], i);
            }
        }
コード例 #3
0
        public TiledTexture(RenderTexture tex)
        {
            deviceResources = tex.GetDeviceResources();
            int width    = tex.GetWidth();
            int height   = tex.GetHeight();
            int x        = (width + 31) / 32;
            int y        = (height + 31) / 32;
            int x2       = (width + 7) / 8;
            int y2       = (height + 7) / 8;
            int tilesmax = x2 * y2;

            int[]         oData   = new int[tilesmax];
            ComputeBuffer tResult = new ComputeBuffer(deviceResources, tilesmax, 4);

            TextureEmptyTest.SetTexture(tex, 0);
            TextureEmptyTest.SetUAVBuffer(tResult, 0);
            TextureEmptyTest.Dispatch(x2, y2, 1);
            tResult.GetData(oData);
            tResult.Dispose();
            TilesList = new List <Vector2Int>();
            for (int i = 0; i < tilesmax; i++)
            {
                if (oData[i] != 0)
                {
                    Vector2Int a = new Vector2Int()
                    {
                        x = (i % x2) * 8, y = (i / x2) * 8
                    };
                    TilesList.Add(a);
                }
            }
            tilesCount = TilesList.Count;
            if (tilesCount == 0)
            {
                return;
            }

            BlocksData = new ComputeBuffer(tex.GetDeviceResources(), tilesCount, 1024);

            BlocksOffsetsData = new ComputeBuffer(tex.GetDeviceResources(), tilesCount, 8, TilesList.ToArray());

            Texture2TT.SetTexture(tex, 0);
            Texture2TT.SetBuffer(BlocksOffsetsData, 1);
            Texture2TT.SetUAVBuffer(BlocksData, 0);
            Texture2TT.Dispatch(1, 1, tilesCount);
            tileRect    = new TileRect(TilesList);
            TilesStatus = new TileIndexCollection(tileRect);
            for (int i = 0; i < TilesList.Count; i++)
            {
                TilesStatus.Add(TilesList[i], i);
            }
        }
コード例 #4
0
        public TiledTexture(RenderTexture tex, List <Vector2Int> tiles)
        {
            deviceResources   = tex.GetDeviceResources();
            tilesCount        = tiles.Count;
            BlocksData        = new ComputeBuffer(deviceResources, tilesCount, 1024);
            BlocksOffsetsData = new ComputeBuffer(deviceResources, tilesCount, 8, tiles.ToArray());
            Texture2TT.SetTexture(tex, 0);
            Texture2TT.SetBuffer(BlocksOffsetsData, 1);
            Texture2TT.SetUAVBuffer(BlocksData, 0);
            Texture2TT.Dispatch(1, 1, tilesCount);

            TilesList   = new List <Vector2Int>(tiles);
            tileRect    = new TileRect(TilesList);
            TilesStatus = new TileIndexCollection(tileRect);
            for (int i = 0; i < TilesList.Count; i++)
            {
                TilesStatus.Add(TilesList[i], i);
            }
        }