aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp356
1 files changed, 178 insertions, 178 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp
index 5bcce19..cb2a941 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CMeshCache.cpp
@@ -1,178 +1,178 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CMeshCache.h" 5#include "CMeshCache.h"
6#include "IAnimatedMesh.h" 6#include "IAnimatedMesh.h"
7#include "IMesh.h" 7#include "IMesh.h"
8 8
9namespace irr 9namespace irr
10{ 10{
11namespace scene 11namespace scene
12{ 12{
13 13
14static const io::SNamedPath emptyNamedPath; 14static const io::SNamedPath emptyNamedPath;
15 15
16 16
17CMeshCache::~CMeshCache() 17CMeshCache::~CMeshCache()
18{ 18{
19 clear(); 19 clear();
20} 20}
21 21
22 22
23//! adds a mesh to the list 23//! adds a mesh to the list
24void CMeshCache::addMesh(const io::path& filename, IAnimatedMesh* mesh) 24void CMeshCache::addMesh(const io::path& filename, IAnimatedMesh* mesh)
25{ 25{
26 mesh->grab(); 26 mesh->grab();
27 27
28 MeshEntry e ( filename ); 28 MeshEntry e ( filename );
29 e.Mesh = mesh; 29 e.Mesh = mesh;
30 30
31 Meshes.push_back(e); 31 Meshes.push_back(e);
32} 32}
33 33
34 34
35//! Removes a mesh from the cache. 35//! Removes a mesh from the cache.
36void CMeshCache::removeMesh(const IMesh* const mesh) 36void CMeshCache::removeMesh(const IMesh* const mesh)
37{ 37{
38 if ( !mesh ) 38 if ( !mesh )
39 return; 39 return;
40 for (u32 i=0; i<Meshes.size(); ++i) 40 for (u32 i=0; i<Meshes.size(); ++i)
41 { 41 {
42 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) 42 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh))
43 { 43 {
44 Meshes[i].Mesh->drop(); 44 Meshes[i].Mesh->drop();
45 Meshes.erase(i); 45 Meshes.erase(i);
46 return; 46 return;
47 } 47 }
48 } 48 }
49} 49}
50 50
51 51
52//! Returns amount of loaded meshes 52//! Returns amount of loaded meshes
53u32 CMeshCache::getMeshCount() const 53u32 CMeshCache::getMeshCount() const
54{ 54{
55 return Meshes.size(); 55 return Meshes.size();
56} 56}
57 57
58 58
59//! Returns current number of the mesh 59//! Returns current number of the mesh
60s32 CMeshCache::getMeshIndex(const IMesh* const mesh) const 60s32 CMeshCache::getMeshIndex(const IMesh* const mesh) const
61{ 61{
62 for (u32 i=0; i<Meshes.size(); ++i) 62 for (u32 i=0; i<Meshes.size(); ++i)
63 { 63 {
64 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) 64 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh))
65 return (s32)i; 65 return (s32)i;
66 } 66 }
67 67
68 return -1; 68 return -1;
69} 69}
70 70
71 71
72//! Returns a mesh based on its index number 72//! Returns a mesh based on its index number
73IAnimatedMesh* CMeshCache::getMeshByIndex(u32 number) 73IAnimatedMesh* CMeshCache::getMeshByIndex(u32 number)
74{ 74{
75 if (number >= Meshes.size()) 75 if (number >= Meshes.size())
76 return 0; 76 return 0;
77 77
78 return Meshes[number].Mesh; 78 return Meshes[number].Mesh;
79} 79}
80 80
81 81
82//! Returns a mesh based on its name. 82//! Returns a mesh based on its name.
83IAnimatedMesh* CMeshCache::getMeshByName(const io::path& name) 83IAnimatedMesh* CMeshCache::getMeshByName(const io::path& name)
84{ 84{
85 MeshEntry e ( name ); 85 MeshEntry e ( name );
86 s32 id = Meshes.binary_search(e); 86 s32 id = Meshes.binary_search(e);
87 return (id != -1) ? Meshes[id].Mesh : 0; 87 return (id != -1) ? Meshes[id].Mesh : 0;
88} 88}
89 89
90 90
91//! Get the name of a loaded mesh, based on its index. 91//! Get the name of a loaded mesh, based on its index.
92const io::SNamedPath& CMeshCache::getMeshName(u32 index) const 92const io::SNamedPath& CMeshCache::getMeshName(u32 index) const
93{ 93{
94 if (index >= Meshes.size()) 94 if (index >= Meshes.size())
95 return emptyNamedPath; 95 return emptyNamedPath;
96 96
97 return Meshes[index].NamedPath; 97 return Meshes[index].NamedPath;
98} 98}
99 99
100 100
101//! Get the name of a loaded mesh, if there is any. 101//! Get the name of a loaded mesh, if there is any.
102const io::SNamedPath& CMeshCache::getMeshName(const IMesh* const mesh) const 102const io::SNamedPath& CMeshCache::getMeshName(const IMesh* const mesh) const
103{ 103{
104 if (!mesh) 104 if (!mesh)
105 return emptyNamedPath; 105 return emptyNamedPath;
106 106
107 for (u32 i=0; i<Meshes.size(); ++i) 107 for (u32 i=0; i<Meshes.size(); ++i)
108 { 108 {
109 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) 109 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh))
110 return Meshes[i].NamedPath; 110 return Meshes[i].NamedPath;
111 } 111 }
112 112
113 return emptyNamedPath; 113 return emptyNamedPath;
114} 114}
115 115
116//! Renames a loaded mesh. 116//! Renames a loaded mesh.
117bool CMeshCache::renameMesh(u32 index, const io::path& name) 117bool CMeshCache::renameMesh(u32 index, const io::path& name)
118{ 118{
119 if (index >= Meshes.size()) 119 if (index >= Meshes.size())
120 return false; 120 return false;
121 121
122 Meshes[index].NamedPath.setPath(name); 122 Meshes[index].NamedPath.setPath(name);
123 Meshes.sort(); 123 Meshes.sort();
124 return true; 124 return true;
125} 125}
126 126
127 127
128//! Renames a loaded mesh. 128//! Renames a loaded mesh.
129bool CMeshCache::renameMesh(const IMesh* const mesh, const io::path& name) 129bool CMeshCache::renameMesh(const IMesh* const mesh, const io::path& name)
130{ 130{
131 for (u32 i=0; i<Meshes.size(); ++i) 131 for (u32 i=0; i<Meshes.size(); ++i)
132 { 132 {
133 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh)) 133 if (Meshes[i].Mesh == mesh || (Meshes[i].Mesh && Meshes[i].Mesh->getMesh(0) == mesh))
134 { 134 {
135 Meshes[i].NamedPath.setPath(name); 135 Meshes[i].NamedPath.setPath(name);
136 Meshes.sort(); 136 Meshes.sort();
137 return true; 137 return true;
138 } 138 }
139 } 139 }
140 140
141 return false; 141 return false;
142} 142}
143 143
144 144
145//! returns if a mesh already was loaded 145//! returns if a mesh already was loaded
146bool CMeshCache::isMeshLoaded(const io::path& name) 146bool CMeshCache::isMeshLoaded(const io::path& name)
147{ 147{
148 return getMeshByName(name) != 0; 148 return getMeshByName(name) != 0;
149} 149}
150 150
151 151
152//! Clears the whole mesh cache, removing all meshes. 152//! Clears the whole mesh cache, removing all meshes.
153void CMeshCache::clear() 153void CMeshCache::clear()
154{ 154{
155 for (u32 i=0; i<Meshes.size(); ++i) 155 for (u32 i=0; i<Meshes.size(); ++i)
156 Meshes[i].Mesh->drop(); 156 Meshes[i].Mesh->drop();
157 157
158 Meshes.clear(); 158 Meshes.clear();
159} 159}
160 160
161//! Clears all meshes that are held in the mesh cache but not used anywhere else. 161//! Clears all meshes that are held in the mesh cache but not used anywhere else.
162void CMeshCache::clearUnusedMeshes() 162void CMeshCache::clearUnusedMeshes()
163{ 163{
164 for (u32 i=0; i<Meshes.size(); ++i) 164 for (u32 i=0; i<Meshes.size(); ++i)
165 { 165 {
166 if (Meshes[i].Mesh->getReferenceCount() == 1) 166 if (Meshes[i].Mesh->getReferenceCount() == 1)
167 { 167 {
168 Meshes[i].Mesh->drop(); 168 Meshes[i].Mesh->drop();
169 Meshes.erase(i); 169 Meshes.erase(i);
170 --i; 170 --i;
171 } 171 }
172 } 172 }
173} 173}
174 174
175 175
176} // end namespace scene 176} // end namespace scene
177} // end namespace irr 177} // end namespace irr
178 178