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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - albert_lazaro

Pages: 1 [2]
16
General discussions / Re: Setting Frame Limit of the project
« on: September 29, 2019, 07:35:41 pm »
I think Vsync would have to be configurable by the user in a option menu, but you can't be sure it will work 100% of times.

There is more info in the tutorials -> https://www.sfml-dev.org/tutorials/2.0/window-window.php#controlling-the-framerate

17
General discussions / Re: Setting Frame Limit of the project
« on: September 22, 2019, 06:30:13 pm »
Thanks for the response, I'm a web developer so this is new for me (on web development I don't have this type of problems XD ).

So the idea of make games are simple 2D games for the moment. The first one would be an RPG like Final fantasy I ().

I think I don't need higher precision (this would not be an AAA game) so I don't want to use 100% CPU. So I'm between using Standard sleep (usually good enough) and try Vsync in the future.

Now I will search for use standard sleep.

PD: I develop on a laptop, so it heads up easily if the usage of CPU is 100%.

18
General discussions / Setting Frame Limit of the project
« on: September 18, 2019, 09:15:06 pm »
Hi, I’m learning SFML with “SFML Game Development” (https://www.amazon.com/SFML-Game-Development-Jan-Haller/dp/1849696845) and there is something I don’t understand about fixed time steps technique to give always the same delta time to the update function:

/*
When we are over the required amount for one frame, we substract
desired length of this frame (TimePerFrame) and update the game.
*/

void Game::run()
{
    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;

    while(mWindow.isOpen())
    {
        processEvents();

        timeSinceLastUpdate += clock.restart();
       
        // collects the user input and computes the game logic.
        while (timeSinceLastUpdate > TimePerFrame)
        {
            timeSinceLastUpdate -= TimePerFrame;
            processEvents();
            update(TimePerFrame);    
        }        
        render();
    }
}

So we accumulate the elapsed time in timeSinceLastUpdate and substract the desired length of this frame (TimePerFrame = 1.f /60.f) and do this until we are below the required amount again ant then render the scene (this is called logic frame rate). With this the frame rate is 60 fps.

With this, if rendering is slow, processEvents()  and update() may be called multiple times before one render() call, so the game occasionally slutters becuase not every update is rendered, but the game doesn’t go slow down. On the other hand fast rendering can lead to call render() multiple times without a logic update in between.

Ok, the problem of this method is that CPU usage is high (about 50% or more).

Then I can use sf::RenderWindow::setFrameLimit(60) that calls sleep() internally but lacks precision, and then is sf::RenderWindow::setVerticalSyncEnabled() that adapts the graphical updates to the refresh rate of the monitor (GPU I think).

My question is about what method do you usually use: and accurate method like first, the setFrameLimit function or the setVerticalSyncEnabled()? And if the answer is the first one, how do you solve the problem of the CPU usage?

Thanks to everyone.

Pages: 1 [2]