Esempio n. 1
0
        public virtual void Update(double elapsed)
        {
            mUdpCheckPool.Update(elapsed);

            int nPackageCount = 0;

            while (!mNeedHandlePackageQueue.IsEmpty)
            {
                NetPackage mNetPackage = null;
                if (!mNeedHandlePackageQueue.TryDequeue(out mNetPackage))
                {
                    break;
                }

                PackageManager.Instance.Execute(this as ClientPeer, mNetPackage);

                if (mNetPackage is NetCombinePackage)
                {
                    NetCombinePackage mCombinePackage = mNetPackage as NetCombinePackage;
                    ObjectPoolManager.Instance.mCombinePackagePool.recycle(mNetPackage as NetCombinePackage);
                }
                else if (mNetPackage is NetUdpFixedSizePackage)
                {
                    ObjectPoolManager.Instance.mUdpFixedSizePackagePool.recycle(mNetPackage as NetUdpFixedSizePackage);
                }

                nPackageCount++;
            }

            if (nPackageCount > 20)
            {
                DebugSystem.Log("服务器 处理逻辑的数量: " + nPackageCount);
            }
        }
        private void CheckCombinePackage(NetUdpFixedSizePackage mPackage)
        {
            if (mPackage.nGroupCount > 1)
            {
                NetCombinePackage cc = ObjectPoolManager.Instance.mCombinePackagePool.Pop();
                cc.Init(mPackage);
                mCombinePackageQueue.Enqueue(cc);
            }
            else
            {
                if (!mCombinePackageQueue.IsEmpty)
                {
                    NetCombinePackage currentGroup = null;
                    if (mCombinePackageQueue.TryPeek(out currentGroup))
                    {
                        currentGroup.Add(mPackage);

                        if (currentGroup.CheckCombineFinish())
                        {
                            if (mCombinePackageQueue.TryDequeue(out currentGroup))
                            {
                                mUdpPeer.AddLogicHandleQueue(currentGroup);
                            }
                        }
                    }
                }
                else
                {
                    mUdpPeer.AddLogicHandleQueue(mPackage);
                }
            }
        }