예제 #1
0
        internal static QuadTreeNode <T> CreateQuadTreeNode(Rect bound)
        {
            QuadTreeNode <T> ret = AbstractPool <QuadTreeNode <T> > .GetNode() as QuadTreeNode <T>;

            ret.Init(bound);
            return(ret);
        }
예제 #2
0
        public static tReqSend CreateFromPool(byte[] pData, int bufSize)
        {
            tReqSend ret = (tReqSend)AbstractPool <tReqSend> .GetNode();

            ret.Init(pData, bufSize);
            return(ret);
        }
예제 #3
0
 private void InitChilds()
 {
     if (m_Childs == null)
     {
         m_Childs = AbstractPool <QuadTreeNodeArray <T> > .GetNode() as QuadTreeNodeArray <T>;
     }
 }
예제 #4
0
    private static VisibleNode GetVisibleNode(int instanceId, bool isVisible)
    {
        // 内部带锁了,线程安全
        VisibleNode ret = AbstractPool <VisibleNode> .GetNode() as VisibleNode;

        ret.InstanceId = instanceId;
        ret.isVisible  = isVisible;
        return(ret);
    }
예제 #5
0
        public override void Dispose()
        {
            if (pSendData != null)
            {
                pSendData.Dispose();
                pSendData = null;
            }

            AbstractPool <tReqSend> ._DestroyNode(this);
        }
예제 #6
0
    public override void OnInspectorGUI()
    {
        AbstractPool poolScript = target as AbstractPool;

        EditorGUILayout.PropertyField(parentProp);
        poolScript.parent = (Transform)parentProp.objectReferenceValue;
        EditorGUILayout.PropertyField(startCountProp);
        poolScript.startCount = startCountProp.intValue;
        EditorGUILayout.PropertyField(isDynamicProp);
        poolScript.isDynamic = isDynamicProp.boolValue;

        // Only show max if ObjectPool is not dynamic
        if (!poolScript.isDynamic)
        {
            EditorGUILayout.PropertyField(maxProp);
            poolScript.max = maxProp.intValue;
        }
    }
 public static PoolT MakePool <PoolT>() where PoolT : AbstractPool <BitStream>, new()
 {
     return(AbstractPool <BitStream> .MakePool <BitStream, PoolT>((pool) => new BitStream((NetBuffer)null, false)));
 }
예제 #8
0
        private QuadGroupNode <T> InitTree(int row, int col, T[] array)
        {
            if (row <= 0 || col <= 0 || array == null || array.Length <= 0)
            {
                return(null);
            }

            int rCnt = Mathf.CeilToInt(((float)row) / ((float)_cPer));
            int cCnt = Mathf.CeilToInt(((float)col) / ((float)_cPer));

            Func <int, T> GetItem = (int idx) =>
            {
                if (idx < 0 || idx >= array.Length)
                {
                    return(null);
                }
                return(array[idx]);
            };

            List <QuadGroupNode <T> > nodeList = new List <QuadGroupNode <T> >();

            for (int r = 0; r < rCnt; ++r)
            {
                for (int c = 0; c < cCnt; ++c)
                {
                    /*
                     * 3 4
                     * 1 2
                     */

                    int  rr        = r * _cPer;
                    int  cc        = c * _cPer;
                    int  idx1      = (rr) * col + cc;
                    int  idx2      = -1;
                    bool isVaildCC = cc + 1 < col;
                    if (isVaildCC)
                    {
                        idx2 = (rr) * col + cc + 1;
                    }

                    int  idx3      = -1;
                    bool isVaildrr = rr + 1 < row;
                    if (isVaildrr)
                    {
                        idx3 = (rr + 1) * col + cc;
                    }
                    int idx4 = -1;
                    if (isVaildCC && isVaildrr)
                    {
                        idx4 = (rr + 1) * col + cc + 1;
                    }

                    QuadGroupNode <T> root = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    QuadGroupNode <T> n1 = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    QuadGroupNode <T> n2 = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    QuadGroupNode <T> n3 = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    QuadGroupNode <T> n4 = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    T item1 = GetItem(idx1);
                    T item2 = GetItem(idx2);
                    T item3 = GetItem(idx3);
                    T item4 = GetItem(idx4);

                    n1.Init(item1);
                    n2.Init(item2);
                    n3.Init(item3);
                    n4.Init(item4);

                    QuadGroupNodeArray <T> nodeArray = AbstractPool <QuadGroupNodeArray <T> > .GetNode() as QuadGroupNodeArray <T>;

                    nodeArray[0] = n1;
                    nodeArray[1] = n2;
                    nodeArray[2] = n3;
                    nodeArray[3] = n4;

                    root.Init(nodeArray);
                    nodeList.Add(root);
                }
            }

            while (true)
            {
                InitTree(ref rCnt, ref cCnt, ref nodeList);
                if (nodeList.Count <= 1)
                {
                    break;
                }
            }

            if (nodeList.Count <= 0)
            {
                return(null);
            }

            return(nodeList[0]);
        }
예제 #9
0
        private void InitTree(ref int row, ref int col, ref List <QuadGroupNode <T> > parentNodeList)
        {
            if (parentNodeList == null || parentNodeList.Count <= 0)
            {
                return;
            }


            int rCnt = Mathf.CeilToInt(((float)row) / ((float)_cPer));
            int cCnt = Mathf.CeilToInt(((float)col) / ((float)_cPer));

            var pNodeList = parentNodeList;
            Func <int, QuadGroupNode <T> > GetItem = (int idx) =>
            {
                if (idx < 0 || idx >= pNodeList.Count)
                {
                    return(null);
                }
                return(pNodeList[idx]);
            };

            List <QuadGroupNode <T> > nodeList = new List <QuadGroupNode <T> >();

            for (int r = 0; r < rCnt; ++r)
            {
                for (int c = 0; c < cCnt; ++c)
                {
                    /*
                     * 3 4
                     * 1 2
                     */

                    int  rr        = r * _cPer;
                    int  cc        = c * _cPer;
                    int  idx1      = (rr) * col + cc;
                    int  idx2      = -1;
                    bool isVaildCC = cc + 1 < col;
                    if (isVaildCC)
                    {
                        idx2 = (rr) * col + cc + 1;
                    }

                    int  idx3      = -1;
                    bool isVaildrr = rr + 1 < row;
                    if (isVaildrr)
                    {
                        idx3 = (rr + 1) * col + cc;
                    }
                    int idx4 = -1;
                    if (isVaildCC && isVaildrr)
                    {
                        idx4 = (rr + 1) * col + cc + 1;
                    }

                    QuadGroupNode <T> root = AbstractPool <QuadGroupNode <T> > .GetNode() as QuadGroupNode <T>;

                    var n1 = GetItem(idx1);
                    var n2 = GetItem(idx2);
                    var n3 = GetItem(idx3);
                    var n4 = GetItem(idx4);

                    QuadGroupNodeArray <T> nodeArray = AbstractPool <QuadGroupNodeArray <T> > .GetNode() as QuadGroupNodeArray <T>;

                    nodeArray[0] = n1;
                    nodeArray[1] = n2;
                    nodeArray[2] = n3;
                    nodeArray[3] = n4;

                    root.Init(nodeArray);
                    nodeList.Add(root);
                }
            }



            row            = rCnt;
            col            = cCnt;
            parentNodeList = nodeList;
        }