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

a-yyg 76591232+a-yyg at users.noreply.github.com
Fri Jul 9 04:02:18 UTC 2021


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

Summary:
42a2c7bc4b SAGA2: Move mTaskList to Saga2Engine
6ad3058c1a SAGA2: Implement MotionTasks save/loading
b882744405 SAGA2: Remove placement-new for threadList


Commit: 42a2c7bc4bafb84ccca9b69de11fe422e245c4f7
    https://github.com/scummvm/scummvm/commit/42a2c7bc4bafb84ccca9b69de11fe422e245c4f7
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T12:59:41+09:00

Commit Message:
SAGA2: Move mTaskList to Saga2Engine

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


diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 650c16b3d6..9f1c3ebb06 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -33,8 +33,10 @@
 #include "engines/util.h"
 
 #include "saga2/saga2.h"
+#include "saga2/fta.h"
 
 #include "saga2/gdraw.h"
+#include "saga2/motion.h"
 #include "saga2/mouseimg.h"
 #include "saga2/contain.h"
 #include "saga2/imagcach.h"
@@ -72,6 +74,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	_loadedWeapons = 0;
 
 	_imageCache = new CImageCache;
+	_mTaskList = new MotionTaskList;
 }
 
 Saga2Engine::~Saga2Engine() {
@@ -82,6 +85,7 @@ Saga2Engine::~Saga2Engine() {
 	// Dispose your resources here
 	delete _rnd;
 	delete _imageCache;
+	delete _mTaskList;
 }
 
 Common::Error Saga2Engine::run() {
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index 601326aac2..fa2618ed5f 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -47,6 +47,7 @@ class BandList;
 class ActorAppearance;
 class PathRequest;
 class MotionTask;
+class MotionTaskList;
 class GrabInfo;
 class CImageCache;
 class SensorList;
@@ -113,6 +114,7 @@ public:
 	Common::List<MotionTask *>::iterator _nextMT;
 	Common::List<int> _platformLRU;
 	BandList *_bandList;
+	MotionTaskList *_mTaskList;
 	CImageCache *_imageCache;
 	GrabInfo *_mouseInfo;
 	EffectDisplayPrototypeList *_edpList;


Commit: 6ad3058c1a7fd133cc74b7f5ca20261cb3b2507e
    https://github.com/scummvm/scummvm/commit/6ad3058c1a7fd133cc74b7f5ca20261cb3b2507e
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T12:59:41+09:00

Commit Message:
SAGA2: Implement MotionTasks save/loading

Changed paths:
    engines/saga2/loadsave.cpp
    engines/saga2/motion.cpp
    engines/saga2/motion.h


diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index 98b246902f..9879be4622 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -156,9 +156,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveTileCyclingStates(out);
 	saveSAGADataSeg(out);
 	saveSAGAThreads(out);
+	saveMotionTasks(out);
 
 #if 0
-	saveMotionTasks(saveGame);
 	saveTaskStacks(saveGame);
 	saveTasks(saveGame);
 	saveTileTasks(saveGame);
@@ -306,15 +306,15 @@ void loadSavedGameState(int16 saveNo) {
 			loadSAGAThreads(in, chunkSize);
 			loadFlags |= loadSAGAThreadsFlag;
 			break;
-#if 0
 
 		case MKTAG('M', 'O', 'T', 'N'):
 			if (!(~loadFlags & (loadActorsFlag | loadObjectsFlag))) {
-				loadMotionTasks(saveGame);
+				loadMotionTasks(in, chunkSize);
 				loadFlags |= loadMotionTasksFlag;
 			} else
 				error("MotionTasks loaded prematurely");
 			break;
+#if 0
 
 		case MKTAG('T', 'S', 'T', 'K'):
 			if (loadFlags & loadActorsFlag) {
diff --git a/engines/saga2/motion.cpp b/engines/saga2/motion.cpp
index 127be79b25..9dbd888f4b 100644
--- a/engines/saga2/motion.cpp
+++ b/engines/saga2/motion.cpp
@@ -347,11 +347,6 @@ uint8 computeTurnFrames(Direction fromDir, Direction toDir) {
    MotionTaskList member functions
  * ===================================================================== */
 
-//-----------------------------------------------------------------------
-//	The list of active motion tasks for all actors
-
-static MotionTaskList *mTaskList;
-
 //-----------------------------------------------------------------------
 //	Initialize the MotionTaskList
 
@@ -396,6 +391,26 @@ MotionTaskList::MotionTaskList(void **buf) {
 #endif
 }
 
+MotionTaskList::MotionTaskList(Common::SeekableReadStream *stream) {
+	read(stream);
+}
+
+
+void MotionTaskList::read(Common::InSaveFile *in) {
+	int16 motionTaskCount;
+	//  Retrieve the motion task count
+	motionTaskCount = in->readSint16LE();
+
+	for (int i = 0; i < motionTaskCount; i++) {
+		MotionTask *mt;
+
+		mt = new MotionTask;
+		_list.push_back(mt);
+
+		mt->read(in);
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Return the number of bytes needed to archive the motion tasks
 //	in a buffer
@@ -427,6 +442,17 @@ void *MotionTaskList::archive(void *buf) {
 	return buf;
 }
 
+void MotionTaskList::write(Common::OutSaveFile *out) {
+	int16 motionTaskCount = _list.size();
+
+	//  Store the motion task count
+	out->writeSint16LE(motionTaskCount);
+
+	//  Archive the active motion tasks
+	for (Common::List<MotionTask *>::iterator it = _list.begin(); it != _list.end(); ++it)
+		(*it)->write(out);
+}
+
 //-----------------------------------------------------------------------
 //	Cleanup the motion tasks
 
@@ -776,6 +802,257 @@ void *MotionTask::restore(void *buf) {
 	return buf;
 }
 
+void MotionTask::read(Common::InSaveFile *in) {
+	ObjectID    objectID;
+
+	//  Restore the motion type and previous motion type
+	motionType = in->readByte();
+	prevMotionType = in->readByte();
+
+	//  Restore the thread ID
+	thread = in->readSint16LE();
+
+	//  Restore the motion flags
+	flags = in->readUint16LE();
+
+	//  Get the object ID
+	objectID = in->readUint16LE();
+
+	//  Convert the object ID to and object address
+	object =    objectID != Nothing
+	            ?   GameObject::objectAddress(objectID)
+	            :   NULL;
+
+	//  If the object is an actor, plug this motion task into the actor
+	if (object && isActor(object))
+		((Actor *)object)->moveTask = this;
+
+	if (motionType == motionTypeWalk
+	        ||  prevMotionType == motionTypeWalk) {
+		//  Restore the target _data.locations
+		immediateLocation.load(in);
+		finalTarget.load(in);
+
+		//  If there is a tether restore it
+		if (flags & tethered) {
+			tetherMinU = in->readSint16LE();
+			tetherMinV = in->readSint16LE();
+			tetherMaxU = in->readSint16LE();
+			tetherMaxV = in->readSint16LE();
+		}
+
+		//  Restore the direction
+		direction = in->readByte();
+
+		//  Restore the path index and path count
+		pathIndex = in->readSint16LE();
+		pathCount = in->readSint16LE();
+		runCount = in->readSint16LE();
+
+		//  Restore the action counter if needed
+		if (flags & agitated)
+			actionCounter = in->readSint16LE();
+
+		//  If there were valid path way points, restore those
+		if (pathIndex >= 0 && pathIndex < pathCount) {
+			int16 wayPointIndex = pathIndex;
+
+			while (wayPointIndex < pathCount) {
+				pathList[wayPointIndex].load(in);
+
+				wayPointIndex++;
+			}
+		}
+
+		//  If this motion task previously had a path finding request
+		//  it must be restarted
+		pathFindTask = NULL;
+	}
+
+	if (motionType == motionTypeThrown || motionType == motionTypeShot) {
+		//  Restore the velocity
+		velocity.load(in);
+
+		//  Restore other ballistic motion variables
+		steps = in->readSint16LE();
+		uFrac = in->readSint16LE();
+		vFrac = in->readSint16LE();
+		uErrorTerm = in->readSint16LE();
+		vErrorTerm = in->readSint16LE();
+
+		if (motionType == motionTypeShot) {
+			ObjectID targetObjID,
+			         enactorID;
+
+			targetObjID = in->readUint16LE();
+
+			targetObj = targetObjID
+			            ?   GameObject::objectAddress(targetObjID)
+			            :   NULL;
+
+			enactorID = in->readUint16LE();
+
+			o.enactor = enactorID != Nothing
+			            ? (Actor *)GameObject::objectAddress(enactorID)
+			            :   NULL;
+		}
+	} else if (motionType == motionTypeClimbUp
+	           ||  motionType == motionTypeClimbDown) {
+		immediateLocation.load(in);
+	} else if (motionType == motionTypeJump) {
+		velocity.load(in);
+	} else if (motionType == motionTypeTurn) {
+		direction = in->readByte();
+	} else if (motionType == motionTypeGive) {
+		ObjectID id = in->readUint16LE();
+		targetObj = id != Nothing
+		            ?   GameObject::objectAddress(id)
+		            :   NULL;
+	} else if (motionType == motionTypeWait) {
+		actionCounter = in->readSint16LE();
+	} else if (motionType == motionTypeUseObject
+	           ||  motionType == motionTypeUseObjectOnObject
+	           ||  motionType == motionTypeUseObjectOnTAI
+	           ||  motionType == motionTypeUseObjectOnLocation
+	           ||  motionType == motionTypeDropObject
+	           ||  motionType == motionTypeDropObjectOnObject
+	           ||  motionType == motionTypeDropObjectOnTAI) {
+	    ObjectID directObjID = in->readUint16LE();
+		o.directObject = directObjID != Nothing
+		                ?   GameObject::objectAddress(directObjID)
+		                :   NULL;
+
+		direction = in->readByte();
+
+		if (motionType == motionTypeUseObjectOnObject
+		        ||  motionType == motionTypeDropObjectOnObject) {
+		    ObjectID indirectObjID = in->readUint16LE();
+			o.indirectObject =  indirectObjID != Nothing
+			                    ?   GameObject::objectAddress(indirectObjID)
+			                    :   NULL;
+		} else {
+			if (motionType == motionTypeUseObjectOnTAI
+			        ||  motionType == motionTypeDropObjectOnTAI) {
+			    ActiveItemID tai(in->readSint16LE());
+				o.TAI = tai != NoActiveItem
+				        ?   ActiveItem::activeItemAddress(tai)
+				        :   NULL;
+			}
+
+			if (motionType == motionTypeUseObjectOnLocation
+			        ||  motionType == motionTypeDropObject
+			        ||  motionType == motionTypeDropObjectOnTAI) {
+				targetLoc.load(in);
+			}
+		}
+	} else if (motionType == motionTypeUseTAI) {
+		ActiveItemID tai(in->readSint16LE());
+		o.TAI = tai != NoActiveItem
+		        ?   ActiveItem::activeItemAddress(tai)
+		        :   NULL;
+
+		direction = in->readByte();
+	} else if (motionType == motionTypeTwoHandedSwing
+	           ||  motionType == motionTypeOneHandedSwing
+	           ||  motionType == motionTypeFireBow
+	           ||  motionType == motionTypeCastSpell
+	           ||  motionType == motionTypeUseWand) {
+		ObjectID    targetObjID;
+
+		//  Restore the direction
+		direction = in->readByte();
+
+		//  Restore the combat motion type
+		combatMotionType = in->readByte();
+
+		//  Get the target object ID
+		targetObjID = in->readUint16LE();
+
+		//  Convert the target object ID to a pointer
+		targetObj = targetObjID != Nothing
+		            ?   GameObject::objectAddress(targetObjID)
+		            :   NULL;
+
+		if (motionType == motionTypeCastSpell) {
+			SpellID sid       ;
+			ObjectID toid     ;
+			ActiveItemID ttaid;
+
+			//  restore the spell prototype
+			warning("MotionTask::read: Check SpellID size");
+			sid = (SpellID)in->readUint32LE();
+			spellObj = sid != nullSpell
+			           ? skillProtoFromID(sid)
+			           : NULL;
+
+			//  restore object target
+			toid = in->readUint16LE();
+			targetObj = toid != Nothing
+			            ?   GameObject::objectAddress(toid)
+			            :   NULL;
+
+			//  restore TAG target
+			ttaid = in->readSint16LE();
+			targetTAG = ttaid != NoActiveItem
+			            ?  ActiveItem::activeItemAddress(ttaid)
+			            :  NULL;
+
+			//  restore _data.location target
+			targetLoc.load(in);
+		}
+
+		//  Restore the action counter
+		actionCounter = in->readSint16LE();
+	} else if (motionType == motionTypeTwoHandedParry
+	           ||  motionType == motionTypeOneHandedParry
+	           ||  motionType == motionTypeShieldParry) {
+		ObjectID attackerID,
+		         defensiveObjID;
+
+		//  Restore the direction
+		direction = in->readByte();
+
+		//  Get the attacker's and defensive object's IDs
+		attackerID = in->readByte();
+		defensiveObjID = in->readByte();
+
+		//  Convert IDs to pointers
+		d.attacker = attackerID != Nothing
+		            ? (Actor *)GameObject::objectAddress(attackerID)
+		            :   NULL;
+
+		d.defensiveObj = defensiveObjID != Nothing
+		                ?   GameObject::objectAddress(defensiveObjID)
+		                :   NULL;
+
+		//  Restore the defense flags
+		d.defenseFlags = in->readByte();
+
+		//  Restore the action counter
+		actionCounter = in->readSint16LE();
+
+		if (motionType == motionTypeOneHandedParry) {
+			//  Restore the combat sub-motion type
+			combatMotionType = in->readByte();
+		}
+	} else if (motionType == motionTypeDodge
+	           ||  motionType == motionTypeAcceptHit
+	           ||  motionType == motionTypeFallDown) {
+		ObjectID        attackerID;
+
+		//  Get the attacker's ID
+		attackerID = in->readUint16LE();
+
+		//  Convert ID to pointer
+		d.attacker = attackerID != Nothing
+		            ? (Actor *)GameObject::objectAddress(attackerID)
+		            :   NULL;
+
+		//  Restore the action counter
+		actionCounter = in->readSint16LE();
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Return the number of bytes needed to archive this MotionTask
 
@@ -1171,11 +1448,241 @@ void *MotionTask::archive(void *buf) {
 	return buf;
 }
 
+void MotionTask::write(Common::OutSaveFile *out) {
+	ObjectID    objectID;
+
+	//  Store the motion type and previous motion type
+	out->writeByte(motionType);
+	out->writeByte(prevMotionType);
+
+	//  Store the thread ID
+	out->writeSint16LE(thread);
+
+	//  Store the motion flags
+	out->writeUint16LE(flags);
+
+	//  Convert the object pointer to an object ID
+	objectID = object != NULL ? object->thisID() : Nothing;
+
+	//  Store the object ID
+	out->writeUint16LE(objectID);
+
+	if (motionType == motionTypeWalk
+	        ||  prevMotionType == motionTypeWalk) {
+		//  Store the target _data.locations
+		immediateLocation.write(out);
+		finalTarget.write(out);
+
+		//  If there is a tether store it
+		if (flags & tethered) {
+			out->writeSint16LE(tetherMinU);
+			out->writeSint16LE(tetherMinV);
+			out->writeSint16LE(tetherMaxU);
+			out->writeSint16LE(tetherMaxV);
+		}
+
+		//  Store the direction
+		out->writeByte(direction);
+
+		//  Store the path index and path count
+		out->writeSint16LE(pathIndex);
+		out->writeSint16LE(pathCount);
+		out->writeSint16LE(runCount);
+
+		//  Store the action counter if needed
+		if (flags & agitated)
+			out->writeSint16LE(actionCounter);
+
+		//  If there are valid path way points, store them
+		if (pathIndex >= 0 && pathIndex < pathCount) {
+			int16   wayPointIndex = pathIndex;
+
+			while (wayPointIndex < pathCount) {
+				pathList[wayPointIndex].write(out);
+
+				wayPointIndex++;
+			}
+		}
+	}
+
+	if (motionType == motionTypeThrown || motionType == motionTypeShot) {
+		//  Store the velocity
+		velocity.write(out);
+
+		//  Store other ballistic motion variables
+		out->writeSint16LE(steps);
+		out->writeSint16LE(uFrac);
+		out->writeSint16LE(vFrac);
+		out->writeSint16LE(uErrorTerm);
+		out->writeSint16LE(vErrorTerm);
+
+		if (motionType == motionTypeShot) {
+			ObjectID        targetObjID,
+			                enactorID;
+
+			targetObjID =   targetObj != NULL
+			                ?   targetObj->thisID()
+			                :   Nothing;
+
+			out->writeUint16LE(targetObjID);
+
+			enactorID = o.enactor != NULL
+			            ?   o.enactor->thisID()
+			            :   Nothing;
+
+			out->writeUint16LE(enactorID);
+		}
+	} else if (motionType == motionTypeClimbUp
+	           ||  motionType == motionTypeClimbDown) {
+		immediateLocation.write(out);
+	} else if (motionType == motionTypeJump) {
+		velocity.write(out);
+	} else if (motionType == motionTypeTurn) {
+		out->writeByte(direction);
+	} else if (motionType == motionTypeGive) {
+		if (targetObj != NULL)
+			out->writeUint16LE(targetObj->thisID());
+		else
+			out->writeUint16LE(Nothing);
+	} else if (motionType == motionTypeUseObject
+	           ||  motionType == motionTypeUseObjectOnObject
+	           ||  motionType == motionTypeUseObjectOnTAI
+	           ||  motionType == motionTypeUseObjectOnLocation
+	           ||  motionType == motionTypeDropObject
+	           ||  motionType == motionTypeDropObjectOnObject
+	           ||  motionType == motionTypeDropObjectOnTAI) {
+		if (o.directObject != NULL)
+			out->writeUint16LE(o.directObject->thisID());
+		else
+			out->writeUint16LE(Nothing);
+
+		out->writeByte(direction);
+
+		if (motionType == motionTypeUseObjectOnObject
+		        ||  motionType == motionTypeDropObjectOnObject) {
+			if (o.indirectObject != NULL)
+				out->writeUint16LE(o.indirectObject->thisID());
+			else
+				out->writeUint16LE(Nothing);
+		} else {
+			if (motionType == motionTypeUseObjectOnTAI
+			        ||  motionType == motionTypeDropObjectOnTAI) {
+				if (o.TAI != NULL)
+					out->writeSint16LE(o.TAI->thisID());
+				else
+					out->writeSint16LE(NoActiveItem.val);
+			}
+
+			if (motionType == motionTypeUseObjectOnLocation
+			        ||  motionType == motionTypeDropObject
+			        ||  motionType == motionTypeDropObjectOnTAI) {
+				targetLoc.write(out);
+			}
+		}
+	} else if (motionType == motionTypeUseTAI) {
+		if (o.TAI != NULL)
+			out->writeSint16LE(o.TAI->thisID());
+		else
+			out->writeSint16LE(NoActiveItem.val);
+
+		out->writeByte(direction);
+	} else if (motionType == motionTypeTwoHandedSwing
+	           ||  motionType == motionTypeOneHandedSwing
+	           ||  motionType == motionTypeFireBow
+	           ||  motionType == motionTypeCastSpell
+	           ||  motionType == motionTypeUseWand) {
+		ObjectID    targetObjID;
+
+		//  Store the direction
+		out->writeByte(direction);
+
+		//  Store the combat motion type
+		out->writeByte(combatMotionType);
+
+		//  Convert the target object pointer to an ID
+		targetObjID = targetObj != NULL ? targetObj->thisID() : Nothing;
+
+		//  Store the target object ID
+		out->writeUint16LE(targetObjID);
+
+		if (motionType == motionTypeCastSpell) {
+			//  Convert the spell object pointer to an ID
+
+			SpellID sid         = spellObj != NULL
+			                      ? spellObj->getSpellID()
+			                      : nullSpell;
+
+			ObjectID toid       = targetObj != NULL
+			                      ? targetObj->thisID()
+			                      : Nothing;
+
+			ActiveItemID ttaid  = targetTAG != NULL
+			                      ? targetTAG->thisID()
+			                      : NoActiveItem;
+
+			//  Store the spell prototype
+			warning("MotionTask::write: Check SpellID size");
+			out->writeUint32LE(sid);
+
+			//  Store object target
+			out->writeUint16LE(toid);
+
+			//  Store TAG target
+			out->writeSint16LE(ttaid.val);
+
+			//  Store _data.location target
+			targetLoc.write(out);
+		}
+
+		//  Store the action counter
+		out->writeSint16LE(actionCounter);
+
+	} else if (motionType == motionTypeTwoHandedParry
+	           ||  motionType == motionTypeOneHandedParry
+	           ||  motionType == motionTypeShieldParry) {
+		ObjectID        attackerID,
+		                defensiveObjID;
+
+		//  Store the direction
+		out->writeByte(direction);
+
+		attackerID = d.attacker != NULL ? d.attacker->thisID() : Nothing;
+		defensiveObjID = d.defensiveObj != NULL ? d.defensiveObj->thisID() : Nothing;
+
+		//  Store the attacker's and defensive object's IDs
+		out->writeUint16LE(attackerID);
+		out->writeUint16LE(defensiveObjID);
+
+		//  Store the defense flags
+		out->writeByte(d.defenseFlags);
+
+		//  Store the action counter
+		out->writeSint16LE(actionCounter);
+
+		if (motionType == motionTypeOneHandedParry) {
+			//  Store the combat sub-motion type
+			out->writeByte(combatMotionType);
+		}
+	} else if (motionType == motionTypeDodge
+	           ||  motionType == motionTypeAcceptHit
+	           ||  motionType == motionTypeFallDown) {
+		ObjectID        attackerID;
+
+		attackerID = d.attacker != NULL ? d.attacker->thisID() : Nothing;
+
+		//  Store the attacker's ID
+		out->writeUint16LE(attackerID);
+
+		//  Store the action counter
+		out->writeSint16LE(actionCounter);
+	}
+}
+
 //-----------------------------------------------------------------------
 //	When a motion task is finished, call this function to delete it.
 
 void MotionTask::remove(int16 returnVal) {
-	if (g_vm->_nextMT != mTaskList->_list.end() && *(g_vm->_nextMT) == this)
+	if (g_vm->_nextMT != g_vm->_mTaskList->_list.end() && *(g_vm->_nextMT) == this)
 		++g_vm->_nextMT;
 
 	object->_data.objectFlags &= ~objectMoving;
@@ -1196,7 +1703,7 @@ void MotionTask::remove(int16 returnVal) {
 			a->setInterruptablity(true);
 	}
 
-	mTaskList->_list.remove(this);
+	g_vm->_mTaskList->_list.remove(this);
 
 	abortPathFind(this);
 	pathFindTask = NULL;
@@ -1264,7 +1771,7 @@ void MotionTask::turn(Actor &obj, Direction dir) {
 
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&obj)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&obj)) != NULL) {
 		mt->direction = dir;
 		mt->motionType = motionTypeTurn;
 		mt->flags = reset;
@@ -1277,7 +1784,7 @@ void MotionTask::turn(Actor &obj, Direction dir) {
 void MotionTask::turnTowards(Actor &obj, const TilePoint &where) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&obj)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&obj)) != NULL) {
 		mt->direction = (where - obj.getLocation()).quickDir();
 		mt->motionType = motionTypeTurn;
 		mt->flags = reset;
@@ -1291,7 +1798,7 @@ void MotionTask::turnTowards(Actor &obj, const TilePoint &where) {
 void MotionTask::give(Actor &actor, Actor &givee) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		mt->targetObj = &givee;
 		mt->motionType = motionTypeGive;
 		mt->flags = reset;
@@ -1304,7 +1811,7 @@ void MotionTask::give(Actor &actor, Actor &givee) {
 void MotionTask::throwObject(GameObject &obj, const TilePoint &velocity) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&obj)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&obj)) != NULL) {
 		if (obj.isMissile()) obj._data.missileFacing = missileNoFacing;
 		mt->velocity = velocity;
 		mt->motionType = motionTypeThrown;
@@ -1322,7 +1829,7 @@ void MotionTask::throwObjectTo(GameObject &obj, const TilePoint &where) {
 	MotionTask      *mt;
 	const int16     turns = 15;
 
-	if ((mt = mTaskList->newTask(&obj)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&obj)) != NULL) {
 		if (obj.isMissile()) obj._data.missileFacing = missileNoFacing;
 		mt->calcVelocity(where - obj.getLocation(), turns);
 		mt->motionType = motionTypeThrown;
@@ -1340,7 +1847,7 @@ void MotionTask::shootObject(
     int16 speed) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&obj)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&obj)) != NULL) {
 		TilePoint   targetLoc = target.getLocation();
 
 		targetLoc.z += target.proto()->height / 2;
@@ -1380,7 +1887,7 @@ void MotionTask::walkTo(
     bool            canAgitate) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (!mt->isReflex() && !actor.isImmobile()) {
 			unstickObject(&actor);
 			mt->finalTarget = mt->immediateLocation = target;
@@ -1409,7 +1916,7 @@ void MotionTask::walkToDirect(
     bool            canAgitate) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (!mt->isReflex() && !actor.isImmobile()) {
 			//  Abort any pending path finding task
 			abortPathFind(mt);
@@ -1438,7 +1945,7 @@ void MotionTask::wander(
     bool        run) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (!mt->isReflex() && !actor.isImmobile()) {
 			//  Abort any pending path finding task
 			abortPathFind(mt);
@@ -1468,7 +1975,7 @@ void MotionTask::tetheredWander(
     bool                run) {
 	MotionTask          *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (!mt->isReflex() && !actor.isImmobile()) {
 			//  Abort any pending path finding task
 			abortPathFind(mt);
@@ -1499,7 +2006,7 @@ void MotionTask::tetheredWander(
 void MotionTask::upLadder(Actor &actor) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (mt->motionType != motionTypeClimbUp) {
 			mt->motionType = motionTypeClimbUp;
 			mt->flags = reset;
@@ -1513,7 +2020,7 @@ void MotionTask::upLadder(Actor &actor) {
 void MotionTask::downLadder(Actor &actor) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (mt->motionType != motionTypeClimbDown) {
 			mt->motionType = motionTypeClimbDown;
 			mt->flags = reset;
@@ -1527,7 +2034,7 @@ void MotionTask::downLadder(Actor &actor) {
 void MotionTask::talk(Actor &actor) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (mt->motionType != motionTypeTalk) {
 			mt->motionType = motionTypeTalk;
 			mt->flags = reset;
@@ -1542,7 +2049,7 @@ void MotionTask::talk(Actor &actor) {
 void MotionTask::jump(Actor &actor) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&actor)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&actor)) != NULL) {
 		if (mt->motionType != motionTypeThrown) {
 			mt->velocity.z = 10;
 			mt->motionType = motionTypeJump;
@@ -1558,7 +2065,7 @@ void MotionTask::jump(Actor &actor) {
 void MotionTask::wait(Actor &a) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeWait) {
 			mt->motionType = motionTypeWait;
 			mt->flags = reset;
@@ -1572,7 +2079,7 @@ void MotionTask::wait(Actor &a) {
 void MotionTask::useObject(Actor &a, GameObject &dObj) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseObject) {
 			mt->motionType = motionTypeUseObject;
 			mt->o.directObject = &dObj;
@@ -1591,7 +2098,7 @@ void MotionTask::useObjectOnObject(
     GameObject  &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseObjectOnObject) {
 			mt->motionType = motionTypeUseObjectOnObject;
 			mt->o.directObject = &dObj;
@@ -1611,7 +2118,7 @@ void MotionTask::useObjectOnTAI(
     ActiveItem  &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseObjectOnTAI) {
 			mt->motionType = motionTypeUseObjectOnTAI;
 			mt->o.directObject = &dObj;
@@ -1630,7 +2137,7 @@ void MotionTask::useObjectOnLocation(
     const Location  &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseObjectOnLocation) {
 			mt->motionType = motionTypeUseObjectOnLocation;
 			mt->o.directObject = &dObj;
@@ -1646,7 +2153,7 @@ void MotionTask::useObjectOnLocation(
 void MotionTask::useTAI(Actor &a, ActiveItem &dTAI) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseTAI) {
 			mt->motionType = motionTypeUseTAI;
 			mt->o.TAI = &dTAI;
@@ -1664,7 +2171,7 @@ void MotionTask::dropObject(Actor       &a,
                             int16      num) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeDropObject) {
 			mt->motionType = motionTypeDropObject;
 			mt->o.directObject = &dObj;
@@ -1699,7 +2206,7 @@ void MotionTask::dropObjectOnObject(
 
 	//  Otherwise, drop it on the object
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeDropObjectOnObject) {
 			mt->motionType = motionTypeDropObjectOnObject;
 			mt->o.directObject = &dObj;
@@ -1720,7 +2227,7 @@ void MotionTask::dropObjectOnTAI(
     const Location  &loc) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeDropObjectOnTAI) {
 			mt->motionType = motionTypeDropObjectOnTAI;
 			mt->o.directObject = &dObj;
@@ -1752,7 +2259,7 @@ bool MotionTask::isReflex(void) {
 void MotionTask::twoHandedSwing(Actor &a, GameObject &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeTwoHandedSwing) {
 			mt->motionType = motionTypeTwoHandedSwing;
 			mt->targetObj = ⌖
@@ -1767,7 +2274,7 @@ void MotionTask::twoHandedSwing(Actor &a, GameObject &target) {
 void MotionTask::oneHandedSwing(Actor &a, GameObject &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeOneHandedSwing) {
 			mt->motionType = motionTypeOneHandedSwing;
 			mt->targetObj = ⌖
@@ -1782,7 +2289,7 @@ void MotionTask::oneHandedSwing(Actor &a, GameObject &target) {
 void MotionTask::fireBow(Actor &a, GameObject &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeFireBow) {
 			mt->motionType = motionTypeFireBow;
 			mt->targetObj = ⌖
@@ -1802,7 +2309,7 @@ void MotionTask::castSpell(Actor &a, SkillProto &spell, GameObject &target) {
 	    motionTypeCastSpell;
 
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != type) {
 			mt->motionType = type;
 			mt->spellObj = &spell;
@@ -1821,7 +2328,7 @@ void MotionTask::castSpell(Actor &a, SkillProto &spell, Location &target) {
 	    motionTypeGive :
 	    motionTypeCastSpell;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != type) {
 			mt->motionType = type;
 			mt->spellObj = &spell;
@@ -1840,7 +2347,7 @@ void MotionTask::castSpell(Actor &a, SkillProto &spell, ActiveItem &target) {
 	    motionTypeGive :
 	    motionTypeCastSpell;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != type) {
 			Location loc;
 			assert(target._data.itemType == activeTypeInstance);
@@ -1866,7 +2373,7 @@ void MotionTask::castSpell(Actor &a, SkillProto &spell, ActiveItem &target) {
 void MotionTask::useWand(Actor &a, GameObject &target) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeUseWand) {
 			mt->motionType = motionTypeUseWand;
 			mt->targetObj = ⌖
@@ -1886,7 +2393,7 @@ void MotionTask::twoHandedParry(
     Actor       &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeTwoHandedParry) {
 			mt->motionType = motionTypeTwoHandedParry;
 			mt->d.attacker = &opponent;
@@ -1906,7 +2413,7 @@ void MotionTask::oneHandedParry(
     Actor       &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeOneHandedParry) {
 			mt->motionType = motionTypeOneHandedParry;
 			mt->d.attacker = &opponent;
@@ -1926,7 +2433,7 @@ void MotionTask::shieldParry(
     Actor       &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeShieldParry) {
 			mt->motionType = motionTypeShieldParry;
 			mt->d.attacker = &opponent;
@@ -1943,7 +2450,7 @@ void MotionTask::shieldParry(
 void MotionTask::dodge(Actor &a, Actor &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeDodge) {
 			mt->motionType = motionTypeDodge;
 			mt->d.attacker = &opponent;
@@ -1961,7 +2468,7 @@ void MotionTask::dodge(Actor &a, Actor &opponent) {
 void MotionTask::acceptHit(Actor &a, Actor &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeAcceptHit) {
 			mt->motionType = motionTypeAcceptHit;
 			mt->d.attacker = &opponent;
@@ -1976,7 +2483,7 @@ void MotionTask::acceptHit(Actor &a, Actor &opponent) {
 void MotionTask::fallDown(Actor &a, Actor &opponent) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeFallDown) {
 			mt->motionType = motionTypeFallDown;
 			mt->d.attacker = &opponent;
@@ -1991,7 +2498,7 @@ void MotionTask::fallDown(Actor &a, Actor &opponent) {
 void MotionTask::die(Actor &a) {
 	MotionTask      *mt;
 
-	if ((mt = mTaskList->newTask(&a)) != NULL) {
+	if ((mt = g_vm->_mTaskList->newTask(&a)) != NULL) {
 		if (mt->motionType != motionTypeDie) {
 			mt->motionType = motionTypeDie;
 			mt->flags = reset;
@@ -4142,7 +4649,7 @@ void MotionTask::updatePositions(void) {
 	int16           targetDist;
 	StandingTileInfo sti;
 
-	for (Common::List<MotionTask *>::iterator it = mTaskList->_list.begin(); it != mTaskList->_list.end(); it = g_vm->_nextMT) {
+	for (Common::List<MotionTask *>::iterator it = g_vm->_mTaskList->_list.begin(); it != g_vm->_mTaskList->_list.end(); it = g_vm->_nextMT) {
 		MotionTask *mt = *it;
 		GameObject  *obj = mt->object;
 		ProtoObj    *proto = obj->proto();
@@ -4924,7 +5431,7 @@ void resumeInterruptableMotions(void) {
 
 void initMotionTasks(void) {
 	//  Simply call the default MotionTaskList constructor
-	mTaskList = new MotionTaskList;
+	//new (g_vm->_mTaskList) MotionTaskList;
 }
 
 //-----------------------------------------------------------------------
@@ -4934,13 +5441,13 @@ void saveMotionTasks(SaveFileConstructor &saveGame) {
 	int32   archiveBufSize;
 	void    *archiveBuffer;
 
-	archiveBufSize = mTaskList->archiveSize();
+	archiveBufSize = g_vm->_mTaskList->archiveSize();
 
 	archiveBuffer = malloc(archiveBufSize);
 	if (archiveBuffer == NULL)
 		error("Unable to allocate motion task archive buffer");
 
-	mTaskList->archive(archiveBuffer);
+	g_vm->_mTaskList->archive(archiveBuffer);
 
 	saveGame.writeChunk(
 	    MakeID('M', 'O', 'T', 'N'),
@@ -4950,6 +5457,19 @@ void saveMotionTasks(SaveFileConstructor &saveGame) {
 	free(archiveBuffer);
 }
 
+void saveMotionTasks(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving MotionTasks");
+
+	int32   archiveBufSize;
+	
+	archiveBufSize = g_vm->_mTaskList->archiveSize();
+
+	out->write("MOTN", 4);
+	out->writeUint32LE(archiveBufSize);
+
+	g_vm->_mTaskList->write(out);
+}
+
 //-----------------------------------------------------------------------
 //	Load the motion task list from a save file
 
@@ -4958,7 +5478,7 @@ void loadMotionTasks(SaveFileReader &saveGame) {
 #if 0
 	//  If there is no saved data, simply call the default constructor
 	if (saveGame.getChunkSize() == 0) {
-		new (&mTaskList) MotionTaskList;
+		new (&g_vm->_mTaskList) MotionTaskList;
 		return;
 	}
 
@@ -4974,20 +5494,32 @@ void loadMotionTasks(SaveFileReader &saveGame) {
 
 	bufferPtr = archiveBuffer;
 
-	//  Reconstruct mTaskList from archived data
-	new (&mTaskList) MotionTaskList(&bufferPtr);
+	//  Reconstruct g_vm->_mTaskList from archived data
+	new (&g_vm->_mTaskList) MotionTaskList(&bufferPtr);
 
 	free(archiveBuffer);
 #endif
 }
 
+void loadMotionTasks(Common::InSaveFile *in, int32 chunkSize) {
+	debugC(2, kDebugSaveload, "Loading MotionTasks");
+
+	//  If there is no saved data, simply call the default constructor
+	if (chunkSize == 0) {
+		//new (g_vm->_mTaskList) MotionTaskList;
+		return;
+	}
+
+	//  Reconstruct g_vm->_mTaskList from archived data
+	g_vm->_mTaskList->read(in);
+}
+
 //-----------------------------------------------------------------------
 //	Cleanup the motion task list
 
 void cleanupMotionTasks(void) {
 	//  Simply call stackList's cleanup
-	mTaskList->cleanup();
-	delete mTaskList;
+	g_vm->_mTaskList->cleanup();
 }
 
 } // end of namespace Saga2
diff --git a/engines/saga2/motion.h b/engines/saga2/motion.h
index d246d4f5f1..37040422a2 100644
--- a/engines/saga2/motion.h
+++ b/engines/saga2/motion.h
@@ -261,12 +261,16 @@ private:
 	//  Reconstruct this MotionTask from an archive buffer
 	void *restore(void *buf);
 
+	void read(Common::InSaveFile *in);
+
 	//  Return the number of bytes needed to archive this MotionTask
 	int32 archiveSize(void);
 
 	//  Archive this MotionTask in a buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	// motion task is finished.
 	void remove(int16 returnVal = motionInterrupted);
 
@@ -548,6 +552,10 @@ public:
 	//  Reconstruct motion task list from archive buffer
 	MotionTaskList(void **buf);
 
+	MotionTaskList(Common::SeekableReadStream *stream);
+
+	void read(Common::InSaveFile *in);
+
 	//  Return the number of bytes needed to archive the motion tasks
 	//  in a buffer
 	int32 archiveSize(void);
@@ -555,6 +563,8 @@ public:
 	//  Create an archive of the motion tasks in the specified buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	//  Cleanup the motion tasks
 	void cleanup(void);
 
@@ -622,9 +632,11 @@ void initMotionTasks(void);
 
 //  Save the motion task list to a save file
 void saveMotionTasks(SaveFileConstructor &saveGame);
+void saveMotionTasks(Common::OutSaveFile *out);
 
 //  Load the motion task list from a save file
 void loadMotionTasks(SaveFileReader &saveGame);
+void loadMotionTasks(Common::InSaveFile *in, int32 chunkSize);
 
 //  Cleanup the motion task list
 void cleanupMotionTasks(void);


Commit: b8827444050db1c6b91bbc30f619a1da78e08de3
    https://github.com/scummvm/scummvm/commit/b8827444050db1c6b91bbc30f619a1da78e08de3
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T12:59:42+09:00

Commit Message:
SAGA2: Remove placement-new for threadList

Changed paths:
    engines/saga2/interp.cpp


diff --git a/engines/saga2/interp.cpp b/engines/saga2/interp.cpp
index b33c3013b2..71a25ac9bd 100644
--- a/engines/saga2/interp.cpp
+++ b/engines/saga2/interp.cpp
@@ -1398,7 +1398,6 @@ static ThreadList &threadList = *((ThreadList *)threadListBuffer);
 
 void initSAGAThreads(void) {
 	//  Simply call the Thread List default constructor
-	new (&threadList) ThreadList;
 }
 
 //-------------------------------------------------------------------
@@ -1470,14 +1469,11 @@ void loadSAGAThreads(SaveFileReader &saveGame) {
 void loadSAGAThreads(Common::InSaveFile *in, int32 chunkSize) {
 	debugC(2, kDebugSaveload, "Loading SAGA Threads");
 
-	//  If there is no saved data, simply call the default constructor
 	if (chunkSize == 0) {
-		new (&threadList) ThreadList;
 		return;
 	}
 
 	//  Reconstruct stackList from archived data
-	new (&threadList) ThreadList;
 	threadList.read(in);
 }
 




More information about the Scummvm-git-logs mailing list