Hey guys. I am doing an engine to make things easier while creating my games.I could make it work, but not on the way it is taught in most of tutorials. I mean, when I try to use the funcion al_wait_for_event to get mouse or keyboard events it takes like "forever" to read them. To fixe it I had to create 2 new variables and these are them: ALLEGRO_KEYBOARD_STATE and ALLEGRO_MOUSE_STATE. When I use them the program runs pretty smoth, but when I try to let the ALLEGRO_EVENT handle it, the program doesn't behave as well as I expected it to.

The code is the same in the main function. Only the speed changes.When I try to catch the event through event.keboard.keycode or event.mouseit makes the code slow. But when I use the ALLEGRO_MOUSE_STATE and KEYBOARD_STATEit goes so fast. So I imagine there's something wrong in al_wait_for_event, or itdoesn't accept to be called through dll?

APPEND:I don't see the call to al_wait_for_event in your code, maybe you could post that part? It would also be interesting to see how you control the main loop speed.

By the way, you have a lot of code duplication. For starters, I would use a switch instead of a bunch of if statements. And you don't need to repeat things like where->key_press(where, ALLEGRO_KEY_ALT) a million times. Keep it short and clear, split the code into functions or macros if you need to. Also, I would probably keep the input information in a struct INPUT, not inside PLACE. And I'm not sure why you use function pointers, but maybe you have a reason

The part of the code that updates the events is just the running function.And here it is:

PLACE_CALL STATUS PLACE_TYPE place_running(PLACE * to){if(to && to->machine.running){al_wait_for_event(to->machine.plugin.event_row,&to->machine.plugin.event);al_get_keyboard_state(&to->machine.plugin.key);// the keyboard andal_get_mouse_state(&to->machine.plugin.mouse);// mouse only responds fastreturn(On);// if I call the state's functions}return(Off);// if I only try with al_wait_for_event it goes slow}

Thanks for let me know about how to use the tag code in here.I use to do [code] like this.And about the key, I changed the code. See if it is better now. About the function's pointer, I like using this way, for the C to be more like oriented object. I have tested the engine with about 1.000.000 objects and it was running in my i5 with 4gb.

Calling al_get_keyboard_state and al_get_mouse_state should not make things go faster. The problem has to be somewhere else in your code. Remove the calls to al_get_keyboard_state and al_get_mouse_state, and try to get your code working without them. Print some logging information to see where in your code you are, and what the values of important variables are. Maybe even just putting things like `fprintf(stderr, ".");` in the loop, then you can see how often it runs, where the delays are, etc.

As I said, I have tried to use the code without the state's function, but it goes slow and I had to rewrite all the parts of the keyboard and mouse calls. If I hadn't I wasn't disturbing you guys.. be sure about that. I did the same code with other graphic library and it worked, but when I tried to use it on linux, it didn't show some images. So I changed to allegro again. I thing I got a little experience now. I have watched the device manager and it doesn't see to have any memory leak. it is running smoth. What should be the next step dude?

here is one of the codes that responds normally(repair it has the sugested printf() testing it, but I commented it because this way there's no problem):

About the debbuging, I use to do this always. But when I check the code, and there's no problem there, I use to comment it for the program not to go slow. When I changed the code to state and it did work well I commented the printf function.And about the direction, I don't want to do a function like direction_set, because functions make the program slower than to call the variable directly on the main loop I guess. I reduced the number of functions in order to speed up my code.. And about the verification of the character, I couldn't figure out a way to make it better, if you have a suggestion I would appreciate. Thanks ... ah, about the ifs, I didn't use else, because I could see no reason to use. Because when you use else, you can only do one of the works, but when you use only ifs, it doesn't deppends on the other parts. And about my english, its a crap I now... but here in Brasil the don't care a shit about study.

And about the direction, I don't want to do a function like direction_set, because functions make the program slower than to call the variable directly on the main loop I guess. I reduced the number of functions in order to speed up my code..

You probably would not notice the function call overhead in your code, it probably takes thousands of extra calls per second for it to matter. And having the same code many times can also make your code slower, because there is more code to transfer to the CPU, and it takes up space in the CPU cache that could be used for other code instead. But what always matters is how readable and maintainable your code is

This is exactly the "L" of the question. I think I should not to call any more functions than those... only if it is really necessary. Don't you think that if I use object->direction_set instead of object->where = direction it will be more slow? and do you think my code is not readable enough? if yes, what should I do to make it more readable?

All right. But the above code has many codes which look like the other, but each one do a different thing... if you don't show me where I shall change I won't guess it.... This is the best way I could figure the problem out. So if you have I suggest to improve my code, please post it. But until now I could not have any Idea on how to fix the al_wait_for_event's problem.

Alright brother. I am posting only the library place.Because the main.c is in here yet.In the place's zip there's more than one folder, because of the auxiliar libraries that I made, like symbol, status, timer, object, allegro5_plugin, etc. Thanks for your patience dude.

My bad... I put the images into a folder named image.. inside it there are 2 folders. The background and the sprite folder. You will have to make some modifications on the directory in main.c... but I think you will figure it out easy. And, I don't know if you got it, but I reimplemented the timer function... The objects are now controled by time in the main.c.

I don't have it anymore dude. And I have found a bug. I think I won't be able to be using the library symbol.h. I works for a while and somewhere it crashes away.I have ran it in gcc - mingw with netbeans... did it runs well in VC? I will take a little time now and try to reimpletent it through event. As soon as I get it done I will post the code.

The animations played well I posted the place's folder again.This time it has the code you haveand one more file named "place_old.c"This file is using al_wait_for_event.I tried to run it here and it continuedto respond slow. The only way it torespond fast and without bugs wasthrough state's functions...

And about this version control, do youmean to make some defines with macro?