ScummVM API documentation
toon.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  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has
23  * exclusively licensed this code on March 23th, 2024, to be used in
24  * closed-source products.
25  * Therefore, any contributions (commits) to it will also be dual-licensed.
26  *
27  */
28 
29 #ifndef TOON_TOON_H
30 #define TOON_TOON_H
31 
32 #include "engines/engine.h"
33 #include "graphics/surface.h"
34 #include "common/random.h"
35 #include "common/error.h"
36 #include "toon/resource.h"
37 #include "toon/script.h"
38 #include "toon/script_func.h"
39 #include "toon/state.h"
40 #include "toon/picture.h"
41 #include "toon/anim.h"
42 #include "toon/movie.h"
43 #include "toon/font.h"
44 #include "toon/text.h"
45 #include "toon/audio.h"
46 #include "toon/console.h"
47 
48 namespace Common {
49 class MemoryWriteStreamDynamic;
50 }
51 
52 struct ADGameDescription;
53 
54 #define TOON_DAT_VER_MAJ 0 // 1 byte
55 #define TOON_DAT_VER_MIN 4 // 1 byte
56 #define TOON_SAVEGAME_VERSION 6
57 #define DATAALIGNMENT 4
58 #define MAX_SAVE_SLOT 99
59 
60 #define TOON_SCREEN_WIDTH 640
61 #define TOON_SCREEN_HEIGHT 400
62 #define TOON_BACKBUFFER_WIDTH 1280
63 #define TOON_BACKBUFFER_HEIGHT 400
64 
73 namespace Toon {
74 
75 enum TOONAction {
76  kActionNone,
77  kActionEscape,
78  kActionStopCurrentVoice,
79  kActionSaveGame,
80  kActionLoadGame,
81  kActionSubtitles,
82  kActionMuteMusic,
83  kActionSpeechMute,
84  kActionSFXMute,
85  kActionShowOptions
86 };
87 
88 enum ToonGameType {
89  GType_TOON = 1
90 };
91 
92 enum ToonDebugChannels {
93  kDebugAnim = 1 << 0,
94  kDebugCharacter = 1 << 1,
95  kDebugAudio = 1 << 2,
96  kDebugHotspot = 1 << 3,
97  kDebugFont = 1 << 4,
98  kDebugPath = 1 << 5,
99  kDebugMovie = 1 << 6,
100  kDebugPicture = 1 << 7,
101  kDebugResource = 1 << 8,
102  kDebugState = 1 << 9,
103  kDebugTools = 1 << 10,
104  kDebugText = 1 << 11
105 };
106 
107 class Picture;
108 class Movie;
109 class Hotspots;
110 class Character;
111 class CharacterDrew;
112 class CharacterFlux;
113 class FontRenderer;
114 class TextResource;
115 class AudioManager;
116 class PathFinding;
117 
118 class ToonEngine : public Engine {
119 public:
120  ToonEngine(OSystem *syst, const ADGameDescription *gameDescription);
121  ~ToonEngine() override;
122 
123  const ADGameDescription *_gameDescription;
124  Common::Language _language;
125  byte _numVariant;
126  byte _gameVariant;
127  char **_locationDirNotVisited;
128  char **_locationDirVisited;
129  char **_specialInfoLine;
130 
131  Common::Error run() override;
132  bool showMainMenu(bool &loadedGame);
133  bool showOptions();
134  bool showQuitConfirmationDialogue();
135  void init();
136  bool loadToonDat();
137  char **loadTextsVariants(Common::File &in);
138  void unloadTextsVariants(char **texts);
139  void unloadToonDat();
140  void setPaletteEntries(uint8 *palette, int32 offset, int32 num);
141  void fixPaletteEntries(uint8 *palette, int num);
142  void flushPalette(bool deferFlushToNextRender = true);
143  void parseInput();
144  void initChapter();
145  void initFonts();
146  void setFont(bool alternative);
147  void loadScene(int32 SceneId, bool forGameLoad = false);
148  void exitScene();
149  void loadCursor();
150  void setCursor(int32 type, bool inventory = false, int32 offsetX = 0, int offsetY = 0);
151  void loadAdditionalPalette(const Common::Path &fileName, int32 mode);
152  void setupGeneralPalette();
153  void render();
154  void update(int32 timeIncrement);
155  void doFrame();
156  void updateAnimationSceneScripts(int32 timeElapsed);
157  void updateCharacters(int32 timeElapsed);
158  void setSceneAnimationScriptUpdate(bool enable);
159  bool isUpdatingSceneAnimation();
160  int32 getCurrentUpdatingSceneAnimation();
161  int32 randRange(int32 minStart, int32 maxStart);
162  void selectHotspot();
163  void clickEvent();
164  int32 runEventScript(int32 x, int32 y, int32 mode, int32 id, int32 scriptId);
165  void flipScreens();
166  void drawInfoLine();
167  void drawConversationLine();
168  const char *getLocationString(int32 locationId, bool alreadyVisited);
169  int32 getScaleAtPoint(int32 x, int32 y);
170  int32 getZAtPoint(int32 x, int32 y);
171  int32 getLayerAtPoint(int32 x, int32 y);
172  int32 characterTalk(int32 dialogid, bool blocking = true);
173  int32 simpleCharacterTalk(int32 dialogid);
174  void sayLines(int numLines, int dialogId);
175  void haveAConversation(int32 convId);
176  void processConversationClick(Conversation *conv, int32 status);
177  int32 runConversationCommand(int16 **command);
178  void prepareConversations();
179  void drawConversationIcons();
180  void simpleUpdate(bool waitCharacterToTalk = false);
181  int32 waitTicks(int32 numTicks, bool breakOnMouseClick);
182  void copyToVirtualScreen(bool updateScreen = true);
183  void getMouseEvent();
184  int32 showInventory();
185  void drawSack();
186  void addItemToInventory(int32 item);
187  void deleteItemFromInventory(int32 item);
188  void replaceItemFromInventory(int32 item, int32 destItem);
189  void rearrangeInventory();
190  void createMouseItem(int32 item);
191  void deleteMouseItem();
192  void showCutaway(const Common::Path &cutawayPicture);
193  void hideCutaway();
194  void drawPalette();
195  void newGame();
196  void playSoundWrong();
197  void playSFX(int32 id, int32 volume);
198  void storeRifFlags(int32 location);
199  void restoreRifFlags(int32 location);
200  void getTextPosition(int32 characterId, int32 *retX, int32 *retY);
201  int32 getConversationFlag(int32 locationId, int32 param);
202  int32 getSpecialInventoryItem(int32 item);
203  Character *getCharacterById(int32 charId);
204  Common::String getSavegameName(int nr);
205  bool loadGame(int32 slot);
206  bool saveGame(int32 slot, const Common::String &saveGameDesc);
207  void fadeIn(int32 numFrames);
208  void fadeOut(int32 numFrames);
209  void initCharacter(int32 characterId, int32 animScriptId, int32 animToPlayId, int32 sceneAnimationId);
210  int32 handleInventoryOnFlux(int32 itemId);
211  int32 handleInventoryOnInventory(int32 itemDest, int32 itemSrc);
212  int32 handleInventoryOnDrew(int32 itemId);
213  int32 pauseSceneAnimationScript(int32 animScriptId, int32 tickToWait);
214  void updateTimer(int32 timeIncrement);
215  Common::Path createRoomFilename(const Common::String &name);
216  void createShadowLUT();
217  void playTalkAnimOnCharacter(int32 animID, int32 characterId, bool talker);
218  void updateScrolling(bool force, int32 timeIncrement);
219  void enableTimer(int32 timerId);
220  void setTimer(int32 timerId, int32 timerWait);
221  void disableTimer(int32 timerId);
222  void updateTimers();
223  void makeLineNonWalkable(int32 x, int32 y, int32 x2, int32 y2);
224  void makeLineWalkable(int32 x, int32 y, int32 x2, int32 y2);
225  void renderInventory();
226  void viewInventoryItem(const Common::Path &str, int32 lineId, int32 itemDest);
227  void storePalette();
228  void restorePalette();
229  const char *getSpecialConversationMusic(int32 locationId);
230  void playRoomMusic();
231  void waitForScriptStep();
232  void doMagnifierEffect();
233  void drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color);
234  bool showConversationText() const;
235  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
236  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
237  void pauseEngineIntern(bool pause) override;
238  void syncSoundSettings() override;
239 
240  Resources *resources() {
241  return _resources;
242  }
243 
244  State *state() {
245  return _gameState;
246  }
247 
248  Graphics::Surface &getMainSurface() {
249  return *_mainSurface;
250  }
251 
252  Picture *getMask() {
253  return _currentMask;
254  }
255 
256  Picture *getPicture() {
257  return _currentPicture;
258  }
259 
260  AnimationManager *getAnimationManager() {
261  return _animationManager;
262  }
263 
264  Movie *getMoviePlayer() {
265  return _moviePlayer;
266  }
267 
268  SceneAnimation *getSceneAnimation(int32 id) {
269  return &_sceneAnimations[id];
270  }
271 
272  SceneAnimationScript *getSceneAnimationScript(int32 id) {
273  return &_sceneAnimationScripts[id];
274  }
275 
276  EMCInterpreter *getScript() {
277  return _script;
278  }
279 
280  Hotspots *getHotspots() {
281  return _hotspots;
282  }
283 
284  Character *getCharacter(int32 charId) {
285  return _characters[charId];
286  }
287 
288  uint8 *getShadowLUT() {
289  return _shadowLUT;
290  }
291 
292  int32 getCurrentLineToSay() {
293  return _currentTextLineId;
294  }
295 
296  int32 getCurrentCharacterTalking() {
297  return _currentTextLineCharacterId;
298  }
299 
300  CharacterDrew *getDrew() {
301  return (CharacterDrew *)_drew;
302  }
303 
304  CharacterFlux *getFlux() {
305  return (CharacterFlux *)_flux;
306  }
307 
308  int32 getTickLength() {
309  return _tickLength;
310  }
311 
312  int32 getOldMilli() {
313  return _oldTimer2;
314  }
315 
316  AudioManager *getAudioManager() {
317  return _audioManager;
318  }
319 
320  int32 getScriptRegionNested() {
321  return _currentScriptRegion;
322  }
323 
324  int32 getMouseX() {
325  return _mouseX;
326  }
327 
328  int32 getMouseY() {
329  return _mouseY;
330  }
331 
332  PathFinding *getPathFinding() {
333  return _pathFinding;
334  }
335 
336  bool isEnglishDemo() {
337  return _isEnglishDemo;
338  }
339 
340  Common::WriteStream *getSaveBufferStream();
341 
342  bool shouldQuitGame() const {
343  return _shouldQuit;
344  }
345 
346  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override {
347  return (saveGame(slot, desc) ? Common::kNoError : Common::kWritingFailed);
348  }
349 
350  Common::Error loadGameState(int slot) override {
351  return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed);
352  }
353 
354  bool hasFeature(EngineFeature f) const override {
355  return
356  (f == kSupportsSubtitleOptions) ||
357  (f == kSupportsReturnToLauncher) ||
358  (f == kSupportsLoadingDuringRuntime) ||
359  (f == kSupportsSavingDuringRuntime);
360  }
361 
362  void dirtyAllScreen();
363  void addDirtyRect(int32 left, int32 top, int32 right, int32 bottom);
364  void clearDirtyRects();
365 
366 protected:
367  int32 _tickLength;
368  Resources *_resources;
369  TextResource *_genericTexts;
370  TextResource *_roomTexts;
371  State *_gameState;
372  uint8 *_finalPalette;
373  uint8 *_backupPalette;
374  uint8 *_additionalPalette1;
375  uint8 *_additionalPalette2;
376  bool _additionalPalette2Present;
377  uint8 *_cutawayPalette;
378  uint8 *_universalPalette;
379  uint8 *_fluxPalette;
380  uint8 *_roomScaleData;
381  uint8 *_shadowLUT;
382 
383  Picture *_currentPicture;
384  Picture *_currentMask;
385  Picture *_currentCutaway;
386  Picture *_inventoryPicture;
387  PathFinding *_pathFinding;
388 
389  EMCInterpreter *_script;
390  EMCData _scriptData;
391  EMCState _scriptState[4];
392  int32 _currentScriptRegion; // script region ( nested script run )
393 
394  ScriptFunc *_script_func;
395 
396  SceneAnimation _sceneAnimations[64];
397  SceneAnimationScript _sceneAnimationScripts[64];
398  int32 _lastProcessedSceneScript;
399  bool _animationSceneScriptRunFlag;
400  bool _updatingSceneScriptRunFlag;
401 
402  Graphics::Surface *_mainSurface;
403  Common::Array<Common::Rect> _dirtyRects;
404  Common::Array<Common::Rect> _oldDirtyRects;
405 
406  bool _dirtyAll;
407 
408 
409  AnimationInstance *_cursorAnimationInstance;
410  Animation *_cursorAnimation;
411  Animation *_dialogIcons;
412  Animation *_inventoryIcons;
413  Animation *_inventoryIconSlots;
414  int32 _cursorOffsetX;
415  int32 _cursorOffsetY;
416 
417  char *_currentTextLine;
418  int32 _currentTextLineId;
419  int32 _currentTextLineX;
420  int32 _currentTextLineY;
421  int32 _currentTextLineCharacterId;
422 
423  int32 _oldScrollValue;
424 
425  AnimationManager *_animationManager;
426 
427  Character *_characters[32];
428  Character *_drew;
429  Character *_flux;
430 
431  Hotspots *_hotspots;
432  int32 _currentHotspotItem;
433 
434  bool _shouldQuit;
435  int32 _scriptStep;
436 
437  int32 _mouseX;
438  int32 _mouseY;
439  int32 _mouseButton;
440  int32 _lastMouseButton;
441 
442  int32 _oldTimer;
443  int32 _oldTimer2;
444  int32 _lastRenderTime;
445 
446  Movie *_moviePlayer;
447 
449 
450  FontRenderer *_fontRenderer;
451  Animation *_fontToon;
452  Animation *_fontEZ;
453  Animation *_currentFont;
454  Common::String *_currentDemoFont;
455 
456  AudioManager *_audioManager;
457 
458  Common::MemoryWriteStreamDynamic *_saveBufferStream;
459 
460  int16 *_conversationData;
461 
462  bool _firstFrame;
463  bool _isDemo;
464  bool _isEnglishDemo;
465  bool _showConversationText;
466  int _textSpeed;
467  bool _useAlternativeFont;
468  bool _needPaletteFlush;
469  bool _noMusicDriver; // If "Music Device" is set to "No Music" from Audio tab
470 };
471 
472 } // End of namespace Toon
473 
474 #endif
Definition: anim.h:193
Definition: flux.h:38
Definition: str.h:59
Definition: surface.h:67
Failed to read a file (permission denied?).
Definition: error.h:62
EngineFeature
Definition: engine.h:253
Definition: stream.h:77
Definition: error.h:84
Definition: conversation.h:37
Definition: script.h:44
Definition: advancedDetector.h:163
Definition: random.h:44
Definition: state.h:52
No error occurred.
Definition: error.h:48
Definition: memstream.h:194
Definition: path.h:52
Definition: anim.h:181
Definition: script_func.h:41
Common::Error loadGameState(int slot) override
Definition: toon.h:350
bool hasFeature(EngineFeature f) const override
Definition: toon.h:354
Definition: toon.h:118
Definition: movie.h:54
Definition: resource.h:80
Definition: ustr.h:57
Definition: file.h:47
Definition: anim.h:164
Definition: algorithm.h:29
Definition: text.h:36
Definition: drew.h:38
Definition: audio.h:131
Definition: font.h:38
Definition: anim.h:39
Definition: hotspot.h:54
Definition: script.h:55
Definition: anim.h:95
Definition: system.h:161
Definition: character.h:58
Failure to write data - disk full?
Definition: error.h:63
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Definition: toon.h:346
Definition: engine.h:144
Definition: path.h:64
Definition: picture.h:43
Definition: script.h:100
Definition: anim.h:54
Language
Definition: language.h:45