From e4a37322a6678aa3874d96ce131bebbccbdd7a44 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 20 Aug 2011 00:23:45 +0200 Subject: CGE: More misc cleanup. --- engines/cge/btfile.cpp | 4 --- engines/cge/events.cpp | 1 - engines/cge/sound.cpp | 19 ++---------- engines/cge/text.cpp | 78 ++++++++++++++++++++++++-------------------------- engines/cge/walk.cpp | 19 ++++-------- 5 files changed, 47 insertions(+), 74 deletions(-) (limited to 'engines/cge') diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 053f264b35..a4d16010e5 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -48,7 +48,6 @@ BtFile::BtFile(const char *name, IOMode mode, Crypt *crpt) } } - BtFile::~BtFile() { debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); for (int i = 0; i < kBtLevel; i++) { @@ -57,7 +56,6 @@ BtFile::~BtFile() { } } - void BtFile::putPage(int lev, bool hard) { debugC(1, kCGEDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); @@ -68,7 +66,6 @@ void BtFile::putPage(int lev, bool hard) { } } - BtPage *BtFile::getPage(int lev, uint16 pgn) { debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); @@ -130,7 +127,6 @@ BtKeypack *BtFile::find(const char *key) { return NULL; } - int keycomp(const void *k1, const void *k2) { return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize); } diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 6e23b4e613..5af5a9ee3f 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -179,7 +179,6 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) step(1); } - Mouse::~Mouse() { off(); } diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index b22548c16d..432bca75b5 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -42,22 +42,18 @@ Sound::Sound(CGEEngine *vm) : _vm(vm) { open(); } - Sound::~Sound() { close(); } - void Sound::close() { _vm->_midiPlayer.killMidi(); } - void Sound::open() { play((*_fx)[30000], 8); } - void Sound::play(DataCk *wav, int pan, int cnt) { if (wav) { stop(); @@ -97,16 +93,13 @@ Fx::Fx(int size) : _current(NULL) { } } - Fx::~Fx() { clear(); delete[] _cache; } - void Fx::clear() { - Han *p, * q; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref) { p->_ref = 0; delete p->_wav; @@ -116,11 +109,9 @@ void Fx::clear() { _current = NULL; } - int Fx::find(int ref) { - Han *p, * q; int i = 0; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref == ref) break; else @@ -129,12 +120,10 @@ int Fx::find(int ref) { return i; } - void Fx::preload(int ref0) { Han *cacheLim = _cache + _size; - int ref; - for (ref = ref0; ref < ref0 + 10; ref++) { + for (int ref = ref0; ref < ref0 + 10; ref++) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); @@ -149,7 +138,6 @@ void Fx::preload(int ref0) { } } - DataCk *Fx::load(int idx, int ref) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); @@ -164,7 +152,6 @@ DataCk *Fx::load(int idx, int ref) { return wav; } - DataCk *Fx::operator [](int ref) { int i; if ((i = find(ref)) < _size) diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 7e58762afa..0e6fc40920 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -79,44 +79,44 @@ int Text::find(int ref) { void Text::preload(int from, int upto) { INI_FILE tf = _fileName; - if (!tf._error) { - Han *CacheLim = _cache + _size; - char line[kLineMax + 1]; - int n; - - while ((n = tf.read((uint8 *)line)) != 0) { - char *s; - - if (line[n - 1] == '\n') - line[--n] = '\0'; - - if ((s = strtok(line, " =,;/\t\n")) == NULL) - continue; - if (!IsDigit(*s)) - continue; - - int ref = atoi(s); - if (ref && ref >= from && ref < upto) { - Han *p = &_cache[find(ref)]; - - if (p < CacheLim) { - delete[] p->_text; - p->_text = NULL; - } else - p = &_cache[find(0)]; - - if (p >= CacheLim) - break; - - s += strlen(s); - if (s < line + n) - ++s; - if ((p->_text = new char[strlen(s) + 1]) == NULL) - break; - - p->_ref = ref; - strcpy(p->_text, s); - } + if (tf._error) + return; + + Han *CacheLim = _cache + _size; + char line[kLineMax + 1]; + int n; + + while ((n = tf.read((uint8 *)line)) != 0) { + if (line[n - 1] == '\n') + line[--n] = '\0'; + + char *s; + if ((s = strtok(line, " =,;/\t\n")) == NULL) + continue; + if (!IsDigit(*s)) + continue; + + int ref = atoi(s); + if (ref && ref >= from && ref < upto) { + Han *p = &_cache[find(ref)]; + + if (p < CacheLim) { + delete[] p->_text; + p->_text = NULL; + } else + p = &_cache[find(0)]; + + if (p >= CacheLim) + break; + + s += strlen(s); + if (s < line + n) + ++s; + if ((p->_text = new char[strlen(s) + 1]) == NULL) + break; + + p->_ref = ref; + strcpy(p->_text, s); } } } @@ -161,7 +161,6 @@ char *Text::load(int idx, int ref) { return NULL; } - char *Text::getText(int ref) { int i; if ((i = find(ref)) < _size) @@ -177,7 +176,6 @@ char *Text::getText(int ref) { return load(i, ref); } - void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index ccbb0e5532..95cc92afd4 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -57,7 +57,6 @@ Cluster XZ(int x, int y) { return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); } - Cluster XZ(Couple xy) { signed char x, y; xy.split(x, y); @@ -68,7 +67,6 @@ Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } - void Walk::tick() { if (_flags._hide) return; @@ -76,9 +74,8 @@ void Walk::tick() { _here = XZ(_x + _w / 2, _y + _h); if (_dir != kDirNone) { - Sprite *spr; _sys->funTouch(); - for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { _vm->feedSnail(spr, kNear); @@ -103,8 +100,10 @@ void Walk::tick() { turn(d); } } + step(); - if ((_dir == kDirWest && _x <= 0) || + + if ((_dir == kDirWest && _x <= 0) || (_dir == kDirEast && _x + _w >= kScrWidth) || (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); @@ -115,7 +114,6 @@ void Walk::tick() { } } - int Walk::distance(Sprite *spr) { int dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) @@ -136,7 +134,6 @@ int Walk::distance(Sprite *spr) { return dz - 1; } - void Walk::turn(Dir d) { Dir dir = (_dir == kDirNone) ? kDirSouth : _dir; if (d != _dir) { @@ -145,7 +142,6 @@ void Walk::turn(Dir d) { } } - void Walk::park() { if (_time == 0) _time++; @@ -157,7 +153,6 @@ void Walk::park() { } } - void Walk::findWay(Cluster c) { if (c == _here) return; @@ -171,13 +166,13 @@ void Walk::findWay(Cluster c) { if (find1Way(Cluster(x, z))) break; } + _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); if (_tracePtr < 0) noWay(); _time = 1; } - void Walk::findWay(Sprite *spr) { if (!spr || spr == this) return; @@ -194,12 +189,10 @@ void Walk::findWay(Sprite *spr) { : (z - 1)))); } - bool Walk::lower(Sprite *spr) { return (spr->_y > _y + (_h * 3) / 5); } - void Walk::reach(Sprite *spr, int mode) { if (spr) { _hero->findWay(spr); @@ -230,7 +223,6 @@ bool Cluster::chkBar() const { } bool Walk::find1Way(Cluster c) { - Cluster start = c; const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; @@ -251,6 +243,7 @@ bool Walk::find1Way(Cluster c) { return false; // Loop through each direction + Cluster start = c; for (int i = 0; i < tabLen; i++) { // Reset to starting position c = start; -- cgit v1.2.3