Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*
- // Class created by Chris Armitt for use with HGE
- //*
- #pragma once
- #include <hge.h>
- #include <map>
- #include <string>
- #define TEXTURE_FOLDER "../Data/Images/"
- using namespace std;
- class TextureManager
- {
- private:
- HGE* m_pHge;
- map<string, HTEXTURE> m_Textures;
- TextureManager()
- {
- m_pHge = hgeCreate(HGE_VERSION);
- }
- ~TextureManager()
- {
- Flush();
- m_pHge->Release();
- }
- public:
- static TextureManager& GetInstance()
- {
- static TextureManager tm;
- return tm;
- }
- void Flush()
- {
- auto it = m_Textures.begin();
- auto end = m_Textures.end();
- for (it; it != end; it++)
- {
- m_pHge->Texture_Free(it->second);
- }
- m_Textures.clear();
- }
- HTEXTURE GetTexture(string texture)
- {
- //Attempt to return texture
- //-------------------------------------
- auto it = m_Textures.find(texture);
- auto end = m_Textures.end();
- if(it != end)
- return it->second;
- //-------------------------------------
- //Load Texture and Store it
- //-------------------------------------
- string filepath = TEXTURE_FOLDER;
- filepath += texture;
- HTEXTURE tex = m_pHge->Texture_Load(filepath.c_str());
- m_Textures.insert(make_pair(texture, tex));
- //-------------------------------------
- return tex;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement