- Timestamp:
- 06/22/08 05:24:22 (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r2793 r2795 1 #include " BinaryLoader.h"1 #include "ResourceManager.h" 2 2 #include "Matrix4x4.h" 3 3 #include "Geometry.h" … … 5 5 #include "Material.h" 6 6 #include "Texture.h" 7 //#include "gzstream.h"7 #include "gzstream.h" 8 8 9 9 … … 15 15 16 16 17 BinaryLoader::~BinaryLoader() 18 { 19 /** delete all maps. 20 */ 21 std::map<int, Texture *>::iterator it, it_end = mTextureTable.end(); 22 23 for (it = mTextureTable.begin(); it != it_end; ++ it) 24 { 25 Texture *tex = (*it).second; 26 delete tex; 27 } 28 29 std::map<int, Material *>::iterator nit, nit_end = mMaterialTable.end(); 30 31 for (nit = mMaterialTable.begin(); nit != nit_end; ++ nit) 32 { 33 Material *mat = (*nit).second; 34 delete mat; 35 } 36 37 38 std::map<int, Geometry *>::iterator git, git_end = mGeometryTable.end(); 39 40 for (git = mGeometryTable.begin(); git != git_end; ++git) 41 { 42 Geometry *geom = (*git).second; 43 delete geom; 44 } 45 } 46 47 //SceneEntity *BinaryLoader::LoadSceneEntity(igzstream &str) 48 SceneEntity *BinaryLoader::LoadSceneEntity(ifstream &str) 17 ResourceManager::~ResourceManager() 18 { 19 // delete all resources. 20 CLEAR_CONTAINER(mSceneEntities); 21 CLEAR_CONTAINER(mGeometry); 22 CLEAR_CONTAINER(mMaterials); 23 CLEAR_CONTAINER(mTextures); 24 CLEAR_CONTAINER(mTrafos); 25 } 26 27 28 SceneEntity *ResourceManager::LoadSceneEntity(igzstream &str) 49 29 { 50 30 // shape … … 69 49 trafo = new Matrix4x4(); 70 50 str.read(reinterpret_cast<char *>(trafo->x), sizeof(Matrix4x4)); 51 mTrafos.push_back(trafo); 71 52 } 72 53 … … 77 58 78 59 79 void BinaryLoader::LoadTextures(ifstream &str)60 void ResourceManager::LoadTextures(igzstream &str) 80 61 { 81 62 int numTextures; … … 97 78 98 79 mTextureTable[i] = tex; 80 mTextures.push_back(tex); 99 81 } 100 82 … … 103 85 104 86 105 void BinaryLoader::LoadShapes(ifstream &str)87 void ResourceManager::LoadShapes(igzstream &str) 106 88 { 107 89 int numShapes; … … 115 97 mGeometryTable[i] = geom; 116 98 mMaterialTable[i] = mat; 99 100 mGeometry.push_back(geom); 101 mMaterials.push_back(mat); 117 102 } 118 103 … … 121 106 122 107 123 //Appearance *BinaryLoader::LoadMaterial(igzstream &str) 124 Material *BinaryLoader::LoadMaterial(ifstream &str) 108 Material *ResourceManager::LoadMaterial(igzstream &str) 125 109 { 126 110 // default material … … 145 129 str.read(reinterpret_cast<char *>(&mat->mAmbientColor), sizeof(Vector3)); 146 130 str.read(reinterpret_cast<char *>(&mat->mDiffuseColor), sizeof(Vector3)); 131 str.read(reinterpret_cast<char *>(&mat->mEmmisiveColor), sizeof(Vector3)); 147 132 str.read(reinterpret_cast<char *>(&mat->mSpecularColor), sizeof(Vector3)); 148 133 } … … 152 137 153 138 154 //Geometry *BinaryLoader::LoadGeometry(igzstream &str) 155 Geometry *BinaryLoader::LoadGeometry(ifstream &str) 139 Geometry *ResourceManager::LoadGeometry(igzstream &str) 156 140 { 157 141 Vector3 *vertices; … … 183 167 if (texCoordCount) 184 168 { 185 //cout << "loading texcoords of size " << texCoordCount << endl;186 169 texcoords = new float[texCoordCount * 2]; 187 170 str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2); … … 194 177 195 178 196 void BinaryLoader::LoadSceneEntities(ifstream &str, SceneEntityContainer &entities)179 void ResourceManager::LoadSceneEntities(igzstream &str, SceneEntityContainer &entities) 197 180 { 198 181 int entityCount; … … 205 188 SceneEntity *ent = LoadSceneEntity(str); 206 189 entities[i] = ent; 190 mSceneEntities.push_back(ent); 207 191 } 208 192 … … 211 195 212 196 213 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &entities) 214 { 215 //clear_textures(); // clear the texture table 216 217 //igzstream str(filename.c_str());//, ios::binary); 218 ifstream istr(filename.c_str(), ios::binary); 197 bool ResourceManager::Load(const std::string &filename, SceneEntityContainer &entities) 198 { 199 igzstream istr(filename.c_str()); 219 200 220 201 if (!istr.is_open()) … … 236 217 cout << "bin loading finished" << endl; 237 218 219 // clean up 220 mTextureTable.clear(); 221 mGeometryTable.clear(); 222 mMaterialTable.clear(); 223 238 224 return true; 239 225 }
Note: See TracChangeset
for help on using the changeset viewer.