sorry for the new post but my old one was locked for some reason.
is there a way to read keyboard up and down events and mouse up and down events outside of main without needing to pass a handle to the display?
I want to make a simple 6 functions without needing to update them in main..
is there a easy way to do this?
EDIT: I think this might be able to be done with threads but I am afraid to use them due to mutex locks.
You could use global variables. Something like:
Call the two event functions when you receive a key up/down event in main. Call the after_game_tick function when you're done handling game input to reset the down/up counters.
Exactly the same will work for mouse.
Your old topic wasn't locked. You just can't double post.
Your old topic wasn't locked. You just can't double post.
Could mention the trick to get around that: Edit the post, preferreably putting "APPEND:" or similiar before the additions, then click on Send to top
, why? You just did it for me. :/
I meant that I could :p
@Elias
is there a way to implement this so I don't have to handler the events in the main loop?
I was thinking something like a simple init function.
@Edgar Reynaldo and @torhu
sorry I didn't realize that.
does APPEND notify users of the topic that it has updated?
No, but the "Send to Top" button does (if it has been more than an hour since your last update).
The way I do it is I have an init() function and tick() function for the game and do everything there (and the actual main loop inside of main() does nothing but handling the Allegro events).
@bamccaig awesome i will keep that in mind.
@Elias so is it possible to handle events for my gui in tick without a display?
and if so is it possiable to do it so I can use the same events for another module?
For now, you have to have a window to get input. Because that's where Windows sends you the input. There's no way around it.
Please explain what you are trying to do.
It seems that the OP is having a case of the “XY Problem”. He is asking about an attempted solution rather than his actual problem.
In other words, he is trying to solve a problem X. He really thinks solution Y will work. Now, instead of asking about X, he is asking about Y.
Can you start from 0 and tell us what you want to do? I saw a red flag when you mentioned threads. Most code doesn’t need threads at all. You also said modules. Are you trying to abstract Allegro into different components or something like that? The more information and code you provide, the more likely someone here will give you a solution.
Examples are often made as single file / function, but I understand the issue is about organizing the code in different modules (C files).
The main event loop, wherever it is, could include this part : (Adapted from Edgar's earlier example)
input.c:
input.h:
// the declaration of all the above methods // mykeys is *not* declared here, because other modules don't need to know about it
so I wrote this yesterday. however I can't test it since it's in a dll project and I can't figure out how to link it into my executable
I cannot test this either though one thing seems to be wrong - namely, second source file, at line 31:
for (int i = 0; i < ALLEGRO_KEY_MAX; i++)
I believe you should change ALLEGRO_KEY_MAX to a variable that your would set in your program's initialization part using the function call that Edgar suggested here: https://www.allegro.cc/forums/thread/617983
MikiZX, nope. ALLEGRO_KEY_MAX is a constant that doesn't change. It's perfectly safe to use.
There are two 'for' loops in Shadowblitz's source, one after the other. The first one is for the keys while the second one is for the mouse buttons. It seems the second loop is the one that accesses an array of 16 elements using an index well out of bounds - sorry, I should have explained it better in my previous post.
so I wrote this yesterday. however I can't test it since it's in a dll project and I can't figure out how to link it into my executable
You need to split it into header files and implementation (*.cpp) files. Function definitions go in the implementation files. Class/struct declarations, function prototypes, symbolic constants, typedefs, etc. go in the headers.
Then you just add these files to your game project, which should be configured to build an executable. You don't need to create DLL's unless you have a specific reason to want that level of separation.
Also, you don't really need multiple levels of namespaces in a small project, it's just more to type.
Oh, MikiZX, you're right, sorry I can't read. No, you definitely don't want to check ALLEGRO_KEY_MAX mouse buttons.
You need to split it into header files and implementation (*.cpp) files. Function definitions go in the implementation files. Class/struct declarations, function prototypes, symbolic constants, typedefs, etc. go in the headers.
This is something good, I would like to bookmark it.
And... I just did.