It doesn't take long to add once you figure out how to actually include it and call it. It's in a namespace (fastdelegate), which tripped me up for a while. Aside from that, it acts just like a function pointer except that it can point to member functions (even virtual ones).
For example, using FastDelegate in b2World for joint-destroyed events (patterned after the "Passing a FastDelegate as a function parameter" section of the article) would look something like this:
Code:
public:
typedef fastdelegate::FastDelegate<void (b2Joint *)> b2WorldListenerJointDestroyed;
void SetWorldListenerJointDestroyed(b2WorldListenerJointDestroyed listener) { m_jointdestroyed = listener; }
private:
b2WorldListenerJointDestroyed m_jointdestroyed;
To bind the delegate to a non-member function JointDestroyedCallback:
Code:
SetWorldListenerJointDestroyed(JointDestroyedCallback);
To bind the delegate to an instance of a b2WorldListener named worldListener:
Code:
SetWorldListenerJointDestroyed(MakeDelegate(worldListener, &b2WorldListener::NotifyJointDestroyed));
Alternatively, if the listener is public:
Code:
m_jointdestroyed.bind(JointDestroyedCallback);
and
Code:
m_jointdestroyed.bind(worldListener, &b2WorldListener::NotifyJointDestroyed);
Then, b2World can use the delegate to notify the listener when a joint gets destroyed:
Code:
if (m_jointdestroyed)
m_jointdestroyed(jn0->joint);
The FastDelegate header is incredibly convoluted because of the variety of ways compilers implement pointer-to-member, but this towering edifice of template code compiles down to an amazingly small number of machine instructions.