WorldSim  inDev
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
TextureManager.hpp
Go to the documentation of this file.
1 #pragma once
2 #ifndef WORLDSIM_TEXTURE_MANAGER_HPP
3 #define WORLDSIM_TEXTURE_MANAGER_HPP
4 
5 /* WorldSim: TextureManager.hpp
6  #include "TextureManager.hpp"
7 
8  Class to manage custom Texture objects. Note that these should not be linked during render because constant lookups
9  will be slow. Rather they should be linked during startup.
10 */
11 
12 #include <Graphics/Texture/Texture.hpp>
13 #include <Graphics/Texture/TextureLoader.hpp>
14 
15 #include <File/WTFManager.hpp> // loading raws
16 
18 {
19  public:
20 
21  Vector <Texture*> vTexture;
22  Vector <std::string> vTexName;
23  Texture* tex404; // use this if we can't find the texture we need.
24 
25  void add (Texture& texture)
26  {
27  }
28 
29  // Get texture for linking with object
30  Texture * get (std::string name)
31  {
32  return 0;
33  }
34 
35  void loadTextureVerbose(const std::string _path, Texture* _texture)
36  {
37  std::cout<<"Loading: "<<_path<<".\n";
38 
39  if(loadTextureNearestNeighbour(_path,_texture)==false)
40  { std::cout<<"Error loading "<<_path<<".\n"; }
41  }
42 
43  void loadRaw(std::string strRaw)
44  {
45  std::cout<<"Texture manager: Getting raw:\n"<<strRaw<<"\n";
46  WTFManager wtfManager;
47  std::cout<<"Parsing...\n";
48  wtfManager.parse(strRaw);
49  std::cout<<"End parsing\n";
50 
51  // get all texture paths and texture names
52  Vector <WTFNode*>* vNode = wtfManager.getAllSub("TEXTURE");
53 
54  if (vNode == 0)
55  {
56  std::cout<<"Error null ptr\n";
57  }
58  for (int i=0;i<vNode->size();++i)
59  {
60  // load texture
61  // store texture name
62  std::string texName = (*vNode)(i)->getValue("NAME");
63  std::string texPath = (*vNode)(i)->getValue("PATH");
64 
65  Texture * tex = new Texture();
66  loadTextureVerbose(texPath,tex);
67  vTexName.push(texName);
68  vTexture.push(tex);
69 
70 
71  std::cout<<"Loaded tex: "<<texName<<", "<<texPath<<"\n";
72  }
73  }
74 
75  Texture * getTextureByName(std::string _texName)
76  {
77  for (int i=0;i<vTexName.size();++i)
78  {
79  if (vTexName(i) == _texName)
80  {
81  if (vTexture.isSafe(i))
82  {
83  return vTexture(i);
84  }
85  }
86  }
87  return 0;
88  }
89 };
90 
91 #endif
Vector< Texture * > vTexture
Definition: TextureManager.hpp:21
Definition: TextureManager.hpp:17
Texture * tex404
Definition: TextureManager.hpp:23
Texture * getTextureByName(std::string _texName)
Definition: TextureManager.hpp:75
void loadTextureVerbose(const std::string _path, Texture *_texture)
Definition: TextureManager.hpp:35
void loadRaw(std::string strRaw)
Definition: TextureManager.hpp:43
void add(Texture &texture)
Definition: TextureManager.hpp:25
Vector< std::string > vTexName
Definition: TextureManager.hpp:22