Posted on 2011-10-17 11:26
点点滴滴 阅读(191)
评论(0) 编辑 收藏 引用
void Grid2DPageStrategy::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
section->loadPage(pageID);
}
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
}
}
}