ScummVM API documentation
composer.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 COMPOSER_COMPOSER_H
23 #define COMPOSER_COMPOSER_H
24 
25 #include "common/formats/ini-file.h"
26 #include "common/random.h"
27 #include "common/system.h"
28 #include "common/debug.h"
29 #include "common/debug-channels.h"
30 #include "common/error.h"
31 #include "common/serializer.h"
32 #include "common/textconsole.h"
33 #include "common/rect.h"
34 
35 #include "engines/engine.h"
36 #include "engines/util.h"
37 
38 #include "gui/debugger.h"
39 
40 #include "graphics/surface.h"
41 
42 #include "audio/mixer.h"
43 
44 #include "composer/resource.h"
45 #include "composer/console.h"
46 #include "composer/detection.h"
47 
48 namespace Audio {
49  class QueuingAudioStream;
50 }
51 
52 namespace Composer {
53 
54 class Archive;
55 struct Animation;
56 class ComposerEngine;
57 class Pipe;
58 struct Sprite;
59 
60 enum {
61  kButtonRect = 0,
62  kButtonEllipse = 1,
63  kButtonSprites = 4
64 };
65 
66 class Button {
67 public:
68  Button() { }
69  Button(Common::SeekableReadStream *stream, uint16 id, uint gameType);
71 
72  bool contains(const Common::Point &pos) const;
73 
74  uint16 _id;
75  uint16 _type;
76  uint16 _zorder;
77  uint16 _scriptId;
78  uint16 _scriptIdRollOn;
79  uint16 _scriptIdRollOff;
80  bool _active;
81 
82  Common::Rect _rect;
83  Common::Array<uint16> _spriteIds;
84 };
85 
86 enum {
87  kEventAnimStarted = 1,
88  kEventAnimDone = 2,
89  kEventLoad = 3,
90  kEventUnload = 4,
91  kEventKeyDown = 5,
92  kEventChar = 6,
93  kEventKeyUp = 7
94 };
95 
97  uint16 keyId;
98  uint16 modifierId;
99  uint16 scriptId;
100 };
101 
102 struct RandomEvent {
103  uint16 weight;
104  uint16 scriptId;
105 };
106 
107 struct Library {
108  uint _id;
109  Archive *_archive;
110 
111  Common::String _group;
112  Common::List<Button> _buttons;
113  Common::List<KeyboardHandler> _keyboardHandlers;
114 };
115 
116 struct QueuedScript {
117  uint32 _baseTime;
118  uint32 _duration;
119  uint32 _count;
120  uint16 _scriptId;
121 };
122 
124  PendingPageChange() { }
125  PendingPageChange(uint16 id, bool remove) : _pageId(id), _remove(remove) { }
126 
127  uint16 _pageId;
128  bool _remove;
129 };
130 
131 struct OldScript {
132  OldScript(uint16 id, Common::SeekableReadStream *stream);
133  ~OldScript();
134 
135  uint16 _id;
136 
137  uint32 _size;
139 
140  uint16 _zorder;
141  uint32 _currDelay;
142 };
143 
144 class ComposerEngine : public Engine {
145 protected:
146  Common::Error run() override;
147 
148  template <typename T>
149  void syncArray(Common::Serializer &ser, Common::Array<T> &data, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
150  template <typename T>
151  void syncList(Common::Serializer &ser, Common::List<T> &data, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
152  template <typename T>
153  void syncListReverse(Common::Serializer &ser, Common::List<T> &data, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
154  template <typename T>
155  void sync(Common::Serializer &ser, T &data, Common::Serializer::Version minVersion, Common::Serializer::Version maxVersion);
156  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
157  Common::Error loadGameState(int slot) override;
158  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
159  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
160 
161 public:
162  ComposerEngine(OSystem *syst, const ComposerGameDescription *gameDesc);
163  ~ComposerEngine() override;
164 
165  bool hasFeature(EngineFeature f) const override;
166 
167  int getGameType() const;
168  const char *getGameId() const;
169  uint32 getFeatures() const;
170  Common::Language getLanguage() const;
171  Common::Platform getPlatform() const;
172  bool loadDetectedConfigFile(Common::INIFile &configFile) const;
173 
174  const ComposerGameDescription *_gameDescription;
175 
176 private:
177  Common::RandomSource *_rnd;
178 
179  Audio::SoundHandle _soundHandle;
180  Audio::QueuingAudioStream *_audioStream;
181  uint16 _currSoundPriority;
182 
183  uint32 _currentTime, _lastTime, _timeDelta;
184 
185  bool _needsUpdate;
186  Common::Array<Common::Rect> _dirtyRects;
187  Graphics::Surface _screen;
188  Common::List<Sprite> _sprites;
189 
190  uint _directoriesToStrip;
191  Common::INIFile _bookIni;
192  Common::String _bookGroup;
193  Common::List<Library> _libraries;
194  Common::Array<PendingPageChange> _pendingPageChanges;
195 
196  Common::Array<uint16> _stack;
197  Common::Array<uint16> _vars;
198 
199  Common::List<OldScript *> _oldScripts;
200  Common::Array<QueuedScript> _queuedScripts;
202  Common::List<Pipe *> _pipes;
204 
206 
207  void onMouseDown(const Common::Point &pos);
208  void onMouseMove(const Common::Point &pos);
209  void onKeyDown(uint16 keyCode);
210  void setCursor(uint16 id, const Common::Point &offset);
211  void setCursorVisible(bool visible);
212 
213  bool _mouseEnabled;
214  bool _mouseVisible;
215  Common::Point _lastMousePos;
216  const Button *_lastButton;
217  uint16 _mouseSpriteId;
218  Common::Point _mouseOffset;
219 
220  Common::String getSaveStateName(int slot) const override;
221  Common::String getStringFromConfig(const Common::String &section, const Common::String &key);
222  Common::Path getFilename(const Common::String &section, uint id);
223  Common::Path mangleFilename(Common::String filename);
224  void loadLibrary(uint id);
225  void unloadLibrary(uint id);
226 
227  bool hasResource(uint32 tag, uint16 id);
228  Common::SeekableReadStream *getResource(uint32 tag, uint16 id);
229 
230  void runEvent(uint16 id, int16 param1, int16 param2, int16 param3);
231  int16 runScript(uint16 id, int16 param1, int16 param2, int16 param3);
232 
233  int16 getArg(uint16 arg, uint16 type);
234  void setArg(uint16 arg, uint16 type, uint16 val);
235  void runScript(uint16 id);
236  int16 scriptFuncCall(uint16 id, int16 param1, int16 param2, int16 param3);
237  void runOldScript(uint16 id, uint16 wait);
238  void stopOldScript(uint16 id);
239  void tickOldScripts();
240  bool tickOldScript(OldScript *script);
241 
242  void loadAnimation(Animation *&anim, uint16 animId, int16 x, int16 y, int16 eventParam, int32 size = 0);
243  void playAnimation(uint16 animId, int16 param1, int16 param2, int16 param3);
244  void stopAnimation(Animation *anim, bool localOnly = false, bool pipesOnly = false);
245  void playWaveForAnim(uint16 id, uint16 priority, bool bufferingOnly);
246  void processAnimFrame();
247 
248  void playPipe(uint16 id);
249  void stopPipes();
250 
251  bool spriteVisible(uint16 id, uint16 animId);
252  Sprite *addSprite(uint16 id, uint16 animId, uint16 zorder, const Common::Point &pos);
253  void removeSprite(uint16 id, uint16 animId);
254  const Sprite *getSpriteAtPos(const Common::Point &pos);
255  const Button *getButtonFor(const Sprite *sprite, const Common::Point &pos);
256  void setButtonActive(uint16 id, bool active);
257 
258  void dirtySprite(const Sprite &sprite);
259  void redraw();
260  void loadCTBL(uint16 id, uint fadePercent);
261  void setBackground(uint16 id);
262  void decompressBitmap(uint16 type, Common::SeekableReadStream *stream, byte *buffer, uint32 size, uint width, uint height);
263  bool initSprite(Sprite &sprite);
264  Common::SeekableReadStream *getStreamForSprite(uint16 id);
265  void drawSprite(const Sprite &sprite);
266 };
267 
268 } // End of namespace Composer
269 
270 #endif
Definition: composer.h:102
Definition: str.h:59
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
Definition: composer.h:116
Definition: error.h:84
Definition: random.h:44
Definition: composer.h:123
Definition: list.h:44
Definition: graphics.h:50
Definition: rect.h:144
Definition: path.h:52
Definition: stream.h:745
Definition: serializer.h:79
Definition: composer.h:96
Definition: composer.h:131
Definition: mixer.h:49
Definition: resource.h:52
Definition: hashmap.h:85
Definition: ustr.h:57
Definition: composer.h:107
Definition: rect.h:45
Definition: audiostream.h:370
Definition: composer.h:66
Definition: ini-file.h:58
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: composer.h:156
Definition: graphics.h:32
Definition: system.h:167
Definition: composer.h:52
Definition: composer.h:144
Definition: engine.h:143
Definition: system.h:37
Platform
Definition: platform.h:46
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: composer.h:158
Language
Definition: language.h:45
Definition: detection.h:40