Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TerrainTextureManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 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 <vector>
22 #include <map>
23 #include <boost/shared_ptr.hpp>
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;
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 
101 
103 
105 
106  // Find+load all textures in directory; check if
107  // there's an override XML with the same basename (if there is, load it)
108  void LoadTextures(const CTerrainPropertiesPtr& props, const VfsPath& path);
109 
110  // Load all terrains below path, using props as the parent property sheet.
111  void RecurseDirectory(const CTerrainPropertiesPtr& props, const VfsPath& path);
112 
114 
115 public:
116  // constructor, destructor
119 
120  // Find all XML's in the directory (with subdirs) and try to load them as
121  // terrain XML's
122  int LoadTerrainTextures();
123 
124  void UnloadTerrainTextures();
125 
126  CTerrainTextureEntry* FindTexture(const CStr& tag);
127 
128  // Create a texture object for a new terrain texture at path, using the
129  // property sheet props.
130  CTerrainTextureEntry *AddTexture(const CTerrainPropertiesPtr& props, const VfsPath& path);
131 
132  // Remove the texture from all our maps and lists and delete it afterwards.
133  void DeleteTexture(CTerrainTextureEntry* entry);
134 
135  // Find or create a new texture group. All terrain groups are owned by the
136  // texturemanager (TerrainTypeManager)
137  CTerrainGroup *FindGroup(const CStr& name);
138 
139  const TerrainGroupMap &GetGroups() const
140  { return m_TerrainGroups; }
141 };
142 
143 
144 #endif
struct TerrainAlpha::@16 m_AlphaMapCoords[NUM_ALPHA_MAPS]
shared_ptr< CTerrainProperties > CTerrainPropertiesPtr
std::vector< CTerrainTextureEntry * > m_Terrains
const std::vector< CTerrainTextureEntry * > & GetTerrains() const
const TerrainGroupMap & GetGroups() const
std::vector< CTerrainTextureEntry * > m_TextureEntries
void RecurseDirectory(const CTerrainPropertiesPtr &props, const VfsPath &path)
CTerrainTextureEntry * FindTexture(const CStr &tag)
#define NUM_ALPHA_MAPS
CTerrainGroup * FindGroup(const CStr &name)
Definition: path.h:75
i64 Handle
`handle&#39; representing a reference to a resource (sound, texture, etc.)
Definition: handle.h:41
std::map< VfsPath, TerrainAlpha > TerrainAlphaMap
void LoadTextures(const CTerrainPropertiesPtr &props, const VfsPath &path)
CTerrainPropertiesPtr GetPropertiesFromFile(const CTerrainPropertiesPtr &props, const VfsPath &pathname)
CStr GetName() const
void AddTerrain(CTerrainTextureEntry *)
CTerrainTextureEntry * AddTexture(const CTerrainPropertiesPtr &props, const VfsPath &path)
size_t GetIndex() const
void RemoveTerrain(CTerrainTextureEntry *)
std::map< CStr, CTerrainGroup * > TerrainGroupMap
void DeleteTexture(CTerrainTextureEntry *entry)
CTerrainGroup(CStr name, size_t index)