コード例 #1
0
ファイル: FastPool .cs プロジェクト: wyyayy/ARPainting
        public void Free(T pInstance)
        {
#if DISABLE_POOLING
            pInstance.Destroy();
#else
            Debugger.Assert(_iCursor + 1 < _nMaxSize, "Object pool exceed max size! Do you free an object that is not managed by FastPool?");
            Debugger.Assert(pInstance != null);

            Debugger.DebugSection(() => 
            {
                foreach(T element in this)
                {
                    Debugger.Assert(element != pInstance
                        , "Object already in pool, cannot FreeInstance it twice! Object is: " + element);
                }
            });

            if (_iCursor + 1 >= _arrObjectSlots.Length)
            {
                _incressSlots();
            }

            _iCursor++;
            _arrObjectSlots[_iCursor] = pInstance;
#endif
        }
コード例 #2
0
ファイル: CoroutineMgr.cs プロジェクト: wyyayy/ARPainting
        internal void _AddToQueue(Coroutine pCoroutine)
        {
            Debugger.DebugSection(() =>
            {
                if (pCoroutine._bPooled)
                {
                    Debugger.Assert(pCoroutine.state == CoroutineState.InUse);
                }
                else
                {
                    Debugger.Assert(pCoroutine.state == CoroutineState.Stopped);
                }
            });

            Debugger.Assert(!_IsCoroutineInQueue(pCoroutine));

            pCoroutine._bInQueue = true;

            if (_InUpdating)
            {
                __arrAddedCoroutines.Add(pCoroutine);
            }
            else
            {
                _arrCoroutines.Add(pCoroutine);
            }
        }
コード例 #3
0
ファイル: ObjectPool.cs プロジェクト: wyyayy/ARPainting
        public void Free(T pInstance)
        {
#if DISABLE_POOLING
            pInstance.Destroy();
#else
            Debugger.Assert(_nPoolSize <= _nMaxSize, "Object pool exceed max size! Do you free an object that is not managed by ObjectPool?");
            Debugger.Assert(pInstance != null);

            Debugger.DebugSection(() =>
            {
                foreach (T element in this)
                {
                    Debugger.Assert(element != pInstance
                                    , "Object already in pool, cannot FreeInstance it twice! Object is: " + element);
                }
            });

            _objectQueue.AddToBack(pInstance);
#endif
        }
コード例 #4
0
        /// Return value indicate whether this coroutine is dead.
        internal bool _Update(float fTime)
        {
            bool bIsDead = false;

            try
            {
                if (_onUpdate != null && state == CoroutineState.Running)
                {
                    _onUpdate(_pCurrentInstruction);
                }
            }
            catch (Exception e)
            {
                _HandleException(new CoroutineException(e, this));
                bIsDead = true;
            }

            bool bIsComplete = false;

            if (_state < CoroutineState.Running)
            {
                if (_state == CoroutineState.Paused)
                {
                    return(false);
                }
                else if (_state == CoroutineState.Stopped)
                {
                    bIsComplete = true;
                }
                else if (_state == CoroutineState.Disposed)
                {
                    /// Occurred when a manual coroutine is Removed.
                    return(true);
                }
                else
                {
                    Debugger.Assert(false);
                }
            }

            try
            {
                _pCoroutineMgr._CoEnterLogStack.Push(this);

                if (bIsComplete)
                {
                    if (!__bIsManualStopped)
                    {
                        __doComplete();
                    }
                    return(true);
                }

                ///-------------------
                bIsDead = false;

                Debugger.Assert(_pCurrentInstruction != null);

                Debugger.DebugSection(() =>
                {
                    if (_pCurrentInstruction.GetInstructionType() == YieldInstructionType.Coroutine)
                    {
                        var coroutine = _pCurrentInstruction as Coroutine;
                        Debugger.ConditionalAssert(coroutine._bPooled, coroutine.state != CoroutineState.Freed);
                    }
                });

                if (_pCurrentInstruction.GetInstructionType() == YieldInstructionType.ReturnValue)
                {
                    bIsDead = true;

                    _ReturnValue pReturnValue = _pCurrentInstruction as _ReturnValue;

                    __doComplete(pReturnValue.returnValue);
                }
                else
                {
                    _pCurrentInstruction.Update(fTime);

                    if (_pCurrentInstruction.IsDone())
                    {
                        if (_onYieldDone != null)
                        {
                            _onYieldDone(_pCurrentInstruction);
                        }

                        if (state != CoroutineState.Stopped)
                        {
                            Debugger.Assert(_pCurrentInstruction != null);
                            _pCurrentInstruction.Stop();

                            if (!_pCoroutineFunc.MoveNext())
                            {
                                _pCurrentInstruction.DecRef();
                                _pCurrentInstruction = null;

                                bIsDead = true;
                                __doComplete();
                            }
                            else
                            {
                                if (_state != CoroutineState.Stopped)
                                {
                                    Debugger.Assert(_state != CoroutineState.Freed && _state != CoroutineState.Disposed);
                                    Debugger.Assert(_pCoroutineFunc != null, "Coroutine function is null but still in update, you may be operated on a dead coroutine!!!");

                                    /// Why defRef here? Because MoveNext() may cause current instruction
                                    _pCurrentInstruction.DecRef();

                                    _pCurrentInstruction = _pCoroutineFunc.Current as IYieldInstruction;
                                    if (_pCurrentInstruction == null)
                                    {
                                        throw new UnsupportedYieldInstruction();
                                    }

                                    _pCurrentInstruction.Start(fTime);
                                    _pCurrentInstruction.IncRef();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debugger.Assert(!(e is CoroutineException));
                _HandleException(new CoroutineException(e, this));
                bIsDead = true;
            }
            finally
            {
                Debugger.Assert(_pCoroutineMgr._CoEnterLogStack.Peek() == this);
                _pCoroutineMgr._CoEnterLogStack.Pop();
            }

            return(bIsDead);
        }