diff options
author | Strangerke | 2011-09-16 20:31:11 +0200 |
---|---|---|
committer | Strangerke | 2011-09-16 20:31:39 +0200 |
commit | 938c08ae589eaa9b0cafc02478997f34bf7d598d (patch) | |
tree | e2ca985bb8db4db38184a168cf7597a75b313a77 | |
parent | 679fc754089473b8459c07b7192eb07f0b1ca183 (diff) | |
download | scummvm-rg350-938c08ae589eaa9b0cafc02478997f34bf7d598d.tar.gz scummvm-rg350-938c08ae589eaa9b0cafc02478997f34bf7d598d.tar.bz2 scummvm-rg350-938c08ae589eaa9b0cafc02478997f34bf7d598d.zip |
CGE: Get rid of some more global functions and static members
-rw-r--r-- | engines/cge/cge.cpp | 2 | ||||
-rw-r--r-- | engines/cge/cge.h | 3 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 28 | ||||
-rw-r--r-- | engines/cge/events.cpp | 4 | ||||
-rw-r--r-- | engines/cge/events.h | 3 | ||||
-rw-r--r-- | engines/cge/game.cpp | 11 | ||||
-rw-r--r-- | engines/cge/game.h | 15 | ||||
-rw-r--r-- | engines/cge/snail.cpp | 8 | ||||
-rw-r--r-- | engines/cge/snail.h | 14 | ||||
-rw-r--r-- | engines/cge/sound.cpp | 14 | ||||
-rw-r--r-- | engines/cge/sound.h | 7 | ||||
-rw-r--r-- | engines/cge/text.cpp | 10 | ||||
-rw-r--r-- | engines/cge/text.h | 3 | ||||
-rw-r--r-- | engines/cge/vmenu.h | 1 | ||||
-rw-r--r-- | engines/cge/walk.cpp | 12 | ||||
-rw-r--r-- | engines/cge/walk.h | 2 |
16 files changed, 67 insertions, 70 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 1297aea5e3..349bf3f31c 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -105,7 +105,7 @@ void CGEEngine::init() { _mouse = new Mouse(this); _keyboard = new Keyboard(this); - _eventManager = new EventManager(); + _eventManager = new EventManager(this); _fx = new Fx(16); // must precede SOUND!! _sound = new Sound(this); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 24288cdece..af526742b3 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -40,6 +40,7 @@ namespace CGE { class Console; class Sprite; +class Cluster; #define kSavegameVersion 2 #define kSavegameStrSize 11 @@ -232,6 +233,8 @@ public: void sndSetVolume(); Sprite *locate(int ref); Sprite *spriteAt(int x, int y); + Cluster XZ(int16 x, int16 y); + void killText(); void snBackPt(Sprite *spr, int stp); void snHBarrier(const int scene, const int barX); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index dde8fd1c11..7d9acb462c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -540,7 +540,7 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & kMouseLeftUp) { - XZ(_x + x, _y + y).cell() = 0; + _vm->XZ(_x + x, _y + y).cell() = 0; _snail_->addCom(kSnKill, -1, 0, this); } } @@ -778,7 +778,7 @@ void System::touch(uint16 mask, int x, int y) { if (mask & kEventKeyb) { _vm->keyClick(); - killText(); + _vm->killText(); if (_vm->_startupMode == 1) { _snail->addCom(kSnClear, -1, 0, NULL); return; @@ -831,7 +831,7 @@ void System::touch(uint16 mask, int x, int y) { if (_horzLine && !_horzLine->_flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { - Cluster tmpCluster = XZ(x, y); + Cluster tmpCluster = _vm->XZ(x, y); int16 x1 = tmpCluster._pt.x; int16 z1 = tmpCluster._pt.y; Cluster::_map[z1][x1] = 1; @@ -840,7 +840,7 @@ void System::touch(uint16 mask, int x, int y) { } else { if (!_talk && _snail->idle() && _hero && y >= kMapTop && y < kMapTop + kMapHig && !_vm->_game) { - _hero->findWay(XZ(x, y)); + _hero->findWay(_vm->XZ(x, y)); } } } @@ -850,7 +850,7 @@ void System::touch(uint16 mask, int x, int y) { void System::tick() { if (!_vm->_startupMode) if (--_funDel == 0) { - killText(); + _vm->killText(); if (_snail->idle()) { if (_vm->_flag[0]) // Pain flag _vm->heroCover(9); @@ -1239,6 +1239,24 @@ Sprite *CGEEngine::spriteAt(int x, int y) { return spr; } +Cluster CGEEngine::XZ(int16 x, int16 y) { + if (y < kMapTop) + y = kMapTop; + + if (y > kMapTop + kMapHig - kMapGridZ) + y = kMapTop + kMapHig - kMapGridZ; + + return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); +} + +void CGEEngine::killText() { + if (!_talk) + return; + + _snail_->addCom(kSnKill, -1, 0, _talk); + _talk = NULL; +} + void CGEEngine::mainLoop() { _vga->show(); _snail_->runCom(); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 1330466aa2..59e0d5f87a 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -271,7 +271,7 @@ void Mouse::newMouse(Common::Event &event) { /*----------------- EventManager interface -----------------*/ -EventManager::EventManager() { +EventManager::EventManager(CGEEngine *vm) : _vm(vm){ _quitFlag = false; _eventQueueHead = 0; _eventQueueTail = 0; @@ -349,7 +349,7 @@ void EventManager::handleEvents() { // discard Text if button released if (e._mask & (kMouseLeftUp | kMouseRightUp)) - killText(); + _vm->killText(); } _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } diff --git a/engines/cge/events.h b/engines/cge/events.h index f170455fa7..26678a5ae2 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -134,6 +134,7 @@ private: class EventManager { private: + CGEEngine *_vm; Common::Event _event; CGEEvent _eventQueue[kEventMax]; uint16 _eventQueueHead; @@ -143,7 +144,7 @@ private: public: bool _quitFlag; - EventManager(); + EventManager(CGEEngine *vm); void poll(); void clearEvent(Sprite *spr); diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 115de222ad..851f6c59fb 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -30,15 +30,10 @@ namespace CGE { -const int Fly::_l = 20, - Fly::_t = 40, - Fly::_r = 110, - Fly::_b = 100; - Fly::Fly(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { step(_vm->newRandom(2)); - gotoxy(_l + _vm->newRandom(_r - _l - _w), _t + _vm->newRandom(_b - _t - _h)); + gotoxy(kFlyL + _vm->newRandom(kFlyR - kFlyL - _w), kFlyT + _vm->newRandom(kFlyB - kFlyT - _h)); } void Fly::tick() { @@ -49,9 +44,9 @@ void Fly::tick() { _tx = _vm->newRandom(3) - 1; _ty = _vm->newRandom(3) - 1; } - if (_x + _tx < _l || _x + _tx + _w > _r) + if (_x + _tx < kFlyL || _x + _tx + _w > kFlyR) _tx = -_tx; - if (_y + _ty < _t || _y + _ty + _h > _b) + if (_y + _ty < kFlyT || _y + _ty + _h > kFlyB) _ty = -_ty; gotoxy(_x + _tx, _y + _ty); } diff --git a/engines/cge/game.h b/engines/cge/game.h index 88ef4344ba..4d5acf7371 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -32,17 +32,20 @@ namespace CGE { +enum { + kFlyL = 20, + kFlyT = 40, + kFlyR = 110, + kFlyB = 100 +}; + class Fly : public Sprite { - static const int _l; - static const int _t; - static const int _r; - static const int _b; +private: + CGEEngine *_vm; public: int _tx, _ty; Fly(CGEEngine *vm, Bitmap **shpl); void tick(); -private: - CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 19adf6bcb4..b542006014 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -415,7 +415,7 @@ void Snail::addCom(SnCom com, int ref, int val, void *ptr) { snc->_cbType = kNullCB; if (com == kSnClear) { _tail = _head; - killText(); + _vm->killText(); _timerExpiry = 0; } } @@ -429,7 +429,7 @@ void Snail::addCom2(SnCom com, int ref, int val, CallbackType cbType) { snc->_cbType = cbType; if (com == kSnClear) { _tail = _head; - killText(); + _vm->killText(); _timerExpiry = 0; } } @@ -449,7 +449,7 @@ void Snail::insCom(SnCom com, int ref, int val, void *ptr) { snc->_ptr = ptr; if (com == kSnClear) { _tail = _head; - killText(); + _vm->killText(); _timerExpiry = 0; } } @@ -956,7 +956,7 @@ void Snail::runCom() { _timerExpiry = 0; } else { if (_textDelay) { - killText(); + _vm->killText(); _textDelay = false; } } diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 533d6b74ef..481f0a5542 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -60,17 +60,11 @@ public: void *_ptr; CallbackType _cbType; } *_snList; - uint8 _head; - uint8 _tail; - bool _turbo; - bool _busy; - bool _textDelay; - uint32 _timerExpiry; static const char *_comText[]; bool _talkEnable; + Snail(CGEEngine *vm, bool turbo); ~Snail(); - void runCom(); void addCom(SnCom com, int ref, int val, void *ptr); void addCom2(SnCom com, int ref, int val, CallbackType cbType); @@ -78,6 +72,12 @@ public: bool idle(); private: CGEEngine *_vm; + bool _turbo; + uint8 _head; + uint8 _tail; + bool _busy; + bool _textDelay; + uint32 _timerExpiry; }; } // End of namespace CGE diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 3dec5e749b..93ccbe9c80 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -35,13 +35,6 @@ namespace CGE { -DataCk *loadWave(EncryptedStream *file) { - byte *data = (byte *)malloc(file->size()); - file->read(data, file->size()); - - return new DataCk(data, file->size()); -} - DataCk::DataCk(byte *buf, int bufSize) { _buf = buf; _ckSize = bufSize; @@ -181,6 +174,13 @@ DataCk *Fx::load(int idx, int ref) { return wav; } +DataCk *Fx::loadWave(EncryptedStream *file) { + byte *data = (byte *)malloc(file->size()); + file->read(data, file->size()); + + return new DataCk(data, file->size()); +} + DataCk *Fx::operator[](int ref) { int i; if ((i = find(ref)) < _size) diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 727ee78a5b..26a1525831 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -64,11 +64,10 @@ public: } }; -DataCk *loadWave(EncryptedStream *file); - class Sound { public: SmpInfo _smpinf; + Sound(CGEEngine *vm); ~Sound(); void open(); @@ -87,17 +86,19 @@ private: void sndDigiStop(SmpInfo *PSmpInfo); }; - class Fx { struct Handler { int _ref; DataCk *_wav; } *_cache; int _size; + DataCk *load(int idx, int ref); + DataCk *loadWave(EncryptedStream *file); int find(int ref); public: DataCk *_current; + Fx(int size); ~Fx(); void clear(); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 3268070aff..c28e3ba70a 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -137,7 +137,7 @@ char *Text::getText(int ref) { } void Text::say(const char *text, Sprite *spr) { - killText(); + _vm->killText(); _talk = new Talk(_vm, text, kTBRound); if (!_talk) return; @@ -205,12 +205,4 @@ void Text::sayTime(Sprite *spr) { say(t, spr); } -void killText() { - if (!_talk) - return; - - _snail_->addCom(kSnKill, -1, 0, _talk); - _talk = NULL; -} - } // End of namespace CGE diff --git a/engines/cge/text.h b/engines/cge/text.h index 668f307f72..5acdaaa519 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -61,11 +61,8 @@ private: CGEEngine *_vm; }; -extern Talk *_talk; extern Text *_text; -void killText(); - } // End of namespace CGE #endif diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index b8740a9e93..89ef7a9484 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -51,7 +51,6 @@ private: CGEEngine *_vm; }; - class Vmenu : public Talk { public: static Vmenu *_addr; diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index cda2875ac4..4de8bc779d 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -47,16 +47,6 @@ bool Cluster::isValid() const { return (_pt.x >= 0) && (_pt.x < kMapXCnt) && (_pt.y >= 0) && (_pt.y < kMapZCnt); } -Cluster XZ(int16 x, int16 y) { - if (y < kMapTop) - y = kMapTop; - - if (y > kMapTop + kMapHig - kMapGridZ) - y = kMapTop + kMapHig - kMapGridZ; - - return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); -} - Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } @@ -65,7 +55,7 @@ void Walk::tick() { if (_flags._hide) return; - _here = XZ(_x + _w / 2, _y + _h); + _here = _vm->XZ(_x + _w / 2, _y + _h); if (_dir != kDirNone) { _sys->funTouch(); diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 9b94120bb4..2224ae8745 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -86,8 +86,6 @@ public: bool find1Way(Cluster c); }; -Cluster XZ(int16 x, int16 y); - extern Walk *_hero; } // End of namespace CGE |