[Scummvm-git-logs] scummvm master -> 546cb580c173c61d2e7a93d2b21f509566de7aa4

OMGPizzaGuy noreply at scummvm.org
Sun Jun 9 15:02:06 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
546cb580c1 ULTIMA8: Use Point3 in animation tracker


Commit: 546cb580c173c61d2e7a93d2b21f509566de7aa4
    https://github.com/scummvm/scummvm/commit/546cb580c173c61d2e7a93d2b21f509566de7aa4
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2024-06-09T10:00:31-05:00

Commit Message:
ULTIMA8: Use Point3 in animation tracker

Changed paths:
    engines/ultima/ultima8/world/actors/actor.cpp
    engines/ultima/ultima8/world/actors/actor_anim_process.cpp
    engines/ultima/ultima8/world/actors/animation_tracker.cpp
    engines/ultima/ultima8/world/actors/animation_tracker.h
    engines/ultima/ultima8/world/actors/targeted_anim_process.cpp
    engines/ultima/ultima8/world/actors/targeted_anim_process.h


diff --git a/engines/ultima/ultima8/world/actors/actor.cpp b/engines/ultima/ultima8/world/actors/actor.cpp
index 5803ae03fed..a2a4ec8a03a 100644
--- a/engines/ultima/ultima8/world/actors/actor.cpp
+++ b/engines/ultima/ultima8/world/actors/actor.cpp
@@ -632,8 +632,8 @@ Animation::Result Actor::tryAnim(Animation::Sequence anim, Direction dir,
 
 	// isUnsupported only checks for AFF_ONGROUND, we need either
 	Box start = getWorldBox();
-	Box target = start;
-	tracker.getPosition(target._x, target._y, target._z);
+	Point3 pt = tracker.getPosition();
+	Box target(pt.x, pt.y, pt.z, start._xd, start._yd, start._zd);
 
 	CurrentMap *cm = World::get_instance()->getCurrentMap();
 	PositionInfo info = cm->getPositionInfo(target, start, getShapeInfo()->_flags, _objId);
diff --git a/engines/ultima/ultima8/world/actors/actor_anim_process.cpp b/engines/ultima/ultima8/world/actors/actor_anim_process.cpp
index 4e94fb60f72..46c6f833385 100644
--- a/engines/ultima/ultima8/world/actors/actor_anim_process.cpp
+++ b/engines/ultima/ultima8/world/actors/actor_anim_process.cpp
@@ -194,7 +194,7 @@ void ActorAnimProcess::run() {
 	if (_repeatCounter == 0) {
 		// next step:
 		Point3 pt = a->getLocation();
-		resultVal = _tracker->stepFrom(pt.x, pt.y, pt.z);
+		resultVal = _tracker->stepFrom(pt);
 		_tracker->updateActorFlags();
 		_currentStep++;
 
@@ -288,14 +288,14 @@ void ActorAnimProcess::run() {
 		}
 	}
 
-	int32 x2, y2, z2;
 	Point3 pt = a->getLocation();
+	Point3 pt2;
 
 	if (_interpolate) {
 		// Apply interpolated position on repeated frames
-		_tracker->getInterpolatedPosition(x2, y2, z2, _repeatCounter);
-		if (pt.x == x2 && pt.y == y2 && pt.z == z2) {
-			_tracker->getInterpolatedPosition(pt.x, pt.y, pt.z, _repeatCounter + 1);
+		pt2 = _tracker->getInterpolatedPosition(_repeatCounter);
+		if (pt == pt2) {
+			pt = _tracker->getInterpolatedPosition(_repeatCounter + 1);
 			a->collideMove(pt.x, pt.y, pt.z, false, true); // forced move
 			a->setFrame(_tracker->getFrame());
 #ifdef WATCHACTOR
@@ -309,13 +309,11 @@ void ActorAnimProcess::run() {
 	} else {
 		// Just move the whole distance on frame 0 of the repeat.
 		if (_repeatCounter == 0) {
-			_tracker->getPosition(x2, y2, z2);
-			a->collideMove(x2, y2, z2, false, true); // forced move
+			pt2 = _tracker->getPosition();
+			a->collideMove(pt2.x, pt2.y, pt2.z, false, true); // forced move
 			a->setFrame(_tracker->getFrame());
 		} else {
-			x2 = pt.x;
-			y2 = pt.y;
-			z2 = pt.z;
+			pt2 = pt;
 		}
 	}
 
@@ -343,7 +341,7 @@ void ActorAnimProcess::run() {
 			info += "H";
 
 		debugC(kDebugActor, "Animation [%u] ActorAnimProcess showing frame (%d, %d, %d)-(%d, %d, %d) shp (%u, %u) sfx %d rep %d flg %04X %s",
-			  Kernel::get_instance()->getFrameNum(), pt.x, pt.y, pt.z, x2, y2, z2,
+			  Kernel::get_instance()->getFrameNum(), pt.x, pt.y, pt.z, pt2.x, pt2.y, pt2.z,
 			  a->getShape(), _tracker->getFrame(), _tracker->getAnimFrame()->_sfx,
 			  _repeatCounter, _tracker->getAnimFrame()->_flags, info.c_str());
 	}
@@ -464,7 +462,7 @@ void ActorAnimProcess::doSpecial() {
 		a->getFootpadWorld(xd, yd, zd);
 		Box start(pt.x, pt.y, pt.z, xd, yd, zd);
 
-		_tracker->getPosition(pt.x, pt.y, pt.z);
+		pt = _tracker->getPosition();
 		Box target(pt.x, pt.y, pt.z, xd, yd, zd);
 
 		CurrentMap *cm = World::get_instance()->getCurrentMap();
diff --git a/engines/ultima/ultima8/world/actors/animation_tracker.cpp b/engines/ultima/ultima8/world/actors/animation_tracker.cpp
index 3bc964ca43b..4b509474c26 100644
--- a/engines/ultima/ultima8/world/actors/animation_tracker.cpp
+++ b/engines/ultima/ultima8/world/actors/animation_tracker.cpp
@@ -126,10 +126,8 @@ unsigned int AnimationTracker::getNextFrame(unsigned int frame) const {
 	return frame;
 }
 
-bool AnimationTracker::stepFrom(int32 x, int32 y, int32 z) {
-	_curr.x = x;
-	_curr.y = y;
-	_curr.z = z;
+bool AnimationTracker::stepFrom(const Point3 &pt) {
+	_curr = pt;
 
 	return step();
 }
@@ -402,7 +400,7 @@ const AnimFrame *AnimationTracker::getAnimFrame() const {
 	return &_animAction->getFrame(_dir, _currentFrame);
 }
 
-void AnimationTracker::setTargetedMode(int32 x, int32 y, int32 z) {
+void AnimationTracker::setTargetedMode(const Point3 &pt) {
 	unsigned int i;
 	int totaldir = 0;
 	int totalz = 0;
@@ -424,9 +422,9 @@ void AnimationTracker::setTargetedMode(int32 x, int32 y, int32 z) {
 	if (offGround) {
 		_mode = TargetMode;
 		_targetOffGroundLeft = offGround;
-		_targetDx = x - _curr.x - end_dx;
-		_targetDy = y - _curr.y - end_dy;
-		_targetDz = z - _curr.z - end_dz;
+		_targetDx = pt.x - _curr.x - end_dx;
+		_targetDy = pt.y - _curr.y - end_dy;
+		_targetDz = pt.z - _curr.z - end_dz;
 
 		// Don't allow large changes in Z
 		if (_targetDz > 16)
@@ -526,17 +524,16 @@ void AnimationTracker::updateActorFlags() {
 		a->_animFrame = _currentFrame;
 }
 
-void AnimationTracker::getInterpolatedPosition(int32 &x, int32 &y,
-											   int32 &z, int fc) const {
+Point3 AnimationTracker::getInterpolatedPosition(int fc) const {
 	int32 dx = _curr.x - _prev.x;
 	int32 dy = _curr.y - _prev.y;
 	int32 dz = _curr.z - _prev.z;
 
 	int repeat = _animAction->getFrameRepeat();
 
-	x = _prev.x + (dx * fc) / (repeat + 1);
-	y = _prev.y + (dy * fc) / (repeat + 1);
-	z = _prev.z + (dz * fc) / (repeat + 1);
+	return Point3(_prev.x + (dx * fc) / (repeat + 1),
+				  _prev.y + (dy * fc) / (repeat + 1),
+				  _prev.z + (dz * fc) / (repeat + 1));
 }
 
 void AnimationTracker::getSpeed(int32 &dx, int32 &dy, int32 &dz) const {
diff --git a/engines/ultima/ultima8/world/actors/animation_tracker.h b/engines/ultima/ultima8/world/actors/animation_tracker.h
index d2f508cf02e..108ad02da6f 100644
--- a/engines/ultima/ultima8/world/actors/animation_tracker.h
+++ b/engines/ultima/ultima8/world/actors/animation_tracker.h
@@ -53,10 +53,10 @@ public:
 	//! caller must decide if animation should continue after a 'false'
 	bool step();
 
-	//! do a single step of the animation, starting at (x,y,z)
+	//! do a single step of the animation, starting at the point
 	//! returns true if everything ok, false if not
 	//! caller must decide if animation should continue after a 'false'
-	bool stepFrom(int32 x, int32 y, int32 z);
+	bool stepFrom(const Point3 &pt);
 
 	//! update the PathfindingState with latest coordinates and flags
 	void updateState(PathfindingState &state);
@@ -65,14 +65,11 @@ public:
 	void updateActorFlags();
 
 	//! get the current position
-	void getPosition(int32 &x, int32 &y, int32 &z) const {
-		x = _curr.x;
-		y = _curr.y;
-		z = _curr.z;
+	Point3 getPosition() const {
+		return _curr;
 	}
 
-	void getInterpolatedPosition(int32 &x, int32 &y, int32 &z, int fc)
-			const;
+	Point3 getInterpolatedPosition(int fc) const;
 
 	//! get the difference between current position and previous position
 	void getSpeed(int32 &dx, int32 &dy, int32 &dz) const;
@@ -90,7 +87,7 @@ public:
 	//! get the current AnimFrame
 	const AnimFrame *getAnimFrame() const;
 
-	void setTargetedMode(int32 x, int32 y, int32 z);
+	void setTargetedMode(const Point3 &pt);
 
 	bool isDone() const {
 		return _done;
diff --git a/engines/ultima/ultima8/world/actors/targeted_anim_process.cpp b/engines/ultima/ultima8/world/actors/targeted_anim_process.cpp
index 531e9fb6244..5b6052f21ed 100644
--- a/engines/ultima/ultima8/world/actors/targeted_anim_process.cpp
+++ b/engines/ultima/ultima8/world/actors/targeted_anim_process.cpp
@@ -29,19 +29,19 @@ namespace Ultima8 {
 DEFINE_RUNTIME_CLASSTYPE_CODE(TargetedAnimProcess)
 
 TargetedAnimProcess::TargetedAnimProcess() : ActorAnimProcess(),
-		_x(0), _y(0), _z(0) {
+		_pt() {
 }
 
-TargetedAnimProcess::TargetedAnimProcess(Actor *actor, Animation::Sequence action, Direction dir, const Point3 &coords) :
+TargetedAnimProcess::TargetedAnimProcess(Actor *actor, Animation::Sequence action, Direction dir, const Point3 &pt) :
 	ActorAnimProcess(actor, action, dir),
-	_x(coords.x), _y(coords.y), _z(coords.z) {
+	_pt(pt) {
 }
 
 bool TargetedAnimProcess::init() {
 	if (!ActorAnimProcess::init())
 		return false;
 
-	_tracker->setTargetedMode(_x, _y, _z);
+	_tracker->setTargetedMode(_pt);
 	return true;
 }
 
@@ -49,18 +49,17 @@ bool TargetedAnimProcess::init() {
 void TargetedAnimProcess::saveData(Common::WriteStream *ws) {
 	ActorAnimProcess::saveData(ws);
 
-	ws->writeUint32LE(static_cast<uint32>(_x));
-	ws->writeUint32LE(static_cast<uint32>(_y));
-	ws->writeUint32LE(static_cast<uint32>(_z));
-
+	ws->writeUint32LE(static_cast<uint32>(_pt.x));
+	ws->writeUint32LE(static_cast<uint32>(_pt.y));
+	ws->writeUint32LE(static_cast<uint32>(_pt.z));
 }
 
 bool TargetedAnimProcess::loadData(Common::ReadStream *rs, uint32 version) {
 	if (!ActorAnimProcess::loadData(rs, version)) return false;
 
-	_x = rs->readUint32LE();
-	_y = rs->readUint32LE();
-	_z = rs->readUint32LE();
+	_pt.x = rs->readUint32LE();
+	_pt.y = rs->readUint32LE();
+	_pt.z = rs->readUint32LE();
 
 	return true;
 }
diff --git a/engines/ultima/ultima8/world/actors/targeted_anim_process.h b/engines/ultima/ultima8/world/actors/targeted_anim_process.h
index 863326a5523..5345bc56a23 100644
--- a/engines/ultima/ultima8/world/actors/targeted_anim_process.h
+++ b/engines/ultima/ultima8/world/actors/targeted_anim_process.h
@@ -35,7 +35,7 @@ public:
 	TargetedAnimProcess();
 	//! note: this probably needs some more parameters
 	TargetedAnimProcess(Actor *actor, Animation::Sequence action, Direction dir,
-	                    const Point3 &coords);
+	                    const Point3 &pt);
 
 	ENABLE_RUNTIME_CLASSTYPE()
 
@@ -45,7 +45,7 @@ public:
 protected:
 	bool init() override;
 
-	int32 _x, _y, _z;
+	Point3 _pt;
 };
 
 } // End of namespace Ultima8




More information about the Scummvm-git-logs mailing list