Beispiel #1
0
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 OverhangTerrainPagedWorldSection::syncSettings()
	{
		// Base grid on terrain settings
		Grid2DPageStrategyData * gridData = getGridStrategyData();

		switch (_pOhGrp->options.alignment)
		{
		case ALIGN_X_Y:
			gridData->setMode(G2D_X_Y);
			break;
		case ALIGN_X_Z:
			gridData->setMode(G2D_X_Z);
			break;
		case ALIGN_Y_Z:
			gridData->setMode(G2D_Y_Z);
			break;
		}

		gridData->setOrigin(_pOhGrp->getOrigin());
		gridData->setCellSize(_pOhGrp->options.getPageWorldSize());
	}
    //---------------------------------------------------------------------
    void TerrainPagedWorldSection::syncSettings()
    {

        // Base grid on terrain settings
        Grid2DPageStrategyData* gridData = getGridStrategyData();
        switch (mTerrainGroup->getAlignment())
        {
        case Terrain::ALIGN_X_Y:
            gridData->setMode(G2D_X_Y);
            break;
        case Terrain::ALIGN_X_Z:
            gridData->setMode(G2D_X_Z);
            break;
        case Terrain::ALIGN_Y_Z:
            gridData->setMode(G2D_Y_Z);
            break;
        }
        gridData->setOrigin(mTerrainGroup->getOrigin());

        gridData->setCellSize(mTerrainGroup->getTerrainWorldSize());

    }
Beispiel #4
0
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
		}
	}
}