Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Member Functions | Static Public Member Functions | List of all members
jop::ResourceManager Class Reference

#include <ResourceManager.hpp>

Inheritance diagram for jop::ResourceManager:
jop::Subsystem

Public Member Functions

 ResourceManager ()
 Default constructor. More...
 
 ~ResourceManager () override
 Destructor. More...
 
- Public Member Functions inherited from jop::Subsystem
 Subsystem (const uint32 ID)
 Constructor. More...
 
virtual ~Subsystem ()=0
 Virtual destructor. More...
 
virtual void preUpdate (const float deltaTime)
 Pre-update. More...
 
virtual void postUpdate (const float deltaTime)
 Post-update. More...
 
virtual void draw ()
 Draw. More...
 
Message::Result sendMessage (const Message &message)
 Function to handle messages. More...
 
SubsystemsetActive (const bool active)
 Set this sub system active. More...
 
bool isActive () const
 Check if this sub system is active. More...
 
uint32 getID () const
 Get the ID. More...
 

Static Public Member Functions

template<typename T , typename... Args>
static T & get (Args &&...args)
 Get a resource. More...
 
template<typename T , typename... Args>
static T & getNamed (const std::string &name, Args &&...args)
 Get a named resource. More...
 
template<typename T , typename... Args>
static T & getEmpty (Args &&...args)
 Get an empty resource. More...
 
template<typename T >
static T & getExisting (const std::string &name)
 Get an existing resource. More...
 
template<typename T >
static bool exists (const std::string &name)
 Check is a resource exists. More...
 
template<typename T >
static T & copy (const std::string &name, const std::string &newName)
 Copy a resource. More...
 
static void unload (const std::string &name)
 Delete resources. More...
 
template<typename T >
static void unload (const std::string &name)
 Delete a resource from memory. More...
 
static void unload (const unsigned short persistence=0xFFFF, const bool descending=true)
 Delete all resources. More...
 
static void beginLoadPhase ()
 Mark the beginning of a resource loading phase. More...
 
static void endLoadPhase (const uint16 persistence)
 Mark the ending of a resource loading phase. More...
 
template<typename T >
static bool isDefault (const T &resource)
 Check is a resource is the default resource. More...
 
template<typename T >
static bool isError (const T &resource)
 Check is a resource is the error resource. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jop::Subsystem
virtual Message::Result receiveMessage (const Message &message)
 Receive a message. More...
 

Detailed Description

Definition at line 54 of file ResourceManager.hpp.

Constructor & Destructor Documentation

jop::ResourceManager::ResourceManager ( )

Default constructor.

jop::ResourceManager::~ResourceManager ( )
override

Destructor.

Member Function Documentation

static void jop::ResourceManager::beginLoadPhase ( )
static

Mark the beginning of a resource loading phase.

This function is provided to make it easier to manage big amounts of resources. When called, every resource that is referenced after, will become flagged. When the load phase is ended, all resources not flagged will be removed, provided they pass the persistence test.

Warning
It's very important to call endLoadPhase() after this, right after all the needed resources are loaded
See also
endLoadPhase()
template<typename T >
static T& jop::ResourceManager::copy ( const std::string &  name,
const std::string &  newName 
)
static

Copy a resource.

This function requires that the resource has a valid copy constructor. If the resource is not found or is of the wrong type, the default/error resource will be returned instead.

Parameters
nameName of the resource to copy
newNameName of the copied resource
Returns
Reference to the resource
See also
Resource::Resource(const Resource&, const std::string&)
static void jop::ResourceManager::endLoadPhase ( const uint16  persistence)
static

Mark the ending of a resource loading phase.

If a load phase was previously initiated, calling this function will end it and clear all resources as described on beginLoadPhase().

Parameters
persistenceThe maximum persistence level to take into account. Resources with equal or greater persistence level will be removed
See also
beginLoadPhase()
template<typename T >
static bool jop::ResourceManager::exists ( const std::string &  name)
static

Check is a resource exists.

The name and type must both match.

Parameters
nameName of the resource
Returns
True if the resource exists
template<typename T , typename... Args>
static T& jop::ResourceManager::get ( Args &&...  args)
static

Get a resource.

If resource is not found this creates a new one. The first argument must be convertible into std::string, as it's used as a hash map key.

Parameters
argsArguments passed to resource's constructor
Returns
Reference to the resource
template<typename T , typename... Args>
static T& jop::ResourceManager::getEmpty ( Args &&...  args)
static

Get an empty resource.

This function will not call the resource's load function.

Parameters
argsArguments to pass to the resource's constructor
Returns
Reference to the resource
template<typename T >
static T& jop::ResourceManager::getExisting ( const std::string &  name)
static

Get an existing resource.

This function will not attempt to create the resource if it's not found or is not of the matching type. Instead a default is returned.

Parameters
nameName of the resource
Returns
Reference to the resource
template<typename T , typename... Args>
static T& jop::ResourceManager::getNamed ( const std::string &  name,
Args &&...  args 
)
static

Get a named resource.

This is primarily used when the resource is not loaded from a file. After the resource has been loaded once, it can be retrieved by using getExisting().

Parameters
nameName for the resource
argsArguments passed to resource's constructor
Returns
Reference to the resource
template<typename T >
static bool jop::ResourceManager::isDefault ( const T &  resource)
static

Check is a resource is the default resource.

Parameters
resourceReference to the resource
Returns
True if the resource is the default resource
template<typename T >
static bool jop::ResourceManager::isError ( const T &  resource)
static

Check is a resource is the error resource.

Parameters
resourceReference to the resource
Returns
True if the resource is the error resource
static void jop::ResourceManager::unload ( const std::string &  name)
static

Delete resources.

This will delete all the resources with the given name, regardless of type.

The resources, if found, will be deleted regardless of the persistence level. Resources with the persistence level of 0 will not be removed, however.

Parameters
nameName of the resources to unload
template<typename T >
static void jop::ResourceManager::unload ( const std::string &  name)
static

Delete a resource from memory.

The resource, if found, will be deleted regardless of the persistence level. Resources with the persistence level of 0 will not be removed, however.

When possible, you should prefer this overload. It's possibly magnitudes faster.

Parameters
nameName of the resource
static void jop::ResourceManager::unload ( const unsigned short  persistence = 0xFFFF,
const bool  descending = true 
)
static

Delete all resources.

Parameters
persistenceThe persistence of the resources to unload
descendingSet true to unload all resources with the given and greater persistence levels

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