[Scummvm-cvs-logs] CVS: scummvm/sword2 build_display.cpp,1.80,1.81

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Wed Nov 2 09:06:49 CET 2005


Update of /cvsroot/scummvm/scummvm/sword2
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17339

Modified Files:
	build_display.cpp 
Log Message:
Used the Array class for storing the end credits lines, rather than a
statically allocated one. I hope I'm using it correctly.


Index: build_display.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/build_display.cpp,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- build_display.cpp	30 Oct 2005 16:21:54 -0000	1.80
+++ build_display.cpp	2 Nov 2005 17:04:44 -0000	1.81
@@ -664,6 +664,11 @@
 	int top;
 	int height;
 	byte *sprite;
+
+	CreditsLine() {
+		str = NULL;
+		sprite = NULL;
+	};
 };
 
 #define CREDITS_FONT_HEIGHT 25
@@ -752,37 +757,26 @@
 
 	// Read the credits text
 
-	// This should be plenty
-	CreditsLine creditsLines[350];
+	Common::Array<CreditsLine *> creditsLines;
 
-	for (i = 0; i < ARRAYSIZE(creditsLines); i++) {
-		creditsLines[i].str = NULL;
-		creditsLines[i].sprite = NULL;
-	}
+	int lineCount = 0;
+	int lineTop = 400;
+	int paragraphStart = 0;
+	bool hasCenterMark = false;
 
 	if (!f.open("credits.clu")) {
 		warning("Can't find credits.clu");
 		return;
 	}
 
-	int lineTop = 400;
-	int lineCount = 0;
-	int paragraphStart = 0;
-	bool hasCenterMark = false;
-
 	while (1) {
-		if (lineCount >= ARRAYSIZE(creditsLines)) {
-			warning("Too many credits lines");
-			break;
-		}
-
 		char buffer[80];
 		char *line = f.readLine(buffer, sizeof(buffer));
 
 		if (!line || *line == 0) {
 			if (!hasCenterMark) {
 				for (i = paragraphStart; i < lineCount; i++)
-					creditsLines[i].type = LINE_CENTER;
+					creditsLines[i]->type = LINE_CENTER;
 			}
 			paragraphStart = lineCount;
 			hasCenterMark = false;
@@ -802,50 +796,50 @@
 			hasCenterMark = true;
 
 			if (center_mark != line) {
+				creditsLines.push_back(new CreditsLine);
+
 				// The center mark is somewhere inside the
 				// line. Split it into left and right side.
 				*center_mark = 0;
 
-				creditsLines[lineCount].top = lineTop;
-				creditsLines[lineCount].height = CREDITS_FONT_HEIGHT;
-				creditsLines[lineCount].type = LINE_LEFT;
-				creditsLines[lineCount].str = strdup(line);
+				creditsLines[lineCount]->top = lineTop;
+				creditsLines[lineCount]->height = CREDITS_FONT_HEIGHT;
+				creditsLines[lineCount]->type = LINE_LEFT;
+				creditsLines[lineCount]->str = strdup(line);
 
 				lineCount++;
-
-				if (lineCount >= ARRAYSIZE(creditsLines)) {
-					warning("Too many credits lines");
-					break;
-				}
-
 				*center_mark = '^';
 			}
 
 			line = center_mark;
 		}
 
-		creditsLines[lineCount].top = lineTop;
+		creditsLines.push_back(new CreditsLine);
+
+		creditsLines[lineCount]->top = lineTop;
 
 		if (*line == '^') {
-			creditsLines[lineCount].type = LINE_RIGHT;
+			creditsLines[lineCount]->type = LINE_RIGHT;
 			line++;
 		} else
-			creditsLines[lineCount].type = LINE_LEFT;
+			creditsLines[lineCount]->type = LINE_LEFT;
 
 		if (strcmp(line, "@") == 0) {
-			creditsLines[lineCount].height = logoHeight;
+			creditsLines[lineCount]->height = logoHeight;
 			lineTop += logoHeight;
 		} else {
-			creditsLines[lineCount].height = CREDITS_FONT_HEIGHT;
+			creditsLines[lineCount]->height = CREDITS_FONT_HEIGHT;
 			lineTop += CREDITS_LINE_SPACING;
 		}
 
-		creditsLines[lineCount].str = strdup(line);
+		creditsLines[lineCount]->str = strdup(line);
 		lineCount++;
 	}
 
 	f.close();
 
+printf("lineCount = %d\n", lineCount); fflush(stdout);
+
 	// We could easily add some ScummVM stuff to the credits, if we wanted
 	// to. On the other hand, anyone with the attention span to actually
 	// read all the credits probably already knows. :-)
@@ -888,37 +882,35 @@
 		for (i = startLine; i < lineCount; i++) {
 			// Free any sprites that have scrolled off the screen
 
-			if (creditsLines[i].top + creditsLines[i].height < scrollPos) {
-				if (creditsLines[i].sprite) {
-					free(creditsLines[i].sprite);
-					creditsLines[i].sprite = NULL;
-					debug(2, "Freeing sprite '%s'", creditsLines[i].str);
-				}
-				if (creditsLines[i].str) {
-					free(creditsLines[i].str);
-					creditsLines[i].str = NULL;
-				}
-			} else if (creditsLines[i].top < scrollPos + 400) {
+			if (creditsLines[i]->top + creditsLines[i]->height < scrollPos) {
+				debug(2, "Freeing line %d", i);
+
+				free(creditsLines[i]->sprite);
+				creditsLines[i]->sprite = NULL;
+
+				free(creditsLines[i]->str);
+				creditsLines[i]->str = NULL;
+			} else if (creditsLines[i]->top < scrollPos + 400) {
 				if (!foundStartLine) {
 					startLine = i;
 					foundStartLine = true;
 				}
 
-				if (!creditsLines[i].sprite) {
-					debug(2, "Creating sprite '%s'", creditsLines[i].str);
-					creditsLines[i].sprite = _vm->_fontRenderer->makeTextSprite((byte *)creditsLines[i].str, 600, 14, _vm->_speechFontId, 0);
+				if (!creditsLines[i]->sprite) {
+					debug(2, "Creating line %d sprite '%s'", i, creditsLines[i]->str);
+					creditsLines[i]->sprite = _vm->_fontRenderer->makeTextSprite((byte *)creditsLines[i]->str, 600, 14, _vm->_speechFontId, 0);
 				}
 
 				FrameHeader frame;
 
-				frame.read(creditsLines[i].sprite);
+				frame.read(creditsLines[i]->sprite);
 
-				spriteInfo.y = creditsLines[i].top - scrollPos;
+				spriteInfo.y = creditsLines[i]->top - scrollPos;
 				spriteInfo.w = frame.width;
 				spriteInfo.h = frame.height;
-				spriteInfo.data = creditsLines[i].sprite + FrameHeader::size();
+				spriteInfo.data = creditsLines[i]->sprite + FrameHeader::size();
 
-				switch (creditsLines[i].type) {
+				switch (creditsLines[i]->type) {
 				case LINE_LEFT:
 					spriteInfo.x = RENDERWIDE / 2 - 5 - frame.width;
 					break;
@@ -926,7 +918,7 @@
 					spriteInfo.x = RENDERWIDE / 2 + 5;
 					break;
 				case LINE_CENTER:
-					if (strcmp(creditsLines[i].str, "@") == 0) {
+					if (strcmp(creditsLines[i]->str, "@") == 0) {
 						spriteInfo.data = logoData;
 						spriteInfo.x = (RENDERWIDE - logoWidth) / 2;
 						spriteInfo.w = logoWidth;
@@ -964,10 +956,9 @@
 	// before the credits.
 
 	for (i = 0; i < lineCount; i++) {
-		if (creditsLines[i].str)
-			free(creditsLines[i].str);
-		if (creditsLines[i].sprite)
-			free(creditsLines[i].sprite);
+		free(creditsLines[i]->str);
+		free(creditsLines[i]->sprite);
+		delete creditsLines[i];
 	}
 
 	if (logoData)





More information about the Scummvm-git-logs mailing list