ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 };
97 
98 enum {
99  GF_DESKTOP = 1 << 0,
100  GF_640x480 = 1 << 1,
101  GF_32BPP = 1 << 2,
102  GF_GAMMA = 1 << 3,
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 _skipFrameAdvance;
271  bool _centerStage;
272  char _dirSeparator;
273  bool _fixStageSize;
274  Archive *_mainArchive;
275  Common::Rect _fixStageRect;
276  Common::List<Common::String> _extraSearchPath;
277 
278  // Owner of all Archive objects.
280  // Handles to resource files that were opened by OpenResFile.
282  // List of all currently open resource files
283  Common::List<Common::Path> _allOpenResFiles;
284 
286 
287 
288 protected:
289  Common::Error run() override;
290 
291 public:
292  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 
306 private:
307  byte _currentPalette[768];
308  uint16 _currentPaletteLength;
309  bool _gammaCorrection;
310  Lingo *_lingo;
311  uint16 _version;
312 
313  Window *_stage;
314  Common::Array<Window *> _windowList;
315  Common::Array<Window *> _windowsToForget;
316  Window *_currentWindow;
317  Window *_cursorWindow;
318 
319  Graphics::MacPatterns _director3Patterns;
320  Graphics::MacPatterns _director3QuickDrawPatterns;
321  PatternTile _builtinTiles[kNumBuiltinTiles];
322 
325  PaletteV4 _loaded4Palette;
326 
327  Graphics::ManagedSurface *_surface;
328  Graphics::Primitives *_primitives;
329 
330  StartOptions _options;
331 
332 public:
333  const Common::Array<Window *> *getWindowList() { return &_windowList; }
334 
335  int _tickBaseline;
336  Common::Path _traceLogFile;
337 
338  uint16 _framesRan = 0; // used by kDebugFewFramesOnly
339  bool _noFatalLingoError = false;
340 
341  bool _firstMovie = true;
342 };
343 
344 // An extension of MacPlotData for interfacing with inks and patterns without
345 // needing extra surfaces.
347  DirectorEngine *d = nullptr;
348  Graphics::ManagedSurface *dst = nullptr;
349 
350  Common::Rect destRect;
351  Common::Point srcPoint;
352 
353  Graphics::ManagedSurface *srf = nullptr;
354  MacShape *ms = nullptr;
355 
356  SpriteType sprite = kInactiveSprite;
357  bool oneBitImage = false;
358  InkType ink = kInkTypeCopy;
359  uint32 colorWhite;
360  uint32 colorBlack;
361  int alpha = 0;
362 
363  uint32 backColor;
364  uint32 foreColor;
365  bool applyColor = false;
366 
367  // graphics.cpp
368  void setApplyColor();
369  uint32 preprocessColor(uint32 src);
370  void inkBlitShape(Common::Rect &srcRect);
371  void inkBlitSurface(Common::Rect &srcRect, const Graphics::Surface *mask);
372 
373  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) {
374  colorWhite = d->_wm->_colorWhite;
375  colorBlack = d->_wm->_colorBlack;
376  }
377 
378  DirectorPlotData(const DirectorPlotData &old) : d(old.d), sprite(old.sprite),
379  ink(old.ink), alpha(old.alpha),
380  backColor(old.backColor), foreColor(old.foreColor),
381  srf(old.srf), dst(old.dst),
382  destRect(old.destRect), srcPoint(old.srcPoint),
383  colorWhite(old.colorWhite), colorBlack(old.colorBlack),
384  applyColor(old.applyColor) {
385  if (old.ms) {
386  ms = new MacShape(*old.ms);
387  } else {
388  ms = nullptr;
389  }
390  }
391 
392  DirectorPlotData &operator=(const DirectorPlotData &);
393 
394  ~DirectorPlotData() {
395  delete ms;
396  }
397 };
398 
399 extern DirectorEngine *g_director;
400 extern Debugger *g_debugger;
401 
402 } // End of namespace Director
403 
404 #endif
Definition: managed_surface.h:51
Definition: director.h:105
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:113
Definition: archive.h:35
Definition: macwindowmanager.h:147
Definition: archive.h:53
Definition: primitives.h:29
Definition: director.h:124
Definition: hashmap.h:85
Definition: director.h:147
Definition: events.h:199
Definition: algorithm.h:29
Definition: fs.h:69
Definition: formatinfo.h:28
Definition: rect.h:45
Definition: director.h:133
Definition: macwindowmanager.h:117
Definition: director.h:119
Definition: director.h:156
Definition: system.h:161
Definition: engine.h:144
Definition: detection.h:35
Definition: lingo.h:348
Definition: types.h:408
Definition: director.h:346
Platform
Definition: platform.h:46
Language
Definition: language.h:45