[Scummvm-cvs-logs] SF.net SVN: scummvm:[35326] scummvm/trunk/engines/parallaction
peres001 at users.sourceforge.net
peres001 at users.sourceforge.net
Sat Dec 13 04:37:44 CET 2008
Revision: 35326
http://scummvm.svn.sourceforge.net/scummvm/?rev=35326&view=rev
Author: peres001
Date: 2008-12-13 03:37:43 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
* Replaced char* with Common::String in the parser.
* Enforced const-correctness on related routines.
Modified Paths:
--------------
scummvm/trunk/engines/parallaction/balloons.cpp
scummvm/trunk/engines/parallaction/dialogue.cpp
scummvm/trunk/engines/parallaction/graphics.h
scummvm/trunk/engines/parallaction/objects.cpp
scummvm/trunk/engines/parallaction/objects.h
scummvm/trunk/engines/parallaction/parallaction.cpp
scummvm/trunk/engines/parallaction/parallaction.h
scummvm/trunk/engines/parallaction/parser.h
scummvm/trunk/engines/parallaction/parser_ns.cpp
Modified: scummvm/trunk/engines/parallaction/balloons.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/balloons.cpp 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/balloons.cpp 2008-12-13 03:37:43 UTC (rev 35326)
@@ -267,10 +267,10 @@
~BalloonManager_ns();
void freeBalloons();
- int setLocationBalloon(char *text, bool endGame);
- int setDialogueBalloon(char *text, uint16 winding, TextColor textColor);
- int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor);
- void setBalloonText(uint id, char *text, TextColor textColor);
+ int setLocationBalloon(const char *text, bool endGame);
+ int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor);
+ int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor);
+ void setBalloonText(uint id, const char *text, TextColor textColor);
int hitTestDialogueBalloon(int x, int y);
};
@@ -327,7 +327,7 @@
}
-int BalloonManager_ns::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) {
+int BalloonManager_ns::setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) {
int16 w, h;
@@ -351,7 +351,7 @@
return id;
}
-int BalloonManager_ns::setDialogueBalloon(char *text, uint16 winding, TextColor textColor) {
+int BalloonManager_ns::setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) {
int16 w, h;
@@ -381,7 +381,7 @@
return id;
}
-void BalloonManager_ns::setBalloonText(uint id, char *text, TextColor textColor) {
+void BalloonManager_ns::setBalloonText(uint id, const char *text, TextColor textColor) {
Balloon *balloon = getBalloon(id);
balloon->surface->fillRect(balloon->innerBox, 1);
@@ -390,7 +390,7 @@
}
-int BalloonManager_ns::setLocationBalloon(char *text, bool endGame) {
+int BalloonManager_ns::setLocationBalloon(const char *text, bool endGame) {
int16 w, h;
@@ -565,10 +565,10 @@
~BalloonManager_br();
void freeBalloons();
- int setLocationBalloon(char *text, bool endGame);
- int setDialogueBalloon(char *text, uint16 winding, TextColor textColor);
- int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor);
- void setBalloonText(uint id, char *text, TextColor textColor);
+ int setLocationBalloon(const char *text, bool endGame);
+ int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor);
+ int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor);
+ void setBalloonText(uint id, const char *text, TextColor textColor);
int hitTestDialogueBalloon(int x, int y);
};
@@ -594,7 +594,7 @@
return surf;
}
-int BalloonManager_br::setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) {
+int BalloonManager_br::setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) {
cacheAnims();
int id = _numBalloons;
@@ -630,7 +630,7 @@
return id;
}
-int BalloonManager_br::setDialogueBalloon(char *text, uint16 winding, TextColor textColor) {
+int BalloonManager_br::setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) {
cacheAnims();
int id = _numBalloons;
@@ -666,7 +666,7 @@
return id;
}
-void BalloonManager_br::setBalloonText(uint id, char *text, TextColor textColor) {
+void BalloonManager_br::setBalloonText(uint id, const char *text, TextColor textColor) {
Balloon *balloon = getBalloon(id);
StringWriter_BR sw(_vm->_dialogueFont);
@@ -692,7 +692,7 @@
return id;
}
-int BalloonManager_br::setLocationBalloon(char *text, bool endGame) {
+int BalloonManager_br::setLocationBalloon(const char *text, bool endGame) {
StringExtent_BR se(_vm->_dialogueFont);
se.calc(text, 240);
Modified: scummvm/trunk/engines/parallaction/dialogue.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/dialogue.cpp 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/dialogue.cpp 2008-12-13 03:37:43 UTC (rev 35326)
@@ -173,11 +173,11 @@
// display suitable answers
if (((a->_yesFlags & flags) == a->_yesFlags) && ((a->_noFlags & ~flags) == a->_noFlags)) {
- int id = _vm->_balloonMan->setDialogueBalloon(a->_text, 1, BalloonManager::kUnselectedColor);
+ int id = _vm->_balloonMan->setDialogueBalloon(a->_text.c_str(), 1, BalloonManager::kUnselectedColor);
assert(id >= 0);
_visAnswers[id] = i;
- _askPassword = (strstr(a->_text, "%P") != NULL);
+ _askPassword = a->_text.contains("%P");
_numVisAnswers++;
return true;
@@ -203,7 +203,7 @@
if (_numVisAnswers == 1) {
int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y);
_vm->_gfx->setItemFrame(id, _q->_answers[0]->_mood & 0xF);
- _vm->_balloonMan->setBalloonText(0, _q->_answers[_visAnswers[0]]->_text, BalloonManager::kNormalColor);
+ _vm->_balloonMan->setBalloonText(0, _q->_answers[_visAnswers[0]]->_text.c_str(), BalloonManager::kNormalColor);
} else
if (_numVisAnswers > 1) {
int id = _vm->_gfx->setItem(_answerer, _ballonPos._answerChar.x, _ballonPos._answerChar.y);
@@ -216,9 +216,9 @@
}
bool DialogueManager::displayQuestion() {
- if (!scumm_stricmp(_q->_text, "NULL")) return false;
+ if (!_q->_text.compareToIgnoreCase("NULL")) return false;
- _vm->_balloonMan->setSingleBalloon(_q->_text, _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor);
+ _vm->_balloonMan->setSingleBalloon(_q->_text.c_str(), _ballonPos._questionBalloon.x, _ballonPos._questionBalloon.y, _q->_mood & 0x10, BalloonManager::kNormalColor);
int id = _vm->_gfx->setItem(_questioner, _ballonPos._questionChar.x, _ballonPos._questionChar.y);
_vm->_gfx->setItemFrame(id, _q->_mood & 0xF);
@@ -256,7 +256,7 @@
}
if (_passwordChanged) {
- _vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text, BalloonManager::kNormalColor);
+ _vm->_balloonMan->setBalloonText(0, _q->_answers[0]->_text.c_str(), BalloonManager::kNormalColor);
_passwordChanged = false;
}
@@ -286,11 +286,11 @@
if (_selection != _oldSelection) {
if (_oldSelection != -1) {
- _vm->_balloonMan->setBalloonText(_oldSelection, _q->_answers[_visAnswers[_oldSelection]]->_text, BalloonManager::kUnselectedColor);
+ _vm->_balloonMan->setBalloonText(_oldSelection, _q->_answers[_visAnswers[_oldSelection]]->_text.c_str(), BalloonManager::kUnselectedColor);
}
if (_selection != -1) {
- _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text, BalloonManager::kSelectedColor);
+ _vm->_balloonMan->setBalloonText(_selection, _q->_answers[_visAnswers[_selection]]->_text.c_str(), BalloonManager::kSelectedColor);
_vm->_gfx->setItemFrame(0, _q->_answers[_visAnswers[_selection]]->_mood & 0xF);
}
}
@@ -323,7 +323,7 @@
return;
}
- if (!scumm_stricmp(_q->_answers[0]->_text, "NULL")) {
+ if (!_q->_answers[0]->_text.compareToIgnoreCase("NULL")) {
_answerId = 0;
_state = NEXT_QUESTION;
return;
@@ -354,7 +354,7 @@
void DialogueManager::nextQuestion() {
debugC(9, kDebugDialogue, "nextQuestion\n");
- _q = _q->_answers[_answerId]->_following._question;
+ _q = _q->_answers[_answerId]->_followingQuestion;
if (_q == 0) {
_state = DIALOGUE_OVER;
} else {
Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/graphics.h 2008-12-13 03:37:43 UTC (rev 35326)
@@ -141,6 +141,8 @@
}
void create(uint16 width, uint16 height) {
+ free();
+
w = width;
internalWidth = w >> 2;
h = height;
@@ -221,6 +223,8 @@
}
void create(uint16 width, uint16 height) {
+ free();
+
w = width;
internalWidth = w >> 3;
h = height;
@@ -467,10 +471,10 @@
virtual ~BalloonManager() { }
virtual void freeBalloons() = 0;
- virtual int setLocationBalloon(char *text, bool endGame) = 0;
- virtual int setDialogueBalloon(char *text, uint16 winding, TextColor textColor) = 0;
- virtual int setSingleBalloon(char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) = 0;
- virtual void setBalloonText(uint id, char *text, TextColor textColor) = 0;
+ virtual int setLocationBalloon(const char *text, bool endGame) = 0;
+ virtual int setDialogueBalloon(const char *text, uint16 winding, TextColor textColor) = 0;
+ virtual int setSingleBalloon(const char *text, uint16 x, uint16 y, uint16 winding, TextColor textColor) = 0;
+ virtual void setBalloonText(uint id, const char *text, TextColor textColor) = 0;
virtual int hitTestDialogueBalloon(int x, int y) = 0;
};
Modified: scummvm/trunk/engines/parallaction/objects.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/objects.cpp 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/objects.cpp 2008-12-13 03:37:43 UTC (rev 35326)
@@ -173,7 +173,7 @@
switch (_type & 0xFFFF) {
case kZoneExamine:
free(u.examine->_filename);
- free(u.examine->_description);
+ u.examine->_description.clear();
delete u.examine->_cnv;
delete u.examine;
break;
@@ -201,7 +201,7 @@
case kZoneMerge:
delete u.merge;
break;
-
+
case kZonePath:
delete u.path;
break;
@@ -240,19 +240,13 @@
}
Answer::Answer() {
- _text = NULL;
_mood = 0;
- _following._question = NULL;
+ _followingQuestion = NULL;
_noFlags = 0;
_yesFlags = 0;
}
-Answer::~Answer() {
- free(_text);
-}
-
Question::Question() {
- _text = NULL;
_mood = 0;
for (uint32 i = 0; i < NUM_ANSWERS; i++)
@@ -261,12 +255,9 @@
}
Question::~Question() {
-
for (uint32 i = 0; i < NUM_ANSWERS; i++) {
delete _answers[i];
}
-
- free(_text);
}
Instruction::Instruction() {
Modified: scummvm/trunk/engines/parallaction/objects.h
===================================================================
--- scummvm/trunk/engines/parallaction/objects.h 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/objects.h 2008-12-13 03:37:43 UTC (rev 35326)
@@ -162,22 +162,20 @@
#define NUM_ANSWERS 5
struct Answer {
- char* _text;
+ Common::String _text;
uint16 _mood;
- union {
- Question* _question;
- char* _name;
- } _following;
+ Question* _followingQuestion;
+ Common::String _followingName;
+
CommandList _commands;
uint32 _noFlags;
uint32 _yesFlags;
Answer();
- ~Answer();
};
struct Question {
- char* _text;
+ Common::String _text;
uint16 _mood;
Answer* _answers[NUM_ANSWERS];
@@ -215,11 +213,10 @@
};
struct ExamineData {
GfxObj *_cnv;
- char* _description;
+ Common::String _description;
char* _filename;
ExamineData() {
- _description = NULL;
_filename = NULL;
_cnv = NULL;
}
Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp 2008-12-13 03:37:43 UTC (rev 35326)
@@ -116,8 +116,6 @@
_location._startPosition.x = -1000;
_location._startPosition.y = -1000;
_location._startFrame = 0;
- _location._comment = NULL;
- _location._endComment = NULL;
_pathBuffer = 0;
@@ -265,7 +263,7 @@
}
-Location::Location() : _comment(0), _endComment(0) {
+Location::Location() {
cleanup(true);
}
@@ -274,8 +272,8 @@
}
void Location::cleanup(bool removeAll) {
- free(_comment); _comment = 0;
- free(_endComment); _endComment = 0;
+ _comment.clear();
+ _endComment.clear();
freeZones(removeAll);
freeAnimations();
@@ -324,8 +322,8 @@
return;
}
-void Parallaction::showLocationComment(const char *text, bool end) {
- _balloonMan->setLocationBalloon(const_cast<char*>(text), end);
+void Parallaction::showLocationComment(const Common::String &text, bool end) {
+ _balloonMan->setLocationBalloon(text.c_str(), end);
}
@@ -400,7 +398,7 @@
void Parallaction::doLocationEnterTransition() {
debugC(2, kDebugExec, "doLocationEnterTransition");
- if (!_location._comment) {
+ if (_location._comment.empty()) {
return;
}
@@ -568,7 +566,7 @@
ExamineData *data = _commentZone->u.examine;
- if (!data->_description) {
+ if (data->_description.empty()) {
return;
}
@@ -581,7 +579,7 @@
}
_gfx->setHalfbriteMode(true);
- _balloonMan->setSingleBalloon(data->_description, 0, 90, 0, BalloonManager::kNormalColor);
+ _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 90, 0, BalloonManager::kNormalColor);
Common::Rect r;
data->_cnv->getRect(0, r);
id = _gfx->setItem(data->_cnv, 140, (_screenHeight - r.height())/2);
@@ -589,13 +587,13 @@
id = _gfx->setItem(_char._head, 100, 152);
_gfx->setItemFrame(id, 0);
} else {
- _balloonMan->setSingleBalloon(data->_description, 140, 10, 0, BalloonManager::kNormalColor);
+ _balloonMan->setSingleBalloon(data->_description.c_str(), 140, 10, 0, BalloonManager::kNormalColor);
id = _gfx->setItem(_char._talk, 190, 80);
_gfx->setItemFrame(id, 0);
}
} else
if (getGameType() == GType_BRA) {
- _balloonMan->setSingleBalloon(data->_description, 0, 0, 1, BalloonManager::kNormalColor);
+ _balloonMan->setSingleBalloon(data->_description.c_str(), 0, 0, 1, BalloonManager::kNormalColor);
int id = _gfx->setItem(_char._talk, 10, 80);
_gfx->setItemFrame(id, 0);
}
Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/parallaction.h 2008-12-13 03:37:43 UTC (rev 35326)
@@ -131,8 +131,8 @@
CommandList _aCommands;
CommandList _commands;
- char *_comment;
- char *_endComment;
+ Common::String _comment;
+ Common::String _endComment;
ZoneList _zones;
AnimationList _animations;
@@ -316,7 +316,7 @@
void doLocationEnterTransition();
void allocateLocationSlot(const char *name);
void finalizeLocationParsing();
- void showLocationComment(const char *text, bool end);
+ void showLocationComment(const Common::String &text, bool end);
void setupBalloonManager();
public:
Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/parser.h 2008-12-13 03:37:43 UTC (rev 35326)
@@ -185,8 +185,8 @@
virtual void parseHearData(ZonePtr z);
virtual void parseSpeakData(ZonePtr z);
- char *parseComment();
- char *parseDialogueString();
+ Common::String parseComment();
+ Common::String parseDialogueString();
Dialogue *parseDialogue();
void resolveDialogueForwards(Dialogue *dialogue, uint numQuestions, Table &forwards);
Answer *parseAnswer();
@@ -216,7 +216,7 @@
}
public:
- LocationParser_ns(Parallaction_ns *vm) : _vm(vm), _commandsNames(0), _locationStmt(0),
+ LocationParser_ns(Parallaction_ns *vm) : _vm(vm), _commandsNames(0), _locationStmt(0),
_locationZoneStmt(0), _locationAnimStmt(0) {
}
@@ -261,10 +261,9 @@
class LocationParser_br : public LocationParser_ns {
protected:
+ Parallaction_br* _vm;
Table *_audioCommandsNames;
- Parallaction_br* _vm;
-
DECLARE_UNQUALIFIED_LOCATION_PARSER(location);
DECLARE_UNQUALIFIED_LOCATION_PARSER(zone);
DECLARE_UNQUALIFIED_LOCATION_PARSER(animation);
@@ -327,10 +326,9 @@
class ProgramParser_ns {
protected:
- Parser *_parser;
Parallaction_ns *_vm;
+ Parser *_parser;
-
Script *_script;
ProgramPtr _program;
Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp 2008-12-13 03:36:28 UTC (rev 35325)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp 2008-12-13 03:37:43 UTC (rev 35326)
@@ -901,7 +901,7 @@
_script->readLineToken(true);
answer->_mood = atoi(_tokens[0]);
- answer->_following._name = parseDialogueString();
+ answer->_followingName = parseDialogueString();
_script->readLineToken(true);
if (!scumm_stricmp(_tokens[0], "commands")) {
@@ -928,27 +928,26 @@
Answer *answer = question->_answers[j];
if (answer == 0) continue;
- int16 index = forwards.lookup(answer->_following._name);
- free(answer->_following._name);
- answer->_following._name = 0;
+ int16 index = forwards.lookup(answer->_followingName.c_str());
+ answer->_followingName.clear();
if (index == Table::notFound)
- answer->_following._question = 0;
+ answer->_followingQuestion = 0;
else
- answer->_following._question = dialogue->_questions[index - 1];
+ answer->_followingQuestion = dialogue->_questions[index - 1];
}
}
}
-char *LocationParser_ns::parseDialogueString() {
- char buf[200];
- char *line = _script->readLine(buf, 200);
+Common::String LocationParser_ns::parseDialogueString() {
+ char buf[400];
+ char *line = _script->readLine(buf, 400);
if (line == 0) {
return 0;
}
- return strdup(line);
+ return Common::String(line);
}
@@ -1265,31 +1264,25 @@
// a comment can appear both at location and Zone levels
// comments are displayed into rectangles on the screen
//
-char *LocationParser_ns::parseComment() {
- const int tempSize = 1000;
- char temp[tempSize] = "\0";
- int len = 0;
+Common::String LocationParser_ns::parseComment() {
+ Common::String comment;
char buf[400];
do {
char *line = _script->readLine(buf, 400);
if (!scumm_stricmp(line, "endtext"))
break;
- strncat(temp, line, tempSize - len - 1);
- strcat(temp, " ");
- len = len + strlen(line) + 1;
- } while (len < tempSize);
+ if (comment.size() > 0)
+ comment += " ";
- if (len == 0) {
+ comment += line;
+ } while (true);
+
+ if (comment.size() == 0) {
return 0;
}
- if (len == tempSize) {
- warning("overflow in LocationParser_ns::parseComment (line %i)", _script->getLine());
- }
-
- temp[len-1] = '\0'; // removes the last space pasted in the string
- return strdup(temp);
+ return comment;
}
DECLARE_ZONE_PARSER(null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list