示例#1
0
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 ) );
    }
}
示例#2
0
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;
}
示例#3
0
文件: qbc.cpp 项目: zhaobr/qbrt
void index_resources(ResourceSet &rs)
{
	uint16_t index(1);
	ResourceSet::iterator it(rs.begin());
	for (; it!=rs.end(); ++it) {
		it->second = index++;
	}
}
示例#4
0
文件: qbc.cpp 项目: zhaobr/qbrt
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);
	}
}
示例#5
0
文件: qbc.cpp 项目: zhaobr/qbrt
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);
		}
	}
}
示例#6
0
文件: qbc.cpp 项目: zhaobr/qbrt
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;
	}
}
示例#7
0
文件: qbc.cpp 项目: zhaobr/qbrt
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);
}