Skip to content

Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.

C#

Every scratch frame is computed: the budget and its "not computed" note go

Alexander Graefa6f85dccd3d8
diff --git a/CLAUDE.md b/CLAUDE.md
index 39b9b52..55b04ac 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -57,9 +57,10 @@ WPF shell as it stands:
IsComputingFrame`, from the request to its result or a newer request's) and that has lasted longer than
150 ms, each picture dims (black at 45 %) under a turning three-quarter ring (`PreviewPane.
IsBusyOverlayVisible`, the `Spinner` style with a storyboard on `IsVisible`); the overlay goes the moment
- the frame arrives, and shorter waits pass unmarked so a fast machine does not strobe. A frame that was
- skipped (over the scratch budget) with no stored frame to stand in shows a note on the pictures instead
- (`IsFrameSkipped`, `PreviewNotComputed`, id `PreviewNotComputed`), since no spinner would ever resolve it.
+ the frame arrives, and shorter waits pass unmarked so a fast machine does not strobe. Every requested frame is
+ computed, however long it takes (2026-10-16, the user's rule): the scratch budget that skipped frames predicted
+ to take over six seconds, its "Not computed: this frame would take too long" note on the pictures and its status
+ line were removed, since the note appeared on frames that would not have taken long and nobody had asked for it.
- **Taskbar progress** (2026-10-14, the user's rule): the status bar's busy bar (an export's frames, or the
marquee while an export waits for its run or a scratch frame computes) is mirrored on the taskbar button
through WPF's `TaskbarItemInfo` (`MainWindow.Taskbar.cs`, fed from `UpdateBusy`).
@@ -216,8 +217,7 @@ WPF shell as it stands:
stays. Showing the run's newest frame meanwhile was tried twice and rejected both times: it reads
as a replay from frame 0 (2026-10-10). That rule also holds without a run: the presenter is
cleared only when both the run and the scratch frame are gone (the project replaced), not on
- every scrub step, which flashed the empty picture between frames (2026-10-13). A skipped scratch frame (predicted cost over
- `ScratchRunner.Budget`, 6 s) is said in the status bar once per frame. **No scratch frame while the preview
+ every scrub step, which flashed the empty picture between frames (2026-10-13). **No scratch frame while the preview
plays** (2026-10-16, after an edit during playback of a finished run kept playing the old source until playback
ended): every playback step restarted the 120 ms scratch timer, so it never fired, and the automatic re-run,
which waits behind a pending scratch frame, never started. `ScheduleScratch` does nothing while
@@ -990,9 +990,11 @@ FrameStore (temporary file in %LOCALAPPDATA%\WaveDudeNext\cache, DeleteOnClose,
frames at 1080p (the clock stays correct; only the newest request is rendered).
**Scratch frames** (the live preview after an edit) cost steps × the pure step time plus one
capture: frame 1249 of the default project (2499 steps, 4th order) measured **1.5 s** on the GPU
- in the app; on the CPU 14 ms per 4th-order step (frame 150 in 4 s), so frames beyond ~200 are
- skipped (`ScratchRunner.Budget` is 6 s, predicted from the stepping cost of the last request with
- at least 50 steps; a request with no measurement yet always computes). Frames early in the run are proportionally cheaper (frame 0: 90 ms including
+ in the app; on the CPU 14 ms per 4th-order step (frame 150 in 4 s, frame 1999 of the ball lens 57 s on the
+ laptop's HD 520). **There is no budget**: every request is computed (2026-10-16, the user's rule; the six-second
+ budget with its predicted skips, and a version that abandoned a frame while stepping, both went the same day:
+ the skip note showed on frames that would not have taken long, and nobody had asked for either). A newer
+ request still replaces one in progress. Frames early in the run are proportionally cheaper (frame 0: 90 ms including
the capture and the UI round trip).
- Known limits:
`OpenClApi` imports `"OpenCL"` (resolves to `OpenCL.dll` here, `libOpenCL.so` elsewhere); the library is
diff --git a/WaveDudeNext.WPF/MainWindow.Live.cs b/WaveDudeNext.WPF/MainWindow.Live.cs
index 5922e72..8a0bda3 100644
--- a/WaveDudeNext.WPF/MainWindow.Live.cs
+++ b/WaveDudeNext.WPF/MainWindow.Live.cs
@@ -72,7 +72,6 @@ public partial class MainWindow
private ProjectWatcher? _watcher;
private ScratchRunner? _scratch;
private SimulationRun? _pausedForScratch;
- private int _lastSkippedFrame = -1;
private DispatcherTimer? _scratchTimer;
private DispatcherTimer? _rerunTimer;
private (RunSpec Spec, int Frame)? _scratchRequested;
@@ -336,12 +335,6 @@ public partial class MainWindow
paused.Resume();
}
}
- if (result.Snapshot == null && result.Frame != _lastSkippedFrame)
- {
- // the status bar says why nothing appears; once per frame, so scrubbing does not flood it
- _lastSkippedFrame = result.Frame;
- Logger.Info("Preview of frame {Frame} skipped: it would take {Seconds:0} s to compute; wait for the run, or use the GPU", result.Frame, result.Estimate.TotalSeconds);
- }
ScratchFrame = result;
}
diff --git a/WaveDudeNext.WPF/Panes/PreviewPane.xaml b/WaveDudeNext.WPF/Panes/PreviewPane.xaml
index bd31266..226a7f7 100644
--- a/WaveDudeNext.WPF/Panes/PreviewPane.xaml
+++ b/WaveDudeNext.WPF/Panes/PreviewPane.xaml
@@ -510,12 +510,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<Rectangle Fill="Black" Opacity="0.45" />
<Path Style="{StaticResource Spinner}" />
</Grid>
- <!-- the frame was not computed (its predicted cost is over the scratch budget) and nothing stands in: say so -->
- <Border IsHitTestVisible="False" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#C0101216" CornerRadius="3" Padding="10,6"
- Visibility="{Binding IsFrameSkipped, RelativeSource={RelativeSource AncestorType={x:Type local:PreviewPane}}, Converter={StaticResource BoolToVisibility}}">
- <TextBlock Text="{DynamicResource PreviewNotComputed}" Foreground="White" TextWrapping="Wrap" MaxWidth="280" TextAlignment="Center"
- AutomationProperties.AutomationId="PreviewNotComputed" />
- </Border>
</Grid>
</controls:PictureFrame>
</ControlTemplate>
diff --git a/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs b/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
index 272d528..4cfb1a4 100644
--- a/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
+++ b/WaveDudeNext.WPF/Panes/PreviewPane.xaml.cs
@@ -206,12 +206,6 @@ public partial class PreviewPane : UserControl
/// <summary>Identifies the <see cref="IsBusyOverlayVisible"/> property.</summary>
public static readonly DependencyProperty IsBusyOverlayVisibleProperty = IsBusyOverlayVisibleKey.DependencyProperty;
- private static readonly DependencyPropertyKey IsFrameSkippedKey = DependencyProperty.RegisterReadOnly(
- nameof(IsFrameSkipped), typeof(bool), typeof(PreviewPane), new PropertyMetadata(false));
-
- /// <summary>Identifies the <see cref="IsFrameSkipped"/> property.</summary>
- public static readonly DependencyProperty IsFrameSkippedProperty = IsFrameSkippedKey.DependencyProperty;
-
/// <summary>How long a frame may take before the pictures dim and the spinner shows; shorter waits pass unmarked, so a fast machine does not strobe.</summary>
private static readonly TimeSpan BusyOverlayDelay = TimeSpan.FromMilliseconds(150);
@@ -520,13 +514,6 @@ public partial class PreviewPane : UserControl
private set => SetValue(IsBusyOverlayVisibleKey, value);
}
- /// <summary>Whether the frame at <see cref="Position"/> was not computed (its predicted cost exceeded the scratch budget) and nothing else can show it; a note says so on the pictures.</summary>
- public bool IsFrameSkipped
- {
- get => (bool)GetValue(IsFrameSkippedProperty);
- private set => SetValue(IsFrameSkippedKey, value);
- }
-
/// <summary>Whether a probe was edited since the run started: its frames hold, its recordings do not. Bound to the main window.</summary>
public bool IsProbesStale
{
@@ -652,16 +639,13 @@ public partial class PreviewPane : UserControl
{
SimulationRun? run = Run;
ScratchResult? scratch = ScratchFrame;
- bool storeHasFrame = run != null && !IsStale && run.FrameCount > Position;
- // the position's frame was skipped (over the budget) and no stored frame stands in: the pictures say so
- IsFrameSkipped = scratch is { Snapshot: null } && scratch.Frame == Position && !storeHasFrame;
- bool useScratch = scratch is { Snapshot: not null } && scratch.Frame == Position
+ bool useScratch = scratch != null && scratch.Frame == Position
&& (run == null || IsStale || run.FrameCount <= Position);
if (useScratch)
{
if (_scratchSource == null || !ReferenceEquals(_scratchSource.Snapshot, scratch!.Snapshot))
{
- _scratchSource = new SnapshotFrameSource(scratch!.Snapshot!);
+ _scratchSource = new SnapshotFrameSource(scratch!.Snapshot);
}
_presenter.Source = _scratchSource;
GraphScratch = scratch;
diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
index ccc3a48..2339100 100644
--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml
@@ -198,7 +198,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ExportStatusFormat">Exportiere {0} / {1} Bilder</s:String>
<s:String x:Key="ExportStatusWaiting">Export: wartet auf den Lauf</s:String>
<s:String x:Key="StatusComputingFormat">Berechne Bild {0}</s:String>
- <s:String x:Key="PreviewNotComputed">Nicht berechnet: dieses Bild allein würde zu lange dauern. Starten Sie die Simulation (F5), um es zu erhalten.</s:String>
<s:String x:Key="TipExportCancel">Export abbrechen (Esc)</s:String>
<s:String x:Key="Untitled">Unbenannt</s:String>
<s:String x:Key="SaveChangesFormat">Änderungen an {0} speichern?</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
index f306896..4d3d64f 100644
--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml
@@ -200,7 +200,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ExportStatusFormat">Exporting {0} / {1} frames</s:String>
<s:String x:Key="ExportStatusWaiting">Export: waiting for the run</s:String>
<s:String x:Key="StatusComputingFormat">Computing frame {0}</s:String>
- <s:String x:Key="PreviewNotComputed">Not computed: this frame would take too long on its own. Run the simulation (F5) to get it.</s:String>
<s:String x:Key="TipExportCancel">Cancel the export (Esc)</s:String>
<s:String x:Key="Untitled">Untitled</s:String>
<s:String x:Key="SaveChangesFormat">Save the changes to {0}?</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
index f055aa6..cd9c7d5 100644
--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml
@@ -198,7 +198,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ExportStatusFormat">Export : {0} / {1} images</s:String>
<s:String x:Key="ExportStatusWaiting">Export : en attente de l'exécution</s:String>
<s:String x:Key="StatusComputingFormat">Calcul de l'image {0}</s:String>
- <s:String x:Key="PreviewNotComputed">Non calculée : cette image seule prendrait trop de temps. Lancez la simulation (F5) pour l'obtenir.</s:String>
<s:String x:Key="TipExportCancel">Annuler l'export (Échap)</s:String>
<s:String x:Key="Untitled">Sans titre</s:String>
<s:String x:Key="SaveChangesFormat">Enregistrer les modifications de {0} ?</s:String>
diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
index 6622fc3..9ea52ca 100644
--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml
+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml
@@ -198,7 +198,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or
<s:String x:Key="ExportStatusFormat">Exporteren: {0} / {1} beelden</s:String>
<s:String x:Key="ExportStatusWaiting">Export: wacht op de run</s:String>
<s:String x:Key="StatusComputingFormat">Beeld {0} wordt berekend</s:String>
- <s:String x:Key="PreviewNotComputed">Niet berekend: dit beeld alleen zou te lang duren. Start de simulatie (F5) om het te krijgen.</s:String>
<s:String x:Key="TipExportCancel">Export annuleren (Esc)</s:String>
<s:String x:Key="Untitled">Naamloos</s:String>
<s:String x:Key="SaveChangesFormat">Wijzigingen in {0} opslaan?</s:String>
diff --git a/WaveDudeNext/Runs/ScratchRunner.cs b/WaveDudeNext/Runs/ScratchRunner.cs
index 3e3d0bc..ff4edc6 100644
--- a/WaveDudeNext/Runs/ScratchRunner.cs
+++ b/WaveDudeNext/Runs/ScratchRunner.cs
@@ -22,13 +22,13 @@ using WaveDudeNext.Probes;
namespace WaveDudeNext.Runs;
-/// <summary>The outcome of a scratch request: the frame and the probe recordings up to it, or why it was not computed.</summary>
+/// <summary>The outcome of a scratch request: the frame and the probe recordings up to it.</summary>
/// <param name="Spec">The snapshot of the project the frame was computed for.</param>
/// <param name="Frame">The frame index requested.</param>
-/// <param name="Snapshot">The frame, or null when it was skipped; owned by the runner and valid until the next outcome.</param>
-/// <param name="Estimate">How long the runner expected (or took) to compute it.</param>
-/// <param name="Traces">Per probe of <see cref="RunSpec.Probes"/>: the series up to the frame's step and, for a line probe, its one profile at the frame (index 0); empty when skipped or without probes. Owned by the result; read on the UI thread.</param>
-public sealed record ScratchResult(RunSpec Spec, int Frame, FrameSnapshot? Snapshot, TimeSpan Estimate, ProbeTrace[] Traces);
+/// <param name="Snapshot">The frame; owned by the runner and valid until the next outcome.</param>
+/// <param name="Elapsed">How long the runner took to compute it.</param>
+/// <param name="Traces">Per probe of <see cref="RunSpec.Probes"/>: the series up to the frame's step and, for a line probe, its one profile at the frame (index 0); empty without probes. Owned by the result; read on the UI thread.</param>
+public sealed record ScratchResult(RunSpec Spec, int Frame, FrameSnapshot Snapshot, TimeSpan Elapsed, ProbeTrace[] Traces);
/// <summary>
/// Computes single frames of the current project state on demand, without a store: after an edit the
@@ -38,8 +38,10 @@ public sealed record ScratchResult(RunSpec Spec, int Frame, FrameSnapshot? Snaps
/// against the stepping). The engine is kept between requests (a GPU engine takes a few hundred
/// milliseconds to build) and only reset, or given new emitters when just the sources changed; it is rebuilt
/// when the scene or the solver options change. Only the newest request is served: a request arriving
-/// while one is computing abandons it. A request whose predicted cost (steps × the measured cost per step)
-/// exceeds <see cref="Budget"/> is skipped and reported, so a slow engine does not stall the UI.
+/// while one is computing abandons it. Every request is computed, however long it takes (2026-10-16, the user's
+/// rule; a budget that skipped frames predicted to take over six seconds, and a version that abandoned them while
+/// stepping, were both removed the same day: the note "not computed, would take too long" appeared on frames that
+/// would not have, and nobody had asked for it).
/// </summary>
/// <remarks>
/// Threads: <see cref="Request"/> may be called from any thread; the work runs on one long-running task;
@@ -54,9 +56,6 @@ public sealed class ScratchRunner : IDisposable
/// <summary>How often the worker checks for a newer request, in steps.</summary>
private const int CheckInterval = 16;
- /// <summary>Fewer steps than this say nothing reliable about the cost per step.</summary>
- private const int MinStepsToMeasure = 50;
-
private readonly SynchronizationContext? _context;
private readonly SemaphoreSlim _signal = new(0);
private readonly CancellationTokenSource _cancel = new();
@@ -67,7 +66,6 @@ public sealed class ScratchRunner : IDisposable
private RunSpec? _engineSpec;
private FrameSnapshot?[] _snapshots = new FrameSnapshot?[2];
private int _nextSnapshot;
- private double _msPerStep = double.NaN;
private int _busy;
/// <param name="context">Where <see cref="Completed"/> is raised; null raises it on the worker.</param>
@@ -77,16 +75,10 @@ public sealed class ScratchRunner : IDisposable
_worker = Task.Factory.StartNew(Loop, TaskCreationOptions.LongRunning);
}
- /// <summary>Longest predicted compute time a request may have before it is skipped.</summary>
- public TimeSpan Budget { get; set; } = TimeSpan.FromSeconds(6);
-
/// <summary>Whether a request is being computed.</summary>
public bool IsBusy => Volatile.Read(ref _busy) != 0;
- /// <summary>Cost of one step of the current engine as last measured, or NaN before the first compute.</summary>
- public double MillisecondsPerStep => Volatile.Read(ref _msPerStep);
-
- /// <summary>A request finished: with a frame, or skipped (<see cref="ScratchResult.Snapshot"/> null).</summary>
+ /// <summary>A request finished with its frame.</summary>
public event EventHandler<ScratchResult>? Completed;
/// <summary>Asks for frame <paramref name="frame"/> of <paramref name="spec"/>; replaces any request not yet started or in progress.</summary>
@@ -180,14 +172,6 @@ public sealed class ScratchRunner : IDisposable
private void Compute(RunSpec spec, int frame, CancellationToken token)
{
int steps = frame * spec.VisualizeEvery + 1;
- double msPerStep = Volatile.Read(ref _msPerStep);
- var estimate = TimeSpan.FromMilliseconds(double.IsNaN(msPerStep) ? 0 : msPerStep * steps);
- if (!double.IsNaN(msPerStep) && estimate > Budget)
- {
- Logger.Debug("Preview frame {Frame} skipped: {Steps} steps would take {Estimate:0.0} s", frame, steps, estimate.TotalSeconds);
- Post(new ScratchResult(spec, frame, null, estimate, []));
- return;
- }
IWaveEngine engine = EngineFor(spec);
// the spec's probes, installed per request (Reset removes them; a fresh engine has none)
ProbeSampler? sampler = spec.Probes.Length > 0 ? ProbeSampler.Build(spec.Probes, spec.Width, spec.Height) : null;
@@ -221,13 +205,7 @@ public sealed class ScratchRunner : IDisposable
traces = collector.Traces;
}
clock.Stop();
- // the stepping loop alone rules the next prediction (the capture is a fixed cost, and the GPU's first
- // steps include its warm-up), and only when there were enough steps to measure
- if (steps >= MinStepsToMeasure)
- {
- Volatile.Write(ref _msPerStep, stepping.TotalMilliseconds / steps);
- }
- Logger.Debug("Preview frame {Frame}: {Steps} steps in {Elapsed:0} ms on {Engine}", frame, steps, clock.Elapsed.TotalMilliseconds, engine.Description);
+ Logger.Debug("Preview frame {Frame}: {Steps} steps in {Elapsed:0} ms ({Stepping:0} ms stepping) on {Engine}", frame, steps, clock.Elapsed.TotalMilliseconds, stepping.TotalMilliseconds, engine.Description);
Post(new ScratchResult(spec, frame, snapshot, clock.Elapsed, traces));
}
@@ -249,7 +227,6 @@ public sealed class ScratchRunner : IDisposable
var clock = Stopwatch.StartNew();
_engine = WaveEngineFactory.Create(spec.BuildScene(), spec.Engine, spec.PreferGpu, spec.Emitters, out string note);
_engineSpec = spec;
- _msPerStep = double.NaN;
Logger.Debug("Preview engine: {Engine} in {Elapsed:0} ms{Note}", _engine.Description, clock.ElapsedMilliseconds, note.Length > 0 ? " (" + note + ")" : "");
return _engine;
}