CGE: Talk now uses EncryptedStream. Clean up of EncryptedStream

This commit is contained in:
Strangerke 2011-09-11 15:07:56 +02:00
parent cdba3ac108
commit 3b9b89a78b
5 changed files with 41 additions and 22 deletions

View file

@ -398,6 +398,22 @@ EncryptedStream::EncryptedStream(const char *name) {
_readStream = new Common::MemoryReadStream(dataBuffer, kp->_size, DisposeAfterUse::YES);
}
uint32 EncryptedStream::read(void *dataPtr, uint32 dataSize) {
return _readStream->read(dataPtr, dataSize);
}
bool EncryptedStream::err() {
return (_error & _readStream->err());
}
bool EncryptedStream::eos() {
return _readStream->eos();
}
Common::String EncryptedStream::readLine() {
return _readStream->readLine();
}
EncryptedStream::~EncryptedStream() {
}

View file

@ -148,11 +148,16 @@ public:
};
class EncryptedStream {
public:
private:
Common::SeekableReadStream *_readStream;
bool _error;
public:
EncryptedStream(const char *name);
~EncryptedStream();
Common::SeekableReadStream *_readStream;
bool err();
bool eos();
uint32 read(void *dataPtr, uint32 dataSize);
Common::String readLine();
};
extern CFile *_dat;

View file

@ -36,9 +36,9 @@ namespace CGE {
Font::Font(const char *name) {
_map = (uint8 *)malloc(kMapSize);
_pos = (uint16 *)malloc(kPosSize * sizeof(uint16));
_wid = (uint8 *)malloc(kWidSize);
_widthArr = (uint8 *)malloc(kWidSize);
assert((_map != NULL) && (_pos != NULL) && (_wid != NULL));
assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL));
mergeExt(_path, name, kFontExt);
load();
}
@ -46,22 +46,20 @@ Font::Font(const char *name) {
Font::~Font() {
free(_map);
free(_pos);
free(_wid);
free(_widthArr);
}
void Font::load() {
VFile f(_path);
if (f._error)
return;
EncryptedStream f = _path;
assert(!f.err());
f.read(_wid, kWidSize);
if (f._error)
return;
f.read(_widthArr, kWidSize);
assert(!f.err());
uint16 p = 0;
for (uint16 i = 0; i < kPosSize; i++) {
_pos[i] = p;
p += _wid[i];
p += _widthArr[i];
}
f.read(_map, p);
}
@ -71,7 +69,7 @@ uint16 Font::width(const char *text) {
if (!text)
return 0;
while (*text)
w += _wid[(unsigned char)*(text++)];
w += _widthArr[(unsigned char)*(text++)];
return w;
}
@ -116,7 +114,7 @@ void Talk::update(const char *text) {
mw = k;
k = 2 * hmarg;
} else
k += _font->_wid[(unsigned char)*p];
k += _font->_widthArr[(unsigned char)*p];
}
if (k > mw)
mw = k;
@ -132,7 +130,7 @@ void Talk::update(const char *text) {
if (*text == '|' || *text == '\n') {
m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg;
} else {
int cw = _font->_wid[(unsigned char)*text];
int cw = _font->_widthArr[(unsigned char)*text];
uint8 *f = _font->_map + _font->_pos[(unsigned char)*text];
for (int i = 0; i < cw; i++) {
uint8 *pp = m;
@ -223,7 +221,7 @@ void Talk::putLine(int line, const char *text) {
uint8 *q = v + size;
while (*text) {
uint16 cw = _font->_wid[(unsigned char)*text], i;
uint16 cw = _font->_widthArr[(unsigned char)*text], i;
uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text];
for (i = 0; i < cw; i++) {
@ -280,7 +278,7 @@ void InfoLine::update(const char *text) {
uint8 *p = v + 2, * q = p + size;
while (*text) {
uint16 cw = _font->_wid[(unsigned char)*text];
uint16 cw = _font->_widthArr[(unsigned char)*text];
uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text];
for (uint16 i = 0; i < cw; i++) {

View file

@ -52,7 +52,7 @@ class Font {
char _path[kPathMax];
void load();
public:
uint8 *_wid;
uint8 *_widthArr;
uint16 *_pos;
uint8 *_map;
Font(const char *name);

View file

@ -60,14 +60,14 @@ Text::~Text() {
int16 Text::count() {
EncryptedStream tf = _fileName;
if (tf._error)
if (tf.err())
return NULL;
Common::String line;
char tmpStr[kLineMax + 1];
int n, count = 0;
for (line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) {
for (line = tf.readLine(); !tf.eos(); line = tf.readLine()) {
n = line.size();
char *s;
@ -94,13 +94,13 @@ void Text::clear() {
void Text::load() {
EncryptedStream tf = _fileName;
assert(!tf._error);
assert(!tf.err());
Common::String line;
char tmpStr[kLineMax + 1];
int idx;
for (idx = 0, line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) {
for (idx = 0, line = tf.readLine(); !tf.eos(); line = tf.readLine()) {
int n = line.size();
char *s;