コード例 #1
0
ファイル: BSPCollisionChecker.cs プロジェクト: vb0067/LGame
 private BSPCollisionNode GetBSPNode()
 {
     if (size == 0)
     {
         return(new BSPCollisionNode(new RectBox(), 0, 0));
     }
     else
     {
         int ppos = tail - size;
         if (ppos < 0)
         {
             ppos += MAX_SIZE;
         }
         BSPCollisionNode node = cache[ppos];
         node.SetParent((BSPCollisionNode)null);
         --size;
         return(node);
     }
 }
コード例 #2
0
ファイル: BSPCollisionChecker.cs プロジェクト: vb0067/LGame
        private BSPCollisionNode CheckRemoveNode(BSPCollisionNode node)
        {
            int idx = 0;

            for (; idx < MAX_SIZE;)
            {
                if (node != null && node.IsEmpty())
                {
                    BSPCollisionNode parent = node.GetParent();
                    int side = (parent != null) ? parent.GetChildSide(node) : 3;
                    BSPCollisionNode left  = node.GetLeft();
                    BSPCollisionNode right = node.GetRight();
                    if (left == null)
                    {
                        if (parent != null)
                        {
                            if (right != null)
                            {
                                right.SetArea(node.GetArea());
                            }
                            parent.SetChild(side, right);
                        }
                        else
                        {
                            this.bspTree = right;
                            if (right != null)
                            {
                                right.SetParent((BSPCollisionNode)null);
                            }
                        }
                        node.SetChild(1, (BSPCollisionNode)null);
                        ReturnNode(node);
                        node = parent;
                        continue;
                    }

                    if (right == null)
                    {
                        if (parent != null)
                        {
                            if (left != null)
                            {
                                left.SetArea(node.GetArea());
                            }

                            parent.SetChild(side, left);
                        }
                        else
                        {
                            this.bspTree = left;
                            if (left != null)
                            {
                                left.SetParent((BSPCollisionNode)null);
                            }
                        }

                        node.SetChild(0, (BSPCollisionNode)null);
                        ReturnNode(node);
                        node = parent;
                        continue;
                    }
                }
                idx++;
                return(node);
            }
            return(null);
        }