00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include "OSGStateChunk.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052
00053
00054
00055
00063
00064
00065
00066
00091 std::vector<std::string> *StateChunkClass::_classNames = NULL;
00092
00100 std::vector<UInt32> *StateChunkClass::_numslots = NULL;
00101
00106 StateChunkClass::StateChunkClass(Char8 *name, UInt32 numslots)
00107 {
00108 if(!_classNames)
00109 {
00110 _classNames = new std::vector<std::string>(0);
00111 _numslots = new std::vector< UInt32>(0);
00112 }
00113
00114 _classId = _classNames->size();
00115
00116 for(unsigned i = 0; i < numslots; i++)
00117 {
00118 _classNames->push_back(std::string(name));
00119 _numslots->push_back (numslots);
00120 }
00121 }
00122
00123 UInt32 StateChunkClass::getId(void) const
00124 {
00125 return _classId;
00126 }
00127
00128 const Char8 *StateChunkClass::getName(void) const
00129 {
00130 return(*_classNames)[_classId].c_str();
00131 }
00132
00133 Int32 StateChunkClass::getNumSlots(void) const
00134 {
00135 return(*_numslots)[_classId];
00136 }
00137
00141 const Char8 *StateChunkClass::getName(UInt32 index)
00142 {
00143 if(index >=(*_classNames).size())
00144 return "<Unknown StatChunkClass!>";
00145
00146 return(*_classNames)[index].c_str();
00147 }
00148
00152 Int32 StateChunkClass::getNumSlots(UInt32 index)
00153 {
00154 if(index >= (*_numslots).size())
00155 return -1;
00156
00157 return (*_numslots)[index];
00158 }
00159
00168 StateChunkClass::iterator StateChunkClass::begin(void)
00169 {
00170 return _classNames->begin();
00171 }
00172
00176 StateChunkClass::iterator StateChunkClass::end(void)
00177 {
00178 return _classNames->end();
00179 }
00180
00181 void StateChunkClass::swap(StateChunkClass &other)
00182 {
00183 FINFO(("Swap %s(%d|%d) %s(%d|%d)\n",
00184 this->getName(),
00185 this->getId(),
00186 this->getNumSlots(),
00187 other.getName(),
00188 other.getId(),
00189 other.getNumSlots()));
00190
00191 bool bNeighborSwap = false;
00192
00193 if(this->getNumSlots() != other.getNumSlots())
00194 {
00195 if( ( (this->getId() < other.getId() &&
00196 this->getId() + this->getNumSlots() != other.getId()) ||
00197 (other.getId() < this->getId() &&
00198 other.getId() + other.getNumSlots() != this->getId()) ) )
00199 {
00200 FWARNING(("Can only swap if #slots is equal or if"
00201 "the chunks are neighbors\n"));
00202 return;
00203 }
00204 else
00205 {
00206 bNeighborSwap = true;
00207 }
00208 }
00209
00210 std::string thisName = this->getName ();
00211 UInt32 thisNumSlots = this->getNumSlots();
00212
00213 std::string otherName = other.getName ();
00214 UInt32 otherNumSlots = other.getNumSlots();
00215
00216 if(bNeighborSwap == false)
00217 {
00218 UInt32 tmp;
00219
00220 tmp = this->_classId;
00221 this->_classId = other._classId;
00222 other._classId = tmp;
00223 }
00224 else
00225 {
00226 if(this->_classId < other._classId)
00227 {
00228 other._classId = this->_classId;
00229 this->_classId += otherNumSlots;
00230 }
00231 else
00232 {
00233 this->_classId = other._classId;
00234 other._classId += thisNumSlots;
00235 }
00236 }
00237
00238 for(UInt32 i = this->getId();
00239 i < this->getId() + thisNumSlots;
00240 ++i)
00241 {
00242 (*_classNames)[i] = thisName;
00243 (*_numslots )[i] = thisNumSlots;
00244 }
00245
00246 for(UInt32 i = other.getId();
00247 i < other.getId() + otherNumSlots;
00248 ++i)
00249 {
00250 (*_classNames)[i] = otherName;
00251 (*_numslots )[i] = otherNumSlots;
00252 }
00253 }
00254
00255
00256
00257
00258
00259 char StateChunk::cvsid[] = "@(#)$Id: $";
00260
00261
00262
00263
00264
00265 void StateChunk::initMethod(void)
00266 {
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 StateChunk::StateChunk(void) :
00281 Inherited()
00282 {
00283 }
00284
00285 StateChunk::StateChunk(const StateChunk &source) :
00286 Inherited(source)
00287 {
00288 }
00289
00290 StateChunk::~StateChunk(void)
00291 {
00292 }
00293
00294
00295
00296 void StateChunk::changed(BitVector, UInt32)
00297 {
00298 }
00299
00300
00301
00302 void StateChunk::dump( UInt32 OSG_CHECK_ARG(uiIndent),
00303 const BitVector OSG_CHECK_ARG(bvFlags )) const
00304 {
00305 SLOG << "Dump StateChunk NI" << std::endl;
00306 }
00307
00308
00309
00310
00311 void StateChunk::update(DrawActionBase *OSG_CHECK_ARG(action))
00312 {
00313 }
00314
00319 void StateChunk::activate(DrawActionBase *OSG_CHECK_ARG(action),
00320 UInt32 OSG_CHECK_ARG(index ))
00321 {
00322 FWARNING(("StateChunk::activate called!\n"));
00323 }
00324
00330 void StateChunk::changeFrom(DrawActionBase *action,
00331 StateChunk *old,
00332 UInt32 index)
00333 {
00334 old->deactivate(action, index);
00335 activate(action, index);
00336 }
00337
00342 void StateChunk::deactivate(DrawActionBase *OSG_CHECK_ARG(action),
00343 UInt32 OSG_CHECK_ARG(index))
00344 {
00345 FWARNING(("StateChunk::deactivate called!\n"));
00346 }
00347
00352 bool StateChunk::isTransparent(void) const
00353 {
00354 return false;
00355 }
00356
00357
00358
00359 const StateChunkClass *StateChunk::getClass(void) const
00360 {
00361 return NULL;
00362 }
00363
00364
00365
00370 Real32 StateChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00371 {
00372 return 0;
00373 }
00374
00375 bool StateChunk::operator <(const StateChunk &other) const
00376 {
00377 return this < &other;
00378 }
00379
00383 bool StateChunk::operator ==(const StateChunk &OSG_CHECK_ARG(other)) const
00384 {
00385 return false;
00386 }
00387
00388 bool StateChunk::operator !=(const StateChunk &other) const
00389 {
00390 return !(*this == other);
00391 }