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