Ejemplo n.º 1
0
        public void Insert(Agent agent)
        {
            int   index  = 0;
            VRect bounds = this.bounds;
            VInt2 xz     = agent.position.xz;

            agent.next     = null;
            this.maxRadius = IntMath.Max((long)agent.radius.i, this.maxRadius);
            int num3 = 0;

            while (true)
            {
                num3++;
                if (this.nodes[index].child00 == index)
                {
                    if ((this.nodes[index].count < 15) || (num3 > 10))
                    {
                        this.nodes[index].Add(agent);
                        this.nodes[index].count = (byte)(this.nodes[index].count + 1);
                        return;
                    }
                    Node node = this.nodes[index];
                    node.child00      = this.GetNodeIndex();
                    node.child01      = this.GetNodeIndex();
                    node.child10      = this.GetNodeIndex();
                    node.child11      = this.GetNodeIndex();
                    this.nodes[index] = node;
                    this.nodes[index].Distribute(this.nodes, bounds);
                }
                if (this.nodes[index].child00 != index)
                {
                    VInt2 center = bounds.center;
                    if (xz.x > center.x)
                    {
                        if (xz.y > center.y)
                        {
                            index  = this.nodes[index].child11;
                            bounds = VRect.MinMaxRect(center.x, center.y, bounds.xMax, bounds.yMax);
                        }
                        else
                        {
                            index  = this.nodes[index].child10;
                            bounds = VRect.MinMaxRect(center.x, bounds.yMin, bounds.xMax, center.y);
                        }
                    }
                    else if (xz.y > center.y)
                    {
                        index  = this.nodes[index].child01;
                        bounds = VRect.MinMaxRect(bounds.xMin, center.y, center.x, bounds.yMax);
                    }
                    else
                    {
                        index  = this.nodes[index].child00;
                        bounds = VRect.MinMaxRect(bounds.xMin, bounds.yMin, center.x, center.y);
                    }
                }
            }
        }
Ejemplo n.º 2
0
    void Update()
    {
        VInt now        = (VInt)Time.time;
        int  frameCount = frameOrderList.Count;

        if (now - lastFrameTime >= nextFrameWaitTime && frameCount > 0)
        {
            lastFrameTime = now;
            // 循环体
            Loop();
            // 调整循环速度,对抗网络延迟
            if (frameCount == 1)
            {
                nextFrameWaitTime = (VInt)0.05f;
            }
            else if (frameCount == 2)
            {
                nextFrameWaitTime = (VInt)0.038f;
            }
            else if (frameCount <= 4)
            {
                nextFrameWaitTime = (VInt)0.016f;
            }
            else if (frameCount <= 16)
            {
                nextFrameWaitTime = (VInt)0.0f;
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    Loop();
                }
                nextFrameWaitTime = (VInt)0.0f;
            }
            nextFrameWaitTime = IntMath.Max((VInt)0, nextFrameWaitTime - (VInt)Time.deltaTime / (VInt)2.0f);
        }
    }
        public void Insert(Agent agent)
        {
            int   num = 0;
            VRect r   = this.bounds;
            VInt2 xz  = agent.position.xz;

            agent.next     = null;
            this.maxRadius = IntMath.Max((long)agent.radius.i, this.maxRadius);
            int num2 = 0;

            while (true)
            {
                num2++;
                if (this.nodes[num].child00 == num)
                {
                    if (this.nodes[num].count < 15 || num2 > 10)
                    {
                        break;
                    }
                    RVOQuadtree.Node node = this.nodes[num];
                    node.child00    = this.GetNodeIndex();
                    node.child01    = this.GetNodeIndex();
                    node.child10    = this.GetNodeIndex();
                    node.child11    = this.GetNodeIndex();
                    this.nodes[num] = node;
                    this.nodes[num].Distribute(this.nodes, r);
                }
                if (this.nodes[num].child00 != num)
                {
                    VInt2 center = r.center;
                    if (xz.x > center.x)
                    {
                        if (xz.y > center.y)
                        {
                            num = this.nodes[num].child11;
                            r   = VRect.MinMaxRect(center.x, center.y, r.xMax, r.yMax);
                        }
                        else
                        {
                            num = this.nodes[num].child10;
                            r   = VRect.MinMaxRect(center.x, r.yMin, r.xMax, center.y);
                        }
                    }
                    else if (xz.y > center.y)
                    {
                        num = this.nodes[num].child01;
                        r   = VRect.MinMaxRect(r.xMin, center.y, center.x, r.yMax);
                    }
                    else
                    {
                        num = this.nodes[num].child00;
                        r   = VRect.MinMaxRect(r.xMin, r.yMin, center.x, center.y);
                    }
                }
            }
            this.nodes[num].Add(agent);
            RVOQuadtree.Node[] array = this.nodes;
            int num3 = num;

            array[num3].count = array[num3].count + 1;
        }