Hacker News new | ask | show | jobs
by XCSme 1465 days ago
For https://curvefever.pro we actually decided to store the state of the world for undo purposes, this way you can go anywhere back in time in constant time, and to redo you execute the commands again. The big advantage is that you don't have to create an undo function for each command (which might be tricky in some cases, as many times it still involves storing state) and you don't have to iterate through/apply all the commands to go back at a specific time. To save memory, we actually only store the state every 5 ticks (so if you want go to back to tick 23, you go back to tick 20 and run the simulation forward for 3 ticks).
1 comments

To be more clear, in case an "undo" of a player action has to happen, the state before that action is loaded, the action is removed and the world ticked forward again with all the commands (excepting the removed one).