Skip to content

Commit e8c877f

Browse files
Allowed specifying node types when subclassing QuadtreeMonoRoot
1 parent f56ee7a commit e8c877f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Scripts/GameObjectRootNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Quadtree
55
{
66
[ExecuteInEditMode]
77
[AddComponentMenu("Spatial partitioning/Quadtree/Root node (for GameObjects)")]
8-
public class GameObjectRootNode : QuadtreeMonoRoot<GameObjectItem>
8+
public class GameObjectRootNode : QuadtreeMonoRoot<GameObjectItem, Node<GameObjectItem>>
99
{
1010
}
1111
}

Scripts/QuadtreeMonoRoot.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ namespace Quadtree
77
/// <summary>
88
/// Main class of the Quadtree structure - it represents the root of the tree.
99
/// </summary>
10-
public abstract class QuadtreeMonoRoot<TItem> : MonoBehaviour, IQuadtreeRoot<TItem, Node<TItem>>
11-
where TItem : IItem<TItem, Node<TItem>>
10+
public abstract class QuadtreeMonoRoot<TItem, TNode> : MonoBehaviour, IQuadtreeRoot<TItem, TNode>
11+
where TItem : IItem<TItem, TNode>
12+
where TNode : INode<TItem, TNode>, new()
1213
{
1314
//==========================================================================dd==
1415
// MonoBehaviour METHODS
@@ -36,11 +37,11 @@ protected void OnDrawGizmos()
3637
/// <summary>
3738
/// Root node containing all items and sub-nodes.
3839
/// </summary>
39-
protected QuadtreeRoot<TItem, Node<TItem>> TreeRoot = null;
40+
protected QuadtreeRoot<TItem, TNode> TreeRoot = null;
4041

4142
public bool Initialized => TreeRoot != null && TreeRoot.Initialized;
4243

43-
public Node<TItem> CurrentRootNode => TreeRoot.CurrentRootNode;
44+
public TNode CurrentRootNode => TreeRoot.CurrentRootNode;
4445

4546
[SerializeField]
4647
protected Vector3 DefaultRootNodeSize = new Vector3(64f, 0f, 64f);
@@ -49,13 +50,13 @@ protected void OnDrawGizmos()
4950
[SerializeField]
5051
protected float MinimumPossibleNodeSize = 1f;
5152

52-
float IQuadtreeRoot<TItem, Node<TItem>>.MinimumPossibleNodeSize => MinimumPossibleNodeSize;
53+
float IQuadtreeRoot<TItem, TNode>.MinimumPossibleNodeSize => MinimumPossibleNodeSize;
5354

5455
/// <inheritdoc cref="IQuadtreeRoot{TItem, TNode}.DisplayNumberOfItemsInGizmos"/>
5556
[SerializeField]
5657
private bool DisplayNumberOfItemsInGizmos = false;
5758

58-
bool IQuadtreeRoot<TItem, Node<TItem>>.DisplayNumberOfItemsInGizmos => DisplayNumberOfItemsInGizmos;
59+
bool IQuadtreeRoot<TItem, TNode>.DisplayNumberOfItemsInGizmos => DisplayNumberOfItemsInGizmos;
5960

6061
/// <summary>
6162
/// Initializes Quadtree - creates initial root node and builds the tree (if allowed).
@@ -66,7 +67,7 @@ protected void Init()
6667
{
6768
if (TreeRoot == null)
6869
{
69-
TreeRoot = new QuadtreeRoot<TItem, Node<TItem>>(transform.position, DefaultRootNodeSize);
70+
TreeRoot = new QuadtreeRoot<TItem, TNode>(transform.position, DefaultRootNodeSize);
7071
}
7172
else
7273
{

0 commit comments

Comments
 (0)