[Scummvm-cvs-logs] SF.net SVN: scummvm:[38894] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Thu Feb 26 10:42:08 CET 2009


Revision: 38894
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38894&view=rev
Author:   peres001
Date:     2009-02-26 09:42:08 +0000 (Thu, 26 Feb 2009)

Log Message:
-----------
Merged walk code for NS, and simplified handling.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parallaction_ns.cpp
    scummvm/trunk/engines/parallaction/walk.cpp
    scummvm/trunk/engines/parallaction/walk.h

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-26 09:12:29 UTC (rev 38893)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-26 09:42:08 UTC (rev 38894)
@@ -167,7 +167,7 @@
 		scrollX = _gfx->getScrollPos();
 
 		Common::Point foot;
-		_char.getFoot(foot);
+		_char._ani->getFoot(foot);
 
 		foot.x -= scrollX;
 		//foot.y -= ...
@@ -829,43 +829,11 @@
 }
 
 
-enum {
-	WALK_LEFT = 0,
-	WALK_RIGHT = 1,
-	WALK_DOWN = 2,
-	WALK_UP = 3
-};
 
-struct WalkFrames {
-	int16 stillFrame[4];
-	int16 firstWalkFrame[4];
-	int16 numWalkFrames[4];
-	int16 frameRepeat[4];
-};
-
-WalkFrames _char20WalkFrames = {
-	{  0,  7, 14, 17 },
-	{  1,  8, 15, 18 },
-	{  6,  6,  2,  2 },
-	{  2,  2,  4,  4 }
-};
-
-WalkFrames _char24WalkFrames = {
-	{  0,  9, 18, 21 },
-	{  1, 10, 19, 22 },
-	{  8,  8,  2,  2 },
-	{  2,  2,  4,  4 }
-};
-
-
-
 Character::Character(Parallaction *vm) : _vm(vm), _ani(new Animation) {
 	_talk = NULL;
 	_head = NULL;
 
-	_direction = WALK_DOWN;
-	_step = 0;
-
 	_ani->setX(150);
 	_ani->setY(100);
 	_ani->setZ(10);
@@ -875,27 +843,7 @@
 	strncpy(_ani->_name, "yourself", ZONENAME_LENGTH);
 }
 
-Character::~Character() {
 
-}
-
-void Character::getFoot(Common::Point &foot) {
-	Common::Rect rect;
-	_ani->gfxobj->getRect(_ani->getF(), rect);
-
-	foot.x = _ani->getX() + (rect.left + rect.width() / 2);
-	foot.y = _ani->getY() + (rect.top + rect.height());
-}
-
-void Character::setFoot(const Common::Point &foot) {
-	Common::Rect rect;
-	_ani->gfxobj->getRect(_ani->getF(), rect);
-
-	_ani->setX(foot.x - (rect.left + rect.width() / 2));
-	_ani->setY(foot.y - (rect.top + rect.height()));
-}
-
-
 void Character::setName(const char *name) {
 	_name.bind(name);
 }
@@ -916,29 +864,8 @@
 	return _name.dummy();
 }
 
-void Character::updateDirection(const Common::Point& pos, const Common::Point& to) {
 
-	Common::Point dist(to.x - pos.x, to.y - pos.y);
-	WalkFrames *frames = (_ani->getFrameNum() == 20) ? &_char20WalkFrames : &_char24WalkFrames;
 
-	_step++;
-
-	if (dist.x == 0 && dist.y == 0) {
-		_ani->setF(frames->stillFrame[_direction]);
-		return;
-	}
-
-	if (dist.x < 0)
-		dist.x = -dist.x;
-	if (dist.y < 0)
-		dist.y = -dist.y;
-
-	_direction = (dist.x > dist.y) ? ((to.x > pos.x) ? WALK_LEFT : WALK_RIGHT) : ((to.y > pos.y) ? WALK_DOWN : WALK_UP);
-	_ani->setF(frames->firstWalkFrame[_direction] + (_step / frames->frameRepeat[_direction]) % frames->numWalkFrames[_direction]);
-}
-
-
-
 // Various ways of detecting character modes used to exist
 // inside the engine, so they have been unified in the two
 // following macros.

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2009-02-26 09:12:29 UTC (rev 38893)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2009-02-26 09:42:08 UTC (rev 38894)
@@ -120,7 +120,6 @@
 class Input;
 class DialogueManager;
 class MenuInputHelper;
-class PathBuilder_NS;
 class PathWalker_NS;
 class PathWalker_BR;
 class CommandExec;
@@ -199,32 +198,21 @@
 struct Character {
 	Parallaction	*_vm;
 
-
 	AnimationPtr	_ani;
 	GfxObj			*_head;
 	GfxObj			*_talk;
-	PointList		_walkPath;
 
 	Character(Parallaction *vm);
-	~Character();
 
-	void getFoot(Common::Point &foot);
-	void setFoot(const Common::Point &foot);
-
 protected:
 	CharacterName	_name;
 
-	int16		_direction, _step;
-
 public:
 	void setName(const char *name);
 	const char *getName() const;
 	const char *getBaseName() const;
 	const char *getFullName() const;
 	bool dummy() const;
-
-	void updateDirection(const Common::Point& pos, const Common::Point& to);
-
 };
 
 
@@ -435,7 +423,6 @@
 	static const Callable _dosCallables[25];
 	static const Callable _amigaCallables[25];
 
-	PathBuilder_NS		*_builder;
 	PathWalker_NS		*_walker;
 
 	// common callables

Modified: scummvm/trunk/engines/parallaction/parallaction_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2009-02-26 09:12:29 UTC (rev 38893)
+++ scummvm/trunk/engines/parallaction/parallaction_ns.cpp	2009-02-26 09:42:08 UTC (rev 38894)
@@ -146,7 +146,7 @@
 }
 
 Parallaction_ns::Parallaction_ns(OSystem* syst, const PARALLACTIONGameDescription *gameDesc) : Parallaction(syst, gameDesc),
-	_locationParser(0), _programParser(0), _builder(0), _walker(0) {
+	_locationParser(0), _programParser(0), _walker(0) {
 }
 
 Common::Error Parallaction_ns::init() {
@@ -184,8 +184,7 @@
 	_cmdExec = new CommandExec_ns(this);
 	_programExec = new ProgramExec_ns(this);
 
-	_builder = new PathBuilder_NS(&_char);
-	_walker = new PathWalker_NS(&_char);
+	_walker = new PathWalker_NS;
 
 	_sarcophagusDeltaX = 0;
 	_movingSarcophagus = false;
@@ -215,7 +214,6 @@
 
 	_location._animations.remove(_char._ani);
 
-	delete _builder;
 	delete _walker;
 }
 
@@ -503,7 +501,7 @@
 		return;
 	}
 
-	_builder->buildPath(x, y);
+	_walker->buildPath(a, x, y);
 	_engineFlags |= kEngineWalking;
 }
 

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2009-02-26 09:12:29 UTC (rev 38893)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2009-02-26 09:42:08 UTC (rev 38894)
@@ -31,9 +31,38 @@
 
 #define IS_PATH_CLEAR(x,y) _vm->_gfx->_backgroundInfo->_path->getValue((x), (y))
 
+enum {
+	WALK_LEFT = 0,
+	WALK_RIGHT = 1,
+	WALK_DOWN = 2,
+	WALK_UP = 3
+};
+
+struct WalkFrames {
+	int16 stillFrame[4];
+	int16 firstWalkFrame[4];
+	int16 numWalkFrames[4];
+	int16 frameRepeat[4];
+};
+
+WalkFrames _char20WalkFrames_NS = {
+	{  0,  7, 14, 17 },
+	{  1,  8, 15, 18 },
+	{  6,  6,  2,  2 },
+	{  2,  2,  4,  4 }
+};
+
+WalkFrames _char24WalkFrames_NS = {
+	{  0,  9, 18, 21 },
+	{  1, 10, 19, 22 },
+	{  8,  8,  2,  2 },
+	{  2,  2,  4,  4 }
+};
+
+
 // adjusts position towards nearest walkable point
 //
-void PathBuilder_NS::correctPathPoint(Common::Point &to) {
+void PathWalker_NS::correctPathPoint(Common::Point &to) {
 
 	if (IS_PATH_CLEAR(to.x, to.y)) return;
 
@@ -84,7 +113,7 @@
 
 }
 
-uint32 PathBuilder_NS::buildSubPath(const Common::Point& pos, const Common::Point& stop) {
+uint32 PathWalker_NS::buildSubPath(const Common::Point& pos, const Common::Point& stop) {
 
 	uint32 v28 = 0;
 	uint32 v2C = 0;
@@ -132,11 +161,13 @@
 //
 //	x, y: mouse click (foot) coordinates
 //
-void PathBuilder_NS::buildPath(uint16 x, uint16 y) {
+void PathWalker_NS::buildPath(AnimationPtr a, uint16 x, uint16 y) {
 	debugC(1, kDebugWalk, "PathBuilder::buildPath to (%i, %i)", x, y);
 
-	_ch->_walkPath.clear();
+    _a = a;
 
+	_walkPath.clear();
+
 	Common::Point to(x, y);
 	correctPathPoint(to);
 	debugC(1, kDebugWalk, "found closest path point at (%i, %i)", to.x, to.y);
@@ -148,26 +179,26 @@
 	if (v38 == 1) {
 		// destination directly reachable
 		debugC(1, kDebugWalk, "direct move to (%i, %i)", to.x, to.y);
-		_ch->_walkPath.push_back(v48);
+		_walkPath.push_back(v48);
 		return;
 	}
 
 	// path is obstructed: look for alternative
-	_ch->_walkPath.push_back(v48);
+	_walkPath.push_back(v48);
 	Common::Point pos;
-	_ch->getFoot(pos);
+	_a->getFoot(pos);
 
 	uint32 v34 = buildSubPath(pos, v48);
 	if (v38 != 0 && v34 > v38) {
 		// no alternative path (gap?)
-		_ch->_walkPath.clear();
-		_ch->_walkPath.push_back(v44);
+		_walkPath.clear();
+		_walkPath.push_back(v44);
 		return;
 	}
-	_ch->_walkPath.insert(_ch->_walkPath.begin(), _subPath.begin(), _subPath.end());
+	_walkPath.insert(_walkPath.begin(), _subPath.begin(), _subPath.end());
 
-	buildSubPath(pos, *_ch->_walkPath.begin());
-	_ch->_walkPath.insert(_ch->_walkPath.begin(), _subPath.begin(), _subPath.end());
+	buildSubPath(pos, *_walkPath.begin());
+	_walkPath.insert(_walkPath.begin(), _subPath.begin(), _subPath.end());
 
 	return;
 }
@@ -180,14 +211,14 @@
 //	1 : Point reachable in a straight line
 //	other values: square distance to target (point not reachable in a straight line)
 //
-uint16 PathBuilder_NS::walkFunc1(const Common::Point &to, Common::Point& node) {
+uint16 PathWalker_NS::walkFunc1(const Common::Point &to, Common::Point& node) {
 
 	Common::Point arg(to);
 
 	Common::Point v4;
 
 	Common::Point foot;
-	_ch->getFoot(foot);
+	_a->getFoot(foot);
 
 	Common::Point v8(foot);
 
@@ -286,10 +317,10 @@
 	_engineFlags &= ~kEngineWalking;
 
 	Common::Point foot;
-	_ch->getFoot(foot);
+	_a->getFoot(foot);
 	checkDoor(foot);
 
-	_ch->_walkPath.clear();
+	_walkPath.clear();
 }
 
 void PathWalker_NS::walk() {
@@ -298,20 +329,20 @@
 	}
 
 	Common::Point curPos;
-	_ch->getFoot(curPos);
+	_a->getFoot(curPos);
 
 	// update target, if previous was reached
-	PointList::iterator it = _ch->_walkPath.begin();
-	if (it != _ch->_walkPath.end()) {
+	PointList::iterator it = _walkPath.begin();
+	if (it != _walkPath.end()) {
 		if (*it == curPos) {
 			debugC(1, kDebugWalk, "walk reached node (%i, %i)", (*it).x, (*it).y);
-			it = _ch->_walkPath.erase(it);
+			it = _walkPath.erase(it);
 		}
 	}
 
 	// advance character towards the target
 	Common::Point targetPos;
-	if (it == _ch->_walkPath.end()) {
+	if (it == _walkPath.end()) {
 		debugC(1, kDebugWalk, "walk reached last node");
 		finalizeWalk();
 		targetPos = curPos;
@@ -321,7 +352,7 @@
 
 		Common::Point newPos(curPos);
 		clipMove(newPos, targetPos);
-		_ch->setFoot(newPos);
+		_a->setFoot(newPos);
 
 		if (newPos == curPos) {
 			debugC(1, kDebugWalk, "walk was blocked by an unforeseen obstacle");
@@ -336,15 +367,35 @@
 	// from curPos to newPos is prone to abrutply change in direction, thus making the
 	// code select 'too different' frames when walking diagonally against obstacles,
 	// and yielding an annoying shaking effect in the character.
-	_ch->updateDirection(curPos, targetPos);
+	updateDirection(curPos, targetPos);
 }
 
+void PathWalker_NS::updateDirection(const Common::Point& pos, const Common::Point& to) {
 
+	Common::Point dist(to.x - pos.x, to.y - pos.y);
+	WalkFrames *frames = (_a->getFrameNum() == 20) ? &_char20WalkFrames_NS : &_char24WalkFrames_NS;
 
-PathBuilder_NS::PathBuilder_NS(Character *ch) : PathBuilder(ch) {
+	_step++;
+
+	if (dist.x == 0 && dist.y == 0) {
+		_a->setF(frames->stillFrame[_direction]);
+		return;
+	}
+
+	if (dist.x < 0)
+		dist.x = -dist.x;
+	if (dist.y < 0)
+		dist.y = -dist.y;
+
+	_direction = (dist.x > dist.y) ? ((to.x > pos.x) ? WALK_LEFT : WALK_RIGHT) : ((to.y > pos.y) ? WALK_DOWN : WALK_UP);
+	_a->setF(frames->firstWalkFrame[_direction] + (_step / frames->frameRepeat[_direction]) % frames->numWalkFrames[_direction]);
 }
 
 
+PathWalker_NS::PathWalker_NS() : _direction(WALK_DOWN), _step(0) {
+}
+
+
 bool PathWalker_BR::directPathExists(const Common::Point &from, const Common::Point &to) {
 
 	Common::Point copy(from);

Modified: scummvm/trunk/engines/parallaction/walk.h
===================================================================
--- scummvm/trunk/engines/parallaction/walk.h	2009-02-26 09:12:29 UTC (rev 38893)
+++ scummvm/trunk/engines/parallaction/walk.h	2009-02-26 09:42:08 UTC (rev 38894)
@@ -36,51 +36,28 @@
 
 struct Character;
 
-class PathBuilder {
 
-protected:
-	Character *_ch;
+class PathWalker_NS {
+    AnimationPtr _a;
+	PointList	_walkPath;
+	int16		_direction, _step;
 
-public:
-	PathBuilder(Character *ch) : _ch(ch) { }
-	virtual ~PathBuilder() { }
-
-	virtual void buildPath(uint16 x, uint16 y) = 0;
-};
-
-class PathWalker {
-protected:
-	Character	*_ch;
-public:
-	PathWalker(Character *ch) : _ch(ch) { }
-	virtual ~PathWalker() { }
-	virtual void walk() = 0;
-};
-
-
-
-class PathBuilder_NS : public PathBuilder {
-
+    // builder routines
 	PointList	_subPath;
-
 	void correctPathPoint(Common::Point &to);
 	uint32 buildSubPath(const Common::Point& pos, const Common::Point& stop);
 	uint16 walkFunc1(const Common::Point &to, Common::Point& node);
 
-public:
-	PathBuilder_NS(Character *ch);
-	void buildPath(uint16 x, uint16 y);
-};
-
-class PathWalker_NS : public PathWalker {
-
-
+    // walker routines
 	void finalizeWalk();
 	void clipMove(Common::Point& pos, const Common::Point& to);
 	void checkDoor(const Common::Point &foot);
+    void updateDirection(const Common::Point& pos, const Common::Point& to);
 
 public:
-	PathWalker_NS(Character *ch) : PathWalker(ch) { }
+	PathWalker_NS();
+
+    void buildPath(AnimationPtr a, uint16 x, uint16 y);
 	void walk();
 };
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list