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