Missing keyboard events

Hi all,

I just started programming, especially with SDL and I am wondering why my
program seems to miss keystrokes. My main game loop looks something like:

void GameLoop(void)
{
int quit = 0;
Uint8 *keystate;

while(quit == 0)
{

/* Update SDL's internal input state information. */
SDL_PumpEvents();
	
/* Grab a snapshot of the keyboard. */
keystate = SDL_GetKeyState(NULL);

/* Respond to input. */
if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;

if (keystate[SDLK_LEFT]) ship.move((-1 * time_scale));
if (keystate[SDLK_RIGHT]) ship.move((1 * time_scale));

RenderFrame();
frames_drawn++;
}

}

I took this code from John Hall’s Programming Linux Games and I think it
shouldn’t miss keystrokes as long as the framerate is high enough which it is
(approx. 90 fps). By the way: I am using OpenGL rendering but i can’t think
of a reason why that should interfere.

Mattijs de Groot

the problem is just that you aren’t receiving events, and rather are just
taking the current state of the keyboard. when you do that, you always
stand the chance of missing key strokes.>From: mdg

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: [SDL] missing keyboard events
Date: Mon, 17 Dec 2001 18:05:08 -0500

Hi all,

I just started programming, especially with SDL and I am wondering why my
program seems to miss keystrokes. My main game loop looks something like:

void GameLoop(void)
{
int quit = 0;
Uint8 *keystate;

while(quit == 0)
{

/* Update SDL’s internal input state information. */
SDL_PumpEvents();

/* Grab a snapshot of the keyboard. */
keystate = SDL_GetKeyState(NULL);

/* Respond to input. */
if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;

if (keystate[SDLK_LEFT]) ship.move((-1 * time_scale));
if (keystate[SDLK_RIGHT]) ship.move((1 * time_scale));

RenderFrame();
frames_drawn++;
}
}

I took this code from John Hall’s Programming Linux Games and I think it
shouldn’t miss keystrokes as long as the framerate is high enough which it
is
(approx. 90 fps). By the way: I am using OpenGL rendering but i can’t think
of a reason why that should interfere.

Mattijs de Groot


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

OK I changed my input loop to use SDL_PollEvent() and it seems to work now,
but I was thinking: is it a good idea maybe to use a separate thread with
SDL_WaitEvent() instead?.On Monday 17 December 2001 01:37 pm, you wrote:

the problem is just that you aren’t receiving events, and rather are just
taking the current state of the keyboard. when you do that, you always
stand the chance of missing key strokes.

From: mdg <@Mattijs_de_Groot>

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: [SDL] missing keyboard events
Date: Mon, 17 Dec 2001 18:05:08 -0500

Hi all,

I just started programming, especially with SDL and I am wondering why my
program seems to miss keystrokes. My main game loop looks something like:

void GameLoop(void)
{
int quit = 0;
Uint8 *keystate;

while(quit == 0)
{

/* Update SDL’s internal input state information. */
SDL_PumpEvents();

/* Grab a snapshot of the keyboard. */
keystate = SDL_GetKeyState(NULL);

/* Respond to input. */
if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;

if (keystate[SDLK_LEFT]) ship.move((-1 * time_scale));
if (keystate[SDLK_RIGHT]) ship.move((1 * time_scale));

RenderFrame();
frames_drawn++;
}
}

I took this code from John Hall’s Programming Linux Games and I think it
shouldn’t miss keystrokes as long as the framerate is high enough which it
is
(approx. 90 fps). By the way: I am using OpenGL rendering but i can’t
think of a reason why that should interfere.

Mattijs de Groot


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

In general (for games and other multimedia apps), no. You’d just move
buffering and synchronization into your code, instead of letting SDL’s
event queue deal with it.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Tuesday 18 December 2001 02:21, mdg wrote:

OK I changed my input loop to use SDL_PollEvent() and it seems to work
now, but I was thinking: is it a good idea maybe to use a separate
thread with SDL_WaitEvent() instead?.

OK I changed my input loop to use SDL_PollEvent() and it seems to work now,
but I was thinking: is it a good idea maybe to use a separate thread with
SDL_WaitEvent() instead?.

I don’t think the SDL event loop and threads mix. At least, I wouldn’t
count on it.

Not to mention you can’t spin threads on MacOS Classic.

Check for and process all available events at the start of every iteration
of your game loop. This is how just about every game in the universe does
it, and so should you.

–ryan.