public void OnResourceComplate(ResourceRef resource)
 {
     if (processor[resource.Processor].current == resource)
     {
         processor[resource.Processor].current = null;
     }
 }
Esempio n. 2
0
        public void ProcessQueue(PriorityQueue <ResourceRef> queueResources)
        {
            while (queueResources.Count > 0)
            {
                ResourceRef resource = queueResources.Top();

                // 尝试取到一个引用计数不为0的资源
                while (resource.Refs == 0 && queueResources.Count > 0)
                {
                    queueResources.Pop();
                    resource = queueResources.Top();
                }

                // 取到了一个引用计数不为0的资源
                if (!resource.Async)
                {
                    resource.Start();
                    queueResources.Pop();
                }
                else
                {
                    break;
                }
            }
        }
Esempio n. 3
0
        private IPromise <ResourceRef> _addResource(string url, int priority, bool bAsync)
        {
            ResourceRef resource = null;

            Debug.Assert(url != null, "addResource url 不能为 null");
            Debug.Assert(url != string.Empty, "addResource url 不能为 string.Empty");
            if (!dictResources.ContainsKey(url))
            {
                resource                 = new ResourceRef(url, this);
                resource.Priority        = priority;
                resource.Async           = bAsync;
                resource.ComplatedEvent += OnResourceComplate;
                dictResources[url]       = resource;
                queueResources.Push(resource);
            }
            else
            {
                resource = dictResources[url];
                resource.AddRefs();

                if (resource.InQueue)
                {
                    int  oldPriority = resource.Priority;
                    bool oldAsync    = resource.Async;
                    resource.Priority = Math.Max(priority, resource.Priority);
                    resource.Async    = resource.Async && bAsync;                       // 一直传异步参数才能保持资源异步,一旦传入过同步参数,就一直是同步的了。
                    if ((oldPriority != resource.Priority) || (oldAsync != resource.Async))
                    {
                        queueResources.ReSort();
                    }
                }
            }

            return(resource.AcceptPromise());
        }
Esempio n. 4
0
 private void ReleaseResource(ResourceRef resource)
 {
     if (resource.IsDone && resource.resourceObject != null)
     {
         resource.resourceObject.Dispose();
         resource.resourceObject = null;
         needRemoveUnused        = true;
     }
 }
Esempio n. 5
0
 public void ReleaseAll()
 {
     Dictionary <string, ResourceRef> .Enumerator e = dictResources.GetEnumerator();
     while (e.MoveNext())
     {
         ResourceRef resource = e.Current.Value;
         resource.DelRefs();
         ReleaseResource(resource);
     }
     dictResources.Clear();
     queueResources.Clear();
 }
Esempio n. 6
0
        public void delResource(string url)
        {
            Debug.Assert(url != null, "delResource url 不能为 null");
            Debug.Assert(url != string.Empty, "delResource url 不能为 string.Empty");
            Debug.Assert(dictResources.ContainsKey(url), "资源 url = " + url + "不存在");
            if (dictResources.ContainsKey(url))
            {
                ResourceRef resource = dictResources[url];
                resource.DelRefs();

                if (resource.Refs == 0)
                {
                    ReleaseResource(resource);
                    //Debug.Log("资源 url = " + url + "计数器为0被删除");
                    dictResources.Remove(url);
                }
            }
        }
Esempio n. 7
0
        void OnResourceComplate(ResourceRef resource)
        {
            resource.ComplatedEvent -= OnResourceComplate;

            if (resource.Async)
            {
                asyncProcessor.OnResourceComplate(resource);
            }
            else
            {
                syncProcessor.OnResourceComplate(resource);
            }

            if (resource.Refs == 0)
            {
                ReleaseResource(resource);
                return;
            }
        }
Esempio n. 8
0
        public ResourceRef[] addResources(string[] urls, int[] priorities, bool bAsync, Action <ResourceRef[]> actComplate, Action <Exception> actError)
        {
            IPromise <ResourceRef>[] promises = new IPromise <ResourceRef> [urls.Length];
            ResourceRef[]            refs     = new ResourceRef[urls.Length];
            for (int i = 0; i < urls.Length; i++)
            {
                int priority = (priorities != null)?(priorities.Length >= urls.Length?priorities[i]:priorities[0]):0;
                promises[i] = _addResource(urls[i], priority, bAsync);
                refs[i]     = getResource(urls[i]);
            }

            Func <IEnumerable <ResourceRef>, IEnumerable <IPromise <ResourceRef> > > funcResolved = resources => {
                actComplate(resources.ToArray());
                return(promises);
            };

            Promise <ResourceRef> .All(promises).Catch(actError).ThenAll(funcResolved).Done();

            return(refs);
        }
        public void ProcessQueue(PriorityQueue <ResourceRef> queueResources)
        {
            for (int i = 0; i < processor.Length; i++)
            {
                if ((processor[i].current == null) && (queueResources.Count > 0))
                {
                    ResourceRef resource = queueResources.Pop();

                    // 尝试取到一个引用计数不为0的资源
                    while (resource.Refs == 0 && queueResources.Count > 0)
                    {
                        resource = queueResources.Pop();
                    }

                    // 取到了一个引用计数不为0的资源
                    if (resource.Refs > 0)
                    {
                        resource.Processor    = i;
                        processor [i].current = resource;
                        resource.Start();
                    }
                }
            }
        }
Esempio n. 10
0
 public void OnResourceComplate(ResourceRef resource)
 {
 }