[Scummvm-cvs-logs] CVS: scummvm/queen graphics.h,1.17,1.18 graphics.cpp,1.18,1.19 logic.h,1.31,1.32 logic.cpp,1.42,1.43 structs.h,1.10,1.11

Gregory Montoir cyx at users.sourceforge.net
Wed Oct 15 09:32:11 CEST 2003


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv27251

Modified Files:
	graphics.h graphics.cpp logic.h logic.cpp structs.h 
Log Message:
preliminary GRAPHIC_ANIM support

Index: graphics.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/graphics.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- graphics.h	13 Oct 2003 16:49:53 -0000	1.17
+++ graphics.h	15 Oct 2003 16:31:51 -0000	1.18
@@ -64,8 +64,8 @@
 
 		//! string based animation
 		struct {
-			uint16* buffer;
-			uint16* curPos;
+			const AnimFrame *buffer;
+			const AnimFrame *curPos;
 		} string;
 
 		//! normal moving animation
@@ -123,7 +123,7 @@
 	void bankErase(uint32 bankslot); // erase()
 
 	void bobSetupControl();
-	void bobAnimString(uint32 bobnum, uint16* animBuf); // stringanim()
+	void bobAnimString(uint32 bobnum, const AnimFrame *buf); // stringanim()
 	void bobAnimNormal(uint32 bobnum, uint16 firstFrame, uint16 lastFrame, uint16 speed, bool rebound, bool xflip); // makeanim()
 	void bobMove(uint32 bobnum, uint16 endx, uint16 endy, int16 speed); // movebob()
 	void bobDraw(uint32 bobnum, uint16 x, uint16 y, uint16 scale, bool xflip, const Box& box); // bob()

Index: graphics.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/graphics.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- graphics.cpp	13 Oct 2003 16:49:53 -0000	1.18
+++ graphics.cpp	15 Oct 2003 16:31:51 -0000	1.19
@@ -387,15 +387,15 @@
 }
 
 
-void Graphics::bobAnimString(uint32 bobnum, uint16* animBuf) {
+void Graphics::bobAnimString(uint32 bobnum, const AnimFrame *animBuf) {
 
 	BobSlot *pbs = &_bobs[bobnum];
 	pbs->active = true;
 	pbs->animating = true;
 	pbs->anim.string.buffer = animBuf;
 	pbs->anim.string.curPos = animBuf;
-	pbs->frameNum = animBuf[0];
-	pbs->anim.speed = animBuf[1] / 4;
+	pbs->frameNum = animBuf->frame;
+	pbs->anim.speed = animBuf->speed / 4;
 }
 
 
@@ -501,16 +501,17 @@
 	if (anim.string.buffer != NULL) {
 		--anim.speed;
 		if(anim.speed == 0) {
-			anim.string.curPos += 2;
-			uint16 nextFrame = anim.string.curPos[0];
+			// jump to next entry
+			++anim.string.curPos;
+			uint16 nextFrame = anim.string.curPos->frame;
 			if (nextFrame == 0) {
 				anim.string.curPos = anim.string.buffer;
-				frameNum = anim.string.curPos[0];
+				frameNum = anim.string.curPos->frame;
 			}
 			else {
 				frameNum = nextFrame;
 			}
-			anim.speed = anim.string.curPos[1] / 4;
+			anim.speed = anim.string.curPos->speed / 4;
 
 			// FIXME: handle that when QueenSound class is ready
 			// play memory sfx and move on to next frame

Index: logic.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- logic.h	15 Oct 2003 09:23:05 -0000	1.31
+++ logic.h	15 Oct 2003 16:31:51 -0000	1.32
@@ -124,6 +124,7 @@
 
 	uint16 animCreate(uint16 curImage, const Person *person); // CREATE_ANIM
 	void animErase(uint16 bobNum);
+	int16 animFindAll(const GraphicData *gd, uint16 firstImage, AnimFrame *paf); // FIND_GRAPHIC_ANIMS
 
 	StateDirection findStateDirection(uint16 state); // == FIND_STATE(state, "DIR");
 	StateTalk      findStateTalk     (uint16 state); // == FIND_STATE(state, "TALK");
@@ -221,8 +222,8 @@
 	uint16 _numFrames; // FRAMES
 	uint16 _personFrames[4];
 
-	//! contains the animation frames (max 60) to use for a bob (whose number must be < 17)
-	uint16 _newAnim[17][60];
+	//! contains the animation frames (max 30) to use for a bob (whose number must be < 17)
+	AnimFrame _newAnim[17][30];
 
 	Resource *_resource;
 	Graphics *_graphics;

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- logic.cpp	15 Oct 2003 10:01:54 -0000	1.42
+++ logic.cpp	15 Oct 2003 16:31:51 -0000	1.43
@@ -725,7 +725,7 @@
 		_personFrames[i] = 0;
 	}
 	for (i = 1; i <= 16; ++i) {
-		_newAnim[i][0] = 0;
+		_newAnim[i][0].frame = 0;
 	}
 
 	uint16 cur = _roomData[_oldRoom] + 1;
@@ -889,9 +889,28 @@
 				rebound = true;
 			}
 			if (pgd->firstFrame < 0) {
-				// FIXME: need GRAPHIC_ANIM stuff
-				// see queen.c l.1251-1296
-				warning("Logic::roomSetupObjects() - Object number %d not handled", pod->image);
+				// FIXME: if(TEMPA[1]<0) bobs[CURRBOB].xflip=1;
+				curBob = 5 + _numFurnitureAnimated;
+				AnimFrame *paf = NULL;
+				if (pod->name > 0) {
+					paf = _newAnim[curBob + numObjectAnimated];
+				}
+				BobSlot *pbs = _graphics->bob(curBob + numObjectAnimated);
+				int16 f = animFindAll(pgd, curImage + 1, paf);
+				curImage += pgd->lastFrame;
+				if (paf != NULL) {
+					if (f < 0) {
+						pbs->xflip = true;
+					}
+					pbs->active = true;
+					pbs->x = pgd->x;
+					pbs->y = pgd->y;
+					_graphics->bobAnimString(curBob + numObjectAnimated, paf);
+				}
+				else {
+					pbs->animating = false;
+				}
+				++numObjectAnimated;
 			}
 			else if (lastFrame != 0) {
 				// animated objects
@@ -1022,50 +1041,65 @@
 	curImage = findFrame(obj);
 
 	int image = pod->image;
-	if (pod->image > 5000)
+	if (image > 5000) {
 		image -= 5000;
-
-		
-		GraphicData *pgd = &_graphicData[image];
-		bool rebound = false;
-		int16 lastFrame = pgd->lastFrame;
-		if (lastFrame < 0) {
-			lastFrame = -lastFrame;
-			rebound = true;
+	}
+	
+	GraphicData *pgd = &_graphicData[image];
+	bool rebound = false;
+	int16 lastFrame = pgd->lastFrame;
+	if (lastFrame < 0) {
+		lastFrame = -lastFrame;
+		rebound = true;
+	}
+	if (pgd->firstFrame < 0) {
+		AnimFrame *paf = NULL;
+		if (pod->name != 0) {
+			paf = _newAnim[curBob];
 		}
-		if (pgd->firstFrame) {
-			// FIXME: need GRAPHIC_ANIM stuff
-			// see queen.c l.944-981
-			warning("Logic::roomRefreshObject() - Object number %d not handled", obj);
+		int16 f = animFindAll(pgd, curImage, paf);
+		curImage += pgd->lastFrame - 1;
+		if (f < 0) {
+			pbs->xflip = true;
 		}
-		else if (lastFrame != 0) {
-			// turn on an animated bob
-			_graphics->bankUnpack(pgd->firstFrame, 2, 15);
-			pbs->animating = false;
-			uint16 firstFrame = curImage;
-			--curImage;
-			uint16 j;
-			for (j = pgd->firstFrame; j <= lastFrame; ++j) {
-				++curImage;
-				_graphics->bankUnpack(j, curImage, 15);
-			}
+		if (paf != NULL) {
 			pbs->active = true;
 			pbs->x = pgd->x;
 			pbs->y = pgd->y;
-			pbs->frameNum = firstFrame;
-			if (pgd->speed > 0) {
-				_graphics->bobAnimNormal(curBob, firstFrame, curImage, pgd->speed / 4, rebound, false);
-			}
+			_graphics->bobAnimString(curBob, _newAnim[curBob]);
 		}
 		else {
-			// frame 2 is used as a buffer frame to prevent BOB flickering
-			_graphics->bankUnpack(pgd->firstFrame, 2, 15);
-			_graphics->bankUnpack(pgd->firstFrame, curImage, 15);
-			pbs->active = true;
-			pbs->x = pgd->x;
-			pbs->y = pgd->y;
-			pbs->frameNum = curImage;
+			pbs->animating = false;
+		}
+	}
+	else if (lastFrame != 0) {
+		// turn on an animated bob
+		_graphics->bankUnpack(pgd->firstFrame, 2, 15);
+		pbs->animating = false;
+		uint16 firstImage = curImage;
+		--curImage;
+		uint16 j;
+		for (j = pgd->firstFrame; j <= lastFrame; ++j) {
+			++curImage;
+			_graphics->bankUnpack(j, curImage, 15);
+		}
+		pbs->active = true;
+		pbs->x = pgd->x;
+		pbs->y = pgd->y;
+		pbs->frameNum = firstImage;
+		if (pgd->speed > 0) {
+			_graphics->bobAnimNormal(curBob, firstImage, curImage, pgd->speed / 4, rebound, false);
 		}
+	}
+	else {
+		// frame 2 is used as a buffer frame to prevent BOB flickering
+		_graphics->bankUnpack(pgd->firstFrame, 2, 15);
+		_graphics->bankUnpack(pgd->firstFrame, curImage, 15);
+		pbs->active = true;
+		pbs->x = pgd->x;
+		pbs->y = pgd->y;
+		pbs->frameNum = curImage;
+	}
 
 	return curImage;
 }
@@ -1289,7 +1323,7 @@
 
 uint16 Logic::animCreate(uint16 curImage, const Person *person) {
 
-	uint16 *animFrames = _newAnim[person->actor->bobNum];
+	AnimFrame *animFrames = _newAnim[person->actor->bobNum];
 
 	uint16 allocatedFrames[256];
 	memset(allocatedFrames, 0, sizeof(allocatedFrames));
@@ -1298,8 +1332,8 @@
 	uint16 f1, f2;
 	do {
 		sscanf(p, "%3hu,%3hu", &f1, &f2);
-		animFrames[frame + 0] = f1;
-		animFrames[frame + 1] = f2;
+		animFrames[frame].frame = f1;
+		animFrames[frame].speed = f2;
 		
 		if (f1 > 500) {
 			// SFX
@@ -1310,7 +1344,7 @@
 		}
 		
 		p += 8;
-		frame += 2;
+		++frame;
 	} while(f1 != 0);
 	
 	// ajust frame numbers
@@ -1322,13 +1356,13 @@
 			++n;
 		}
 	}
-	for (i = 0; animFrames[i] != 0; i += 2) {
-		uint16 frameNum = animFrames[i];
+	for (i = 0; animFrames[i].frame != 0; ++i) {
+		uint16 frameNum = animFrames[i].frame;
 		if (frameNum > 500) {
-			animFrames[i] = curImage + allocatedFrames[frameNum - 500] + 500;
+			animFrames[i].frame = curImage + allocatedFrames[frameNum - 500] + 500;
 		}
 		else {
-			animFrames[i] = curImage + allocatedFrames[frameNum];
+			animFrames[i].frame = curImage + allocatedFrames[frameNum];
 		}
 	}
 	
@@ -1348,10 +1382,83 @@
 
 
 void Logic::animErase(uint16 bobNum) {
-	_newAnim[bobNum][0] = 0;
+	_newAnim[bobNum][0].frame = 0;
 	BobSlot *pbs = _graphics->bob(bobNum);
 	pbs->animating = false;
 	pbs->anim.string.buffer = NULL;
+}
+
+
+int16 Logic::animFindAll(const GraphicData *gd, uint16 firstImage, AnimFrame *paf) {
+	
+	int16 tempFrames[20];
+	memset(tempFrames, 0, sizeof(tempFrames));
+	uint16 numTempFrames = 0;
+	uint16 i, j;
+	for (i = 1; i <= _numGraphicAnim; ++i) {
+		const GraphicAnim *pga = &_graphicAnim[i];
+		if (pga->keyFrame == gd->firstFrame) {
+			int16 frame = pga->frame;
+			if (frame > 500) { // SFX
+				frame -= 500;
+			}
+			bool foundMatchingFrame = false;
+			for (j = 0; j < numTempFrames; ++j) {
+				if (tempFrames[j] == frame) {
+					foundMatchingFrame = true;
+					break;
+				}
+			}
+			if (!foundMatchingFrame) {
+				assert(numTempFrames < 20);
+				tempFrames[numTempFrames] = frame;
+				++numTempFrames;
+			}
+		}
+	}
+
+	// sort found frames ascending
+	bool swap = true;
+	while (swap) {
+		swap = false;
+		for (i = 0; i < numTempFrames - 1; ++i) {
+			if (tempFrames[i] > tempFrames[i + 1]) {
+				SWAP(tempFrames[i], tempFrames[i + 1]);
+				swap = true;
+			}
+		}
+	}
+
+	// queen.c l.962-980 / l.1269-1294
+	for (i = 0; i < gd->lastFrame; ++i) {
+		_graphics->bankUnpack(ABS(tempFrames[i]), firstImage + i, 15);
+	}
+	if (paf != NULL) {
+		uint16 frameNr = 0;
+		for (i = 1; i <= _numGraphicAnim; ++i) {
+			const GraphicAnim *pga = &_graphicAnim[i];
+			if (pga->keyFrame == gd->firstFrame) {
+				for (j = 1; j <= gd->lastFrame; ++j) {
+					int16 f = pga->frame;
+					if (f > 500) {
+						f -= 500;
+					}
+					if (f == tempFrames[j - 1]) {
+						frameNr = j + firstImage - 1;
+					}
+					if (pga->frame > 500) {
+						frameNr += 500;
+					}
+				}
+				paf->frame = frameNr;
+				paf->speed = pga->speed;
+				++paf;
+			}
+		}
+		paf->frame = 0;
+		paf->speed = 0;
+	}
+	return tempFrames[0];
 }
 
 

Index: structs.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/structs.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- structs.h	15 Oct 2003 08:46:18 -0000	1.10
+++ structs.h	15 Oct 2003 16:31:51 -0000	1.11
@@ -421,15 +421,21 @@
 
 
 struct GraphicAnim {
-	int16 frame1;
-	int16 frame2;
-	int16 frame3;
+	int16 keyFrame;
+	int16 frame;
+	uint16 speed;
 
 	void readFrom(byte *&ptr) {
-		frame1 = (int16)READ_BE_UINT16(ptr); ptr += 2;
-		frame2 = (int16)READ_BE_UINT16(ptr); ptr += 2;
-		frame3 = (int16)READ_BE_UINT16(ptr); ptr += 2;
+		keyFrame = (int16)READ_BE_UINT16(ptr); ptr += 2;
+		frame = (int16)READ_BE_UINT16(ptr); ptr += 2;
+		speed = READ_BE_UINT16(ptr); ptr += 2;
 	}
+};
+
+
+struct AnimFrame {
+	uint16 frame;
+	uint16 speed;
 };
 
 





More information about the Scummvm-git-logs mailing list