dallegro 2.0 beta 4 released

Anders F Björklund afb at algonet.se
Tue Mar 13 15:50:13 PDT 2007


torhu wrote:

> dallegro 2.0 is a new set of D bindings for Allegro.  It's primarily 
> tested on Windows, but is reported to work on linux.  It's also likely 
> to work on MacOS X, although untested so far.

It mostly works, if you set the extra "version(MacOSX)" and
tell the Makefile about gdmd and the allegro-config --libs.

(You might want to do a "version(darwin) version=MacOSX;" and
you might want to use the allegro-config output by default ?)

However, you get link errors (= no "__mangled_main_address")
since it is missing the END_OF_MAIN macro that C/C++ uses...


This is the same situation that standard SDL on Mac OS X has,
with the library written in Objective-C and needing some init.
So they #define the usual main over to something else, and then
provide a library with "main" and a callback to your usual main.

For SDL it is "SDL_main", and for Allegro it is "_mangled_main".
It's expecting a C/C++ main, i.e. extern(C), and not the D main.
You can see my SDL wrappers for a workaround, where the D main
simply calls a patched mainlib and then handles the C callback.

i.e. the "main" from the Objective-C runtime library is renamed
to "D_main", and then the D main routine calls this after setup.
Then, when Objective-C is done with the setup for SDL/Allegro,
it will call the SDL_main/_mangled_main with a new argc/argv.


Where the Windows/Linux versions simple wrap the D args up as C,
do the "C" callback, and then wrap the C args back into D again:

int main(char[][] args)
{
     return sdl.main.SDL_InitApplication(args);
}

extern(C)
int SDL_main(int argc, char **argv) // _mangled_main for Allegro
{
     char[][] args = sdl.main.SDL_ApplicationArgs(argc, argv);

     // regular D program goes here

     return 0;
}

This gives the D wrapper of the C library a chance to intercept,
and initialize the Objective-C runtime if needed (i.e Mac OS X)


A similar workaround should work for using Allegro from D as well ?
But you do need to patch Allegro, and to modify the D programs...

The Allegro file is src/macosx/main.m, library is liballeg-main.a
(this would be the "Objective-C runtime" library mentioned above)


> All Allegro's examples, the demo game, plus the tools and tests that
> are ported to dallegro, seem to run without a hitch.  Performance is
> on par with the C version.  The platform-independent parts of the API
> are completed, so are Windows, linux and OS X specifics.  So as far
> as I'm concerned, dallegro is ready for some real game programming!

Good Work!

As a closing remark, you might want to offer an allegro.allegro
module (just a new name), in addition to the allegro.all module ?

i.e. just make it "public import" the other one, for flexibility...
http://www.prowiki.org/wiki4d/wiki.cgi?BestPractices#ConventionalModuleNameforImportingAllModulesinaPackage

--anders


PS. Might post a more complete Mac dallegro how-to/patch, later on.
     But it shouldn't be any harder to use Allegro than to use SDL ?



More information about the Digitalmars-d-announce mailing list