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 #include "OSGExtendActorBase.h"
00040 #include "OSGBasicActorBase.h"
00041
00042 OSG_BEGIN_NAMESPACE
00043
00044
00045
00046
00047
00051 inline DepthFirstStateAction::ResultE
00052 DepthFirstStateAction::enterNode(const NodePtr &pNode, UInt32 pass)
00053 {
00054 FunctorArgumentType funcArg(NULL, pNode, pass);
00055 ResultE result = NewActionTypes::Continue;
00056
00057 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00058 ExtendActorStoreIt endExtend = _extendEnterActors.end ();
00059
00060 for(; (itExtend != endExtend ) &&
00061 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00062 ++itExtend )
00063 {
00064 funcArg.setActor(*itExtend);
00065
00066 result = static_cast<ResultE>(result | (*itExtend)->enterNode(funcArg));
00067 }
00068
00069 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00070 BasicActorStoreIt endBasic = _basicEnterActors.end ();
00071
00072 for(; (itBasic != endBasic ) &&
00073 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00074 ++itBasic )
00075 {
00076 funcArg.setActor(*itBasic);
00077
00078 result = static_cast<ResultE>(result | (*itBasic)->enterNode(funcArg));
00079 }
00080
00081 return result;
00082 }
00083
00087 inline DepthFirstStateAction::ResultE
00088 DepthFirstStateAction::leaveNode(const NodePtr &pNode, UInt32 pass)
00089 {
00090 FunctorArgumentType funcArg(NULL, pNode, pass);
00091 ResultE result = NewActionTypes::Continue;
00092
00093 ExtendActorStoreIt itExtend = _extendLeaveActors.begin();
00094 ExtendActorStoreIt endExtend = _extendLeaveActors.end ();
00095
00096 for(; (itExtend != endExtend ) &&
00097 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00098 ++itExtend )
00099 {
00100 funcArg.setActor(*itExtend);
00101
00102 result = static_cast<ResultE>(result | (*itExtend)->leaveNode(funcArg));
00103 }
00104
00105 BasicActorStoreIt itBasic = _basicLeaveActors.begin();
00106 BasicActorStoreIt endBasic = _basicLeaveActors.end ();
00107
00108 for(; (itBasic != endBasic ) &&
00109 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00110 ++itBasic )
00111 {
00112 funcArg.setActor(*itBasic);
00113
00114 result = static_cast<ResultE>(result | (*itBasic)->leaveNode(funcArg));
00115 }
00116
00117 return result;
00118 }
00119
00120
00121
00122
00123
00124 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00125
00134 inline
00135 DepthFirstStateAction::StateRefCount::StateRefCount(const StateRefCount &source)
00136 : _stateSlot(source._stateSlot),
00137 _refCount (source._refCount )
00138 {
00139 }
00140
00148 inline
00149 DepthFirstStateAction::StateRefCount::StateRefCount(UInt32 stateSlot)
00150 : _stateSlot(stateSlot),
00151 _refCount (0 )
00152 {
00153 }
00154
00158 inline
00159 DepthFirstStateAction::StateRefCount::StateRefCount
00160 (UInt32 stateSlot, Int32 refCount)
00161
00162 : _stateSlot(stateSlot),
00163 _refCount (refCount )
00164 {
00165 }
00166
00170 inline UInt32
00171 DepthFirstStateAction::StateRefCount::getStateSlot(void) const
00172 {
00173 return _stateSlot;
00174 }
00175
00176
00177
00178
00179 inline void
00180 DepthFirstStateAction::StateRefCount::setStateSlot(UInt32 stateSlot)
00181 {
00182 _stateSlot = stateSlot;
00183 }
00184
00188 inline Int32
00189 DepthFirstStateAction::StateRefCount::getRefCount(void) const
00190 {
00191 return _refCount;
00192 }
00193
00197 inline void
00198 DepthFirstStateAction::StateRefCount::incRefCount(Int32 inc)
00199 {
00200 _refCount += inc;
00201 }
00202
00206 inline void
00207 DepthFirstStateAction::StateRefCount::decRefCount(Int32 dec)
00208 {
00209 _refCount -= inc;
00210 }
00211
00212 #else
00213
00222 inline
00223 DepthFirstStateAction::StateRefCount::StateRefCount(const StateRefCount &source)
00224 : _itState (source._itState ),
00225 _refCount(source._refCount)
00226 {
00227 }
00228
00236 inline
00237 DepthFirstStateAction::StateRefCount::StateRefCount(const StateStoreIt &itState)
00238 : _itState (itState),
00239 _refCount(0 )
00240 {
00241 }
00242
00246 inline
00247 DepthFirstStateAction::StateRefCount::StateRefCount(
00248 const StateStoreIt &itState, Int32 refCount)
00249
00250 : _itState (itState ),
00251 _refCount(refCount)
00252 {
00253 }
00254
00258 inline DepthFirstStateAction::StateStoreIt
00259 DepthFirstStateAction::StateRefCount::getState(void) const
00260 {
00261 return _itState;
00262 }
00263
00267 inline void
00268 DepthFirstStateAction::StateRefCount::setState(const StateStoreIt &itState)
00269 {
00270 _itState = itState;
00271 }
00272
00276 inline Int32
00277 DepthFirstStateAction::StateRefCount::getRefCount(void) const
00278 {
00279 return _refCount;
00280 }
00281
00285 inline void
00286 DepthFirstStateAction::StateRefCount::incRefCount(Int32 inc)
00287 {
00288 _refCount += inc;
00289 }
00290
00294 inline void
00295 DepthFirstStateAction::StateRefCount::decRefCount(Int32 dec)
00296 {
00297 _refCount -= dec;
00298 }
00299
00300 #endif
00301
00302 inline
00303 DepthFirstStateAction::NodeStackEntry::NodeStackEntry(void)
00304
00305 : _pNode (NullFC),
00306 _itStateRefCount( ),
00307 _passCount (0 )
00308 {
00309 }
00310
00311 inline
00312 DepthFirstStateAction::NodeStackEntry::NodeStackEntry(
00313 const NodeStackEntry &source)
00314
00315 : _pNode (source._pNode ),
00316 _itStateRefCount(source._itStateRefCount),
00317 _passCount (source._passCount )
00318 {
00319 }
00320
00321 inline
00322 DepthFirstStateAction::NodeStackEntry::NodeStackEntry(
00323 const NodePtr &pNode, const StateRefCountStoreIt &itStateRefCount,
00324 Int32 passCount )
00325
00326 : _pNode (pNode ),
00327 _itStateRefCount(itStateRefCount),
00328 _passCount (passCount )
00329 {
00330 }
00331
00332 inline NodePtr
00333 DepthFirstStateAction::NodeStackEntry::getNode(void) const
00334 {
00335 return _pNode;
00336 }
00337
00338 inline Int32
00339 DepthFirstStateAction::NodeStackEntry::getPassCount(void) const
00340 {
00341 return _passCount;
00342 }
00343
00344 inline void
00345 DepthFirstStateAction::NodeStackEntry::setPassCount(Int32 passCount)
00346 {
00347 _passCount = passCount;
00348 }
00349
00350 inline DepthFirstStateAction::StateRefCountStoreIt
00351 DepthFirstStateAction::NodeStackEntry::getStateRefCount(void) const
00352 {
00353 return _itStateRefCount;
00354 }
00355
00356 inline void
00357 DepthFirstStateAction::NodeStackEntry::setStateRefCount(
00358 const StateRefCountStoreIt &itStateRefCount)
00359 {
00360 _itStateRefCount = itStateRefCount;
00361 }
00362
00366 inline DepthFirstStateAction::StateRefCountStoreIt
00367 DepthFirstStateAction::cloneState(void)
00368 {
00369 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00370
00371 UInt32 stateSlot;
00372 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end());
00373
00374 ExtendActorStoreIt itExtend = beginExtend();
00375 ExtendActorStoreIt endItExtend = endExtend ();
00376
00377 for(; itExtend != endItExtend; ++itExtend)
00378 {
00379 stateSlot = (*itExtend)->createStateClone();
00380 }
00381
00382 BasicActorStoreIt itBasic = beginBasic();
00383 BasicActorStoreIt endItBasic = endBasic ();
00384
00385 for(; itBasic != endItBasic; ++itBasic)
00386 {
00387 stateSlot = (*itBasic)->createStateClone();
00388 }
00389
00390 _stateRefCountStore.push_back(StateRefCount(stateSlot));
00391
00392 return ++itStateRefCount;
00393
00394 #else
00395
00396 StateStoreIt itState = --(_stateStore .end ());
00397 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00398
00399 ExtendActorStoreIt itExtend = beginExtend();
00400 ExtendActorStoreIt endItExtend = endExtend ();
00401
00402 for(; itExtend != endItExtend; ++itExtend)
00403 {
00404 _stateStore.push_back((*itExtend)->createStateClone());
00405 }
00406
00407 BasicActorStoreIt itBasic = beginBasic();
00408 BasicActorStoreIt endItBasic = endBasic ();
00409
00410 for(; itBasic != endItBasic; ++itBasic)
00411 {
00412 _stateStore.push_back((*itBasic)->createStateClone());
00413 }
00414
00415 _stateRefCountStore.push_back(StateRefCount(++itState));
00416
00417 return ++itStateRefCount;
00418
00419 #endif
00420 }
00421
00425 inline DepthFirstStateAction::StateRefCountStoreIt
00426 DepthFirstStateAction::getState(void)
00427 {
00428 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00429
00430 UInt32 stateSlot;
00431 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00432
00433 ExtendActorStoreIt itExtend = beginExtend();
00434 ExtendActorStoreIt endItExtend = endExtend ();
00435
00436 for(; itExtend != endItExtend; ++itExtend)
00437 {
00438 stateSlot = (*itExtend)->getSlotMap().size();
00439
00440 (*itExtend)->getSlotMap().push_back((*itExtend)->getState());
00441 }
00442
00443 BasicActorStoreIt itBasic = beginBasic();
00444 BasicActorStoreIt endItBasic = endBasic ();
00445
00446 for(; itBasic != endItBasic; ++itBasic)
00447 {
00448 stateSlot = (*itExtend)->getSlotMap().size();
00449
00450 (*itExtend)->getSlotMap().push_back((*itExtend)->getState());
00451 }
00452
00453 _stateRefCountStore.push_back(StateRefCount(stateSlot));
00454
00455 return ++itStateRefCount;
00456
00457 #else
00458
00459 StateStoreIt itState = --(_stateStore .end ());
00460 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00461
00462 ExtendActorStoreIt itExtend = beginExtend();
00463 ExtendActorStoreIt endItExtend = endExtend ();
00464
00465 for(; itExtend != endItExtend; ++itExtend)
00466 {
00467 _stateStore.push_back((*itExtend)->getState());
00468 }
00469
00470 BasicActorStoreIt itBasic = beginBasic();
00471 BasicActorStoreIt endItBasic = endBasic ();
00472
00473 for(; itBasic != endItBasic; ++itBasic)
00474 {
00475 _stateStore.push_back((*itBasic)->getState());
00476 }
00477
00478 _stateRefCountStore.push_back(StateRefCount(++itState));
00479
00480 return ++itStateRefCount;
00481
00482 #endif
00483 }
00484
00488 inline void
00489 DepthFirstStateAction::setState(StateRefCountStoreIt itStateRefCount)
00490 {
00491 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00492
00493 UInt32 stateSlot = itStateRefCount->getStateSlot();
00494
00495 ExtendActorStoreIt itExtend = beginExtend();
00496 ExtendActorStoreIt endItExtend = endExtend ();
00497
00498 for(; itExtend != endItExtend; ++itExtend, ++itState)
00499 {
00500 (*itExtend)->setState((*itExtend)->getSlotMap()[stateSlot]);
00501 }
00502
00503 BasicActorStoreIt itBasic = beginBasic();
00504 BasicActorStoreIt endItBasic = endBasic ();
00505
00506 for(; itBasic != endItBasic; ++itBasic, ++itState)
00507 {
00508 (*itBasic)->setState((*itBasic)->getSlotMap()[stateSlot]);
00509 }
00510
00511 #else
00512
00513 StateStoreIt itState = itStateRefCount->getState();
00514
00515 ExtendActorStoreIt itExtend = beginExtend();
00516 ExtendActorStoreIt endItExtend = endExtend ();
00517
00518 for(; itExtend != endItExtend; ++itExtend, ++itState)
00519 {
00520 (*itExtend)->setState(*itState);
00521 }
00522
00523 BasicActorStoreIt itBasic = beginBasic();
00524 BasicActorStoreIt endItBasic = endBasic ();
00525
00526 for(; itBasic != endItBasic; ++itBasic, ++itState)
00527 {
00528 (*itBasic)->setState(*itState);
00529 }
00530
00531 #endif
00532 }
00533
00537 inline void
00538 DepthFirstStateAction::incRefCount(StateRefCountStoreIt itStateRefCount, Int32 inc)
00539 {
00540 itStateRefCount->incRefCount(inc);
00541 }
00542
00546 inline void
00547 DepthFirstStateAction::decRefCount(StateRefCountStoreIt itStateRefCount, Int32 dec)
00548 {
00549 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00550
00551 itStateRefCount->decRefCount(dec);
00552
00553 if(itStateRefCount->getRefCount() <= 0)
00554 {
00555 UInt32 stateSlot = itStateRefCount->getStateSlot();
00556
00557 ExtendActorStoreIt itExtend = beginExtend();
00558 ExtendActorStoreIt endItExtend = endExtend ();
00559
00560 for(; itExtend != endExtend; ++itExtend)
00561 {
00562 delete (*itExtend)->getSlotMap()[stateSlot];
00563
00564
00565 }
00566
00567 BasicActorStoreIt itBasic = beginBasic();
00568 BasicActorStoreIt endItBasic = endBasic ();
00569
00570 for(; itBasic != endBasic; ++itBasic)
00571 {
00572 delete (*itBasic)->getSlotMap()[stateSlot];
00573
00574
00575 }
00576
00577 _stateRefCountStore.erase(itStateRefCount);
00578 }
00579
00580 #else
00581
00582 itStateRefCount->decRefCount(dec);
00583
00584 if(itStateRefCount->getRefCount() <= 0)
00585 {
00586 StateStoreIt itState = itStateRefCount->getState();
00587
00588 ExtendActorStoreIt itExtend = beginExtend();
00589 ExtendActorStoreIt endItExtend = endExtend ();
00590
00591 for(; itExtend != endItExtend; ++itExtend)
00592 {
00593 delete *itState;
00594
00595
00596
00597 itState = _stateStore.erase(itState);
00598 }
00599
00600 BasicActorStoreIt itBasic = beginBasic();
00601 BasicActorStoreIt endItBasic = endBasic ();
00602
00603 for(; itBasic != endItBasic; ++itBasic)
00604 {
00605 delete *itState;
00606
00607
00608
00609 itState = _stateStore.erase(itState);
00610 }
00611
00612 _stateRefCountStore.erase(itStateRefCount);
00613 }
00614
00615 #endif
00616 }
00617
00618 OSG_END_NAMESPACE
00619
00620 #define OSGDEPTHFIRSTSTATEACTION_INLINE_CVSID "@(#)$Id: OSGDepthFirstStateAction.inl,v 1.2 2004/09/17 14:09:43 neumannc Exp $"