Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  HiResTimer with JNI  (Read 4597 times)
0 Members and 1 Guest are viewing this topic.
mbw
Guest
« Posted 2002-10-28 08:13:52 »

Hi there !

I heard some people use native Timers through the JNI to achieve nano-resolution with windows-platforms.

Does anyone know how to do this, or where to find a tutorial about it ?

I never used JNI, so i would be very glad if someone knows.

mbw
Offline Woz

Senior Newbie




A Troll who lives in a hole


« Reply #1 - Posted 2002-10-28 09:55:18 »

Java Pro had an article about using the high res timer for windows (along with the code needed):
http://www.fawcette.com/archives/magazines/javapro/

Entitled: Time for Java by a chap called Kevin T. Manley, Dated 2001/08.
Try:
http://www.fawcette.com/archives/listissue.asp?pubID=3&MagIssueId=407#

Or search the old forum for other links & tips.

Hope this helps!

--------
Woz.

P.S.
Why is this post inserting a space between 40 & 7# Huh
The link still works though.
Offline princec

JGO Kernel


Medals: 366
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2002-10-28 10:23:32 »

Or just go grab the Lightweight Java Game Library:

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

Which has one in there. Either pluck the bits of source code out just to do the hires timer, or marvel at all the other useful things you can do and use the lot Grin

If you're using JNI anyway, may as well go the whole hog, eh?

Cas Smiley

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

Senior Member




Friendly fire isn't friendly!


« Reply #3 - Posted 2002-10-28 11:28:05 »

... or look at the hires timer from the latest Java3D release.

I assume it relies on QueryPerformanceCounter() and ticks VERY fast! I've not measured it yet, but I think it's by far good enough for every gaming issue.

I expect this timer to be part of the next J2SE, so your effort will not be wasted.



HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline GergisKhan

Junior Member




"C8 H10 N4 O2"


« Reply #4 - Posted 2002-10-28 14:16:16 »

Anyone care to comment on a Mac OS X version of any of this?

You give me that, so that I can have a mac and windows hi-res timer, I'll be the happiest person.  Grin

If it can't be done, I'd really like to know why.  I have searched for anyone using JNI on the Mac, and nothing.


gK

"Go.  Teach them not to mess with us."
          -- Cao Cao, Dynasty Warriors 3
Offline phic

Innocent Bystander




Java games rock!


« Reply #5 - Posted 2002-11-03 08:32:28 »

I just grabbed the Lightweight Java Game Library (
http://java-game-lib.sourceforge.net/ ) and meassured the granularity of its HiresTimer, and it seems to have an granularity of 0.01 ms and less, whereas System.currentTimeMillies has a granularity of 50 ms on my machine (Win98, K6-2 333MHz).

Is this possible? I can't believe it!
Offline princec

JGO Kernel


Medals: 366
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2002-11-03 09:10:26 »

The hires timer in Windows, and indeed any x86 based machine, is actually a clock-cycle ticker direct from the CPU. Its granularity can be down to 1,000,000,000ths of a second. By contrast the O/S thread scheduler and messaging system is very vague, relying on the fairly low resolution of the system clock.

On MacOS there should be an equivalent hires timer but it's up to Gregory to make the port happen. Of course he can't yet, because he hasn't got a 1.4.x Mac port to play with. But it will rock.

And we still have no takers to port the LWJGL to Linux. C'mon, surely not difficult?

Cas Smiley

mbw
Guest
« Reply #7 - Posted 2002-11-04 07:01:26 »

Thanks for the support guys !  Grin
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2002-11-07 19:55:43 »

Quote
I just grabbed the Lightweight Java Game Library (
http://java-game-lib.sourceforge.net/ ) and meassured the granularity of its HiresTimer, and it seems to have an granularity of 0.01 ms and less, whereas System.currentTimeMillies has a granularity of 50 ms on my machine (Win98, K6-2 333MHz).

Is this possible? I can't believe it!


Karnak the great says...

Youa re running WIin95, Win 98 or Win ME.

And yes thats correct.  The Win32 call used by System.currentTimeMillis()  is very inaccurate on those systems.

Highres tiemrs either call the cloick in the multi-media extensions DLL which is much faster or go directly to the CPU ticks.

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 GergisKhan

Junior Member




"C8 H10 N4 O2"


« Reply #9 - Posted 2002-11-08 06:27:29 »

Cas,

I'd love to do it myself.  There are two problems stopping me:

1) don't own a Mac yet.  I can get 1.4.1, but I have nothing to install it on.  Cry

2) I have ZERO programming experience on the Mac.  So even if I could write the JNI header and such (which I am sure I could) I wouldn't have the faintest notion of what to attach two.

Sorry, I wish I could be more help there.

gK

"Go.  Teach them not to mess with us."
          -- Cao Cao, Dynasty Warriors 3
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Olof Hanell

Senior Newbie




Smooth scrolling rocks.


« Reply #10 - Posted 2002-11-15 23:35:34 »

Just found something that could be useful.

Take a look into the MidiSystem and get hold od an MidiDevice through the MidiDevice.Info class. In it yuo'll have getMicrosecondPosition().

here's what it says:

public long getMicrosecondPosition()

Obtains the current time-stamp of the device, in microseconds. If a device supports time-stamps, it should start counting at 0 when the device is opened and continue incrementing its time-stamp in microseconds until the device is closed. If it does not support time-stamps, it should always return -1.

Returns:
the current time-stamp of the device in microseconds, or -1 if time-stamping is not supported by the device.

anyone tried it?
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.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (35 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (32 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (35 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!