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

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

    Double Buffered State

    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 an old and new state for multi-Model Controllers.[/bquote]

    [size="5"]Problem
    [bquote]Some Controller systems (for example, collision physics) need to track the state of several objects simultaneously and it must be ensured that they always read the same time step state for each Model instance.

    If double buffering is not used, then as the physics system traverses the Models, it will become "confused" when it reads a state which has already been updated, thus using a new state instead of an old state.

    This is analogous to a variable swap. int temp = a; a = b; b = temp; Without the temp varaible, a = b; b = a; would cause a==b always.[/bquote]
    [size="5"]Solution
    [bquote]The necessary state information is typically isolated into a separate structure. For example:

    struct PhysicsState {
    Vec3 pos,vel,angles,angVel,forceAccum,torqueAccum
    };
    Two instances of this class are combined into either the controller or model, often in a two element array. A global or local variable is used to flip between the two states using an accessor method.

    For example:

    class Model {
    PhysicsState states[2];
    PhysicsState getOldState() { return state[ globalFrame &1]; }
    PhysicsState getNewState() { return state[(globalFrame+1)&1]; }
    };
    [/bquote]

    [size="5"]Structure
    [bquote]Not available at this time.[/bquote]

    [size="5"]Examples
    [bquote]None at this time.[/bquote]

    [size="5"]Issues and Risks
    [bquote]None at this time.[/bquote]

    [size="5"]Related Patterns
    [bquote]Controller[/bquote]

    [size="5"]Uses and References
    [bquote]Thanks to Chris Hecker.[/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!