allan-takuya / cpptweener

Automatically exported from code.google.com/p/cpptweener
0 stars 0 forks source link

C++ template metaprogramming would allow equation functions to be called without the overhead of pure virtual function dereference #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As in the subject, you could achieve no-overhead function calls by exploiting 
generics programming.
For example, as you already have, define the Animation mode:

enum
{
    EaseIn,
    EaseOut,
    EaseInOut
}

Then defines the equation solvers as static functions:

...

class Expo
{
    public:

        static float easeIn( float t, float b, float c, float d );
        static float easeOut( float t, float b, float c, float d );
        static float easeInOut( float t, float b, float c, float d );
};

Then, define the invoker:

template< class T, int mode >
float ease( float accuFrameTime )
{
    ...
    float ret = iFrom;
    switch( mode )
    {
        case EaseIn:
        {
            ret = T::easeIn( t, b, c, d );
            break;
        }
        case EaseOut:
        {
            ret = T::easeOut( t, b, c, d );
            break;
        }
        case EaseIn:
        {
            ret = T::easeInOut( t, b, c, d );
            break;
        }
    }

    return ret;
}

Original issue reported on code.google.com by manuel....@gmail.com on 14 Feb 2010 at 3:48

GoogleCodeExporter commented 9 years ago
Done that, calling the correct solver is as straightforward as doing:

myAnimator.ease<Expo,EaseIn>( t, b, c, d );

Original comment by manuel....@gmail.com on 14 Feb 2010 at 3:50