VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtDynamicTerrainFeature.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvUtil/vrvUtil.h>
15 #include <vrvUtil/signalslib.h>
16 
17 #include <boost/function.hpp>
18 #include <boost/enable_shared_from_this.hpp>
19 #include <boost/optional.hpp>
20 
21 #include <tbb/spin_rw_mutex.h>
22 
23 #include <map>
24 
25 class DtString;
26 
27 namespace makVrv
28 {
29  class DtDynamicTerrainGeometry;
30  class DtDynamicTerrainChange;
31  class DtDynamicTerrainWorld;
32  class DtDynamicTerrainIndex;
33  class DtDynamicTerrainChanges;
34 
56 
84  : public DtDisconnectable
85  , public boost::enable_shared_from_this<DtDynamicTerrainFeature>
86 
87  {
88  public:
89  class Link;
90  class RequestInfo;
91 
96  {
97  public:
99  RequestHandle();
100 
104  void removeTerrainChange();
105 
108  void releaseOwnership();
109 
110  private:
111  friend class DtDynamicTerrainWorld;
113 
114  explicit RequestHandle(
115  const boost::shared_ptr<DtDynamicTerrainFeature::RequestInfo>&);
116 
117  boost::weak_ptr<DtDynamicTerrainFeature::RequestInfo> myRequest;
118  };
119 
120  static unsigned long long GetObjectCount();
121 
124 
126  virtual ~DtDynamicTerrainFeature();
127 
132  virtual bool matches(const DtDynamicTerrainChange&, bool useOriginalGeometry = false) const = 0;
133  virtual bool matches(const DtDynamicTerrainGeometry&, bool useOriginalGeometry = false) const = 0;
134 
136  virtual const DtDynamicTerrainGeometry* geometry() const = 0;
137 
139  virtual const DtDynamicTerrainGeometry* originalGeometry() const;
140 
142  virtual boost::optional<DtString> featureAttribute(const DtString& key) const;
143 
145  virtual bool isInDefaultState() const = 0;
146 
149  virtual bool lastStateWasDefaultState() const = 0;
150 
156  virtual void changeState(const DtDynamicTerrainChanges& history) = 0;
157 
161 
162 
163  typedef boost::function<void (const DtDynamicTerrainFeature&)> Callback;
164 
165  typedef
166  boost::function<void (const DtDynamicTerrainFeature&, const DtDynamicTerrainChanges&)>
168 
174  virtual boost::signalslib::connection connectToChangeSignal(const ChangeCallback& callback) const;
175 
180  virtual boost::signalslib::connection connectToPageOutSignal(const Callback& callback) const;
181 
183 
188 
189  virtual DtString description() const = 0;
191 
192  virtual const DtDynamicTerrainFeature* parentFeature() const;
194 
208  virtual void iterateCommands(const boost::function<void(const DtDynamicTerrainChange&)>& callback) const;
209 
210  virtual void iterateCommands(const boost::function<void(const DtDynamicTerrainChange&)>& callback,
211  const DtString& key) const;
212 
214  void changed();
215 
218  bool pageOut();
219 
222  void changes(const boost::function<void (const DtDynamicTerrainChanges&)>& callback) const;
223 
225  RequestHandle addChangeRequest(DtDynamicTerrainChange* change);
226  RequestHandle addChangeRequest(double time, DtDynamicTerrainChange* change);
227 
228  protected:
231 
232  void indexDoubleAscending(const DtString& key);
233  void indexDoubleDescending(const DtString& key);
234  void indexIntAscending(const DtString& key);
235  void indexIntDescending(const DtString& key);
236  void indexStringAscending(const DtString& key);
237  void indexStringDescending(const DtString& key);
238 
239  void setupIndex(const DtString& key, DtDynamicTerrainIndex* index);
241 
248  virtual void removeTerrainChange(const DtDynamicTerrainChange& change);
249 
250 
251  private:
252  friend class Link;
253 
254  typedef boost::signalslib::signal<void (const DtDynamicTerrainFeature&)> Signal;
255 
256  typedef boost::signalslib::signal<
259 
260  typedef std::map<RequestInfo*, boost::shared_ptr<Link> > LinkInfoMap;
261 
263  bool makeLinkToRequest(const boost::shared_ptr<Link>& link);
265  virtual void breakLinkToRequest(LinkInfoMap::iterator);
267 
268  mutable ChangeSignal myChangeSignal; // implements connectToChangeSignal
269  mutable Signal myPageOutSignal; // implements connectToRemoveSignal
270 
273 
274  typedef tbb::spin_rw_mutex Mutex;
275  mutable Mutex myMutex;
276 
277  // Container which holds links to all the requests that match the feature.
279 
280  typedef std::map<DtString, DtDynamicTerrainIndex*> IndexMap;
282  };
283 
288  {
289  public:
290  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
291 
293  virtual ~DtDynamicTerrainIndex();
294 
299  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
300 
305  virtual const DtDynamicTerrainChange* firstChange() const = 0;
306 
308  virtual int size() const = 0;
309 
311  virtual bool addValue(
312  const boost::shared_ptr<DtDynamicTerrainFeature::Link>& link,
313  const DtString& key) = 0;
314  };
315 
317  {
318  public:
319  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
320 
322  virtual ~DtDynamicTerrainChanges();
323 
328  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
329 
332  virtual const DtDynamicTerrainIndex* indexFor(const DtString& key) const = 0;
333  };
334 
335  // Represents the link between a change request and a feature that is made when the feature
336  // determines that the request applies to it. The objects are managed by shared pointers
337  // and live two separate containers, one in the request info and one in the feature info.
338  // The feature holds them in a map from the time of the request to the link, so that the
339  // map implements the time line. The request holds the links in an unordered list since it
340  // does not care anything about the order of changes to the various features it has applied to.
342  {
343  public:
344  static unsigned long long GetObjectCount();
345 
346  // Create link between a feature and a request.
347  // This will create the object and insert it into the feature and request.
348  // Neither parameter can be null.
349  static bool Create(
350  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
351  const boost::shared_ptr<RequestInfo>& reqInfo);
352 
353  virtual ~Link();
354 
355  RequestInfo& request() { return *myRequestInfo; }
356  DtDynamicTerrainFeature& feature() { return *myFeatureInfo; }
357 
358  private:
359  Link(
360  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
361  const boost::shared_ptr<RequestInfo>& reqInfo);
362 
363  const boost::shared_ptr<RequestInfo> myRequestInfo;
364  const boost::shared_ptr<DtDynamicTerrainFeature> myFeatureInfo;
365  };
366 
367  // Bookkeeping info for an individual change request.
368  // Holds the list of links that this change request applies to.
369  class DT_DLL_VRVUTIL DtDynamicTerrainFeature::RequestInfo
370  : public DtDisconnectable
371  {
372  public:
373  friend class Link;
374 
375  static unsigned long long GetObjectCount();
376 
377  // takes ownership of command
378  explicit RequestInfo(DtDynamicTerrainChange* command);
379 
380  virtual ~RequestInfo();
381 
382  const DtDynamicTerrainChange& command() const;
383 
384  // called by DtDynamicTerrainWorld::RequestHandle to remove the request
385  void pageOut();
386 
387  private:
388  typedef std::list<boost::shared_ptr<Link> > LinkList;
389 
390  // functions for creating and breaking the links
391  void makeLinkToFeature(const boost::shared_ptr<Link>& link);
392  void breakLinkToFeature(LinkList::iterator i);
393 
394  // command of this request
395  boost::scoped_ptr<DtDynamicTerrainChange> myCommand;
396 
397  // mutex only protects myLinksToFeatures, all other members not changed after initial setup
398  typedef tbb::spin_mutex Mutex;
399  mutable Mutex myMutex;
400  // list of links to the features we've linked to
402  };
403 }
#define DT_DLL_VRVUTIL
Definition: vrvUtil.h:34
Definition: DtDynamicTerrainFeature.h:316
Represents (possibly infinite) area of space.
Definition: DtDynamicTerrainGeometry.h:20
Mutex myMutex
Definition: DtDynamicTerrainFeature.h:275
Contains makVrv::DtDisconnectable class.
voidpf void uLong size
Definition: ioapi.h:39
const boost::shared_ptr< DtDynamicTerrainFeature > myFeatureInfo
Definition: DtDynamicTerrainFeature.h:364
LinkInfoMap myLinkMap
Definition: DtDynamicTerrainFeature.h:278
RequestInfo & request()
Definition: DtDynamicTerrainFeature.h:355
boost::signalslib::signal< void(const DtDynamicTerrainFeature &)> Signal
Definition: DtDynamicTerrainFeature.h:254
tbb::spin_mutex Mutex
Definition: DtDynamicTerrainFeature.h:398
tbb::spin_rw_mutex Mutex
Definition: DtDynamicTerrainFeature.h:274
boost::function< void(const DtDynamicTerrainFeature &)> Callback
Signal notification. The functions can be used to install callbacks which are called when events happ...
Definition: DtDynamicTerrainFeature.h:163
Contains DLL export macros.
IndexMap myIndices
Definition: DtDynamicTerrainFeature.h:281
LinkList myLinksToFeatures
Definition: DtDynamicTerrainFeature.h:401
Functionality for disconnecting the various references that objects make to each other.
Definition: DtDisconnectable.h:25
boost::function< void(const DtDynamicTerrainChange &)> IterateRequestCallback
Definition: DtDynamicTerrainFeature.h:319
std::map< RequestInfo *, boost::shared_ptr< Link > > LinkInfoMap
Definition: DtDynamicTerrainFeature.h:260
std::list< boost::shared_ptr< Link > > LinkList
Definition: DtDynamicTerrainFeature.h:388
Contains DtDynamicTerrainChange class.
boost::function< void(const DtDynamicTerrainFeature &, const DtDynamicTerrainChanges &)> ChangeCallback
Signal notification. The functions can be used to install callbacks which are called when events happ...
Definition: DtDynamicTerrainFeature.h:167
boost::signalslib::signal< > ChangeSignal
Definition: DtDynamicTerrainFeature.h:258
Signal myPageOutSignal
Definition: DtDynamicTerrainFeature.h:269
Interface which abstracts the concept of a individually identifiable &quot;thing&quot; in the terrain...
Definition: DtDynamicTerrainFeature.h:83
boost::scoped_ptr< DtDynamicTerrainChange > myCommand
Definition: DtDynamicTerrainFeature.h:395
ChangeSignal myChangeSignal
Definition: DtDynamicTerrainFeature.h:268
boost::weak_ptr< DtDynamicTerrainFeature::RequestInfo > myRequest
Definition: DtDynamicTerrainFeature.h:117
Command which can be given to the dynamic terrain system to perform some change. This class is a simp...
Definition: DtDynamicTerrainChange.h:42
DtDynamicTerrainFeature & feature()
Definition: DtDynamicTerrainFeature.h:356
const boost::shared_ptr< RequestInfo > myRequestInfo
Definition: DtDynamicTerrainFeature.h:363
boost::function< void(const DtDynamicTerrainChange &)> IterateRequestCallback
Definition: DtDynamicTerrainFeature.h:290
Container for dynamic terrain features, change requests, and queries.
Definition: DtDynamicTerrainWorld.h:71
std::map< DtString, DtDynamicTerrainIndex * > IndexMap
Definition: DtDynamicTerrainFeature.h:280
tbb::spin_mutex Mutex
Definition: DtDisconnectable.h:49
Interface provided to terrain feature&#39;s state change functions.
Definition: DtDynamicTerrainFeature.h:287
Resource handle for a change request which has been added to the system. Returned from addChangeReque...
Definition: DtDynamicTerrainFeature.h:95

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)