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 
36 template<typename T, class DL = Common::DefaultDeleter<T> >
38 
39 namespace Graphics {
40 class Screen;
41 }
42 
43 struct ADGameDescription;
44 
45 namespace Twp {
46 
47 struct ActorSlot;
48 class AudioSystem;
49 class Callback;
50 class Camera;
51 class Cutscene;
52 class Dialog;
53 class FadeShader;
54 class GGPackSet;
55 class Hud;
56 class TwpImGui;
57 class InputState;
58 struct Light;
59 class Lighting;
60 class LightingNode;
61 class Motor;
62 class NoOverrideNode;
63 class Object;
64 class PathNode;
65 class ResManager;
66 class Room;
67 class SaveGameManager;
68 struct Scaling;
69 class Scene;
70 struct ShaderParams;
71 class Task;
72 class TextDb;
73 class ThreadBase;
74 struct TwpGameDescription;
75 struct Verb;
76 struct VerbId;
77 class Vm;
78 class WalkboxNode;
79 
80 enum class FadeEffect;
81 enum class RoomEffect;
82 enum class UseFlag;
83 
84 class TwpEngine : public Engine {
85 private:
86  const TwpGameDescription *_gameDescription;
87  Common::RandomSource _randomSource;
88 
89 protected:
90  // Engine APIs
91  Common::Error run() override;
92 
93 public:
94  TwpEngine(OSystem *syst, const TwpGameDescription *gameDesc);
95  ~TwpEngine() override;
96 
97  uint32 getFeatures() const;
98 
102  Common::String getGameId() const;
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) ||
115  (f == kSupportsSavingDuringRuntime) ||
116  (f == kSupportsReturnToLauncher) ||
117  (f == kSupportsChangingOptionsDuringRuntime);
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;
130  Common::Error loadGameStream(Common::SeekableReadStream *stream) 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 
170 private:
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 
190 private:
191  unique_ptr<Vm> _vm;
192 
193 public:
194  unique_ptr<GGPackSet> _pack;
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;
213  Common::SharedPtr<Lighting> _lighting;
214  Common::SharedPtr<Cutscene> _cutscene;
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 
264 private:
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 
277 extern TwpEngine *g_twp;
278 #define SHOULD_QUIT ::Twp::g_twp->shouldQuit()
279 
280 } // End of namespace Twp
281 
282 #endif // TWP_H
Definition: hud.h:51
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: twp.h:122
Definition: twp.h:243
Definition: twp.h:222
Definition: sqvm.h:33
Definition: actorswitcher.h:49
Definition: str.h:59
Definition: gfx.h:116
Definition: surface.h:67
EngineFeature
Definition: engine.h:253
Definition: twp.h:84
Definition: stream.h:77
Definition: error.h:84
Definition: room.h:71
bool canSaveAutosaveCurrently() override
Definition: twp.h:132
Definition: array.h:52
Definition: advancedDetector.h:163
Definition: object.h:78
Definition: random.h:44
Definition: scenegraph.h:336
Definition: atari-screen.h:60
Definition: stream.h:745
Definition: hud.h:75
Definition: tsv.h:30
Definition: ptr.h:572
Definition: gfx.h:35
Definition: squirrel.h:153
Definition: ustr.h:57
Definition: scenegraph.h:295
Definition: formatinfo.h:28
Common::RandomSource & getRandomSource()
Definition: twp.h:107
Definition: actorswitcher.h:37
Definition: detection.h:58
Definition: dialog.h:49
bool hasFeature(EngineFeature f) const override
Definition: twp.h:113
Definition: system.h:161
Definition: ptr.h:159
Definition: engine.h:144
Definition: scenegraph.h:243
Definition: achievements_tables.h:27
Definition: gfx.h:161