internal void Reload(Sprite Sprite, ResourceLoadType LoadType)
        {
            if (Sprite.internalFrames != null)
            {
                Sprite.internalFrames[0].loading = true;
            }

            if (LoadType == ResourceLoadType.Delayed)
            {
                delayLoader.Enqueue(Sprite);
                return;
            }

            for (int i = 0; i < Sprite.internalFrames.Length; i++)
            {
                if (Sprite.internalFrames[i].HasSystemCopy)
                {
                    SlimDX.Direct3D9.Texture            tex  = engine.Device.CreateTexture(MakePowerOfTwo(Sprite.internalFrames[i].size.x), MakePowerOfTwo(Sprite.internalFrames[i].size.y));
                    SlimDX.Direct3D9.SurfaceDescription desc = tex.GetLevelDescription(0);
                    MemoryUsage += desc.Width * desc.Height * 4;

                    Sprite.internalFrames[i].texture = tex;
                    Sprite.internalFrames[i].RestoreFromSystemCopy();
                    Sprite.internalFrames[i].loading = false;
                    Sprite.internalFrames[i].loaded  = true;
                }
            }

            ResourceID id = Sprite.ID;

            if (id.File == "" || !spriteProcessors.ContainsKey(id.Format))
            {
                return;
            }

            ResourceID realid = (string)id;

            // check replacements
            if (replacement != null)
            {
                ResourceID newid = GetReplacementID(id);
                if (newid != null)
                {
                    if (CheckReplacementID(newid))
                    {
                        id = newid;
                    }
                }
            }

            engine.IncreaseLoadingCount();

            ISpriteProcessor loader = GetSpriteProcessor(id, true);

            if (loader is ISpriteAnimationProcessor)
            {
                ISpriteAnimationProcessor loaderAni = (ISpriteAnimationProcessor)loader;
                loader.Process(id);
                Log.Debug("reload \"" + id + "\"");

                for (int i = 0; i < loaderAni.FrameCount; i++)
                {
                    if (!loaderAni.SetFrame(i))
                    {
                        SpriteFrame[] frames = new SpriteFrame[i];
                        for (int j = 0; j < i; j++)
                        {
                            frames[j] = Sprite.Frames[j];
                        }
                        Sprite.internalFrames = frames;
                        Sprite.ani.frameCount = i;
                        break;
                    }

                    SlimDX.Direct3D9.Texture tex = engine.Device.CreateTexture(MakePowerOfTwo(loaderAni.FrameSize.x), MakePowerOfTwo(loaderAni.FrameSize.y));

                    SlimDX.Direct3D9.SurfaceDescription desc = tex.GetLevelDescription(0);
                    MemoryUsage += desc.Width * desc.Height * 4;

                    SlimDX.DataRectangle data = tex.LockRectangle(0, SlimDX.Direct3D9.LockFlags.Discard);
                    loader.Render(data.Data, data.Pitch);
                    tex.UnlockRectangle(0);

                    Sprite.Frames[i].Texture   = tex;
                    Sprite.Frames[i].Width     = loaderAni.FrameSize.x;
                    Sprite.Frames[i].Height    = loaderAni.FrameSize.y;
                    Sprite.Frames[i].TimeStamp = System.Diagnostics.Stopwatch.GetTimestamp();
                }
            }
            else
            {
                loader.Process(id);
                Log.Debug("reload \"" + id + "\"");

                SlimDX.Direct3D9.Texture tex = engine.Device.CreateTexture(MakePowerOfTwo(loader.Size.x), MakePowerOfTwo(loader.Size.y));

                SlimDX.Direct3D9.SurfaceDescription desc = tex.GetLevelDescription(0);
                MemoryUsage += desc.Width * desc.Height * 4;

                SlimDX.DataRectangle data = tex.LockRectangle(0, SlimDX.Direct3D9.LockFlags.Discard);
                loader.Render(data.Data, data.Pitch);
                tex.UnlockRectangle(0);

                Sprite.Frame.Texture   = tex;
                Sprite.Frame.Width     = loader.Size.x;
                Sprite.Frame.Height    = loader.Size.y;
                Sprite.Frame.TimeStamp = System.Diagnostics.Stopwatch.GetTimestamp();
            }

            if (Sprite.internalFrames != null)
            {
                Sprite.internalFrames[0].loading = false;
                Sprite.internalFrames[0].loaded  = true;
            }

            engine.DecreaseLoadingCount();
        }
        Sprite GetSprite(ResourceID id, ResourceLoadType LoadType)
        {
            float      factor = 1;
            ResourceID realid = (string)id;

            // check replacements
            if (replacement != null)
            {
                ResourceID newid = GetReplacementID(id);
                if (newid != null)
                {
                    // if available return newid sprite right away
                    if (sprites.ContainsKey(newid))
                    {
                        return(sprites[newid].Clone());
                    }
                    // otherwise check if newid is available, if not fallback to old id
                    else if (CheckReplacementID(newid))
                    {
                        id     = newid;
                        factor = replacement[""].GetFloat("sprite_resolution");
                    }
                }
            }

            if (sprites.ContainsKey(id))
            {
                return(sprites[id].Clone());
            }
            else
            {
                Sprite s;

                String format = id.Format;

                Log.Debug("load \"" + id + "\"");

                if (!spriteProcessors.ContainsKey(format))
                {
                    return(null);
                }

                engine.IncreaseLoadingCount();

                lock (this)
                {
                    ISpriteProcessor loader = GetSpriteProcessor(id, false);
                    if (loader is ISpriteAnimationProcessor)
                    {
                        ISpriteAnimationProcessor loaderAni = (ISpriteAnimationProcessor)loader;

                        loader.Process(id);

                        int count = loaderAni.FrameCount;

                        SpriteFrame[] frames = new SpriteFrame[loaderAni.FrameCount];
                        for (int i = 0; i < loaderAni.FrameCount; i++)
                        {
                            //loaderAni.SetFrame(i);

                            //SlimDX.Direct3D9.Texture tex = new SlimDX.Direct3D9.Texture(engine.Device, loaderAni.FrameSize.x, loaderAni.FrameSize.y, 1,
                            //    SlimDX.Direct3D9.Usage.Dynamic, SlimDX.Direct3D9.Format.A8R8G8B8,
                            //    SlimDX.Direct3D9.Pool.Default);

                            //SlimDX.DataRectangle data = tex.LockRectangle(0, SlimDX.Direct3D9.LockFlags.Discard);
                            //loader.Render(data.Data, data.Pitch);
                            //tex.UnlockRectangle(0);

                            frames[i] = new SpriteFrame(this);
                        }

                        s            = new Sprite(this, realid, frames, new SpriteAnimation(loaderAni.FrameCount));
                        s.LoadType   = LoadType;
                        s.Resolution = factor;

                        sprites.Add(id, s);
                    }
                    else
                    {
                        //loader.Process(id);

                        //SlimDX.Direct3D9.Texture tex = new SlimDX.Direct3D9.Texture(engine.Device, loader.Size.x, loader.Size.y, 1,
                        //    SlimDX.Direct3D9.Usage.Dynamic, SlimDX.Direct3D9.Format.A8R8G8B8,
                        //    SlimDX.Direct3D9.Pool.Default);

                        //SlimDX.DataRectangle data = tex.LockRectangle(0, SlimDX.Direct3D9.LockFlags.Discard);
                        //loader.Render(data.Data, data.Pitch);
                        //tex.UnlockRectangle(0);

                        SpriteFrame si = new SpriteFrame(this);
                        s            = new Sprite(this, realid, si);
                        s.LoadType   = LoadType;
                        s.Resolution = factor;

                        sprites.Add(id, s);
                    }
                }

                if (LoadType == ResourceLoadType.Now)
                {
                    Reload(s, ResourceLoadType.Now);
                }

                engine.DecreaseLoadingCount();
                return(s);
            }
        }