250cc mx engine, and dyno

This commit is contained in:
max
2026-06-09 20:20:56 +02:00
parent aba9b76530
commit ac2eab6f83
5 changed files with 385 additions and 82 deletions

View File

@@ -33,17 +33,21 @@ public class Program
// Audio & simulation
private static SimulationRingBuffer _simRingBuffer = null!;
private static SoundEngine _soundEngine = null!;
private static Scenario _scenario = null!; // cast to access ThrottleArea
private static Scenario _scenario = null!;
private static Font? _overlayFont;
private static Text? _overlayText;
// Throttle control
private static float _throttleTarget = 1.0f; // 01, set by arrow keys
private static float _throttleCurrent = 0.0f; // actual current fraction (lerped)
private const float ThrottleLerpRate = 10.0f; // times per second (speed of movement)
private static float _throttleTarget = 1.0f;
private static float _throttleCurrent = 0.0f;
private const float ThrottleLerpRate = 10.0f;
private static bool _wKeyHeld = false;
private static float _lastThrottleUpdateTime;
// Load
private static float _loadTarget = 0.0f; // 01
private static float _loadCurrent = 0.0f;
private const int TargetMaxFill = (int)(SampleRate * 0.2);
public static void Main()
@@ -51,6 +55,7 @@ public class Program
var window = CreateWindow();
LoadFont();
_scenario = new SingleCylScenario();
_scenario.Font = _overlayFont;
_scenario.Initialize(SampleRate);
_lastThrottleUpdateTime = 0.0f;
@@ -76,14 +81,12 @@ public class Program
(1.0 - Math.Exp(-8.0 * (now - lastDrawTime)));
_soundEngine.Speed = _currentDisplaySpeed;
// ---- Throttle update ----
// ---- Throttle & Load update (shared dt) ----
float dtThrottle = (float)now - _lastThrottleUpdateTime;
_lastThrottleUpdateTime = (float)now;
float throttleDesiredFraction = _wKeyHeld ? _throttleTarget : 0.0f;
// Snap to zero instantly when target is zero (key released)
if (throttleDesiredFraction == 0.0)
if (throttleDesiredFraction == 0.0f)
{
_throttleCurrent = 0.0f;
}
@@ -93,8 +96,13 @@ public class Program
_throttleCurrent += (throttleDesiredFraction - _throttleCurrent) * smoothing;
}
float loadSmoothing = 1.0f - MathF.Exp(-ThrottleLerpRate * dtThrottle);
_loadCurrent += (_loadTarget - _loadCurrent) * loadSmoothing;
_scenario.Load = _loadCurrent;
_scenario.Throttle = _throttleCurrent;
// ---- Drawing ----
if (now - lastDrawTime >= 1.0 / DrawFrequency)
{
@@ -103,7 +111,7 @@ public class Program
string toggleHint = _isRealTime ? "[Space] slow mo" : "[Space] real time";
_overlayText.DisplayedString =
$"{toggleHint} Speed: {_currentDisplaySpeed:F3}x RT: {(_currentDisplaySpeed * 100.0):F1}% Sim load: {_loadTracker.LoadPercent:F0}%\n" +
$"Throttle: {_throttleCurrent * 100:F0}% Target: {_throttleTarget * 100:F0}% [W] {(_wKeyHeld ? "BLIP" : "---")}";
$"Load: {_loadCurrent*100:F0}% [←][→] Throttle: {_throttleCurrent * 100:F0}% Target: {_throttleTarget * 100:F0}% [W] {(_wKeyHeld ? "BLIP" : "---")}";
}
window.Clear(Color.Black);
@@ -205,6 +213,14 @@ public class Program
case Keyboard.Key.Down:
_throttleTarget = MathF.Max(0.0f, _throttleTarget - 0.05f);
break;
case Keyboard.Key.Left:
_loadTarget = MathF.Max(0.0f, _loadTarget - 0.05f);
break;
case Keyboard.Key.Right:
_loadTarget = MathF.Min(1.0f, _loadTarget + 0.05f);
break;
}
}