More updatage
Resource_Manager.h
Code:
#include <vector>
#include "MS3D.H"
#include <map>
class Resource_Cache
{
public:
struct MS3DModelRenderData
{
float Position[3]; // will be changed to vectors eventually
float Orientation[3];
MS3DModel *pModel;
};
std::vector<MS3DModelRenderData*> MS3DModels; // holds pointers to all MS3D Models
private:
bool Add_MS3DModel_To_Cache(const char *filename); // loads a milkshape model to the cache
};
template < typename resource_t >
class Resource_Manager
{
std::map< std::string , resource_t* > Resources;
public:
resource_t& Load( const std::string & filename )
{
std::map< std::string , resource_t* >::iterator entry = Resources.find( filename );
if ( entry != resources.end() ) // if the entry is found
{
return * entry->second; // return the reference to the resource
}
else
{
resource_t* resource( new resource_t( filename ) );
// first we gotta load the resource, then we can make a pair
// and return the reference
resources.insert( std::make_pair( filename , resource ) );
return * resource;
}
}
virtual ~Resource_Manager( void )
{
std::map< std::string , resource_t * >::iterator destroyer, end;
for ( destroyer = resources.begin() , end = resources.end() ; destroyer != end ; ++destroyer )
{
delete destroyer->first;
delete destroyer->second;
}
}
};
Resource_Manager.cpp
Code:
#include "Resource_Manager.h"
#include <windows.h>
bool Resource_Cache::Add_MS3DModel_To_Cache(const char *filename)
{
MS3DModelRenderData *Model;
Model = new MS3DModelRenderData;
Model->pModel = new MS3DModel;
if ( Model->pModel->Load_MS3D_Model( filename ) == false )
{
MessageBox( NULL, "Couldn't load the model data.", "Error", MB_OK | MB_ICONERROR );
return 0; // If Model Didn't Load, Quit
}
MS3DModels.push_back(Model);
return 1;
}
TODO:
Add file extension recognition to choose right loader function.
Make it so the actual load functions return a reference to the manager so that he can make a pair out of the resource filename and the reference.
Make it so no matter what another reference gets pushed back into the list of things to draw if a load request is sent.. We can't just do nothing if there is a file already loaded!
That is all I can think of right now! Working!