Skip to content

Commit

Permalink
SWORD2: Replace use of strdup with Common::String
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover authored and ccawley2011 committed Aug 15, 2018
1 parent e915b4c commit a81f3c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions engines/sword2/maketext.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions engines/sword2/maketext.h
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
18 changes: 7 additions & 11 deletions engines/sword2/screen.cpp
Expand Up @@ -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;
}
};

Expand Down Expand Up @@ -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 = '^';
Expand All @@ -1063,7 +1059,7 @@ void Screen::rollCredits() {
lineTop += CREDITS_LINE_SPACING;
}

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

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit a81f3c3

Please sign in to comment.