Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Before The Fall...

This thread is locked; no one can reply to it. rss feed Print
Before The Fall...
Sean_carter
Member #13,817
December 2011

What a situation we've gotten into! The API has gone downhill so far, so fast in Allegro 5, I'm just not sure what to think. Before The Fall Allegro was so refreshingly elegant, the "Hello, World" program was half a page of gloriously self-explanatory code. But no more. We've gone from iPod to Zune. Porche to Dodge Neon. Coen Brothers to Adam Sandler. The API has become awkward, verbose, and just plain ugly. Is there a new group of people in charge of the API? We need to either put the old guard back in charge, or fork the source code and fix things ourselves.
Now, a tool that can't do the job you need it to because it lacks the capability is useless. But a tool which is too complicated to do the job you need it to within 10 minutes is also useless, because you'll give up and try something else.
There's a certain subtle beauty in a rich, elegant design that the people working on the API right now don't seem to understand or appreciate. They don't seem to grok the fact that there is value in simplicity.
Making a tool that is complete but ugly is easy. Making a tool that is both complete and beautiful is damn hard. But we can do it. We can do better than this.

Can I hear a Hell, Yeah?

taron 
Member #10,584
January 2009
avatar

What? The API seems very clear...

Let's just say, I totally disagree.

23yrold3yrold
Member #1,134
March 2001
avatar

Considering it got LESS complicated, this could have been a much better troll. You'll do better next time.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

jmasterx
Member #11,410
October 2009

Allegro 5 is incredibly easy to use.

AMCerasoli
Member #11,955
May 2010
avatar

They don't seem to grok the fact that there is value in simplicity.

What are you doing here?...

I hope you came here thinking that programming was easy and then you realize that is not. Then you thought: "what the hell let's troll a little bit".

I really hope that you don't think that Allegro isn't simple... Because then...

What are you doing here?...

Sean_carter
Member #13,817
December 2011

Seriously?? Try doing the following in allegro 5, see what an ugly mess it devolves into. You have to mess around with events, primitives, etc etc.

#SelectExpand
1#include <iostream> 2#include <allegro.h> //ONE INCLUDE! 3 4using namespace std; 5 6int main() { 7 allegro_init(); 8 install_keyboard(); 9 10 if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) < 0) { 11 cout << "Unable to set graphic mode!" << endl; 12 return 0; 13 } 14 15 while (true) { 16 if(keypressed()) { 17 unsigned char key; 18 key = readkey() & 0xff; 19 if(key == 'q') { //quit 20 break; 21 } 22 clear_keybuf(); 23 } 24 line(screen, 0, 0, 100, 100, makecol(255, 255, 0)); 25 } 26 27 return 0; 28} 29 30END_OF_MAIN()

taron 
Member #10,584
January 2009
avatar

Yes you need to mess around with events and add-ons.

But what does it matter? It's maybe a bit more code, but it adds so much more flexibility.

Now take a look at the allegro4 api.
'line' it's a function that does not even say what it does.
keypressed and clear_keybuf why is the code style different here?
Why isn't it key_pressed and clear_key_buffer?

If anything, the allegro 5 API is much more clean than the allegro 4 one...

jmasterx
Member #11,410
October 2009

Just you wait until you do a slightly large project. Then you'll appreciate the simplicity and flexibility of events. I hope you don't think less lines of code means easier to use.

I think I'll come out with my own game API, it will be simple and have 3 functions:

void playPacMan();
void playTetris();
void playMinewseeper();

I think you'll like it, you can get 3 games working with only 3 lines of code!

Also, in real life, input polling is not as practical as it seems and events are much better. They offer a much more modular and object oriented way to do things.

Sean_carter
Member #13,817
December 2011

What does it matter?? Louis Armstrong was once asked, "What is Jazz?" His response was, "Man, if you gotta ask, you'll never know."

The point is that with the old API at least you can read the function and quickly guess what it does, and guess correctly. The function line... draws a line. The function read_key... reads a key. Allegro was developed for the explicit purpose of being a simple library for people who don't want to go through the windows API or some other bloated behemoth with a 10 page "Hello, World!". I know that it's possible to set up objects for an application and a window and pass WM_LBUTTONDOWN messages around, and then have a bunch of callbacks and other garbage every time an event occurs, but I don't want to have to do that! That's why Allegro exists in the first place!

Edgar Reynaldo
Member #8,592
May 2007
avatar

BAF, is that you? :P

#SelectExpand
1#include <iostream> 2#include <allegro.h> //ONE INCLUDE! 3 4using namespace std; 5 6int main() { 7 allegro_init(); 8 install_keyboard(); 9 10 if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) < 0) { 11 cout << "Unable to set graphic mode!" << endl; 12 return 0; 13 } 14 15 while (true) { 16 if(keypressed()) { 17 unsigned char key; 18 key = readkey() & 0xff; 19 if(key == 'q') { //quit 20 break; 21 } 22 clear_keybuf(); 23 } 24 line(screen, 0, 0, 100, 100, makecol(255, 255, 0)); 25 } 26 27 return 0; 28} 29 30END_OF_MAIN()

Compared to the exact same in A5 :

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_primitives.h> 4using namespace std; 5 6int main(int argc , char** argv) { 7 al_init(); 8 al_install_keyboard(); 9 10 ALLEGRO_DISPLAY* display = al_create_display(1024,768); 11 if (!display) { 12 cout << "Failed to create display" << endl; 13 return 1; 14 } 15 ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue(); 16 al_register_event_source(al_get_keyboard_event_source()); 17 al_register_event_source(al_get_display_event_source(display); 18 19 al_init_primitives_addon(); 20 21 al_clear_to_color(al_map_rgb(0,0,0)); 22 al_draw_line(0.5 , 0.5 , 100.5 , 100.5 , al_map_rgb(255,255,0) , 1.0); 23 al_flip_display(); 24 25 bool quit = false; 26 while (!quit) { 27 do { 28 ALLEGRO_EVENT ev; 29 al_wait_for_event(queue , &ev); 30 if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 31 if (ev.keyboard.keycode == ALLEGRO_KEY_Q) {quit = true;break;} 32 } 33 } while (!al_is_event_queue_empty(queue)); 34 } 35 return 0; 36}

36 lines instead of 30. Oh Lordie, Whatever shall we do? ::)

If you use a simple C++ wrapper for setup, then it is just as easy to use A5 as it was to use A4. And, you get hardware acceleration, and your choice of events or state based polling if you prefer.

The point is that with the old API at least you can read the function and quickly guess what it does, and guess correctly.

So you're not sure what al_draw_line does? Or was it al_wait_for_event that you're not sure about, or maybe al_is_event_queue_empty that doesn't tell you exactly what it does?

Geez. If it bothers you so much, go back to SDL, or wherever else it is you came from, troll.
{"name":"605197","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/2\/824750140ba48e437ef9c21facdac5a0.jpg","w":400,"h":295,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/2\/824750140ba48e437ef9c21facdac5a0"}605197

jmasterx
Member #11,410
October 2009

I see Allegro 5 more as a serious API to compete with SFML and SDL.

At the end of the day, if you do not like Allegro 5 by all means do not use it. But do note that you're one of a very small subset of Allegro users that dislikes the API and therefore the AL5 developers were right in there decision since they added so much flexibility and made almost all of its users pleased with the new API.

Also Allegro 5 provides input polling http://www.liballeg.org/a5docs/refman/keyboard.html#al_get_keyboard_state

not that I would ever use it, events are much better.

In addition, there are mouse callbacks to setup in AL4 and what is so readable about mouse_b & 1?

Sean_carter
Member #13,817
December 2011

First off, you cheated a little bit on your line count by removing whitespace and blank lines. Look, if you think that the monster you posted is as easy to work with as what I put up... OK, that's your opinion. But, you're fooling yourself. If I have to use a C++ wrapper for setup.. something is very wrong! The windows API is flexible too, you know.

I read recently that new ideas are subversive, because an idea is a suggestion and a suggestion is a complaint. OK, fine. Maybe I'm coming on kind of strong here. It just makes me depressed when something really good dies.

Look, I can see that nobody here is going to agree with me. Fine... but Allegro is definitely going to die slowly if you continue down this course. Here is the "Hello, World" for Allegro 6.0...

#SelectExpand
1#include <windows> 2#include <condefs.h> 3 4 5LRESULT CALLBACK myWndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) 6{ 7 if (msg==WM_PAINT) 8 { 9 PAINTSTRUCT ps; 10 const HDC hDC = BeginPaint(hWindow,&ps); 11 RECT rect; 12 GetClientRect(hWindow,&rect); 13 DrawText(hDC,TEXT("HELLO WORLD"),-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); 14 EndPaint(hWindow,&ps); 15 return 0; 16 } 17 else if (msg==WM_DESTROY) 18 { 19 PostQuitMessage(0); 20 return 0; 21 } 22 return DefWindowProc(hWindow,msg,wParam,lParam); 23} 24int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 25{ 26 const static TCHAR appName[] = TEXT("Hello world"); 27 WNDCLASSEX myWin; 28 myWin.cbSize = sizeof(myWin); 29 myWin.style = CS_HREDRAW | CS_VREDRAW; 30 myWin.lpfnWndProc = myWndProc; 31 myWin.cbClsExtra = 0; 32 myWin.cbWndExtra = 0; 33 myWin.hInstance = hInstance; 34 myWin.hIcon = 0; 35 myWin.hIconSm = 0; 36 myWin.hCursor = 0; 37 myWin.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 38 myWin.lpszMenuName = 0; 39 myWin.lpszClassName = appName; 40 //Register 41 if (!RegisterClassEx(&myWin)) return 0; 42 const HWND hWindow = CreateWindow( 43 appName, 44 appName, 45 WS_OVERLAPPEDWINDOW, 46 CW_USEDEFAULT, 47 CW_USEDEFAULT, 48 CW_USEDEFAULT, 49 CW_USEDEFAULT, 50 0, 51 0, 52 hInstance, 53 0); 54 ShowWindow(hWindow,iCmdShow); 55 UpdateWindow(hWindow); 56 { 57 MSG msg; 58 while(GetMessage(&msg,0,0,0)) 59 { 60 TranslateMessage(&msg); 61 DispatchMessage(&msg); 62 } 63 return (int)msg.wParam; 64 } 65}

AMCerasoli
Member #11,955
May 2010
avatar

Finally a troll!, the forum was getting bored... ;D

Look! 29 28 lines! with the entire events registered in my event_queue!

#SelectExpand
1#include "RESOURCE_MANAGER.h" 2 3 ALLEGRO_EVENT ev; 4 bool close_game = false; 5 6int main(){ 7 8 RESOURCE_MANAGER rm; 9 ALLEGRO_EVENT_QUEUE *event_queue = rm.get_event_queue(); 10 11 while(!close_game){ 12 al_wait_for_event(event_queue, &ev); 13 14 switch(ev.type){ 15 case ALLEGRO_EVENT_TIMER: 16 if(al_is_event_queue_empty(event_queue)){ 17 draw_ev(); 18 al_flip_display(); 19 } 20 break; 21 22 case ALLEGRO_EVENT_KEY_CHAR: 23 key_ev(); 24 break; 25 }; 26 } 27 return 0; 28}

jmasterx
Member #11,410
October 2009

Now why would a cross platform library make WinAPI specific calls? That's just silly.

video

Everyone sing along, Trolls like these only come around the Holidays :)

Sean_carter
Member #13,817
December 2011

Come on, dude, moving all the code to an external .h file doesn't count. You're not even trying!
And what the hell, you do realize I posted a windows API program as a comparison of style, right? I'm obviously not saying we should use Win32 calls.

Arg, never underestimate the power of a chorus of morons! OK! Fine! I'm done. You don't need to post any further comments because I won't read them. Happy goldfish bowl to you. Just ignore anybody you don't agree with. Don't make points, hurl insults. Business as usual. Keep on telling yourself that you're right.

23yrold3yrold
Member #1,134
March 2001
avatar

Like I said, you'll troll better next time.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

AMCerasoli
Member #11,955
May 2010
avatar

Do you know what is the saddest part?, that I think he was actually talking seriously... I mean, if you're there trolly... Haven't you took a look at SDL or SFML before talking? they're doing the same, why? because technology gets better and because people find new and better ways to do things, and because everything is getting more complex by the pass of time, but don't worry, your brain is able to handle it. But believe me, if you think Allegro 5 is not simple then you're not meant to be a programmer.

Mark Oates
Member #1,146
March 2001
avatar

Though A5 is less straight forward than A4, the end result is a much better and more robust library. It does take some practice and a little legwork to get used to the methodology if you're accustomed to A4.

One thing that makes A5 strong is what you got hit with in this thread - the community. If you make claims that Allegro is on the collapse, you've unleashed the army, they'll call you a troll and reverse-troll you for your sacrilege. We've all had a lot of time to learn Allegro and use it well, and realize that A5 gives us more of what we want/need than A4 was able to.

kazzmir
Member #1,786
December 2001
avatar

I sympathize with Sean. I think A5 is an order of magnitude harder to understand than A4. A5 is more correct in many respects, but that correctness comes at the cost of sophistication.

I picked up A4 when I was just a noob coder many years ago. I'm not entirely sure I could pick up A5 if I was still a noob. I get the feeling that a lot of the "its better you just don't realize it yet" posts have lost touch with people who aren't as experienced. Almost by definition if one person says X is hard, then its hard.

Anyway to ameliorate the situation I have started and continue to improve (with elias's help now) a compatibility layer between A4 and A5. A5's feature set is really much better than A4, its just not as easy to use. It does not seem to me that A5's API was specifically designed to be easy to use, rather it was designed to have a set of features deemed relevant to today's issues.

https://github.com/kazzmir/allegro4-to-5

Elias
Member #358
May 2000

If you must, you can still use A4 style in A5:

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_primitives.h> 3 4int main(int argc , char** argv) { 5 al_init(); 6 al_install_keyboard(); 7 al_create_display(1024, 768); 8 al_init_primitives_addon(); 9 10 al_clear_to_color(al_map_rgb(0, 0, 0)); 11 al_draw_line(0.5 , 0.5 , 100.5 , 100.5 , al_map_rgb(255, 255, 0) , 1.0); 12 al_flip_display(); 13 14 while(true) { 15 ALLEGRO_KEYBOARD_STATE(keys); 16 al_get_keyboard_state(&keys); 17 if (al_key_down(&keys, ALLEGRO_KEY_Q)) break; 18 } 19 return 0; 20}

However it's not a real comparison as the A4 code you posted won't be very scalable. As soon as you do something like clear the screen you would get horrible flicker as any update to "screen" happens in real time. Usually A4 code prevents that by implementing things like "double buffering" or "page flipping" - so to get a proper, useful mainloop up in A4 you will end up with more code than in A5 and with very hard to explain code.

That's not to say A4 was all bad but the API just had a lot of things like that which weren't fixable for DirectX/OpenGL based hardware and so the developers abandoned it. That's not to say A5 is the only good way to do things - but a lot of research and thought and discussions went into its API and it should at least stand up well against things like SDL 2 (1.3) or SFML or XNA.

Also, jonrafkind and me were working on an A4 addon the past few days which allows A4 style code to run on top of A5. Our idea is mostly to help in porting old A4 code (so you'd start out with that addon but then gradually fix it all to use proper A5 code) but sounds appropriate to mention here :)

[edit:] i mean kazzmir, and he just beat me to mentioning it in the post above

--
"Either help out or stop whining" - Evert

kenmasters1976
Member #8,794
July 2007

Elias wins. Sean, see what an ugly mess your code looks like when compared to Elias' Allegro 5 version.

But seriously, just because you have to type a few more words with Allegro 5 doesn't mean it's worse. Yes, it's different from Allegro 4 and we all had to learn the new API but once you get used to it you won't miss Allegro 4. Also, the naming convention was chosen for a reason and it's better than the Allegro 4 naming convention.

Edgar Reynaldo
Member #8,592
May 2007
avatar

First off, you cheated a little bit on your line count by removing whitespace and blank lines.

Huh? With no blank lines in either example it would be 31 lines to 24. That only gained you a further one line difference. :P

Sean_carter said:

Look, if you think that the monster you posted is as easy to work with as what I put up... OK, that's your opinion. But, you're fooling yourself. If I have to use a C++ wrapper for setup.. something is very wrong! The windows API is flexible too, you know.

Almost the only difference between A4 and A5 is the amount of setup, and with A5 it gives more flexibility, not less. People can use only the addons they are interested in and prevent themselves from shipping more dlls than they have to.

Sean_carter said:

I read recently that new ideas are subversive, because an idea is a suggestion and a suggestion is a complaint. OK, fine. Maybe I'm coming on kind of strong here. It just makes me depressed when something really good dies.

There's nothing wrong with ideas, but you stormed in here and proclaimed that A5 is some kind of disaster, when in fact it is pretty useful. I doubt you have even made any programs with A5 yet, and so I don't really think you're qualified to give much of an opinion on it.

Besides all that, you're still fully welcome to use A4.4 to your hearts content. I still do, but I can also appreciate the work and effort put into A5 in making a cleaner API, a more competitive library, and something that will be useful into the future. Ever try using OpenGL with A4? You have to use AllegroGL to do that, but with A5 it is built in. Can you use D3D and DX with A4? No, you can't.

Sean_carter said:

Look, I can see that nobody here is going to agree with me. Fine... but Allegro is definitely going to die slowly if you continue down this course. Here is the "Hello, World" for Allegro 6.0...

Maybe if you would stop being so melodramatic, and such a whiny brat, then maybe we would take you seriously.

Arg, never underestimate the power of a chorus of morons! OK! Fine! I'm done. You don't need to post any further comments because I won't read them. Happy goldfish bowl to you. Just ignore anybody you don't agree with. Don't make points, hurl insults. Business as usual. Keep on telling yourself that you're right.

I don't think anybody here ignored you... We just don't agree with you because your arguments are hollow and weak, and we've been using both A4 and A5, so don't you think we would know if Allegro went down hill or not? ???

Anyway, go regroup, and see if you can come up with any valid complaints, and then maybe we'll give a shit.

Matthew Leverton
Supreme Loser
January 1999
avatar

Is there a new group of people in charge of the API? We need to either put the old guard back in charge, or fork the source code and fix things ourselves.

Yes, let's storm Redmond, abduct Shawn H, and demand that he works on a new API. Oh wait, we'd end up with something like the XNA. :-/

But in truth, no revolution is required, and you don't need to fork the source code. Allegro 4.4 still exists. All it needs is people like you to keep it up to date. You can start by getting it working on the latest version of OS X.

So let us know when you've done something useful. Telling other people to do something for you is not.

Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, Allegro 4 could really use some fresh blood. The old guard really doesn't like touching it more than they have to. If some new people who really love it want to work on it, we welcome them all :)

--
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
"Goto is the buldozer of coding. Sometimes, the buldozer is just the right tool for the job. Not often, but sometimes." -- LordBob

Go to: