aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorGregory Montoir2007-02-25 22:24:11 +0000
committerGregory Montoir2007-02-25 22:24:11 +0000
commitca597dbf50bbc5c43a07f306e2407dd314411077 (patch)
tree43c20cdd4a3cec2c15e12788a5d271c8a4816cf2 /engines
parentc9f652dc1fb40f87d35a3700163b5e36dc6df0dd (diff)
downloadscummvm-rg350-ca597dbf50bbc5c43a07f306e2407dd314411077.tar.gz
scummvm-rg350-ca597dbf50bbc5c43a07f306e2407dd314411077.tar.bz2
scummvm-rg350-ca597dbf50bbc5c43a07f306e2407dd314411077.zip
reduced code dup, Queen::LineReader -> SeekableReadStream::readLine
svn-id: r25871
Diffstat (limited to 'engines')
-rw-r--r--engines/queen/credits.cpp15
-rw-r--r--engines/queen/credits.h5
-rw-r--r--engines/queen/journal.cpp6
-rw-r--r--engines/queen/logic.cpp115
-rw-r--r--engines/queen/logic.h43
-rw-r--r--engines/queen/resource.cpp35
-rw-r--r--engines/queen/resource.h19
7 files changed, 91 insertions, 147 deletions
diff --git a/engines/queen/credits.cpp b/engines/queen/credits.cpp
index a88c67e587..8e4a716a8c 100644
--- a/engines/queen/credits.cpp
+++ b/engines/queen/credits.cpp
@@ -30,14 +30,8 @@
namespace Queen {
Credits::Credits(QueenEngine *vm, const char* filename) :
- _vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0) {
- uint32 size;
- char *buf = (char *)_vm->resource()->loadFile(filename, 0, &size);
- _credits = new LineReader(buf, size);
-}
-
-Credits::~Credits() {
- delete _credits;
+ _vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0), _lineNum(0) {
+ _vm->resource()->loadTextFile(filename, _credits);
}
void Credits::nextRoom() {
@@ -62,8 +56,9 @@ void Credits::update() {
if (-1 == _pause)
return;
- for (;;) {
- const char *line = _credits->nextLine();
+ while (_lineNum < _credits.size()) {
+ const char *line = _credits[_lineNum].c_str();
+ ++_lineNum;
if (0 == memcmp(line, "EN", 2)) {
_running = false;
diff --git a/engines/queen/credits.h b/engines/queen/credits.h
index 2882a31bcf..1cf81a3856 100644
--- a/engines/queen/credits.h
+++ b/engines/queen/credits.h
@@ -35,7 +35,6 @@ class Credits {
public:
Credits(QueenEngine *vm, const char* filename);
- ~Credits();
//! update/display credits for current room
void update();
@@ -77,8 +76,10 @@ private:
//! current text position
int _zone;
+ uint _lineNum;
+
//! contains the credits description
- LineReader *_credits;
+ Common::StringList _credits;
QueenEngine *_vm;
};
diff --git a/engines/queen/journal.cpp b/engines/queen/journal.cpp
index 11213e9714..3107f8ea6b 100644
--- a/engines/queen/journal.cpp
+++ b/engines/queen/journal.cpp
@@ -418,7 +418,11 @@ void Journal::drawPanel(const int *frames, const int *titles, int n) {
int y = 8;
while (n--) {
showBob(bobNum++, 32, y, *frames++);
- drawPanelText(y + 12, _vm->logic()->joeResponse(*titles++));
+ // trim panel texts for spanish version
+ char buf[128];
+ strncpy(buf, _vm->logic()->joeResponse(*titles++), 128);
+ buf[127] = 0;
+ drawPanelText(y + 12, Common::trim(buf));
y += 48;
}
}
diff --git a/engines/queen/logic.cpp b/engines/queen/logic.cpp
index 1931ee831d..fcdabb0ae7 100644
--- a/engines/queen/logic.cpp
+++ b/engines/queen/logic.cpp
@@ -181,65 +181,21 @@ void Logic::readQueenJas() {
if (memcmp(ptr, _vm->resource()->getJASVersion(), 5) != 0) {
warning("Unexpected queen.jas file format");
}
-
delete[] jas;
- uint32 size;
- char *buf = (char *)_vm->resource()->loadFile("QUEEN2.JAS", 0, &size);
- LineReader queen2jas(buf, size);
-
- _objDescription.push_back("");
- for (i = 1; i <= _numDescriptions; i++) {
- _objDescription.push_back(queen2jas.nextLine());
- }
+ _vm->resource()->loadTextFile("QUEEN2.JAS", _jasStringList);
+ _jasStringOffset[0] = 0;
+ _jasStringOffset[1] = _jasStringOffset[0] + _numDescriptions;
+ _jasStringOffset[2] = _jasStringOffset[1] + _numNames;
+ _jasStringOffset[3] = _jasStringOffset[2] + _numRooms;
+ _jasStringOffset[4] = _jasStringOffset[3] + 12;
+ _jasStringOffset[5] = _jasStringOffset[4] + JOE_RESPONSE_MAX;
+ _jasStringOffset[6] = _jasStringOffset[5] + _numAAnim;
+ _jasStringOffset[7] = _jasStringOffset[6] + _numAName;
// Patch for German text bug
if (_vm->resource()->getLanguage() == Common::DE_DEU) {
- _objDescription[296] = "Es bringt nicht viel, das festzubinden.";
- }
-
- _objName.push_back("");
- for (i = 1; i <= _numNames; i++) {
- _objName.push_back(queen2jas.nextLine());
- }
-
- _roomName.push_back("");
- for (i = 1; i <= _numRooms; i++) {
- _roomName.push_back(queen2jas.nextLine());
- }
-
- _verbName.push_back("");
- for (i = 1; i <= 12; i++) {
- _verbName.push_back(queen2jas.nextLine());
- }
-
- _joeResponse.push_back("");
- for (i = 1; i <= JOE_RESPONSE_MAX; i++) {
- char *defaultResponse = queen2jas.nextLine();
-
- // In the spanish version, captions of journal buttons have leading & trailing
- // whitespaces (they probably did it that way to center the texts). As we do
- // differently (see code in journal.cpp), we remove these extra characters here.
- if (_vm->resource()->getLanguage() == Common::ES_ESP && i >= 30 && i <= 35) {
- defaultResponse = Common::trim(defaultResponse);
- }
-
- _joeResponse.push_back(defaultResponse);
- }
-
- _aAnim.push_back("");
- for (i = 1; i <= _numAAnim; i++) {
- _aAnim.push_back(queen2jas.nextLine());
- }
-
- _aName.push_back("");
- for (i = 1; i <= _numAName; i++) {
- _aName.push_back(queen2jas.nextLine());
- }
-
- _aFile.push_back("");
- for (i = 1; i <= _numAFile; i++) {
- _aFile.push_back(queen2jas.nextLine());
+ _jasStringList[_jasStringOffset[JSO_OBJECT_DESCRIPTION] + 296 - 1] = "Es bringt nicht viel, das festzubinden.";
}
}
@@ -256,11 +212,6 @@ void Logic::start() {
_newRoom = _currentRoom;
}
-ObjectData* Logic::objectData(int index) const {
- assert(index >= 0 && index <= _numObjects);
- return &_objectData[index];
-}
-
uint16 Logic::findBob(uint16 obj) const {
assert(obj <= _numObjects);
@@ -441,27 +392,45 @@ void Logic::gameState(int index, int16 newValue) {
const char *Logic::roomName(uint16 roomNum) const {
assert(roomNum >= 1 && roomNum <= _numRooms);
- return _roomName[roomNum].c_str();
+ return _jasStringList[_jasStringOffset[JSO_ROOM_NAME] + roomNum - 1].c_str();
}
const char *Logic::objectName(uint16 objNum) const {
assert(objNum >= 1 && objNum <= _numNames);
- return _objName[objNum].c_str();
+ return _jasStringList[_jasStringOffset[JSO_OBJECT_NAME] + objNum - 1].c_str();
}
const char *Logic::objectTextualDescription(uint16 objNum) const {
assert(objNum >= 1 && objNum <= _numDescriptions);
- return _objDescription[objNum].c_str();
+ return _jasStringList[_jasStringOffset[JSO_OBJECT_DESCRIPTION] + objNum - 1].c_str();
}
const char *Logic::joeResponse(int i) const {
assert(i >= 1 && i <= JOE_RESPONSE_MAX);
- return _joeResponse[i].c_str();
+ return _jasStringList[_jasStringOffset[JSO_JOE_RESPONSE] + i - 1].c_str();
}
const char *Logic::verbName(Verb v) const {
assert(v >= 0 && v <= 12);
- return _verbName[v].c_str();
+ if (v == 0) {
+ return "";
+ }
+ return _jasStringList[_jasStringOffset[JSO_VERB_NAME] + v - 1].c_str();
+}
+
+const char *Logic::actorAnim(int num) const {
+ assert(num >= 1 && num < _numAAnim);
+ return _jasStringList[_jasStringOffset[JSO_ACTOR_ANIM] + num - 1].c_str();
+}
+
+const char *Logic::actorName(int num) const {
+ assert(num >= 1 && num < _numAName);
+ return _jasStringList[_jasStringOffset[JSO_ACTOR_NAME] + num - 1].c_str();
+}
+
+const char *Logic::actorFile(int num) const {
+ assert(num >= 1 && num < _numAFile);
+ return _jasStringList[_jasStringOffset[JSO_ACTOR_FILE] + num - 1].c_str();
}
void Logic::eraseRoom() {
@@ -559,7 +528,7 @@ ActorData *Logic::findActor(uint16 noun, const char *name) const {
for (uint16 i = 1; i <= _numActors; ++i) {
ActorData *pad = &_actorData[i];
if (pad->room == _currentRoom && gameState(pad->gsSlot) == pad->gsValue) {
- if (bobNum == pad->bobNum || (name && _aName[pad->name] == name)) {
+ if (bobNum == pad->bobNum || (name && strcmp(actorName(pad->name), name) == 0)) {
return pad;
}
}
@@ -568,18 +537,18 @@ ActorData *Logic::findActor(uint16 noun, const char *name) const {
return NULL;
}
-bool Logic::initPerson(uint16 noun, const char *actorName, bool loadBank, Person *pp) {
- const ActorData *pad = findActor(noun, actorName);
+bool Logic::initPerson(uint16 noun, const char *name, bool loadBank, Person *pp) {
+ const ActorData *pad = findActor(noun, name);
if (pad != NULL) {
pp->actor = pad;
- pp->name = _aName[pad->name].c_str();
+ pp->name = actorName(pad->name);
if (pad->anim != 0) {
- pp->anim = _aAnim[pad->anim].c_str();
+ pp->anim = actorAnim(pad->anim);
} else {
pp->anim = NULL;
}
if (loadBank && pad->file != 0) {
- _vm->bankMan()->load(_aFile[pad->file].c_str(), pad->bankNum);
+ _vm->bankMan()->load(actorFile(pad->file), pad->bankNum);
// if there is no valid actor file (ie pad->file is 0), the person
// data is already loaded as it is included in objects room bank (.bbk)
}
@@ -613,7 +582,7 @@ void Logic::loadJoeBanks(const char *animBank, const char *standBank) {
}
void Logic::setupJoe() {
- loadJoeBanks("joe_a.BBK", "joe_b.BBK");
+ loadJoeBanks("JOE_A.BBK", "JOE_B.BBK");
joePrevFacing(DIR_FRONT);
joeFacing(DIR_FRONT);
}
@@ -871,7 +840,7 @@ void Logic::playCutaway(const char *cutFile, char *next) {
}
void Logic::makeJoeSpeak(uint16 descNum, bool objectType) {
- const char *text = objectType ? _objDescription[descNum].c_str() : _joeResponse[descNum].c_str();
+ const char *text = objectType ? objectTextualDescription(descNum) : joeResponse(descNum);
if (objectType) {
descNum += JOE_RESPONSE_MAX;
}
@@ -1963,8 +1932,8 @@ void Logic::asmScrollTitle() {
bob->y = 300;
bob->scale = 100;
while (bob->y >= 120) {
- bob->y -= 4;
_vm->update();
+ bob->y -= 4;
}
}
diff --git a/engines/queen/logic.h b/engines/queen/logic.h
index 1c0868babc..0c68f80345 100644
--- a/engines/queen/logic.h
+++ b/engines/queen/logic.h
@@ -43,9 +43,20 @@ enum JoeWalkMode {
JWM_SPEAK = 3
};
+enum {
+ JSO_OBJECT_DESCRIPTION = 0,
+ JSO_OBJECT_NAME,
+ JSO_ROOM_NAME,
+ JSO_VERB_NAME,
+ JSO_JOE_RESPONSE,
+ JSO_ACTOR_ANIM,
+ JSO_ACTOR_NAME,
+ JSO_ACTOR_FILE,
+ JSO_COUNT
+};
+
class Credits;
class Journal;
-class LineReader;
class QueenEngine;
class Logic {
@@ -72,7 +83,7 @@ public:
_newRoom = room;
}
- ObjectData *objectData(int index) const;
+ ObjectData *objectData(int index) const { return &_objectData[index]; }
uint16 roomData(int room) const { return _roomData[room]; }
GraphicData *graphicData(int index) const { return &_graphicData[index]; }
ItemData *itemData(int index) const { return &_itemData[index]; }
@@ -117,6 +128,9 @@ public:
const char *objectTextualDescription(uint16 objNum) const;
const char *joeResponse(int i) const;
const char *verbName(Verb v) const;
+ const char *actorAnim(int num) const;
+ const char *actorName(int num) const;
+ const char *actorFile(int num) const;
void eraseRoom();
void setupRoom(const char *room, int comPanel, bool inCutaway);
@@ -321,30 +335,13 @@ protected:
//! actor initial position in room is _walkOffData[_entryObj]
int16 _entryObj;
- //! object description (Look At)
- Common::StringList _objDescription;
- uint16 _numDescriptions;
+ Common::StringList _jasStringList;
+ int _jasStringOffset[JSO_COUNT];
- Common::StringList _objName;
+ uint16 _numDescriptions;
uint16 _numNames;
-
- //! room name, prefix for data files (PCX, LUM...)
- Common::StringList _roomName;
-
- Common::StringList _verbName;
-
- Common::StringList _joeResponse;
-
- //! actor animation strings
- Common::StringList _aAnim;
uint16 _numAAnim;
-
- //! actor names
- Common::StringList _aName;
uint16 _numAName;
-
- //! actor filenames
- Common::StringList _aFile;
uint16 _numAFile;
struct {
@@ -366,7 +363,7 @@ protected:
//! cutscene counter
int _scene;
-
+
SpecialMoveProc _specialMoves[40];
Credits *_credits;
diff --git a/engines/queen/resource.cpp b/engines/queen/resource.cpp
index a7e029f0ce..0319d90a3f 100644
--- a/engines/queen/resource.cpp
+++ b/engines/queen/resource.cpp
@@ -90,10 +90,6 @@ Resource::~Resource() {
}
ResourceEntry *Resource::resourceEntry(const char *filename) const {
- if (filename[0] == 0 || strlen(filename) >= 14) {
- uint8 *p = 0;
- *p = 0x1234;
- }
assert(filename[0] && strlen(filename) < 14);
Common::String entryName(filename);
@@ -129,6 +125,18 @@ uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, uint32 *size)
return dstBuf;
}
+void Resource::loadTextFile(const char *filename, Common::StringList &stringList) {
+ debug(7, "Resource::loadTextFile('%s')", filename);
+ ResourceEntry *re = resourceEntry(filename);
+ assert(re != NULL);
+ seekResourceFile(re->bundle, re->offset);
+ char buf[512];
+ Common::SeekableSubReadStream stream(&_resourceFile, re->offset, re->offset + re->size);
+ while (stream.readLine(buf, 512)) {
+ stringList.push_back(buf);
+ }
+}
+
bool Resource::detectVersion(DetectedGameVersion *ver, Common::File *f) {
memset(ver, 0, sizeof(DetectedGameVersion));
@@ -306,25 +314,6 @@ Common::File *Resource::findSound(const char *filename, uint32 *size) {
return NULL;
}
-LineReader::LineReader(char *buffer, uint32 bufsize) : _buffer(buffer), _bufSize(bufsize), _current(0) {
-}
-
-LineReader::~LineReader() {
- delete[] _buffer;
-}
-
-char *LineReader::nextLine() {
- char *startOfLine = _buffer + _current;
- char *curPos = startOfLine;
- while (curPos < _buffer + _bufSize && *curPos++ != 0xd) ;
- *(curPos - 1) = '\0'; // '\r'
- if (curPos < _buffer + _bufSize) {
- *curPos = '\0'; // '\n'
- _current = (curPos - _buffer) + 1;
- }
- return startOfLine;
-}
-
} // End of namespace Queen
#ifdef PALMOS_68K
diff --git a/engines/queen/resource.h b/engines/queen/resource.h
index 609e8edc8f..43e325f2ba 100644
--- a/engines/queen/resource.h
+++ b/engines/queen/resource.h
@@ -65,9 +65,12 @@ public:
Resource();
~Resource();
- //! loads the specified from the resource file
+ //! loads a binary file
uint8 *loadFile(const char *filename, uint32 skipBytes = 0, uint32 *size = NULL);
+ //! loads a text file
+ void loadTextFile(const char *filename, Common::StringList &stringList);
+
//! returns true if the file is present in the resource
bool fileExists(const char *filename) const { return resourceEntry(filename) != NULL; }
@@ -167,20 +170,6 @@ protected:
#endif
};
-class LineReader {
-public:
-
- LineReader(char *buffer, uint32 bufsize);
- ~LineReader();
- char *nextLine();
-
-private:
-
- char *_buffer;
- uint32 _bufSize;
- int _current;
-};
-
} // End of namespace Queen
#endif