diff options
author | johndoe123 | 2014-03-13 10:05:22 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | d2b036fa5b22f7a4802443b5b72adb6d444893c3 (patch) | |
tree | 6a0b4167b87630cb69526b0a3884ba8e9034ccf6 /engines/illusions/thread.cpp | |
parent | 4211f8ffcd74563c7f7a17c34cc14ebc7bdeee59 (diff) | |
download | scummvm-rg350-d2b036fa5b22f7a4802443b5b72adb6d444893c3.tar.gz scummvm-rg350-d2b036fa5b22f7a4802443b5b72adb6d444893c3.tar.bz2 scummvm-rg350-d2b036fa5b22f7a4802443b5b72adb6d444893c3.zip |
ILLUSIONS: Start with thread classes
Diffstat (limited to 'engines/illusions/thread.cpp')
-rw-r--r-- | engines/illusions/thread.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/engines/illusions/thread.cpp b/engines/illusions/thread.cpp new file mode 100644 index 0000000000..8a1c805a49 --- /dev/null +++ b/engines/illusions/thread.cpp @@ -0,0 +1,134 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "illusions/illusions.h" +#include "illusions/thread.h" + +namespace Illusions { + +// Thread + +Thread::Thread(IllusionsEngine *vm) + : _vm(vm), _pauseCtr(0), _terminated(false) { +} + +void Thread::pause() { + if (!_terminated) { + ++_pauseCtr; + if (_pauseCtr == 1) + onPause(); + } +} + +void Thread::resume() { + if (!_terminated) { + --_pauseCtr; + if (_pauseCtr == 0) + onResume(); + } +} + +void Thread::suspend() { + if (!_terminated) { + ++_pauseCtr; + if (_pauseCtr == 1) + onSuspend(); + } +} + +void Thread::notify() { + if (!_terminated) { + --_pauseCtr; + if (_pauseCtr == 0) + onNotify(); + } +} + +int Thread::update() { + // NOTE Deletion of removed threads handled in caller + int result = 2; + if (!_terminated) { + if (_pauseCtr > 0) + result = 2; + else + result = onUpdate(); + if (result == 1) + terminate(); + else if (result == 3) + suspend(); + } + return result; +} + +void Thread::terminate() { + if (!_terminated) { + if (_callingThreadId) { + if (!(_notifyFlags & 1)) { + // TODO scrmgrNotifyID(_callingThreadId); + } + _callingThreadId = 0; + } + onTerminated(); + // TODO _vm->removeThread(_threadId, this); + _terminated = true; + } +} + +// ThreadList + +ThreadList::ThreadList(IllusionsEngine *vm) + : _vm(vm) { +} + +void ThreadList::startThread(Thread *thread) { + // TODO tag has to be set by the Thread class scrmgrGetCurrentScene(); + _threads.push_back(thread); + // TODO _vm->addThread(thread->_threadId, thread); +} + +void ThreadList::updateThreads() { + while (1) { + Iterator it = _threads.begin(); + while (it != _threads.end()) { + Thread *thread = *it; + if (thread->_terminated) { + it = _threads.erase(it); + delete thread; + } else { + while (!thread->_terminated) { + int updateResult = thread->update(); + if (updateResult == 1 || updateResult == 2) + break; + } + ++it; + } + } + /* TODO + if (script->threadUpdateContinueFlag) + script->_threadUpdateContinueFlag = false; + else + */ + break; + } +} + +} // End of namespace Illusions |