From fa2866c45ded66c1fba6842435a44496c19b2690 Mon Sep 17 00:00:00 2001 From: JetSetIlly Date: Sun, 5 May 2024 16:58:44 +0100 Subject: [PATCH] sdlimgui preferences correctly initialised on first use this fix is very important because without it, the frame queue is set to zero. this means that the display is likely to be very choppy creating a bad impression of the emulator for first time users --- gui/sdlimgui/preferences.go | 75 ++++++++++++++++++++----------------- gui/sdlimgui/win_prefs.go | 4 +- prefs/defunct.go | 2 + rewind/preferences.go | 4 +- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/gui/sdlimgui/preferences.go b/gui/sdlimgui/preferences.go index f2286a89..00c20b5b 100644 --- a/gui/sdlimgui/preferences.go +++ b/gui/sdlimgui/preferences.go @@ -69,9 +69,9 @@ type preferences struct { codeFontLineSpacing prefs.Int // display - frameQueueAuto prefs.Bool - frameQueue prefs.Int - glSwapInterval prefs.Int + frameQueueLenAuto prefs.Bool + frameQueueLen prefs.Int + glSwapInterval prefs.Int // window preferences are split over two prefs.Disk instances, to allow // geometry to be saved at a different time to the fullscreen preference @@ -85,29 +85,6 @@ type preferences struct { func newPreferences(img *SdlImgui) (*preferences, error) { p := &preferences{img: img} - // defaults - p.terminalOnError.Set(true) - p.audioMuteDebugger.Set(true) - p.showTooltips.Set(true) - p.showTimelineThumbnail.Set(false) - p.colorDisasm.Set(true) - p.fpsDetail.Set(false) - p.activePause.Set(false) - p.audioMutePlaymode.Set(false) - p.controllerNotifcations.Set(true) - p.plusromNotifications.Set(true) - p.superchargerNotifications.Set(true) - p.audioMuteNotification.Set(true) - p.notificationVisibility.Set(0.75) - p.memoryUsageInOverlay.Set(false) - p.guiFontSize.Set(13) - p.terminalFontSize.Set(12) - p.codeFontSize.Set(15) - p.codeFontLineSpacing.Set(2.0) - p.frameQueueAuto.Set(false) - p.frameQueue.Set(5) - p.glSwapInterval.Set(1) - // setup preferences pth, err := resources.JoinPath(prefs.DefaultPrefsFile) if err != nil { @@ -195,28 +172,27 @@ func newPreferences(img *SdlImgui) (*preferences, error) { // display options - // frameQueueAuto *must* be added after frameQueue so that the auto - // post-hook can override the frameQueue value on load as required - err = p.dsk.Add("sdlimgui.display.frameQueue", &p.frameQueue) + err = p.dsk.Add("sdlimgui.display.frameQueueLen", &p.frameQueueLen) if err != nil { return nil, err } - p.frameQueue.SetHookPost(func(v prefs.Value) error { - p.img.screen.setFrameQueue(p.frameQueueAuto.Get().(bool), v.(int)) + p.frameQueueLen.SetHookPost(func(v prefs.Value) error { + p.img.screen.setFrameQueue(p.frameQueueLenAuto.Get().(bool), v.(int)) return nil }) - err = p.dsk.Add("sdlimgui.display.frameQueueAuto", &p.frameQueueAuto) + + err = p.dsk.Add("sdlimgui.display.frameQueueLenAuto", &p.frameQueueLenAuto) if err != nil { return nil, err } - p.frameQueueAuto.SetHookPost(func(v prefs.Value) error { + p.frameQueueLenAuto.SetHookPost(func(v prefs.Value) error { // set frameQueue value if auto is true. there is no need to call // screen.setFrameQueue() in that instance becase the post hook for the // frameQueue value does that if v.(bool) { p.img.screen.setFrameQueue(true, 1) } else { - p.img.screen.setFrameQueue(false, p.frameQueue.Get().(int)) + p.img.screen.setFrameQueue(false, p.frameQueueLen.Get().(int)) } return nil }) @@ -278,8 +254,39 @@ func newPreferences(img *SdlImgui) (*preferences, error) { return p, nil } +func (p *preferences) setDefaults() { + p.terminalOnError.Set(true) + p.audioMuteDebugger.Set(true) + p.showTooltips.Set(true) + p.showTimelineThumbnail.Set(false) + p.colorDisasm.Set(true) + p.fpsDetail.Set(false) + p.activePause.Set(false) + p.audioMutePlaymode.Set(false) + p.controllerNotifcations.Set(true) + p.plusromNotifications.Set(true) + p.superchargerNotifications.Set(true) + p.audioMuteNotification.Set(true) + p.notificationVisibility.Set(0.75) + p.memoryUsageInOverlay.Set(false) + p.guiFontSize.Set(13) + p.terminalFontSize.Set(12) + p.codeFontSize.Set(15) + p.codeFontLineSpacing.Set(2.0) + p.frameQueueLenAuto.Set(false) + p.frameQueueLen.Set(3) + p.glSwapInterval.Set(1) +} + // load preferences from disk. does not load window preferences. func (p *preferences) load() error { + // calling set defaults before loading the values from disk. this makes sure + // that the value hooks have been called at least once + // + // this is important because if the value is not on disk (eg. on first use + // of the emulator) then the hook will not be triggered by the load process + p.setDefaults() + return p.dsk.Load(false) } diff --git a/gui/sdlimgui/win_prefs.go b/gui/sdlimgui/win_prefs.go index c815d401..38d8d676 100644 --- a/gui/sdlimgui/win_prefs.go +++ b/gui/sdlimgui/win_prefs.go @@ -278,7 +278,7 @@ of the ROM.`) } if imgui.Checkbox("Automatic Frame Queue Length", &frameQueueAuto) { - win.img.prefs.frameQueueAuto.Set(frameQueueAuto) + win.img.prefs.frameQueueLenAuto.Set(frameQueueAuto) } imgui.Spacing() @@ -291,7 +291,7 @@ of the ROM.`) } if imgui.SliderInt("Frame Queue Length", &frameQueueLen, 1, maxFrameQueue) { - win.img.prefs.frameQueue.Set(frameQueueLen) + // win.img.prefs.frameQueue.Set(frameQueueLen) } } } diff --git a/prefs/defunct.go b/prefs/defunct.go index bcc79d5d..15b33a73 100644 --- a/prefs/defunct.go +++ b/prefs/defunct.go @@ -72,6 +72,8 @@ var defunct = []string{ "crt.contrast", "crt.hue", "crt.saturation", + "sdlimgui.display.frameQueue", + "sdlimgui.display.frameQueueAuto", } // returns true if string is in list of defunct values. diff --git a/rewind/preferences.go b/rewind/preferences.go index 86bdbe12..3ed54cc9 100644 --- a/rewind/preferences.go +++ b/rewind/preferences.go @@ -90,12 +90,12 @@ func (p *Preferences) SetDefaults() { p.Freq.Set(snapshotFreq) } -// Load disassembly preferences and apply to the current disassembly. +// Load rewind preferences from disk. func (p *Preferences) Load() error { return p.dsk.Load(false) } -// Save current disassembly preferences to disk. +// Save current rewind preferences to disk. func (p *Preferences) Save() error { return p.dsk.Save() }