Alchemy , AS3 and Box2d?

Hey guys.

Feel free to shoot me down here.

I have noticed that Mayo and Boris have been hard at work recently.

I am wondering about Alchemy.

"With Alchemy, it is easy bridge between C/C++ and ActionScript 3.0 to expand the capabilities of applications on the Flash Platform, while ensuring that the generated SWCs and SWFs cannot bypass existing Flash Player security protections."

Does this not mean that it would be easier to use Alchemy to make a port so that it is available as a SWC for AS3 development?

Since Erins code is either C or C++ and since the point in Alchemy seems to be able to make it available "easily" to flash, is this not a better option? Apart from freeing boris up and turning him into 24/7 support instead lol... Alchemy code appears to execute faster inside the runtime over native AS3?

I am not in any way comfortable about this conversation. C which i dont understand, box2d which i barely understand and alchemy which i have never hardly heard off. However, other than that i seem to think if theres any use for it, box2d would be perfect?

Anyways its worth asking!

Cheers,

Clark.
BorisTheBrave is working on a flash native port of the Box2D c++ source. He has stated his reasons are both personal and functional. It is something he wants to do, and if the source is in flash it is easy to extend and modify for the end user.

Mayobutter is creating an flash port of Erin's work using Alchemy. It does appear to be faster than the un-optomized native port and from all accounts is mostly up to date with the c++ source. As of right now it is fairly heavily integrated into his World Construction Kit(WCK) and may not be as easy to modify. (Your mileage may vary with this as I am going on forum chatter for that one.)

I'm not shooting you down, or not attempting to. Just pointing it out.
I wanted to get out 2.1 and compare, as every time I do a benchmark, I later notice some horrendous performance problem. Erin is making this difficult by keeping on adding features before releasing (odd thing to complain about, I know). It's hard to sink time into a project, and then just give it up, particularly when there are nagging doubts in the benefit. I think the only tangible problem I have is the use two different Point classes in Alchemy.

The difference in porting ease is considerable, and is probably a bigger asset than the speed, which I don't see as vastly different. Had I had the time of porting to spend on other things, there would be many extra features etc. But, ironically, I would have run up into the shortcomings of Alchemy ports quicker too, as I'd be obliged to write much of it in C++, which is a comparative pain in the ass. Even ignoring garbage collection issues, Box2D's C++ style has no containers, and no way to return destroyable polymorphic objects (i.e. no smart pointers). I'd still be interested in writing for the main C++ version, but that's not happening. So when I say "easy to extend", I largely mean for myself.

So I'm not very sure what the position is, either. I've offered to host the Alchemy port alongside the AS3 one, which would probably have lead to a switch, but iirc mayo wasn't interested. He's been very good in that his port isn't tied very heavily to the rest of his engine, but this fact is mentioned rather quietly. It ain't at all documented, which is more why people haven't done much extracting.

I am interested in hearing from the community on this.
I personally think I would prefer the native as3 version.
although I haven't tried 2.1 in either form yet.

however if switching to the alchemy port means more features from you, it may be worth while. xWeld comes to mind.

Would the users of the Alchemy port need to understand the steps to republish the Alchemy swc?
Would boristhebrave come out with a controller grab pack in c++ that we would have to integrate our selves?

i think with it being a swc it would compile a bit faster.
i also think it may be harder to get started, and scare off some users.
I think both ports have their uses.

The work you (Boris) have done is outstanding - Way beyond the level of effort anyone could expect.
But it sounds like its impossible (given time-constraints) of keeping up with the official C++ version (and especially to do so fully optimized?).

Alchemy obviously makes this process a lot faster, while ensuring great compatibility with the C++ version? The downside to that of course being its difficult to hack (especially if only versed in AS3) - but not impossible.

The alchemy port shouldn't be feared by anyone new to flash Box2D. When I first heard about it I stayed well away because I don't know C++, and I assumed to create anything in alchemy you had to know C++ - This isn't the case.
I would imagine the majority of users of flash Box2D don't have any need to change the core of the engine - and everything else is AS3, so there's very little difference.
Hmm yeah i agree!

It was actually feeling bad for boris that was partly the reason i posted this. Given his knowledge of the AS3 port, its pretty safe to say that theres very few people out there who could trump him on his knowledge. Boris could probably start a blog and be the authority on AS3 physics development! No mean feat if you ask me. To get him off porting and spending his time with what is available to him would likely open impressive technical demos of the flash runtime.

I also feel that choosing between Alchemy and Native wont do anything to the popularity of Box2d. Having a choice of project between a stable 2.1 quickly and a native 2.1 in time wont make any difference to 90% of Flash Developers. What does make a big difference is the lack of documentation and a lack of knowing where to begin. I have recommeneded box2d in the past on forums and people often reply the same way "i dont know how to use it" "i dont know where to begin" "i tried to follow a tutorial on google and it didnt work" and so on.

The solution to this is documentation and this is also why i posted the thread. If a 2.1 alchemy port was released shortly after erins, i could jump into that port and within a few months, i could start to write some documentation. Documentation which would be relevant to the native release (if indeed the native release continues).

If we can run an alchemy version to match erins, then it just seems much simpler. Instead of reading constantly how to set up the engine, we could spend time actually exploring it.

Bare in mind that you guys aside, keith peters books on Actionscript 3 animation is really the pinicle of manual physics based work available to your standard flash developer. Taking even box2d 2.0 opens up so many new avenues that extending the engine will not be required 99% of the time.
I developed the alchemy port because I got impatient waiting for new features to trickle down to AS3 and was unsatisfied with the speed of the native port. It usually only takes me an hour or so to get the Alchemy port up to date when Erin makes a commit. I have no problem with some friendly competition though. In fact, I would be very happy if the native port eventually ended up being faster.

WCK and the Alchemy port are hosted together, but the Alchemy port can be used alone. Most of the interest in it so far has actually been in using it this way. I'll try to make this clearer or separate the two projects somehow. The API is pretty much the same as the native port though. There are also some bonus features - Native AS3 Events, run time polygon decomposition, conveyor belt contacts, etc.

Some parts of the Alchemy port are a bit awkward:

1. V2 vs b2Vec2: V2 is for doing fast vector calculations in AS3 without invoking Alchemy. b2Vec2 is for reading from / writing to Alchemy.

2. Many classes, such as b2BodyDef, have to be explicitly destroyed. If not destroyed, the AS3 instance will be garbage collected, but the C++ instance will still be in memory. This can be avoided be always using the same definition instances globally, such as the ones provided by the b2Def class.

3. You have to set "reportBeginContact", etc. on fixtures if you want their contact events dispatched. This is because reporting contacts from C++ to AS3 has some overhead.

These issues may confuse new users / switchers. I welcome suggestions on better implementations. There are also some dangling "not implemented" functions that I don't use or think anyone else really uses. They should be easy to implement should anyone need them though.
Hmm, ok interesting.

sketchbookgames: Controllers is totally ported to C++. When Erin was still accepting feature patches, I was always porting to C++ or starting from there. My day job is C++, so I'm equally competent there, it's just not what I'm particularly keen to do afterwards. It's not up to date any more, as it was kicked to Contrib, where it's never worked. Mayobutter has mentioned that he's working on controllers, which I think means getting that back up to date in C++.

itr77: Yes, starting to accept this. It's showing itself as increasing amounts of bugs from hasty porting. But who cares about compatibility with the C++ version. It's not like many people switch between them, and if so, they can probably handle differences between them due to language differences. Piggy backing in C++ documentation is what has made the situation such a mess, particularly as the docs are not great in the first place. That's why I've started a clean sheet at http://box2dflash.boristhebrave.com, I wanted docs of our own, and semi official looking.

clark: Much of the above applies. I'm aware that Box2D could be more sucessful even with less features, had it better polish. I don't mind doing that stuff, but (like porting) it's unexciting, so even if I had the time, I might well do little on that front. It seems a good thing to open to the community, but the wiki was pretty much terrible, so yeah...
But part of that polish is having a nice AS3 syntax, which I'm very slowly moving towards. Alchemy is a step in the wrong direction there, and slightly harder to fix.

Mayo: Good of you to weigh in. Lemme just post what I was writing, then I'll read and respond to you.
I also don't mind the competition. The existence of your alchemy port (which you really need name, btw), has driven me to care a bit about speed. It was not a priority to me, but users obviously care.
But the competition is not great for everyone except us, as people have stated. I'm wasting my time, and simultaneously confusing documentation and users. You are not really wasting your time, but you're still suffering because of me.

But still, I'm not sure I like the idea of hacking on Alchemy. Take controllers. They were a breeze in AS3. A bit worse in C++, as I was obliged to use the definition-factory method of allocation. Now I want to add another feature to controllers - you specify an iterator of bodies for them, instead of a manual list. There are 4 iterators initially available - manual, all, inside an AABB, and touching a sensor. It's mainly completed in AS3, and quickly, but I would be hard pushed to write it at all in C++ without introducing some of the higher level features of the language. I could keep that all in the AS3 layer, but you've repeatedly said that it's bad to go frequently between the layers, which that would be doing a lot.

BTW, amongst the things on my todolist, there is making BodyDef and FixtureDef optional. That probably goes double for Alchemy, if you think think the definitions are a pain. They have really little benefit in AS3.
Oh I don't care how compatible the AS3/alchemy port is with C++, I'll never use the C++ (sorry! 😳), my point was that new and useful features added to the C++ version will be quick and easy to get into our flash version.

Personally I would like to see everyone working on the same core port (my preference at the moment being alchemy, for the reasons outlined already) and adding features to it, regardless of those features being present in/planned for the C++ core.

Of course this would mean losing the native AS3 port which would be a bad thing, as its an amazing piece of work and is very useful in its own right.

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