Results 1 to 6 of 6

Thread: Undo

  1. #1
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Undo

    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.
    NecroSOFT - End of line -

  2. #2

    Undo

    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

  3. #3

    Undo

    You could also save the states at intervals of time, and allow custom checkpoints for the user.

  4. #4
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Undo

    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.
    NecroSOFT - End of line -

  5. #5

    Undo

    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.

  6. #6
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Undo

    Thnx, I seen it before, only I never used (made) it myself.
    NecroSOFT - End of line -

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL