コード例 #1
0
 /// <summary>
 /// Retrieves an BroadPhaseEntry list from the resource pool.
 /// </summary>
 /// <returns>Empty BroadPhaseEntry list.</returns>
 public static RawList <BroadPhaseEntry> GetBroadPhaseEntryList()
 {
     if (SubPoolBroadPhaseEntryList == null)
     {
         SubPoolBroadPhaseEntryList = new UnsafeResourcePool <RawList <BroadPhaseEntry> >();
     }
     return(SubPoolBroadPhaseEntryList.Take());
 }
コード例 #2
0
 /// <summary>
 /// Retrieves a Collidable list from the resource pool.
 /// </summary>
 /// <returns>Empty Collidable list.</returns>
 public static RawList <Collidable> GetCollidableList()
 {
     if (SubPoolCollidableList == null)
     {
         SubPoolCollidableList = new UnsafeResourcePool <RawList <Collidable> >();
     }
     return(SubPoolCollidableList.Take());
 }
コード例 #3
0
 /// <summary>
 /// Retrieves a simulation island connection from the resource pool.
 /// </summary>
 /// <returns>Uninitialized simulation island connection.</returns>
 public static SimulationIslandConnection GetSimulationIslandConnection()
 {
     if (SimulationIslandConnections == null)
     {
         SimulationIslandConnections = new UnsafeResourcePool <SimulationIslandConnection>();
     }
     return(SimulationIslandConnections.Take());
 }
コード例 #4
0
 //#endif
 /// <summary>
 /// Retrieves a ray cast result list from the resource pool.
 /// </summary>
 /// <returns>Empty ray cast result list.</returns>
 public static RawList <RayCastResult> GetRayCastResultList()
 {
     if (SubPoolRayCastResultList == null)
     {
         SubPoolRayCastResultList = new UnsafeResourcePool <RawList <RayCastResult> >();
     }
     return(SubPoolRayCastResultList.Take());
 }
コード例 #5
0
        /// <summary>
        /// Retrieves a TriangleCollidable from the resource pool.
        /// </summary>
        /// <param name="a">First vertex in the triangle.</param>
        /// <param name="b">Second vertex in the triangle.</param>
        /// <param name="c">Third vertex in the triangle.</param>
        /// <returns>Initialized TriangleCollidable.</returns>
        public static TriangleCollidable GetTriangleCollidable(ref Vector3 a, ref Vector3 b, ref Vector3 c)
        {
            if (SubPoolTriangleCollidables == null)
            {
                SubPoolTriangleCollidables = new UnsafeResourcePool <TriangleCollidable>();
            }
            var tri   = SubPoolTriangleCollidables.Take();
            var shape = tri.Shape;

            shape.vA = a;
            shape.vB = b;
            shape.vC = c;
            var identity = RigidTransform.Identity;

            tri.UpdateBoundingBoxForTransform(ref identity);
            return(tri);
        }
コード例 #6
0
 /// <summary>
 /// Retrieves a Triangle shape from the resource pool.
 /// </summary>
 /// <returns>Initialized TriangleShape.</returns>
 public static TriangleShape GetTriangle()
 {
     if (SubPoolTriangleShape == null)
     {
         SubPoolTriangleShape = new UnsafeResourcePool <TriangleShape>();
     }
     return(SubPoolTriangleShape.Take());
 }
コード例 #7
0
 /// <summary>
 /// Retrieves an Entity RawList from the resource pool.
 /// </summary>
 /// <returns>Empty Entity raw list.</returns>
 public static RawList <Entity> GetEntityRawList()
 {
     if (SubPoolEntityRawList == null)
     {
         SubPoolEntityRawList = new UnsafeResourcePool <RawList <Entity> >();
     }
     return(SubPoolEntityRawList.Take());
 }
コード例 #8
0
 /// <summary>
 /// Retrieves an CompoundChild list from the resource pool.
 /// </summary>
 /// <returns>Empty information list.</returns>
 public static RawList <CompoundChild> GetCompoundChildList()
 {
     if (SubPoolCompoundChildList == null)
     {
         SubPoolCompoundChildList = new UnsafeResourcePool <RawList <CompoundChild> >();
     }
     return(SubPoolCompoundChildList.Take());
 }
コード例 #9
0
        protected virtual void Add(ref ContactData contactCandidate)
        {
            Contact adding = unusedContacts.Take();

            adding.Setup(ref contactCandidate);
            contacts.Add(adding);
            OnAdded(adding);
        }
コード例 #10
0
        /// <summary>
        /// Tries to split connections between the two island members.
        /// </summary>
        /// <param name="member1">First island member.</param>
        /// <param name="member2">Second island member.</param>
        /// <returns>Whether a split operation was run.  This does not mean a split was
        /// successful, just that the expensive test was performed.</returns>
        private bool TryToSplit(SimulationIslandMember member1, SimulationIslandMember member2)
        {
            //Can't split if they aren't even in the same island.
            //This also covers the case where the connection involves a kinematic entity that has no
            //simulation island at all.
            if (member1.SimulationIsland != member2.SimulationIsland ||
                member1.SimulationIsland == null ||
                member2.SimulationIsland == null)
            {
                return(false);
            }


            //By now, we know the members belong to the same island and are not null.
            //Start a BFS starting from each member.
            //Two-way can complete the search quicker.

            member1Friends.Enqueue(member1);
            member2Friends.Enqueue(member2);
            searchedMembers1.Add(member1);
            searchedMembers2.Add(member2);
            member1.searchState = SimulationIslandSearchState.OwnedByFirst;
            member2.searchState = SimulationIslandSearchState.OwnedBySecond;

            while (member1Friends.Count > 0 && member2Friends.Count > 0)
            {
                SimulationIslandMember currentNode = member1Friends.Dequeue();
                for (int i = 0; i < currentNode.connections.Count; i++)
                {
                    for (int j = 0; j < currentNode.connections.Elements[i].entries.Count; j++)
                    {
                        SimulationIslandMember connectedNode;
                        if ((connectedNode = currentNode.connections.Elements[i].entries.Elements[j].Member) != currentNode &&
                            connectedNode.SimulationIsland != null) //The connection could be connected to something that isn't in the Space and has no island, or it's not dynamic.
                        {
                            switch (connectedNode.searchState)
                            {
                            case SimulationIslandSearchState.Unclaimed:
                                //Found a new friend :)
                                member1Friends.Enqueue(connectedNode);
                                connectedNode.searchState = SimulationIslandSearchState.OwnedByFirst;
                                searchedMembers1.Add(connectedNode);
                                break;

                            case SimulationIslandSearchState.OwnedBySecond:
                                //Found our way to member2Friends set; cannot split!
                                member1Friends.Clear();
                                member2Friends.Clear();
                                goto ResetSearchStates;
                            }
                        }
                    }
                }

                currentNode = member2Friends.Dequeue();
                for (int i = 0; i < currentNode.connections.Count; i++)
                {
                    for (int j = 0; j < currentNode.connections.Elements[i].entries.Count; j++)
                    {
                        SimulationIslandMember connectedNode;
                        if ((connectedNode = currentNode.connections.Elements[i].entries.Elements[j].Member) != currentNode &&
                            connectedNode.SimulationIsland != null) //The connection could be connected to something that isn't in the Space and has no island, or it's not dynamic.
                        {
                            switch (connectedNode.searchState)
                            {
                            case SimulationIslandSearchState.Unclaimed:
                                //Found a new friend :)
                                member2Friends.Enqueue(connectedNode);
                                connectedNode.searchState = SimulationIslandSearchState.OwnedBySecond;
                                searchedMembers2.Add(connectedNode);
                                break;

                            case SimulationIslandSearchState.OwnedByFirst:
                                //Found our way to member1Friends set; cannot split!
                                member1Friends.Clear();
                                member2Friends.Clear();
                                goto ResetSearchStates;
                            }
                        }
                    }
                }
            }
            //If one of the queues empties out without finding anything, it means it's isolated.  The other one will never find it.
            //Now we can do a split.  Grab a new Island, fill it with the isolated search stuff.  Remove the isolated search stuff from the old Island.


            SimulationIsland newIsland = islandPool.Take();

            simulationIslands.Add(newIsland);
            if (member1Friends.Count == 0)
            {
                //Member 1 is isolated, give it its own simulation island!
                for (int i = 0; i < searchedMembers1.Count; i++)
                {
                    searchedMembers1[i].simulationIsland.Remove(searchedMembers1[i]);
                    newIsland.Add(searchedMembers1[i]);
                }
                member2Friends.Clear();
            }
            else if (member2Friends.Count == 0)
            {
                //Member 2 is isolated, give it its own simulation island!
                for (int i = 0; i < searchedMembers2.Count; i++)
                {
                    searchedMembers2[i].simulationIsland.Remove(searchedMembers2[i]);
                    newIsland.Add(searchedMembers2[i]);
                }
                member1Friends.Clear();
            }

            //Force the system awake.
            //Technically, the members should already be awake.
            //However, calling Activate on them resets the members'
            //deactivation candidacy timers.  This prevents the island
            //from instantly going back to sleep, which could leave
            //objects hanging in mid-air.
            member1.Activate();
            member2.Activate();


ResetSearchStates:
            for (int i = 0; i < searchedMembers1.Count; i++)
            {
                searchedMembers1[i].searchState = SimulationIslandSearchState.Unclaimed;
            }
            for (int i = 0; i < searchedMembers2.Count; i++)
            {
                searchedMembers2[i].searchState = SimulationIslandSearchState.Unclaimed;
            }
            searchedMembers1.Clear();
            searchedMembers2.Clear();
            return(true);
        }