diff options
author | Torbjörn Andersson | 2005-11-02 17:04:44 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2005-11-02 17:04:44 +0000 |
commit | aadfc0f5ed2b3147f5add2cf51573b09ca3deed8 (patch) | |
tree | ed498699e9f805f2d03a34cbb63c6eb2146b27d7 | |
parent | 419cc6898780f62b01b062aadf2bd119d7f87e5f (diff) | |
download | scummvm-rg350-aadfc0f5ed2b3147f5add2cf51573b09ca3deed8.tar.gz scummvm-rg350-aadfc0f5ed2b3147f5add2cf51573b09ca3deed8.tar.bz2 scummvm-rg350-aadfc0f5ed2b3147f5add2cf51573b09ca3deed8.zip |
Used the Array class for storing the end credits lines, rather than a
statically allocated one. I hope I'm using it correctly.
svn-id: r19394
-rw-r--r-- | sword2/build_display.cpp | 103 |
1 files changed, 47 insertions, 56 deletions
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp index 8a07c82b51..14ac412ddd 100644 --- a/sword2/build_display.cpp +++ b/sword2/build_display.cpp @@ -664,6 +664,11 @@ struct CreditsLine { int top; int height; byte *sprite; + + CreditsLine() { + str = NULL; + sprite = NULL; + }; }; #define CREDITS_FONT_HEIGHT 25 @@ -752,37 +757,26 @@ void Screen::rollCredits() { // 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 @@ void Screen::rollCredits() { 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 @@ void Screen::rollCredits() { 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 @@ void Screen::rollCredits() { 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 @@ void Screen::rollCredits() { // 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) |