Pyrogenesis  trunk
TerrainTextureManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_TERRAINTEXTUREMANAGER
19 #define INCLUDED_TERRAINTEXTUREMANAGER
20 
21 #include <map>
22 #include <memory>
23 #include <vector>
24 
26 #include "lib/res/handle.h"
27 #include "lib/file/vfs/vfs_path.h"
28 #include "ps/CStr.h"
29 #include "ps/Singleton.h"
30 
31 // access to sole CTerrainTextureManager object
32 #define g_TexMan CTerrainTextureManager::GetSingleton()
33 
34 #define NUM_ALPHA_MAPS 14
35 
36 class XMBElement;
37 class CXeromyces;
40 
41 typedef shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
42 
44 {
45  // name of this terrain group (as specified by the terrain XML)
46  CStr m_Name;
47  // "index".. basically a bogus integer that can be used by ScEd to set texture
48  // priorities
49  size_t m_Index;
50  // list of textures of this type (found from the texture directory)
51  std::vector<CTerrainTextureEntry*> m_Terrains;
52 
53 public:
54  CTerrainGroup(CStr name, size_t index):
55  m_Name(name),
56  m_Index(index)
57  {}
58 
59  // Add a texture entry to this terrain type
61  // Remove a texture entry
63 
64  size_t GetIndex() const
65  { return m_Index; }
66  CStr GetName() const
67  { return m_Name; }
68 
69  const std::vector<CTerrainTextureEntry*> &GetTerrains() const
70  { return m_Terrains; }
71 };
72 
73 
75 {
76  // ogl_tex handle of composite alpha map (all the alpha maps packed into one texture)
78  // coordinates of each (untransformed) alpha map within the packed texture
79  struct {
80  float u0,u1,v0,v1;
81  } m_AlphaMapCoords[NUM_ALPHA_MAPS];
82 };
83 
84 
85 ///////////////////////////////////////////////////////////////////////////////////////////
86 // CTerrainTextureManager : manager class for all terrain texture objects
87 class CTerrainTextureManager : public Singleton<CTerrainTextureManager>
88 {
89  friend class CTerrainTextureEntry;
90 
91 public:
92  typedef std::map<CStr, CTerrainGroup*> TerrainGroupMap;
93  typedef std::map<VfsPath, TerrainAlpha> TerrainAlphaMap;
94 
95 private:
96  // All texture entries created by this class, for easy freeing now that
97  // textures may be in several STextureType's
98  std::vector<CTerrainTextureEntry*> m_TextureEntries;
99 
100  TerrainGroupMap m_TerrainGroups;
101 
102  TerrainAlphaMap m_TerrainAlphas;
103 
105 
106 public:
107  // constructor, destructor
110 
111  // Find all XML's in the directory (with subdirs) and try to load them as
112  // terrain XML's
113  int LoadTerrainTextures();
114 
115  void UnloadTerrainTextures();
116 
117  CTerrainTextureEntry* FindTexture(const CStr& tag) const;
118 
119  // Create a texture object for a new terrain texture at path, using the
120  // property sheet props.
121  CTerrainTextureEntry* AddTexture(const CTerrainPropertiesPtr& props, const VfsPath& path);
122 
123  // Remove the texture from all our maps and lists and delete it afterwards.
124  void DeleteTexture(CTerrainTextureEntry* entry);
125 
126  // Find or create a new texture group. All terrain groups are owned by the
127  // texturemanager (TerrainTypeManager)
128  CTerrainGroup* FindGroup(const CStr& name);
129 
130  const TerrainGroupMap& GetGroups() const
131  { return m_TerrainGroups; }
132 };
133 
134 
135 #endif
TerrainAlphaMap m_TerrainAlphas
Definition: TerrainTextureManager.h:102
shared_ptr< CTerrainProperties > CTerrainPropertiesPtr
Definition: TerrainProperties.h:38
CStr m_Name
Definition: TerrainTextureManager.h:46
std::vector< CTerrainTextureEntry * > m_Terrains
Definition: TerrainTextureManager.h:51
size_t m_Index
Definition: TerrainTextureManager.h:49
const std::vector< CTerrainTextureEntry * > & GetTerrains() const
Definition: TerrainTextureManager.h:69
const TerrainGroupMap & GetGroups() const
Definition: TerrainTextureManager.h:130
shared_ptr< CTerrainProperties > CTerrainPropertiesPtr
Definition: TerrainTextureManager.h:39
Definition: XeroXMB.h:160
Definition: TerrainTextureEntry.h:38
std::map< CStr, CTerrainGroup * > TerrainGroupMap
Definition: TerrainTextureManager.h:92
#define NUM_ALPHA_MAPS
Definition: TerrainTextureManager.h:34
TerrainGroupMap m_TerrainGroups
Definition: TerrainTextureManager.h:100
Definition: TerrainTextureManager.h:74
Definition: path.h:77
Definition: TerrainProperties.h:42
i64 Handle
`handle&#39; representing a reference to a resource (sound, texture, etc.)
Definition: handle.h:41
size_t m_LastGroupIndex
Definition: TerrainTextureManager.h:104
std::map< VfsPath, TerrainAlpha > TerrainAlphaMap
Definition: TerrainTextureManager.h:93
Definition: Xeromyces.h:42
float v1
Definition: TerrainTextureManager.h:80
Definition: TerrainTextureManager.h:87
CStr GetName() const
Definition: TerrainTextureManager.h:66
void AddTerrain(CTerrainTextureEntry *)
Definition: TerrainTextureManager.cpp:144
size_t GetIndex() const
Definition: TerrainTextureManager.h:64
void RemoveTerrain(CTerrainTextureEntry *)
Definition: TerrainTextureManager.cpp:149
std::vector< CTerrainTextureEntry * > m_TextureEntries
Definition: TerrainTextureManager.h:98
Definition: Singleton.h:34
Definition: TerrainTextureManager.h:43
Handle m_hCompositeAlphaMap
Definition: TerrainTextureManager.h:77
CTerrainGroup(CStr name, size_t index)
Definition: TerrainTextureManager.h:54