ScummVM API documentation
director.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 DIRECTOR_DIRECTOR_H
23#define DIRECTOR_DIRECTOR_H
24
25#include "common/hash-ptr.h"
26#include "common/gui_options.h"
27
28#include "graphics/macgui/macwindowmanager.h"
29
30#include "director/types.h"
31#include "director/util.h"
32#include "director/detection.h"
33
34#define GAMEOPTION_GAMMA_CORRECTION GUIO_GAMEOPTIONS1
35#define GAMEOPTION_TRUE_COLOR GUIO_GAMEOPTIONS2
36
37namespace Common {
38class MacResManager;
39class SeekableReadStream;
40class SeekableReadStreamEndian;
41}
42
43namespace Graphics {
44class Primitives;
45class MacWindowManager;
46struct MacPlotData;
47struct WinCursorGroup;
48typedef Common::Array<const byte *> MacPatterns;
49
50class ManagedSurface;
51}
52
53namespace Director {
54
55class Archive;
56class MacArchive;
57class Cast;
58class Debugger;
59class DirectorSound;
60class Lingo;
61class LingoProfiler;
62class Movie;
63class Window;
64struct Picture;
65class Score;
66class Channel;
67class CastMember;
68class Stxt;
69
70enum {
71 kDebugLingoExec = 1,
72 kDebugCompile,
73 kDebugLoading,
74 kDebugImages,
75 kDebugText,
76 kDebugEvents,
77 kDebugParse,
78 kDebugCompileOnly,
79 kDebugSlow,
80 kDebugFast,
81 kDebugNoLoop,
82 kDebugNoBytecode,
83 kDebugFewFramesOnly,
84 kDebugPreprocess,
85 kDebugScreenshot,
86 kDebugDesktop,
87 kDebug32bpp,
88 kDebugEndVideo,
89 kDebugLingoStrict,
90 kDebugSound,
91 kDebugConsole,
92 kDebugXObj,
93 kDebugLingoThe,
94 kDebugPaused,
95 kDebugPauseOnLoad,
96 kDebugSaving,
97 kDebugPaths,
98};
99
100enum {
101 GF_DESKTOP = 1 << 0,
102 GF_640x480 = 1 << 1,
103 GF_TRUECOLOR = 1 << 2,
104 GF_GAMMA = 1 << 3,
105};
106
108 Common::String movie;
109 Common::String frameS;
110 int frameI;
111
112 MovieReference() { frameI = -1; }
113};
114
116 Common::String startMovie;
117 int16 startFrame;
118
119};
120
122 StartMovie startMovie;
123 Common::String startupPath;
124};
125
126struct PaletteV4 {
127 CastMemberID id;
128 const byte *palette;
129 int length;
130
131 PaletteV4(CastMemberID i, const byte *p, int l) : id(i), palette(p), length(l) {}
132 PaletteV4() : id(), palette(nullptr), length(0) {}
133};
134
135struct MacShape {
136 InkType ink;
137 byte spriteType;
138 uint32 foreColor;
139 uint32 backColor;
140 int lineSize;
141 uint pattern;
142
143 Picture *tile;
144 const Common::Rect *tileRect;
145
147};
148
150 Picture *img = nullptr;
151 Common::Rect rect;
152
153 ~PatternTile();
154};
155
156const int SCALE_THRESHOLD = 0x100;
157
158class DirectorEngine : public ::Engine {
159public:
160 DirectorEngine(OSystem *syst, const DirectorGameDescription *gameDesc);
161 ~DirectorEngine() override;
162
163 // Detection related functions
164
165 DirectorGameGID getGameGID() const;
166 const char *getGameId() const;
167 uint16 getDescriptionVersion() const;
168 uint16 getVersion() const { return _version; }
169 void setVersion(uint16 version);
170 Common::Platform getPlatform() const;
171 Common::Language getLanguage() const;
172 uint32 getGameFlags() const;
173 bool isDemo() const;
174 Common::String getTargetName() { return _targetName; }
175 const char *getExtra();
176 Common::String getRawEXEName() const;
177 Common::String getEXEName() const;
178 StartMovie getStartMovie() const;
179 void parseOptions();
180 Graphics::MacWindowManager *getMacWindowManager() const { return _wm; }
181 Lingo *getLingo() const { return _lingo; }
182 Window *getStage() const { return _stage; }
183 Window *getCurrentWindow() const { return _currentWindow; }
184 Window *getOrCreateWindow(Common::String &name);
185 void forgetWindow(Window *window);
186 bool isWindowRegistered(Window *window) const;
187 void setCurrentWindow(Window *window);
188 Window *getCursorWindow() const { return _cursorWindow; }
189 void setCursorWindow(Window *window) { _cursorWindow = window; }
190 Movie *getCurrentMovie() const;
191 void setCurrentMovie(Movie *movie);
192 Common::SharedPtr<Archive> getMainArchive() const { return _mainArchive; }
193 void setMainArchive(Common::SharedPtr<Archive> archive) { _mainArchive = archive; }
194 Common::String getCurrentPath() const;
195 Common::String getCurrentAbsolutePath();
196 Common::Path getStartupPath() const;
197
198 // graphics.cpp
199 bool hasFeature(EngineFeature f) const override;
200
201 void addPalette(CastMemberID &id, const byte *palette, int length);
202 bool setPalette(const CastMemberID &id);
203 void setPalette(const byte *palette, uint16 count);
204 void shiftPalette(int startIndex, int endIndex, bool reverse);
205 void syncPalette();
206 void clearPalettes();
207 PaletteV4 *getPalette(CastMemberID id);
208 bool hasPalette(CastMemberID id);
209 void loadDefaultPalettes();
210
211 const Common::HashMap<CastMemberID, PaletteV4> &getLoadedPalettes() { return _loadedPalettes; }
212 const Common::HashMap<CastMemberID, PaletteV4> &getLoaded16Palettes() { return _loaded16Palettes; }
213 const PaletteV4 &getLoaded4Palette() { return _loaded4Palette; }
214
215 const Common::FSNode *getGameDataDir() const { return &_gameDataDir; }
216 const byte *getPalette() const { return _currentPalette; }
217 uint16 getPaletteColorCount() const { return _currentPaletteLength; }
218
219 void loadPatterns();
220 Picture *getTile(int num);
221 const Common::Rect &getTileRect(int num);
222 uint32 transformColor(uint32 color);
223 Graphics::MacPatterns &getPatterns();
224 void setCursor(DirectorCursor type);
225 void draw();
226
227 Graphics::Primitives *getInkPrimitives();
228 uint32 getColorBlack();
229 uint32 getColorWhite();
230
231 void loadKeyCodes();
232 void setMachineType(int machineType);
233 Common::CodePage getPlatformEncoding();
234
235 Archive *createArchive();
236 Common::SharedPtr<Archive> openArchive(const Common::Path &movie);
237 void addArchiveToOpenList(const Common::Path &path);
238 Archive *loadEXE(const Common::Path &movie);
239 Archive *loadEXEv3(Common::SeekableReadStream *stream);
240 Archive *loadEXEv4(Common::SeekableReadStream *stream);
241 Archive *loadEXEv5(Common::SeekableReadStream *stream);
242 Archive *loadEXEv7(Common::SeekableReadStream *stream);
243 Archive *loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
244 Archive *loadMac(const Common::Path &movie);
245
246 bool desktopEnabled();
247
248 // events.cpp
249 bool pollEvent(Common::Event &event);
250 bool processSysEvents(bool captureClick = false, bool skipWindowManager = false);
251 void processEventQUIT();
252 int getMacTicks();
253 Common::Array<Common::Event> _injectedEvents;
254
255 // game-quirks.cpp
256 bool lingoOpenWrapper(const char *target, Common::Platform platform, const Common::String &whichApplication, const Common::String &whichDocument);
257 void gameQuirks(const char *target, Common::Platform platform);
258 void loadSlowdownCooloff(uint32 delay = 2000);
259
260 void delayMillis(uint32 delay);
261
262public:
263 RandomState _rnd;
265 Graphics::PixelFormat _pixelformat;
266
267 uint32 _debugDraw = 0;
268 int _defaultVolume = 255;
269
270public:
271 int _colorDepth;
273 int _machineType;
274 bool _centerStage;
275 char _dirSeparator;
276 bool _fixStageSize;
277 Common::SharedPtr<Archive> _mainArchive;
278 Common::Rect _fixStageRect;
279 Common::List<Common::String> _extraSearchPath;
280 bool _emulateMultiButtonMouse;
281
282 // Owner of all Archive objects.
284 // Handles to resource files that were opened by OpenResFile.
286 // List of all currently open resource files
287 Common::List<Common::Path> _allOpenResFiles;
288
290
291
292protected:
293 Common::Error run() override;
294
295public:
296 const DirectorGameDescription *_gameDescription;
298 Common::FSNode _gameDataDir;
299 CastMemberID *_clipBoard;
300 uint32 _wmMode;
301 uint16 _wmWidth;
302 uint16 _wmHeight;
303 CastMemberID _lastPalette;
304 CastMemberID _lastPuppetPalette;
305
306 // used for quirks
307 byte _fpsLimit;
308 TimeDate _forceDate;
309 uint32 _loadSlowdownFactor;
310 uint32 _loadSlowdownCooldownTime;
311 int _fileIOType;
312 bool _vfwPaletteHack;
313
314 uint16 _key;
315 int _keyCode;
316 byte _keyFlags;
317
318 LingoProfiler *_lingoProfiler = nullptr;
319
320private:
321 byte _currentPalette[768];
322 uint16 _currentPaletteLength;
323 bool _gammaCorrection;
324 Lingo *_lingo;
325 uint16 _version;
326
327 Window *_stage;
328 Common::Array<Window *> _windowList;
329 Common::Array<Window *> _windowsToForget;
330 Window *_currentWindow;
331 Window *_cursorWindow;
332
333 Graphics::MacPatterns _director3Patterns;
334 Graphics::MacPatterns _director3QuickDrawPatterns;
335 PatternTile _builtinTiles[kNumBuiltinTiles];
336
339 PaletteV4 _loaded4Palette;
340
341 Graphics::ManagedSurface *_surface;
342 Graphics::Primitives *_primitives;
343
344 StartOptions _options;
345
346public:
347 const Common::Array<Window *> *getWindowList() { return &_windowList; }
348
349 int _tickBaseline;
350 Common::Path _traceLogFile;
351
352 uint16 _framesRan = 0; // used by kDebugFewFramesOnly
353 bool _noFatalLingoError = false;
354
355 bool _firstMovie = true;
356};
357
358// An extension of MacPlotData for interfacing with inks and patterns without
359// needing extra surfaces.
361 DirectorEngine *d = nullptr;
362 Graphics::ManagedSurface *dst = nullptr;
363
364 Common::Rect destRect;
365 Common::Point srcPoint;
366
367 Graphics::ManagedSurface *srf = nullptr;
368 Graphics::ManagedSurface *srfMask = nullptr;
369 MacShape *ms = nullptr;
370
371 SpriteType sprite = kInactiveSprite;
372 bool oneBitImage = false;
373 InkType ink = kInkTypeCopy;
374 uint32 colorWhite;
375 uint32 colorBlack;
376 int alpha = 0;
377
378 uint32 backColor;
379 uint32 foreColor;
380 bool applyColor = false;
381
382 // graphics.cpp
383 void setApplyColor();
384 uint32 preprocessColor(uint32 src);
385 void inkBlitShape(Common::Rect &srcRect);
386 void inkBlitSurface(Common::Rect &srcRect, const Graphics::Surface *mask);
387
388 DirectorPlotData(DirectorEngine *d_, SpriteType s, InkType i, int a, uint32 b, uint32 f) : d(d_), sprite(s), ink(i), alpha(a), backColor(b), foreColor(f) {
389 colorWhite = d->_wm->_colorWhite;
390 colorBlack = d->_wm->_colorBlack;
391 }
392
393 DirectorPlotData(const DirectorPlotData &old) : d(old.d), sprite(old.sprite),
394 ink(old.ink), alpha(old.alpha),
395 backColor(old.backColor), foreColor(old.foreColor),
396 srf(old.srf), dst(old.dst),
397 destRect(old.destRect), srcPoint(old.srcPoint),
398 colorWhite(old.colorWhite), colorBlack(old.colorBlack),
399 applyColor(old.applyColor) {
400 if (old.ms) {
401 ms = new MacShape(*old.ms);
402 } else {
403 ms = nullptr;
404 }
405 }
406
407 DirectorPlotData &operator=(const DirectorPlotData &);
408
410 if (ms)
411 delete ms;
412 }
413};
414
415extern DirectorEngine *g_director;
416extern Debugger *g_debugger;
417
418} // End of namespace Director
419
420#endif
Definition: error.h:81
Definition: fs.h:69
Definition: hashmap.h:85
Definition: path.h:52
Definition: stream.h:745
Definition: ptr.h:159
Definition: str.h:59
Definition: debugger.h:70
Definition: director.h:158
bool hasFeature(EngineFeature f) const override
Common::Error run() override
Definition: lingo.h:366
Definition: lingo-profiler.h:51
Definition: movie.h:88
Definition: window.h:106
Definition: engine.h:149
const Common::String _targetName
Definition: engine.h:186
EngineFeature
Definition: engine.h:282
Definition: macwindowmanager.h:149
Definition: managed_surface.h:51
Definition: primitives.h:29
Definition: system.h:166
Language
Definition: language.h:45
Platform
Definition: platform.h:93
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: events.h:218
Definition: rect.h:144
Definition: rect.h:536
Definition: types.h:424
Definition: detection.h:35
Definition: director.h:360
Definition: director.h:135
Definition: director.h:107
Definition: director.h:126
Definition: director.h:149
Definition: picture.h:33
Definition: director.h:115
Definition: director.h:121
Definition: macwindowmanager.h:117
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: system.h:111