SameBoy icon indicating copy to clipboard operation
SameBoy copied to clipboard

Feature request: Save state undo

Open meithecatte opened this issue 6 years ago • 2 comments

Every time I want to use a savestate, I have to doublecheck the key bindings - is shift used to save or load? If I get it wrong, either the saved or the currently running state gets discarded. The problem of potentially destructive features in software is usually solved with undo, and I believe this is also applicable here.

The implementation seems simple on the surface:

  • Before state is saved to slot k, the previous contents st[k], if any, is stored in the undo slot:
if (st[k]) undo = struct undo { k, st[k] };
st[k] = gb_state;
  • When state is loaded from slot k, the running state is stored in the undo slot:
if (st[k]) {
    undo = struct undo { -1, gb_state };
    gb_state = st[k];
}
  • When undo is triggered (proposed keybind: CTRL-Z), the corresponding save state slot is restored to the state stored in the undo slot:
if (undo) {
    if (undo.slot == -1) gb_state = undo.state;
    else st[undo.slot] = undo.state;
}

The impact of this change would be much greater if the feature was adequately advertised. Gambatte notifies the user of a successful state save and load by overlaying a status message in the lower left corner of the screen. Should this mechanism be adopted, appending (Ctrl-Z to undo) to the messages would be a great way to notify the user of this feature.

meithecatte avatar Aug 27 '19 13:08 meithecatte

Regardless of this feature, just noting that loading a save state can already be reverted using the Rewind feature.

LIJI32 avatar Apr 12 '20 19:04 LIJI32

If this feature is still wanted, I think I can make this work. would someone have time to discuss a proposed solution?

Diesel-Gaming avatar Aug 31 '22 16:08 Diesel-Gaming