Resource.h
Code:
#ifndef resource_h__
#define resource_h__
#include "hge_wrapper.h"
template<typename Type, typename LoadFncT, LoadFncT LoadFnc>
struct LoadFncCallHelper {};
template<typename Type, typename LoadFncT, LoadFncT LoadFnc, void (CALL HGE::* FreeFnc)(Type)>
class Resource
{
public:
Resource(hge_wrapper& hge, const char* strResource): m_hge(hge)
{
m_Resource = LoadFncCallHelper<Type, LoadFncT, LoadFnc>::Call(hge, strResource);
}
~Resource()
{
(m_hge.get()->*FreeFnc)(m_Resource);
}
Type& get() { return m_Resource; }
private:
void operator = (Resource&);
Resource(Resource&);
Type m_Resource;
hge_wrapper& m_hge;
};
#endif // resource_h__
Texture.h
Code:
#ifndef texture_h__
#define texture_h__
#include "resource.h"
typedef HEFFECT (CALL HGE::* TextureLoadFnc_ptr_t)(const char*, DWORD, bool);
template<TextureLoadFnc_ptr_t LoadFnc>
struct LoadFncCallHelper<HTEXTURE, TextureLoadFnc_ptr_t, LoadFnc>
{
static HEFFECT Call(hge_wrapper& hge, const char* strResource)
{
return (hge.get()->*LoadFnc)(strResource, 0, false);
}
};
class Texture: public Resource<HTEXTURE, TextureLoadFnc_ptr_t, &HGE::Texture_Load, &HGE::Texture_Free>
{
public:
Texture(hge_wrapper& hge, const char* strEffect): Resource(hge, strEffect) {}
};
#endif // texture_h__
The call
Code:
m_spr(m_tex->get(), tex_x, tex_y, tex_w, tex_h)
There you go, I'll just give it all, hope Elysia won't mind xP