1

I have been doing research on what the best way to achieve undo/redo functionality is for a painting app. I am using OpenGL ES 2.0 on iOS. The most popular approach seems to be to save a list of commands and VBOs to re-generate the painting to its previous state (Memento design structure). The other approach is to take graphical snapshots after each drawing action and revert to these snapshots on undo.

I have a problem with both approaches:

1) Memento - after a long list of actions, especially computationally intensive flood fill algorithms, the undo/redo functionally will get very slow and intensive.

2) Snapshots - after a long list of actions these snapshot will start to take up a lot of memory, especially if in raw state.

I was wondering if anybody has found a solution that works well for this situation, or perhaps somebody here has an idea how to optimize the above approaches.

Thanks.

Amendale
  • 317
  • 3
  • 19

2 Answers2

1

I don't think there's a way around limiting the number of steps that are undoable. You will always need some amount of memory to capture either the previous state, or the state change, for each undoable operation.

The Command pattern actually seems like the much more natural fit than the Memento to handle undo/redo. Using this, you will only store information about the specific changes for each operation. Which can still be substantial depending on the operation, but I think it can be much more targeted than blindly saving entire object states with a Memento.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
1

I have decided to try a hybrid approach, where I save a bitmap snapshot every 10-15 actions, and use command lines to restore individual actions past the snapshots. A more in depth answer is offered here: https://stackoverflow.com/a/3944758/2303367

Community
  • 1
  • 1
Amendale
  • 317
  • 3
  • 19