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 isMod() const { return (_gameFlags & TwinE::TF_MOD) != 0; }
265  bool isDotEmuEnhanced() const { return (_gameFlags & TwinE::TF_DOTEMU_ENHANCED) != 0; }
266  bool isLba1Classic() const { return (_gameFlags & TwinE::TF_LBA1_CLASSIC) != 0; }
267  bool isDemo() const { return (_gameFlags & ADGF_DEMO) != 0; };
268  bool isAndroid() const { return _platform == Common::Platform::kPlatformAndroid; };
269  const char *getGameId() const;
270  Common::Language getGameLang() const;
271 
272  inline int numHoloPos() const {
273  const int maxLocations = isLBA1() ? MAX_HOLO_POS : MAX_HOLO_POS_2;
274  return maxLocations;
275  }
276 
277  inline int getMaxLife() const {
278  return isLBA1() ? 50 : 255;
279  }
280 
281  bool unlockAchievement(const Common::String &id);
282 
283  Actor *_actor;
284  Animations *_animations;
285  Collision *_collision;
286  Extra *_extra;
287  GameState *_gameState;
288  Grid *_grid;
289  Movements *_movements;
290  Interface *_interface;
291  Menu *_menu;
292  Movies *_movie;
293  MenuOptions *_menuOptions;
294  Music *_music;
295  Redraw *_redraw;
296  Renderer *_renderer;
297  Resources *_resources;
298  Scene *_scene;
299  Screens *_screens;
300  Holomap *_holomap;
301  Sound *_sound;
302  Text *_text;
303  Input *_input;
304  Buggy *_buggy; // lba2
305  Dart *_dart; // lba2
306  Rain *_rain; // lba2
307  Wagon *_wagon; // lba2
308  DebugState *_debugState;
309 
310  ScriptLife *_scriptLife;
311  ScriptMove *_scriptMove;
312 
316 
317  int32 _frameCounter = 0;
318  SceneLoopState _sceneLoopState = SceneLoopState::ReturnToMenu; // FlagTheEnd
319  int32 timerRef = 0;
320 
321  int32 _loopInventoryItem = 0;
322  int32 _stepFalling = 0;
323  uint32 _gameFlags = 0u;
324  Common::Platform _platform;
325  bool _flagRain = false;
326 
328  bool _cameraZone = false;
329 
330  Graphics::ManagedSurface _imageBuffer;
335 
336  int width() const;
337  int height() const;
338 
339  // the resolution the game was meant to be played with
340  int originalWidth() const;
341  int originalHeight() const;
342 
343  Common::Rect rect() const;
344  Common::Rect centerOnScreen(int32 w, int32 h) const;
345  Common::Rect centerOnScreenX(int32 w, int32 y, int32 h) const;
346 
347  void extInitMcga();
348  void extInitSvga();
349  void testRestoreModeSVGA(bool redraw);
350 
351  void queueMovie(const char *filename);
352 
353  void clearScreenMinMax(Common::Rect &rect);
354  void adjustScreenMax(Common::Rect &rect, int16 x, int16 y);
355 
359  int getRandomNumber(uint max = 0x7FFF);
360 
361  void blitWorkToFront(const Common::Rect &rect);
362  void copyBlock(const Common::Rect &rect);
363  void restoreFrontBuffer();
364  void saveFrontBuffer();
365 
366  void saveTimer(bool pause);
367  void restoreTimer();
368 
373  bool mainLoop();
374 
380  bool delaySkip(uint32 time);
381 
386  void setPalette(const Graphics::Palette &palette, uint startColor = 0u);
387 
395  void setPalette(uint startColor, uint numColors, const byte *palette);
396 
404  void copyBlockPhys(int32 left, int32 top, int32 right, int32 bottom);
405  void copyBlockPhys(const Common::Rect &rect);
406 
408  void readKeys();
409 
417  void drawText(int32 x, int32 y, const Common::String &text, bool center = false, bool bigFont = false, int width = 100);
418 };
419 
420 inline int TwinEEngine::width() const {
421  return _frontVideoBuffer.w;
422 }
423 
424 inline int TwinEEngine::height() const {
425  return _frontVideoBuffer.h;
426 }
427 
428 inline Common::Rect TwinEEngine::rect() const {
429  return Common::Rect(0, 0, _frontVideoBuffer.w - 1, _frontVideoBuffer.h - 1);
430 }
431 
432 inline int TwinEEngine::originalWidth() const {
433  return 640;
434 }
435 
436 inline int TwinEEngine::originalHeight() const {
437  return 480;
438 }
439 
440 
441 } // namespace TwinE
442 
443 #endif
Definition: managed_surface.h:51
Graphics::ManagedSurface _workVideoBuffer
Definition: twine.h:332
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:274
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:315
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:334
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:45
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