Skip to content

Commit

Permalink
Rename ActiveList to Proxies in DynamicTree.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Aug 18, 2024
1 parent cc4892c commit 043a573
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
32 changes: 16 additions & 16 deletions src/Jitter2/Collision/DynamicTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class DynamicTree
{
private volatile SlimBag<IDynamicTreeProxy>[] lists = Array.Empty<SlimBag<IDynamicTreeProxy>>();

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

public readonly ReadOnlyActiveList<IDynamicTreeProxy> ActiveList;
public readonly ReadOnlyActiveList<IDynamicTreeProxy> Proxies;

/// <summary>
/// Gets the PairHashSet that contains pairs representing potential collisions. This should not be modified directly.
Expand Down Expand Up @@ -110,7 +110,7 @@ public DynamicTree(Func<IDynamicTreeProxy, IDynamicTreeProxy, bool> filter)
ScanForOverlaps(batch.BatchIndex, false);
};

ActiveList = new ReadOnlyActiveList<IDynamicTreeProxy>(activeList);
Proxies = new ReadOnlyActiveList<IDynamicTreeProxy>(proxies);

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

Expand Down Expand Up @@ -158,8 +158,8 @@ void SetTime(Timings type)
if (multiThread)
{
const int taskThreshold = 24;
int numTasks = Math.Clamp(activeList.Active / taskThreshold, 1, ThreadPool.Instance.ThreadCount);
Parallel.ForBatch(0, activeList.Active, numTasks, scanOverlapsPre);
int numTasks = Math.Clamp(proxies.Active / taskThreshold, 1, ThreadPool.Instance.ThreadCount);
Parallel.ForBatch(0, proxies.Active, numTasks, scanOverlapsPre);

SetTime(Timings.ScanOverlapsPre);

Expand All @@ -180,13 +180,13 @@ void SetTime(Timings type)

SetTime(Timings.UpdateProxies);

Parallel.ForBatch(0, activeList.Active, numTasks, scanOverlapsPost);
Parallel.ForBatch(0, proxies.Active, numTasks, scanOverlapsPost);

SetTime(Timings.ScanOverlapsPost);
}
else
{
scanOverlapsPre(new Parallel.Batch(0, activeList.Active));
scanOverlapsPre(new Parallel.Batch(0, proxies.Active));
SetTime(Timings.ScanOverlapsPre);

var sl = lists[0];
Expand All @@ -199,7 +199,7 @@ void SetTime(Timings type)

SetTime(Timings.UpdateProxies);

scanOverlapsPost(new Parallel.Batch(0, activeList.Active));
scanOverlapsPost(new Parallel.Batch(0, proxies.Active));
SetTime(Timings.ScanOverlapsPost);
}
}
Expand All @@ -223,25 +223,25 @@ public void AddProxy<T>(T proxy, bool active = true) where T : class, IDynamicTr
{
InternalAddProxy(proxy);
OverlapCheck(root, proxy.NodePtr, true);
activeList.Add(proxy, active);
proxies.Add(proxy, active);
}

public bool IsActive<T>(T proxy) where T : class, IDynamicTreeProxy
{
return activeList.IsActive(proxy);
return proxies.IsActive(proxy);
}

public void Activate<T>(T proxy) where T : class, IDynamicTreeProxy
{
if (activeList.MoveToActive(proxy))
if (proxies.MoveToActive(proxy))
{
Nodes[proxy.NodePtr].ForceUpdate = true;
}
}

public void Deactivate<T>(T proxy) where T : class, IDynamicTreeProxy
{
activeList.MoveToInactive(proxy);
proxies.MoveToInactive(proxy);
}

/// <summary>
Expand All @@ -252,7 +252,7 @@ public void RemoveProxy(IDynamicTreeProxy proxy)
OverlapCheck(root, proxy.NodePtr, false);
InternalRemoveProxy(proxy);
proxy.NodePtr = NullNode;
activeList.Remove(proxy);
proxies.Remove(proxy);
}

/// <summary>
Expand Down Expand Up @@ -413,9 +413,9 @@ public void Optimize(int sweeps = 100)
Stack<IDynamicTreeProxy> temp = new();
for (int e = 0; e < sweeps; e++)
{
for (int i = 0; i < activeList.Count; i++)
for (int i = 0; i < proxies.Count; i++)
{
var proxy = activeList[i];
var proxy = proxies[i];

if (optimizeRandom.NextDouble() > 0.01d) continue;

Expand Down Expand Up @@ -517,7 +517,7 @@ private void ScanForMovedProxies(Parallel.Batch batch)

for (int i = batch.Start; i < batch.End; i++)
{
var proxy = activeList[i];
var proxy = proxies[i];

ref var node = ref Nodes[proxy.NodePtr];

Expand Down
16 changes: 8 additions & 8 deletions src/Jitter2/World.Step.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public partial class World
private Action<Parallel.Batch> prepareSmallConstraints;
private Action<Parallel.Batch> iterateSmallConstraints;
private Action<Parallel.Batch> updateBodies;
private Action<Parallel.Batch> updateShapes;
private Action<Parallel.Batch> updateBoundingBoxes;
private Action<Parallel.Batch> detectCollisions;

private void InitParallelCallbacks()
Expand All @@ -70,7 +70,7 @@ private void InitParallelCallbacks()
iterateSmallConstraints = IterateSmallConstraintsCallback;
updateContacts = UpdateContactsCallback;
updateBodies = UpdateBodiesCallback;
updateShapes = UpdateShapesCallback;
updateBoundingBoxes = UpdateBoundingBoxesCallback;
detectCollisions = DetectCollisionsCallback;
}

Expand Down Expand Up @@ -210,12 +210,12 @@ void SetTime(Timings type)
}
}

private void UpdateShapesCallback(Parallel.Batch batch)
private void UpdateBoundingBoxesCallback(Parallel.Batch batch)
{
for (int i = batch.Start; i < batch.End; i++)
{
var shape = DynamicTree.ActiveList[i];
if (shape is IUpdatableBoundingBox sh) sh.UpdateWorldBoundingBox(step_dt);
var proxy = DynamicTree.Proxies[i];
if (proxy is IUpdatableBoundingBox sh) sh.UpdateWorldBoundingBox(step_dt);
}
}

Expand Down Expand Up @@ -447,12 +447,12 @@ private void ForeachActiveShape(bool multiThread)
{
if (multiThread)
{
DynamicTree.ActiveList.ParallelForBatch(256, updateShapes);
DynamicTree.Proxies.ParallelForBatch(256, updateBoundingBoxes);
}
else
{
Parallel.Batch batch = new(0, DynamicTree.ActiveList.Active);
UpdateShapesCallback(batch);
Parallel.Batch batch = new(0, DynamicTree.Proxies.Active);
UpdateBoundingBoxesCallback(batch);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Jitter2/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void Clear()
while (bodyStack.Count > 0) Remove(bodyStack.Pop());

// Left-over shapes not associated with a rigid body.
Stack<IDynamicTreeProxy> proxies = new(DynamicTree.ActiveList);
Stack<IDynamicTreeProxy> proxies = new(DynamicTree.Proxies);
while (proxies.Count > 0) DynamicTree.RemoveProxy(proxies.Pop());
}

Expand Down
2 changes: 1 addition & 1 deletion src/JitterDemo/Playground.Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void DebugDraw()

if (debugDrawShapes)
{
foreach (var shape in World.DynamicTree.ActiveList)
foreach (var shape in World.DynamicTree.Proxies)
{
var bb = shape.WorldBoundingBox;
DebugRenderer.PushBox(DebugRenderer.Color.Green, Conversion.FromJitter(bb.Min),
Expand Down
2 changes: 1 addition & 1 deletion src/JitterDemo/Playground.Gui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void AddRow(string a, string b, string c)
AddRow("Arbiter", $"{data.Contacts.Length}", $"{data.ActiveContacts.Length}");
AddRow("Constraints", $"{data.Constraints.Length}", $"{data.ActiveConstraints.Length}");
AddRow("SmallConstraints", $"{data.SmallConstraints.Length}", $"{data.ActiveSmallConstraints.Length}");
AddRow("Shapes", $"{World.DynamicTree.ActiveList.Count}", $"{World.DynamicTree.ActiveList.Active}");
AddRow("Proxies", $"{World.DynamicTree.Proxies.Count}", $"{World.DynamicTree.Proxies.Active}");

ImGui.EndTable();
ImGui.TreePop();
Expand Down

0 comments on commit 043a573

Please sign in to comment.