git » fp-git.git » commit f0de880

first working version: running animation read from dat

author ecalot
2004-07-17 20:41:42 UTC
committer ecalot
2004-07-17 20:41:42 UTC
parent e3deb19773be8b61d3b08f61b7eacaeafc79dc36

first working version: running animation read from dat

FP/src/include/output.h +12 -1
FP/src/ker/kernel.c +8 -3
FP/src/out/output.c +15 -9
FP/src/res/resources.c +5 -2

diff --git a/FP/src/include/output.h b/FP/src/include/output.h
index 8b2dcac..a1f6c99 100644
--- a/FP/src/include/output.h
+++ b/FP/src/include/output.h
@@ -40,6 +40,17 @@ output.h: Free Prince : Output Devices Handler
 
 #include <SDL/SDL.h>	/* SDL stuff */
 
+typedef struct tColor{
+	unsigned char r;
+	unsigned char g;
+	unsigned char b;
+}tColor;
+
+typedef struct tPalette{
+	int     colors;
+	tColor* color;
+}tPalette;
+
 /* Text Primitives*/
 void outputDrawText(int x, int y, const char *fmt, ...);
 void outputDrawMessage(const char* fmt, ...); 
@@ -51,7 +62,7 @@ void outputPlayMid(tMemory music); /* Starts the music reproduction and returns
 /* Graph */
 
  /* Graph: Primitives for resources module */
-void* outputLoadBitmap(const unsigned char* data, int size, const unsigned char* palette, int h,int w,int invert, int firstColorTransparent);
+void* outputLoadBitmap(const unsigned char* data, int size, const tPalette palette, int h,int w,int invert, int firstColorTransparent);
 	/* Returns an abstract object allocated in memory using the data information ti build it
 	* invert is 0 when no invertion is needed and non-zero when an inversion is performed
 	*/
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index b350388..7fe8fd0 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -47,8 +47,9 @@ int kernel(int optionflag,int level) {
 	
 	SDL_Surface *screen /* , *test */;
 	SDL_Event e;
-	int i;
+	int i,x;
 	tData* testResource;
+	tData* fondo;
 	
 	screen = outputInit();
 
@@ -58,6 +59,7 @@ int kernel(int optionflag,int level) {
 	}
 
 	testResource=resLoad(RES_ANIM_RUN_LEFT);
+	fondo=resLoad(RES_IMG_BACKGROUND);
 	if (!testResource) {
 		printf("The resource couldn't be loaded!\n");
 		exit(1);
@@ -70,16 +72,19 @@ int kernel(int optionflag,int level) {
 	);
 
 	i=0;
+	x=380;
 	while (1) {
 		if (SDL_PollEvent(&e)) {
 			if (e.type == SDL_QUIT) break;
 		}
 		outputClearScreen(screen);
-		outputDrawBitmap(screen, testResource->pFrames[i], 30, 30);
+		outputDrawBitmap(screen, fondo->pFrames[0], 0, 0);
+		outputDrawBitmap(screen, testResource->pFrames[i], x, 141);
 		outputUpdateScreen(screen);
 		i++;
 		SDL_Delay(50);
-		if (i>13) i =0;
+		x--;
+		if (i>10) i =0;
 	}
 
 	outputStop();
diff --git a/FP/src/out/output.c b/FP/src/out/output.c
index 101855b..5bb19db 100644
--- a/FP/src/out/output.c
+++ b/FP/src/out/output.c
@@ -70,7 +70,7 @@ void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
 /* Graphics: Primitives for resources module */
 void*
 outputLoadBitmap(const unsigned char* data, int size, 
-		const unsigned char* palette, int h, int w, int invert, 
+		const tPalette palette, int h, int w, int invert, 
 		int firstColorTransparent)
 {
  /* Returns an abstract object allocated in memory using the data 
@@ -79,24 +79,28 @@ outputLoadBitmap(const unsigned char* data, int size,
 
 	SDL_Surface* result;
 	int i,j;
-	SDL_Color colors[256];
+	SDL_Color* colors;
+
+	colors=(SDL_Color*)malloc(sizeof(SDL_Color)*palette.colors);
 
 	/* Fill colors with color information */
-	for(i=0;i<256;i++) {
-		colors[i].r=i;
-		colors[i].g=255-i;
-		colors[i].b=255-i;
+	for(i=0;i<palette.colors;i++) {
+		colors[i].r=palette.color[i].r<<2;
+		colors[i].g=palette.color[i].g<<2;
+		colors[i].b=palette.color[i].b<<2;
 	}
 
 	printf("outputLoadBitmap: I'm creating an SDL structure :p\n");
 	printf("outputLoadBitmap: invert=%d. transparent=%d. size=%d\n", invert, firstColorTransparent, size);
 
 	result = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, 0, 0, 0, 0);
+	SDL_SetColorKey(result, SDL_SRCCOLORKEY, 0);
+	printf("%d\n",firstColorTransparent);
 	if (!result) {
 		fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
 		return NULL;
 	}
-	SDL_SetPalette(result, SDL_LOGPAL, colors, 0, 256);
+	SDL_SetPalette(result, SDL_LOGPAL, colors, 0, palette.colors);
 
 	w = (w + 1) / 2;
 
@@ -108,9 +112,10 @@ outputLoadBitmap(const unsigned char* data, int size,
 		}
 	}
 
-	for (i = 0; i < result->w; i++) {
+	for (i = 0; i < w; i++) {
 		for (j = 0; j < result->h; j++) {
-			putpixel(result, i, j, *(data+j+i*size));
+			putpixel(result, i<<1, j, (data[i+j*w])>>4);
+			putpixel(result, (i<<1)+1, j, (data[i+j*w])&0x0f);
 		}
 	}
 	
@@ -118,6 +123,7 @@ outputLoadBitmap(const unsigned char* data, int size,
 		SDL_UnlockSurface(result);
 	}
 
+	free(colors);
 	return (void*)result;
 }
 
diff --git a/FP/src/res/resources.c b/FP/src/res/resources.c
index 61896b2..3b60314 100644
--- a/FP/src/res/resources.c
+++ b/FP/src/res/resources.c
@@ -77,7 +77,10 @@ tData* res_createData(int nFrames,int type) {
 void res_createFrames(tMemory data,int type,void** returnValue,int number) {
 	tMemory* result;
 	static tImage image;
-	
+	static tPalette palette;
+	palette.colors=16; /* TODO: detect when it is 2 colors */
+	palette.color=(tColor*)image.pal;
+
 	switch (type) {
 		case RES_TYPE_IMG_TR_LEFT:
 		case RES_TYPE_IMG_TR_RIGHT:
@@ -97,7 +100,7 @@ void res_createFrames(tMemory data,int type,void** returnValue,int number) {
 			mExpandGraphic(data.array,&image,data.size);
 			/* TODO: the result must be an object created in output module: */
 			result=(void*)outputLoadBitmap(
-				image.pix,image.widthInBytes*image.height,image.pal,image.height,image.width,
+				image.pix,image.widthInBytes*image.height,palette,image.height,image.width,
 				(type==RES_TYPE_IMG_TR_RIGHT||type==RES_TYPE_IMG_BL_RIGHT),
 				(type==RES_TYPE_IMG_TR_RIGHT||type==RES_TYPE_IMG_TR_LEFT)
 			);