AGI: Turn g_tickTimer & g_mouse into members of class AgiEngine resp. AgiBase

svn-id: r45259
This commit is contained in:
Max Horn 2009-10-20 11:13:00 +00:00
parent a41292a92f
commit 50435d6bae
11 changed files with 62 additions and 62 deletions

View file

@ -48,9 +48,6 @@
namespace Agi {
static uint32 g_tickTimer;
struct Mouse g_mouse;
void AgiEngine::allowSynthetic(bool allow) {
_allowSynthetic = allow;
}
@ -81,17 +78,17 @@ void AgiEngine::processEvents() {
break;
case Common::EVENT_LBUTTONDOWN:
key = BUTTON_LEFT;
g_mouse.button = kAgiMouseButtonLeft;
_mouse.button = kAgiMouseButtonLeft;
keyEnqueue(key);
g_mouse.x = event.mouse.x;
g_mouse.y = event.mouse.y;
_mouse.x = event.mouse.x;
_mouse.y = event.mouse.y;
break;
case Common::EVENT_RBUTTONDOWN:
key = BUTTON_RIGHT;
g_mouse.button = kAgiMouseButtonRight;
_mouse.button = kAgiMouseButtonRight;
keyEnqueue(key);
g_mouse.x = event.mouse.x;
g_mouse.y = event.mouse.y;
_mouse.x = event.mouse.x;
_mouse.y = event.mouse.y;
break;
case Common::EVENT_WHEELUP:
key = WHEEL_UP;
@ -102,28 +99,28 @@ void AgiEngine::processEvents() {
keyEnqueue(key);
break;
case Common::EVENT_MOUSEMOVE:
g_mouse.x = event.mouse.x;
g_mouse.y = event.mouse.y;
_mouse.x = event.mouse.x;
_mouse.y = event.mouse.y;
if (!_game.mouseFence.isEmpty()) {
if (g_mouse.x < _game.mouseFence.left)
g_mouse.x = _game.mouseFence.left;
if (g_mouse.x > _game.mouseFence.right)
g_mouse.x = _game.mouseFence.right;
if (g_mouse.y < _game.mouseFence.top)
g_mouse.y = _game.mouseFence.top;
if (g_mouse.y > _game.mouseFence.bottom)
g_mouse.y = _game.mouseFence.bottom;
if (_mouse.x < _game.mouseFence.left)
_mouse.x = _game.mouseFence.left;
if (_mouse.x > _game.mouseFence.right)
_mouse.x = _game.mouseFence.right;
if (_mouse.y < _game.mouseFence.top)
_mouse.y = _game.mouseFence.top;
if (_mouse.y > _game.mouseFence.bottom)
_mouse.y = _game.mouseFence.bottom;
g_system->warpMouse(g_mouse.x, g_mouse.y);
g_system->warpMouse(_mouse.x, _mouse.y);
}
break;
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONUP:
g_mouse.button = kAgiMouseButtonUp;
g_mouse.x = event.mouse.x;
g_mouse.y = event.mouse.y;
_mouse.button = kAgiMouseButtonUp;
_mouse.x = event.mouse.x;
_mouse.y = event.mouse.y;
break;
case Common::EVENT_KEYDOWN:
if (event.kbd.flags == Common::KBD_CTRL && event.kbd.keycode == Common::KEYCODE_d) {
@ -276,21 +273,22 @@ void AgiEngine::pollTimer(void) {
static uint32 m = 0;
uint32 dm;
if (g_tickTimer < m)
if (_tickTimer < m)
m = 0;
while ((dm = g_tickTimer - m) < 5) {
while ((dm = _tickTimer - m) < 5) {
processEvents();
if (_console->isAttached())
_console->onFrame();
_system->delayMillis(10);
_system->updateScreen();
}
m = g_tickTimer;
m = _tickTimer;
}
void AgiEngine::agiTimerFunctionLow(void *refCon) {
g_tickTimer++;
AgiEngine *self = (AgiEngine *)refCon;
self->_tickTimer++;
}
void AgiEngine::pause(uint32 msec) {
@ -532,7 +530,7 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
memset(&_game, 0, sizeof(struct AgiGame));
memset(&_debug, 0, sizeof(struct AgiDebug));
memset(&g_mouse, 0, sizeof(struct Mouse));
memset(&_mouse, 0, sizeof(struct Mouse));
_game.clockEnabled = false;
_game.state = STATE_INIT;
@ -542,7 +540,7 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
_allowSynthetic = false;
g_tickTimer = 0;
_tickTimer = 0;
_intobj = NULL;
@ -636,7 +634,7 @@ void AgiEngine::initialize() {
_lastSaveTime = 0;
_timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, NULL);
_timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, this);
debugC(2, kDebugLevelMain, "Detect game");

View file

@ -666,8 +666,6 @@ class SpritesMgr;
class Menu;
class SearchTree;
extern struct Mouse g_mouse;
// Image stack support
struct ImageStackElement {
uint8 type;
@ -719,6 +717,8 @@ public:
AgiGame _game;
Common::RandomSource *_rnd;
Mouse _mouse;
bool _noSaveLoadAllowed;
virtual void pollTimer(void) = 0;
@ -788,6 +788,8 @@ public:
private:
uint32 _tickTimer;
int _keyQueue[KEY_QUEUE_SIZE];
int _keyQueueStart;
int _keyQueueEnd;

View file

@ -201,8 +201,8 @@ int AgiEngine::mainCycle() {
//
// We run AGIMOUSE always as a side effect
if (getFeatures() & GF_AGIMOUSE || 1) {
_game.vars[28] = g_mouse.x / 2;
_game.vars[29] = g_mouse.y;
_game.vars[28] = _mouse.x / 2;
_game.vars[29] = _mouse.y;
}
if (key == KEY_PRIORITY) {
_sprites->eraseBoth();

View file

@ -776,7 +776,7 @@ int GfxMgr::testButton(int x, int y, const char *s) {
x2 = x + CHAR_COLS * len + 2;
y2 = y + CHAR_LINES + 2;
if ((int)g_mouse.x >= x1 && (int)g_mouse.y >= y1 && (int)g_mouse.x <= x2 && (int)g_mouse.y <= y2)
if ((int)_vm->_mouse.x >= x1 && (int)_vm->_mouse.y >= y1 && (int)_vm->_mouse.x < x2 && (int)_vm->_mouse.y <= y2)
return true;
return false;

View file

@ -74,8 +74,8 @@ void AgiEngine::printItem(int n, int fg, int bg) {
int AgiEngine::findItem() {
int r, c;
r = g_mouse.y / CHAR_LINES;
c = g_mouse.x / CHAR_COLS;
r = _mouse.y / CHAR_LINES;
c = _mouse.x / CHAR_COLS;
debugC(6, kDebugLevelInventory, "r = %d, c = %d", r, c);

View file

@ -130,7 +130,7 @@ int AgiEngine::handleController(int key) {
}
if (key == BUTTON_LEFT) {
if ((getflag(fMenusWork) || (getFeatures() & GF_MENUS)) && g_mouse.y <= CHAR_LINES) {
if ((getflag(fMenusWork) || (getFeatures() & GF_MENUS)) && _mouse.y <= CHAR_LINES) {
newInputMode(INPUT_MENU);
return true;
}
@ -138,8 +138,8 @@ int AgiEngine::handleController(int key) {
// Show predictive dialog if the user clicks on input area
if (key == BUTTON_LEFT &&
(int)g_mouse.y >= _game.lineUserInput * CHAR_LINES &&
(int)g_mouse.y <= (_game.lineUserInput + 1) * CHAR_LINES) {
(int)_mouse.y >= _game.lineUserInput * CHAR_LINES &&
(int)_mouse.y <= (_game.lineUserInput + 1) * CHAR_LINES) {
if (predictiveDialog()) {
if (_game.inputMode == INPUT_NONE) {
for (int n = 0; _predictiveResult[n]; n++)
@ -188,8 +188,8 @@ int AgiEngine::handleController(int key) {
// Handle mouse button events
if (key == BUTTON_LEFT) {
v->flags |= ADJ_EGO_XY;
v->parm1 = WIN_TO_PIC_X(g_mouse.x);
v->parm2 = WIN_TO_PIC_Y(g_mouse.y);
v->parm1 = WIN_TO_PIC_X(_mouse.x);
v->parm2 = WIN_TO_PIC_Y(_mouse.y);
return true;
}
}
@ -216,8 +216,8 @@ void AgiEngine::handleGetstring(int key) {
switch (key) {
case BUTTON_LEFT:
if ((int)g_mouse.y >= _stringdata.y * CHAR_LINES &&
(int)g_mouse.y <= (_stringdata.y + 1) * CHAR_LINES) {
if ((int)_mouse.y >= _stringdata.y * CHAR_LINES &&
(int)_mouse.y <= (_stringdata.y + 1) * CHAR_LINES) {
if (predictiveDialog()) {
strcpy(_game.strings[_stringdata.str], _predictiveResult);
newInputMode(INPUT_NORMAL);

View file

@ -132,16 +132,16 @@ void Menu::newMenuSelected(int i) {
}
bool Menu::mouseOverText(int line, int col, char *s) {
if (g_mouse.x < col * CHAR_COLS)
if (_vm->_mouse.x < col * CHAR_COLS)
return false;
if (g_mouse.x > (int)(col + strlen(s)) * CHAR_COLS)
if (_vm->_mouse.x > (int)(col + strlen(s)) * CHAR_COLS)
return false;
if (g_mouse.y < line * CHAR_LINES)
if (_vm->_mouse.y < line * CHAR_LINES)
return false;
if (g_mouse.y >= (line + 1) * CHAR_LINES)
if (_vm->_mouse.y >= (line + 1) * CHAR_LINES)
return false;
return true;
@ -296,12 +296,12 @@ bool Menu::keyhandler(int key) {
//
// Mouse handling
//
if (g_mouse.button) {
if (_vm->_mouse.button) {
int hmenu, vmenu;
buttonUsed = 1; // Button has been used at least once
if (g_mouse.y <= CHAR_LINES) {
if (_vm->_mouse.y <= CHAR_LINES) {
// on the menubar
hmenu = 0;
@ -361,7 +361,7 @@ bool Menu::keyhandler(int key) {
drawMenuOptionHilite(_hCurMenu, _vCurMenu);
if (g_mouse.y <= CHAR_LINES) {
if (_vm->_mouse.y <= CHAR_LINES) {
// on the menubar
} else {
// see which option we selected

View file

@ -1519,9 +1519,9 @@ cmd(print_at_v) {
cmd(push_script) {
// We run AGIMOUSE always as a side effect
if (g_agi->getFeatures() & GF_AGIMOUSE || 1) {
game.vars[27] = g_mouse.button;
game.vars[28] = g_mouse.x / 2;
game.vars[29] = g_mouse.y;
game.vars[27] = g_agi->_mouse.button;
game.vars[28] = g_agi->_mouse.x / 2;
game.vars[29] = g_agi->_mouse.y;
} else {
if (g_agi->getVersion() >= 0x2915) {
report("push.script\n");
@ -1546,8 +1546,8 @@ cmd(set_pri_base) {
}
cmd(mouse_posn) {
_v[p0] = WIN_TO_PIC_X(g_mouse.x);
_v[p1] = WIN_TO_PIC_Y(g_mouse.y);
_v[p0] = WIN_TO_PIC_X(g_agi->_mouse.x);
_v[p1] = WIN_TO_PIC_Y(g_agi->_mouse.y);
}
cmd(shake_screen) {

View file

@ -69,7 +69,7 @@ PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) :
memset(&_game, 0, sizeof(struct AgiGame));
memset(&_debug, 0, sizeof(struct AgiDebug));
memset(&g_mouse, 0, sizeof(struct Mouse));
memset(&_mouse, 0, sizeof(struct Mouse));
}
void PreAgiEngine::initialize() {

View file

@ -689,16 +689,16 @@ int AgiEngine::selectSlot() {
rc = -1;
goto getout;
}
slotClicked = ((int)g_mouse.y - 1) / CHAR_COLS - (vm + 4);
slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4);
xmin = (hm + 1) * CHAR_COLS;
xmax = xmin + CHAR_COLS * 34;
if ((int)g_mouse.x >= xmin && (int)g_mouse.x <= xmax) {
if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) {
if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS)
active = slotClicked;
}
xmin = (hm + 36) * CHAR_COLS;
xmax = xmin + CHAR_COLS;
if ((int)g_mouse.x >= xmin && (int)g_mouse.x <= xmax) {
if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) {
if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) {
if (slotClicked == 0)
keyEnqueue(KEY_UP);

View file

@ -623,8 +623,8 @@ void AgiEngine::writeStatus() {
if (_debug.statusline) {
printStatus("%3d(%03d) %3d,%3d(%3d,%3d) ",
getvar(0), getvar(1), _game.viewTable[0].xPos,
_game.viewTable[0].yPos, WIN_TO_PIC_X(g_mouse.x),
WIN_TO_PIC_Y(g_mouse.y));
_game.viewTable[0].yPos, WIN_TO_PIC_X(_mouse.x),
WIN_TO_PIC_Y(_mouse.y));
return;
}