VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtDynamicFidManager.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2024 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
16 
17 #include <tbb/mutex.h>
18 #include <tbb/spin_mutex.h>
19 
20 #include <osg/BoundingBox>
21 
22 #include <boost/shared_ptr.hpp>
23 
24 #include <set>
25 #include <deque>
26 #include <vector>
27 #include <unordered_map>
28 
29 namespace osgEarth
30 {
31  class MapNode;
32 }
33 
34 namespace makVrv
35 {
36 
37  typedef long long DtFid;
38  typedef unsigned long DtDynamicFidChangeId;
39 
40  // Holds info about a single FID that has been dynamically changed.
41  // This includes the alternative model put in place (if any)
43  {
44  public:
46  virtual ~DtDynamicFidEntry() {};
47 
48  virtual void inrementRefCount();
49  virtual void decrementRefCount();
50  virtual unsigned int refCount() const;
51  virtual DtFid fid() const { return myFid; };
52  virtual void setBoundingBox(const osg::BoundingBox& bb) { myBoundingBox = bb; };
53  virtual osg::BoundingBox boundingBox() const { return myBoundingBox; }
54  // Returns true if the reference count was previously (since last clearHistory() call) 0 and is now greater than 0.
55  virtual bool newlyReferenced() const;
56  // Returns true if the reference count was previously (since last clearHistory() call) non-zero and is now 0.
57  virtual bool newlyUnreferenced() const;
58  // Clears history for newlyReference() and newlyUnreferenced().
59  virtual void clearHistory();
60 
61  protected:
63  osg::BoundingBoxd myBoundingBox;
64  // The number of DtDynamicFidChangeEntry instances that point to this entry.
65  unsigned int myRefCount;
66  unsigned int myPrefRefCount;
67 
68  };
69 
70  // Holds info on a single change request to dynamic FIDs
71  // This change request may affect 0 or more FIDs
72  // This entry holds pointers to the FIDs that have been altered
73  // and preserves the change info that that addition FIDs can be altered
74  // as needed as terrain pages in.
76  {
77  public:
78  DtDynamicFidChangeEntry(boost::shared_ptr< DtDynamicTerrainChange > changeCommand,
79  DtDynamicFidChangeId changeId);
81  // Adds the fid entry to the list, and increments the ref count of the fid entry.
82  void addChangedFid(DtDynamicFidEntry* fidEntry);
83  // Removes the fid entry and decrements the ref count of the fid entry.
84  void removeChangedFid(DtDynamicFidEntry* fidEntry);
85  // Clears the fid entry list and decrements ref counter of fid entries.
86  void removeAllFidEntries();
87  boost::shared_ptr< DtDynamicTerrainChange > change();
88  std::set<DtFid> currentFids() const;
89  DtDynamicFidChangeId changeId() const;
90 
91  protected:
92  // List of FIDs currently altered by this change
93  std::vector<DtDynamicFidEntry*> myAlteredFids;
94  //boost::shared_ptr<DtDynamicTerrainRequestHandle::RequestHandleImpl> myChangeHandle;
95  boost::shared_ptr< makVrv::DtDynamicTerrainChange > myChangeCommand;
97 
98  };
99 
100  typedef boost::shared_ptr<DtDynamicFidChangeEntry> DtDynamicFidChangeEntryPtr;
101 
102  class DtDynamicFidManager;
103 
104  // Manages altering FIDs in the terrain based on a list of requests passed
105  // to this manager.
106  // This manager keeps the current requests and applies changes to terrain as it pages in,
107  // as well as applying to terrain already paged in.
108  // Changes can be removed, and will result in reverting FIDs to their original state.
109  // If multiple changes affect the same FID, that FID will only be reverted when all
110  // related changes have been removed.
111  //
112  // When changes are added/removed, the internal state of the manager is updated, but
113  // changes are not pushed to the terrain system until updateTerrain() is called.
114  //
115  // This is an abstract base class to manage the data, but does not interface with the
116  // terrain directly, so that it can be used in both VRV and VRF Sim.
117  // Subclasses must implement destroyFid() and resotreFid() in order to apply the changes
118  // to their terrain.
119  // Subclasses also must implement their own add and remove functions, which should call
120  // addChangeRequestInternal() and removeChangeInternal(). This is so that subclasses
121  // can manage how they track changes in their own way.
123  {
124  public:
126  virtual ~DtDynamicFidManager();
127 
128  // Updates the terrain with any changes that have been added/removed since the last updateTerrain() call.
129  // This call results in calls to destroyFid() and restoreFid().
130  virtual void updateTerrain();
131 
132  // Intentional no-op derived classes override to call reapplyChanges( tbb::concurrent_vector& )
134  virtual void reapplyChangesIfRequired();
135  virtual void reapplyChanges( std::deque<DtDynamicTerrainSphere>& queue );
137  //
138  // Reapply all changes that were previously added.
139  // This calls updateTerrain() when complete.
140  virtual void reapplyChanges();
141 
142  // \return True if the specified FID should currently be hidden, based on changes in this FID manager.
143  virtual bool isFidHidden(const DtFid fid) const;
144 
145  protected:
146  // Called whenever a fid entry changes to the destroyed state.
147  // Subclasses should override this call to alter their terrain representation.
148  virtual void destroyFids(const std::vector<DtDynamicFidEntry*>& fidEntries) = 0;
149  // Called whenever a fid entry is restored from the destroyed state to the normal state.
150  // Subclasses should override this call to alter their terrain representation.
151  virtual void resotreFids(const std::vector<DtDynamicFidEntry*>& fidEntries) = 0;
152 
153  // Override to provide the MapNode used by this class.
154  virtual osgEarth::MapNode* mapNode() = 0;
155 
156  // Creates and returns a DtDynamicFidEntry. Override to create a subclass to hold implementation specific data.
157  virtual DtDynamicFidEntry* createDynamicFidEntry(DtFid fid);
158 
159  // This function is called from updateTerrain() with a list of all entries that have been
160  // modified since the last call to updateTerrain(). Override this function to provide notification
161  // to other parts of the system about terrain changes.
162  // Default implementation does nothing.
163  virtual void notifyModifications(const std::vector<DtDynamicFidEntry*>& modifiedEntries);
164 
165  // Internal logic for adding a change request that returns the new entry (if created).
166  // Here to allow subclasses to customize the addChangeRequest logic to return handles/ids of their choice.
167  virtual boost::shared_ptr<DtDynamicFidChangeEntry> addChangeRequestInternal(const makVrv::DtDynamicTerrainChange& changeCommand);
168 
169  // This call should not normally be made by the client code, and is here to be called from DtDynamicFidTerrainRequestHandleImpl::removeChange().
170  virtual void removeChangeInternal(boost::shared_ptr<DtDynamicFidChangeEntry> changeEntry);
171 
172  // Finds the currently loaded FIDs that match this change, and if they are not already tracked by the change entry,
173  // add them to the change and call destroyFid() as needed for any new ones.
174  // This call is appropriate for when a change is new and also when new terrain has paged in and new FIDs might be available.
175  // This call does not make changes to the DtCollisionWorld. It alters the internal state of which FIDs are hidden.
176  // The next call to updateTerrain() after this call is made will apply changes to the collision world.
177  virtual void refreshChange(DtDynamicFidChangeEntryPtr changeEntry);
178 
179  protected:
180  std::unordered_map<DtDynamicFidChangeId, DtDynamicFidChangeEntryPtr > myChanges;
181  std::unordered_map<DtFid, DtDynamicFidEntry*> myAlteredFids;
183  mutable tbb::spin_mutex myMutex;
184  };
185 };
unsigned int myRefCount
Definition: DtDynamicFidManager.h:65
Definition: DtDynamicFidManager.h:75
virtual DtFid fid() const
Definition: DtDynamicFidManager.h:51
virtual osg::BoundingBox boundingBox() const
Definition: DtDynamicFidManager.h:53
virtual void setBoundingBox(const osg::BoundingBox &bb)
Definition: DtDynamicFidManager.h:52
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Contains makVrv::DtDynamicTerrainSphere class.
Definition: DtDynamicFidManager.h:122
std::vector< DtDynamicFidEntry * > myAlteredFids
Definition: DtDynamicFidManager.h:93
boost::shared_ptr< DtDynamicFidChangeEntry > DtDynamicFidChangeEntryPtr
Definition: DtDynamicFidManager.h:100
long long DtFid
Definition: DtDynamicFidManager.h:37
DtFid myFid
Definition: DtDynamicFidManager.h:62
DtDynamicFidChangeId myNextChangeId
Definition: DtDynamicFidManager.h:182
unsigned int myPrefRefCount
Definition: DtDynamicFidManager.h:66
tbb::spin_mutex myMutex
Definition: DtDynamicFidManager.h:183
std::unordered_map< DtFid, DtDynamicFidEntry * > myAlteredFids
Definition: DtDynamicFidManager.h:181
DtDynamicFidChangeId myChangeId
Definition: DtDynamicFidManager.h:96
std::unordered_map< DtDynamicFidChangeId, DtDynamicFidChangeEntryPtr > myChanges
Definition: DtDynamicFidManager.h:180
osg::BoundingBoxd myBoundingBox
Definition: DtDynamicFidManager.h:63
boost::shared_ptr< makVrv::DtDynamicTerrainChange > myChangeCommand
Definition: DtDynamicFidManager.h:95
Contains DtDynamicTerrainChange class.
Definition: DtDynamicFidManager.h:42
Command which can be given to the dynamic terrain system to perform some change. This class is a simp...
Definition: DtDynamicTerrainChange.h:42
Contains DLL export macros.
virtual ~DtDynamicFidEntry()
Definition: DtDynamicFidManager.h:46
unsigned long DtDynamicFidChangeId
Definition: DtDynamicFidManager.h:38

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)