Box2D Forums

It is currently Tue May 21, 2013 6:34 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Sep 15, 2010 1:09 pm 
Offline

Joined: Fri May 14, 2010 5:01 am
Posts: 3
Hi,

i created a full JNI wrapper for the native Box2D implementation (latest stable release). It's integrated with my Android game development lib called libgdx. You can find it at http://code.google.com/p/libgdx/. The only thing i haven't implemented yet is the raycasting APIs as well as pre-solve. Everything else is completely integrated and works pretty well, a lot better than the JBox2D. There's no garbage collection issues at all and the JNI call overhead is so minimal that i wouldn't give it a second thought. Another nice benefit is that it also works on the desktop (libgdx is actually cross platform, Win/MacOs/Linux/Android, albeit it only works on 32-bit VMs at the moment as i'm a lazy bastard and didn't compile for 64-bit yet). Oh, and the thing is Apache License 2 so you can basically do with it whatever you want, e.g. cut out all Box2D related code if you don't want to use libgdx :).

You can find additional information on my blog a http://www.badlogicgames.com

Hope that helps some of you guys

Ciao,
Mario


Top
 Profile  
 
PostPosted: Wed Sep 29, 2010 9:23 am 
Offline

Joined: Thu Aug 12, 2010 3:50 am
Posts: 5
Wow :D That's some neat work! And a strange coincidence, because I was going to release the same kind of thing! I based mine off the stable 2.1.2 release.

Getting it to compile was pretty simple. Box2D uses a tidbit of the C++ STL here and there, which Android doesn't support, but those were easily replaced by C counterparts (<limits> for infinite floats, <algorithm> for one std::sort call, and one seemingly redundant <memory>). I had to add one <new> somewhere to let the compiler know about the existence of placement new.

Using the almighty and amazing SWIG, the wrapping was almost effortless. I didn't wrap everything yet, because I'm renaming everything to match Java conventions. b2World becomes World (in package org.box2d.android), b2_fixedBody becomes BodyType.FIXED_BODY, etcetera. As you can see, I'm going for an interface that integrates seamlessly with other Java code.

One thing I'm worried about is the callback interfaces like b2DebugDraw; SWIG directors refuse to compile on the NDK, so it will require some manual labour, probably similar to what you did.

I'm also adding some convenience methods to prevent unnecessary construction and destruction of b2Vec2 objects. For example, a World constructor that takes (float gravityX, float gravityY, bool doSleep). I didn't measure whether this matters for performance in the long run, but it does save typing in many cases :) And in a crippled language without operator overloading, b2Vec2 isn't all that useful anyway.

Since you appear to have taken largely the same approach, I think there's little point in me polishing my code for release anymore. If anyone is interested anyway, let me know!


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 4:13 pm 
Offline

Joined: Tue Feb 16, 2010 3:08 pm
Posts: 21
Wow, cheers dude.

Just picked this one up intergrated with cocos over at:
http://code.google.com/p/cocos2d-android-1/ (update/improvement to: code.google.com/p/cocos2d-android/ )

Basically, it runs faster with 200 cubes on screen than the original cocos/Jbox2d droid package
did with around 16.

Really good job!


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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