diff options
author | Strangerke | 2011-09-17 17:17:22 +0200 |
---|---|---|
committer | Strangerke | 2011-09-17 17:17:22 +0200 |
commit | 3583c949f253330dbf4c53a66b74e764de9ea156 (patch) | |
tree | 13d3aa82e12feef7300f8cf615af210d6efd8448 | |
parent | 8491e557ce46f03ca98f9a4486005a5e337de8ed (diff) | |
download | scummvm-rg350-3583c949f253330dbf4c53a66b74e764de9ea156.tar.gz scummvm-rg350-3583c949f253330dbf4c53a66b74e764de9ea156.tar.bz2 scummvm-rg350-3583c949f253330dbf4c53a66b74e764de9ea156.zip |
CGE: Move some more globals to CGEEngine
-rw-r--r-- | engines/cge/bitmap.cpp | 17 | ||||
-rw-r--r-- | engines/cge/bitmap.h | 3 | ||||
-rw-r--r-- | engines/cge/cge.cpp | 11 | ||||
-rw-r--r-- | engines/cge/cge.h | 7 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 30 | ||||
-rw-r--r-- | engines/cge/snail.cpp | 10 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 40 | ||||
-rw-r--r-- | engines/cge/walk.h | 16 |
8 files changed, 62 insertions, 72 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 27ab5770eb..39bafc5e98 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -34,15 +34,6 @@ namespace CGE { -Dac *Bitmap::_pal = NULL; - -void Bitmap::init() { - _pal = NULL; -} - -void Bitmap::deinit() { -} - Bitmap::Bitmap(CGEEngine *vm, const char *fname) : _m(NULL), _v(NULL), _map(0), _vm(vm) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%s)", fname); @@ -373,16 +364,16 @@ bool Bitmap::loadVBM(EncryptedStream *f) { if (!f->err()) { if (p) { - if (_pal) { + if (_vm->_bitmapPalette) { // Read in the palette byte palData[kPalSize]; f->read(palData, kPalSize); const byte *srcP = palData; for (int idx = 0; idx < kPalCount; idx++, srcP += 3) { - _pal[idx]._r = *srcP; - _pal[idx]._g = *(srcP + 1); - _pal[idx]._b = *(srcP + 2); + _vm->_bitmapPalette[idx]._r = *srcP; + _vm->_bitmapPalette[idx]._g = *(srcP + 1); + _vm->_bitmapPalette[idx]._b = *(srcP + 2); } } else f->seek(f->pos() + kPalSize); diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index bb935e7049..aa6282705c 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -58,7 +58,6 @@ class Bitmap { char *forceExt(char *buf, const char *name, const char *ext); bool loadVBM(EncryptedStream *f); public: - static Dac *_pal; uint16 _w; uint16 _h; uint8 *_m; @@ -72,8 +71,6 @@ public: Bitmap(CGEEngine *vm, const Bitmap &bmp); ~Bitmap(); - static void init(); - static void deinit(); Bitmap *code(); Bitmap &operator=(const Bitmap &bmp); void hide(int16 x, int16 y); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 68b07c8fb2..f1b69a0ecd 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -52,6 +52,9 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) _demoText = kDemo; _oldLev = 0; _pocPtr = 0; + _bitmapPalette = NULL; + + } @@ -84,10 +87,6 @@ void CGEEngine::init() { // Create debugger console _console = new CGEConsole(this); - // Initialise classes that have static members - Bitmap::init(); - Cluster::init(this); - // Initialise engine objects _font = new Font(this, "CGE"); _text = new Text(this, "CGE"); @@ -140,10 +139,6 @@ void CGEEngine::init() { } void CGEEngine::deinit() { - // Call classes with static members to clear them up - Bitmap::deinit(); - Cluster::init(this); - // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 5bf6e278ea..1d7ad69009 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -51,6 +51,7 @@ class SceneLight; class Snail; class EventManager; class ResourceManager; +class Walk; #define kSavegameVersion 2 #define kSavegameStrSize 11 @@ -70,7 +71,8 @@ class ResourceManager; #define kPathMax 128 #define kCryptSeed 0xA5 #define kMaxFile 128 - +#define kMapXCnt 40 +#define kMapZCnt 20 // our engine debug channels enum { @@ -156,6 +158,8 @@ public: int _soundOk; int _gameCase2Cpt; int _offUseCount; + Dac *_bitmapPalette; + uint8 _clusterMap[kMapZCnt][kMapXCnt]; Sprite *_sprTv; Sprite *_sprK1; @@ -184,6 +188,7 @@ public: Sound *_sound; ResourceManager *_resman; Sprite *_pocket[kPocketNX]; + Walk *_hero; Common::RandomSource _randomSource; MusicPlayer *_midiPlayer; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index de3511813a..4666181906 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -497,7 +497,7 @@ void CGEEngine::loadMapping() { // Read in the data for (int z = 0; z < kMapZCnt; ++z) { - cf.read(&Cluster::_map[z][0], kMapXCnt); + cf.read(&_clusterMap[z][0], kMapXCnt); } } } @@ -529,7 +529,7 @@ void CGEEngine::setMapBrick(int x, int z) { char n[6]; s->gotoxy(x * kMapGridX, kMapTop + z * kMapGridZ); sprintf(n, "%02d:%02d", x, z); - Cluster::_map[z][x] = 1; + _clusterMap[z][x] = 1; s->setName(n); _vga->_showQ->insert(s, _vga->_showQ->first()); } @@ -596,9 +596,9 @@ void CGEEngine::showBak(int ref) { if (!spr) return; - Bitmap::_pal = _vga->_sysPal; + _bitmapPalette = _vga->_sysPal; spr->expand(); - Bitmap::_pal = NULL; + _bitmapPalette = NULL; spr->show(2); _vga->copyPage(1, 2); _sys->setPal(); @@ -802,7 +802,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->postMiniStep(selectedScene - 1); if (mask & kMouseLeftUp) { - if (selectedScene && _vm->_snail->idle() && _hero->_tracePtr < 0) + if (selectedScene && _vm->_snail->idle() && _vm->_hero->_tracePtr < 0) _vm->switchScene(selectedScene); if (_vm->_horzLine && !_vm->_horzLine->_flags._hide) { @@ -810,13 +810,13 @@ void System::touch(uint16 mask, int x, int y) { Cluster tmpCluster = _vm->XZ(x, y); int16 x1 = tmpCluster._pt.x; int16 z1 = tmpCluster._pt.y; - Cluster::_map[z1][x1] = 1; + _vm->_clusterMap[z1][x1] = 1; _vm->setMapBrick(x1, z1); } } else { - if (!_talk && _vm->_snail->idle() && _hero + if (!_talk && _vm->_snail->idle() && _vm->_hero && y >= kMapTop && y < kMapTop + kMapHig && !_vm->_game) { - _hero->findWay(_vm->XZ(x, y)); + _vm->_hero->findWay(_vm->XZ(x, y)); } } } @@ -833,7 +833,7 @@ void System::tick() { else { // CHECKME: Before, was: if (Startup::_core >= CORE_MID) { int n = _vm->newRandom(100); if (n > 96) - _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2)); + _vm->heroCover(6 + (_vm->_hero->_x + _vm->_hero->_w / 2 < kScrWidth / 2)); else if (n > 90) _vm->heroCover(5); else if (n > 60) @@ -880,7 +880,7 @@ void CGEEngine::switchMapping() { if (_horzLine && _horzLine->_flags._hide) { for (int i = 0; i < kMapZCnt; i++) { for (int j = 0; j < kMapXCnt; j++) { - if (Cluster::_map[i][j]) + if (_clusterMap[i][j]) setMapBrick(j, i); } } @@ -949,7 +949,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & kMouseRightUp) && _vm->_snail->idle()) { Sprite *ps = (_vm->_pocLight->_seqPtr) ? _vm->_pocket[_vm->_pocPtr] : NULL; if (ps) { - if (_flags._kept || _hero->distance(this) < kDistMax) { + if (_flags._kept || _vm->_hero->distance(this) < kDistMax) { if (works(ps)) { _vm->feedSnail(ps, kTake); } else @@ -961,7 +961,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (_flags._kept) { mask |= kMouseLeftUp; } else { - if (_hero->distance(this) < kDistMax) { + if (_vm->_hero->distance(this) < kDistMax) { if (_flags._port) { if (_vm->findPocket(NULL) < 0) { _vm->pocFul(); @@ -1222,7 +1222,7 @@ Cluster CGEEngine::XZ(int16 x, int16 y) { if (y > kMapTop + kMapHig - kMapGridZ) y = kMapTop + kMapHig - kMapGridZ; - return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); + return Cluster(this, x / kMapGridX, (y - kMapTop) / kMapGridZ); } void CGEEngine::killText() { @@ -1447,11 +1447,11 @@ bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; - Bitmap::_pal = _vga->_sysPal; + _bitmapPalette = _vga->_sysPal; BitmapPtr *LB = new BitmapPtr[2]; LB[0] = new Bitmap(this, name); LB[1] = NULL; - Bitmap::_pal = NULL; + _bitmapPalette = NULL; Sprite D(this, LB); D._flags._kill = true; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 148307dab8..3c85f4abdb 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -565,12 +565,12 @@ void CGEEngine::snSend(Sprite *spr, int val) { spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) - Bitmap::_pal = _vga->_sysPal; + _bitmapPalette = _vga->_sysPal; if (spr->_flags._back) spr->backShow(true); else expandSprite(spr); - Bitmap::_pal = NULL; + _bitmapPalette = NULL; } } } @@ -976,7 +976,7 @@ void Snail::runCom() { case kSnWait: if (spr) { if (spr->seqTest(snc->_val) && - (snc->_val >= 0 || spr != _hero || _hero->_tracePtr < 0)) { + (snc->_val >= 0 || spr != _vm->_hero || _vm->_hero->_tracePtr < 0)) { _timerExpiry = g_system->getMillis() + spr->_time * kSnailFrameDelay; } else { _busy = false; @@ -992,7 +992,7 @@ void Snail::runCom() { break; case kSnSay: if (spr && _talkEnable) { - if (spr == _hero && spr->seqTest(-1)) + if (spr == _vm->_hero && spr->seqTest(-1)) spr->step(kSeqHTalk); _text->say(_text->getText(snc->_val), spr); _vm->_sys->_funDel = kHeroFun0; @@ -1006,7 +1006,7 @@ void Snail::runCom() { break; case kSnTime: if (spr && _talkEnable) { - if (spr == _hero && spr->seqTest(-1)) + if (spr == _vm->_hero && spr->seqTest(-1)) spr->step(kSeqHTalk); _text->sayTime(spr); } diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 314d5920f8..04c85a4c6a 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -30,17 +30,16 @@ namespace CGE { -Walk *_hero; - -uint8 Cluster::_map[kMapZCnt][kMapXCnt]; -CGEEngine *Cluster::_vm; +Cluster::Cluster(CGEEngine *vm, int16 a, int16 b) : _vm(vm) { + _pt = Common::Point(a, b); +} -void Cluster::init(CGEEngine *vm) { - _vm = vm; +Cluster::Cluster(CGEEngine *vm) : _vm(vm) { + _pt = Common::Point(-1, -1); } uint8 &Cluster::cell() { - return _map[_pt.y][_pt.x]; + return _vm->_clusterMap[_pt.y][_pt.x]; } bool Cluster::isValid() const { @@ -48,7 +47,16 @@ bool Cluster::isValid() const { } Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) - : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { + : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _here(vm), _vm(vm) { + for (int i = 0; i < kMaxFindLevel; i++) { + Cluster *tmpClust = new Cluster(_vm); + _trace.push_back(tmpClust); + } +} + +Walk::~Walk() { + for (uint idx = 0; idx < _trace.size(); ++idx) + delete _trace[idx]; } void Walk::tick() { @@ -74,11 +82,11 @@ void Walk::tick() { if (_flags._hold || _tracePtr < 0) { park(); } else { - if (_here._pt == _trace[_tracePtr]._pt) { + if (_here._pt == _trace[_tracePtr]->_pt) { if (--_tracePtr < 0) park(); } else { - Common::Point tmpPoint = _trace[_tracePtr]._pt - _here._pt; + Common::Point tmpPoint = _trace[_tracePtr]->_pt - _here._pt; int16 dx = tmpPoint.x; int16 dz = tmpPoint.y; Dir d = (dx) ? ((dx > 0) ? kDirEast : kDirWest) : ((dz > 0) ? kDirSouth : kDirNorth); @@ -147,7 +155,7 @@ void Walk::findWay(Cluster c) { int16 x = c._pt.x; int16 z = c._pt.y; - if (find1Way(Cluster(x, z))) + if (find1Way(Cluster(_vm, x, z))) break; } @@ -168,7 +176,7 @@ void Walk::findWay(Sprite *spr) { else x -= _w / 2 - kWalkSide; - findWay(Cluster((x / kMapGridX), + findWay(Cluster(_vm, (x / kMapGridX), ((z < kMapZCnt - kDistMax) ? (z + 1) : (z - 1)))); } @@ -179,7 +187,7 @@ bool Walk::lower(Sprite *spr) { void Walk::reach(Sprite *spr, int mode) { if (spr) { - _hero->findWay(spr); + _vm->_hero->findWay(spr); if (mode < 0) { mode = spr->_flags._east; if (lower(spr)) @@ -190,7 +198,7 @@ void Walk::reach(Sprite *spr, int mode) { _vm->_snail->insCom(kSnPause, -1, 64, NULL); _vm->_snail->insCom(kSnSeq, -1, kTSeq + mode, this); if (spr) { - _vm->_snail->insCom(kSnWait, -1, -1, _hero); + _vm->_snail->insCom(kSnWait, -1, -1, _vm->_hero); //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, @@ -207,7 +215,7 @@ bool Cluster::chkBar() const { } bool Walk::find1Way(Cluster c) { - const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; + const Cluster tab[4] = { Cluster(_vm, -1, 0), Cluster(_vm, 1, 0), Cluster(_vm, 0, -1), Cluster(_vm, 0, 1)}; const int tabLen = 4; if (c._pt == _target) @@ -247,7 +255,7 @@ bool Walk::find1Way(Cluster c) { if (foundPath) { // Set route point - _trace[_level] = start; + _trace[_level]->_pt = start._pt; return true; } } while (!c.chkBar() && !c.cell()); diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 2224ae8745..99dc362eec 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -34,8 +34,6 @@ namespace CGE { -#define kMapXCnt 40 -#define kMapZCnt 20 #define kMapArrSize (kMapZCnt * kMapXCnt) #define kMapTop 80 #define kMapHig 80 @@ -47,15 +45,12 @@ enum Dir { kDirNone = -1, kDirNorth, kDirEast, kDirSouth, kDirWest }; class Cluster { public: - static uint8 _map[kMapZCnt][kMapXCnt]; - static CGEEngine *_vm; + CGEEngine *_vm; Common::Point _pt; - - static void init(CGEEngine *vm); public: uint8 &cell(); - Cluster(int16 a, int16 b) { _pt = Common::Point(a, b); } - Cluster() { _pt = Common::Point(-1, -1); } + Cluster(CGEEngine *vm, int16 a, int16 b); + Cluster(CGEEngine *vm); bool chkBar() const; bool isValid() const; }; @@ -69,10 +64,11 @@ public: int _level; int _findLevel; Common::Point _target; - Cluster _trace[kMaxFindLevel]; + Common::Array<Cluster *> _trace; Dir _dir; Walk(CGEEngine *vm, BitmapPtr *shpl); + ~Walk(); void tick(); void findWay(Cluster c); void findWay(Sprite *spr); @@ -86,8 +82,6 @@ public: bool find1Way(Cluster c); }; -extern Walk *_hero; - } // End of namespace CGE #endif |