Permalink
Browse files

SWORD2: Replace use of strdup with Common::String

  • Loading branch information...
csnover authored and sev- committed Dec 5, 2017
1 parent 072a52a commit 2f872168647e0dc4d87f449ed283b830716ad78e
Showing with 13 additions and 17 deletions.
  1. +3 −3 engines/sword2/maketext.cpp
  2. +3 −3 engines/sword2/maketext.h
  3. +7 −11 engines/sword2/screen.cpp
@@ -83,7 +83,7 @@ namespace Sword2 {
* error-signal character (chequered flag)
*/

byte *FontRenderer::makeTextSprite(byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border) {
byte *FontRenderer::makeTextSprite(const byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border) {
debug(5, "makeTextSprite(\"%s\", maxWidth=%u)", sentence, maxWidth);

_borderPen = border;
@@ -123,7 +123,7 @@ byte *FontRenderer::makeTextSprite(byte *sentence, uint16 maxWidth, uint8 pen, u
return textSprite;
}

uint16 FontRenderer::analyzeSentence(byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line) {
uint16 FontRenderer::analyzeSentence(const byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line) {
// joinWidth = how much extra space is needed to append a word to a
// line. NB. SPACE requires TWICE the '_charSpacing' to join a word
// to line
@@ -207,7 +207,7 @@ uint16 FontRenderer::analyzeSentence(byte *sentence, uint16 maxWidth, uint32 fon
* error-signal character (chequered flag)
*/

byte *FontRenderer::buildTextSprite(byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines) {
byte *FontRenderer::buildTextSprite(const byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines) {
uint16 i;

// Find the width of the widest line in the output text
@@ -91,8 +91,8 @@ class FontRenderer {
// each line - negative for overlap
uint8 _borderPen; // output pen color of character borders

uint16 analyzeSentence(byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line);
byte *buildTextSprite(byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines);
uint16 analyzeSentence(const byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line);
byte *buildTextSprite(const byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines);
uint16 charWidth(byte ch, uint32 fontRes);
uint16 charHeight(uint32 fontRes);
byte *findChar(byte ch, byte *charSet);
@@ -109,7 +109,7 @@ class FontRenderer {
free(_blocList[i].text_mem);
}

byte *makeTextSprite(byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border = BORDER_PEN);
byte *makeTextSprite(const byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border = BORDER_PEN);

void killTextBloc(uint32 bloc_number);
void printTextBlocs();
@@ -845,22 +845,18 @@ enum {
};

struct CreditsLine {
char *str;
Common::String str;
byte type;
int top;
int height;
byte *sprite;

CreditsLine() {
str = NULL;
sprite = NULL;
}

~CreditsLine() {
free(str);
free(sprite);
str = NULL;
sprite = NULL;
}
};

@@ -1036,7 +1032,7 @@ void Screen::rollCredits() {
creditsLines[lineCount]->top = lineTop;
creditsLines[lineCount]->height = CREDITS_FONT_HEIGHT;
creditsLines[lineCount]->type = LINE_LEFT;
creditsLines[lineCount]->str = strdup(line);
creditsLines[lineCount]->str = line;

lineCount++;
*center_mark = '^';
@@ -1063,7 +1059,7 @@ void Screen::rollCredits() {
lineTop += CREDITS_LINE_SPACING;
}

creditsLines[lineCount]->str = strdup(line);
creditsLines[lineCount]->str = line;
lineCount++;
}

@@ -1113,16 +1109,16 @@ void Screen::rollCredits() {
// Free any sprites that have scrolled off the screen

if (creditsLines[i]->top + creditsLines[i]->height < scrollPos) {
debug(2, "Freeing line %d: '%s'", i, creditsLines[i]->str);
debug(2, "Freeing line %d: '%s'", i, creditsLines[i]->str.c_str());

delete creditsLines[i];
creditsLines[i] = NULL;

startLine = i + 1;
} else if (creditsLines[i]->top < scrollPos + 400) {
if (!creditsLines[i]->sprite) {
debug(2, "Creating line %d: '%s'", i, creditsLines[i]->str);
creditsLines[i]->sprite = _vm->_fontRenderer->makeTextSprite((byte *)creditsLines[i]->str, 600, 14, _vm->_speechFontId, 0);
debug(2, "Creating line %d: '%s'", i, creditsLines[i]->str.c_str());
creditsLines[i]->sprite = _vm->_fontRenderer->makeTextSprite((byte *)creditsLines[i]->str.c_str(), 600, 14, _vm->_speechFontId, 0);
}

FrameHeader frame;
@@ -1143,7 +1139,7 @@ void Screen::rollCredits() {
spriteInfo.x = RENDERWIDE / 2 + 5;
break;
case LINE_CENTER:
if (strcmp(creditsLines[i]->str, "@") == 0) {
if (strcmp(creditsLines[i]->str.c_str(), "@") == 0) {
spriteInfo.data = logoData;
spriteInfo.x = (RENDERWIDE - logoWidth) / 2;
spriteInfo.w = logoWidth;

0 comments on commit 2f87216

Please sign in to comment.