test/testsprite.c
changeset 1895 c121d94672cb
parent 1516 4d241ea8a1cd
child 1907 06c27a737b7a
     1.1 --- a/test/testsprite.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/test/testsprite.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -1,10 +1,6 @@
     1.4  /* Simple program:  Move N sprites around on the screen as fast as possible */
     1.5  
     1.6 -#include <stdio.h>
     1.7  #include <stdlib.h>
     1.8 -#include <string.h>
     1.9 -#include <ctype.h>
    1.10 -#include <math.h>
    1.11  #include <time.h>
    1.12  
    1.13  #include "SDL.h"
    1.14 @@ -22,302 +18,300 @@
    1.15  Uint16 sprite_w, sprite_h;
    1.16  
    1.17  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.18 -static void quit(int rc)
    1.19 +static void
    1.20 +quit(int rc)
    1.21  {
    1.22 -	SDL_Quit();
    1.23 -	exit(rc);
    1.24 +    SDL_Quit();
    1.25 +    exit(rc);
    1.26  }
    1.27  
    1.28 -int LoadSprite(char *file)
    1.29 +int
    1.30 +LoadSprite(char *file)
    1.31  {
    1.32 -	SDL_Surface *temp;
    1.33 +    SDL_Surface *temp;
    1.34  
    1.35 -	/* Load the sprite image */
    1.36 -	sprite = SDL_LoadBMP(file);
    1.37 -	if ( sprite == NULL ) {
    1.38 -		fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
    1.39 -		return(-1);
    1.40 -	}
    1.41 +    /* Load the sprite image */
    1.42 +    sprite = SDL_LoadBMP(file);
    1.43 +    if (sprite == NULL) {
    1.44 +        fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
    1.45 +        return (-1);
    1.46 +    }
    1.47  
    1.48 -	/* Set transparent pixel as the pixel at (0,0) */
    1.49 -	if ( sprite->format->palette ) {
    1.50 -		SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL),
    1.51 -						*(Uint8 *)sprite->pixels);
    1.52 -	}
    1.53 +    /* Set transparent pixel as the pixel at (0,0) */
    1.54 +    if (sprite->format->palette) {
    1.55 +        SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
    1.56 +                        *(Uint8 *) sprite->pixels);
    1.57 +    }
    1.58  
    1.59 -	/* Convert sprite to video format */
    1.60 -	temp = SDL_DisplayFormat(sprite);
    1.61 -	SDL_FreeSurface(sprite);
    1.62 -	if ( temp == NULL ) {
    1.63 -		fprintf(stderr, "Couldn't convert background: %s\n",
    1.64 -							SDL_GetError());
    1.65 -		return(-1);
    1.66 -	}
    1.67 -	sprite = temp;
    1.68 +    /* Convert sprite to video format */
    1.69 +    temp = SDL_DisplayFormat(sprite);
    1.70 +    SDL_FreeSurface(sprite);
    1.71 +    if (temp == NULL) {
    1.72 +        fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError());
    1.73 +        return (-1);
    1.74 +    }
    1.75 +    sprite = temp;
    1.76  
    1.77 -	/* We're ready to roll. :) */
    1.78 -	return(0);
    1.79 +    /* We're ready to roll. :) */
    1.80 +    return (0);
    1.81  }
    1.82  
    1.83 -void MoveSprites(SDL_Surface *screen, Uint32 background)
    1.84 +void
    1.85 +MoveSprites(SDL_Surface * screen, Uint32 background)
    1.86  {
    1.87 -	int i, nupdates;
    1.88 -	SDL_Rect area, *position, *velocity;
    1.89 +    int i, nupdates;
    1.90 +    SDL_Rect area, *position, *velocity;
    1.91  
    1.92 -	nupdates = 0;
    1.93 -	/* Erase all the sprites if necessary */
    1.94 -	if ( sprites_visible ) {
    1.95 -		SDL_FillRect(screen, NULL, background);
    1.96 -	}
    1.97 +    nupdates = 0;
    1.98 +    /* Erase all the sprites if necessary */
    1.99 +    if (sprites_visible) {
   1.100 +        SDL_FillRect(screen, NULL, background);
   1.101 +    }
   1.102  
   1.103 -	/* Move the sprite, bounce at the wall, and draw */
   1.104 -	for ( i=0; i<numsprites; ++i ) {
   1.105 -		position = &positions[i];
   1.106 -		velocity = &velocities[i];
   1.107 -		position->x += velocity->x;
   1.108 -		if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
   1.109 -			velocity->x = -velocity->x;
   1.110 -			position->x += velocity->x;
   1.111 -		}
   1.112 -		position->y += velocity->y;
   1.113 -		if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
   1.114 -			velocity->y = -velocity->y;
   1.115 -			position->y += velocity->y;
   1.116 -		}
   1.117 +    /* Move the sprite, bounce at the wall, and draw */
   1.118 +    for (i = 0; i < numsprites; ++i) {
   1.119 +        position = &positions[i];
   1.120 +        velocity = &velocities[i];
   1.121 +        position->x += velocity->x;
   1.122 +        if ((position->x < 0) || (position->x >= (screen->w - sprite_w))) {
   1.123 +            velocity->x = -velocity->x;
   1.124 +            position->x += velocity->x;
   1.125 +        }
   1.126 +        position->y += velocity->y;
   1.127 +        if ((position->y < 0) || (position->y >= (screen->h - sprite_w))) {
   1.128 +            velocity->y = -velocity->y;
   1.129 +            position->y += velocity->y;
   1.130 +        }
   1.131  
   1.132 -		/* Blit the sprite onto the screen */
   1.133 -		area = *position;
   1.134 -		SDL_BlitSurface(sprite, NULL, screen, &area);
   1.135 -		sprite_rects[nupdates++] = area;
   1.136 -	}
   1.137 +        /* Blit the sprite onto the screen */
   1.138 +        area = *position;
   1.139 +        SDL_BlitSurface(sprite, NULL, screen, &area);
   1.140 +        sprite_rects[nupdates++] = area;
   1.141 +    }
   1.142  
   1.143 -	if (debug_flip) {
   1.144 -		if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.145 -			static int t = 0;
   1.146 +    if (debug_flip) {
   1.147 +        if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.148 +            static int t = 0;
   1.149  
   1.150 -			Uint32 color = SDL_MapRGB (screen->format, 255, 0, 0);
   1.151 -			SDL_Rect r;
   1.152 -			r.x = (sin((float)t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w-20);
   1.153 -			r.y = 0;
   1.154 -			r.w = 20;
   1.155 -			r.h = screen->h;
   1.156 +            Uint32 color = SDL_MapRGB(screen->format, 255, 0, 0);
   1.157 +            SDL_Rect r;
   1.158 +            r.x =
   1.159 +                (sin((float) t * 2 * 3.1459) + 1.0) / 2.0 * (screen->w - 20);
   1.160 +            r.y = 0;
   1.161 +            r.w = 20;
   1.162 +            r.h = screen->h;
   1.163  
   1.164 -			SDL_FillRect (screen, &r, color);
   1.165 -			t+=2;
   1.166 -		}
   1.167 -	}
   1.168 +            SDL_FillRect(screen, &r, color);
   1.169 +            t += 2;
   1.170 +        }
   1.171 +    }
   1.172  
   1.173 -	/* Update the screen! */
   1.174 -	if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.175 -		SDL_Flip(screen);
   1.176 -	} else {
   1.177 -		SDL_UpdateRects(screen, nupdates, sprite_rects);
   1.178 -	}
   1.179 -	sprites_visible = 1;
   1.180 +    /* Update the screen! */
   1.181 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.182 +        SDL_Flip(screen);
   1.183 +    } else {
   1.184 +        SDL_UpdateRects(screen, nupdates, sprite_rects);
   1.185 +    }
   1.186 +    sprites_visible = 1;
   1.187  }
   1.188  
   1.189  /* This is a way of telling whether or not to use hardware surfaces */
   1.190 -Uint32 FastestFlags(Uint32 flags, int width, int height, int bpp)
   1.191 +Uint32
   1.192 +FastestFlags(Uint32 flags, int width, int height, int bpp)
   1.193  {
   1.194 -	const SDL_VideoInfo *info;
   1.195 +    const SDL_VideoInfo *info;
   1.196  
   1.197 -	/* Hardware acceleration is only used in fullscreen mode */
   1.198 -	flags |= SDL_FULLSCREEN;
   1.199 +    /* Hardware acceleration is only used in fullscreen mode */
   1.200 +    flags |= SDL_FULLSCREEN;
   1.201  
   1.202 -	/* Check for various video capabilities */
   1.203 -	info = SDL_GetVideoInfo();
   1.204 -	if ( info->blit_hw_CC && info->blit_fill ) {
   1.205 -		/* We use accelerated colorkeying and color filling */
   1.206 -		flags |= SDL_HWSURFACE;
   1.207 -	}
   1.208 -	/* If we have enough video memory, and will use accelerated
   1.209 -	   blits directly to it, then use page flipping.
   1.210 -	 */
   1.211 -	if ( (flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.212 -		/* Direct hardware blitting without double-buffering
   1.213 -		   causes really bad flickering.
   1.214 -		 */
   1.215 -		if ( info->video_mem*1024 > (height*width*bpp/8) ) {
   1.216 -			flags |= SDL_DOUBLEBUF;
   1.217 -		} else {
   1.218 -			flags &= ~SDL_HWSURFACE;
   1.219 -		}
   1.220 -	}
   1.221 +    /* Check for various video capabilities */
   1.222 +    info = SDL_GetVideoInfo();
   1.223 +    if (info->blit_hw_CC && info->blit_fill) {
   1.224 +        /* We use accelerated colorkeying and color filling */
   1.225 +        flags |= SDL_HWSURFACE;
   1.226 +    }
   1.227 +    /* If we have enough video memory, and will use accelerated
   1.228 +       blits directly to it, then use page flipping.
   1.229 +     */
   1.230 +    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.231 +        /* Direct hardware blitting without double-buffering
   1.232 +           causes really bad flickering.
   1.233 +         */
   1.234 +        if (info->video_mem * 1024 > (height * width * bpp / 8)) {
   1.235 +            flags |= SDL_DOUBLEBUF;
   1.236 +        } else {
   1.237 +            flags &= ~SDL_HWSURFACE;
   1.238 +        }
   1.239 +    }
   1.240  
   1.241 -	/* Return the flags */
   1.242 -	return(flags);
   1.243 +    /* Return the flags */
   1.244 +    return (flags);
   1.245  }
   1.246  
   1.247 -int main(int argc, char *argv[])
   1.248 +int
   1.249 +main(int argc, char *argv[])
   1.250  {
   1.251 -	SDL_Surface *screen;
   1.252 -	Uint8 *mem;
   1.253 -	int width, height;
   1.254 -	Uint8  video_bpp;
   1.255 -	Uint32 videoflags;
   1.256 -	Uint32 background;
   1.257 -	int    i, done;
   1.258 -	SDL_Event event;
   1.259 -	Uint32 then, now, frames;
   1.260 +    SDL_Surface *screen;
   1.261 +    Uint8 *mem;
   1.262 +    int width, height;
   1.263 +    Uint8 video_bpp;
   1.264 +    Uint32 videoflags;
   1.265 +    Uint32 background;
   1.266 +    int i, done;
   1.267 +    SDL_Event event;
   1.268 +    Uint32 then, now, frames;
   1.269  
   1.270 -	/* Initialize SDL */
   1.271 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.272 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
   1.273 -		return(1);
   1.274 -	}
   1.275 +    /* Initialize SDL */
   1.276 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   1.277 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.278 +        return (1);
   1.279 +    }
   1.280  
   1.281 -	numsprites = NUM_SPRITES;
   1.282 -	videoflags = SDL_SWSURFACE|SDL_ANYFORMAT;
   1.283 -	width = 640;
   1.284 -	height = 480;
   1.285 -	video_bpp = 8;
   1.286 -	debug_flip = 0;
   1.287 -	while ( argc > 1 ) {
   1.288 -		--argc;
   1.289 -		if ( strcmp(argv[argc-1], "-width") == 0 ) {
   1.290 -			width = atoi(argv[argc]);
   1.291 -			--argc;
   1.292 -		} else
   1.293 -		if ( strcmp(argv[argc-1], "-height") == 0 ) {
   1.294 -			height = atoi(argv[argc]);
   1.295 -			--argc;
   1.296 -		} else
   1.297 -		if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
   1.298 -			video_bpp = atoi(argv[argc]);
   1.299 -			videoflags &= ~SDL_ANYFORMAT;
   1.300 -			--argc;
   1.301 -		} else
   1.302 -		if ( strcmp(argv[argc], "-fast") == 0 ) {
   1.303 -			videoflags = FastestFlags(videoflags, width, height, video_bpp);
   1.304 -		} else
   1.305 -		if ( strcmp(argv[argc], "-hw") == 0 ) {
   1.306 -			videoflags ^= SDL_HWSURFACE;
   1.307 -		} else
   1.308 -		if ( strcmp(argv[argc], "-flip") == 0 ) {
   1.309 -			videoflags ^= SDL_DOUBLEBUF;
   1.310 -		} else
   1.311 -		if ( strcmp(argv[argc], "-debugflip") == 0 ) {
   1.312 -			debug_flip ^= 1;
   1.313 -		} else
   1.314 -		if ( strcmp(argv[argc], "-fullscreen") == 0 ) {
   1.315 -			videoflags ^= SDL_FULLSCREEN;
   1.316 -		} else
   1.317 -		if ( isdigit(argv[argc][0]) ) {
   1.318 -			numsprites = atoi(argv[argc]);
   1.319 -		} else {
   1.320 -			fprintf(stderr, 
   1.321 -	"Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
   1.322 -								argv[0]);
   1.323 -			quit(1);
   1.324 -		}
   1.325 -	}
   1.326 +    numsprites = NUM_SPRITES;
   1.327 +    videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
   1.328 +    width = 640;
   1.329 +    height = 480;
   1.330 +    video_bpp = 8;
   1.331 +    debug_flip = 0;
   1.332 +    while (argc > 1) {
   1.333 +        --argc;
   1.334 +        if (strcmp(argv[argc - 1], "-width") == 0) {
   1.335 +            width = atoi(argv[argc]);
   1.336 +            --argc;
   1.337 +        } else if (strcmp(argv[argc - 1], "-height") == 0) {
   1.338 +            height = atoi(argv[argc]);
   1.339 +            --argc;
   1.340 +        } else if (strcmp(argv[argc - 1], "-bpp") == 0) {
   1.341 +            video_bpp = atoi(argv[argc]);
   1.342 +            videoflags &= ~SDL_ANYFORMAT;
   1.343 +            --argc;
   1.344 +        } else if (strcmp(argv[argc], "-fast") == 0) {
   1.345 +            videoflags = FastestFlags(videoflags, width, height, video_bpp);
   1.346 +        } else if (strcmp(argv[argc], "-hw") == 0) {
   1.347 +            videoflags ^= SDL_HWSURFACE;
   1.348 +        } else if (strcmp(argv[argc], "-flip") == 0) {
   1.349 +            videoflags ^= SDL_DOUBLEBUF;
   1.350 +        } else if (strcmp(argv[argc], "-debugflip") == 0) {
   1.351 +            debug_flip ^= 1;
   1.352 +        } else if (strcmp(argv[argc], "-fullscreen") == 0) {
   1.353 +            videoflags ^= SDL_FULLSCREEN;
   1.354 +        } else if (isdigit(argv[argc][0])) {
   1.355 +            numsprites = atoi(argv[argc]);
   1.356 +        } else {
   1.357 +            fprintf(stderr,
   1.358 +                    "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n",
   1.359 +                    argv[0]);
   1.360 +            quit(1);
   1.361 +        }
   1.362 +    }
   1.363  
   1.364 -	/* Set video mode */
   1.365 -	screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
   1.366 -	if ( ! screen ) {
   1.367 -		fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
   1.368 -					width, height, SDL_GetError());
   1.369 -		quit(2);
   1.370 -	}
   1.371 +    /* Set video mode */
   1.372 +    screen = SDL_SetVideoMode(width, height, video_bpp, videoflags);
   1.373 +    if (!screen) {
   1.374 +        fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
   1.375 +                width, height, SDL_GetError());
   1.376 +        quit(2);
   1.377 +    }
   1.378  
   1.379 -	/* Load the sprite */
   1.380 -	if ( LoadSprite("icon.bmp") < 0 ) {
   1.381 -		quit(1);
   1.382 -	}
   1.383 +    /* Load the sprite */
   1.384 +    if (LoadSprite("icon.bmp") < 0) {
   1.385 +        quit(1);
   1.386 +    }
   1.387  
   1.388 -	/* Allocate memory for the sprite info */
   1.389 -	mem = (Uint8 *)malloc(4*sizeof(SDL_Rect)*numsprites);
   1.390 -	if ( mem == NULL ) {
   1.391 -		SDL_FreeSurface(sprite);
   1.392 -		fprintf(stderr, "Out of memory!\n");
   1.393 -		quit(2);
   1.394 -	}
   1.395 -	sprite_rects = (SDL_Rect *)mem;
   1.396 -	positions = sprite_rects;
   1.397 -	sprite_rects += numsprites;
   1.398 -	velocities = sprite_rects;
   1.399 -	sprite_rects += numsprites;
   1.400 -	sprite_w = sprite->w;
   1.401 -	sprite_h = sprite->h;
   1.402 -	srand(time(NULL));
   1.403 -	for ( i=0; i<numsprites; ++i ) {
   1.404 -		positions[i].x = rand()%(screen->w - sprite_w);
   1.405 -		positions[i].y = rand()%(screen->h - sprite_h);
   1.406 -		positions[i].w = sprite->w;
   1.407 -		positions[i].h = sprite->h;
   1.408 -		velocities[i].x = 0;
   1.409 -		velocities[i].y = 0;
   1.410 -		while ( ! velocities[i].x && ! velocities[i].y ) {
   1.411 -			velocities[i].x = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
   1.412 -			velocities[i].y = (rand()%(MAX_SPEED*2+1))-MAX_SPEED;
   1.413 -		}
   1.414 -	}
   1.415 -	background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
   1.416 +    /* Allocate memory for the sprite info */
   1.417 +    mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
   1.418 +    if (mem == NULL) {
   1.419 +        SDL_FreeSurface(sprite);
   1.420 +        fprintf(stderr, "Out of memory!\n");
   1.421 +        quit(2);
   1.422 +    }
   1.423 +    sprite_rects = (SDL_Rect *) mem;
   1.424 +    positions = sprite_rects;
   1.425 +    sprite_rects += numsprites;
   1.426 +    velocities = sprite_rects;
   1.427 +    sprite_rects += numsprites;
   1.428 +    sprite_w = sprite->w;
   1.429 +    sprite_h = sprite->h;
   1.430 +    srand(time(NULL));
   1.431 +    for (i = 0; i < numsprites; ++i) {
   1.432 +        positions[i].x = rand() % (screen->w - sprite_w);
   1.433 +        positions[i].y = rand() % (screen->h - sprite_h);
   1.434 +        positions[i].w = sprite->w;
   1.435 +        positions[i].h = sprite->h;
   1.436 +        velocities[i].x = 0;
   1.437 +        velocities[i].y = 0;
   1.438 +        while (!velocities[i].x && !velocities[i].y) {
   1.439 +            velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   1.440 +            velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
   1.441 +        }
   1.442 +    }
   1.443 +    background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
   1.444  
   1.445 -	/* Print out information about our surfaces */
   1.446 -	printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel);
   1.447 -	if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.448 -		printf("Screen is in video memory\n");
   1.449 -	} else {
   1.450 -		printf("Screen is in system memory\n");
   1.451 -	}
   1.452 -	if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
   1.453 -		printf("Screen has double-buffering enabled\n");
   1.454 -	}
   1.455 -	if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) {
   1.456 -		printf("Sprite is in video memory\n");
   1.457 -	} else {
   1.458 -		printf("Sprite is in system memory\n");
   1.459 -	}
   1.460 -	/* Run a sample blit to trigger blit acceleration */
   1.461 -	{ SDL_Rect dst;
   1.462 -		dst.x = 0;
   1.463 -		dst.y = 0;
   1.464 -		dst.w = sprite->w;
   1.465 -		dst.h = sprite->h;
   1.466 -		SDL_BlitSurface(sprite, NULL, screen, &dst);
   1.467 -		SDL_FillRect(screen, &dst, background);
   1.468 -	}
   1.469 -	if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) {
   1.470 -		printf("Sprite blit uses hardware acceleration\n");
   1.471 -	}
   1.472 -	if ( (sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) {
   1.473 -		printf("Sprite blit uses RLE acceleration\n");
   1.474 -	}
   1.475 +    /* Print out information about our surfaces */
   1.476 +    printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel);
   1.477 +    if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.478 +        printf("Screen is in video memory\n");
   1.479 +    } else {
   1.480 +        printf("Screen is in system memory\n");
   1.481 +    }
   1.482 +    if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
   1.483 +        printf("Screen has double-buffering enabled\n");
   1.484 +    }
   1.485 +    if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   1.486 +        printf("Sprite is in video memory\n");
   1.487 +    } else {
   1.488 +        printf("Sprite is in system memory\n");
   1.489 +    }
   1.490 +    /* Run a sample blit to trigger blit acceleration */
   1.491 +    {
   1.492 +        SDL_Rect dst;
   1.493 +        dst.x = 0;
   1.494 +        dst.y = 0;
   1.495 +        dst.w = sprite->w;
   1.496 +        dst.h = sprite->h;
   1.497 +        SDL_BlitSurface(sprite, NULL, screen, &dst);
   1.498 +        SDL_FillRect(screen, &dst, background);
   1.499 +    }
   1.500 +    if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) {
   1.501 +        printf("Sprite blit uses hardware acceleration\n");
   1.502 +    }
   1.503 +    if ((sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
   1.504 +        printf("Sprite blit uses RLE acceleration\n");
   1.505 +    }
   1.506  
   1.507 -	/* Loop, blitting sprites and waiting for a keystroke */
   1.508 -	frames = 0;
   1.509 -	then = SDL_GetTicks();
   1.510 -	done = 0;
   1.511 -	sprites_visible = 0;
   1.512 -	while ( !done ) {
   1.513 -		/* Check for events */
   1.514 -		++frames;
   1.515 -		while ( SDL_PollEvent(&event) ) {
   1.516 -			switch (event.type) {
   1.517 -				case SDL_MOUSEBUTTONDOWN:
   1.518 -					SDL_WarpMouse(screen->w/2, screen->h/2);
   1.519 -					break;
   1.520 -				case SDL_KEYDOWN:
   1.521 -					/* Any keypress quits the app... */
   1.522 -				case SDL_QUIT:
   1.523 -					done = 1;
   1.524 -					break;
   1.525 -				default:
   1.526 -					break;
   1.527 -			}
   1.528 -		}
   1.529 -		MoveSprites(screen, background);
   1.530 -	}
   1.531 -	SDL_FreeSurface(sprite);
   1.532 -	free(mem);
   1.533 +    /* Loop, blitting sprites and waiting for a keystroke */
   1.534 +    frames = 0;
   1.535 +    then = SDL_GetTicks();
   1.536 +    done = 0;
   1.537 +    sprites_visible = 0;
   1.538 +    while (!done) {
   1.539 +        /* Check for events */
   1.540 +        ++frames;
   1.541 +        while (SDL_PollEvent(&event)) {
   1.542 +            switch (event.type) {
   1.543 +            case SDL_MOUSEBUTTONDOWN:
   1.544 +                SDL_WarpMouse(screen->w / 2, screen->h / 2);
   1.545 +                break;
   1.546 +            case SDL_KEYDOWN:
   1.547 +                /* Any keypress quits the app... */
   1.548 +            case SDL_QUIT:
   1.549 +                done = 1;
   1.550 +                break;
   1.551 +            default:
   1.552 +                break;
   1.553 +            }
   1.554 +        }
   1.555 +        MoveSprites(screen, background);
   1.556 +    }
   1.557 +    SDL_FreeSurface(sprite);
   1.558 +    free(mem);
   1.559  
   1.560 -	/* Print out some timing information */
   1.561 -	now = SDL_GetTicks();
   1.562 -	if ( now > then ) {
   1.563 -		printf("%2.2f frames per second\n",
   1.564 -					((double)frames*1000)/(now-then));
   1.565 -	}
   1.566 -	SDL_Quit();
   1.567 -	return(0);
   1.568 +    /* Print out some timing information */
   1.569 +    now = SDL_GetTicks();
   1.570 +    if (now > then) {
   1.571 +        printf("%2.2f frames per second\n",
   1.572 +               ((double) frames * 1000) / (now - then));
   1.573 +    }
   1.574 +    SDL_Quit();
   1.575 +    return (0);
   1.576  }