diff options
-rw-r--r-- | engines/neverhood/mouse.cpp | 111 | ||||
-rw-r--r-- | engines/neverhood/neverhood.cpp | 13 | ||||
-rw-r--r-- | engines/neverhood/resource.h | 2 | ||||
-rw-r--r-- | engines/neverhood/scene.cpp | 6 | ||||
-rw-r--r-- | engines/neverhood/screen.cpp | 7 | ||||
-rw-r--r-- | engines/neverhood/screen.h | 2 |
6 files changed, 71 insertions, 70 deletions
diff --git a/engines/neverhood/mouse.cpp b/engines/neverhood/mouse.cpp index 03b1478c55..a1c4a9a5a8 100644 --- a/engines/neverhood/mouse.cpp +++ b/engines/neverhood/mouse.cpp @@ -21,11 +21,10 @@ */ #include "neverhood/mouse.h" +#include "graphics/cursorman.h" namespace Neverhood { -// TODO: Use CursorMan - Mouse::Mouse(NeverhoodEngine *vm, uint32 fileHash, const NRect &mouseRect) : StaticSprite(vm, 2000), _mouseType(kMouseType433), _mouseCursorResource(vm), _frameNum(0) { @@ -95,64 +94,59 @@ void Mouse::update() { uint32 Mouse::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { debug(7, "Mouse::handleMessage(%04X)", messageNum); - uint32 messageResult = 0; - if (messageNum != 5) { - messageResult = Sprite::handleMessage(messageNum, param, sender); - switch (messageNum) { - case 0x2064: - _x = param.asPoint().x; - _y = param.asPoint().y; - switch (_type) { - case 1: - if (_x >= 320) - messageResult = 1; - else - messageResult = 0; - break; - case 2: - default: - if (_x < 100) - messageResult = 0; - else if (_x > 540) - messageResult = 1; - else - messageResult = 2; - break; - case 3: - if (_x < 100) - messageResult = 0; - else if (_x > 540) - messageResult = 1; - else - messageResult = 4; - break; - case 4: - if (_x < 100) - messageResult = 0; - else if (_x > 540) - messageResult = 1; - else if (_y >= 150) - messageResult = 2; - else - messageResult = 3; - break; - case 5: - if (_y >= 240) - messageResult = 4; - else - messageResult = 3; - break; - } + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x2064: + _x = param.asPoint().x; + _y = param.asPoint().y; + switch (_type) { + case 1: + if (_x >= 320) + messageResult = 1; + else + messageResult = 0; + break; + case 2: + default: + if (_x < 100) + messageResult = 0; + else if (_x > 540) + messageResult = 1; + else + messageResult = 2; + break; + case 3: + if (_x < 100) + messageResult = 0; + else if (_x > 540) + messageResult = 1; + else + messageResult = 4; + break; + case 4: + if (_x < 100) + messageResult = 0; + else if (_x > 540) + messageResult = 1; + else if (_y >= 150) + messageResult = 2; + else + messageResult = 3; break; - case 0x4002: - _x = param.asPoint().x; - _y = param.asPoint().y; - updateCursorNum(); - processDelta(); + case 5: + if (_y >= 240) + messageResult = 4; + else + messageResult = 3; break; } - } else { - // TODO: Debug stuff + break; + case 0x4002: + _x = param.asPoint().x; + _y = param.asPoint().y; + updateCursorNum(); + processDelta(); + break; } return messageResult; } @@ -178,6 +172,9 @@ void Mouse::updateCursor() { _needRefresh = false; _drawRect = _mouseCursorResource.getRect(); _surface->drawMouseCursorResource(_mouseCursorResource, _frameNum / 2); + Graphics::Surface *cursorSurface = _surface->getSurface(); + CursorMan.replaceCursor((const byte*)cursorSurface->pixels, + cursorSurface->w, cursorSurface->h, -_drawRect.x, -_drawRect.y, 0); } } diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index 72fa3601ed..5152def96a 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -106,6 +106,8 @@ Common::Error NeverhoodEngine::run() { _gameModule = new GameModule(this); _gameModule->startup(); + + uint32 nextFrameTime = 0; // Preliminary main loop, needs some more work but works for testing while (!shouldQuit()) { @@ -148,13 +150,16 @@ Common::Error NeverhoodEngine::run() { } } - //debug("millis %d", _system->getMillis()); - _gameModule->handleUpdate(); - _gameModule->draw(); + if (_system->getMillis() >= nextFrameTime) { + _gameModule->handleUpdate(); + _gameModule->draw(); + nextFrameTime = _screen->getNextFrameTime(); + }; + _soundMan->update(); _audioResourceMan->update(); - _screen->wait(); _screen->update(); + _system->delayMillis(10); debug(0, "---------------------------------------"); diff --git a/engines/neverhood/resource.h b/engines/neverhood/resource.h index 16782968f8..b49ee883b7 100644 --- a/engines/neverhood/resource.h +++ b/engines/neverhood/resource.h @@ -114,7 +114,7 @@ public: NDrawRect& getRect(); void draw(int frameNum, byte *dest, int destPitch); int getCursorNum() const { return _cursorNum; } - void setCursorNum(int value) { _cursorNum = value; } + void setCursorNum(int cursorNum) { _cursorNum = cursorNum; } protected: int _cursorNum; SpriteResource _cursorSprite; diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp index 318a0df10a..bec399af3d 100644 --- a/engines/neverhood/scene.cpp +++ b/engines/neverhood/scene.cpp @@ -209,17 +209,17 @@ void Scene::insertMouse433(uint32 fileHash, NRect *mouseRect) { if (mouseRect) rect = *mouseRect; _mouseCursor = new Mouse(_vm, 0x0820C408, rect); - addSprite(_mouseCursor); + addEntity(_mouseCursor); } void Scene::insertMouse435(uint32 fileHash, int16 x1, int16 x2) { _mouseCursor = new Mouse(_vm, fileHash, x1, x2); - addSprite(_mouseCursor); + addEntity(_mouseCursor); } void Scene::insertNavigationMouse(uint32 fileHash, int type) { _mouseCursor = new Mouse(_vm, fileHash, type); - addSprite(_mouseCursor); + addEntity(_mouseCursor); } void Scene::showMouse(bool visible) { diff --git a/engines/neverhood/screen.cpp b/engines/neverhood/screen.cpp index 4689d3ba2d..f9e8d49743 100644 --- a/engines/neverhood/screen.cpp +++ b/engines/neverhood/screen.cpp @@ -41,20 +41,19 @@ Screen::~Screen() { } void Screen::update() { + _ticks = _vm->_system->getMillis(); updatePalette(); // TODO: Implement actual code _vm->_system->copyRectToScreen((const byte*)_backScreen->pixels, _backScreen->pitch, 0, 0, 640, 480); _vm->_system->updateScreen(); } -void Screen::wait() { +uint32 Screen::getNextFrameTime() { int32 frameDelay = _frameDelay; if (_smackerDecoder && _smackerDecoder->isVideoLoaded() && !_smackerDecoder->endOfVideo()) frameDelay = _smackerDecoder->getTimeToNextFrame(); int32 waitTicks = frameDelay - (_vm->_system->getMillis() - _ticks); - if (waitTicks > 0) - _vm->_system->delayMillis(waitTicks); - _ticks = _vm->_system->getMillis(); + return _vm->_system->getMillis() + waitTicks; } void Screen::setFps(int fps) { diff --git a/engines/neverhood/screen.h b/engines/neverhood/screen.h index 56a256757c..e3a2bfbef7 100644 --- a/engines/neverhood/screen.h +++ b/engines/neverhood/screen.h @@ -35,7 +35,7 @@ public: Screen(NeverhoodEngine *vm); ~Screen(); void update(); - void wait(); + uint32 getNextFrameTime(); void setFps(int fps); int getFps(); void setPaletteData(byte *paletteData); |