![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2010 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtAgentManager.h,v $ $Revision: 1.47 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #ifndef DtSceneManager_H_ 00014 #define DtSceneManager_H_ 00015 00016 #include <vrvCore/vrvCore.h> 00017 #include <vrvUtil/DtVirtualBaseClass.h> 00018 #include <vrvCore/DtAgentManagerInterface.h> 00019 #include <vrvUtil/DtLockedBufferedQueue.h> 00020 00021 #include <boost/smart_ptr/detail/atomic_count.hpp> 00022 #include <boost/thread/condition.hpp> 00023 #include <boost/thread/mutex.hpp> 00024 #include <boost/signals.hpp> 00025 #include <boost/unordered_map.hpp> 00026 00027 #include <list> 00028 #include <map> 00029 #include <vector> 00030 00031 namespace makVrv 00032 { 00033 class DtAsynchronousAgentManager; 00034 class DtCoordinateSystem; 00035 class DtDe; 00036 class DtMessage; 00037 class DtSceneProctor; 00038 class DtAgentUpdateResolverInterface; 00039 class DtAgent; 00040 00045 class DT_DLL_VRVCORE DtAgentManager : public DtAgentManagerInterface 00046 { 00047 public: 00048 00049 friend class DtAsynchronousAgentManager; 00050 00052 DtAgentManager(DtDe&); 00053 00055 virtual ~DtAgentManager(); 00056 00060 virtual void tick(); 00061 00063 virtual void updateScene(DtMessage& message); 00064 00067 virtual DtAgentUpdateResolverInterface* findUpdater(DtUniqueID id); 00068 00070 DtElementID findElementId(DtUniqueID id); 00071 00075 virtual bool sceneObjectIsVisible(DtElementID id) const; 00076 00077 //@name DtAsynchronousAgentManagerInterfaces related functions. 00079 00086 virtual DtAsynchronousAgentManager* createAsynchronousManager(const std::string& ownerName); 00087 00090 void checkForIgLock(bool forceLock = false); 00091 00097 virtual DtDe& acquireLockedIg(); 00098 00104 virtual void releaseLockedIg(); 00105 00107 00109 inline DtDe& de() 00110 { 00111 return myDe; 00112 } 00113 00117 void clear(); 00118 00121 boost::signal<void (DtUniqueID id)> signal_objectCreated; 00122 00123 protected: 00124 00132 virtual unsigned char acquireNamespaceId( 00133 DtAsynchronousAgentManager* sceneManagerInterface, 00134 const std::string& ownerName); 00135 00138 virtual void releaseNamespaceId(unsigned char nsId); 00139 00142 struct MessageParcel 00143 { 00144 00145 public: 00146 00147 MessageParcel() 00148 : message(0) 00149 , distribute(false) 00150 { 00151 } 00152 00153 bool distribute; 00154 DtMessage* message; 00155 00156 }; 00157 00158 typedef std::vector<MessageParcel> MessageParcelVector; 00159 00165 virtual void addAsynchronousUpdateMessages(MessageParcelVector& messages); 00166 00167 typedef std::vector<DtMessage*> MessageList; 00168 00171 void distributeAndUpdate( MessageList& masterMessages, MessageList& distributedMessages ); 00172 00176 virtual void localEncodeAndUpdateScene(); 00177 00179 virtual void createObject(const std::string& className, DtUniqueID id); 00180 00182 virtual void updateObject(DtUniqueID id,DtMessage& msg, unsigned int updatesize); 00183 00185 virtual void destroyObject(DtUniqueID id); 00186 00187 protected: 00188 00189 typedef boost::function< void (DtAgentManagerInterface*) > 00190 AgentManagerInterfaceFunction; 00191 00192 typedef DtLockedBufferedQueue<AgentManagerInterfaceFunction> 00193 AsynchronousAgentManagerInterfaceFunctionQueue; 00194 struct AsynchronousInterfaceEntry 00195 { 00196 //Local copy. 00197 std::string name; 00198 //Used to pass functions to be executed on the asynchronous interface. 00199 AsynchronousAgentManagerInterfaceFunctionQueue* asyncFunctionQueue; 00200 }; 00201 00202 typedef boost::unordered_map<DtUniqueID,AsynchronousInterfaceEntry> NamespaceMap; 00203 typedef boost::unordered_map<DtUniqueID,DtAgentUpdateResolverInterface*> UpdaterMap; 00204 typedef std::vector<DtAgent*> DriverVector; 00205 00206 00207 DtDe& myDe; 00208 00209 UpdaterMap myUpdaterMap; 00210 std::pair<DtUniqueID,DtAgentUpdateResolverInterface*> myLastObjectCache; 00211 DtSceneProctor* mySceneProctor; 00212 DtLockedBufferedQueue< MessageParcel > myAsynchronousMessageQueue; 00213 NamespaceMap myNamespaceMap; 00214 unsigned char myNextValidNamespaceIdGuess; 00215 00216 boost::detail::atomic_count myAtomicWaitingCount; 00217 boost::condition myRequestIgCondition; 00218 boost::condition myReleaseIgCondition; 00219 boost::mutex myMonitor; 00220 00221 //Force checking the asynchronous messages. 00222 bool myForceCheckAysncMessages; 00223 00224 }; 00225 00228 class DT_DLL_VRVCORE DtSceneManagerCreator : public DtVirtualBaseClass 00229 { 00230 00231 public: 00233 static DtSceneManagerCreator& instance(DtDe& theIG); 00234 00236 static void registerInstance(DtDe& theIG,DtSceneManagerCreator* anInstance); 00237 00239 virtual DtAgentManager* create(DtDe&); 00240 }; 00241 00242 } 00243 00244 #endif