public void ToTileMaskContainer(TileMask tm)
 {
     XDisp    = tm.XDispString;
     YDisp    = tm.YDispString;
     SP       = (int)tm.SP;
     PalId    = (int)tm.Palette;
     Size     = tm.Size;
     Priority = (int)tm.Priority;
     FlipX    = tm.FlipX;
     FlipY    = tm.FlipY;
     Tile     = tm.Tile;
 }
示例#2
0
        public TileMask Clone()
        {
            TileMask tm = new TileMask(SP, tile, zoom, flipX, flipY)
            {
                XDisp    = XDisp,
                YDisp    = YDisp,
                palette  = palette,
                Priority = Priority
            };

            tm.tile.IsFullyDirty += tm.tileDirty;
            return(tm);
        }
        static int tilesorter(TileMask tm1, TileMask tm2)
        {
            if (tm1.XDisp < tm2.XDisp)
            {
                return(-1);
            }
            else if (tm1.XDisp > tm2.XDisp)
            {
                return(1);
            }

            if (tm1.YDisp < tm2.YDisp)
            {
                return(-1);
            }
            else if (tm1.YDisp > tm2.YDisp)
            {
                return(1);
            }

            return(0);
        }
        public static Frame FillGFX(Bitmap bp, int midx, int midy, PaletteId pid, ImageNode imn, DynamicSize DZ, Dictionary <Int32, byte> pal)
        {
            Frame f = new Frame()
            {
                Dynamic = true,
                DynSize = DZ,
                MidX    = midx,
                MidY    = midy
            };

            byte[,] gfx = new byte[128, f.DynSize.Height];

            ImageNode[] FollowsX = new ImageNode[imn.Length16];

            ImageNode imnaux = imn;
            ImageNode imnaux2;
            int       next = 0;

            /*
             * while(imnaux != null)
             * {
             *  imnaux2 = imnaux.Father;
             *  while (imnaux2 != null && imnaux.Size == 16)
             *  {
             *      if (imnaux2.Size == 16 && imnaux.Y == imnaux2.Y
             *          && Math.Abs(imnaux.X - imnaux2.X) <= 8)
             *      {
             *          if (imnaux.X < imnaux2.X)
             *          {
             *              FollowsX[next] = imnaux;
             *              FollowsX[next + 1] = imnaux2;
             *          }
             *          else
             *          {
             *              FollowsX[next] = imnaux2;
             *              FollowsX[next + 1] = imnaux;
             *          }
             *          next += 2;
             *      }
             *      imnaux2 = imnaux2.Father;
             *  }
             *  imnaux = imnaux.Father;
             * }*/

            ImageNode[] imns16 = new ImageNode[imn.Length16];
            ImageNode[] imns8  = new ImageNode[imn.Length8];

            imnaux = imn;
            int next16 = 0;
            int next8  = 0;

            while (imnaux != null)
            {
                if (imnaux.Size == 16)
                {
                    if (!FollowsX.Contains(imnaux))
                    {
                        imns16[next16] = imnaux;
                        next16++;
                    }
                }
                else
                {
                    imns8[next8] = imnaux;
                    next8++;
                }
                imnaux = imnaux.Father;
            }

            int w = (f.DynSize.Width / 8);
            int h = (f.DynSize.Height / 8);

            int[]     spaceUsed = new int[w * h];
            int       baseX     = 0;
            int       baseY     = 0;
            Color     c;
            int       bx, by;
            TileMask  tm;
            ImageNode imn1, imn2;

            for (int i = 0; i < FollowsX.Length; i += 2)
            {
                if (FollowsX[i] == null)
                {
                    break;
                }
                imn1 = FollowsX[i];
                imn2 = FollowsX[i + 1];
                if (FollowsX[i + 1].X < FollowsX[i].X)
                {
                    imn1 = FollowsX[i + 1];
                    imn2 = FollowsX[i];
                }
                bx = baseX / 8;
                by = baseY / 8;
                Buffer.BlockCopy(space24x16, 0, spaceUsed, (by / w + (bx % w)) * 4, 12);
                Buffer.BlockCopy(space24x16, 0, spaceUsed, ((by / w) + w + (bx % w)) * 4, 12);
                for (int x = 0; x < 16 && x + baseX < f.DynSize.Width; x++)
                {
                    for (int y = 0; y < 16 && y + baseY < f.DynSize.Height; y++)
                    {
                        c = bp.GetPixel(imn1.X + x, imn1.Y + y);
                        if (c.A == 255)
                        {
                            gfx[baseX + x, baseY + y] = pal[c.ToArgb()];
                        }
                    }
                }
                tm = new TileMask(TileSP.SP23, Tiles16[bx, by], 2, false, false)
                {
                    XDisp    = imn1.X * 2,
                    YDisp    = imn1.Y * 2,
                    Priority = Priority,
                    Palette  = pid
                };
                f.AddTile(tm);
                baseX += 8;
                for (int x = 0; x < 16 && imn1.X + x + 8 < bp.Width && x + baseX < f.DynSize.Width; x++)
                {
                    for (int y = 0; y < 16 && y + baseY < f.DynSize.Height; y++)
                    {
                        c = bp.GetPixel(imn1.X + x + 8, imn1.Y + y);
                        if (c.A == 255)
                        {
                            gfx[baseX + x, baseY + y] = pal[c.ToArgb()];
                        }
                    }
                }
                tm = new TileMask(TileSP.SP23, Tiles16[bx + 1, by], 2, false, false)
                {
                    XDisp    = (imn1.X + 8) * 2,
                    YDisp    = imn1.Y * 2,
                    Priority = Priority,
                    Palette  = pid
                };
                f.AddTile(tm);
                baseX += 16;
                if (baseX >= f.DynSize.Width)
                {
                    baseX  = 0;
                    baseY += 16;
                }
            }
            bool found = false;

            for (int i = 0; i < imns16.Length; i++)
            {
                if (imns16[i] == null)
                {
                    break;
                }
                found = false;
                for (int q = 0; q < h - 1; q++)
                {
                    for (int p = 0; p < w - 1; p++)
                    {
                        if (spaceUsed[q * w + p] == 0 &&
                            spaceUsed[q * w + p + 1] == 0 &&
                            spaceUsed[q * w + p + w] == 0 &&
                            spaceUsed[q * w + p + w + 1] == 0)
                        {
                            found = true;
                            baseX = p * 8;
                            baseY = q * 8;
                            spaceUsed[q * w + p]         = 1;
                            spaceUsed[q * w + p + 1]     = 1;
                            spaceUsed[q * w + p + w]     = 1;
                            spaceUsed[q * w + p + w + 1] = 1;
                            for (int x = 0; x < 16 && x + baseX < f.DynSize.Width && imns16[i].X + x < bp.Width; x++)
                            {
                                for (int y = 0; y < 16 && y + baseY < f.DynSize.Height && imns16[i].Y + y < bp.Height; y++)
                                {
                                    c = bp.GetPixel(imns16[i].X + x, imns16[i].Y + y);
                                    if (c.A == 255)
                                    {
                                        if (pal.ContainsKey(c.ToArgb()))
                                        {
                                            gfx[baseX + x, baseY + y] = pal[c.ToArgb()];
                                        }
                                        else
                                        {
                                            throw new KeyNotFoundException();
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (!found)
                {
                    return(null);
                }
                else
                {
                    bx = baseX / 8;
                    by = baseY / 8;
                    tm = new TileMask(TileSP.SP23, Tiles16[bx, by], 2, false, false)
                    {
                        XDisp    = imns16[i].X * 2,
                        YDisp    = imns16[i].Y * 2,
                        Priority = Priority,
                        Palette  = pid
                    };
                    f.AddTile(tm);
                }
            }

            for (int i = 0; i < imns8.Length; i++)
            {
                if (imns8[i] == null)
                {
                    break;
                }
                found = false;
                for (int p = 0; p < h; p++)
                {
                    for (int q = 0; q < w; q++)
                    {
                        if (spaceUsed[p * w + q] == 0)
                        {
                            found = true;
                            baseX = q * 8;
                            baseY = p * 8;
                            spaceUsed[p * w + q] = 1;
                            for (int x = 0; x < 8 && x + baseX < f.DynSize.Width && imns8[i].X + x < bp.Width; x++)
                            {
                                for (int y = 0; y < 8 && y + baseY < f.DynSize.Height && imns8[i].Y + y < bp.Height; y++)
                                {
                                    c = bp.GetPixel(imns8[i].X + x, imns8[i].Y + y);
                                    if (c.A == 255)
                                    {
                                        gfx[baseX + x, baseY + y] = pal[c.ToArgb()];
                                    }
                                }
                            }
                            break;
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                if (!found)
                {
                    return(null);
                }
                else
                {
                    bx = baseX / 8;
                    by = baseY / 8;
                    tm = new TileMask(TileSP.SP23, Tiles8[bx, by], 2, false, false)
                    {
                        XDisp    = imns8[i].X * 2,
                        YDisp    = imns8[i].Y * 2,
                        Priority = Priority,
                        Palette  = pid
                    };
                    f.AddTile(tm);
                }
            }

            f.GFX = SnesGraphics.GetGFXFromColorMatrix(gfx);
            f.Sort(tilesorter);
            return(f);
        }
        public TileMask ToTileMask(Tile[,] t16SP12, Tile[,] t16SP34, Tile[,] t8SP12, Tile[,] t8SP34)
        {
            Tile[,] t;

            if (SP == 0)
            {
                if (Size == 16)
                {
                    t = t16SP12;
                }
                else
                {
                    t = t8SP12;
                }
            }
            else
            {
                if (Size == 16)
                {
                    t = t16SP34;
                }
                else
                {
                    t = t8SP34;
                }
            }

            int i = 0;

            if (Tile[1] >= 'A')
            {
                i = 10 + Tile[1] - 'A';
            }
            else
            {
                i = Tile[1] - '0';
            }

            int j = 0;

            if (Tile[2] >= 'A')
            {
                j = 10 + Tile[2] - 'A';
            }
            else
            {
                j = Tile[2] - '0';
            }

            TileSP sp = TileSP.SP01;

            if (SP > 0)
            {
                sp = TileSP.SP23;
            }

            TileMask tm = new TileMask(sp, t[j, i], 2, FlipX, FlipY);

            sbyte b = Convert.ToSByte(XDisp.Substring(1), 16);

            tm.XDisp    = b + 128;
            tm.XDisp   *= 2;
            b           = Convert.ToSByte(YDisp.Substring(1), 16);
            tm.YDisp    = b + 112;
            tm.YDisp   *= 2;
            tm.Palette  = (PaletteId)PalId;
            tm.Priority = (TilePriority)Priority;
            return(tm);
        }