ScummVM API documentation
twp.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_H
23#define TWP_H
24
25#include "common/random.h"
26#include "common/ptr.h"
27#include "engines/engine.h"
28#include "twp/actorswitcher.h"
29#include "twp/squirrel/squirrel.h"
30
31#define SCREEN_MARGIN 100.f
32#define SCREEN_WIDTH 1280
33#define SCREEN_HEIGHT 720
34#define VERBDEFAULT "verbDefault"
35
36template<typename T, class DL = Common::DefaultDeleter<T> >
38
39namespace Graphics {
40class Screen;
41}
42
44
45namespace Twp {
46
47struct ActorSlot;
48class AudioSystem;
49class Callback;
50class Camera;
51class Cutscene;
52class Dialog;
53class FadeShader;
54class GGPackSet;
55class Hud;
56class TwpImGui;
57class InputState;
58struct Light;
59class Lighting;
60class LightingNode;
61class Motor;
62class NoOverrideNode;
63class Object;
64class PathNode;
65class ResManager;
66class Room;
67class SaveGameManager;
68struct Scaling;
69class Scene;
70struct ShaderParams;
71class Task;
72class TextDb;
73class ThreadBase;
74struct TwpGameDescription;
75struct Verb;
76struct VerbId;
77class Vm;
78class WalkboxNode;
79
80enum class FadeEffect;
81enum class RoomEffect;
82enum class UseFlag;
83
84class TwpEngine : public Engine {
85private:
86 const TwpGameDescription *_gameDescription;
87 Common::RandomSource _randomSource;
88
89protected:
90 // Engine APIs
91 Common::Error run() override;
92
93public:
94 TwpEngine(OSystem *syst, const TwpGameDescription *gameDesc);
95 ~TwpEngine() override;
96
97 uint32 getFeatures() const;
98
103
107 Common::RandomSource &getRandomSource() { return _randomSource; }
108
109 HSQUIRRELVM getVm();
110 inline Gfx &getGfx() { return _gfx; }
111 inline TextDb &getTextDb() { return *_textDb; }
112
113 bool hasFeature(EngineFeature f) const override {
114 return (f == kSupportsLoadingDuringRuntime) ||
118 }
119
120 void updateSettingVars();
121
122 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override {
123 return !_cutscene;
124 }
125 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
126
127 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
128
129 Common::Error loadGameState(int slot) override;
131 Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
132 bool canSaveAutosaveCurrently() override { return false; }
133 void capture(Graphics::Surface &surface, int width, int height);
134
135 Math::Vector2d winToScreen(const Math::Vector2d &pos) const;
136 Math::Vector2d screenToWin(const Math::Vector2d &pos) const;
137 Math::Vector2d roomToScreen(const Math::Vector2d &pos) const;
138 Math::Vector2d screenToRoom(const Math::Vector2d &pos) const;
139
140 void setActor(Common::SharedPtr<Object> actor, bool userSelected = false);
141 Common::SharedPtr<Object> objAt(const Math::Vector2d &pos);
142 void flashSelectableActor(int flash);
143 void sayLineAt(const Math::Vector2d &pos, const Color &color, Common::SharedPtr<Object> actor, float duration, const Common::String &text);
144 void stopTalking();
145 bool isSomeoneTalking() const;
146 void walkFast(bool state = true);
147
148 void actorEnter(Common::SharedPtr<Object> actor);
149 void actorExit(Common::SharedPtr<Object> actor);
150 Common::SharedPtr<Room> defineRoom(const Common::String &name, HSQOBJECT table, bool pseudo = false);
151 void setRoom(Common::SharedPtr<Room> room, bool force = false);
152 void enterRoom(Common::SharedPtr<Room> room, Common::SharedPtr<Object> door = nullptr);
153
154 void cameraAt(const Math::Vector2d &at);
155 // Returns the camera position: the position of the middle of the screen.
156 Math::Vector2d cameraPos();
157 void follow(Common::SharedPtr<Object> actor);
158 void fadeTo(FadeEffect effect, float duration, bool fadeToSep = false);
159
160 void execNutEntry(HSQUIRRELVM v, const Common::String &entry);
161 void execBnutEntry(HSQUIRRELVM v, const Common::String &entry);
162 bool callVerb(Common::SharedPtr<Object> actor, VerbId verbId, Common::SharedPtr<Object> noun1, Common::SharedPtr<Object> noun2 = nullptr);
163 bool execSentence(Common::SharedPtr<Object> actor, VerbId verbId, Common::SharedPtr<Object> noun1, Common::SharedPtr<Object> noun2 = nullptr);
164
165 float getRandom() const;
166 float getRandom(float min, float max) const;
167
168 int runDialog(GUI::Dialog &dialog) override;
169
170private:
171 void update(float elapsedMs);
172 void draw(RenderTexture *texture = nullptr);
173 void exitRoom(Common::SharedPtr<Room> nextRoom);
174 void cancelSentence(Common::SharedPtr<Object> actor = nullptr);
175 void clickedAt(const Math::Vector2d &scrPos);
176 bool clickedAtHandled(const Math::Vector2d &roomPos);
177 void setShaderEffect(RoomEffect effect);
178 bool selectable(Common::SharedPtr<Object> actor);
179 void resetVerb();
180 Common::String cursorText();
181 Verb verb();
183 void updateTriggers();
184 void callTrigger(Common::SharedPtr<Object> obj, HSQOBJECT trigger);
185 Common::Array<ActorSwitcherSlot> actorSwitcherSlots();
186 ActorSwitcherSlot actorSwitcherSlot(ActorSlot *slot);
187 Scaling *getScaling(const Common::String &name);
188 void skipCutscene();
189
190private:
191 unique_ptr<Vm> _vm;
192
193public:
195 unique_ptr<ResManager> _resManager;
202 Common::SharedPtr<Object> _followActor;
204 float _time = 0.f;
207 UseFlag _useFlag;
208 HSQOBJECT _defaultObj;
209 bool _walkFastState = false;
210 bool _holdToMove = false;
211 float _nextHoldToMoveTime = 0.f;
212 int _frameCounter = 0;
215 unique_ptr<Scene> _scene;
216 unique_ptr<Scene> _screenScene;
217 unique_ptr<NoOverrideNode> _noOverride;
218 InputState _inputState;
219 unique_ptr<Camera> _camera;
220 unique_ptr<TextDb> _textDb;
221 unique_ptr<Dialog> _dialog;
222 struct Cursor {
223 Math::Vector2d pos;
224 bool oldLeftDown = false;
225 bool leftDown = false;
226 int leftDownTime = 0;
227 bool oldRightDown = false;
228 bool rightDown = false;
229 int doubleClick = false;
230 bool holdLeft = false;
231 bool holdRight = false;
232 bool holdUp = false;
233 bool holdDown = false;
234
235 void update() {
236 oldLeftDown = leftDown;
237 oldRightDown = rightDown;
238 }
239 bool isLeftDown() { return !oldLeftDown && leftDown; }
240 bool isRightDown() { return !oldRightDown && rightDown; }
241 } _cursor;
242
243 struct Stats {
244 uint32 totalUpdateTime = 0;
245 uint32 updateRoomTime = 0;
246 uint32 updateTasksTime = 0;
247 uint32 updateMiscTime = 0;
248 uint32 updateCutsceneTime = 0;
249 uint32 updateThreadsTime = 0;
250 uint32 updateCallbacksTime = 0;
251 uint32 drawTime = 0;
252 } _stats;
253 unique_ptr<Hud> _hud;
254 Inventory _uiInv;
255 ActorSwitcher _actorSwitcher;
257 unique_ptr<SaveGameManager> _saveGameManager;
258 unique_ptr<ShaderParams> _shaderParams;
259 unique_ptr<HotspotMarkerNode> _hotspotMarker;
260 unique_ptr<FadeShader> _fadeShader;
261 unique_ptr<LightingNode> _lightingNode;
262 unique_ptr<Motor> _moveCursorTo;
263
264private:
265 Gfx _gfx;
266 SentenceNode _sentence;
267 unique_ptr<WalkboxNode> _walkboxNode;
268 unique_ptr<PathNode> _pathNode;
269 unique_ptr<Shader> _bwShader;
270 unique_ptr<Shader> _ghostShader;
271 unique_ptr<Shader> _sepiaShader;
272 int _speed = 1;
273 bool _control = false;
274 unique_ptr<Motor> _talking;
275};
276
277extern TwpEngine *g_twp;
278#define SHOULD_QUIT ::Twp::g_twp->shouldQuit()
279
280} // End of namespace Twp
281
282#endif // TWP_H
Definition: array.h:52
Definition: error.h:81
Definition: random.h:44
Definition: ptr.h:572
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
@ kSupportsReturnToLauncher
Definition: engine.h:296
@ kSupportsSavingDuringRuntime
Definition: engine.h:314
@ kSupportsLoadingDuringRuntime
Definition: engine.h:305
@ kSupportsChangingOptionsDuringRuntime
Definition: engine.h:322
Definition: dialog.h:49
Definition: system.h:166
Definition: actorswitcher.h:49
Definition: gfx.h:161
Definition: scenegraph.h:243
Definition: scenegraph.h:295
Definition: gfx.h:116
Definition: scenegraph.h:336
Definition: twp.h:84
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Common::Error run() override
Common::Error loadGameState(int slot) override
bool hasFeature(EngineFeature f) const override
Definition: twp.h:113
int runDialog(GUI::Dialog &dialog) override
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::RandomSource & getRandomSource()
Definition: twp.h:107
Common::String getGameId() const
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: twp.h:122
bool canSaveAutosaveCurrently() override
Definition: twp.h:132
Definition: formatinfo.h:28
Definition: advancedDetector.h:164
Definition: surface.h:67
Definition: sqvm.h:34
Definition: atari-screen.h:58
Definition: hud.h:75
Definition: actorswitcher.h:37
Definition: gfx.h:35
Definition: room.h:71
Definition: twp.h:222
Definition: twp.h:243
Definition: detection.h:57
Definition: hud.h:51
Definition: object.h:78
Definition: squirrel.h:154