Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Ogre::TerrainPageSource Class Reference

Abstract class which describes the interface which a source of terrain pages must implement. More...

#include <OgreTerrainPageSource.h>

Inheritance diagram for Ogre::TerrainPageSource:

Ogre::HeightmapTerrainPageSource List of all members.

Public Member Functions

 TerrainPageSource ()
virtual ~TerrainPageSource ()
virtual void initialise (TerrainSceneManager *tsm, ushort tileSize, ushort pageSize, bool asyncLoading, TerrainPageSourceOptionList &optionList)
 Initialise this tile source based on a series of options as dictated by the scene manager.

virtual void shutdown (void)
 Shut down this tile source, freeing all it's memory ready for decommissioning.

virtual void requestPage (ushort x, ushort z)=0
 Requests a new page of tiles from the source.

virtual void expirePage (ushort x, ushort z)=0
 This notifies the tile source that the specified page of tiles has been automatically detached.


Static Public Member Functions

void addListener (TerrainPageSourceListener *pl)
 Register a class which will be called back whenever a new page is available.

void removeListener (TerrainPageSourceListener *pl)
 Unregister a class which will be called back whenever a new page is available.


Protected Member Functions

virtual TerrainPagebuildPage (Real *heightData, const MaterialPtr &pMaterial)
 Utility method for building a page of tiles based on some source data, wherever that may have come from.


Static Protected Member Functions

void firePageConstructed (size_t pagex, size_t pagez, Real *heightData)
 Internal method for firing pageContructed events.


Protected Attributes

TerrainSceneManagermSceneManager
 Link back to parent manager.

bool mAsyncLoading
 Has asynchronous loading been requested?

unsigned short mPageSize
 The expected size of the page in number of vertices.

unsigned short mTileSize
 The expected size of a tile in number of vertices.


Detailed Description

Abstract class which describes the interface which a source of terrain pages must implement.

Remarks:
The TerrainSceneManager can accept external classes as providers of terrain data, to allow terrain height data to come from anywhere the user application may choose, and additionally to support on-demand loading an unloading of terrain data. Providers must suclass this class, and implement the abstract methods (details are described within each method)
The overall sequence of events is this:
  1. TerrainSceneManager is created as usual, and options such as tile size etc are set.
  2. CustomTerrainPageSource is registered with TerrainSceneManager by calling registerPageSource(), registering a particular named type of source data with this tile source.
  3. TerrainSceneManager::setWorldGeometry is called. Depending on the configuration, this will call one of the page source classes initialise methods, when the scene manager will communicate it's preferred options. It does not have to load anything immediately on this call (especially if the terrain options include paging). It will also set this tile source as the primary.
  4. As and when TerrainSceneManager requires more tiles (and this will either be done all up-front, or progressively depending on paging settings) it will call the primary tile source's requestPage() method, with the page it requires.
  5. It is then the responsibility of the tile source to prepare TerrainRenderable instances for the page(s) requested, and to attach them to the TerrainSceneManager. Note that preparing the tiles does not involve modifying any shared data so may be done in an alternate thread, if required. Attaching them must be done synchronously though.
  6. When paging, the TerrainSceneManager will request tiles in advance, within it's 'buffer zone' so some delay in loading is acceptable. It will also indicate when tiles are no longer required (and will detach them); it is up to the tile source whether that memory is actually freed or held for a while longer.
Note:
The comments on paging above are in principle, the implementation of paging in this manager is not present yet but the system is designed to extend to it. For now, all tiles are requested up-front.

Definition at line 131 of file OgreTerrainPageSource.h.


Constructor & Destructor Documentation

Ogre::TerrainPageSource::TerrainPageSource  ) 
 

virtual Ogre::TerrainPageSource::~TerrainPageSource  )  [virtual]
 

Definition at line 158 of file OgreTerrainPageSource.h.


Member Function Documentation

void Ogre::TerrainPageSource::addListener TerrainPageSourceListener pl  )  [static]
 

Register a class which will be called back whenever a new page is available.

Remarks:
Since this method is static, it applies to any page source which is in active use; there is no need to register one per source.

virtual TerrainPage* Ogre::TerrainPageSource::buildPage Real heightData,
const MaterialPtr pMaterial
[protected, virtual]
 

Utility method for building a page of tiles based on some source data, wherever that may have come from.

Remarks:
It is expected that this height data is represented in the range [0..1], which will be duly scaled by the TerrainRenderables it creates.

virtual void Ogre::TerrainPageSource::expirePage ushort  x,
ushort  z
[pure virtual]
 

This notifies the tile source that the specified page of tiles has been automatically detached.

Remarks:
When paging is enabled, tiles go out of scope and the TerrainSceneManager detaches them automatically, notifying the TerrainPageSource that this has happened. The tile source can choose to either keep these tiles in memory (incase they are requested again) or can delete them if it wishes to free memory. This freeing does not need to be done before the return of this method - like requesting tiles, the freeing of them can be done in another thread or across many frames if required, since the shared data in TerrainSceneManager has already been updated synchronously when the page was detached.
Parameters:
x The x index of the page expired
z The z index of the page expired

Implemented in Ogre::HeightmapTerrainPageSource.

void Ogre::TerrainPageSource::firePageConstructed size_t  pagex,
size_t  pagez,
Real heightData
[static, protected]
 

Internal method for firing pageContructed events.

virtual void Ogre::TerrainPageSource::initialise TerrainSceneManager tsm,
ushort  tileSize,
ushort  pageSize,
bool  asyncLoading,
TerrainPageSourceOptionList optionList
[virtual]
 

Initialise this tile source based on a series of options as dictated by the scene manager.

Parameters:
tsm The TerrainSceneManager doing the initialising. This should be allowed NULL, for use by external tools if they want to read data generically without necessarily having a real scene manager involved
tileSize The number of horizontal (and hence also vertical) vertices in a single tile (which is a TerrainRenderable). This will always be (2^n)+1.
pageSize The number of horizontal (and hence also vertical) vertices in a single page. This will always be (2^n)+1.
asyncLoading True if the scene manager would like the tile source to load tiles asynchronously. It does not have to do this, although if it does not when requested, it will likely result in stalls in the terrain rendering.
optionList A list of name/value pairs describing custom options for this particular page source. The expected convention for option names is "TypeName.OptionName", where TypeName is the type under which this page source has been registered.

Reimplemented in Ogre::HeightmapTerrainPageSource.

Definition at line 180 of file OgreTerrainPageSource.h.

References Ogre::TerrainPageSourceOptionList, and Ogre::ushort.

void Ogre::TerrainPageSource::removeListener TerrainPageSourceListener pl  )  [static]
 

Unregister a class which will be called back whenever a new page is available.

virtual void Ogre::TerrainPageSource::requestPage ushort  x,
ushort  z
[pure virtual]
 

Requests a new page of tiles from the source.

Remarks:
The TerrainSceneManager will call this method when it needs new tiles. In response, this class must prepare TerrainRenderable instances for the page requested and attach the entire page when ready using TerrainSceneManager::attachTerrainPage.
Now, the tile source does not necessarily need to do all that before the return of this method. If it likes, and particularly if asynchronous loading is enabled, it can merely queue this request, and process it either in another thread, or over a series of frames. The key thing is that attaching the new page has to be done synchronously with the main rendering loop in order to avoid concurrency issues; other than that, you are free to load and prepare new tiles in a concurrent fashion if you like.
Typically the scene manager will request at least one page up-front, with the possibility of requesting more if paging is enabled.
Parameters:
x The x index of the page requested
z The z index of the page requested

Implemented in Ogre::HeightmapTerrainPageSource.

virtual void Ogre::TerrainPageSource::shutdown void   )  [virtual]
 

Shut down this tile source, freeing all it's memory ready for decommissioning.

Remarks:
This method will normally just be called on destruction; however it may also be called by the TerrainSceneManager if another source is provided for the same type of tile source.

Reimplemented in Ogre::HeightmapTerrainPageSource.

Definition at line 196 of file OgreTerrainPageSource.h.


Member Data Documentation

bool Ogre::TerrainPageSource::mAsyncLoading [protected]
 

Has asynchronous loading been requested?

Definition at line 137 of file OgreTerrainPageSource.h.

unsigned short Ogre::TerrainPageSource::mPageSize [protected]
 

The expected size of the page in number of vertices.

Definition at line 139 of file OgreTerrainPageSource.h.

TerrainSceneManager* Ogre::TerrainPageSource::mSceneManager [protected]
 

Link back to parent manager.

Definition at line 135 of file OgreTerrainPageSource.h.

unsigned short Ogre::TerrainPageSource::mTileSize [protected]
 

The expected size of a tile in number of vertices.

Definition at line 141 of file OgreTerrainPageSource.h.


The documentation for this class was generated from the following file:

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 13:06:27 2006