Skip to content

Commit

Permalink
UI: Initialize timer once
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal committed Jan 23, 2024
1 parent 91202ca commit 45e3fa5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Spice86/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase, IPauseStatus, I
[ObservableProperty]
private Configuration _configuration;
private bool _disposed;
private bool _renderingTimerInitialized;
private bool _drawingSemaphoreSlimDisposed;
private Thread? _emulatorThread;
private bool _isSettingResolution;
Expand Down Expand Up @@ -332,7 +333,11 @@ public void ShowColorPalette() {
[RelayCommand]
public void ResetTimeMultiplier() => TimeMultiplier = Configuration.TimeMultiplier;

private void InitializeRenderingThread() {
private void InitializeRenderingTimer() {
if (_renderingTimerInitialized) {
return;
}
_renderingTimerInitialized = true;
_drawTimer.Elapsed += (_, _) => DrawScreen();
_drawTimer.Start();
}
Expand Down Expand Up @@ -448,7 +453,7 @@ public void SetResolution(int width, int height) => _uiDispatcher.Post(() => {
}
}
_isSettingResolution = false;
InitializeRenderingThread();
InitializeRenderingTimer();
}, DispatcherPriority.MaxValue);

public event EventHandler<UIRenderEventArgs>? RenderScreen;
Expand Down

0 comments on commit 45e3fa5

Please sign in to comment.