ScummVM API documentation
twine.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 TWINE_TWINE_H
23 #define TWINE_TWINE_H
24 
25 #include "backends/keymapper/keymap.h"
26 #include "common/platform.h"
27 #include "common/random.h"
28 #include "common/rect.h"
29 #include "engines/advancedDetector.h"
30 #include "engines/engine.h"
31 
32 #include "engines/metaengine.h"
33 #include "graphics/managed_surface.h"
34 #include "graphics/screen.h"
35 #include "graphics/pixelformat.h"
36 #include "graphics/surface.h"
37 #include "twine/detection.h"
38 #include "twine/input.h"
39 #include "twine/scene/actor.h"
40 #include "twine/scene/buggy.h"
41 #include "twine/script/script_life.h"
42 #include "twine/script/script_move.h"
43 #include "twine/shared.h"
44 
45 namespace TwinE {
46 
48 #define EUROPE_VERSION 0
49 
50 #define USA_VERSION 1
51 
52 #define MODIFICATION_VERSION 2
53 
55 #define DEFAULT_FRAMES_PER_SECOND 20
56 #define DEFAULT_HZ (1000 / DEFAULT_FRAMES_PER_SECOND)
57 
58 #define ORIGINAL_WIDTH 640
59 #define ORIGINAL_HEIGHT 480
60 
61 static const struct TwinELanguage {
62  const char *name;
63  const char *id;
64  const int voice;
65 } LanguageTypes[] = {
66  {"English", "EN_", 1},
67  {"French", "FR_", 2},
68  {"German", "DE_", 3},
69  {"Spanish", "SP_", 1},
70  {"Italian", "IT_", 1},
71  {"Portuguese", "", 1}};
72 
73 enum MidiFileType {
74  MIDIFILE_NONE,
75  MIDIFILE_DOS,
76  MIDIFILE_WIN
77 };
78 
80 enum MovieType {
81  CONF_MOVIE_NONE = 0,
82  CONF_MOVIE_FLA = 1,
83  CONF_MOVIE_FLAWIDE = 2,
84  CONF_MOVIE_FLAGIF = 3
85 };
86 
91 struct ConfigFile {
93  int32 _languageId = 0;
95  bool FlagDisplayText = false;
97  bool Debug = false;
99  MidiFileType MidiType = MIDIFILE_NONE;
101  int32 Version = EUROPE_VERSION;
103  int32 UseCD = 0;
105  int32 Sound = 0;
107  int32 Movie = CONF_MOVIE_FLA;
109  int32 Fps = 0;
110 
111  // these settings are not available in the original version
113  bool WallCollision = false;
115  bool UseAutoSaving = false;
116  bool Mouse = false;
117 
118  // these settings can be changed in-game - and must be persisted
120  int32 ShadowMode = 0;
121  int32 PolygonDetails = 2;
123  bool SceZoom = false;
124 };
125 
126 class Actor;
127 class Animations;
128 class Collision;
129 class Extra;
130 class GameState;
131 class Grid;
132 class Movements;
133 class Interface;
134 class Menu;
135 class Movies;
136 class MenuOptions;
137 class Music;
138 class Redraw;
139 class Renderer;
140 class Resources;
141 class Scene;
142 class Screens;
143 class ScriptLifeV1;
144 class ScriptMoveV1;
145 class Holomap;
146 class Sound;
147 class Text;
148 class DebugGrid;
149 struct Keyboard;
150 class Debug;
151 class DebugScene;
152 
153 enum class EngineState {
154  Menu,
155  GameLoop,
156  LoadedGame,
157  QuitGame
158 };
159 
160 enum class SceneLoopState {
161  Continue = -1,
162  ReturnToMenu = 0,
163  Finished = 1
164 };
165 
167  TwinEEngine *_engine;
168  ScopedEngineFreeze(TwinEEngine *engine, bool pause = false);
170 };
171 
172 struct ScopedCursor {
173  TwinEEngine *_engine;
174  ScopedCursor(TwinEEngine *engine);
175  ~ScopedCursor();
176 };
177 
178 class FrameMarker {
179 private:
180  TwinEEngine *_engine;
181  uint32 _fps;
182  uint32 _start;
183 public:
184  FrameMarker(TwinEEngine *engine, uint32 fps = DEFAULT_FRAMES_PER_SECOND);
185  ~FrameMarker();
186 };
187 
189 private:
190  using Super = Graphics::Screen;
191  TwinEEngine *_engine;
192  int _lastFrame = -1;
193 
194 public:
195  TwineScreen(TwinEEngine *engine);
196 
197  void update() override;
198 };
199 
200 class TwinEEngine : public Engine {
201 private:
202  int32 _isTimeFreezed = 0;
203  int32 _saveFreezedTime = 0;
204  int32 _mouseCursorState = 0;
205  ActorMoveStruct _loopMovePtr; // mainLoopVar1
206  PauseToken _pauseToken;
207  TwineGameType _gameType;
208  EngineState _state = EngineState::Menu;
209  Common::String _queuedFlaMovie;
210 
211  ScriptLife *_scriptLife;
212  ScriptMove *_scriptMove;
213 
215  Common::Language _gameLang;
216 
217  void processBookOfBu();
218  void processBonusList();
219  void processInventoryAction();
220  void processOptionsMenu();
221 
222  void initConfigurations();
224  void initAll();
225  void playIntro();
226  void processActorSamplePosition(int32 actorIdx);
228  void allocVideoMemory(int32 w, int32 h);
229 
234  bool runGameEngine();
235 public:
236  TwinEEngine(OSystem *system, Common::Language language, uint32 flagsTwineGameType, Common::Platform platform, TwineGameType gameType);
237  ~TwinEEngine() override;
238 
239  Common::Error run() override;
240  bool hasFeature(EngineFeature f) const override;
241 
242  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
243  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
244 
245  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
246  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
247 
248  int32 toSeconds(int x) const;
249  void wipeSaveSlot(int slot);
250  SaveStateList getSaveSlots() const;
251  void autoSave();
252 
253  void pushMouseCursorVisible();
254  void popMouseCursorVisible();
255 
256  bool isCDROM() const { return true; /* TODO */}
257  bool isLBA1() const { return _gameType == TwineGameType::GType_LBA; }
258  bool isLBA2() const { return _gameType == TwineGameType::GType_LBA2; }
259  bool isLBASlideShow() const { return _gameType == TwineGameType::GType_LBASHOW; }
260  bool isMod() const { return (_gameFlags & TwinE::TF_MOD) != 0; }
261  bool isDotEmuEnhanced() const { return (_gameFlags & TwinE::TF_DOTEMU_ENHANCED) != 0; }
262  bool isLba1Classic() const { return (_gameFlags & TwinE::TF_LBA1_CLASSIC) != 0; }
263  bool isDemo() const { return (_gameFlags & ADGF_DEMO) != 0; };
264  bool isAndroid() const { return _platform == Common::Platform::kPlatformAndroid; };
265  const char *getGameId() const;
266  Common::Language getGameLang() const;
267 
268  inline int numLocations() const {
269  const int maxLocations = isLBA1() ? 150 : NUM_LOCATIONS;
270  return maxLocations;
271  }
272 
273  bool unlockAchievement(const Common::String &id);
274 
275  Actor *_actor;
276  Animations *_animations;
277  Collision *_collision;
278  Extra *_extra;
279  GameState *_gameState;
280  Grid *_grid;
281  Movements *_movements;
282  Interface *_interface;
283  Menu *_menu;
284  Movies *_movie;
285  MenuOptions *_menuOptions;
286  Music *_music;
287  Redraw *_redraw;
288  Renderer *_renderer;
289  Resources *_resources;
290  Scene *_scene;
291  Screens *_screens;
292  Holomap *_holomap;
293  Sound *_sound;
294  Text *_text;
295  DebugGrid *_debugGrid;
296  Input *_input;
297  Debug *_debug;
298  Buggy *_buggy; // lba2
299  DebugScene *_debugScene;
300 
304 
305  int32 _frameCounter = 0;
306  SceneLoopState _sceneLoopState = SceneLoopState::ReturnToMenu; // FlagTheEnd
307  int32 timerRef = 0;
308 
309  int32 _loopInventoryItem = 0;
310  int32 _stepFalling = 0;
311  uint32 _gameFlags;
312  Common::Platform _platform;
313  bool _flagRain;
314 
316  bool _disableScreenRecenter = false;
317 
318  Graphics::ManagedSurface _imageBuffer;
323 
324  int width() const;
325  int height() const;
326 
327  // the resolution the game was meant to be played with
328  int originalWidth() const;
329  int originalHeight() const;
330 
331  Common::Rect rect() const;
332  Common::Rect centerOnScreen(int32 w, int32 h) const;
333  Common::Rect centerOnScreenX(int32 w, int32 y, int32 h) const;
334 
335  void extInitMcga();
336  void extInitSvga();
337  void testRestoreModeSVGA(bool redraw);
338 
339  void queueMovie(const char *filename);
340 
341  void clearScreenMinMax(Common::Rect &rect);
342  void adjustScreenMax(Common::Rect &rect, int16 x, int16 y);
343 
347  int getRandomNumber(uint max = 0x7FFF);
348 
349  void blitWorkToFront(const Common::Rect &rect);
350  void blitFrontToWork(const Common::Rect &rect);
351  void restoreFrontBuffer();
352  void saveFrontBuffer();
353 
354  void freezeTime(bool pause);
355  void unfreezeTime();
356 
361  bool gameEngineLoop();
362 
368  bool delaySkip(uint32 time);
369 
374  void setPalette(const uint32 *palette);
382  void setPalette(uint startColor, uint numColors, const byte *palette);
383 
391  void copyBlockPhys(int32 left, int32 top, int32 right, int32 bottom);
392  void copyBlockPhys(const Common::Rect &rect);
393 
395  void readKeys();
396 
404  void drawText(int32 x, int32 y, const Common::String &text, bool center = false, bool bigFont = false, int width = 100);
405 };
406 
407 inline int TwinEEngine::width() const {
408  return _frontVideoBuffer.w;
409 }
410 
411 inline int TwinEEngine::height() const {
412  return _frontVideoBuffer.h;
413 }
414 
415 inline Common::Rect TwinEEngine::rect() const {
416  return Common::Rect(0, 0, _frontVideoBuffer.w - 1, _frontVideoBuffer.h - 1);
417 }
418 
419 inline int TwinEEngine::originalWidth() const {
420  return 640;
421 }
422 
423 inline int TwinEEngine::originalHeight() const {
424  return 480;
425 }
426 
427 
428 } // namespace TwinE
429 
430 #endif
Definition: managed_surface.h:51
Graphics::ManagedSurface _workVideoBuffer
Definition: twine.h:320
Definition: engine.h:102
Definition: screens.h:33
Definition: str.h:59
EngineFeature
Definition: engine.h:250
Definition: twine.h:178
Definition: actor.h:261
Definition: holomap.h:49
Definition: stream.h:77
Definition: error.h:84
Definition: twine.h:166
Definition: grid.h:95
Definition: sound.h:53
Definition: random.h:44
Definition: menuoptions.h:34
Definition: input.h:113
Definition: rect.h:144
Definition: buggy.h:31
Definition: stream.h:745
Definition: screen.h:50
Definition: animations.h:34
ConfigFile _cfgfile
Definition: twine.h:303
Definition: twine.h:172
Definition: script_life_v1.h:31
Definition: renderer.h:97
Definition: debug_scene.h:33
Definition: debug.h:76
Definition: ustr.h:57
Definition: script_move_v1.h:31
Definition: scene.h:116
Definition: menu.h:135
Definition: script_move.h:59
TwineScreen _frontVideoBuffer
Definition: twine.h:322
Definition: extra.h:87
Definition: script_life.h:71
Definition: twine.h:200
Definition: achievements_tables.h:27
Definition: text.h:44
Definition: redraw.h:88
Definition: resources.h:128
Definition: actor.h:40
Definition: music.h:41
Definition: system.h:167
Definition: gamestate.h:42
Definition: debug_grid.h:31
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: twine.h:242
Add "-demo" to gameid.
Definition: advancedDetector.h:113
Definition: engine.h:143
Definition: movies.h:58
Definition: movements.h:34
Platform
Definition: platform.h:46
Definition: twine.h:188
Definition: collision.h:34
Definition: twine.h:91
Language
Definition: language.h:45
Definition: interface.h:36