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 | |
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')
-rw-r--r-- | engines/illusions/illusions.cpp | 1 | ||||
-rw-r--r-- | engines/illusions/module.mk | 1 | ||||
-rw-r--r-- | engines/illusions/thread.cpp | 134 | ||||
-rw-r--r-- | engines/illusions/thread.h | 75 |
4 files changed, 211 insertions, 0 deletions
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp index 8cfd29e110..06662fb4aa 100644 --- a/engines/illusions/illusions.cpp +++ b/engines/illusions/illusions.cpp @@ -31,6 +31,7 @@ #include "illusions/spritedecompressqueue.h" #include "illusions/actor.h" #include "illusions/actorresource.h" +#include "illusions/thread.h" #include "audio/audiostream.h" #include "common/config-manager.h" diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk index 722a55254d..99e84f5efb 100644 --- a/engines/illusions/module.mk +++ b/engines/illusions/module.mk @@ -13,6 +13,7 @@ MODULE_OBJS := \ resourcesystem.o \ spritedecompressqueue.o \ spritedrawqueue.o \ + thread.o \ time.o \ updatefunctions.o 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 diff --git a/engines/illusions/thread.h b/engines/illusions/thread.h new file mode 100644 index 0000000000..27d4c41657 --- /dev/null +++ b/engines/illusions/thread.h @@ -0,0 +1,75 @@ +/* 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. + * + */ + +#ifndef ILLUSIONS_THREAD_H +#define ILLUSIONS_THREAD_H + +#include "common/list.h" + +namespace Illusions { + +class IllusionsEngine; + +class Thread { +public: + Thread(IllusionsEngine *vm); + virtual ~Thread(); + virtual int onUpdate() = 0; + virtual void onSuspend() = 0; + virtual void onNotify() = 0; + virtual void onPause() = 0; + virtual void onResume() = 0; + virtual void onTerminated() = 0; + void pause(); + void resume(); + void suspend(); + void notify(); + int update(); + void terminate(); +public: + IllusionsEngine *_vm; + //field_0 dw + int _pauseCtr; + bool _terminated; + //field_6 dw + uint _type; + uint32 _threadId; + uint32 _callingThreadId; + uint32 _tag; + uint _notifyFlags; +}; + +class ThreadList { +public: + ThreadList(IllusionsEngine *vm); + void startThread(Thread *thread); + void updateThreads(); +protected: + typedef Common::List<Thread*> List; + typedef List::iterator Iterator; + IllusionsEngine *_vm; + List _threads; +}; + +} // End of namespace Illusions + +#endif // ILLUSIONS_THREAD_H |