testsAndMisc/SFMLEngine/makingAGameTick/resources.hpp

29 lines
906 B
C++

#ifndef RESOURCES_HPP
#define RESOURCES_HPP
#include <assert.h>
// Mostly Chapter 2
// Handles resource management
namespace Textures // This gives us a scope for the enumerators which allows us to write Textures::Airplane instead of just Airplane to avoid name collisions in the global scope
{
enum ID { Landscape, Airplane, Missile };
}
template <typename Resource, typename Identifier>
class ResourceHolder
{
public:
void load(Identifier id, const std::string& filename);
Resource& get(Identifier id);
const Resource& get(Identifier id) const;
private:
std::map< Identifier, std::unique_ptr<Resource> > mResourceMap;
// unique_ptr are class templates that act like pointers, this allows us to work with heavyweight objects without copying them all the time, or we can store classes that are non-cpyable like sf::Shader
};
#include "resources.inl"
#endif // RESOURCES_HPP