Exemple #1
0
        public static HeightMapVertex[,] DecodeHeightMap(byte[] HeightData1, byte[] HeightData2)
        {
            HeightMapVertex[,] heightMap = new HeightMapVertex[0x21, 0x41]; //0x21 blank spaces between the 2 vertex sets, unused?

            int offset = 0;

            //Decode heightmap 1
            for (int j = 0; j <= 0x20; j++)
            {
                for (int i = 0; i <= 0x10; i += 2)
                {
                    heightMap[i * 2, j * 2] = DecodeVertex(HeightData1, ref offset,
                                                           (short)(i * 0x100), (short)(j * 0x100));
                }

                for (int i = 1; i <= 0x10; i += 2)
                {
                    heightMap[i * 2, j * 2] = DecodeVertex(HeightData1, ref offset,
                                                           (short)(i * 0x100), (short)(j * 0x100));
                }
            }

            List <HeightMapVertex> UnusedVertices = new List <HeightMapVertex>(); //should be 33

            for (int i = 0; i <= 0x20; i++)
            {
                UnusedVertices.Add(DecodeVertex(HeightData1, ref offset, 0, 0));
            }

            //Decode heightmap 2
            offset = 0;

            for (int j = 0; j < 16; j++)
            {
                for (int i = 0; i < 8; i++)
                {
                    for (int k = 0; k < 16; k++)
                    {
                        int   x, y;
                        short defaultS, defaultT;

                        GetHeightMap2Info(i, j, k, out x, out y);
                        GetDefaultHD2Values(k, out defaultS, out defaultT);
                        HeightMapVertex vertex = DecodeVertex(HeightData2, ref offset,
                                                              (short)(x * 0x80), (short)(y * 0x80));
                        vertex.S        = defaultS;
                        vertex.T        = defaultT;
                        heightMap[x, y] = vertex;
                    }
                }
            }

            return(heightMap);
        }
Exemple #2
0
        public static HeightMapVertex[,] CreateBlankMap()
        {
            HeightMapVertex[,] vertices = new HeightMapVertex[0x21, 0x41];

            for (int j = 0; j < 0x41; j++)
            {
                for (int i = 0; i < 0x21; i++)
                {
                    vertices[i, j] = new HeightMapVertex((short)(i * 0x80), 0, (short)(j * 0x80));
                }
            }

            return(vertices);
        }
Exemple #3
0
        private static void EncodeVertex(HeightMapVertex vertex, List <byte> output,
                                         short defaultX, short defaultZ)
        {
            CommandByte command = new CommandByte();

            command.UseDefaultX = (defaultX == vertex.X);
            command.UseDefaultZ = (defaultZ == vertex.Z);

            List <byte> bytes = new List <byte>();

            if (!command.UseDefaultX)
            {
                //Determine x flags
                if (((ushort)(vertex.X << 8) >> 8) == vertex.X)
                {
                    command.XFlags = CommandByte.ByteReadingType.Read1ByteNoShift;
                    bytes.Add((byte)(vertex.X & 0xff));
                }
                else if ((vertex.X & 0x3fc0) == vertex.X && ((ushort)(vertex.X << 2) >> 2) == vertex.X)
                {
                    command.XFlags = CommandByte.ByteReadingType.Read1ByteShift2;
                    bytes.Add((byte)((vertex.X >> 6) & 0xff));
                }
                else if ((vertex.X & 0x1fe0) == vertex.X && ((ushort)(vertex.X << 3) >> 3) == vertex.X)
                {
                    command.XFlags = CommandByte.ByteReadingType.Read1ByteShift1;
                    bytes.Add((byte)((vertex.X >> 5) & 0xff));
                }
                else
                {
                    command.XFlags = CommandByte.ByteReadingType.Read2Bytes;
                    bytes.Add((byte)((vertex.X >> 8) & 0xff));
                    bytes.Add((byte)(vertex.X & 0xff));
                }
            }

            //Determine y flags
            if (((ushort)(vertex.Y << 8) >> 8) == vertex.Y)
            {
                command.YFlags = CommandByte.ByteReadingType.Read1ByteNoShift;
                bytes.Add((byte)(vertex.Y & 0xff));
            }
            else if ((vertex.Y & 0x03fc) == vertex.Y && ((ushort)(vertex.Y << 6) >> 6) == vertex.Y)
            {
                command.YFlags = CommandByte.ByteReadingType.Read1ByteShift2;
                bytes.Add((byte)((vertex.Y >> 2) & 0xff));
            }
            else if ((vertex.Y & 0x01fe) == vertex.Y && ((ushort)(vertex.Y << 7) >> 7) == vertex.Y)
            {
                command.YFlags = CommandByte.ByteReadingType.Read1ByteShift1;
                bytes.Add((byte)((vertex.Y >> 1) & 0xff));
            }
            else
            {
                command.YFlags = CommandByte.ByteReadingType.Read2Bytes;
                bytes.Add((byte)((vertex.Y >> 8) & 0xff));
                bytes.Add((byte)(vertex.Y & 0xff));
            }

            if (!command.UseDefaultZ)
            {
                //Determine z flags
                if (((ushort)(vertex.Z << 8) >> 8) == vertex.Z)
                {
                    command.ZFlags = CommandByte.ByteReadingType.Read1ByteNoShift;
                    bytes.Add((byte)(vertex.Z & 0xff));
                }
                else if ((vertex.Z & 0x3fc0) == vertex.Z && ((ushort)(vertex.Z << 2) >> 2) == vertex.Z)
                {
                    command.ZFlags = CommandByte.ByteReadingType.Read1ByteShift2;
                    bytes.Add((byte)((vertex.Z >> 6) & 0xff));
                }
                else if ((vertex.Z & 0x1fe0) == vertex.Z && ((ushort)(vertex.Z << 3) >> 3) == vertex.Z)
                {
                    command.ZFlags = CommandByte.ByteReadingType.Read1ByteShift1;
                    bytes.Add((byte)((vertex.Z >> 5) & 0xff));
                }
                else
                {
                    command.ZFlags = CommandByte.ByteReadingType.Read2Bytes;
                    bytes.Add((byte)((vertex.Z >> 8) & 0xff));
                    bytes.Add((byte)(vertex.Z & 0xff));
                }
            }

            bytes.Insert(0, command.GetAsByte());

            output.AddRange(bytes);

            return;
        }