Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  New Timer Code  (Read 4033 times)
0 Members and 1 Guest are viewing this topic.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Posted 2005-03-09 12:15:11 »

Hey all, the org.lwjgl.Sys class now has a radically redesigned hires timer.

On Speedstep, HyperThreaded, or dual-processor systems, the hires timer reports wildly inaccurate values (you can check this yourself using System.nanoTime()). Unfortunately this renders every single game I've got on my speedstepped hyperthreaded laptop totally unplayable - even my own games, which I've had to develop with the problem! HalfLife 2 sucked greatly because of this as well.

The symptom manifests itself as the game suddenly going into treacle 30fps mode for a few seconds, then speeding back up to normal rate, over and over. It's horrible.

Sometimes you can start out at normal speed but then the game speeds up instead.

The new hires timer continually corrects itself to take account of this phenomenon. It's not 100% perfect (it can't ever be 100% perfect because it basically has to make a guess that something's wrong 2-3 frames after the slowdown begins) but I can finally play Puppytron at a creamy smooth 60fps on my own computer. And Valve with their multi-million dollar budgets don't appear to be any the wiser Smiley

Just thought I'd let you know.

Cas Smiley

Offline jbanes

JGO Coder


Projects: 1


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


« Reply #1 - Posted 2005-03-09 13:27:29 »

FYI, the "correct" thing to do is to set the processor affinity so that the timer values don't jump around. It's not a guarantee, but it does usually prevent the issue.

EDIT: BTW, did you ever get your AMD64 machine?

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

Junior Member




where I should sign ?


« Reply #2 - Posted 2005-03-09 13:46:17 »

there is a bug opened at Sun for System.nanoTime() ? what a workaround ...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2005-03-09 18:07:25 »

Affinity doesn't help (tried it as well, just to prove this), and you can't do this from Java anyway, and what's more of course it means you lose a whole core which might otherwise have been used for something more useful.

This is not a "bug" in nanoTime, it's a bug in just about all the timer code you're ever likely to see. Every single game on this laptop runs badly as a result of this issue.

<edit>Jerason - seeing as the LWJGL code is BSD licensed it might well be good for you to have a look at what I've done and incorporate it in GAGETimer, which of course suffers from the same problem.

Cas Smiley

Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2005-03-14 15:02:46 »

Further update:
I've removed the timer calibration code, and ditched the hires timer completely from LWJGL win32. Now we are using a timer which is accurate to 1ms, which is accurate enough for most purposes (and is also, coincidentally, how accurate the Linux and MacOS timers are too).

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #5 - Posted 2005-03-14 16:58:42 »

Awwww... Sad

>Now we are using a timer which is accurate to 1ms, which is
>accurate enough for most purposes

Framecapping needs more than that. Eg 1000/60... 16.666 etc msec. 17msec is 58.8fps and 16msec is 62.5fps. :-/

Please put it back in. The other one can stay there as alternative timer if you like.

弾幕 ☆ @mahonnaiseblog
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2005-03-14 18:48:34 »

I will enable the QPC timer if a special system property is set. Otherwise 1ms is pretty much accurate enough for more-or-less consistent framerates on all 3 OSes.

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #7 - Posted 2005-03-14 23:37:04 »

Thanks Smiley

弾幕 ☆ @mahonnaiseblog
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2005-03-15 09:22:36 »

Just remember that if you use it you'll break your code on my laptop Smiley

Cas Smiley

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #9 - Posted 2005-03-16 08:43:57 »

Any chance of being able to choose the QPC timer per default but fall back if the computer it's running on won't be able to use it?

And is there no such thing as a QPC timer available on mac and linux, or is it just not implemented in LWJGL? I would be surprised if a mac didn't have any high resolution timer...

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

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2005-03-16 09:39:30 »

I'm very wary of enabling QPC by default as it is definitely broken and the problem is going to get worse and worse as more HT/Speedstepped systems are deployed. I would rather use the 1ms timer by default and then we're at parity with the Mac / Linux implementations as well.

Cas Smiley

Offline Spasi
« Reply #11 - Posted 2005-03-16 17:13:31 »

I found the following in an NVIDIA newsletter tip:

Quote
Don't use the Read Time Stamp Counter (RDTSC) to do timing in your app. Here's why: it is unusable on mobile platforms because calculations assume a fixed clock speed. Mobile platforms (such as notebooks) will throttle back the CPU at unexpected times making the tick count from RDTSC useless. Instead use QueryPerformanceCounter, which insures consistent architecture independent results.
Offline tom
« Reply #12 - Posted 2005-03-16 19:44:12 »

Quote
I found the following in an NVIDIA newsletter tip:

Don't use the Read Time Stamp Counter (RDTSC) to do timing in your app. Here's why: it is unusable on mobile platforms because calculations assume a fixed clock speed. Mobile platforms (such as notebooks) will throttle back the CPU at unexpected times making the tick count from RDTSC useless. Instead use QueryPerformanceCounter, which insures consistent architecture independent results.

I think the problem is that QPC falls back on RDTSC on some hyperthreaded system. Thus makeing QPC just as useless as RDTSC.

Could we have both QPC and the new timer in lwjgl at the same time. Just document the differnces and potential problems.

cas: Have you mesured the frequency that you get with QPC on the laptop with the one you get on working computers. If it falls back on RDTSC the freq will be much higher than usuall. Could it be possible to detect a potential problem?

Offline jbanes

JGO Coder


Projects: 1


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


« Reply #13 - Posted 2005-03-16 19:52:17 »

FYI, QueryPerformanceCounter is what the GAGE DLL uses. The problem is that it screws up on multiprocessor systems unless the affinity is set.

Hyperthreading is definitely a cool technology, but I've seen quite a few programs screw up and die on it. For example, a Java program I wrote ends up in a race condition when it loads information on startup. Bad, bad, bad. It's going to take some work to figure out how to properly deal with HyperThreaded systems. :-/

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

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2005-03-16 21:13:40 »

The solution is simple: use timeGetTime instead Smiley It's not as hi-res but who cares, it's consistent and it's more or less all we need!

Cas Smiley

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.

Dwinin (6 views)
2014-07-29 10:59:34

E.R. Fleming (20 views)
2014-07-29 03:07:13

E.R. Fleming (8 views)
2014-07-29 03:06:25

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

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

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

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

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

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

danieldean (42 views)
2014-07-17 23:41:23
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!