Ejemplo n.º 1
0
        /// Will return null if reach max size.
        public T Get()
        {
#if DISABLE_POOLING
            return(_pCreator(this));
#else
            Debugger.Assert(!(_nPoolSize == _nMaxSize && GetFreeObjectCount() == 0), "Exceed pool max size!!! Max pool size is " + _nMaxSize);

            T pObject;

            if (_objectQueue.Count == 0)
            {
                pObject = _pCreator(this);
                _nPoolSize++;
            }
            else
            {
                pObject = _objectQueue.RemoveFromFront();

                /*
                 #if DEBUG
                 *              _arrObjectSlots[_iCursor] = default(T);
                 #endif
                 */
            }

            Debugger.Assert(_nPoolSize <= _nMaxSize);
            Debugger.Assert(pObject != null);
            return(pObject);
#endif
        }
Ejemplo n.º 2
0
        internal bool _IsCoroutineInQueue(Coroutine pCoroutine)
        {
            var bInQueue = __arrAddedCoroutines.Contains(pCoroutine) || _arrCoroutines.Contains(pCoroutine);

            Debugger.Assert(pCoroutine._bInQueue == bInQueue);
            return(bInQueue);
        }
Ejemplo n.º 3
0
        protected override void _onRelease()
        {
            Debugger.Assert(_signal == null);
            Debugger.Assert(_updateHandler == null);

            CoroutineMgr._Instance._FreeSignalWaiter(this);
        }
Ejemplo n.º 4
0
        public IEnumerator <T> GetEnumerator()
        {
#if DISABLE_POOLING
            Debugger.Assert(false, "GetEnumerator not allowed if DISABLE_POOLING");
#endif
            return(_objectQueue.GetEnumerator());
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
    private void _onConnectedCallback(IAsyncResult pAsyncResult)
    {
        lock (__lock)
        {
            try
            {
                TcpClient pTCPClient = pAsyncResult.AsyncState as TcpClient;

                Debugger.Assert(System.Object.ReferenceEquals(pTCPClient, _tcpClient));
                pTCPClient.EndConnect(pAsyncResult);

                _tcpClient.NoDelay = true;

                _networkStream = pTCPClient.GetStream();
                Debugger.Assert(_networkStream.CanRead);

                __bIsReceiveHeader = true;
                _networkStream.BeginRead(__receiveBuffer, 0, HEAD_SIZE, _onReadCallback, 0);

                _connectionState = ConnectionState.CONNECTED;

                _InternalMsg sysMsg = new _InternalMsg(_InternalMsgType.Connected);
                __sysMsgQueue.Add(sysMsg);
            }
            catch (Exception e)
            {
                _InternalMsg errMsg = new _InternalMsg(_InternalMsgType.ConnectFailed, e);
                __sysMsgQueue.Add(errMsg);
            }
        }
    }
Ejemplo n.º 7
0
        /// Will return null if reach max size.
        public T GetOrCreate()
        {
#if DISABLE_POOLING
            return _pCreator(this);
#else
            Debugger.Assert(!(_nPoolSize == _nMaxSize && GetFreeObjectCount() == 0), "Exceed pool max size!!! Max pool size is " + _nMaxSize);

            T pObject;

            if (_iCursor == -1)
            {
                pObject = _pCreator(this);
                _nPoolSize++;
            }
            else
            {
                pObject = _arrObjectSlots[_iCursor];
#if DEBUG
                _arrObjectSlots[_iCursor] = default(T);
#endif
                _iCursor--;
            }

            Debugger.Assert(_nPoolSize <= _nMaxSize);
            Debugger.Assert(pObject != null);
            return pObject;
#endif
        }
Ejemplo n.º 8
0
        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
        }
Ejemplo n.º 9
0
    public void Disconnect()
    {
        if (_connectionState == ConnectionState.DISCONNECTED)
        {
            return;
        }

        __onConnect = null;

        lock (__lock)
        {
            if (_networkStream != null)
            {
                _networkStream.Close();
                _networkStream = null;
            }

            Debugger.Assert(_tcpClient != null);
            _tcpClient.Close();
            _tcpClient = null;

            __nBytesReceived   = 0;
            __bIsReceiveHeader = true;

            __sendMsgQueue.Clear();
            __sysMsgQueue.Clear();
            __rawMsgQueue.Clear();

            _rpcCallMap.Clear();

            _connectionState  = ConnectionState.DISCONNECTED;
            __fCurrentSeconds = 0;
        }
    }
Ejemplo n.º 10
0
        public T GetProperty <T>(string strName) where T : class, IProperty
        {
            var prop = GetProperty(strName);

            Debugger.Assert(prop is T);
            return(prop as T);
        }
Ejemplo n.º 11
0
        virtual public void SetAutoKill(bool bAutoKill)
        {
            if (!IsAlive())
            {
                Debugger.LogWarning("SetAutoKill failed, coroutine is not alive! Current state: " + _state);
                return;
            }

            Debugger.Assert(GetRef() != 0);
            Debugger.Assert(_bInQueue);

            if (_AutoKill == bAutoKill)
            {
                return;
            }

            _AutoKill = bAutoKill;
            if (!_AutoKill)
            {
                IncRef();
            }
            else
            {
                DecRef();
            }
        }
Ejemplo n.º 12
0
        static public EaseType GetInvEaseType(EaseType type)
        {
            if (type == EaseType.Linear)
            {
                return(EaseType.Linear);
            }
            else if (type < EaseType.NormalEaseEnd)
            {
                int modeRet = ((int)type % 3);
                switch (modeRet)
                {
                case 0:
                    return(type);

                case 1:
                    return((EaseType)(type + 1));

                case 2:
                    return((EaseType)(type - 1));
                }
            }
            else
            {
                Debugger.Assert(false);
            }

            return(EaseType.Invalid);
        }
Ejemplo n.º 13
0
 override protected void _onRelease()
 {
     if (_isType(TickableType.Pooled))
     {
         Debugger.Assert(_IsDead == true && status == TickerStatus.STOPPED);
         _helper.DoRelease();
     }
 }
Ejemplo n.º 14
0
        override public void Stop()
        {
            Debugger.Assert(GetRef() != 0);
            Debugger.ConditionalAssert(_isType(TickableType.Pooled)
                                       , !_AutoKill, "You can call pause/resume/stop with the tweener handle only when it is not AutoKill mode.");

            _doStop();
        }
Ejemplo n.º 15
0
        static public T ConvertDictData <T>(object pData) where T : class
        {
            IDictionary <string, object> pDictData = pData as Dictionary <string, object>;

            Debugger.Assert(pDictData != null, "type error");
            object pDeserialized = TypeUtil.DictionaryToObject(typeof(T), pDictData);

            return(pDeserialized as T);
        }
Ejemplo n.º 16
0
    ///------------
    private void _sendMessage(Message pMessage)
    {
        Debugger.Assert(IsConnected(), "_sendMessage failed, connection already down!");

        try
        {
            byte[] rawBuffer;
            int    nLength;

            if (pMessage.IsRPCCall())
            {
                _rpcIndex                  = (ushort)(1 + ((_rpcIndex + 1) % (ushort.MaxValue - 1)));
                pMessage.RPC_ID            = _rpcIndex;
                pMessage._RPCCallStartTime = __fCurrentSeconds;
            }

            pMessage.Serialize(out rawBuffer, out nLength);

            if (OnSendingFilter != null)
            {
                if (!OnSendingFilter(pMessage))
                {
                    if (pMessage._Callback != null)
                    {
                        pMessage._Callback(Message.REJECTED_BY_SENDING_FILTER);
                    }
                }
                else
                {
                    if (pMessage.IsRPCCall())
                    {
                        Debugger.Assert(!_rpcCallMap.ContainsKey(pMessage.RPC_ID));
                        _rpcCallMap.Add(_rpcIndex, pMessage);
                        pMessage._RPCCallStartTime = __fCurrentSeconds;
                    }

                    _networkStream.BeginWrite(rawBuffer, 0, nLength, _onWriteCallback, pMessage);
                }
            }
            else
            {
                if (pMessage.IsRPCCall())
                {
                    Debugger.Assert(!_rpcCallMap.ContainsKey(pMessage.RPC_ID));
                    _rpcCallMap.Add(_rpcIndex, pMessage);
                    pMessage._RPCCallStartTime = __fCurrentSeconds;
                }

                _networkStream.BeginWrite(rawBuffer, 0, nLength, _onWriteCallback, pMessage);
            }
        }
        catch (Exception e)
        {
            _onConnectError(e);
        }
    }
Ejemplo n.º 17
0
        override public void Resume(float fTime)
        {
            Debugger.Assert(GetRef() != 0);
            Debugger.ConditionalAssert(_bPooled
                                       , !_AutoKill, "You can call pause/resume/stop a pooled coroutine only when AutoKill is false.");
            Debugger.Assert(_state == CoroutineState.Paused);

            _state = CoroutineState.Running;
            _pCurrentInstruction.Resume(fTime);
        }
Ejemplo n.º 18
0
        static public T Instantiate <T>(string strResPath, Transform parent = null)
        {
            var obj = Instantiate(strResPath, parent);

            Debugger.Assert(obj != null, "Resource " + strResPath + " load failed!");
            var requestType = obj.GetComponent <T>();

            Debugger.Assert(requestType != null, "Resource " + strResPath + " doesn't contains " + typeof(T).Name + " component!");
            return(requestType);
        }
Ejemplo n.º 19
0
    public bool IsConnected()
    {
#if UNITY_EDITOR
        if (_connectionState == ConnectionState.CONNECTED || _connectionState == ConnectionState.VALIDATED)
        {
            Debugger.Assert(_tcpClient != null && _tcpClient.Connected);
        }
#endif
        return(_connectionState == ConnectionState.CONNECTED || _connectionState == ConnectionState.VALIDATED);
    }
Ejemplo n.º 20
0
        public void Dispose()
        {
            Debugger.Assert(_state == CoroutineState.Stopped, "Must stop a coroutine before dispose it!!!");
            Debugger.Assert(!_bPooled, "Pooled coroutine cannot be manual disposed!!!");
            Debugger.Assert(GetRef() == 0, "Cannot dispose a coroutine if it still referenced by other Objects (such as another Coroutine) !");

            Reset();
            _pCoroutineFunc = null;
            _state          = CoroutineState.Disposed;
        }
Ejemplo n.º 21
0
        /// Will Stop it first and then free it back to the pool.
        virtual public void StopAndKill()
        {
            Debugger.Assert(_bPooled);
            Debugger.Assert(!_AutoKill);

            Stop();

            _AutoKill = true;
            DecRef();
        }
Ejemplo n.º 22
0
        public void DecRef()
        {
            Debugger.Assert(_nRefCount > 0);
            _nRefCount--;

            if (_nRefCount == 0)
            {
                _onRelease();
            }
        }
Ejemplo n.º 23
0
        public void Start()
        {
            Debugger.Assert(GetRef() != 0);

            _IsDead = false;
            _status = TickerStatus.TICKING;

            ///... Currently, use TickableMgr to tick tween. Consider using TweenMgr to tick tween later.
            TimerMgr._Instance._PlayTickable(this);
        }
Ejemplo n.º 24
0
        public void Add(T pObject)
        {
#if DISABLE_POOLING
            pObject.Destroy();
#endif
            Debugger.Assert(_nPoolSize + 1 <= _nMaxSize, "Object pool exceed max size!");

            _objectQueue.AddToBack(pObject);
            _nPoolSize++;
        }
Ejemplo n.º 25
0
        /// Second param mean force dispose the coroutine. If false, the coroutine will be disposed when its reference count
        /// decreased to 0 automatically.
        static public void RemoveCoroutine(this object target, Coroutine pCoroutine, bool bDispose = false)
        {
            Debugger.Assert(!pCoroutine._bPooled);
            pCoroutine.DecRef();

            if (bDispose)
            {
                pCoroutine.Dispose();
            }
        }
Ejemplo n.º 26
0
    public void RemoveTail(int count)
    {
        Debugger.Assert(count >= 0 && count <= this.Count);

        for (int i = this.Count - count; i < this.Count; ++i)
        {
            _Buffer[i] = default(T);
        }

        this.Count -= count;
    }
Ejemplo n.º 27
0
 public T this[int i]
 {
     get
     {
         Debugger.Assert(i < Count);
         return(_Buffer[i]);
     }
     set
     {
         Debugger.Assert(i < Count);
         _Buffer[i] = value;
     }
 }
Ejemplo n.º 28
0
        public IEnumerator<T> GetEnumerator()
        {
#if DISABLE_POOLING
            Debugger.Assert(false, "GetEnumerator not allowed if DISABLE_POOLING");
#endif
            if (_arrObjectSlots != null)
            {
                int nSize = GetFreeObjectCount();
                for (int i = 0; i < nSize; ++i)
                {
                    yield return _arrObjectSlots[i];
                }
            }
        }
Ejemplo n.º 29
0
        public void Free(T[] arrInstances, int count)
        {
#if DISABLE_POOLING
            foreach (var instance in arrInstances)
            {
                instance.Destroy();
            }
#else
            Debugger.Assert(_nPoolSize + count <= _nMaxSize, "Object pool exceed max size! Do you free an object that is not managed by ObjectPool?");
            Debugger.Assert(arrInstances != null);

            Debugger.Assert(false, "Not implemented yet!");
            /// _objectQueue.AddToBack(arrInstances, count);
#endif
        }
Ejemplo n.º 30
0
        /// Prepare some objects into pool. Return old pool size.
        public int Prepare(int nSize)
        {
#if DISABLE_POOLING
            return _nPoolSize;
#else
            Debugger.Assert((_nPoolSize + nSize) <= _nMaxSize);

            int nOldPoolSize = _nPoolSize;
            for (int i = 0; i < nSize; ++i) Add(_pCreator(this));

            Debugger.Assert(_nPoolSize == nOldPoolSize + nSize);

            return nOldPoolSize;
#endif
        }