VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
trpage_managers.h
Go to the documentation of this file.
1 /* ************************
2  Copyright Terrain Experts Inc.
3  Terrain Experts Inc (TERREX) reserves all rights to this source code
4  unless otherwise specified in writing by the President of TERREX.
5  This copyright may be updated in the future, in which case that version
6  supercedes this one.
7  -------------------
8  Terrex Experts Inc.
9  4400 East Broadway #314
10  Tucson, AZ 85711
11  info@terrex.com
12  Tel: (520) 323-7990
13  ************************
14  */
15 
16 #ifndef _trpage_managers_h_
17 #define _trpage_managers_h_
18 
20 #include <deque>
21 
22 /* This file contains class definitions for managers
23  that help you keep track of data related to
24  paging. For instance, which tiles to load
25  in at any given time and what textures you need
26  to read for a given tile.
27  */
28 
29 class trpgPageManager;
30 
33 {
34  TileLocationInfo(): x(-1), y(-1), lod(-1) {}
35  TileLocationInfo(int gx, int gy, int glod, const trpgwAppAddress& gaddr): x(gx), y(gy), lod(glod), addr(gaddr) {}
36  int x, y, lod;
38 };
39 
40 /* Managed Tiles are used by the trpgPageManager to keep
41  track of which tiles are loaded and what textures (and
42  models) they need loaded into memory with them.
43  */
45 {
46  friend class trpgPageManager;
47 public:
48  trpgManagedTile(void);
49 
51  void Reset(void);
52 
53  /* Call this when you hit a tile header in your own
54  Scene parser callback. The managed tile
55  can then keep track of which textures and models
56  go with this tile.
57  */
58  bool ParseTileHeader(trpgReadBuffer &);
59 
61  bool IsLoaded(void);
62 
63  /* Set the tile location. This resets any internal
64  state we may be keeping.
65  */
66  bool SetTileLoc(int x,int y,int lod);
68  bool GetTileLoc(int &x,int &y,int &lod) const;
69 
73  void SetTileAddress(const trpgwAppAddress& gAddr);
74  void SetTileAddress(int32 file, int32 offset);
75  const trpgwAppAddress& GetTileAddress() const;
76 
77 
78 
80  const trpgTileHeader *GetTileHead(void);
81 
82  /* Return a pointer to the list of locally defined
83  materials. As soon as the tile header is read by
84  ParseTileHeader (which you call) you'll want to get
85  this list and load the pageable textures. You can
86  use SetMatData to keep track of our internal texture
87  structures.
88  */
89  const std::vector<trpgLocalMaterial> *GetLocMatList(void) const;
90 
91  /* Returns a pointer to a single local material, if within
92  the valid range of local materials for this tile.
93  */
94  const trpgLocalMaterial *GetLocMaterial(int id) const;
95 
96  /* Set Local Data for managed tile. The local data would
97  probably be a pointer to the top of the scene graph you're
98  using to represent just this tile.
99  */
100  void SetLocalData(void *);
101 
102  /* Returns the local data you set with SetLocalData.
103  */
104  void *GetLocalData(void) const;
105 
106  /* Associates a void * with one of the materials referenced
107  within this tile. The idea here is that you'll want
108  to load the texture for a given local material and then
109  pass your own internal texture structure into here as
110  a void *. That way, the trpgPageManager will keep track
111  of which textures you should unload when this tile goes
112  out of range.
113  */
114  bool SetMatData(int id,void *);
115 
116  /* Gets the void * data you associated with a given local
117  material index. See SetMatData for more information.
118  */
119  void *GetMatData(int id) const;
120 
121  /* Add Group ID to this tile. This is called by the page
122  manager to keep track of which group IDs belong to this tile.
123  We use this information to NULL out the appropriate positions
124  in the group map help by the page manager.
125  */
126  void AddGroupID(int id);
127 
128  /* Retrieve the list of group IDs for this tile.
129  */
130  const std::vector<int> *GetGroupIDs(void) const;
131 
132  /* Print the current status and information about this managed
133  Tile.
134  */
135  void Print(trpgPrintBuffer &);
136 
138  unsigned int GetNbChildren() const
139  {
140  return (unsigned int)childLocationInfo.size();
141  }
142  bool SetChildLocationInfo(int childIdx, int x, int y, const trpgwAppAddress& addr);
143  bool SetChildLocationInfo(int childIdx, const TileLocationInfo& info);
144  const TileLocationInfo& GetChildLocationInfo(int childIdx) const;
145  bool GetChildTileLoc(int childIdx, int &x,int &y,int &lod) const;
146  const trpgwAppAddress& GetChildTileAddress(int childIdx) const;
147 
148 
149 protected:
151  bool isLoaded;
154 
158  std::vector<void *> localMatData;
160  std::vector<int> groupIDs;
162  void *localData;
163 
166  std::vector<TileLocationInfo> childLocationInfo;
167 
169 };
170 
171 /* The Page Manager is a helper class that can be used
172  to keep track of: (1) which tiles need to be loaded
173  into memory for a given viewer position, (2) which tiles
174  are currently loaded and (3) which tiles need to be unloaded
175  when the viewer position moves. The tile list this
176  class generates is guaranteed to be in the right order
177  for loading. You would use this class if you're implementing
178  a TerraPage reader for your visual run-time system.
179 */
181 {
182 public:
183  trpgPageManager(void);
184  virtual ~trpgPageManager(void);
185 
187  virtual void Init(trpgr_Archive *);
188  virtual void Init(trpgr_Archive *inArch, int maxLod);
189 
190  /* Set Paging Distance
191  This is the extra distance outside the visible range
192  we want to page. The defaults will be valid. You would
193  set this if you want to pull tiles in earlier. Be sure
194  to call it before you call Init(), however.
195  */
196  virtual bool SetPageDistFactor(double);
197 
198  /* Updates the current location for paging purposes.
199  Returns true if any load or unloads need to happen.
200  */
201  virtual bool SetLocation(trpg2dPoint &);
202 
203  /* Get next tile to load.
204  The paging manager is keeping track of which tiles
205  need to be loaded and in what order. This method
206  returns a pointer to the next one. The user is
207  expected to call AckLoad() after the tile is loaded.
208  */
209  virtual trpgManagedTile *GetNextLoad(void);
210  /* Acknowledge Tile Load.
211  This method should be called when a tile has been
212  loaded by the caller. This method is used in conjunction
213  with GetNextLoad().
214 
215  Version 2.1 and over supports variable lod so that we cannot know
216  from the tile table if a tile exist or not. So to manage this
217  the user must parse the loaded tile and extract its list of children
218  and pass it on to AckLoad() which will add to the appropriate lod list
219  the children info. If this is not done then only lod 0 will be pageable.
220  */
221 
222  virtual void AckLoad(std::vector<TileLocationInfo> const& children);
223 
225  virtual void AckLoad();
226 
227  /* Add Group ID to map.
228  This should be called when the user encounters a group-like
229  object while processing the scene graph data from a tile.
230  The groupId is given by TerraPage and the data should be
231  the corresponding group object that the user creates in
232  their own scenegraph toolkit. This information can then
233  be retrieved later by GetGroupData().
234  */
235  virtual void AddGroupID(trpgManagedTile *,int groupID,void *data);
236 
237  /* Get Group Data fetches the data cached by the user and
238  associated with the given groupID. This would be used in
239  conjunction with trpgAttach nodes to implement geometry paging.
240  */
241  virtual void *GetGroupData(int groupID);
242 
243  /* Get next tile to unload.
244  The paging manager keeps track of which tiles need
245  to be unloaded based on a change of location. It's
246  best if you unload tiles before loading them, but
247  that's really up to you.
248  */
249  virtual trpgManagedTile *GetNextUnload(void);
250  /* Acknowledge a tile unload.
251  You should call this after you've "unloaded" a tile
252  and all its associated textures.
253  */
254  virtual void AckUnload(void);
255 
256 
257  /* Stop paging entirely. Call this right before you want to
258  shut down paging. Everything active will wind up on the
259  unload lists. Then you can unload those tiles and move on.
260  */
261  virtual bool Stop(void);
262 
264  virtual void Print(trpgPrintBuffer &);
265 
266 protected:
268 
271 
272  /* Information associated with each terrain level of
273  detail as related to paging.
274  */
276  friend class trpgPageManager;
277  public:
278  LodPageInfo(void);
279  virtual ~LodPageInfo(void);
280 
281  /* Initializes the class with its current LOD.
282  It figures out all the rest.
283  */
284  virtual bool Init(trpgr_Archive *, int myLod, double scale, int freeListDivider = 1);
285 
286  /* Reset the location. This forces a recalculation
287  of what to load and unload if the cell has changed
288  or if this is the first SetLocation.
289  The location passed in must be relative to the southwest
290  corner of the TerraPage archive.
291  */
292  virtual bool SetLocation(trpg2dPoint &);
293 
295  virtual trpgManagedTile *GetNextLoad(void);
298  virtual void AckLoad();
299 
301  //bool GetLoadedTile
302 
304  virtual trpgManagedTile *GetNextUnload(void);
307  virtual void AckUnload(void);
310  virtual bool Stop(void);
312  virtual void Print(trpgPrintBuffer &);
313 
314  const trpg2iPoint& GetLodSize() const
315  {
316  return lodSize;
317  }
318 
319  int GetLod() const
320  {
321  return lod;
322  }
323 
324  double GetPageDistance() const
325  {
326  return pageDist;
327  }
328 
329  const trpg2dPoint& GetCellSize() const
330  {
331  return cellSize;
332  }
333 
335  const trpg2iPoint& GetAreaOfInterest() const
336  {
337  return aoiSize;
338  }
339 
340 
343  const trpg2iPoint& GetCellPagingLocation() const
344  {
345  return cell;
346  }
347 
348  protected:
349  virtual void Clean(void);
350  virtual void Update(void);
351 
354  bool AddToLoadList(int x, int y, const trpgwAppAddress& addr);
355 
359  void AddChildrenToLoadList(std::vector<trpgManagedTile*>& parentList);
360 
362  bool isWithin(trpgManagedTile *,trpg2iPoint &sw,trpg2iPoint &ne);
363 
366  void GetLoadedTileWithin(double pagingDistance, std::vector<trpgManagedTile*>& tileList);
367 
368  bool valid;
369 
371  int lod;
372 
373  /* Adjusted (e.g. paranoid) distance outward from
374  which to page this terrain LOD. This takes into
375  account the distance in the header as well as
376  any factor the user may have added.
377  */
378  double pageDist;
379 
380  /* Max tiles we could have loaded in at any given time.
381  This is just a guess because it's up to the user
382  to load (and, more importantly) unload.
383  */
385 
388 
391 
392  /* Area of interest size in cells
393  This is a linear distance "ahead" of the center cell.
394  */
396 
397  /* Our effective paging location sits at the middle
398  of this cell. We don't recalculate unless the
399  cell changes. */
401 
403  std::deque<trpgManagedTile *> load;
405  std::deque<trpgManagedTile *> unload;
407  std::deque<trpgManagedTile *> current;
408 
410  std::vector<bool> tmpCurrent;
411 
418 
420  std::deque<trpgManagedTile *> freeList;
421 
424 
426  };
427 
429  std::vector<LodPageInfo> pageInfo;
430 
432  typedef enum {Load,Unload,None} LoadType;
433  /* Information about what the pending load/unload operation
434  is. It's up to the user to complete and acknowledge it.
435  */
438  int lastLod;
441 
443  double scale;
444 
446  typedef std::map<int,void *> ManageGroupMap;
448 
451 
452  bool valid;
453 };
454 
462 {
463 public:
464  void *Parse(trpgToken tok, trpgReadBuffer& rbuf);
466  unsigned int GetNbChildren() const;
469  const trpgChildRef& GetChildRef(unsigned int idx) const;
470 
472  void Reset();
473 protected:
480  typedef std::vector<trpgChildRef> ChildList;
482 };
483 
484 /* Page Manager Tester. This class tests a given paging manager
485  by applying likely
486 */
488 {
489 public:
491  virtual ~trpgPageManageTester();
492 
493  /* Initialize the tester with a paging manager
494  and an archive.
495  */
497 
498  /* Feeds the paging manager coordinates starting from
499  the lower left to upper right of the database in the
500  given increment.
501  */
502  void Fly_LL_to_UR(double dist=100.0);
503 
504  /* Jumps around randomly within the archive loading and
505  unloading as needed.
506  */
507  void RandomTest(int no=100,int seed=-1);
508 
509 protected:
510 
512  void ProcessChanges();
513 
517 
520 
522  int majorVersion, minorVersion;
523 };
524 
525 #endif

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)