git » fp-git.git » commit d9df0e6

modified the object object primitives to receive allways a pointer. Added objectInterrupt. Renamed stateInterrupt to stateReset.

author ecalot
2005-02-23 14:46:20 UTC
committer ecalot
2005-02-23 14:46:20 UTC
parent 4b6b981a76e3975a9cdc22bc4ca446eb2fb52e5c

modified the object object primitives to receive allways a pointer. Added objectInterrupt. Renamed stateInterrupt to stateReset.

FP/src/include/object.h +4 -3
FP/src/include/states.h +4 -4
FP/src/ker/kernel.c +2 -2
FP/src/ker/object.c +11 -7
FP/src/ker/states.c +1 -1
FP/src/ker/titles.c +3 -3

diff --git a/FP/src/include/object.h b/FP/src/include/object.h
index a368df5..581e0ba 100644
--- a/FP/src/include/object.h
+++ b/FP/src/include/object.h
@@ -40,14 +40,15 @@ kid.h: Free Prince : Generic objects
 #define DIR_LEFT  1
 #define DIR_RIGHT 0
 
-#define object_getLocation(object,image) ((object).location/*-(outputGetWidth(image)>>1)*/)
+#define object_getLocation(object,image) ((object)->location/*-(outputGetWidth(image)>>1)*/)
 
 #include "types.h"
 
 tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type);
-void objectDraw(tObject obj);
+void objectDraw(tObject* obj);
 int  objectMove(tObject* obj,tKey key,tRoom* room);
-void objectFree(tObject obj);
+void objectInterrupt(tObject* obj,short action);
+void objectFree(tObject* obj);
 
 #endif
 
diff --git a/FP/src/include/states.h b/FP/src/include/states.h
index 04839b9..fe04ead 100644
--- a/FP/src/include/states.h
+++ b/FP/src/include/states.h
@@ -27,9 +27,9 @@ typedef struct {
 	short        animSize; /* number of frames to be shown */
 } tsAction;
 
-#define stateGetImage(a) (((a).action.image))
-#define stateGetBottom(a) (((a).action.imgoffx))
-#define stateGetMirror(a) (((a).action.mirror))
+#define stateGetImage(a) (((a)->action.image))
+#define stateGetBottom(a) (((a)->action.imgoffx))
+#define stateGetMirror(a) (((a)->action.mirror))
 
 /* public functions interface */
 
@@ -55,7 +55,7 @@ short stateUpdate(tKey* key, tObject* kid,tRoom* room);
 /* Create a State depending on the level */
 int stateKidInLevel(int level);
 tState stateCreate(short stateId);
-void stateInterrupt(tState* state, short stateId);
+void stateReset(tState* state, short stateId);
 void stateFree(tState* state);
 
 #include "states_conf.h"
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index bde9873..beca3cc 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -95,7 +95,7 @@ int playgame(int optionflag,int level) {
 				outputClearScreen(); /* TODO: send to drawBackground() */
 				roomDrawBackground(&room);
 				kidDrawLives(&kid);
-				objectDraw(kid);
+				objectDraw(&kid);
 				roomDrawForeground(&room);
 				/* if dead */
 				if (flags&STATES_FLAG_X) {
@@ -233,7 +233,7 @@ int kernel(int optionflag,int level) {
 		}
 	} while(!quit);
 
-	objectFree(kid); /*TODO: exiting from the story will cause a game crash because this object wasn't allocated*/
+	objectFree(&kid); /*TODO: exiting from the story will cause a game crash because this object wasn't allocated*/
 	inputStopTimer();
 	outputStop();
 	return 0;
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c
index 595b1a9..c3a8105 100644
--- a/FP/src/ker/object.c
+++ b/FP/src/ker/object.c
@@ -47,10 +47,14 @@ void loadGfx(int storeMirrored, tData** gfxCache, unsigned long resId) {
 		gfxCache[DIR_RIGHT]=NULL;
 }
 
-void objectFree(tObject obj) {
-	resFree(obj.gfxCache[DIR_LEFT]);
-	if (obj.gfxCache[DIR_RIGHT]) resFree(obj.gfxCache[DIR_RIGHT]);
-	stateFree(&obj.action);
+void objectFree(tObject* obj) {
+	resFree(obj->gfxCache[DIR_LEFT]);
+	if (obj->gfxCache[DIR_RIGHT]) resFree(obj->gfxCache[DIR_RIGHT]);
+	stateFree(&obj->action);
+}
+
+void objectInterrupt(tObject* obj,short action) {
+	stateReset(&obj->action,action);
 }
 
 /* TODO: make a function in maps.c that calls this one for the kid */
@@ -71,13 +75,13 @@ tObject objectCreate(int location, int floor, int direction, int stateId, unsign
 	return object;
 }
 
-void objectDraw(tObject object) {
-	void* image=object.gfxCache[object.direction ^ stateGetMirror(object)]->pFrames[stateGetImage(object)-1];
+void objectDraw(tObject* object) {
+	void* image=object->gfxCache[object->direction ^ stateGetMirror(object)]->pFrames[stateGetImage(object)-1];
 	/* TODO: move this -1 to each script frame */
 	outputDrawBitmap(
 		image, 
 		object_getLocation(object,image),
-		58-stateGetBottom(object)+object.floor*TILE_H
+		58-stateGetBottom(object)+object->floor*TILE_H
 	);
 }
 
diff --git a/FP/src/ker/states.c b/FP/src/ker/states.c
index 79b3315..21d6c82 100644
--- a/FP/src/ker/states.c
+++ b/FP/src/ker/states.c
@@ -96,7 +96,7 @@ void stateFree(tState* state) {
 	free(state->offsx);
 }
 
-void stateInterrupt(tState* state, short stateId) {
+void stateReset(tState* state, short stateId) {
 	stateFree(state);
 	*state=stateCreate(stateId);
 }
diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c
index ad29bcc..c2ad675 100644
--- a/FP/src/ker/titles.c
+++ b/FP/src/ker/titles.c
@@ -141,10 +141,10 @@ tMenuOption playAnimation(int id) {
 					/* if the time is over or exit code detected */
 					if ((objArray[i].duration==1)||(exitCode<0)) {
 						/*printf("exit Code detected: i=%d exit=%d \n",i,exitCode);*/
-						objectFree(objArray[i].obj);
+						objectFree(&objArray[i].obj);
 						objArray[i].active=0; /* remember it is destroyed */
 					} else {
-		  			objectDraw(objArray[i].obj);
+		  			objectDraw(&objArray[i].obj);
 					}
 				}
 			}
@@ -173,7 +173,7 @@ tMenuOption playAnimation(int id) {
 		}
 	}
 
-	for (i=0;i<objsActive;i++) if (objArray[i].active) objectFree(objArray[i].obj);
+	for (i=0;i<objsActive;i++) if (objArray[i].active) objectFree(&objArray[i].obj);
 	for (i=0;i<imgsActive;i++) resFree(imgArray[i].img);
 	free(imgArray);
 	free(objArray);