Esempio n. 1
0
        /// <summary>
        /// Unused and probably doesn't work, supposed to do tile redundancy checking
        /// </summary>
        void /*Tuple<OAM_Array, uint>*/ GetOAMfromFile(GBA.Image image)
        {
            /*
             * List<List<OAM>> matches;
             * matches = new List<List<OAM>>();
             * foreach (Tileset sheet in Graphics)
             * {
             *  matches.Add(new List<OAM>());
             * }
             * OAM match;
             * GBA.Tile tile;
             * for (int y = minY; y < maxY; y += 8)
             * for (int x = minX; x < maxX; x += 8)
             * {
             *  tile = image.GetTile(x, y);
             *
             *  if (tile.IsEmpty()) continue;
             *
             *  for (int i = 0; i < Graphics.Count; i++)
             *  {
             *      match = GetMatch(image, x, y, i, Graphics[i].FindMatch(tile));
             *
             *      if (match == null) continue;
             *      else
             *      {
             *          matches[i].Add(match);
             *      }
             *  }
             * }
             *
             * int tileset = 0;
             * string debug = "";
             * for (int i = 0; i < Graphics.Count; i++)
             * {
             *  debug += i + " - " + matches[i].Count + "\n";
             *  if (matches[i].Count > matches[tileset].Count)
             *      tileset = i;
             * }   // select the tileset with the most matches
             * Program.ShowMessage(debug);
             */



            /*
             * bool[,] mapped = new bool[width, height];
             * // create a bool matrix to check what pixels have yet to be put in the tileset
             * for (int y = 0; y < height; y++)
             * for (int x = 0; x < width; x++)
             * {
             *  if (image[minX + x, minY + y] == image.Colors[0])
             *  {
             *      mapped[x, y] = true;
             *  }
             * }   // all bg-color pixels are marked as mapped
             *
             * Size size;
             * Point pos;
             * for (int i = 0; i < matches[tileset].Count; i++)
             * {
             *  pos = matches[tileset][i].Position;
             *  size = matches[tileset][i].GetDimensions();
             *  int X, Y;
             *  for (int y = 0; y < size.Height; y++)
             *  for (int x = 0; x < size.Width; x++)
             *  {
             *      for (int tileY = 0; tileY < 8; tileY++)
             *      for (int tileX = 0; tileX < 8; tileX++)
             *      {
             *          X = (pos.X + 0x94 - minX) + (x * 8 + tileX);
             *          Y = (pos.Y - minY) + (y * 8 + tileY);
             *          mapped[X, Y] = true;
             *      }
             *  }
             * }
             */



            /*
             * int tileset = Graphics.Count - 1;
             * string debug = "\n tileset " + tileset + ": \n";
             * for (int y = 0; y < 8; y++)
             * {
             *  for (int x = 0; x < 32; x++)
             *  {
             *      debug += (Graphics[tileset][1 + x + y * 32] != null) ? "O" : ",_,";
             *  }
             *  debug += "\n";
             * }
             * Program.ShowMessage(debug);
             */
            // (matches[tileset].Count == 0) ? -1 : tileset);
            //Program.ShowMessage("added oam: " + new_oam.Count);
        }
Esempio n. 2
0
        /// <summary>
        /// Supposed to check other OAMs in the sheet to avoid redundancy - currently unused
        /// </summary>
        OAM GetMatch(GBA.Image image, int imageX, int imageY, int tileset, Tuple <Point, bool, bool> match, ref List <TileSheet> Graphics)
        {
            if (match == null)
            {
                return(OAM.Terminator);
            }

            bool[,] matched = new bool[8, 8];
            Point sheet = match.Item1;
            bool  flipH = match.Item2;
            bool  flipV = match.Item3;
            Tile  tile;

            for (int tileY = 0; flipV ? (tileY > -8) : (tileY < 8); tileY += flipV ? -1 : 1)
            {
                for (int tileX = 0; flipH ? (tileX > -8) : (tileX < 8); tileX += flipH ? -1 : 1)
                {
                    if (tileX == 0 && tileY == 0)
                    {
                        continue;
                    }
                    // top-left corner tile of OAM obj has already been matched
                    try
                    {
                        if (Graphics[tileset][sheet.X + tileX, sheet.Y + tileY] == null)
                        {
                            continue;
                        }

                        tile = image.GetTile(imageX + tileX * 8, imageY + tileY * 8);
                    }
                    catch { break; }

                    if (flipH)
                    {
                        tile = tile.FlipHorizontal();
                    }
                    if (flipV)
                    {
                        tile = tile.FlipVertical();
                    }

                    if (tile.Equals(Graphics[tileset][sheet.X + tileX, sheet.Y + tileY]))
                    {
                        matched[Math.Abs(tileX), Math.Abs(tileY)] = true;
                    }
                }
            }

            var shapesize = OAM.GetShapeSize(GetSpriteSize(matched));

            if (shapesize == null)
            {
                return(OAM.Terminator);
            }

            return(new OAM(
                       shapesize.Item1,
                       shapesize.Item2,
                       (Int16)(imageX - 0x94), (Int16)(imageY),
                       0x00,
                       0x00,
                       OAM_GFXMode.Normal,
                       OAM_OBJMode.Normal,
                       false,
                       false,
                       (byte)sheet.X, (byte)sheet.Y,
                       flipH, flipV));
        }
Esempio n. 3
0
        public OAM_Maker(ref List <TileSheet> Graphics, GBA.Image image, int offsetX, int offsetY)
        {
            Rectangle sprite = GetSpriteArea(image);

            if (sprite == new Rectangle())
            {
                TilesetIndex = 0;
                SpriteData   = new OAM_Array();
                return;
            }

            var OAMs = GetSpriteOAMs(image, sprite);

            TilesetIndex = -1;
            Point[] sheet = new Point[OAMs.Count];
            for (int i = 0; i < Graphics.Count; i++)
            {
                sheet = Graphics[i].CheckIfFits(OAMs);

                if (sheet == null)
                {
                    continue;
                }
                else
                {
                    TilesetIndex = i; break;
                }
            }
            if (TilesetIndex == -1)
            {
                TilesetIndex = Graphics.Count;
                Graphics.Add(new TileSheet(32, 8));
                sheet = Graphics[TilesetIndex].CheckIfFits(OAMs);
                if (sheet == null)
                {
                    throw new Exception("Frame has more tiles than a 32x8 TileSheet allows.");
                }
            }

            List <OAM> result = new List <OAM>();
            Point      pos;
            Size       size;

            for (int i = 0; i < OAMs.Count; i++)
            {
                pos  = OAMs[i].Item1;
                size = OAMs[i].Item2;

                for (int y = 0; y < size.Height; y++)
                {
                    for (int x = 0; x < size.Width; x++)
                    {
                        Graphics[TilesetIndex][sheet[i].X + x, sheet[i].Y + y] = image.GetTile(
                            pos.X + x * Tile.SIZE,
                            pos.Y + y * Tile.SIZE);
                    }
                }

                var shapesize = OAM.GetShapeSize(size);
                if (shapesize == null)
                {
                    throw new Exception("Invalid OAM Shape/Size created.");
                }

                if (result.Count == MAXIMUM)
                {
                    throw new Exception("There cannot be more than " + MAXIMUM + " OAM objects in one frame.");
                }
                result.Add(new OAM(
                               shapesize.Item1,
                               shapesize.Item2,
                               (Int16)(pos.X - offsetX),
                               (Int16)(pos.Y - offsetY),
                               0x00,
                               0x00,
                               OAM_GFXMode.Normal,
                               OAM_OBJMode.Normal,
                               false,
                               false,
                               (byte)sheet[i].X, (byte)sheet[i].Y,
                               false, false));

                /*
                 * EmblemMagic.Program.ShowMessage(
                 *  "h: " + size.Width + ", w: " + size.Height +
                 *  '\n' + "shape: " + shapesize.Item1 + ", size: " + shapesize.Item2 +
                 *  '\n' + result[result.Count - 1].SpriteShape + ", " + result[result.Count - 1].SpriteSize +
                 *  '\n' + EmblemMagic.Util.BytesToSpacedHex(result[result.Count - 1].ToBytes())); */
            }

            SpriteData = new OAM_Array(result);
        }