Jump to content
  • Advertisement
  • Remove ads and support GameDev.net for only $3. Learn more: The New GDNet+: No Ads!

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

    Controller State Machine

    General and Gameplay Programming

    Myopic Rhino
    (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]
    [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]
    [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]
    [bquote]None at this time.[/bquote]
    [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]

      Report Article
    Sign in to follow this  

    User Feedback

    There are no comments to display.

    Create an account or sign in to comment

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

    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

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!