Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to boost FPS to a safe amount  (Read 1676 times)

0 Members and 1 Guest are viewing this topic.

Jungletoe

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Trying to boost FPS to a safe amount
« on: July 30, 2012, 04:07:54 am »
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Trying to boost FPS to a safe amount
« Reply #1 on: July 30, 2012, 09:10:12 am »
You probably should look into sf::VertexArray. Also there are many examples for tilemaps with sf::VertexArray in the forum, just make use of the search function. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/