git » fp-git.git » commit 54c4b35

forked object.c and kid.c

author ecalot
2005-01-15 17:24:02 UTC
committer ecalot
2005-01-15 17:24:02 UTC
parent d406725cc88b52db113899d8f61ce7b460ce63ed

forked object.c and kid.c

FP/src/Makefile +11 -4
FP/src/include/kid.h +4 -0
FP/src/include/object.h +4 -0
FP/src/ker/kid.c +7 -76
FP/src/ker/object.c +2 -70

diff --git a/FP/src/Makefile b/FP/src/Makefile
index 26b0c8e..5308b4e 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -47,7 +47,8 @@ LINKERRELEASE =
 #Binary code files
 OBJFILES      = main.o kernel.o resources.o dat.o disk.o compress.o \
                 output.o maps.o config.o room.o titles.o \
-                input.o kid.o states.o tiles.o walls.o anims.o
+                input.o kid.o states.o tiles.o walls.o anims.o\
+								object.o
 EXEFILE       = bin/freeprince
 
 GENERATEDRESHEADERS = include/res_conf_parts.h include/res_conf_files.h\
@@ -159,13 +160,19 @@ 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\
-       include/states.h $(GENERATEDRESHEADERS)\
-			 $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS) include/res_conf.h\
+kid.o: ker/kid.c include/kid.h include/states.h $(GENERATEDSTAHEADERS) \
+       $(GENERATEDTILHEADERS) include/res_conf.h\
        include/types.h include/tiles.h include/tiles_conf.h
 	$(INFO) Compiling kernel object support...
 	$(CC) -c ker/kid.c $(OPTIONS)
 
+object.o: ker/object.c include/kid.h include/resources.h include/res_conf.h\
+       include/states.h $(GENERATEDRESHEADERS)\
+			 $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS) include/res_conf.h\
+       include/types.h include/tiles.h include/tiles_conf.h include/output.h
+	$(INFO) Compiling kernel kid object support...
+	$(CC) -c ker/object.c $(OPTIONS)
+
 titles.o: ker/titles.c include/resources.h include/res_conf.h\
           include/anims_conf.h $(GENERATEDSTAHEADERS) $(GENERATEDRESHEADERS)\
           include/kid.h
diff --git a/FP/src/include/kid.h b/FP/src/include/kid.h
index da03042..e0a065e 100644
--- a/FP/src/include/kid.h
+++ b/FP/src/include/kid.h
@@ -40,6 +40,8 @@ kid.h: Free Prince : Kid and other object
 #define DIR_LEFT  1
 #define DIR_RIGHT 0
 
+#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);
@@ -47,5 +49,7 @@ void objectDraw(tObject obj);
 int  objectMove(tObject* obj,tKey key,tRoom* room);
 void objectFree(tObject obj);
 
+int kidMove(tObject* kid,short flags,tRoom* room);
+
 #endif
 
diff --git a/FP/src/include/object.h b/FP/src/include/object.h
index da03042..e0a065e 100644
--- a/FP/src/include/object.h
+++ b/FP/src/include/object.h
@@ -40,6 +40,8 @@ kid.h: Free Prince : Kid and other object
 #define DIR_LEFT  1
 #define DIR_RIGHT 0
 
+#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);
@@ -47,5 +49,7 @@ void objectDraw(tObject obj);
 int  objectMove(tObject* obj,tKey key,tRoom* room);
 void objectFree(tObject obj);
 
+int kidMove(tObject* kid,short flags,tRoom* room);
+
 #endif
 
diff --git a/FP/src/ker/kid.c b/FP/src/ker/kid.c
index 2013eb7..afd0b08 100644
--- a/FP/src/ker/kid.c
+++ b/FP/src/ker/kid.c
@@ -19,7 +19,7 @@
 */
 
 /*
-kid.h: Free Prince : Kid and other objects
+kid.c: Free Prince : Kid object
 \xaf\xaf\xaf\xaf\xaf
  Copyright 2004 Princed Development Team
   Created: 19 Jul 2004
@@ -31,41 +31,11 @@ kid.h: Free Prince : Kid and other objects
 */
 
 #include "kid.h"
-#include "output.h"
-#include "resources.h" /* resLoad/resFree */
 #include "room.h"
-#include "maps.h" /* getTile */
-#include <stdio.h> /* NULL */
+#include <stdio.h> /* DEBUG printf */
 #include "states.h"
+/* #include "maps.h" * mapPressedTile */
 
-#define NEW_KERNEL
-
-void loadGfx(int storeMirrored, tData** gfxCache, unsigned long resId) {
-	gfxCache[DIR_LEFT]=resLoad(resId);
-	if (storeMirrored)
-		gfxCache[DIR_RIGHT]=resLoad(resId|RES_MODS_INVERT);
-	else
-		gfxCache[DIR_RIGHT]=NULL;
-}
-
-void objectFree(tObject obj) {
-	resFree(obj.gfxCache[DIR_LEFT]);
-	if (obj.gfxCache[DIR_RIGHT]) resFree(obj.gfxCache[DIR_RIGHT]);
-}
-
-/* TODO: make a function in maps.c that calls this one for the kid */
-tObject objectCreate(int location, int floor, int direction, int stateId, unsigned long resId, int cacheMirror, tObjectType type) {
-	tObject object;
-
-	loadGfx(cacheMirror,object.gfxCache,resId);
-
-	object.location=location;
-	object.floor=floor;
-	object.type=type;
-	object.direction=direction;
-	object.action=createState(stateId);
-	return object;
-}
 
 int kidVerifyRoom(tObject *kid,tRoom *room) {
 	/* if the kid is out of the screen we need to change the screen and put
@@ -107,32 +77,20 @@ int kidVerifyRoom(tObject *kid,tRoom *room) {
 	return refresh;
 }
 	
-#define object_getLocation(object,image) ((object).location/*-(outputGetWidth(image)>>1)*/)
-
-void objectDraw(tObject object) {
-	void* image=object.gfxCache[object.direction]->pFrames[stateGetImage(object)-1];
-	/* TODO: move this -1 to each script frame */
-	outputDrawBitmap(
-		image, 
-		object_getLocation(object,image),
-		58+object.floor*TILE_H
-	);
-}
-
 int kidMove(tObject* kid,short flags,tRoom* room) {
 	int refresh=0;
-	int x;
 	
-	x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W;
+/*	x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W;*/
 	
 	if (flags&STATES_FLAG_P)
-		refresh=mapPressedTile(
+/*		refresh=mapPressedTile(
 			room->level,
 			roomGetTile(room,x+1,kid->floor+1),
 			room->id,
 			x+1,
 			kid->floor+1
-		);
+		);*/
+		refresh=roomPress(room,kid);
 printf("f era %d. ",kid->floor);
 	if (flags&STATES_FLAG_F)
 		kid->floor++;
@@ -142,30 +100,3 @@ printf("f pasa a ser %d\n",kid->floor);
 	return kidVerifyRoom(kid,room)||refresh;
 }
 	
-int objectMove(tObject* object,tKey key,tRoom* room) {
-	/* advance state and get the flag, then interpret the flag and do the events */
-	short flags;
-	int refresh;
-	
-	flags=stateUpdate(&key,object,room);
-
-	if (room==NULL) return flags; /* exits if it is not associated to a room */
-
-/* a static variable type in the tObject determinates what objet is it about. This is to simulate polymorphism.
- * call a function that performs all the actions knowing the room, the object and the flags. Returns refresh. After that, kid.c can be renamed to object.c */	
-	switch (object->type) {
-		case oKid:
-			refresh=kidMove(object,flags,room);
-			break;
-		case oGeneric:
-		default:
-			refresh=0;
-			break;
-	}
-	
-	if (refresh) { /* room map was changed and needs to be refreshed */
-		*room=mapGetRoom(room->level,room->id);
-	}
-	return flags;
-}
-
diff --git a/FP/src/ker/object.c b/FP/src/ker/object.c
index 2013eb7..f491490 100644
--- a/FP/src/ker/object.c
+++ b/FP/src/ker/object.c
@@ -19,7 +19,7 @@
 */
 
 /*
-kid.h: Free Prince : Kid and other objects
+object.h: Free Prince : Objects
 \xaf\xaf\xaf\xaf\xaf
  Copyright 2004 Princed Development Team
   Created: 19 Jul 2004
@@ -33,13 +33,10 @@ kid.h: Free Prince : Kid and other objects
 #include "kid.h"
 #include "output.h"
 #include "resources.h" /* resLoad/resFree */
-#include "room.h"
-#include "maps.h" /* getTile */
+#include "maps.h" /* mapGetRoom getTile */
 #include <stdio.h> /* NULL */
 #include "states.h"
 
-#define NEW_KERNEL
-
 void loadGfx(int storeMirrored, tData** gfxCache, unsigned long resId) {
 	gfxCache[DIR_LEFT]=resLoad(resId);
 	if (storeMirrored)
@@ -67,48 +64,6 @@ tObject objectCreate(int location, int floor, int direction, int stateId, unsign
 	return object;
 }
 
-int kidVerifyRoom(tObject *kid,tRoom *room) {
-	/* if the kid is out of the screen we need to change the screen and put
-	 * the kid back again on it
-	 * PRE: tObject *kid is a kid
-	 */
-	
-	int refresh=0;
-	
-	/* The kid is down */
-	if (kid->floor==4) {
-		kid->floor=0;
-		room->id=room->links[eDown];
-		refresh=1;
-	}
-	
-	/* The kid is up */
-	if (kid->floor==-1) {
-		printf("pas\xf3: kf=0 ahora es 3, cambio el id del room y refresco\n");
-		kid->floor=2;
-		room->id=room->links[eUp];
-		refresh=1;
-	}
-
-	/* The kid is left */
-	if (kid->location<0) {
-		kid->location+=TILE_W*10;
-		room->id=room->links[eLeft];
-		refresh=1;
-	}
-
-	/* The kid is right */
-	if (kid->location>TILE_W*10) {
-		kid->location-=TILE_W*10;
-		room->id=room->links[eRight];
-		refresh=1;
-	}
-
-	return refresh;
-}
-	
-#define object_getLocation(object,image) ((object).location/*-(outputGetWidth(image)>>1)*/)
-
 void objectDraw(tObject object) {
 	void* image=object.gfxCache[object.direction]->pFrames[stateGetImage(object)-1];
 	/* TODO: move this -1 to each script frame */
@@ -119,29 +74,6 @@ void objectDraw(tObject object) {
 	);
 }
 
-int kidMove(tObject* kid,short flags,tRoom* room) {
-	int refresh=0;
-	int x;
-	
-	x=object_getLocation(*kid,kid->gfxCache[kid->direction]->pFrames[stateGetImage(*kid)-1])/TILE_W;
-	
-	if (flags&STATES_FLAG_P)
-		refresh=mapPressedTile(
-			room->level,
-			roomGetTile(room,x+1,kid->floor+1),
-			room->id,
-			x+1,
-			kid->floor+1
-		);
-printf("f era %d. ",kid->floor);
-	if (flags&STATES_FLAG_F)
-		kid->floor++;
-	if (flags&STATES_FLAG_U)
-		kid->floor--;
-printf("f pasa a ser %d\n",kid->floor);
-	return kidVerifyRoom(kid,room)||refresh;
-}
-	
 int objectMove(tObject* object,tKey key,tRoom* room) {
 	/* advance state and get the flag, then interpret the flag and do the events */
 	short flags;