From baffdd97e22851ad050bbeb1e800e38606b8f4c1 Mon Sep 17 00:00:00 2001 From: uruk Date: Sun, 15 Jun 2014 21:11:27 +0200 Subject: CGE2: Fix coordinates of mouse handling. Now infoLine is working properly. Rework solidAt() to achieve that. Also move spriteAt from talk.cpp to cge2_main.cpp, and remove the older version which didn't use V2D as a parameter. --- engines/cge2/bitmap.cpp | 11 +++++++---- engines/cge2/bitmap.h | 2 +- engines/cge2/cge2.h | 1 - engines/cge2/cge2_main.cpp | 23 ++++++++++++----------- engines/cge2/events.cpp | 2 +- engines/cge2/talk.cpp | 14 -------------- 6 files changed, 21 insertions(+), 32 deletions(-) (limited to 'engines/cge2') diff --git a/engines/cge2/bitmap.cpp b/engines/cge2/bitmap.cpp index 7a7a88430c..c62a784110 100644 --- a/engines/cge2/bitmap.cpp +++ b/engines/cge2/bitmap.cpp @@ -274,13 +274,16 @@ BitmapPtr Bitmap::code(uint8 *map) { return this; } -bool Bitmap::solidAt(int16 x, int16 y) { - if ((x >= _w) || (y >= _h)) +bool Bitmap::solidAt(V2D pos) { + pos.x += _w >> 1; + pos.y = _h - pos.y; + + if (!pos.limited(V2D(_vm, _w, _h))) return false; uint8 *m = _v; - uint16 r = static_cast(x) % 4; - uint16 n0 = (kScrWidth * y + x) / 4; + uint16 r = static_cast(pos.x) % 4; + uint16 n0 = (kScrWidth * pos.y + pos.x) / 4; uint16 n = 0; while (r) { diff --git a/engines/cge2/bitmap.h b/engines/cge2/bitmap.h index 8bff8fe99c..2c7b31b110 100644 --- a/engines/cge2/bitmap.h +++ b/engines/cge2/bitmap.h @@ -83,7 +83,7 @@ public: void release(); void hide(int16 x, int16 y); void show(int16 x, int16 y); - bool solidAt(int16 x, int16 y); + bool solidAt(V2D pos); void xLatPos(V2D& p); bool moveHi(); bool moveLo(); diff --git a/engines/cge2/cge2.h b/engines/cge2/cge2.h index 611976819b..0206a3ce6d 100644 --- a/engines/cge2/cge2.h +++ b/engines/cge2/cge2.h @@ -123,7 +123,6 @@ public: void mainLoop(); void handleFrame(); Sprite *locate(int ref); - Sprite *spriteAt(int x, int y); bool isHero(Sprite *spr); void loadUser(); void checkSaySwitch(); diff --git a/engines/cge2/cge2_main.cpp b/engines/cge2/cge2_main.cpp index 802b72ed4d..198f4a359e 100644 --- a/engines/cge2/cge2_main.cpp +++ b/engines/cge2/cge2_main.cpp @@ -868,17 +868,6 @@ void CGE2Engine::switchHero(int sex) { _commandHandler->addCommand(kCmdSeq, -1, 1, face); } -Sprite *CGE2Engine::spriteAt(int x, int y) { - Sprite *spr = NULL, *queueTail = _vga->_showQ->last(); - if (queueTail) { - for (spr = queueTail->_prev; spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran && spr->getShp()->solidAt(x - spr->_pos2D.x, y - spr->_pos2D.y)) - break; - } - } - return spr; -} - #pragma argsused void Sprite::touch(uint16 mask, int x, int y, Common::KeyCode keyCode) { if ((mask & kEventAttn) != 0) @@ -961,5 +950,17 @@ void CGE2Engine::offUse() { warning("STUB: CGE2Engine::offUse()"); } +Sprite *CGE2Engine::spriteAt(V2D pos) { + Sprite *spr; + + for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { + if (!spr->_flags._hide && !spr->_flags._tran) { + if (spr->getShp()->solidAt(pos - spr->_pos2D)) + break; + } + } + + return spr; +} } // End of namespace CGE2 diff --git a/engines/cge2/events.cpp b/engines/cge2/events.cpp index 79455aff66..c3433dfb87 100644 --- a/engines/cge2/events.cpp +++ b/engines/cge2/events.cpp @@ -117,7 +117,7 @@ void Mouse::newMouse(Common::Event &event) { evt._x = event.mouse.x; evt._y = event.mouse.y; evt._keyCode = Common::KEYCODE_INVALID; - evt._spritePtr = _vm->spriteAt(evt._x, evt._y); + evt._spritePtr = _vm->spriteAt(V2D(_vm, evt._x, evt._y)); switch (event.type) { case Common::EVENT_MOUSEMOVE: diff --git a/engines/cge2/talk.cpp b/engines/cge2/talk.cpp index 54e9ea3764..a6d9945665 100644 --- a/engines/cge2/talk.cpp +++ b/engines/cge2/talk.cpp @@ -34,20 +34,6 @@ void CGE2Engine::setAutoColors() { warning("STUB: CGE2Engine::setAutoColors()"); } -Sprite *CGE2Engine::spriteAt(V2D pos) { - Sprite *spr; - - for (spr = _vga->_showQ->last(); spr; spr = spr->_prev) { - if (!spr->_flags._hide && !spr->_flags._tran) { - V2D temp = pos - spr->_pos2D; - if (spr->getShp()->solidAt(temp.x, temp.y)) - break; - } - } - - return spr; -} - Font::Font(CGE2Engine *vm) : _vm(vm) { _map = new uint8[kMapSize]; _pos = new uint16[kPosSize]; -- cgit v1.2.3