[Scummvm-git-logs] scummvm master -> afdfff9c81fa8400672156d24a3078704f352234

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Jul 14 00:52:13 UTC 2021


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:
afdfff9c81 SAGA2: Fix Task loading


Commit: afdfff9c81fa8400672156d24a3078704f352234
    https://github.com/scummvm/scummvm/commit/afdfff9c81fa8400672156d24a3078704f352234
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-14T09:45:28+09:00

Commit Message:
SAGA2: Fix Task loading

Changed paths:
    engines/saga2/task.cpp
    engines/saga2/task.h


diff --git a/engines/saga2/task.cpp b/engines/saga2/task.cpp
index 06f8863bab..336a77c585 100644
--- a/engines/saga2/task.cpp
+++ b/engines/saga2/task.cpp
@@ -483,6 +483,14 @@ void TaskList::read(Common::InSaveFile *in) {
 
 		readTask(id, in);
 	}
+
+	//	Iterate through the Tasks to fixup the subtask pointers
+	for (int i = 0; i < numTasks; ++i) {
+		if (_list[i] == nullptr)
+			continue;
+
+		_list[i]->fixup();
+	}
 }
 
 //----------------------------------------------------------------------
@@ -742,11 +750,18 @@ void writeTask(Task *t, Common::OutSaveFile *out) {
 
 Task::Task(Common::InSaveFile *in, TaskID id) {
 	//  Place the stack ID into the stack pointer field
-	int16 stackID = in->readSint16LE();
-	stack = getTaskStackAddress(stackID);
+	_stackID = in->readSint16LE();
 	newTask(this, id);
 }
 
+//----------------------------------------------------------------------
+//	Fixup the Task pointers
+
+void Task::fixup(void) {
+	//	Convert the stack ID to a stack pointer
+	stack = getTaskStackAddress(_stackID);
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes necessary to create an archive of this
 //	object's data
@@ -884,10 +899,20 @@ TetheredWanderTask::TetheredWanderTask(Common::InSaveFile *in, TaskID id) : Wand
 	maxV = in->readSint16LE();
 
 	//  Put the gotoTether ID into the gotoTether pointer field
-	int gotoTetherID = in->readSint16LE();
-	gotoTether = gotoTetherID != NoTask
-	             ? (GotoRegionTask *)getTaskAddress(gotoTetherID)
-	             :   NULL;
+	_gotoTetherID = in->readSint16LE();
+}
+
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void TetheredWanderTask::fixup(void) {
+	//	Let the base class fixup it's pointers
+	WanderTask::fixup();
+
+	//	Restore the gotoTether pointer
+	gotoTether = _gotoTetherID != NoTask
+				 ?	(GotoRegionTask *)getTaskAddress(_gotoTetherID)
+				 :	NULL;
 }
 
 //----------------------------------------------------------------------
@@ -1036,15 +1061,25 @@ TaskResult TetheredWanderTask::handleWander(void) {
 
 GotoTask::GotoTask(Common::InSaveFile *in, TaskID id) : Task(in, id) {
 	//  Get the wander TaskID
-	TaskID wanderID = in->readSint16LE();
-	wander = wanderID != NoTask
-	         ? (WanderTask *)getTaskAddress(wanderID)
-	         :   NULL;
+	_wanderID = in->readSint16LE();
 
 	//  Restore prevRunState
 	prevRunState = in->readByte();
 }
 
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void GotoTask::fixup(void) {
+	//	Let the base class fixup its pointers
+	Task::fixup();
+
+	//	Convert wanderID to a Task pointer
+	wander = _wanderID != NoTask
+	         ? (WanderTask *)getTaskAddress(_wanderID)
+	         :   NULL;
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this object in
 //	a buffer
@@ -1640,15 +1675,24 @@ bool GotoActorTask::run(void) {
 
 GoAwayFromTask::GoAwayFromTask(Common::InSaveFile *in, TaskID id) : Task(in, id) {
 	//  Get the subtask ID
-	TaskID goTaskID = in->readSint16LE();
-	goTask = goTaskID != NoTask
-	         ? (GotoLocationTask *)getTaskAddress(goTaskID)
-	         :   NULL;
+	_goTaskID = in->readSint16LE();
 
 	//  Restore the flags
 	flags = in->readByte();
 }
 
+//----------------------------------------------------------------------
+//	Fixup the subtask pointer
+
+void GoAwayFromTask::fixup(void) {
+		//	Let the base class fixup its pointers
+	Task::fixup();
+
+	goTask = _goTaskID != NoTask
+	         ? (GotoLocationTask *)getTaskAddress(_goTaskID)
+	         :   NULL;
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this object in
 //	a buffer
@@ -1920,12 +1964,23 @@ HuntTask::HuntTask(Common::InSaveFile *in, TaskID id) : Task(in, id) {
 	huntFlags = in->readByte();
 
 	//  If the flags say we have a sub task, restore it too
-	if (huntFlags & (huntGoto | huntWander)) {
-		TaskID subTaskID = in->readSint16LE();
-		subTask = getTaskAddress(subTaskID);
-	} else {
+	if (huntFlags & (huntGoto | huntWander))
+		_subTaskID = in->readSint16LE();
+	else
+		_subTaskID = NoTask;
+}
+
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void HuntTask::fixup( void ) {
+	//	Let the base class fixup its pointers
+	Task::fixup();
+
+	if (huntFlags & (huntGoto | huntWander))
+		subTask = getTaskAddress(_subTaskID);
+	else
 		subTask = nullptr;
-	}
 }
 
 //----------------------------------------------------------------------
@@ -2684,12 +2739,7 @@ HuntToBeNearActorTask::HuntToBeNearActorTask(Common::InSaveFile *in, TaskID id)
 	debugC(3, kDebugSaveload, "... Loading HuntToBeNearActorTask");
 
 	//  Get the goAway task ID
-	TaskID goAwayID = in->readSint16LE();
-
-	//  Convert the task ID to a task pointer
-	goAway = goAwayID != NoTask
-	         ? (GoAwayFromObjectTask *)getTaskAddress(goAwayID)
-	         :   NULL;
+	_goAwayID = in->readSint16LE();
 
 	//  Restore the range
 	range = in->readUint16LE();
@@ -2698,6 +2748,19 @@ HuntToBeNearActorTask::HuntToBeNearActorTask(Common::InSaveFile *in, TaskID id)
 	targetEvaluateCtr = in->readByte();
 }
 
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void HuntToBeNearActorTask::fixup(void) {
+		//	Let the base class fixup its pointers
+	HuntActorTask::fixup();
+
+	//  Convert the task ID to a task pointer
+	goAway = _goAwayID != NoTask
+	         ? (GoAwayFromObjectTask *)getTaskAddress(_goAwayID)
+	         :   NULL;
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this object in
 //	a buffer
@@ -3401,14 +3464,9 @@ bool BandTask::BandingRepulsorIterator::next(
 }
 
 BandTask::BandTask(Common::InSaveFile *in, TaskID id) : HuntTask(in, id) {
-	TaskID attendID = in->readSint16LE();
 	debugC(3, kDebugSaveload, "... Loading BandTask");
 
-
-	//  Convert the TaskID to a Task pointer
-	attend = attendID != NoTask
-	         ? (AttendTask *)getTaskAddress(attendID)
-	         :   NULL;
+	_attendID = in->readSint16LE();
 
 	//  Restore the current target location
 	currentTarget.load(in);
@@ -3417,6 +3475,19 @@ BandTask::BandTask(Common::InSaveFile *in, TaskID id) : HuntTask(in, id) {
 	targetEvaluateCtr = in->readByte();
 }
 
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void BandTask::fixup(void) {
+	//	Let the base class fixup its pointers
+	HuntTask::fixup();
+
+	//  Convert the TaskID to a Task pointer
+	attend = _attendID != NoTask
+	         ? (AttendTask *)getTaskAddress(_attendID)
+	         :   NULL;
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this object in
 //	a buffer
@@ -3769,12 +3840,8 @@ FollowPatrolRouteTask::FollowPatrolRouteTask(Common::InSaveFile *in, TaskID id)
 	debugC(3, kDebugSaveload, "... Loading FollowPatrolRouteTask");
 
 	//  Get the gotoWayPoint TaskID
-	TaskID gotoWayPointID = in->readSint16LE();
+	_gotoWayPointID = in->readSint16LE();
 
-	//  Convert the TaskID to a Task pointer
-	gotoWayPoint = gotoWayPointID != NoTask
-	               ? (GotoLocationTask *)getTaskAddress(gotoWayPointID)
-	               :   NULL;
 
 	//  Restore the patrol route iterator
 	patrolIter.read(in);
@@ -3789,6 +3856,19 @@ FollowPatrolRouteTask::FollowPatrolRouteTask(Common::InSaveFile *in, TaskID id)
 	counter = in->readSint16LE();
 }
 
+//----------------------------------------------------------------------
+//	Fixup the subtask pointers
+
+void FollowPatrolRouteTask::fixup(void) {
+	//	Let the base class fixup its pointers
+	Task::fixup();
+
+	//  Convert the TaskID to a Task pointer
+	gotoWayPoint = _gotoWayPointID != NoTask
+	               ? (GotoLocationTask *)getTaskAddress(_gotoWayPointID)
+	               :   NULL;
+}
+
 //----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this object in
 //	a buffer
diff --git a/engines/saga2/task.h b/engines/saga2/task.h
index a8b2e84f88..e7c072c07a 100644
--- a/engines/saga2/task.h
+++ b/engines/saga2/task.h
@@ -125,12 +125,13 @@ class Task {
 protected:
 	//  A pointer to this task's stack
 	TaskStack   *stack;
+	TaskStackID _stackID;
 
 public:
 	Common::String _type;
 
 	//  Constructor -- initial construction
-	Task(TaskStack *ts) : stack(ts) {
+	Task(TaskStack *ts) : stack(ts), _stackID(NoTaskStack) {
 		newTask(this);
 	}
 
@@ -145,6 +146,9 @@ public:
 		deleteTask(this);
 	}
 
+	//	Fixup any subtask pointers
+	virtual void fixup(void);
+
 	//  Return the number of bytes necessary to archive this Task
 	//  in a buffer
 	virtual int32 archiveSize(void) const;
@@ -234,6 +238,7 @@ class TetheredWanderTask : public WanderTask {
 
 	//  Pointer to subtask for going to the tether region
 	GotoRegionTask  *gotoTether;
+	TaskID _gotoTetherID;
 
 public:
 	//  Constructor
@@ -248,13 +253,17 @@ public:
 		minV(vMin),
 		maxU(uMax),
 		maxV(vMax),
-		gotoTether(NULL) {
+		gotoTether(NULL),
+		_gotoTetherID(NoTask) {
 		debugC(2, kDebugTasks, " - TetheredWanderTask");
 		_type = "TetheredWanderTask";
 	}
 
 	TetheredWanderTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointers
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;
@@ -285,6 +294,7 @@ public:
 
 class GotoTask : public Task {
 	WanderTask  *wander;
+	TaskID _wanderID;
 	bool        prevRunState;
 
 public:
@@ -292,6 +302,7 @@ public:
 	GotoTask(TaskStack *ts) :
 		Task(ts),
 		wander(NULL),
+		_wanderID(NoTask),
 		prevRunState(false) {
 		debugC(2, kDebugTasks, " - GotoTask");
 		_type = "GotoTask";
@@ -571,6 +582,7 @@ private:
 
 class GoAwayFromTask : public Task {
 	GotoLocationTask        *goTask;
+	TaskID _goTaskID;
 
 	uint8                   flags;
 
@@ -583,6 +595,7 @@ public:
 	GoAwayFromTask(TaskStack *ts) :
 		Task(ts),
 		goTask(NULL),
+		_goTaskID(NoTask),
 		flags(0) {
 		debugC(2, kDebugTasks, " - GoAwayFromTask1");
 		_type = "GoAwayFromTask";
@@ -591,6 +604,7 @@ public:
 	GoAwayFromTask(TaskStack *ts, bool runFlag) :
 		Task(ts),
 		goTask(NULL),
+		_goTaskID(NoTask),
 		flags(runFlag ? run : 0) {
 		debugC(2, kDebugTasks, " - GoAwayFromTask2");
 		_type = "GoAwayFromTask";
@@ -598,6 +612,9 @@ public:
 
 	GoAwayFromTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointer
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;
@@ -698,6 +715,7 @@ private:
 
 class HuntTask : public Task {
 	Task            *subTask;   //  This will either be a wander task of a
+	TaskID _subTaskID;
 	//  goto task
 	uint8           huntFlags;
 
@@ -708,13 +726,16 @@ class HuntTask : public Task {
 
 public:
 	//  Constructor -- initial construction
-	HuntTask(TaskStack *ts) : Task(ts), huntFlags(0), subTask(nullptr) {
+	HuntTask(TaskStack *ts) : Task(ts), huntFlags(0), subTask(nullptr), _subTaskID(NoTask) {
 		debugC(2, kDebugTasks, " - HuntTask");
 		_type = "HuntTask";
 	}
 
 	HuntTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointer
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;
@@ -1023,6 +1044,7 @@ protected:
 
 class HuntToBeNearActorTask : public HuntActorTask {
 	GoAwayFromObjectTask    *goAway;    //  The 'go away' sub task pointer
+	TaskID _goAwayID;
 	uint16                  range;      //  Maximum range
 
 	uint8                   targetEvaluateCtr;
@@ -1046,6 +1068,7 @@ public:
 	    bool                trackFlag = false) :
 		HuntActorTask(ts, at, trackFlag),
 		goAway(NULL),
+		_goAwayID(NoTask),
 		range(MAX<uint16>(r, 16)),
 		targetEvaluateCtr(0) {
 		debugC(2, kDebugTasks, " - HuntToBeNearActorTask");
@@ -1054,6 +1077,9 @@ public:
 
 	HuntToBeNearActorTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointer
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;
@@ -1205,6 +1231,7 @@ class AttendTask;
 
 class BandTask : public HuntTask {
 	AttendTask          *attend;
+	TaskID _attendID;
 
 	TilePoint           currentTarget;
 	uint8               targetEvaluateCtr;
@@ -1291,6 +1318,7 @@ public:
 	BandTask(TaskStack *ts) :
 		HuntTask(ts),
 		attend(NULL),
+		_attendID(NoTask),
 		currentTarget(Nowhere),
 		targetEvaluateCtr(0) {
 		debugC(2, kDebugTasks, " - BandTask");
@@ -1299,6 +1327,9 @@ public:
 
 	BandTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointer
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;
@@ -1396,6 +1427,7 @@ protected:
 
 class FollowPatrolRouteTask : public Task {
 	GotoLocationTask        *gotoWayPoint;  //  A goto waypoint sub task
+	TaskID _gotoWayPointID;
 	//  pointer.
 	PatrolRouteIterator     patrolIter;     //  The patrol route iterator.
 	int16                   lastWayPointNum;    //  Waypoint at which to end
@@ -1413,6 +1445,7 @@ public:
 	    int16               stopAt = -1) :
 		Task(ts),
 		gotoWayPoint(NULL),
+		_gotoWayPointID(NoTask),
 		patrolIter(iter),
 		lastWayPointNum(stopAt), counter(0) {
 		debugC(2, kDebugTasks, " - FollowPatrolRouteTask");
@@ -1422,6 +1455,9 @@ public:
 
 	FollowPatrolRouteTask(Common::InSaveFile *in, TaskID id);
 
+	//	Fixup the subtask pointer
+	void fixup(void);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void) const;




More information about the Scummvm-git-logs mailing list