Monday, July 19, 2010

Physics library updates

For my lunar-lander-on-a-disc program I need some intersection-testing functions that were added to the Chipmunk Physics library I'm roughly based on. Since I translated the library from C99 to C++, though, I would need to translate the new code as well. This is a maintenance pain, so this weekend I spent some time trying unsuccessfully to get the stock library into a state in which I could use it.

I like Chipmunk; it's very understandably written and sensibly designed. I'm sure its author Scott Lembcke is reading this. (Hi Scott!) The key problem seems to be that the library is written in C99, a newer dialect of C which is poorly supported by Microsoft's C compiler. Since C99 moves C toward C++ I can get by with relatively small modifications if I compile the C code as if it were C++. Still, since the main library development isn't using my compiler I can expect to have to do this regularly.

As a result I've been examining Box2D some more. It builds easily out of the box, and it's written in C++ so it should mesh better with my project. It has a different approach to collision shapes; I'd need to break down the rocket hull into a set of convex shapes, but that wouldn't be hard. The terrain might be a bit more work. Box2D doesn't support line segments as a collision primitive (although there is contributed code to do so), so I'd probably take the triangulation and merge triangles into polygons up to the 8-vertex limit.

I've got various directions I can go and it's hard to decide how much work I should spend on this. I could patch up my library and continue working on gameplay; that might be the most prudent. Ultimately I want to produce a Flash version of the game, and I think Box2D might give me some help there.

4 comments:

Unknown said...

Well, Chipmunk is mostly supposed to compile as C++ code under MSVC. I say "mostly" because I'm only going on feedback from MSVC users occasionally about what needs to change. I know there are only a few issues at the moment, but I don't have MSVC to try or fix it with. http://www.slembcke.net/forums/viewtopic.php?f=1&t=1084

The frustrating part is that most of the people that try to help I only ever hear from once. They upload a modified source archive and it's often very difficult to get further information out of them when the diff tool explodes on their changes. What I really need is somebody who would be willing to send me an svn diff from trunk of their changes. (or somebody that I can give svn commit access to)

I know a number of people would appreciate an up to date C++ binding as well. The Obj-C binding is under 1.5kloc of highly templated code, a lot of which is memory management related. A large part of writting Chipmunk in C was to make it easier to bind and use from other languages.

I'd completely understand if you were more interested in finishing a game than dinking around with engines though. ;)

James McNeill said...

Hi Scott,

Thanks for the reply. I think I could get an SVN diff put together. I got really close to getting Chipmunk building with VC10; I was down to link errors, which were stumping me. dumpbin didn't seem to be working on the .obj files so I wasn't sure what symbol names were actually getting exported. I think I may drop back to VC9 since that's what I have been using, and just knock out the FFI macros in that build.

I should probably learn CMake; Box2D uses it to generate the project files and I see you have CMake files as well. The .vcproj files are annoying to maintain since they tend to change radically from version to version of MSVC (VC10's are in an entirely new syntax from VC9, for instance).

I'll give it some more effort; it'd be great to have it working under both VC9 and VC10.

Unknown said...

Oh? That sounds a bit annoying. I guess XCode isn't necessarily better, though it does seem to do a decent job of providing backward compatibility. Not that I'm trying to imply that XCode is an acceptable tool for doing just about anything. :p

I've had to update the CMake files on occasion, but I didn't actually originally create them. They seem pretty easy to work with though. A Linux user contributed them hoping that everybody would use them for all platforms. I'll admit that I've never bothered to try generating an XCode project with it, but only used it to build Chipmunk under Linux.

Unknown said...

I just tried the CMake -> Xcode generator. It actually seems to work just fine (I was highly skeptical). It seems to get all the settings right and there were no weird issues with the project it generated.

The project structure was pretty unnavigable, but I don't really think that is the point of auto-generating a project. ;)