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