summaryrefslogtreecommitdiff
path: root/marching/Assets/Scripts
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-05-08 09:27:52 +0800
committerchai <215380520@qq.com>2023-05-08 09:27:52 +0800
commiteb73f77e18423c984837e70ddb46b0ffaf467e73 (patch)
treec512b9f29721fb110f60652b82e1e99ff6ea81b1 /marching/Assets/Scripts
parentb5aeebf4835ba0d7335113dd3f320a4af5b6d148 (diff)
*misc
Diffstat (limited to 'marching/Assets/Scripts')
-rw-r--r--marching/Assets/Scripts/Physics/Quadtree.cs27
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>