aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/illusions/scriptman.h3
-rw-r--r--engines/illusions/thread.cpp126
-rw-r--r--engines/illusions/thread.h19
3 files changed, 137 insertions, 11 deletions
diff --git a/engines/illusions/scriptman.h b/engines/illusions/scriptman.h
index 18b6090fa2..acfd51491a 100644
--- a/engines/illusions/scriptman.h
+++ b/engines/illusions/scriptman.h
@@ -24,6 +24,7 @@
#define ILLUSIONS_SCRIPTMAN_H
#include "illusions/scriptresource.h"
+#include "illusions/thread.h"
#include "common/algorithm.h"
#include "common/stack.h"
@@ -78,6 +79,8 @@ public:
uint32 _theSceneId;
uint32 _theThreadId;
+
+
};
} // End of namespace Illusions
diff --git a/engines/illusions/thread.cpp b/engines/illusions/thread.cpp
index 8a1c805a49..8c2f585360 100644
--- a/engines/illusions/thread.cpp
+++ b/engines/illusions/thread.cpp
@@ -64,13 +64,10 @@ void Thread::notify() {
}
int Thread::update() {
- // NOTE Deletion of removed threads handled in caller
+ // NOTE Deletion of terminated threads handled in caller
int result = 2;
- if (!_terminated) {
- if (_pauseCtr > 0)
- result = 2;
- else
- result = onUpdate();
+ if (!_terminated && _pauseCtr <= 0) {
+ result = onUpdate();
if (result == 1)
terminate();
else if (result == 3)
@@ -114,11 +111,9 @@ void ThreadList::updateThreads() {
it = _threads.erase(it);
delete thread;
} else {
- while (!thread->_terminated) {
- int updateResult = thread->update();
- if (updateResult == 1 || updateResult == 2)
- break;
- }
+ int updateResult = 4;
+ while (!thread->_terminated && updateResult != 1 && updateResult != 2)
+ updateResult = thread->update();
++it;
}
}
@@ -131,4 +126,113 @@ void ThreadList::updateThreads() {
}
}
+Thread *ThreadList::findThread(uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it)
+ if ((*it)->_threadId == threadId && !(*it)->_terminated)
+ return (*it);
+ return 0;
+}
+
+void ThreadList::suspendId(uint32 threadId) {
+ Thread *thread = findThread(threadId);
+ if (thread)
+ thread->suspend();
+}
+
+void ThreadList::notifyId(uint32 threadId) {
+ Thread *thread = findThread(threadId);
+ if (thread)
+ thread->notify();
+}
+
+void ThreadList::notifyTimerThreads(uint32 callingThreadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_type == kTTTimerThread && thread->_callingThreadId == callingThreadId)
+ thread->notify();
+ }
+}
+
+void ThreadList::suspendTimerThreads(uint32 callingThreadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_type == kTTTimerThread && thread->_callingThreadId == callingThreadId)
+ thread->suspend();
+ }
+}
+
+void ThreadList::terminateThreads(uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_threadId != threadId)
+ thread->terminate();
+ }
+}
+
+void ThreadList::terminateThreadsByTag(uint32 tag, uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_tag == tag && thread->_threadId != threadId)
+ thread->terminate();
+ }
+}
+
+void ThreadList::suspendThreadsByTag(uint32 tag, uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_tag == tag && thread->_threadId != threadId)
+ thread->suspend();
+ }
+}
+
+void ThreadList::notifyThreadsByTag(uint32 tag, uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_tag == tag && thread->_threadId != threadId)
+ thread->notify();
+ }
+}
+
+void ThreadList::pauseThreads(uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_threadId != threadId)
+ thread->pause();
+ }
+}
+
+void ThreadList::resumeThreads(uint32 threadId) {
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *thread = *it;
+ if (thread->_threadId != threadId)
+ thread->resume();
+ }
+}
+
+void ThreadList::killThread(uint32 threadId) {
+
+ if (!threadId)
+ return;
+
+ Thread *thread = findThread(threadId);
+ if (!thread)
+ return;
+
+ for (Iterator it = _threads.begin(); it != _threads.end(); ++it) {
+ Thread *childThread = *it;
+ if (childThread->_callingThreadId == threadId)
+ killThread(childThread->_threadId);
+ }
+
+ if (thread->_type == kTTTalkThread) {
+ thread->_callingThreadId = 0;
+ // TODO script_TalkThreads_sub_417F60(thread->_threadId, 0);
+ // TODO script_TalkThreads_sub_417FA0(thread->_threadId, 0);
+ } else {
+ // TODO artmgrThreadIsDead(thread->threadId);
+ thread->terminate();
+ }
+
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/thread.h b/engines/illusions/thread.h
index 27d4c41657..2a2c0f10d2 100644
--- a/engines/illusions/thread.h
+++ b/engines/illusions/thread.h
@@ -29,6 +29,13 @@ namespace Illusions {
class IllusionsEngine;
+enum ThreadType {
+ kTTScriptThread = 1,
+ kTTTimerThread = 2,
+ kTTTalkThread = 3,
+ kTTSpecialThread = 5
+};
+
class Thread {
public:
Thread(IllusionsEngine *vm);
@@ -63,6 +70,18 @@ public:
ThreadList(IllusionsEngine *vm);
void startThread(Thread *thread);
void updateThreads();
+ Thread *findThread(uint32 threadId);
+ void suspendId(uint32 threadId);
+ void notifyId(uint32 threadId);
+ void notifyTimerThreads(uint32 callingThreadId);
+ void suspendTimerThreads(uint32 callingThreadId);
+ void terminateThreads(uint32 threadId);
+ void terminateThreadsByTag(uint32 tag, uint32 threadId);
+ void suspendThreadsByTag(uint32 tag, uint32 threadId);
+ void notifyThreadsByTag(uint32 tag, uint32 threadId);
+ void pauseThreads(uint32 threadId);
+ void resumeThreads(uint32 threadId);
+ void killThread(uint32 threadId);
protected:
typedef Common::List<Thread*> List;
typedef List::iterator Iterator;