public static void DrawInBitmap(this OAMEntry oam, Bitmap bm, Animation.NCER.MappingFormat mapping, GraphicsBank graphics, int xOffset, int yOffset) { if (mapping == Animation.NCER.MappingFormat.CM_2D) { oam.DrawInBitmap2DMapping(bm, graphics, xOffset, yOffset); } else { oam.DrawInBitmap1DMapping(bm, graphics, xOffset, yOffset); } }
private void parseCellBank(Stream stream) { using (var r = new BinaryReader(stream)) { int cellCount = r.ReadUInt16(); var attributes = r.ReadUInt16(); Cells = new List <AnimationCell>(cellCount); uint cellOffset = r.ReadUInt32(); Mapping = (MappingFormat)r.ReadUInt32(); var sectionPtr = r.ReadUInt32(); //2 junk pointers that aren't used stream.Position = cellOffset; int tileIndexShift = ((int)Mapping) & 3; long cellDataSize = (attributes == 1) ? 16 : 8; long oamStart = cellOffset + cellDataSize * cellCount; for (int cellIndex = 0; cellIndex < cellCount; ++cellIndex) { var cell = new AnimationCell(); int numOAMS = r.ReadUInt16(); r.Skip(2); //attributes long oamOffset = r.ReadUInt32(); { long curPos = stream.Position; stream.Position = oamStart + oamOffset; var oams = new List <OAMEntry>(numOAMS); for (int oamIndex = 0; oamIndex < numOAMS; ++oamIndex) { var oam = new OAMEntry(); oam.Load(r, tileIndexShift, 0); oams.Add(oam); } cell.oams = oams; Cells.Add(cell); stream.Position = curPos; } if (attributes == 1) { r.Skip(8); } } } }
private static void DrawInBitmap1DMapping(this OAMEntry oam, Bitmap bm, GraphicsBank graphics, int xOffset, int yOffset) { for (uint tileY = 0; tileY < oam.TilesY; ++tileY) { for (uint tileX = 0; tileX < oam.TilesX; ++tileX) { uint tileIndex = oam.TileIndex; tileIndex += tileX + oam.TilesX * tileY; var tile = graphics.Tiles[tileIndex]; oam.DrawInBitmap(bm, tile, tileX, tileY, xOffset, yOffset); } } }
public static void DrawInBitmap2DMapping(this OAMEntry oam, Bitmap bm, GraphicsBank graphics, int xOffset, int yOffset) { uint baseX = oam.TileIndex % graphics.TilesX; uint baseY = oam.TileIndex / graphics.TilesX; uint subTileWidth = (graphics.TilesX == 0xFFFF) ? oam.TilesX : graphics.TilesX; for (uint tileY = 0; tileY < oam.TilesY; ++tileY) { for (uint tileX = 0; tileX < oam.TilesX; ++tileX) { uint subTileYIndex = baseY + tileY; uint subTileXIndex = baseX + tileX; uint tileIndex = subTileXIndex + subTileYIndex * subTileWidth; var tile = graphics.Tiles[tileIndex]; oam.DrawInBitmap(bm, tile, tileX, tileY, xOffset, yOffset); } } }
private static void DrawInBitmap(this OAMEntry oam, Bitmap bm, Tile tile, uint tileX, uint tileY, int xOffset, int yOffset) { int x = oam.X; if (oam.XFlip) { x += xOffset + Tile.Width * (int)(oam.TilesX - (tileX + 1)); } else { x += xOffset + (int)(Tile.Width * tileX); } int y = oam.Y; if (oam.YFlip) { y += yOffset + Tile.Height * (int)(oam.TilesY - (tileY + 1)); } else { y += yOffset + (int)(Tile.Height * tileY); } tile.DrawInBitmap(bm, x, y, oam.XFlip, oam.YFlip, oam.PaletteIndex); }