m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
-// qWarning() << __PRETTY_FUNCTION__ << topLeftX << topLeftY << gridWidth << gridHeight;
+ qWarning() << __PRETTY_FUNCTION__ << topLeftX << topLeftY << "->"
+ << topLeftX + gridWidth << topLeftY + gridHeight;
return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
}
void MapEngine::getTiles(QPoint sceneCoordinate)
{
- qWarning() << __PRETTY_FUNCTION__;
+ qDebug() << __PRETTY_FUNCTION__;
m_viewTilesGrid = calculateTileGrid(sceneCoordinate);
updateViewTilesSceneRect();
int tileX = x;
int tileY = y;
- int debugX = x;
+ int requestedX = x;
- if (tileX < 0)
+ // span in horizontal direction if world limits has been reached
+ if (tileX < 0) {
tileX += tileMaxVal + 1;
- else if (tileX > tileMaxVal)
+// qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
+ }
+ else if (tileX > tileMaxVal) {
tileX -= tileMaxVal + 1;
+// qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
+ }
- if (tileY < 0)
- tileY += tileMaxVal + 1;
- else if (tileY > tileMaxVal)
- tileY -= tileMaxVal + 1;
-
- qWarning() << __PRETTY_FUNCTION__ << "x value:" << debugX << "->" << tileX;
+ // map doesn't span in vertical direction
+ if (tileY < 0 || tileY > tileMaxVal)
+ continue;
- if (!m_mapScene->isTileInScene(tilePath(m_zoomLevel, tileX, tileY)))
+ MapTile *tile;
+ if (!(tile = m_mapScene->tileInScene(tilePath(m_zoomLevel, tileX, tileY)))) {
emit fetchImage(m_zoomLevel, tileX, tileY);
+ }
+ else {
+ // tile was already in the scene, maybe it should be moved?
+// qWarning() << __PRETTY_FUNCTION__ << "tile was already in the scene";
+ m_mapScene->setTilePosition(tile);
+ }
}
}
}
void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__ << "x:" << x << "y:" << y;
QString hashKey = tilePath(zoomLevel, x, y);
- if (!m_mapScene->isTileInScene(hashKey)) {
+ if (!m_mapScene->tileInScene(hashKey)) {
MapTile *mapTile = new MapTile();
mapTile->setZoomLevel(zoomLevel, m_zoomLevel);
m_mapScene->addTile(mapTile, hashKey);
m_mapScene->enqueueRemoveStackedTiles(mapTile);
- }
+ }
+ else {
+ qWarning() << __PRETTY_FUNCTION__ << "WARNING: Received tile which already is in the scene";
+ }
}
void MapEngine::receiveOwnLocation(User *user)
void MapEngine::setLocation(QPoint sceneCoordinate)
{
- qDebug() << __PRETTY_FUNCTION__;
+// qWarning() << __PRETTY_FUNCTION__ << "X:" << sceneCoordinate.x();
if (sceneCoordinate.x() < 0) {
- qWarning() << __PRETTY_FUNCTION__ << "World west limit reached";
+// qWarning() << __PRETTY_FUNCTION__ << "World west limit reached";
sceneCoordinate.setX(sceneCoordinate.x() + WORLD_PIXELS_X);
}
else if (sceneCoordinate.x() > WORLD_PIXELS_X - 1) {
- qWarning() << __PRETTY_FUNCTION__ << "World east limit reached";
+// qWarning() << __PRETTY_FUNCTION__ << "World east limit reached";
sceneCoordinate.setX(sceneCoordinate.x() - WORLD_PIXELS_X);
}
}
}
-bool MapScene::isTileInScene(QString hashKey)
+MapTile* MapScene::tileInScene(QString hashKey)
{
qDebug() << __PRETTY_FUNCTION__;
- return m_mapTilesInScene.contains(hashKey);
+ return m_mapTilesInScene.value(hashKey, 0);
}
void MapScene::runNextStackedTilesRemoval()
{
qDebug() << __PRETTY_FUNCTION__;
- m_mapTilesInScene.remove(MapEngine::tilePath(tile->zoomLevel(),
- tile->tileNumber().x(),
- tile->tileNumber().y()));
- removeItem(tile);
- m_removeStackedTilesList.removeAll(tile);
- delete tile;
+// m_mapTilesInScene.remove(MapEngine::tilePath(tile->zoomLevel(),
+// tile->tileNumber().x(),
+// tile->tileNumber().y()));
+// removeItem(tile);
+// m_removeStackedTilesList.removeAll(tile);
+// delete tile;
}
void MapScene::setTilePosition(MapTile *tile)
}
else {
tile->setPos(UNDEFINED, UNDEFINED);
+ qCritical() << __PRETTY_FUNCTION__ << "Tile position is undefined";
}
}
void enqueueRemoveStackedTiles(MapTile *newTile);
/**
- * @brief Returns if tile mathcing hash key is already in the scene
+ * @brief Returns tile mathcing given hash key
*
* @param hashKey
- * @return True if tile was in the scene, otherwise false
+ * @return Returns tile matching given hash key, or 0 if no match found
*/
- bool isTileInScene(QString hashKey);
+ MapTile* tileInScene(QString hashKey);
/**
* @brief Remove tiles which are out of view bounds.
void removeTile(MapTile *tile);
/**
+ * @brief Set position of the tile in the MapScene coordinate system
+ *
+ * Does set the position based on the tiles' m_zoomLevel and m_TileNumber and the current
+ * m_viewRect. Position is set to (UNDEFINED, UNDEFINED) if there is something wrong with zoom
+ * level or tile numbers. If tile is out of the current view rect, then it is moved to opposite
+ * side of the world to make spanning over world limit work.
+ */
+ void setTilePosition(MapTile *tile);
+
+ /**
* @brief Set drawing order of all tiles in the scene
*
* Check MapTile::setSceneLevel for more information.
*/
void viewRectUpdated(QRect viewRect);
-private:
- void setTilePosition(MapTile *tile);
-
private slots:
/**
* @brief Slot for running next queued removal of stacked tiles