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 -    num_windows = NUM_WINDOWS;
    1.52 -    window_w = WINDOW_W;
    1.53 -    window_h = WINDOW_H;
    1.54 -    while (argc > 1) {
    1.55 -        if (strcmp(argv[argc - 1], "-width") == 0) {
    1.56 -            window_w = atoi(argv[argc]);
    1.57 -            --argc;
    1.58 -        } else if (strcmp(argv[argc - 1], "-height") == 0) {
    1.59 -            window_h = atoi(argv[argc]);
    1.60 -            --argc;
    1.61 -        } else {
    1.62 -            fprintf(stderr, "Usage: %s [-width] [-height]\n", argv[0]);
    1.63 +        consumed = CommonArg(state, i);
    1.64 +        if (consumed == 0) {
    1.65 +            consumed = -1;
    1.66 +        }
    1.67 +        if (consumed < 0) {
    1.68 +            fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state));
    1.69              quit(1);
    1.70          }
    1.71 +        i += consumed;
    1.72 +    }
    1.73 +    if (!CommonInit(state)) {
    1.74 +        quit(2);
    1.75      }
    1.76  
    1.77 -    /* Create the windows */
    1.78 -    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
    1.79 -    if (!windows) {
    1.80 -        fprintf(stderr, "Out of memory!\n");
    1.81 -        quit(2);
    1.82 -    }
    1.83 -    for (i = 0; i < num_windows; ++i) {
    1.84 -        char title[32];
    1.85 -        int x, y;
    1.86 -
    1.87 -        SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
    1.88 -        if (i == 0) {
    1.89 -            x = SDL_WINDOWPOS_CENTERED;
    1.90 -            y = SDL_WINDOWPOS_CENTERED;
    1.91 -        } else {
    1.92 -            x = SDL_WINDOWPOS_UNDEFINED;
    1.93 -            y = SDL_WINDOWPOS_UNDEFINED;
    1.94 -        }
    1.95 -        windows[i] =
    1.96 -            SDL_CreateWindow(title, x, y, window_w, window_h,
    1.97 -                             SDL_WINDOW_SHOWN);
    1.98 -        if (!windows[i]) {
    1.99 -            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
   1.100 -            quit(2);
   1.101 -        }
   1.102 -    }
   1.103 -
   1.104 -    /* Loop, blitting sprites and waiting for a keystroke */
   1.105 +    /* Main render loop */
   1.106      done = 0;
   1.107      while (!done) {
   1.108          /* Check for events */
   1.109          while (SDL_PollEvent(&event)) {
   1.110 -            switch (event.type) {
   1.111 -            case SDL_KEYDOWN:
   1.112 -                /* Any keypress quits the app... */
   1.113 -            case SDL_QUIT:
   1.114 -                done = 1;
   1.115 -                break;
   1.116 -            default:
   1.117 -                break;
   1.118 -            }
   1.119 +            CommonEvent(state, &event, &done);
   1.120          }
   1.121      }
   1.122 -
   1.123      quit(0);
   1.124  }
   1.125