Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Accurate timing in Javascript

Name: Anonymous 2013-09-23 18:07

I'm trying to get real-time networking working with a browser game demonstration I have been working on in my spare time.

The demo is written with Javascript, so on the server I am using node so I can re-use client code (as well as have an excuse to play with Coffeescript and node in general).

This all works fine, and server authoritative movement for players works quite well, albeit with the jerkiness implied with internet latency.

The problem I'm having comes when attempting to set up client-side prediction. The general idea is, keep a record of input and local player state each frame, when the server sends an update, rewind this record to the game time the server update has, insert the player state from the server, and replay local physics to the current local game time before the next frame (this allows for lagless movement from the perspective of the local player).

In nearly all implementations of this general idea I've seen,  the client and server have a relatively synchronized clock "timestep". This way, the client can compare the current local time to the server's sent timestamp on the update and decide where in the state buffer to insert the update (which is, from the client's point of view, in the past).

How am I supposed to do this in javascript though? I've tried nearly everything it seems, and perhaps there are other errors in my implementation, but I've spent hours simply trying to get the game clock anywhere near synched up to no avail.

setTimeout and setInterval are both 'unreliable' when it comes to actually running code when you tell them to, this is the nature of Javascript; however even when adjusting the game clock per the actual passage of time, the client always end up falling behind the server.

This has to be possible, I've seen several massively multiplayer games written in JS with minimal input lag (the mozilla MMO demo comes to mind, also the bomberman game with >100 players on a map at any time) that surely have stable, synchronized game clocks...

How do I do this? Is using the literal epoch time as game time a good idea or a bad idea? I have no idea what is going on server side for the examples I've mentioned, is there no hope for a Javascript backend with these requirements?

Even if I managed to get a relatively stable clock on either client or server, when do I start the client clock upon connection to an already running server? Do I have to measure latency before I can accept the server's game time?

I'd especially love to hear from the "Javascript is the future" g(o|u)y

Name: Anonymous 2013-09-23 19:47

Using Javascript is your first mistake.

Name: Anonymous 2013-09-25 20:05

>>2
but muh browser

Name: Anonymous 2013-09-25 20:18

BREAKING NEWS

Somebody just got dubs in http://dis.4chan.org/read/prog/1210633048/11

Be sure to check them for him.

Name: Anonymous 2013-09-25 20:19

Read RFC5905. You don't need to use it directly, but understand how it works.

Name: Anonymous 2013-09-25 22:33

>> the mozilla MMO demo comes to mind
This one? Look at the source and see how they did it: https://github.com/mozilla/BrowserQuest

Name: Anonymous 2013-09-25 23:58

Fuck all that. Just use Zk
https://www.google.com/search?q=zk+timer

Name: Anonymous 2013-09-26 0:18

>>5
Thanks, I should have thought of that

>>6
Well, it is real time, however the movement is based on a grid and isn't as fine-grained as mine is, fairly certain that the client rarely if ever contradicts the server. I have more freeform movement with momentum, i'm sure I could make it more deterministic but that only helps so much.

>>7
What the fuck is this

Name: Anonymous 2013-09-26 0:57

http://www.zkoss.org/ "ZK is the best open source Java framework for building enterprise"
stopping reading

also it's kind of ironic that their home page slideshow uses setTimeout on 10 second intervals, but when you manually click back a slide, that setTimeout doesn't reset like you would expect it to

>>8
Sorry OP, wish I could help you, but unfortunately I stalled on my browser-based MMORPG at exactly this moment in my own development.

Name: Anonymous 2013-09-26 5:14

>>6
Steaming pile of shit nearly killed my Firefox.

Name: Anonymous 2013-09-26 9:26

>le pedophile sage

Name: Anonymous 2013-09-26 9:32

>>11
>le forum psyops

Name: Anonymous 2013-09-26 9:39

>>10
Firefox 23 here. I just finished the game now without problem.

Name: Anonymous 2013-09-26 10:06

>>12
>le pedophile made up words

Name: Anonymous 2013-09-26 10:13

>>14
>le forum psyops

Name: Anonymous 2013-09-26 10:54



 A pedo died in 2013 by a well-adjusted normalfag. He threw him into general population when he was still alive. The murdered chanted, "I sentence you to ten years in prison" as he sentenced him. Now that you have read the chant, you will meet this pedo. In the middle of the night he will coming through your window. He will shank you like he was shanked. If you post this, he will not bother you. Your kindness will be rewarded.

Name: Anonymous 2013-09-26 11:08

A desperate admin died in 2013 due dildo overdose. He punctured his intestines when he was still alive. The admin chanted, ">le pedophile sage" as he posted another pseudo-shitpost. Now that you have read the chant, you will meet this admin. In the middle of the night he will coming through your browser. He will then force you to migrate to his private forum. If you repost this, he will not spam you. Your kindness will be rewarded.

Name: Anonymous 2013-09-26 12:36

A desperate web developer died in 2013 due Javascript overdose. His anus was haxed while he was still alive. The web developer chanted, ``scalable turnkey web 3.o solutions'' as he posted another non-programming post. Now that you have read the chant, you will meet this developer. In the middle of the night he wiull coming through your Hacker News. He will then port your C to the browser. If you repost this, he will not touch your anus. You kindness be reward.

Name: Anonymous 2013-09-26 12:41

>le pedophile sage
>le pedophile backticks
>le pedophile spoiler

Name: Anonymous 2013-09-26 12:45

>>11-19

Not programming

Name: Anonymous 2013-09-26 12:49

>>20
Not dubs

Name: Anonymous 2013-09-26 12:50

>le pedophile sage

Name: Anonymous 2013-09-26 12:50

>>22
How about them dubs? Check your dubs!

Name: Anonymous 2013-09-26 12:51

>>20
Back to /g/ please!

Name: Anonymous 2013-09-26 12:53

>le pedophile exclamation mark

Name: Anonymous 2013-09-26 12:59

>>25
Terrible!

Don't change these.
Name: Email:
Entire Thread Thread List