Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (537)
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  
  Timing in java and networking  (Read 2912 times)
0 Members and 1 Guest are viewing this topic.
Offline Absolution

Senior Newbie




Java games rock!


« Posted 2004-02-16 01:29:19 »

Due to the problem of timing in java, is it not difficult to keep your games in sync.?  Say, one client is using win2k and has 10ms resolution, while another is using 98 and has 15ms resolution.  It's pretty much impossible to run a real-time game and keep the game in sync. on both computers is it not (assuming you want to just send input commands)?  This probably isn't a problem in the latest version since a higher res. timer is available, but what about older applets and such?
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2004-02-16 02:36:07 »

Search for GAGE Timer...  or check the WIKI (link at the top of this page).  This problem has been noted here many times already and the GAGE timer is probably as good as any other solution out there.  (I haven't used it myself)

Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #2 - Posted 2004-02-16 07:29:45 »

Long time timer accuracy and timer resolution do not neccesarily interfere.

When I used to head for currentTimeMillis() in a prototype where it's resolution was sufficient, I found that also the absolute values show a significant drift on different machines. The values can drift by multiple seconds during several minutes of play.

So I use to resynchronize clocks frequently (every minute or so). For my clock sync is the only natural point where I can measure the ping value, I use it to give the user some feedback about the current quality of his connection.


HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2004-02-16 10:36:56 »

Quote
Due to the problem of timing in java, is it not difficult to keep your games in sync.?


Sync'ing distributed clocks is much much harder than the problems of pre-1.5 inconsistencies in java's timing granularity. Distributed time is quite easy if you know how (look up research on vector-time/vector-clocks for a start), which works by not using clocks at all.

Short answer: don't bother with your PC's local clock for game-synch. Use something more high-level (in general), like key-frames. Obviously, it's non-trivial choosing what to use, and depends very much on the architecture of your game.

malloc will be first against the wall when the revolution comes...
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #4 - Posted 2004-02-16 11:43:37 »

From your hint, I found

http://www.vs.inf.ethz.ch/publ/papers/logtime.pdf

which helps to categorize, what kind of time actually is needed.

For sure there's a difference between systems that can talk in 'frames' (e.g. RTS) and one that seems to be continous in time (like a flightsim).

I always try to live with 'roughly synced clocks', so that I can use timestamps that mean at least something, if not the true time. But I admit that it is hard to deal with that.
Object may die remote before I see that I hit them and so on.

Really difficult. For games, maybe its a good strategy to cheat and fake. Taking time into account more or less, depending on what looks better in a particular case Smiley

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

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2004-02-16 11:58:54 »

Quote


Thanks, that's quite a good PDF on the subject.

malloc will be first against the wall when the revolution comes...
Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2004-02-25 03:27:44 »

There are a number of open Java sntp implementations out there.  Thats what Ive used to synchronize system time and deal with drifts.

Micro-timing is somewhat pointless on the intern et where latencies can range for a few hundred ms all the way up to 6 or so seconds for an analog modem retrain.

For timing within an app though, you can use GAGE or the new nanosecond timer in JDK1.5


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 Mark Thornton

Senior Member





« Reply #7 - Posted 2004-02-25 13:40:27 »

Of course the granularity of the new nanoTime method is still likely to vary from system to system even if the operating system is the same.
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2004-02-28 04:51:20 »

Yes, but it is gauranteed to be the best possible  on the platform.

So its as good as you coudl do from native.

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 Mark Thornton

Senior Member





« Reply #9 - Posted 2004-02-28 08:11:08 »

Quote
Yes, but it is gauranteed to be the best possible  on the platform.

So its as good as you coudl do from native.

I have some native code which reads the Pentium clock count register; that is the best possible on this machine but I'm not sure that nanoTime is doing that.

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

JGO Coder




Got any cats?


« Reply #10 - Posted 2004-03-03 03:33:22 »

By definition if it is not producing as accurate a time as you are then its a bug.  Report it and give your native code sample.

That was the reason the definition was written the way it was.

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 #11 - Posted 2004-03-03 10:50:26 »

The "Pentium clock count register" has some issues that may make it unfit to be used by nanoTime. First of all ticks per second has to be mesured using another timer. Also the number of actuall ticks per second can vary. Apparently some computers may dynamicly change the mhz. In wich case you can't use it to mesure time.

Offline Mark Thornton

Senior Member





« Reply #12 - Posted 2004-03-03 11:48:42 »

Quote
In wich case you can't use it to mesure time.
I only use it for evaluating performance where counting clocks is actually an advantage --- it is independent of the clock frequency. Apart from directly reading the clock counter register, the next best 'timer' on Windows is the performance counter api. However on dual processor machines this also returns the clock count. I don't know if the frequency values returned by this api vary on machines with variable clock frequencies (not common on true duals, but more likely on a hyperthreaded machine).
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.

CogWheelz (16 views)
2014-08-01 22:53:16

CogWheelz (15 views)
2014-08-01 22:51:43

CopyableCougar4 (18 views)
2014-08-01 19:37:19

CogWheelz (19 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

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

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

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

pw (44 views)
2014-07-24 01:59:36
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

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

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

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
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!