singleton and other designs

This is a discussion on singleton and other designs within the C++ Programming forums, part of the General Programming Boards category; one way you could do it would be to use the boost.serialisation library and simply save the state of each ...

  1. #16
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    one way you could do it would be to use the boost.serialisation library and simply save the state of each class that has an option.

    for instance, let's assume you're making a game, and you have the following options
    • screen resolution
    • difficulty
    • environmental options (gravity) etc
    • control bindings


    so lets say we have the following classes
    Code:
    class RenderingEngine
    {
    // stuff
    private:
        int m_screenHeight;
        int m_screenWidth;
    };
    
    class AI
    {
    // stuff
    private:
        enum Difficulty
        {
             GRANNY,
             MOM,
             GIRLFRIEND,
             MATE,
             HAS_NO_LIFE_AND_PLAYS_ALL_DAY
        };
        
        Difficulty m_diff;
    };
    
    class World
    {
    // stuff
    private:
        int m_gravity
    };
    
    class UserInput
    {
    // stuff
    private:
        std::map<Key, Command> m_controls;
    };
    you could then use a visitor pattern to call Serialise on each object.

    Sorry, I'd meant to write more, but I have to head out now. I'll post more later.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  2. #17
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Thank you, this would be very helpful!

  3. #18
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Hello..
    I read a little about visitor design pattern.. Is this the best approach to use when solving similar problems?

    It doesnt seem to be widely used and it doesnt look so easy to get used to it..

    It would be really cool if someone could post some more information about it..

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21