Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SlimTimmy

Command Pattern in Realtime

This topic is 5297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!