void CameraFocusedGrid2DPageStrategy::loadNearestPages(const Vector2& gridpos, PagedWorldSection* section) { //Get all pages that are within 100 meters and load them instantly. std::set<Ogre::PageID> pagesToLoad; Grid2DPageStrategyData* stratData = dynamic_cast<Grid2DPageStrategyData*>(section->getStrategyData()); auto calculatePageId = [&](const Ogre::Vector2& pos) { Ogre::int32 x, y; stratData->determineGridLocation(pos, &x, &y); pagesToLoad.insert(stratData->calculatePageID(x, y)); }; calculatePageId(gridpos); calculatePageId(gridpos + Ogre::Vector2(100, 100)); calculatePageId(gridpos + Ogre::Vector2(100, -100)); calculatePageId(gridpos + Ogre::Vector2(-100, 100)); calculatePageId(gridpos + Ogre::Vector2(-100, -100)); for (auto& pageId : pagesToLoad) { section->loadPage(pageId, false); } }
void SynchronousGrid2DPageStrategy::notifyCamera(Camera* cam, PagedWorldSection* section) { Grid2DPageStrategyData* stratData = static_cast<Grid2DPageStrategyData*>(section->getStrategyData()); const Vector3& pos = cam->getDerivedPosition(); Vector2 gridpos; stratData->convertWorldToGridSpace(pos, gridpos); int32 x, y; stratData->determineGridLocation(gridpos, &x, &y); Real loadRadius = stratData->getLoadRadiusInCells(); Real holdRadius = stratData->getHoldRadiusInCells(); // scan the whole Hold range Real fxmin = (Real)x - holdRadius; Real fxmax = (Real)x + holdRadius; Real fymin = (Real)y - holdRadius; Real fymax = (Real)y + holdRadius; int32 xmin = stratData->getCellRangeMinX(); int32 xmax = stratData->getCellRangeMaxX(); int32 ymin = stratData->getCellRangeMinY(); int32 ymax = stratData->getCellRangeMaxY(); // Round UP max, round DOWN min xmin = fxmin < xmin ? xmin : (int32)floor(fxmin); xmax = fxmax > xmax ? xmax : (int32)ceil(fxmax); ymin = fymin < ymin ? ymin : (int32)floor(fymin); ymax = fymax > ymax ? ymax : (int32)ceil(fymax); // the inner, active load range fxmin = (Real)x - loadRadius; fxmax = (Real)x + loadRadius; fymin = (Real)y - loadRadius; fymax = (Real)y + loadRadius; // Round UP max, round DOWN min int32 loadxmin = fxmin < xmin ? xmin : (int32)floor(fxmin); int32 loadxmax = fxmax > xmax ? xmax : (int32)ceil(fxmax); int32 loadymin = fymin < ymin ? ymin : (int32)floor(fymin); int32 loadymax = fymax > ymax ? ymax : (int32)ceil(fymax); for (int32 cy = ymin; cy <= ymax; ++cy) { for (int32 cx = xmin; cx <= xmax; ++cx) { PageID pageID = stratData->calculatePageID(cx, cy); if (cx >= loadxmin && cx <= loadxmax && cy >= loadymin && cy <= loadymax) { // in the 'load' range, request it // **synchronously** section->loadPage(pageID, true); } else { // in the outer 'hold' range, keep it but don't actively load section->holdPage(pageID); } // other pages will by inference be marked for unloading } } }