GlyphSetPtr GlyphSet::createFromDatFile(const std::string& vfsPath, const std::string& fontname, const std::string& language, Resolution resolution) { ArchiveFilePtr file = GlobalFileSystem().openFile(vfsPath); // Check file size if (file->size() != sizeof(q3font::Q3FontInfo)) { rWarning() << "FontLoader: invalid file size of file " << vfsPath << ", expected " << sizeof(q3font::Q3FontInfo) << ", found " << file->size() << std::endl; return GlyphSetPtr(); } // Allocate a buffer with the Quake3 info structure q3font::Q3FontInfoPtr buf(new q3font::Q3FontInfo); InputStream& stream = file->getInputStream(); stream.read( reinterpret_cast<StreamBase::byte_type*>(buf.get()), sizeof(q3font::Q3FontInfo) ); // Construct a glyph set using the loaded info GlyphSetPtr glyphSet(new GlyphSet(*buf, fontname, language, resolution)); rMessage() << "FontLoader: " << vfsPath << " loaded successfully." << std::endl; return glyphSet; }
std::size_t Doom3FileSystem::loadFile(const std::string& filename, void **buffer) { std::string fixedFilename(os::standardPathWithSlash(filename)); ArchiveFilePtr file = openFile(fixedFilename); if (file != NULL) { // Allocate one byte more for the trailing zero *buffer = malloc(file->size()+1); // we need to end the buffer with a 0 ((char*) (*buffer))[file->size()] = 0; std::size_t length = file->getInputStream().read( reinterpret_cast<InputStream::byte_type*>(*buffer), file->size() ); return length; } *buffer = NULL; return 0; }
// Load the given model from the VFS path IModelPtr PicoModelLoader::loadModelFromPath(const std::string& name) { // Open an ArchiveFile to load ArchiveFilePtr file = GlobalFileSystem().openFile(name); if (file == NULL) { rError() << "Failed to load model " << name << std::endl; return IModelPtr(); } // Determine the file extension (ASE or LWO) to pass down to the PicoModel std::string fName = file->getName(); boost::algorithm::to_lower(fName); std::string fExt = fName.substr(fName.size() - 3, 3); picoModel_t* model = PicoModuleLoadModelStream( _module, &file->getInputStream(), picoInputStreamReam, file->size(), 0 ); // greebo: Check if the model load was successful if (model == NULL || model->numSurfaces == 0) { // Model is either NULL or has no surfaces, this must've failed return IModelPtr(); } RenderablePicoModelPtr modelObj( new RenderablePicoModel(model, fExt) ); // Set the filename modelObj->setFilename(os::getFilename(file->getName())); modelObj->setModelPath(name); PicoFreeModel(model); return modelObj; }