• 06/19/01 10:21 PM
    Sign in to follow this  

    Controller State Machine

    General and Gameplay Programming

    Myopic Rhino
    [i](C) 2000 - Zachary Booth Simpson. Copied with permission from [url="http://www.mine-control.com/zack"]http://www.mine-control.com/zack[/url]. If you find any of this work useful, please sign Zack's guest book: [url="http://www.mine-control.com/cgi/gbook-zbs.cgi"]http://www.mine-cont...i/gbook-zbs.cgi[/url].[/i] [size="5"][b]Intent[/b][/size] [indent][bquote]Track a complicated state process with a controller.[/bquote][/indent] [size="5"][b]Problem[/b][/size] [indent][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][/indent] [size="5"][b]Solution[/b][/size] [indent][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: [code]void Animation::doProcess() { switch( animState ) { case RUNNING_STARTING: case RUNNING: case RUNNING_STOPPING: ...[/code]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] [/indent] [size="5"][b]Structure[/b][/size] [indent][bquote]None at this time.[/bquote][/indent] [size="5"][b]Examples[/b][/size] [indent][bquote]Link to example is no longer valid[/bquote][/indent] [size="5"][b]Issues and Risks[/b][/size] [indent][bquote]None at this time.[/bquote][/indent] [size="5"][b]Related Patterns[/b][/size] [indent][bquote]Controller, State[/bquote][/indent]


      Report Article
    Sign in to follow this  


    User Feedback

    Create an account or sign in to leave a review

    You need to be a member in order to leave a review

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now