Box2D Java

You'll probably see no major speed improvements compared to 1.4.3 (actually, things may get a little worse due to CCD), though I'm now trying to be more careful about vector creations whenever I can get rid of them without too much trouble (it takes a lot of work to remove them all, and I run the risk of introducing bugs if I inline things improperly). I have been profiling, so I do have a pretty good sense where the bottlenecks are now, so as soon as I get 2.0 done I'm going to start attacking those pretty heavily - currently, temporary Vec2 creation/GC seems to account for a pretty huge piece of the pie, from about 20% to over 50% depending on the usage, and almost all of that could potentially be eliminated (at a decent cost in terms of effort and maintainability, of course). Another minor version or so after 2.0 and I'd expect a medium performance increase (max of maybe 10 or 20%, I'd guess) as I do this for the highest traffic areas; beyond that, it's pretty much up to Erin upstream, as I don't want to start rewriting algorithms in Java while the C++ version is still changing so much. Erin says that there are tons of optimizations he could apply if things settle down a bit, so we'll see about that, and if any of it will carry over to Java.

If the next Java VM has escape analysis + stack allocation enabled, that would be the best improvement you're likely to see for this stuff - yell at Sun about this if you care, otherwise it looks like it might be left out of the client JVM altogether!

Also, I might have time to include a Slick demo with 2.0, which would be nice because it will give a better sense how fast this stuff can really run.
Just a quick question here...

I'm trying to convert the C++ demo from the this post (movable character) to work with the Java version (will release the source when done).
However, it uses the method Idle but this one isn't available in JBox2D, is there any alternative?

Btw, why doesn't the Java version get it's own forum like the Flash one?
I'm pretty sure Idle() is a glut-registered function. From what I remember about glut, it's just called once per frame (can't remember whether it's before or after the drawing). Do the same and you should be fine - try it before and after the step and drawing calls, see if it makes a difference (it likely won't make any as long as all the key-presses are recorded, as it's not integration code that's going to cause instabilities or anything like that). If you're using the testbed demos as your base (subclassing PTest with your class) you can overload the public void preStep() and postStep() functions - that's exactly what they're there for. Otherwise, just put it into your game loop.

Right now it doesn't make sense for a JBox2d forum to be here, as there just isn't the critical mass of users (far fewer Java game programmers out there than C++ or Flash). Over the next few updates it should become a bit easier to use (version 2.0 should be released in a few days, and as soon as that's done I'm going to start getting Javadocs in order), so it's possible more people will be using it, if that's the case we'll see.

BTW, version 2.0 is running now, and though it's not completely debugged or optimized and the testbed is in an unfinished state, the API is now in line with Box2d 2.0 and shouldn't change much, so any bleeding-edgers can grab the code from SVN (head to http://www.sf.net/projects/jbox2d to find the repo information). The executable file is TestbedMain.java, and there's only one working test now, but it's probably safe to start coding with if you're not afraid to update the engine out from under your own code later - just don't base anything on the org.jbox2d.testbed or org.jbox2d.util packages, those are going to change a lot!

(Edit: the SVN repository can be anonymously checked out from https://jbox2d.svn.sourceforge.net/svnroot/jbox2d or with the command "svn co https://jbox2d.svn.sourceforge.net/svnroot/jbox2d jbox2d")
ewjordan wrote:
BTW, version 2.0 is running now, and though it's not completely debugged or optimized and the testbed is in an unfinished state, the API is now in line with Box2d 2.0 and shouldn't change much, so any bleeding-edgers can grab the code from SVN (head to http://www.sf.net/projects/jbox2d to find the repo information). The executable file is TestbedMain.java, and there's only one working test now, but it's probably safe to start coding with if you're not afraid to update the engine out from under your own code later - just don't base anything on the org.jbox2d.testbed or org.jbox2d.util packages, those are going to change a lot!


Excellent, I played with 1.4.3 a bit but decided to wait for this. I'll be experimenting and such, mostly looking for a game to write using physics 🙂

Thanks for the work!

Bill
ewjordan wrote:
BTW, version 2.0 is running now, and though it's not completely debugged or optimized and the testbed is in an unfinished state, the API is now in line with Box2d 2.0 and shouldn't change much, so any bleeding-edgers can grab the code from SVN (head to http://www.sf.net/projects/jbox2d to find the repo information). The executable file is TestbedMain.java, and there's only one working test now, but it's probably safe to start coding with if you're not afraid to update the engine out from under your own code later - just don't base anything on the org.jbox2d.testbed or org.jbox2d.util packages, those are going to change a lot!

(Edit: the SVN repository can be anonymously checked out from https://jbox2d.svn.sourceforge.net/svnroot/jbox2d or with the command "svn co https://jbox2d.svn.sourceforge.net/svnroot/jbox2d jbox2d")


I'm having trouble accessing the files. When I click on the link the directory shows, but when I use Eclipse (using the Subclipse plug-in) it cannot find the host. Could you create the zip file for downloading?

Thanks for your time
Jeff
I see the dependency on javax.vecmath now... complete with the GPL v2.0 license?

edit: I see it's really just Color3f from that package, for some debug drawing stuff.

Bill
Re: SVN trouble, sorry about that, I'm not sure what's going on there, Sourceforge acts up sometimes for no apparent reason. I can't get at the files right now, but tomorrow during the day I'll get a .zip file up.

The Color3f thing was just sort of a random choice, I don't need any of the methods or anything like that, I just needed some sort of a color holder class. I didn't even realize it was GPL, I assumed at most it was LGPL and could be linked without any sort of license issues - honestly, it's a bit of a pain to deal with anyways for various reasons, so I'll swap that out and just use my own color holder.

Also, bug reports will be gladly accepted from any and all - just post problems to this thread. I've already found a couple, and I'm currently hunting a couple more (I know that CCD fails sometimes in CCDTest, much worse than in the C++ version, so no need to report that, I'm working on it), but it always helps to have more people using the thing.
ewjordan wrote:
The Color3f thing was just sort of a random choice, I don't need any of the methods or anything like that, I just needed some sort of a color holder class. I didn't even realize it was GPL, I assumed at most it was LGPL and could be linked without any sort of license issues - honestly, it's a bit of a pain to deal with anyways for various reasons, so I'll swap that out and just use my own color holder.


I would have thought the same (LGPL or GPL 3 Classpath version)... as it is the GPL would have made it a mess to figure out how it works with the other libraries I use 🙂

Bill
Ok, there's a zip up at http://jbox2d.svn.sourceforge.net/svnro ... 7-2008.zip - hopefully that will work even if you can't access the repo through Subclipse. If not, let me know, I can upload somewhere else.

CCD should be working correctly now, btw, I found the bug that was messing it up.

[edit: changed .zip file name]
Just wanted to throw up a link to a JBox2d 2.0 testbed applet for you guys to check out: http://www.jbox2d.org/v2demos/

This testbed now runs all the examples in a single applet (switch using left/right arrows) and adds a bomb slingshot (shift + drag).

Anyone that has the time to respond, I'm interested in a few things:

1) Does the applet successfully load + run on your machine? If not, what is your setup (browser, Java version, OS)?
2) If you reload the page, does the applet still run?
3) What kind of frame rates are you getting on the stress tests? (Pyramid, Domino Tower, and Circles)

1) and 2) are important to me in my decision as to whether or not to switch away from an applet based demo to perhaps a Web Start one or something else. I'm trying a new applet loader Javascript trick that's supposed to somewhat ease the pain of applets, but I'm still skeptical...there are so many issues with applets that I'm starting to wonder whether it's even worth trying to deal with them at all.

Anyways, the official release will come as soon as I finish enough examples to properly demonstrate all (or at least most) of the API. Optimizations will come after that. Comments are welcome, as always.

(Edit: If you have a crash, it's probably because of the javax.vecmath library not existing on your computer...oops, I'll fix that dependency ASAP, I promise! On my Mac it's there by default, so I never noticed it myself)

Original thread: https://box2d.org/forum/viewtopic.php?t=36