For those of you who are interested in performance oriented programming in AS3, there’s a pretty good reference of how not to program in AS3.
It’s called jiglib flash.
I’ve been perusing the source code, for general tips on 3D solid body dynamics.
One thing I need to make clear first, is that the AS3 port of jiglib is NOT by the original author of the C++ engine, Danny Chapman, who is obviously a very clever guy.
It’s programmed really, really badly from a performance perspective. Excessive calculations, excessive data access, marshalling, plentiful usage of Objects, function calls, and downright GRATUITOUS levels of class creation at run time.
In fact, the amount of pointless, gratuitous, borderline nihilist levels of class creation makes me feel queasy. Literally every single calculation returns a new class where possible. Whoever ported it must be pretty disappointed that a dot product is simply a number, as that’s about the only function that doesn’t return a new class.
Obviously from a performance and ram perspective, this is awful.
The only thing I can think of is that the guy is from a C++ background, and doesn’t really know how to program in AS3.
But even so, it seems bizarre and a bit lazy, to go to the effort of porting a pretty complex C++ library to AS3, and not even do some basic benchmarks first, which would quickly reveal that many of the methods in broad use are painfully slow.
The engine is literally pushed to the limits with only 10 boxes stacked on top of each other, it runs at 20fps.
When my 3D solid body physics engine is ready, I think I’ll be able to get around 100 stacked boxes running at 60fps.
So anyway, have a look at the source code, and if you want your code to run fast, pretty much do the exact opposite of everything that’s being done there
Cheers,
RumbleSushi.