Skip to content

Commit

Permalink
Noise texture is no longer updated if a window is in the background a…
Browse files Browse the repository at this point in the history
…nd "Pause emulation while in background" is activated. (#763)
  • Loading branch information
dirkwhoffmann committed Jan 25, 2024
1 parent 55aadf4 commit 63f9a1a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion GUI/Layers/Canvas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ class Canvas: Layer {

let w = TextureSize.original.width
let h = TextureSize.original.height
emulatorTexture.replace(w: w, h: h, buffer: c64.vic.noise)
if !controller.inBackground || !controller.pref.pauseInBackground {
emulatorTexture.replace(w: w, h: h, buffer: c64.vic.noise)
}
return
}

Expand Down
6 changes: 1 addition & 5 deletions GUI/Layers/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import Carbon.HIToolbox

class Console: Layer {

let controller: MyController

var window: NSWindow { return controller.window! }
var contentView: NSView { return window.contentView! }

Expand All @@ -27,9 +25,7 @@ class Console: Layer {
//

override init(renderer: Renderer) {

controller = renderer.parent


textView = (scrollView.documentView as? NSTextView)!
textView.isEditable = false
textView.backgroundColor = NSColor(r: 0x80, g: 0x80, b: 0x80, a: 0x80)
Expand Down
6 changes: 1 addition & 5 deletions GUI/Layers/DropZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import Foundation

class DropZone: Layer {

let controller: MyController

var window: NSWindow { return controller.window! }
var contentView: NSView { return window.contentView! }
var metal: MetalView { return controller.metal! }
Expand Down Expand Up @@ -48,9 +46,7 @@ class DropZone: Layer {
//

override init(renderer: Renderer) {

controller = renderer.parent


for i in 0...4 { zones[i].unregisterDraggedTypes() }
super.init(renderer: renderer)
resize()
Expand Down
1 change: 1 addition & 0 deletions GUI/Layers/Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Layer: NSObject {

let renderer: Renderer

var controller : MyController { return renderer.parent }
var ressourceManager: RessourceManager { return renderer.ressourceManager }
var device: MTLDevice { return renderer.device }
var view: MTKView { return renderer.view }
Expand Down
3 changes: 3 additions & 0 deletions GUI/MyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class MyController: NSWindowController, MessageReceiver {
var smallTape = NSImage(named: "tapeTemplate")!.resize(size: iconSize)
var smallCart = NSImage(named: "crtTemplate")!.resize(size: iconSize)

// Indicates if the window is in background
var inBackground = false

// Remembers the running state for the pauseInBackground feature
var pauseInBackgroundSavedState = false

Expand Down
4 changes: 4 additions & 0 deletions GUI/WindowDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extension MyController: NSWindowDelegate {

guard let window = notification.object as? NSWindow else { return }

inBackground = false

// Inform the application delegate
myAppDelegate.windowDidBecomeMain(window)

Expand All @@ -31,6 +33,8 @@ extension MyController: NSWindowDelegate {

public func windowDidResignMain(_ notification: Notification) {

inBackground = true

// Stop the emulator if it is supposed to pause in background
if c64 != nil {
pauseInBackgroundSavedState = c64.running
Expand Down

0 comments on commit 63f9a1a

Please sign in to comment.