[Scummvm-cvs-logs] SF.net SVN: scummvm: [26451] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Tue Apr 10 20:46:35 CEST 2007


Revision: 26451
          http://scummvm.svn.sourceforge.net/scummvm/?rev=26451&view=rev
Author:   peres001
Date:     2007-04-10 11:46:34 -0700 (Tue, 10 Apr 2007)

Log Message:
-----------
Moved Jobs to ManagedList. Since Jobs must be ordered according to their priority, a new insertSorted method has been added to the implementation.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/defs.h
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h

Modified: scummvm/trunk/engines/parallaction/defs.h
===================================================================
--- scummvm/trunk/engines/parallaction/defs.h	2007-04-10 15:10:18 UTC (rev 26450)
+++ scummvm/trunk/engines/parallaction/defs.h	2007-04-10 18:46:34 UTC (rev 26451)
@@ -51,6 +51,8 @@
 	typedef typename Common::List<T> 				Common_List;
 	typedef typename Common::List<T>::iterator 		iterator;
 
+	typedef int (*CompareFunction) (const T& a, const T& b);
+
 	~ManagedList() {
 		clear();
 	}
@@ -71,6 +73,17 @@
 		return Common_List::erase(first, last);
 	}
 
+	// keeps list ordered in *ascending* order, as expressed by the compare function
+	void insertSorted(const T& element, CompareFunction compare) {
+		iterator it = Common_List::begin();
+		for ( ; it != Common_List::end(); it++)
+			if (compare(element, *it) < 0) break;
+
+		if (it == Common_List::end())
+			Common_List::push_back(element);
+		else
+			Common_List::insert(it, element);
+	}
 };
 
 } // namespace Parallaction
@@ -80,3 +93,4 @@
 
 
 
+

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-10 15:10:18 UTC (rev 26450)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2007-04-10 18:46:34 UTC (rev 26451)
@@ -834,6 +834,14 @@
 	return;
 }
 
+/*
+	helper function to provide *descending* ordering of the job list
+	(higher priorities values comes first in the list)
+*/
+int compareJobPriority(const JobPointer &j1, const JobPointer &j2) {
+	if (j1->_tag == j2->_tag) return 0;
+	return (j1->_tag >= j2->_tag ? -1 : 1);
+}
 
 Job *Parallaction::addJob(JobFn fn, void *parm, uint16 tag) {
 
@@ -845,15 +853,8 @@
 	v8->_finished = 0;
 	v8->_count = 0;
 
-	Job *v4 = &_jobs;
+	_jobs.insertSorted(v8, compareJobPriority);
 
-	// TODO (LIST): the loop will be useless once we have an ordered
-	// list _jobs. So this code will just be: _jobs.insert(v8)
-	while (v4->_next && ((Job*)(v4->_next))->_tag > tag) {
-		v4 = (Job*)v4->_next;
-	}
-	addNode(v4, v8);
-
 	return v8;
 }
 
@@ -876,22 +877,22 @@
 
 	if (_engineFlags & kEnginePauseJobs) return;
 
-	Job *j = (Job*)_jobs._next;
-	while (j) {
-		debugC(3, kDebugJobs, "runJobs: %i", j->_tag);
+	JobList::iterator it = _jobs.begin();
+	while (it != _jobs.end()) {
+		if ((*it)->_finished == 1)
+			it = _jobs.erase(it);
+		else
+			it++;
+	}
 
-		Job *v4 = (Job*)j->_next;
+	it = _jobs.begin();
+	while (it != _jobs.end()) {
+		debugC(3, kDebugJobs, "runJobs: %i", (*it)->_tag);
+		(*(*it)->_fn)((*it)->_parm, (*it));
+		it++;
+	}
 
-		if (j->_finished == 1) {
-			removeNode(j);
-			delete j;
-		} else {
-			(*j->_fn)(j->_parm, j);
-		}
 
-		j = v4;
-	}
-
 	return;
 }
 

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2007-04-10 15:10:18 UTC (rev 26450)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2007-04-10 18:46:34 UTC (rev 26451)
@@ -135,7 +135,7 @@
 struct Job;
 typedef void (*JobFn)(void*, Job*);
 
-struct Job : public Node {
+struct Job {
 	uint16		_count; 		// # of executions left
 	uint16		_tag;			// used for ordering
 	uint16		_finished;
@@ -147,6 +147,9 @@
 	}
 };
 
+typedef Job* JobPointer;
+typedef ManagedList<JobPointer> JobList;
+
 struct Credit {
 	const char *_role;
 	const char *_name;
@@ -399,7 +402,7 @@
 
 	int16 _keyDown;
 
-	Job			_jobs;
+	JobList		_jobs;
 
 	Node 		helperNode;			// used for freeZones: to be removed
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list