Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  How does getTimeInMillis() work??  (Read 2741 times)
0 Members and 1 Guest are viewing this topic.
Offline Rarkon

Senior Newbie




Oh god the universe is collapsing on me!!!


« Posted 2004-03-22 20:34:28 »

I'm trying to get my game to render properly without refresh line. But the redering code I've come across all seem to need getTimeInMillis. So my question is how do you use getTimeInMillis, or if you know of a way to render without getTime please tell me. Thank you.


p.s. sorry if this was asked I'm new and I couldn't find it using search.
Offline dreamweaver

Junior Newbie




Java games rock!


« Reply #1 - Posted 2004-03-23 03:11:15 »

I'm newbee too .
Really don't understand clearly but Java has
System.getCurrentTimeMillis() if you need.
Offline Jeff

JGO Coder




Got any cats?


« Reply #2 - Posted 2004-03-30 22:11:29 »

True though its accuracy is bad under Win98

Most game use GAGE totday. You can google for it.

JDK1.5 has the nanosecond timer which is gauranteed to have a good accuracy.

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
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 2004-04-01 16:25:44 »

Quote
True though its accuracy is bad under Win98

Most game use GAGE totday. You can google for it.

JDK1.5 has the nanosecond timer which is gauranteed to have a good accuracy.


Ack! Poor guy! He'll be trying to figure out what N-GAGE has to do with anything.

The GAGETimer API can be found at http://java.dnsalias.com

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

JGO Coder




Got any cats?


« Reply #4 - Posted 2004-04-01 18:04:12 »

Thanks JB.

jk

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 D.t.O

Junior Member




Psych'd about Java Games


« Reply #5 - Posted 2004-04-02 18:46:37 »

http://java.dnsalias.com:
Quote
GAGETimer has been updated to support the Java 1.5 System.nanoTime() method. The nanotimer is the default timer under 1.5 VMs. Previous Java versions will continue to use System.currentTimeMillis() or the native Windows timer.

Is the "native Windows timer" more accurate than the Java currentTimeMillis() timer? I thought currentTimeMillis() was native..

Enjoy.
Regards,
     - D.t.O
Offline jbanes

JGO Coder


Projects: 1


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


« Reply #6 - Posted 2004-04-02 20:07:43 »

The currentTimeMillis() timer only ticks 20-100 times per second on Windows. This is far too slow for a high performance game. Thus I added a DLL to GAGETimer that allowed it to access the Windows Hi-res timer which ticks ~30,000 times per second. This is what most people have been using. 1.5 has added a new timer (nanotimer) that ticks some ungodly number of times per second. This is now the default if you're using 1.5. Grin

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

JGO Coder




Got any cats?


« Reply #7 - Posted 2004-04-04 22:45:53 »

Quote
http://java.dnsalias.com:
Is the "native Windows timer" more accurate than the Java currentTimeMillis() timer? I thought currentTimeMillis() was native..


There are multiple tiemrs under Win32.

currentTimeMillis uses the standard system timer, its accuracy is bad (under NT) to horrible (under 98).

There is another timer called the multimedia timer but there are Win32 performance reasons why the standard
currentTimeMillis() doesn't use it.

If you are under 1.5 use the nanosecond timer.
Otherwise use GAGE Smiley

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 endolf

JGO Knight


Medals: 7
Projects: 1


Current project release date: sometime in 3003


« Reply #8 - Posted 2004-04-05 08:35:06 »

But don't use it on a game server Smiley, client side fine, but not on the server, ~60% CPU usage v.s. 0.1% Smiley

No idea why, but that was the only change Smiley

Endolf

Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2004-04-05 08:47:54 »

Whelp i did say there were performance reasons for using the lower accuracy timer under Win32 .

Otehrwise they wouldve just changed the timer's implementation instead of creating a whole new entry point.

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline endolf

JGO Knight


Medals: 7
Projects: 1


Current project release date: sometime in 3003


« Reply #10 - Posted 2004-04-05 09:35:48 »

That was under linux, so that probably makes a huge difference, as I'm not sure how gage handles linux

Offline jbanes

JGO Coder


Projects: 1


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


« Reply #11 - Posted 2004-04-05 17:31:42 »

Quote
That was under linux, so that probably makes a huge difference, as I'm not sure how gage handles linux


Depends on how you use it. GAGE is built to be the most accurate and precise timer for games possible with current Java technology. If you're going to use it for a game server, make sure you don't use the sleep methods! These methods are designed to spin on sleep, and will degrade the performance of a multithreaded server environment. If you just want to know the current time, GAGE should still work fine.

What were you using it for on your server?

Java Game Console Project
Last Journal Entry: 12/17/04
Offline D.t.O

Junior Member




Psych'd about Java Games


« Reply #12 - Posted 2004-04-05 18:27:52 »

Quote
...make sure you don't use the sleep methods! These methods are designed to spin on sleep, and will degrade the performance of a multithreaded server environment.

What does it mean for a method to "spin on" sleep (or any other method) Huh
This may seem obvious to most, so sorry Embarrassed ... keep in mind I'm a newbie.

Enjoy.
Regards,
     - D.t.O
Offline endolf

JGO Knight


Medals: 7
Projects: 1


Current project release date: sometime in 3003


« Reply #13 - Posted 2004-04-05 19:48:08 »

Quote
What were you using it for on your server?


I'm just the BOFH in this case, but I think it was a sleepUntil.

Endolf

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2004-04-05 20:35:06 »

Guess, I'll have to own up.. it was the MA server and it was indeed using sleepUntil. I had assumed on linux that it would just use a Thread.sleep(), hence my mistake.

Spinning on the sleep means that it constantly loops round on a very small pause, using up lots of processor time..

My mistake has been rectified Smiley

Kev

Offline jbanes

JGO Coder


Projects: 1


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


« Reply #15 - Posted 2004-04-05 20:43:45 »

Quote

What does it mean for a method to "spin on" sleep (or any other method) Huh
This may seem obvious to most, so sorry Embarrassed ... keep in mind I'm a newbie.


1  
2  
3  
4  
public void sleepUntil(long time)
{
    while(System.currentTimeMillis() < time) Thread.yield();
}


By yielding instead of sleeping, the method will return almost to the moment the clock flips over to match the "time" variable. The only problem is that it will use 100% of the CPU to do it. Of course, this isn't a big deal as the method is actually giving up its time to other processes, but anything that the other processes don't use will come right back to that loop.

This method is particularly advantageous when dealing with the System.currentTimeMillis() timer. For example, if I'm deploying my game on Windows 2000, System.currentTimeMillis() gives a tick rate of 100 ticks per second. If we use Thread.sleep(), we have no idea how many milliseconds we have until the next tick. This means that the framerate may jump all over the place as we'll have no idea how often we need to sleep, or for how long. But if we latch onto the digital wave generated by the clock, we can always guarantee exactly 10ms to render each frame. Extra time can be slept off by waiting for the next clock tick.

Here's a graph to demonstrate:

1  
2  
3  
4  
5  
6  
--    --    --
  |__|  |__|

  ^  ^  ^  ^
  |  |  |  |
begin rendering


Make sense?

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

JGO Coder


Projects: 1


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


« Reply #16 - Posted 2004-04-05 20:45:55 »

Quote
Guess, I'll have to own up.. it was the MA server and it was indeed using sleepUntil. I had assumed on linux that it would just use a Thread.sleep(), hence my mistake. ... My mistake has been rectified Smiley


All's well that ends well, right? Grin

Java Game Console Project
Last Journal Entry: 12/17/04
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.

xsi3rr4x (31 views)
2014-04-15 18:08:23

BurntPizza (28 views)
2014-04-15 03:46:01

UprightPath (43 views)
2014-04-14 17:39:50

UprightPath (26 views)
2014-04-14 17:35:47

Porlus (43 views)
2014-04-14 15:48:38

tom_mai78101 (64 views)
2014-04-10 04:04:31

BurntPizza (124 views)
2014-04-08 23:06:04

tom_mai78101 (224 views)
2014-04-05 13:34:39

trollwarrior1 (190 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!