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 - sezium

Pages: [1]
1
Hello everyone, I'm trying to understand delta time once again, and with this code:

#include <chrono>
#include <SFML/Graphics.hpp>


int main() {

    constexpr unsigned char MAX_FPS = 60;

    constexpr std::chrono::microseconds FRAME_DURATION(1000000 / MAX_FPS);
        std::chrono::steady_clock::time_point previous_time;
        std::chrono::microseconds lag(0);

        sf::Event event;

        sf::RenderWindow window(sf::VideoMode(500, 500), "SFML", sf::Style::Close);
    //window.setFramerateLimit(MAX_FPS);

        previous_time = std::chrono::steady_clock::now();

        while (window.isOpen()) {

                std::chrono::microseconds dt = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - previous_time);

                lag += dt;

                previous_time += dt;

                while (FRAME_DURATION <= lag) {

                        lag -= FRAME_DURATION;

                        while (window.pollEvent(event)) {
                                switch (event.type) {

                                        case sf::Event::Closed: {
                                                window.close();

                                                break;
                                        }
                                }
                        }



                        if (FRAME_DURATION > lag) {

                                window.clear();

                                window.display();

                //sf::sleep(sf::milliseconds(50));
                        }
                }
        }
}
 

Is better to use sleep or setFramelimit? what are the differences in this case? Btw when I use none of them, my cpu usage is high.

2
General discussions / Is deltaTime precise?
« on: November 27, 2023, 01:25:58 pm »
I'm trying to create Super Mario Bros but I think there is something wrong with deltaTime
When I change the FPS_LIMIT to 20, Mario goes higher than normal (like 20px more).
Can someone explain?
This is the code:

Pages: [1]
anything