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