changeset 2694:c1c7cb1b5a47 gsoc2008_nds

More sprite-work in the render driver, and some updates to the nds-test-progs.
author Darren Alton <dalton@stevens.edu>
date Sat, 16 Aug 2008 12:58:36 +0000
parents bae97b6ac32b
children c04a266c277a
files 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
diffstat 4 files changed, 51 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/nds/SDL_ndsrender.c	Sat Aug 16 12:08:12 2008 +0000
+++ b/src/video/nds/SDL_ndsrender.c	Sat Aug 16 12:58:36 2008 +0000
@@ -341,10 +341,22 @@
             sprent->objMode = OBJMODE_BITMAP;
             sprent->posX = 0; sprent->posY = 0;
             sprent->colMode = OBJCOLOR_16; /* OBJCOLOR_256 for INDEX8 */
+
+            /* the first 32 sprites get transformation matrices.
+               first come, first served */
             if(whichspr < MATRIX_COUNT) {
                 sprent->isRotoscale = 1;
                 sprent->rsMatrixIdx = whichspr;
             }
+
+            sprent->objShape = OBJSHAPE_SQUARE;
+            if(texture->w/2 >= texture->h) {
+                sprent->objShape = OBJSHAPE_WIDE;
+            } else if(texture->h/2 >= texture->w) {
+                sprent->objShape = OBJSHAPE_TALL;
+            }
+        } else {
+            SDL_SetError("Out of NDS sprites.");
         }
     } else if(texture->w <= 256 && texture->h <= 256) {
         int whichbg = -1, base = 0;
@@ -385,7 +397,6 @@
             /*txdat->size = txdat->dim.pitch * texture->h;*/
         } else {
             SDL_SetError("Out of NDS backgrounds.");
-            printf("ran out.\n");
         }
     } else {
         SDL_SetError("Texture too big for NDS hardware.");
@@ -393,7 +404,6 @@
 
     TRACE("-NDS_CreateTexture\n");
     if (!texture->driverdata) {
-        SDL_SetError("Couldn't create NDS render driver data.");
         return -1;
     }
 
--- a/test/nds-test-progs/general/source/main.c	Sat Aug 16 12:08:12 2008 +0000
+++ b/test/nds-test-progs/general/source/main.c	Sat Aug 16 12:58:36 2008 +0000
@@ -2,13 +2,26 @@
 #include <SDL/SDL.h>
 #if defined(NDS) || defined(__NDS__) || defined (__NDS)
 #include <nds.h>
+#include <fat.h>
 #else
 #define swiWaitForVBlank() 
 #define consoleDemoInit() 
+#define fatInitDefault() 
 #define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
 #endif
 
-void delay(int s) {
+void splash(SDL_Surface *screen, int s) {
+	SDL_Surface *logo;
+	SDL_Rect area = {0,0,256,192};
+
+	logo = SDL_LoadBMP("sdl.bmp");
+	if(!logo) {
+		printf("Couldn't splash.\n");
+		return;
+	}
+	/*logo->flags &= ~SDL_PREALLOC;*/
+	SDL_BlitSurface(logo, NULL, screen, &area);
+	SDL_Flip(screen);
 	while(s-- > 0) {
 		int i = 60;
 		while(--i) swiWaitForVBlank();
@@ -22,7 +35,8 @@
 	SDL_Rect rect = {8,8,240,176};
 	int i;
 
-	consoleDemoInit();
+	consoleDemoInit(); puts("Hello world!  Initializing FAT...");
+	fatInitDefault();
 	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) {
 		puts("# error initializing SDL");
 		puts(SDL_GetError());
@@ -44,6 +58,9 @@
 //		return 3;
 	}
 	puts("* opened joystick");
+
+	/*splash(screen, 3);*/
+
 	SDL_FillRect(screen, &rect, RGB15(0,0,31)|0x8000);
 	SDL_Flip(screen);
 
@@ -66,7 +83,7 @@
 			break;
 			default: break;
 		}
-		printf("joy_%d\n", event.jbutton.which);
+		printf("joy_%d, at %d\n", event.jbutton.which, SDL_GetTicks());
 		SDL_Flip(screen);
 		break;
 		case SDL_QUIT: SDL_Quit(); return 0;
--- a/test/nds-test-progs/sprite/source/testsprite.c	Sat Aug 16 12:08:12 2008 +0000
+++ b/test/nds-test-progs/sprite/source/testsprite.c	Sat Aug 16 12:58:36 2008 +0000
@@ -7,7 +7,7 @@
 #include <fat.h>
 #include <SDL/SDL.h>
 
-#define NUM_SPRITES	100
+#define NUM_SPRITES	10
 #define MAX_SPEED 	1
 
 SDL_Surface *sprite;
@@ -162,18 +162,21 @@
     int i, done;
     SDL_Event event;
     Uint32 then, now, frames;
+
+    consoleDemoInit(); puts("Hello world!  Initializing FAT...");
     fatInitDefault();
     /* Initialize SDL */
     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
         return (1);
     }
+    puts("* initialized SDL");
 
     numsprites = NUM_SPRITES;
-    videoflags = SDL_SWSURFACE | SDL_ANYFORMAT;
-    width = 640;
-    height = 480;
-    video_bpp = 8;
+    videoflags = SDL_SWSURFACE /*| SDL_ANYFORMAT*/;
+    width = 256;
+    height = 192;
+    video_bpp = 15;
     debug_flip = 0;
     while (argc > 1) {
         --argc;
@@ -214,11 +217,14 @@
                 width, height, SDL_GetError());
         quit(2);
     }
+    screen->flags &= ~SDL_PREALLOC;
+    puts("* set video mode");
 
     /* Load the sprite */
     if (LoadSprite("icon.bmp") < 0) {
         quit(1);
     }
+    puts("* loaded sprite");
 
     /* Allocate memory for the sprite info */
     mem = (Uint8 *) malloc(4 * sizeof(SDL_Rect) * numsprites);
@@ -286,25 +292,15 @@
     then = SDL_GetTicks();
     done = 0;
     sprites_visible = 0;
+    puts("hello!");
     while (!done) {
         /* Check for events */
         ++frames;
-        while (SDL_PollEvent(&event)) {
-            switch (event.type) {
-            case SDL_MOUSEBUTTONDOWN:
-                SDL_WarpMouse(screen->w / 2, screen->h / 2);
-                break;
-            case SDL_KEYDOWN:
-                /* Any keypress quits the app... */
-            case SDL_QUIT:
-                done = 1;
-                break;
-            default:
-                break;
-            }
-        }
+        printf(".");
+        swiWaitForVBlank();
         MoveSprites(screen, background);
     }
+    puts("goodbye!");
     SDL_FreeSurface(sprite);
     free(mem);
 
--- a/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Aug 16 12:08:12 2008 +0000
+++ b/test/nds-test-progs/sprite2/source/testsprite2.c	Sat Aug 16 12:58:36 2008 +0000
@@ -7,7 +7,7 @@
 #include <fat.h>
 #include "common.h"
 
-#define NUM_SPRITES	100
+#define NUM_SPRITES	10
 #define MAX_SPEED 	1
 
 static CommonState *state;
@@ -149,7 +149,10 @@
     int i, done;
     SDL_Event event;
     Uint32 then, now, frames;
+
+    consoleDemoInit(); puts("Hello world!  Initializing FAT...");
     fatInitDefault();
+
     /* Initialize parameters */
     num_sprites = NUM_SPRITES;