Use of C++ library in FlashPunk

(Max Herrmann) #1

Dear community,

I’m planning to create a Lunar Lander game in FlashPunk after having successfully launched my adaption of Asteroids.

For an implementation of the autopilot I need to include some functionality of an external C++ library which takes care of the numerical optimization part.

On my search for a solution I’ve stepped across the (deferred) Crossbridge project of Adobe which allows for writing native C++ code and have it compiled to some Flash format (e.g. *.swf).

As per my understanding, working in this framework would exclude the use of FlashPunk since Crossbridge was exclusively built for the use of AS3.

Is that correct? Is there any workaround? Is there a way of accessing external C++ library functionality within FlashPunk?

Thank you out there!


(Martí Angelats i Ribera) #2

If I remember correctly you could execute routines in Adobe Air (which are precompiled). But they are not supported by web flash player nor smartphones (for security reasons). Other than that i don’t remember being able to import C++ code into AS3.

If they are mathematical util functions, maybe they are already implemented in AS3 and it’s own mathematical library (that’s actually pretty big). If not i think you’ll have to translate it to be sure it works in every device.

PS: I never touched crossbridge.

(Max Herrmann) #3

Thank you for your contribution @Copying! Really helps in getting a grip on the problem.

Unfortunately, there’s no blink of a chance that I could possibly translate that optimization piece even in part. It’s just too damn huge and complex.

Set the case I have to abandon FlashPunk for the above given reasons. What are the odds that I could reimplement the code completely in AS3, given it’s a fairly easy game…

(rostok) #4

Long time ago I managed to get LUA interpreter running in AS3. It was done by attaching .swc file which obviously was compiled with Alchemy (previous name of FlasCC). It really doesn’t matter if you are using FlashPunk or some other framework. All you will have to do is somehow access exported objects and functions from your C++ library in SWC and just call them. So I see no reason for abandoning good old FP.

(Martí Angelats i Ribera) #5

What functions are you using? Maybe there is another library out there that does the same in AS3. Or maybe they are simple to make (you only have to make the ones you need; not the entire library).

(rostok) #6

This is good point. I think that getting external C++ library to work with AS3 may be harder than writing something simple from scratch. Yet to be fully honest I do not know the details.

(Jacob Albano) #7

I’ve never used Crossbridge, but from what I can find it apparently runs in both AIR and the Flash Player. There’s no reason you shouldn’t be able to include the generated SWF in a Flashpunk project.

(Max Herrmann) #8

Thanks for sharing your experience @rostok, that sounds really promising! I’ll have to look into that swc topic, maybe that’s the key to bringing those two codes together.

(Max Herrmann) #9

I’m using a full-scale numerical optimization routine. It’s really a very advanced piece of software that can’t be done from scratch. It comprises a lot of customized and fine-tuned mathematics and some good amount of programming expertise. I wouldn’t be able to tell which part of the software could be excluded and how.

The interface is rather easy to work with, though. That’s the reason for this undertaking. :grinning:

(Max Herrmann) #10

Thank you @jacobalbano!

I had absolutely no idea that it’s possible to use a built *.swf-file in the FlashPunk code. Really? I mean, can I access an external function if I include such a file in my project (currently working with FDT)?

Groundbreaking news.

(Martí Angelats i Ribera) #11

We still not know what library it is. That’s a pretty necessary information IMHO.

(Jacob Albano) #12

It’s really simple, actually. I can’t say what the process is in FDT, but in Flashdevelop all you to is put the SWF in your project folder (I put mine in a subfolder called “lib”), then right-click on it from within your IDE and choose “Add to library”. It adds the packages and classes to your classpath and you can import and use them just as though you were using normal source files.

(Jacob Albano) #13

Not really. :stuck_out_tongue_winking_eye:

(Max Herrmann) #14

Damn right @Copying. The library is called ACADO. And thanks for the hands-on guideline, @jacobalbano! I’ll build a minimum example as soon as my workload let’s me…