From acea7b2e728787a0d83bbf83c8c1f042d2c32e7e Mon Sep 17 00:00:00 2001
From: chai <215380520@qq.com>
Date: Mon, 3 Jun 2024 10:15:45 +0800
Subject: + plugins project
---
.../QuadTree/QuadTreeData.cs | 88 ++++++++++++++++++++++
1 file changed, 88 insertions(+)
create mode 100644 Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs
(limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs')
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs
new file mode 100644
index 0000000..db6da3e
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Collisions/QuadTree/QuadTreeData.cs
@@ -0,0 +1,88 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MonoGame.Extended.Collisions.QuadTree;
+
+///
+/// Data structure for the quad tree.
+/// Holds the entity and collision data for it.
+///
+public class QuadtreeData
+{
+ private readonly ICollisionActor _target;
+ private readonly HashSet _parents = new();
+
+ ///
+ /// Initialize a new instance of QuadTreeData.
+ ///
+ ///
+ public QuadtreeData(ICollisionActor target)
+ {
+ _target = target;
+ Bounds = _target.Bounds.BoundingRectangle;
+ }
+
+ ///
+ /// Remove a parent node.
+ ///
+ ///
+ public void RemoveParent(QuadTree parent)
+ {
+ _parents.Remove(parent);
+ }
+
+ ///
+ /// Add a parent node.
+ ///
+ ///
+ public void AddParent(QuadTree parent)
+ {
+ _parents.Add(parent);
+ Bounds = _target.Bounds.BoundingRectangle;
+ }
+
+ ///
+ /// Remove all parent nodes from this node.
+ ///
+ public void RemoveFromAllParents()
+ {
+ foreach (var parent in _parents.ToList())
+ {
+ parent.Remove(this);
+ }
+
+ _parents.Clear();
+ }
+
+ ///
+ /// Gets the bounding box for collision detection.
+ ///
+ public RectangleF Bounds { get; set; }
+
+ ///
+ /// Gets the collision actor target.
+ ///
+ public ICollisionActor Target => _target;
+
+ ///
+ /// Gets or sets whether Target has had its collision handled this
+ /// iteration.
+ ///
+ public bool Dirty { get; private set; }
+
+ ///
+ /// Mark node as dirty.
+ ///
+ public void MarkDirty()
+ {
+ Dirty = true;
+ }
+
+ ///
+ /// Mark node as clean, i.e. not dirty.
+ ///
+ public void MarkClean()
+ {
+ Dirty = false;
+ }
+}
--
cgit v1.1-26-g67d0