[java] Getting accurate time

Started by
12 comments, last by snowmoon 23 years, 3 months ago
The JMF API includes classes that support high-resolution, multimedia timing. I haven''t tried this myself, but you may be able to use those classes for timing your game loop.

The two classes in particular to look at would be TimeBase and Clock.

While this would require installing the JMF API, you would still be pure Java. Check out the JMF site at Javasoft.com for more information:

http://www.javasoft.com/products/java-media/jmf/index.html
Advertisement
quote:Original post by Jerry Lynn

While this would require installing the JMF API, you would still be pure Java.


I would call that stretching the definition of pure Java. A pure Java program should be able to run on any platform, but all the optional packages and especially those that are still in beta can hardly be found on anything but Sun''s own implementation.

Sun is spewing out new APIs so fast that no other implementation can keep up. In my terminology (I would apprecaite a link to a precise definition) a 100% pure Java program uses only those API calls part of the core JDK API (downloaded with the JDK) or any library written entirely in Java using this API.

Jacob Marner

Jacob Marner, M.Sc.Console Programmer, Deadline Games
Actually there is a cross-platform version of the JMF that is pure Java and will work on all platforms that the JDK 1.2 is available for. In addition there are ''performance'' packs available for Windows, Solaris, and for Linux available from Blackdown.

I would probably not recommend using the cross-platform pack for decoding full screen MPEG''s, but I think you would still be able to use the TimeBase class for loop timing.

So in essence JMF is pure Java, but you can achieve superior performance by installing a version specific for the OS you are using (if available).
If there exists versions of JMF written in pure Java then those versions only have access to API calls from the standard Java API. This means that something like the Timebase functions also must call something in the standard API. In essense this means that they cannot get a higher time accuracy than calls made yourself to the standard API.

So it simply does not make sense that (cross-platform) JMF can giver higher accuracy. For the platform specific optimizations I believe you but not for the other ones. It might be that the cross platform version of JMF simply uses System.currentTimeMillis() which gives a good granularity on most systems (except Windows) and the optimized version for Windows calls the clock cycle counter via JNI.

Cheers,
Jacob
Jacob Marner, M.Sc.Console Programmer, Deadline Games

This topic is closed to new replies.

Advertisement