PDA

View Full Version : Undo



NecroDOME
16-01-2007, 09:55 PM
So I was wondering how you guys make an undo function.

Currently I have an undo function that works. When I move/rotate etc an object/mesh/light etc. I save the movement data. as I press undo, it just moves the object back where it came from. However I don't have an undo function when for example a texture changes.
It could easily be made, but I was wondering if you knew a better way if there is any.

jdarling
17-01-2007, 12:10 AM
Well, in the end you have to keep a record of previous states. I've seen lots of ways of doing it, but I like something similar to VariantRecords myself. Basically, a header record and then records for each "Message" type. The header contains an ID for the message type. When I write the message I record its type, when I read it, I read the message type back in and pass it out (thus allowing me to add messages quite quickly).

Also, I use a stack of N (an array) to record my undo actions. Simply record the Max top item (incase you want redo), and a stack pointer at the current state. Walk the stack either way to perform the actions (undo or redo). This is nice, as I can write the undo stack into the data file for use when the user re-loads the actual data file. Of course, you can strip the info to shrink the data file size.

Anyways, there is my answer ;)

cronodragon
17-01-2007, 01:21 AM
You could also save the states at intervals of time, and allow custom checkpoints for the user. :D

NecroDOME
17-01-2007, 02:04 AM
thnx
I never done anything with variants, but they sound like things I should use more often. Can you give me some more explanation or point me to a site with a tutorial on variants?

About checkpoints, I don't think I set them automatically. The only thing I think I going to implement is an auto-save function. something like saving every 5-10 minuets. I already got some sort of crash-recovery. When it crashes is save instantly saves the map-file.

jdarling
17-01-2007, 02:45 AM
Well, here is an article on the "Normal" way of doing it: http://www.delphicorner.f9.co.uk/articles/op6.htm
Google for "variant records delphi" will turn up quite a few results.

The other way is a bit more complicated, but it saves the overhead that a standard variant record creates. The way I'm talking about uses strong usage of pointers and other fun things. I'll see if I can find a simple sample on my drive some place, and if so I'll post it here.

NecroDOME
17-01-2007, 12:55 PM
Thnx, I seen it before, only I never used (made) it myself.