Skip to content

Commit

Permalink
Create properties for dynamicTree.Proxies and world.RigidBodies
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Nov 27, 2024
1 parent 6df9965 commit ff3eec7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/Jitter2/Collision/DynamicTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public partial class DynamicTree

private readonly ActiveList<IDynamicTreeProxy> proxies = new();

public readonly ReadOnlyActiveList<IDynamicTreeProxy> Proxies;
public ReadOnlyActiveList<IDynamicTreeProxy> Proxies => new ReadOnlyActiveList<IDynamicTreeProxy>(proxies);

/// <summary>
/// Gets the PairHashSet that contains pairs representing potential collisions. This should not be modified directly.
Expand Down Expand Up @@ -125,7 +125,7 @@ public struct Node
private readonly Stack<int> freeNodes = new();
private int nodePointer = -1;
private int root = NullNode;

private Action<Parallel.Batch> updateBoundingBoxes;

/// <summary>
Expand All @@ -150,10 +150,8 @@ public DynamicTree(Func<IDynamicTreeProxy, IDynamicTreeProxy, bool> filter)
ScanForOverlaps(batch.BatchIndex, false);
};

Proxies = new ReadOnlyActiveList<IDynamicTreeProxy>(proxies);

scanOverlapsPost = batch => { ScanForOverlaps(batch.BatchIndex, true); };

updateBoundingBoxes = UpdateBoundingBoxesCallback;

Filter = filter;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Jitter2/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static (ulong min, ulong max) RequestId(int count)
/// <summary>
/// All rigid bodies in this world.
/// </summary>
public ReadOnlyActiveList<RigidBody> RigidBodies { get; private set; }
public ReadOnlyActiveList<RigidBody> RigidBodies => new ReadOnlyActiveList<RigidBody>(bodies);

/// <summary>
/// Access to the <see cref="DynamicTree"/> instance. The instance
Expand Down Expand Up @@ -263,8 +263,6 @@ public World(Capacity capacity)

InitParallelCallbacks();

RigidBodies = new ReadOnlyActiveList<RigidBody>(bodies);

NullBody = CreateRigidBody();
NullBody.IsStatic = true;

Expand Down

0 comments on commit ff3eec7

Please sign in to comment.