# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

lod_character_shape_bank.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/lod_character_shape_bank.h"
00029 #include "3d/lod_character_shape.h"
00030 
00031 
00032 using namespace NLMISC;
00033 using namespace std;
00034 
00035 namespace NL3D 
00036 {
00037 
00038 
00039 
00040 // ***************************************************************************
00041 CLodCharacterShapeBank::CLodCharacterShapeBank()
00042 {
00043 }
00044 
00045 // ***************************************************************************
00046 void                                            CLodCharacterShapeBank::reset()
00047 {
00048         contReset(_ShapeArray);
00049         contReset(_ShapeMap);
00050 }
00051 
00052 // ***************************************************************************
00053 uint32                                          CLodCharacterShapeBank::addShape()
00054 {
00055         // Alloc a new shape
00056         _ShapeArray.resize(_ShapeArray.size()+1);
00057 
00058         return _ShapeArray.size()-1;
00059 }
00060 
00061 // ***************************************************************************
00062 sint32                                          CLodCharacterShapeBank::getShapeIdByName(const std::string &name) const
00063 {
00064         CstItStrIdMap   it= _ShapeMap.find(name);
00065         if(it==_ShapeMap.end())
00066                 return -1;
00067         else
00068                 return it->second;
00069 }
00070 
00071 // ***************************************************************************
00072 const CLodCharacterShape        *CLodCharacterShapeBank::getShape(uint32 shapeId) const
00073 {
00074         if(shapeId >= _ShapeArray.size())
00075                 return NULL;
00076         else
00077                 return &_ShapeArray[shapeId];
00078 }
00079 
00080 // ***************************************************************************
00081 CLodCharacterShape                      *CLodCharacterShapeBank::getShapeFullAcces(uint32 shapeId)
00082 {
00083         if(shapeId >= _ShapeArray.size())
00084                 return NULL;
00085         else
00086                 return &_ShapeArray[shapeId];
00087 }
00088 
00089 // ***************************************************************************
00090 bool                                            CLodCharacterShapeBank::compile()
00091 {
00092         bool    error= false;
00093 
00094         // clear the map
00095         contReset(_ShapeMap);
00096 
00097         // build the map
00098         for(uint i=0; i<_ShapeArray.size(); i++)
00099         {
00100                 const string &name= _ShapeArray[i].getName();
00101                 ItStrIdMap      it= _ShapeMap.find(name);
00102                 if(it == _ShapeMap.end())
00103                         _ShapeMap.insert(make_pair(name, i));
00104                 else
00105                 {
00106                         error= true;
00107                         nlwarning("Found a CLod with same name in the bank: %s", name.c_str());
00108                 }
00109         }
00110 
00111         return error;
00112 }
00113 
00114 // ***************************************************************************
00115 uint                                            CLodCharacterShapeBank::getNumShapes() const
00116 {
00117         return _ShapeArray.size();
00118 }
00119 
00120 // ***************************************************************************
00121 void                    CLodCharacterShapeBank::serial(NLMISC::IStream &f)
00122 {
00123         (void)f.serialVersion(0);
00124 
00125         f.serialCont(_ShapeArray);
00126         f.serialCont(_ShapeMap);
00127 }
00128 
00129 
00130 
00131 } // NL3D