Recent Resources
-
GLSL 4.0: Discarding Fragments to Create a Perf...
-
GLSL 4.0: Using Subroutines to Select Shader Fu...
-
Building a Complete Board-based Puzzle Game wit...
-
JIRA: Programming Workflows
-
.NET Generics 4.0: Container Patterns and Best...
-
Raw Meat: Game Design Tips from Team Meat's...
-
Sedge: An Automated Error Reporting Tool
Controller State Machine
By Zachary Booth Simpson | Published Jun 19 2001 10:21 PM in General Programming
© 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.
Intent
Problem
Solution
Structure
Examples
Issues and Risks
Related Patterns
Intent
Track a complicated state process with a controller.
Problem
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.
Solution
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() {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.
switch( animState ) {
case RUNNING_STARTING:
case RUNNING:
case 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.
Structure
None at this time.
Examples
See http://www.totempole...temachines.html for a sample implementation of this technique.
Issues and Risks
None at this time.
Related Patterns
Controller, State


















