Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Allegro headers part II

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
Allegro headers part II
Matěj Týč
Member #9,863
June 2008
avatar

Hello again, I would like to reopen discussion regarding Allegro interface (that is, headers)
AFAIK, hiding implementaion is a very smart practice for every library, not only multiplatform ones.
The current state of this in Allegro is not very nice: If you compile your code that uses Allegro, you have to tell Allegro which platform you use at that moment.
Although Allegro "does this for you", it is quite obscure.
If you take a look at allegro/internal/alconfig.h

 #if defined ALLEGRO_DJGPP
      #include "allegro/platform/aldjgpp.h"
 #if defined ...
      #include ...
//and so on...

Normally, you should pass -DALLEGRO_UNIX as CFLAGS on Unixes (includes Linux). You don't have to do that since the hand-written makefile adds a line containing this #define to allegro/platform/alplatf.h. You can imagine the cost of understanding and maintaining a build setup that has to perform such tricks.

When I have asked about this earlier, I received the following answer:

Thomas Fjellstrom said:

Allegro has to use platform specific code in order to work on the different platforms. In some cases you can also include special headers to gain access to platform specific allegro functions which make it easier to get at platform stuff like win32 window handles and such. The main allegro API is platform independent, if you only use Allegro and language functions (and other platform independent libs).

There is nothing wrong with it, but IMHO the multiplatform part of Allegro should be somehow separated from platform dependent part. I suggest not including those files by default and/or to force users to specify the appropriate CFLAGS manually if they need them. I don't think that many users use this. Then everybody would know whether it is easy or not to port his/her program to other platforms.
What are your opinions on this?

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

X-G
Member #856
December 2000
avatar

... why are you proposing changes to a codebase that is never going to change? (All active developmnent is in 4.9. Comment on that instead.)

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Matěj Týč
Member #9,863
June 2008
avatar

I have took a look on 4.9 in SVN and it seems to be pretty much the same. This affects allegro5 as well...

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

SiegeLord
Member #7,827
October 2006
avatar

Quote:

Then everybody would know whether it is easy or not to port his/her program to other platforms.

If you use Allegro's standard API, it will be easy to port to other platforms. If you use the platform specific API that is obtained only if you include those platform specific headers, then it will be hard to port to other platforms. I don't see where the confusion is.

You do realize that Allegro is multi-platform by the very virtue of it having equivalent implementations for its API for every platform? There will always be a need to include platform specific code. As long as you don't override that process via including headers on your own, though, your program will remain cross platform because Allegro will automagically determine which platform specific headers to include on any given platform. Why do you wish for this to be the responsibility of the user?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Matěj Týč
Member #9,863
June 2008
avatar

Quote:

If you use the platform specific API that is obtained only if you include those platform specific headers, then it will be hard to port to other platforms.

I think that they are included regardless if you want it or not... Am I wrong?

Quote:

There will always be a need to include platform specific code...

I don't agree if you mean that the user of Allegro has to include platform specific code in her/his programs. Otherwise there would be no way that that program would be multiplatform, don't you think?

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

LennyLen
Member #5,313
December 2004
avatar

Quote:

I don't agree if you mean that the user of Allegro has to include platform specific code in her/his programs. Otherwise there would be no way that that program would be multiplatform, don't you think?

He meant that Allegro's code will always have to have platform-specific code.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

I think that they are included regardless if you want it or not... Am I wrong?

You are not wrong, but you are missing the point nonetheless. Allegro has to include platform specific code, or it will not function.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Matěj Týč
Member #9,863
June 2008
avatar

Hm, I was not concerned about internal Allegro structure, but rather about library interface for users.

I sum my ideas in this list:
1. Allegro user interface includes platform specific headers by default.
2. Point 1 implies that user can write platform-specific code without being clearly aware of that... [EDIT: This is not really true :) ]
3. The current situation is obscure, there are many #defines all over the place + you have to generate allegro/platform/alplatf.h

What do you think?

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

SiegeLord
Member #7,827
October 2006
avatar

I don't believe points 1 and 2 are true for the 4.9 branch any longer.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Mokkan
Member #4,355
February 2004
avatar

The library interface for users is fine.

Matěj Týč
Member #9,863
June 2008
avatar

Quote:

I don't believe points 1 and 2 are true for the 4.9 branch any longer.

I think that if you take a look to allegro5/internal/alconfig.h, you may change your opinion.

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

SiegeLord
Member #7,827
October 2006
avatar

I didn't need to. I tried to put some platform specific code into my program, and it failed to compile. That's good enough for me.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Evert
Member #794
November 2000
avatar

Quote:

and/or to force users to specify the appropriate CFLAGS manually if they need them.

No.

Quote:

I don't think that many users use this. Then everybody would know whether it is easy or not to port his/her program to other platforms.

Stick to Allegro's platform independent API (ie, things not marked as "platform specific") and standard C library functions (of your favourite standard) and you're good. It's not more complicated than that.

Quote:

1. Allegro user interface includes platform specific headers by default.

That's because Allegro on platform X needs to know things about platform X, which means you may need some information stored in Allegro structures. For instance, a BITMAP struct on Windows may need to have a DirectX handle (or something equivalent), which doesn't exist or make sense in Linux (where you might have an X11 handle) or OS X. This is completely opaque to the user, however.

Quote:

2. Point 1 implies that user can write platform-specific code without being clearly aware of that...

How?

Quote:

What do you think?

If it ain't broken, don't fix it.

Thomas Fjellstrom
Member #476
June 2000
avatar

And since you have to recompile your program just to get a binary that will work on a given platform, there is no issue. You have to recompile anyway.

As Evert said, so long as you stick to language standard functions, and allegro's non platform specific functions, you'll be fine, and your program can be compiled and run on any platform it happens to directly support.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Peter Wang
Member #23
April 2000

Matěj, if you want to help, please help us on the 4.9 branch. As X-G said, 4.2 development is closed. 4.3 development is mostly closed as well, but we are accepting code for new ports. 4.9 is what you should help with.

I agree that we shouldn't include platform-specific headers into user programs by default. This may not be possible in all cases, but it's something we should strive for. But breaking 4.2/4.3 now is just not on. Work on the 4.9 branch.

Evert
Member #794
November 2000
avatar

In addition to what Peter said, please contribute patches for 4.9 rather than point out what should be changed and how. :)
(I know you're willing to provide them, just making sure).

Matěj Týč
Member #9,863
June 2008
avatar

Actually I took a closer look and I can say that there is almost no platform dependent code in files that get included by default (files allegro5/platform/al*.h) There are rather some #defines that I don't quite understand. Is it really neccessary in Allegro5?

I haven't found any DX handle in BITMAP in those headers, is it possible?

However the file allegro5/internal/alconfig.h is ugly and things like

#if (defined ALLEGRO_DOS) || (defined ALLEGRO_WINDOWS)
   #define OTHER_PATH_SEPARATOR  '\\'
   #define DEVICE_SEPARATOR      ':'

should disappear and should be stored in the library itself (like char OTHER_PATH_SEPARATOR). This would even preserve compatibility.

I have thus found out that point 2 is invalid. Point 1 and 3 are undesirable and should be fixed if possible.

Quote:

In addition to what Peter said, please contribute patches for 4.9 rather than point out what should be changed and how

I would like to know whether you would be interested in such patches first. And then, I would like to know your opinions regarding how things could be fixed. And why they look like the way they look like ;)

Regarding 4.9 vs 4.2: Things regarding build are extremely similar for 4.9 and 4.2. Since we use SVN, it make sense to fix everything with little bit bigger effort than to concentrate exclusively on 4.9...

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

it make sense to fix everything with little bit bigger effort than to concentrate exclusively on 4.9...

Not if theres never going to be another release based on 4.2 it doesn't. And we have very limited resources, getting 5 finished up is taking what little time we all have.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Milan Mimica
Member #3,877
September 2003
avatar

Quote:

Things regarding build are extremely similar for 4.9 and 4.2

Except that the we're using a completely different build system, yeah...

Quote:

should disappear and should be stored in the library itself

4.9 must not export any global vars.

Matěj Týč
Member #9,863
June 2008
avatar

Quote:

4.9 must not export any global vars.

How come? Now Allegro #defines macros... And 'screen' is not a global var? ;)
When I think about it, following thoughts how this can be solved in another way come to my mind:
1. Export constants (constants are not variables, right? :-)
2. Make library functions that return those platform specific data.
3. Make allegro_init to return some structure that would contain all the data
4. Generate ONE header during (or just before) compilation that has the same name on all platforms (this would at least kill those #ifdef somesystem #include somefile things)

I just have to solve a minor difficulty with modules under Unix and then I will be able to send a patch that brings that new level of autotools experience to 4.2

Then it can be svn copied to another branches where it will require only small modifications in order to work well.

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

SiegeLord
Member #7,827
October 2006
avatar

I think you should look at the A5 API before making any further suggestions. Your comment about the 'screen' variable, as well as the allegro_init data structure suggestions show that you are ignorant of the fundamental differences between A5 and A4 in terms of their internal structure and operation.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

LennyLen
Member #5,313
December 2004
avatar

Quote:

I just have to solve a minor difficulty with modules under Unix and then I will be able to send a patch that brings that new level of autotools experience to 4.2

How many times do you have to be told before it gets through to you? Allegro 4.2 isn't going to change. Look at future versions.

Evert
Member #794
November 2000
avatar

Quote:

Things regarding build are extremely similar for 4.9 and 4.2. Since we use SVN, it make sense to fix everything with little bit bigger effort than to concentrate exclusively on 4.9...

Not really. 4.9 and 4.2 are very different. A change in 4,2 can not be directly applied to 4.9 at the moment.

Quote:

How come? Now Allegro #defines macros...

Macro's can be #undef'ined.

Quote:

And 'screen' is not a global var? ;)

What "screen"? There is no "screen" in Allegro 5 - and if there were, you'd have to get a pointer to it with al_get_screen().

Matěj Týč
Member #9,863
June 2008
avatar

Quote:

Not really. 4.9 and 4.2 are very different..

Are we still discussing the point of build setup fans? For instance, I have noticed that Allegro5 even uses modules...
I mean, this can't be sooo different, you always end up generating a header, checking for stuff and finally doing some compiling/linking and docs generation...

And when I took a look on CMakeLists.txt, I just wonder who said that autotools are arcane and ugly etc. ;)

Regarding the current header situation, don't you consider making some brainstorming on how to improve it? I think that it is clear that it can and should be improved and the question is how to do that in the smartest way. You guys know Allegro5 better than me and maybe I am more inspired by 'standards' and simplicity; and it would be great if these two qualities could somehow work together for the benefit of Allegro and its users. There are more things to improve, so we can make some sort of 10 minutes "IRC brainstorming" among people that feel interested in this. I can post the results to the wiki afterwards so that everybody will be able make suggestions or learn on how things are...

---------------------------------------------------
Mind is like space, it is open, clear and unlimited. -- Ole Nydahl

Thomas Fjellstrom
Member #476
June 2000
avatar

Allegro 5's internal structure does have documentation on the wiki. While not complete, it should help

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

 1   2   3 


Go to: