Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  High resolution Timers  (Read 6454 times)
0 Members and 1 Guest are viewing this topic.
Offline moorej

Senior Newbie




Mmmm Lasagna....


« Posted 2003-06-22 10:10:00 »

There are significant flaws in the millisecond timer that ships with the normal JDK.  I am suggesting that we write a High Resolution Timer to give microseconds, just as Magician did, otherwise I've found java animation to be a little jumpy.  Take a look at : http://www.javaworld.com/javaworld/javaqa/2003-01/01-qa-0110-timing.html?

I think this is the way to go.

Another question is that If I wanted to write this and submit it back, what is the process to do that.  I tried to register as a developer but the jogl admins said they weren't accepting that role yet.

-Jason
Offline kevglass

« JGO Spiffy Duke »


Medals: 212
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-06-22 10:24:46 »

If you read around a bit, there are high resolution timers available in:

* Java 3D
* GAGE
* A hidden on embedded in JDK1.4.2 (which I suppose will be made available properly in the next release?)

Either way, use one of them, lets not get another one going...

Kev

Offline moorej

Senior Newbie




Mmmm Lasagna....


« Reply #2 - Posted 2003-06-23 22:55:00 »

I need a true cross platform API for the timers, Java3D isn't going to cut it.  I have not run across the GAGE timers before and unfortunately there is only a Windows implementation.

The fact that it's a hidden on JDK1.4.2 and may be exposed in a later version is a trend in the right direction, now all we need is unsigned primitives and we're all set...  Smiley

I will look at writing more of the ports for the GAGE timers, it appears to be not quite what I need, but thanks for the heads up.

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

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2003-06-23 23:20:54 »

What do you need better than 1/1000 of a second for? I designed GAGETimer to give *at least* 1/1000 of a second no matter the platform. That's about 10 times what is needed to provide 100 frames per second. The reason why there's only a Windows DLL is because Windows is the only OS that doesn't provide millisecond resolution.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline josgood

Senior Newbie




Nudge reality.


« Reply #4 - Posted 2003-06-24 03:47:43 »

jbanes et al-


I just looked at GAGE's AdvancedTimer.  It's the exact right solution.

In defense of moorej's request, sometimes it's fun for benchmarking/profiling, like with a ProfileGL.


Cheers, Jason
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2003-06-24 12:40:39 »

Quote
In defense of moorej's request, sometimes it's fun for benchmarking/profiling, like with a ProfileGL.


True. I was just curious as to why he thinks he needs better than millisecond resolution. There *are* actual needs for such a timer, but the need is pretty rare and usually has little to do with games. Profiling is "fun", but any code that runs in less than a millisecond probably doesn't need to be optimized anyway. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline shawnkendall

Senior Devvie





« Reply #6 - Posted 2003-06-24 13:20:47 »

1/60 second = 0.0167 second or 16.7 millisecond

So if you want get it right you need better than 1 ms...

Shawn Kendall
Cosmic Interactive, LLC
http://www.facebook.com/BermudaDash
Offline abies

Senior Devvie





« Reply #7 - Posted 2003-06-24 13:34:34 »

Quote
Profiling is "fun", but any code that runs in less than a millisecond probably doesn't need to be optimized anyway. Smiley


If we are talking about games, you have, let's say, 5 ms per frame for computations - another 5-15 for rendering. I think that ANY method which comes close to 1ms mark is a target for HEAVY optimalization Smiley

Bigger problem is that you cannot measure too small periods with even good timer, because overhead of measurement comes into play. But this point is well below 1ms.

Artur Biesiadowski
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #8 - Posted 2003-06-24 14:25:58 »

Quote
1/60 second = 0.0167 second or 16.7 millisecond

So if you want get it right you need better than 1 ms...


You're going to need better than a millisecond of play room for each loop due to scheduling concerns of the OS. If you try to deal in the .7 ms range you're going to get burned.

Quote
If we are talking about games, you have, let's say, 5 ms per frame for computations - another 5-15 for rendering. I think that ANY method which comes close to 1ms mark is a target for HEAVY optimalization


Yes, any method that is 1ms or greater should be optimized. Anything in the sub-ms range is probably fine. Of course, that assumes that you're profiling chunks of code such as map drawing vs. sprite drawing vs. collision detection. My own experience tells me that trying to profile the individual components of these tasks is pretty pointless (scheduling tends to interfere) unless you are looking for a "hotspot" that's eating away at your time.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline paul

Junior Newbie




Java rocks!


« Reply #9 - Posted 2003-06-24 17:06:39 »


The Java3D high resolution timer uses the highest res timers available in each OS. The timer is in the utils class so should
be reusable in jogl.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mark Thornton

Senior Devvie





« Reply #10 - Posted 2003-06-24 18:37:43 »

Quote

The Java3D high resolution timer uses the highest res timers available in each OS. The timer is in the utils class so should
be reusable in jogl.


The Windows QueryPerformanceCounter method gives areound 1us resolution on a single processor machine but CPU clock frequency on dual processors. My own timer for Win32 uses the CPU clock counter all the time (for both single and dual processors).

I use this for profiling short sections of code that might typically be called 10s of millions of times. Discarding high value outliers strips out the scheduling interference and gives reliable and accurate results for code taking as little as 10us.
Offline Smoke

Senior Newbie




games rock!


« Reply #11 - Posted 2003-06-24 19:46:50 »

imho a serious programming language should have serious timing tools.

you know... i keep hearing: "java for games? lol that has only 50ms timing resolution!"

come on sun guys. give yourself a little push and roll out a neat little timer for us. please?  Kiss
Offline moorej

Senior Newbie




Mmmm Lasagna....


« Reply #12 - Posted 2003-06-24 22:45:57 »

I never expected my little request to cause such a fever of discussion.  Grin Timers are critical to accurate animation and for profiling.  While you may all be looking at uses for jogl that are for games.  I am not.  I am currently using GL4Java to write the realtime visual portion of simulations, for scientific analysis, and for non-realtime rendering to generate MPEG's.  I do not know if there is a concensus here, I am feeling that there is not, but it brings up a more important question on how the open source community is going to deal with Requests For Enhancements (RFE) for jogl?  The jogl site has an area for votes, are we to use that?

-Jason
Offline leknor

Junior Devvie




ROCK!!!


« Reply #13 - Posted 2003-06-25 00:18:38 »

<rant>The explanation I heard, from Jeff I think, for the resolution of currentMillis on windows being so bad was because Sun didn't want to have to load the Media libs which was slowing startup time of the JVM. I can understand that and I think that is a valid reason, but what I don't understand is why they don't start up with the low resolution timer and then 10 or 15 seconds after the JVM is loaded swap in the higher resolution timer. Yea, it's a hack. Yes, it means you could get different resolutions at different times. But the resolution is undefined so it's legal wrt to the API docs. It solves the JVM startup problem, and it satisfies the game community. Also, you cannot tell me it isn't possible because we already know the JVM can load dynamic libraries at run time.</rant>
Offline Jeff

JGO Coder




Got any cats?


« Reply #14 - Posted 2003-06-25 06:26:51 »

Even more to the point there are techniques for doing high precision timing without using the media libs.

The good news is that there is a high res timer now (1.4.2) in the the com.sun.* space and I am hopeful it will migrate to standard API space by 1.5


Why wasn't it done before? 'cause before you guys came along noone made enough noise about it Wink

Jeff

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Mark Thornton

Senior Devvie





« Reply #15 - Posted 2003-06-25 06:29:41 »

I can't remember if the Windows media timer is properly synchronized to 'time of day'. We currently use java.System.currentTimeMillis for two different purposes: finding the current date and time, and for measuring (usually short) intervals. Windows provides at least 3 different timers:
a) Date/time
b) media timer
c) performance counter
You certainly can't use the performance counter to obtain the current date. I think Java should provide separate interfaces for each of these classes of timer, which might on some systems use a common timer internally.
Offline gregorypierce

Senior Devvie




I come upon thee like the blue screen of death....


« Reply #16 - Posted 2003-07-10 19:18:55 »

Just kinda read through this thread and kinda received an interesting vibe from something. Are you guys saying that the best way to get a certain frame rate from Java is to do a:

render()
Thread.sleep( sleepTime );

where sleepTime = (1/fps) * 1000 ?

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline moorej

Senior Newbie




Mmmm Lasagna....


« Reply #17 - Posted 2003-07-10 22:24:40 »

If you ask me, that is a terrible way of setting frame rate.   You need to ask yourself whether you want a FPS construct at all.  Most of the time, games want to render as many frames per second as possible.  If that is the case then you want to record the time between the last time that you rendered and the next time and that would dictate the amount on animation that has taken place and update the locations of elements accordingly.

-Jason

I am sure someone is going to argue with me on this, so look for some good discussion.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #18 - Posted 2003-07-11 00:09:27 »

I'm not going to disagree.    Your method is perfectly valid.  I will point out though that there are many types of games that don't have enough action to warrant that method. For games on PCs, particularly games that would run in a window, it makes sense to throttle back the actual CPU usage instead of actively drawing the exact same frame a hundred times a second.  I could be playing a game while I wait for my disk to defrag, or I'm printing a large document, etc.  The idea of taking over the machine doesn't always fit.  Be friendly to multitaskers when appropriate.

Gregory left out a bit in his sleepTime calculation.. the amount of time it took to execute the render() call should be subtracted from the sleepTime.  If sleepTime < 0 you can't keep up at that framerate and might be able to do something about (like lower detail).

Offline gregorypierce

Senior Devvie




I come upon thee like the blue screen of death....


« Reply #19 - Posted 2003-07-11 00:22:58 »

From my perspective I'm more looking for consistency than high frame rate. If I can guarantee 60Hz that's actually fine by me - that's what I want to do, moreso  trying to get hundreds of frames per second.

You are correct palmer about the time computation, I was speaking in more general terms. I didn't expect that Thread.sleep() ran at such a resolution to allow one to lock a framerate using that method. I assumed that the resolution was such that native code would be required.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline Mark Thornton

Senior Devvie





« Reply #20 - Posted 2003-07-11 07:08:04 »

On Windows sleep does provide millisecond resolution for the interval. The catch is that the standard resolution in which you can measure the time elapsed (in the sleep and in the renderer) is only 10ms (or 15.625ms on some systems).
This means you either use JNI, the new hidden timer in 1.4.2, or have a thread with sleep(1) and a counter in a tight loop to provide extra time measurement resolution.
Also watch out for this (look at the related bug as well)
http://developer.java.sun.com/developer/bugParade/bugs/4500388.html
Offline Rob Nugent

Junior Devvie




May contain nuts


« Reply #21 - Posted 2003-07-11 11:38:49 »

For information, see the following RFE:

http://developer.java.sun.com/developer/bugParade/bugs/4478186.html

'Add a high-resolution timer to the API'.
Offline gregorypierce

Senior Devvie




I come upon thee like the blue screen of death....


« Reply #22 - Posted 2003-07-11 16:07:02 »

Actually I've been talking to a variety of developers and it seems that there are variety of high resolution timers scattered in optional classes/APIs like Java3D and the Apple Sound utility classes.

Quote

In the mean time you might consider using the
com.apple.audio.util.HostTime class. Specifically getCurrentHostTime()
returns an AbsoluteTime which is a system bus cycle count. There are
utility methods to convert that to e.g. nanoseconds. Is that hi res
enough for ya?


At the moment I don't want to use native code for a timer because I don't want to factor in more native code right now (harder to refactor out when everyone has 1.5) so for right now I'm going to use all of the piecepart Java APIs like the bootleg hidden stuff in 1.4.2 and the Apple timer in 1.4.1 (since there is no 1.4.2 yet).

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!