From eb73f77e18423c984837e70ddb46b0ffaf467e73 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Mon, 8 May 2023 09:27:52 +0800 Subject: *misc --- marching/Assets/Scripts/Physics/Quadtree.cs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'marching/Assets/Scripts/Physics') 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); } /// -- cgit v1.1-26-g67d0