mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-23 19:16:21 +00:00
DREAMWEB: Convert exText into TextFile
This commit is contained in:
parent
e54196f37f
commit
f729742f87
@ -150,8 +150,7 @@ protected:
|
||||
// Extras segment (NB: this is saved)
|
||||
GraphicsFile _exFrames;
|
||||
DynObject _exData[kNumExObjects];
|
||||
uint16 _exTextdatLE[kNumExObjects+2]; // TODO: Convert into TextFile
|
||||
char _exText[18000];
|
||||
TextFile _exText;
|
||||
|
||||
public:
|
||||
DreamBase(DreamWeb::DreamWebEngine *en);
|
||||
|
@ -407,7 +407,7 @@ uint8 DreamWebEngine::modifyChar(uint8 c) const {
|
||||
namespace DreamGen {
|
||||
|
||||
// FIXME/TODO: Move this to a better place.
|
||||
DreamBase::DreamBase(DreamWeb::DreamWebEngine *en) : engine(en) {
|
||||
DreamBase::DreamBase(DreamWeb::DreamWebEngine *en) : engine(en), _exText(kNumExObjects+2) {
|
||||
_openChangeSize = kInventx+(4*kItempicsize);
|
||||
_quitRequested = false;
|
||||
|
||||
|
@ -251,12 +251,12 @@ void DreamBase::inventory() {
|
||||
}
|
||||
|
||||
void DreamBase::transferText(uint8 from, uint8 to) {
|
||||
WRITE_LE_UINT16(&_exTextdatLE[to], data.word(kExtextpos));
|
||||
_exText.setOffset(to, data.word(kExtextpos));
|
||||
uint16 freeTextOffset = 2*from;
|
||||
uint16 srcOffset = getSegment(data.word(kFreedesc)).word(kFreetextdat + freeTextOffset);
|
||||
|
||||
const char *src = (const char *)getSegment(data.word(kFreedesc)).ptr(kFreetext + srcOffset, 0);
|
||||
char *dst = _exText + data.word(kExtextpos);
|
||||
char *dst = _exText._text + data.word(kExtextpos);
|
||||
|
||||
size_t len = strlen(src);
|
||||
memcpy(dst, src, len + 1);
|
||||
@ -449,24 +449,24 @@ void DreamBase::deleteExFrame(uint8 frameNum) {
|
||||
}
|
||||
|
||||
void DreamBase::deleteExText(uint8 textNum) {
|
||||
uint16 offset = READ_LE_UINT16(&_exTextdatLE[textNum]);
|
||||
uint16 offset = _exText.getOffset(textNum);
|
||||
|
||||
uint16 startOff = offset;
|
||||
uint16 textSize = strlen(&_exText[startOff]) + 1;
|
||||
uint16 textSize = strlen(_exText.getString(textNum)) + 1;
|
||||
uint16 endOff = startOff + textSize;
|
||||
uint16 remainder = kExtextlen - offset - textSize;
|
||||
|
||||
// Shift text data after this one down
|
||||
memmove(&_exText[startOff], &_exText[endOff], remainder);
|
||||
memmove(&_exText._text[startOff], &_exText._text[endOff], remainder);
|
||||
|
||||
// Combined text data is now frameSize smaller
|
||||
data.word(kExtextpos) -= textSize;
|
||||
|
||||
// Adjust all text pointers pointing into the shifted data
|
||||
for (unsigned int i = 0; i < kNumexobjects; ++i) {
|
||||
uint16 t = READ_LE_UINT16(&_exTextdatLE[i]);
|
||||
uint16 t = _exText.getOffset(i);
|
||||
if (t >= offset + textSize)
|
||||
WRITE_LE_UINT16(&_exTextdatLE[i], t - textSize);
|
||||
_exText.setOffset(i, t - textSize);
|
||||
}
|
||||
}
|
||||
|
||||
@ -604,9 +604,9 @@ const uint8 *DreamBase::getObTextStart() {
|
||||
textBase = getSegment(textSeg).ptr(textOff, 0);
|
||||
text = textBase + getSegment(textSeg).word(textDatOff + 2*data.byte(kCommand));
|
||||
} else {
|
||||
textBase = (const uint8 *)_exText;
|
||||
textBase = (const uint8 *)_exText._text;
|
||||
textOff = kExtext;
|
||||
text = textBase + READ_LE_UINT16(&_exTextdatLE[data.byte(kCommand)]);
|
||||
text = (const uint8 *)_exText.getString(data.byte(kCommand));
|
||||
}
|
||||
|
||||
if (data.byte(kObjecttype) != kSetObjectType1)
|
||||
|
@ -481,8 +481,8 @@ void DreamBase::savePosition(unsigned int slot, const char *descbuf) {
|
||||
outSaveFile->write((const uint8 *)_exFrames._frames, 2080);
|
||||
outSaveFile->write((const uint8 *)_exFrames._data, kExframeslen);
|
||||
outSaveFile->write((const uint8 *)_exData, sizeof(DynObject)*kNumexobjects);
|
||||
outSaveFile->write((const uint8 *)_exTextdatLE, 2*(kNumExObjects+2));
|
||||
outSaveFile->write((const uint8 *)_exText, kExtextlen);
|
||||
outSaveFile->write((const uint8 *)_exText._offsetsLE, 2*(kNumExObjects+2));
|
||||
outSaveFile->write((const uint8 *)_exText._text, kExtextlen);
|
||||
|
||||
outSaveFile->write(_listOfChanges, len[3]);
|
||||
|
||||
@ -554,8 +554,8 @@ void DreamBase::loadPosition(unsigned int slot) {
|
||||
inSaveFile->read((uint8 *)_exFrames._frames, 2080);
|
||||
inSaveFile->read((uint8 *)_exFrames._data, kExframeslen);
|
||||
inSaveFile->read((uint8 *)_exData, sizeof(DynObject)*kNumexobjects);
|
||||
inSaveFile->read((uint8 *)_exTextdatLE, 2*(kNumExObjects+2));
|
||||
inSaveFile->read((uint8 *)_exText, kExtextlen);
|
||||
inSaveFile->read((uint8 *)_exText._offsetsLE, 2*(kNumExObjects+2));
|
||||
inSaveFile->read((uint8 *)_exText._text, kExtextlen);
|
||||
|
||||
inSaveFile->read(_listOfChanges, len[3]);
|
||||
|
||||
|
@ -295,14 +295,28 @@ struct MapFlag {
|
||||
};
|
||||
|
||||
struct TextFile {
|
||||
TextFile() : _text(0) { }
|
||||
TextFile(unsigned int size = 66) : _size(size), _text(0) { _offsetsLE = new uint16[_size]; }
|
||||
|
||||
uint16 _offsetsLE[66];
|
||||
~TextFile() {
|
||||
delete[] _offsetsLE;
|
||||
_offsetsLE = 0;
|
||||
_size = 0;
|
||||
clear();
|
||||
}
|
||||
|
||||
uint16 *_offsetsLE;
|
||||
unsigned int _size;
|
||||
char *_text;
|
||||
|
||||
const char *getString(unsigned int i) const {
|
||||
assert(i < 66);
|
||||
return _text + READ_LE_UINT16(&_offsetsLE[i]);
|
||||
assert(i < _size);
|
||||
return _text + getOffset(i);
|
||||
}
|
||||
void setOffset(unsigned int i, uint16 offset) {
|
||||
WRITE_LE_UINT16(&_offsetsLE[i], offset);
|
||||
}
|
||||
uint16 getOffset(unsigned int i) const {
|
||||
return READ_LE_UINT16(&_offsetsLE[i]);
|
||||
}
|
||||
void clear() {
|
||||
delete[] _text;
|
||||
|
@ -1230,8 +1230,7 @@ const uint8 *DreamBase::findObName(uint8 type, uint8 index) {
|
||||
uint16 offset = getSegment(data.word(kPeople)).word(kPersontxtdat + i) + kPersontext;
|
||||
return getSegment(data.word(kPeople)).ptr(offset, 0);
|
||||
} else if (type == 4) {
|
||||
uint16 offset = READ_LE_UINT16(&_exTextdatLE[index]);
|
||||
return (const uint8 *)_exText + offset;
|
||||
return (const uint8 *)_exText.getString(index);
|
||||
} else if (type == 2) {
|
||||
uint16 offset = getSegment(data.word(kFreedesc)).word(kFreetextdat + index * 2) + kFreetext;
|
||||
return getSegment(data.word(kFreedesc)).ptr(offset, 0);
|
||||
@ -2223,6 +2222,7 @@ void DreamBase::loadRoomData(const Room &room, bool skipDat) {
|
||||
data.word(kReel3) = allocateAndLoad(len[6]);
|
||||
data.word(kReels) = allocateAndLoad(len[7]);
|
||||
data.word(kPeople) = allocateAndLoad(len[8]);
|
||||
// TODO: kSetdesc, kBlockdesc, kRoomdesc are also TextFiles?
|
||||
data.word(kSetdesc) = allocateAndLoad(len[9]);
|
||||
data.word(kBlockdesc) = allocateAndLoad(len[10]);
|
||||
data.word(kRoomdesc) = allocateAndLoad(len[11]);
|
||||
@ -2238,6 +2238,7 @@ void DreamBase::loadRoomData(const Room &room, bool skipDat) {
|
||||
clearAndLoad(data.word(kFreedat), 255, len[13], kFreedatlen);
|
||||
else
|
||||
engine->skipBytes(len[13]);
|
||||
// TODO: kFreedesc is also a TextFile?
|
||||
data.word(kFreedesc) = allocateAndLoad(len[14]);
|
||||
|
||||
engine->closeFile();
|
||||
@ -2499,6 +2500,9 @@ void DreamBase::drawFloor() {
|
||||
void DreamBase::allocateBuffers() {
|
||||
_exFrames.clear();
|
||||
_exFrames._data = new uint8[kExframeslen];
|
||||
_exText.clear();
|
||||
_exText._text = new char[kExtextlen];
|
||||
|
||||
data.word(kFreedat) = allocateMem(kFreedatlen/16);
|
||||
data.word(kSetdat) = allocateMem(kSetdatlen/16);
|
||||
}
|
||||
@ -3622,8 +3626,8 @@ void DreamBase::clearChanges() {
|
||||
memset(_exFrames._frames, 0xFF, 2080);
|
||||
memset(_exFrames._data, 0xFF, kExframeslen);
|
||||
memset(_exData, 0xFF, sizeof(DynObject) * kNumexobjects);
|
||||
memset(_exTextdatLE, 0xFF, 2*(kNumexobjects+2));
|
||||
memset(_exText, 0xFF, kExtextlen);
|
||||
memset(_exText._offsetsLE, 0xFF, 2*(kNumexobjects+2));
|
||||
memset(_exText._text, 0xFF, kExtextlen);
|
||||
|
||||
const uint8 initialRoomsCanGo[] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user