Making OGRE more event-driven

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
NintenDave
Halfling
Posts: 43
Joined: Fri Jul 04, 2008 10:36 am
Location: Wales

Making OGRE more event-driven

Post by NintenDave »

I'm a fan of event-driven models for games, and so I'm trying to create some classes to help facilitate that. For example, I notice I often need something to happen at a particular point in an animation, and so I made the class below. I would like to know how any of you have make OGRE more event-driven, or any other opinions on the subject.

Thanks.

Code: Select all

class AnimationListener
{
public:
    typedef boost::function<void, void> Callback;

    AnimationListener(Real callbackTime, AnimationState* anim, const Callback& callback):
        callbackTime(callbackTime), anim(anim), callback(callback)
    {
    }

    void step(float timeStep)
    {
        static bool called = false;
        Real time = anim->getTimePosition();

        anim->addTime(timeStep);

        if(called)
        {
            // It was called at some point

            if(time >=0 && time < callbackTime)
            {
                // It is not yet time to do it this loop
                // We say it hasn't been called
                called = false;
            }
        }
        else
        {
            // It hasn't been called yet

            if(time > callbackTime)
            {
                // It should be called now
                // We say it has been called and call it
                callback();
                called = true;
            }
        }
    }

private:
    Real callbackTime;
    AnimationState* anim;
    Callback callback;
};
Post Reply