I use managers in my game designs, whatever I'm making, from a text adventure to a fullblown 3d engine, managers or container classes as bubba said are the best way to do things in my opinion..
Generic manager class:
Code:
#ifndef RESOURCE_MANAGER_H
#define RESOURCE_MANAGER_H
#pragma warning(disable: 4786)
#pragma warning(disable: 64)
#include <vector>
#include <map>
#include <string>
#include <boost\shared_ptr.hpp>
#include <boost\weak_ptr.hpp>
#include <iostream>
template< typename T_ >
class Resource_Manager
{
public:
typedef T_ value_type; // std library convention
typedef boost::shared_ptr<T_> Resource_Ptr;
typedef boost::weak_ptr<T_> Resource_Observer;
typedef std::map< std::string, Resource_Ptr > Resource_Map;
Resource_Manager<T_>() {};
~Resource_Manager<T_>() {};
void Add_Resource(const std::string & name, T_)
{
Resource_Ptr Raw_Resource(T_);
mResources.insert(std::make_pair(name, Raw_Resource));
}
Resource_Observer Request_Resource(const std::string & name)
{
Resource_Map::iterator it = mResources.find(name);
if (it == mResources.end())
{
std::cout << "Internal program error, " << name << " does not exist!" << std::endl;
}
else
{
return Resource_Observer(it->second);
}
}
void Request_Resource_Removal(const std::string & name)
{
Resource_Map::iterator it = mResources.find(name);
if (it != mResources.end())
{
mResources.erase(it);
}
}
private:
Resource_Map mResources;
};
#endif
I use a templated approach to my manager, it allows me to store and dynamically allocate memory for a set of like objects. It works on anything from sound files, to 3d models, to simple menu chains.
I like it :d