Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Timer?  (Read 1445 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Posted 2005-12-30 23:13:14 »

Any good texts on game-loop-timers? I need to synchronize player movements for my game, because it's gonna be multiplayer. Any good pointers?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-12-31 01:16:04 »

If all you need is high precision timing and you are under 1.4 or ,later, use the nanotimer.

if you need to synchronize time between machines, you'll probably need  to use some form of NTP

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 tom
« Reply #2 - Posted 2005-12-31 02:01:38 »

nanotimer was introduced in 1.5. In 1.4 you can use GAGETimer or sun.misc.Perf. Some graphics libs like Java3d and lwjgl also provide their own hires timers. They all use the performance counter on windows except lwjgl wich use timeGetTime().

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

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #3 - Posted 2005-12-31 02:08:58 »

I don't find the LWJGL timer to be very good.  I switched my game to 1.5 recently and replaced the LWJGL timer call with nano time and wow...huge difference in accuracy at least on my windows XP - I was just messing around, not expecting anything much and was very surprised at the difference.

Offline tom
« Reply #4 - Posted 2005-12-31 02:33:04 »

QueryPerformanceCounter is used by most hires timers and it is affected by change in clock speed. That is bad on laptops that change the mhz to save power. timeGetTime() has a maximum resolution of 1 ms. But in order to get that you need to use sleep(1) instead of yield in your game loop. Even then it will only get 10-15ms resolution on some computers, like mine. It just don't always work. So there is no hires timer that works all the time, and that is a royal pain in the ass.

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #5 - Posted 2005-12-31 04:03:31 »

Perhapse I should have stated, this is for a game I'm making for the 4K competition.

Perfect accuracy isn't required, small differences are acceptable, but not something that is noticable.

Currently, I'm doing something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
long startTime;
while(true) {
   startTime = System.currentTimeMillis();
   
   update();
   draw();

   do {
      Thread.yield();
   } while (System.currentTimeMillis()-startTime< 10);
}


But I don't know how good this will be in the multiplayer game.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2005-12-31 05:08:39 »

QueryPerformanceCounter is used by most hires timers and it is affected by change in clock speed.

This should be BR'd.  How are C games handling modern laptops?

 

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 Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2005-12-31 05:10:31 »

Perhapse I should have stated, this is for a game I'm making for the 4K competition.

Perfect accuracy isn't required, small differences are acceptable, but not something that is noticable.

Currently, I'm doing something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
long startTime;
while(true) {
   startTime = System.currentTimeMillis();
   
   update();
   draw();

   do {
      Thread.yield();
   } while (System.currentTimeMillis()-startTime< 10);
}


But I don't know how good this will be in the multiplayer game.

currentTimeMillis is pretty much the worst of all options. the nanotimer was invented to deal with its short-comings.

I dont get your multi-player issue.  You are goinmg to have to describe how you are doing multiplayer in a lot more detail I think.

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 Mr_Light

Senior Member




shiny.


« Reply #8 - Posted 2005-12-31 13:54:27 »

This should be BR'd.  How are C games handling modern laptops?
poor.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #9 - Posted 2005-12-31 14:34:48 »

I don't find the LWJGL timer to be very good.  I switched my game to 1.5 recently and replaced the LWJGL timer call with nano time and wow...huge difference in accuracy at least on my windows XP - I was just messing around, not expecting anything much and was very surprised at the difference.
yeah, because you're not on a HT CPU or speedstep or whatever. Once those kick in, QPC will give you errors. (nanotime).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #10 - Posted 2005-12-31 14:48:25 »

Perhapse I should have stated, this is for a game I'm making for the 4K competition.

Take a look at the throtteling code posted in the "is this the best performace I can get from the game loop?" thread.

Quote
currentTimeMillis is pretty much the worst of all options. the nanotimer was invented to deal with its short-comings.
He can not use the nanotimer as the 4k entries have to be compatible with 1.4.

Offline woogley
« Reply #11 - Posted 2005-12-31 17:08:37 »

appel's attempt at a networked 4K game is brave to say the least, because the code to cover both the server and client can sum up to no more than 4K. The only 4K game that has pulled off networking thus far is IsOlation Net
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.

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

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

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

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

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

danieldean (30 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47
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!