![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
Allegro for D |
torhu
Member #2,727
September 2002
![]() |
In 2004, some guy posted a zip with the files needed to use allegro with the D programming language: The file attachment was gone, so I've uploaded it here: I've also started to do some improvements to his work, still for Allegro 4.0. I'm currently just checking out how to solve certain problem when converting C headers into D, so there's not much new yet. But I thought I'd post to see if there's any interest in this. What's new in v1.1 is mostly that you can actually access allegro's globals directly now. Like screen, font, gfx_driver, mouse_x, etc. Version 1.0 replaces those with function calls like get_screen() and set_font(). I've started work to convert the 4.2.1 headers into D, but if and when that will be finished, I'm not sure yet. I'll organize allegro.d with one section for each C header, so it's easier to update with new allegro releases. You just go through each of the files in the order they are listed in allegro.h, and update allegro.d accordingly. For people not familiar with D: Downloads and installation instructions are here: I can tell you right away that the main weakness of D is probably the poor debugger support. You can use windbg to pinpoint access violations, but I haven't been able to use it for much more than that. Hopefully, that will change. for now it's basically printf debugging and such. If that is not an option for you, stick with C/C++. But for those okay with not having great tools, D will be a relief, whether you compare it to C, or C++. That's what I think, anyway. |
nonnus29
Member #2,606
August 2002
![]() |
D has changed alot over the past couple of years. They added some really nice template syntax and the contracts thing is kinda interesting. Must look into again sometime... Keep us posted about your progress! |
Archon
Member #4,195
January 2004
![]() |
I'm going to try it. Right now, I have to get 4.0 because that's the version that you've wrapped Also, I'm using Linux (in case you were wondering why I don't just use alleg.lib). The source files compile well but it's the linking part that's giving problems. [update] |
Indeterminatus
Member #737
November 2000
![]() |
Great, thanks! I have a bunch of D-related stuff lurking around on my hard-disk, but I never really had the incentive to give it a try in a real application (just a bunch of very small projects playing around with the language's features). I guess it's time to get started. Once there's support for Allegro 4.2 Keep it up! _______________________________ |
torhu
Member #2,727
September 2002
![]() |
I've ported enough of Allegro 4.2.1 to D to be able to actually start allegro and set the gfx mode. Nothing else yet. 9 of 31 headers are more or less done. So far it's been almost too easy. I'll probably get stuck for weeks in some debugging nightmare or something soon. For the most part, C features map nicely to D. Only a couple of things need to be worked around. I'm trying to keep as close to C and the allegro manual as possible. No D-ification of allegro is planned at the moment. If someone wants to write wrappers, my work should make that pretty easy. *** UPDATE *** Here's a beta release, if anyone wants to try it out. It's not completely done yet, but it's pretty close. I've ported 18 of allegro's examples so far, and they work just fine. The only thing that worries me is that expal.d doesn't display the mouse pointer. But the mouse works fine in the other examples. One of the annoyances when using a C lib in with D is that arrays are not quite the same as C's, and that D's IO functions don't support null-terminated strings. But you can just use C IO (import std.c.stdio;), or use toString() to convert. The D language itself has good support for them, however. If you give a char pointer to writefln(), it will actually print the address, instead of the contents. Not very useful. You can also get it wrong the other way around. D's preferred string type is dynamic char arrays (char[]), which are 'fat pointers', or references. Like this: struct CharArray { size_t length; char* data; }; If you give that to a variadic C function, it will print gibberish, since it will 'dereference' the lenght field. Or it might crash your game. You can use the standard D function toStringz() to convert to a C string. Using "%*s" as the format also works. D has an array type (static arrays) that is binary compatible with C arrays. Allegro has globals that are defined like 'char allegro_error[SOME_SIZE];'. Let's say you do this: allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); Since the function is variadic, the compiler won't complain. D does not verify variadic argument types during compilation, since it has it's own, typesafe variadic functions. What happens here seems to be that allegro_error is converted into a dynamic array, since that's the only way to have the length follow the array into the function. Which doesn't help in this case. So D's static (fixed-length) arrays are not equivalent to pointers when used as arguments to variadic functions. The solution is to just add '.ptr' to allegro_error, since in this case we know it's already null-terminated. But I guess we are bound to forget this now and then. Another issue is that functions that expect a static array, do not accept a pointer. Take, for instance 'void set_palette(PALETTE p);', and 'alias RGB[256] PALETTE'. If you load a palette from a datafile, you get a pointer to 256 RGB structs. And if set_palette is defined like that, it won't accept any pointer. So you have to do something like this: PALETTE r = (cast(RGB*)datafile[THE_PALETTE].dat)[0..PAL_SIZE]; Which is pretty ugly. One option is to change set_palette() and similar functions to take an RGB* as their argument. Or to make a function template to do the conversion, preferrable without copying. But ok, let me know how it works out for you. |
juvinious
Member #5,145
October 2004
![]() |
nice to see, this also gives me an excuse to play with D. __________________________________________ |
AngelChild
Member #3,401
April 2003
![]() |
And I ----- |
Archon
Member #4,195
January 2004
![]() |
Cookies goes to Tydr Schnubbis. |
BAF
Member #2,981
December 2002
![]() |
Can we compile D and target it to ARM CPUs? |
Elias
Member #358
May 2000
|
gdc is supposed to target anything gcc can. (The digital mars compiler itself only can target Windows and Linux I think.) -- |
BAF
Member #2,981
December 2002
![]() |
How do you generate one that will target ARM7/9 then? Is there source someplace to compile a toolchain for it? |
Elias
Member #358
May 2000
|
The gdc readme mentions it from what I remember, didn't read too closely though. Or I think it just says something like "If you need a D cross-compiler, do it like with a C++ crosscompiler." Anyway, googling for "gdc arm" seems to turn up some posts. -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I'd assume it'd worlk like normal, compile some D code: gdc -target <platform> -arch <whatever> <etc> -- |
torhu
Member #2,727
September 2002
![]() |
We are having trouble with dallegro on linux. juvinious and I are looking into it. We haven't tried gdc yet, just dmd. Some examples still crash on linux. I don't run linux, so if anyone feels like some debugging, we'd be glad to get some help. *** UPDATE *** It's not crashing anymore! Turns out I had had a small search-and-replace accident, which didn't matter on windows, but caused crashes on linux. Scary. |
Peter Wang
Member #23
April 2000
|
Quote:
Here's a beta release, if anyone wants to try it out. That zip file is broken.
|
torhu
Member #2,727
September 2002
![]() |
Broken how? I just downloaded it, and it was fine. |
Peter Wang
Member #23
April 2000
|
For some reason, I can't unzip it. Here's a transcript:
I can unzip d-allegro-win32-1.1-4.0.zip though.
|
BAF
Member #2,981
December 2002
![]() |
It worked fine for me, however, I recompressed it for you. |
Peter Wang
Member #23
April 2000
|
Thanks. It looks like my download stopped prematurely on three separate occasions (and I don't think it was due to the browser cache either). Sorry about that.
|
torhu
Member #2,727
September 2002
![]() |
http://torhus.googlepages.com/dallegro_20_beta2.zip New test version. A couple of new examples, lots of bug fixes and cleanups. And it includes a build script for linux, that also enables static linking. If you've previously tried this on linux and given up on it, please try again. allegro_error and cpu_vendor are now char pointers, like allegro_id already was. Should make it harder to do the wrong thing when calling variadic C functions. More volatile variables have been wrapped as properties. Not sure how useful this is. **EDIT** Question for you guys: Is DAllegro a good name or not? Anyone got better suggestions? Doesn't matter much, I know. I should probably email the original dallegro guy and ask if he's okay with me stealing his project name. |
Elias
Member #358
May 2000
|
Hm, SDL named their D wrapper "derelict". But I think dallegro is a good name -- |
Peter Wang
Member #23
April 2000
|
I'd like to see D become an officially supported language for Allegro, either by bundling the bindings in the main package or as a separate download. It would be nice to install it with just a "make install-d" command.
|
torhu
Member #2,727
September 2002
![]() |
I've been offered svn hosting at tomasu.org. That seems like a good place to set up shop if dallegro is to become an official part of or maybe just an 'offical add-on' to allegro. If you feel like adding dallegro support to the allegro makefiles, please do. I haven't written a makefile in a few years. Now I've gotten the main test app to run (tests/test.c). I've run a couple of the benchmarks, and performance seems to be on par with the C version. If anyone wants to help out, at the moment I'm mostly interested in feedback about the design of dallegro. What can be done to make using allegro with D smoother, how to help users avoid common pitfalls, etc. How to best maintain portability when D gets ported to other platforms in the future, does dallegro need to support memory locking, etc. |
Peter Wang
Member #23
April 2000
|
Why not the Allegro SourceForge repository?
|
Thomas Fjellstrom
Member #476
June 2000
![]() |
Quote: Why not the Allegro SourceForge repository? Mine has better uptime? -- |
|
1
2
|