Skip to content

feat(minarch): undo load state - #792

Open
duonqfs wants to merge 2 commits into
LoveRetro:mainfrom
duonqfs:feat/undo-load-state
Open

feat(minarch): undo load state#792
duonqfs wants to merge 2 commits into
LoveRetro:mainfrom
duonqfs:feat/undo-load-state

Conversation

@duonqfs

@duonqfs duonqfs commented Jul 26, 2026

Copy link
Copy Markdown

Adds undo for an accidental load state, mirroring RetroArch's undo_load_state.

Loading a state through the in-game menu or the Load State shortcut now snapshots the running state to memory first. Undoing swaps that snapshot with the current state, so pressing undo a second time returns to the state that was loaded — the same swap semantics RetroArch uses. Nothing is written to the SD card.

Reachable two ways: an "Undo" row in the in-game menu, under Load, and a bindable "Undo Load State" shortcut. The menu row greys out via State_hasUndo() whenever no snapshot is available and does nothing when confirmed, so the menu never offers an action it can't perform. Availability is evaluated on menu redraw rather than every frame, keeping core.serialize_size() off the hot path.

The snapshot is only kept when the load actually succeeded, and it is dropped if the core starts reporting a different serialize size. Disc changes drop it too: Menu_loadState() swaps discs before reading the state, so a snapshot taken afterwards would hold the previous disc's machine state while the new disc is inserted. A load that changed discs skips the capture entirely, and changing discs from the menu's Continue row invalidates a stale snapshot.

Undo is blocked in RetroAchievements hardcore mode, same as loading a state.
Pokémon Team Rocket Edition 2026-07-26-18-43-10
Pokémon Team Rocket Edition 2026-07-26-18-44-04
Pokémon Team Rocket Edition 2026-07-26-18-43-53

Adds undo for an accidental load state, mirroring RetroArch's
undo_load_state.

Loading a state through the in-game menu or the Load State shortcut now
snapshots the running state to memory first. Undoing swaps that snapshot
with the current state, so pressing undo a second time returns to the state
that was loaded — the same swap semantics RetroArch uses. Nothing is
written to the SD card.

Reachable two ways: an "Undo" row in the in-game menu, under Load, and a
bindable "Undo Load State" shortcut. The menu row greys out via
State_hasUndo() whenever no snapshot is available and does nothing when
confirmed, so the menu never offers an action it can't perform.
Availability is evaluated on menu redraw rather than every frame, keeping
core.serialize_size() off the hot path.

The snapshot is only kept when the load actually succeeded, and it is
dropped if the core starts reporting a different serialize size. Disc
changes drop it too: Menu_loadState() swaps discs before reading the state,
so a snapshot taken afterwards would hold the previous disc's machine state
while the new disc is inserted. A load that changed discs skips the capture
entirely, and changing discs from the menu's Continue row invalidates a
stale snapshot.

Undo is blocked in RetroAchievements hardcore mode, same as loading a
state.
@duonqfs

duonqfs commented Jul 27, 2026

Copy link
Copy Markdown
Author

Hi @frysee , when you have a chance, could you please take a look at this PR? I'd really appreciate your review. Thanks!

@frysee

frysee commented Jul 27, 2026

Copy link
Copy Markdown
Member

I will, thanks. What I can already tell you is that this should not take up space in the main menu, imo.

@Pobega

Pobega commented Jul 27, 2026

Copy link
Copy Markdown

Could the Undo Load option be made to be one of the selectable loadable states (left/right when hovering over 'Load'?) I think that might be the ideal way to express this to the user via the UI without adding an extra top level menu entry.

Of course this would also need frysee's approval, but just a thought.

@duonqfs

duonqfs commented Jul 28, 2026

Copy link
Copy Markdown
Author

Thanks for the feedback. I’ve updated the PR and removed the separate Undo item from the main menu.

Undo Load is now shown as a contextual X — UNDO LOAD action only when Load is selected and a valid undo snapshot exists. The hint remains hidden when undo is unavailable.

I’ve attached screenshots of the new behavior. Could you please take another look and let me know what you think?
Pokémon Team Rocket Edition 2026-07-28-13-22-13

@duonqfs
duonqfs force-pushed the feat/undo-load-state branch from d17d0e8 to 5806ecc Compare July 28, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants