private Node AllocateNode(out int nodeId)
        {
            // Expand the node pool as needed
            if (this.freeList == NULL_NODE)
            {
                VoltDebug.Assert(this.nodeCount == this.nodeCapacity);

                // The free list is empty -- rebuild a bigger pool
                Node[] oldNodes = this.nodes;
                this.nodeCapacity = VoltUtil.ExpandArray(ref this.nodes);
                Array.Copy(oldNodes, this.nodes, this.nodeCount);

                // Build a linked list for the free list
                // The parent pointer becomes the "next" pointer
                for (int i = this.nodeCount; i < this.nodeCapacity - 1; ++i)
                {
                    this.nodes[i] = new Node(i + 1, -1);
                }

                this.nodes[this.nodeCapacity - 1] = new Node(NULL_NODE, -1);
                this.freeList = this.nodeCount;
            }

            // Peel a node off the free list.
            nodeId = this.freeList;
            Node result = this.nodes[nodeId];

            this.freeList = result.parentOrNext;
            result.Reset();

            this.nodeCount++;
            return(result);
        }
示例#2
0
        private static Manifold Polygon_Polygon(
            VoltWorld world,
            VoltPolygon polyA,
            VoltPolygon polyB)
        {
            Axis a1, a2;

            if (Collision.FindMinSepAxis(polyA, polyB, out a1) == false)
            {
                return(null);
            }
            if (Collision.FindMinSepAxis(polyB, polyA, out a2) == false)
            {
                return(null);
            }

            // We will use poly1's axis, so we may need to swap
            if (a2.Width > a1.Width)
            {
                VoltUtil.Swap(ref polyA, ref polyB);
                VoltUtil.Swap(ref a1, ref a2);
            }

            // Build the collision Manifold
            Manifold manifold =
                world.AllocateManifold().Assign(world, polyA, polyB);

            Collision.FindVerts(polyA, polyB, a1.Normal, a1.Width, manifold);
            return(manifold);
        }
示例#3
0
        internal void Add(T[] bodies, int count)
        {
            if ((this.count + count) >= this.items.Length)
            {
                VoltUtil.ExpandArray(ref this.items, (this.count + count));
            }

            Array.Copy(bodies, 0, this.items, this.count, count);
            this.count += count;
        }
示例#4
0
        /// <summary>
        /// Adds a new element to the end of the list. Returns the index of the
        /// newly-indexed object.
        /// </summary>
        internal void Add(T body)
        {
            if (this.count >= this.items.Length)
            {
                VoltUtil.ExpandArray(ref this.items);
            }

            this.items[this.count] = body;
            this.count++;
        }
示例#5
0
        public void AddBody(VoltBody body)
        {
            if (this.count >= this.bodies.Length)
            {
                VoltUtil.ExpandArray(ref this.bodies);
            }

            this.bodies[this.count] = body;
            body.ProxyId            = this.count;
            this.count++;
        }
示例#6
0
        /// <summary>
        /// Adds a new element to the end of the list. Returns the index of the
        /// newly-indexed object.
        /// </summary>
        public void Add(T value)
        {
            if (this.count >= this.values.Length)
            {
                VoltUtil.ExpandArray(ref this.values);
            }

            this.values[this.count] = value;
            value.Index             = this.count;
            this.count++;
        }