aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2014-03-29 17:12:12 -0400
committerPaul Gilbert2014-03-29 17:12:12 -0400
commitf3db90b646d4af5b6daf43d11e99d59de0649b03 (patch)
tree07491eed952a9fb2269a697e5b3cbf5fd7fbc0d6 /engines
parent5f3a15022584c3eb7377291a278165a1b1b8dd7b (diff)
downloadscummvm-rg350-f3db90b646d4af5b6daf43d11e99d59de0649b03.tar.gz
scummvm-rg350-f3db90b646d4af5b6daf43d11e99d59de0649b03.tar.bz2
scummvm-rg350-f3db90b646d4af5b6daf43d11e99d59de0649b03.zip
MADS: Refactored pathfinder into it's own class
Diffstat (limited to 'engines')
-rw-r--r--engines/mads/module.mk1
-rw-r--r--engines/mads/player.cpp139
-rw-r--r--engines/mads/player.h17
-rw-r--r--engines/mads/rails.cpp269
-rw-r--r--engines/mads/rails.h128
-rw-r--r--engines/mads/scene.cpp8
-rw-r--r--engines/mads/scene.h3
-rw-r--r--engines/mads/scene_data.cpp92
-rw-r--r--engines/mads/scene_data.h27
9 files changed, 415 insertions, 269 deletions
diff --git a/engines/mads/module.mk b/engines/mads/module.mk
index 54126b1b06..13b4f8589b 100644
--- a/engines/mads/module.mk
+++ b/engines/mads/module.mk
@@ -27,6 +27,7 @@ MODULE_OBJS := \
msurface.o \
palette.o \
player.o \
+ rails.o \
resources.o \
scene.o \
scene_data.o \
diff --git a/engines/mads/player.cpp b/engines/mads/player.cpp
index 1705b117ba..e726c800fd 100644
--- a/engines/mads/player.cpp
+++ b/engines/mads/player.cpp
@@ -78,14 +78,14 @@ Player::Player(MADSEngine *vm): _vm(vm) {
}
void Player::cancelWalk() {
- _action = &_vm->_game->_scene._action;
+ Scene &scene = _vm->_game->_scene;
+ _action = &scene._action;
_targetPos = _playerPos;
_targetFacing = FACING_NONE;
_turnToFacing = _facing;
_moving = false;
_walkOffScreen = _walkOffScreenSceneId = 0;
- _next = 0;
- _routeCount = 0;
+ scene._rails.resetRoute();
_walkAnywhere = false;
_needToWalk = false;
@@ -352,30 +352,12 @@ void Player::startWalking(const Common::Point &pt, Facing facing) {
_moving = true;
_targetFacing = facing;
- scene._sceneInfo->setRouteNode(scene._sceneInfo->_nodes.size() - 2,
- _playerPos, scene._depthSurface);
- scene._sceneInfo->setRouteNode(scene._sceneInfo->_nodes.size() - 1,
- pt, scene._depthSurface);
-
bool v = scene._depthSurface.getDepthHighBit(pt);
- setupRoute(v);
- _next = 0;
-
- if (_routeCount > 0) {
- Common::Point srcPos = _playerPos;
- for (int routeCtr = _routeCount - 1; (routeCtr >= 0) && (_next == 0); --routeCtr) {
- int idx = _routeIndexes[routeCtr];
- const Common::Point &pt =scene._sceneInfo->_nodes[idx]._walkPos;
- _next = scanPath(scene._depthSurface, srcPos, pt);
- srcPos = pt;
- }
- }
+ scene._rails.setupRoute(v, _playerPos, pt);
}
void Player::walk(const Common::Point &pos, Facing facing) {
- Scene &scene = _vm->_game->_scene;
-
cancelWalk();
_needToWalk = true;
_readyToWalk = true;
@@ -402,23 +384,23 @@ void Player::nextFrame() {
void Player::move() {
Scene &scene = _vm->_game->_scene;
+ Rails &rails = scene._rails;
bool newFacing = false;
if (_moving) {
- int idx = _routeCount;
+ bool isRouteEmpty = rails.empty();
while (!_walkOffScreen && _playerPos == _targetPos) {
- if (idx != 0) {
- --idx;
- SceneNode &node = scene._sceneInfo->_nodes[_routeIndexes[idx]];
+ if (!isRouteEmpty) {
+ const WalkNode &node = rails.popNode();
+
_targetPos = node._walkPos;
newFacing = true;
- } else if (_walkOffScreenSceneId == idx) {
+ } else if (!_walkOffScreenSceneId) {
// End of walking path
- _routeCount = 0;
+ rails.resetRoute();
_moving = false;
setFinalFacing();
newFacing = true;
- idx = _routeCount;
} else {
_walkOffScreen = _walkOffScreenSceneId;
_walkAnywhere = true;
@@ -430,7 +412,6 @@ void Player::move() {
if (!_moving)
break;
}
- _routeCount = idx;
}
if (newFacing && _moving)
@@ -579,104 +560,6 @@ void Player::setBaseFrameRate() {
_ticksAmount = 6;
}
-void Player::setupRoute(bool bitFlag) {
- Scene &scene = _vm->_game->_scene;
-
- // Reset the flag set of nodes in use
- SceneNodeList &nodes = scene._sceneInfo->_nodes;
- for (uint i = 0; i < nodes.size(); ++i)
- nodes[i]._active = false;
-
- // Start constructing route node list
- _routeLength = 0x3FFF;
- _routeCount = 0;
-
- setupRouteNode(_tempRoute, nodes.size() - 1, bitFlag ? 0xC000 : 0x8000, 0);
-}
-
-void Player::setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength) {
- Scene &scene = _vm->_game->_scene;
- SceneNodeList &nodes = scene._sceneInfo->_nodes;
- SceneNode &currentNode = nodes[nodeIndex];
- currentNode._active = true;
-
- *routeIndexP++ = nodeIndex;
-
- int subIndex = nodes.size() - 2;
- int indexVal = nodes[nodeIndex]._indexes[subIndex];
- if (indexVal & flags) {
- routeLength += indexVal & 0x3FFF;
- if (routeLength < _routeLength) {
- // Found a new shorter route to destination, so set up the route with the found one
- Common::copy(_tempRoute, routeIndexP, _routeIndexes);
- _routeCount = routeIndexP - _tempRoute;
- _routeLength = indexVal & 0x3FFF;
- }
- } else {
- for (int idx = nodes.size() - 2; idx > 0; --idx) {
- int nodePos = idx - 1;
- if (!nodes[nodePos]._active && ((currentNode._indexes[nodePos] & flags) != 0))
- setupRouteNode(routeIndexP, nodePos, 0x8000, indexVal & 0x3fff);
- }
- }
-
- currentNode._active = false;
-}
-
-int Player::scanPath(MSurface &depthSurface, const Common::Point &srcPos, const Common::Point &destPos) {
- Scene &scene = _vm->_game->_scene;
-
- // For compressed depth surfaces, always return 0
- if (scene._sceneInfo->_depthStyle != 2)
- return 0;
-
- int yDiff = destPos.y - srcPos.y;
- int yAmount = MADS_SCREEN_WIDTH;
-
- if (yDiff < 0) {
- yDiff = -yDiff;
- yAmount = -yAmount;
- }
-
- int xDiff = destPos.x - srcPos.y;
- int xDirection = 1;
- int xAmount = 0;
- if (xDiff < 0) {
- xDiff = -xDiff;
- xDirection = -xDirection;
- xAmount = MIN(yDiff, xDiff);
- }
-
- ++xDiff;
- ++yDiff;
-
- const byte *srcP = depthSurface.getBasePtr(srcPos.x, srcPos.y);
- int index = xAmount;
-
- // Outer horizontal movement loop
- for (int yIndex = 0; yIndex < yDiff; ++yIndex) {
- index += yDiff;
- int v = (*srcP & 0x7F) >> 4;
- if (v)
- return v;
-
- // Inner loop for handling vertical movement
- while (index >= xDiff) {
- index -= xDiff;
-
- v = (*srcP & 0x7F) >> 4;
- if (v)
- return v;
-
- srcP += yAmount;
- }
-
- srcP += xDirection;
- }
-
- return 0;
-}
-
void Player::startMovement() {
int xDiff = _targetPos.x - _playerPos.x;
int yDiff = _targetPos.y - _playerPos.y;
diff --git a/engines/mads/player.h b/engines/mads/player.h
index 7ff14be191..986971bbc1 100644
--- a/engines/mads/player.h
+++ b/engines/mads/player.h
@@ -57,7 +57,6 @@ private:
int _distAccum;
int _pixelAccum;
int _deltaDistance;
- int _routeLength;
int _stopWalkerList[12];
int _stopWalkerTrigger[12];
int _totalDistance;
@@ -89,18 +88,6 @@ private:
*/
void setBaseFrameRate();
- void setupRoute();
-
- void setupRoute(bool bitFlag);
-
- void setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength);
-
- /**
- * Scans along an edge connecting two points within the depths/walk surface, and returns the information of the first
- * pixel high nibble encountered with a non-zero value
- */
- int scanPath(MSurface &depthSurface, const Common::Point &srcPos, const Common::Point &destPos);
-
/**
* Starts a player moving to a given destination
*/
@@ -151,10 +138,6 @@ public:
int _currentDepth;
int _currentScale;
Common::String _spritesPrefix;
- int _routeCount;
- int _routeOffset;
- int _tempRoute[MAX_ROUTE_NODES];
- int _routeIndexes[MAX_ROUTE_NODES];
public:
Player(MADSEngine *vm);
diff --git a/engines/mads/rails.cpp b/engines/mads/rails.cpp
new file mode 100644
index 0000000000..0baaa12793
--- /dev/null
+++ b/engines/mads/rails.cpp
@@ -0,0 +1,269 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+#include "mads/mads.h"
+#include "mads/rails.h"
+
+namespace MADS {
+
+WalkNode::WalkNode() {
+ _active = false;
+ Common::fill(&_distances[0], &_distances[MAX_ROUTE_NODES], 0);
+}
+
+void WalkNode::load(Common::SeekableReadStream *f) {
+ _walkPos.x = f->readSint16LE();
+ _walkPos.y = f->readSint16LE();
+ for (int i = 0; i < MAX_ROUTE_NODES; ++i)
+ _distances[i] = f->readUint16LE();
+}
+
+/*------------------------------------------------------------------------*/
+
+Rails::Rails() {
+ _depthSurface = nullptr;
+ _routeLength = 0;
+}
+
+void Rails::load(const WalkNodeList &nodes, DepthSurface *depthSurface, int depthStyle) {
+ // Store the depth surface and depth style to use
+ _depthSurface = depthSurface;
+ _depthStyle = depthStyle;
+
+ // Load the passed node list
+ _nodes.clear();
+
+ for (uint i = 0; i < nodes.size(); ++i)
+ _nodes.push_back(nodes[i]);
+
+ // Add two more empty nodes for the start and end points of any walk sequence
+ _nodes.push_back(WalkNode());
+ _nodes.push_back(WalkNode());
+}
+
+
+void Rails::setupRoute(bool bitFlag, const Common::Point &srcPos, const Common::Point &destPos) {
+ // Reset the nodes in as being inactive
+ for (uint i = 0; i < _nodes.size(); ++i)
+ _nodes[i]._active = false;
+
+ // Set the two extra walk nodes to the start and destination positions
+ setNodePosition(_nodes.size() - 2, srcPos);
+ setNodePosition(_nodes.size() - 1, destPos);
+
+ // Start constructing route node list
+ _routeLength = 0x3FFF;
+ _routeIndexes.clear();
+
+ // Recursively form a route from the destination walk node back to the player's position
+ setupRouteNode(&_tempRoute[0], _nodes.size() - 1, bitFlag ? 0xC000 : 0x8000, 0);
+
+ _next = 0;
+ if (_routeIndexes.size() > 0) {
+ Common::Point currPos = srcPos;
+ for (int routeCtr = size() - 1; (routeCtr >= 0) && (_next == 0); --routeCtr) {
+ int idx = _routeIndexes[routeCtr];
+ const Common::Point &pt = _nodes[idx]._walkPos;
+
+ _next = scanPath(currPos, pt);
+ currPos = pt;
+ }
+ }
+}
+
+void Rails::setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength) {
+ WalkNode &currentNode = _nodes[nodeIndex];
+ currentNode._active = true;
+
+ *routeIndexP++ = nodeIndex;
+
+ // Get the index of the ultimate source position (the player)
+ int subIndex = _nodes.size() - 2;
+
+ int distanceVal = _nodes[nodeIndex]._distances[subIndex];
+ if (distanceVal & flags) {
+ routeLength += distanceVal & 0x3FFF;
+ if (routeLength < _routeLength) {
+ // Found a new shorter route to destination, so set up the route with the found one
+ _routeIndexes.clear();
+ for (int i = 0; routeIndexP != &_tempRoute[i]; ++i)
+ _routeIndexes.push(_tempRoute[i]);
+ _routeLength = routeLength;
+ }
+ } else {
+ for (int idx = _nodes.size() - 2; idx > 0; --idx) {
+ int nodePos = idx - 1;
+ if (!_nodes[nodePos]._active && ((currentNode._distances[nodePos] & flags) != 0))
+ setupRouteNode(routeIndexP, nodePos, 0x8000, distanceVal & 0x3fff);
+ }
+ }
+
+ currentNode._active = false;
+}
+
+
+int Rails::scanPath(const Common::Point &srcPos, const Common::Point &destPos) {
+ // For compressed depth surfaces, always return 0
+ if (_depthStyle != 2)
+ return 0;
+
+ int yDiff = destPos.y - srcPos.y;
+ int yAmount = MADS_SCREEN_WIDTH;
+
+ if (yDiff < 0) {
+ yDiff = -yDiff;
+ yAmount = -yAmount;
+ }
+
+ int xDiff = destPos.x - srcPos.y;
+ int xDirection = 1;
+ int xAmount = 0;
+ if (xDiff < 0) {
+ xDiff = -xDiff;
+ xDirection = -xDirection;
+ xAmount = MIN(yDiff, xDiff);
+ }
+
+ ++xDiff;
+ ++yDiff;
+
+ const byte *srcP = _depthSurface->getBasePtr(srcPos.x, srcPos.y);
+ int index = xAmount;
+
+ // Outer horizontal movement loop
+ for (int yIndex = 0; yIndex < yDiff; ++yIndex) {
+ index += yDiff;
+ int v = (*srcP & 0x7F) >> 4;
+ if (v)
+ return v;
+
+ // Inner loop for handling vertical movement
+ while (index >= xDiff) {
+ index -= xDiff;
+
+ v = (*srcP & 0x7F) >> 4;
+ if (v)
+ return v;
+
+ srcP += yAmount;
+ }
+
+ srcP += xDirection;
+ }
+
+ return 0;
+}
+
+void Rails::resetRoute() {
+ _routeIndexes.clear();
+ _next = 0;
+}
+
+const WalkNode &Rails::popNode() {
+ assert(!_routeIndexes.empty());
+
+ return _nodes[_routeIndexes.pop()];
+}
+
+void Rails::setNodePosition(int nodeIndex, const Common::Point &pt) {
+ int flags, hypotenuse;
+
+ _nodes[nodeIndex]._walkPos = pt;
+
+ // Recalculate inter-node lengths
+ for (uint idx = 0; idx < _nodes.size(); ++idx) {
+ int entry;
+ if (idx == (uint)nodeIndex) {
+ entry = 0x3FFF;
+ }
+ else {
+ // Process the node
+ flags = getRouteFlags(pt, _nodes[idx]._walkPos);
+
+ int xDiff = ABS(_nodes[idx]._walkPos.x - pt.x);
+ int yDiff = ABS(_nodes[idx]._walkPos.y - pt.y);
+ hypotenuse = sqrt((double)(xDiff * xDiff + yDiff * yDiff));
+
+ if (hypotenuse >= 0x3FFF)
+ // Shouldn't ever be this large
+ hypotenuse = 0x3FFF;
+
+ entry = hypotenuse | flags;
+ _nodes[idx]._distances[nodeIndex] = entry;
+ _nodes[nodeIndex]._distances[idx] = entry;
+ }
+ }
+}
+
+int Rails::getRouteFlags(const Common::Point &src, const Common::Point &dest) {
+ int result = 0x8000;
+ bool flag = false;
+
+ int xDiff = ABS(dest.x - src.x);
+ int yDiff = ABS(dest.y - src.y);
+ int xDirection = dest.x >= src.x ? 1 : -1;
+ int yDirection = dest.y >= src.y ? _depthSurface->w : -_depthSurface->w;
+ int majorDiff = 0;
+ if (dest.x < src.x)
+ majorDiff = MAX(xDiff, yDiff);
+ ++xDiff;
+ ++yDiff;
+
+ byte *srcP = _depthSurface->getBasePtr(src.x, src.y);
+
+ int totalCtr = majorDiff;
+ for (int xCtr = 0; xCtr < xDiff; ++xCtr, srcP += xDirection) {
+ totalCtr += yDiff;
+
+ if ((*srcP & 0x80) == 0)
+ flag = false;
+ else if (!flag) {
+ flag = true;
+ result -= 0x4000;
+ if (result == 0)
+ break;
+ }
+
+ while (totalCtr >= xDiff) {
+ totalCtr -= xDiff;
+
+ if ((*srcP & 0x80) == 0)
+ flag = false;
+ else if (!flag) {
+ flag = true;
+ result -= 0x4000;
+ if (result == 0)
+ break;
+ }
+
+ srcP += yDirection;
+ }
+ if (result == 0)
+ break;
+ }
+
+ return result;
+}
+
+
+} // End of namespace MADS
diff --git a/engines/mads/rails.h b/engines/mads/rails.h
new file mode 100644
index 0000000000..026eddae1f
--- /dev/null
+++ b/engines/mads/rails.h
@@ -0,0 +1,128 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef MADS_RAILS_H
+#define MADS_RAILS_H
+
+#include "common/scummsys.h"
+#include "common/array.h"
+#include "common/rect.h"
+#include "common/stack.h"
+#include "mads/msurface.h"
+
+namespace MADS {
+
+class WalkNode {
+public:
+ Common::Point _walkPos;
+ int _distances[MAX_ROUTE_NODES];
+ bool _active;
+
+ /**
+ * Constructor
+ */
+ WalkNode();
+
+ /**
+ * Loads the scene node
+ */
+ void load(Common::SeekableReadStream *f);
+};
+typedef Common::Array<WalkNode> WalkNodeList;
+
+/**
+ * This class handles storing the intermediate walk node points for a
+ * given scene, and calculating walking routes between any two positions.
+ */
+class Rails {
+private:
+ WalkNodeList _nodes;
+ DepthSurface *_depthSurface;
+ int _depthStyle;
+ int _routeLength;
+ int _next;
+ int _routeOffset;
+ int _tempRoute[MAX_ROUTE_NODES];
+ Common::Stack<int> _routeIndexes;
+private:
+ /**
+ * Change the position of a walking node. Doing so causes a recalculation of the
+ * distance between it and every other node, and vice versa
+ */
+ void setNodePosition(int nodeIndex, const Common::Point &pt);
+
+ int getRouteFlags(const Common::Point &src, const Common::Point &dest);
+public:
+ /**
+ * Constructor
+ */
+ Rails();
+
+ /**
+ * Loads the scene data for the list of intermediate walk nodes and the
+ * depth surface to use.
+ * @param nodes Intermediate walk-points
+ * @param depthSurface Depth surface to use
+ */
+ void load(const WalkNodeList &nodes, DepthSurface *depthSurface, int depthStyle);
+
+ /**
+ * Set up a route between two points in a scene
+ */
+ void setupRoute(bool bitFlag, const Common::Point &srcPos, const Common::Point &destPos);
+
+ void setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength);
+
+ /**
+ * Resets any currently running route
+ */
+ void resetRoute();
+
+ /**
+ * Scans along an edge connecting two points within the depths/walk surface, and returns the information of the first
+ * pixel high nibble encountered with a non-zero value
+ */
+ int scanPath(const Common::Point &srcPos, const Common::Point &destPos);
+
+ /*
+ * Return the number of walk nodes in the calculated route
+ */
+ int size() const { return _routeIndexes.size(); }
+
+ /**
+ * Returns true if the current calculated walk route is empty
+ */
+ bool empty() const { return _routeIndexes.empty(); }
+
+ /**
+ * Returns the data for a given walk node
+ */
+ const WalkNode &operator[](int idx) { return _nodes[_routeIndexes[idx]]; }
+
+ const WalkNode &popNode();
+
+ void resetNext() { _next = 0; }
+};
+
+} // End of namespace MADS
+
+#endif /* MADS_RAILS_H */
diff --git a/engines/mads/scene.cpp b/engines/mads/scene.cpp
index b8b8888e53..83c059444d 100644
--- a/engines/mads/scene.cpp
+++ b/engines/mads/scene.cpp
@@ -132,13 +132,7 @@ void Scene::loadScene(int sceneId, const Common::String &prefix, bool palFlag) {
initPaletteAnimation(_sceneInfo->_palAnimData, false);
// Copy over nodes
- _nodes.clear();
- for (uint i = 0; i < _sceneInfo->_nodes.size(); ++i)
- _nodes.push_back(_sceneInfo->_nodes[i]);
-
- // Add two more empty nodes for the start and end points of any walk sequence
- _nodes.push_back(SceneNode());
- _nodes.push_back(SceneNode());
+ _rails.load(_sceneInfo->_nodes, &_depthSurface, _sceneInfo->_depthStyle);
// Load hotspots
loadHotspots();
diff --git a/engines/mads/scene.h b/engines/mads/scene.h
index 7b5d791d12..1caba12851 100644
--- a/engines/mads/scene.h
+++ b/engines/mads/scene.h
@@ -33,6 +33,7 @@
#include "mads/msurface.h"
#include "mads/scene_data.h"
#include "mads/animation.h"
+#include "mads/rails.h"
#include "mads/sequence.h"
#include "mads/sprites.h"
#include "mads/user_interface.h"
@@ -92,6 +93,7 @@ public:
Common::Array<int> _activeVocabs;
SequenceList _sequences;
KernelMessages _kernelMessages;
+ Rails _rails;
Common::String _talkFont;
int _textSpacing;
Hotspots _hotspots;
@@ -106,7 +108,6 @@ public:
int _animCount;
Common::Array<uint32> _animTicksList;
Common::Array<RGB4> _animPalData;
- SceneNodeList _nodes;
Common::StringArray _vocabStrings;
Animation *_animationData;
Animation *_activeAnimation;
diff --git a/engines/mads/scene_data.cpp b/engines/mads/scene_data.cpp
index 5b5c47f402..abe0b7bf21 100644
--- a/engines/mads/scene_data.cpp
+++ b/engines/mads/scene_data.cpp
@@ -30,15 +30,6 @@
namespace MADS {
-void SceneNode::load(Common::SeekableReadStream *f) {
- _walkPos.x = f->readSint16LE();
- _walkPos.y = f->readSint16LE();
- for (int i = 0; i < MAX_ROUTE_NODES; ++i)
- _indexes[i] = f->readUint16LE();
-}
-
-/*------------------------------------------------------------------------*/
-
KernelMessage::KernelMessage() {
_flags = 0;
_sequenceIndex = 0;
@@ -97,87 +88,6 @@ void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) {
_scale = f->readByte();
}
-void SceneInfo::setRouteNode(int nodeIndex, const Common::Point &pt, MSurface &depthSurface) {
- int flags, hypotenuse;
-
- _nodes[nodeIndex]._walkPos = pt;
-
- // Recalculate inter-node lengths
- for (uint idx = 0; idx < _nodes.size(); ++idx) {
- int entry;
- if (idx == (uint)nodeIndex) {
- entry = 0x3FFF;
- }
- else {
- // Process the node
- flags = getRouteFlags(pt, _nodes[idx]._walkPos, depthSurface);
-
- int xDiff = ABS(_nodes[idx]._walkPos.x - pt.x);
- int yDiff = ABS(_nodes[idx]._walkPos.y - pt.y);
- hypotenuse = sqrt((double)(xDiff * xDiff + yDiff * yDiff));
-
- if (hypotenuse >= 0x3FFF)
- // Shouldn't ever be this large
- hypotenuse = 0x3FFF;
-
- entry = hypotenuse | flags;
- _nodes[idx]._indexes[nodeIndex] = entry;
- _nodes[nodeIndex]._indexes[idx] = entry;
- }
- }
-}
-
-int SceneInfo::getRouteFlags(const Common::Point &src, const Common::Point &dest,
- MSurface &depthSurface) {
- int result = 0x8000;
- bool flag = false;
-
- int xDiff = ABS(dest.x - src.x);
- int yDiff = ABS(dest.y - src.y);
- int xDirection = dest.x >= src.x ? 1 : -1;
- int yDirection = dest.y >= src.y ? depthSurface.w : -depthSurface.w;
- int majorDiff = 0;
- if (dest.x < src.x)
- majorDiff = MAX(xDiff, yDiff);
- ++xDiff;
- ++yDiff;
-
- byte *srcP = depthSurface.getBasePtr(src.x, src.y);
-
- int totalCtr = majorDiff;
- for (int xCtr = 0; xCtr < xDiff; ++xCtr, srcP += xDirection) {
- totalCtr += yDiff;
-
- if ((*srcP & 0x80) == 0)
- flag = false;
- else if (!flag) {
- flag = true;
- result -= 0x4000;
- if (result == 0)
- break;
- }
-
- while (totalCtr >= xDiff) {
- totalCtr -= xDiff;
-
- if ((*srcP & 0x80) == 0)
- flag = false;
- else if (!flag) {
- flag = true;
- result -= 0x4000;
- if (result == 0)
- break;
- }
-
- srcP += yDirection;
- }
- if (result == 0)
- break;
- }
-
- return result;
-}
-
/*------------------------------------------------------------------------*/
SceneInfo *SceneInfo::init(MADSEngine *vm) {
@@ -225,7 +135,7 @@ void SceneInfo::load(int sceneId, int v1, const Common::String &resName,
// Load the set of objects that are associated with the scene
for (int i = 0; i < 20; ++i) {
- SceneNode node;
+ WalkNode node;
node.load(infoStream);
if (i < nodeCount)
diff --git a/engines/mads/scene_data.h b/engines/mads/scene_data.h
index d7c008b66d..33c053f8ec 100644
--- a/engines/mads/scene_data.h
+++ b/engines/mads/scene_data.h
@@ -34,6 +34,7 @@
#include "mads/game_data.h"
#include "mads/hotspots.h"
#include "mads/messages.h"
+#include "mads/rails.h"
#include "mads/user_interface.h"
namespace MADS {
@@ -116,25 +117,6 @@ struct ARTHeader {
void load(Common::SeekableReadStream *f);
};
-class SceneNode {
-public:
- Common::Point _walkPos;
- int _indexes[MAX_ROUTE_NODES];
- bool _active;
-
- /**
- * Constructor
- */
- SceneNode() : _active(false) {}
-
- /**
- * Loads the scene node
- */
- void load(Common::SeekableReadStream *f);
-};
-typedef Common::Array<SceneNode> SceneNodeList;
-
-
/**
* Handles general data for a given scene
*/
@@ -179,7 +161,7 @@ public:
int _usageIndex;
Common::Array<RGB4> _palAnimData;
- SceneNodeList _nodes;
+ WalkNodeList _nodes;
public:
/**
* Destructor
@@ -198,11 +180,6 @@ public:
MSurface &depthSurface, MSurface &bgSurface);
/**
- * Set up a route node
- */
- void setRouteNode(int nodeIndex, const Common::Point &pt, MSurface &depthSurface);
-
- /**
* Loads the given surface with depth information of a given scene
*/
virtual void loadCodes(MSurface &depthSurface, Common::SeekableReadStream *stream) = 0;