Ejemplo n.º 1
0
 int comparer(ConnectedTextureConfig c1, ConnectedTextureConfig c2)
 {
     if (c1.slots > c2.slots)
     {
         return(-1);
     }
     if (c1.slots < c2.slots)
     {
         return(1);
     }
     return(0);
 }
Ejemplo n.º 2
0
        void ComputeMatchesMatrix()
        {
            if (solve == null || solve.Length == 0)
            {
                solve = new int [256];
            }

            if (config == null)
            {
                return;
            }

            for (int k = 0; k < solve.Length; k++)
            {
                solve [k] = 0;
            }

            for (int k = 0; k < config.Length; k++)
            {
                int key   = 0;
                int slots = 0;
                if (config [k].tl)
                {
                    key += 1; slots++;
                }
                if (config [k].t)
                {
                    key += 2; slots++;
                }
                if (config [k].tr)
                {
                    key += 4; slots++;
                }
                if (config [k].l)
                {
                    key += 8; slots++;
                }
                if (config [k].r)
                {
                    key += 16; slots++;
                }
                if (config [k].bl)
                {
                    key += 32; slots++;
                }
                if (config [k].b)
                {
                    key += 64; slots++;
                }
                if (config [k].br)
                {
                    key += 128; slots++;
                }
                config [k].key   = key;
                config [k].slots = slots;
                solve [key]      = config [k].textureIndex;
            }

            List <ConnectedTextureConfig> sortedConfig = new List <ConnectedTextureConfig> (config);

            sortedConfig.Sort(comparer);

            // Fill combinations
            for (int k = 0; k < sortedConfig.Count; k++)
            {
                ConnectedTextureConfig c = sortedConfig [k];
                for (int j = 1; j < 256; j++)
                {
                    if (solve [j] == 0 && (j & c.key) == c.key)
                    {
                        solve [j] = c.textureIndex;
                    }
                }
            }
        }