1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef ILLUSIONS_THREAD_H 24 #define ILLUSIONS_THREAD_H 25 26 #include "common/list.h" 27 28 namespace Illusions { 29 30 class IllusionsEngine; 31 32 enum ThreadType { 33 kTTScriptThread = 1, 34 kTTTimerThread = 2, 35 kTTTalkThread = 3, 36 kTTAbortableThread = 4, 37 kTTSpecialThread = 5, 38 kTTCauseThread = 6 39 }; 40 41 enum ThreadStatus { 42 kTSTerminate = 1, 43 kTSYield = 2, 44 kTSSuspend = 3, 45 kTSRun = 4 46 }; 47 48 class Thread { 49 public: 50 Thread(IllusionsEngine *vm, uint32 threadId, uint32 callingThreadId, uint notifyFlags); 51 virtual ~Thread(); 52 virtual int onUpdate(); 53 virtual void onSuspend(); 54 virtual void onNotify(); 55 virtual void onPause(); 56 virtual void onUnpause(); 57 virtual void onResume(); 58 virtual void onTerminated(); 59 virtual void onKill(); 60 virtual uint32 sendMessage(int msgNum, uint32 msgValue); 61 void pause(); 62 void unpause(); 63 void resume(); 64 void suspend(); 65 void notify(); 66 int update(); 67 void terminate(); 68 public: 69 IllusionsEngine *_vm; 70 //field_0 dw 71 int _pauseCtr; 72 bool _terminated; 73 //field_6 dw 74 uint _type; 75 uint32 _threadId; 76 uint32 _callingThreadId; 77 uint32 _sceneId; 78 uint _notifyFlags; 79 }; 80 81 class ThreadList { 82 public: 83 ThreadList(IllusionsEngine *vm); 84 void startThread(Thread *thread); 85 void updateThreads(); 86 Thread *findThread(uint32 threadId); 87 void suspendId(uint32 threadId); 88 void notifyId(uint32 threadId); 89 void notifyTimerThreads(uint32 callingThreadId); 90 void suspendTimerThreads(uint32 callingThreadId); 91 void terminateThreads(uint32 threadId); 92 void terminateActiveThreads(uint32 threadId); 93 void terminateThreadsBySceneId(uint32 sceneId, uint32 threadId); 94 void suspendThreadsBySceneId(uint32 sceneId, uint32 threadId); 95 void notifyThreads(uint32 threadId); 96 void notifyThreadsBySceneId(uint32 sceneId, uint32 threadId); 97 void pauseThreads(uint32 threadId); 98 void unpauseThreads(uint32 threadId); 99 void suspendThreads(uint32 threadId); 100 void resumeThreads(uint32 threadId); 101 void endTalkThreads(); 102 void endTalkThreadsNoNotify(); 103 void terminateThreadChain(uint32 threadId); 104 void killThread(uint32 threadId); 105 void setThreadSceneId(uint32 threadId, uint32 sceneId); 106 uint32 getThreadSceneId(uint32 threadId); 107 bool isActiveThread(int msgNum); 108 protected: 109 typedef Common::List<Thread*> List; 110 typedef List::iterator Iterator; 111 IllusionsEngine *_vm; 112 List _threads; 113 }; 114 115 } // End of namespace Illusions 116 117 #endif // ILLUSIONS_THREAD_H 118