Most time accurate scripting language for small online games?

Started by
14 comments, last by hbbukowski 10 years, 6 months ago

Hello dear experts!

I apologize if you feel this question has been asked hundred of times, I looked in the past records I couldn't find any trace.

My question: What is according to you the most time accurate scripting language for programming small online games?

First some definitions:

- time accurate: meaning that (1) there can't be any lag, (2) temporal resolution must be millisecond to tens of millisecond.

- small onling game: simple 2D animations, single player, loadable on any browser

Why this question:

I would like to program a game anyone can play on his browser in which accurate timing is the essence. E.g.: I need to be able to tell that a player played 21 ms faster than the first time.

I had read C was the most powerful (least memory consumption and fastest running time, hence I suppose most time accurate?) but C can't go online. So what's the best alternatives ?

Thanks in advance for all your inputs !

Advertisement

If it has to play in a browser you got 2 options:

1) Javascript (It is the only language that is supported by most browsers)

2) Rely on a browser plugin that allows you to use a different language Flash(Actionscript), Java and Unity(C#/UnityScript/Boo) are fairly commonly installed. for other languages you might have to write your own browser plugin.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Okay, thanks!

But then between Javascript / Flash(as) / Java / Unity, which you think is the most time accurate (millisecond precision) scripting language for programming small online games?

I know that on Windows, Java and JavaScript both have a precision of about 8ms for keyboard events. That could be different on other OSs though.

There is an easy way to test that. Open a JS console in your browser (usually with F12) and then type in


document.onkeydown = function() { console.log(new Date().getTime()) }

Then click on the website and press two keys at the same time. Two numbers will be printed in the console. The smallest difference you get gives you the accuracy in ms.

 

I know that on Windows, Java and JavaScript both have a precision of about 8ms for keyboard events. That could be different on other OSs though.
There is an easy way to test that. Open a JS console in your browser (usually with F12) and then type in

document.onkeydown = function() { console.log(new Date().getTime()) }
Then click on the website and press two keys at the same time. Two numbers will be printed in the console. The smallest difference you get gives you the accuracy in ms.
 

input event latency is a bit of a different matter though, especially when you track it through callback functions.

Java should use the highest accuracy timer available on the OS, System.nanoTime uses QueryPerformanceCounter on Windows which gives it a very high precision.

JavaScript is browser and OS dependant, the Date().getTime() function has at best a 1ms precision but on Windows it tends to be 10ms, some browers however support performance.now() (performance.webkitNow() in older chrome versions) which uses the most accurate timer the OS provides (Which gives you micro or nanosecond precision on all major desktop operatingsystems)

Basically, as long as you're not worrying about supporting old browsers(IE9 or lower lack high precision timer support), any option will work, if you intend to support old browsers you need to use a plugin (Java/Unity/Flash/etc)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

I tested it again. It depends on the browser. In Chrome performance.now() only has an accuracy of 8ms. On Firefox it's less than 1 ms. But the input latency is still 8ms for both browsers. For a game input latency is what counts I guess.

It'd probably help if you were more specific about what you're trying to accomplish, reading what you said could mean a lot of different things.

Lag could either be referring to internet lag or what most people assume, FPS lag, you could also mean lag in the delay time for timing something like a stopwatch, really rather vague. Additionally you're talking about something that has a lot of factors involved with whatever the program is, input lag could be a big contributor if its some kind of game and timing in and of itself is hard to accurately do due to delays in the program getting to loop again to check elapsed time due to things like OS scheduling or even the resolution of the timer you're using.

I'm not really sure you could peg any particular language as being "faster" at any specific task anyway, a lot of it comes down to the full product.

I tested it again. It depends on the browser. In Chrome performance.now() only has an accuracy of 8ms. On Firefox it's less than 1 ms. But the input latency is still 8ms for both browsers. For a game input latency is what counts I guess.

in chromium (on Linux) running: for (i=0;i<1000;i++) { console.log(performance.now()); } gives me a unique value for each iteration of the loop. (each iteration takes roughly 0.08ms)

In firefox (Also on Linux) i still get a unique value for each loop iteration (but each iteration takes a bit longer, ~0.2ms)

running a normal game at 60fps there will be ~16ms between frames.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Thank you all for your advices, it is highly appreciated!

Thanks SimonForsman, 60 fps is a good point too because I guess any game based on keyboard events in response to visual displays is intrisically limited in time accuracy by the fps.

So 16 ms is the best temporal resolution I can hope. And so JavaScript or Java are equally good to attain this precision.

Then my choice would depend on sensitiveness or occurences to/of lags. For that I answer to Satharis :

It'd probably help if you were more specific about what you're trying to accomplish, reading what you said could mean a lot of different things.

Lag could either be referring to internet lag or what most people assume, FPS lag, you could also mean lag in the delay time for timing something like a stopwatch, really rather vague. Additionally you're talking about something that has a lot of factors involved with whatever the program is, input lag could be a big contributor if its some kind of game and timing in and of itself is hard to accurately do due to delays in the program getting to loop again to check elapsed time due to things like OS scheduling or even the resolution of the timer you're using.

I'm not really sure you could peg any particular language as being "faster" at any specific task anyway, a lot of it comes down to the full product.

Yes, you're right. I'll try to be more specific:

Goals:

- accurately record the time elapsed between the presentation of a visual stimulus and a keyboard event

- present visual stimuli for precisely the time asked or the closest (e.g. 250 ms)

The potential sources of inaccuracies are then:

- delay in loading and presenting the visual stimulus ( --> the stimulus is presented 25 ms later than expected)

- delay for timing ( --> the stopwatch stops and records the time elapsed 25 ms later than expected)

- delay due to processing the line codes in general.

Would you favor a specific browser-compatible scripting language when accounting for these kinds of delay?

Thank you again for your help!

Let's put the question simplier:

Between: Javascript / Flash(as) / Java / Unity

Which is best for:

- quick pictures/sounds loading and presentation

- accurate stopwatch timing

- overall speed of processing

Thanks again !

This topic is closed to new replies.

Advertisement