test/testwm2.c
changeset 1933 7ee5297340f7
parent 1895 c121d94672cb
child 1985 8055185ae4ed
     1.1 --- a/test/testwm2.c	Sun Jul 23 09:16:14 2006 +0000
     1.2 +++ b/test/testwm2.c	Mon Jul 24 05:03:02 2006 +0000
     1.3 @@ -1,98 +1,56 @@
     1.4 -/* Simple program:  Move N sprites around on the screen as fast as possible */
     1.5  
     1.6 -#include "SDL.h"
     1.7 +#include <stdlib.h>
     1.8 +#include <stdio.h>
     1.9  
    1.10 -#define NUM_WINDOWS 2
    1.11 -#define WINDOW_W    640
    1.12 -#define WINDOW_H    480
    1.13 +#include "common.h"
    1.14  
    1.15 -static int num_windows;
    1.16 -static SDL_WindowID *windows;
    1.17 +static CommonState *state;
    1.18  
    1.19  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.20  static void
    1.21  quit(int rc)
    1.22  {
    1.23 -    if (windows) {
    1.24 -        SDL_free(windows);
    1.25 -    }
    1.26 -    SDL_Quit();
    1.27 +    CommonQuit(state);
    1.28      exit(rc);
    1.29  }
    1.30  
    1.31  int
    1.32  main(int argc, char *argv[])
    1.33  {
    1.34 -    int window_w, window_h;
    1.35      int i, done;
    1.36      SDL_Event event;
    1.37  
    1.38 -    /* Initialize SDL */
    1.39 -    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.40 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    1.41 -        return (1);
    1.42 +    /* Initialize test framework */
    1.43 +    state = CommonCreateState(argv, SDL_INIT_VIDEO);
    1.44 +    if (!state) {
    1.45 +        return 1;
    1.46 +    }
    1.47 +    state->skip_renderer = SDL_TRUE;
    1.48 +    for (i = 1; i < argc;) {
    1.49 +        int consumed;
    1.50 +
    1.51 +        consumed = CommonArg(state, i);
    1.52 +        if (consumed == 0) {
    1.53 +            consumed = -1;
    1.54 +        }
    1.55 +        if (consumed < 0) {
    1.56 +            fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state));
    1.57 +            quit(1);
    1.58 +        }
    1.59 +        i += consumed;
    1.60 +    }
    1.61 +    if (!CommonInit(state)) {
    1.62 +        quit(2);
    1.63      }
    1.64  
    1.65 -    num_windows = NUM_WINDOWS;
    1.66 -    window_w = WINDOW_W;
    1.67 -    window_h = WINDOW_H;
    1.68 -    while (argc > 1) {
    1.69 -        if (strcmp(argv[argc - 1], "-width") == 0) {
    1.70 -            window_w = atoi(argv[argc]);
    1.71 -            --argc;
    1.72 -        } else if (strcmp(argv[argc - 1], "-height") == 0) {
    1.73 -            window_h = atoi(argv[argc]);
    1.74 -            --argc;
    1.75 -        } else {
    1.76 -            fprintf(stderr, "Usage: %s [-width] [-height]\n", argv[0]);
    1.77 -            quit(1);
    1.78 -        }
    1.79 -    }
    1.80 -
    1.81 -    /* Create the windows */
    1.82 -    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
    1.83 -    if (!windows) {
    1.84 -        fprintf(stderr, "Out of memory!\n");
    1.85 -        quit(2);
    1.86 -    }
    1.87 -    for (i = 0; i < num_windows; ++i) {
    1.88 -        char title[32];
    1.89 -        int x, y;
    1.90 -
    1.91 -        SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
    1.92 -        if (i == 0) {
    1.93 -            x = SDL_WINDOWPOS_CENTERED;
    1.94 -            y = SDL_WINDOWPOS_CENTERED;
    1.95 -        } else {
    1.96 -            x = SDL_WINDOWPOS_UNDEFINED;
    1.97 -            y = SDL_WINDOWPOS_UNDEFINED;
    1.98 -        }
    1.99 -        windows[i] =
   1.100 -            SDL_CreateWindow(title, x, y, window_w, window_h,
   1.101 -                             SDL_WINDOW_SHOWN);
   1.102 -        if (!windows[i]) {
   1.103 -            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
   1.104 -            quit(2);
   1.105 -        }
   1.106 -    }
   1.107 -
   1.108 -    /* Loop, blitting sprites and waiting for a keystroke */
   1.109 +    /* Main render loop */
   1.110      done = 0;
   1.111      while (!done) {
   1.112          /* Check for events */
   1.113          while (SDL_PollEvent(&event)) {
   1.114 -            switch (event.type) {
   1.115 -            case SDL_KEYDOWN:
   1.116 -                /* Any keypress quits the app... */
   1.117 -            case SDL_QUIT:
   1.118 -                done = 1;
   1.119 -                break;
   1.120 -            default:
   1.121 -                break;
   1.122 -            }
   1.123 +            CommonEvent(state, &event, &done);
   1.124          }
   1.125      }
   1.126 -
   1.127      quit(0);
   1.128  }
   1.129