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

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Sun Jul 13 08:27:31 CEST 2008


Revision: 33023
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33023&view=rev
Author:   peres001
Date:     2008-07-12 23:27:31 -0700 (Sat, 12 Jul 2008)

Log Message:
-----------
Cleanup of walk code.

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

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2008-07-13 03:39:42 UTC (rev 33022)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2008-07-13 06:27:31 UTC (rev 33023)
@@ -390,7 +390,7 @@
 		if (_char._ani->gfxobj) {
 			_char._ani->gfxobj->z = _char._ani->_z;
 		}
-		walk();
+		walk(_char);
 		drawAnimations();
 	}
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2008-07-13 03:39:42 UTC (rev 33022)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2008-07-13 06:27:31 UTC (rev 33023)
@@ -261,9 +261,9 @@
 	void		pauseJobs();
 	void		resumeJobs();
 
-	void		finalizeWalk(WalkNodeList *list);
-	int16		selectWalkFrame(const Common::Point& pos, const WalkNodePtr from);
-	void		clipMove(Common::Point& pos, const WalkNodePtr from);
+	void		finalizeWalk(Character &character);
+	int16		selectWalkFrame(Character &character, const Common::Point& pos, const WalkNodePtr to);
+	void		clipMove(Common::Point& pos, const WalkNodePtr to);
 
 	ZonePtr		findZone(const char *name);
 	ZonePtr		hitZone(uint32 type, uint16 x, uint16 y);
@@ -357,7 +357,7 @@
 
 	void		displayComment(ExamineData *data);
 
-	uint16		checkDoor();
+	void		checkDoor(Character &character);
 
 	void		freeCharacter();
 
@@ -379,7 +379,7 @@
 
 	void updateDoor(ZonePtr z);
 
-	virtual void walk() = 0;
+	virtual void walk(Character &character) = 0;
 	virtual void drawAnimations() = 0;
 
 	void		beep();
@@ -575,7 +575,7 @@
 	const Callable *_callables;
 
 protected:
-	void walk();
+	void walk(Character &character);
 	void drawAnimations();
 
 	void		parseLocation(const char *filename);

Modified: scummvm/trunk/engines/parallaction/walk.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/walk.cpp	2008-07-13 03:39:42 UTC (rev 33022)
+++ scummvm/trunk/engines/parallaction/walk.cpp	2008-07-13 06:27:31 UTC (rev 33023)
@@ -27,9 +27,11 @@
 
 namespace Parallaction {
 
+// should be reset on location switch
 static uint16 _doorData1 = 1000;
 static ZonePtr _zoneTrap;
 
+// should be reset on character switch
 static uint16	walkData1 = 0;
 static uint16	walkData2 = 0;	// next walk frame
 
@@ -259,30 +261,30 @@
 	return 1;
 }
 
-void Parallaction::clipMove(Common::Point& pos, const WalkNodePtr from) {
+void Parallaction::clipMove(Common::Point& pos, const WalkNodePtr to) {
 
-	if ((pos.x < from->_x) && (pos.x < _pathBuffer->w) && (_pathBuffer->getValue(pos.x + 2, pos.y) != 0)) {
-		pos.x = (pos.x + 2 < from->_x) ? pos.x + 2 : from->_x;
+	if ((pos.x < to->_x) && (pos.x < _pathBuffer->w) && (_pathBuffer->getValue(pos.x + 2, pos.y) != 0)) {
+		pos.x = (pos.x + 2 < to->_x) ? pos.x + 2 : to->_x;
 	}
 
-	if ((pos.x > from->_x) && (pos.x > 0) && (_pathBuffer->getValue(pos.x - 2, pos.y) != 0)) {
-		pos.x = (pos.x - 2 > from->_x) ? pos.x - 2 : from->_x;
+	if ((pos.x > to->_x) && (pos.x > 0) && (_pathBuffer->getValue(pos.x - 2, pos.y) != 0)) {
+		pos.x = (pos.x - 2 > to->_x) ? pos.x - 2 : to->_x;
 	}
 
-	if ((pos.y < from->_y) && (pos.y < _pathBuffer->h) && (_pathBuffer->getValue(pos.x, pos.y + 2) != 0)) {
-		pos.y = (pos.y + 2 <= from->_y) ? pos.y + 2 : from->_y;
+	if ((pos.y < to->_y) && (pos.y < _pathBuffer->h) && (_pathBuffer->getValue(pos.x, pos.y + 2) != 0)) {
+		pos.y = (pos.y + 2 <= to->_y) ? pos.y + 2 : to->_y;
 	}
 
-	if ((pos.y > from->_y) && (pos.y > 0) && (_pathBuffer->getValue(pos.x, pos.y - 2) != 0)) {
-		pos.y = (pos.y - 2 >= from->_y) ? pos.y - 2 :from->_y;
+	if ((pos.y > to->_y) && (pos.y > 0) && (_pathBuffer->getValue(pos.x, pos.y - 2) != 0)) {
+		pos.y = (pos.y - 2 >= to->_y) ? pos.y - 2 : to->_y;
 	}
 
 	return;
 }
 
-int16 Parallaction::selectWalkFrame(const Common::Point& pos, const WalkNodePtr from) {
+int16 Parallaction::selectWalkFrame(Character &character, const Common::Point& pos, const WalkNodePtr to) {
 
-	Common::Point dist(from->_x - pos.x, from->_y - pos.y);
+	Common::Point dist(to->_x - pos.x, to->_y - pos.y);
 
 	if (dist.x < 0)
 		dist.x = -dist.x;
@@ -293,14 +295,14 @@
 
 	// walk frame selection
 	int16 v16;
-	if (_char._ani->getFrameNum() == 20) {
+	if (character._ani->getFrameNum() == 20) {
 
 		if (dist.x > dist.y) {
-			walkData2 = (from->_x > pos.x) ? 0 : 7;
+			walkData2 = (to->_x > pos.x) ? 0 : 7;
 			walkData1 %= 12;
 			v16 = walkData1 / 2;
 		} else {
-			walkData2 = (from->_y > pos.y) ? 14 : 17;
+			walkData2 = (to->_y > pos.y) ? 14 : 17;
 			walkData1 %= 8;
 			v16 = walkData1 / 4;
 		}
@@ -308,11 +310,11 @@
 	} else {
 
 		if (dist.x > dist.y) {
-			walkData2 = (from->_x > pos.x) ? 0 : 9;
+			walkData2 = (to->_x > pos.x) ? 0 : 9;
 			walkData1 %= 16;
 			v16 = walkData1 / 2;
 		} else {
-			walkData2 = (from->_y > pos.y) ? 18 : 21;
+			walkData2 = (to->_y > pos.y) ? 18 : 21;
 			walkData1 %= 8;
 			v16 = walkData1 / 4;
 		}
@@ -322,9 +324,7 @@
 	return v16;
 }
 
-uint16 Parallaction::checkDoor() {
-//	printf("checkDoor()...");
-
+void Parallaction::checkDoor(Character &character) {
 	if (_currentLocationIndex != _doorData1) {
 		_doorData1 = _currentLocationIndex;
 		_zoneTrap = nullZonePtr;
@@ -334,7 +334,7 @@
 
 	Common::Point foot;
 
-	_char.getFoot(foot);
+	character.getFoot(foot);
 	ZonePtr z = hitZone(kZoneDoor, foot.x, foot.y);
 
 	if (z) {
@@ -351,7 +351,7 @@
 		}
 	}
 
-	_char.getFoot(foot);
+	character.getFoot(foot);
 	z = hitZone(kZoneTrap, foot.x, foot.y);
 
 	if (z) {
@@ -367,61 +367,51 @@
 		_zoneTrap = nullZonePtr;
 	}
 
-//	printf("done\n");
-
-	_char._ani->_frame = walkData2;
-	return _char._ani->_frame;
 }
 
 
-void Parallaction::finalizeWalk(WalkNodeList *list) {
-	checkDoor();
-	delete list;
+void Parallaction::finalizeWalk(Character &character) {
+	checkDoor(character);
+	delete character._walkPath;
+	character._walkPath = 0;
+
+	character._ani->_frame = walkData2;
 }
 
-void Parallaction_ns::walk() {
+void Parallaction_ns::walk(Character &character) {
 	if ((_engineFlags & kEngineWalking) == 0) {
 		return;
 	}
 
-	WalkNodeList *list = _char._walkPath;
+	Common::Point curPos;
+	character.getFoot(curPos);
 
-	_char._ani->_oldPos.x = _char._ani->_left;
-	_char._ani->_oldPos.y = _char._ani->_top;
+	WalkNodeList::iterator it = character._walkPath->begin();
 
-	Common::Point pos;
-	_char.getFoot(pos);
-
-	WalkNodeList::iterator it = list->begin();
-
-	if (it != list->end()) {
-		if ((*it)->_x == pos.x && (*it)->_y == pos.y) {
+	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);
-			it = list->erase(it);
+			it = character._walkPath->erase(it);
 		}
 	}
-	if (it == list->end()) {
+	if (it == character._walkPath->end()) {
 		debugC(1, kDebugWalk, "walk reached last node");
-//		j->_finished = 1;
-		finalizeWalk(list);
+		finalizeWalk(character);
 		return;
 	}
-	_char._walkPath = list;
 
 	// selectWalkFrame must be performed before position is changed by clipMove
-	int16 v16 = selectWalkFrame(pos, *it);
-	clipMove(pos, *it);
+	int16 walkFrame = selectWalkFrame(character, curPos, *it);
 
-	_char.setFoot(pos);
+	Common::Point newPos(curPos);
+	clipMove(newPos, *it);
+	character.setFoot(newPos);
 
-	Common::Point newpos(_char._ani->_left, _char._ani->_top);
-
-	if (newpos == _char._ani->_oldPos) {
+	if (newPos == curPos) {
 		debugC(1, kDebugWalk, "walk was blocked by an unforeseen obstacle");
-//		j->_finished = 1;
-		finalizeWalk(list);
+		finalizeWalk(character);
 	} else {
-		_char._ani->_frame = v16 + walkData2 + 1;
+		character._ani->_frame = walkFrame + walkData2 + 1;
 	}
 
 	return;


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