More sprite-work in the render driver, and some updates to the nds-test-progs. gsoc2008_nds
authorDarren Alton <dalton@stevens.edu>
Sat, 16 Aug 2008 12:58:36 +0000
branchgsoc2008_nds
changeset 2694c1c7cb1b5a47
parent 2693 bae97b6ac32b
child 2695 c04a266c277a
More sprite-work in the render driver, and some updates to the nds-test-progs.
src/video/nds/SDL_ndsrender.c
test/nds-test-progs/general/source/main.c
test/nds-test-progs/sprite/source/testsprite.c
test/nds-test-progs/sprite2/source/testsprite2.c
     1.1 --- a/src/video/nds/SDL_ndsrender.c	Sat Aug 16 12:08:12 2008 +0000
     1.2 +++ b/src/video/nds/SDL_ndsrender.c	Sat Aug 16 12:58:36 2008 +0000
     1.3 @@ -341,10 +341,22 @@
     1.4              sprent->objMode = OBJMODE_BITMAP;
     1.5              sprent->posX = 0; sprent->posY = 0;
     1.6              sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */
     1.7 +
     1.8 +            /* the first 32 sprites get transformation matrices.
     1.9 +               first come, first served */
    1.10              if(whichspr < MATRIX_COUNT) {
    1.11                  sprent->isRotoscale = 1;
    1.12                  sprent->rsMatrixIdx = whichspr;
    1.13              }
    1.14 +
    1.15 +            sprent->objShape = OBJSHAPE_SQUARE;
    1.16 +            if(texture->w/2 >= texture->h) {
    1.17 +                sprent->objShape = OBJSHAPE_WIDE;
    1.18 +            } else if(texture->h/2 >= texture->w) {
    1.19 +                sprent->objShape = OBJSHAPE_TALL;
    1.20 +            }
    1.21 +        } else {
    1.22 +            SDL_SetError("Out of NDS sprites.");
    1.23          }
    1.24      } else if(texture->w <= 256 && texture->h <= 256) {
    1.25          int whichbg = -1, base = 0;
    1.26 @@ -385,7 +397,6 @@
    1.27              /*txdat->size = txdat->dim.pitch * texture->h;*/
    1.28          } else {
    1.29              SDL_SetError("Out of NDS backgrounds.");
    1.30 -            printf("ran out.\n");
    1.31          }
    1.32      } else {
    1.33          SDL_SetError("Texture too big for NDS hardware.");
    1.34 @@ -393,7 +404,6 @@
    1.35  
    1.36      TRACE("-NDS_CreateTexture\n");
    1.37      if (!texture->driverdata) {
    1.38 -        SDL_SetError("Couldn't create NDS render driver data.");
    1.39          return -1;
    1.40      }
    1.41  
     2.1 --- a/test/nds-test-progs/general/source/main.c	Sat Aug 16 12:08:12 2008 +0000
     2.2 +++ b/test/nds-test-progs/general/source/main.c	Sat Aug 16 12:58:36 2008 +0000
     2.3 @@ -2,13 +2,26 @@
     2.4  #include <SDL/SDL.h>
     2.5  #if defined(NDS) || defined(__NDS__) || defined (__NDS)
     2.6  #include <nds.h>
     2.7 +#include <fat.h>
     2.8  #else
     2.9  #define swiWaitForVBlank() 
    2.10  #define consoleDemoInit() 
    2.11 +#define fatInitDefault() 
    2.12  #define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
    2.13  #endif
    2.14  
    2.15 -void delay(int s) {
    2.16 +void splash(SDL_Surface *screen, int s) {
    2.17 +	SDL_Surface *logo;
    2.18 +	SDL_Rect area = {0,0,256,192};
    2.19 +
    2.20 +	logo = SDL_LoadBMP("sdl.bmp");
    2.21 +	if(!logo) {
    2.22 +		printf("Couldn't splash.\n");
    2.23 +		return;
    2.24 +	}
    2.25 +	/*logo->flags &= ~SDL_PREALLOC;*/
    2.26 +	SDL_BlitSurface(logo, NULL, screen, &area);
    2.27 +	SDL_Flip(screen);
    2.28  	while(s-- > 0) {
    2.29  		int i = 60;
    2.30  		while(--i) swiWaitForVBlank();
    2.31 @@ -22,7 +35,8 @@
    2.32  	SDL_Rect rect = {8,8,240,176};
    2.33  	int i;
    2.34  
    2.35 -	consoleDemoInit();
    2.36 +	consoleDemoInit(); puts("Hello world!  Initializing FAT...");
    2.37 +	fatInitDefault();
    2.38  	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) {
    2.39  		puts("# error initializing SDL");
    2.40  		puts(SDL_GetError());
    2.41 @@ -44,6 +58,9 @@
    2.42  //		return 3;
    2.43  	}
    2.44  	puts("* opened joystick");
    2.45 +
    2.46 +	/*splash(screen, 3);*/
    2.47 +
    2.48  	SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
    2.49  	SDL_Flip(screen);
    2.50  
    2.51 @@ -66,7 +83,7 @@
    2.52  			break;
    2.53  			default: break;
    2.54  		}
    2.55 -		printf("joy_%d\n", event.jbutton.which);
    2.56 +		printf("joy_%d, at %d\n", event.jbutton.which, SDL_GetTicks());
    2.57  		SDL_Flip(screen);
    2.58  		break;
    2.59  		case SDL_QUIT: SDL_Quit(); return 0;
     3.1 --- a/test/nds-test-progs/sprite/source/testsprite.c	Sat Aug 16 12:08:12 2008 +0000
     3.2 +++ b/test/nds-test-progs/sprite/source/testsprite.c	Sat Aug 16 12:58:36 2008 +0000
     3.3 @@ -7,7 +7,7 @@
     3.4  #include <fat.h>
     3.5  #include <SDL/SDL.h>
     3.6  
     3.7 -#define NUM_SPRITES	100
     3.8 +#define NUM_SPRITES	10
     3.9  #define MAX_SPEED 	1
    3.10  
    3.11  SDL_Surface *sprite;
    3.12 @@ -162,18 +162,21 @@
    3.13      int i, done;
    3.14      SDL_Event event;
    3.15      Uint32 then, now, frames;
    3.16 +
    3.17 +    consoleDemoInit(); puts("Hello world!  Initializing FAT...");
    3.18      fatInitDefault();
    3.19      /* Initialize SDL */
    3.20      if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    3.21          fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    3.22          return (1);
    3.23      }
    3.24 +    puts("* initialized SDL");
    3.25  
    3.26      numsprites = NUM_SPRITES;
    3.27 -    videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
    3.28 -    width = 640;
    3.29 -    height = 480;
    3.30 -    video_bpp = 8;
    3.31 +    videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT*/;
    3.32 +    width = 256;
    3.33 +    height = 192;
    3.34 +    video_bpp = 15;
    3.35      debug_flip = 0;
    3.36      while (argc > 1) {
    3.37          --argc;
    3.38 @@ -214,11 +217,14 @@
    3.39                  width, height, SDL_GetError());
    3.40          quit(2);
    3.41      }
    3.42 +    screen->flags &= ~SDL_PREALLOC;
    3.43 +    puts("* set video mode");
    3.44  
    3.45      /* Load the sprite */
    3.46      if (LoadSprite("icon.bmp") < 0) {
    3.47          quit(1);
    3.48      }
    3.49 +    puts("* loaded sprite");
    3.50  
    3.51      /* Allocate memory for the sprite info */
    3.52      mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
    3.53 @@ -286,25 +292,15 @@
    3.54      then = SDL_GetTicks();
    3.55      done = 0;
    3.56      sprites_visible = 0;
    3.57 +    puts("hello!");
    3.58      while (!done) {
    3.59          /* Check for events */
    3.60          ++frames;
    3.61 -        while (SDL_PollEvent(&event)) {
    3.62 -            switch (event.type) {
    3.63 -            case SDL_MOUSEBUTTONDOWN:
    3.64 -                SDL_WarpMouse(screen->w / 2, screen->h / 2);
    3.65 -                break;
    3.66 -            case SDL_KEYDOWN:
    3.67 -                /* Any keypress quits the app... */
    3.68 -            case SDL_QUIT:
    3.69 -                done = 1;
    3.70 -                break;
    3.71 -            default:
    3.72 -                break;
    3.73 -            }
    3.74 -        }
    3.75 +        printf(".");
    3.76 +        swiWaitForVBlank();
    3.77          MoveSprites(screen, background);
    3.78      }
    3.79 +    puts("goodbye!");
    3.80      SDL_FreeSurface(sprite);
    3.81      free(mem);
    3.82  
     4.1 --- a/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Aug 16 12:08:12 2008 +0000
     4.2 +++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Aug 16 12:58:36 2008 +0000
     4.3 @@ -7,7 +7,7 @@
     4.4  #include <fat.h>
     4.5  #include "common.h"
     4.6  
     4.7 -#define NUM_SPRITES	100
     4.8 +#define NUM_SPRITES	10
     4.9  #define MAX_SPEED 	1
    4.10  
    4.11  static CommonState *state;
    4.12 @@ -149,7 +149,10 @@
    4.13      int i, done;
    4.14      SDL_Event event;
    4.15      Uint32 then, now, frames;
    4.16 +
    4.17 +    consoleDemoInit(); puts("Hello world!  Initializing FAT...");
    4.18      fatInitDefault();
    4.19 +
    4.20      /* Initialize parameters */
    4.21      num_sprites = NUM_SPRITES;
    4.22