コード例 #1
0
ファイル: AnimationData.cs プロジェクト: FreeReign/UltimaXNA
        public unsafe AnimationFrame(GraphicsDevice graphics, uint[] palette, BinaryFileReader reader)
        {
            int xCenter = reader.ReadShort();
            int yCenter = reader.ReadShort();

            int width = reader.ReadUShort();
            int height = reader.ReadUShort();

            // Fix for animations with no UltimaData.
            if ((width == 0) || (height == 0))
            {
                m_Texture = null;
                return;
            }

            uint[] data = new uint[width * height];

            int header;

            int xBase = xCenter - 0x200;
            int yBase = (yCenter + height) - 0x200;

            fixed (uint* pData = data)
            {
                uint* dataRef = pData;
                int delta = width;

                int dataRead = 0;

                dataRef += xBase;
                dataRef += (yBase * delta);

                while ((header = reader.ReadInt()) != 0x7FFF7FFF)
                {
                    header ^= DoubleXor;

                    uint* cur = dataRef + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF));
                    uint* end = cur + (header & 0xFFF);

                    int filecounter = 0;
                    byte[] filedata = reader.ReadBytes(header & 0xFFF);

                    while (cur < end)
                        *cur++ = palette[filedata[filecounter++]];

                    dataRead += header & 0xFFF;
                }

                Diagnostics.Metrics.ReportDataRead(dataRead);
            }

            m_Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter);

            m_Texture = new Texture2D(graphics, width, height);
            m_Texture.SetData<uint>(data);
        }
コード例 #2
0
ファイル: AnimationData.cs プロジェクト: FreeReign/UltimaXNA
 private static uint[] getPalette(BinaryFileReader reader)
 {
     uint[] pal = new uint[0x100];
     for (int i = 0; i < 0x100; ++i)
     {
         uint color = reader.ReadUShort();
         pal[i] = 0xff000000 + (
             ((((color >> 10) & 0x1F) * 0xFF / 0x1F)) |
             ((((color >> 5) & 0x1F) * 0xFF / 0x1F) << 8) |
             (((color & 0x1F) * 0xFF / 0x1F) << 16)
             );
     }
     return pal;
 }