From 3e08d36363c1f761807ad012de4dd3f6aa3589b0 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Fri, 25 Jul 2008 16:01:25 +0000 Subject: * Changed walk code to use Common::Point instead of the clumsy WalkNode. * Changed walk code to use object copy instead of managing pointers. svn-id: r33289 --- engines/parallaction/parallaction.h | 5 ++-- engines/parallaction/parser.h | 2 +- engines/parallaction/parser_ns.cpp | 12 ++------ engines/parallaction/walk.cpp | 58 +++++++++++++------------------------ engines/parallaction/walk.h | 23 ++++----------- 5 files changed, 31 insertions(+), 69 deletions(-) (limited to 'engines') diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 523ec06a61..5bbd6ea8c7 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -177,7 +177,7 @@ struct Location { char _soundFile[50]; // NS specific - WalkNodeList _walkNodes; + PointList _walkNodes; char _slideText[2][MAX_TOKEN_LEN]; // BRA specific @@ -199,7 +199,7 @@ struct Character { GfxObj *_talk; GfxObj *_objs; PathBuilder _builder; - WalkNodeList *_walkPath; + PointList *_walkPath; Character(Parallaction *vm); void getFoot(Common::Point &foot); @@ -259,7 +259,6 @@ public: void resumeJobs(); void finalizeWalk(Character &character); - int16 selectWalkFrame(Character &character, const Common::Point& pos, const WalkNodePtr to); void clipMove(Common::Point& pos, const Common::Point& to); ZonePtr findZone(const char *name); diff --git a/engines/parallaction/parser.h b/engines/parallaction/parser.h index 1541fb89b2..a31be2ccb0 100644 --- a/engines/parallaction/parser.h +++ b/engines/parallaction/parser.h @@ -193,7 +193,7 @@ protected: void parseZone(ZoneList &list, char *name); void parseZoneTypeBlock(ZonePtr z); - void parseWalkNodes(WalkNodeList &list); + void parseWalkNodes(PointList &list); void parseAnimation(AnimationList &list, char *name); void parseCommands(CommandList&); void parseCommandFlags(); diff --git a/engines/parallaction/parser_ns.cpp b/engines/parallaction/parser_ns.cpp index 2f4d2df776..3595fa5696 100644 --- a/engines/parallaction/parser_ns.cpp +++ b/engines/parallaction/parser_ns.cpp @@ -1124,20 +1124,14 @@ void LocationParser_ns::parse(Script *script) { resolveCommandForwards(); } -void LocationParser_ns::parseWalkNodes(WalkNodeList &list) { +void LocationParser_ns::parseWalkNodes(PointList &list) { debugC(5, kDebugParser, "parseWalkNodes()"); _script->readLineToken(true); while (scumm_stricmp(_tokens[0], "ENDNODES")) { if (!scumm_stricmp(_tokens[0], "COORD")) { - - WalkNodePtr v4(new WalkNode( - atoi(_tokens[1]), - atoi(_tokens[2]) - )); - - list.push_front(v4); + list.push_front(Common::Point(atoi(_tokens[1]), atoi(_tokens[2]))); } _script->readLineToken(true); @@ -1397,7 +1391,7 @@ void LocationParser_ns::parseZone(ZoneList &list, char *name) { list.push_front(z); _parser->pushTables(&_locationZoneParsers, _locationZoneStmt); - + return; } diff --git a/engines/parallaction/walk.cpp b/engines/parallaction/walk.cpp index a717b615e6..1914117915 100644 --- a/engines/parallaction/walk.cpp +++ b/engines/parallaction/walk.cpp @@ -97,16 +97,15 @@ uint32 PathBuilder::buildSubPath(const Common::Point& pos, const Common::Point& while (true) { - WalkNodeList::iterator nearest = _vm->_location._walkNodes.end(); - WalkNodeList::iterator locNode = _vm->_location._walkNodes.begin(); + PointList::iterator nearest = _vm->_location._walkNodes.end(); + PointList::iterator locNode = _vm->_location._walkNodes.begin(); // scans location path nodes searching for the nearest Node // which can't be farther than the target position // otherwise no _closest_node is selected while (locNode != _vm->_location._walkNodes.end()) { - Common::Point v8; - (*locNode)->getPoint(v8); + Common::Point v8 = *locNode; v2C = v8.sqrDist(stop); v28 = v8.sqrDist(v20); @@ -120,10 +119,10 @@ uint32 PathBuilder::buildSubPath(const Common::Point& pos, const Common::Point& if (nearest == _vm->_location._walkNodes.end()) break; - (*nearest)->getPoint(v20); + v20 = *nearest; v34 = v30 = v20.sqrDist(stop); - _subPath.push_back(WalkNodePtr(new WalkNode(**nearest))); + _subPath.push_back(*nearest); } return v34; @@ -141,34 +140,34 @@ void printNodes(WalkNodeList *list, const char* text) { // // x, y: mouse click (foot) coordinates // -WalkNodeList *PathBuilder::buildPath(uint16 x, uint16 y) { +PointList *PathBuilder::buildPath(uint16 x, uint16 y) { debugC(1, kDebugWalk, "PathBuilder::buildPath to (%i, %i)", x, y); Common::Point to(x, y); correctPathPoint(to); debugC(1, kDebugWalk, "found closest path point at (%i, %i)", to.x, to.y); - WalkNodePtr v48(new WalkNode(to.x, to.y)); - WalkNodePtr v44 = v48; + Common::Point v48(to); + Common::Point v44(to); uint16 v38 = walkFunc1(to.x, to.y, v44); if (v38 == 1) { // destination directly reachable debugC(1, kDebugWalk, "direct move to (%i, %i)", to.x, to.y); - _list = new WalkNodeList; + _list = new PointList; _list->push_back(v48); return _list; } // path is obstructed: look for alternative - _list = new WalkNodeList; + _list = new PointList; _list->push_back(v48); #if 0 printNodes(_list, "start"); #endif - Common::Point stop(v48->_x, v48->_y); + Common::Point stop(v48.x, v48.y); Common::Point pos; _vm->_char.getFoot(pos); @@ -184,7 +183,7 @@ WalkNodeList *PathBuilder::buildPath(uint16 x, uint16 y) { printNodes(_list, "first segment"); #endif - (*_list->begin())->getPoint(stop); + stop = *_list->begin(); buildSubPath(pos, stop); _list->insert(_list->begin(), _subPath.begin(), _subPath.end()); #if 0 @@ -202,7 +201,7 @@ WalkNodeList *PathBuilder::buildPath(uint16 x, uint16 y) { // 1 : Point reachable in a straight line // other values: square distance to target (point not reachable in a straight line) // -uint16 PathBuilder::walkFunc1(int16 x, int16 y, WalkNodePtr Node) { +uint16 PathBuilder::walkFunc1(int16 x, int16 y, Common::Point& node) { Common::Point arg(x, y); @@ -239,9 +238,7 @@ uint16 PathBuilder::walkFunc1(int16 x, int16 y, WalkNodePtr Node) { v8 = foot; } - Node->_x = v4.x; - Node->_y = v4.y; - + node = v4; return (x - v4.x) * (x - v4.x) + (y - v4.y) * (y - v4.y); } @@ -326,10 +323,10 @@ void Parallaction_ns::walk(Character &character) { character.getFoot(curPos); // update target, if previous was reached - WalkNodeList::iterator it = character._walkPath->begin(); + PointList::iterator it = character._walkPath->begin(); if (it != character._walkPath->end()) { - if ((*it)->_x == curPos.x && (*it)->_y == curPos.y) { - debugC(1, kDebugWalk, "walk reached node (%i, %i)", (*it)->_x, (*it)->_y); + if ((*it).x == curPos.x && (*it).y == curPos.y) { + debugC(1, kDebugWalk, "walk reached node (%i, %i)", (*it).x, (*it).y); it = character._walkPath->erase(it); } } @@ -341,11 +338,9 @@ void Parallaction_ns::walk(Character &character) { finalizeWalk(character); targetPos = curPos; } else { - if (*it) { - // targetPos is saved to help setting character direction - targetPos.x = (*it)->_x; - targetPos.y = (*it)->_y; - } + // targetPos is saved to help setting character direction + targetPos.x = (*it).x; + targetPos.y = (*it).y; Common::Point newPos(curPos); clipMove(newPos, targetPos); @@ -368,19 +363,6 @@ void Parallaction_ns::walk(Character &character) { } -WalkNode::WalkNode() : _x(0), _y(0) { -} - -WalkNode::WalkNode(int16 x, int16 y) : _x(x), _y(y) { -} - -WalkNode::WalkNode(const WalkNode& w) : _x(w._x), _y(w._y) { -} - -void WalkNode::getPoint(Common::Point &p) const { - p.x = _x; - p.y = _y; -} PathBuilder::PathBuilder(AnimationPtr anim) : _anim(anim), _list(0) { } diff --git a/engines/parallaction/walk.h b/engines/parallaction/walk.h index 788a6e1375..c2114c5988 100644 --- a/engines/parallaction/walk.h +++ b/engines/parallaction/walk.h @@ -33,36 +33,23 @@ namespace Parallaction { struct Animation; -struct WalkNode { - int16 _x; - int16 _y; - -public: - WalkNode(); - WalkNode(int16 x, int16 y); - WalkNode(const WalkNode& w); - - void getPoint(Common::Point &p) const; -}; - -typedef Common::SharedPtr WalkNodePtr; -typedef Common::List WalkNodeList; +typedef Common::List PointList; class PathBuilder { AnimationPtr _anim; - WalkNodeList *_list; - WalkNodeList _subPath; + PointList *_list; + PointList _subPath; void correctPathPoint(Common::Point &to); uint32 buildSubPath(const Common::Point& pos, const Common::Point& stop); - uint16 walkFunc1(int16 x, int16 y, WalkNodePtr Node); + uint16 walkFunc1(int16 x, int16 y, Common::Point& Node); public: PathBuilder(AnimationPtr anim); - WalkNodeList* buildPath(uint16 x, uint16 y); + PointList* buildPath(uint16 x, uint16 y); }; -- cgit v1.2.3