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

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)