Example #1
0
        internal override void GetOverlaps(Node opposingNode, DynamicHierarchy owner)
        {
            bool intersects;

            //note: This is never executed when the opposing node is the current node.
            if (opposingNode.IsLeaf)
            {
                //We're both leaves!  Our parents have already done the testing for us, so we know we're overlapping.
                owner.TryToAddOverlap(element, opposingNode.Element);
            }
            else
            {
                var opposingChildA = opposingNode.ChildA;
                var opposingChildB = opposingNode.ChildB;
                //If it's not a leaf, try to go deeper in the opposing hierarchy.
                BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                if (intersects)
                {
                    GetOverlaps(opposingChildA, owner);
                }
                BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                if (intersects)
                {
                    GetOverlaps(opposingChildB, owner);
                }
            }
        }
Example #2
0
        ///<summary>
        /// Constructs a new space for things to live in.
        ///</summary>
        ///<param name="parallelLooper">Used by the space to perform multithreaded updates. Pass null if multithreading is not required.</param>
        public Space(IParallelLooper parallelLooper)
        {
            timeStepSettings = new TimeStepSettings();

            this.parallelLooper = parallelLooper;

            SpaceObjectBuffer      = new SpaceObjectBuffer(this);
            EntityStateWriteBuffer = new EntityStateWriteBuffer();
            DeactivationManager    = new DeactivationManager(TimeStepSettings, ParallelLooper);
            ForceUpdater           = new ForceUpdater(TimeStepSettings, ParallelLooper);
            BoundingBoxUpdater     = new BoundingBoxUpdater(TimeStepSettings, ParallelLooper);
            BroadPhase             = new DynamicHierarchy(ParallelLooper);
            NarrowPhase            = new NarrowPhase(TimeStepSettings, BroadPhase.Overlaps, ParallelLooper);
            Solver                  = new Solver(TimeStepSettings, DeactivationManager, ParallelLooper);
            NarrowPhase.Solver      = Solver;
            PositionUpdater         = new ContinuousPositionUpdater(TimeStepSettings, ParallelLooper);
            BufferedStates          = new BufferedStatesManager(ParallelLooper);
            DeferredEventDispatcher = new DeferredEventDispatcher();

            DuringForcesUpdateables         = new DuringForcesUpdateableManager(timeStepSettings, ParallelLooper);
            BeforeNarrowPhaseUpdateables    = new BeforeNarrowPhaseUpdateableManager(timeStepSettings, ParallelLooper);
            BeforeSolverUpdateables         = new BeforeSolverUpdateableManager(timeStepSettings, ParallelLooper);
            BeforePositionUpdateUpdateables = new BeforePositionUpdateUpdateableManager(timeStepSettings, ParallelLooper);
            EndOfTimeStepUpdateables        = new EndOfTimeStepUpdateableManager(timeStepSettings, ParallelLooper);
            EndOfFrameUpdateables           = new EndOfFrameUpdateableManager(timeStepSettings, ParallelLooper);
        }
 internal DynamicHierarchyQueryAccelerator(DynamicHierarchy hierarchy)
 {
     this.hierarchy = hierarchy;
 }
Example #4
0
        internal override void GetMultithreadedOverlaps(Node opposingNode, int splitDepth, int currentDepth, DynamicHierarchy owner, RawList <DynamicHierarchy.NodePair> multithreadingSourceOverlaps)
        {
            bool intersects;

            //note: This is never executed when the opposing node is the current node.
            if (opposingNode.IsLeaf)
            {
                //We're both leaves!  Our parents have already done the testing for us, so we know we're overlapping.
                owner.TryToAddOverlap(element, opposingNode.Element);
            }
            else
            {
                var opposingChildA = opposingNode.ChildA;
                var opposingChildB = opposingNode.ChildB;
                if (splitDepth == currentDepth)
                {
                    //Time to add the child overlaps to the multithreading set!
                    BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                    if (intersects)
                    {
                        multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                        {
                            a = this, b = opposingChildA
                        });
                    }
                    BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                        {
                            a = this, b = opposingChildB
                        });
                    }

                    return;
                }
                //If it's not a leaf, try to go deeper in the opposing hierarchy.
                BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                if (intersects)
                {
                    GetOverlaps(opposingChildA, owner);
                }
                BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                if (intersects)
                {
                    GetOverlaps(opposingChildB, owner);
                }
            }
        }
Example #5
0
        internal override void GetMultithreadedOverlaps(Node opposingNode, int splitDepth, int currentDepth, DynamicHierarchy owner, RawList <DynamicHierarchy.NodePair> multithreadingSourceOverlaps)
        {
            bool intersects;

            if (currentDepth == splitDepth)
            {
                //We've reached the depth where our child comparisons will be multithreaded.
                if (this == opposingNode)
                {
                    //We are being compared against ourselves!
                    //Obviously we're an internal node, so spawn three children:
                    //A versus A:
                    if (!childA.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                    {
                        multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                        {
                            a = childA, b = childA
                        });
                    }
                    //B versus B:
                    if (!childB.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                    {
                        multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                        {
                            a = childB, b = childB
                        });
                    }
                    //A versus B (if they intersect):
                    childA.BoundingBox.Intersects(ref childB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                        {
                            a = childA, b = childB
                        });
                    }
                }
                else
                {
                    //Two different nodes.  The other one may be a leaf.
                    if (opposingNode.IsLeaf)
                    {
                        //If it's a leaf, go deeper in our hierarchy, but not the opposition.
                        childA.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childA, b = opposingNode
                            });
                        }
                        childB.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childB, b = opposingNode
                            });
                        }
                    }
                    else
                    {
                        var opposingChildA = opposingNode.ChildA;
                        var opposingChildB = opposingNode.ChildB;
                        //If it's not a leaf, try to go deeper in both hierarchies.
                        childA.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childA, b = opposingChildA
                            });
                        }
                        childA.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childA, b = opposingChildB
                            });
                        }
                        childB.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childB, b = opposingChildA
                            });
                        }
                        childB.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                        if (intersects)
                        {
                            multithreadingSourceOverlaps.Add(new DynamicHierarchy.NodePair()
                            {
                                a = childB, b = opposingChildB
                            });
                        }
                    }
                }
                return;
            }
            if (this == opposingNode)
            {
                //We are being compared against ourselves!
                //Obviously we're an internal node, so spawn three children:
                //A versus A:
                if (!childA.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                {
                    childA.GetMultithreadedOverlaps(childA, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                }
                //B versus B:
                if (!childB.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                {
                    childB.GetMultithreadedOverlaps(childB, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                }
                //A versus B (if they intersect):
                childA.BoundingBox.Intersects(ref childB.BoundingBox, out intersects);
                if (intersects)
                {
                    childA.GetMultithreadedOverlaps(childB, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                }
            }
            else
            {
                //Two different nodes.  The other one may be a leaf.
                if (opposingNode.IsLeaf)
                {
                    //If it's a leaf, go deeper in our hierarchy, but not the opposition.
                    childA.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetMultithreadedOverlaps(opposingNode, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                    childB.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetMultithreadedOverlaps(opposingNode, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                }
                else
                {
                    var opposingChildA = opposingNode.ChildA;
                    var opposingChildB = opposingNode.ChildB;
                    //If it's not a leaf, try to go deeper in both hierarchies.
                    childA.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetMultithreadedOverlaps(opposingChildA, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                    childA.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetMultithreadedOverlaps(opposingChildB, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                    childB.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetMultithreadedOverlaps(opposingChildA, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                    childB.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetMultithreadedOverlaps(opposingChildB, splitDepth, currentDepth + 1, owner, multithreadingSourceOverlaps);
                    }
                }
            }
        }
Example #6
0
 internal abstract void GetMultithreadedOverlaps(Node opposingNode, int splitDepth, int currentDepth, DynamicHierarchy owner, RawList <DynamicHierarchy.NodePair> multithreadingSourceOverlaps);
Example #7
0
        internal override void GetOverlaps(Node opposingNode, DynamicHierarchy owner)
        {
            bool intersects;

            if (this == opposingNode)
            {
                //We are being compared against ourselves!
                //Obviously we're an internal node, so spawn three children:
                //A versus A:
                if (!childA.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                {
                    childA.GetOverlaps(childA, owner);
                }
                //B versus B:
                if (!childB.IsLeaf) //This is performed in the child method usually by convention, but this saves some time.
                {
                    childB.GetOverlaps(childB, owner);
                }
                //A versus B (if they intersect):
                childA.BoundingBox.Intersects(ref childB.BoundingBox, out intersects);
                if (intersects)
                {
                    childA.GetOverlaps(childB, owner);
                }
            }
            else
            {
                //Two different nodes.  The other one may be a leaf.
                if (opposingNode.IsLeaf)
                {
                    //If it's a leaf, go deeper in our hierarchy, but not the opposition.
                    childA.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetOverlaps(opposingNode, owner);
                    }
                    childB.BoundingBox.Intersects(ref opposingNode.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetOverlaps(opposingNode, owner);
                    }
                }
                else
                {
                    var opposingChildA = opposingNode.ChildA;
                    var opposingChildB = opposingNode.ChildB;
                    //If it's not a leaf, try to go deeper in both hierarchies.
                    childA.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetOverlaps(opposingChildA, owner);
                    }
                    childA.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childA.GetOverlaps(opposingChildB, owner);
                    }
                    childB.BoundingBox.Intersects(ref opposingChildA.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetOverlaps(opposingChildA, owner);
                    }
                    childB.BoundingBox.Intersects(ref opposingChildB.BoundingBox, out intersects);
                    if (intersects)
                    {
                        childB.GetOverlaps(opposingChildB, owner);
                    }
                }
            }
        }
Example #8
0
 internal abstract void GetOverlaps(Node node, DynamicHierarchy owner);