Latest Uploads
Invasion V ... prototype

rychan

Invasion V ... Prototype

rychan

Shields 64x64

Pakz

Ffs_Spam

Jayenkai

Hives Screen shot

rychan

Rpg Potion Sprites

Pakz

Forum Home

Universal Clock

UserMessage
Posted : Thursday, 26 August 2010, 17: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, 18:18 | Permalink
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, 01:54 | Permalink
Stealth


Why does your game need to know the exact time?
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 09:40 | Permalink
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, 13:40 | Permalink
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.

-----
Americans elected Trump...
Homepage : http://strubhar.me
Posted : Friday, 27 August 2010, 21:00 | Permalink
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, 17:45 | Permalink
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, 09:25 | Permalink
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, 10:21 | Permalink
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
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!
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 621|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Latest Posts
Pillowcases for kids!
rockford Thu 16:15
CSS-Me-Do - SoCoder2
Jayenkai Thu 09:38
More Monkey Madness - With Ducks
Pakz Thu 04:51
Manchester Arena Explosion
Jayenkai Thu 02:04
Buy Zelda
spinal Wed 11:31
Family
Jayenkai Wed 04:06
RIP - Sir Roger Moore
rockford Tue 15:56
Any Feature Requests?
spinal Mon 12:02
Switch - Mini Dock
Jayenkai Mon 06:26
AGameAWeek : 2017 - Part One
rychan Mon 05:17
More

Latest Items
Dev-Diary : My Journey into NES Development
rychan Thu 12:31
Showcase : Flappadiddle
Jayenkai Sun 14:39
Snippet : QFind
Jayenkai Sun 13:02
Showcase : Tiny Blocks
Jayenkai Sun 04:08
Showcase : Read Error A
rychan Fri 05:13
Blog : All my makes!
Jayenkai Tue 05:48
Showcase : Infinitron
rychan Mon 18:03
Showcase : Hives
rockford Wed 12:53
Showcase : Quadoban
rskgames Fri 10:11
Blog : My Arduino experience.
steve_ancell Wed 17:02
Showcase : Roguelike Explorer
Pakz Fri 06:59
News : Newsletter #311
Jayenkai Thu 17:27
Link : Super Shapes Exploration Kit
Andy_A Thu 11:09
Dev-Diary : Sensitive - Arduboy!
rychan Thu 17:27
Snippet : Skylines
steve_ancell Tue 14:25
More

Who's Online
steve_ancell
Thu, at 19:00
rskgames
Thu, at 18:38
9572AD
Thu, at 18:19
rychan
Thu, at 17:24
LineOf7s
Thu, at 16:20
rockford
Thu, at 16:15
Jayenkai
Thu, at 15:31
Pakz
Thu, at 13:45
shroom_monk
Thu, at 12:44
spinal
Thu, at 11:33
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.