diff options
author | Alyssa Milburn | 2011-08-19 16:04:10 +0200 |
---|---|---|
committer | Alyssa Milburn | 2011-08-19 16:04:10 +0200 |
commit | 4e156b24635c3cb44d46dde7a01f97fb2fe4a552 (patch) | |
tree | 4c29aff0ee1d7046c287d0f9ea5c4e00ec2c5028 /engines | |
parent | f0889d3f5492a71293d789b5ffb9752c90c9b6f8 (diff) | |
download | scummvm-rg350-4e156b24635c3cb44d46dde7a01f97fb2fe4a552.tar.gz scummvm-rg350-4e156b24635c3cb44d46dde7a01f97fb2fe4a552.tar.bz2 scummvm-rg350-4e156b24635c3cb44d46dde7a01f97fb2fe4a552.zip |
CGE: Mass re-style/cleanup.
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cge/bitmap.cpp | 68 | ||||
-rw-r--r-- | engines/cge/cfile.cpp | 18 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 319 | ||||
-rw-r--r-- | engines/cge/events.cpp | 6 | ||||
-rw-r--r-- | engines/cge/events.h | 1 | ||||
-rw-r--r-- | engines/cge/game.cpp | 22 | ||||
-rw-r--r-- | engines/cge/game.h | 9 | ||||
-rw-r--r-- | engines/cge/general.cpp | 32 | ||||
-rw-r--r-- | engines/cge/gettext.cpp | 14 | ||||
-rw-r--r-- | engines/cge/mixer.cpp | 17 | ||||
-rw-r--r-- | engines/cge/talk.cpp | 200 | ||||
-rw-r--r-- | engines/cge/text.cpp | 184 | ||||
-rw-r--r-- | engines/cge/vmenu.cpp | 72 | ||||
-rw-r--r-- | engines/cge/vol.cpp | 3 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 66 | ||||
-rw-r--r-- | engines/cge/walk.h | 1 |
16 files changed, 494 insertions, 538 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index e497828788..0829600902 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -81,14 +81,12 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { } } - Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%d, %d, map)", w, h); if (map) code(); } - // following routine creates filled rectangle // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display @@ -134,21 +132,20 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) _b = b; } - Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(bmp)"); uint8 *v0 = bmp._v; - if (v0) { - uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); - uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = new uint8[siz]; - assert(v1 != NULL); - memcpy(v1, v0, siz); - _b = (HideDesc *)((_v = v1) + vsiz); - } + if (!v0) + return; + + uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); + uint16 siz = vsiz + _h * sizeof(HideDesc); + uint8 *v1 = new uint8[siz]; + assert(v1 != NULL); + memcpy(v1, v0, siz); + _b = (HideDesc *)((_v = v1) + vsiz); } - Bitmap::~Bitmap() { debugC(6, kCGEDebugBitmap, "Bitmap::~Bitmap()"); @@ -156,7 +153,6 @@ Bitmap::~Bitmap() { delete[] _v; } - Bitmap &Bitmap::operator = (const Bitmap &bmp) { debugC(1, kCGEDebugBitmap, "&Bitmap::operator ="); @@ -166,9 +162,10 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _m = NULL; _map = 0; delete[] _v; - if (v0 == NULL) + + if (v0 == NULL) { _v = NULL; - else { + } else { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); @@ -179,21 +176,19 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { return *this; } - uint16 Bitmap::moveVmap(uint8 *buf) { debugC(1, kCGEDebugBitmap, "Bitmap::moveVmap(buf)"); - if (_v) { - uint16 vsiz = (uint8 *)_b - (uint8 *)_v; - uint16 siz = vsiz + _h * sizeof(HideDesc); - memcpy(buf, _v, siz); - delete[] _v; - _b = (HideDesc *)((_v = buf) + vsiz); - return siz; - } - return 0; -} + if (!_v) + return 0; + uint16 vsiz = (uint8 *)_b - (uint8 *)_v; + uint16 siz = vsiz + _h * sizeof(HideDesc); + memcpy(buf, _v, siz); + delete[] _v; + _b = (HideDesc *)((_v = buf) + vsiz); + return siz; +} BitmapPtr Bitmap::code() { debugC(1, kCGEDebugBitmap, "Bitmap::code()"); @@ -201,7 +196,7 @@ BitmapPtr Bitmap::code() { if (!_m) return false; - uint16 i, cnt; + uint16 cnt; if (_v) { // old X-map exists, so remove it delete[] _v; @@ -214,7 +209,7 @@ BitmapPtr Bitmap::code() { int bpl; if (_v) { // 2nd pass - fill the hide table - for (i = 0; i < _h; i++) { + for (uint16 i = 0; i < _h; i++) { _b[i]._skip = 0xFFFF; _b[i]._hide = 0x0000; } @@ -225,7 +220,7 @@ BitmapPtr Bitmap::code() { uint16 j; cnt = 0; - for (i = 0; i < _h; i++) { // once per each line + for (uint16 i = 0; i < _h; i++) { // once per each line uint8 pix; for (j = bpl; j < _w; j += 4) { pix = bm[j]; @@ -293,7 +288,7 @@ BitmapPtr Bitmap::code() { _b = (HideDesc *)(_v + sizV); } cnt = 0; - for (i = 0; i < _h; i++) { + for (uint16 i = 0; i < _h; i++) { if (_b[i]._skip == 0xFFFF) { // whole line is skipped _b[i]._skip = (cnt + kScrWidth) >> 2; cnt = 0; @@ -309,19 +304,16 @@ BitmapPtr Bitmap::code() { return this; } - bool Bitmap::solidAt(int16 x, int16 y) { debugC(6, kCGEDebugBitmap, "Bitmap::solidAt(%d, %d)", x, y); - uint8 *m; - uint16 r, n, n0; - if ((x >= _w) || (y >= _h)) return false; - m = _v; - r = static_cast<uint16>(x) % 4; - n0 = (kScrWidth * y + x) / 4, n = 0; + uint8 *m = _v; + uint16 r = static_cast<uint16>(x) % 4; + uint16 n0 = (kScrWidth * y + x) / 4; + uint16 n = 0; while (r) { uint16 w, t; @@ -372,7 +364,6 @@ bool Bitmap::solidAt(int16 x, int16 y) { } } - bool Bitmap::saveVBM(XFile *f) { debugC(1, kCGEDebugBitmap, "Bitmap::saveVBM(f)"); @@ -400,7 +391,6 @@ bool Bitmap::saveVBM(XFile *f) { return (f->_error == 0); } - bool Bitmap::loadVBM(XFile *f) { debugC(5, kCGEDebugBitmap, "Bitmap::loadVBM(f)"); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index c6144f624b..c5c2c2c19c 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -44,7 +44,6 @@ IoBuf::IoBuf(IOMode mode, Crypt *crypt) assert(_buff != NULL); } - IoBuf::IoBuf(const char *name, IOMode mode, Crypt *crypt) : IoHand(name, mode, crypt), _bufMark(0), @@ -64,7 +63,6 @@ IoBuf::~IoBuf() { free(_buff); } - void IoBuf::readBuf() { debugC(4, kCGEDebugFile, "IoBuf::readBuf()"); @@ -73,7 +71,6 @@ void IoBuf::readBuf() { _ptr = 0; } - void IoBuf::writeBuf() { debugC(4, kCGEDebugFile, "IoBuf::writeBuf()"); @@ -84,7 +81,6 @@ void IoBuf::writeBuf() { } } - uint16 IoBuf::read(void *buf, uint16 len) { debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); @@ -107,7 +103,6 @@ uint16 IoBuf::read(void *buf, uint16 len) { return total; } - uint16 IoBuf::read(uint8 *buf) { debugC(3, kCGEDebugFile, "IoBuf::read(buf)"); @@ -154,7 +149,6 @@ uint16 IoBuf::read(uint8 *buf) { return total; } - uint16 IoBuf::write(void *buf, uint16 len) { debugC(1, kCGEDebugFile, "IoBuf::write(buf, %d)", len); @@ -175,7 +169,6 @@ uint16 IoBuf::write(void *buf, uint16 len) { return tot; } - uint16 IoBuf::write(uint8 *buf) { debugC(1, kCGEDebugFile, "IoBuf::write(buf)"); @@ -195,7 +188,6 @@ uint16 IoBuf::write(uint8 *buf) { return len; } - int IoBuf::read() { debugC(1, kCGEDebugFile, "IoBuf::read()"); @@ -207,7 +199,6 @@ int IoBuf::read() { return _buff[_ptr++]; } - void IoBuf::write(uint8 b) { debugC(1, kCGEDebugFile, "IoBuf::write(%d)", b); @@ -216,20 +207,16 @@ void IoBuf::write(uint8 b) { _buff[_lim++] = b; } - -uint16 CFile::_maxLineLen = kLineMaxSize; - +uint16 CFile::_maxLineLen = kLineMaxSize; CFile::CFile(const char *name, IOMode mode, Crypt *crypt) : IoBuf(name, mode, crypt) { debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crypt)", name, mode); } - CFile::~CFile() { } - void CFile::flush() { debugC(1, kCGEDebugFile, "CFile::flush()"); @@ -246,14 +233,12 @@ void CFile::flush() { warning("FIXME: CFILE::Flush"); } - long CFile::mark() { debugC(5, kCGEDebugFile, "CFile::mark()"); return _bufMark + ((_mode != kModeRead) ? _lim : _ptr); } - long CFile::seek(long pos) { debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); @@ -271,7 +256,6 @@ long CFile::seek(long pos) { } } - void CFile::append(CFile &f) { debugC(1, kCGEDebugFile, "CFile::append(f)"); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 39e65370e8..91de45e447 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -88,8 +88,8 @@ const char *savegameStr = "SCUMMVM_CGE"; //-------------------------------------------------------------------------- -static bool _finis = false; -int _offUseCount; +static bool _finis = false; +int _offUseCount; extern Dac _stdPal[58]; @@ -255,7 +255,6 @@ Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { return Common::kNoError; } - void CGEEngine::saveSound() { warning("STUB: CGEEngine::saveSound"); /* Convert to saving any such needed data in ScummVM configuration file @@ -317,13 +316,10 @@ void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &he } void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny) { - Sprite *spr; - int i; - Common::Serializer s(readStream, writeStream); if (s.isSaving()) { - for (i = 0; i < kPocketNX; i++) { + for (int i = 0; i < kPocketNX; i++) { register Sprite *pocSpr = _pocket[i]; _pocref[i] = (pocSpr) ? pocSpr->_ref : -1; } @@ -340,7 +336,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt if (s.isSaving()) { // Loop through saving the sprite data - for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_spareQ->first(); spr; spr = spr->_next) { if ((spr->_ref >= 1000) && !s.err()) spr->sync(s); } @@ -359,14 +355,14 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt S.sync(s); S._prev = S._next = NULL; - spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) + Sprite *spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) : new Sprite(this, NULL); assert(spr != NULL); *spr = S; _vga->_spareQ->append(spr); } - for (i = 0; i < kPocketNX; i++) { + for (int i = 0; i < kPocketNX; i++) { register int r = _pocref[i]; _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); } @@ -482,7 +478,6 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { setShapeList(MB); } - void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & kMouseLeftUp) { @@ -491,7 +486,6 @@ void Square::touch(uint16 mask, int x, int y) { } } - void CGEEngine::setMapBrick(int x, int z) { debugC(1, kCGEDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); @@ -513,7 +507,6 @@ void CGEEngine::keyClick() { _snail_->addCom(kSnSound, -1, 5, NULL); } - void CGEEngine::resetQSwitch() { debugC(1, kCGEDebugEngine, "CGEEngine::resetQSwitch()"); @@ -521,7 +514,6 @@ void CGEEngine::resetQSwitch() { keyClick(); } - void CGEEngine::quit() { debugC(1, kCGEDebugEngine, "CGEEngine::quit()"); @@ -545,7 +537,6 @@ void CGEEngine::quit() { } } - void CGEEngine::AltCtrlDel() { debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); @@ -577,21 +568,22 @@ void CGEEngine::showBak(int ref) { debugC(1, kCGEDebugEngine, "CGEEngine::showBack(%d)", ref); Sprite *spr = _vga->_spareQ->locate(ref); - if (spr) { - Bitmap::_pal = Vga::_sysPal; - spr->expand(); - Bitmap::_pal = NULL; - spr->show(2); - _vga->copyPage(1, 2); - _sys->setPal(); - spr->contract(); - } + if (!spr) + return; + + Bitmap::_pal = Vga::_sysPal; + spr->expand(); + Bitmap::_pal = NULL; + spr->show(2); + _vga->copyPage(1, 2); + _sys->setPal(); + spr->contract(); } void CGEEngine::caveUp() { debugC(1, kCGEDebugEngine, "CGEEngine::caveUp()"); - int BakRef = 1000 * _now; + const int BakRef = 1000 * _now; if (_music) _midiPlayer.loadMidi(_now); @@ -652,11 +644,10 @@ void CGEEngine::caveUp() { void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); - Sprite *spr; if (_horzLine && !_horzLine->_flags._hide) switchMapping(); - for (spr = _vga->_showQ->first(); spr;) { + for (Sprite *spr = _vga->_showQ->first(); spr;) { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) @@ -689,31 +680,31 @@ void CGEEngine::qGame() { _finis = true; } - void CGEEngine::switchCave(int cav) { debugC(1, kCGEDebugEngine, "CGEEngine::switchCave(%d)", cav); - if (cav != _now) { - if (cav < 0) { - _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint - _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave - } else { - _now = cav; - _mouse->off(); - if (_hero) { - _hero->park(); - _hero->step(0); - if (!_isDemo) - _vga->_spareQ->_show = 0; - } - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); - killText(); - if (!_startupMode) - keyClick(); - _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint - _snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave + if (cav == _now) + return; + + if (cav < 0) { + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave + } else { + _now = cav; + _mouse->off(); + if (_hero) { + _hero->park(); + _hero->step(0); + if (!_isDemo) + _vga->_spareQ->_show = 0; } + _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, + kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + killText(); + if (!_startupMode) + keyClick(); + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave } } @@ -724,9 +715,8 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { } void System::setPal() { - uint i; Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); - for (i = 0; i < ArrayCount(_stdPal); i++) { + for (uint i = 0; i < ArrayCount(_stdPal); i++) { p[i]._r = _stdPal[i]._r >> 2; p[i]._g = _stdPal[i]._g >> 2; p[i]._b = _stdPal[i]._b >> 2; @@ -918,9 +908,9 @@ void CGEEngine::switchMusic() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()"); if (_keyboard->_key[kKeyAlt]) { - if (Vmenu::_addr) + if (Vmenu::_addr) { _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); - else { + } else { _snail_->addCom(kSnSeq, 122, (_music = false), NULL); _snail->addCom2(kSnExec, -1, 0, kSelectSound); } @@ -944,9 +934,9 @@ void CGEEngine::startCountDown() { void CGEEngine::takeName() { debugC(1, kCGEDebugEngine, "CGEEngine::takeName()"); - if (GetText::_ptr) + if (GetText::_ptr) { _snail_->addCom(kSnKill, -1, 0, GetText::_ptr); - else { + } else { memset(_usrFnam, 0, 15); GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8); if (tn) { @@ -964,17 +954,14 @@ void CGEEngine::switchMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); if (_horzLine && _horzLine->_flags._hide) { - int i; - for (i = 0; i < kMapZCnt; i++) { - int j; - for (j = 0; j < kMapXCnt; j++) { + for (int i = 0; i < kMapZCnt; i++) { + for (int j = 0; j < kMapXCnt; j++) { if (Cluster::_map[i][j]) setMapBrick(j, i); } } } else { - Sprite *s; - for (s = _vga->_showQ->first(); s; s = s->_next) + for (Sprite *s = _vga->_showQ->first(); s; s = s->_next) if (s->_w == kMapGridX && s->_h == kMapGridZ) _snail_->addCom(kSnKill, -1, 0, s); } @@ -1084,104 +1071,109 @@ void CGEEngine::sayDebug() { } } - void CGEEngine::switchDebug() { _debugLine->_flags._hide = !_debugLine->_flags._hide; } - void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { - case 1 : + case 1: if (mask & kMouseLeftUp) switchColorMode(); break; - case 2 : - if (mask & kMouseLeftUp) + case 2: + if (mask & kMouseLeftUp) { switchMusic(); - else if (mask & kMouseRightUp) + } else if (mask & kMouseRightUp) if (!Mixer::_appear) { Mixer::_appear = true; new Mixer(this, kButtonX, kButtonY); } break; - case 3 : + case 3: if (mask & kMouseLeftUp) quit(); break; } } - #pragma argsused void Sprite::touch(uint16 mask, int x, int y) { _sys->funTouch(); - if ((mask & kEventAttn) == 0) { - _infoLine->update(name()); - if (mask & (kMouseRightDown | kMouseLeftDown)) - _sprite = this; - if (_ref / 10 == 12) { - _vm->optionTouch(_ref % 10, mask); - return; + + if ((mask & kEventAttn) != 0) + return; + + _infoLine->update(name()); + + if (mask & (kMouseRightDown | kMouseLeftDown)) + _sprite = this; + + if (_ref / 10 == 12) { + _vm->optionTouch(_ref % 10, mask); + return; + } + + if (_flags._syst) + return; // cannot access system sprites + + if (_vm->_game) + if (mask & kMouseLeftUp) { + mask &= ~kMouseLeftUp; + mask |= kMouseRightUp; } - if (_flags._syst) - return; // cannot access system sprites - if (_vm->_game) if (mask & kMouseLeftUp) { - mask &= ~kMouseLeftUp; - mask |= kMouseRightUp; - } - if ((mask & kMouseRightUp) && _snail->idle()) { - Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; - if (ps) { - if (_flags._kept || _hero->distance(this) < kDistMax) { - if (works(ps)) { - _vm->feedSnail(ps, kTake); - } else - _vm->offUse(); - _vm->selectPocket(-1); + + if ((mask & kMouseRightUp) && _snail->idle()) { + Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; + if (ps) { + if (_flags._kept || _hero->distance(this) < kDistMax) { + if (works(ps)) { + _vm->feedSnail(ps, kTake); } else - _vm->tooFar(); + _vm->offUse(); + _vm->selectPocket(-1); + } else + _vm->tooFar(); + } else { + if (_flags._kept) { + mask |= kMouseLeftUp; } else { - if (_flags._kept) - mask |= kMouseLeftUp; - else { - if (_hero->distance(this) < kDistMax) { - /// - if (_flags._port) { - if (_vm->findPocket(NULL) < 0) - _vm->pocFul(); - else { - _snail->addCom(kSnReach, -1, -1, this); - _snail->addCom(kSnKeep, -1, -1, this); - _flags._port = false; - } - } else { - if (_takePtr != NO_PTR) { - if (snList(kTake)[_takePtr]._com == kSnNext) - _vm->offUse(); - else - _vm->feedSnail(this, kTake); - } else - _vm->offUse(); + if (_hero->distance(this) < kDistMax) { + /// + if (_flags._port) { + if (_vm->findPocket(NULL) < 0) + _vm->pocFul(); + else { + _snail->addCom(kSnReach, -1, -1, this); + _snail->addCom(kSnKeep, -1, -1, this); + _flags._port = false; } - }/// - else - _vm->tooFar(); - } + } else { + if (_takePtr != NO_PTR) { + if (snList(kTake)[_takePtr]._com == kSnNext) + _vm->offUse(); + else + _vm->feedSnail(this, kTake); + } else + _vm->offUse(); + } + }/// + else + _vm->tooFar(); } } - if ((mask & kMouseLeftUp) && _snail->idle()) { - if (_flags._kept) { - int n; - for (n = 0; n < kPocketNX; n++) { - if (_pocket[n] == this) { - _vm->selectPocket(n); - break; - } + } + + if ((mask & kMouseLeftUp) && _snail->idle()) { + if (_flags._kept) { + for (int n = 0; n < kPocketNX; n++) { + if (_pocket[n] == this) { + _vm->selectPocket(n); + break; } - } else - _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); - } + } + } else + _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); } } @@ -1196,7 +1188,6 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", "FLY", NULL }; - char line[kLineMax]; int shpcnt = 0; int type = 0; // DEAD @@ -1204,14 +1195,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int bool port = false; bool tran = false; int i, lcnt = 0; - uint16 len; + char line[kLineMax]; mergeExt(line, fname, SPR_EXT); + if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); if (sprf._error) error("Bad SPR [%s]", line); + uint16 len; while ((len = sprf.read((uint8 *)line)) != 0) { lcnt++; if (len && line[len - 1] == '\n') @@ -1252,15 +1245,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int // make sprite of choosen type switch (type) { - case 1 : { // AUTO + case 1: + // AUTO _sprite = new Sprite(this, NULL); if (_sprite) { _sprite->gotoxy(col, row); //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; - } - case 2 : { // WALK + case 2: + { // WALK Walk *w = new Walk(this, NULL); if (w && ref == 1) { w->gotoxy(col, row); @@ -1270,7 +1264,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int } _sprite = w; break; - } + } /* case 3 : // NEWTON NEWTON * n = new NEWTON(NULL); @@ -1286,7 +1280,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite = n; break; */ - case 4 : { // LISSAJOUS + case 4: + // LISSAJOUS error("Bad type [%s]", fname); /* LISSAJOUS * l = new LISSAJOUS(NULL); @@ -1304,20 +1299,21 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite = l; */ break; - } - case 5 : { // FLY + case 5: + { // FLY Fly *f = new Fly(this, NULL); _sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; - } - default: { // DEAD + } + default: + // DEAD _sprite = new Sprite(this, NULL); if (_sprite) _sprite->gotoxy(col, row); break; } - } + if (_sprite) { _sprite->_ref = ref; _sprite->_cave = cav; @@ -1339,19 +1335,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int } } - void CGEEngine::loadScript(const char *fname) { - char line[kLineMax]; - char *SpN; - int SpI, SpA, SpX, SpY, SpZ; - bool BkG = false; INI_FILE scrf(fname); - int lcnt = 0; - bool ok = true; if (scrf._error) return; + bool ok = true; + int lcnt = 0; + + char line[kLineMax]; while (scrf.read((uint8 *)line) != 0) { char *p; @@ -1360,33 +1353,41 @@ void CGEEngine::loadScript(const char *fname) { continue; ok = false; // not OK if break + // sprite ident number if ((p = strtok(line, " \t\n")) == NULL) break; - SpI = atoi(p); + int SpI = atoi(p); + // sprite file name + char *SpN; if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) break; + // sprite cave if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpA = atoi(p); + int SpA = atoi(p); + // sprite column if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpX = atoi(p); + int SpX = atoi(p); + // sprite row if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpY = atoi(p); + int SpY = atoi(p); + // sprite Z pos if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpZ = atoi(p); + int SpZ = atoi(p); + // sprite life if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - BkG = atoi(p) == 0; + bool BkG = atoi(p) == 0; ok = true; // no break: OK @@ -1395,7 +1396,8 @@ void CGEEngine::loadScript(const char *fname) { if (_sprite && BkG) _sprite->_flags._back = true; } - if (! ok) + + if (!ok) error("Bad INI line %d [%s]", lcnt, fname); } @@ -1469,15 +1471,14 @@ void CGEEngine::loadUser() { // user .SVG file found - load it from slot 0 loadGame(0, NULL); } else if (_mode == 1) { - // Load either initial game state savegame or launcher specified savegame - loadGame(_startGameSlot, NULL); + // Load either initial game state savegame or launcher specified savegame + loadGame(_startGameSlot, NULL); } else { - error("Creating setup savegames not supported"); + error("Creating setup savegames not supported"); } loadScript(progName(kIn0Ext)); } - void CGEEngine::runGame() { if (_eventManager->_quitFlag) return; @@ -1601,7 +1602,6 @@ void CGEEngine::runGame() { _shadow = NULL; } - void CGEEngine::movie(const char *ext) { if (_eventManager->_quitFlag) return; @@ -1624,7 +1624,6 @@ void CGEEngine::movie(const char *ext) { } } - bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; @@ -1634,7 +1633,6 @@ bool CGEEngine::showTitle(const char *name) { LB[0] = new Bitmap(name, true); LB[1] = NULL; Bitmap::_pal = NULL; - bool userOk = false; Sprite D(this, LB); D._flags._kill = true; @@ -1672,6 +1670,7 @@ bool CGEEngine::showTitle(const char *name) { _midiPlayer.loadMidi(0); } + bool userOk = false; if (_mode < 2) { if (_isDemo) { strcpy(_usrFnam, progName(kSvgExt)); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 916de839eb..342a0a8cb1 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -184,7 +184,6 @@ Mouse::~Mouse() { off(); } - void Mouse::on() { if (_seqPtr && _exist) { _active = true; @@ -194,7 +193,6 @@ void Mouse::on() { } } - void Mouse::off() { if (_seqPtr == 0) { if (_exist) { @@ -332,8 +330,7 @@ void EventManager::handleEvents() { void EventManager::clearEvent(Sprite *spr) { if (spr) { - uint16 e; - for (e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) + for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) if (_eventQueue[e]._spritePtr == spr) _eventQueue[e]._mask = 0; } else @@ -346,4 +343,5 @@ CGEEvent &EventManager::getNextEvent() { return evt; } + } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index 124597c329..9df09fdba5 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -82,7 +82,6 @@ struct CGEEvent { Sprite *_spritePtr; }; - class Mouse : public Sprite { public: Sprite *_hold; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index e64e4af38a..0c4f5971bc 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -43,7 +43,7 @@ uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { return x; } -int Fly::_l = 20, +const int Fly::_l = 20, Fly::_t = 40, Fly::_r = 110, Fly::_b = 100; @@ -56,17 +56,17 @@ Fly::Fly(CGEEngine *vm, Bitmap **shpl) void Fly::tick() { step(); - if (!_flags._kept) { - if (newRandom(10) < 1) { - _tx = newRandom(3) - 1; - _ty = newRandom(3) - 1; - } - if (_x + _tx < _l || _x + _tx + _w > _r) - _tx = -_tx; - if (_y + _ty < _t || _y + _ty + _h > _b) - _ty = -_ty; - gotoxy(_x + _tx, _y + _ty); + if (_flags._kept) + return; + if (newRandom(10) < 1) { + _tx = newRandom(3) - 1; + _ty = newRandom(3) - 1; } + if (_x + _tx < _l || _x + _tx + _w > _r) + _tx = -_tx; + if (_y + _ty < _t || _y + _ty + _h > _b) + _ty = -_ty; + gotoxy(_x + _tx, _y + _ty); } } // End of namespace CGE diff --git a/engines/cge/game.h b/engines/cge/game.h index 078f3880ea..bb4f3655a2 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -32,14 +32,13 @@ namespace CGE { - uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b); class Fly : public Sprite { - static int _l; - static int _t; - static int _r; - static int _b; + static const int _l; + static const int _t; + static const int _r; + static const int _b; public: int _tx, _ty; Fly(CGEEngine *vm, Bitmap **shpl); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 112de730ec..25ed7d6ff2 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -124,7 +124,7 @@ char *forceExt(char *buf, const char *name, const char *ext) { return buf; } -static unsigned Seed = 0xA5; +static unsigned Seed = 0xA5; unsigned fastRand() { return Seed = 257 * Seed + 817; @@ -157,22 +157,25 @@ uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { } uint16 atow(const char *a) { + if (!a) + return 0; + uint16 w = 0; - if (a) - while (IsDigit(*a)) - w = (10 * w) + (*(a++) & 0xF); + while (IsDigit(*a)) + w = (10 * w) + (*(a++) & 0xF); return w; } uint16 xtow(const char *x) { + if (!x) + return 0; + uint16 w = 0; - if (x) { - while (IsHxDig(*x)) { - register uint16 d = *(x++); - if (d > '9') - d -= 'A' - ('9' + 1); - w = (w << 4) | (d & 0xF); - } + while (IsHxDig(*x)) { + register uint16 d = *(x++); + if (d > '9') + d -= 'A' - ('9' + 1); + w = (w << 4) | (d & 0xF); } return w; } @@ -261,8 +264,7 @@ long IoHand::size() { } bool IoHand::exist(const char *name) { - Common::File f; - return f.exists(name); + return Common::File::exists(name); } void sndSetVolume() { @@ -298,8 +300,8 @@ DataCk::DataCk(byte *buf, int bufSize) { } DataCk::~DataCk() { - if (_buf) - free(_buf); + if (_buf) + free(_buf); } } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index d96e494402..46dacbe1de 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -33,15 +33,14 @@ namespace CGE { GetText *GetText::_ptr = NULL; - GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) : Talk(vm), _text(text), _size(min<int>(size, kGetTextMax)), _len(min<int>(_size, strlen(text))), _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - int i = 2 * kTextHMargin + _font->width(info); _ptr = this; _mode = kTBRect; _ts = new BitmapPtr[2]; + const int i = 2 * kTextHMargin + _font->width(info); _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); _ts[1] = NULL; setShapeList(_ts); @@ -55,13 +54,11 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) tick(); } - GetText::~GetText() { _keyboard->setClient(_oldKeybClient); _ptr = NULL; } - void GetText::tick() { if (++_cntr >= kGetTextBlink) { _buff[_len] ^= (' ' ^ '_'); @@ -71,7 +68,6 @@ void GetText::tick() { _time = kGetTextTime; } - void GetText::touch(uint16 mask, int x, int y) { static char ogon[] = ""; static char bezo[] = "ACELNOSXZ"; @@ -80,7 +76,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (mask & kEventKeyb) { _vm->keyClick(); switch (x) { - case Enter : + case Enter: _buff[_len] = '\0'; strcpy(_text, _buff); for (p = _text; *p; p++) { @@ -88,17 +84,17 @@ void GetText::touch(uint16 mask, int x, int y) { if (q) *p = bezo[q - ogon]; } - case Esc : + case Esc: _snail_->addCom(kSnKill, -1, 0, this); break; - case BSp : + case BSp: if (_len) { _len--; _buff[_len] = _buff[_len + 1]; _buff[_len + 1] = _buff[_len + 2]; } break; - default : + default: if (x < 'A' || x > 'Z') { if (_oldKeybClient) _oldKeybClient->touch(mask, x, y); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index ba24f832c3..8390647cec 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -38,7 +38,6 @@ extern Mouse *Mouse; bool Mixer::_appear = false; - Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _vm(vm) { _appear = true; _mb[0] = new Bitmap("VOLUME", true); @@ -53,19 +52,18 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ // slaves - uint i; Seq ls[kMixMax]; - for (i = 0; i < kMixMax; i++) { + for (uint i = 0; i < kMixMax; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); _lb[i] = new Bitmap(fn, true); ls[i]._now = ls[i]._next = i; ls[i]._dx = ls[i]._dy = ls[i]._dly = 0; } - _lb[i] = NULL; + _lb[kMixMax] = NULL; - for (i = 0; i < ArrayCount(_led); i++) { + for (uint i = 0; i < ArrayCount(_led); i++) { register Sprite *spr = new Sprite(_vm, _lb); Seq *seq = (Seq *)malloc(kMixMax * sizeof(Seq)); @@ -82,7 +80,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ _led[ArrayCount(_led) - 1]->_flags._bDel = true; _vga->_showQ->insert(this); - for (i = 0; i < ArrayCount(_led); i++) + for (uint i = 0; i < ArrayCount(_led); i++) _vga->_showQ->insert(_led[i]); //--- reset balance @@ -102,7 +100,6 @@ Mixer::~Mixer() { _appear = false; } - #pragma argsused void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); @@ -122,7 +119,6 @@ void Mixer::touch(uint16 mask, int x, int y) { } } - void Mixer::tick() { int x = _mouse->_x; int y = _mouse->_y; @@ -131,9 +127,9 @@ void Mixer::tick() { if (_flags._hold) touch(kMouseLeftUp, x - _x, y - _y); } else { - if (_fall) + if (_fall) { _fall--; - else { + } else { for (uint i = 0; i < ArrayCount(_led); i++) _snail_->addCom(kSnKill, -1, 0, _led[i]); _snail_->addCom(kSnKill, -1, 0, this); @@ -142,7 +138,6 @@ void Mixer::tick() { _time = kMixDelay; } - void Mixer::update() { warning("STUB: Mixer::Update"); /* diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 88949dbfc0..4bcd5cb715 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -32,50 +32,51 @@ #include "cge/events.h" namespace CGE { + Font::Font(const char *name) { - _map = (uint8 *) malloc(sizeof(uint8) * kMapSize); - _pos = (uint16 *) malloc(sizeof(uint16) * kPosSize); - _wid = (uint8 *) malloc(sizeof(uint8) * kWidSize); + _map = (uint8 *)malloc(kMapSize); + _pos = (uint16 *)malloc(kPosSize * sizeof(uint16)); + _wid = (uint8 *)malloc(kWidSize); + assert((_map != NULL) && (_pos != NULL) && (_wid != NULL)); mergeExt(_path, name, kFontExt); load(); } - Font::~Font() { free(_map); free(_pos); free(_wid); } - void Font::load() { INI_FILE f(_path); - if (!f._error) { - f.read(_wid, kWidSize); - if (!f._error) { - uint16 i, p = 0; - for (i = 0; i < kPosSize; i++) { - _pos[i] = p; - p += _wid[i]; - } - f.read(_map, p); - } + if (f._error) + return; + + f.read(_wid, kWidSize); + if (f._error) + return; + + uint16 p = 0; + for (uint16 i = 0; i < kPosSize; i++) { + _pos[i] = p; + p += _wid[i]; } + f.read(_map, p); } - uint16 Font::width(const char *text) { uint16 w = 0; - if (text) - while (* text) - w += _wid[(unsigned char)*(text++)]; + if (!text) + return 0; + while (*text) + w += _wid[(unsigned char)*(text++)]; return w; } Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { - _ts = NULL; _flags._syst = true; update(text); @@ -98,19 +99,17 @@ void Talk::deinit() { delete _font; } - void Talk::update(const char *text) { - uint16 vmarg = (_mode) ? kTextVMargin : 0; - uint16 hmarg = (_mode) ? kTextHMargin : 0; + const uint16 vmarg = (_mode) ? kTextVMargin : 0; + const uint16 hmarg = (_mode) ? kTextHMargin : 0; uint16 mw = 0; uint16 ln = vmarg; - const char *p; uint8 *m; if (!_ts) { uint16 k = 2 * hmarg; uint16 mh = 2 * vmarg + kFontHigh; - for (p = text; *p; p++) { + for (const char *p = text; *p; p++) { if (*p == '|' || *p == '\n') { mh += kFontHigh + kTextLineSpace; if (k > mw) @@ -130,15 +129,15 @@ void Talk::update(const char *text) { m = _ts[0]->_m + ln * mw + hmarg; while (*text) { - if (*text == '|' || *text == '\n') + if (*text == '|' || *text == '\n') { m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; - else { - int cw = _font->_wid[(unsigned char)*text], i; + } else { + int cw = _font->_wid[(unsigned char)*text]; uint8 *f = _font->_map + _font->_pos[(unsigned char)*text]; - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { uint8 *pp = m; uint16 n; - register uint16 b = *(f++); + uint16 b = *(f++); for (n = 0; n < kFontHigh; n++) { if (b & 1) *pp = kTextColFG; @@ -155,21 +154,18 @@ void Talk::update(const char *text) { } Bitmap *Talk::box(uint16 w, uint16 h) { - uint8 *b, * p, * q; - uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; - if (w < 8) w = 8; if (h < 8) h = 8; uint16 n = w * h; - b = (uint8 *) malloc(sizeof(uint8) * n); + uint8 *b = (uint8 *)malloc(n); assert(b != NULL); memset(b, kTextColBG, n); if (_mode) { - p = b; - q = b + n - w; + uint8 *p = b; + uint8 *q = b + n - w; memset(p, LGRAY, w); memset(q, DGRAY, w); while (p < q) { @@ -178,6 +174,7 @@ Bitmap *Talk::box(uint16 w, uint16 h) { *p = LGRAY; } p = b; + const uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; for (int i = 0; i < r; i++) { int j; for (j = 0; j < r - i; j++) { @@ -197,13 +194,12 @@ Bitmap *Talk::box(uint16 w, uint16 h) { return new Bitmap(w, h, b); } - void Talk::putLine(int line, const char *text) { -// Note: (TS[0].W % 4) have to be 0 + // Note: (_ts[0]._w % 4) must be 0 uint16 w = _ts[0]->_w; uint16 h = _ts[0]->_h; - uint8 *v = _ts[0]->_v, * p; - uint16 dsiz = w >> 2; // data size (1 plane line size) + uint8 *v = _ts[0]->_v; + uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gap, but + plane trailer uint16 size = 4 * psiz; // whole map size @@ -211,7 +207,7 @@ void Talk::putLine(int line, const char *text) { // set desired line pointer v += (kTextVMargin + (kFontHigh + kTextLineSpace) * line) * lsiz; - p = v; // assume blanked line above text + uint8 *p = v; // assume blanked line above text // clear whole rectangle assert((rsiz % lsiz) == 0); @@ -221,34 +217,32 @@ void Talk::putLine(int line, const char *text) { } // paint text line - if (text) { - uint8 *q; - p = v + 2 + kTextHMargin / 4 + (kTextHMargin % 4) * psiz; - q = v + size; - - while (* text) { - uint16 cw = _font->_wid[(unsigned char)*text], i; - uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; + if (!text) + return; + p = v + 2 + (kTextHMargin / 4) + (kTextHMargin % 4) * psiz; + uint8 *q = v + size; - for (i = 0; i < cw; i++) { - register uint16 b = fp[i]; - uint16 n; - for (n = 0; n < kFontHigh; n++) { - if (b & 1) - *p = kTextColFG; - b >>= 1; - p += lsiz; - } - p = p - rsiz + psiz; - if (p >= q) - p = p - size + 1; + while (*text) { + uint16 cw = _font->_wid[(unsigned char)*text], i; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; + + for (i = 0; i < cw; i++) { + uint16 b = fp[i]; + uint16 n; + for (n = 0; n < kFontHigh; n++) { + if (b & 1) + *p = kTextColFG; + b >>= 1; + p += lsiz; } - text++; + p = p - rsiz + psiz; + if (p >= q) + p = p - size + 1; } + text++; } } - InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { if (!_ts) { _ts = new BitmapPtr[2]; @@ -259,52 +253,52 @@ InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) setShapeList(_ts); } - void InfoLine::update(const char *text) { - if (text != _oldText) { - uint16 w = _ts[0]->_w; - uint16 h = _ts[0]->_h; - uint8 *v = (uint8 *) _ts[0]->_v; - uint16 dsiz = w >> 2; // data size (1 plane line size) - uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = h * lsiz; // - last gape, but + plane trailer - uint16 size = 4 * psiz; // whole map size - - // clear whole rectangle - byte *pDest; - memset(v + 2, kTextColBG, dsiz); // data bytes - for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { - Common::copy(v, v + lsiz, pDest); - } - *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 - for (pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { - Common::copy(v, v + psiz, pDest); - } + if (text == _oldText) + return; + + uint16 w = _ts[0]->_w; + uint16 h = _ts[0]->_h; + uint8 *v = (uint8 *)_ts[0]->_v; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gape, but + plane trailer + uint16 size = 4 * psiz; // whole map size + + // clear whole rectangle + memset(v + 2, kTextColBG, dsiz); // data bytes + for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { + Common::copy(v, v + lsiz, pDest); + } + *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 + for (byte *pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { + Common::copy(v, v + psiz, pDest); + } - // paint text line - if (text) { - uint8 *p = v + 2, * q = p + size; - - while (*text) { - uint16 cw = _font->_wid[(unsigned char)*text]; - uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; - - for (uint16 i = 0; i < cw; i++) { - register uint16 b = fp[i]; - for (uint16 n = 0; n < kFontHigh; n++) { - if (b & 1) - *p = kTextColFG; - b >>= 1; - p += lsiz; - } - if (p >= q) - p = p - size + 1; + // paint text line + if (text) { + uint8 *p = v + 2, * q = p + size; + + while (*text) { + uint16 cw = _font->_wid[(unsigned char)*text]; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; + + for (uint16 i = 0; i < cw; i++) { + uint16 b = fp[i]; + for (uint16 n = 0; n < kFontHigh; n++) { + if (b & 1) + *p = kTextColFG; + b >>= 1; + p += lsiz; } - text++; + if (p >= q) + p = p - size + 1; } + text++; } - _oldText = text; } + + _oldText = text; } } // End of namespace CGE diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 0e77bb8955..7e58762afa 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -50,16 +50,13 @@ Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { } } - Text::~Text() { clear(); delete[] _cache; } - void Text::clear(int from, int upto) { - 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 >= from && p->_ref < upto) { p->_ref = 0; delete[] p->_text; @@ -68,11 +65,9 @@ void Text::clear(int from, int upto) { } } - int Text::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 @@ -91,31 +86,34 @@ void Text::preload(int from, int upto) { while ((n = tf.read((uint8 *)line)) != 0) { char *s; - int ref; if (line[n - 1] == '\n') - line[-- n] = '\0'; + line[--n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (! IsDigit(*s)) + if (!IsDigit(*s)) continue; - ref = atoi(s); + + int ref = atoi(s); if (ref && ref >= from && ref < upto) { - Han *p; + Han *p = &_cache[find(ref)]; - 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); } @@ -126,35 +124,39 @@ void Text::preload(int from, int upto) { char *Text::load(int idx, int ref) { INI_FILE tf = _fileName; - if (!tf._error) { - Han *p = &_cache[idx]; - char line[kLineMax + 1]; - int n; + if (tf._error) + return NULL; + + 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 r = atoi(s); + if (r < ref) + continue; + if (r > ref) + break; - while ((n = tf.read((uint8 *)line)) != 0) { - char *s; + // (r == ref) + s += strlen(s); + if (s < line + n) + ++s; - if (line[n - 1] == '\n') - line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) - continue; - if (! IsDigit(*s)) - continue; + Han *p = &_cache[idx]; + p->_ref = ref; - int r = atoi(s); - if (r < ref) - continue; - if (r > ref) - break; - // (r == ref) - s += strlen(s); - if (s < line + n) - ++s; - p->_ref = ref; - if ((p->_text = new char[strlen(s) + 1]) == NULL) - return NULL; - return strcpy(p->_text, s); - } + if ((p->_text = new char[strlen(s) + 1]) == NULL) + return NULL; + return strcpy(p->_text, s); } return NULL; } @@ -179,42 +181,43 @@ char *Text::getText(int ref) { void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); - if (_talk) { - bool east = spr->_flags._east; - int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); - int y = spr->_y + 2; - Sprite *spike = new Spike(_vm); - uint16 sw = spike->_w; - - if (east) { - if (x + sw + kTextRoundCorner + 5 >= kScrWidth) - east = false; - } else { - if (x <= 5 + kTextRoundCorner + sw) - east = true; - } - x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); - if (spr->_ref == 1) - x += ((east) ? -10 : 10); // Hero - - _talk->_flags._kill = true; - _talk->_flags._bDel = true; - _talk->setName(_text->getText(kSayName)); - _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); - _talk->_z = 125; - _talk->_ref = kSayRef; - - spike->gotoxy(x, _talk->_y + _talk->_h - 1); - spike->_z = 126; - spike->_flags._slav = true; - spike->_flags._kill = true; - spike->setName(_text->getText(kSayName)); - spike->step(east); - spike->_ref = kSayRef; - - _vga->_showQ->insert(_talk, _vga->_showQ->last()); - _vga->_showQ->insert(spike, _vga->_showQ->last()); + if (!_talk) + return; + + bool east = spr->_flags._east; + int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); + int y = spr->_y + 2; + Sprite *spike = new Spike(_vm); + uint16 sw = spike->_w; + + if (east) { + if (x + sw + kTextRoundCorner + 5 >= kScrWidth) + east = false; + } else { + if (x <= 5 + kTextRoundCorner + sw) + east = true; } + x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); + if (spr->_ref == 1) + x += ((east) ? -10 : 10); // Hero + + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(kSayName)); + _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); + _talk->_z = 125; + _talk->_ref = kSayRef; + + spike->gotoxy(x, _talk->_y + _talk->_h - 1); + spike->_z = 126; + spike->_flags._slav = true; + spike->_flags._kill = true; + spike->setName(_text->getText(kSayName)); + spike->step(east); + spike->_ref = kSayRef; + + _vga->_showQ->insert(_talk, _vga->_showQ->last()); + _vga->_showQ->insert(spike, _vga->_showQ->last()); } void CGEEngine::inf(const char *text) { @@ -222,31 +225,34 @@ void CGEEngine::inf(const char *text) { killText(); _talk = new Talk(this, text, kTBRect); - if (_talk) { - _talk->_flags._kill = true; - _talk->_flags._bDel = true; - _talk->setName(_text->getText(kInfName)); - _talk->center(); - _talk->gotoxy(_talk->_x, _talk->_y - 20); - _talk->_z = 126; - _talk->_ref = kInfRef; - _vga->_showQ->insert(_talk, _vga->_showQ->last()); - } + if (!_talk) + return; + + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(kInfName)); + _talk->center(); + _talk->gotoxy(_talk->_x, _talk->_y - 20); + _talk->_z = 126; + _talk->_ref = kInfRef; + _vga->_showQ->insert(_talk, _vga->_showQ->last()); } void Text::sayTime(Sprite *spr) { TimeDate curTime; - char t[6]; _vm->_system->getTimeAndDate(curTime); + + char t[6]; sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min); say(t, spr); } void killText() { - if (_talk) { - _snail_->addCom(kSnKill, -1, 0, _talk); - _talk = NULL; - } + if (!_talk) + return; + + _snail_->addCom(kSnKill, -1, 0, _talk); + _talk = NULL; } } // End of namespace CGE diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 48b27d9727..c8a21160bf 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -59,9 +59,7 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { _flags._bDel = true; } - -static char *vmgt; - +static char *g_vmgt; char *VMGather(Choice *list) { Choice *cp; @@ -71,30 +69,28 @@ char *VMGather(Choice *list) { len += strlen(cp->_text); h++; } - vmgt = new char[len + h]; - if (vmgt) { - *vmgt = '\0'; + g_vmgt = new char[len + h]; + if (g_vmgt) { + *g_vmgt = '\0'; for (cp = list; cp->_text; cp++) { - if (*vmgt) - strcat(vmgt, "|"); - strcat(vmgt, cp->_text); + if (*g_vmgt) + strcat(g_vmgt, "|"); + strcat(g_vmgt, cp->_text); h++; } } - return vmgt; + return g_vmgt; } - Vmenu *Vmenu::_addr = NULL; -int Vmenu::_recent = -1; - +int Vmenu::_recent = -1; Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) : Talk(vm, VMGather(list), kTBRect), _menu(list), _bar(NULL), _vm(vm) { Choice *cp; _addr = this; - delete[] vmgt; + delete[] g_vmgt; _items = 0; for (cp = list; cp->_text; cp++) _items++; @@ -110,7 +106,6 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) _vga->_showQ->insert(_bar, _vga->_showQ->last()); } - Vmenu::~Vmenu() { _addr = NULL; } @@ -118,31 +113,32 @@ Vmenu::~Vmenu() { #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) void Vmenu::touch(uint16 mask, int x, int y) { - if (_items) { - Sprite::touch(mask, x, y); - - y -= kTextVMargin - 1; - int n = 0; - bool ok = false; - uint16 h = kFontHigh + kTextLineSpace; - - if (y >= 0) { - n = y / h; - if (n < _items) - ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/); - else - n = _items - 1; - } + if (!_items) + return; + + Sprite::touch(mask, x, y); + + y -= kTextVMargin - 1; + int n = 0; + bool ok = false; + uint16 h = kFontHigh + kTextLineSpace; + + if (y >= 0) { + n = y / h; + if (n < _items) + ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/); + else + n = _items - 1; + } - _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); + _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); - if (ok && (mask & kMouseLeftUp)) { - _items = 0; - _snail_->addCom(kSnKill, -1, 0, this); - _recent = n; - assert(_menu[n].Proc); - CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); - } + if (ok && (mask & kMouseLeftUp)) { + _items = 0; + _snail_->addCom(kSnKill, -1, 0, this); + _recent = n; + assert(_menu[n].Proc); + CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); } } diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 44cad5e832..51dbe4f856 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -73,20 +73,17 @@ VFile::VFile(const char *name, IOMode mode) } } - VFile::~VFile() { if (_recent == this) _recent = NULL; } - bool VFile::exist(const char *name) { debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); return scumm_stricmp(_cat->find(name)->_key, name) == 0; } - void VFile::readBuf() { debugC(3, kCGEDebugFile, "VFile::readBuf()"); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 7bce9e29e6..89d7f6308b 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -96,9 +96,9 @@ void Walk::tick() { } } - if (_flags._hold || _tracePtr < 0) + if (_flags._hold || _tracePtr < 0) { park(); - else { + } else { if (_here == _trace[_tracePtr]) { if (--_tracePtr < 0) park(); @@ -112,9 +112,9 @@ void Walk::tick() { step(); if ((_dir == kDirWest && _x <= 0) || (_dir == kDirEast && _x + _w >= kScrWidth) || - (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) + (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); - else { + } else { signed char x; // dummy var _here.split(x, _z); // take current Z position _snail_->addCom(kSnZTrim, -1, 0, this); // update Hero's pos in show queue @@ -123,8 +123,7 @@ void Walk::tick() { int Walk::distance(Sprite *spr) { - int dx, dz; - dx = spr->_x - (_x + _w - kWalkSide); + int dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) dx = (_x + kWalkSide) - (spr->_x + spr->_w); @@ -132,7 +131,7 @@ int Walk::distance(Sprite *spr) { dx = 0; dx /= kMapGridX; - dz = spr->_z - _z; + int dz = spr->_z - _z; if (dz < 0) dz = - dz; @@ -166,36 +165,39 @@ void Walk::park() { void Walk::findWay(Cluster c) { - if (c != _here) { - for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { - signed char x, z; - _here.split(x, z); - _target = Couple(x, z); - c.split(x, z); - - if (find1Way(Cluster(x, z))) - break; - } - _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); - if (_tracePtr < 0) - noWay(); - _time = 1; + if (c == _here) + return; + + for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { + signed char x, z; + _here.split(x, z); + _target = Couple(x, z); + c.split(x, z); + + 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) { - int x = spr->_x; - int z = spr->_z; - if (spr->_flags._east) - x += spr->_w + _w / 2 - kWalkSide; - else - x -= _w / 2 - kWalkSide; - findWay(Cluster((x / kMapGridX), - ((z < kMapZCnt - kDistMax) ? (z + 1) - : (z - 1)))); - } + if (!spr || spr == this) + return; + + int x = spr->_x; + int z = spr->_z; + if (spr->_flags._east) + x += spr->_w + _w / 2 - kWalkSide; + else + x -= _w / 2 - kWalkSide; + + findWay(Cluster((x / kMapGridX), + ((z < kMapZCnt - kDistMax) ? (z + 1) + : (z - 1)))); } diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 271663e51d..e924976927 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -96,7 +96,6 @@ public: bool isValid() const; }; - class Walk : public Sprite { private: CGEEngine *_vm; |