Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 1632 times)
0 Members and 1 Guest are viewing this topic.
Offline Darrin

Junior Member


Projects: 1



« Posted 2009-04-09 04: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) {}

Results

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


Game Engineer


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

System.nanoTime

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 Ninja


Medals: 38



« Reply #2 - Posted 2009-04-09 12: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 Member


Projects: 1



« Reply #3 - Posted 2009-04-09 14: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 Member


Projects: 1



« Reply #4 - Posted 2009-04-09 15: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

http://blogs.sun.com/dholmes/entry/inside_the_hotspot_vm_clocks

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


Game Engineer


« Reply #5 - Posted 2009-04-09 21: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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (12 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!