Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous stutter #1199

Closed
naezith opened this issue Mar 4, 2017 · 1 comment
Closed

Continuous stutter #1199

naezith opened this issue Mar 4, 2017 · 1 comment

Comments

@naezith
Copy link

naezith commented Mar 4, 2017

I have a stutter issue that I couldn't fix trying everything for 2.5 years. It is not always happening but like %75 of the time I have stutter. When it's gone, game runs ultra smooth.

Here I recorded it, I thought it wouldn't be visible in camera because of low FPS but it is clearly visible. It looks like a thick pillar moving to right in the video because of the FPS but you will see that sometimes it snaps to left for a moment, that's the stutter. Screenshot of the snap moment.

Here are the stuff I tried.

  • VSync On/Off does not matter
  • FPS 60-2000 does not matter

Here is the minimal code:

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

using namespace std::chrono_literals;

int main() {
	sf::RenderWindow window(sf::VideoMode(1280, 720), "Stutter");
	sf::Event event;

	const float dt = 0.008f;
    std::chrono::nanoseconds timestep(8ms), lag(0ns);
    auto time_start = std::chrono::high_resolution_clock::now();

	sf::RectangleShape rect(sf::Vector2f(5.0f, 720.0f));
	float pos = 0.0f, prev_pos = 0.0f, org_pos = 0.0f;

	while(window.isOpen()) {
        // Calculate the elapsed time and add it to lag
        auto now = std::chrono::high_resolution_clock::now();
		lag += now - time_start;
        time_start = now;

		while(lag >= timestep) {
			lag -= timestep;

			// Save the previous value
			prev_pos = pos;

			// Poll Events
			while(window.pollEvent(event)) if(event.type == sf::Event::Closed) window.close();

			// Update
			if((pos += 1000.0f*dt) > 1280.0f) { prev_pos = org_pos = pos = 0.0f; }
		}


		// Save the original value before drawing
		org_pos = pos;

		// Interpolate
		pos = prev_pos + (static_cast<double>(lag.count()) / timestep.count()) * (pos - prev_pos);

		// Set position to interpolated position
		rect.setPosition(pos, 0.0f);

		// Render
		window.clear();
		window.draw(rect);
		window.display();

		// Recover the original value
		pos = org_pos;
	}

	return 0;
}

ASUS VG248QE Monitor @144 hz <- Game runs on this
I also have another basic 19" LCD monitor plugged to the motherboard's Intel

SFML 2.4.1
MinGW 5.3.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
Windows 10, updated
GTX 770, updated
i7 i3770k

@naezith
Copy link
Author

naezith commented Mar 4, 2017

Updated SFML, joystick update fixed it.

It was caused by the joystick polling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants