From 9ad5e7461fed883710a0937a919cbee911a6e0a8 Mon Sep 17 00:00:00 2001 From: Robert Špalek Date: Tue, 3 Nov 2009 21:05:26 +0000 Subject: Let setPath() store path with pixel precision, and update the map sprite when reloaded svn-id: r45640 --- engines/draci/game.cpp | 19 ++++++++++++------- engines/draci/walking.cpp | 23 +++++++++++++++++++++++ engines/draci/walking.h | 3 ++- 3 files changed, 37 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 3aad401ca2..cec92bc275 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -980,7 +980,7 @@ void Game::walkHero(int x, int y, SightDirection dir) { redrawWalkingPath(kWalkingObliquePathOverlay, kWalkingObliquePathOverlayColour, obliquePath); } - _walkingState.setPath(obliquePath); + _walkingState.setPath(_hero, target, _walkingMap.getDelta(), obliquePath); // FIXME: Need to add proper walking (this only warps the dragon to position) _hero = target; @@ -1097,22 +1097,21 @@ void Game::loadRoom(int roomNum) { _currentRoom._gates.push_back(roomReader.readSint16LE()); } - // Load the walking map - loadWalkingMap(getMapID()); - // Add overlays for the walking map and shortest/obliqued paths. Animation *map = _vm->_anims->addAnimation(kWalkingMapOverlay, 256, _vm->_showWalkingMap); - Sprite *ov = _walkingMap.newOverlayFromMap(kWalkingMapOverlayColour); - map->addFrame(ov, NULL); + map->addFrame(NULL, NULL); // rewritten below by loadWalkingMap() Animation *sPath = _vm->_anims->addAnimation(kWalkingShortestPathOverlay, 257, _vm->_showWalkingMap); Animation *oPath = _vm->_anims->addAnimation(kWalkingObliquePathOverlay, 258, _vm->_showWalkingMap); WalkingPath emptyPath; - ov = _walkingMap.newOverlayFromPath(emptyPath, 0); + Sprite *ov = _walkingMap.newOverlayFromPath(emptyPath, 0); sPath->addFrame(ov, NULL); ov = _walkingMap.newOverlayFromPath(emptyPath, 0); oPath->addFrame(ov, NULL); + // Load the walking map + loadWalkingMap(getMapID()); + // Load the room's objects for (uint i = 0; i < _info._numObjects; ++i) { debugC(7, kDraciLogicDebugLevel, @@ -1254,6 +1253,12 @@ void Game::loadWalkingMap(int mapID) { const BAFile *f; f = _vm->_walkingMapsArchive->getFile(mapID); _walkingMap.load(f->_data, f->_length); + + Animation *anim = _vm->_anims->getAnimation(kWalkingMapOverlay); + Sprite *ov = _walkingMap.newOverlayFromMap(kWalkingMapOverlayColour); + delete anim->getFrame(0); + anim->replaceFrame(0, ov, NULL); + anim->markDirtyRect(_vm->_screen->getSurface()); } void Game::loadOverlays() { diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp index 372901e5f7..87cd1b3284 100644 --- a/engines/draci/walking.cpp +++ b/engines/draci/walking.cpp @@ -420,4 +420,27 @@ bool WalkingMap::managedToOblique(WalkingPath *path) const { return improved; } +void WalkingState::setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &delta, const WalkingPath& path) { + _path = path; + if (!_path.size()) { + return; + } + if (_path.size() == 1 && p2 != p1) { + // Although the first and last point belong to the same + // rectangle and therefore the computed path is of length 1, + // they are different pixels. + _path.push_back(p2); + } + + // The first and last point are available with pixel accurracy. + _path[0] = p1; + _path[_path.size() - 1] = p2; + // The intermediate points are given with map granularity; convert them + // to pixels. + for (uint i = 1; i < _path.size() - 1; ++i) { + _path[i].x *= delta.x; + _path[i].y *= delta.y; + } +} + } diff --git a/engines/draci/walking.h b/engines/draci/walking.h index 247f57b4c9..104e9ed955 100644 --- a/engines/draci/walking.h +++ b/engines/draci/walking.h @@ -51,6 +51,7 @@ public: bool findShortestPath(Common::Point p1, Common::Point p2, WalkingPath *path) const; void obliquePath(const WalkingPath& path, WalkingPath *obliquedPath); Sprite *newOverlayFromPath(const WalkingPath &path, byte colour) const; + Common::Point getDelta() const { return Common::Point(_deltaX, _deltaY); } private: int _realWidth, _realHeight; @@ -98,7 +99,7 @@ public: WalkingState() : _path() {} ~WalkingState() {} - void setPath(const WalkingPath& path) { _path = path; } + void setPath(const Common::Point &p1, const Common::Point &p2, const Common::Point &delta, const WalkingPath& path); const WalkingPath& getPath() const { return _path; } private: -- cgit v1.2.3