aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2011-07-02 16:46:31 +1000
committerPaul Gilbert2011-07-02 16:46:31 +1000
commitd55401c2e10276827372f8df29418937cc2daf22 (patch)
tree5b5c38bcb2a51cfa89d24c9ae574e26825ca3ed8
parent6833daab84a39a3d5dd0afcb176245f8678b28de (diff)
downloadscummvm-rg350-d55401c2e10276827372f8df29418937cc2daf22.tar.gz
scummvm-rg350-d55401c2e10276827372f8df29418937cc2daf22.tar.bz2
scummvm-rg350-d55401c2e10276827372f8df29418937cc2daf22.zip
CGE: Changed MOUSE class from using static fields to an instantiated class
-rw-r--r--engines/cge/cge.cpp6
-rw-r--r--engines/cge/cge_main.cpp51
-rw-r--r--engines/cge/cge_main.h3
-rw-r--r--engines/cge/events.cpp11
-rw-r--r--engines/cge/events.h20
-rw-r--r--engines/cge/gettext.cpp6
-rw-r--r--engines/cge/mixer.cpp4
-rw-r--r--engines/cge/snail.cpp6
8 files changed, 57 insertions, 50 deletions
diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp
index 43d74ab3a5..3feb8f64d2 100644
--- a/engines/cge/cge.cpp
+++ b/engines/cge/cge.cpp
@@ -96,7 +96,8 @@ void CGEEngine::setup() {
Snail = new SNAIL(this, false);
Snail_ = new SNAIL(this, true);
- Mouse = new MOUSE(this);
+ _mouse = new MOUSE(this);
+ _keyboard = new Keyboard();
OffUseCount = atoi(Text->getText(OFF_USE_COUNT));
}
@@ -121,7 +122,8 @@ CGEEngine::~CGEEngine() {
delete Hero;
delete Sys;
delete _pocLight;
- delete Mouse;
+ delete _keyboard;
+ delete _mouse;
for (int i = 0; i < POCKET_NX; i++)
delete _pocket[i];
delete _sprite;
diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp
index 40bace9c51..6e5c65b76f 100644
--- a/engines/cge/cge_main.cpp
+++ b/engines/cge/cge_main.cpp
@@ -66,7 +66,8 @@ Heart *_heart;
WALK *Hero;
SYSTEM *Sys;
Sprite *_pocLight;
-MOUSE *Mouse;
+Keyboard *_keyboard;
+MOUSE *_mouse;
Sprite *_pocket[POCKET_NX];
Sprite *_sprite;
Sprite *_miniCave;
@@ -741,7 +742,7 @@ static void caveUp() {
Vga->Sunrise(VGA::SysPal);
Dark = false;
if (! Startup)
- Mouse->On();
+ _mouse->On();
_heart->_enable = true;
}
@@ -792,7 +793,7 @@ void CGEEngine::switchCave(int cav) {
warning("SwitchCave() - SNPOST");
} else {
Now = cav;
- Mouse->Off();
+ _mouse->Off();
if (Hero) {
Hero->park();
Hero->step(0);
@@ -836,13 +837,13 @@ void SYSTEM::Touch(uint16 mask, int x, int y) {
pp0 = pp;
switch (x) {
case Del:
- if (Keyboard::_key[ALT] && Keyboard::_key[CTRL])
+ if (_keyboard->_key[ALT] && _keyboard->_key[CTRL])
AltCtrlDel();
else
KillSprite();
break;
case 'F':
- if (Keyboard::_key[ALT]) {
+ if (_keyboard->_key[ALT]) {
Sprite *m = Vga->ShowQ->Locate(17001);
if (m) {
m->step(1);
@@ -860,7 +861,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) {
NextStep();
break;
case '`':
- if (Keyboard::_key[ALT])
+ if (_keyboard->_key[ALT])
SaveMapping();
else
_vm->switchMapping();
@@ -890,7 +891,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) {
Sys->FunDel = 1;
break;
case 'X':
- if (Keyboard::_key[ALT])
+ if (_keyboard->_key[ALT])
Finis = true;
break;
case '0':
@@ -898,7 +899,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) {
case '2':
case '3':
case '4':
- if (Keyboard::_key[ALT]) {
+ if (_keyboard->_key[ALT]) {
SNPOST(SNLEVEL, -1, x - '0', NULL);
break;
}
@@ -1034,7 +1035,7 @@ static void SwitchColorMode(void) {
static void SwitchMusic(void) {
- if (Keyboard::_key[ALT]) {
+ if (_keyboard->_key[ALT]) {
if (VMENU::Addr)
SNPOST_(SNKILL, -1, 0, VMENU::Addr);
else {
@@ -1194,8 +1195,8 @@ static void SayDebug(void) {
t = t1;
}
- dwtom(Mouse->_x, ABSX, 10, 3);
- dwtom(Mouse->_y, ABSY, 10, 3);
+ dwtom(_mouse->_x, ABSX, 10, 3);
+ dwtom(_mouse->_y, ABSY, 10, 3);
// dwtom(coreleft(), NFRE, 10, 5);
// dwtom(farcoreleft(), FFRE, 10, 6);
@@ -1663,9 +1664,9 @@ void CGEEngine::runGame() {
_horzLine->_z = 126;
Vga->ShowQ->Insert(_horzLine);
- Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF);
- if (Mouse->Busy)
- ExpandSprite(Mouse->Busy);
+ _mouse->Busy = Vga->SpareQ->Locate(BUSY_REF);
+ if (_mouse->Busy)
+ ExpandSprite(_mouse->Busy);
Startup = 0;
@@ -1674,7 +1675,7 @@ void CGEEngine::runGame() {
CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY);
caveUp();
- Keyboard::setClient(Sys);
+ _keyboard->setClient(Sys);
// main loop
while (! Finis) {
//TODO Change the SNPOST message send to a special way to send function pointer
@@ -1683,11 +1684,11 @@ void CGEEngine::runGame() {
mainLoop();
}
- Keyboard::setClient(NULL);
+ _keyboard->setClient(NULL);
_heart->_enable = false;
SNPOST(SNCLEAR, -1, 0, NULL);
SNPOST_(SNCLEAR, -1, 0, NULL);
- Mouse->Off();
+ _mouse->Off();
Vga->ShowQ->Clear();
Vga->SpareQ->Clear();
Hero = NULL;
@@ -1706,11 +1707,11 @@ void CGEEngine::movie(const char *ext) {
//Vga->ShowQ->Append(Mouse);
_heart->_enable = true;
- Keyboard::setClient(Sys);
+ _keyboard->setClient(Sys);
while (!Snail->Idle())
mainLoop();
- Keyboard::setClient(NULL);
+ _keyboard->setClient(NULL);
_heart->_enable = false;
SNPOST(SNCLEAR, -1, 0, NULL);
SNPOST_(SNCLEAR, -1, 0, NULL);
@@ -1746,12 +1747,12 @@ bool CGEEngine::showTitle(const char *name) {
if (STARTUP::Mode < 2 && !STARTUP::SoundOk) {
Vga->CopyPage(1, 2);
Vga->CopyPage(0, 1);
- Vga->ShowQ->Append(Mouse);
+ Vga->ShowQ->Append(_mouse);
_heart->_enable = true;
- Mouse->On();
+ _mouse->On();
for (selectSound(); !Snail->Idle() || VMENU::Addr;)
mainLoop();
- Mouse->Off();
+ _mouse->Off();
_heart->_enable = false;
Vga->ShowQ->Clear();
Vga->CopyPage(0, 2);
@@ -1782,13 +1783,13 @@ bool CGEEngine::showTitle(const char *name) {
movie("X00"); // paylist
Vga->CopyPage(1, 2);
Vga->CopyPage(0, 1);
- Vga->ShowQ->Append(Mouse);
+ Vga->ShowQ->Append(_mouse);
//Mouse.On();
_heart->_enable = true;
for (takeName(); GetText::_ptr;)
mainLoop();
_heart->_enable = false;
- if (Keyboard::last() == Enter && *UsrFnam)
+ if (_keyboard->last() == Enter && *UsrFnam)
usr_ok = true;
if (usr_ok)
strcat(UsrFnam, SVG_EXT);
@@ -1842,7 +1843,7 @@ void CGEEngine::cge_main(void) {
//Debug( memset((void *) (-K(4)), 0, K(1)); )
memset(Barriers, 0xFF, sizeof(Barriers));
- if (!Mouse->Exist)
+ if (!_mouse->Exist)
error("%s", Text->getText(NO_MOUSE_TEXT));
if (!SVG0FILE::exist(SVG0NAME))
diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h
index 37d1a91e00..3eea114420 100644
--- a/engines/cge/cge_main.h
+++ b/engines/cge/cge_main.h
@@ -172,7 +172,8 @@ extern Heart *_heart;
extern SYSTEM *Sys;
extern int OffUseCount;
extern Sprite *_pocLight;
-extern MOUSE *Mouse;
+extern Keyboard *_keyboard;
+extern MOUSE *_mouse;
extern Sprite *_pocket[];
extern Sprite *_sprite;
extern Sprite *_miniCave;
diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp
index e5ad00da5e..49b08e407b 100644
--- a/engines/cge/events.cpp
+++ b/engines/cge/events.cpp
@@ -34,10 +34,7 @@ namespace CGE {
/*----------------- KEYBOARD interface -----------------*/
-Sprite *Keyboard::_client = NULL;
-uint8 Keyboard::_key[0x60] = { 0 };
-uint16 Keyboard::_current = 0;
-uint16 Keyboard::_code[0x60] = {
+const uint16 Keyboard::_code[0x60] = {
0, Esc, '1', '2', '3',
'4', '5', '6', '7', '8',
'9', '0', '-', '+', BSp,
@@ -60,10 +57,12 @@ uint16 Keyboard::_code[0x60] = {
0 * 0x5F
};
-void (* Keyboard::OldKeyboard)(...);
-
Keyboard::Keyboard() {
+ _client = NULL;
+ Common::set_to(&_key[0], &_key[0x60], 0);
+ _current = 0;
+
// steal keyboard interrupt
/* TODO replace totally by scummvm handling
OldKeyboard = getvect(KEYBD_INT);
diff --git a/engines/cge/events.h b/engines/cge/events.h
index 518c8c8bd1..462571f5ad 100644
--- a/engines/cge/events.h
+++ b/engines/cge/events.h
@@ -46,18 +46,19 @@ namespace CGE {
class Keyboard {
public:
- static void (* OldKeyboard)(...);
- static void NewKeyboard(...);
- static uint16 _code[0x60];
- static uint16 _current;
- static Sprite *_client;
- static uint8 _key[0x60];
- static uint16 last() {
+ static const uint16 _code[0x60];
+
+ void NewKeyboard(...);
+ uint16 _current;
+ Sprite *_client;
+ uint8 _key[0x60];
+ uint16 last() {
uint16 cur = _current;
_current = 0;
return cur;
}
- static Sprite *setClient(Sprite *spr);
+ Sprite *setClient(Sprite *spr);
+
Keyboard();
~Keyboard();
};
@@ -111,6 +112,9 @@ private:
CGEEngine *_vm;
};
+/*----------------- Access variables -----------------*/
+// TODO: Move this into either the CGEEngine class or a suitable 'globals'
+
} // End of namespace CGE
#endif
diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp
index 889aee4fed..9a6c1539d1 100644
--- a/engines/cge/gettext.cpp
+++ b/engines/cge/gettext.cpp
@@ -37,7 +37,7 @@ GetText *GetText::_ptr = NULL;
GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)())
: TALK(vm), _text(text), _size(min<int>(size, GTMAX)), _len(min<int>(_size, strlen(text))),
- _cntr(GTBLINK), _click(click), _oldKeybClient(Keyboard::setClient(this)), _vm(vm) {
+ _cntr(GTBLINK), _click(click), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) {
int i = 2 * TEXT_HM + _Font->Width(info);
_ptr = this;
Mode = RECT;
@@ -54,7 +54,7 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*c
GetText::~GetText() {
- Keyboard::setClient(_oldKeybClient);
+ _keyboard->setClient(_oldKeybClient);
_ptr = NULL;
}
@@ -101,7 +101,7 @@ void GetText::touch(uint16 mask, int x, int y) {
if (_oldKeybClient)
_oldKeybClient->touch(mask, x, y);
} else {
- if (Keyboard::_key[ALT]) {
+ if (_keyboard->_key[ALT]) {
p = strchr(bezo, x);
if (p)
x = ogon[p - bezo];
diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp
index f8c0b9ceab..18bbfb65b5 100644
--- a/engines/cge/mixer.cpp
+++ b/engines/cge/mixer.cpp
@@ -114,8 +114,8 @@ void Mixer::touch(uint16 mask, int x, int y) {
void Mixer::tick() {
- int x = Mouse->_x;
- int y = Mouse->_y;
+ int x = _mouse->_x;
+ int y = _mouse->_y;
if (SpriteAt(x, y) == this) {
_fall = MIX_FALL;
if (_flags._hold)
diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp
index 217acb2448..9db8f4af6f 100644
--- a/engines/cge/snail.cpp
+++ b/engines/cge/snail.cpp
@@ -180,7 +180,7 @@ static void SNGame(Sprite *spr, int num) {
k2->step(new_random(6));
k3->step(new_random(6));
///--------------------
- if (spr->_ref == 1 && Keyboard::_key[ALT]) {
+ if (spr->_ref == 1 && _keyboard->_key[ALT]) {
k1->step(5);
k2->step(5);
k3->step(5);
@@ -897,9 +897,9 @@ static void SNReach(Sprite *spr, int mode) {
static void SNMouse(bool on) {
if (on)
- Mouse->On();
+ _mouse->On();
else
- Mouse->Off();
+ _mouse->Off();
}