Why god why... More game loop nonsense

For one reason or another my game loop has been acting strange. Its seems like I have started to stutter again… and again, no matter if I used a fixed time step or variable time step!

If possible could any one test this code and/or tell me where I went wrong? Its based on a fixed timestep decoupled from FPS. You should just be able to just cut and paste it
Thanks!

http://pastebin.java-gaming.org/4440b947231

{Edit : I always forget this, specs on my dev pc}

Dell Studio XPS 1640 Laptop -
Windows 7 64 bit
4.0 GB ram DDR2
Core Duo T955 2.66 Ghz
ATI Mobility Radeon HD 4670 [Drivers up to date]

Butter smooth here at 7000 FPS.

EDIT:
Try changing your initing code to this:


         Display.setDisplayMode(new DisplayMode(800, 600));
         Display.create(new PixelFormat(24, 0, 0, 0, 8));
         Display.setVSyncEnabled(true);


Hey! I just wrote an article on game loops, maybe it can help you figure out what your problem is:

http://www.gameprogblog.com/generic-game-loop/

I tried this and still same results :frowning:

This also happens on the other computer I test on which was built for gaming and much more powerful than the dev computer. It has a fresh install of Windows 7 and updated drivers directly from the nvidia site.

Now this may sound crazy but is there some “openGL driver” I have to install? I mean this should have already been with my drivers but at this point I don’t know. DirectX games and etc run just fine, but anything dealing with openGL stutters or has some crazy line distortion going down the screen when I go full screen (Same thing happens on the gaming pc).

Then your computer is the cause of the stuttering. Radeon cards do have a reputation of having small frame time spikes at times. It could also be something with your laptop’s monitor. For example, my desktop monitor is pretty cheap and only updates every other line each frame or something like that, so things moving at exactly 1 pixel / screen refresh looks all fuzzy. It might also just be your imagination. We’re all differently sensitive to stuttering. I’d say I’m pretty good at seeing it though. Let me just say that you’ve done pretty much everything you can with code.

Wait, you’re getting stuttering with VSync on? -_-’

Is it stuttering because you have a low FPS or is it something less consistent?

Yep :frowning:

According to the Direct X Samples from the June 2010 SDK I run in the range of 200 - 700 FPS.
Where samples with multiple lighting effects and etc trigger the low end of my FPS range.

Definitely something wrong with your computer. VSync + 60FPS + good interpolation values = no stuttering. You’ve done everything right if that’s what you’re getting.

Have you checked in the nvidia control panel if you’re forcing vsync off ? This can screw with some things, not sure if it applies to your specific problem, but worth checking.

Both machines have the setting set to vsync off unless the application says other wise. I tried using force off anyway but I still stutter.

Also can someone check out

And tell me if they get this really weird horizontal line (its like the refresh line that distorts everything) going down the screen every second or so when it is in full screen mode or a steady ticking (once again every second or so) in windowed mode?
Also, if you do get the moving line, what would you call this? I’m not sure how to research it at the moment.

This is called screen tearing and is caused by updating or switching the frame buffer while it is displayed. This is usually caused by not doing double buffering or when VSYNC is off.

Since LWJGL uses double buffering by default, either your VSYNC is off, or there is a bug in your driver or the lwjgl version you are using.

Also I am not sure, if using a tight gameloop without any sleep or yield like this may cause hickups with the OS thread/process scheduler, that may force executing of another thread/process at unfavorable times, because it simply does not have a “free” time slot. But thats just a guess, not really backed by knowledge :wink:

Could it be caused by garbage collection pauses or something? But that would still make a dent in the FPS with Vsync on!

If anything you should force it on in this case, not off.

That’s completely irrelevant. What is your program’s average frame rate when it’s not stuttering?

There is nothing that creates garbage.

I just ran it and you’re syncing to 59 FPS. Sigh. -_-’

Is that a bad thing, cause I never set any sync options. Other than the Display.setVSyncEnabled(true) up at the top

I have added a FPS counter and I get

Roughly 2000 FPS without vsync, and then I get 59 - 61? FPS with it on (using the Display.setVSyncEnabled(true) command)

Here is the code I am currently using
http://pastebin.java-gaming.org/0b421288735

Oh, sorry, I ran this:

That one synched to 59 FPS and didn’t use VSync, which gave screen tearing.

Concerning your latest paste: First of all, [icode]glColor3f(255, 255, 255);[/icode] is wrong. Float values go from 0.0 to 1.0. It’s getting clamped to 1.0 right now anyway, so it works by chance. A gray color would be [icode]glColor3f(0.5f, 0.5f, 0.5f);[/icode]

I changed it to use nanoTime() instead and to use longs instead of doubles for measuring time. See if it’s any better.

http://www.java-gaming.org/?action=pastebin&id=383

Also, setting the update rate to 30 seems to improve things slightly unless I’m imagining things.

I tried your code and something strange is happening for sure. If I leave the line setting Vsync on it makes the square hiccup horrible.
But if I turn it off it moves smoothly but hiccups every once and a while.

Any ideas?

I have also tried a complete removal of my graphics drivers by

  1. Running the ATI Catalyst uninstaller
  2. Using driver sweeper AKA Driver Fusion to pick up any remaining files
  3. Reinstalled ATI Drivers and Catalysis Control Center

You can test how accurate the interpolation calculation is by setting the update rate to 60 updates/sec, enabling V-sync and printing the interpolation value each frame. The value should remain very constant. If it’s jumping around a lot, you have a problem. Anyway, I’m almost sure it’s a driver problem with the AMD drivers now. Either that or System.nanoTime() isn’t accurate enough.