Not really, the code is pretty deeply intertwined. You might want to
look at the source before you decide it is faster. Generally SDL has to
read an event queue to get the information it puts in the key vector.
Anyway, the cost is so small it doesn’t really affect game play even
with 4 players on one machine. OTOH, if you are only using one keyboard
then you will have problems with keys presses not being detected at all.
(I’m not sure what kind of reading input state you meant in second paragraph, probably messaging)
Well it’s the thing that’s very important to me, because having reliabe input system which won’t miss keypresses, even when 4 players use the same keyboard simultaneusly, is a must for my game. So when designing input class I thought that using events probably will be less accurate (to be honest, actually performance isn’t what I care about, so forget that argument from earlier post) then using key vectory, reasons:
-
Having only one PollEvent in main loop would couse key events to come far too late, especially with 4 players (1 event / 1 game loop). Also doing it way that it polls for events untill queue is empty, in hardcore situations (4 players pressing X keys each, where X belongs to [1, 4] ) could make the game stay still, polling endless keypressess (though now I think it’s problem only in my imagination, in real world SDL probably has some sort of max. events cap).
-
OTOH, when SDL_GetKeyState for key vector would be called appropriate number of times / second (ie. 100), in theory I shouldn’t bother with missing keypressess: humans are not robots so ability to press and relase key so fast that it would be left unnoticed by game running with 100 fps (which means you have 10 ms for doing this) IMHO is very unique :-]
There were also other reasons but I can’t recall them now. And yes, I know the ones I’ve written can’t be treated very seriously, in fact, the most important reason was that such system was propsed in Enginuity series on GameDev; I’ve seen there this system along with some pretty cool ideas, so I thought to myself: “that guy knows what he’s doing, I should give it a try”. It’s just that simple
BTW: anybody knows is SDL_GetKeyState is supposed to properly and reliably read state of all keys, so ie. if I put huge book on keyboard which will couse more than 20 keys to be pressed, will all of them be properly read?
Additionaly, it would be great if anyone knows if key events could handle this situation properly? I remember from good old pascal days that some low level asm interrupt implementations allowed for max up to 4 keys being pressed/released at once, but it was many years ago, I wonder if hardware and software are now better in dealing with such cases.
Since the key vector shows you the state at the time you check it, it is
pretty easy to miss key presses and shift presses. People don’t press
them at the same time so you might get wrong results at times. The only
way around that problem is to use a form of input that doesn’t let you
miss key presses/releases.
Hmmm, another problem :-/
I’ll test if it happen and if it will prove to couse problems I’ll probably change input system for using events. Thx for making aware of this issue!
Koshmaar