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, uint32 tag);
114  bool keepOriginalCastBytes(CastMember *target);
115  bool hasUnsavableChanges();
116  void saveCastData(Common::SeekableWriteStream *writeStream, Resource *res);
117  void saveCastData();
118  void writeCastInfo(Common::SeekableWriteStream *writeStream, uint32 castId);
119  uint32 getCastInfoSize(uint32 castId);
120  uint32 getCastInfoStringLength(uint32 stringIndex, CastMemberInfo *ci);
121 
122  uint32 getConfigSize();
123 
124  int getCastSize();
125  int getCastMaxID();
126  int getNextUnusedID();
127  Common::Rect getCastMemberInitialRect(int castId);
128  void setCastMemberModified(int castId);
129  CastMember *setCastMember(int castId, CastMember *cast);
130  bool duplicateCastMember(CastMember *source, CastMemberInfo *info, int targetId);
131  bool eraseCastMember(int castId);
132  CastMember *getCastMember(int castId, bool load = true);
133  CastMember *getCastMemberByNameAndType(const Common::String &name, CastType type);
134  CastMember *getCastMemberByScriptId(int scriptId);
135  int getCastIdByScriptId(uint32 scriptId) const;
136  CastMemberInfo *getCastMemberInfo(int castId);
137  const Stxt *getStxt(int castId);
138  Common::String getLinkedPath(int castId);
139  Common::String getVideoPath(int castId);
140  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id);
141  void rebuildCastNameCache();
142 
143  // release all castmember's widget, should be called when we are changing movie.
144  // 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)
145  void releaseCastMemberWidget();
146 
147  void dumpScript(const char *script, ScriptType type, uint16 id);
148 
149  Common::CodePage getFileEncoding();
150  Common::U32String decodeString(const Common::String &str);
151 
152  // Script contexts keep a back-pointer to their owning cast.
153  void registerScriptContext(ScriptContext *ctx) { _liveScriptContexts.setVal(ctx, true); }
154  void unregisterScriptContext(ScriptContext *ctx) { _liveScriptContexts.erase(ctx); }
155 
156  Common::String formatCastSummary(int castId);
157  PaletteV4 loadPalette(Common::SeekableReadStreamEndian &stream, int id);
158 
159 private:
160  void loadScriptV2(Common::SeekableReadStreamEndian &stream, uint16 id);
161  void loadFontMap(Common::SeekableReadStreamEndian &stream);
162  void loadFontMapV4(Common::SeekableReadStreamEndian &stream);
163  void loadFXmp(Common::SeekableReadStreamEndian &stream);
164  bool readFXmpLine(Common::SeekableReadStreamEndian &stream);
165  void loadVWTL(Common::SeekableReadStreamEndian &stream);
166 
167  uint32 computeChecksum();
168 
169 public:
170  Common::SharedPtr<Archive> _castArchive;
171  Common::Platform _platform;
172  uint16 _castLibID;
173  uint32 _libResourceId;
174  bool _isExternal;
175 
176  CharMap _macCharsToWin;
177  CharMap _winCharsToMac;
178  FontXPlatformMap _fontXPlatformMap;
179  FontMap _fontMap;
180 
181  bool _isProtected;
182 
188  uint16 _castIDoffset;
189 
190  Common::Rect _movieRect;
191  TilePatternEntry _tiles[kNumBuiltinTiles];
192 
193  LingoArchive *_lingoArchive;
194 
195  LingoDec::ScriptContext *_lingodec = nullptr;
196  LingoDec::ChunkResolver *_chunkResolver = nullptr;
197 
198  uint16 _castArrayStartForChecksum;
199  uint16 _castArrayEndForChecksum;
200 
201  /* Config Data to be saved */
202  /* 0 */ uint16 _len;
203  /* 2 */ uint16 _fileVersion;
204  /* 4, 6, 8, 10 */ Common::Rect _checkRect;
205  /* 12 */ uint16 _castArrayStart;
206  /* 14 */ uint16 _castArrayEnd;
207  /* 16 */ byte _readRate;
208  /* 17 */ byte _lightswitch;
209 
210  // Director 6 and below
211  /* 18 */ int16 _unk1; // Mentioned in ProjectorRays as preD7field11
212 
213  // Director 7 and above: stageColorG at byte 18, stageColorB at byte 19;
214  // _unk1 keeps the raw 16-bit value for the VWCF checksum and save.
215  /* 18 */ uint8 _D7stageColorG;
216  /* 19 */ uint8 _D7stageColorB;
217 
218  /* 20 */ uint16 _commentFont;
219  /* 22 */ uint16 _commentSize;
220  /* 24 */ uint16 _commentStyle;
221 
222  // Director 6 and below
223  /* 26 */ uint16 _stageColor;
224  // Director 7 and above: stageColorIsRGB at byte 26, stageColorR at
225  // byte 27; _stageColor keeps the raw 16-bit value for checksum and save.
226  /* 26 */ uint8 _D7stageColorIsRGB;
227  /* 27 */ uint8 _D7stageColorR;
228 
229  /* 28 */ uint16 _bitdepth;
230  /* 30 */ uint8 _field17;
231  /* 31 */ uint8 _field18;
232  /* 32 */ int32 _field19;
233  /* 36 */ int16 _version;
234  /* 38 */ int16 _movieDepth;
235  /* 40 */ int32 _field22;
236  /* 44 */ int32 _field23;
237  /* 48 */ int32 _field24;
238  /* 52 */ int8 _field25;
239  /* 53 */ uint8 _field26;
240  /* 54 */ int16 _frameRate;
241  /* 56 */ int16 _platformID;
242  /* 58 */ int16 _protection;
243  /* 60 */ int32 _field29;
244  /* 64 */ uint32 _checksum;
245  /* 68 */ uint16 _field30; // Marked as remnants in ProjectorRays
246  /* 70 */ uint16 _defPaletteNum = 0; // _defaultPalette before D5, unused later
247  /* 72 */ uint32 _chunkBaseNum = 0;
248  /* 76 */ CastMemberID _defaultPalette;
249 
250  /****** D6.0-D8.5 *******/
251  /* 80 */ int8 _netUnk1 = 0;
252  /* 81 */ int8 _netUnk2 = 0;
253  /* 82 */ int16 _netPreloadNumFrames = 0;
254 
255  /****** post D9-D10 *******/
256  /* 84 */ uint32 _windowFlags = 0;
257  /* 88 */ CastMemberID _windowIconId;
258  /* 92 */ CastMemberID _windowMaskId;
259  /* 96 */ CastMemberID _windowDragRegionMaskId;
260 
261  /* 100 */ // End of config
262 
263 private:
264  DirectorEngine *_vm;
265  Lingo *_lingo;
266  Movie *_movie;
267 
268  bool _isShared;
269  bool _loadMutex;
270  Common::Array<CastMember *> _loadQueue;
271 
272  Common::String _macName;
273  Common::String _castName;
274 
277  Common::HashMap<uint16, int> _castsScriptIds;
278 
279  Common::HashMap<ScriptContext *, bool> _liveScriptContexts;
280 
281 };
282 
283 } // End of namespace Director
284 
285 #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:126
Definition: ustr.h:57
Definition: cast.h:83
Definition: algorithm.h:29
Definition: resolver.h:15
Definition: archive.h:43
Definition: stream.h:351
Definition: context.h:26
Definition: stream.h:944
Definition: director.h:158
Definition: cast.h:73
Definition: ptr.h:159
Definition: castmember.h:48
Definition: lingo.h:366
Definition: types.h:424
Definition: castmember.h:172
Definition: lingo-object.h:213
Platform
Definition: platform.h:93