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 Thread;
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.id == 0;
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  SQRESULT skipCutscene();
171 
172 private:
173  void update(float elapsedMs);
174  void draw(RenderTexture *texture = nullptr);
175  void exitRoom(Common::SharedPtr<Room> nextRoom);
176  void cancelSentence(Common::SharedPtr<Object> actor = nullptr);
177  void clickedAt(const Math::Vector2d &scrPos);
178  bool clickedAtHandled(const Math::Vector2d &roomPos);
179  void setShaderEffect(RoomEffect effect);
180  bool selectable(Common::SharedPtr<Object> actor);
181  void resetVerb();
182  Common::String cursorText();
183  Verb verb();
185  void updateTriggers();
186  void callTrigger(Common::SharedPtr<Object> obj, HSQOBJECT trigger);
187  Common::Array<ActorSwitcherSlot> actorSwitcherSlots();
188  ActorSwitcherSlot actorSwitcherSlot(ActorSlot *slot);
189  Scaling *getScaling(const Common::String &name);
190 
191 private:
192  unique_ptr<Vm> _vm;
193 
194 public:
195  unique_ptr<GGPackSet> _pack;
196  unique_ptr<ResManager> _resManager;
203  Common::SharedPtr<Object> _followActor;
205  float _time = 0.f;
208  UseFlag _useFlag;
209  HSQOBJECT _defaultObj;
210  bool _walkFastState = false;
211  bool _holdToMove = false;
212  float _nextHoldToMoveTime = 0.f;
213  int _frameCounter = 0;
214  Common::SharedPtr<Lighting> _lighting;
215  struct {
216  int id = 0;
217  InputStateFlag inputState = (InputStateFlag)0;
218  bool showCursor = false;
219  bool inOverride = false;
220  HSQOBJECT envObj;
221  HSQOBJECT closureOverride;
222  } _cutscene;
223  unique_ptr<Scene> _scene;
224  unique_ptr<Scene> _screenScene;
225  unique_ptr<NoOverrideNode> _noOverride;
226  InputState _inputState;
227  unique_ptr<Camera> _camera;
228  unique_ptr<TextDb> _textDb;
229  unique_ptr<Dialog> _dialog;
230  struct Cursor {
231  Math::Vector2d pos;
232  bool oldLeftDown = false;
233  bool leftDown = false;
234  int leftDownTime = 0;
235  bool oldRightDown = false;
236  bool rightDown = false;
237  int doubleClick = false;
238  bool holdLeft = false;
239  bool holdRight = false;
240  bool holdUp = false;
241  bool holdDown = false;
242 
243  void update() {
244  oldLeftDown = leftDown;
245  oldRightDown = rightDown;
246  }
247  bool isLeftDown() { return !oldLeftDown && leftDown; }
248  bool isRightDown() { return !oldRightDown && rightDown; }
249  } _cursor;
250 
251  struct Stats {
252  uint32 totalUpdateTime = 0;
253  uint32 updateRoomTime = 0;
254  uint32 updateTasksTime = 0;
255  uint32 updateMiscTime = 0;
256  uint32 updateCutsceneTime = 0;
257  uint32 updateThreadsTime = 0;
258  uint32 updateCallbacksTime = 0;
259  uint32 drawTime = 0;
260  } _stats;
261  unique_ptr<Hud> _hud;
262  Inventory _uiInv;
263  ActorSwitcher _actorSwitcher;
265  unique_ptr<SaveGameManager> _saveGameManager;
266  unique_ptr<ShaderParams> _shaderParams;
267  unique_ptr<HotspotMarkerNode> _hotspotMarker;
268  unique_ptr<FadeShader> _fadeShader;
269  unique_ptr<LightingNode> _lightingNode;
270  unique_ptr<Motor> _moveCursorTo;
271 
272 private:
273  Gfx _gfx;
274  SentenceNode _sentence;
275  unique_ptr<WalkboxNode> _walkboxNode;
276  unique_ptr<PathNode> _pathNode;
277  unique_ptr<Shader> _bwShader;
278  unique_ptr<Shader> _ghostShader;
279  unique_ptr<Shader> _sepiaShader;
280  int _speed = 1;
281  bool _control = false;
282  unique_ptr<Motor> _talking;
283 };
284 
285 extern TwpEngine *g_twp;
286 #define SHOULD_QUIT ::Twp::g_twp->shouldQuit()
287 
288 } // End of namespace Twp
289 
290 #endif // TWP_H
Definition: hud.h:51
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: twp.h:122
Definition: twp.h:251
Definition: twp.h:230
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