1
\$\begingroup\$

I coded a simple Tetris game to for some programming practice. It has all the features you would expect from Tetris, like rotating shapes and clearing rows. I implemented a frame rate measure tool out of curiosity to see what the frame rate was. It is currently saying that the game is running at around 250 fps. Could that be accurate? That seems very high to me, but I don't really know too much about computers. Is it realistic for even a simple game like Tetris to run at such high speeds on a laptop, or is my measuring off?

These were the two ways I used for counting the FPS, I suspect that they are both flawed.

Method 1, which generally gave lower results:

{

        //At the end of my game loop

        static unsigned int ticks = 0;
        static unsigned int ticksAtStart = 0;
        static sf::Clock clock;

        ticks++;
        if (clock.getElapsedTime().asMicroseconds() >= 1000000)
        {
            frameRate_ = ticks - ticksAtStart;
            ticksAtStart = ticks;
            clock.restart();
        }
}

Method 2, which generally gave higher results:

{
        // At the end of my game loop

        static sf::Clock;
        frameRate_ = (unsigned int)std::roundf(1000000.f / (float)clock.getElapsedTime().asMicroseconds());
        clock.restart();
}
```
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Most Tetris games won't use any rendering techniques more complex than simple sprite blitting, so it would actually surprise me that it reaches only 250 FPS. But it does of course depend on the hardware (laptops are not created equal), what features exactly you have in your version of Tetris and how you implemented them. But it does not seem particularly implausible. \$\endgroup\$
    – Philipp
    Commented Oct 12, 2021 at 8:34

2 Answers 2

1
\$\begingroup\$

A 2D game of Tetris can indeed run very fast on current day computers. Because this is maybe the first time you programmed a frame rate measuring tool it is hard to say if you can trust it.

You could of course run a third party tool to measure the framerate of your tetris game. There are many tools to choose from, some hidden in the control panel of your GPU like GeForce Experience or Radeon Adrenalin. (Depending on your hardware.) On Windows 10 there is also a performance window you can open on the "XBox Game Bar".

Another idea is to enable "vsync" either from your games code/settings or from your graphics control panel. VSync means vertical-synchronisation and it would prevent your game from drawing faster than your screen can display images. Typically displays show 60 to 144 images per second. (If you have a freensync/gsync monitor this would be wrong though.)

\$\endgroup\$
1
\$\begingroup\$

The game mechanics of Tetris are not very computationally expensive. It ran fine on the 4.19 MHz CPU of my Nintendo Game Boy in 1990.

And I don't know what your version of Tetris does for the visual representation. With enough time, creativity and knowledge of GFX programming, it is perfectly possible to create a Tetris version full of fancy but expensive graphic effects. But when you are a beginner then I doubt that you do anything more advanced than just blitting sprites.

So I assume that what you have is a Tetris clone which does use simple graphics and which is implemented in a straight-forward manner with no major performance blunders but also no fancy optimization tricks. Such a game running on 250 Fps on a modern low-budget laptop is pretty plausible.

But it is of course not impossible that your programming isn't actually that free of performance blunders, and that your FPS counter is buggy too. Hard to tell without seeing your code. So when your FPS counter says the game runs at 250 FPS but what you see on the screen does not look and feel like 250 FPS, then you might want to show us how exactly you implemented it.

\$\endgroup\$
1
  • \$\begingroup\$ It is sort of hard to determine if it feels like 250 FPS, since the graphical aspect of Tetris (or at least my version) is pretty much just boxes jumping to the next square. As for the FPS counter, do you happen to know the standard method for measuring FPS from inside the code? I added the code I used for the FPS-counting to the question body, would you mind taking a quick look at it? \$\endgroup\$
    – JensB
    Commented Oct 12, 2021 at 15:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .