Terminus
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
terminus::ResourceManager Class Reference

The ResourceManager class loads geometry, materials and shader progams during initialization and provides access to those resources. More...

#include <resourcemanager.h>

Public Member Functions

virtual ~ResourceManager ()
 
virtual void loadResources ()
 All external resources the game might use are loaded here. More...
 
virtual std::shared_ptr< std::unique_ptr< Geometry > > getGeometry (std::string name)
 
virtual std::shared_ptr< std::unique_ptr< Material > > getMaterial (std::string name)
 
virtual std::shared_ptr< std::unique_ptr< Program > > getProgram (std::string name)
 

Static Public Member Functions

static ResourceManagergetInstance ()
 Returns the singelton instance of the ResourceManager class. More...
 

Protected Member Functions

 ResourceManager ()
 
virtual void loadObj (std::string path)
 The .obj file specified by "path" will be parsed and stored in the geometry container m_geometryStorage. More...
 
virtual void loadObjGenerateAdd (std::vector< QVector3D > &positions, std::vector< QVector3D > &texCoords, std::vector< QVector3D > &normals, std::vector< IndexTriple > &indexTriples, std::string name)
 This method is part of the loading mechanism for .obj files. More...
 
virtual void loadMtl (std::string path)
 Loads material data from .mtl files. More...
 
virtual void loadProgram (std::string path)
 Vertex and fragment shader files are loaded an combined into on program instance from the Program class. More...
 
virtual void putGeometry (std::string name, Geometry *geometry)
 
virtual void putMaterial (std::string name, Material *material)
 
virtual void putProgram (std::string name, Program *program)
 

Static Protected Member Functions

static std::string entityName (const std::string path, const std::string name)
 Generates a unique resource identifier from the resource's file path and name. More...
 
static std::string entityName (const std::string path)
 Generates a unique resource identifier from the resource's file path. More...
 

Protected Attributes

std::map< std::string, std::shared_ptr< std::unique_ptr< Geometry > > > m_geometryStorage
 
std::map< std::string, std::shared_ptr< std::unique_ptr< Material > > > m_materialStorage
 
std::map< std::string, std::shared_ptr< std::unique_ptr< Program > > > m_programStorage
 

Static Protected Attributes

static ResourceManagerm_instance = nullptr
 

Detailed Description

The ResourceManager class loads geometry, materials and shader progams during initialization and provides access to those resources.

Loaded data is stored in three corresponding member variables of type "std::map<std::string, std::shared_ptr<std::unique_ptr< ... >>>". Having two pointers secures to have valid data accessable at all times. By the time data is updated during runtime, classes with references to stored data will automatically load the recent data. Implemented as a singelton, accessibility for all classes is ensured.

Constructor & Destructor Documentation

terminus::ResourceManager::~ResourceManager ( )
virtual
terminus::ResourceManager::ResourceManager ( )
protected

Member Function Documentation

std::string terminus::ResourceManager::entityName ( const std::string  path,
const std::string  name 
)
staticprotected

Generates a unique resource identifier from the resource's file path and name.

Parameters
path
name
Returns
resource identifier
std::string terminus::ResourceManager::entityName ( const std::string  path)
staticprotected

Generates a unique resource identifier from the resource's file path.

Parameters
path
Returns
resource identifier
std::shared_ptr< std::unique_ptr< Geometry > > terminus::ResourceManager::getGeometry ( std::string  name)
virtual
ResourceManager * terminus::ResourceManager::getInstance ( )
static

Returns the singelton instance of the ResourceManager class.

std::shared_ptr< std::unique_ptr< Material > > terminus::ResourceManager::getMaterial ( std::string  name)
virtual
std::shared_ptr< std::unique_ptr< Program > > terminus::ResourceManager::getProgram ( std::string  name)
virtual
void terminus::ResourceManager::loadMtl ( std::string  path)
protectedvirtual

Loads material data from .mtl files.

Parameters
pathAny number of materials encoded in one .mtl file are loaded and stored in the material container m_materialStorage.
void terminus::ResourceManager::loadObj ( std::string  path)
protectedvirtual

The .obj file specified by "path" will be parsed and stored in the geometry container m_geometryStorage.

Parameters
pathThe file is parsed line by line, storing data for vertex position (line begins with "v"), texture coordinates (line begins with "t"), normal vectors (line begins with "n") and geometry faces (line begins with "f"). A line starting with "o" specifies the object name. The corresponding BBox is generated while parsing the data.
void terminus::ResourceManager::loadObjGenerateAdd ( std::vector< QVector3D > &  positions,
std::vector< QVector3D > &  texCoords,
std::vector< QVector3D > &  normals,
std::vector< IndexTriple > &  indexTriples,
std::string  name 
)
protectedvirtual

This method is part of the loading mechanism for .obj files.

Parameters
positions
texCoords
normals
indexTriples
nameIndexTriples as specified in the .obj file are converted to a single index and a new Geometry instance is created and added to the geometry container "m_geometryStorage".
void terminus::ResourceManager::loadProgram ( std::string  path)
protectedvirtual

Vertex and fragment shader files are loaded an combined into on program instance from the Program class.

Parameters
path
void terminus::ResourceManager::loadResources ( )
virtual

All external resources the game might use are loaded here.

void terminus::ResourceManager::putGeometry ( std::string  name,
Geometry geometry 
)
protectedvirtual
void terminus::ResourceManager::putMaterial ( std::string  name,
Material material 
)
protectedvirtual
void terminus::ResourceManager::putProgram ( std::string  name,
Program program 
)
protectedvirtual

Member Data Documentation

std::map<std::string, std::shared_ptr<std::unique_ptr<Geometry> > > terminus::ResourceManager::m_geometryStorage
protected
ResourceManager * terminus::ResourceManager::m_instance = nullptr
staticprotected
std::map<std::string, std::shared_ptr<std::unique_ptr<Material> > > terminus::ResourceManager::m_materialStorage
protected
std::map<std::string, std::shared_ptr<std::unique_ptr<Program> > > terminus::ResourceManager::m_programStorage
protected

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