Today I had an incredibly productive morning, and I managed to do in a few hours the amount of work I expected to do in 4 days.
I started by implementing a NetworkTime class to handle all the information related to network time, and I also refactored the TimeManager class to make it a bit more accessible.
After that I refactored the messages, and created a ClientUpdate and a ServerUpdate message.
After that I spent most of the time working on the protocol. Right now a client cannot send messages (except for the ClientUpdate one) until he's connected. To connect a client must send an update, get an answer from the server and sync the time. The time is then averaged before the last received packages to avoid spikes due to floating latency.
To achieve this I had to handle this new types of packages both on client and server.
In the end I also added safety measures to remove every net objects and close the client if the connection with the server is lost.
In the picture there is a bunch of number in every shell. They are the difference between the local and network time. All of them are a couple of seconds bigger than zero (which is roughly the time it takes to establish the first connection), and then the difference remain roughly constant.
Still, I'm not storing the difference, but the actual network time, which is safer in case a client has a faster clock.

Nessun commento:
Posta un commento