Advertisement

1500 archers: speed control in 2 bytes?

Started by July 01, 2006 10:13 AM
0 comments, last by hplus0603 18 years, 7 months ago
My networking protocol closely resembles that of Age of Empires as described in the "1500 archers" article. From the section on Speed Control:
Quote:
Each client would also measure a round trip "ping time" periodically from it to the other clients. It would also send the longest average ping time it was seeing to any of the clients with the "Turn Done" message. (Total of 2 bytes was used for speed control)
Now, I take this to mean that they send 2 timespan values in 2 bytes, so I was wondering what representation of a timespan they are using that fits into one byte? Say one byte gives 250 possible values. Given that the data is a ping time and has a limited range where the time is actually relevant, you could probably clamp it to some maximum like 1000ms and have resolution of 4ms: float measuredPing; uint8 pingTime = (uint8) (min(1000.0f, measuredPing) / 4); This is my best guess as to what they did... any ideas?
Sounds reasonable. Settle on a maximum ping and minimum ping you'd want to allow reporting of, and spread the available values between them. I e, if a ping faster than 50 ms won't do any good for the game, then no need encoding the range from 0 through 50.

You could also, if you're fancy, spread the precision, so that you get better precision at the lower times (where it's percentagewise more important), by using a logarithmic or power scale. For example:

uint8 encoded = (uint8)(sqrtf(clamp(ping-50, 0, 1000)/1000.0) * 255);float decoded = v/255.0 * v/255.0 * 1000.0 + 50;


However, chances are that your initial suggestion is quite good enough!
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement