Box2D Forums

It is currently Thu Nov 27, 2014 8:59 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: SVN Unstable
PostPosted: Fri Dec 21, 2007 1:49 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2946
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.


Top
 Profile  
 
 Post subject: Re: SVN Unstable
PostPosted: Fri Dec 21, 2007 1:59 pm 
Offline

Joined: Sun Dec 02, 2007 6:29 pm
Posts: 100
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.


Top
 Profile  
 
 Post subject: Re: SVN Unstable
PostPosted: Fri Dec 21, 2007 4:37 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2946
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.


Top
 Profile  
 
 Post subject: Re: SVN Unstable
PostPosted: Fri Dec 21, 2007 5:22 pm 
Offline

Joined: Sun Dec 02, 2007 6:29 pm
Posts: 100
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.


Top
 Profile  
 
 Post subject: Re: SVN Unstable
PostPosted: Sat Dec 22, 2007 9:41 am 
Offline

Joined: Tue Sep 18, 2007 6:17 am
Posts: 155
Location: Western Cape, South Africa
Yup, that sure is broken :P

Feature list in TODO looks good though :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group