I'm an ex-long time "AAA" game programmer, now solo indie developer making GearBlocks, a game all about creative building, interactive machines, and gears - lots of gears!
Hi all, over the holiday period I decided to take some time out to try an experiment: attempt to add undo functionality to the game. Specifically, implement a command history, to which a command would be added for each tool action (e.g. select, move, or attach parts, apply material or paint, etc.) and then allow the player to undo or redo the commands in that history.
The game's tools were not originally built with this in mind, but the code is reasonably well structured so I thought it might be possible. The initial prototype turned out to be promising, and showed the potential improvement to usability this would bring.
Well, I couldn't resist seeing this through to completion, and so that's what I've been working on for the past few weeks. It required substantial refactoring of some of the tool code, and took a while, but the results are well worth it I think.
Here it is in action, I've exposed the command history to Lua scripting, and made a script mod that shows the current list of commands:-
Rather than store an absolute snapshot every time something changes, the commands in the history store relative deltas. A command keeps a record of the change that was made by a tool action. This means implementation was kind of an "all or nothing" prospect: all tool actions must be accounted for the command history (in the right order!) for everything to work properly.
Here are the commands I ended up with, these are added to history when...
The command history has a buffer containing references to the added commands, in the order they were added. This allows for the commands to be undone in reverse order, and redone in forward order.
The history maintains an index of the last undone command, and if a new command is added, it will go into the buffer at this point. Any commands that came after the one most recently undone will be lost.
The buffer is a finite size (currently 256), if a command is added to history and it's full, the oldest command is removed.
So, the game now has full undo / redo capability (using Ctrl + Z / Ctrl + Y). This is a feature that this genre of game really should have, and I think it was worth making the effort to get it done.
There are still a couple of issues left to deal with, but it's now in a usable state, so I've just updated the demo to include it. A lot of code had to change, hopefully I haven't introduced any glaring bugs, it seems stable so far. Give it a try and let me know how you get on with it!
No blogs were found matching the criteria specified. We suggest you try the blog list with no filter applied, to browse all available. Join now to share your own content, we welcome creators and consumers alike and look forward to your comments.
For all Unity developers and developers-to-be, both beginners and professionals!
A group dedicated to indie and standalone game development.
For us folks who like to stay Free and use the Blender 3d program over every other costly options!
Indie developer of GearBlocks - a game about creative building, interactive machines, and gears - lots of gears.
No groups were found matching the criteria specified. We suggest you try the group list with no filter applied, to browse all available. Start a group and help us achieve our mission of showcasing the best content from all developers. Join now to share your own content, we welcome creators and consumers alike and look forward to your comments.
Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.
I really would like to add something to the game. For example, new part) Just how to do it, I don't know(
Hi sam! I very like you game)