Ticket #8904: bs2-archive.patch
File bs2-archive.patch, 25.2 KB (added by , 16 years ago) |
---|
-
animation.cpp
27 27 28 28 29 29 #include "common/config-manager.h" 30 #include "common/file.h"31 30 #include "common/events.h" 32 31 #include "common/system.h" 33 32 … … 865 864 // Factory function for creating the appropriate cutscene player 866 865 /////////////////////////////////////////////////////////////////////////////// 867 866 868 MoviePlayer * makeMoviePlayer(Sword2Engine *vm,const char *name) {867 MoviePlayer *Sword2Engine::makeMoviePlayer(const char *name) { 869 868 static char filename[20]; 870 869 871 870 #ifdef USE_ZLIB 872 871 snprintf(filename, sizeof(filename), "%s.dxa", name); 873 872 874 if ( Common::File::exists(filename)) {875 return new MoviePlayerDXA( vm, name);873 if (_vm->_searchSet.hasFile(filename)) { 874 return new MoviePlayerDXA(this, name); 876 875 } 877 876 #endif 878 877 879 878 #ifdef USE_MPEG2 880 879 snprintf(filename, sizeof(filename), "%s.mp2", name); 881 880 882 if ( Common::File::exists(filename)) {883 return new MoviePlayerMPEG( vm, name);881 if (_vm->_searchSet.hasFile(filename)) { 882 return new MoviePlayerMPEG(this, name); 884 883 } 885 884 #endif 886 885 887 return new MoviePlayerDummy( vm, name);886 return new MoviePlayerDummy(this, name); 888 887 } 889 888 890 889 } // End of namespace Sword2 -
anims.cpp
32 32 // --------------------------------------------------------------------------- 33 33 34 34 35 #include "common/file.h"36 35 37 36 #include "sword2/sword2.h" 38 37 #include "sword2/defs.h" -
function.cpp
27 27 28 28 29 29 #include "common/system.h" 30 #include "common/file.h"31 30 32 31 #include "sword2/sword2.h" 33 32 #include "sword2/defs.h" … … 2139 2138 // pause sfx during sequence 2140 2139 _vm->_sound->pauseFx(); 2141 2140 2142 MoviePlayer *player = makeMoviePlayer(_vm,filename);2141 MoviePlayer *player = _vm->makeMoviePlayer(filename); 2143 2142 2144 2143 if (player->load()) { 2145 2144 player->play(_sequenceTextList, _sequenceTextLines, _smackerLeadIn, _smackerLeadOut); -
music.cpp
32 32 // All things considered, I think this is more bother than it's worth. 33 33 34 34 35 #include "common/file.h"36 35 #include "common/system.h" 37 36 38 37 #include "sound/mp3.h" … … 49 48 50 49 namespace Sword2 { 51 50 52 static Audio::AudioStream *makeCLUStream(Common:: File *fp, int size);51 static Audio::AudioStream *makeCLUStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size); 53 52 54 static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) { 55 bool alreadyOpen; 53 Audio::AudioStream *resetAudioStream(SoundFileHandle *fh, const char *base, uint32 id, uint32 *numSamples, bool alreadyOpen) { 56 54 57 if (!fh->file.isOpen()) {58 alreadyOpen = false;59 60 struct {61 const char *ext;62 int mode;63 } file_types[] = {64 #ifdef USE_FLAC65 { "clf", kFlacMode },66 #endif67 #ifdef USE_VORBIS68 { "clg", kVorbisMode },69 #endif70 #ifdef USE_MAD71 { "cl3", kMP3Mode },72 #endif73 { "clu", kCLUMode }74 };75 76 int soundMode = 0;77 char filename[20];78 79 for (int i = 0; i < ARRAYSIZE(file_types); i++) {80 sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext);81 if (Common::File::exists(filename)) {82 soundMode = file_types[i].mode;83 break;84 }85 86 sprintf(filename, "%s.%s", base, file_types[i].ext);87 if (Common::File::exists(filename)) {88 soundMode = file_types[i].mode;89 break;90 }91 }92 93 if (soundMode == 0)94 return NULL;95 96 fh->file.open(filename);97 fh->fileType = soundMode;98 if (!fh->file.isOpen()) {99 warning("BS2 getAudioStream: Failed opening file '%s'", filename);100 return NULL;101 }102 if (fh->fileSize != fh->file.size()) {103 if (fh->idxTab) {104 free(fh->idxTab);105 fh->idxTab = NULL;106 }107 }108 } else109 alreadyOpen = true;110 111 55 uint32 entrySize = (fh->fileType == kCLUMode) ? 2 : 3; 112 56 113 57 if (!fh->idxTab) { 114 fh-> file.seek(0);115 fh->idxLen = fh-> file.readUint32LE();116 fh-> file.seek(entrySize * 4);58 fh->stream->seek(0); 59 fh->idxLen = fh->stream->readUint32LE(); 60 fh->stream->seek(entrySize * 4); 117 61 118 62 fh->idxTab = (uint32*)malloc(fh->idxLen * 3 * sizeof(uint32)); 119 63 for (uint32 cnt = 0; cnt < fh->idxLen; cnt++) { 120 fh->idxTab[cnt * 3 + 0] = fh-> file.readUint32LE();121 fh->idxTab[cnt * 3 + 1] = fh-> file.readUint32LE();64 fh->idxTab[cnt * 3 + 0] = fh->stream->readUint32LE(); 65 fh->idxTab[cnt * 3 + 1] = fh->stream->readUint32LE(); 122 66 if (fh->fileType == kCLUMode) { 123 67 fh->idxTab[cnt * 3 + 2] = fh->idxTab[cnt * 3 + 1]; 124 68 fh->idxTab[cnt * 3 + 1]--; 125 69 } else 126 fh->idxTab[cnt * 3 + 2] = fh-> file.readUint32LE();70 fh->idxTab[cnt * 3 + 2] = fh->stream->readUint32LE(); 127 71 } 128 72 } 129 73 … … 141 85 // open though, because something is playing from it. 142 86 warning("getAudioStream: Could not find %s ID %d! Possibly the wrong file", base, id); 143 87 if (!alreadyOpen) 144 fh-> file.close();88 fh->stream.reset(); 145 89 return NULL; 146 90 } 147 91 148 fh-> file.seek(pos, SEEK_SET);92 fh->stream->seek(pos, SEEK_SET); 149 93 150 94 Common::MemoryReadStream *tmp = 0; 151 95 152 96 switch (fh->fileType) { 153 97 case kCLUMode: 154 return makeCLUStream( &fh->file, enc_len);98 return makeCLUStream(fh->stream, enc_len); 155 99 #ifdef USE_MAD 156 100 case kMP3Mode: 157 tmp = fh-> file.readStream(enc_len);101 tmp = fh->stream->readStream(enc_len); 158 102 assert(tmp); 159 103 return Audio::makeMP3Stream(tmp, true); 160 104 #endif 161 105 #ifdef USE_VORBIS 162 106 case kVorbisMode: 163 tmp = fh-> file.readStream(enc_len);107 tmp = fh->stream->readStream(enc_len); 164 108 assert(tmp); 165 109 return Audio::makeVorbisStream(tmp, true); 166 110 #endif 167 111 #ifdef USE_FLAC 168 112 case kFlacMode: 169 tmp = fh-> file.readStream(enc_len);113 tmp = fh->stream->readStream(enc_len); 170 114 assert(tmp); 171 115 return Audio::makeFlacStream(tmp, true); 172 116 #endif 173 117 default: 174 118 return NULL; 175 119 } 120 176 121 } 177 122 123 Audio::AudioStream *Sound::getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) { 124 bool alreadyOpen; 125 126 if (!fh->stream) { 127 alreadyOpen = false; 128 129 struct { 130 const char *ext; 131 int mode; 132 } file_types[] = { 133 #ifdef USE_FLAC 134 { "clf", kFlacMode }, 135 #endif 136 #ifdef USE_VORBIS 137 { "clg", kVorbisMode }, 138 #endif 139 #ifdef USE_MAD 140 { "cl3", kMP3Mode }, 141 #endif 142 { "clu", kCLUMode } 143 }; 144 145 int soundMode = 0; 146 char filename[20]; 147 148 for (int i = 0; i < ARRAYSIZE(file_types); i++) { 149 sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext); 150 if (_vm->_searchSet.hasFile(filename)) { 151 soundMode = file_types[i].mode; 152 break; 153 } 154 155 sprintf(filename, "%s.%s", base, file_types[i].ext); 156 if (_vm->_searchSet.hasFile(filename)) { 157 soundMode = file_types[i].mode; 158 break; 159 } 160 } 161 162 if (soundMode == 0) 163 return NULL; 164 165 fh->stream = _vm->_searchSet.openFile(filename); 166 fh->fileType = soundMode; 167 if (!fh->stream) { 168 warning("BS2 getAudioStream: Failed opening file '%s'", filename); 169 return NULL; 170 } 171 if (fh->fileSize != fh->stream->size()) { 172 if (fh->idxTab) { 173 free(fh->idxTab); 174 fh->idxTab = NULL; 175 } 176 } 177 } else 178 alreadyOpen = true; 179 180 return resetAudioStream(fh, base, id, numSamples, alreadyOpen); 181 } 182 183 178 184 // ---------------------------------------------------------------------------- 179 185 // Custom AudioStream class to handle Broken Sword 2's audio compression. 180 186 // ---------------------------------------------------------------------------- … … 183 189 #define GetCompressedSign(n) ((n) & 0x08) 184 190 #define GetCompressedAmplitude(n) ((n) & 0x07) 185 191 186 CLUInputStream::CLUInputStream(Common:: File *file, int size)187 : _ file(file), _firstTime(true), _bufferEnd(_outbuf + BUFFER_SIZE) {192 CLUInputStream::CLUInputStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size) 193 : _stream(stream), _firstTime(true), _bufferEnd(_outbuf + BUFFER_SIZE) { 188 194 189 195 // Determine the end position. 190 _file_pos = _ file->pos();196 _file_pos = _stream->pos(); 191 197 _end_pos = _file_pos + size; 192 198 193 199 // Read in initial data … … 216 222 byte *in = _inbuf; 217 223 int16 *out = _outbuf; 218 224 219 _ file->seek(_file_pos, SEEK_SET);225 _stream->seek(_file_pos, SEEK_SET); 220 226 221 uint len_left = _ file->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _file->pos()));227 uint len_left = _stream->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _stream->pos())); 222 228 223 _file_pos = _ file->pos();229 _file_pos = _stream->pos(); 224 230 225 231 while (len_left > 0) { 226 232 uint16 sample; … … 250 256 _bufferEnd = out; 251 257 } 252 258 253 Audio::AudioStream *makeCLUStream(Common:: File *file, int size) {254 return new CLUInputStream( file, size);259 Audio::AudioStream *makeCLUStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size) { 260 return new CLUInputStream(stream, size); 255 261 } 256 262 257 263 // ---------------------------------------------------------------------------- … … 262 268 // The length of a fade-in/out, in milliseconds. 263 269 #define FADE_LENGTH 3000 264 270 265 MusicInputStream::MusicInputStream(int cd, SoundFileHandle *fh, uint32 musicId, bool looping) { 266 _cd = cd; 271 MusicInputStream::MusicInputStream(Audio::AudioStream *decoder, SoundFileHandle *fh, uint32 musicId, uint32 numSamples, bool looping) { 267 272 _fh = fh; 268 273 _musicId = musicId; 274 _numSamples = numSamples; 269 275 _looping = looping; 270 276 271 277 _bufferEnd = _buffer + BUFFER_SIZE; 272 278 _remove = false; 273 279 _fading = 0; 274 280 275 _decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);281 _decoder = decoder; 276 282 if (_decoder) { 277 283 _samplesLeft = _numSamples; 278 284 _fadeSamples = (getRate() * FADE_LENGTH) / 1000; … … 283 289 } 284 290 } 285 291 292 286 293 MusicInputStream::~MusicInputStream() { 287 294 delete _decoder; 288 295 _decoder = NULL; … … 390 397 if (!_samplesLeft) { 391 398 if (_looping) { 392 399 delete _decoder; 393 _decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);400 _decoder = resetAudioStream(_fh, "music", _musicId, &_numSamples, true); 394 401 _samplesLeft = _numSamples; 395 402 } else 396 403 _remove = true; … … 485 492 } 486 493 487 494 for (i = 0; i < MAXMUS; i++) { 488 if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i]. file.isOpen())489 _musicFile[i]. file.close();495 if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].stream) 496 _musicFile[i].stream.reset(); 490 497 } 491 498 492 499 return numSamples; … … 617 624 fh->inUse = true; 618 625 _mutex.unlock(); 619 626 620 MusicInputStream *tmp = new MusicInputStream(cd, fh, musicId, loop); 627 uint32 numSamples; 628 Audio::AudioStream *decoder = getAudioStream(fh, "music", cd, musicId, &numSamples); 629 MusicInputStream *tmp = new MusicInputStream(decoder, fh, musicId, numSamples, loop); 621 630 622 631 if (tmp->isReady()) { 623 632 _mutex.lock(); -
resman.cpp
26 26 */ 27 27 28 28 29 #include "common/file.h"30 29 #include "common/system.h" 31 30 32 31 #include "sword2/sword2.h" … … 103 102 // within the clusters at this point it makes no difference. We only 104 103 // wish to know what resource files there are and what is in each 105 104 106 Common:: File file;107 108 if (! file.open("resource.inf")) {105 Common::SharedPtr<Common::SeekableReadStream> stream; 106 stream = _vm->_searchSet.openFile("resource.inf"); 107 if (!stream) { 109 108 _vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.inf"); 110 109 return false; 111 110 } … … 113 112 // The resource.inf file is a simple text file containing the names of 114 113 // all the resource files. 115 114 116 while ( file.readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) {115 while (stream->readLine(_resFiles[_totalClusters].fileName, sizeof(_resFiles[_totalClusters].fileName))) { 117 116 _resFiles[_totalClusters].numEntries = -1; 118 117 _resFiles[_totalClusters].entryTab = NULL; 119 118 if (++_totalClusters >= MAX_res_files) { … … 122 121 } 123 122 } 124 123 125 file.close();126 127 124 // Now load in the binary id to res conversion table 128 if (!file.open("resource.tab")) { 125 stream = _vm->_searchSet.openFile("resource.tab"); 126 if (!stream) { 129 127 _vm->GUIErrorMessage("Broken Sword 2: Cannot open resource.tab"); 130 128 return false; 131 129 } 132 130 133 131 // Find how many resources 134 uint32 size = file.size();132 uint32 size = stream->size(); 135 133 136 134 _totalResFiles = size / 4; 137 135 … … 139 137 _resConvTable = (uint16 *)malloc(size); 140 138 141 139 for (i = 0; i < size / 2; i++) 142 _resConvTable[i] = file.readUint16LE();140 _resConvTable[i] = stream->readUint16LE(); 143 141 144 if (file.ioFailed()) { 145 file.close(); 142 if (stream->ioFailed()) { 146 143 _vm->GUIErrorMessage("Broken Sword 2: Cannot read resource.tab"); 147 144 return false; 148 145 } 149 146 150 file.close();151 147 152 if (!file.open("cd.inf")) { 148 stream = _vm->_searchSet.openFile("cd.inf"); 149 if (!stream) { 153 150 _vm->GUIErrorMessage("Broken Sword 2: Cannot open cd.inf"); 154 151 return false; 155 152 } … … 157 154 CdInf *cdInf = new CdInf[_totalClusters]; 158 155 159 156 for (i = 0; i < _totalClusters; i++) { 160 file.read(cdInf[i].clusterName, sizeof(cdInf[i].clusterName));157 stream->read(cdInf[i].clusterName, sizeof(cdInf[i].clusterName)); 161 158 162 cdInf[i].cd = file.readByte();159 cdInf[i].cd = stream->readByte(); 163 160 164 if ( file.ioFailed()) {161 if (stream->ioFailed()) { 165 162 delete cdInf; 166 file.close();167 163 _vm->GUIErrorMessage("Broken Sword 2: Cannot read cd.inf"); 168 164 return false; 169 165 } … … 189 185 // during game-play (oh, that wascally wabbit!) in which case 190 186 // the resource manager will print a fatal error. 191 187 192 if (cdInf[i].cd == 0 && ! Common::File::exists((char*)cdInf[i].clusterName)) {188 if (cdInf[i].cd == 0 && !_vm->_searchSet.hasFile((char*)cdInf[i].clusterName)) { 193 189 _vm->GUIErrorMessage("Broken Sword 2: Cannot find " + Common::String((char *)cdInf[i].clusterName)); 194 190 delete[] cdInf; 195 191 return false; 196 192 } 197 193 } 198 194 199 file.close();200 201 195 for (i = 0; i < _totalClusters; i++) { 202 196 for (j = 0; j < _totalClusters; j++) { 203 197 if (scumm_stricmp((char *)cdInf[j].clusterName, _resFiles[i].fileName) == 0) … … 260 254 // care which CD it's on. But if we can't find it, keep asking 261 255 // for the CD until we do. 262 256 263 Common:: File *file= openCluFile(cluFileNum);257 Common::SharedPtr<Common::SeekableReadStream> stream = openCluFile(cluFileNum); 264 258 265 259 if (_resFiles[cluFileNum].entryTab == NULL) { 266 260 // we didn't read from this file before, get its index table 267 readCluIndex(cluFileNum, file);261 readCluIndex(cluFileNum, stream); 268 262 } 269 263 270 264 uint32 pos = _resFiles[cluFileNum].entryTab[actual_res * 2 + 0]; 271 265 uint32 len = _resFiles[cluFileNum].entryTab[actual_res * 2 + 1]; 272 266 273 file->seek(pos, SEEK_SET);267 stream->seek(pos, SEEK_SET); 274 268 275 269 debug(6, "res len %d", len); 276 270 … … 279 273 _resList[res].size = len; 280 274 _resList[res].refCount = 0; 281 275 282 file->read(_resList[res].ptr, len);276 stream->read(_resList[res].ptr, len); 283 277 284 278 debug(3, "Loaded resource '%s' (%d) from '%s' on CD %d (%d)", fetchName(_resList[res].ptr), res, _resFiles[cluFileNum].fileName, getCD(), _resFiles[cluFileNum].cd); 285 279 … … 334 328 335 329 sprintf(buf, "dumps/%s-%d.dmp", tag, res); 336 330 337 if (! Common::File::exists(buf)) {331 if (!_vm->_searchSet.hasFile(buf)) { 338 332 Common::DumpFile out; 339 333 if (out.open(buf)) 340 334 out.write(_resList[res].ptr, len); 341 335 } 342 336 } 343 337 344 // close the cluster345 file->close();346 delete file;347 348 338 _usedMem += len; 349 339 checkMemUsage(); 350 340 } else if (_resList[res].refCount == 0) … … 405 395 _cacheEnd = res; 406 396 } 407 397 408 Common::File *ResourceManager::openCluFile(uint16 fileNum) { 409 Common::File *file = new Common::File; 410 while (!file->open(_resFiles[fileNum].fileName)) { 398 Common::SharedPtr<Common::SeekableReadStream> ResourceManager::openCluFile(uint16 fileNum) { 399 while (!_vm->_searchSet.hasFile(_resFiles[fileNum].fileName)) { 411 400 // HACK: We have to check for this, or it'll be impossible to 412 401 // quit while the game is asking for the user to insert a CD. 413 402 // But recovering from this situation gracefully is just too … … 424 413 425 414 askForCD(_resFiles[fileNum].cd); 426 415 } 427 return file; 416 417 Common::SharedPtr<Common::SeekableReadStream> stream = _vm->_searchSet.openFile(_resFiles[fileNum].fileName); 418 return stream; 428 419 } 429 420 430 void ResourceManager::readCluIndex(uint16 fileNum, Common:: File *file) {421 void ResourceManager::readCluIndex(uint16 fileNum, Common::SharedPtr<Common::SeekableReadStream> file) { 431 422 // we didn't read from this file before, get its index table 432 423 assert(_resFiles[fileNum].entryTab == NULL); 433 424 assert(file); … … 492 483 // open the cluster file 493 484 494 485 if (_resFiles[parent_res_file].entryTab == NULL) { 495 Common::File *file = openCluFile(parent_res_file); 496 readCluIndex(parent_res_file, file); 497 delete file; 486 Common::SharedPtr<Common::SeekableReadStream> stream = openCluFile(parent_res_file); 487 readCluIndex(parent_res_file, stream); 498 488 } 499 489 return _resFiles[parent_res_file].entryTab[actual_res * 2 + 1]; 500 490 } -
resman.h
28 28 #ifndef SWORD2_RESMAN_H 29 29 #define SWORD2_RESMAN_H 30 30 31 namespace Common { 32 class File; 33 } 31 #include "common/ptr.h" 34 32 33 35 34 #ifdef PALMOS_MODE 36 35 #define MAX_MEM_CACHE (4 * 1024 * 1024) // 4 seems to be enough, 8 = out of memory 37 36 #else … … 59 58 60 59 class ResourceManager { 61 60 private: 62 Common:: File *openCluFile(uint16 fileNum);63 void readCluIndex(uint16 fileNum, Common:: File *file);61 Common::SharedPtr<Common::SeekableReadStream> openCluFile(uint16 fileNum); 62 void readCluIndex(uint16 fileNum, Common::SharedPtr<Common::SeekableReadStream> stream); 64 63 void removeFromCacheList(Resource *res); 65 64 void addToCacheList(Resource *res); 66 65 void checkMemUsage(); -
screen.cpp
867 867 // now, let's just the standard speech font instead. 868 868 869 869 SpriteInfo spriteInfo; 870 Common:: File f;870 Common::SharedPtr<Common::SeekableReadStream> stream; 871 871 int i; 872 872 873 873 // Read the "Smacker" logo … … 877 877 byte *logoData = NULL; 878 878 byte palette[256 * 4]; 879 879 880 if (f.open("credits.bmp")) { 881 logoWidth = f.readUint16LE(); 882 logoHeight = f.readUint16LE(); 880 stream = _vm->_searchSet.openFile("credits.bmp"); 881 if (stream) { 882 logoWidth = stream->readUint16LE(); 883 logoHeight = stream->readUint16LE(); 883 884 884 885 for (i = 0; i < 256; i++) { 885 palette[i * 4 + 0] = f.readByte() << 2;886 palette[i * 4 + 1] = f.readByte() << 2;887 palette[i * 4 + 2] = f.readByte() << 2;886 palette[i * 4 + 0] = stream->readByte() << 2; 887 palette[i * 4 + 1] = stream->readByte() << 2; 888 palette[i * 4 + 2] = stream->readByte() << 2; 888 889 palette[i * 4 + 3] = 0; 889 890 } 890 891 891 892 logoData = (byte *)malloc(logoWidth * logoHeight); 892 893 893 f.read(logoData, logoWidth * logoHeight); 894 f.close(); 894 stream->read(logoData, logoWidth * logoHeight); 895 895 } else { 896 896 warning("Can't find credits.bmp"); 897 897 memset(palette, 0, sizeof(palette)); … … 912 912 int paragraphStart = 0; 913 913 bool hasCenterMark = false; 914 914 915 if (!f.open("credits.clu")) { 915 stream = _vm->_searchSet.openFile("credits.clu"); 916 if (!stream) { 916 917 warning("Can't find credits.clu"); 917 918 return; 918 919 } 919 920 920 921 while (1) { 921 922 char buffer[80]; 922 char *line = f.readLine(buffer, sizeof(buffer));923 char *line = stream->readLine(buffer, sizeof(buffer)); 923 924 924 925 if (!line || *line == 0) { 925 926 if (!hasCenterMark) { … … 999 1000 lineCount++; 1000 1001 } 1001 1002 1002 f.close();1003 1004 1003 // We could easily add some ScummVM stuff to the credits, if we wanted 1005 1004 // to. On the other hand, anyone with the attention span to actually 1006 1005 // read all the credits probably already knows. :-) -
sound.cpp
36 36 // --------------------------------------------------------------------------- 37 37 38 38 39 #include "common/file.h"40 39 #include "common/system.h" 41 40 42 41 #include "sword2/sword2.h" … … 102 101 free(_mixBuffer); 103 102 104 103 for (int i = 0; i < MAXMUS; i++) { 105 if (_musicFile[i]. file.isOpen())106 _musicFile[i]. file.close();107 if (_speechFile[i]. file.isOpen())108 _speechFile[i]. file.close();104 if (_musicFile[i].stream) 105 _musicFile[i].stream.reset(); 106 if (_speechFile[i].stream) 107 _speechFile[i].stream.reset(); 109 108 110 109 free(_musicFile[i].idxTab); 111 110 free(_speechFile[i].idxTab); -
sound.h
38 38 #ifndef SWORD2_SOUND_H 39 39 #define SWORD2_SOUND_H 40 40 41 #include "common/file.h"42 41 #include "sound/audiostream.h" 43 42 #include "sound/mixer.h" 44 43 … … 92 91 93 92 class CLUInputStream : public Audio::AudioStream { 94 93 private: 95 Common:: File *_file;94 Common::SharedPtr<Common::SeekableReadStream> _stream; 96 95 bool _firstTime; 97 96 uint32 _file_pos; 98 97 uint32 _end_pos; … … 106 105 void refill(); 107 106 108 107 inline bool eosIntern() const { 109 return !_ file->isOpen()|| _pos >= _bufferEnd;108 return !_stream || _pos >= _bufferEnd; 110 109 } 111 110 112 111 public: 113 CLUInputStream(Common:: File *file, int size);112 CLUInputStream(Common::SharedPtr<Common::SeekableReadStream> stream, int size); 114 113 ~CLUInputStream(); 115 114 116 115 int readBuffer(int16 *buffer, const int numSamples); … … 121 120 }; 122 121 123 122 struct SoundFileHandle { 124 Common:: File file;123 Common::SharedPtr<Common::SeekableReadStream> stream; 125 124 uint32 *idxTab; 126 125 uint32 idxLen; 127 126 uint32 fileSize; … … 155 154 } 156 155 157 156 public: 158 MusicInputStream( int cd, SoundFileHandle *fh, uint32 musicId, bool looping);157 MusicInputStream(Audio::AudioStream *decoder, SoundFileHandle *fh, uint32 musicId, uint32 numSamples, bool looping); 159 158 ~MusicInputStream(); 160 159 161 160 int readBuffer(int16 *buffer, const int numSamples); … … 281 280 int32 streamCompMusic(uint32 musicId, bool loop); 282 281 void stopMusic(bool immediately); 283 282 int32 musicTimeRemaining(); 283 284 Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples); 284 285 }; 285 286 286 287 } // End of namespace Sword2 -
speech.cpp
26 26 */ 27 27 28 28 29 #include "common/file.h"30 29 31 30 #include "sword2/sword2.h" 32 31 #include "sword2/defs.h" -
startup.cpp
26 26 */ 27 27 28 28 29 #include "common/file.h"30 31 29 #include "sword2/sword2.h" 32 30 #include "sword2/defs.h" 33 31 #include "sword2/header.h" … … 48 46 // We query each in turn and setup an array of start structures. 49 47 // If the file doesn't exist then we say so and return a 0. 50 48 51 Common:: File fp;49 Common::SharedPtr<Common::SeekableReadStream> stream; 52 50 53 51 // ok, load in the master screen manager file 54 52 55 53 _totalStartups = 0; 56 54 _totalScreenManagers = 0; 57 55 58 if (!fp.open("startup.inf")) { 56 stream = _searchSet.openFile("startup.inf"); 57 if (!stream) { 59 58 warning("Cannot open startup.inf - the debugger won't have a start menu"); 60 59 return false; 61 60 } … … 68 67 69 68 int lineno = 0; 70 69 71 while ( fp.readLine(buf, sizeof(buf))) {70 while (stream->readLine(buf, sizeof(buf))) { 72 71 char *errptr; 73 72 int id; 74 73 … … 98 97 } 99 98 } 100 99 101 fp.close();102 103 100 // Using this method the Gode generated resource.inf must have #0d0a 104 101 // on the last entry 105 102 -
sword2.cpp
30 30 #include "base/plugins.h" 31 31 32 32 #include "common/config-manager.h" 33 #include "common/file.h" 34 #include "common/fs.h" 33 35 34 #include "common/events.h" 36 35 #include "common/system.h" 37 36 … … 189 188 namespace Sword2 { 190 189 191 190 Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) { 191 192 Common::SharedPtr<Common::FSDirectory> _baseDir(new Common::FSDirectory(_gameDataPath)); 193 192 194 // Add default file directories 193 Common::File::addDefaultDirectory(_gameDataPath + "CLUSTERS/"); 194 Common::File::addDefaultDirectory(_gameDataPath + "SWORD2/"); 195 Common::File::addDefaultDirectory(_gameDataPath + "VIDEO/"); 196 Common::File::addDefaultDirectory(_gameDataPath + "clusters/"); 197 Common::File::addDefaultDirectory(_gameDataPath + "sword2/"); 198 Common::File::addDefaultDirectory(_gameDataPath + "video/"); 195 _searchSet.add("base", _baseDir); 196 _searchSet.add("vid", _baseDir->getSubDirectory("VIDEO")); 197 _searchSet.add("clu", _baseDir->getSubDirectory("CLUSTERS")); 198 _searchSet.add("s2", _baseDir->getSubDirectory("SWORD2")); 199 199 200 200 if (0 == scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo")) 201 201 _features = GF_DEMO; -
sword2.h
40 40 #include "engines/engine.h" 41 41 42 42 #include "common/events.h" 43 #include "common/archive.h" 43 44 #include "common/util.h" 44 45 45 46 #define MAX_starts 100 … … 62 63 class FontRenderer; 63 64 class Gui; 64 65 class Debugger; 66 class MoviePlayer; 65 67 66 68 enum { 67 69 RD_LEFTBUTTONDOWN = 0x01, … … 152 154 Mouse *_mouse; 153 155 Logic *_logic; 154 156 FontRenderer *_fontRenderer; 157 Common::SearchSet _searchSet; 155 158 156 159 Debugger *_debugger; 157 160 … … 228 231 229 232 void runStart(int start); 230 233 234 MoviePlayer *makeMoviePlayer(const char *name); 235 231 236 // Convenience alias for OSystem::getMillis(). 232 237 // This is a bit hackish, of course :-). 233 238 uint32 getMillis();