void ResourceManager::loadResources( const ResourceList& rResources, const SimpleResourceCallback& rCallbackSlot ) { // Convert to set to remove duplicates. ResourceSet resources = ResourceInfo::toResourceSet( rResources ); if( resources.empty() ) { // If there are no resources to be loaded, call the slot and return immediately. rCallbackSlot(); return; } ResourceManager::ResourcesLoader* resourceLoader = ResourceManager::ResourcesLoader::create( rCallbackSlot ); unsigned short loaded = 0; for( ResourceSet::const_iterator i = resources.begin(); i != resources.end(); ++i ) { // Add resources to resource loader. Ogre::ResourcePtr resource = ResourceManager::getResource( *i, true ); if( resource.isNull() ) { DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot load resource " + (*i).mFile.string() + ", file does not exist.", "ResourceManager::loadResource" ); } if( resource->isLoaded() ) loaded++; else resourceLoader->addResource( resource ); } // All resources are already loaded. if( loaded == resources.size() ) { rCallbackSlot(); delete resourceLoader; return; } for( ResourceSet::const_iterator j = resources.begin(); j != resources.end(); ++j ) { // Load all resources and callback to the resource loader. If all resources are loaded // the rCallbackSlot will be called and the resource loader will be destroyed. ResourceManager::loadResource( *j, sigc::mem_fun( resourceLoader, &ResourceManager::ResourcesLoader::loadingComplete ) ); } }
ResourceSet ResourceInfo::toResourceSet( const ResourceList& rResourceList ) { ResourceSet set; std::insert_iterator<ResourceSet> ii( set, set.begin() ); std::copy( rResourceList.begin(), rResourceList.end(), ii ); return set; }
void index_resources(ResourceSet &rs) { uint16_t index(1); ResourceSet::iterator it(rs.begin()); for (; it!=rs.end(); ++it) { it->second = index++; } }
void write_resource_data(ostream &out, ResourceIndex &index , const ResourceSet &rs) { uint32_t offset(0); ResourceSet::const_iterator it(rs.begin()); for (; it!=rs.end(); ++it) { index.push_back(ResourceInfo(offset, it->first->type)); offset += it->first->write(out); } }
void measure_jumps(ResourceSet &rs) { ResourceSet::iterator it(rs.begin()); for (; it!=rs.end(); ++it) { if (it->first->type == RESOURCE_FUNCTION) { AsmFunc *func = dynamic_cast< AsmFunc * >(it->first); measure_function_jumps(*func); } } }
void print_resources(const ResourceSet &rs) { cout << "collected " << rs.size() << " resources\n"; ResourceSet::const_iterator it(rs.begin()); for (; it!=rs.end(); ++it) { cout << it->second << "\t"; it->first->pretty(cout); cout << endl; } }
void generate_code(ResourceSet &rs) { ResourceSet::iterator it(rs.begin()); AsmFunc *func; for (; it!=rs.end(); ++it) { if (it->first->type != RESOURCE_FUNCTION) { // no code to generate for non-functions continue; } func = static_cast< AsmFunc * >(it->first); if (!func->stmts) { continue; } generate_codeblock(*func, *func->stmts); } measure_jumps(rs); }