I thought Ogre's terrain sample contained an example of the paging system. Actually, I believe it references TerrainPaging and TerrainPagingWorldSection. These two files are found in the Terrain component. These two files implements classes from the Paging component.
In my system I do this (I'm little bit tired right now so I may be making no sense):
Basically you will need a Ogre::PageManager. This PageManager manages Ogre Paging. You will need to use this object to create an Ogre::World and also register a factory object which creates Ogre::WorldSection.
For the actual paging, on the top-most level there is the Ogre::PageWorld (you can reference Ogre's docs for the specifics) which contains Ogre::WorldSections. You will need to derive WorldSections and implement the WorldSection's interfaces to do the actual paging is done. There is also a PageProvider which I suppose provides procedural page generation but Ogre terrain's sample doesn't use this, it only has a DummyPageProvider which does nothing. So I followed suite.
For example, in my child WorldSection class's overridden virtual method I have:
Code:
/**
* THis method hooks into volume maps for creating pages.
*/
void
VolumePagedWorldSection::loadPage(PageID pageID, bool forceSynchronous)
{
if (!mParent->getManager()->getPagingOperationsEnabled())
return;
PageMap::iterator i = mPages.find(pageID);
if (i == mPages.end())
{
long x, y;
_unpackIndex(pageID, &x, &y);
std::stringstream ss;
ss << "++++++++++++++Load PageID: " << x << "," << -y << "++++++++++++++++\n";
Ogre::LogManager::getSingleton().logMessage(Ogre::LML_NORMAL, ss.str());
_volumeMap->loadPage(pageID);
}
PagedWorldSection::loadPage(pageID, forceSynchronous);
}
You can reference Ogre's terrain sample for all of this. Notice how I'm calling _volumeMap->loadPage(pageID). _volumeMap is my own class which handles the paging. Of course you will have to attach _volumeMap at some point.
To make all this work, I have a function (actually it's a class) which has this function:
Code:
VolumePagedWorldSection*
VolumeMapPaging::createWorldSection(PagedWorld* world, VolumeMap* volumeMap, Real loadRadius, Real holdRadius, Ogre::int32 minX, Ogre::int32 minY, Ogre::int32 maxX, Ogre::int32 maxY,
SceneManager* scnMgr, const String& sectionName)
{
VolumePagedWorldSection* ret = static_cast<VolumePagedWorldSection*> (world->createSection(scnMgr, SectionFactory::FACTORY_NAME, sectionName));
ret->init(volumeMap);
ret->setLoadRadius(loadRadius);
ret->setHoldRadius(holdRadius);
ret->setPageRange(minX, minY, maxX, maxY);
return ret;
}
This creates the world section. By this point you will need to have registered the world section factory with Ogre::PageManager.
(Again, all this is can be found in Ogre's terrain sample. I duplicated that system in it's entirety. I may alter this sometime down the line).
Here is the code to initialize everything:
Code:
void
WorldController::_loadWorldMap(WorldMapConfig &config)
{
//_worldMap.reset(new WorldMap());
//_worldMap->load(); //We should implement load from configuration file.
size_t numOfPagesPerAxis = (config.unloadRadius / WORLD_BLOCK_WIDTH * 2 + 1);
size_t numOfPagesPerAxisInView = (config.loadRadius / WORLD_BLOCK_WIDTH * 2 + 1);
//_volumeMap.reset(new VolumeMap(_scnMgr, numOfPagesPerAxis, config.forceSync));
_volumeMap.reset(new VolumeMap(_scnMgr, numOfPagesPerAxis,
numOfPagesPerAxisInView,
config.forceSync,
config.forceBlock));
_volumeMap->load(_physicsMgr.get());
_pageManager.setPageProvider(&_pageProvider);
_pageManager.addCamera(_cam);
_volumePaging = OGRE_NEW_T(VolumeMapPaging(&_pageManager),
Ogre::MEMCATEGORY_GENERAL);
Ogre::PagedWorld* world = _pageManager.createWorld();
_volumePaging->createWorldSection(world, _volumeMap.get(), config.loadRadius,
config.unloadRadius, config.minx, config.miny,
config.maxx, config.maxy,
_scnMgr);
}