Exemple #1
0
MapTile* MapIndex::loadTile(int z, int x)
{
  if( !hasTile( z, x ) )
  {
    return NULL;
  }

  if( tileLoaded( z, x ) )
  {
    return mTiles[z][x].tile;
  }

  std::stringstream filename;
  filename << "World\\Maps\\" << basename << "\\" << basename << "_" << x << "_" << z << ".adt";

  if( !MPQFile::exists( filename.str() ) )
  {
    LogError << "The requested tile \"" << filename.str() << "\" does not exist! Oo" << std::endl;
    return NULL;
  }

  if(mTiles[z][x].tile) //just to sure
  {
    delete mTiles[z][x].tile;
    mTiles[z][x].tile = NULL;
  }

  mTiles[z][x].tile = new MapTile( x, z, filename.str(), mBigAlpha );// XZ STEFF Swap MapTile( z, x, file
  return mTiles[z][x].tile;
}
Exemple #2
0
void MapIndex::setFlag(bool to, float x, float z)
{
  // set the inpass flag to selected chunk
  this->setChanged(x, z);
  const int newX = x / TILESIZE;
  const int newZ = z / TILESIZE;

  for( int j = newZ - 1; j < newZ + 1; ++j )
  {
    for( int i = newX - 1; i < newX + 1; ++i )
    {
      if( tileLoaded( j, i ) )
      {
        for( int ty = 0; ty < 16; ++ty )
        {
          for( int tx = 0; tx < 16; ++tx )
          {
            MapChunk* chunk = mTiles[j][i].tile->getChunk( ty, tx );
            if( chunk->xbase < x && chunk->xbase + CHUNKSIZE > x && chunk->zbase < z && chunk->zbase + CHUNKSIZE > z )
            {
              chunk->setFlag(to);
            }
          }
        }
      }
    }
  }
}
Exemple #3
0
void MapIndex::enterTile( int x, int z )
{
  if( !hasTile( z, x ) )
  {
    noadt = true;
    return;
  }

  noadt = false;

  cx = x;
  cz = z;
  for( int i = std::max(cz - 2, 0); i < std::min(cz + 2, 64); ++i )
  {
    for( int j = std::max(cx - 2, 0); j < std::min(cx + 2, 64); ++j )
    {
      mTiles[i][j].tile = loadTile( i, j );
    }
  }

  if( autoheight && tileLoaded( cz, cx ) ) //ZX STEFF HERE SWAP!
  {
    float maxHeight = mTiles[cz][cx].tile->getMaxHeight();
    maxHeight = std::max( maxHeight, 0.0f );
    gWorld->camera.y = maxHeight + 50.0f;

    autoheight = false;
  }
}
Exemple #4
0
void MapIndex::saveTile(int x, int z)
{
  // save goven tile
  if( tileLoaded( z, x ) )
  {
    mTiles[z][x].tile->saveTile();
  }
}
Exemple #5
0
void MapIndex::saveChanged()
{

  // First recalculated UIDs.
  //  for( int j = 0; j < 64; ++j )
  //  {
  //    for( int i = 0; i < 64; ++i )
  //    {
  //      if( tileLoaded( j, i ) )
  //      {
  //        if(this->getChanged(j,i) == 1)
  //        {
  //          mTiles[j][i].tile->uidTile();
  //        }
  //      }
  //    }
  //  }

  if(changed)
    save();

  // Now save all marked as 1 and 2 because UIDs now fits.
  for( int j = 0; j < 64; ++j )
  {
    for( int i = 0; i < 64; ++i )
    {
      if(!tileLoaded(j, i)) continue;
      if(!getChanged(j,i)) continue;

      mTiles[j][i].tile->saveTile();
      unsetChanged(j,i);
    }
  }

  std::map<int, WMOInstance> wmoTemp(gWorld->mWMOInstances);
  gWorld->mWMOInstances.clear();

  for(std::map<int, WMOInstance>::iterator it = wmoTemp.begin(); it != wmoTemp.end(); ++it)
  {
    gWorld->mWMOInstances[it->second.mUniqueID] = it->second;
    it->second.unlockUID();
  }

  std::map<int, ModelInstance> modelTemp(gWorld->mModelInstances);
  gWorld->mModelInstances.clear();

  for( std::map<int, ModelInstance>::iterator it = modelTemp.begin(); it != modelTemp.end(); ++it )
  {
    gWorld->mModelInstances[it->second.d1] = it->second;
    it->second.unlockUID();
  }
}
Exemple #6
0
TilesMap::TilesMap(LatLon center, int zoom, bool online, QWidget *parent) :
    QWidget(parent),
    m_center(center),
    m_zoom(zoom),
    m_online(online)
{
    m_emptyTile = QPixmap(TILE_SIZE, TILE_SIZE);
    m_emptyTile.fill(Qt::lightGray);
    m_sources["osm"] = new OSMTilesSource();
    m_source = m_sources["osm"];
    connect(&m_loaderThread, SIGNAL(tileLoaded(QPoint)), SLOT(updateTile(QPoint)));
    connect(&m_loaderThread, SIGNAL(tilesLoading(int)), SIGNAL(tilesLoading(int)));
}
Exemple #7
0
void MapIndex::reloadTile(int x, int z)
{
  if( tileLoaded( z, x ) )
  {
    delete mTiles[z][x].tile;
    mTiles[z][x].tile = NULL;

    std::stringstream filename;
    filename << "World\\Maps\\" << basename << "\\" << basename << "_" << x << "_" << z << ".adt";

    mTiles[z][x].tile = new MapTile( x, z, filename.str(), mBigAlpha );
    enterTile( cx, cz );
  }
}
Exemple #8
0
MapIndex::~MapIndex()
{
  for( int j = 0; j < 64; ++j )
  {
    for( int i = 0; i < 64; ++i )
    {
      if( tileLoaded( j, i ) )
      {
        delete mTiles[j][i].tile;
        mTiles[j][i].tile = NULL;
      }
    }
  }
}
Exemple #9
0
const StackedTile* StackedTileLoader::loadTile( TileId const & stackedTileId )
{
    // check if the tile is in the hash
    d->m_cacheLock.lockForRead();
    StackedTile * stackedTile = d->m_tilesOnDisplay.value( stackedTileId, 0 );
    d->m_cacheLock.unlock();
    if ( stackedTile ) {
        stackedTile->setUsed( true );
        return stackedTile;
    }
    // here ends the performance critical section of this method

    d->m_cacheLock.lockForWrite();

    // has another thread loaded our tile due to a race condition?
    stackedTile = d->m_tilesOnDisplay.value( stackedTileId, 0 );
    if ( stackedTile ) {
        Q_ASSERT( stackedTile->used() && "other thread should have marked tile as used" );
        d->m_cacheLock.unlock();
        return stackedTile;
    }

    // the tile was not in the hash so check if it is in the cache
    stackedTile = d->m_tileCache.take( stackedTileId );
    if ( stackedTile ) {
        Q_ASSERT( !stackedTile->used() && "tiles in m_tileCache are invisible and should thus be marked as unused" );
        stackedTile->setUsed( true );
        d->m_tilesOnDisplay[ stackedTileId ] = stackedTile;
        d->m_cacheLock.unlock();
        return stackedTile;
    }

    // tile (valid) has not been found in hash or cache, so load it from disk
    // and place it in the hash from where it will get transferred to the cache

    mDebug() << "load tile from disk:" << stackedTileId;

    stackedTile = d->m_layerDecorator->loadTile( stackedTileId );
    Q_ASSERT( stackedTile );
    stackedTile->setUsed( true );

    d->m_tilesOnDisplay[ stackedTileId ] = stackedTile;
    d->m_cacheLock.unlock();

    emit tileLoaded( stackedTileId );

    return stackedTile;
}
Exemple #10
0
void StackedTileLoader::updateTile( TileId const &tileId, QImage const &tileImage )
{
    const TileId stackedTileId( 0, tileId.zoomLevel(), tileId.x(), tileId.y() );

    StackedTile * displayedTile = d->m_tilesOnDisplay.take( stackedTileId );
    if ( displayedTile ) {
        Q_ASSERT( !d->m_tileCache.contains( stackedTileId ) );

        StackedTile *const stackedTile = d->m_layerDecorator->updateTile( *displayedTile, tileId, tileImage );
        stackedTile->setUsed( true );
        d->m_tilesOnDisplay.insert( stackedTileId, stackedTile );

        delete displayedTile;
        displayedTile = 0;

        emit tileLoaded( stackedTileId );
    } else {
        d->m_tileCache.remove( stackedTileId );
    }
}
Exemple #11
0
void TileFetcher::networkRequestCompleted(QNetworkReply *reply)
{
    QImage img;
    int zoom = reply->request().attribute(QNetworkRequest::User).toInt();
    QPoint offset = reply->request().attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 1)).toPoint();

    reply->deleteLater();
    if (reply->error() || !img.load(reply, "PNG"))
        return;

    /* TODO1 on maemo only if MyDocs is mounted! */
    QString path = QString("%1/%2/%3/%4")
                   .arg(MAPTILES_LOCATION)
                   .arg("OpenStreetMap I")
                   .arg(zoom)
                   .arg(offset.x());
    QDir().mkpath(path);
    img.save(QString("%1/%2.png").arg(path).arg(offset.y()));

    emit tileLoaded(zoom, offset, img);
}