Event handling still slow

I’ll post my code so maybe someone can see what I’m not. Hope it’s not to big.
I still have to hold the key for at least a second. Not sure why though. Here
it is. Thanks for all the help, because of you help, more and more games have
been built by up and coming programmers!

#include <stdio.h>
#include <stdlib.h>
#include “/usr/include/SDL/SDL.h”
#include “/usr/include/SDL/SDL_timer.h”
#include <time.h>

SDL_Surface *screen;
SDL_Surface *scenery;
SDL_Surface *toolbar;
SDL_Surface *deer_small;

SDL_Rect dest;
int ncolors, i,x,xpos,ran_num;
SDL_Color *colors;

int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) > 0)
{
keys = SDL_GetKeyState(NULL);

       if ( keys[SDLK_ESCAPE] )
            {
              exit(1);
            }

}
}

/******************* Video Stuff ********************/
void initialize()
{
/
Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}

/* Clean up on exit */
atexit(SDL_Quit);

/* Initialize the display in a 640x480 8-bit palettized mode */
screen = SDL_SetVideoMode(800, 600, 16, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(1);
}
}
/*****************************************************/

/****** Load images *********************************/
void load_images(void)
{
/
Load the BMP file into a surface /
scenery = SDL_LoadBMP(“sample.bmp”);
if ( scenery == NULL ) {
fprintf(stderr, “Couldn’t load scenery.bmp: %s\n”,
SDL_GetError());
exit(1);
}
/
Load the BMP file into a surface /
toolbar = SDL_LoadBMP(“toolbar.bmp”);
if ( toolbar == NULL ) {
fprintf(stderr, “Couldn’t load toolbar.bmp: %s\n”,
SDL_GetError());
exit(1);
}
/
Load the BMP file into a surface */
deer_small = SDL_LoadBMP(“deer_small.bmp”);
if ( deer_small == NULL ) {
fprintf(stderr, “Couldn’t load deer_small.bmp: %s\n”,
SDL_GetError());
exit(1);
}

}
/*****************************************************/

/************** Blit images **************************/

void blit_background(void)
{
/* Blit onto the screen surface*/
dest.x = 0;
dest.y = 0;
dest.w = scenery->w;
dest.h = scenery->h;
SDL_BlitSurface(scenery, NULL, screen, &dest);
SDL_UpdateRects(screen, 1, &dest);
}
void blit_toolbar()
{
/* Blit onto the screen surface*/
dest.x = 0;
dest.y = 525;
dest.w = toolbar->w;
dest.h = toolbar->h;
SDL_BlitSurface(toolbar, NULL, screen, &dest);
SDL_UpdateRects(screen, 1, &dest);
}
/*****************************************************/

/***************** Run Game **************************/
void blit_deer(int x,int y)
{

/* Blit onto the screen surface*/
  dest.x = x;
  dest.y = y;
  dest.w = deer_small->w;
  dest.h = deer_small->h;
  SDL_BlitSurface(deer_small, NULL, screen, &dest);
  SDL_UpdateRects(screen, 1, &dest);   

}

/*****************************************************/

/*************** Scenerios of Movement ***************************/
/
I have tried key_events after blit_deer() also. */

void scen_1()
{
for(x=1;x<=110;x=x+5)key_events(),SDL_Delay(10), blit_background(),
blit_deer(x,420);
}
void scen_2()
{

 for(x=100;x<=210;x=x+5)key_events(),SDL_Delay(10), blit_background(),
   blit_deer(x,420);

}
void scen_3()
{

 for(x=600;x<=710;x=x+5)key_events(),SDL_Delay(10), blit_background(),
   blit_deer(x,420);

}
void scen_4()
{

 for(x=1;x<=110;x=x+5)key_events(),SDL_Delay(10), blit_background(),
   blit_deer(x,420);

}

/******************************************************/

/************** Figure out which scenerio and Run it ****/

void which_scen()
{

ran_num = 1+(int) (3.0*rand()/(RAND_MAX+1.0));

if (ran_num == 0) {
scen_1(); }
else if (ran_num == 1) {
scen_2(); }
else if (ran_num == 2) {
scen_3(); }
else if (ran_num >= 3 ) {
scen_4();

              }

}
/*********************************************************/

/************ Set Color Map of Scenery************************/
void setcolormap()
{
if ( scenery->format->palette != NULL ) {
SDL_SetColors(screen,
scenery->format->palette->colors, 0,
scenery->format->palette->ncolors);
}
}

//
/
Make deer transparent /
void trans_image()
{
if (SDL_SetColorKey(deer_small, (SDL_SRCCOLORKEY),
SDL_MapRGB(deer_small -> format,0xFF, 0xFF, 0xFF)) == -1);
}
/
*********/
int main()
{
srand(time(NULL));
initialize();
load_images();
setcolormap();
blit_background();
blit_toolbar();
trans_image();
which_scen();
exit(1);
}

int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) > 0)
{
keys = SDL_GetKeyState(NULL);

       if ( keys[SDLK_ESCAPE] )
            {
              exit(1);
            }

}
}

try this…

// process events.
SDL_Event event;
if (gSys->PollEvent(&event)) {
switch(event.type) {
case SDL_KEYDOWN:
if (SDL_GetKeyState(NULL)[SDLK_ESCAPE] == SDL_PRESSED)
exit(1);
}
}

Also, try using the event filter to drop event you are not interested
in.

-dv

// process events.
if (gSys->PollEvent(&event)) {

sorry this should have said:

if (SDL_PollEvent(...)) {

:)

the theory is what matters.

-dv