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