Controller State Machine

Published June 19, 2001 by Zachary Booth Simpson, posted by Myopic Rhino
Do you see issues with this article? Let us know.
Advertisement
(C) 2000 - Zachary Booth Simpson. Copied with permission from http://www.mine-control.com/zack. If you find any of this work useful, please sign Zack's guest book: http://www.mine-cont...i/gbook-zbs.cgi. [size="5"]Intent
[bquote]Track a complicated state process with a controller.[/bquote]
[size="5"]Problem
[bquote]Many Controllers are very complicated state machines which involve convoluted state transitions as circumstances progress and in response to events. Animation is the canonical example - both time and user input effect the state transitions of animations, often with many special cases and subtle complications.[/bquote]
[size="5"]Solution
[bquote]A Controller subclass is created which contains the list of all state variables. For example, and animation might have: currectFrame, currentAnim, lastFrameTime, etc. The process virtual of the controller contains a switch on some primary state. For example: void Animation::doProcess() { switch( animState ) { case RUNNING_STARTING: case RUNNING: case RUNNING_STOPPING: ...Each state updates and checks for transition conditions. For example, RUNNIG may check to see if it is at the end of the cycle, if so, restart it. It might also check to see if the mouse button is still down, if not, change to RUNNING_STOPPING. State machines can become very complicated and difficult to maintain using this technique. One alternative is to use function pointers and setjmp/longjmp.[/bquote]
[size="5"]Structure
[bquote]None at this time.[/bquote]
[size="5"]Examples
[bquote]Link to example is no longer valid[/bquote]
[size="5"]Issues and Risks
[bquote]None at this time.[/bquote]
[size="5"]Related Patterns
[bquote]Controller, State[/bquote]
Cancel Save
0 Likes 1 Comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement