Keyboard Input and performance

Hi!
I’m developing an SDL top-down scrolling shooter for linux, and i
seem to be having performance issues related to my screen redraw. I
have tried every optimization i could think of to speed up the drawing,
but nevertheless the drawing is really slow at 640x480x(Best pixel
format determined by SDL_GetVideoInfo()) once i start drawing 6-7 64x64
images. An odd thing i have noticed while running my test is that the
program seems to hog ~99% of the system! I am only redrawing the screen
if it needs to, not every loop, so the drawing can’t be the source of
the problem. The only thing i can think of is, i call SDL_GetKeyState()
to return the state of the keyboard every time through the loop, because
i have not found another way to keep receiving events when a key is held
down. So my question is, could SDL_GetKeyState() be causing the big
performance hit?

                                                    Michael Frank

the problem. The only thing i can think of is, i call SDL_GetKeyState()
to return the state of the keyboard every time through the loop, because
i have not found another way to keep receiving events when a key is held
down. So my question is, could SDL_GetKeyState() be causing the big
performance hit?

How tight is your loop? Do you call SDL_Delay() in there at all?

Also, need any help with the game? Every time I see Raiden or 1942 I
get the urge to do a shooter. :wink:

-bill!

William Kendrick wrote:

How tight is your loop? Do you call SDL_Delay() in there at all?

no. as of right now, all the loop does is grab the keyboard input, process
one event on the queue (using SDL_PollEvent()) if there is one, and then draw
if the user has moved at all.

Also, need any help with the game? Every time I see Raiden or 1942 I
get the urge to do a shooter. :wink:

Sure! i’ll email you with more information about the game.

                                                                Michael

Frank

down. So my question is, could SDL_GetKeyState() be causing the big
performance hit?

Just look at the source. It just returns a pointer, end of story. That
pointer is to an array of key entries which are updated doing the
event loop.

Now, processing the key state may take time…

m.On Wed, Jan 19, 2000 at 06:04:28PM -0800, Michael Frank wrote:


Programmer "I wrote a song about dental floss,
Loki Entertainment Software but did anyone’s teeth get cleaner?"
http://lokigames.com/~briareos/ - Frank Zappa, re: the PMRC

down. So my question is, could SDL_GetKeyState() be causing the big
performance hit?

Just look at the source. It just returns a pointer, end of story. That
pointer is to an array of key entries which are updated doing the
event loop.

Now, processing the key state may take time…

And if you are in a tight loop checking pointer values without any kind
of sleep, then that will chew CPU too.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software> On Wed, Jan 19, 2000 at 06:04:28PM -0800, Michael Frank wrote:

“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

William Kendrick wrote:

How tight is your loop? Do you call SDL_Delay() in there at all?

no. as of right now, all the loop does is grab the keyboard input, process
one event on the queue (using SDL_PollEvent()) if there is one, and then draw
if the user has moved at all.

Seems innocuous enough. Til one of your smart-ass friends complains that
the game takes up 100% of his CPU. Then you test it yourself and see that
he’s right. :wink: :wink: :wink:

Stick an “SDL_Delay()” call in there. If you want the loop to iterate every
30th of a second, you could do it approximately with:

SDL_Delay(33);

(however, depending on the timer resolution of your box, it might actually
pause for 40 thousandths of a second, I believe, so you might wanna try
SDL_Delay(30); insteady).

Also, need any help with the game? Every time I see Raiden or 1942 I
get the urge to do a shooter. :wink:

Sure! i’ll email you with more information about the game.

Cool! Thanks! :slight_smile: Mmm… if it’s a space game (vs, like a WWII game), maybe
I could try doing that cool trademark bezier curve laser from Raiden. I LOVE
that thing! :slight_smile:

-bill!