Timing

Hi everybody!

This is my first posting here because I’m a newbie with java.
I’ve programmed before with C/C++ and used queryPerformanceCounter for timing.
In java I know only System.currentTimeMillis() and I was wondering
if there is any better/faster way than it?
(I haven’t found myself)
If java has many ways to do timing, which is the best?

Congratulations, you found one of java’s oldest shortcomings. :slight_smile:
System.currentTimeMillis() is the only way to measure time without any additional packages/libraries.
If you want to use an additional library:
LWJGL, Java3D and GAGE all have a high resolution timer.
Use LWJGL if you are planning to go for max performance 3D graphics and sound using openGL/openAL, use java3D of you want a convenient general purpose 3D scenegraph API or GAGE if you want to create games using the standard java API’s.
(The authors will surely correct me if I’m wrong somewhere ;))

There is a hidden hires timer in the 1.4.2beta…

http://www.java-gaming.org/cgi-bin/JGOForums/YaBB.cgi?board=Tuning;action=display;num=1053157119

Well you can’t rely on it. It won’t stay there for sure but there will be one in the future :slight_smile:

Untill it’s official you should do some stuff with the mentioned libs. I like lwjgl most… but it depends on your needs :wink:

Thanks both of you

I’m not planning to go 3D yet. :’( (just starting 2D with java)
But I think I’ll take a look at the packages.
So where can I get LWJGL and GAGE? ???
And what kind of libraries they are? ???

So where can I get LWJGL and GAGE? ???

lwjgl:
http://java-game-lib.sourceforge.net

gage:
http://java.dnsalias.com/

And what kind of libraries they are? ???

LWJGL is a openGL wrapper, openal (sound) and input - everything you need to make a fast 2d or 3d game. BTW we have a nice lwjgl forum here :wink:

GAGE is a lib for handling 2d stuff and sound. It should be easier to use GAGE for your first 2d game (or your first bunch of games ;)).

Both libs are 100% free to use (even for commercial projects) and are written by talented people of this forum :slight_smile:

LWJGL: http://java-game-lib.sourceforge.net
GAGE: http://java.dnsalias.com

Disclaimer: I’m the GAGE author. I think you’ll like GAGETimer tho. :slight_smile:

How do I use the GAGE timer? what is the animation loop? is it the one at the bottom of the page?

[quote]How do I use the GAGE timer? what is the animation loop? is it the one at the bottom of the page?
[/quote]
The timer is very simply that, a timer. It will give you the current time if you ask. The GAGETimer also includes a way to limit the framerate, thus the algorithm at the bottom of the page. You only need to limit the rate if you have VSyncing disabled. Look at the JavaDocs for some good info on how to interface with the class.

Edit: Added link to JavaDocs

Oh I get it. So after importing the API I just instanciate by saying timer = new AvancedTimer() and later can make the timer.sleep(…) calls in my animation loop.
Question, is your timer a native timer?

Is the GAGE timer windows only? I only saw a library for windows (.dll) and was just wondering.

Kev

GAGE is fully cross platform. The DLL is specific to Windows to get around Windows’ poor timing ability.