Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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  
  Help with Timer  (Read 1887 times)
0 Members and 1 Guest are viewing this topic.
Offline Darrin

Junior Devvie

Projects: 1

« Posted 2009-04-09 02:12:33 »

Ok so I was thinking about going to Jogl or Slick or LWGL but I've spent so much time with Java2d that I thought that maybe I could optimize things to run well on large screen sizes over 1000 wide.   With that in mind, I've started testing everything I can think of.  The first thing weird that occurs is the timer.

I'm using the standard Kevin Glass setup with a delta with non-recommended System.currentTimeMillis

try { Thread.sleep(loopTime+10-System.currentTimeMillis()); } catch (Exception e) {}


1) Framerate changes drastically everytime I run the test even though all I'm doing is drawing tiles and backgrounds.  Sometimes it is 65 fps and others 94. 
2) For some reason setting the delay between 9-12 seems to have little effect on the frame rates.

Question:  Why does the frame rate vary everytime I run it?

Okay so now I throw out the System.currentTimeMillis and go to the Gage timer.

try { Thread.sleep(loopTime+10-SystemTimer.getTime()); } catch (Exception e) {}

Presto I start getting 95 to 96 fps everytime. 

Question why would I be getting a 1% improvement in frame rates wth a different timer?

Is there a better timer than Gage?

Additional notes:  I reran these test about 60 times and it really seems like Java has an issue with the 10 delay.   Even with both timers I get different frame rates.   11 is fine  and 9 is fine but 10 seems to cause problems with both of them.

Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #1 - Posted 2009-04-09 06:20:06 »


I'm guessing you're running a Windows machine, because the resolution of currentTimeMillis on Windows is really pretty bad - somewhere around 50 ms I think. This can cause a fluctuating framerate.

I don't know why 10 specifically causes problems - I'd guess it's actually caused by something else.

See my work:
OTC Software
Offline cylab

JGO Wizard

Medals: 89

« Reply #2 - Posted 2009-04-09 10:26:08 »

somewhere around 50 ms I think

It's usually between 15 and 17 for my, with some spikes sometimes...

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Darrin

Junior Devvie

Projects: 1

« Reply #3 - Posted 2009-04-09 12:35:09 »

Yes windows xp, sorry for not being clear.

I changed the code to:  try { Thread.sleep(10); } catch (Exception e) {}

And got the same results.  10 is not liked by the system.   With the Gage timer, both 9 and 11 are faster.   With System.currentTimeMillis(); it is all over the place but always slow on 10 about 65 fps.

hmm I'll look into the nanotimer.

Offline Darrin

Junior Devvie

Projects: 1

« Reply #4 - Posted 2009-04-09 13:06:35 »

What a mess!   Seems to be a Microsoft / Java issue.   So doesn't really matter if you use nano or whatever.

-XX:+ForceTimeHighResolution   kills performance but makes the resolution 10 always or something like that.  I always get 65 fps never higher.   This might be a good thing for animation if not so low.  I wonder what it does on other operating systems?

here is the sun blog

David Holmes suggests a task repeater but that seems like it might be bad for games.   Anyone tried it?

Offline Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

« Reply #5 - Posted 2009-04-09 19:40:19 »

Hm, I rarely test on Windows personally, but this is definitely not the first time I've heard of problems with the Windows timer. On Mac OS X I've never had issues with either currentTimeMillis or nanoTime.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (12 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (17 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (29 views)
2015-07-25 00:14:37

BurntPizza (40 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (27 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!