Ignore:
Timestamp:
06/22/08 05:24:22 (16 years ago)
Author:
mattausch
Message:
 
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" 
    22#include "Matrix4x4.h" 
    33#include "Geometry.h" 
     
    55#include "Material.h" 
    66#include "Texture.h" 
    7 //#include "gzstream.h" 
     7#include "gzstream.h" 
    88 
    99 
     
    1515 
    1616 
    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) 
     17ResourceManager::~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 
     28SceneEntity *ResourceManager::LoadSceneEntity(igzstream &str) 
    4929{        
    5030        // shape 
     
    6949                trafo = new Matrix4x4(); 
    7050                str.read(reinterpret_cast<char *>(trafo->x), sizeof(Matrix4x4)); 
     51                mTrafos.push_back(trafo); 
    7152        } 
    7253 
     
    7758 
    7859 
    79 void BinaryLoader::LoadTextures(ifstream &str) 
     60void ResourceManager::LoadTextures(igzstream &str) 
    8061{ 
    8162        int numTextures; 
     
    9778 
    9879                mTextureTable[i] = tex; 
     80                mTextures.push_back(tex); 
    9981        } 
    10082 
     
    10385 
    10486 
    105 void BinaryLoader::LoadShapes(ifstream &str) 
     87void ResourceManager::LoadShapes(igzstream &str) 
    10688{ 
    10789        int numShapes; 
     
    11597                mGeometryTable[i] = geom; 
    11698                mMaterialTable[i] = mat; 
     99 
     100                mGeometry.push_back(geom); 
     101                mMaterials.push_back(mat); 
    117102        } 
    118103 
     
    121106 
    122107 
    123 //Appearance *BinaryLoader::LoadMaterial(igzstream &str) 
    124 Material *BinaryLoader::LoadMaterial(ifstream &str) 
     108Material *ResourceManager::LoadMaterial(igzstream &str) 
    125109{ 
    126110        // default material 
     
    145129                str.read(reinterpret_cast<char *>(&mat->mAmbientColor), sizeof(Vector3)); 
    146130                str.read(reinterpret_cast<char *>(&mat->mDiffuseColor), sizeof(Vector3)); 
     131                str.read(reinterpret_cast<char *>(&mat->mEmmisiveColor), sizeof(Vector3)); 
    147132                str.read(reinterpret_cast<char *>(&mat->mSpecularColor), sizeof(Vector3)); 
    148133        } 
     
    152137 
    153138 
    154 //Geometry *BinaryLoader::LoadGeometry(igzstream &str) 
    155 Geometry *BinaryLoader::LoadGeometry(ifstream &str) 
     139Geometry *ResourceManager::LoadGeometry(igzstream &str) 
    156140{ 
    157141        Vector3 *vertices; 
     
    183167        if (texCoordCount) 
    184168        { 
    185                 //cout << "loading texcoords of size " << texCoordCount << endl; 
    186169                texcoords = new float[texCoordCount * 2]; 
    187170                str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2); 
     
    194177 
    195178 
    196 void BinaryLoader::LoadSceneEntities(ifstream &str, SceneEntityContainer &entities) 
     179void ResourceManager::LoadSceneEntities(igzstream &str, SceneEntityContainer &entities) 
    197180{ 
    198181        int entityCount; 
     
    205188                SceneEntity *ent = LoadSceneEntity(str); 
    206189                entities[i] = ent; 
     190                mSceneEntities.push_back(ent); 
    207191        } 
    208192 
     
    211195 
    212196 
    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); 
     197bool ResourceManager::Load(const std::string &filename, SceneEntityContainer &entities) 
     198{ 
     199        igzstream istr(filename.c_str()); 
    219200         
    220201        if (!istr.is_open()) 
     
    236217        cout << "bin loading finished" << endl; 
    237218 
     219        // clean up 
     220        mTextureTable.clear(); 
     221        mGeometryTable.clear(); 
     222        mMaterialTable.clear(); 
     223 
    238224        return true; 
    239225} 
Note: See TracChangeset for help on using the changeset viewer.