TestArchive() { { Archive* archive = OpenArchive(""); archive->release(); } { Archive* archive = OpenArchive("NONEXISTANTFILE"); archive->release(); } { Archive* archive = OpenArchive("c:/quake/id1/quake101.wad"); ArchiveFile* file = archive->openFile("textures/sky1.mip"); if(file != 0) { unsigned char* buffer = new unsigned char[file->size()]; file->getInputStream().read((InputStream::byte_type*)buffer, file->size()); delete[] buffer; file->release(); } TestVisitor visitor; archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), ""); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), ""); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), "textures/"); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), "textures/"); archive->release(); } }
void RoutingLumpLoader::loadRoutingLump (ArchiveFile& file) { /* load the file */ InputStream &stream = file.getInputStream(); const std::size_t size = file.size(); byte *buf = (byte*) malloc(size + 1); dBspHeader_t *header = (dBspHeader_t *) buf; stream.read(buf, size); CMod_LoadRouting(_routingLump, file.getName(), &header->lumps[LUMP_ROUTING], (byte *) buf, 0, 0, 0); free(buf); }
void test1() { Archive* archive = OpenArchive("d:/quake/id1/"); ArchiveFile* file = archive->openFile("quake101.wad"); if(file != 0) { char buffer[1024]; file->getInputStream().read(buffer, 1024); file->release(); } TestVisitor visitor; archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), ""); archive->release(); }
// NOTE: when loading a file, you have to allocate one extra byte and set it to \0 std::size_t LoadFile (const char *filename, void **bufferptr, int index) { char fixed[PATH_MAX+1]; strncpy (fixed, filename, PATH_MAX); fixed[PATH_MAX] = '\0'; FixDOSName (fixed); ArchiveFile* file = OpenFile(fixed); if(file != 0) { *bufferptr = malloc (file->size()+1); // we need to end the buffer with a 0 ((char*) (*bufferptr))[file->size()] = 0; std::size_t length = file->getInputStream().read((InputStream::byte_type*)*bufferptr, file->size()); file->release(); return length; } *bufferptr = 0; return 0; }
ImagePtr LoadDDS(ArchiveFile& file) { return LoadDDSFromStream(file.getInputStream()); }
void SoundPlayer::play(ArchiveFile& file) { // If we're not initialised yet, do it now if (!_initialised) { initialise(); } // Stop any previous playback operations, that might be still active clearBuffer(); // Retrieve the extension std::string ext = os::getExtension(file.getName()); if (boost::algorithm::to_lower_copy(ext) == "ogg") { // Convert the file into a buffer, self-destructs at end of scope ScopedArchiveBuffer buffer(file); // This is an OGG Vorbis file, decode it vorbis_info* vorbisInfo; OggVorbis_File oggFile; // Initialise the wrapper class OggFileStream stream(buffer); // Setup the callbacks and point them to the helper class ov_callbacks callbacks; callbacks.read_func = OggFileStream::oggReadFunc; callbacks.seek_func = OggFileStream::oggSeekFunc; callbacks.close_func = OggFileStream::oggCloseFunc; callbacks.tell_func = OggFileStream::oggTellFunc; // Open the OGG data stream using the custom callbacks int res = ov_open_callbacks(static_cast<void*>(&stream), &oggFile, NULL, 0, callbacks); if (res == 0) { // Open successful // Get some information about the OGG file vorbisInfo = ov_info(&oggFile, -1); // Check the number of channels ALenum format = (vorbisInfo->channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; // Get the sample Rate ALsizei freq = (vorbisInfo->rate); //std::cout << "Sample rate is " << freq << "\n"; long bytes; char smallBuffer[4096]; DecodeBufferPtr largeBuffer(new DecodeBuffer()); do { int bitStream; // Read a chunk of decoded data from the vorbis file bytes = ov_read(&oggFile, smallBuffer, sizeof(smallBuffer), 0, 2, 1, &bitStream); if (bytes == OV_HOLE) { rError() << "SoundPlayer: Error decoding OGG: OV_HOLE.\n"; } else if (bytes == OV_EBADLINK) { rError() << "SoundPlayer: Error decoding OGG: OV_EBADLINK.\n"; } else { // Stuff this into the variable-sized buffer largeBuffer->insert(largeBuffer->end(), smallBuffer, smallBuffer + bytes); } } while (bytes > 0); // Allocate a new buffer alGenBuffers(1, &_buffer); DecodeBuffer& bufferRef = *largeBuffer; // Upload sound data to buffer alBufferData(_buffer, format, &bufferRef[0], static_cast<ALsizei>(bufferRef.size()), freq); // Clean up the OGG routines ov_clear(&oggFile); } else { rError() << "SoundPlayer: Error opening OGG file.\n"; } } else { // Must be a wave file try { // Create an AL sound buffer directly from the buffer in memory _buffer = WavFileLoader::LoadFromStream(file.getInputStream()); } catch (std::runtime_error& e) { rError() << "SoundPlayer: Error opening WAV file: " << e.what() << std::endl; _buffer = 0; } } if (_buffer != 0) { alGenSources(1, &_source); // Assign the buffer to the source and play it alSourcei(_source, AL_BUFFER, _buffer); // greebo: Wait 10 msec. to fix a problem with buffers not being played // maybe the AL needs time to push the data? usleep(10000); alSourcePlay(_source); // Enable the periodic buffer check, this destructs the buffer // as soon as the playback has finished _timer.enable(); } }