Skip to main content
gamedev.net
🔒 Locked

Command Pattern in Realtime

Started by SlimTimmy 6 replies 2.2k views
Original Post
SlimTimmy
SlimTimmy
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?
fup
fup
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
quorn
quorn
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.
SlimTimmy
SlimTimmy
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?
vesoljc
vesoljc
if ur passing float elapsed, u can allways pass -elapsed
Abnormal behaviour of abnormal brain makes me normal...www.zootfly.com
vesoljc
vesoljc
*pop*

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.