/// 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 }
internal bool _IsCoroutineInQueue(Coroutine pCoroutine) { var bInQueue = __arrAddedCoroutines.Contains(pCoroutine) || _arrCoroutines.Contains(pCoroutine); Debugger.Assert(pCoroutine._bInQueue == bInQueue); return(bInQueue); }
protected override void _onRelease() { Debugger.Assert(_signal == null); Debugger.Assert(_updateHandler == null); CoroutineMgr._Instance._FreeSignalWaiter(this); }
public IEnumerator <T> GetEnumerator() { #if DISABLE_POOLING Debugger.Assert(false, "GetEnumerator not allowed if DISABLE_POOLING"); #endif return(_objectQueue.GetEnumerator()); }
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); } }
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); } } }
/// 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 }
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 }
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; } }
public T GetProperty <T>(string strName) where T : class, IProperty { var prop = GetProperty(strName); Debugger.Assert(prop is T); return(prop as T); }
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(); } }
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); }
override protected void _onRelease() { if (_isType(TickableType.Pooled)) { Debugger.Assert(_IsDead == true && status == TickerStatus.STOPPED); _helper.DoRelease(); } }
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(); }
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); }
///------------ 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); } }
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); }
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); }
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); }
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; }
/// 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(); }
public void DecRef() { Debugger.Assert(_nRefCount > 0); _nRefCount--; if (_nRefCount == 0) { _onRelease(); } }
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); }
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++; }
/// 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(); } }
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; }
public T this[int i] { get { Debugger.Assert(i < Count); return(_Buffer[i]); } set { Debugger.Assert(i < Count); _Buffer[i] = value; } }
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]; } } }
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 }
/// 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 }