git » fp-git.git » commit cccf6e5

Improved event handling using auxiliary structures. Bugfixes in map loading. Added verifications in case the level format is invalid.

author ecalot
2004-08-26 10:36:16 UTC
committer ecalot
2004-08-26 10:36:16 UTC
parent 8a0dec94d92db7d17bf7914342b1645a7e31c7b2

Improved event handling using auxiliary structures. Bugfixes in map loading. Added verifications in case the level format is invalid.

FP/src/include/types.h +5 -2
FP/src/ker/kernel.c +10 -1
FP/src/ker/room.c +37 -9
FP/src/res/maps.c +33 -6

diff --git a/FP/src/include/types.h b/FP/src/include/types.h
index 6a401a9..5526bbe 100644
--- a/FP/src/include/types.h
+++ b/FP/src/include/types.h
@@ -67,8 +67,11 @@ typedef struct {
 	tGate**        screenGates[24];
 	tGate*         gates;
 	int            totalGates;
+	tPressable**   screenPressables[24];
+	tPressable*    pressables;
+	int            totalPressables;
 	tEvent         events[256];
-	int time;
+	int            time;
 	unsigned char start[3];
 } tMap;
 
@@ -96,7 +99,7 @@ typedef struct {
 	int isExit;
 	int isRaise;
 	int isGate;
-	tGate* gateInfo;
+	void* moreInfo;
 	int bricks;
 	int isPressable;
 	int hasSpikes;
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index 7f4d62c..e8e02c3 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -128,7 +128,16 @@ int playgame(int optionflag,int level) {
 					room.links[eDown]
 				);
 				break;
-		default:
+			case showMoreScreens:
+				fprintf(stderr,"S%d AL%d AR%d BL%d BR%d\n",
+					room.id,
+					room.corners[0],
+					room.corners[1],
+					room.corners[2],
+					room.corners[3]
+				);
+				break;
+			default:
 				break;
 			}
 		}
diff --git a/FP/src/ker/room.c b/FP/src/ker/room.c
index d73947b..9266d8a 100644
--- a/FP/src/ker/room.c
+++ b/FP/src/ker/room.c
@@ -82,7 +82,8 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 		result.hasPillar=0;
 		result.hasBigPillar=0;
 		result.isGate=(result.code==T_GATE);
-		result.gateInfo=room->level->screenGates[roomId-1][result.back];
+		if (roomId<24)
+			result.moreInfo=room->level->screenGates[roomId-1][result.back];
 		result.walkable=1;
 		result.hasChopper=0;
 		result.isExit=(result.code==T_EXIT_LEFT)?1:((result.code==T_EXIT_RIGHT)?2:0);
@@ -97,6 +98,35 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 		result.isWall=0;
 		result.hasSword=0;
 		break;
+	case T_BTN_RAISE:
+	case T_BTN_DROP:
+		roomId=room->id;
+		if (y==0)	roomId=room->links[eUp]; /*TODO: validate corners */
+		if (x==0) roomId=room->links[eLeft];
+		if (y==4) roomId=room->links[eDown];
+		if (x==11)roomId=room->links[eRight];
+		result.hasGateFrame=0;
+		result.bricks=0;
+		result.hasPillar=0;
+		result.hasBigPillar=0;
+		result.isGate=0;
+		result.walkable=1;
+		/* the case that a button is in tile 0 should never happen, but we'll care about it just in case */
+		if (roomId<24)
+			result.moreInfo=room->level->screenPressables[roomId-1][result.back];
+		result.hasChopper=0;
+		result.isExit=0;
+		result.block=0;
+		result.isRaise=(result.code==T_BTN_RAISE);
+		result.isPressable=1;
+		result.hasSkeleton=0;
+		result.hasSpikes=0;
+		result.hasTorch=0;
+		result.hasFloor=(result.code==T_BTN_DROP);
+		result.hasBrokenTile=0;
+		result.isWall=0;
+		result.hasSword=0;
+		break;
 	case T_FLOOR:
 	case T_TORCH:
 	case T_SWORD:
@@ -104,8 +134,6 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 	case T_POTION:
 	case T_SPIKES:
 	case T_BP_BOTTOM:
-	case T_BTN_RAISE:
-	case T_BTN_DROP:
 	case T_TORCH_DEBRIS:
 	case T_EXIT_RIGHT:
 	case T_SKELETON:
@@ -121,12 +149,12 @@ tTile roomGetTile(tRoom* room,int x, int y) {
 		result.hasChopper=(result.code==T_CHOPPER);
 		result.isExit=(result.code==T_EXIT_LEFT)?1:((result.code==T_EXIT_RIGHT)?2:0);
 		result.block=0;
-		result.isRaise=(result.code==T_BTN_RAISE);
-		result.isPressable=(result.code==T_BTN_RAISE)|(result.code==T_BTN_DROP);
+		result.isRaise=0;
+		result.isPressable=0;
 		result.hasSkeleton=(result.code==T_SKELETON);
 		result.hasSpikes=(result.code==T_SPIKES);
 		result.hasTorch=(result.code==T_TORCH)|(result.code==T_TORCH_DEBRIS);
-		result.hasFloor=((result.code==T_FLOOR)|(result.code==T_TORCH)|(result.code==T_LOOSE)|(result.code==T_POTION)|(result.code==T_BTN_DROP)|(result.code==T_SWORD)|(result.code==T_CHOPPER));
+		result.hasFloor=((result.code==T_FLOOR)|(result.code==T_TORCH)|(result.code==T_LOOSE)|(result.code==T_POTION)|(result.code==T_SWORD)|(result.code==T_CHOPPER));
 		result.hasBrokenTile=(result.code==T_DEBRIS)|(result.code==T_TORCH_DEBRIS);
 		result.isWall=0;
 		result.hasSword=(result.code==T_SWORD);
@@ -229,7 +257,7 @@ void drawBackPanel(tRoom* room,int x, int y) {
 			(x-1)*TILE_W,
 			y*TILE_H+2
 		);
-		drawGate((x-1)*TILE_W,(y-1)*TILE_H+3,left.gateInfo->frame);
+		drawGate((x-1)*TILE_W,(y-1)*TILE_H+3,((tGate*)left.moreInfo)->frame);
 	}
 	/* normal/left */
 	if (left.hasFloor) {
@@ -380,7 +408,7 @@ void drawBackPanel(tRoom* room,int x, int y) {
 				(x-1)*TILE_W,
 				y*TILE_H
 			);
-			drawExit(x*TILE_W+8,(y-1)*TILE_H-1,tile.gateInfo->frame);
+			drawExit(x*TILE_W+8,(y-1)*TILE_H-1,((tGate*)tile.moreInfo)->frame);
 		}
 	}
 	/* pillar/this */
@@ -501,7 +529,7 @@ void drawBackBottomTile(tRoom* room,int x, int y) {
 					(x-1)*TILE_W,
 					y*TILE_H+3
 				);
-			/*	drawGateTop(x*TILE_W,(y-1)*TILE_H+3,tile.gateInfo->frame);*/
+			/*	drawGateTop(x*TILE_W,(y-1)*TILE_H+3,((tGate*)tile.moreInfo)->frame);*/
 			}
 			/* big_pillar/left */
 			if (dleft.hasBigPillar==2) {
diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c
index d75569b..81fb4ec 100644
--- a/FP/src/res/maps.c
+++ b/FP/src/res/maps.c
@@ -44,6 +44,8 @@ void* mapLoadLevel(tMemory level) {
 	int i,j;
 	int gates=0;
 	int gateInRoom=0;
+	int pressables=0;
+	int pressableInRoom=0;
 	tGate** auxGates=malloc(sizeof(tGate*)*24*30);
 	
 	/* copy maps, links and start position */
@@ -58,6 +60,9 @@ void* mapLoadLevel(tMemory level) {
 			if (((map->fore[i*30+j]&0x1f)==T_GATE)||((map->fore[i*30+j]&0x1f)==T_EXIT_LEFT)) {
 				gateInRoom++;
 				gates++;
+			} else if (((map->fore[i*30+j]&0x1f)==T_BTN_RAISE)||((map->fore[i*30+j]&0x1f)==T_BTN_DROP)) {
+				pressableInRoom++;
+				pressables++;
 			}
 		}
 		if (gateInRoom) {
@@ -65,12 +70,21 @@ void* mapLoadLevel(tMemory level) {
 		} else {
 			map->screenGates[i]=NULL;
 		}
+		if (pressableInRoom) {
+			map->screenPressables[i]=malloc(pressableInRoom*sizeof(tPressable*));
+		} else {
+			map->screenPressables[i]=NULL;
+		}
 		gateInRoom=0;
+		pressableInRoom=0;
 	}
 	/* create gates sctucture */
 	map->gates=malloc(gates*sizeof(tGate));
 	map->totalGates=gates;
+	map->pressables=malloc(pressables*sizeof(tPressable));
+	map->totalPressables=pressables;
 	gates=0;
+	pressables=0;
 	for (i=0;i<24;i++) {
 		for (j=0;j<30;j++) {
 			if (((map->fore[i*30+j]&0x1f)==T_GATE)||((map->fore[i*30+j]&0x1f)==T_EXIT_LEFT)) {
@@ -84,10 +98,21 @@ void* mapLoadLevel(tMemory level) {
 				fprintf(stderr,"mapLoadLevel: Loading gate: indexed=%d gate pointer=%p\n",i,(void*)auxGates[i*30+j]);
 				map->gates[gates++]=newGate;
 				gateInRoom++;
+			} else if (((map->fore[i*30+j]&0x1f)==T_BTN_RAISE)||((map->fore[i*30+j]&0x1f)==T_BTN_DROP)) {
+				tPressable newPressable;
+				newPressable.event=map->events+map->back[i*30+j];
+				newPressable.action=eNormal;
+				map->back[i*30+j]=pressableInRoom;
+				map->screenPressables[i][pressableInRoom]=map->pressables+pressables;
+				fprintf(stderr,"mapLoadLevel: Creating button: indexed=%d,%d btn pointer=%p\n",i,pressableInRoom,(void*)(map->pressables+pressables));
+				map->pressables[pressables++]=newPressable;
+				pressableInRoom++;
 			}
 		}
 		if (!gateInRoom) map->screenGates[i]=NULL;
+		if (!pressableInRoom) map->screenPressables[i]=NULL;
 		gateInRoom=0;
+		pressableInRoom=0;
 	}
 	for (i=0;i<256;i++) {
 		unsigned char byte1=level.array[MAPS_BLOCK_OFFSET_GATE_1+i];
@@ -191,12 +216,12 @@ tRoom mapGetRoom(tMap* map, tRoomId roomAux) {
 		result.fore[47]=*(slevel(fore)+30*(roomAux-1)+20);
 		result.back[47]=*(slevel(back)+30*(roomAux-1)+20);
 	} else {
-		result.fore[11]=MAP_F_WALL;
-		result.back[11]=MAP_B_NONE;
 		result.fore[23]=MAP_F_WALL;
 		result.back[23]=MAP_B_NONE;
 		result.fore[35]=MAP_F_WALL;
-		result.back[35]=MAP_B_NONE;	
+		result.back[35]=MAP_B_NONE;
+		result.fore[47]=MAP_F_WALL;
+		result.back[47]=MAP_B_NONE;	
 	}
 
 	/* Top room */
@@ -307,11 +332,13 @@ void  mapMove(tMap* map) {
 
 void  mapPressedTile(tMap* map, tTile tile, int s, int x, int y) {
 	if (tile.isPressable) {
+		tEvent* event;
 		/* drop or raise button */
-		fprintf(stderr,"mapPressedTile: throw event %d\n",tile.back);
+		event=((tPressable*)tile.moreInfo)->event;
+		fprintf(stderr,"mapPressedTile: throw event from button %d event:%p\n",tile.back,(void*)event);
 		do {
-			map->events[tile.back].gate->action=tile.isRaise?eOpening:eClosingFast;
-		} while	(map->events[tile.back++].triggerNext);
+			event->gate->action=tile.isRaise?eOpening:eClosingFast;
+		} while	((event++)->triggerNext);
 	}
 
 }