[Scummvm-cvs-logs] CVS: residual actor.cpp,1.25,1.26 actor.h,1.12,1.13 lua.cpp,1.54,1.55 walkplane.cpp,1.8,1.9 walkplane.h,1.6,1.7

Daniel Schepler dschepler at users.sourceforge.net
Thu Mar 25 07:55:06 CET 2004


Update of /cvsroot/scummvm/residual
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28086

Modified Files:
	actor.cpp actor.h lua.cpp walkplane.cpp walkplane.h 
Log Message:
Implemented GetActorPuckVector and IsActorResting.  Also rearranged
the walking code to be a bit more similar to the turning code.


Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/actor.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- actor.cpp	25 Mar 2004 09:33:17 -0000	1.25
+++ actor.cpp	25 Mar 2004 15:43:05 -0000	1.26
@@ -30,7 +30,7 @@
 		pitch_(0), yaw_(0), roll_(0), walkRate_(0), turnRate_(0),
 		visible_(true), talkSound_(NULL), turning_(false), walking_(false),
 		restCostume_(NULL), restChore_(-1),
-		walkCostume_(NULL), walkChore_(-1), lastWalkTime_(-1),
+		walkCostume_(NULL), walkChore_(-1), walkedLast_(false), walkedCur_(-1),
 		turnCostume_(NULL), leftTurnChore_(-1), rightTurnChore_(-1),
 		lastTurnDir_(0), currTurnDir_(0),
 		mumbleCostume_(NULL), mumbleChore_(-1) {
@@ -69,6 +69,18 @@
 	}
 }
 
+bool Actor::isWalking() const {
+	return walkedLast_ || walkedCur_ || walking_;
+}
+
+bool Actor::isTurning() const {
+	if (turning_)
+		return true;
+	if (lastTurnDir_ != 0 || currTurnDir_ != 0)
+		return true;
+	return false;
+}
+
 void Actor::walkForward() {
 	float dist = Engine::instance()->perSecond(walkRate_);
 	float yaw_rad = yaw_ * (M_PI / 180), pitch_rad = pitch_ * (M_PI / 180);
@@ -79,18 +91,31 @@
 
 	if (! constrain_) {
 		pos_ = destPos;
-		lastWalkTime_ = Engine::instance()->frameStart();
+		walkedCur_ = true;
 	}
 	else {
 		Sector *sector = Engine::instance()->currScene()->findPointSector(destPos, 0x1000);
 		if (sector != NULL) {
 			pos_ = sector->projectToPlane(destPos);
-			lastWalkTime_ = Engine::instance()->frameStart();
+			walkedCur_ = true;
 		}
 	}
 }
 
+Vector3d Actor::puckVector() const {
+	float yaw_rad = yaw_ * (M_PI / 180);
+	Vector3d forwardVec(-std::sin(yaw_rad), std::cos(yaw_rad), 0);
+
+	Sector *sector = Engine::instance()->currScene()->findPointSector(pos_, 0x1000);
+	if (sector == NULL)
+		return forwardVec;
+	else
+		return sector->projectToPuckVector(forwardVec);
+}
+
 void Actor::setRestChore(int chore, Costume *cost) {
+	if (restCostume_ == cost && restChore_ == chore)
+		return;
 	if (restChore_ >= 0)
 		restCostume_->stopChore(restChore_);
 	restCostume_ = cost;
@@ -99,6 +124,8 @@
 }
 
 void Actor::setWalkChore(int chore, Costume *cost) {
+	if (walkCostume_ == cost && walkChore_ == chore)
+		return;
 	if (walkChore_ >= 0)
 		walkCostume_->stopChore(walkChore_);
 	walkCostume_ = cost;
@@ -106,6 +133,9 @@
 }
 
 void Actor::setTurnChores(int left_chore, int right_chore, Costume *cost) {
+	if (turnCostume_ == cost && leftTurnChore_ == left_chore &&
+	    rightTurnChore_ == right_chore)
+		return;
 	if (leftTurnChore_ >= 0) {
 		turnCostume_->stopChore(leftTurnChore_);
 		turnCostume_->stopChore(rightTurnChore_);
@@ -123,6 +153,8 @@
 	if (index < 1 || index > 10)
 		error("Got talk chore index out of range (%d)\n", index);
 	index--;
+	if (talkCostume_[index] == cost && talkChore_[index] == chore)
+		return;
 	if (talkChore_[index] >= 0)
 		talkCostume_[index]->stopChore(talkChore_[index]);
 	talkCostume_[index] = cost;
@@ -278,6 +310,8 @@
 			}
 		else
 			pos_ += dir * walkAmt;
+
+		walkedCur_ = true;
 	}
 
 	// The rest chore might have been stopped because of a
@@ -285,10 +319,8 @@
 	if (restChore_ >= 0 && restCostume_->isChoring(restChore_, false) < 0)
 		restCostume_->playChoreLooping(restChore_);
 
-	bool isWalking = (walking_ ||
-			  lastWalkTime_ == Engine::instance()->frameStart());
 	if (walkChore_ >= 0) {
-		if (isWalking) {
+		if (walkedCur_) {
 			if (walkCostume_->isChoring(walkChore_, false) < 0)
 				walkCostume_->playChoreLooping(walkChore_);
 		}
@@ -299,7 +331,7 @@
 	}
 
 	if (leftTurnChore_ >= 0) {
-		if (isWalking)
+		if (walkedCur_)
 			currTurnDir_ = 0;
 		if (lastTurnDir_ != 0 && lastTurnDir_ != currTurnDir_)
 			turnCostume_->stopChore(getTurnChore(lastTurnDir_));
@@ -308,6 +340,8 @@
 	}
 	else
 		currTurnDir_ = 0;
+	walkedLast_ = walkedCur_;
+	walkedCur_ = false;
 	lastTurnDir_ = currTurnDir_;
 	currTurnDir_ = 0;
 

Index: actor.h
===================================================================
RCS file: /cvsroot/scummvm/residual/actor.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- actor.h	25 Mar 2004 09:33:17 -0000	1.12
+++ actor.h	25 Mar 2004 15:43:05 -0000	1.13
@@ -38,12 +38,12 @@
 	void setPos(Vector3d pos) { pos_ = pos; }
 	Vector3d pos() const { return pos_; }
 	void walkTo(Vector3d p);
-	bool isWalking() const { return walking_; }
+	bool isWalking() const;
 	void setRot(float pitch, float yaw, float roll) {
 		pitch_ = pitch; yaw_ = yaw; roll_ = roll;
 	}
 	void turnTo(float pitch, float yaw, float roll);
-	bool isTurning() const { return turning_; }
+	bool isTurning() const;
 	float pitch() const { return pitch_; }
 	float yaw() const { return yaw_; }
 	float roll() const { return roll_; }
@@ -63,6 +63,7 @@
 		return setName_ == name;
 	}
 	void walkForward();
+	Vector3d puckVector() const;
 	void turn(int dir);
 
 	void sayLine(const char *msg);
@@ -140,7 +141,7 @@
 
 	Costume *walkCostume_;
 	int walkChore_;
-	int lastWalkTime_;
+	bool walkedLast_, walkedCur_;
 
 	Costume *turnCostume_;
 	int leftTurnChore_, rightTurnChore_;

Index: lua.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- lua.cpp	25 Mar 2004 09:33:17 -0000	1.54
+++ lua.cpp	25 Mar 2004 15:43:05 -0000	1.55
@@ -407,6 +407,14 @@
 	act->walkForward();
 }
 
+static void GetActorPuckVector() {
+	Actor *act = check_actor(1);
+	Vector3d result = act->puckVector();
+	lua_pushnumber(result.x());
+	lua_pushnumber(result.y());
+	lua_pushnumber(result.z());
+}
+
 static void WalkActorTo() {
 	Actor *act = check_actor(1);
 	double x = luaL_check_number(2);
@@ -420,6 +428,11 @@
 	pushbool(act->isWalking());
 }
 
+static void IsActorResting() {
+	Actor *act = check_actor(1);
+	pushbool(!(act->isWalking() || act->isTurning()));
+}
+
 static void TurnActor() {
 	Actor *act = check_actor(1);
 	int dir = check_int(2);
@@ -1287,7 +1300,6 @@
 	"LockFont",
 	"EnableDebugKeys",
 	"WorldToScreen",
-	"IsActorResting",
 	"CompleteActorChore",
 	"SetActorRoll",
 	"SetActorPitch",
@@ -1301,7 +1313,6 @@
 	"WalkActorVector",
 	"PutActorAtInterest",
 	"SetActorReflection",
-	"GetActorPuckVector",
 	"GetActorRect",
 	"GetActorNodeLocation",
 	"SetActorTimeScale",
@@ -1522,8 +1533,10 @@
 	{ "GetActorWalkRate", GetActorWalkRate },
 	{ "SetActorTurnRate", SetActorTurnRate },
 	{ "WalkActorForward", WalkActorForward },
+	{ "GetActorPuckVector", GetActorPuckVector },
 	{ "WalkActorTo", WalkActorTo },
 	{ "IsActorMoving", IsActorMoving },
+	{ "IsActorResting", IsActorResting },
 	{ "TurnActor", TurnActor },
 	{ "PushActorCostume", PushActorCostume },
 	{ "SetActorRestChore", SetActorRestChore },

Index: walkplane.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- walkplane.cpp	25 Mar 2004 09:33:17 -0000	1.8
+++ walkplane.cpp	25 Mar 2004 15:43:05 -0000	1.9
@@ -119,3 +119,12 @@
 	result.z() -= dot(normal_, point - vertices_[0]) / normal_.z();
 	return result;
 }
+
+Vector3d Sector::projectToPuckVector(Vector3d v) const {
+	if (normal_.z() == 0)
+		error("Trying to walk along vertical plane\n");
+
+	Vector3d result = v;
+	result.z() -= dot(normal_, v) / normal_.z();
+	return result;
+}

Index: walkplane.h
===================================================================
RCS file: /cvsroot/scummvm/residual/walkplane.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- walkplane.h	25 Mar 2004 09:33:17 -0000	1.6
+++ walkplane.h	25 Mar 2004 15:43:05 -0000	1.7
@@ -40,6 +40,7 @@
 	bool isPointInSector(Vector3d point) const;
 
 	Vector3d projectToPlane(Vector3d point) const;
+	Vector3d projectToPuckVector(Vector3d v) const;
 
 private:
 	int numVertices_, id_;





More information about the Scummvm-git-logs mailing list