When drawing to the window, my application runs fine (at 60fps is what I'd like) with small window/view sizes. When I increase view size to show more of the drawn map, it then starts to slow. Large window, small map size helps a little bit. I'd like to bounce my design choices off the community here, if that's OK.
Here's the flow of the program:
- Load textures that we'll need (only 6 different textures for now) into std::vector<sf::Texture>.
- Pull data from a .csv file, 0 is empty space, not 0 is a wall, where {1,2,3,...} specify texture/sprite. I'm drawing a bunch of 10x10px "blocks" on a 10x10 grid.
- Store map_data in std::vector<std::vector<int>>.
- Loop through map_data, drawing by creating a sprite for each block from the &loaded_textures, setting it's position, then drawing. Return std::vector<sf::FloatRect> of all bounding boxes.
Having run gprof, I'm seeing a lot of time spent in that final point there, mainly creating the sf::Sprite and drawing, which can be seen below. I've tried creating a std::vector<sf::Sprite> to pull from in the same manner as I'm pulling from needed_textures right now, but didn't see any speed increase. Map size is 35x29 right now, so say ~500 10x10px sprites are being drawn per frame.
sf::FloatRect drawBlock(std::vector<sf::Texture> &needed_textures, int block_type, int left, int top, sf::RenderWindow &window)
{
sf::Sprite block_sprite;
block_sprite.setTexture(needed_textures.at(block_type - 1));
block_sprite.setPosition(left, top);
window.draw(block_sprite);
return block_sprite.getGlobalBounds();
}