git » fp-git.git » commit a656c35

version 0.3. new kid kernel using states added. the game now is a bit broken.

author ecalot
2004-10-21 22:23:18 UTC
committer ecalot
2004-10-21 22:23:18 UTC
parent 1c3e73f2713b2b3f140cd8d3e1a0be4ac964c11d

version 0.3. new kid kernel using states added. the game now is a bit broken.

FP/doc/CHANGELOG +2 -2
FP/src/Makefile +3 -1
FP/src/conf/awk/states_conf_static.awk +3 -2
FP/src/conf/states/main.conf +7 -7
FP/src/include/kernel.h +1 -1
FP/src/include/states.h +2 -2
FP/src/include/types.h +7 -4
FP/src/ker/kid.c +19 -8
FP/src/ker/object.c +19 -8
FP/src/ker/states.c +75 -22

diff --git a/FP/doc/CHANGELOG b/FP/doc/CHANGELOG
index 4bddddb..3dc75c5 100644
--- a/FP/doc/CHANGELOG
+++ b/FP/doc/CHANGELOG
@@ -9,7 +9,7 @@ Versions
  - Rebuilt kernel
  - Hard Coded Movements support
  - Tested OS X and Windows ports
-
-* 0.3
  - Window Caption
 
+* 0.3
+ - Reboult kernel to support configuration files
diff --git a/FP/src/Makefile b/FP/src/Makefile
index 88e598e..e847e36 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -148,7 +148,9 @@ room.o: ker/room.c include/room.h include/resources.h include/res_conf.h
 	$(INFO) Compiling kernel room object...
 	$(CC) -c ker/room.c $(OPTIONS)
 
-kid.o: ker/kid.c include/kid.h include/resources.h include/res_conf.h
+kid.o: ker/kid.c include/kid.h include/resources.h include/res_conf.h\
+       include/states.h include/states_conf.h include/res_conf.h\
+       include/types.h include/tiles.h include/tiles_conf.h
 	$(INFO) Compiling kernel kid object...
 	$(CC) -c ker/kid.c $(OPTIONS)
 
diff --git a/FP/src/conf/awk/states_conf_static.awk b/FP/src/conf/awk/states_conf_static.awk
index 2a73192..f6ceccb 100644
--- a/FP/src/conf/awk/states_conf_static.awk
+++ b/FP/src/conf/awk/states_conf_static.awk
@@ -33,6 +33,7 @@ BEGIN {
 	currentAction=0
 	printf("#define STATES_MOVETYPES_RELATIVE 0\n")
 	printf("#define STATES_MOVETYPES_ABSOLUTEFORWARD 1\n\n")
+	printf("#define STATES_MOVETYPES_RELATIVETURN 2\n\n")
 	printf("#define STATES_CONDITIONS {\\\n")
 	tmp="conf/statesproperties.conf"
 	while ((getline line < tmp) > 0) {
@@ -85,7 +86,7 @@ BEGIN {
 						split($1,a,"-")
 						for (g=a[1];g<=a[2];g++) {
 							arrayAnimation[currentAnimation,"frame"]=g
-							arrayAnimation[currentAnimation,"flags"]=""
+							arrayAnimation[currentAnimation,"flags"]=$2
 							currentAnimation++
 						}
 					} else {
@@ -205,7 +206,7 @@ END {
 			coma2=""
 			flagmask=""
 			for (j=1;j<=length(flags);j++) {
-				c=substr(flags,j,j+1)
+				c=substr(flags,j,1)
 				flagmask=sprintf("%s%sSTATES_FLAG_%s",flagmask,coma2,toupper(c))
 				coma2="|"
 			}
diff --git a/FP/src/conf/states/main.conf b/FP/src/conf/states/main.conf
index a013d14..6231920 100644
--- a/FP/src/conf/states/main.conf
+++ b/FP/src/conf/states/main.conf
@@ -39,15 +39,13 @@ normal:
 			relative 10
 		animation
 			134-145	
-		level
-			1
 	action            Turn
 		conditions
 			KeyBack                pressed
 		next
 			normal
 		steps
-			relative 0
+			relativeTurn 0
 		animation
 			45-52
 	action            Jump
@@ -57,9 +55,9 @@ normal:
 		next
 			normal
 		animation
-			16-27
-			28 p
-			29-38
+			16-27 
+			28 ps
+			29-33 p
 		steps
 			relative 20
 	action            If there aren't more actions then the normal state is kept
@@ -68,9 +66,11 @@ normal:
 		next
 			normal
 		animation
-			15
+			15 p
 		steps
 			relative 0
+		level
+			1
 
 
 oldnormal:
diff --git a/FP/src/include/kernel.h b/FP/src/include/kernel.h
index c3c672e..56a94b4 100644
--- a/FP/src/include/kernel.h
+++ b/FP/src/include/kernel.h
@@ -43,7 +43,7 @@ kernel.h: Princed Resources : Resource Handler headers
 #define hasFlag(a) (optionflag&(a))
 #define setFlag(a) optionflag|=(a)
 
-#define FP_VERSION "0.2-pre-alpha"
+#define FP_VERSION "0.3-pre-alpha"
 
 int kernel(int optionflag,int level);
 /* level=-1 is default
diff --git a/FP/src/include/states.h b/FP/src/include/states.h
index 3ade7e0..c0faf79 100644
--- a/FP/src/include/states.h
+++ b/FP/src/include/states.h
@@ -10,7 +10,7 @@ typedef enum {esLast=0,esKeyUp,esKeyDown,esKeyForward,esKeyBack,esKeyShift,esMap
 
 
 typedef enum {esDangerous,esNone,esWalk,esPotion,esSword,esMirror,esNotApplicable=0}tsTileType;
-typedef enum {esRelative,esForwardTile}tsMoveType; /*  */
+typedef enum {esRelative,esForwardTile,esRelativeTurn}tsMoveType; /*  */
 
 typedef struct {
 	tsConditionType type;
@@ -30,7 +30,7 @@ typedef struct {
 
 /* This function should return the image frame
  * and actions to be performed by this call */
-int stateUpdate(tState* current,tKey* key, tKid* kid,tRoom* room,short* flags);
+int stateUpdate(tKey* key, tKid* kid,tRoom* room,short* flags);
 
 /* Create a State depending on the level */
 tState createState(int level);
diff --git a/FP/src/include/types.h b/FP/src/include/types.h
index 38b7dda..3577ba5 100644
--- a/FP/src/include/types.h
+++ b/FP/src/include/types.h
@@ -47,6 +47,8 @@ typedef enum {eDrop,eRaise}tPressableType;
 typedef struct { /* The state object: only struct that is not static to the state class */
 	short  frame; /* when zero, animation is released and the next state is taken */
 	short* animation;
+	short* animOffset;
+	short* flags;
 	short  currentState;
 } tState;
 
@@ -127,10 +129,11 @@ typedef struct {
 	int location;
 	int floor;
 	int direction;
-	int frame;
-	int velocity;
-	enum {stay,run}nextAction;
-	tData* action;
+	void* frame;
+	/*int velocity;*/
+	/*enum {stay,run}nextAction;*/
+	/*tData* action;*/
+	tState action;
 } tKid;
 
 typedef enum {eLeft=0,eRight=1,eUp=2,eDown=3}tDirection;
diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c
index 338592b..8c5e270 100644
--- a/FP/src/ker/kid.c
+++ b/FP/src/ker/kid.c
@@ -36,8 +36,9 @@ kid.h: Free Prince : Kid object
 #include "room.h"
 #include "maps.h" /* getTile */
 #include <stdio.h> /* NULL */
+#include "states.h"
 
-/*#define NEW_KERNEL*/
+#define NEW_KERNEL
 
 static struct {
 #ifdef NEW_KERNEL
@@ -58,8 +59,8 @@ static struct {
 
 void loadGfx() {
 #ifdef NEW_KERNEL
-	kidGfx.kid[DIR_LEFT]=resLoad(RES_IMG_KID_ALL);
-	kidGfx.kid[DIR_RIGHT]=resLoad(RES_IMG_KID_ALL|RES_MODS_INVERT);
+	kidGfx.kid[DIR_LEFT]=resLoad(RES_IMG_ALL_KID);
+	kidGfx.kid[DIR_RIGHT]=resLoad(RES_IMG_ALL_KID|RES_MODS_INVERT);
 #else
 	kidGfx.turning[DIR_LEFT]=resLoad(RES_ANIM_TURNING);
 	kidGfx.turning[DIR_RIGHT]=resLoad(RES_ANIM_TURNING|RES_MODS_INVERT);
@@ -116,23 +117,33 @@ void kidFree() {
 tKid kidCreate() {
 	tKid kid;
 
-	if (kidGfx.turning[0]==NULL) loadGfx();
+	if (kidGfx.kid[0]==NULL) loadGfx();
 
 	kid.location=100;
 	kid.floor=0;
 	kid.direction=DIR_LEFT;
-	kid.frame=0;
+/*	kid.frame=0;
 	kid.action=kidGfx.normal[DIR_LEFT];
 	kid.nextAction=stay;
 	kid.velocity=0;
+*/
+	kid.action=createState(1); /* level 1 */
 	return kid;
 }
 
 void kidDraw(tKid kid) {
-	outputDrawBitmap(kid.action->pFrames[kid.frame],kid.location,58+kid.floor*TILE_H); /* TODO: use TILE_H */
+	outputDrawBitmap(kid.frame,kid.location,58+kid.floor*TILE_H); /* TODO: change location value in a lower layer*/
 }
 
 int kidMove(tKid* kid,tKey key,tRoom* room) {
+#ifdef NEW_KERNEL
+	short flags;
+	int index=stateUpdate(&key,kid,room,&flags)-1;
+	printf("index=%d\n",index);
+	kid->frame=kidGfx.kid[kid->direction]->pFrames[index];
+	/* TODO: stateUpdate should return flags and edit kid->frame by it's own */
+	printf("flags=%x (%d)\n",flags,flags);
+#else
 	int result;
 	tTile tile;
 	/* Returns 1 if the action is done
@@ -285,7 +296,7 @@ int kidMove(tKid* kid,tKey key,tRoom* room) {
 		*room=mapGetRoom((void*)(room->level),room->links[eDown]);
 		kid->floor=0;
 	}
-
-	return result;
+#endif
+	return 1/*result*/;
 }
 
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c
index 338592b..8c5e270 100644
--- a/FP/src/ker/object.c
+++ b/FP/src/ker/object.c
@@ -36,8 +36,9 @@ kid.h: Free Prince : Kid object
 #include "room.h"
 #include "maps.h" /* getTile */
 #include <stdio.h> /* NULL */
+#include "states.h"
 
-/*#define NEW_KERNEL*/
+#define NEW_KERNEL
 
 static struct {
 #ifdef NEW_KERNEL
@@ -58,8 +59,8 @@ static struct {
 
 void loadGfx() {
 #ifdef NEW_KERNEL
-	kidGfx.kid[DIR_LEFT]=resLoad(RES_IMG_KID_ALL);
-	kidGfx.kid[DIR_RIGHT]=resLoad(RES_IMG_KID_ALL|RES_MODS_INVERT);
+	kidGfx.kid[DIR_LEFT]=resLoad(RES_IMG_ALL_KID);
+	kidGfx.kid[DIR_RIGHT]=resLoad(RES_IMG_ALL_KID|RES_MODS_INVERT);
 #else
 	kidGfx.turning[DIR_LEFT]=resLoad(RES_ANIM_TURNING);
 	kidGfx.turning[DIR_RIGHT]=resLoad(RES_ANIM_TURNING|RES_MODS_INVERT);
@@ -116,23 +117,33 @@ void kidFree() {
 tKid kidCreate() {
 	tKid kid;
 
-	if (kidGfx.turning[0]==NULL) loadGfx();
+	if (kidGfx.kid[0]==NULL) loadGfx();
 
 	kid.location=100;
 	kid.floor=0;
 	kid.direction=DIR_LEFT;
-	kid.frame=0;
+/*	kid.frame=0;
 	kid.action=kidGfx.normal[DIR_LEFT];
 	kid.nextAction=stay;
 	kid.velocity=0;
+*/
+	kid.action=createState(1); /* level 1 */
 	return kid;
 }
 
 void kidDraw(tKid kid) {
-	outputDrawBitmap(kid.action->pFrames[kid.frame],kid.location,58+kid.floor*TILE_H); /* TODO: use TILE_H */
+	outputDrawBitmap(kid.frame,kid.location,58+kid.floor*TILE_H); /* TODO: change location value in a lower layer*/
 }
 
 int kidMove(tKid* kid,tKey key,tRoom* room) {
+#ifdef NEW_KERNEL
+	short flags;
+	int index=stateUpdate(&key,kid,room,&flags)-1;
+	printf("index=%d\n",index);
+	kid->frame=kidGfx.kid[kid->direction]->pFrames[index];
+	/* TODO: stateUpdate should return flags and edit kid->frame by it's own */
+	printf("flags=%x (%d)\n",flags,flags);
+#else
 	int result;
 	tTile tile;
 	/* Returns 1 if the action is done
@@ -285,7 +296,7 @@ int kidMove(tKid* kid,tKey key,tRoom* room) {
 		*room=mapGetRoom((void*)(room->level),room->links[eDown]);
 		kid->floor=0;
 	}
-
-	return result;
+#endif
+	return 1/*result*/;
 }
 
diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c
index a16bcb2..7a2521a 100644
--- a/FP/src/ker/states.c
+++ b/FP/src/ker/states.c
@@ -1,24 +1,31 @@
 #include "states.h"
 #include <stdlib.h>
 #include "tiles.h" /* isInGroup & groups */
+#include <stdio.h> /* For debug purposes */
+#include "kid.h" /* DIR_LEFT DIR_RIGHT */
 
 /* Private static state graph */
 static tsAction statesActionList[]=STATES_ACTIONS;
 static short statesAnimationList[]=STATES_ANIMATIONS;
 static tsCondition statesConditionList[]=STATES_CONDITIONS;
 
-short* stateGetAnimation(int action,short *frames) {
+short* stateGetAnimation(int action,short *frames,short** flags,float* offsets) {
 	short* result;
 	tsAction* a=statesActionList+action;
 	short i=a->animSize;
-	short* j=statesAnimationList+a->animStart;
+	short* j=statesAnimationList+(a->animStart*2);
+	short totaloffset=a->moveOffset;
 	/* TODO: depending on relative and absolute crop the middle frames */
 	*frames=i;
-	i<<=1;
 	result=(short*)malloc(sizeof(short)*i);
-	while (i) {
-		result[i--]=*(j++);
-		result[i--]=*(j++); /* result[i] is a flag and doesn't have to be evaluated */
+	*flags =(short*)malloc(sizeof(short)*i);
+	printf("animsize=%d animstart=%d\n",i,a->animStart);
+	*offsets=(float)(totaloffset)/(float)(*frames); /* the second short is the flag */
+	while (i--) {
+		printf ("copiando animacion=%d ",result[i]=*j);
+		j++;
+		printf("flag=%d j=%p\n",((*flags)[i])=*j,(void*)j); /* the second short is the flag */
+		j++;
 	}
 	return result;
 }
@@ -27,7 +34,8 @@ short* stateGetAnimation(int action,short *frames) {
 tState createState(int level) {
 	tState start;
 	static short statesLevelList[]=STATES_LEVELS;
-	start.animation=stateGetAnimation(statesLevelList[level],&(start.frame));
+	float step;
+	start.animation=stateGetAnimation(statesLevelList[level],&(start.frame),&(start.flags),&step);
 	start.currentState=statesActionList[statesLevelList[level]].nextStateId;
 	return start;
 }
@@ -38,7 +46,7 @@ tState createState(int level) {
 int evaluateCondition(int condition,tKey* key, tKid* kid, tRoom* room) {
 	tsCondition c=statesConditionList[condition];
 	int thisTile=kid->location/32+1+12*kid->floor;
-	int whereInTile=(kid->direction==eLeft)?(kid->location%32):32-(kid->location%32);
+	int whereInTile=(kid->direction==DIR_LEFT)?(kid->location%32):32-(kid->location%32);
 	switch(c.type) {
 	case esKeyUp:
 		return inputGetUp(key->status)? /* TODO: argument notPressed isn't supported */
@@ -47,10 +55,10 @@ int evaluateCondition(int condition,tKey* key, tKid* kid, tRoom* room) {
 		return inputGetDown(key->status)?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyForward:
-		return ((kid->direction==eLeft)?inputGetLeft(key->status):inputGetRight(key->status))?
+		return ((kid->direction==DIR_LEFT)?inputGetLeft(key->status):inputGetRight(key->status))?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyBack:
-		return ((kid->direction==eLeft)?inputGetRight(key->status):inputGetLeft(key->status))?
+		return ((kid->direction==DIR_LEFT)?inputGetRight(key->status):inputGetLeft(key->status))?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esKeyShift:
 		return inputGetShift(key->status)?
@@ -62,10 +70,10 @@ int evaluateCondition(int condition,tKey* key, tKid* kid, tRoom* room) {
 		return isInGroup(room->fore[thisTile+12],c.argument)?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapForward:
-		return isInGroup(room->fore[thisTile+((kid->direction==eLeft)?-1:1)],c.argument)?
+		return isInGroup(room->fore[thisTile+((kid->direction==DIR_LEFT)?-1:1)],c.argument)?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapBack:
-		return isInGroup(room->fore[thisTile+((kid->direction==eLeft)?1:-1)],c.argument)?
+		return isInGroup(room->fore[thisTile+((kid->direction==DIR_LEFT)?1:-1)],c.argument)?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esMapOn:
 		return isInGroup(room->fore[thisTile],c.argument)?
@@ -83,8 +91,8 @@ int evaluateCondition(int condition,tKey* key, tKid* kid, tRoom* room) {
 		return (room->level->levelNumber==c.argument)?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esForwardChangeToScreen:
-		return ((kid->direction==eLeft)&&(thisTile==1))
-			||((kid->direction==eRight)&&(thisTile==10))?
+		return ((kid->direction==DIR_LEFT)&&(thisTile==1))
+			||((kid->direction==DIR_RIGHT)&&(thisTile==10))?
 			STATES_CONDRESULT_TRUE:STATES_CONDRESULT_FALSE;
 	case esLast:
 		return STATES_CONDRESULT_END;
@@ -111,18 +119,63 @@ int evaluateState(int state, tKey* key, tKid* kid, tRoom* room) {
 
 /* This function should return the image frame and actions to be performed by this call
  * returns the animation number corresponding to this frame */
-int stateUpdate(tState* current,tKey* key, tKid* kid,tRoom* room,short* flags) {
-	int imageFrame=statesAnimationList[current->animation[(current->frame<<1)+0]];
-	*flags        =statesAnimationList[current->animation[(current->frame<<1)+1]];
-	if (current->frame) {
-		current->frame--;
-	} else {
+int stateUpdate(tKey* key, tKid* kid,tRoom* room,short* flags) {
+	tState* current=&(kid->action);
+	static float step;
+	static float acumLocation;
+	int imageFrame;
+
+	current->frame--;
+	
+	imageFrame    =current->animation[current->frame];
+	*flags        =current->flags    [current->frame];
+	printf("stateUpdate: animation=%d flags=%d\n",imageFrame,*flags);
+	/*printf("currentframe=%d\n",current->frame)*/
+	if (!current->frame) {
 		int action;
-		/* free(current->animation) */
+		free(current->animation);
+		free(current->flags);
+		/* Find matching action */
 		action=evaluateState(current->currentState,key,kid,room);
-		current->animation=stateGetAnimation(action,&(current->frame));
+
+		/* Performs the events called by this action */
+			/* Remember the animation and flags for the next current->frame frames */
+		current->animation=stateGetAnimation(action,&(current->frame),&(current->flags),&step);
+			/* Remember the state where we are now */
 		current->currentState=statesActionList[action].nextStateId;
+			/* Move the kid (turn+traslate) */
+		if (kid->direction==DIR_LEFT) {
+			step=-step;
+			switch(statesActionList[action].moveType) {
+			case STATES_MOVETYPES_RELATIVE:
+				kid->location-=statesActionList[action].moveOffset;
+				break;
+			case STATES_MOVETYPES_ABSOLUTEFORWARD:
+				kid->location=kid->location-(kid->location%32);
+				break;
+			case STATES_MOVETYPES_RELATIVETURN:
+				kid->location-=statesActionList[action].moveOffset;
+				kid->direction=DIR_RIGHT;
+				break;
+			}
+		} else {
+			switch(statesActionList[action].moveType) {
+			case STATES_MOVETYPES_RELATIVE:
+				kid->location+=statesActionList[action].moveOffset;
+				break;
+			case STATES_MOVETYPES_ABSOLUTEFORWARD:
+				kid->location=32+kid->location-(kid->location%32);
+				break;
+			case STATES_MOVETYPES_RELATIVETURN:
+				kid->location+=statesActionList[action].moveOffset;
+				kid->direction=DIR_LEFT;
+				break;
+			}
+		}
+		acumLocation=kid->location;
 	}
+	acumLocation+=step;
+	kid->location=acumLocation;
 	return imageFrame;
 }