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

    Controller

    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]Update a Model's state based on circumstance.[/bquote][/indent]
    [size="5"][b]Problem[/b][/size]
    [indent][bquote]Controllers implement the rules of a game. They determine how objects behave given a circumstance, and isolate these rules from the objects themselves. This makes both the controllers and models more reusable and maintainable.[/bquote][/indent]
    [size="5"][b]Solution[/b][/size]
    [indent][bquote]Controllers relate to Models and Views as follows: [indent] [list][*]Models are read-writeable by Controllers.[*]Controllers are created and destroyed by Models, but are otherwise invisible.[*]Views are invisible to Controllers and vice-versa.[/list] [/indent] Controllers are often associated with only one model instance. For example: animation, AI, pathfinding. In these cases the controller instance is usually created and destroyed synchronously with the associated model.

    Some Controllers inherently have more than one associated Model. For example: multi-body physics, target tracking (heat seeking missiles, etc). These controllers often maintain Model references which must be notified / garbage collected when the referenced object dies. This is called the "model death problem". The creation and deletion of these multi-owner controllers is usually done by some primary owner.

    Controllers are often implemented as "processes" in a mini cooperative multi-tasking kernel. (See Mini-kernel) but may also be implemented as "hard wired updates" in the main loop, especially for large multi-model controllers like physics.

    Some simple Controllers are stateless. For example, a homing missile controller may just compute the direction to the target and apply force as necessary. Most controllers, however, are state-aware. For example, an animation tracks progress through the animation and changes states accordingly; e.g. if (frame > 10) state = STOP_WALKING.

    State-aware controllers often become significantly complicated with large switch statements. (See State Machine Controller.)[/bquote]
    [/indent] [size="5"][b]Structure[/b][/size]
    [indent][bquote]Not available at this time.[/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]Mini-kernels aggregate Controllers, giving each controller some time to work. Controllers modify Model's states.

    Views may translate Model state with an Appearance Map.

    Complicated state-aware controllers may use a Controller State Machine.[/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

    There are no reviews to display.