diff --git a/src/Jitter2/Collision/DynamicTree.cs b/src/Jitter2/Collision/DynamicTree.cs index 17d8b63f..43a6e210 100644 --- a/src/Jitter2/Collision/DynamicTree.cs +++ b/src/Jitter2/Collision/DynamicTree.cs @@ -78,7 +78,7 @@ public partial class DynamicTree private readonly ActiveList proxies = new(); - public readonly ReadOnlyActiveList Proxies; + public ReadOnlyActiveList Proxies => new ReadOnlyActiveList(proxies); /// /// Gets the PairHashSet that contains pairs representing potential collisions. This should not be modified directly. @@ -125,7 +125,7 @@ public struct Node private readonly Stack freeNodes = new(); private int nodePointer = -1; private int root = NullNode; - + private Action updateBoundingBoxes; /// @@ -150,10 +150,8 @@ public DynamicTree(Func filter) ScanForOverlaps(batch.BatchIndex, false); }; - Proxies = new ReadOnlyActiveList(proxies); - scanOverlapsPost = batch => { ScanForOverlaps(batch.BatchIndex, true); }; - + updateBoundingBoxes = UpdateBoundingBoxesCallback; Filter = filter; @@ -204,7 +202,7 @@ void SetTime(Timings type) if (multiThread) { - Proxies.ParallelForBatch(256, updateBoundingBoxes); + proxies.ParallelForBatch(256, updateBoundingBoxes); const int taskThreshold = 24; int numTasks = Math.Clamp(proxies.ActiveCount / taskThreshold, 1, ThreadPool.Instance.ThreadCount); @@ -236,7 +234,7 @@ void SetTime(Timings type) } else { - var batch = new Parallel.Batch(0, Proxies.Active); + var batch = new Parallel.Batch(0, proxies.ActiveCount); UpdateBoundingBoxesCallback(batch); SetTime(Timings.UpdateBoundingBoxes); @@ -260,12 +258,12 @@ void SetTime(Timings type) } private Real step_dt; - + private void UpdateBoundingBoxesCallback(Parallel.Batch batch) { for (int i = batch.Start; i < batch.End; i++) { - var proxy = Proxies[i]; + var proxy = proxies[i]; if (proxy is IUpdatableBoundingBox sh) sh.UpdateWorldBoundingBox(step_dt); } } diff --git a/src/Jitter2/World.cs b/src/Jitter2/World.cs index a4aabbec..ecf68947 100644 --- a/src/Jitter2/World.cs +++ b/src/Jitter2/World.cs @@ -150,7 +150,7 @@ public static (ulong min, ulong max) RequestId(int count) /// /// All rigid bodies in this world. /// - public ReadOnlyActiveList RigidBodies { get; private set; } + public ReadOnlyActiveList RigidBodies => new ReadOnlyActiveList(bodies); /// /// Access to the instance. The instance @@ -263,8 +263,6 @@ public World(Capacity capacity) InitParallelCallbacks(); - RigidBodies = new ReadOnlyActiveList(bodies); - NullBody = CreateRigidBody(); NullBody.IsStatic = true;