public static AnimationFrame[] GetAnimation(BinaryFileReader reader) { uint[] palette = getPalette(reader); // 0x100 * 2 = 0x0200 bytes int read_start = (int)reader.Position; // save file position after palette. int frameCount = reader.ReadInt(); // 0x04 bytes int[] lookups = new int[frameCount]; // frameCount * 0x04 bytes for (int i = 0; i < frameCount; ++i) { lookups[i] = reader.ReadInt(); } AnimationFrame[] frames = new AnimationFrame[frameCount]; for (int i = 0; i < frameCount; ++i) { if (lookups[i] < lookups[0]) { frames[i] = AnimationFrame.Empty; // Fix for broken animations, per issue13 } else { reader.Seek(read_start + lookups[i], SeekOrigin.Begin); frames[i] = new AnimationFrame(m_graphics, palette, reader); } } return frames; }
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); }
public MultiComponentList(BinaryFileReader reader, int count) { int metrics_dataread_start = (int)reader.Position; m_Min = m_Max = Point.Empty; MultiTileEntry[] allTiles = new MultiTileEntry[count]; for (int i = 0; i < count; ++i) { allTiles[i].m_ItemID = reader.ReadShort(); allTiles[i].m_OffsetX = reader.ReadShort(); allTiles[i].m_OffsetY = reader.ReadShort(); allTiles[i].m_OffsetZ = reader.ReadShort(); allTiles[i].m_Flags = reader.ReadInt(); MultiTileEntry e = allTiles[i]; if (e.m_OffsetX < m_Min.X) m_Min.X = e.m_OffsetX; if (e.m_OffsetY < m_Min.Y) m_Min.Y = e.m_OffsetY; if (e.m_OffsetX > m_Max.X) m_Max.X = e.m_OffsetX; if (e.m_OffsetY > m_Max.Y) m_Max.Y = e.m_OffsetY; } m_Center = new Point(-m_Min.X, -m_Min.Y); m_Width = (m_Max.X - m_Min.X) + 1; m_Height = (m_Max.Y - m_Min.Y) + 1; StaticTileList[][] tiles = new StaticTileList[m_Width][]; m_Tiles = new StaticTile[m_Width][][]; for (int x = 0; x < m_Width; ++x) { tiles[x] = new StaticTileList[m_Height]; m_Tiles[x] = new StaticTile[m_Height][]; for (int y = 0; y < m_Height; ++y) tiles[x][y] = new StaticTileList(); } for (int i = 0; i < allTiles.Length; ++i) { int xOffset = allTiles[i].m_OffsetX + m_Center.X; int yOffset = allTiles[i].m_OffsetY + m_Center.Y; tiles[xOffset][yOffset].Add((short)((allTiles[i].m_ItemID & 0x3FFF) + 0x4000), (sbyte)allTiles[i].m_OffsetZ); } for (int x = 0; x < m_Width; ++x) { for (int y = 0; y < m_Height; ++y) { m_Tiles[x][y] = tiles[x][y].ToArray(); // // This is unnecessary, since TileEngine has to sort/resort anyways. // // if (m_Tiles[x][y].Length > 1) // { // Array.Sort(m_Tiles[x][y]); // } } } Diagnostics.Metrics.ReportDataRead((int)reader.Position - metrics_dataread_start); }