コード例 #1
0
        private void AddToActiveMultithreaded(IBroadphaseEntity body, bool addToList)
        {
            FP   x   = body.BoundingBox.min.x;
            int  num = this.active.Count;
            bool isStaticOrInactive = body.IsStaticOrInactive;
            int  num2 = 0;

            while (num2 != num)
            {
                IBroadphaseEntity broadphaseEntity = this.active[num2];
                TSBBox            boundingBox      = broadphaseEntity.BoundingBox;
                bool flag = boundingBox.max.x < x;
                if (flag)
                {
                    num--;
                    this.active.RemoveAt(num2);
                }
                else
                {
                    TSBBox boundingBox2 = body.BoundingBox;
                    bool   flag2        = (!isStaticOrInactive || !broadphaseEntity.IsStaticOrInactive) && (boundingBox2.max.z >= boundingBox.min.z && boundingBox2.min.z <= boundingBox.max.z) && boundingBox2.max.y >= boundingBox.min.y && boundingBox2.min.y <= boundingBox.max.y;
                    if (flag2)
                    {
                        bool flag3 = base.RaisePassedBroadphase(broadphaseEntity, body);
                        if (flag3)
                        {
                            CollisionSystem.BroadphasePair @new = CollisionSystem.BroadphasePair.Pool.GetNew();
                            bool flag4 = this.swapOrder;
                            if (flag4)
                            {
                                @new.Entity1 = body;
                                @new.Entity2 = broadphaseEntity;
                            }
                            else
                            {
                                @new.Entity2 = body;
                                @new.Entity1 = broadphaseEntity;
                            }
                            this.swapOrder = !this.swapOrder;
                            this.threadManager.AddTask(this.detectCallback, @new);
                        }
                    }
                    num2++;
                }
            }
            this.active.Add(body);
        }
コード例 #2
0
 private void DetectCallback(object obj)
 {
     CollisionSystem.BroadphasePair broadphasePair = obj as CollisionSystem.BroadphasePair;
     base.Detect(broadphasePair.Entity1, broadphasePair.Entity2);
     CollisionSystem.BroadphasePair.Pool.GiveBack(broadphasePair);
 }
コード例 #3
0
        public override void Detect(bool multiThreaded)
        {
            bool flag = this.addCounter > 250;

            if (flag)
            {
                this.fullOverlaps.Clear();
                this.DirtySortAxis(this.axis1);
                this.DirtySortAxis(this.axis2);
                this.DirtySortAxis(this.axis3);
            }
            else if (multiThreaded)
            {
                this.threadManager.AddTask(this.sortCallback, this.axis1);
                this.threadManager.AddTask(this.sortCallback, this.axis2);
                this.threadManager.AddTask(this.sortCallback, this.axis3);
                threadManager.Execute();
            }
            else
            {
                this.sortCallback(this.axis1);
                this.sortCallback(this.axis2);
                this.sortCallback(this.axis3);
            }
            this.addCounter = 0;
            foreach (OverlapPair current in this.fullOverlaps)
            {
                bool flag2 = base.CheckBothStaticNonKinematic(current.Entity1, current.Entity2);
                if (!flag2)
                {
                    bool flag3 = base.RaisePassedBroadphase(current.Entity1, current.Entity2);
                    if (flag3)
                    {
                        if (multiThreaded)
                        {
                            CollisionSystem.BroadphasePair @new = CollisionSystem.BroadphasePair.Pool.GetNew();
                            bool flag4 = this.swapOrder;
                            if (flag4)
                            {
                                @new.Entity1 = current.Entity1;
                                @new.Entity2 = current.Entity2;
                            }
                            else
                            {
                                @new.Entity2 = current.Entity2;
                                @new.Entity1 = current.Entity1;
                            }
                            this.threadManager.AddTask(this.detectCallback, @new);
                        }
                        else
                        {
                            bool flag5 = this.swapOrder;
                            if (flag5)
                            {
                                this.Detect(current.Entity1, current.Entity2);
                            }
                            else
                            {
                                this.Detect(current.Entity2, current.Entity1);
                            }
                        }
                        this.swapOrder = !this.swapOrder;
                    }
                }
            }
            if (multiThreaded)
            {
                threadManager.Execute();
            }
        }
コード例 #4
0
        public override void Detect(bool multiThreaded)
        {
            int count = this.bodyList.Count;

            if (multiThreaded)
            {
                for (int i = 0; i < count; i++)
                {
                    for (int j = i + 1; j < count; j++)
                    {
                        bool flag = !base.CheckBothStaticOrInactive(this.bodyList[i], this.bodyList[j]) && base.CheckBoundingBoxes(this.bodyList[i], this.bodyList[j]);
                        if (flag)
                        {
                            bool flag2 = base.RaisePassedBroadphase(this.bodyList[i], this.bodyList[j]);
                            if (flag2)
                            {
                                CollisionSystem.BroadphasePair @new = CollisionSystem.BroadphasePair.Pool.GetNew();
                                bool flag3 = this.swapOrder;
                                if (flag3)
                                {
                                    @new.Entity1 = this.bodyList[i];
                                    @new.Entity2 = this.bodyList[j];
                                }
                                else
                                {
                                    @new.Entity2 = this.bodyList[j];
                                    @new.Entity1 = this.bodyList[i];
                                }
                                this.swapOrder = !this.swapOrder;
                                threadManager.AddTask(detectCallback, @new);
                            }
                        }
                    }
                }
                threadManager.Execute();
            }
            else
            {
                for (int k = 0; k < count; k++)
                {
                    for (int l = k + 1; l < count; l++)
                    {
                        bool flag4 = !base.CheckBothStaticOrInactive(this.bodyList[k], this.bodyList[l]) && base.CheckBoundingBoxes(this.bodyList[k], this.bodyList[l]);
                        if (flag4)
                        {
                            bool flag5 = base.RaisePassedBroadphase(this.bodyList[k], this.bodyList[l]);
                            if (flag5)
                            {
                                bool flag6 = this.swapOrder;
                                if (flag6)
                                {
                                    this.Detect(this.bodyList[k], this.bodyList[l]);
                                }
                                else
                                {
                                    this.Detect(this.bodyList[l], this.bodyList[k]);
                                }
                                this.swapOrder = !this.swapOrder;
                            }
                        }
                    }
                }
            }
        }