ScummVM API documentation
cast.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_CAST_H
23 #define DIRECTOR_CAST_H
24 
25 #include "common/hash-str.h"
26 
27 namespace Common {
28  class ReadStreamEndian;
29  class MemoryWriteStream;
30  struct Rect;
31  class SeekableReadStreamEndian;
32 }
33 
34 namespace LingoDec {
35  class ChunkResolver;
36  struct ScriptContext;
37 }
38 
39 namespace Director {
40 
41 class Archive;
42 struct CastMemberInfo;
43 class CastMember;
44 class DirectorEngine;
45 class Lingo;
46 struct LingoArchive;
47 struct Resource;
48 class ScriptContext;
49 class Stxt;
50 class RTE0;
51 class RTE1;
52 class RTE2;
53 class BitmapCastMember;
54 class FilmLoopCastMember;
55 class ScriptCastMember;
56 class ShapeCastMember;
57 class TextCastMember;
58 class PaletteCastMember;
59 class SoundCastMember;
60 struct ConfigChunk;
61 
62 typedef Common::HashMap<byte, byte> CharMap;
63 typedef Common::HashMap<uint16, uint16> FontSizeMap;
65  Common::String toFont;
66  bool remapChars;
67  FontSizeMap sizeMap;
68 
69  FontXPlatformInfo() : remapChars(false) {}
70 };
72 
73 struct FontMapEntry {
74  uint16 toFont;
75  bool remapChars;
76  FontSizeMap sizeMap;
77 
78  FontMapEntry() : toFont(0), remapChars(false) {}
79 };
81 
82 #define NUMTILEPATTERNS 8
84  CastMemberID bitmapId;
85  Common::Rect rect;
86 };
87 
88 class Cast {
89 public:
90  Cast(Movie *movie, uint16 castLibID, bool isShared = false, bool isExternal = false, uint32 libResourceId = 1024);
91  ~Cast();
92 
93  void loadArchive();
94  void setArchive(Common::SharedPtr<Archive> archive);
95  Common::SharedPtr<Archive> getArchive() const { return _castArchive; };
96  Movie *getMovie() const { return _movie; }
97  void setMovie(Movie *movie) { _movie = movie; }
98  Common::String getMacName() const { return _macName; }
99  Common::String getCastName() const { return _castName; }
100  void setCastName(const Common::String &name) { _castName = name; }
101 
102  bool loadConfig();
103  void loadCast();
104  void loadCastDataVWCR(Common::SeekableReadStreamEndian &stream);
105  void loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Resource *res);
106  void loadCastInfo(Common::SeekableReadStreamEndian &stream, uint16 id);
107  void loadCastLibInfo(Common::SeekableReadStreamEndian &stream, uint16 id);
108  void loadLingoContext(Common::SeekableReadStreamEndian &stream);
109  void loadExternalSound(Common::SeekableReadStreamEndian &stream);
110  void loadSord(Common::SeekableReadStreamEndian &stream);
111  bool importFileInto(int castId, const Common::Path &path);
112 
113  void saveConfig(Common::SeekableWriteStream *writeStream, uint32 offset);
114  void saveCastData(Common::SeekableWriteStream *writeStream, Resource *res);
115  void saveCastData();
116  void writeCastInfo(Common::SeekableWriteStream *writeStream, uint32 castId);
117  uint32 getCastInfoSize(uint32 castId);
118  uint32 getCastInfoStringLength(uint32 stringIndex, CastMemberInfo *ci);
119 
120  uint32 getConfigSize();
121 
122  int getCastSize();
123  int getCastMaxID();
124  int getNextUnusedID();
125  Common::Rect getCastMemberInitialRect(int castId);
126  void setCastMemberModified(int castId);
127  CastMember *setCastMember(int castId, CastMember *cast);
128  bool duplicateCastMember(CastMember *source, CastMemberInfo *info, int targetId);
129  bool eraseCastMember(int castId);
130  CastMember *getCastMember(int castId, bool load = true);
131  CastMember *getCastMemberByNameAndType(const Common::String &name, CastType type);
132  CastMember *getCastMemberByScriptId(int scriptId);
133  int getCastIdByScriptId(uint32 scriptId) const;
134  CastMemberInfo *getCastMemberInfo(int castId);
135  const Stxt *getStxt(int castId);
136  Common::String getLinkedPath(int castId);
137  Common::String getVideoPath(int castId);
138  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id);
139  void rebuildCastNameCache();
140 
141  // release all castmember's widget, should be called when we are changing movie.
142  // because widget is handled by channel, thus we should clear all of those run-time info when we are switching the movie. (because we will create new widgets for cast)
143  void releaseCastMemberWidget();
144 
145  void dumpScript(const char *script, ScriptType type, uint16 id);
146 
147  Common::CodePage getFileEncoding();
148  Common::U32String decodeString(const Common::String &str);
149 
150  // Script contexts keep a back-pointer to their owning cast.
151  void registerScriptContext(ScriptContext *ctx) { _liveScriptContexts.setVal(ctx, true); }
152  void unregisterScriptContext(ScriptContext *ctx) { _liveScriptContexts.erase(ctx); }
153 
154  Common::String formatCastSummary(int castId);
155  PaletteV4 loadPalette(Common::SeekableReadStreamEndian &stream, int id);
156 
157 private:
158  void loadScriptV2(Common::SeekableReadStreamEndian &stream, uint16 id);
159  void loadFontMap(Common::SeekableReadStreamEndian &stream);
160  void loadFontMapV4(Common::SeekableReadStreamEndian &stream);
161  void loadFXmp(Common::SeekableReadStreamEndian &stream);
162  bool readFXmpLine(Common::SeekableReadStreamEndian &stream);
163  void loadVWTL(Common::SeekableReadStreamEndian &stream);
164 
165  uint32 computeChecksum();
166 
167 public:
168  Common::SharedPtr<Archive> _castArchive;
169  Common::Platform _platform;
170  uint16 _castLibID;
171  uint32 _libResourceId;
172  bool _isExternal;
173 
174  CharMap _macCharsToWin;
175  CharMap _winCharsToMac;
176  FontXPlatformMap _fontXPlatformMap;
177  FontMap _fontMap;
178 
179  bool _isProtected;
180 
186  uint16 _castIDoffset;
187 
188  Common::Rect _movieRect;
189  TilePatternEntry _tiles[kNumBuiltinTiles];
190 
191  LingoArchive *_lingoArchive;
192 
193  LingoDec::ScriptContext *_lingodec = nullptr;
194  LingoDec::ChunkResolver *_chunkResolver = nullptr;
195 
196  uint16 _castArrayStartForChecksum;
197  uint16 _castArrayEndForChecksum;
198 
199  /* Config Data to be saved */
200  /* 0 */ uint16 _len;
201  /* 2 */ uint16 _fileVersion;
202  /* 4, 6, 8, 10 */ Common::Rect _checkRect;
203  /* 12 */ uint16 _castArrayStart;
204  /* 14 */ uint16 _castArrayEnd;
205  /* 16 */ byte _readRate;
206  /* 17 */ byte _lightswitch;
207 
208  // Director 6 and below
209  /* 18 */ int16 _unk1; // Mentioned in ProjectorRays as preD7field11
210 
211  // Director 7 and above: stageColorG at byte 18, stageColorB at byte 19;
212  // _unk1 keeps the raw 16-bit value for the VWCF checksum and save.
213  /* 18 */ uint8 _D7stageColorG;
214  /* 19 */ uint8 _D7stageColorB;
215 
216  /* 20 */ uint16 _commentFont;
217  /* 22 */ uint16 _commentSize;
218  /* 24 */ uint16 _commentStyle;
219 
220  // Director 6 and below
221  /* 26 */ uint16 _stageColor;
222  // Director 7 and above: stageColorIsRGB at byte 26, stageColorR at
223  // byte 27; _stageColor keeps the raw 16-bit value for checksum and save.
224  /* 26 */ uint8 _D7stageColorIsRGB;
225  /* 27 */ uint8 _D7stageColorR;
226 
227  /* 28 */ uint16 _bitdepth;
228  /* 30 */ uint8 _field17;
229  /* 31 */ uint8 _field18;
230  /* 32 */ int32 _field19;
231  /* 36 */ int16 _version;
232  /* 38 */ int16 _movieDepth;
233  /* 40 */ int32 _field22;
234  /* 44 */ int32 _field23;
235  /* 48 */ int32 _field24;
236  /* 52 */ int8 _field25;
237  /* 53 */ uint8 _field26;
238  /* 54 */ int16 _frameRate;
239  /* 56 */ int16 _platformID;
240  /* 58 */ int16 _protection;
241  /* 60 */ int32 _field29;
242  /* 64 */ uint32 _checksum;
243  /* 68 */ uint16 _field30; // Marked as remnants in ProjectorRays
244  /* 70 */ uint16 _defPaletteNum = 0; // _defaultPalette before D5, unused later
245  /* 72 */ uint32 _chunkBaseNum = 0;
246  /* 76 */ CastMemberID _defaultPalette;
247 
248  /****** D6.0-D8.5 *******/
249  /* 80 */ int8 _netUnk1 = 0;
250  /* 81 */ int8 _netUnk2 = 0;
251  /* 82 */ int16 _netPreloadNumFrames = 0;
252 
253  /****** post D9-D10 *******/
254  /* 84 */ uint32 _windowFlags = 0;
255  /* 88 */ CastMemberID _windowIconId;
256  /* 92 */ CastMemberID _windowMaskId;
257  /* 96 */ CastMemberID _windowDragRegionMaskId;
258 
259  /* 100 */ // End of config
260 
261 private:
262  DirectorEngine *_vm;
263  Lingo *_lingo;
264  Movie *_movie;
265 
266  bool _isShared;
267  bool _loadMutex;
268  Common::Array<CastMember *> _loadQueue;
269 
270  Common::String _macName;
271  Common::String _castName;
272 
275  Common::HashMap<uint16, int> _castsScriptIds;
276 
277  Common::HashMap<ScriptContext *, bool> _liveScriptContexts;
278 
279 };
280 
281 } // End of namespace Director
282 
283 #endif
Definition: cast.h:88
Definition: str.h:59
Definition: lingo.h:315
Definition: array.h:52
Definition: stxt.h:51
Definition: rect.h:536
Definition: path.h:52
Definition: cast.h:34
Definition: movie.h:88
Definition: archive.h:36
Definition: cast.h:64
Definition: director.h:125
Definition: ustr.h:57
Definition: cast.h:83
Definition: algorithm.h:29
Definition: resolver.h:15
Definition: archive.h:40
Definition: stream.h:351
Definition: context.h:26
Definition: stream.h:944
Definition: director.h:157
Definition: cast.h:73
Definition: ptr.h:159
Definition: castmember.h:48
Definition: lingo.h:366
Definition: types.h:424
Definition: castmember.h:163
Definition: lingo-object.h:213
Platform
Definition: platform.h:93