trpage_managers.h
来自「最新osg包」· C头文件 代码 · 共 525 行 · 第 1/2 页
H
525 行
/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */#ifndef _trpage_managers_h_#define _trpage_managers_h_#include <deque>/* This file contains class definitions for managers that help you keep track of data related to paging. For instance, which tiles to load in at any given time and what textures you need to read for a given tile. */class trpgPageManager;// Grid and file location of a tilestruct TileLocationInfo{ TileLocationInfo(): x(-1), y(-1), lod(-1) {} TileLocationInfo(int gx, int gy, int glod, const trpgwAppAddress& gaddr): x(gx), y(gy), lod(glod), addr(gaddr) {} int x, y, lod; trpgwAppAddress addr;};/* Managed Tiles are used by the trpgPageManager to keep track of which tiles are loaded and what textures (and models) they need loaded into memory with them. */TX_EXDECL class TX_CLDECL trpgManagedTile{ friend class trpgPageManager; public: trpgManagedTile(void); // Called to clear any info out of this tile void Reset(void); /* Call this when you hit a tile header in your own Scene parser callback. The managed tile can then keep track of which textures and models go with this tile. */ bool ParseTileHeader(trpgReadBuffer &); // Check if the tile is loaded (e.g. the header read in) bool IsLoaded(void); /* Set the tile location. This resets any internal state we may be keeping. */ bool SetTileLoc(int x,int y,int lod); // Get the tile location bool GetTileLoc(int &x,int &y,int &lod) const; // In version 2.1 we no longer have the tile table to // find the tiles, only by traversing the parent can it be // found. So when we have this info, this is were to save it. void SetTileAddress(const trpgwAppAddress& gAddr); void SetTileAddress(int32 file, int32 offset); const trpgwAppAddress& GetTileAddress() const; // Return a pointer to the tile header const trpgTileHeader *GetTileHead(void); /* Return a pointer to the list of locally defined materials. As soon as the tile header is read by ParseTileHeader (which you call) you'll want to get this list and load the pageable textures. You can use SetMatData to keep track of our internal texture structures. */ const std::vector<trpgLocalMaterial> *GetLocMatList(void) const; /* Returns a pointer to a single local material, if within the valid range of local materials for this tile. */ const trpgLocalMaterial *GetLocMaterial(int id) const; /* Set Local Data for managed tile. The local data would probably be a pointer to the top of the scene graph you're using to represent just this tile. */ void SetLocalData(void *); /* Returns the local data you set with SetLocalData. */ void *GetLocalData(void) const; /* Associates a void * with one of the materials referenced within this tile. The idea here is that you'll want to load the texture for a given local material and then pass your own internal texture structure into here as a void *. That way, the trpgPageManager will keep track of which textures you should unload when this tile goes out of range. */ bool SetMatData(int id,void *); /* Gets the void * data you associated with a given local material index. See SetMatData for more information. */ void *GetMatData(int id) const; /* Add Group ID to this tile. This is called by the page manager to keep track of which group IDs belong to this tile. We use this information to NULL out the appropriate positions in the group map help by the page manager. */ void AddGroupID(int id); /* Retrieve the list of group IDs for this tile. */ const std::vector<int> *GetGroupIDs(void) const; /* Print the current status and information about this managed Tile. */ void Print(trpgPrintBuffer &); // Children info, will throw exception if child index is out of bound unsigned int GetNbChildren() const { return (unsigned int)childLocationInfo.size(); } bool SetChildLocationInfo(int childIdx, int x, int y, const trpgwAppAddress& addr); bool SetChildLocationInfo(int childIdx, const TileLocationInfo& info); const TileLocationInfo& GetChildLocationInfo(int childIdx) const; bool GetChildTileLoc(int childIdx, int &x,int &y,int &lod) const; const trpgwAppAddress& GetChildTileAddress(int childIdx) const; protected: // Set if a tile is currently loaded bool isLoaded; // Tile location info TileLocationInfo location; // Tile Header associated with this tile trpgTileHeader tileHead; // Data to keep associated with each individual local material index std::vector<void *> localMatData; // Used to keep track of group IDs in this tile std::vector<int> groupIDs; // Local data (probably the top of the local scene graph) void *localData; // What are the children: this to be used for version 2.1 and up. // Both vector should have the same size std::vector<TileLocationInfo> childLocationInfo; // Note: Should do models too if anyone wanted them.};/* The Page Manager is a helper class that can be used to keep track of: (1) which tiles need to be loaded into memory for a given viewer position, (2) which tiles are currently loaded and (3) which tiles need to be unloaded when the viewer position moves. The tile list this class generates is guaranteed to be in the right order for loading. You would use this class if you're implementing a TerraPage reader for your visual run-time system.*/TX_EXDECL class TX_CLDECL trpgPageManager{ public: trpgPageManager(void); virtual ~trpgPageManager(void); // Initialize with an archive virtual void Init(trpgr_Archive *); virtual void Init(trpgr_Archive *inArch, int maxLod); /* Set Paging Distance This is the extra distance outside the visible range we want to page. The defaults will be valid. You would set this if you want to pull tiles in earlier. Be sure to call it before you call Init(), however. */ virtual bool SetPageDistFactor(double); /* Updates the current location for paging purposes. Returns true if any load or unloads need to happen. */ virtual bool SetLocation(trpg2dPoint &); /* Get next tile to load. The paging manager is keeping track of which tiles need to be loaded and in what order. This method returns a pointer to the next one. The user is expected to call AckLoad() after the tile is loaded. */ virtual trpgManagedTile *GetNextLoad(void); /* Acknowledge Tile Load. This method should be called when a tile has been loaded by the caller. This method is used in conjunction with GetNextLoad(). Version 2.1 and over supports variable lod so that we cannot know from the tile table if a tile exist or not. So to manage this the user must parse the loaded tile and extract its list of children and pass it on to AckLoad() which will add to the appropriate lod list the children info. If this is not done then only lod 0 will be pageable. */ virtual void AckLoad(std::vector<TileLocationInfo> const& children); // Using this call with version 2.1 and over will only page lod 0 tiles virtual void AckLoad(); /* Add Group ID to map. This should be called when the user encounters a group-like object while processing the scene graph data from a tile. The groupId is given by TerraPage and the data should be the corresponding group object that the user creates in their own scenegraph toolkit. This information can then be retrieved later by GetGroupData(). */ virtual void AddGroupID(trpgManagedTile *,int groupID,void *data); /* Get Group Data fetches the data cached by the user and associated with the given groupID. This would be used in conjunction with trpgAttach nodes to implement geometry paging. */ virtual void *GetGroupData(int groupID); /* Get next tile to unload. The paging manager keeps track of which tiles need to be unloaded based on a change of location. It's best if you unload tiles before loading them, but that's really up to you. */ virtual trpgManagedTile *GetNextUnload(void); /* Acknowledge a tile unload. You should call this after you've "unloaded" a tile and all its associated textures. */ virtual void AckUnload(void); /* Stop paging entirely. Call this right before you want to shut down paging. Everything active will wind up on the unload lists. Then you can unload those tiles and move on. */ virtual bool Stop(void); // Print current status and content information virtual void Print(trpgPrintBuffer &);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?