diff options
| author | chai <215380520@qq.com> | 2023-05-08 09:27:52 +0800 | 
|---|---|---|
| committer | chai <215380520@qq.com> | 2023-05-08 09:27:52 +0800 | 
| commit | eb73f77e18423c984837e70ddb46b0ffaf467e73 (patch) | |
| tree | c512b9f29721fb110f60652b82e1e99ff6ea81b1 /marching/Assets/Scripts/Physics/Quadtree.cs | |
| parent | b5aeebf4835ba0d7335113dd3f320a4af5b6d148 (diff) | |
*misc
Diffstat (limited to 'marching/Assets/Scripts/Physics/Quadtree.cs')
| -rw-r--r-- | marching/Assets/Scripts/Physics/Quadtree.cs | 27 | 
1 files changed, 18 insertions, 9 deletions
| diff --git a/marching/Assets/Scripts/Physics/Quadtree.cs b/marching/Assets/Scripts/Physics/Quadtree.cs index c157512..af7a005 100644 --- a/marching/Assets/Scripts/Physics/Quadtree.cs +++ b/marching/Assets/Scripts/Physics/Quadtree.cs @@ -16,7 +16,7 @@ namespace mh      public class Quadtree      { -        public const int kMaxObjectsPerBlock = 5; +        public const int kMaxObjectsPerBlock = 4;          public const int kMaxLevel = 20;          private int m_Level; @@ -146,16 +146,23 @@ namespace mh          public void Insert(IQuadTreeObject obj)          { -            if (m_SubTrees[0] != null) +            int index = GetSubtreeIndex(obj.bound); +            if(index != -1)              { -                int index = GetSubtreeIndex(obj.bound); -                if (index != -1) -                { -                    m_SubTrees[index].Insert(obj); -                    return; -                } +                if (m_SubTrees[0] == null) Split(); +                m_SubTrees[index].Insert(obj); +                return;              } +            //if (m_SubTrees[0] != null) +            //{ +            //    if (index != -1) +            //    { +            //        m_SubTrees[index].Insert(obj); +            //        return; +            //    } +            //} +              m_Objects.Add(obj);              if(m_Objects.Count > kMaxObjectsPerBlock && m_Level < kMaxLevel) // 本层满了之后重新排布层内对象 @@ -164,7 +171,7 @@ namespace mh                  for(int i = m_Objects.Count - 1; i >= 0; i--)                   { -                    int index = GetSubtreeIndex(m_Objects[i].bound); +                    index = GetSubtreeIndex(m_Objects[i].bound);                      if(index != -1)                       {                          IQuadTreeObject o = m_Objects[i]; @@ -173,6 +180,8 @@ namespace mh                      }                  }              } + +          // Debug.Log(m_Objects.Count);          }          /// <summary> | 
