adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Adonthell-devel] Re: Loading/saving engine state


From: Kai Sterker
Subject: [Adonthell-devel] Re: Loading/saving engine state
Date: Thu, 17 Sep 2009 00:14:56 +0200

On Tue, Sep 15, 2009 at 11:03 PM, Kai Sterker <address@hidden> wrote:
> On Sun, Sep 13, 2009 at 2:00 PM, Kai Sterker <address@hidden> wrote:
>
>> On a second thought, here is a better design: implement that save game
>> manager in the base module and allow all the other modules to register
>> the classes that need to be saved or loaded. Then, on saving, the
>> manager will just iterate over those and call the appropriate
>> interface method. This would also allow for a rough progress
>> indication as we'd know in advance how many classes need to be
>> loaded/saved.
>
> Started with the implementation today, but didn't get very far yet.
> Hope to have something to show over the weekend.

Quite a bit of v0.3 gamedata class ported to v0.4 today. Also had some
thoughts about the registration process:

On the one hand, classes we want to serialize should be static, so
that they can register themselves! OTOH, for registration we then need
some kind of wrapper that can actually be registered.

My current thoughts involve a mix of a template and functors. Something like

    template <class T>
    class serializer
    {
    public:
        serializer()
        {
            Save = base::make_functor_ret(&T::save);
            Load = base::make_functor_ret(&T::load);
        }

        bool save (const std::string & path)
        {
            return (*Save)(path);
        }

        bool load ()
        {
            return (*Load)();
        }

    private:
        base::functor_1ret<bool, const std::string> *Save;
        base::functor_0ret<bool> *Load;
    };

It needs to be refined somewhat, so that it can be used from Python
too. And of course, we'd want to be able to register instantiated
objects directly. So I guess there could be a base class that has
virtual save/load methods. Anything that wants to be directly
serializable would have to implement that base class then. Any static
classes to be serialized also had to implement save/load, otherwise
there'd be compile errors. So things should be pretty safe.

Will play around with that tomorrow ... as usual, comments and
suggestions welcome.

Kai




reply via email to

[Prev in Thread] Current Thread [Next in Thread]