I'm having an issue with my tilemap renderer, with small maps (like 40*40 tiles) it works fine but with maps that have 400*400 tiles the framerate becomes really slow when I try to move the camera.
Here are my rendering methods
/// Renders the map
void Map::Map::render(sf::RenderWindow& window)
{
for (auto c : m_tiles)
{
for (Tile& tile : c)
{
m_renderer.render(tile);
}
}
}
And for the TileRenderer
void Renderer::TileRenderer::render(const Map::Tile& tile) const
{
try
{
if (m_previousType != tile.getType())
m_sprite.setTextureRect(getTypeTextureRect(tile.getType()));
m_sprite.setPosition(tile.getAbsolutePosition());
m_renderWindow.draw(m_sprite);
m_previousType = tile.getType();
}
catch (ETileTypeUndefined e)
{
Logger::getInstance().log(e.what());
}
}
Any idea to solve that poor framerate ? It doesn't seems to be a memory issue. Visual Studio debugger tells me that external code spend a lot of time in the renderer's render function (calls to sf::RenderWindow::draw(sf::Drawable) I guess).