General testing

This commit is contained in:
2026-05-05 10:32:30 +02:00
parent ff4c4aef23
commit d963032e74
11 changed files with 794 additions and 448 deletions

View File

@@ -13,23 +13,23 @@ public class Program
private static Scenario scenario;
// Speed control
//private static double desiredSpeed = 1.0;
private static double desiredSpeed = 0.0001;
//private static double desiredSpeed = 1;
private static double currentSpeed = desiredSpeed;
private const double MinSpeed = 0.0001;
private const double MaxSpeed = 1.0;
private const double ScrollFactor = 1.1;
// Spacetoggle state
private static double lastDesiredSpeed = 0.1; // remembers the last non1.0 scroll speed
private static bool isRealTime = true; // true when desiredSpeed == 1.0
private static double lastDesiredSpeed = 0.1; // remembers the last non1.0 speed
private static bool isRealTime = false; // starts in slowmo (desiredSpeed != 1.0)
private static volatile bool running = true;
public static void Main()
{
var mode = new VideoMode(new Vector2u(1280, 720));
var window = new RenderWindow(mode, "Pipe Resonator");
var window = new RenderWindow(mode, "FluidSim - Helmholtz Resonator");
window.SetVerticalSyncEnabled(true);
window.Closed += (_, _) => { running = false; window.Close(); };
window.MouseWheelScrolled += OnMouseWheel;
@@ -39,9 +39,11 @@ public class Program
soundEngine.Volume = 70;
soundEngine.Start();
//scenario = new PipeResonatorScenario();
// Choose one scenario. The Helmholtz resonator is fully updated.
//scenario = new HelmholtzResonatorScenario();
scenario = new SodShockTubeScenario();
//scenario = new PipeResonatorScenario(); // needs update to new API
//scenario = new SodShockTubeScenario(); // needs update to new API
scenario = new EngineScenario(); // also works (provided earlier)
scenario.Initialize(SampleRate);
@@ -51,9 +53,10 @@ public class Program
double lastSpeedUpdateTime = stopwatch.Elapsed.TotalSeconds;
// Resampling buffer
List<float> simBuffer = new List<float>(4096);
var simBuffer = new List<float>(4096);
double readIndex = 0.0;
// Prime the buffer with a few samples
for (int i = 0; i < 4; i++)
simBuffer.Add(scenario.Process());
@@ -73,7 +76,6 @@ public class Program
lastSpeedUpdateTime = currentRealTime;
// Smoothly transition currentSpeed → desiredSpeed
// When toggling, desiredSpeed jumps, but currentSpeed follows with a smooth lerp
double smoothingRate = 8.0; // higher = faster catchup
currentSpeed += (desiredSpeed - currentSpeed) * (1.0 - Math.Exp(-smoothingRate * dtSpeed));
@@ -122,7 +124,7 @@ public class Program
break;
}
// ---------- Drawing & title ----------
// ---------- Drawing & window title ----------
if (currentRealTime - lastDrawTime >= drawInterval)
{
double actualSpeed = totalOutputSamples / (currentRealTime * SampleRate);
@@ -156,7 +158,7 @@ public class Program
desiredSpeed = Math.Clamp(desiredSpeed, MinSpeed, MaxSpeed);
// Update the remembered slow-mo speed (unless we are exactly at 1.0)
// Update the remembered slowmo speed (unless we are exactly at 1.0)
if (!wasRealTime || Math.Abs(desiredSpeed - 1.0) > 1e-6)
lastDesiredSpeed = desiredSpeed;