Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Rendering Loop Stuttering On Random App Instances  (Read 601 times)
0 Members and 1 Guest are viewing this topic.
Offline ghostsoldier23

Junior Member


Medals: 1



« Posted 2013-01-06 06:58:21 »

I'm using a fixed timestep in my rendering loop to interpolate the render positions and maintain a steady framerate of 60fps and update interval of 30tps.

I have a test animation that moves a single image across the screen in a linear path, checking for a minimum timestep on each update.

The odd thing is, the animation is smooth on a majority of the times I launch the program, but sometimes it begins to stutter (i.e. the image "shakes" while moving or jumps ahead/behind in its position a little bit).

What I don't understand, is that the frame-rate monitor has the frame rate and update rate staying steady even while the image is stuttering during the animation.

What could be causing this?  And why is it so inconsistent between application instances?

If you need any code snippets, let me know.

Thanks in advance for your input!
Offline HeroesGraveDev

JGO Wizard


Medals: 64
Projects: 8


Muahahahahahaha...


« Reply #1 - Posted 2013-01-06 07:50:58 »

You can't have a "fixed variable" timestep. It's one or the other. Pointing

Of course we need code snippets. We can't read your mind. persecutioncomplex

Offline jonjava

JGO Knight


Medals: 33



« Reply #2 - Posted 2013-01-06 10:49:28 »

How much does it jump/stutter? Could be a rounding error (or lack thereof) when drawing or faulty interpolation.

That or it could just be Swing, if you're using that.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ghostsoldier23

Junior Member


Medals: 1



« Reply #3 - Posted 2013-01-06 18:32:48 »

You can't have a "fixed variable" timestep. It's one or the other. Pointing

Of course we need code snippets. We can't read your mind. persecutioncomplex

My mistake.  That was a stupid miswording.  It's a fixed timestep (I'll fix that in the question).

There's a lot of different code snippets, so I figured we should start with speculation and theory and then I can get you any specific sections of code you need (i.e. rendering logic, timestep loop, etc.)

How much does it jump/stutter? Could be a rounding error (or lack thereof) when drawing or faulty interpolation.

That or it could just be Swing, if you're using that.

I'm using Math.round when applying the interpolation to rendering positions.  That should work fine right?

I am using Swing.  The goal of the engine was to use pure Java2D.  Surely it can work....
Offline jonjava

JGO Knight


Medals: 33



« Reply #4 - Posted 2013-01-06 23:10:07 »

Could be Swing, the code, system clock or a number of things.

A notorious cause can be the inaccurate windows clock which you can force to use a more accurate one by making an infinite daemon loop. The "windows daemon fix" which some call it.

Game loops have been discussed extensively and the slight stutter you mention isn't unheard of:

Game loops:
http://www.java-gaming.org/topics/game-loops/24220/view.html

Stutter discussion:
http://www.java-gaming.org/topics/slight-jerkiness/24311/view.html

Offline ghostsoldier23

Junior Member


Medals: 1



« Reply #5 - Posted 2013-01-07 21:14:12 »

Could be Swing, the code, system clock or a number of things.

A notorious cause can be the inaccurate windows clock which you can force to use a more accurate one by making an infinite daemon loop. The "windows daemon fix" which some call it.


I am actually already using that infinite daemon timer fix.  It does seem to work quite nicely for the Windows timer.

After switching the buffer and display BufferedImages to native image type (Graphics.createNativeImage I think is the method), and adding the -Dsun.java2d.opengl=true VM argument, the stuttering seems to be mostly gone on Windows.  It does still occur on Linux, however.  That actually surprises me quite a bit.... I would've expected Linux to perform better.

That may have something to do with my Graphics driver on Linux.  Not sure.  Are there any known issues with Java2D on Linux?
Offline Eli Delventhal
« League of Dukes »

JGO Kernel


Medals: 39
Projects: 12


Game Engineer


« Reply #6 - Posted 2013-01-08 01:27:44 »

Unfortunately Java2D just can't be relied upon. Your issues sound like they may be unique to your system or drivers, but that's just the problem – you're always going to have machines that have issues. This is complete guesswork, but in my experience around 10% of people have problems of one kind or anything playing games I have made in Java2D. It's also worth mentioning that Applets are for the most part broken now because of all the security scares (Apple no longer has Java enabled without fiddling, for example), so there is little advantage to using Java2D. You might as well touch the hardware if you have a downloaded app.

See my work:
OTC Software
Offline ghostsoldier23

Junior Member


Medals: 1



« Reply #7 - Posted 2013-01-10 05:05:48 »

I was able to bring the stuttering down to a reasonable minimum on Linux, and nearly eliminate it on Windows.

I find that playing with various things such as BufferStrategy buffer count, render ops, and max-updates in the fixed timestep can make a difference depending on the platform.  That seems reasonable.  It isn't uncommon that you have to adjust video settings in a game to get optimal results.

Setting the JVM flag -Dsun.java2d.opengl=true REALLY helps.  I highly recommend that to anyone having slow rendering/stuttering problems in Java2D.
Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (111 views)
2013-05-17 21:29:12

alaslipknot (120 views)
2013-05-16 21:24:48

gouessej (149 views)
2013-05-16 00:53:38

gouessej (143 views)
2013-05-16 00:17:58

theagentd (156 views)
2013-05-15 15:01:13

theagentd (140 views)
2013-05-15 15:00:54

StreetDoggy (184 views)
2013-05-14 15:56:26

kutucuk (208 views)
2013-05-12 17:10:36

kutucuk (208 views)
2013-05-12 15:36:09

UnluckyDevil (213 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.093 seconds with 20 queries.