Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / lod_character_shape_bank.cpp
blobf8fdd1a22e066c38f1de08a8c2f122c33a7177ea
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
19 #include "nel/3d/lod_character_shape_bank.h"
20 #include "nel/3d/lod_character_shape.h"
23 using namespace NLMISC;
24 using namespace std;
26 #ifdef DEBUG_NEW
27 #define new DEBUG_NEW
28 #endif
30 namespace NL3D
35 // ***************************************************************************
36 CLodCharacterShapeBank::CLodCharacterShapeBank()
40 // ***************************************************************************
41 void CLodCharacterShapeBank::reset()
43 contReset(_ShapeArray);
44 contReset(_ShapeMap);
47 // ***************************************************************************
48 uint32 CLodCharacterShapeBank::addShape()
50 // Alloc a new shape
51 _ShapeArray.resize(_ShapeArray.size()+1);
53 return (uint32)_ShapeArray.size()-1;
56 // ***************************************************************************
57 sint32 CLodCharacterShapeBank::getShapeIdByName(const std::string &name) const
59 CstItStrIdMap it= _ShapeMap.find(name);
60 if(it==_ShapeMap.end())
61 return -1;
62 else
63 return it->second;
66 // ***************************************************************************
67 const CLodCharacterShape *CLodCharacterShapeBank::getShape(uint32 shapeId) const
69 if(shapeId >= _ShapeArray.size())
70 return NULL;
71 else
72 return &_ShapeArray[shapeId];
75 // ***************************************************************************
76 CLodCharacterShape *CLodCharacterShapeBank::getShapeFullAcces(uint32 shapeId)
78 if(shapeId >= _ShapeArray.size())
79 return NULL;
80 else
81 return &_ShapeArray[shapeId];
84 // ***************************************************************************
85 bool CLodCharacterShapeBank::compile()
87 bool error= false;
89 // clear the map
90 contReset(_ShapeMap);
92 // build the map
93 for(uint i=0; i<_ShapeArray.size(); i++)
95 const string &name= _ShapeArray[i].getName();
96 ItStrIdMap it= _ShapeMap.find(name);
97 if(it == _ShapeMap.end())
98 _ShapeMap.insert(make_pair(name, i));
99 else
101 error= true;
102 nlwarning("Found a CLod with same name in the bank: %s", name.c_str());
106 return error;
109 // ***************************************************************************
110 uint CLodCharacterShapeBank::getNumShapes() const
112 return (uint)_ShapeArray.size();
115 // ***************************************************************************
116 void CLodCharacterShapeBank::serial(NLMISC::IStream &f)
118 (void)f.serialVersion(0);
120 f.serialCont(_ShapeArray);
121 f.serialCont(_ShapeMap);
126 } // NL3D