I'm constantly getting a good 90+ uncapped FPS in my tile-based game, but I really want to get that number higher to allow room for more things to get rendered besides just the tiles.
As of right now, I'm storing all of my tiles in a 2D vector of a tile struct, which contains 3 ints (X, Y, and ID). Each draw call, it goes through all the tiles in the 2D vector and draws the ones that are within the camera bounds. It draws each tile separately. Here is what it looks like:
if(loaded)
{
sf::Sprite sprite;
for(int x = 0; x <= width - 1; x++)
{
for(int y = 0; y <= height - 1; y++)
{
if ( ((ent::camera.x) <= (x * getTileH()) + 32) && ((x * getTileH()) < (ent::camera.x + gl::Vars::screenW)) && (( (ent::camera.y) <= ( y * getTileW()) + 32) && (( y * getTileW()) < (ent::camera.y + gl::Vars::screenH))))
{
sprite.setTexture(*textures.at(map[x][y]->ID));
sprite.setPosition(x * tileW, y * tileH);
gl::Win.draw(sprite);
}
}
}
}
Would it be faster to render all of my tiles and changes to a sprite and then render one huge sprite at once every loop instead of 50 individual renders? My games aims to be a HUGE world (nearly infinite) and be changeable. Tons of tiles will have a chance to be changed each loop due to people either digging or modifying them in some way related to the game (I
hate to say this, but think of Terraria).
What's the best way to do this for my game? It's not a typical ORPG pre-made map. There are many changes to the map on the fly.
Also, do you guys have any other tips for boosting FPS? My aim is to get it over 400 uncapped.