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.


Topics - CombustibleL3m0n

Pages: [1]
1
Window / Frame Rate/Periodic Lag Issues
« on: August 25, 2013, 07:51:57 pm »
Hi everybody,

I'm new to SFML and new to the forum so sorry if I haven't posted correctly, but I'm having some issues with my C++ game.

My problem is that I'm getting inconsistent lag. I have searched around for solutions to frame rate issues and found people telling me to use Vsync, which I did but it didn't improve the situation. I've tried using an if statement inside my while(window.isOpen()) loop with sf::Clock.getTimeElapsed.asSeconds() > 1.0f/30.0f (my desired frame rate), and I've also tried to use the setFramerateLimit(30) function, but none of this seems to help.

The strange thing is, that I have tested the framerate by outputting the elapsed time to the console every frame, and the elapsed time is close to 0.033 for 9 or so frames, then it randomly increases to about 0.08, then back down again, and this cycle repeats, so the spike is about every half second.

Can anyone explain this weird behaviour? I am running this on a powerful machine, and my game has fairly efficient game logic, so I can't explain why these lag spikes occur. I didn't think including source code would be useful, but I can if anyone wants to take a look.
Any help would be greatly appreciated.

Thanks.  :)


Update:

I'm still at a loss, I've tried it even using basic minimal coding, and i'm still getting lagg spikes
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
        window.setVerticalSyncEnabled(true);
        sf::Clock clock;
        float currTime = 0.0f;
        float prevTime = 0.0f;

    while (window.isOpen())
    {
                        sf::Event event;
                        while (window.pollEvent(event))
                        {
                                if (event.type == sf::Event::Closed)
                                        window.close();
                        }
                        currTime = clock.getElapsedTime().asSeconds();
                        std::cout << currTime - prevTime << std::endl;
                        prevTime = currTime;
                        window.clear(sf::Color::Black);
                        window.display();
                        sf::sleep(sf::Time(sf::milliseconds(20)));
    }

    return 0;
}
 

I've got a screenshot of what the console outputs here, showing where the spikes occur:

Any help greatly appreciated :)

Pages: [1]