Sync joystick resume correction from VCC Plus 1bd2b50e

This commit is contained in:
Brian Holman committed 2026-11-14 02:31:30 -07:00
1 parent b2ecec4d87
commit 8236ca17c6
4 files changed
+34 -6

No files matched your search

+9
View File
@@ -568,8 +568,12 @@ final class MachineModel: ObservableObject {
private var polling = false
private var imageGeneration: UInt64 = 0
private var imageRevision: UInt64 = 0
private var observedInputGeneration: UInt64?
private func accept(_ snapshot: VCCMachineSnapshot) {
let inputNeedsResynchronization = snapshot.state == .running &&
(state != .running || snapshot.generation != observedInputGeneration)
observedInputGeneration = snapshot.generation
diskEditorLocked = snapshot.diskEditorLocked
printer.observe(snapshot)
let basic = BASICDebugState(attached: snapshot.basicDebugAttached,
@@ -631,6 +635,11 @@ final class MachineModel: ObservableObject {
let nextHardware = HardwareState(snapshot: snapshot, activities: activity, sdcActivity: sdcActivity)
if hardware != nextHardware { hardware = nextHardware }
state = snapshot.state
// The core deliberately ignores host joystick submissions while paused.
// Reapply the configured interfaces only after a resume/new machine is
// running, even when neutral axes match the host's cached last sample.
// Do not initialize native input solely for receiving a snapshot.
if inputNeedsResynchronization { existingInputHub?.release() }
frames = snapshot.frames
error = snapshot.errorMessage
guard snapshot.pixels != nil else {
@@ -253,6 +253,11 @@ final class SoftwareLibraryMachineLaunchTests: XCTestCase {
@MainActor func testManualDiskLaunchMountsWithoutInjectingCommands() async throws {
let fixture = try Fixture(); defer { fixture.cleanup() }
try await withMachine(fixture) { model, controller, _ in
var configuredInput = model.input.settings
configuredInput.right = PortSettings(source: .controller, interface: .tandy, device: "remembered-disconnected")
configuredInput.left = PortSettings(source: .mouse, interface: .cocoMax)
model.input.applyProfileSettings(configuredInput)
let inputEpoch = model.input.epoch
let plan = try fixture.plan(cartridge: false)
XCTAssertTrue(plan.commands.isEmpty); XCTAssertFalse(plan.automaticallyStarts)
let prepared = try await model.prepareLibraryLaunch(plan)
@@ -261,6 +266,10 @@ final class SoftwareLibraryMachineLaunchTests: XCTestCase {
let running = await step(controller.snapshot)
XCTAssertEqual(running.state, .running); XCTAssertTrue(running.disks[0].mounted)
XCTAssertEqual(running.pasteRemaining, 0)
XCTAssertEqual(Int(running.joystickInputs[0].mode), configuredInput.right.interface.rawValue)
XCTAssertEqual(Int(running.joystickInputs[1].mode), configuredInput.left.interface.rawValue)
XCTAssertEqual(model.input.settings, configuredInput)
XCTAssertEqual(model.input.epoch, inputEpoch)
XCTAssertEqual(model.diskAssignments.drives[0]?.url, plan.floppyURLs[0])
}
}
+10
View File
@@ -356,10 +356,20 @@ extension StartupTests {
"Preserving settings must also restore their interface to the newly loaded guest")
var personal = try f.startup.appDefaults()
personal.name = "Explicit personal input"; personal.input.right.source = .mouse
personal.input.right.interface = .cocoMax
personal.input.left.source = .keyboard; personal.sound = false
await model.loadProfile(personal)
XCTAssertNil(model.profileError); XCTAssertEqual(model.input.settings, personal.input)
XCTAssertFalse(try inputStore.loadState().automaticRightController)
let inputEpoch = model.input.epoch
model.input.poll() // A neutral sample while paused must not suppress resynchronization.
model.resume(); try await waitForStartup(model)
let resumed = await withCheckedContinuation { done in controller.snapshot { done.resume(returning: $0) } }
XCTAssertEqual(Int(resumed.joystickInputs[0].mode), personal.input.right.interface.rawValue,
"Ordinary resume must apply a profile's unchanged configured interface after paused submissions were ignored")
XCTAssertEqual(resumed.joystickInputs[0].buttons, 0)
XCTAssertEqual(model.input.epoch, inputEpoch, "Machine resynchronization is not a settings edit")
XCTAssertEqual(try inputStore.load(), personal.input)
let reset = await model.restoreAppDefaults()
XCTAssertTrue(reset); XCTAssertEqual(model.input.settings, .freshDefaults)
XCTAssertTrue(try inputStore.loadState().automaticRightController)