SVN Unstable

News about Box2D
Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

SVN Unstable

Postby Erin Catto » Fri Dec 21, 2007 1:49 am

The SVN version is very unstable now. The code may not even compile!

Please stick with 1.4.3 until 2.0 is released. This will make it easier for me to move between computers.

kdmiller3
Posts: 100
Joined: Sun Dec 02, 2007 6:29 pm

Re: SVN Unstable

Postby kdmiller3 » Fri Dec 21, 2007 1:59 pm

I've been browsing through the changes, and now I'm really looking forwards to 2.0... 8-)

The callback mechanism would work better using the C++ Fast Delegate template instead of an abstract interface class. I switched over to it from abstract interfaces for collision and damage events and it drastically simplified things and eliminated a lot of multiple inheritance. The delegate object is essentially a function pointer and "this" pointer, and can handle free functions (including static members), regular member functions, virtual member functions, and even gnarly things like multiple inheritance and virtual base classes. Once you have a delegate, you can then use it like a function pointer (using operator()) without caring where it came from. I discovered the power of delegates from ActionScript mx.utils.Delegate, of all places, but it's just as useful (if not more so) in C++.

The CodeProject site has been a bit slow today, but it seems to be working now.

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: SVN Unstable

Postby Erin Catto » Fri Dec 21, 2007 4:37 pm

Thanks for the tip. I won't have time to look into this for 2.0, but perhaps for a future release.

One issue that concerns me is compiler support. Box2D is often compiled on some limited platforms, like the DS and GP32.

kdmiller3
Posts: 100
Joined: Sun Dec 02, 2007 6:29 pm

Re: SVN Unstable

Postby kdmiller3 » Fri Dec 21, 2007 5:22 pm

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: Select all

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: Select all

SetWorldListenerJointDestroyed(JointDestroyedCallback);


To bind the delegate to an instance of a b2WorldListener named worldListener:

Code: Select all

SetWorldListenerJointDestroyed(MakeDelegate(worldListener, &b2WorldListener::NotifyJointDestroyed));


Alternatively, if the listener is public:

Code: Select all

m_jointdestroyed.bind(JointDestroyedCallback);

and

Code: Select all

m_jointdestroyed.bind(worldListener, &b2WorldListener::NotifyJointDestroyed);


Then, b2World can use the delegate to notify the listener when a joint gets destroyed:

Code: Select all

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.

Wahooney
Posts: 155
Joined: Tue Sep 18, 2007 6:17 am
Location: Western Cape, South Africa
Contact:

Re: SVN Unstable

Postby Wahooney » Sat Dec 22, 2007 9:41 am

Yup, that sure is broken :P

Feature list in TODO looks good though :)


Return to “News”



Who is online

Users browsing this forum: No registered users and 0 guests