[Scummvm-git-logs] scummvm master -> 04230264545898cd38816a4829729211f7741228

OMGPizzaGuy noreply at scummvm.org
Mon Dec 5 03:28:25 UTC 2022


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:
0423026454 ULTIMA8: Add process flag to specify disposal after termination


Commit: 04230264545898cd38816a4829729211f7741228
    https://github.com/scummvm/scummvm/commit/04230264545898cd38816a4829729211f7741228
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-04T21:28:01-06:00

Commit Message:
ULTIMA8: Add process flag to specify disposal after termination

Currently there is no way to check failure of a process due to disposal immediately after termination. With this flag, a process can be owned elsewhere and checked for success after termination.

Changed paths:
    engines/ultima/ultima8/kernel/kernel.cpp
    engines/ultima/ultima8/kernel/kernel.h
    engines/ultima/ultima8/kernel/process.cpp
    engines/ultima/ultima8/kernel/process.h


diff --git a/engines/ultima/ultima8/kernel/kernel.cpp b/engines/ultima/ultima8/kernel/kernel.cpp
index b8910f30aaf..aca185e1641 100644
--- a/engines/ultima/ultima8/kernel/kernel.cpp
+++ b/engines/ultima/ultima8/kernel/kernel.cpp
@@ -63,7 +63,12 @@ void Kernel::reset() {
 	debugN(MM_INFO, "Resetting Kernel...\n");
 
 	for (ProcessIterator it = _processes.begin(); it != _processes.end(); ++it) {
-		delete(*it);
+		Process *p = *it;
+		if (p->_flags & Process::PROC_TERM_DISPOSE) {
+			delete p;
+		} else {
+			p->_flags |= Process::PROC_TERMINATED;
+		}
 	}
 	_processes.clear();
 	_currentProcess = _processes.begin();
@@ -87,7 +92,7 @@ ProcId Kernel::assignPID(Process *proc) {
 	return proc->_pid;
 }
 
-ProcId Kernel::addProcess(Process *proc) {
+ProcId Kernel::addProcess(Process *proc, bool dispose) {
 #if 0
 	for (ProcessIterator it = processes.begin(); it != processes.end(); ++it) {
 		if (*it == proc)
@@ -102,13 +107,14 @@ ProcId Kernel::addProcess(Process *proc) {
 	<< ", pid = " << proc->_pid << " type " << proc->GetClassType()._className << Std::endl;
 #endif
 
-//	processes.push_back(proc);
-//	proc->active = true;
+	if (dispose) {
+		proc->_flags |= Process::PROC_TERM_DISPOSE;
+	}
 	setNextProcess(proc);
 	return proc->_pid;
 }
 
-ProcId Kernel::addProcessExec(Process *proc) {
+ProcId Kernel::addProcessExec(Process *proc, bool dispose) {
 #if 0
 	for (ProcessIterator it = processes.begin(); it != processes.end(); ++it) {
 		if (*it == proc)
@@ -123,6 +129,9 @@ ProcId Kernel::addProcessExec(Process *proc) {
 	     << ", pid = " << proc->_pid << Std::endl;
 #endif
 
+	if (dispose) {
+		proc->_flags |= Process::PROC_TERM_DISPOSE;
+	}
 	_processes.push_back(proc);
 	proc->_flags |= Process::PROC_ACTIVE;
 
@@ -195,8 +204,9 @@ void Kernel::runProcesses() {
 			// Clear pid
 			_pIDs->clearID(p->_pid);
 
-			//! is this the right place to delete processes?
-			delete p;
+			if (p->_flags & Process::PROC_TERM_DISPOSE) {
+				delete p;
+			}
 		} else if (!_paused && (p->_flags & Process::PROC_TERM_DEFERRED) && GAME_IS_CRUSADER) {
 			//
 			// In Crusader, move term deferred processes to the end to clean up after
diff --git a/engines/ultima/ultima8/kernel/kernel.h b/engines/ultima/ultima8/kernel/kernel.h
index b97d2093d38..bfb310291b0 100644
--- a/engines/ultima/ultima8/kernel/kernel.h
+++ b/engines/ultima/ultima8/kernel/kernel.h
@@ -49,11 +49,12 @@ public:
 
 	void reset();
 
-	ProcId addProcess(Process *proc); // returns pid of new process
+	// returns pid of new process
+	ProcId addProcess(Process *proc, bool dispose = true);
 
 	//! add a process and run it immediately
 	//! \return pid of process
-	ProcId addProcessExec(Process *proc);
+	ProcId addProcessExec(Process *proc, bool dispose = true);
 
 	void runProcesses();
 	Process *getProcess(ProcId pid);
diff --git a/engines/ultima/ultima8/kernel/process.cpp b/engines/ultima/ultima8/kernel/process.cpp
index 1f61c67208b..962fcf61fc6 100644
--- a/engines/ultima/ultima8/kernel/process.cpp
+++ b/engines/ultima/ultima8/kernel/process.cpp
@@ -45,7 +45,8 @@ void Process::fail() {
 }
 
 void Process::terminate() {
-	assert(!(_flags & PROC_TERMINATED));
+	if (_flags & PROC_TERMINATED)
+		return;
 
 	Kernel *kernel = Kernel::get_instance();
 
@@ -116,6 +117,8 @@ void Process::dumpInfo() const {
 	if (_flags & PROC_TERM_DEFERRED) info += "t";
 	if (_flags & PROC_FAILED) info += "F";
 	if (_flags & PROC_RUNPAUSED) info += "R";
+	if (_flags & PROC_TERM_DISPOSE) info += "D";
+
 	if (!_waiting.empty()) {
 		info += ", notify: ";
 		for (Std::vector<ProcId>::const_iterator i = _waiting.begin(); i != _waiting.end(); ++i) {
diff --git a/engines/ultima/ultima8/kernel/process.h b/engines/ultima/ultima8/kernel/process.h
index e4c72d86f18..555698d8824 100644
--- a/engines/ultima/ultima8/kernel/process.h
+++ b/engines/ultima/ultima8/kernel/process.h
@@ -153,7 +153,8 @@ public:
 		PROC_TERMINATED  = 0x0004,
 		PROC_TERM_DEFERRED = 0x0008, //!< automatically call terminate next frame
 		PROC_FAILED      = 0x0010,
-		PROC_RUNPAUSED   = 0x0020    //!< run even if game is paused
+		PROC_RUNPAUSED   = 0x0020,    //!< run even if game is paused
+		PROC_TERM_DISPOSE = 0x0040,  //!< Dispose after termination
 	};
 
 };




More information about the Scummvm-git-logs mailing list