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; }
model::IModelPtr MD5ModelLoader::loadModelFromPath(const std::string& name) { // Open an ArchiveFile to load ArchiveFilePtr file = GlobalFileSystem().openFile(name); if (file != NULL) { // Construct a new MD5Model container MD5ModelPtr model(new MD5Model); // Store the VFS path in this model model->setModelPath(name); // Set the filename this model was loaded from model->setFilename(os::getFilename(file->getName())); // greebo: Get the Inputstream from the given file BinaryToTextInputStream<InputStream> inputStream(file->getInputStream()); // Construct a Tokeniser object and start reading the file try { std::istream is(&inputStream); parser::BasicDefTokeniser<std::istream> tokeniser(is); // Invoke the parser routine (might throw) model->parseFromTokens(tokeniser); } catch (parser::ParseException& e) { rError() << "[md5model] Parse failure. Exception was:" << std::endl << e.what() << std::endl; // Return an empty model on error return model::IModelPtr(); } // Load was successful, return the model return model; } else { rError() << "Failed to load model " << name << std::endl; return model::IModelPtr(); // delete the model } }
// 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; }
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; }