Box2D Java

Great! Will check it out soon. One crucial thing: I started the port of the Box2D 1.0.0 version, then 1.1.0 and 1.2.0 where released, but since I had half of 1.0.0 going on, I kept porting that version so I didn't mix them up. Which version you started porting? Also, since Erin moved folders on the SVN repository, it's a bit difficult to find the diff between the files
Ah, good to know. I started right when 1.2.0 was released, so I've been doing that one. I looked around, it seems like if you go into SVN Browse for Box2d you can actually trace what happened to each file without too much trouble.

Honestly, given that Erin has already figured out the algorithmic changes needed to go from 1.0.0->1.2.0, if we can get any combination of the two working it should be pretty easy to bump it up and bring it in line with the newest version.
Okay, we're pretty close now - I've been through most of the code, figuring out where we differ and stuff. I finally got HelloWorld (the Box2d version) to successfully compile and run by making a whole bunch of edits. Unfortunately I mangled my Eclipse project in the process of getting it to run, so I need to fix that before I can safely commit the changes, but hopefully tomorrow at some point I'll have it set - I'm not sure whether the results are correct, I'll have to compare with the C++ version.

The main problem at the moment with the Java code (not a criticism, btw, this is just as much of a problem in my code) is that a lot of variables are not initialized when the classes are constructed. I changed what I found, but I'm sure I didn't catch all of them (you don't need a lot of the classes/functions to get HelloWorld to run), so keep that on your mind. Every time a NullPointerException showed up, that's what was causing it, usually via an uninitialized array or something like that (it's the easiest thing to miss, because even if you init the array, you still have to loop through it and initialize each member, too). But I like the approach of solving these as they cause problems, not before - some objects are always initialized anyways before they are used, and it would be wasted time to do it in the constructor if we're just going to do it again later. The other main change was visibility - default visibility doesn't work in a lot of places, so I've been bumping fields/methods to public whenever it seems reasonable. Pretty much everything that started out as a struct should be public, anyways, as it's technically part of the public API for Box2d, and we probably want to stay pretty close to that (if only to sponge off of Erin's reference materials as well as the codebase 🙂 ).

A specific problem I'm having: there's a std::sort() call in b2Broadphase that's confusing the heck out of me - it's sorting an array of b2Pair objects in the Validate() function, but I can't for the life of me figure out from the C++ what comparison function it is using, as I don't think there's any default > operator for structs, and the struct doesn't define its own. The Java version would be easy enough to get right if I knew what to sort by - Erin, any chance you could explain what's going on there? Maybe I'm just missing something...

Keep an eye out, I'll commit the HelloWorld stuff ASAP, then try moving on to one of the TestBed examples to see how close things really are to working. quixote_arg, your code is close enough to complete that I definitely think it's best to start from there; mine would take a lot more time to get to the point where it could actually run, though it might be useful to refer to if there are problems. The bump up to 1.2.0 can wait until we've got a working demo.
yes, I've noticed that most of the structs just access to variables, we need to do a new. In some classes I added a constructor and replaced the code to start working, but later on switched to mode "make it work first"

With the b2Pair, there is a > operator definition somewhere, don't remember if it's in the .h or the .cpp; the java way to go with that would be to declare that the class implements Comparable, add the compareTo method and then just use Collections.sort... but that's AFTER we got all the demos working, I think!
The validatation code is sorting b2BufferedPair, which has the < operator defined in b2BroadPhase.cpp.

I'm just trying to verify that there are no duplicate pairs.
Okay, HelloWorld and assorted edits are in SVN now. My project is still mush (apparently Eclipse _really_ doesn't like having both a collision and a Collision package in the same project, so much so that it won't let me delete or rename either of them!), but I was at least able to commit the changes. Next I'll try one of the real demos, get it compiling, and link up a simple graphics display.

Yup, I noticed the BufferedPair < operator right after I posted my question. If it's something we can wait to implement, that sounds good to me. I already implemented the interface, but unfortunately Collections.sort() requires a List<>, not an array, so it will still take some rearranging. But if it's just debugging code (which I'd have realized it was if I'd read the code more carefully instead of just bug hunting) it's not too important now.
Everything compiles! iuuuju! 😀

Ok, done some minor changes:

- implements Comparable<type> to avoid typecasting in Pair and BufferedPair
- added Collections.sort to BroadPhase

Ok, so the make it compile section is over, milestone behind!

Now we must make the testbed work... be reading you
Just an update (quixote_arg already knows what's going on here, but just to keep any interested lurkers in the loop):

We're almost there on this. We now have most of the physics working correctly, and finally got to see it actually run last night. The joints and time stepping are working correctly, but we're still tracking down a fairly difficult bug in the broadphase that's keeping collision detection from functioning (something's going wrong with stabbing counts). Once that is resolved, we're in the last leg of this thing.

It should be just a few days or so until this stuff is done, at which point it will be a few more days to take in all the changes made to Box2D since the start of the port (we've still got mostly 1.0.0 code in there right now). After that we're going to begin optimizing and refactoring for Java, which may be a slightly more drawn out process. So if you're interested in using this code, I'd guess it will be ready for serious testing in a week or two, and it would be great to have a lot of people hitting it pretty hard so we can track down the bugs.
Just curious... anyone interested in this port please say hi!
Hi! 😎

Messing around with c++ is proving to be quite fun (after all this time), but I'm still a Java convert.

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