undo, redo
undo, redo
how undo and redo is achieved? i have zero idea how they did that. any tips?
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
Basically you have 2 ways. You either save complete states or you save actions. The former is easier the latter usually more effective.
Using an image-manipulation program as example, saving the complete state would mean saving the whole image regularly and push it into an array. Then on undo you can get an older image out of the array and on redo you can get back to a newer one. Also think about what to do when you start modifying again after an undo/redo ... which images would you remove from the array and where would you insert the next ones. Just compare with how other applications handle those cases.
But saving states is often (especially when working with images) very memory consuming, so you can't do that always. So you save state-differences. Each action knows which parts need to be saves when they are executed. And each action also knows how to undo itself with the saved information. So for example a line-drawing action would save just all the affected pixels between start and endpoints for the undo. And it would save the line-drawing parameters for the redo (color, start-point, end-point, line-width).
Undo-redo is unfortunately often not trivial...
Using an image-manipulation program as example, saving the complete state would mean saving the whole image regularly and push it into an array. Then on undo you can get an older image out of the array and on redo you can get back to a newer one. Also think about what to do when you start modifying again after an undo/redo ... which images would you remove from the array and where would you insert the next ones. Just compare with how other applications handle those cases.
But saving states is often (especially when working with images) very memory consuming, so you can't do that always. So you save state-differences. Each action knows which parts need to be saves when they are executed. And each action also knows how to undo itself with the saved information. So for example a line-drawing action would save just all the affected pixels between start and endpoints for the undo. And it would save the line-drawing parameters for the redo (color, start-point, end-point, line-width).
Undo-redo is unfortunately often not trivial...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 126
- Joined: Sun Apr 02, 2006 1:21 am
- Location: Canada
I agree almost entirely with CuteAlien. However, I would just like to add that instead of using an array, it would be a lot easier to use a stack.
This way, whenever a change is made, you put the difference into the stack. When you want to undo, you just pop the item off of the stack. To enable redo, you could then take the difference you took of the stack and put it into another stack.
I think it's just an easier way of keeping track of it.
This way, whenever a change is made, you put the difference into the stack. When you want to undo, you just pop the item off of the stack. To enable redo, you could then take the difference you took of the stack and put it into another stack.
I think it's just an easier way of keeping track of it.
Don't bet against vitek, he's got scary mind-reading skills!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 126
- Joined: Sun Apr 02, 2006 1:21 am
- Location: Canada
Hmmm, stacks are dynamic are they not? Meaning you don't have to worry about expanding your array. Of course, I suppose if you want to limit the number of undos available, an array probably would be better.
Also, I have no desire to bet against any of you, my c++ knowledge as not as great as I'd like it to be. Two years in university and we're still just using Java.
Also, I have no desire to bet against any of you, my c++ knowledge as not as great as I'd like it to be. Two years in university and we're still just using Java.
Yes, they are, and yes you are correct about arrays not being dynamic. This is just an issue of context. In the C/C++ language, the term array usually refers to a fixed size collection of elements, like int x[10]. In Irrlicht, the term array usually means irr::core::array<> which is essentially the same as the C++ Standard Library std::vector<> container. It is dynamic.DarkDepths wrote:Hmmm, stacks are dynamic are they not?
Travis
-
- Posts: 126
- Joined: Sun Apr 02, 2006 1:21 am
- Location: Canada