CGE: Get rid of some more global functions and static members

This commit is contained in:
Strangerke 2011-09-16 20:31:11 +02:00
parent 679fc75408
commit 938c08ae58
16 changed files with 67 additions and 70 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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();

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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)

View File

@ -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();

View File

@ -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

View File

@ -61,11 +61,8 @@ private:
CGEEngine *_vm;
};
extern Talk *_talk;
extern Text *_text;
void killText();
} // End of namespace CGE
#endif

View File

@ -51,7 +51,6 @@ private:
CGEEngine *_vm;
};
class Vmenu : public Talk {
public:
static Vmenu *_addr;

View File

@ -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();

View File

@ -86,8 +86,6 @@ public:
bool find1Way(Cluster c);
};
Cluster XZ(int16 x, int16 y);
extern Walk *_hero;
} // End of namespace CGE