git » fp-git.git » commit a799c9a

definitly added animation system

author ecalot
2005-01-10 19:13:44 UTC
committer ecalot
2005-01-10 19:13:44 UTC
parent 2d88341d78fd17b3885e05d224ddcc082ddcc501

definitly added animation system

FP/src/Makefile +1 -1
FP/src/conf/anims.conf +7 -7
FP/src/conf/states/main.conf +0 -14
FP/src/include/anims.h +1 -1
FP/src/ker/states.c +1 -1
FP/src/ker/titles.c +48 -29
FP/src/res/anims.c +6 -8

diff --git a/FP/src/Makefile b/FP/src/Makefile
index 5c5f367..9349dac 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -239,7 +239,7 @@ include/res_conf_resources.h: conf/resources.conf conf/awk/res_conf_resources.aw
 
 include/states_conf.h: $(GENERATEDSTAHEADERS)
 
-include/states_conf_static.h: conf/awk/states_conf_static.awk
+include/states_conf_static.h: conf/awk/states_conf_static.awk conf/states/*.conf
 	$(INFO) Creating states list configuration file...
 	$(AWK) -f conf/awk/states_conf_static.awk conf/states/*.conf>include/states_conf_static.h
 
diff --git a/FP/src/conf/anims.conf b/FP/src/conf/anims.conf
index 764d519..2d5dd53 100644
--- a/FP/src/conf/anims.conf
+++ b/FP/src/conf/anims.conf
@@ -5,14 +5,14 @@
 #be drawn over the state animation.
 
 ANIMATION presentation 1000
-	#frame type     res                 Duration Layer  x  y
-	0      FIXEDIMG img_main_background 9        bottom 10 10
-	3      FIXEDIMG img_main_copyright  3        bottom 10 10
-	9      FIXEDIMG img_princess_room   infinite bottom left bottom #princess room
-	9      FIXEDIMG img_princess_bed    infinite bottom 98 124 #bed
-	9      FIXEDIMG img_princess_pillar infinite top    98 124 #pillar
+	#frame type     res                 Duration Layer  x    y
+	0      FIXEDIMG img_main_background 30       bottom left bottom
+	10     FIXEDIMG img_main_copyright  10       bottom 50   190
+	30     FIXEDIMG img_princess_room   infinite bottom left bottom #princess room
+	30     FIXEDIMG img_princess_bed    infinite bottom left 183    #bed
+	30     FIXEDIMG img_princess_pillar infinite top    188  124    #pillar
 	#frame type     res                 state    Location Floor   Mirror
-	#0     STATE    img_jaffar          jaffar   100      center  no
+	40     STATE    img_jaffar          jaffar   100      center  yes
 	#frame type     res
 	#0     MIDI     
 	#0     WAV      
diff --git a/FP/src/conf/states/main.conf b/FP/src/conf/states/main.conf
index eca9931..0a8880e 100644
--- a/FP/src/conf/states/main.conf
+++ b/FP/src/conf/states/main.conf
@@ -361,17 +361,3 @@ crouched:
 #			coruched
 #		animation
 #			120 p
-
-#title animations
-titlesjaffar:
-	action                      Say hi to the princess
-		conditions
-			none
-		next
-			exit jaffar
-		animation
-			1-20
-		steps
-			relative  0
-		mark
-			jaffar
diff --git a/FP/src/include/anims.h b/FP/src/include/anims.h
index 1d23b0a..7a9f0f1 100644
--- a/FP/src/include/anims.h
+++ b/FP/src/include/anims.h
@@ -63,7 +63,7 @@ typedef struct {
 } animSound;
 
 void animStart(int animId,int *qt,int *qf,int *qo);
-int animGetFrame(int* qf,int* qt,int* qo, animFixedimg* f,animState* t, animSound* o);
+int animGetFrame(int* qf,int* qt,int* qo, animFixedimg** f,animState** t, animSound** o);
 
 #endif
 
diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c
index 1099178..4420827 100644
--- a/FP/src/ker/states.c
+++ b/FP/src/ker/states.c
@@ -295,7 +295,7 @@ short stateUpdate(tKey* key, tObject* kid,tRoom* room) {
 */
 
 	
-	if (current->currentState<0) return current->currentState; /* if last state return exit code */
+	if (current->frame==1&&current->currentState<0) return current->currentState; /* if last frame of the last state, return exit code */
 	return flags;
 }
 
diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c
index 1934472..6d24451 100644
--- a/FP/src/ker/titles.c
+++ b/FP/src/ker/titles.c
@@ -48,7 +48,17 @@ typedef struct {
 	unsigned short y;
 } titleFixedimg;
 
-/* New source */
+tMenuOption getAction(tKey key) {
+	switch(key.actionPerformed) {
+	case quit:
+		return menuQuit;
+	case load:
+		return menuLoad;
+	default:
+		return menuStart;
+	}
+}
+
 tMenuOption playAnimation(int id) {
 	/* Declare variables */
 	int qf,            qt,              qo,                 i;
@@ -56,7 +66,7 @@ tMenuOption playAnimation(int id) {
 	titleFixedimg* fa; tObject*   ta; /*animSound* oa;*/
 	int activef=0;     int activet=0; /*int activeo=0;*/
 	int totalf,        totalt,          totalo;
-	
+	int* statesAlive;
 	tKey key=inputCreateKey();
 	tKey nullKey=inputCreateKey();
 
@@ -64,19 +74,24 @@ tMenuOption playAnimation(int id) {
 	animStart(id,&totalf,&totalt,&totalo);
 	fa=(titleFixedimg*)malloc(totalf*sizeof(titleFixedimg));
 	ta=(tObject*)malloc(totalt*sizeof(tObject));
+	statesAlive=(int*)malloc(totalt*sizeof(int));
 	/*oa=(animSound*)malloc(totalo*sizeof(animSound));*/
 
 	/* main animation kernel loop */
-	while (animGetFrame(&qf,&qt,&qo,f,t,o)) {
-		printf("f%d t%d o%d ",qf,qt,qo);
+	while (animGetFrame(&qf,&qt,&qo,&f,&t,&o)) {
+		/*printf("f%d t%d o%d\n",qf,qt,qo);*/
 		if (!inputGetEvent(&key)) {
 			/* key pressed */
 			printf("key pressed\n");
-			return menuQuit;
+			return getAction(key);
 		} else {
 			/* create new images/objects/sounds */
 			for (i=0;i<qf;i++) { /*images*/
 				fa[activef].img=resLoad(f[i].res);
+				if (!fa[activef].img) {
+					fprintf(stderr,"resource coudn't be loaded.");
+					return menuQuit;
+				}
 				fa[activef].y=f[i].y;
 				fa[activef].x=f[i].x;
 				fa[activef].layer=f[i].layer;
@@ -85,6 +100,7 @@ tMenuOption playAnimation(int id) {
 			}
 			for (i=0;i<qt;i++) { /*objects*/
 				ta[activet]=objectCreate(t[i].location,t[i].floor,DIR_LEFT,t[i].state,t[i].res,t[i].cacheMirror);
+				statesAlive[activet]=1;
 				activet++;
 			}
 /*		TODO: code sounds	
@@ -94,60 +110,65 @@ tMenuOption playAnimation(int id) {
 			}*/
 
 			outputClearScreen();
+
 			/* The bottom layer */
 			for (i=0;i<activef;i++) {
 				if (fa[i].layer==ANIMS_LAYERTYPE_BOTTOM)
 					outputDrawBitmap(fa[i].img->pFrames[0], fa[i].x, fa[i].y);
 			}
+			
 			/* move objects */
 			for (i=0;i<activet;i++) {
+				int exitCode=0;
 				/*TODO: detect exits */
-	  		objectMove(ta+i,nullKey,NULL);
-	  		objectDraw(ta[i]);
+				if (statesAlive[i]) {
+		  		exitCode=objectMove(ta+i,nullKey,NULL);
+		  		objectDraw(ta[i]);
+				}
+			
+				/* detect exited states and destroy them */
+				if (exitCode<0) { /* exit code detected */
+					printf("exit Code detected: i=%d exit=%d \n",i,exitCode);
+					objectFree(ta[i]);
+					statesAlive[i]=0; /* remember it is destroyed */
+				}
 			}
+			
 			/* The top layer */
 			for (i=0;i<activef;i++) {
-				if (fa[i].layer==ANIMS_LAYERTYPE_TOP)
+				if (fa[i].layer==ANIMS_LAYERTYPE_TOP) {
 					outputDrawBitmap(fa[i].img->pFrames[0], fa[i].x, fa[i].y);
+				}
 			}
 			outputUpdateScreen();
 
-			/* exited states and caducied backgrounds destruction */
-			for (i=0;i<activef;i++) {
-				printf("checking img=%d duration=%d\n",i,fa[i].duration);
+			/* caducied backgrounds destruction */
+			i=activef;
+			while(i) {
+				i--;
 				if (fa[i].duration) { /* if not 0 (infinite) */
 					fa[i].duration--;
 					if (!fa[i].duration) { /* time is over for this images */
 						activef--;
 						resFree(fa[i].img);
-						printf("salio %d\n",i);
 						fa[i]=fa[activef];
 					}
 				}
 			}	
 		}
 	}
-	/*void objectDraw(tObject kid);*/
-	for (i=0;i<activef;i++) objectFree(ta[i]);
+
+	for (i=0;i<activet;i++) if (statesAlive[i]) objectFree(ta[i]);
+	for (i=0;i<activef;i++) resFree(fa[i].img);
 	free(fa);
 	free(ta);
+	free(statesAlive);
 	/*free(oa);*/
 	return menuQuit;
 }
 
 /* Old source */
 
-tMenuOption getAction(tKey key) {
-	switch(key.actionPerformed) {
-	case quit:
-		return menuQuit;
-	case load:
-		return menuLoad;
-	default:
-		return menuStart;
-	}
-}
-
 tMenuOption sleep(int ticks) {
 	/* Wait ticks or a key is pressed if an action is thrown process it */
 	tKey key=inputCreateKey();
@@ -174,13 +195,11 @@ tMenuOption showTitles() {
  * returns 1 if the user has selected to load a saved game 
  * returns 2 if the user has selected to start the game
  */
-/*#define testing*/
+#define testing
 #ifdef testing
 	printf("Starting animation testing\n");
 				
-	playAnimation(ANIMS_ID_PRESENTATION);
-	printf("Finishing animation testing\n");
-	return menuQuit;
+	return playAnimation(ANIMS_ID_PRESENTATION);
 #else
 	tData *main_title;
 	/*tData *main_text;*/
diff --git a/FP/src/res/anims.c b/FP/src/res/anims.c
index a71af4c..42f3224 100644
--- a/FP/src/res/anims.c
+++ b/FP/src/res/anims.c
@@ -62,31 +62,29 @@ void animStart(int animId,int *qf,int *qt,int *qo) {
 	*qo=rec.soundSize;
 }
 
-int animGetFrame(int* qf,int* qt,int* qo, animFixedimg* f,animState* t, animSound* o) {
+int animGetFrame(int* qf,int* qt,int* qo, animFixedimg** f,animState** t, animSound** o) {
 	*qf=0;
 	*qt=0;
 	*qo=0;
-	f=fixedimg+rec.fixedimgStart;
-	t=state+rec.stateStart;
-	o=sound+rec.soundStart;
+	*f=fixedimg+rec.fixedimgStart;
+	*t=state+rec.stateStart;
+	*o=sound+rec.soundStart;
 	while (rec.fixedimgSize&&fixedimg[rec.fixedimgStart].frame==frame) {
 		rec.fixedimgSize--;
 		rec.fixedimgStart++;
 		(*qf)++;
-		printf("entro %d\n",*qf);
 	}
 	while (rec.stateSize&&state[rec.stateStart].frame==frame) {
 		rec.stateSize--;
 		rec.stateStart++;
-		(*qf)++;
+		(*qt)++;
 	}
 	while (rec.soundSize&&sound[rec.soundStart].frame==frame) {
 		rec.soundSize--;
 		rec.soundStart++;
-		(*qf)++;
+		(*qo)++;
 	}
 	frame++;
-	printf("frame=%d\n",frame);
 	return frame!=rec.animSize;
 }