• Register

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!

RSS My Blogs

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:-

Implementation details

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...

  • Select tool: ...a tool is selected (some actions are only valid when the correct tool is active, so this must go in the history).
  • Select parts: ...any frozen parts are selected or deselected.
  • Select pivot: ...a pivot point is selected, which detaches all the selected part(s).
  • Move / resize selection: ...the selected part(s) are translated, rotated, or resized via manipulators.
  • Replace attachment: ...an attachment's type is changed.
  • Lock attachment: ...an attachment is locked or unlocked.
  • Delete attachments: ...attachments are deleted (whether directly, due to the selection being detached, or due to a part being destroyed).
  • Spawn / destroy construction: ...a part / construction is spawned or destroyed.
  • Freeze construction: ...a construction is frozen or unfrozen.
  • Swap material: ...a material is applied to a part.
  • Add / remove links: ...link(s) between link nodes are added or removed.
  • Apply paint: ...paint colour is applied to a part.

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.

New demo

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!

Start a group Groups
Unity Games

Unity Games

1,850 members Fans & Clans

For all Unity developers and developers-to-be, both beginners and professionals!

Indie Devs

Indie Devs

1,704 members Hobbies & Interests

A group dedicated to indie and standalone game development.

Blenderheads

Blenderheads

579 members Arts & Literature

For us folks who like to stay Free and use the Blender 3d program over every other costly options!

SmashHammer Games

SmashHammer Games

1 member Developer & Publisher

Indie developer of GearBlocks - a game about creative building, interactive machines, and gears - lots of gears.

Comments
clashka43
clashka43

I really would like to add something to the game. For example, new part) Just how to do it, I don't know(

Reply Good karma Bad karma+1 vote
clashka43
clashka43

Hi sam! I very like you game)

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

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.

Twitter

Latest tweets from @dangersamn

RT @GearBlocksGame: Drifting around a track in this rear engined player creation in the GearBlocks demo. #indiegames #indiedevT.co

Mar 28 2023

RT @GearBlocksGame: Some impressive angle skip block sculpting in these player creations in the GearBlocks demo. #indiegames #indiedevT.co

Mar 21 2023

RT @GearBlocksGame: Here's how the leaf springs were made, a lot of slider joints! T.co

Mar 15 2023

RT @GearBlocksGame: A player made some leaf springs in the GearBlocks demo. #indiegames #indiedev #madewithunity T.co

Mar 14 2023

RT @GearBlocksGame: A cool steering linkage design in this GearBlocks demo player creation. #indiegames #indiedev #madewithunity T.co

Feb 27 2023

RT @GearBlocksGame: Drifting in the desert. GearBlocks demo player creation. #indiegames #indiedev #madewithunity T.co

Feb 23 2023

RT @GearBlocksGame: Anyone else miss popup headlights? GearBlocks demo player creation. #indiegames #indiedev #madewithunity T.co

Feb 20 2023

RT @GearBlocksGame: Gear shifter linkage mechanism, player made in the GearBlocks demo. #gamedev #indiedev #madewithunity T.co

Feb 10 2023

RT @GearBlocksGame: Drifting, using differentials (diff lock) as brakes! GearBlocks demo player creation. #indiegames #indiedevT.co

Feb 3 2023

RT @GearBlocksGame: Testing out some rather nice suspension design on this player creation in the GearBlocks demo. #indiegamesT.co

Jan 31 2023