Skip to content

Commit

Permalink
Some tuning.
Browse files Browse the repository at this point in the history
  • Loading branch information
RossNordby committed Nov 29, 2024
1 parent 4e6d36d commit 16b77b8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 72 deletions.
1 change: 0 additions & 1 deletion BepuPhysics/CollisionDetection/CollidableOverlapFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ public void DispatchOverlaps3(float dt, IThreadDispatcher threadDispatcher = nul
narrowStack = &narrowTaskStack;
const int targetJobsPerThread = 1;
int maximumTaskSize = int.Max(1, previousPairCount3 / (threadDispatcher.ThreadCount * targetJobsPerThread));
//Console.WriteLine($"maixmum taskese: {maximumTaskSize}");
var estimatedMaximumTaskCountPerThread = targetJobsPerThread * 2;
for (int i = 0; i < threadDispatcher.ThreadCount; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void PrepareJobs(ref Tree treeA, ref Tree treeB, TOverlapHandler[] overla
return;
}
Debug.Assert(overlapHandlers.Length >= threadCount);
const float jobMultiplier = 8f;
const float jobMultiplier = 4f;
var targetJobCount = Math.Max(1, jobMultiplier * threadCount);
//TODO: Not a lot of thought was put into this leaf threshold for intertree. Probably better options.
leafThreshold = (int)((treeA.LeafCount + treeB.LeafCount) / targetJobCount);
Expand Down
2 changes: 1 addition & 1 deletion BepuPhysics/Trees/Tree_SelfQueriesMT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void PrepareJobs(ref Tree tree, TOverlapHandler[] overlapHandlers, int th
return;
}
Debug.Assert(overlapHandlers.Length >= threadCount);
const float jobMultiplier = 8f;
const float jobMultiplier = 4f;
var targetJobCount = Math.Max(1, jobMultiplier * threadCount);
leafThreshold = (int)(tree.LeafCount / targetJobCount);
jobs = new QuickList<Job>((int)(targetJobCount * 2), Pool);
Expand Down
69 changes: 0 additions & 69 deletions Demos/SpecializedTests/SimpleTestDemo.cs

This file was deleted.

69 changes: 69 additions & 0 deletions Demos/SpecializedTests/StaggeredDropTestDemo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using BepuUtilities;
using DemoRenderer;
using BepuPhysics;
using BepuPhysics.Collidables;
using System;
using System.Numerics;
using BepuUtilities.Collections;
using DemoContentLoader;
using BepuPhysics.Constraints;
using DemoUtilities;

namespace Demos.SpecializedTests;

public class StaggeredDropTestDemo : Demo
{
public override void Initialize(ContentArchive content, Camera camera)
{
camera.Position = new Vector3(-30, 10, -30);
//camera.Yaw = MathHelper.Pi ;
camera.Yaw = MathHelper.Pi * 3f / 4;
//camera.Pitch = MathHelper.PiOver2 * 0.999f;
Simulation = Simulation.Create(BufferPool, new DemoNarrowPhaseCallbacks(new SpringSettings(30, 1)), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new SolveDescription(4, 1));

var box = new Box(1f, 3f, 2f);

var boxInertia = box.ComputeInertia(1);
var boxIndex = Simulation.Shapes.Add(box);
const int width = 256;
const int height = 1;
const int length = 256;
var shapeCount = 0;
var random = new Random(5);
for (int i = 0; i < width; ++i)
{
for (int j = 0; j < height; ++j)
{
for (int k = 0; k < length; ++k)
{
var location = new Vector3(6, 3, 6) * new Vector3(i, j, k) + new Vector3(-width * 3, 5.5f + random.NextSingle() * 5, -length * 3);
var bodyDescription = BodyDescription.CreateDynamic(location, boxInertia, boxIndex, -0.01f);
var index = shapeCount++;
Simulation.Bodies.Add(bodyDescription);
}
}
}

Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(new Box(5000, 1, 5000))));
//var mesh = DemoMeshHelper.CreateDeformedPlane(128, 128, (x, y) => new Vector3(x - 64, 2f * (float)(Math.Sin(x * 0.5f) * Math.Sin(y * 0.5f)), y - 64), new Vector3(4, 1, 4), BufferPool);
//Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(mesh)));
}

double time = 0;
long frameCount = 0;
public override void Update(Window window, Camera camera, Input input, float dt)
{
base.Update(window, camera, input, dt);
const long minimumFrameToMeasure = 512;
frameCount++;
if (frameCount >= minimumFrameToMeasure)
{
var frameTime = Simulation.Profiler[Simulation.BroadPhaseOverlapFinder];
time += frameTime;
Console.WriteLine($"coldet time (ms): {1e3 * frameTime}, average (ms): {1e3 * time / (frameCount - minimumFrameToMeasure)}");
}

}
}


0 comments on commit 16b77b8

Please sign in to comment.