ScummVM API documentation
thread.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef TWP_THREAD_H
23#define TWP_THREAD_H
24
25#include "common/array.h"
26#include "common/str.h"
27#include "twp/squirrel/squirrel.h"
28
29namespace Twp {
30
32public:
33 virtual ~ThreadBase() {}
34
35 void pause() {
36 if (_pauseable) {
37 _paused = true;
38 suspend();
39 }
40 }
41
42 void unpause() {
43 _paused = false;
44 resume();
45 }
46
47 void setName(const Common::String &name) { _name = name; }
48 Common::String getName() const { return _name; }
49
50 int getId() const { return _id; }
51 virtual HSQUIRRELVM getThread() = 0;
52
53 virtual bool isGlobal() = 0;
54 bool isSuspended();
55 bool isDead();
56
57 void suspend();
58 void resume();
59
60 virtual bool update(float elapsed) = 0;
61 virtual void stop() = 0;
62
63protected:
64public:
65 float _waitTime = 0.f;
66 int _numFrames = 0;
67 bool _paused = false;
68 bool _pauseable = false;
69 uint32 _lastUpdateTime = 0;
70
71protected:
72 int _id = 0;
73 Common::String _name;
74 bool _stopRequest = false;
75 bool _stopped = false;
76};
77
78class Thread final : public ThreadBase {
79public:
80 Thread(const Common::String &name, bool global, HSQOBJECT threadObj, HSQOBJECT envObj, HSQOBJECT closureObj, const Common::Array<HSQOBJECT> args);
81 virtual ~Thread() override final;
82
83 virtual bool isGlobal() override final { return _global; }
84 virtual HSQUIRRELVM getThread() override final { return _threadObj._unVal.pThread; }
85
86 bool call();
87 virtual bool update(float elapsed) override final;
88 virtual void stop() override final;
89
90public:
91 bool _global = false;
92 HSQOBJECT _threadObj, _envObj, _closureObj;
94};
95
96enum CutsceneState {
97 csStart,
98 csCheckEnd,
99 csOverride,
100 csCheckOverride,
101 csEnd,
102 csQuit
103};
104
105class Object;
106class Cutscene final : public ThreadBase {
107public:
108 Cutscene(const Common::String &name, int parentThreadId, HSQOBJECT threadObj, HSQOBJECT closure, HSQOBJECT closureOverride, HSQOBJECT envObj);
109 ~Cutscene() override final;
110
111 void start();
112 bool isGlobal() override final { return false; }
113 HSQUIRRELVM getThread() override final;
114 bool update(float elapsed) override final;
115 void stop() override final;
116
117 bool hasOverride() const;
118 void cutsceneOverride();
119 bool isStopped();
120
121 void setInputState(InputStateFlag state) { _inputState = state; }
122 void setShowCursor(bool state) { _showCursor = state; }
123
124private:
125 void checkEndCutscene();
126 void checkEndCutsceneOverride();
127 void doCutsceneOverride();
128
129private:
130 int _parentThreadId = 0;
131 HSQOBJECT _threadObj, _closure, _closureOverride, _envObj;
132 CutsceneState _state;
133 bool _showCursor = false;
134 InputStateFlag _inputState = (InputStateFlag)0;
136};
137
138} // namespace Twp
139
140#endif
Definition: array.h:52
Definition: str.h:59
Definition: thread.h:106
Definition: thread.h:31
Definition: thread.h:78
Definition: sqvm.h:34
Definition: squirrel.h:154