Solving Stuttering With Fixed Timesteps, Once and For All


I would definitely use interpolation for rendering things in my game that will use fixed 50FPS updating to allow frame rates over 50 FPS. If you do it right, there is no problem at all with interpolation. BUT IT WON’T SOLVE THE REAL PROBLEM FOR F*CKS SAKE.

And yes, if you get stuttering with VSync on AND you’re measuring exactly 60 FPS per second, then yes, it’s something you cannot affect. If you’re getting less than 60 FPS for a game that runs at >80 FPS with VSync off, then it’s your own fault for having some frames take drastically longer time to render than other frames.

I’m not talking LWJGL. I’m talking about anything that goes through your graphics card.

Interpolation does not produce apparently smooth movement. The brain already predicts where something is going to be when it’s supposed to be there, and when it doesn’t appear there precisely on time, no amount of interpolation fixes it. So my advice is not to use interpolation positions but instead to get everything done at an unfailingly fixed rate and hope for the best.

Unless you’re in fullscreen mode, you can’t rely on vsync. But when you can rely on vsync, you’re waiting on the correct side of the graphics card. You will get absolutely perfect 60hz displays with not a stutter in sight. That is what vsync is for. All that confusing stuff about command buffers and so on - no-one really needs to know! All devs need to know is: go fullscreen, turn vsync on, and that’s the best you can do.

Cas :slight_smile:

Although most here are talking about syncing with LWJGL, the OP should be mainly concerned with Java2D until he gains enough experience.

@OP Does this game stutter for you? Is there any screen tearing?
Pressing ‘X’ will alternate between 60FPS and max FPS. I use a busy while loop that calls Thread.yield until the sleeping period is over. At both FPS’s, I don’t see any screen tearing on either good computers or slow computers.

btw - it irritates me greatly that movie framerates don’t match monitor framerates :slight_smile: But then, coz I’ve been working in broadcast video engineering for quite a while, little things like this really grate and stand out for me. I can’t even watch DVDs or normal TV without the MPEG artefacts irritating the hell out of me!

Cas :slight_smile:

Uh, I think you have sort of become confused by what causes tearing and what causes stuttering. On Vista or 7 you can’t even get tearing in a windowed display as the compositor is already vsynced. The speed of a computer also has no relevance to tearing.

Cas :slight_smile:

Ah I meant computers having a single core and integrated graphics (like my school’s computers ;D)
And I did not know that bit about the compositor already being vsynced in Windows 7, interesting!

Thank you for your informative posts, but please drop the condescending attitude. When dealing with human beings, it doesn’t matter whether you’re right, it matters that you have the skills to convey your point of view.

I don’t really agree with you about interpolation, but lets drop it before it gets out of hand. And no, the primary reason for VSync to exist is to prevent tearing, which it does to 100%. With VSync, you will still get occasional stuttering if you get 65-70 FPS without VSync. Even though the game should be able to always produce 60 FPS, with just a margin of 5 FPS you’re pretty sensitive to external factors, which may cause you to miss some trains. Jesus, I’m gonna be called Trainman soon.

Sorry if I’m jumping in here, but I can’t see any stuttering at all here due to the irregular movement. What I can see however is rounding errors. You jump higher when you have 1.5k FPS.

24 FPS videos irritate me too, because have way too low frame rate. I can’t see any stuttering between these frames though. You do realize that the stuttering is about a lot more subtle compared to what you get in the bouncing box demo, right? If you can see that stuttering, I feel sorry for you.

EDIT:

I tried to convey it, both with long explanations and with shorter statements. Sorry for that last post though, I’m getting tired (as in sleepy).

For all I know, this may be the case; but, if so, and it really does only matter on the hardware, then there’s still the ever-present question: Why are Game Maker games fine?

I can’t currently test this right now, but if I remember correctly I didn’t see any stuttering. However, it was a little difficult to be sure if there was or wasn’t any stuttering/tearing. This is because (again, if I remember correctly) the gameplay is pretty fast, it’s all vertical movement, and the movement isn’t at constant speed, and all of those factors make it harder to see if there is or isn’t stuttering.

EDIT: ra4king, perhaps you could make one of those sprites-moving-side-to-side examples with your method? Also, could you perhaps post your game loop and rendering code?

I own all of them, and I did not.

Care to drop a link or create a program that is exactly the same to this one but made in Game Maker?

Like this?

http://www.box.net/shared/6crbm32djhs3627lt93k

Note that I don’t know exactly how Game Maker works internally, but it seems like it employs a fixed timestep.

This example actually DOES stutter on my laptop… ha ha. But I had already observed a little bit of that going on; I have yet to test it on our desktop, on which the differences seem to be most apparent between GM and Java. Specifically, on my desktop GM seems to run more smoothly than on my laptop, and Java seems to run less smoothly. I’ll try to report on that later.

[quote]timeThen = Sys.getTime() & 0x7FFFFFFFFFFFFFFFL;
[/quote]
Swifly off-topic, what the hell is this? What does that ‘&’ do? I know that 0x**** is hexadecimal, or at least afaik. But wth is that &? And how does it work? o.O

Risking sounding like an idiot, does this mean that if you settle for and intentionally update your game every 50 seconds, ie less than your screen refresh rate (which is usually 60hz), you would get smooth frame transitions like in films? And if not, why not? Short dummy explanation please:)

Also interesting note, Peter Jackson is filming his new movie in double the fps ie 48fps. The day when movies will run in higher fps, rather than increased pixels, is coming!:slight_smile:

Another point @theagentd, I never experienced stuttering in my Super mario games on my SNES - why shouldn’t Java be capable of doing the same? Is there a reason it doesn’t, or did my SNES games actually DO stutter and I’ve simply not noticed it?

On my laptop I get greatly visible stuttering. When I press X however, it’s really smooth.

Basically: PC Game Programming and Console Programming are very different things. When programming for a console you know the exact hardware and it will be the same hardware every time - this allows you to write very low level code that works perfectly with this hardware - but not at all with other hardware.

Which is why I would rather program console games ;D

John Carmack said this even about Rage, that it was easier to get Rage running at 60 fps on the consoles than it was on the PC, because of the way ID Tech 5 and especially Mega texture uses the memory, and that pc drivers for memory and video card are written so that they work with many different things - which doesnt allow, what he always calls “aggressive high performance operations” - because of too much driver overhead

So I tested this on my desktop and there is some stuttering, but I think it happens less often than with Java. When it does happen in the Game Maker example, it seems to be a slightly different sort of stuttering; it’s more… “minuscule”? And the stuttering in Java is more “jarring.” Also, it seems that my Java programs have a harder time maintaining an (reported) FPS of 60 (that is, on my desktop; on my laptop 60 FPS is usually maintained, I think).

Has anyone else tested the GM example?

By the way, I’m totally going for an SNES/GBA sort of feel with the stuff I want to make. I can understand that the programming would be different between consoles and PC, though. I wonder if Nintendo will ever support indie games.

[quote=“Saucer,post:53,topic:37426”]
I exp lots of stutter of the slow moving characters, I think this is because of rounding errors and could easily be fixed by enabling interpolation in GM. (In Game Options inside GM)

The high speed ones, ( like the one at the bottom ) is really smooth. However, I do believe, by careful examination, that it experienced stuttering as well. But very little compared to the two Java versions you posted (on the TIG forum). Using double buffering on your Java programs, however, reduced the stuttering phenomenally ( as you would expect ) and I would argue that the GM game and your Java examples with Double buffering produce the same quality of stuttering.

This was all tested on my laptop (notebook really).

Also I’m certain GM uses fixed timesteps. At least GM7 and anything prior did. Therefore GM8 probably does too.

[quote=“jonjava,post:58,topic:37426”]

Thank you for your feedback. You say “using double buffering”… Isn’t that something that the programmer uses? Like, with the BufferStrategy class? Game Maker and my Java programs all should be implementing double buffering whether the player likes it or not…

That’s true. However, in the two examples you posted on the TIG forum you let the user choose, before the application launches, if he wants to use Double buffering or not… right? o.O