VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
navArea.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2015 MaK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 
10 #pragma once
11 
13 #include <string>
16 #include <matrix/vlVector.h>
18 #include "boost/shared_ptr.hpp"
19 #include "boost/weak_ptr.hpp"
20 #include <readerWriter/rwString.h>
21 #include "vrfutil/rwUUID.h"
22 
23 class Coordinate_System;
24 class DtExtent;
25 class DtVrfObject;
26 class DtTerrainInterface;
27 class DtNavBot;
28 struct DtInputNavTag;
29 class DtNavEdge;
30 
32 {
38 };
39 
41 {
46 };
47 
48 typedef std::set<DtNavSectorName> DtNavSectorNames;
49 
50 //Base class for asynchronous Nav Area queries.
51 //In this context asynchronous means non-blocking, but performed
52 //in a single-thread. These queries are time-sliced by
53 //gameware's infrastructure.
54 //Will be ticked by the navArea's update function.
55 
57 {
58 public:
59  typedef boost::shared_ptr<DtNavAreaQuery> Ptr;
60 
62  virtual ~DtNavAreaQuery() { };
63 
64  virtual bool complete() = 0;
65  virtual bool tick() = 0;
66  virtual bool success() = 0;
67 
69  virtual bool navDataChanged() = 0;
70  virtual bool outOfWorkingMemory() = 0;
71  virtual bool hadComputationError() = 0;
72 
73  virtual std::vector<DtVector> results() = 0;
74  virtual std::vector<DtVector> debugPoints() { return std::vector<DtVector>(); };
75  virtual void* internalQuery() = 0;
76 };
77 
78 //Query that can be used when there is no valid navData.
80 {
81 public:
83  virtual ~DtNavAreaNullQuery() { };
84 
85  virtual bool complete() { return true; };
86  virtual bool tick() { return true; };
87  virtual bool success() { return true; };
88  virtual void cancel() {};
89  virtual bool navDataChanged() { return false; };
90  virtual bool outOfWorkingMemory() { return false; };
91  virtual bool hadComputationError() { return false; };
92  virtual std::vector<DtVector> results() { return std::vector<DtVector>(); };
93  virtual void *internalQuery(void) { return 0; };
94 };
95 
98 {
99  DtNavAreaConfig() : workingMemorySize(16), regenerateAtRuntime(true),
100  maxRegenerationThreads(2), regenerationDelay(2.5), queryTimeBudget(1) {};
101 
104  int workingMemorySize;
105 
108 
111 
114 
118 
119 };
120 
124 {
125 public:
127 
128 protected:
131 };
132 
133 
135 typedef boost::weak_ptr<DtNavRegenRequestIdData> DtNavRegenRequestId;
136 
140 {
141 public:
143 
144  void setMaxThreads(unsigned maxThreads)
145  {
147  }
148 
149  unsigned maxThreads() const { return myMaxThreads; }
150 
151  bool claimThread()
152  {
154  {
155  ++myUsedThreads;
156  return true;
157  }
158  return false;
159  }
160 
162  {
163  if (myUsedThreads > 0)
164  {
165  --myUsedThreads;
166  }
167  }
168 
169 private:
170 
171  unsigned myMaxThreads;
172  unsigned myUsedThreads;
173 };
174 
180 {
181 public:
183  {
185  int port;
186  std::vector<DtRwString> profiles;
188  };
189 
191  {
192  DtNavTriangleInfo() : navTag(0, 0) {};
193  DtVector points[3];
195  };
196 
197  typedef DtNavArea* (*DtNavAreaCreatorFcn)();
198  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestEvaluatorFcn)(const DtVector& localPoint, void* userData);
199  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestNavTagEvaluatorFcn)(const DtVector& localPoint, const DtNavTag& tag, void* userData);
200  typedef void (*DtSearchAreaPointCostModifierEvaluatorFcn)(const DtVector& localPoint, float* currentCost, void* userData);
201  typedef DtOnPathToGraphVertexComputedResult(*DtPathCalculatedEvaluatorFcn)(const DtVector& localPoint, double pathCost, void* userData);
202  typedef void(*DtSectorRegenerationCb)(void* userData);
203 
204  static DtNavArea* create();
205  static void setNavAreaCreatorFcn(DtNavAreaCreatorFcn fcn);
206 
207  static bool navAreaDebuggingEnabled();
208  static void setNavAreaDebuggingEnabled(bool enable);
209 
210  virtual ~DtNavArea() {};
211  virtual bool initialize(Coordinate_System* coordSys, DtTerrainInterface* terrainIf, DtNavAreaConfig config,
212  DtNavGenerationThreadCounter* threadCounter,
213  std::vector<DtString> profiles = std::vector<DtString>()) = 0;
214  virtual void update(float deltaTimeInSeconds) = 0;
216  virtual bool loadNavData(const DtString& path, const DtVariableBindingsList& variableBindings =
217  DtReaderWriter::nullVariableReference(), bool objectNavData = false) = 0;
218  virtual bool inNavArea(const DtVector& localPos) = 0;
224  virtual bool validPosition(const DtString& profile, const DtVector& localPos,
225  DtNavTag* navTag = 0, DtVector* outPos = 0) = 0;
226 
227  //Returns true if this area is valid for the given navigation profile.
228  virtual bool validForProfile(const DtString& profile) const = 0;
229 
230  virtual DtNavDataDebugInfo* debugInfo() = 0;
231 
232  virtual void setExtent(DtExtent* e) = 0;
233  virtual DtExtent localExtent() = 0;
234 
236  virtual void cancelQuery(DtNavAreaQuery::Ptr) = 0;
237 
240  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterest(const DtString& profile, const DtVector& startLocalPos,
241  int tag = DtNavDataTagAny, double propagationRadius = 200.,
242  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
243 
247  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterestUsingNavTag(const DtString& profile, const DtVector& startLocalPos,
248  bool useHighPriorityQueue,
249  int tag = DtNavDataTagAny, double propagationRadius = 200.,
250  DtPointOfInterestNavTagEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
251 
254  virtual void findNearbyNavEdgesUsingNavTags(const DtString& profile, double searchRadius, const DtVector& fromFromHere,
255  const std::vector<DtInputNavTag>& navTagVals, std::list<DtNavEdge*>& result) const = 0;
256 
258  virtual void findVerticesUsingNavTags(const DtString& profile, double searchRadius, const DtVector& fromFromHere,
259  const std::vector<DtInputNavTag>& navTagVals, std::list<DtVector>& result) const = 0;
260 
263  virtual DtNavAreaQuery::Ptr findBestExitPoint(const DtString& profile, DtNavBot* searcher,
264  const DtVector& startLocalPos, const DtVector& destination,
265  int tag = DtNavDataTagAny, double propagationRadius = 200.,
266  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
267 
269  virtual bool findInsidePositionFromOutsidePosition(const DtString& profile,
270  double searchRadius, double searchHeight, const DtVector& fromFromHere,
271  DtVector& result, int& halfEdgeType) const = 0;
272 
274  virtual DtNavAreaQuery::Ptr findBestPathTo(const DtString& profile, const DtVector& start,
275  const std::vector<DtVector>& localDestinationPositions, DtNavBot* searcher, int tag = -1,
276  DtSearchAreaPointCostModifierEvaluatorFcn = 0, DtPointOfInterestEvaluatorFcn = 0, DtPathCalculatedEvaluatorFcn = 0,
277  void* usrData = 0, bool startMovingWhenFound = false) = 0;
278 
280  virtual DtNavAreaQuery::Ptr findPathToLocation(const DtString& profile, const DtVector& start,
281  const DtVector& destination, bool useAbstractGraphs = true,
282  const DtVector& locationToAvoid = DtVector(), double avoidanceRadius = 0) = 0;
283 
286  virtual bool findFarthestPositionAlongHeading(const DtString& profile, const DtVector& start,
287  double heading, double maxDistance, DtVector& result, bool& reachedMaxDist) const = 0;
288 
290  virtual bool doesNavIntersectBetweenTwoPoints(const DtString& profile, const DtVector& start, const DtVector& end) const = 0;
291 
292  //User callback to check randomly generated points. The callback function
293  //should return true if the point is acceptable.
294  typedef bool (*DtLocalPointUserEvalCallback)(const DtVector& localVector, DtNavAreaQuery* query, void* userData);
295  static bool emptyCallback(const DtVector&, DtNavAreaQuery*, void*);
296 
297  //Generate some number of random points.
298  //If localAccessibilityPoint is set, all points must be navigable
299  //from the access point.
300  //If boundingArea is set, all points must be inside the area,
301  //ignoring elevation. Note that this will not cause points to be
302  //generated outside the navArea.
303  //If boundingArea is not set, and radius is set, points will be generated
304  //using radius as a maximum distance from accessibilityPoint.
305  //If minDistanceBetweenPoints is set, generated points will be tested
306  //against the rest of the set of random points to make sure none are within
307  //the given distance of each other.
308  //If placementRestriction is set to one of the MovementMode strings (e.g.
309  //DtMovementModePreferRoads), points will be chosen that match that criteria.
310  //If isStrict is true, only points matching the placementRestriction will be
311  //generated, even if we can't create enough to match the desired number.
312  //If tightlyPack is true, points closer to access point or bounding area center
313  //will be favored.
314  //If needLos is true, will try to choose points that should have LOS to the
315  //specified access point.
316  //If groundClamp is true, points will be ground clamped to the terrain at a point
317  //below the original point plus the height of the entity specified in nav generation.
318  //If leftOfLine, the points specified will be considered a line, and only points
319  //to the left of that line will be generated.
320  //If callbackFcn is set, this user function is called on each generated
321  //point, to test if each point is acceptable.
322  virtual DtNavAreaQuery::Ptr generateRandomPoints(const DtString& profile,
323  const DtVector& localAccessibilityPoint = DtVector::zero(),
324  double minRadius = -1,
325  double maxRadius = -1,
326  const DtLocalVertexList& boundingArea = DtLocalVertexList(),
327  unsigned numberOfPoints = 1,
328  double minDistanceBetweenPoints = 0.0,
329  const DtString& placementRestriction = DtString::nullString(),
330  bool isStrict = true,
331  bool tightlyPack = false,
332  bool needLos = false,
333  bool groundClamp = false,
334  const DtLocalVertexList& leftOfLine = DtLocalVertexList(),
335  DtLocalPointUserEvalCallback callbackFcn = emptyCallback,
336  void* userData = 0) = 0;
337 
339  virtual bool tagVolumesToBeIntegrated() const = 0;
340 
341  DtVrfObject* attachedObject() { return myAttachedObject; }
342  void setAttachedObject(DtVrfObject* object) { myAttachedObject = object; }
343 
348  virtual std::vector<DtVector> searchInArea(const DtString& profile,
349  const DtVector& startLocalPos, double radius, double postSpacing, DtNavBot* searcher,
350  DtPointOfInterestEvaluatorFcn evalFcn = 0, void* evalFcnUserData = 0, int tag = -1) const = 0;
351 
352  virtual bool navTrianglesInArea(const DtString& profile, const DtVector& location, double radius, std::list<DtNavTriangleInfo>& triangles) = 0;
353 
355  virtual unsigned newNavTagId() = 0;
356 
358  virtual void associateNavTagIdWithObject(unsigned tagVolumeId, const DtUUID& objectUUID) = 0;
359 
361  virtual void disassociateNavTagId(unsigned navTagId) = 0;
362 
365  virtual DtUUID uuidFromNavTagId(unsigned navTagId) const = 0;
366 
369  virtual unsigned navTagVolumeIdFromUuid(const DtUUID& objectUUID) = 0;
370 
372  virtual const DtNavSectorNames& sectorsQueuedForRegeneration() const = 0;
373 
375  virtual const DtNavSectorNames& sectorsBeingRegenerated() const = 0;
376 
379  virtual void addSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
380  virtual void removeSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
381 
385  virtual DtNavRegenRequestId requestNavDataGeneration(const DtVector& location, double radius,
386  const std::set<DtString>& profiles = std::set<DtString>()) = 0;
387 
389  virtual void requestNavDataReversion(DtNavRegenRequestId id) = 0;
390 
394  virtual unsigned addNavEdge(const DtString& profile, std::vector<DtVector>& LocalPoints,
395  const DtInputNavTag& navTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
396 
400  virtual unsigned addNavIEdge(const DtString& profile, std::vector<DtVector>& LocalPoints, std::vector< std::vector<DtVector> >& localIPoints,
401  const DtInputNavTag& navTag, const DtInputNavTag& entryExitNavTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
402 
404  virtual void removeNavEdge(unsigned edgeId) = 0;
405 
409  virtual unsigned addCoverPoint(const DtString& profile, const DtVector& localPoint,
410  bool& creationComplete) = 0;
411 
413  virtual bool isCoverPointCreated(unsigned coverPointId) = 0;
414 
416  virtual void removeCoverPoint(unsigned coverPointId) = 0;
417 
418 protected:
419  static DtNavAreaCreatorFcn theNavAreaCreatorFcn;
420 
422 
426 };
UUID is a unique ID wrapper class.
Definition: rwUUID.h:222
This class is just used to count the nav generation threads to ensure we do not start too many thread...
Definition: navArea.h:139
DtNavAreaQuery()
Definition: navArea.h:61
bool regenerateAtRuntime
Whether nav data should be regenerated at runtime.
Definition: navArea.h:110
DtVrfObject is used to represent any type of simulated object (entities, aggregate, control objects) in a VR-Forces application.
Definition: vrfObject.h:215
DtNavGenerationThreadCounter(unsigned maxThreads)
Definition: navArea.h:142
virtual ~DtNavAreaQuery()
Definition: navArea.h:62
virtual bool tick()
Definition: navArea.h:86
DtVrfObject * myAttachedObject
Points to the host object if this navArea is attached to an object like a cultural feature or a large...
Definition: navArea.h:425
Definition: navGeneration.h:54
virtual bool outOfWorkingMemory()
Definition: navArea.h:90
double queryTimeBudget
The time budget per frame for path queries in ms. Default value is 1.
Definition: navArea.h:107
virtual bool success()
Definition: navArea.h:87
DtNavAreaNullQuery()
Definition: navArea.h:82
virtual ~DtNavArea()
Definition: navArea.h:210
Definition: navArea.h:79
double regenerationDelay
Minimum delay between an event resulting in nav data regeneration and the start of the regeneration t...
Definition: navArea.h:117
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
virtual void cancel()
Definition: navArea.h:88
Wrapper for GameWare NavTag.
Definition: navDataTag.h:54
static bool theNavAreaDebuggingEnabled
Definition: navArea.h:421
static DtNavAreaCreatorFcn theNavAreaCreatorFcn
Definition: navArea.h:419
Definition: asyncJobServer.h:37
void releaseThread()
Definition: navArea.h:161
static const DtUUID & nullUUID()
Definition: coordSystem.h:54
virtual void * internalQuery(void)
Definition: navArea.h:93
virtual ~DtNavRegenRequestIdData()
Definition: navArea.h:126
Contains all the data and logic for navigation within a specific area.
Definition: navArea.h:179
DtVrfObject * attachedObject()
Definition: navArea.h:341
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
Contains all the data and logic for navigation within a specific edge.
Definition: navEdge.h:18
virtual ~DtNavAreaNullQuery()
Definition: navArea.h:83
int port
Definition: navArea.h:185
This is just an abstract base class for the data contained in a DtNavRegenRequestId.
Definition: navArea.h:123
DtNavRegenRequestIdData(const DtNavRegenRequestIdData &)
Definition: navArea.h:130
DtTerrainInterface allows access to common terrain calls without having to know the terrain implement...
Definition: terrainInterface.h:84
boost::shared_ptr< DtNavAreaQuery > Ptr
Definition: navArea.h:59
virtual std::vector< DtVector > debugPoints()
Definition: navArea.h:74
int maxRegenerationThreads
Maximum number of threads performing nav data regeneration at a time.
Definition: navArea.h:113
DtNavRegenRequestIdData()
Definition: navArea.h:129
static const DtVariableBindingsList & nullVariableReference()
bool claimThread()
Definition: navArea.h:151
void setMaxThreads(unsigned maxThreads)
Definition: navArea.h:144
Definition: navBot.h:27
unsigned myUsedThreads
Definition: navArea.h:172
Definition: navArea.h:182
void setAttachedObject(DtVrfObject *object)
Definition: navArea.h:342
virtual bool navDataChanged()
Returns true if the nav data has changed during this query.
Definition: navArea.h:89
DtNavAreaConfig()
Definition: navArea.h:99
#define DT_DLL_vrfNavigation
This file is used to determine how to build.
Definition: vrfNavigationDefines.h:26
Configuration options for DtNavArea.
Definition: navArea.h:97
DtString status
Definition: navArea.h:187
DtNavTag navTag
Definition: navArea.h:194
virtual bool hadComputationError()
Definition: navArea.h:91
class DtLocalVertexList:
Definition: localVertexList.h:20
DtString navAreaName
Definition: navArea.h:184
std::vector< DtRwString > profiles
Definition: navArea.h:186
Definition: navArea.h:190
virtual std::vector< DtVector > results()
Definition: navArea.h:92
virtual bool complete()
Definition: navArea.h:85
Definition: navArea.h:56
unsigned myMaxThreads
Definition: navArea.h:171
unsigned maxThreads() const
Definition: navArea.h:149

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)