CGE: Get rid of some more global functions and static members
This commit is contained in:
parent
679fc75408
commit
938c08ae58
16 changed files with 67 additions and 70 deletions
|
@ -105,7 +105,7 @@ void CGEEngine::init() {
|
||||||
|
|
||||||
_mouse = new Mouse(this);
|
_mouse = new Mouse(this);
|
||||||
_keyboard = new Keyboard(this);
|
_keyboard = new Keyboard(this);
|
||||||
_eventManager = new EventManager();
|
_eventManager = new EventManager(this);
|
||||||
_fx = new Fx(16); // must precede SOUND!!
|
_fx = new Fx(16); // must precede SOUND!!
|
||||||
_sound = new Sound(this);
|
_sound = new Sound(this);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace CGE {
|
||||||
|
|
||||||
class Console;
|
class Console;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
class Cluster;
|
||||||
|
|
||||||
#define kSavegameVersion 2
|
#define kSavegameVersion 2
|
||||||
#define kSavegameStrSize 11
|
#define kSavegameStrSize 11
|
||||||
|
@ -232,6 +233,8 @@ public:
|
||||||
void sndSetVolume();
|
void sndSetVolume();
|
||||||
Sprite *locate(int ref);
|
Sprite *locate(int ref);
|
||||||
Sprite *spriteAt(int x, int y);
|
Sprite *spriteAt(int x, int y);
|
||||||
|
Cluster XZ(int16 x, int16 y);
|
||||||
|
void killText();
|
||||||
|
|
||||||
void snBackPt(Sprite *spr, int stp);
|
void snBackPt(Sprite *spr, int stp);
|
||||||
void snHBarrier(const int scene, const int barX);
|
void snHBarrier(const int scene, const int barX);
|
||||||
|
|
|
@ -540,7 +540,7 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) {
|
||||||
void Square::touch(uint16 mask, int x, int y) {
|
void Square::touch(uint16 mask, int x, int y) {
|
||||||
Sprite::touch(mask, x, y);
|
Sprite::touch(mask, x, y);
|
||||||
if (mask & kMouseLeftUp) {
|
if (mask & kMouseLeftUp) {
|
||||||
XZ(_x + x, _y + y).cell() = 0;
|
_vm->XZ(_x + x, _y + y).cell() = 0;
|
||||||
_snail_->addCom(kSnKill, -1, 0, this);
|
_snail_->addCom(kSnKill, -1, 0, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -778,7 +778,7 @@ void System::touch(uint16 mask, int x, int y) {
|
||||||
|
|
||||||
if (mask & kEventKeyb) {
|
if (mask & kEventKeyb) {
|
||||||
_vm->keyClick();
|
_vm->keyClick();
|
||||||
killText();
|
_vm->killText();
|
||||||
if (_vm->_startupMode == 1) {
|
if (_vm->_startupMode == 1) {
|
||||||
_snail->addCom(kSnClear, -1, 0, NULL);
|
_snail->addCom(kSnClear, -1, 0, NULL);
|
||||||
return;
|
return;
|
||||||
|
@ -831,7 +831,7 @@ void System::touch(uint16 mask, int x, int y) {
|
||||||
|
|
||||||
if (_horzLine && !_horzLine->_flags._hide) {
|
if (_horzLine && !_horzLine->_flags._hide) {
|
||||||
if (y >= kMapTop && y < kMapTop + kMapHig) {
|
if (y >= kMapTop && y < kMapTop + kMapHig) {
|
||||||
Cluster tmpCluster = XZ(x, y);
|
Cluster tmpCluster = _vm->XZ(x, y);
|
||||||
int16 x1 = tmpCluster._pt.x;
|
int16 x1 = tmpCluster._pt.x;
|
||||||
int16 z1 = tmpCluster._pt.y;
|
int16 z1 = tmpCluster._pt.y;
|
||||||
Cluster::_map[z1][x1] = 1;
|
Cluster::_map[z1][x1] = 1;
|
||||||
|
@ -840,7 +840,7 @@ void System::touch(uint16 mask, int x, int y) {
|
||||||
} else {
|
} else {
|
||||||
if (!_talk && _snail->idle() && _hero
|
if (!_talk && _snail->idle() && _hero
|
||||||
&& y >= kMapTop && y < kMapTop + kMapHig && !_vm->_game) {
|
&& 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() {
|
void System::tick() {
|
||||||
if (!_vm->_startupMode)
|
if (!_vm->_startupMode)
|
||||||
if (--_funDel == 0) {
|
if (--_funDel == 0) {
|
||||||
killText();
|
_vm->killText();
|
||||||
if (_snail->idle()) {
|
if (_snail->idle()) {
|
||||||
if (_vm->_flag[0]) // Pain flag
|
if (_vm->_flag[0]) // Pain flag
|
||||||
_vm->heroCover(9);
|
_vm->heroCover(9);
|
||||||
|
@ -1239,6 +1239,24 @@ Sprite *CGEEngine::spriteAt(int x, int y) {
|
||||||
return spr;
|
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() {
|
void CGEEngine::mainLoop() {
|
||||||
_vga->show();
|
_vga->show();
|
||||||
_snail_->runCom();
|
_snail_->runCom();
|
||||||
|
|
|
@ -271,7 +271,7 @@ void Mouse::newMouse(Common::Event &event) {
|
||||||
|
|
||||||
/*----------------- EventManager interface -----------------*/
|
/*----------------- EventManager interface -----------------*/
|
||||||
|
|
||||||
EventManager::EventManager() {
|
EventManager::EventManager(CGEEngine *vm) : _vm(vm){
|
||||||
_quitFlag = false;
|
_quitFlag = false;
|
||||||
_eventQueueHead = 0;
|
_eventQueueHead = 0;
|
||||||
_eventQueueTail = 0;
|
_eventQueueTail = 0;
|
||||||
|
@ -349,7 +349,7 @@ void EventManager::handleEvents() {
|
||||||
|
|
||||||
// discard Text if button released
|
// discard Text if button released
|
||||||
if (e._mask & (kMouseLeftUp | kMouseRightUp))
|
if (e._mask & (kMouseLeftUp | kMouseRightUp))
|
||||||
killText();
|
_vm->killText();
|
||||||
}
|
}
|
||||||
_eventQueueTail = (_eventQueueTail + 1) % kEventMax;
|
_eventQueueTail = (_eventQueueTail + 1) % kEventMax;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,7 @@ private:
|
||||||
|
|
||||||
class EventManager {
|
class EventManager {
|
||||||
private:
|
private:
|
||||||
|
CGEEngine *_vm;
|
||||||
Common::Event _event;
|
Common::Event _event;
|
||||||
CGEEvent _eventQueue[kEventMax];
|
CGEEvent _eventQueue[kEventMax];
|
||||||
uint16 _eventQueueHead;
|
uint16 _eventQueueHead;
|
||||||
|
@ -143,7 +144,7 @@ private:
|
||||||
public:
|
public:
|
||||||
bool _quitFlag;
|
bool _quitFlag;
|
||||||
|
|
||||||
EventManager();
|
EventManager(CGEEngine *vm);
|
||||||
void poll();
|
void poll();
|
||||||
void clearEvent(Sprite *spr);
|
void clearEvent(Sprite *spr);
|
||||||
|
|
||||||
|
|
|
@ -30,15 +30,10 @@
|
||||||
|
|
||||||
namespace CGE {
|
namespace CGE {
|
||||||
|
|
||||||
const int Fly::_l = 20,
|
|
||||||
Fly::_t = 40,
|
|
||||||
Fly::_r = 110,
|
|
||||||
Fly::_b = 100;
|
|
||||||
|
|
||||||
Fly::Fly(CGEEngine *vm, Bitmap **shpl)
|
Fly::Fly(CGEEngine *vm, Bitmap **shpl)
|
||||||
: Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) {
|
: Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) {
|
||||||
step(_vm->newRandom(2));
|
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() {
|
void Fly::tick() {
|
||||||
|
@ -49,9 +44,9 @@ void Fly::tick() {
|
||||||
_tx = _vm->newRandom(3) - 1;
|
_tx = _vm->newRandom(3) - 1;
|
||||||
_ty = _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;
|
_tx = -_tx;
|
||||||
if (_y + _ty < _t || _y + _ty + _h > _b)
|
if (_y + _ty < kFlyT || _y + _ty + _h > kFlyB)
|
||||||
_ty = -_ty;
|
_ty = -_ty;
|
||||||
gotoxy(_x + _tx, _y + _ty);
|
gotoxy(_x + _tx, _y + _ty);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,17 +32,20 @@
|
||||||
|
|
||||||
namespace CGE {
|
namespace CGE {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kFlyL = 20,
|
||||||
|
kFlyT = 40,
|
||||||
|
kFlyR = 110,
|
||||||
|
kFlyB = 100
|
||||||
|
};
|
||||||
|
|
||||||
class Fly : public Sprite {
|
class Fly : public Sprite {
|
||||||
static const int _l;
|
private:
|
||||||
static const int _t;
|
CGEEngine *_vm;
|
||||||
static const int _r;
|
|
||||||
static const int _b;
|
|
||||||
public:
|
public:
|
||||||
int _tx, _ty;
|
int _tx, _ty;
|
||||||
Fly(CGEEngine *vm, Bitmap **shpl);
|
Fly(CGEEngine *vm, Bitmap **shpl);
|
||||||
void tick();
|
void tick();
|
||||||
private:
|
|
||||||
CGEEngine *_vm;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace CGE
|
} // End of namespace CGE
|
||||||
|
|
|
@ -415,7 +415,7 @@ void Snail::addCom(SnCom com, int ref, int val, void *ptr) {
|
||||||
snc->_cbType = kNullCB;
|
snc->_cbType = kNullCB;
|
||||||
if (com == kSnClear) {
|
if (com == kSnClear) {
|
||||||
_tail = _head;
|
_tail = _head;
|
||||||
killText();
|
_vm->killText();
|
||||||
_timerExpiry = 0;
|
_timerExpiry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ void Snail::addCom2(SnCom com, int ref, int val, CallbackType cbType) {
|
||||||
snc->_cbType = cbType;
|
snc->_cbType = cbType;
|
||||||
if (com == kSnClear) {
|
if (com == kSnClear) {
|
||||||
_tail = _head;
|
_tail = _head;
|
||||||
killText();
|
_vm->killText();
|
||||||
_timerExpiry = 0;
|
_timerExpiry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ void Snail::insCom(SnCom com, int ref, int val, void *ptr) {
|
||||||
snc->_ptr = ptr;
|
snc->_ptr = ptr;
|
||||||
if (com == kSnClear) {
|
if (com == kSnClear) {
|
||||||
_tail = _head;
|
_tail = _head;
|
||||||
killText();
|
_vm->killText();
|
||||||
_timerExpiry = 0;
|
_timerExpiry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -956,7 +956,7 @@ void Snail::runCom() {
|
||||||
_timerExpiry = 0;
|
_timerExpiry = 0;
|
||||||
} else {
|
} else {
|
||||||
if (_textDelay) {
|
if (_textDelay) {
|
||||||
killText();
|
_vm->killText();
|
||||||
_textDelay = false;
|
_textDelay = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,17 +60,11 @@ public:
|
||||||
void *_ptr;
|
void *_ptr;
|
||||||
CallbackType _cbType;
|
CallbackType _cbType;
|
||||||
} *_snList;
|
} *_snList;
|
||||||
uint8 _head;
|
|
||||||
uint8 _tail;
|
|
||||||
bool _turbo;
|
|
||||||
bool _busy;
|
|
||||||
bool _textDelay;
|
|
||||||
uint32 _timerExpiry;
|
|
||||||
static const char *_comText[];
|
static const char *_comText[];
|
||||||
bool _talkEnable;
|
bool _talkEnable;
|
||||||
|
|
||||||
Snail(CGEEngine *vm, bool turbo);
|
Snail(CGEEngine *vm, bool turbo);
|
||||||
~Snail();
|
~Snail();
|
||||||
|
|
||||||
void runCom();
|
void runCom();
|
||||||
void addCom(SnCom com, int ref, int val, void *ptr);
|
void addCom(SnCom com, int ref, int val, void *ptr);
|
||||||
void addCom2(SnCom com, int ref, int val, CallbackType cbType);
|
void addCom2(SnCom com, int ref, int val, CallbackType cbType);
|
||||||
|
@ -78,6 +72,12 @@ public:
|
||||||
bool idle();
|
bool idle();
|
||||||
private:
|
private:
|
||||||
CGEEngine *_vm;
|
CGEEngine *_vm;
|
||||||
|
bool _turbo;
|
||||||
|
uint8 _head;
|
||||||
|
uint8 _tail;
|
||||||
|
bool _busy;
|
||||||
|
bool _textDelay;
|
||||||
|
uint32 _timerExpiry;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace CGE
|
} // End of namespace CGE
|
||||||
|
|
|
@ -35,13 +35,6 @@
|
||||||
|
|
||||||
namespace CGE {
|
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) {
|
DataCk::DataCk(byte *buf, int bufSize) {
|
||||||
_buf = buf;
|
_buf = buf;
|
||||||
_ckSize = bufSize;
|
_ckSize = bufSize;
|
||||||
|
@ -181,6 +174,13 @@ DataCk *Fx::load(int idx, int ref) {
|
||||||
return wav;
|
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) {
|
DataCk *Fx::operator[](int ref) {
|
||||||
int i;
|
int i;
|
||||||
if ((i = find(ref)) < _size)
|
if ((i = find(ref)) < _size)
|
||||||
|
|
|
@ -64,11 +64,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DataCk *loadWave(EncryptedStream *file);
|
|
||||||
|
|
||||||
class Sound {
|
class Sound {
|
||||||
public:
|
public:
|
||||||
SmpInfo _smpinf;
|
SmpInfo _smpinf;
|
||||||
|
|
||||||
Sound(CGEEngine *vm);
|
Sound(CGEEngine *vm);
|
||||||
~Sound();
|
~Sound();
|
||||||
void open();
|
void open();
|
||||||
|
@ -87,17 +86,19 @@ private:
|
||||||
void sndDigiStop(SmpInfo *PSmpInfo);
|
void sndDigiStop(SmpInfo *PSmpInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Fx {
|
class Fx {
|
||||||
struct Handler {
|
struct Handler {
|
||||||
int _ref;
|
int _ref;
|
||||||
DataCk *_wav;
|
DataCk *_wav;
|
||||||
} *_cache;
|
} *_cache;
|
||||||
int _size;
|
int _size;
|
||||||
|
|
||||||
DataCk *load(int idx, int ref);
|
DataCk *load(int idx, int ref);
|
||||||
|
DataCk *loadWave(EncryptedStream *file);
|
||||||
int find(int ref);
|
int find(int ref);
|
||||||
public:
|
public:
|
||||||
DataCk *_current;
|
DataCk *_current;
|
||||||
|
|
||||||
Fx(int size);
|
Fx(int size);
|
||||||
~Fx();
|
~Fx();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
|
@ -137,7 +137,7 @@ char *Text::getText(int ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::say(const char *text, Sprite *spr) {
|
void Text::say(const char *text, Sprite *spr) {
|
||||||
killText();
|
_vm->killText();
|
||||||
_talk = new Talk(_vm, text, kTBRound);
|
_talk = new Talk(_vm, text, kTBRound);
|
||||||
if (!_talk)
|
if (!_talk)
|
||||||
return;
|
return;
|
||||||
|
@ -205,12 +205,4 @@ void Text::sayTime(Sprite *spr) {
|
||||||
say(t, spr);
|
say(t, spr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void killText() {
|
|
||||||
if (!_talk)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_snail_->addCom(kSnKill, -1, 0, _talk);
|
|
||||||
_talk = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End of namespace CGE
|
} // End of namespace CGE
|
||||||
|
|
|
@ -61,11 +61,8 @@ private:
|
||||||
CGEEngine *_vm;
|
CGEEngine *_vm;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Talk *_talk;
|
|
||||||
extern Text *_text;
|
extern Text *_text;
|
||||||
|
|
||||||
void killText();
|
|
||||||
|
|
||||||
} // End of namespace CGE
|
} // End of namespace CGE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,7 +51,6 @@ private:
|
||||||
CGEEngine *_vm;
|
CGEEngine *_vm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Vmenu : public Talk {
|
class Vmenu : public Talk {
|
||||||
public:
|
public:
|
||||||
static Vmenu *_addr;
|
static Vmenu *_addr;
|
||||||
|
|
|
@ -47,16 +47,6 @@ bool Cluster::isValid() const {
|
||||||
return (_pt.x >= 0) && (_pt.x < kMapXCnt) && (_pt.y >= 0) && (_pt.y < kMapZCnt);
|
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)
|
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), _vm(vm) {
|
||||||
}
|
}
|
||||||
|
@ -65,7 +55,7 @@ void Walk::tick() {
|
||||||
if (_flags._hide)
|
if (_flags._hide)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_here = XZ(_x + _w / 2, _y + _h);
|
_here = _vm->XZ(_x + _w / 2, _y + _h);
|
||||||
|
|
||||||
if (_dir != kDirNone) {
|
if (_dir != kDirNone) {
|
||||||
_sys->funTouch();
|
_sys->funTouch();
|
||||||
|
|
|
@ -86,8 +86,6 @@ public:
|
||||||
bool find1Way(Cluster c);
|
bool find1Way(Cluster c);
|
||||||
};
|
};
|
||||||
|
|
||||||
Cluster XZ(int16 x, int16 y);
|
|
||||||
|
|
||||||
extern Walk *_hero;
|
extern Walk *_hero;
|
||||||
|
|
||||||
} // End of namespace CGE
|
} // End of namespace CGE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue