From 7b55afc90dc8d9b1a4023b04442d2018d83e3c84 Mon Sep 17 00:00:00 2001 From: notgiven688 Date: Wed, 18 Dec 2024 12:46:43 +0100 Subject: [PATCH] sampler --- src/JitterDemo/Playground.cs | 9 +++++++++ src/JitterDemo/plot.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/JitterDemo/plot.py diff --git a/src/JitterDemo/Playground.cs b/src/JitterDemo/Playground.cs index 8ea276fa..e5a797c3 100644 --- a/src/JitterDemo/Playground.cs +++ b/src/JitterDemo/Playground.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using Jitter2; using Jitter2.Collision; using Jitter2.Collision.Shapes; @@ -106,6 +107,9 @@ public override void Load() ResetScene(); VerticalSync = false; + + SwitchDemo(2); + multiThread = true; } public RigidBodyShape? FloorShape => floorShape; @@ -130,7 +134,12 @@ public void ShootPrimitive() public override void Draw() { // if (Keyboard.KeyPressBegin(Keyboard.Key.P)) + var swn = Stopwatch.StartNew(); world.Step(1.0f / 100.0f, multiThread); + swn.Stop(); + + System.IO.File.AppendAllText("stats.dat", + $"{swn.Elapsed.TotalMilliseconds}\n"); UpdateDisplayText(); LayoutGui(); diff --git a/src/JitterDemo/plot.py b/src/JitterDemo/plot.py new file mode 100644 index 00000000..f75cf5cc --- /dev/null +++ b/src/JitterDemo/plot.py @@ -0,0 +1,31 @@ +import matplotlib.pyplot as plt + +# Load the data from the files +with open("stats.dat", "r") as f1: + y1 = [float(line.strip()) for line in f1 if line.strip()] + +with open("stats.main.dat", "r") as f2: + y2 = [float(line.strip()) for line in f2 if line.strip()] + +#with open("stats.dat", "r") as f2: +# y3 = [float(line.strip()) for line in f2 if line.strip()] + +# Create x-values (row numbers) +x1 = range(len(y1)) +x2 = range(len(y2)) +#x3 = range(len(y3)) + +# Plot the data +plt.figure(figsize=(8, 6)) +plt.plot(x1, y1, marker="o", linestyle="-", color="b", label="stats.dat") +plt.plot(x2, y2, marker="x", linestyle="--", color="r", label="stats.main.dat") +#plt.plot(x3, y3, marker=".", linestyle="-", color="g", label="stats.main.dat") + +# Customize the plot +plt.xlabel("Row Index") +plt.ylabel("Values") +plt.title("Values from stats.dat and stats.main.dat") +plt.legend() +plt.grid() +plt.show() +