/** * If tile borders empty space, moves tile and returns true, else * returns false. */ bool move(int tile) { // Check whether tile is on the board if (findTile(tile)) { // Check to see if blank tile's row position is equal to selected tile's row position if (blank_row + 1 == found_row || blank_row - 1 == found_row) { // To ensure only selecting tile below or above blank tile (column position stays the same) if (blank_col == found_col) { swap_tiles(); return true; } } // Check to see if blank tile's column position is equal to selected tile's column position if (blank_col + 1 == found_col || blank_col - 1 == found_col) { // To ensure only selecting tiles left or right of blank tile (row position stays the same) if (blank_row == found_row) { swap_tiles(); return true; } } } return false; }
void HydroFlowProducer::putTile(TileCache::Tile *t) { TileProducer::putTile(t); if (t->level > 0) { TileCache::Tile *t2 = findTile(t->level - 1, t->tx / 2, t->ty / 2); assert(t2 != NULL); putTile(t2); } TileCache::Tile *t2 = graphs->findTile(t->level, t->tx, t->ty); graphs->putTile(t2); }
void HydroFlowProducer::stopCreateTile(int level, int tx, int ty) { TileProducer::stopCreateTile(level, tx, ty); if (level > 0) { TileCache::Tile *t = findTile(level - 1, tx / 2, ty / 2); assert(t != NULL); putTile(t); } TileCache::Tile *t = graphs->findTile(level, tx, ty); assert(t != NULL); graphs->putTile(t); }
void CPUElevationProducer::stopCreateTile(int level, int tx, int ty) { if (level > 0) { TileCache::Tile *t = findTile(level - 1, tx / 2, ty / 2); assert(t != NULL); putTile(t); } int tileSize = getCache()->getStorage()->getTileSize() - 5; int residualTileSize = residualTiles->getCache()->getStorage()->getTileSize() - 5; int mod = residualTileSize / tileSize; if (residualTiles->hasTile(level, tx / mod, ty / mod)) { TileCache::Tile *t = residualTiles->findTile(level, tx / mod, ty / mod); assert(t != NULL); residualTiles->putTile(t); } }
bool TileMap::addTile( Tile* t, int palNum, bool optimizeFlag ) { int index= findTile( t ); if ( index == -1 || !optimizeFlag ) { tiles.push_back( t ); map.push_back( new MapAttribute( mode, (tileOffset + (tileCount++)), palNum) ); } else { if ( hasEmptyTile ) map.push_back( new MapAttribute( mode, index+1, palNum ) ); else map.push_back( new MapAttribute( mode, index, palNum ) ); } mapSize++; }
bool CPUElevationProducer::doCreateTile(int level, int tx, int ty, TileStorage::Slot *data) { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "CPUElevation tile " << getId() << " " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("DEM", oss.str()); } CPUTileStorage<float>::CPUSlot *cpuData = dynamic_cast<CPUTileStorage<float>::CPUSlot*>(data); assert(cpuData != NULL); int tileWidth = data->getOwner()->getTileSize(); int tileSize = tileWidth - 5; CPUTileStorage<float>::CPUSlot *parentCpuData = NULL; if (level > 0) { TileCache::Tile *t = findTile(level - 1, tx / 2, ty / 2); assert(t != NULL); parentCpuData = dynamic_cast<CPUTileStorage<float>::CPUSlot*>(t->getData()); assert(parentCpuData != NULL); } int residualTileWidth = residualTiles->getCache()->getStorage()->getTileSize(); int mod = (residualTileWidth - 2 * residualTiles->getBorder() - 1) / tileSize; int rx = (tx % mod) * tileSize; // select the xy coord in residual int ry = (ty % mod) * tileSize; TileCache::Tile *t = residualTiles->findTile(level, tx / mod, ty / mod); CPUTileStorage<float>::CPUSlot *cpuTile = NULL; bool hasResidual = residualTiles->hasTile(level, tx / mod, ty / mod); if (hasResidual) { assert(t != NULL); cpuTile = dynamic_cast<CPUTileStorage<float>::CPUSlot*>(t->getData()); assert(cpuTile != NULL); } int px = 1 + (tx % 2) * tileSize / 2; //select the xy coord in the parent tile int py = 1 + (ty % 2) * tileSize / 2; float *parentTile = NULL; if (level > 0) { parentTile = parentCpuData->data; } for (int j = 0; j < tileWidth; ++j) { for (int i = 0; i < tileWidth; ++i) { float z; float r = 0.0f; if (level == 0) { z = 0.0f; } else { if (j % 2 == 0) { if (i % 2 == 0) { z = parentTile[i / 2 + px + (j / 2 + py) * tileWidth]; } else { float z0 = parentTile[i / 2 + px - 1 + (j / 2 + py) * tileWidth]; float z1 = parentTile[i / 2 + px + (j / 2 + py) * tileWidth]; float z2 = parentTile[i / 2 + px + 1 + (j / 2 + py) * tileWidth]; float z3 = parentTile[i / 2 + px + 2 + (j / 2 + py) * tileWidth]; z = ((z1 + z2) * 9 - (z0 + z3)) / 16; } } else { if (i % 2 == 0) { float z0 = parentTile[i / 2 + px + (j / 2 - 1 + py) * tileWidth]; float z1 = parentTile[i / 2 + px + (j / 2 + py) * tileWidth]; float z2 = parentTile[i / 2 + px + (j / 2 + 1 + py) * tileWidth]; float z3 = parentTile[i / 2 + px + (j / 2 + 2 + py) * tileWidth]; z = ((z1 + z2) * 9 - (z0 + z3)) / 16; } else { int di, dj; z = 0; for (dj = -1; dj <= 2; ++dj) { float f = dj == -1 || dj == 2 ? -1/16.0f : 9/16.0f; for (di = -1; di <= 2; ++di) { float g = di == -1 || di == 2 ? -1/16.0f : 9/16.0f; z += f * g * parentTile[i / 2 + di + px + (j / 2 + dj + py) * tileWidth]; } } } } } if (hasResidual) { r = cpuTile->data[(int)(i + rx + (j + ry) * residualTileWidth)]; } cpuData->data[i + j * tileWidth] = z + r; } } return true; }
bool HydroFlowProducer::doCreateTile(int level, int tx, int ty, TileStorage::Slot *data) { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "Hydro tile " << getId() << " " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("RIVER", oss.str()); } swHYDRODATA->start(); bool res = false; ObjectTileStorage::ObjectSlot *objectData = dynamic_cast<ObjectTileStorage::ObjectSlot*>(data); assert(objectData != NULL); TileCache::Tile::TId id = TileCache::Tile::getTId(getId(), level, tx, ty); TileCache::Tile *graphTile = graphs->findTile(level, tx, ty); assert(graphTile != NULL); ptr<Graph> graphData = dynamic_cast<ObjectTileStorage::ObjectSlot*>(graphTile->getData())->data.cast<Graph>(); float quadSize = getRootQuadSize() / (1 << level); bool diffVersion = false; if (objectData->data != NULL) { diffVersion = !objectData->data.cast<HydroFlowTile>()->equals(graphData->version, slipParameter, min((int) (quadSize / potentialDelta), displayTileSize), searchRadiusFactor);//objectData->data.cast<HydroFlowTile>()->version != graphData->version; } if (diffVersion || id != objectData->id || objectData->data == NULL ) { ptr<HydroFlowTile> hydroData; double ox = getRootQuadSize() * (double(tx) / (1 << level) - 0.5f); double oy = getRootQuadSize() * (double(ty) / (1 << level) - 0.5f); if (level >= minLevel) { if (graphData.cast<HydroGraph>() == NULL && graphData.cast<LazyHydroGraph>() == NULL) { // if the type of graph is wrong if (Logger::ERROR_LOGGER != NULL) { ostringstream oss; oss << "Bad Graph Type : Should be a [Lazy]HydroGraph."; Logger::ERROR_LOGGER->log("RIVER", oss.str()); } return false; } if (quadSize / potentialDelta < displayTileSize / 2 && level - 1 >=minLevel) { //maxLevel objectData->data = dynamic_cast<ObjectTileStorage::ObjectSlot*>(findTile(level - 1, tx / 2, ty / 2)->getData())->data; return true; } float scale = displayTileSize == -1 ? 1 : displayTileSize / quadSize; ptr<Graph::CurveIterator> ci = graphData->getCurves(); vector<ptr<HydroCurve> > banks; float width = 0.f; while(ci->hasNext()) { ptr<HydroCurve> c = ci->next().cast<HydroCurve>(); bool display = false; if (c->getType() != HydroCurve::BANK && c->getWidth() * scale > 1.0f) { display = true; if (width < c->getWidth()) { width = c->getWidth(); } } else if (c->getType() == HydroCurve::BANK && c->getRiver().id != NULL_ID) { if (c->getOwner()->getAncestor()->getCurve(c->getRiver()).cast<HydroCurve>()->getWidth() * scale > 1.0f) { display = true; } } if (display) { banks.push_back(c); } } hydroData = new HydroFlowTile(ox, oy, quadSize, slipParameter, min((int) (quadSize / potentialDelta), displayTileSize), searchRadiusFactor); hydroData->addBanks(banks, width); } else { hydroData = new HydroFlowTile(ox, oy, quadSize, slipParameter, min((int) (quadSize / potentialDelta), displayTileSize), searchRadiusFactor); } objectData->data = hydroData; hydroData->version = graphData->version; res = true; } swHYDRODATA->end(); TileProducer::doCreateTile(level, tx, ty, data); return res; }