xoreos  0.0.5
meshman.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 #include "src/common/util.h"
27 
32 
34 
35 namespace Graphics {
36 
37 namespace Mesh {
38 
40 }
41 
43  deinit();
44 }
45 
47  status("Initialising default mesh containers...");
48 
49  MeshWireBox *wirebox = new MeshWireBox();
50  wirebox->init();
51  wirebox->setName("defaultWireBox");
52  _resourceMap[wirebox->getName()] = wirebox;
53 
54  MeshFont *meshFont = new MeshFont();
55  meshFont->init();
56  meshFont->setName("defaultMeshFont");
57  _resourceMap[meshFont->getName()] = meshFont;
58 
59  MeshQuad *meshQuad = new MeshQuad();
60  meshQuad->init();
61  meshQuad->setName("defaultMeshQuad");
62  _resourceMap[meshQuad->getName()] = meshQuad;
63 }
64 
66  for (std::map<Common::UString, Mesh *>::iterator iter = _resourceMap.begin(); iter != _resourceMap.end(); ++iter) {
67  delete iter->second;
68  }
69  _resourceMap.clear();
70 }
71 
73  std::map<Common::UString, Mesh *>::iterator iter = _resourceMap.begin();
74  while (iter != _resourceMap.end()) {
75  Mesh *mesh = iter->second;
76  if (mesh->useCount() == 0) {
77  iter = delResource(iter);
78  } else {
79  iter++;
80  }
81  }
82 }
83 
85  if (!mesh) {
86  return;
87  }
88 
89  std::map<Common::UString, Mesh *>::iterator iter = _resourceMap.find(mesh->getName());
90  if (iter == _resourceMap.end()) {
91  _resourceMap[mesh->getName()] = mesh;
92  }
93 }
94 
96  if (!mesh) {
97  return;
98  }
99 
100  std::map<Common::UString, Mesh *>::iterator iter = _resourceMap.find(mesh->getName());
101  if (iter != _resourceMap.end()) {
102  delResource(iter);
103  }
104 }
105 
107  std::map<Common::UString, Mesh *>::iterator iter = _resourceMap.find(name);
108  if (iter != _resourceMap.end()) {
109  return iter->second;
110  } else {
111  return 0;
112  }
113 }
114 
115 std::map<Common::UString, Mesh *>::iterator MeshManager::delResource(std::map<Common::UString, Mesh *>::iterator iter) {
116  std::map<Common::UString, Mesh *>::iterator inext = iter;
117  inext++;
118  delete iter->second;
119  _resourceMap.erase(iter);
120 
121  return inext;
122 }
123 
124 } // End of namespace Mesh
125 
126 } // End of namespace Graphics
Default quad mesh.
Wireframe box mesh.
A class holding an UTF-8 string.
Definition: ustring.h:48
const Common::UString & getName() const
Definition: mesh.cpp:51
Dedicated mesh used for dynamic font rendering.
void init()
General mesh initialisation, queuing the mesh for GL resource creation.
Definition: mesh.cpp:71
Mesh * getMesh(const Common::UString &name)
Returns a mesh with the given name, or zero if it does not exist.
Definition: meshman.cpp:106
void delMesh(Mesh *mesh)
Forcibly remove the mesh from the map.
Definition: meshman.cpp:95
Utility templates and functions.
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
Definition: singleton.h:122
std::map< Common::UString, Mesh * >::iterator delResource(std::map< Common::UString, Mesh *>::iterator iter)
Definition: meshman.cpp:115
The global mesh manager.
The mesh manager.
Definition: meshman.h:41
void cleanup()
Remove any resource that has a usage count of zero.
Definition: meshman.cpp:72
std::map< Common::UString, Mesh * > _resourceMap
Definition: meshman.h:64
void status(const char *s,...)
Definition: util.cpp:52
void deinit()
Deinitialise mesh management subsystem.
Definition: meshman.cpp:65
void setName(const Common::UString &name)
Definition: mesh.cpp:47
void addMesh(Mesh *mesh)
Adds a mesh to be managed.
Definition: meshman.cpp:84
void init()
Initialise mesh management, including default mesh creation.
Definition: meshman.cpp:46