Advertisement
MaGuSware2012

Haaf's Game Engine Texture Manager

Feb 26th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. //*
  2. // Class created by Chris Armitt for use with HGE
  3. //*
  4.  
  5. #pragma once
  6. #include <hge.h>
  7. #include <map>
  8. #include <string>
  9.  
  10. #define TEXTURE_FOLDER "../Data/Images/"
  11.  
  12. using namespace std;
  13.  
  14. class TextureManager
  15. {
  16. private:
  17.     HGE* m_pHge;
  18.     map<string, HTEXTURE> m_Textures;
  19.  
  20.     TextureManager()
  21.     {
  22.         m_pHge = hgeCreate(HGE_VERSION);
  23.     }
  24.  
  25.     ~TextureManager()
  26.     {
  27.         Flush();
  28.         m_pHge->Release();
  29.     }
  30.  
  31. public:
  32.     static TextureManager& GetInstance()
  33.     {
  34.         static TextureManager tm;
  35.         return tm;
  36.     }
  37.  
  38.     void Flush()
  39.     {
  40.         auto it = m_Textures.begin();
  41.         auto end = m_Textures.end();
  42.  
  43.         for (it; it != end; it++)
  44.         {
  45.             m_pHge->Texture_Free(it->second);
  46.         }
  47.         m_Textures.clear();
  48.     }
  49.  
  50.     HTEXTURE GetTexture(string texture)
  51.     {
  52.         //Attempt to return texture
  53. //-------------------------------------
  54.         auto it = m_Textures.find(texture);
  55.         auto end = m_Textures.end();
  56.  
  57.         if(it != end)
  58.             return it->second;
  59. //-------------------------------------
  60.  
  61.         //Load Texture and Store it
  62. //-------------------------------------
  63.         string filepath = TEXTURE_FOLDER;
  64.         filepath += texture;
  65.  
  66.         HTEXTURE tex = m_pHge->Texture_Load(filepath.c_str());
  67.         m_Textures.insert(make_pair(texture, tex));
  68. //-------------------------------------
  69.  
  70.         return tex;
  71.     }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement