public void TestInit() { _tree = new DynamicQuadTree(new BoundingBox(new Vector3(0, 0, float.MinValue), new Vector3(100000, 100000, float.MaxValue))); _r = new Random(); _mockEntities = new List <IWorldEntity>(); }
private static int CheckChildrenEntityCount(DynamicQuadTree node) { if (!node.IsLeaf) { var reportedAmount = node.NumEntities; var calculatedAmount = node.Children.Sum(c => CheckChildrenEntityCount(c)); Assert.AreEqual(reportedAmount, calculatedAmount); return(calculatedAmount); } return(node.NumEntities); }
public IIndex <int, WorldBounds, WorldPoint> this[int index] { get { if (_trees[index] == null) { #if FARMATH _trees[index] = new FarCollections.SpatialHashedQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #else _trees[index] = new DynamicQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #endif _changed[index] = new HashSet <int>(); } return(_trees[index]); } }
private int CheckChildrenEntityCount(DynamicQuadTree node) { if (node.IsLeaf) { return(node.NumEntities); } var reportedAmount = node.NumEntities; var calculatedAmount = 0; foreach (var c in node.Children) { calculatedAmount += CheckChildrenEntityCount(c); } Assert.AreEqual(reportedAmount, calculatedAmount); return(calculatedAmount); }
public void Depacketize(IReadablePacket packet) { foreach (var tree in _trees.Where(tree => tree != null)) { tree.Clear(); } foreach (var changed in _changed.Where(changed => changed != null)) { changed.Clear(); } var indexCount = packet.ReadInt32(); for (var i = 0; i < indexCount; ++i) { var index = packet.ReadInt32(); if (_trees[index] == null) { #if FARMATH _trees[index] = new FarCollections.SpatialHashedQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #else _trees[index] = new DynamicQuadTree <int>(_maxEntriesPerNode, _minNodeBounds, 0.1f, 2f, (p, v) => p.Write(v), p => p.ReadInt32()); #endif } if (_changed[index] == null) { _changed[index] = new HashSet <int>(); } packet.ReadPacketizableInto(_trees[index]); var changedCount = packet.ReadInt32(); for (var j = 0; j < changedCount; ++j) { _changed[index].Add(packet.ReadInt32()); } } }
/// <summary>Renders a graphical representation of this tree's cells using the specified shape renderer.</summary> /// <param name="tree">The tree to render.</param> /// <param name="shape">The shape renderer to paint with.</param> /// <param name="translation">The translation to apply to all draw operation.</param> public static void Draw <T>(this DynamicQuadTree <T> tree, AbstractShape shape, TPoint translation) { var screenBounds = new TRectangle(-5000, -5000, 10000, 10000); foreach (var node in tree.GetNodeEnumerable()) { var bounds = node.Item1; bounds.Offset(translation); // ReSharper disable RedundantCast Necessary for FarCollections. var center = (Vector2)bounds.Center; // ReSharper restore RedundantCast if (screenBounds.Intersects(bounds) && !bounds.Contains(screenBounds)) { shape.SetCenter(center.X, center.Y); shape.SetSize((int)bounds.Width - 1, (int)bounds.Height - 1); shape.Draw(); } // Check entries. foreach (var entry in node.Item2) { bounds = tree[entry]; bounds.Offset(translation); // ReSharper disable RedundantCast Necessary for FarCollections. center = (Vector2)bounds.Center; // ReSharper restore RedundantCast if (screenBounds.Intersects(bounds) && !bounds.Contains(screenBounds)) { shape.SetCenter(center.X, center.Y); shape.SetSize((int)bounds.Width, (int)bounds.Height); shape.Draw(); } } } }
public void TestCleanup() { _tree = null; _r = null; _mockEntities = null; }
public void TestCleanup() { tree = null; r = null; mockEntities = null; }