Ejemplo n.º 1
0
        private void ThreadProc()
        {
            while (mIsRunning)
            {
                TextureWorkItem workItem = null;
                lock (mWorkItems)
                {
                    if (mWorkItems.Count > 0)
                    {
                        workItem = mWorkItems[0];
                        mWorkItems.RemoveAt(0);
                    }
                }

                if (workItem == null)
                {
                    lock (mWorkEvent)
                        Monitor.Wait(mWorkEvent);
                }
                else
                {
                    var loadInfo = TextureLoader.Load(workItem.FileName);
                    if (loadInfo != null)
                    {
                        mDispatcher.BeginInvoke(new Action(() => workItem.Texture.LoadFromLoadInfo(loadInfo)));
                    }
                    else
                    {
                        Log.Warning("Load failed: " + workItem.FileName);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Graphics.Texture GetTexture(string path)
        {
            if (string.IsNullOrEmpty(path))
                return new Graphics.Texture(mContext);

            var hash = path.ToUpperInvariant().GetHashCode();
            TextureWorkItem workItem;
            Graphics.Texture retTexture;
            lock (mCache)
            {
                WeakReference<Graphics.Texture> ret;
                if(mCache.TryGetValue(hash, out ret))
                {
                    if (ret.TryGetTarget(out retTexture))
                        return retTexture;

                    mCache.Remove(hash);
                }

                retTexture = new Graphics.Texture(mContext);
                mCache.Add(hash, new WeakReference<Graphics.Texture>(retTexture));
                workItem = new TextureWorkItem(path, retTexture);
            }

            lock (mWorkItems)
            {
                mWorkItems.Add(workItem);
                lock (mWorkEvent)
                    Monitor.Pulse(mWorkEvent);
            }

            return retTexture;
        }
Ejemplo n.º 3
0
        public Graphics.Texture GetTexture(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new Graphics.Texture(mContext));
            }

            var             hash = path.ToUpperInvariant().GetHashCode();
            TextureWorkItem workItem;

            Graphics.Texture retTexture;
            lock (mCache)
            {
                WeakReference <Graphics.Texture> ret;
                if (mCache.TryGetValue(hash, out ret))
                {
                    if (ret.TryGetTarget(out retTexture))
                    {
                        return(retTexture);
                    }

                    mCache.Remove(hash);
                }

                retTexture = new Graphics.Texture(mContext);
                mCache.Add(hash, new WeakReference <Graphics.Texture>(retTexture));
                workItem = new TextureWorkItem(path, retTexture);
            }

            lock (mWorkItems)
            {
                mWorkItems.Add(workItem);
                lock (mWorkEvent)
                    Monitor.Pulse(mWorkEvent);
            }

            return(retTexture);
        }