seemingly working, added display text
This commit is contained in:
67
Program.cs
67
Program.cs
@@ -13,9 +13,8 @@ public class Program
|
||||
private const double DrawFrequency = 60.0;
|
||||
private static Scenario scenario;
|
||||
|
||||
// Speed control (existing + new throttle)
|
||||
// Speed control
|
||||
private static double desiredSpeed = 0.01;
|
||||
//private static double desiredSpeed = 1.0;
|
||||
private static double currentSpeed = desiredSpeed;
|
||||
private const double MinSpeed = 0.0001;
|
||||
private const double MaxSpeed = 1.0;
|
||||
@@ -24,22 +23,47 @@ public class Program
|
||||
private static double lastDesiredSpeed = 0.1;
|
||||
private static bool isRealTime = false;
|
||||
|
||||
// Throttle smoothing
|
||||
private static double targetThrottle = 0.0; // 1.0 when W is pressed, 0.0 otherwise
|
||||
// Throttle smoothing (unused but kept)
|
||||
private static double targetThrottle = 0.0;
|
||||
private static double currentThrottle = 0.0;
|
||||
private const double ThrottleSmoothing = 20.0; // rate of change
|
||||
private const double ThrottleSmoothing = 20.0;
|
||||
|
||||
private static volatile bool running = true;
|
||||
|
||||
// ---- Overlay text ----
|
||||
private static Font? overlayFont;
|
||||
private static Text? overlayText;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
var mode = new VideoMode(new Vector2u(1280, 720));
|
||||
var window = new RenderWindow(mode, "FluidSim - Engine (W = throttle)");
|
||||
var window = new RenderWindow(mode, "FluidSim");
|
||||
window.SetVerticalSyncEnabled(true);
|
||||
window.Closed += (_, _) => { running = false; window.Close(); };
|
||||
window.MouseWheelScrolled += OnMouseWheel;
|
||||
window.KeyPressed += OnKeyPressed;
|
||||
|
||||
// ---- Load font ----
|
||||
try
|
||||
{
|
||||
overlayFont = new Font("fonts/FiraCodeNerdFont-Medium.ttf");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to load font 'fonts/LiberationMono-Regular.ttf': {ex.Message}");
|
||||
overlayFont = null; // will skip text drawing
|
||||
}
|
||||
|
||||
if (overlayFont != null)
|
||||
{
|
||||
// SFML 3 Text(font, character size in pixels)
|
||||
overlayText = new Text(overlayFont)
|
||||
{
|
||||
FillColor = Color.White,
|
||||
Position = new Vector2f(10, 10)
|
||||
};
|
||||
}
|
||||
|
||||
var soundEngine = new SoundEngine(bufferCapacity: 16384);
|
||||
soundEngine.Volume = 100;
|
||||
soundEngine.Start();
|
||||
@@ -74,7 +98,6 @@ public class Program
|
||||
double speedSmoothing = 8.0;
|
||||
currentSpeed += (desiredSpeed - currentSpeed) * (1.0 - Math.Exp(-speedSmoothing * dtClock));
|
||||
|
||||
|
||||
// Generate audio
|
||||
double targetAudioClock = currentRealTime + 0.05;
|
||||
while (totalOutputSamples < targetAudioClock * SampleRate && running)
|
||||
@@ -116,21 +139,30 @@ public class Program
|
||||
break;
|
||||
}
|
||||
|
||||
// Drawing & title
|
||||
// Drawing
|
||||
if (currentRealTime - lastDrawTime >= drawInterval)
|
||||
{
|
||||
double actualSpeed = totalOutputSamples / (currentRealTime * SampleRate);
|
||||
double simTime = totalSimSteps / (double)SampleRate;
|
||||
string toggleHint = isRealTime ? "[Space] slow mo" : "[Space] real time";
|
||||
string throttleHint = Keyboard.IsKeyPressed(Keyboard.Key.W) ? "W held" : "W released";
|
||||
window.SetTitle(
|
||||
$"{toggleHint} {throttleHint} " +
|
||||
$"Thr: {currentThrottle:F2} " +
|
||||
$"Speed: {currentSpeed:F3}x → {desiredSpeed:F3}x " +
|
||||
$"Act: {actualSpeed:F2}x"
|
||||
);
|
||||
double realtimePercent = totalOutputSamples / (currentRealTime * SampleRate) * 100.0;
|
||||
|
||||
// Update overlay text
|
||||
if (overlayText != null)
|
||||
{
|
||||
string toggleHint = isRealTime ? "[Space] slow mo" : "[Space] real time";
|
||||
string throttleHint = Keyboard.IsKeyPressed(Keyboard.Key.W) ? "W held" : "W released";
|
||||
overlayText.DisplayedString =
|
||||
$"{toggleHint} {throttleHint} " +
|
||||
$"Speed: {currentSpeed:F3}x " +
|
||||
$"RT: {realtimePercent:F1}%";
|
||||
}
|
||||
|
||||
window.Clear(Color.Black);
|
||||
scenario.Draw(window);
|
||||
|
||||
// Draw the overlay on top
|
||||
if (overlayText != null)
|
||||
window.Draw(overlayText);
|
||||
|
||||
window.Display();
|
||||
lastDrawTime = currentRealTime;
|
||||
}
|
||||
@@ -140,7 +172,6 @@ public class Program
|
||||
window.Dispose();
|
||||
}
|
||||
|
||||
// (Mouse wheel, space toggle unchanged)
|
||||
private static void OnMouseWheel(object? sender, MouseWheelScrollEventArgs e)
|
||||
{
|
||||
bool wasRealTime = Math.Abs(desiredSpeed - 1.0) < 1e-6;
|
||||
|
||||
Reference in New Issue
Block a user