FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::ImageManager Class Reference

ImageManager. More...

#include <imagemanager.h>

+ Inheritance diagram for FIFE::ImageManager:
+ Collaboration diagram for FIFE::ImageManager:

Public Member Functions

 ImageManager ()
 Default constructor. More...
 
virtual ~ImageManager ()
 Destructor. More...
 
virtual size_t getMemoryUsed () const
 Gets the total amount of memory used by resources. More...
 
virtual size_t getTotalResourcesCreated () const
 Returns the number of unloaded resources. More...
 
virtual size_t getTotalResourcesLoaded () const
 Returns the number of loaded resources. More...
 
virtual size_t getTotalResources () const
 Returns the number of defined resources. More...
 
virtual ImagePtr create (IResourceLoader *loader=0)
 Creates a blank Image but does not load it immediately. More...
 
virtual ImagePtr create (const std::string &name, IResourceLoader *loader=0)
 Creates a blank Image but does not load it immediately. More...
 
virtual ImagePtr load (const std::string &name, IResourceLoader *loader=0)
 Creates a blank resource and loads it from disk. More...
 
virtual ImagePtr loadBlank (uint32_t width, uint32_t height)
 Loads a blank resource. More...
 
virtual ImagePtr loadBlank (const std::string &name, uint32_t width, uint32_t height)
 Loads a blank resource. More...
 
virtual ImagePtr add (Image *res)
 Add an Image to the manager. More...
 
virtual bool exists (const std::string &name)
 Checks to see if an Image exists. More...
 
virtual bool exists (ResourceHandle handle)
 Checks to see if an Image exists. More...
 
virtual void reload (const std::string &name)
 Reloads an Image. More...
 
virtual void reload (ResourceHandle handle)
 Reloads a resource. More...
 
virtual void reloadAll ()
 Reloads all Images. More...
 
virtual void loadUnreferenced ()
 Loads all unreferenced Images. More...
 
virtual void free (const std::string &name)
 Frees an Image from memory. More...
 
virtual void free (ResourceHandle handle)
 Frees an Image from memory. More...
 
virtual void freeAll ()
 Frees all Images. More...
 
virtual void freeUnreferenced ()
 Frees all unreferenced Image. More...
 
virtual void remove (ImagePtr &resource)
 Removes an Image from the manager. More...
 
virtual void remove (const std::string &name)
 Removes an Image from the manager. More...
 
virtual void remove (ResourceHandle handle)
 Removes an Image from the manager. More...
 
virtual void removeAll ()
 Removes all Images from the manager. More...
 
virtual void removeUnreferenced ()
 Removes all unreferenced Images. More...
 
virtual ImagePtr get (const std::string &name)
 Gets a shared pointer to the Image. More...
 
virtual ImagePtr get (ResourceHandle handle)
 Gets a shared pointer to the Image. More...
 
virtual ImagePtr getPtr (const std::string &name)
 
virtual ImagePtr getPtr (ResourceHandle handle)
 
virtual ResourceHandle getResourceHandle (const std::string &name)
 Gets an Image handle by name. More...
 
virtual void invalidate (const std::string &name)
 
virtual void invalidate (ResourceHandle handle)
 
virtual void invalidateAll ()
 
- Public Member Functions inherited from FIFE::IResourceManager
 IResourceManager ()
 Default constructor. More...
 
virtual ~IResourceManager ()
 destructor More...
 
- Public Member Functions inherited from FIFE::DynamicSingleton< ImageManager >
 DynamicSingleton ()
 
virtual ~DynamicSingleton ()
 

Private Types

typedef std::map< ResourceHandle, ImagePtrImageHandleMap
 
typedef std::map< ResourceHandle, ImagePtr >::iterator ImageHandleMapIterator
 
typedef std::map< ResourceHandle, ImagePtr >::const_iterator ImageHandleMapConstIterator
 
typedef std::pair< ResourceHandle, ImagePtrImageHandleMapPair
 
typedef std::map< std::string, ImagePtrImageNameMap
 
typedef std::map< std::string, ImagePtr >::iterator ImageNameMapIterator
 
typedef std::map< std::string, ImagePtr >::const_iterator ImageNameMapConstIterator
 
typedef std::pair< std::string, ImagePtrImageNameMapPair
 

Private Attributes

ImageHandleMap m_imgHandleMap
 
ImageNameMap m_imgNameMap
 

Additional Inherited Members

- Static Public Member Functions inherited from FIFE::DynamicSingleton< ImageManager >
static ImageManagerinstance ()
 

Detailed Description

ImageManager.

An interface for managing images.

See also
IResource
IResourceLoader
IResourceManager

Definition at line 54 of file imagemanager.h.

Member Typedef Documentation

◆ ImageHandleMap

Definition at line 380 of file imagemanager.h.

◆ ImageHandleMapConstIterator

typedef std::map< ResourceHandle, ImagePtr >::const_iterator FIFE::ImageManager::ImageHandleMapConstIterator
private

Definition at line 382 of file imagemanager.h.

◆ ImageHandleMapIterator

typedef std::map< ResourceHandle, ImagePtr >::iterator FIFE::ImageManager::ImageHandleMapIterator
private

Definition at line 381 of file imagemanager.h.

◆ ImageHandleMapPair

Definition at line 383 of file imagemanager.h.

◆ ImageNameMap

typedef std::map< std::string, ImagePtr > FIFE::ImageManager::ImageNameMap
private

Definition at line 385 of file imagemanager.h.

◆ ImageNameMapConstIterator

typedef std::map< std::string, ImagePtr >::const_iterator FIFE::ImageManager::ImageNameMapConstIterator
private

Definition at line 387 of file imagemanager.h.

◆ ImageNameMapIterator

typedef std::map< std::string, ImagePtr >::iterator FIFE::ImageManager::ImageNameMapIterator
private

Definition at line 386 of file imagemanager.h.

◆ ImageNameMapPair

typedef std::pair< std::string, ImagePtr > FIFE::ImageManager::ImageNameMapPair
private

Definition at line 388 of file imagemanager.h.

Constructor & Destructor Documentation

◆ ImageManager()

◆ ~ImageManager()

FIFE::ImageManager::~ImageManager ( )
virtual

Destructor.

Definition at line 46 of file imagemanager.cpp.

Referenced by ImageManager().

+ Here is the caller graph for this function:

Member Function Documentation

◆ add()

ImagePtr FIFE::ImageManager::add ( Image res)
virtual

Add an Image to the manager.

This function will create a ImagePtr and add the Image to the manager. The manager assumes ownership of the Image so DO NOT delete it.

Parameters
resA pointer to the Image
Returns
A ImagePtr to the added resource
See also
Image

Definition at line 155 of file imagemanager.cpp.

References FIFE::_log, exists(), FL_WARN, FIFE::IResource::getHandle(), FIFE::IResource::getName(), m_imgHandleMap, and m_imgNameMap.

Referenced by FIFE::InstanceRenderer::bindColoring(), FIFE::InstanceRenderer::bindMultiOutline(), FIFE::InstanceRenderer::bindOutline(), create(), FIFE::LibRocketRenderInterface::GenerateTexture(), FIFE::InstanceRenderer::getMultiColorOverlay(), ImageManager(), and loadBlank().

+ Here is the caller graph for this function:

◆ create() [1/2]

ImagePtr FIFE::ImageManager::create ( IResourceLoader loader = 0)
virtual

Creates a blank Image but does not load it immediately.

Parameters
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
An ImagePtr to the newly created Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 95 of file imagemanager.cpp.

References add(), FIFE::RenderBackend::createImage(), and FIFE::DynamicSingleton< RenderBackend >::instance().

Referenced by ImageManager(), FIFE::GuiImageLoader::load(), FIFE::SDLImage::load(), FIFE::GLImage::load(), FIFE::ObjectLoader::load(), load(), FIFE::AnimationLoader::loadAnimation(), FIFE::AtlasLoader::loadAtlas(), and FIFE::Cursor::setNativeImageCursor().

+ Here is the caller graph for this function:

◆ create() [2/2]

ImagePtr FIFE::ImageManager::create ( const std::string &  name,
IResourceLoader loader = 0 
)
virtual

Creates a blank Image but does not load it immediately.

Parameters
nameThe resource name. Typically a filename.
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
An ImagePtr to the newly created Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 100 of file imagemanager.cpp.

References FIFE::_log, add(), FIFE::RenderBackend::createImage(), exists(), FL_WARN, getPtr(), and FIFE::DynamicSingleton< RenderBackend >::instance().

◆ exists() [1/2]

bool FIFE::ImageManager::exists ( const std::string &  name)
virtual

Checks to see if an Image exists.

This function will search the manager for Images that match the parameter

Parameters
nameThe name of the Image
Returns
True if the Image exists. False otherwise.

Definition at line 174 of file imagemanager.cpp.

References m_imgNameMap.

Referenced by add(), FIFE::InstanceRenderer::bindColoring(), FIFE::InstanceRenderer::bindMultiOutline(), FIFE::InstanceRenderer::bindOutline(), create(), ImageManager(), FIFE::GuiImageLoader::load(), FIFE::SDLImage::load(), FIFE::ObjectLoader::load(), FIFE::AnimationLoader::loadAnimation(), FIFE::AtlasLoader::loadAtlas(), and FIFE::LibRocketRenderInterface::LoadTexture().

+ Here is the caller graph for this function:

◆ exists() [2/2]

bool FIFE::ImageManager::exists ( ResourceHandle  handle)
virtual

Checks to see if an Image exists.

This function will search the manager for Images that match the parameter

Parameters
handleThe handle of the Image
Returns
True if the Image exists. False otherwise.

Definition at line 183 of file imagemanager.cpp.

References m_imgHandleMap.

◆ free() [1/2]

void FIFE::ImageManager::free ( const std::string &  name)
virtual

Frees an Image from memory.

The Image is not deleted but it's data is freed. This calls the Image::free() function and it is up to the resource to properly free it's memory. The manager keeps a reference to the Image in case its required in the future.

Parameters
nameThe name of the Image
See also
Image

Definition at line 247 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgNameMap, and FIFE::IResource::RES_LOADED.

Referenced by FIFE::InstanceRenderer::check(), FIFE::GuiImage::free(), and ImageManager().

+ Here is the caller graph for this function:

◆ free() [2/2]

void FIFE::ImageManager::free ( ResourceHandle  handle)
virtual

Frees an Image from memory.

The Image is not deleted but it's data is freed. This calls the Image::free() function and it is up to the resource to properly free it's memory. The manager keeps a reference to the Image in case its required in the future.

Parameters
handleThe handle of the Image
See also
Image

Definition at line 260 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

◆ freeAll()

void FIFE::ImageManager::freeAll ( )
virtual

Frees all Images.

This calls the Image::free() function for every Image the manager is managing. It does not remove them from the manager.

See also
Image

Definition at line 272 of file imagemanager.cpp.

References FIFE::_log, FL_DBG, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ freeUnreferenced()

void FIFE::ImageManager::freeUnreferenced ( )
virtual

Frees all unreferenced Image.

This calls the IResource::free() function for Images that have no external references to them. It does not remove them from the manager.

See also
IResource

Definition at line 288 of file imagemanager.cpp.

References FIFE::_log, FL_DBG, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ get() [1/2]

ImagePtr FIFE::ImageManager::get ( const std::string &  name)
virtual

Gets a shared pointer to the Image.

If the Image is not defined it will attempt to create and load the Image based on the name (it assumes the name is a filename)

Parameters
nameThe name of the Image
Returns
An ImagePtr to the Image

Definition at line 398 of file imagemanager.cpp.

References load(), m_imgNameMap, and FIFE::IResource::RES_LOADED.

Referenced by FIFE::LibRocketRenderInterface::freeTextures(), FIFE::GuiImageLoader::load(), FIFE::LibRocketRenderInterface::LoadTexture(), FIFE::LibRocketRenderInterface::render(), FIFE::Camera::renderOverlay(), and FIFE::LayerCache::updateVisual().

+ Here is the caller graph for this function:

◆ get() [2/2]

ImagePtr FIFE::ImageManager::get ( ResourceHandle  handle)
virtual

Gets a shared pointer to the Image.

If the resource is not defined it returns an empty (or invalid) ImagePtr and makes an entry in the log.

Parameters
handleThe handle of the resource
Returns
A ImagePtr to the resource

Definition at line 414 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

◆ getMemoryUsed()

size_t FIFE::ImageManager::getMemoryUsed ( ) const
virtual

Gets the total amount of memory used by resources.

This function uses the IResource's getSize() function to calculate the total memory used. It does not include memory used by the internal resource manager book keeping structures. This value is only accurate if the resources getSize() function returns an accurate result.

Returns
Total memory used

Implements FIFE::IResourceManager.

Definition at line 50 of file imagemanager.cpp.

References m_imgHandleMap.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ getPtr() [1/2]

◆ getPtr() [2/2]

ImagePtr FIFE::ImageManager::getPtr ( ResourceHandle  handle)
virtual

Definition at line 441 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, and m_imgHandleMap.

◆ getResourceHandle()

ResourceHandle FIFE::ImageManager::getResourceHandle ( const std::string &  name)
virtual

Gets an Image handle by name.

Returns the Image handle associated with the name

Parameters
nameThe name of the Image
Returns
0 if the resource name is invalid

Definition at line 452 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, and m_imgNameMap.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ getTotalResources()

size_t FIFE::ImageManager::getTotalResources ( ) const
virtual

Returns the number of defined resources.

Gets the total number of resources managed by the manager.

Returns
Total resources managed

Implements FIFE::IResourceManager.

Definition at line 91 of file imagemanager.cpp.

References m_imgHandleMap.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ getTotalResourcesCreated()

size_t FIFE::ImageManager::getTotalResourcesCreated ( ) const
virtual

Returns the number of unloaded resources.

Gets the total number of resources created but not loaded. These resources have been defined in the resource manager but have yet to be loaded from disk.

Returns
Total resources created

Implements FIFE::IResourceManager.

Definition at line 63 of file imagemanager.cpp.

References m_imgHandleMap, and FIFE::IResource::RES_NOT_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ getTotalResourcesLoaded()

size_t FIFE::ImageManager::getTotalResourcesLoaded ( ) const
virtual

Returns the number of loaded resources.

Gets the total number of resources created and loaded. These resources have been defined in the resource manager have been loaded from disk.

Returns
Total resources loaded

Implements FIFE::IResourceManager.

Definition at line 77 of file imagemanager.cpp.

References m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ invalidate() [1/2]

void FIFE::ImageManager::invalidate ( const std::string &  name)
virtual

Definition at line 463 of file imagemanager.cpp.

References m_imgNameMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ invalidate() [2/2]

void FIFE::ImageManager::invalidate ( ResourceHandle  handle)
virtual

Definition at line 472 of file imagemanager.cpp.

References m_imgHandleMap, and FIFE::IResource::RES_LOADED.

◆ invalidateAll()

void FIFE::ImageManager::invalidateAll ( )
virtual

Definition at line 481 of file imagemanager.cpp.

References m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by FIFE::Engine::changeScreenMode(), and ImageManager().

+ Here is the caller graph for this function:

◆ load()

ImagePtr FIFE::ImageManager::load ( const std::string &  name,
IResourceLoader loader = 0 
)
virtual

Creates a blank resource and loads it from disk.

This function will create the Image if necessary and load the Image from disk. If the Image is not defined it will call ImageManager::create() before loading.

Parameters
nameThe resource name. Typically a filename.
loaderA pointer to the custom resource loader. The default is NULL. If this parameter is present the resource will use the loader to load instead of the default built in functions.
Returns
A ImagePtr to the loaded Image
See also
Image
ImageLoader
IResourceLoader

Definition at line 110 of file imagemanager.cpp.

References FIFE::_log, create(), FL_WARN, FIFE::IResource::getState(), FIFE::Image::load(), m_imgNameMap, and FIFE::IResource::RES_NOT_LOADED.

Referenced by get(), ImageManager(), FIFE::GuiImageLoader::load(), FIFE::LibRocketRenderInterface::LoadTexture(), and FIFE::SubImageFont::SubImageFont().

+ Here is the caller graph for this function:

◆ loadBlank() [1/2]

ImagePtr FIFE::ImageManager::loadBlank ( uint32_t  width,
uint32_t  height 
)
virtual

Loads a blank resource.

Parameters
width
height
Returns
An ImagePtr to the blank image (ready to be modified)

Definition at line 133 of file imagemanager.cpp.

References add(), FIFE::RenderBackend::createImage(), FIFE::DynamicSingleton< RenderBackend >::instance(), FIFE::IResource::RES_LOADED, and FIFE::IResource::setState().

Referenced by ImageManager(), FIFE::GuiImageLoader::load(), FIFE::Camera::renderStaticLayer(), and FIFE::RenderTarget::RenderTarget().

+ Here is the caller graph for this function:

◆ loadBlank() [2/2]

ImagePtr FIFE::ImageManager::loadBlank ( const std::string &  name,
uint32_t  width,
uint32_t  height 
)
virtual

Loads a blank resource.

Parameters
name
width
height
Returns
An ImagePtr to the blank image (ready to be modified)

Definition at line 142 of file imagemanager.cpp.

References add(), FIFE::RenderBackend::createImage(), FIFE::DynamicSingleton< RenderBackend >::instance(), m_imgNameMap, FIFE::IResource::RES_LOADED, and FIFE::IResource::setState().

◆ loadUnreferenced()

void FIFE::ImageManager::loadUnreferenced ( )
virtual

Loads all unreferenced Images.

All Images that have no external references will be loaded into memory.

Definition at line 233 of file imagemanager.cpp.

References FIFE::_log, FL_DBG, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ reload() [1/2]

void FIFE::ImageManager::reload ( const std::string &  name)
virtual

Reloads an Image.

This function will reload an Image if it is managed by the manager. If not it creates an entry in the log specifying that the Image could not be found. It will load the Image if it is not already loaded.

Parameters
nameThe name of the resource

Definition at line 192 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgNameMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ reload() [2/2]

void FIFE::ImageManager::reload ( ResourceHandle  handle)
virtual

Reloads a resource.

This function will reload an Image if it is managed by the manager. If not it creates an entry in the log specifying that the Image could not be found. It will load the Image if it is not already loaded.

Parameters
handleThe handle of the resource

Definition at line 206 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgHandleMap, and FIFE::IResource::RES_LOADED.

◆ reloadAll()

void FIFE::ImageManager::reloadAll ( )
virtual

Reloads all Images.

This function will reload all Images managed by the manager. It will load an Image if it is not already loaded.

Definition at line 221 of file imagemanager.cpp.

References m_imgHandleMap, and FIFE::IResource::RES_LOADED.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ remove() [1/3]

void FIFE::ImageManager::remove ( ImagePtr resource)
virtual

Removes an Image from the manager.

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
resourceA ImagePtr to the image to be removed from the manager
Note
This is useful if you want to remove ownership of a resource from the manager
See also
Image

Definition at line 303 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, FIFE::IResource::getHandle(), FIFE::IResource::getName(), m_imgHandleMap, and m_imgNameMap.

Referenced by FIFE::GuiImageLoader::load(), and FIFE::Cursor::setNativeImageCursor().

+ Here is the caller graph for this function:

◆ remove() [2/3]

void FIFE::ImageManager::remove ( const std::string &  name)
virtual

Removes an Image from the manager.

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
nameThe name of the Image
See also
Image

Definition at line 320 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgHandleMap, and m_imgNameMap.

◆ remove() [3/3]

void FIFE::ImageManager::remove ( ResourceHandle  handle)
virtual

Removes an Image from the manager.

This removes all references to the Image from the manager. It does not however guarantee that the resources destructor is called. If the client has any left over references to the resource it will not be freed.

Parameters
handleThe handle of the Image
See also
Image

Definition at line 342 of file imagemanager.cpp.

References FIFE::_log, FL_WARN, m_imgHandleMap, and m_imgNameMap.

◆ removeAll()

void FIFE::ImageManager::removeAll ( )
virtual

Removes all Images from the manager.

This effectively removes all references to all Images from the manager. If there are left over shared pointers to any resources they will not be deleted.

See also
Image

Definition at line 365 of file imagemanager.cpp.

References FIFE::_log, FL_DBG, m_imgHandleMap, and m_imgNameMap.

Referenced by ImageManager().

+ Here is the caller graph for this function:

◆ removeUnreferenced()

void FIFE::ImageManager::removeUnreferenced ( )
virtual

Removes all unreferenced Images.

This effectively removes all Images that dont have an external reference. The resources will be deleted.

See also
Image

Definition at line 377 of file imagemanager.cpp.

References FIFE::_log, FL_DBG, and m_imgHandleMap.

Referenced by ImageManager().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_imgHandleMap

◆ m_imgNameMap

ImageNameMap FIFE::ImageManager::m_imgNameMap
private

The documentation for this class was generated from the following files: