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 #ifndef _OSGDEPTHFIRSTSTATEACTION_H_
00040 #define _OSGDEPTHFIRSTSTATEACTION_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045
00046
00047
00048
00049 #include <OSGConfig.h>
00050 #include <OSGSystemDef.h>
00051
00052 #include "OSGNewActionBase.h"
00053 #include "OSGActorBase.h"
00054
00055 #include <deque>
00056 #include <list>
00057
00058 OSG_BEGIN_NAMESPACE
00059
00060 class ExtendActorBase;
00061 class BasicActorBase;
00062
00063 class OSG_SYSTEMLIB_DLLMAPPING DepthFirstStateAction : public NewActionBase
00064 {
00065
00066 public:
00067 #ifdef OSG_NEWACTION_STATISTICS
00068
00072 static StatElemDesc<StatIntElem> statStateClones;
00073 static StatElemDesc<StatIntElem> statStateRestores;
00074
00076 #endif
00077
00081 virtual ~DepthFirstStateAction(void);
00082
00084
00088 static DepthFirstStateAction *create(void);
00089
00091
00095 virtual ResultE apply(NodePtr pRoot);
00096
00098
00099 protected:
00100
00104 DepthFirstStateAction(void);
00105
00107
00111 virtual void addExtendEvent (ExtendActorBase *pActor,
00112 UInt32 actorIndex);
00113 virtual void subExtendEvent (ExtendActorBase *pActor,
00114 UInt32 actorIndex);
00115
00116 virtual void addBasicEvent (BasicActorBase *pActor,
00117 UInt32 actorIndex);
00118 virtual void subBasicEvent (BasicActorBase *pActor,
00119 UInt32 actorIndex);
00120
00121 virtual void startEvent (void );
00122 virtual void stopEvent (void );
00123
00124 virtual void beginEditStateEvent(ActorBase *pActor,
00125 UInt32 actorId );
00126 virtual void endEditStateEvent (ActorBase *pActor,
00127 UInt32 actorId );
00128
00130
00131 private:
00132
00136 typedef NewActionBase Inherited;
00137 typedef ActorBase::ActorBaseState ActorBaseState;
00138
00139 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00140
00141 class StateRefCount
00142 {
00143 public:
00144 inline StateRefCount(const StateRefCount &source );
00145
00146 inline explicit StateRefCount( UInt32 stateSlot );
00147 inline explicit StateRefCount( UInt32 stateSlot,
00148 Int32 refCount );
00149
00150 inline UInt32 getStateSlot(void ) const;
00151 inline void setStateSlot(UInt32 stateSlot);
00152
00153 inline Int32 getRefCount (void ) const;
00154 inline void incRefCount (Int32 inc );
00155 inline void decRefCount (Int32 dec );
00156
00157 private:
00158 UInt32 _stateSlot;
00159 Int32 _refCount;
00160 };
00161
00162 #else
00163
00164 typedef std::list<ActorBaseState *> StateStore;
00165 typedef StateStore::iterator StateStoreIt;
00166 typedef StateStore::const_iterator StateStoreConstIt;
00167
00168 class StateRefCount;
00169 class NodeStackEntry;
00170 friend class StateRefCount;
00171 friend class NodeStackEntry;
00172
00173 class StateRefCount
00174 {
00175 public:
00176 inline StateRefCount(const StateRefCount &source );
00177
00178 inline explicit StateRefCount(const StateStoreIt &itState );
00179 inline explicit StateRefCount(const StateStoreIt &itState,
00180 Int32 refCount);
00181
00182 inline StateStoreIt getState( void ) const;
00183 inline void setState(const StateStoreIt &itState);
00184
00185 inline Int32 getRefCount(void ) const;
00186 inline void incRefCount(Int32 inc = 1);
00187 inline void decRefCount(Int32 dec = 1);
00188
00189 private:
00190 StateStoreIt _itState;
00191 Int32 _refCount;
00192 };
00193
00194 #endif
00195
00196 typedef std::list<StateRefCount> StateRefCountStore;
00197 typedef StateRefCountStore::iterator StateRefCountStoreIt;
00198 typedef StateRefCountStore::const_iterator StateRefCountStoreConstIt;
00199
00200 class NodeStackEntry
00201 {
00202 public:
00203 inline NodeStackEntry( void );
00204 inline NodeStackEntry(const NodeStackEntry &source );
00205 inline NodeStackEntry(const NodePtr &pNode,
00206 const StateRefCountStoreIt &itStateRefCount,
00207 Int32 passCount );
00208
00209 inline NodePtr getNode (void ) const;
00210
00211 inline Int32 getPassCount(void ) const;
00212 inline void setPassCount(Int32 passCount);
00213
00214 inline StateRefCountStoreIt getStateRefCount(void ) const;
00215 inline void setStateRefCount(const StateRefCountStoreIt &itStateRefCount);
00216
00217 private:
00218 NodePtr _pNode;
00219 StateRefCountStoreIt _itStateRefCount;
00220 Int32 _passCount;
00221 };
00222
00223 typedef std::deque<NodeStackEntry> NodeStack;
00224
00226
00230 ResultE traverseEnter ( void );
00231 ResultE traverseEnterLeave( void );
00232
00233 void pushChildren (const NodePtr &pNode, ResultE result);
00234
00235 inline ResultE enterNode (const NodePtr &pNode, UInt32 pass );
00236 inline ResultE leaveNode (const NodePtr &pNode, UInt32 pass );
00237
00238 inline StateRefCountStoreIt cloneState(void );
00239 inline StateRefCountStoreIt getState (void );
00240 inline void setState (StateRefCountStoreIt itStateRefCount);
00241
00242 inline void incRefCount(StateRefCountStoreIt itStateRefCount, Int32 inc = 1);
00243 inline void decRefCount(StateRefCountStoreIt itStateRefCount, Int32 dec = 1);
00244
00246
00247
00248 NodeStack _nodeStack;
00249 StateRefCountStore _stateRefCountStore;
00250
00251 #ifndef OSG_NEWACTION_STATESLOTINTERFACE
00252 StateStore _stateStore;
00253 #endif
00254
00255 StateRefCountStoreIt _itInitialState;
00256 StateRefCountStoreIt _itActiveState;
00257
00258 bool _stateClonedFlag;
00259
00260 ExtendActorStore _extendEnterActors;
00261 ExtendActorStore _extendLeaveActors;
00262
00263 BasicActorStore _basicEnterActors;
00264 BasicActorStore _basicLeaveActors;
00265 };
00266
00267 OSG_END_NAMESPACE
00268
00269 #include "OSGDepthFirstStateAction.inl"
00270
00271 #define OSGDEPTHFIRSTSTATEACTION_HEADER_CVSID "@(#)$Id: OSGDepthFirstStateAction.h,v 1.3 2005/08/30 18:21:56 dirk Exp $"
00272
00273 #endif