Cafu Engine
ModelManagerT Class Reference

This class is used for managing model instances. More...

#include "ModelManager.hpp"

Public Member Functions

const CafuModelTGetModel (const std::string &FileName, std::string *ErrorMsg=NULL) const
 Returns (a pointer to) a model instance for the given filename. More...
 

Detailed Description

This class is used for managing model instances.

Without this class, when several users each create their own model instance from the same filename, the model is physically instantiated multiple times. Each instance consumes resources (such as the allocated memory), but is exactly identical to the others. However, once a model has been created, it is immutable (const), because all its variable state is extrinsic, i.e. seperately kept in AnimPoseT instances.

Therefore, very much as in the Flyweight pattern, model instances can be shared among users: It suffices to physically instantiate each model only once and to point users to that instance.

In summary, the purpose of this class is to share model instances among users in order to avoid resource duplication. It also calls the proper loaders according to the requested model filename, and gracefully handles errors by substituting a dummy model instead of propagating an exception.

Member Function Documentation

const CafuModelT * ModelManagerT::GetModel ( const std::string &  FileName,
std::string *  ErrorMsg = NULL 
) const

Returns (a pointer to) a model instance for the given filename.

The returned model instance is possibly shared with other users, and must not be deleted.

If there was an error loading the model, a "dummy model" instance is returned (no exception is thrown and the return value is a valid pointer to the dummy model). When this is the first attempt to load the model, an error message is returned as well; further requests to the same model will just return the dummy model but not the message.

Parameters
FileNameThe filename to load the model from.
ErrorMsgIs set to the error message if there was an error loading the model, or the empty string "" when the model was successfully loaded.

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