예제 #1
0
	//-----------------------------------------------------------------------
	void PagingLandScapePage::setNeighbor(Neighbor n, PagingLandScapePage* p)
	{
		// set page neighbor
		mNeighbors[n] = p;
	 
		// if neigther are loaded, nothing else to do
		const bool thisLoaded = isLoaded();
		const bool neighLoaded = p && p->isLoaded();
		if (!thisLoaded && !neighLoaded) {
			return;
		}

		assert (!thisLoaded || (thisLoaded && !mTiles.empty()));

		// tiles, 0 if not loaded
		PagingLandScapeTile* tileInCurrPage = 0;
		PagingLandScapeTile* tileInNeighborPage = 0;

		// indices for borders
		const unsigned int iNorthBorder = 0;
		const unsigned int iSouthBorder = mNumTiles - 1;
		const unsigned int iEastBorder = mNumTiles - 1;
		const unsigned int iWestBorder = 0;

		// walk the tiles in each border, and set roles accordingly
		switch (n) {
		case EAST:
		{
			for (unsigned int j = 0; j < mNumTiles; ++j) {
				if (thisLoaded) {
					// tiles of this page along east border
					tileInCurrPage = mTiles[iEastBorder][j];
				}

				if (neighLoaded) {
					// tiles of neighbor page along west border
					tileInNeighborPage = p->getTile(iWestBorder, j);
				}

				// set neighbor tiles
				if (tileInCurrPage) {
					tileInCurrPage->_setNeighbor(EAST, tileInNeighborPage);
				}
				if (tileInNeighborPage) {
					tileInNeighborPage->_setNeighbor(WEST, tileInCurrPage);
				}
			}
		}
		break;
		case WEST:
		{
			for (unsigned int j = 0; j < mNumTiles; ++j) {
				if (thisLoaded) {
					// tiles of this page along west border
					tileInCurrPage = mTiles[iWestBorder][j];
				}

				if (neighLoaded) {
					// tiles of neighbor page along east border
					tileInNeighborPage = p->getTile(iEastBorder, j);
				}

				// set neighbor tiles
				if (tileInCurrPage) {
					tileInCurrPage->_setNeighbor(WEST, tileInNeighborPage);
				}
				if (tileInNeighborPage) {
					tileInNeighborPage->_setNeighbor(EAST, tileInCurrPage);
				}
			}
		}
		break;
		case NORTH:
		{
			for (unsigned int i = 0; i < mNumTiles; ++i) {
				if (thisLoaded) {
					// tiles of this page along north border
					tileInCurrPage = mTiles[i][iNorthBorder];
				}

				if (neighLoaded) {
					// tiles of neighbor page along south border
					tileInNeighborPage = p->getTile(i, iSouthBorder);
				}

				// set neighbor tiles
				if (tileInCurrPage) {
					tileInCurrPage->_setNeighbor(NORTH, tileInNeighborPage);
				}
				if (tileInNeighborPage) {
					tileInNeighborPage->_setNeighbor(SOUTH, tileInCurrPage);
				}
			}
		}
		break;
		case SOUTH:
		{
			for (unsigned int i = 0; i < mNumTiles; ++i) {
				if (thisLoaded) {
					// tiles of this page along south border
					tileInCurrPage = mTiles[i][iSouthBorder];
				}

				if (neighLoaded) {
					// tiles of neighbor page along north border
					tileInNeighborPage = p->getTile(i, iNorthBorder);
				}

				// set neighbor tiles
				if (tileInCurrPage) {
					tileInCurrPage->_setNeighbor(SOUTH, tileInNeighborPage);
				}
				if (tileInNeighborPage) {
					tileInNeighborPage->_setNeighbor(NORTH, tileInCurrPage);
				}
			}
		}
		break;
		default:
			break;
		}
	}
예제 #2
0
	//-----------------------------------------------------------------------
	void PagingLandScapePage::load()
	{
		touch();

		if (isLoaded()) {
			S_LOG_WARNING("PagingLandScapePage at (" << mTableX << ", " << mTableZ << ") already loading/loaded, ignoring load() request");
			return;
		}

		S_LOG_VERBOSE("Loading PagingLandScapePage at (" << mTableX << ", " << mTableZ << ")");

		if (mPageState == STATE_INITED) {
			preloadInBackground();
			// it takes a while to do it, so we don't bother trying to load and failing
			return;
		}

		if (mPageState == STATE_PRELOADED) {

			// load texture
			S_LOG_VERBOSE("Loading texture for PagingLandScapePage at (" << mTableX << ", " << mTableZ << ")");
			mPageMgr.getSceneManager()->getTextureManager()->load(mTableX, mTableZ);

			// initialize tile containers
			mTiles.reserve(mNumTiles);
			mTiles.resize(mNumTiles);
			for (size_t i = 0; i < mNumTiles; ++i) {
				mTiles[i].reserve(mNumTiles);
				mTiles[i].resize(mNumTiles);
			}

			// initialize tiles
			PagingLandScapeTileManager* tileMgr = mPageMgr.getSceneManager()->getTileManager();
			for (size_t i = 0; i < mTiles.size(); ++i) {
				for (size_t j = 0; j < mTiles[i].size(); ++j) {
					PagingLandScapeTile* tile = tileMgr->getTile();
					assert (tile);
					mTiles[i][j] = tile;
					tile->init(mPageNode, mTableX, mTableZ, i, j);

					// set up tile neighbors within page
					if (j > 0) {
						PagingLandScapeTile* northTile = mTiles[i][j-1];
						tile->_setNeighbor(NORTH, northTile);
						northTile->_setNeighbor(SOUTH, tile);
					}
					if (i > 0) {
						PagingLandScapeTile* westTile = mTiles[i-1][j];
						tile->_setNeighbor(WEST, westTile);
						westTile->_setNeighbor(EAST, tile);    
					}
				}
			}

			// set new state
			mPageState = STATE_LOADED;

			// set page neighbors
			setNeighbors();

			// fire event
			fireEvent(EVENT_LOADED);

		} else if (mPageState == STATE_PRELOADING) {
			// wait...
			return;
		} else {
			S_LOG_WARNING("PagingLandScapePage at (" << mTableX << ", " << mTableZ << ") already loaded, proceeding to show it");
		}

		show(true);
	}