Latest Uploads
Bumble Bee

dna

Tires

dna

Guess The Remake

rychan

Julia Set Visualer

Andy_A

Julia Set Visualizer

Andy_A

image-07-0 ... -34-29.jpg

Jayenkai

Forum Home

Universal Clock

UserMessage
Posted : Thursday, 26 August 2010, 16:20 | Permalink
BGDDisco


My web game needs a standard time reference.
CurrentTime$() and CurrentDate$() come from the individual user's computer. Not only does this introduce a global positioning timezone error, but even the fact that your computer may be a few seconds or minutes out from the real thing introduces errors.

Does anyone know of an web-accessible time reference that Blitz Basic can refer to?

-----
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Posted : Thursday, 26 August 2010, 17:18 | Permalink | Mark Here
JL235


WW Entries : 7
What are you trying to achieve? Accuracy really depends on what you are trying to build and there might be a far better way of building whatever you are trying to build.

But for this specific question, the proper way would be for you to take advantage of a Time Server. They are servers (many of which are public) designed to hold and distribute the current exact time using the network time protocol and so are pretty much designed specifically for synchronizing computers around the world. You'll never get the exact time due to latency, but implementations do predict the latency you are occuring (note that they only predict).

On Windows there is the Windows Time Service which you could take a look at. This is MS's implementation of the Network Time Protocol and can give you the exact time to within a few seconds. It's also included with Windows since Windows 2000. There are far better libraries out there on the net which will give you a far more accurate time. For use with Blitz you'd probably be best building bindings in C/C++ and then calling it from BB.

As a poor-mans alternative you could find one of the many 'what is the current time' websites only and have your app download the page (using BBs TCP functions) and then just strip out the time on the page. You then need to add on half the time taken between starting the request and receiving the page (this is a cheap way of accounting for the latency).

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Friday, 27 August 2010, 00:54 | Permalink | Mark Here
Stealth


Why does your game need to know the exact time?
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 08:40 | Permalink | Mark Here
BGDDisco


It's not that I need a particularly accurate time, just a standard reference that all my players are 'governed' by.
My two-player games will have a time limit to make your move/play, and if two opponents had differing 'local' times even by a few minutes (just checking my computer - it is 3 seconds slow) this could make a big difference to game play.
Will check if my web-hosts (UK2) have a server time that I can refer to.

-----
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Posted : Friday, 27 August 2010, 12:40 | Permalink | Mark Here
Stealth


You should have both games "handshake" at the beginning of the game. They both essentially agree on a time to use. Both clients should also checkup on the other clients to assure they are playing by the rules. For instance, if the other player sends a move outside of their timeframe, my client would receive the command and should reject it. From there, you can either have error control code or trigger a game "out of sync" error.

-----
Andrew // stealth
"Some people see things as they are and say why? I dream things that never were and say why not?" - Robert Kennedy
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 20:00 | Permalink | Mark Here
JL235


WW Entries : 7
IMHO this would be a much better way to structure your game. You should build it using a server/client architecture. However hosts is running both a server and a client, all other players are just clients.

The servers are just dumb front-ends. They send their moves to the server and visualize the response.

The server runs the game itself and validates all moves that are sent to it (i.e. is the move allowed?). The only time that matters is the servers time, and only the server needs to keep track of this. At the start of a players move the server will record a timestamp and then message the player to say they can move. When the player has finished moving they will message back to the server their move, and the server will know if they are within time by measuring the time difference between it's first instruction to play and the response of the move being carried out.

If a client fails to send it's move to the server within the timelimit, the server sends out an 'out of time' message (or something to that effect) and simply ignores any illegal moves (moves taken when a player can't actually move).

With this structure none of the clients will need to keep track of the time. Only the server will keep track of time and will do this based solely on the timestamps it's recording for the messages it's sending and receiving.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Saturday, 28 August 2010, 16:45 | Permalink | Mark Here
Scherererer


I think he just means getting a standard time, such as everyone using UTC/GMT instead of each computer using their local time.

-----
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Homepage : www.google.com/profiles/Scherererer
Posted : Friday, 03 September 2010, 08:25 | Permalink | Mark Here
BGDDisco


Yep Scherererer, that's exactly it. I don't even want that much accuracy - to the nearest minute would suffice. Anyone know of a web-page with the current time and date somewhere on it (preferably near the beginning) that I could aim my program at as a reference.

My reasons again:
Say P1 and P2 take turns at a game of chess and they have a time limit of 5 minutes to take there turn. P1's (local) CurrentTime$() is a minute slow. P2's CurrentTime$() is a minute fast. This would mean that when the game update with TimeOfLastTurn$() is TCP'd to webspace, P1 would be giving P2 a full two minutes extra to contemplate his turn, and P1 himself would only be getting 3 minutes. This is why I need a remote time reference - even if it's not all that accurate.

-----
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Posted : Friday, 03 September 2010, 09:21 | Permalink | Mark Here
JL235


WW Entries : 7
BGDDisco Say P1 and P2 take turns at a game of chess and they have a time limit of 5 minutes to take there turn. P1's (local) CurrentTime$() is a minute slow. P2's CurrentTime$() is a minute fast. This would mean that when the game update with TimeOfLastTurn$() is TCP'd to webspace, P1 would be giving P2 a full two minutes extra to contemplate his turn, and P1 himself would only be getting 3 minutes. This is why I need a remote time reference - even if it's not all that accurate.

As I understand it, you don't actually need to send players the time, you only need to send them the 'difference' in time between moves. With my suggestion you can do this.

Lets say you want to update the TimeOfLastTurns, first the server takes a timestamp for the current time. For ease we'll say all timestamps work in seconds, and the current timestamp is 660.

When it sends out the time of last moves it'll send out it's current time (the 660) plus it's timestamps for the old moves. Lets say those old moves occurred at 400, 500 and 600.

The client can work out the time to display using this knowledge. 660 is the time now, 17:09:00 for me, so 600 will be 1 minute ago at 17:08:00. 500 is 17:06:20 and 400 is 17:04:40.

To summarise...

Servers timestamp now: 660
Servers timestamps of old moves: 600, 500, 400

Lets say local time on players machine is 17:09:00. 660 represents now, so 660 is 17:09:00!

Therefore...
600 => 17:08:00 (60 seconds earlier),
500 => 17:06:20 (160 seconds earlier),
400 => 17:04:40 (260 seconds earlier)

Does this not solve your problem without having to strip the time from a website?

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Homepage : http://www.StudioFortress.com
Posted : Thursday, 23 December 2010, 07:37 | Permalink | Mark Here
BGDDisco


Finally got a working function written.
I've put the source on BB.com

http://www.blitzbasic.com/codearcs/codearcs.php?code=2800

Use it freely.

-----
God gave Man a brain...and a penis...but only enough blood to run one at a time!
Latest Posts
Jay's New Lumia 1020
Jayenkai Wed 16:13
Free SIMS 2
Jayenkai Wed 15:13
Good TV?
Jayenkai Wed 02:45
SAT:AM Loving
rockford Tue 08:18
AGameAWeek Progress Report
rychan Mon 23:57
[OUYA] AquaVenture
Jayenkai Mon 07:57
Happy Birthday to All
Jayenkai Mon 02:15
Mog's Village
Mog Sun 19:20
Faceless Piles of Shite
Dabz Thu 18:34
Dabz Takes Manhattan
Jayenkai Thu 18:32
More

Latest Items
Techy : Back from Game Dev Con!
Jayenkai Sun 15:52
Family : Sunday
Jayenkai Wed 02:31
Family : Good News (for once)
Kuron Tue 14:37
Showcase : Don't Tap The Zombies
therevillsgames Mon 15:26
Showcase : Mutant Monty
steve_ancell Wed 18:26
Blog : Update
Kuron Mon 12:52
Techy : New Laptop!?
Kuron Fri 14:52
Showcase : Ascension 2 Live Wallpaper
CodersRule Fri 12:48
Showcase : Saviors of Gundthor
CodersRule Fri 11:50
Showcase : Lava Monkey
rychan Tue 15:13
Blog : Mac Rant!
rockford Fri 13:48
Dev-Diary : Yup, another song
Kuron Wed 05:39
Pets : Old pic to share...
rockford Sat 16:01
Blog : EmuMenu
spinal Sat 10:07
Family : More bad news :c(
Kuron Mon 06:07
More

Who's Online
dna
Wed, at 20:37
Evil Roy Ferguson
Wed, at 19:13
steve_ancell
Wed, at 19:10
Jayenkai
Wed, at 16:21
rychan
Wed, at 15:46
rockford
Wed, at 14:31
spinal
Wed, at 13:33
Krakatomato
Wed, at 12:30
blanko1324
Wed, at 09:35
HoboBen
Wed, at 08:13
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.