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 "OSGExtendActorBase.h"
00044 #include "OSGBasicActorBase.h"
00045
00046 OSG_BEGIN_NAMESPACE
00047
00048
00049
00050
00051
00052 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00053
00062 inline
00063 PriorityAction::StateRefCount::StateRefCount(const StateRefCount &source)
00064 : _stateSlot(source._stateSlot),
00065 _refCount (source._refCount )
00066 {
00067 }
00068
00076 inline
00077 PriorityAction::StateRefCount::StateRefCount(UInt32 stateSlot)
00078 : _stateSlot(stateSlot),
00079 _refCount (0 )
00080 {
00081 }
00082
00086 inline
00087 PriorityAction::StateRefCount::StateRefCount(UInt32 stateSlot, Int32 refCount)
00088 : _stateSlot(stateSlot),
00089 _refCount (refCount )
00090 {
00091 }
00092
00096 inline UInt32
00097 PriorityAction::StateRefCount::getStateSlot(void) const
00098 {
00099 return _stateSlot;
00100 }
00101
00102
00103
00104
00105 inline void
00106 PriorityAction::StateRefCount::setStateSlot(UInt32 stateSlot)
00107 {
00108 _stateSlot = stateSlot;
00109 }
00110
00114 inline Int32
00115 PriorityAction::StateRefCount::getRefCount(void) const
00116 {
00117 return _refCount;
00118 }
00119
00123 inline void
00124 PriorityAction::StateRefCount::incRefCount(Int32 inc)
00125 {
00126 _refCount += inc;
00127 }
00128
00132 inline void
00133 PriorityAction::StateRefCount::decRefCount(Int32 dec)
00134 {
00135 _refCount -= inc;
00136 }
00137
00138 #else
00139
00148 inline
00149 PriorityAction::StateRefCount::StateRefCount(const StateRefCount &source)
00150 : _itState (source._itState ),
00151 _refCount(source._refCount)
00152 {
00153 }
00154
00162 inline
00163 PriorityAction::StateRefCount::StateRefCount(const StateStoreIt &itState)
00164 : _itState (itState),
00165 _refCount(0 )
00166 {
00167 }
00168
00172 inline
00173 PriorityAction::StateRefCount::StateRefCount(
00174 const StateStoreIt &itState, Int32 refCount)
00175
00176 : _itState (itState ),
00177 _refCount(refCount)
00178 {
00179 }
00180
00184 inline PriorityAction::StateStoreIt
00185 PriorityAction::StateRefCount::getState(void) const
00186 {
00187 return _itState;
00188 }
00189
00193 inline void
00194 PriorityAction::StateRefCount::setState(const StateStoreIt &itState)
00195 {
00196 _itState = itState;
00197 }
00198
00202 inline Int32
00203 PriorityAction::StateRefCount::getRefCount(void) const
00204 {
00205 return _refCount;
00206 }
00207
00211 inline void
00212 PriorityAction::StateRefCount::incRefCount(Int32 inc)
00213 {
00214 _refCount += inc;
00215 }
00216
00220 inline void
00221 PriorityAction::StateRefCount::decRefCount(Int32 dec)
00222 {
00223 _refCount -= dec;
00224 }
00225
00226 #endif
00227
00236 inline
00237 PriorityAction::NodeQueueEntry::NodeQueueEntry(const NodeQueueEntry &source)
00238 : _pNode (source._pNode ),
00239 _priority (source._priority ),
00240 _itStateRefCount(source._itStateRefCount)
00241 {
00242 }
00243
00247 inline
00248 PriorityAction::NodeQueueEntry::NodeQueueEntry(
00249 const NodePtr &pNode,
00250 PriorityType priority,
00251 UInt32 passCount,
00252 const StateRefCountStoreIt &itStateRefCount)
00253
00254 : _pNode (pNode ),
00255 _priority (priority ),
00256 _passCount (passCount ),
00257 _itStateRefCount(itStateRefCount)
00258 {
00259 }
00260
00264 inline NodePtr
00265 PriorityAction::NodeQueueEntry::getNode(void) const
00266 {
00267 return _pNode;
00268 }
00269
00273 inline PriorityAction::PriorityType
00274 PriorityAction::NodeQueueEntry::getPriority(void) const
00275 {
00276 return _priority;
00277 }
00278
00282 inline UInt32
00283 PriorityAction::NodeQueueEntry::getPassCount(void) const
00284 {
00285 return _passCount;
00286 }
00287
00291 inline PriorityAction::StateRefCountStoreIt
00292 PriorityAction::NodeQueueEntry::getStateRefCount(void) const
00293 {
00294 return _itStateRefCount;
00295 }
00296
00300 inline bool
00301 PriorityAction::NodeQueueEntry::LessCompare::operator()(
00302 const NodeQueueEntry &leftArg, const NodeQueueEntry &rightArg)
00303 {
00304 return (leftArg.getPriority() < rightArg.getPriority());
00305 }
00306
00307
00308
00309
00310
00314 inline PriorityAction::ResultE
00315 PriorityAction::enterNode(const NodePtr &pNode, UInt32 pass)
00316 {
00317 FunctorArgumentType funcArg(NULL, pNode, pass);
00318 ResultE result = NewActionTypes::Continue;
00319
00320 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00321 ExtendActorStoreIt endItExtend = _extendEnterActors.end ();
00322
00323 for(; (itExtend != endItExtend ) &&
00324 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00325 ++itExtend )
00326 {
00327 funcArg.setActor(*itExtend);
00328
00329 result = static_cast<ResultE>(result | (*itExtend)->enterNode(funcArg));
00330 }
00331
00332 BasicActorStoreIt itBasic = beginBasic ();
00333 BasicActorStoreIt endItBasic = endBasic ();
00334
00335 for(; (itBasic != endItBasic ) &&
00336 !(result & (NewActionTypes::Break | NewActionTypes::Quit));
00337 ++itBasic )
00338 {
00339 funcArg.setActor(*itBasic);
00340
00341 result = static_cast<ResultE>(result | (*itBasic)->enterNode(funcArg));
00342 }
00343
00344 return result;
00345 }
00346
00350 inline PriorityAction::StateRefCountStoreIt
00351 PriorityAction::cloneState(void)
00352 {
00353 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00354
00355 UInt32 stateSlot;
00356 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end());
00357
00358 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00359 ExtendActorStoreIt endExtend = _extendEnterActors.end ();
00360
00361 for(; itExtend != endExtend; ++itExtend)
00362 {
00363 stateSlot = (*itExtend)->createStateClone();
00364 }
00365
00366 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00367 BasicActorStoreIt endBasic = _basicEnterActors.end ();
00368
00369 for(; itBasic != endBasic; ++itBasic)
00370 {
00371 stateSlot = (*itBasic)->createStateClone();
00372 }
00373
00374 _stateRefCountStore.push_back(StateRefCount(stateSlot));
00375
00376 return ++itStateRefCount;
00377
00378 #else
00379
00380 StateStoreIt itState = --(_stateStore .end ());
00381 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00382
00383 ExtendActorStoreIt itExtend = _extendEnterActors .begin();
00384 ExtendActorStoreIt endItExtend = _extendEnterActors .end ();
00385
00386 for(; itExtend != endItExtend; ++itExtend)
00387 {
00388 _stateStore.push_back((*itExtend)->createStateClone());
00389 }
00390
00391 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00392 BasicActorStoreIt endItBasic = _basicEnterActors.end ();
00393
00394 for(; itBasic != endItBasic; ++itBasic)
00395 {
00396 _stateStore.push_back((*itBasic)->createStateClone());
00397 }
00398
00399 _stateRefCountStore.push_back(StateRefCount(++itState));
00400
00401 return ++itStateRefCount;
00402
00403 #endif
00404 }
00405
00409 inline PriorityAction::StateRefCountStoreIt
00410 PriorityAction::getState(void)
00411 {
00412 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00413
00414 UInt32 stateSlot;
00415 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00416
00417 ExtendActorStoreIt itExtend = _extendEnterActors .begin();
00418 ExtendActorStoreIt endItExtend = _extendEnterActors .end ();
00419
00420 for(; itExtend != endItExtend; ++itExtend)
00421 {
00422 stateSlot = (*itExtend)->getSlotMap().size();
00423
00424 (*itExtend)->getSlotMap().push_back((*itExtend)->getState());
00425 }
00426
00427 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00428 BasicActorStoreIt endItBasic = _basicEnterActors.end ();
00429
00430 for(; itBasic != endItBasic; ++itBasic)
00431 {
00432 stateSlot = (*itExtend)->getSlotMap().size();
00433
00434 (*itExtend)->getSlotMap().push_back((*itExtend)->getState());
00435 }
00436
00437 _stateRefCountStore.push_back(StateRefCount(stateSlot));
00438
00439 return ++itStateRefCount;
00440
00441 #else
00442
00443 StateStoreIt itState = --(_stateStore .end ());
00444 StateRefCountStoreIt itStateRefCount = --(_stateRefCountStore.end ());
00445
00446 ExtendActorStoreIt itExtend = _extendEnterActors .begin();
00447 ExtendActorStoreIt endItExtend = _extendEnterActors .end ();
00448
00449 for(; itExtend != endItExtend; ++itExtend)
00450 {
00451 _stateStore.push_back((*itExtend)->getState());
00452 }
00453
00454 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00455 BasicActorStoreIt endItBasic = _basicEnterActors.end ();
00456
00457 for(; itBasic != endItBasic; ++itBasic)
00458 {
00459 _stateStore.push_back((*itBasic)->getState());
00460 }
00461
00462 _stateRefCountStore.push_back(StateRefCount(++itState));
00463
00464 return ++itStateRefCount;
00465
00466 #endif
00467 }
00468
00472 inline void
00473 PriorityAction::setState(StateRefCountStoreIt itStateRefCount)
00474 {
00475 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00476
00477 UInt32 stateSlot = itStateRefCount->getStateSlot();
00478
00479 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00480 ExtendActorStoreIt endItExtend = _extendEnterActors.end ();
00481
00482 for(; itExtend != endExtend; ++itExtend, ++itState)
00483 {
00484 (*itExtend)->setState((*itExtend)->getSlotMap()[stateSlot]);
00485 }
00486
00487 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00488 BasicActorStoreIt endItBasic = _basicEnterActors.end ();
00489
00490 for(; itBasic != endItBasic; ++itBasic, ++itState)
00491 {
00492 (*itBasic)->setState((*itBasic)->getSlotMap()[stateSlot]);
00493 }
00494
00495 #else
00496
00497 StateStoreIt itState = itStateRefCount->getState();
00498
00499 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00500 ExtendActorStoreIt endItExtend = _extendEnterActors.end ();
00501
00502 for(; itExtend != endItExtend; ++itExtend, ++itState)
00503 {
00504 (*itExtend)->setState(*itState);
00505 }
00506
00507 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00508 BasicActorStoreIt endItBasic = _basicEnterActors.end ();
00509
00510 for(; itBasic != endItBasic; ++itBasic, ++itState)
00511 {
00512 (*itBasic)->setState(*itState);
00513 }
00514
00515 #endif
00516 }
00517
00521 inline void
00522 PriorityAction::incRefCount(StateRefCountStoreIt itStateRefCount, Int32 inc)
00523 {
00524 itStateRefCount->incRefCount(inc);
00525 }
00526
00530 inline void
00531 PriorityAction::decRefCount(StateRefCountStoreIt itStateRefCount, Int32 dec)
00532 {
00533 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00534
00535 itStateRefCount->decRefCount(dec);
00536
00537 if(itStateRefCount->getRefCount() <= 0)
00538 {
00539 UInt32 stateSlot = itStateRefCount->getStateSlot();
00540
00541 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00542 ExtendActorStoreIt endExtend = _extendEnterActors.end ();
00543
00544 for(; itExtend != endExtend; ++itExtend)
00545 {
00546 delete (*itExtend)->getSlotMap()[stateSlot];
00547
00548
00549 }
00550
00551 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00552 BasicActorStoreIt endBasic = _basicEnterActors.end ();
00553
00554 for(; itBasic != endBasic; ++itBasic)
00555 {
00556 delete (*itBasic)->getSlotMap()[stateSlot];
00557
00558
00559 }
00560
00561 _stateRefCountStore.erase(itStateRefCount);
00562 }
00563
00564 #else
00565
00566 itStateRefCount->decRefCount(dec);
00567
00568 if(itStateRefCount->getRefCount() <= 0)
00569 {
00570 StateStoreIt itState = itStateRefCount->getState();
00571
00572 ExtendActorStoreIt itExtend = _extendEnterActors.begin();
00573 ExtendActorStoreIt endExtend = _extendEnterActors.end ();
00574
00575 for(; itExtend != endExtend; ++itExtend)
00576 {
00577 delete *itState;
00578
00579
00580
00581 itState = _stateStore.erase(itState);
00582 }
00583
00584 BasicActorStoreIt itBasic = _basicEnterActors.begin();
00585 BasicActorStoreIt endBasic = _basicEnterActors.end ();
00586
00587 for(; itBasic != endBasic; ++itBasic)
00588 {
00589 delete *itState;
00590
00591
00592
00593 itState = _stateStore.erase(itState);
00594 }
00595
00596 _stateRefCountStore.erase(itStateRefCount);
00597 }
00598
00599 #endif
00600 }
00601
00602 inline const PriorityAction::NodeQueueEntry &
00603 PriorityAction::pqTop(void) const
00604 {
00605 return _nodePrioQueue.front();
00606 }
00607
00608 inline void
00609 PriorityAction::pqPush(const NodeQueueEntry &entry)
00610 {
00611 _nodePrioQueue.push_back(entry);
00612
00613 std::push_heap(_nodePrioQueue.begin(), _nodePrioQueue.end(),
00614 _nodePrioQueueComp );
00615 }
00616
00617 inline void
00618 PriorityAction::pqPop(void)
00619 {
00620 std::pop_heap(_nodePrioQueue.begin(), _nodePrioQueue.end(),
00621 _nodePrioQueueComp );
00622
00623 _nodePrioQueue.pop_back();
00624 }
00625
00626 inline bool
00627 PriorityAction::pqEmpty(void) const
00628 {
00629 return _nodePrioQueue.empty();
00630 }
00631
00632 inline void
00633 PriorityAction::pqClear(void)
00634 {
00635 _nodePrioQueue.clear();
00636 }
00637
00638 OSG_END_NAMESPACE
00639
00640 #define OSGPRIORITYACTION_INLINE_CVSID "@(#)$Id: OSGPriorityAction.inl,v 1.4 2004/09/17 14:09:43 neumannc Exp $"