void ResourceManager::loadResource(const std::string &path, std::function<void(ResourcePtr)> callback, const Options &options) { if(FileManager::fileExists(Platform::getResourcePath(path).c_str())) { ResourceLoaderPtr loader; if(options.isAsynchronous) { loader = ResourceLoaderPtr(new AsyncResourceLoader<void>(path, callback, options)); asyncLoaders.push_back(loader); }else loader = ResourceLoaderPtr(new ResourceLoader(path, callback, options)); if(options.shouldWatch) reloaders.push_back(loader); loader->notify(); } }
inline ResourceLoaderPtr getDatabaseResourceLoader () { struct DatabaseResourceLoader : public ResourceLoader { virtual osg::ref_ptr<osg::Image> getImage ( std::string const & name ) { return avCore::Database::GetInstance()->LoadImage ( name.c_str ()); } virtual osg::ref_ptr<osg::Shader> getShader ( std::string const & name, osg::Shader::Type type ) { return avCore::GetDatabase()->LoadShader ( name.c_str (), NULL, type ); } virtual osg::ref_ptr<osg::Stream> getStream ( std::string const & name ) { std::string fileName; if ( !avCore::Database::GetInstance()->FindFile ( avCore::Database::PATH_MODEL, name.c_str(), & fileName )) { // avLog ( MT_INFO, "Can't find file '%s'.\n", name.c_str() ); return NULL; } std::auto_ptr<std::istream> is = std::auto_ptr<std::istream> ( new std::ifstream ( fileName.c_str ())); if ( ! is->good ()) { // avLog ( MT_INFO, "Can't open file '%s'.\n", fileName.c_str() ); return NULL; } return new osg::StreamPtr ( is ) ; } }; return ResourceLoaderPtr ( new DatabaseResourceLoader ); }