Пример #1
0
        public void Tick()
        {
            UInt64 resSize = 0;
            var    now     = CEngine.Instance.EngineTime;
            var    it      = SkeletonActions.GetEnumerator();

            while (it.MoveNext())
            {
                var i = it.Current;
                if (i.Value.ResourceState.KeepValid)
                {
                    resSize += i.Value.ResourceState.ResourceSize;
                    continue;
                }

                switch (i.Value.ResourceState.StreamState)
                {
                case EStreamingState.SS_Valid:
                {
                    if (now - i.Value.ResourceState.AccessTime > ForgetTime)
                    {
                        i.Value.ResourceState.StreamState = EStreamingState.SS_Killing;
                        i.Value.InvalidateResource();
                        i.Value.ResourceState.StreamState = EStreamingState.SS_Invalid;
                    }
                    else
                    {
                        resSize += i.Value.ResourceState.ResourceSize;
                    }
                }
                break;

                case EStreamingState.SS_Invalid:
                {
                    //mesh和texture不一样,texture在c++做的updateAccessTime,所以需要检测
                    //但是mesh应该不可能走这里,因为c#内走的PreUse会自动标志状态,而不是只更新时间戳
                    //留下这样的代码就是一种检测而已
                    if (now - i.Value.ResourceState.AccessTime < ActiveTime)
                    {
                        Profiler.Log.WriteLine(Profiler.ELogTag.Error, "Mesh", $"Mesh AccesssTime updated,but StreamingState is invalid");
                        //说明销毁资源后,短期内又有人要用他
                        i.Value.ResourceState.StreamState = EStreamingState.SS_Pending;
                        lock (PendingActions)
                        {
                            PendingActions.Add(i.Value);
                        }
                    }
                }
                break;
                }
            }
            it.Dispose();
            TotalSize = resSize;
        }
Пример #2
0
        /// <summary>
        /// Schedules the action to run on the main thread
        /// </summary>
        /// <param name="action"></param>
        public static void RunOnMainThread(Action action)
        {
            if (IsApplicationQuit)
            {
                return;
            }

            //Make sure we are in the main thread
            if (!IsMainThread)
            {
                lock (syncRoot)
                {
                    PendingActions.Add(action);
                }
            }
            else
            {
                action();
            }
        }