diff -ur --exclude=CVS ScummVM/scumm/smush/chunk.cpp ScummVM+hack/scumm/smush/chunk.cpp
old
|
new
|
|
21 | 21 | |
22 | 22 | #include "stdafx.h" |
23 | 23 | #include "scumm/smush/chunk.h" |
| 24 | #include "scumm/smush/smush_player.h" |
24 | 25 | #include "scumm/scumm.h" |
25 | 26 | |
26 | 27 | #include "common/file.h" |
… |
… |
|
85 | 86 | return true; |
86 | 87 | } |
87 | 88 | |
88 | | FileChunk::FileChunk(const Common::String &name, int offset) |
89 | | : _name(name) { |
90 | | if (!g_scumm->openFile(_data, name.c_str())) |
| 89 | FileChunk::FileChunk(SmushPlayer *player, const Common::String &name, int offset) |
| 90 | : _player(player), _name(name) { |
| 91 | _data = _player->openFile(name.c_str()); |
| 92 | if (!_data) |
91 | 93 | error("FileChunk: Unable to open file %s", name.c_str()); |
92 | 94 | |
93 | | _data.seek(offset); |
94 | | _type = _data.readUint32BE(); |
95 | | _size = _data.readUint32BE(); |
96 | | _offset = _data.pos(); |
| 95 | _data->seek(offset); |
| 96 | _type = _data->readUint32BE(); |
| 97 | _size = _data->readUint32BE(); |
| 98 | _offset = _data->pos(); |
97 | 99 | _curPos = 0; |
98 | 100 | } |
99 | 101 | |
… |
… |
|
101 | 103 | } |
102 | 104 | |
103 | 105 | Chunk *FileChunk::subBlock() { |
104 | | FileChunk *ptr = new FileChunk(_name, _offset + _curPos); |
105 | | _data.seek(_offset + _curPos + sizeof(Chunk::type) + sizeof(uint32)); |
| 106 | FileChunk *ptr = new FileChunk(_player, _name, _offset + _curPos); |
| 107 | _data->seek(_offset + _curPos + sizeof(Chunk::type) + sizeof(uint32)); |
106 | 108 | seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize()); |
107 | 109 | return ptr; |
108 | 110 | } |
… |
… |
|
111 | 113 | if (size <= 0 || (_curPos + size) > _size) |
112 | 114 | error("invalid buffer read request"); |
113 | 115 | |
114 | | // _data.seek(_offset + _curPos); |
115 | | _data.read(buffer, size); |
| 116 | // _data->seek(_offset + _curPos); |
| 117 | _data->read(buffer, size); |
116 | 118 | _curPos += size; |
117 | 119 | return true; |
118 | 120 | } |
… |
… |
|
122 | 124 | } |
123 | 125 | |
124 | 126 | byte FileChunk::getByte() { |
125 | | // _data.seek(_offset + _curPos); |
| 127 | // _data->seek(_offset + _curPos); |
126 | 128 | _curPos++; |
127 | 129 | |
128 | 130 | if (_curPos > _size) |
129 | 131 | error("invalid byte read request"); |
130 | 132 | |
131 | | return _data.readByte(); |
| 133 | return _data->readByte(); |
132 | 134 | } |
133 | 135 | |
134 | 136 | int16 FileChunk::getShort() { |
… |
… |
|
136 | 138 | } |
137 | 139 | |
138 | 140 | uint16 FileChunk::getWord() { |
139 | | // _data.seek(_offset + _curPos); |
| 141 | // _data->seek(_offset + _curPos); |
140 | 142 | _curPos += 2; |
141 | 143 | |
142 | 144 | if (_curPos > _size) |
143 | 145 | error("invalid word read request"); |
144 | 146 | |
145 | | return _data.readUint16LE(); |
| 147 | return _data->readUint16LE(); |
146 | 148 | } |
147 | 149 | |
148 | 150 | uint32 FileChunk::getDword() { |
149 | | // _data.seek(_offset + _curPos); |
| 151 | // _data->seek(_offset + _curPos); |
150 | 152 | _curPos += 4; |
151 | 153 | |
152 | 154 | if (_curPos > _size) |
153 | 155 | error("invalid dword read request"); |
154 | 156 | |
155 | | return _data.readUint32LE(); |
| 157 | return _data->readUint32LE(); |
156 | 158 | } |
157 | 159 | |
158 | 160 | MemoryChunk::MemoryChunk(byte *data) { |
diff -ur --exclude=CVS ScummVM/scumm/smush/chunk.h ScummVM+hack/scumm/smush/chunk.h
old
|
new
|
|
29 | 29 | namespace Scumm { |
30 | 30 | |
31 | 31 | class ScummFile; |
| 32 | class SmushPlayer; |
32 | 33 | |
33 | 34 | class Chunk { |
34 | 35 | public: |
… |
… |
|
69 | 70 | |
70 | 71 | class FileChunk : public BaseChunk { |
71 | 72 | private: |
| 73 | SmushPlayer *_player; |
72 | 74 | Common::String _name; |
73 | | ScummFile _data; |
| 75 | ScummFile *_data; |
74 | 76 | uint32 _offset; |
75 | 77 | |
76 | 78 | public: |
77 | | FileChunk(const Common::String &name, int offset = 0); |
| 79 | FileChunk(SmushPlayer *player, const Common::String &name, int offset = 0); |
78 | 80 | virtual ~FileChunk(); |
79 | 81 | Chunk *subBlock(); |
80 | 82 | bool read(void *buffer, uint32 size); |
diff -ur --exclude=CVS ScummVM/scumm/smush/smush_player.cpp ScummVM+hack/scumm/smush/smush_player.cpp
old
|
new
|
|
174 | 174 | } |
175 | 175 | }; |
176 | 176 | |
177 | | static StringResource *getStrings(ScummEngine *vm, const char *file, bool is_encoded) { |
178 | | debugC(DEBUG_SMUSH, "trying to read text ressources from %s", file); |
179 | | ScummFile theFile; |
| 177 | static StringResource *getStrings(SmushPlayer *player, const char *file, bool is_encoded) { |
| 178 | debugC(DEBUG_SMUSH, "trying to read text resources from %s", file); |
| 179 | ScummFile *theFile; |
180 | 180 | |
181 | | vm->openFile(theFile, file); |
182 | | if (!theFile.isOpen()) { |
| 181 | theFile = player->openFile(file); |
| 182 | if (!theFile) { |
183 | 183 | return 0; |
184 | 184 | } |
185 | | int32 length = theFile.size(); |
| 185 | int32 length = theFile->size(); |
186 | 186 | char *filebuffer = new char [length + 1]; |
187 | 187 | assert(filebuffer); |
188 | | theFile.read(filebuffer, length); |
| 188 | theFile->read(filebuffer, length); |
189 | 189 | filebuffer[length] = 0; |
190 | 190 | |
191 | 191 | if (is_encoded) { |
… |
… |
|
197 | 197 | |
198 | 198 | if (type != TYPE_ETRS) { |
199 | 199 | delete [] filebuffer; |
200 | | return getStrings(vm, file, false); |
| 200 | return getStrings(player, file, false); |
201 | 201 | } |
202 | 202 | |
203 | 203 | char *old = filebuffer; |
… |
… |
|
265 | 265 | release(); |
266 | 266 | } |
267 | 267 | |
| 268 | ScummFile *SmushPlayer::openFile(const char *filename) { |
| 269 | for (FileList::iterator f = _fileList.begin(); f != _fileList.end(); f++) { |
| 270 | if (scumm_stricmp(filename, f->name()) == 0) { |
| 271 | return f; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | ScummFile *file = new ScummFile; |
| 276 | |
| 277 | if (!_vm->openFile(*file, filename)) { |
| 278 | delete file; |
| 279 | return NULL; |
| 280 | } |
| 281 | |
| 282 | _fileList.push_back(*file); |
| 283 | return file; |
| 284 | } |
| 285 | |
268 | 286 | void SmushPlayer::init() { |
269 | 287 | _frame = 0; |
270 | 288 | _alreadyInit = false; |
… |
… |
|
340 | 358 | // some explanation. |
341 | 359 | _vm->virtscr[0].pitch = _origPitch; |
342 | 360 | _vm->gdi._numStrips = _origNumStrips; |
343 | | |
| 361 | |
| 362 | for (FileList::iterator f = _fileList.begin(); f != _fileList.end(); f++) { |
| 363 | f->close(); |
| 364 | } |
| 365 | |
| 366 | _fileList.clear(); |
344 | 367 | |
345 | 368 | _initDone = false; |
346 | 369 | } |
… |
… |
|
661 | 684 | char fname[260]; |
662 | 685 | memcpy(fname, file, i - file); |
663 | 686 | strcpy(fname + (i - file), ".trs"); |
664 | | if ((_strings = getStrings(_vm, fname, false)) != 0) { |
| 687 | if ((_strings = getStrings(this, fname, false)) != 0) { |
665 | 688 | return true; |
666 | 689 | } |
667 | 690 | |
668 | | if ((_strings = getStrings(_vm, "digtxt.trs", true)) != 0) { |
| 691 | if ((_strings = getStrings(this, "digtxt.trs", true)) != 0) { |
669 | 692 | return true; |
670 | 693 | } |
671 | 694 | return false; |
… |
… |
|
986 | 1009 | int i; |
987 | 1010 | char file_font[11]; |
988 | 1011 | |
989 | | _base = new FileChunk(file); |
| 1012 | _base = new FileChunk(this, file); |
990 | 1013 | sub = _base->subBlock(); |
991 | 1014 | checkBlock(*sub, TYPE_AHDR); |
992 | 1015 | handleAnimHeader(*sub); |
… |
… |
|
1162 | 1185 | delete _base; |
1163 | 1186 | } |
1164 | 1187 | |
1165 | | _base = new FileChunk(file); |
| 1188 | _base = new FileChunk(this, file); |
1166 | 1189 | if (pos) { |
1167 | 1190 | assert(pos != 8); |
1168 | 1191 | // In this case we need to get palette and number of frames |
… |
… |
|
1226 | 1249 | void SmushPlayer::play(const char *filename, int32 offset, int32 startFrame) { |
1227 | 1250 | |
1228 | 1251 | // Verify the specified file exists |
1229 | | ScummFile f; |
1230 | | _vm->openFile(f, filename); |
1231 | | if (!f.isOpen()) { |
| 1252 | if (!openFile(filename)) { |
1232 | 1253 | warning("SmushPlayer::play() File not found %s", filename); |
1233 | 1254 | return; |
1234 | 1255 | } |
1235 | | f.close(); |
1236 | 1256 | |
1237 | 1257 | tryCmpFile(filename); |
1238 | 1258 | |
diff -ur --exclude=CVS ScummVM/scumm/smush/smush_player.h ScummVM+hack/scumm/smush/smush_player.h
old
|
new
|
|
38 | 38 | class SmushPlayer { |
39 | 39 | friend class Insane; |
40 | 40 | private: |
| 41 | typedef Common::Array<ScummFile> FileList; |
| 42 | FileList _fileList; |
41 | 43 | ScummEngine_v6 *_vm; |
42 | 44 | int _version; |
43 | 45 | int32 _nbframes; |
… |
… |
|
94 | 96 | |
95 | 97 | void play(const char *filename, int32 offset = 0, int32 startFrame = 0); |
96 | 98 | void warpMouse(int x, int y, int buttons); |
| 99 | ScummFile *openFile(const char *filename); |
97 | 100 | |
98 | 101 | protected: |
99 | 102 | SmushFont *_sf[5]; |