DREAMWEB: Streamline text file handling

This commit is contained in:
Willem Jan Palenstijn 2011-12-27 18:34:23 +01:00
parent df7bb24184
commit 08be0411b1
10 changed files with 132 additions and 108 deletions

View File

@ -244,6 +244,12 @@ p = parser(skip_binary_data = [
'mapstore',
'mapdata',
'backdrops',
'textfile1',
'textfile2',
'textfile3',
'puzzletext',
'commandtext',
'traveltext',
# vgagrafx.asm
'cityname',
'extragraphics1',

View File

@ -65,6 +65,8 @@ class DreamBase : public SegmentManager {
protected:
DreamWeb::DreamWebEngine *engine;
const char *_timedString;
// from backdrop.cpp
uint8 *_backdropBlocks;
BackdropMapFlag _backdropFlags[96];
@ -121,6 +123,14 @@ protected:
Common::List<Rain> _rainList;
uint8 _initialVars[kLengthOfVars]; // TODO: This shouldn't be necessary
// textfiles
TextFile _textFile1;
TextFile _textFile2;
TextFile _textFile3;
TextFile _travelText;
TextFile _puzzleText;
TextFile _commandText;
public:
DreamBase(DreamWeb::DreamWebEngine *en);
@ -481,6 +491,7 @@ public:
uint16 allocateMem(uint16 paragraphs);
void deallocateMem(uint16 segment);
uint16 allocateAndLoad(unsigned int size);
void loadTextFile(TextFile &file, const char *fileName);
uint16 standardLoad(const char *fileName, uint16 *outSizeInBytes = NULL); // Returns a segment handle which needs to be freed with deallocatemem for symmetry
void *standardLoadCPP(const char *fileName, uint16 *outSizeInBytes = NULL); // And this one should be 'free'd
void loadIntoTemp(const char *fileName);
@ -625,7 +636,7 @@ public:
void dumpWatch();
void watchCount();
void signOn();
void searchForFiles(uint16 segment);
void searchForFiles(const char *filesString);
void triggerMessage(uint16 index);
void processTrigger();
void dreamweb();

View File

@ -69,11 +69,9 @@ void DreamGenContext::__start() {
//0x0120: .... .... .... ....
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
//0x0130: .... .... .... ....
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0140: .... .... .... ....
0xff, 0xff, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//0x0150: .... .... .... ....
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, };
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, };
ds.assign(src, src + sizeof(src));
dreamweb();
}

View File

@ -268,34 +268,28 @@ static const uint16 kSetframes = 310;
static const uint16 kFreeframes = 312;
static const uint16 kPeople = 314;
static const uint16 kReels = 316;
static const uint16 kCommandtext = 318;
static const uint16 kPuzzletext = 320;
static const uint16 kTraveltext = 322;
static const uint16 kTempgraphics = 324;
static const uint16 kTempgraphics2 = 326;
static const uint16 kTempgraphics3 = 328;
static const uint16 kTempsprites = 330;
static const uint16 kTextfile1 = 332;
static const uint16 kTextfile2 = 334;
static const uint16 kTextfile3 = 336;
static const uint16 kBlinkframe = 338;
static const uint16 kBlinkcount = 339;
static const uint16 kReasseschanges = 340;
static const uint16 kPointerspath = 341;
static const uint16 kManspath = 342;
static const uint16 kPointerfirstpath = 343;
static const uint16 kFinaldest = 344;
static const uint16 kDestination = 345;
static const uint16 kLinestartx = 346;
static const uint16 kLinestarty = 348;
static const uint16 kLineendx = 350;
static const uint16 kLineendy = 352;
static const uint16 kLinepointer = 354;
static const uint16 kLinedirection = 355;
static const uint16 kLinelength = 356;
static const uint16 kCh0playing = 357;
static const uint16 kCh0repeat = 358;
static const uint16 kCh1playing = 359;
static const uint16 kTempgraphics = 318;
static const uint16 kTempgraphics2 = 320;
static const uint16 kTempgraphics3 = 322;
static const uint16 kTempsprites = 324;
static const uint16 kBlinkframe = 326;
static const uint16 kBlinkcount = 327;
static const uint16 kReasseschanges = 328;
static const uint16 kPointerspath = 329;
static const uint16 kManspath = 330;
static const uint16 kPointerfirstpath = 331;
static const uint16 kFinaldest = 332;
static const uint16 kDestination = 333;
static const uint16 kLinestartx = 334;
static const uint16 kLinestarty = 336;
static const uint16 kLineendx = 338;
static const uint16 kLineendy = 340;
static const uint16 kLinepointer = 342;
static const uint16 kLinedirection = 343;
static const uint16 kLinelength = 344;
static const uint16 kCh0playing = 345;
static const uint16 kCh0repeat = 346;
static const uint16 kCh1playing = 347;
static const uint16 kBlocktextdat = (0);
static const uint16 kPersonframes = (0);
static const uint16 kDebuglevel1 = (0);

View File

@ -91,9 +91,11 @@ void DreamBase::useMon() {
} while (!stop);
getRidOfTemp();
getRidOfTempCharset();
deallocateMem(data.word(kTextfile1));
deallocateMem(data.word(kTextfile2));
deallocateMem(data.word(kTextfile3));
_textFile1.clear();
_textFile2.clear();
_textFile3.clear();
data.byte(kGetback) = 1;
playChannel1(26);
data.byte(kManisoffscreen) = 0;
@ -324,7 +326,7 @@ void DreamBase::randomAccess(uint16 count) {
void DreamBase::monMessage(uint8 index) {
assert(index > 0);
const char *string = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0);
const char *string = _textFile1._text;
for (uint8 i = 0; i < index; ++i) {
while (*string++ != '+') {
}
@ -376,21 +378,21 @@ void DreamBase::printOuterMon() {
void DreamBase::loadPersonal() {
if (data.byte(kLocation) == 0 || data.byte(kLocation) == 42)
data.word(kTextfile1) = standardLoad("DREAMWEB.T01"); // monitor file 1
loadTextFile(_textFile1, "DREAMWEB.T01"); // monitor file 1
else
data.word(kTextfile1) = standardLoad("DREAMWEB.T02"); // monitor file 2
loadTextFile(_textFile1, "DREAMWEB.T02"); // monitor file 2
}
void DreamBase::loadNews() {
// textfile2 holds information accessible by anyone
if (data.byte(kNewsitem) == 0)
data.word(kTextfile2) = standardLoad("DREAMWEB.T10"); // monitor file 10
loadTextFile(_textFile2, "DREAMWEB.T10"); // monitor file 10
else if (data.byte(kNewsitem) == 1)
data.word(kTextfile2) = standardLoad("DREAMWEB.T11"); // monitor file 11
loadTextFile(_textFile2, "DREAMWEB.T11"); // monitor file 11
else if (data.byte(kNewsitem) == 2)
data.word(kTextfile2) = standardLoad("DREAMWEB.T12"); // monitor file 12
loadTextFile(_textFile2, "DREAMWEB.T12"); // monitor file 12
else
data.word(kTextfile2) = standardLoad("DREAMWEB.T13"); // monitor file 13
loadTextFile(_textFile2, "DREAMWEB.T13"); // monitor file 13
}
void DreamBase::loadCart() {
@ -401,15 +403,15 @@ void DreamBase::loadCart() {
cartridgeId = getExAd(cartridgeIndex)->id[3] + 1;
if (cartridgeId == 0)
data.word(kTextfile3) = standardLoad("DREAMWEB.T20"); // monitor file 20
loadTextFile(_textFile3, "DREAMWEB.T20"); // monitor file 20
else if (cartridgeId == 1)
data.word(kTextfile3) = standardLoad("DREAMWEB.T21"); // monitor file 21
loadTextFile(_textFile3, "DREAMWEB.T21"); // monitor file 21
else if (cartridgeId == 2)
data.word(kTextfile3) = standardLoad("DREAMWEB.T22"); // monitor file 22
loadTextFile(_textFile3, "DREAMWEB.T22"); // monitor file 22
else if (cartridgeId == 3)
data.word(kTextfile3) = standardLoad("DREAMWEB.T23"); // monitor file 23
loadTextFile(_textFile3, "DREAMWEB.T23"); // monitor file 23
else
data.word(kTextfile3) = standardLoad("DREAMWEB.T24"); // monitor file 24
loadTextFile(_textFile3, "DREAMWEB.T24"); // monitor file 24
}
void DreamBase::showKeys() {
@ -479,9 +481,9 @@ void DreamBase::dirCom() {
monitorLogo();
scrollMonitor();
monMessage(9);
searchForFiles(data.word(kTextfile1));
searchForFiles(data.word(kTextfile2));
searchForFiles(data.word(kTextfile3));
searchForFiles(_textFile1._text);
searchForFiles(_textFile2._text);
searchForFiles(_textFile3._text);
scrollMonitor();
}
@ -491,13 +493,13 @@ void DreamBase::dirFile(const char *dirName) {
memcpy(topic, dirName, 14);
topic[0] = 34;
const char *text = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0);
const char *text = _textFile1._text;
const char *found = searchForString(topic, text);
if (!found) {
text = (const char *)getSegment(data.word(kTextfile2)).ptr(kTextstart, 0);
text = _textFile2._text;
found = searchForString(topic, text);
if (!found) {
text = (const char *)getSegment(data.word(kTextfile3)).ptr(kTextstart, 0);
text = _textFile3._text;
found = searchForString(topic, text);
}
}
@ -540,13 +542,13 @@ void DreamBase::read() {
const char *topic = _currentFile;
const char *text = (const char *)getSegment(data.word(kTextfile1)).ptr(kTextstart, 0);
const char *text = _textFile1._text;
const char *found = searchForString(topic, text);
if (!found) {
text = (const char *)getSegment(data.word(kTextfile2)).ptr(kTextstart, 0);
text = _textFile2._text;
found = searchForString(topic, text);
if (!found) {
text = (const char *)getSegment(data.word(kTextfile3)).ptr(kTextstart, 0);
text = _textFile3._text;
found = searchForString(topic, text);
}
}
@ -644,8 +646,7 @@ void DreamBase::signOn() {
}
}
void DreamBase::searchForFiles(uint16 segment) {
const char *filesString = (const char *)getSegment(segment).ptr(kTextstart, 0);
void DreamBase::searchForFiles(const char *filesString) {
byte curChar;
while (true) {

View File

@ -92,7 +92,8 @@ void DreamBase::selectLocation() {
getRidOfTemp();
getRidOfTemp2();
getRidOfTemp3();
deallocateMem(data.word(kTraveltext));
_travelText.clear();
}
void DreamBase::showCity() {
@ -120,8 +121,7 @@ void DreamBase::lookAtPlace() {
if (_foreignRelease)
showFrame(tempGraphics3(), 60, 72+55+21, 4, 0);
uint16 offset = kTextstart + getSegment(data.word(kTraveltext)).word(data.byte(kDestpos) * 2);
const uint8 *string = getSegment(data.word(kTraveltext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_travelText.getString(data.byte(kDestpos));
findNextColon(&string);
uint16 y = (_foreignRelease) ? 84 + 4 : 84;
printDirect(&string, 63, &y, 191, 191 & 1);
@ -153,8 +153,7 @@ void DreamBase::locationPic() {
if (data.byte(kDestpos) == data.byte(kReallocation))
showFrame(tempGraphics(), 104, 140 + 14, 3, 0); // Currently in this location
uint16 offset = kTextstart + getSegment(data.word(kTraveltext)).word(data.byte(kDestpos) * 2);
const uint8 *string = getSegment(data.word(kTraveltext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_travelText.getString(data.byte(kDestpos));
DreamBase::printDirect(string, 50, 20, 241, 241 & 1);
}

View File

@ -917,8 +917,7 @@ void DreamBase::mugger(ReelRoutine &routine) {
createPanel2();
showIcon();
uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(41 * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_puzzleText.getString(41);
uint16 y = 104;
printDirect(&string, 33 + 20, &y, 241, 241 & 1);
workToScreen();

View File

@ -292,6 +292,23 @@ struct MapFlag {
uint8 _type;
};
struct TextFile {
TextFile() : _text(0) { }
uint16 _offsetsLE[66];
char *_text;
const char *getString(unsigned int i) const {
assert(i < 66);
return _text + READ_LE_UINT16(&_offsetsLE[i]);
}
void clear() {
delete[] _text;
_text = 0;
}
};
} // End of namespace DreamWeb
#endif

View File

@ -644,6 +644,23 @@ done: // The engine will need some cleaner finalization, let's put it here for n
engine->freeIcons2();
}
void DreamBase::loadTextFile(TextFile &file, const char *fileName)
{
FileHeader header;
Common::File f;
f.open(fileName);
f.read((uint8 *)&header, sizeof(FileHeader));
uint16 sizeInBytes = header.len(0);
assert(sizeInBytes >= 2*66);
delete[] file._text;
file._text = new char[sizeInBytes - 2*66];
f.read(file._offsetsLE, 2*66);
f.read(file._text, sizeInBytes - 2*66);
}
void DreamBase::screenUpdate() {
newPlace();
mainScreen();
@ -837,8 +854,7 @@ void DreamBase::putUnderTimed() {
void DreamBase::triggerMessage(uint16 index) {
multiGet(_mapStore, 174, 153, 200, 63);
uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(index * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_puzzleText.getString(index);
uint16 y = 156;
printDirect(&string, 174, &y, 141, true);
hangOn(140);
@ -877,9 +893,8 @@ void DreamBase::useTimedText() {
else if (data.word(kTimecount) > data.word(kCounttotimed))
return;
const uint8 *string = getSegment(data.word(kTimedseg)).ptr(data.word(kTimedoffset), 0);
uint16 y = data.byte(kTimedy);
printDirect(&string, data.byte(kTimedx), &y, 237, true);
const uint8 *string = (const uint8 *)_timedString;
printDirect(string, data.byte(kTimedx), data.byte(kTimedy), 237, true);
data.byte(kNeedtodumptimed) = 1;
}
@ -904,10 +919,8 @@ void DreamBase::setupTimedTemp(uint8 textIndex, uint8 voiceIndex, uint8 x, uint8
data.byte(kTimedx) = x;
data.word(kCounttotimed) = countToTimed;
data.word(kTimecount) = timeCount + countToTimed;
data.word(kTimedseg) = data.word(kTextfile1);
data.word(kTimedoffset) = kTextstart + getSegment(data.word(kTextfile1)).word(textIndex * 2);
const uint8 *string = getSegment(data.word(kTextfile1)).ptr(data.word(kTimedoffset), 0);
debug(1, "setupTimedTemp: (%d, %d) => '%s'", textIndex, voiceIndex, string);
_timedString = _textFile1.getString(textIndex);
debug(1, "setupTimedTemp: (%d, %d) => '%s'", textIndex, voiceIndex, _timedString);
}
void DreamBase::dumpTimedText() {
@ -1130,11 +1143,8 @@ void DreamBase::delTextLine() {
void DreamBase::commandOnly(uint8 command) {
delTextLine();
uint16 index = command * 2;
uint16 offset = kTextstart + getSegment(data.word(kCommandtext)).word(index);
uint16 y = data.word(kTextaddressy);
const uint8 *string = getSegment(data.word(kCommandtext)).ptr(offset, 0);
printDirect(&string, data.word(kTextaddressx), &y, data.byte(kTextlen), (bool)(data.byte(kTextlen) & 1));
const uint8 *string = (const uint8 *)_commandText.getString(command);
printDirect(string, data.word(kTextaddressx), data.word(kTextaddressy), data.byte(kTextlen), (bool)(data.byte(kTextlen) & 1));
data.byte(kNewtextline) = 1;
}
@ -1228,12 +1238,11 @@ void DreamBase::copyName(uint8 type, uint8 index, uint8 *dst) {
void DreamBase::commandWithOb(uint8 command, uint8 type, uint8 index) {
uint8 commandLine[64] = "OBJECT NAME ONE ";
delTextLine();
uint16 commandText = kTextstart + getSegment(data.word(kCommandtext)).word(command * 2);
uint8 textLen = data.byte(kTextlen);
{
const uint8 *string = getSegment(data.word(kCommandtext)).ptr(commandText, 0);
printDirect(string, data.word(kTextaddressx), data.word(kTextaddressy), textLen, (bool)(textLen & 1));
}
const uint8 *string = (const uint8 *)_commandText.getString(command);
printDirect(string, data.word(kTextaddressx), data.word(kTextaddressy), textLen, (bool)(textLen & 1));
copyName(type, index, commandLine);
uint16 x = data.word(kLastxpos);
if (command != 0)
@ -1628,14 +1637,12 @@ void DreamBase::animPointer() {
}
void DreamBase::printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered) {
uint16 offset = kTextstart + getSegment(data.word(kCommandtext)).word(index * 2);
const uint8 *string = getSegment(data.word(kCommandtext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_commandText.getString(index);
printDirect(string, x, y, maxWidth, centered);
}
void DreamBase::printMessage2(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered, uint8 count) {
uint16 offset = kTextstart + getSegment(data.word(kCommandtext)).word(index * 2);
const uint8 *string = getSegment(data.word(kCommandtext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_commandText.getString(index);
while (count--) {
findNextColon(&string);
}
@ -2033,8 +2040,8 @@ void DreamBase::readSetData() {
engine->setIcons2(icons2Buffer);
data.word(kMainsprites) = standardLoad("DREAMWEB.S00");
data.word(kPuzzletext) = standardLoad("DREAMWEB.T80");
data.word(kCommandtext) = standardLoad("DREAMWEB.T84");
loadTextFile(_puzzleText, "DREAMWEB.T80");
loadTextFile(_commandText, "DREAMWEB.T84");
useCharset1();
// FIXME: Why is this commented out?
@ -2128,7 +2135,7 @@ void DreamBase::getRidOfTemp() {
}
void DreamBase::getRidOfTempText() {
deallocateMem(data.word(kTextfile1));
_textFile1.clear();
}
void DreamBase::getRidOfTemp2() {
@ -2359,10 +2366,7 @@ void DreamBase::examIcon() {
}
const uint8 *DreamBase::getTextInFile1(uint16 index) {
SegmentRef text = getSegment(data.word(kTextfile1));
uint16 offset = text.word(index * 2) + kTextstart;
const uint8 *string = text.ptr(offset, 0);
return string;
return (const uint8 *)_textFile1.getString(index);
}
void DreamBase::checkFolderCoords() {
@ -2443,11 +2447,11 @@ void DreamBase::folderExit() {
}
void DreamBase::loadTravelText() {
data.word(kTraveltext) = standardLoad("DREAMWEB.T81"); // location descs
loadTextFile(_travelText, "DREAMWEB.T81"); // location descs
}
void DreamBase::loadTempText(const char *fileName) {
data.word(kTextfile1) = standardLoad(fileName);
loadTextFile(_textFile1, fileName);
}
void DreamBase::drawFloor() {
@ -2835,13 +2839,11 @@ void DreamBase::describeOb() {
// Additional text
if (compare(data.byte(kCommand), data.byte(kObjecttype), "CUPE")) {
// Empty cup
uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(40 * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_puzzleText.getString(40);
printDirect(string, 36, y + 10, 241, 241 & 1);
} else if (compare(data.byte(kCommand), data.byte(kObjecttype), "CUPF")) {
// Full cup
uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(39 * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_puzzleText.getString(39);
printDirect(string, 36, y + 10, 241, 241 & 1);
}
}
@ -3325,10 +3327,8 @@ void DreamBase::setupTimedUse(uint16 textIndex, uint16 countToTimed, uint16 time
data.byte(kTimedx) = x;
data.word(kCounttotimed) = countToTimed;
data.word(kTimecount) = timeCount + countToTimed;
data.word(kTimedseg) = data.word(kPuzzletext);
data.word(kTimedoffset) = kTextstart + getSegment(data.word(kPuzzletext)).word(textIndex * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(data.word(kTimedoffset), 0);
debug(1, "setupTimedUse: %d => '%s'", textIndex, string);
_timedString = _puzzleText.getString(textIndex);
debug(1, "setupTimedUse: %d => '%s'", textIndex, _timedString);
}
void DreamBase::entryTexts() {

View File

@ -1644,8 +1644,7 @@ void DreamBase::showPuzText(uint16 command, uint16 count) {
showMan();
showExit();
obIcons();
uint16 offset = kTextstart + getSegment(data.word(kPuzzletext)).word(command * 2);
const uint8 *string = getSegment(data.word(kPuzzletext)).ptr(offset, 0);
const uint8 *string = (const uint8 *)_puzzleText.getString(command);
printDirect(string, 36, 104, 241, 241 & 1);
workToScreenM();
hangOnP(count);