From c3f8023ef068e4297238e94b3cd2d4e4a1a25956 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 28 Mar 2018 17:41:18 -0400 Subject: [PATCH] Core/Vmaps: Fixed getting map height near large gameobjects like LK platform --- Source/Game/Collision/DynamicTree.cs | 7 ++----- Source/Game/Collision/RegularGrid2D.cs | 29 +++++++++++++------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Source/Game/Collision/DynamicTree.cs b/Source/Game/Collision/DynamicTree.cs index 9dd069915..6a2c9fb21 100644 --- a/Source/Game/Collision/DynamicTree.cs +++ b/Source/Game/Collision/DynamicTree.cs @@ -48,10 +48,7 @@ namespace Game.Collision { impl.balance(); } - int size() - { - return impl.size(); - } + public void update(uint diff) { impl.update(diff); @@ -161,7 +158,7 @@ namespace Game.Collision public void update(uint difftime) { - if (size() == 0) + if (empty()) return; rebalance_timer.Update((int)difftime); diff --git a/Source/Game/Collision/RegularGrid2D.cs b/Source/Game/Collision/RegularGrid2D.cs index bd0c42618..0a173f0fa 100644 --- a/Source/Game/Collision/RegularGrid2D.cs +++ b/Source/Game/Collision/RegularGrid2D.cs @@ -37,17 +37,24 @@ namespace Game.Collision public virtual void insert(T value) { - Vector3 pos = value.getPosition(); - Node node = getGridFor(pos.X, pos.Y); - node.insert(value); - memberTable.TryAdd(value, node); + AxisAlignedBox bounds = value.getBounds(); + Cell low = Cell.ComputeCell(bounds.Lo.X, bounds.Lo.Y); + Cell high = Cell.ComputeCell(bounds.Hi.X, bounds.Hi.Y); + for (int x = low.x; x <= high.x; ++x) + { + for (int y = low.y; y <= high.y; ++y) + { + Node node = getGrid(x, y); + node.insert(value); + memberTable.Add(value, node); + } + } } public virtual void remove(T value) { - memberTable[value].remove(value); // Remove the member - memberTable.TryRemove(value, out Node node); + memberTable.Remove(value); } public virtual void balance() @@ -64,7 +71,7 @@ namespace Game.Collision } public bool contains(T value) { return memberTable.ContainsKey(value); } - public int size() { return memberTable.Count; } + public bool empty() { return memberTable.Empty(); } public struct Cell { @@ -92,12 +99,6 @@ namespace Game.Collision public bool isValid() { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER; } } - Node getGridFor(float fx, float fy) - { - Cell c = Cell.ComputeCell(fx, fy); - return getGrid(c.x, c.y); - } - Node getGrid(int x, int y) { Contract.Assert(x < CELL_NUMBER && y < CELL_NUMBER); @@ -206,7 +207,7 @@ namespace Game.Collision node.intersectRay(ray, intersectCallback, ref max_dist); } - ConcurrentDictionary memberTable = new ConcurrentDictionary(); + MultiMap memberTable = new MultiMap(); Node[][] nodes = new Node[CELL_NUMBER][]; } }