SuperTuxKart
material_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
4 // Copyright (C) 2010-2015 Steve Baker, Joerg Henrichs
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 3
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 #ifndef HEADER_MATERIAL_MANAGER_HPP
21 #define HEADER_MATERIAL_MANAGER_HPP
22 
23 #include "utils/no_copy.hpp"
24 
25 namespace irr
26 {
27  namespace video { class ITexture; }
28  namespace scene { class IMeshBuffer; class ISceneNode; }
29 }
30 using namespace irr;
31 
32 #include <irrlicht.h>
33 #include <string>
34 #include <vector>
35 #include <map>
36 
37 class Material;
38 class XMLReader;
39 class XMLNode;
40 
44 class MaterialManager : public NoCopy
45 {
46 private:
47 
48  void parseMaterialFile(const std::string& filename);
49  int m_shared_material_index;
50 
51  std::vector<Material*> m_materials;
52 
53  std::map<std::string, Material*> m_default_sp_materials;
54 
55 public:
57  ~MaterialManager();
58  void loadMaterial ();
59  Material* getMaterialFor(video::ITexture* t,
60  scene::IMeshBuffer *mb);
61  Material* getMaterialFor(video::ITexture* t,
62  video::E_MATERIAL_TYPE material_type);
63  Material* getMaterialFor(video::ITexture* t);
64  Material* getMaterialSPM(std::string lay_one_tex_lc,
65  std::string lay_two_tex_lc,
66  const std::string& def_shader_name = "solid");
67  void setAllMaterialFlags(video::ITexture* t,
68  scene::IMeshBuffer *mb);
69  void setAllUntexturedMaterialFlags(scene::IMeshBuffer *mb);
70 
71  int addEntity (Material *m);
72  Material *getMaterial (const std::string& t,
73  bool is_full_path=false,
74  bool make_permanent=false,
75  bool complain_if_not_found=true,
76  bool strip_path=true, bool install=true);
77  void addSharedMaterial(const std::string& filename, bool deprecated = false);
78  bool pushTempMaterial (const std::string& filename, bool deprecated = false);
79  bool pushTempMaterial (const XMLNode *root, const std::string& filename, bool deprecated = false);
80  void popTempMaterial ();
81  void makeMaterialsPermanent();
82  bool hasMaterial(const std::string& fname);
83 
84  void unloadAllTextures();
85 
86  Material* getDefaultSPMaterial(const std::string& shader_name,
87  const std::string& layer_one_lc = "",
88  bool full_path = false);
89  Material* getLatestMaterial() { return m_materials[m_materials.size()-1]; }
90 }; // MaterialManager
91 
92 extern MaterialManager *material_manager;
93 
94 #endif
95 
96 /* EOF */
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
Definition: material.hpp:46
utility class used to parse XML files
Definition: xml_node.hpp:47
Definition: material_manager.hpp:44