Example #1
0
Ogre::ResourcePtr ResourceManager::loadResource( const ResourceInfo& rResource, 
    const ResourceCallback& rCallbackSlot )
{
    Ogre::ResourcePtr resource = ResourceManager::getResource( rResource, true );

    if( !resource.isNull() && resource->isLoaded() )
    {
        CLOGD << "Resource " << rResource << " already loaded.";

        // If the resource is already loaded, callback immediately.
        rCallbackSlot( resource );
    }
    else if( !resource.isNull() && mHandleTickets.count( std::make_pair( 
        resource->getCreator()->getResourceType(), resource->getHandle() ) ) )
    {
        // If the resource is loading, add a callback.
        HandleTickets::iterator i = mHandleTickets.find(  std::make_pair( 
            resource->getCreator()->getResourceType(), resource->getHandle() ) );

        if( i != mHandleTickets.end() )
        {
            mTicketCallbacks.insert( TicketCallbacks::value_type( i->second, rCallbackSlot ) );

            CLOGD << "Resource " << rResource << " is loading, ticket callback: " << i->second;
        }
        else
        {
            DIVERSIA_EXCEPT( Exception::ERR_INTERNAL_ERROR, 
                "Could not find ticket for resource that is loading in the background.", 
	            "ResourceManager::loadResource" );
        }
    }
    else if( !resource.isNull() )
    {
        // Load the resource in the background and register the callback.
        resource = ResourceManager::getResource( rResource, true );
        Ogre::BackgroundProcessTicket ticket = 
            mRBQ.load( ResourceManager::getResourceManagerName( rResource.mType ), 
            rResource.mFile.string(), mGroup, false, 0, 0, this );
        mTicketCallbacks.insert( TicketCallbacks::value_type( ticket, rCallbackSlot ) );
        mHandleTickets.insert( std::make_pair( std::make_pair( 
            resource->getCreator()->getResourceType(), resource->getHandle() ), ticket ) );
        mTicketResources.insert( std::make_pair( ticket, resource ) );

        CLOGD << "Resource " << rResource << " will be loaded, ticket: " << ticket;
    }
    else
    {
        DIVERSIA_EXCEPT( Exception::ERR_FILE_NOT_FOUND, "Cannot load resource " + 
            rResource.mFile.string() + ", file does not exist.", 
	        "ResourceManager::loadResource" );
    }

    return resource;
}
Example #2
0
void ResourceManager::ResourcesLoader::loadingComplete( Ogre::ResourcePtr pResource )
{
    mResources.erase( std::make_pair( pResource->getCreator()->getResourceType(), 
        pResource->getHandle() ) );
    if( !mResources.size() )
    {
        mCompletedSlot();
        delete this;
    }
}
Example #3
0
void ResourceManager::ResourcesLoader::addResource( Ogre::ResourcePtr pResource )
{
    mResources.insert( std::make_pair( pResource->getCreator()->getResourceType(), 
        pResource->getHandle() ) );
}