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::reloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName, const std::string& resourceGroup)
{
    Ogre::ResourcePtr rPtr = resMgr->load(resourceName, resourceGroup);
    if (rPtr.isNull()) LOG_META(FORMAT("The resource '%1%' no longer exists!", resourceName));

    rPtr->reload();
    if (rPtr->isLoaded())
        LOG_META(FORMAT("The resource '%1%' wasn`t unloaded!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was unloaded!", resourceName));
}
Example #3
0
void UnloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName)
{
    Ogre::ResourcePtr rPtr = resMgr->getResourceByName(resourceName);
    if (rPtr.isNull())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource no longer exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
        return;
    }
 
    rPtr->unload();
    if (rPtr->isLoaded())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was not unloaded: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was unloaded: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
 
    resMgr->remove(resourceName);
    rPtr = resMgr->getResourceByName(resourceName);
    if (rPtr.isNull())
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was removed: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource was not removed: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
 
    if (resMgr->resourceExists(resourceName))
    {
        StringUtil::StrStreamType msg;
        msg << "Resource still exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
    else
    {
        StringUtil::StrStreamType msg;
        msg << "Resource no longer exists: " << resourceName;
        Ogre::LogManager::getSingleton().logMessage(msg.str());
    }
}
Example #4
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 ) );
    }
}
    void run()
    {
        Meru::ResourceLoadingQueue *queue = &ResourceLoadingQueue::getSingleton();

        Ogre::ResourcePtr skeletonPtr = Ogre::SkeletonManager::getSingleton().getByName(mName);
        if (skeletonPtr.isNull() || !skeletonPtr->isLoaded()) {
            SILOG(resource,insane, "Skeleton Load Task run(), waiting for " << mName << " To queue");
            SILOG(resource,debug,"Queueing " << mName << " for OGRE load ");
            queue->load(Ogre::SkeletonManager::getSingleton().getResourceType(), mName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, false, NULL, NULL, this);
        }
        else {
            SILOG(resource,insane, "Skeleton Load Task run() AND complete, waited for " << mName << " To queue");
            signalCompletion();
        }
    }
Example #6
0
void ResourceManager::unloadResource(Ogre::ResourceManager* resMgr, const std::string& resourceName)
{
    Ogre::ResourcePtr rPtr = resMgr->getByName(resourceName);
    if (rPtr.isNull()) return

    rPtr->unload();
    if (rPtr->isLoaded())
        LOG_META(FORMAT("The resource '%1%' wasn`t unloaded!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was unloaded!", resourceName));

    resMgr->remove(resourceName);
    rPtr = resMgr->getByName(resourceName);
    if (!rPtr.isNull())
        LOG_META(FORMAT("The resource '%1%' wasn`t removed!", resourceName));
    else
        LOG_META(FORMAT("The resource '%1%' was removed!", resourceName));
}
Example #7
0
void OgreInfo::diagnose(std::ostream& outputStream)
{
	Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerI = Ogre::Root::getSingleton().getSceneManagerIterator();
	while (sceneManagerI.hasMoreElements()) {
		Ogre::SceneManager* sceneManager = sceneManagerI.getNext();
		outputStream << "Scenemanager(" << sceneManager->getTypeName() << ") " << sceneManager->getName() << std::endl;
		outputStream << " Number of scene nodes: " << countNodes(sceneManager->getRootSceneNode()) << std::endl;
		outputStream << " Movable objects:" << std::endl;
		unsigned int movableObjectCounter = 0;
		Ogre::Root::MovableObjectFactoryIterator movableObjectFactoryI = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
		while (movableObjectFactoryI.hasMoreElements()) {
			Ogre::MovableObjectFactory* factory = movableObjectFactoryI.getNext();
			std::string type(factory->getType());
			{
				Ogre::SceneManager::MovableObjectIterator I = sceneManager->getMovableObjectIterator(type);
				while (I.hasMoreElements()) {
					movableObjectCounter++;
					Ogre::MovableObject* movable = I.getNext();
					if (movable->getMovableType() == "Light") {
						Ogre::Light* light = static_cast<Ogre::Light*> (movable);
						outputStream << "  * Light " << light->getName() << "(" << (light->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
						outputStream << "   Pos: " << light->getDerivedPosition() << std::endl;
						outputStream << "   Direction: " << light->getDerivedDirection() << std::endl;

					} else {
						std::stringstream ssPosAndOrientation;
						if (movable->getParentSceneNode() && movable->isInScene()) {
							ssPosAndOrientation << " pos: " << movable->getParentSceneNode()->getPosition() << " orientation: " << movable->getParentSceneNode()->getOrientation();
						}
						outputStream << "  * " << type << " " << movable->getName() << "(" << (movable->isInScene() ? "in scene" : "not in scene") << ")" << ssPosAndOrientation.str() << std::endl;
						//					outputStream << "  Pos: " << light->getDerivedPosition() << std::endl;
						//					outputStream << "  Direction: " << light->getDerivedDirection() << std::endl;
					}
				}
			}
		}

		outputStream << " Number of movable objects: " << movableObjectCounter << std::endl;

		outputStream << " Cameras:" << std::endl;
		{
			Ogre::SceneManager::CameraIterator I = sceneManager->getCameraIterator();
			while (I.hasMoreElements()) {
				Ogre::Camera* camera = I.getNext();
				outputStream << "  Camera " << camera->getName() << "(" << (camera->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
				outputStream << "  Pos: " << camera->getDerivedPosition() << std::endl;
				outputStream << "  Direction: " << camera->getDerivedDirection() << std::endl;
				outputStream << "  Clip distances: " << camera->getNearClipDistance() << " - " << camera->getFarClipDistance() << std::endl;
			}
		}

	}

	size_t resourceMemoryUsage = 0;
	outputStream << "Resource Managers:" << std::endl;
	Ogre::ResourceGroupManager::ResourceManagerIterator I = Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
	while (I.hasMoreElements()) {
		std::string name = I.peekNextKey();
		Ogre::ResourceManager* manager = I.getNext();
		outputStream << " Resource Manager: " << name << std::endl;
		if (manager->getMemoryBudget() == std::numeric_limits<size_t>::max()) {
			outputStream << "  Memory budget: not set" << std::endl;
		} else {
			outputStream << "  Memory budget: " << manager->getMemoryBudget() << " bytes" << std::endl;
		}
		outputStream << "  Memory usage:  " << manager->getMemoryUsage() << " bytes" << std::endl;
		resourceMemoryUsage += manager->getMemoryUsage();

		Ogre::ResourceManager::ResourceMapIterator resourceI = manager->getResourceIterator();
		if (resourceI.hasMoreElements()) {
			outputStream << "  Resources: " << std::endl;
			int resourceCount = 0;
			int loadedResourceCount = 0;
			while (resourceI.hasMoreElements()) {
				Ogre::ResourcePtr resource = resourceI.getNext();
				if (resource->isLoaded()) {
					std::string reloadable = resource->isReloadable() ? " reloadable" : "";
					outputStream << "   " << resource->getName() << " ( " << resource->getSize() << " bytes)" << reloadable;
					Ogre::Texture* texture = dynamic_cast<Ogre::Texture*>(resource.get());
					if (texture) {
						outputStream << texture->getWidth() << "x" << texture->getHeight() << " ";
					}
					outputStream << std::endl;
					loadedResourceCount++;
				}
				resourceCount++;
			}
			outputStream << "  Total number of resources: " << resourceCount << std::endl;
			outputStream << "  Number of loaded resources: " << loadedResourceCount << std::endl;
		}
	}

	outputStream << "Total memory usage for all resource manager: " << resourceMemoryUsage << " bytes" << std::endl;

	outputStream << std::flush;
}