Example #1
0
        // An array of RGBA
        public void SetData(uint[,] colors)
        {
            VerifyThreadAffinity();
            var width  = colors.GetUpperBound(1) + 1;
            var height = colors.GetUpperBound(0) + 1;

            if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
            {
                throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
            }

            Size = new Size(width, height);
            unsafe
            {
                fixed(uint *ptr = &colors[0, 0])
                {
                    var intPtr = new IntPtr((void *)ptr);

                    PrepareTexture();
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height,
                                  0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, intPtr);
                    ErrorHandler.CheckGlError();
                }
            }
        }
Example #2
0
        // An array of RGBA
        public void SetData(uint[,] colors)
        {
            VerifyThreadAffinity();
            var width  = colors.GetUpperBound(1) + 1;
            var height = colors.GetUpperBound(0) + 1;

            if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
            {
                throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
            }

            Size = new Size(width, height);
            unsafe
            {
                fixed(uint *ptr = &colors[0, 0])
                {
                    var intPtr = new IntPtr((void *)ptr);

                    PrepareTexture();
                    OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA8, width, height,
                                        0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, intPtr);
                    OpenGL.CheckGLError();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Convert from ARGB to ABGR
        /// </summary>
        /// <param name="pixelHeight"></param>
        /// <param name="pixelWidth"></param>
        /// <param name="colors"></param>
        //private static void ConvertToABGR(int pixelHeight, int pixelWidth, byte[] colors)
        //{
        //    int pixelCount = pixelHeight * pixelWidth;
        //    //int pixelCount = colors.Length;
        //    for(int i = 0; i < pixelCount; i++)
        //    {
        //        uint pixel = colors[i];
        //        colors[i] = (byte)((pixel & 0xFF00FF00) | ((pixel & 0x00FF0000) >> 16) | ((pixel & 0x000000FF) << 16));
        //    }
        //}

        //public static void ConvertTARGB(byte[] colors) {

        //    for (int i = 0; i < colors.Length; i++) {
        //        uint pixel = colors[i];
        //        colors[i] = (byte)((pixel & 0xFFFFFF00) | ((pixel&0x000000FF)<<24));
        //    }
        //}


        //An array of RGBA
        public void SetData(uint[,] colors)
        {
            Threading.EnsureUIThread();

            var width  = colors.GetUpperBound(1) + 1;
            var height = colors.GetUpperBound(0) + 1;

            if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
            {
                throw new InvalidDataException(string.Format("Non-power-of-two array {0}x{1}", width, height));
            }

            Size = new Size(width, height);

            unsafe
            {
                fixed(uint *ptr = &colors[0, 0])
                {
                    var intPtr = new IntPtr((void *)ptr);

                    PrepareTexture();
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8,
                                  width, height, 0, PixelFormat.BGRA_EXT, PixelType.UnsignedByte, intPtr);
                    //GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, width, height, PixelFormat.Rgba, PixelType.UnsignedByte, intPtr);
                }
            }
        }
Example #4
0
        public static int Find(this uint[,] table, uint value)
        {
            if (table is null)
            {
                throw new ArgumentNullException(nameof(table));
            }

            var min = 0;
            var max = table.GetUpperBound(0);
            int mid;

            if (value < table[0, 0] || value > table[max, 1])
            {
                return(0);
            }

            while (max >= min)
            {
                mid = (min + max) / 2;
                if (value > table[mid, 1])
                {
                    min = mid + 1;
                }
                else if (value < table[mid, 0])
                {
                    max = mid - 1;
                }
                else
                {
                    return(1);
                }
            }

            return(0);
        }
Example #5
0
        // An array of RGBA
        public void SetData(uint[,] colors)
        {
            VerifyThreadAffinity();
            var width  = colors.GetUpperBound(1) + 1;
            var height = colors.GetUpperBound(0) + 1;

            if (!Exts.IsPowerOf2(width) || !Exts.IsPowerOf2(height))
            {
                throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
            }

            Size = new Size(width, height);
            unsafe
            {
                fixed(uint *ptr = &colors[0, 0])
                SetData(new IntPtr(ptr), width, height);
            }
        }
Example #6
0
        /// <summary>
        /// Метод конвертации массива int в Bitmap-изображение
        /// </summary>
        /// <param name="array">Двухмерный массив типа int</param>
        /// <returns>Bitmap-изображение</returns>
        static Bitmap IntArrayToBitmap(uint[,] array)
        {
            DateTime start   = DateTime.Now;
            int      arrDim0 = array.GetUpperBound(0),
                     arrDim1 = array.GetUpperBound(1);

            Bitmap result = new Bitmap(arrDim0 + 1, arrDim1 + 1);

            for (int i = 0; i <= arrDim0; i++)
            {
                for (int j = 0; j <= arrDim1; j++)
                {
                    result.SetPixel(i, j, Color.FromArgb((int)array[i, j]));
                }
            }

            Debug.WriteLine("IntArrayToBitmap: {0}", (DateTime.Now - start));

            return(result);
        }
Example #7
0
        public IEnumerable <ZoneId> GetAllZoneIds()
        {
            HashSet <ZoneId> set = new HashSet <ZoneId>();

            uint[,] zoneIds = ZoneIds;
            int upperBound1 = zoneIds.GetUpperBound(0);
            int upperBound2 = zoneIds.GetUpperBound(1);

            for (int lowerBound1 = zoneIds.GetLowerBound(0); lowerBound1 <= upperBound1; ++lowerBound1)
            {
                for (int lowerBound2 = zoneIds.GetLowerBound(1); lowerBound2 <= upperBound2; ++lowerBound2)
                {
                    ZoneId id = (ZoneId)zoneIds[lowerBound1, lowerBound2];
                    if (id != ZoneId.None && !set.Contains(id))
                    {
                        set.Add(id);
                        yield return(id);
                    }
                }
            }
        }
Example #8
0
        // An array of RGBA
        public void SetData(uint[,] colors)
        {
            int width  = colors.GetUpperBound(1) + 1;
            int height = colors.GetUpperBound(0) + 1;

            if (!IsPowerOf2(width) || !IsPowerOf2(height))
            {
                throw new InvalidDataException("Non-power-of-two array {0}x{1}".F(width, height));
            }

            unsafe
            {
                fixed(uint *ptr = &colors[0, 0])
                {
                    IntPtr intPtr = new IntPtr((void *)ptr);

                    PrepareTexture();
                    Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, width, height,
                                    0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intPtr);
                    ErrorHandler.CheckGlError();
                }
            }
        }
Example #9
0
        /// <summary>
        /// Writes a 2D array of unsigned 32-bit ints to the output.
        /// </summary>
        /// <param name="name">Name of the value</param>
        /// <param name="value">2D array of UInt32</param>
        public void Write(string name, uint[,] value)
        {
            if (value == null)
            {
                _output.Write(NULL_OBJECT);
                return;
            }
            else
            {
                _output.Write(A_OK);
            }
            int row = value.GetUpperBound(0);
            int col = value.GetUpperBound(1);

            _output.Write(row);
            _output.Write(col);
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    _output.Write(value[i, j]);
                }
            }
        }
Example #10
0
 private void CheckInventoryItems()
 {
     // Check all items in inventory
     foreach (WoWItem item in ObjectManager.GetObjectsOfType <WoWItem>())
     {
         // Check to see if it can be lockpicked
         if (SpellManager.HasSpell("Pick Lock") && _lockboxes.Contains(item.Entry))
         {
             SpellManager.Cast("Pick Lock");
             StyxWoW.SleepForLagDuration();
             String s = String.Format("UseItemByName(\"{0}\")", item.Name);
             log("Unlocking {0} guid {1}", item.Name, item.Guid);
             Lua.DoString(s);
             StyxWoW.SleepForLagDuration();
             StyxWoW.SleepForLagDuration();
             while (ObjectManager.Me.IsCasting)
             {
                 Thread.Sleep(50);
             }
             log("Opening {0} guid {1}", item.Name, item.Guid);
             Lua.DoString(s);
             StyxWoW.SleepForLagDuration();
         }
         else
         {
             // Check to see if it can be opened or used or combined.
             for (int i = 0; i <= _data.GetUpperBound(0); i++)
             {
                 if (_data[i, 1] == item.Entry)
                 {
                     int cnt = Convert.ToInt32(Lua.GetReturnValues(String.Format("return GetItemCount(\"{0}\")", item.Name), Name + ".lua")[0]);
                     int max = (int)(cnt / _data[i, 0]);
                     for (int j = 0; j < max; j++)
                     {
                         String s = String.Format("UseItemByName(\"{0}\")", item.Name);
                         log("Using {0} we have {1}", item.Name, cnt);
                         Lua.DoString(s);
                         StyxWoW.SleepForLagDuration();
                     }
                     break;
                 }
             }
         }
     }
 }
 private void CheckInventoryItems()
 {
     foreach (WoWItem item in ObjectManager.GetObjectsOfType <WoWItem>())
     {
         for (int i = 0; i <= _data.GetUpperBound(0); i++)
         {
             if (_data[i, 1] == item.Entry)
             {
                 int cnt = Convert.ToInt32(Lua.GetReturnValues(String.Format("return GetItemCount(\"{0}\")", item.Name), Name + ".lua")[0]);
                 int max = (int)(cnt / _data[i, 0]);
                 for (int j = 0; j < max; j++)
                 {
                     String s = String.Format("UseItemByName(\"{0}\")", item.Name);
                     slog("Using {0} we have {1}", item.Name, cnt);
                     Lua.DoString(s);
                     StyxWoW.SleepForLagDuration();
                 }
                 break;
             }
         }
     }
 }
Example #12
0
        private void CheckInventoryItems()
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems)
            {
                for (int i = 0; i <= _data.GetUpperBound(0); i++)
                {
                    if (_data[i, 1] == item.Entry)
                    {
                        while (IteminBag(item.Entry))
                        {
                            String s = String.Format("UseItemByName(\"{0}\")", item.Name);
                            Lua.DoString(s);
                            StyxWoW.SleepForLagDuration();

                            if (LootFrame.Instance.IsVisible)
                            {
                                Lua.DoString("for i=1,GetNumLootItems() do ConfirmLootSlot(i) LootSlot(i) end");
                            }
                        }
                    }
                }
            }
        }
Example #13
0
        static void TestArray()
        {
            Console.Clear();

            uint[,] ua =                // Объявляем многомерный массив целых
            {
                { 1, 2, 3 },
                { 4, 5, 6 }
            };
            Console.WriteLine("2-dimensional array:\n");
            for (int i = 0; i <= ua.GetUpperBound(0); i++, Console.WriteLine()) // Пробег по нулевому измерению
            {
                for (int j = 0; j < ua.GetLength(1); j++)                       // Пробег по первому измерению
                {
                    Console.Write("a[{0},{1}] = {2},  ", i, j, ua[i, j]);
                }
            }
            Console.WriteLine("\n\nRank = " + ua.Rank);                 // Хотим увидеть значения фундаментальных свойств
            Console.WriteLine("Rows = " + ua.GetLength(0));
            Console.WriteLine("Columns = " + ua.GetLength(1));
            Console.WriteLine("Length = " + ua.Length);

            Console.WriteLine("\n\nUnformatted output\n");
            foreach (uint i in ua)              // Пробег по всем элементам массива
            {
                Console.Write(i + ", ");
            }

            int[] an = { 1, 2, 3, 4, 5 };              // Два массива
            int[] b  = { 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 };

            int lenA = Buffer.ByteLength(an), lenB = Buffer.ByteLength(b);             // Размеры массивов в байтах

            Console.WriteLine("\n\nThe length of Array an: {0} bytes", lenA);
            foreach (int i in an)              // Все элементы массива
            {
                Console.Write("{0},  ", i);
            }
            Console.WriteLine("\n\nThe length of Array b: {0} bytes", lenB);
            foreach (int i in b)
            {
                Console.Write("{0},  ", i);
            }

            Buffer.BlockCopy(an, 0, b, 0, lenA);              // Интересная операция

            Console.WriteLine("\n\nAfter Block copy operation array a :");
            foreach (int i in an)
            {
                Console.Write("{0},  ", i);
            }
            Console.WriteLine("\n\nArray b: ");
            foreach (int i in b)
            {
                Console.Write("{0},  ", i);
            }
            Console.WriteLine("\n\n");

            int[][] at =                // Объявляем массив массивов целых
            {
                new int[] { 1 },
                new int[] {2, 3, 4 },
                new int[] {5, 6, 7, 8, 9 }
            };
            Console.WriteLine("Jagged array:\n");
            for (int i = 0; i < at.GetLength(0); i++)              // 0-е измерение работает как и ранее
            {
                Console.WriteLine();
                for (int j = 0; j < at[i].GetLength(0); j++)                 // Число столбцов переменно, поэтому измерение 1 не работает
                {
                    Console.Write("a[{0}][{1}] = {2},  ", i, j, at[i][j]);
                }
            }
            Console.WriteLine("\n\nRank = " + at.Rank);
            Console.WriteLine("Length = " + at.Length + '\n');
            for (int i = 0; i < at.GetLength(0); i++)
            {
                foreach (int j in at[i])                                // foreach выглядит по-другому
                {
                    Console.Write(j + ", ");
                }
            }

            Console.WriteLine('\n');
            Array a = Array.CreateInstance(typeof(int), new int[] { 2, 3, 4 }, new int[] { -2, 0, 2 });

            for (int i = a.GetLowerBound(0); i <= a.GetUpperBound(0); i++)
            {
                for (int j = a.GetLowerBound(1); j <= a.GetUpperBound(1); j++)
                {
                    for (int k = a.GetLowerBound(2); k <= a.GetUpperBound(2); k++)
                    {
                        a.SetValue(i + j + k, new int[] { i, j, k });
                    }
                }
            }

            for (int i = a.GetLowerBound(0); i <= a.GetUpperBound(0); i++, Console.WriteLine())
            {
                for (int j = a.GetLowerBound(1); j <= a.GetUpperBound(1); j++, Console.WriteLine())
                {
                    for (int k = a.GetLowerBound(2); k <= a.GetUpperBound(2); k++)
                    {
                        Console.Write("a[{0}][{1}][{2}] = {3}", i, j, k, a.GetValue(new int[] { i, j, k }) + ",  ");
                    }
                }
            }



            Console.WriteLine("\n\n\t\tPress any key to go to main menu\n");
            Console.ReadKey(true);
        }