"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSModelLib/Src/ModelManager/LSDModelManager.h

00001 
00016 #ifndef __LSD_MODELMANAGER_H__
00017 #define __LSD_MODELMANAGER_H__
00018 
00019 #include "../LSDModelLib.h"
00020 #include "../Models/LSDDrawableSharedModel.h"
00021 #include "ResourceMan/LSTLResourceManCrtp.h"
00022 #include "String/LSTLString.h"
00023 
00024 namespace lsd {
00025 
00026         // == Types.
00030         typedef CSharedPtr<CSharedModel>                                CSharedModelPtr;
00031 
00035         typedef CSharedPtr<CDrawableSharedModel>                CDrawableSharedModelPtr;
00036 
00043         template <typename _tType>
00044         class CModelManager : public CResourceManCrtp<CModelManager<_tType>, CString, _tType> {
00045         public :
00046                 // == Various constructors.
00047                 LSE_CALLCTOR                                                            CModelManager() {
00048                 }
00049                 LSE_CALLCTOR                                                            ~CModelManager() {
00050                 }
00051 
00052 
00053                 // == Functions.
00062                 _tType LSE_CALL                                                         GetRes( const CString &_sPath ) {
00063                         LSCHAR szBuffer[LSF_MAX_PATH];
00064                         CFileLib::ExpandResourcePath( _sPath.CStr(), szBuffer );
00065                         return Parent::GetRes( szBuffer );
00066                 }
00067 
00068 
00069         protected :
00070                 // == Members.
00071 
00072 
00073                 // == Functions.
00081                 _tType LSE_CALL                                                         AddRes( const CString &_sPath ) {
00082                         _tType dsmpRet;
00083 #ifdef _DEBUG
00084 #define LSD_ERROR( TEXT )               CStd::DebugPrintA( "CModelManager::AddModel():" TEXT "\r\n" )
00085 #else
00086 #define LSD_ERROR( TEXT )
00087 #endif  // #ifdef _DEBUG
00088                         
00089 
00090                         if ( !CFileLib::Exists( _sPath.CStr() ) ) {
00091                                 LSUTFX uBuffer[LSF_MAX_PATH];
00092                                 CStd::Utf8ToUtfX( uBuffer, reinterpret_cast<const LSUTF8 *>(_sPath.CStr()), LSF_MAX_PATH );
00093                                 CStd::DebugPrintA( "CModelManager::AddModel(): File \"" );
00094                                 CStd::DebugPrintW( uBuffer );
00095                                 CStd::DebugPrintA( "\" does not exist.\r\n" );
00096                                 return dsmpRet;
00097                         }
00098 
00099                         if ( !dsmpRet.New() ) {
00100                                 LSD_ERROR( "Not enough memory to create a model." );
00101                                 return dsmpRet;
00102                         }
00103                         
00104                         LSSTD_ERRORS eError = dsmpRet->LoadFromFile( _sPath.CStr() );
00105                         CStd::PrintError( eError );
00106                         if ( eError != LSSTD_E_SUCCESS ) {
00107                                 dsmpRet.Reset();
00108                                 return dsmpRet;
00109                         }
00110 
00111                         if ( !Parent::m_mList.Insert( _sPath.CStr(), dsmpRet ) ) {
00112                                 LSD_ERROR( "Not enough memory to store the created model." );
00113                                 dsmpRet.Reset();
00114                                 return dsmpRet;
00115                         }
00116 
00117                         return dsmpRet;
00118 #undef LSD_ERROR
00119                 }
00120 
00121 
00122         private :
00123                 typedef CResourceManCrtp<CModelManager, CString, _tType>
00124                                                                                                         Parent;
00125                 friend class                                                            CResourceManCrtp<CModelManager, CString, _tType>;
00126         };
00127 
00128 
00129         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00130         // DEFINITIONS
00131         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00132         
00133 
00134 }       // namespace lsd
00135 
00136 #endif  // __LSD_MODELMANAGER_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator