Command Pattern in Realtime

Started by
6 comments, last by SlimTimmy 19 years, 10 months ago
Hello, I''m developping a terrain editor right now and want to use the command pattern to realise this Redo/Undo-Feature. But normally you use the command pattern for opening a document or something like this, that means just single events. But how should I use or modify the command pattern so it is possible to raise/lower a terrain in realtime?
Advertisement
*push*
The command "RaiseTerrain" is still a single event. If "RaiseTerrain" is the current command then that object will keep a record of how much the relevant terrain is raised. When the user releases the mouse button push the command onto the undo/redo stack.


My Website: ai-junkie.com | My Book: AI Techniques for Game Programming
At the start of the modification (e.g. mouse button down), store the state of the things that are about to be changed. At the end of the modification do the same again. Those are your two undo states. Make an undo/redo that has the knowledge (data and access to member functions) to be able to move between the two states.
Ok, thanks for replying.

Another question:
If the user presses the mouse button, I''ll create a command object of type RaiseTerrainCommand, and call the member function doAction(float elapsed). But I have to store this object somewhere and I have to call this method every frame till the mouse button is released. Is this right?
if ur passing float elapsed, u can allways pass -elapsed
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
*push*
*pop*

i just couldnt resist
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com

This topic is closed to new replies.

Advertisement