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