Exemple #1
0
        public static Package Load(string path)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Package pkg = JsonConvert.DeserializeObject <Package>(File.ReadAllText(path));

            pkg.ParseItems();
            pkg.ParseManufactureTables();
            pkg.ParseHarvestTables();

            sw.Stop();
            Debug.LogWarning($"Database loaded ({sw.Elapsed.TotalMilliseconds:F2} ms)");

            return(pkg);
        }
Exemple #2
0
        public unsafe Texture(string path, string name = null, bool clearOnApply = false) : base(name)
        {
            if (!File.Exists(path))
            {
                Debug.LogWarning($"Unable to load texture from \"{path}\": no file existing there.");
                this.Delete();
                return;
            }

            if (name == null)
            {
                this.Name = path.Split('/', '\\').Last().Split('.')[0];
            }

            using (Bitmap img = new Bitmap(path))
            {
                BitmapData data = img.LockBits(
                    new Rectangle(0, 0, img.Width, img.Height),
                    ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                uint *byteData = (uint *)data.Scan0;
                this.Size = new Vector2I(img.Width, img.Height);
                this.Data = new byte[4 * this.Size.X * this.Size.Y];

                Parallel.For(0, this.Size.X * this.Size.Y, (i) => byteData[i] = (byteData[i] & 0xFF000000) >> 24 | (byteData[i] & 0x00FFFFFF) << 8);

                Marshal.Copy(data.Scan0, this.Data, 0, this.Data.Length);

                this.Data = this.Data.Reverse().ToArray();
            }

            lock (CacheLocker)
                Cache.Add(this);

            void glApply()
            {
                bool clearApply = clearOnApply;

                this.Handle = GL.GenTexture();

                this.Use();

                GL.TexImage2D(TextureTarget.Texture2D,
                              0,
                              PixelInternalFormat.Rgba,
                              this.Width,
                              this.Height,
                              0,
                              OpenTK.Graphics.OpenGL4.PixelFormat.Rgba,
                              PixelType.UnsignedByte,
                              this.Data);

                if (clearApply)
                {
                    this.Data = null;
                }

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            }

            if (Thread.CurrentThread == Graphics.Window.Thread)
            {
                glApply();
            }

            else
            {
                Graphics.Window.InvokeRender(glApply);
            }
        }