Exemplo n.º 1
0
void MapIndex::setChanged(int x, int z)
{
  // change the changed flag of the map tile
  if(hasTile(x, z))
  {
    if(!mTiles[x][z].tile)
      loadTile(x, z);

    if(mTiles[x][z].tile->changed == 1)
      return;

     mTiles[x][z].tile->changed = 1;
  }

  for (int posaddx = -1; posaddx < 2; posaddx++)
  {
    for (int posaddz = -1; posaddz < 2; posaddz++)
    {
      if(!hasTile(x+posaddx,z+posaddz))
        continue;

      if(!mTiles[x+posaddx][z+posaddz].tile)
        loadTile(x+posaddx, z+posaddz);

      if(mTiles[x+posaddx][z+posaddz].tile->changed == 1)
        continue;

      mTiles[x+posaddx][z+posaddz].tile->changed = 2;
    }
  }

}
Exemplo n.º 2
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;
}
Exemplo n.º 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;
  }
}
Exemplo n.º 4
0
/**
 * Find a loaded parent of the given tile.
 *
 * @param id The tile ID that we should find children for.
 * @param minCoveringZoom The minimum zoom level of parents to look for.
 * @param retain An object that we add the found tiles to.
 *
 * @return boolean Whether a parent was found.
 */
bool Source::findLoadedParent(const Tile::ID& id, int32_t minCoveringZoom, std::forward_list<Tile::ID>& retain) {
    for (int32_t z = id.z - 1; z >= minCoveringZoom; --z) {
        const Tile::ID parent_id = id.parent(z);
        const TileData::State state = hasTile(parent_id);
        if (state == TileData::State::parsed) {
            retain.emplace_front(parent_id);
            return true;
        }
    }
    return false;
}
Exemplo n.º 5
0
TileData::State Source::addTile(Map& map, uv::worker& worker,
                                util::ptr<Style> style,
                                GlyphAtlas& glyphAtlas, GlyphStore& glyphStore,
                                SpriteAtlas& spriteAtlas, util::ptr<Sprite> sprite,
                                FileSource& fileSource, Texturepool& texturepool,
                                const Tile::ID& id,
                                std::function<void ()> callback) {
    const TileData::State state = hasTile(id);

    if (state != TileData::State::invalid) {
        return state;
    }

    auto pos = tiles.emplace(id, std::make_unique<Tile>(id));
    Tile& new_tile = *pos.first->second;

    // We couldn't find the tile in the list. Create a new one.
    // Try to find the associated TileData object.
    const Tile::ID normalized_id = id.normalized();

    auto it = tile_data.find(normalized_id);
    if (it != tile_data.end()) {
        // Create a shared_ptr handle. Note that this might be empty!
        new_tile.data = it->second.lock();
    }

    if (new_tile.data && new_tile.data->state == TileData::State::obsolete) {
        // Do not consider the tile if it's already obsolete.
        new_tile.data.reset();
    }

    if (!new_tile.data) {
        // If we don't find working tile data, we're just going to load it.
        if (info.type == SourceType::Vector) {
            new_tile.data = std::make_shared<VectorTileData>(normalized_id, map.getMaxZoom(), style,
                                                             glyphAtlas, glyphStore,
                                                             spriteAtlas, sprite,
                                                             texturepool, info);
        } else if (info.type == SourceType::Raster) {
            new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturepool, info);
        } else {
            throw std::runtime_error("source type not implemented");
        }

        new_tile.data->request(worker, fileSource, map.getState().getPixelRatio(), callback);
        tile_data.emplace(new_tile.data->id, new_tile.data);
    }

    return new_tile.data->state;
}
Exemplo n.º 6
0
/**
 * Recursively find children of the given tile that are already loaded.
 *
 * @param id The tile ID that we should find children for.
 * @param maxCoveringZoom The maximum zoom level of children to look for.
 * @param retain An object that we add the found tiles to.
 *
 * @return boolean Whether the children found completely cover the tile.
 */
bool Source::findLoadedChildren(const Tile::ID& id, int32_t maxCoveringZoom, std::forward_list<Tile::ID>& retain) {
    bool complete = true;
    int32_t z = id.z;
    auto ids = id.children(z + 1);
    for (const Tile::ID& child_id : ids) {
        const TileData::State state = hasTile(child_id);
        if (state == TileData::State::parsed) {
            retain.emplace_front(child_id);
        } else {
            complete = false;
            if (z < maxCoveringZoom) {
                // Go further down the hierarchy to find more unloaded children.
                findLoadedChildren(child_id, maxCoveringZoom, retain);
            }
        }
    }
    return complete;
}
Exemplo n.º 7
0
TileData::State Source::addTile(Map &map, const Tile::ID& id) {
    const TileData::State state = hasTile(id);

    if (state != TileData::State::invalid) {
        return state;
    }

    auto pos = tiles.emplace(id, std::make_unique<Tile>(id));
    Tile& new_tile = *pos.first->second;

    // We couldn't find the tile in the list. Create a new one.
    // Try to find the associated TileData object.
    const Tile::ID normalized_id = id.normalized();

    auto it = tile_data.find(normalized_id);
    if (it != tile_data.end()) {
        // Create a shared_ptr handle. Note that this might be empty!
        new_tile.data = it->second.lock();
    }

    if (new_tile.data && new_tile.data->state == TileData::State::obsolete) {
        // Do not consider the tile if it's already obsolete.
        new_tile.data.reset();
    }

    if (!new_tile.data) {
        // If we don't find working tile data, we're just going to load it.
        if (info.type == SourceType::Vector) {
            new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, info);
        } else if (info.type == SourceType::Raster) {
            new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, info);
        } else if (info.type == SourceType::GeoJSON) {
            new_tile.data = std::make_shared<GeoJSONTileData>(normalized_id, map, info);
        } else {
            throw std::runtime_error("source type not implemented");
        }

        new_tile.data->request();
        tile_data.emplace(new_tile.data->id, new_tile.data);
    }

    return new_tile.data->state;
}
Exemplo n.º 8
0
bool MapIndex::tileLoaded(int z, int x)
{
  return hasTile(z, x) && mTiles[z][x].tile;
}