Ejemplo n.º 1
0
        public override TagCompound BuildTag()
        {
            BlockPalette palette = new BlockPalette();

            int[] indexList = new int[Width * Height * Length];

            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Length; z++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        int blockIndex = (y * Length + z) * Width + x;
                        indexList[blockIndex] = palette.GetIndex(_blocks[x, y, z]);
                    }
                }
            }
            int        bits  = (int)Math.Max(4, Math.Ceiling(Math.Log(palette.Count, 2)));
            DenseArray array = new DenseArray(bits, 4096);

            for (int i = 0; i < indexList.Length; i++)
            {
                array[i] = indexList[i];
            }
            return(new TagCompound()
            {
                palette.BuildTag(),
                new TagLongArray("BlockStates", array.RawArray),
                new TagByteArray("BlockLight", _blockLight),
                new TagByteArray("SkyLight", _skyLight),
                new TagByte("Y", (byte)_y)
            });
        }
Ejemplo n.º 2
0
        public IsometricLayer(int sizex, int sizey, bool isObjectPositioningLayer = false)
        {
            Indices = new DenseArray <int>(sizey, sizex);
            map     = IsometricMap.Instance;

            if (isObjectPositioningLayer)
            {
                SetAsObjectPositioningLayer();
            }
        }
Ejemplo n.º 3
0
        public static string RowTransposeEncode(string input, int columns, int[] keysequence)
        {
            StringBuilder     sb     = new StringBuilder();
            int               rows   = input.Length / columns;
            DenseArray <char> matrix = new DenseArray <char>(rows + 1, columns);

            foreach (var key in keysequence)
            {
                var column = matrix.GetColumn(key);
                sb.Append(column);
            }

            return(sb.ToString());
        }
Ejemplo n.º 4
0
        private DenseArray <int> Shift(DenseArray <int> data, int direction)
        {
            DenseArray <int> ret = new DenseArray <int>(data.Rows, data.Columns);
            int i, j;

            switch (direction)
            {
            case 0:     //up
                for (i = 0; i < 7; i++)
                {
                    for (j = 0; j < 8; j++)
                    {
                        ret[i, j] = data[i + 1, j];
                    }
                }
                break;

            case 1:     //down
                for (i = 1; i < 8; i++)
                {
                    for (j = 0; j < 8; j++)
                    {
                        ret[i, j] = data[i - 1, j];
                    }
                }
                break;

            case 2:     //right
                for (i = 0; i < 8; i++)
                {
                    for (j = 0; j < 7; j++)
                    {
                        ret[i, j] = data[i, j + 1];
                    }
                }
                break;

            case 3:     //left
                for (i = 0; i < 8; i++)
                {
                    for (j = 1; j < 8; j++)
                    {
                        ret[i, j] = data[i, j - 1];
                    }
                }
                break;
            }
            return(ret);
        }
Ejemplo n.º 5
0
Archivo: test.cs Proyecto: mono/gert
	static int Main ()
	{
		Array<double> a = new DenseArray<double> (5, 3, 4, 2);
		Sequence s = new Sequence (-1, 1, a.Size);
		a.Fill (s);
		Array<float> b = a.Map<float> (delegate (double x) {
			return (float) (1000 * Math.Sin (x));
		});

		if (a.Shape == b.Shape)
			return 1;

		for (int i = 0; i < b.Size; ++i)
			if (((float) (1000 * Math.Sin (s [i]))) != b [i])
				continue;
		return 0;
	}
Ejemplo n.º 6
0
        private void Generate_Click(object sender, RoutedEventArgs e)
        {
            DenseArray <int> m = Matrix;

            if (DisRot90.IsChecked == true)
            {
                m = Rotate(Matrix, 90);
            }
            else if (DisRotM90.IsChecked == true)
            {
                m = Rotate(Matrix, 90);
            }
            else if (DisRot180.IsChecked == true)
            {
                m = Flip(Matrix, true);
            }

            int[] rows = new int[8];
            //Rectangle r;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (m[i, j] == 1)
                    {
                        rows[i] += 1 << (7 - j);
                    }
                }
            }

            StringBuilder sb = new StringBuilder("const char matrix[] = {");

            for (int i = 0; i < rows.Length; i++)
            {
                sb.Append(rows[i].ToString());
                if (i != rows.Length - 1)
                {
                    sb.Append(", ");
                }
            }
            sb.Append("};\r\n");
            Tabs.SelectedIndex = 1;
            TbOutput.Text     += sb.ToString();
        }
Ejemplo n.º 7
0
        private DenseArray <int> Rotate(DenseArray <int> data, int angle)
        {
            DenseArray <int> ret = new DenseArray <int>(data.Rows, data.Columns);

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (angle / 90 == 1)
                    {
                        ret[i, j] = data[7 - j, i];
                    }
                    else
                    {
                        ret[i, j] = data[j, 7 - i];
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 8
0
        private DenseArray <int> Flip(DenseArray <int> data, bool horizontal)
        {
            DenseArray <int> ret = new DenseArray <int>(data.Rows, data.Columns);

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (horizontal)
                    {
                        ret[i, j] = data[i, 7 - j];
                    }
                    else
                    {
                        ret[i, j] = data[7 - i, j];
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 9
0
        private DenseArray <int> Invert(DenseArray <int> data)
        {
            DenseArray <int> ret = new DenseArray <int>(data.Rows, data.Columns);

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (data[i, j] == 0)
                    {
                        ret[i, j] = 1;
                    }
                    else
                    {
                        ret[i, j] = 0;
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 10
0
        public override void Load(TagCompound c)
        {
            TagList paletteList = (TagList)c["Palette"];

            long[]     data    = c.GetLongArray("BlockStates");
            BlockSet[] palette = new BlockSet[paletteList.Count];
            for (int i = 0; i < palette.Length; i++)
            {
                TagCompound r     = (TagCompound)paletteList[i];
                IBlock      block = GameData.JavaEdition.GetBlock(r.GetString("Name"));
                if (r.ContainsKey("Properties", TagType.Compound))
                {
                    Dictionary <string, string> ps = new Dictionary <string, string>();
                    foreach (TagString tag in (TagCompound)r["Properties"])
                    {
                        ps.Add(tag.Name, tag.Value);
                    }
                    palette[i] = block.GetBlock(ps);
                }
                else
                {
                    palette[i] = new BlockSet(block, block.DefaultBlockSet.Properties, block.DefaultBlockSet.RuntimeId);
                }
            }
            DenseArray array = new DenseArray(data, data.Length * 64 / 4096);

            for (int y = 0; y < Height; y++)
            {
                for (int z = 0; z < Length; z++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        int blockIndex = (y * Length + z) * Width + x;
                        int val        = array[blockIndex];
                        _blocks[x, y, z] = palette[val].RuntimeId;
                    }
                }
            }
            base.Load(c);
        }
Ejemplo n.º 11
0
        public void CalculateTileProperties()
        {
            //Set tile properties to the same size as the map.
            TileProperties = new DenseArray <TileProperties>(Width, Height);

            //For each item
            var properties = ObjectGroups["TileProperties"];

            foreach (var tiledObject in properties)
            {
                //Create a new item.
                var tileProperties = new TileProperties();

                //Parse properties
                tileProperties = tiledObject.Properties
                                 .Aggregate(tileProperties, (current, tiledObjectProperty) =>
                                            TilePropertyMap[tiledObjectProperty.Key].Invoke(tiledObjectProperty.Value, current));

                //find prositon and store.
                var pos = Isometric.WorldToIsometric(tiledObject.WorldPosition, this);
                TileProperties[(int)pos.X, (int)pos.Y] = tileProperties;
            }
        }
Ejemplo n.º 12
0
 public HeightMap(string name)
 {
     _name  = name;
     _array = new DenseArray(9, 256);
 }
Ejemplo n.º 13
0
        private void ShiftDown_Click(object sender, RoutedEventArgs e)
        {
            DenseArray <int> data = Shift(Matrix, 1);

            Matrix = data;
        }
Ejemplo n.º 14
0
        private void Invert_Click(object sender, RoutedEventArgs e)
        {
            DenseArray <int> data = Invert(Matrix);

            Matrix = data;
        }
Ejemplo n.º 15
0
        private void Rotate90ccw_Click(object sender, RoutedEventArgs e)
        {
            DenseArray <int> data = Rotate(Matrix, -90);

            Matrix = data;
        }
Ejemplo n.º 16
0
        private void FlipY_Click(object sender, RoutedEventArgs e)
        {
            DenseArray <int> data = Flip(Matrix, true);

            Matrix = data;
        }
Ejemplo n.º 17
0
 public HeightMap(string name, long[] longArray)
 {
     _name  = name;
     _array = new DenseArray(longArray.Length * 64 / BasicSize, 256);
 }