Archived

This topic is now archived and is closed to further replies.

Wavewash

Edit Undo How to?

Recommended Posts

I reached a point where my level editor is finally useable, and as I started to use it I made a mistake and instantly went up to edit undo only to find I hadn''t made an edit undo function. Now after trying to scower around and find information and coming up with nothing I began thinking how I could make a edit undo capability. I''m guessing a LIFO stack that keeps information to what has recently been done, but the problem is that a lot of diffrent things could have been done. Anyone have experience coding an undo function in a program that could point me in the right direction? ~Wave

Share this post


Link to post
Share on other sites
there are two ways:
1. Store all information in , say, 10 arrays and wrap at it''s ends. for any change made *push* an additionally element storing all infos to the end of that array and *pop* the one where the array begins.

2. Store a array (std::vector) with informations about the performed actions. you can then "undo" a particular action if you know what action it was

Share this post


Link to post
Share on other sites
Using a linked list would be best imo because it makes insertion easy. Every time an action is done, push it onto the list (actually, make it a linked list of linked lists of actions. that way, you can store a group of simmmilar actions in the same entry in the main list. that makes it easier to undo for example painting 50 tiles a different texture and undo it as a single action). What would be a really nice feature is 'selective undo'. Say I made a mistake 10 actions ago, but all the actions since then were correct. It would be nice to be able to pick action 10 and undo only it. You could implement that by undoing all the actions up to the one you need to remove and then redoing all the actions in the right order except for the removed one. Might be slow but it would be a nice feature.

Now, as for the exact implementation: It really depends how you made your editor. If its a large state machine, you could just make a duplicate that does the opposite of an action and store the information it needs in the linked list. For example, for undoing painting tiles you need to know what the tile was before it was changed, so you could store that. Perhaps do as windows does and just store a message ID and a void pointer to a structure with the proper information. The 'undo' function would use the message ID to know what to cast the void * to. Or if you're using C++ you could use a base class and derived ones instead of void * and structs.

[edited by - Extrarius on July 3, 2003 1:11:23 PM]

Share this post


Link to post
Share on other sites