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  kDebugImGui,
94  kDebugPaused,
95  kDebugPauseOnLoad,
96  kDebugSaving,
97  kDebugPaths,
98 };
99 
100 enum {
101  GF_DESKTOP = 1 << 0,
102  GF_640x480 = 1 << 1,
103  GF_32BPP = 1 << 2,
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  Common::String getTargetName() { return _targetName; }
173  const char *getExtra();
174  Common::String getRawEXEName() const;
175  Common::String getEXEName() const;
176  StartMovie getStartMovie() const;
177  void parseOptions();
178  Graphics::MacWindowManager *getMacWindowManager() const { return _wm; }
179  Lingo *getLingo() const { return _lingo; }
180  Window *getStage() const { return _stage; }
181  Window *getCurrentWindow() const { return _currentWindow; }
182  Window *getOrCreateWindow(Common::String &name);
183  void forgetWindow(Window *window);
184  void setCurrentWindow(Window *window);
185  Window *getCursorWindow() const { return _cursorWindow; }
186  void setCursorWindow(Window *window) { _cursorWindow = window; }
187  Movie *getCurrentMovie() const;
188  void setCurrentMovie(Movie *movie);
189  Archive *getMainArchive() const { return _mainArchive; }
190  void setMainArchive(Archive *archive) { _mainArchive = archive; }
191  Common::String getCurrentPath() const;
192  Common::String getCurrentAbsolutePath();
193  Common::Path getStartupPath() const;
194 
195  // graphics.cpp
196  bool hasFeature(EngineFeature f) const override;
197 
198  void addPalette(CastMemberID &id, const byte *palette, int length);
199  bool setPalette(const CastMemberID &id);
200  void setPalette(const byte *palette, uint16 count);
201  void shiftPalette(int startIndex, int endIndex, bool reverse);
202  void syncPalette();
203  void clearPalettes();
204  PaletteV4 *getPalette(CastMemberID id);
205  bool hasPalette(CastMemberID id);
206  void loadDefaultPalettes();
207 
208  const Common::HashMap<CastMemberID, PaletteV4> &getLoadedPalettes() { return _loadedPalettes; }
209  const Common::HashMap<CastMemberID, PaletteV4> &getLoaded16Palettes() { return _loaded16Palettes; }
210  const PaletteV4 &getLoaded4Palette() { return _loaded4Palette; }
211 
212  const Common::FSNode *getGameDataDir() const { return &_gameDataDir; }
213  const byte *getPalette() const { return _currentPalette; }
214  uint16 getPaletteColorCount() const { return _currentPaletteLength; }
215 
216  void loadPatterns();
217  Picture *getTile(int num);
218  const Common::Rect &getTileRect(int num);
219  uint32 transformColor(uint32 color);
220  Graphics::MacPatterns &getPatterns();
221  void setCursor(DirectorCursor type);
222  void draw();
223 
224  Graphics::Primitives *getInkPrimitives();
225  uint32 getColorBlack();
226  uint32 getColorWhite();
227 
228  void loadKeyCodes();
229  void setMachineType(int machineType);
230  Common::CodePage getPlatformEncoding();
231 
232  Archive *createArchive();
233  Archive *openArchive(const Common::Path &movie);
234  void addArchiveToOpenList(const Common::Path &path);
235  Archive *loadEXE(const Common::Path &movie);
236  Archive *loadEXEv3(Common::SeekableReadStream *stream);
237  Archive *loadEXEv4(Common::SeekableReadStream *stream);
238  Archive *loadEXEv5(Common::SeekableReadStream *stream);
239  Archive *loadEXEv7(Common::SeekableReadStream *stream);
240  Archive *loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
241  Archive *loadMac(const Common::Path &movie);
242 
243  bool desktopEnabled();
244 
245  // events.cpp
246  bool pollEvent(Common::Event &event);
247  bool processEvents(bool captureClick = false, bool skipWindowManager = false);
248  void processEventQUIT();
249  int getMacTicks();
250  Common::Array<Common::Event> _injectedEvents;
251 
252  // game-quirks.cpp
253  void gameQuirks(const char *target, Common::Platform platform);
254  void loadSlowdownCooloff(uint32 delay = 2000);
255 
256  void delayMillis(uint32 delay);
257 
258 public:
259  RandomState _rnd;
261  Graphics::PixelFormat _pixelformat;
262 
263  uint32 _debugDraw = 0;
264  int _defaultVolume = 255;
265 
266 public:
267  int _colorDepth;
268  Common::HashMap<int, int> _KeyCodes;
269  int _machineType;
270  bool _playbackPaused;
271  bool _centerStage;
272  char _dirSeparator;
273  bool _fixStageSize;
274  Archive *_mainArchive;
275  Common::Rect _fixStageRect;
276  Common::List<Common::String> _extraSearchPath;
277  bool _emulateMultiButtonMouse;
278 
279  // Owner of all Archive objects.
281  // Handles to resource files that were opened by OpenResFile.
283  // List of all currently open resource files
284  Common::List<Common::Path> _allOpenResFiles;
285 
287 
288 
289 protected:
290  Common::Error run() override;
291 
292 public:
293  const DirectorGameDescription *_gameDescription;
295  Common::FSNode _gameDataDir;
296  CastMemberID *_clipBoard;
297  uint32 _wmMode;
298  uint16 _wmWidth;
299  uint16 _wmHeight;
300  CastMemberID _lastPalette;
301 
302  // used for quirks
303  byte _fpsLimit;
304  TimeDate _forceDate;
305  uint32 _loadSlowdownFactor;
306  uint32 _loadSlowdownCooldownTime;
307  int _fileIOType;
308  bool _vfwPaletteHack;
309 
310 private:
311  byte _currentPalette[768];
312  uint16 _currentPaletteLength;
313  bool _gammaCorrection;
314  Lingo *_lingo;
315  uint16 _version;
316 
317  Window *_stage;
318  Common::Array<Window *> _windowList;
319  Common::Array<Window *> _windowsToForget;
320  Window *_currentWindow;
321  Window *_cursorWindow;
322 
323  Graphics::MacPatterns _director3Patterns;
324  Graphics::MacPatterns _director3QuickDrawPatterns;
325  PatternTile _builtinTiles[kNumBuiltinTiles];
326 
329  PaletteV4 _loaded4Palette;
330 
331  Graphics::ManagedSurface *_surface;
332  Graphics::Primitives *_primitives;
333 
334  StartOptions _options;
335 
336 public:
337  const Common::Array<Window *> *getWindowList() { return &_windowList; }
338 
339  int _tickBaseline;
340  Common::Path _traceLogFile;
341 
342  uint16 _framesRan = 0; // used by kDebugFewFramesOnly
343  bool _noFatalLingoError = false;
344 
345  bool _firstMovie = true;
346 };
347 
348 // An extension of MacPlotData for interfacing with inks and patterns without
349 // needing extra surfaces.
351  DirectorEngine *d = nullptr;
352  Graphics::ManagedSurface *dst = nullptr;
353 
354  Common::Rect destRect;
355  Common::Point srcPoint;
356 
357  Graphics::ManagedSurface *srf = nullptr;
358  MacShape *ms = nullptr;
359 
360  SpriteType sprite = kInactiveSprite;
361  bool oneBitImage = false;
362  InkType ink = kInkTypeCopy;
363  uint32 colorWhite;
364  uint32 colorBlack;
365  int alpha = 0;
366 
367  uint32 backColor;
368  uint32 foreColor;
369  bool applyColor = false;
370 
371  // graphics.cpp
372  void setApplyColor();
373  uint32 preprocessColor(uint32 src);
374  void inkBlitShape(Common::Rect &srcRect);
375  void inkBlitSurface(Common::Rect &srcRect, const Graphics::Surface *mask);
376 
377  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) {
378  colorWhite = d->_wm->_colorWhite;
379  colorBlack = d->_wm->_colorBlack;
380  }
381 
382  DirectorPlotData(const DirectorPlotData &old) : d(old.d), sprite(old.sprite),
383  ink(old.ink), alpha(old.alpha),
384  backColor(old.backColor), foreColor(old.foreColor),
385  srf(old.srf), dst(old.dst),
386  destRect(old.destRect), srcPoint(old.srcPoint),
387  colorWhite(old.colorWhite), colorBlack(old.colorBlack),
388  applyColor(old.applyColor) {
389  if (old.ms) {
390  ms = new MacShape(*old.ms);
391  } else {
392  ms = nullptr;
393  }
394  }
395 
396  DirectorPlotData &operator=(const DirectorPlotData &);
397 
398  ~DirectorPlotData() {
399  delete ms;
400  }
401 };
402 
403 extern DirectorEngine *g_director;
404 extern Debugger *g_debugger;
405 
406 } // End of namespace Director
407 
408 #endif
Definition: managed_surface.h:51
Definition: director.h:106
Definition: system.h:108
Definition: str.h:59
Definition: surface.h:67
EngineFeature
Definition: engine.h:258
Definition: util.h:74
Definition: error.h:81
Definition: picture.h:33
Definition: pixelformat.h:138
Definition: rect.h:524
Definition: path.h:52
Definition: window.h:106
Definition: debugger.h:66
Definition: movie.h:88
Definition: stream.h:745
Definition: director.h:114
Definition: archive.h:36
Definition: macwindowmanager.h:147
Definition: archive.h:75
Definition: primitives.h:29
Definition: director.h:125
Definition: hashmap.h:85
Definition: director.h:148
Definition: events.h:210
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:163
Definition: engine.h:144
Definition: detection.h:35
Definition: lingo.h:356
Definition: types.h:419
Definition: director.h:350
Platform
Definition: platform.h:93
Language
Definition: language.h:45