From 1fb915df69aaa77ec8be39bb96650e5ec568e245 Mon Sep 17 00:00:00 2001 From: signde Date: Sat, 11 Sep 2004 19:34:11 +0000 Subject: (svn r207) -Codechange: randomizer handling -Fix: desync problem fixes -Fix: server doesnt hang anymore when a client timed out -Feature: low latency connection enhancements [*net_sync_freq, *net_ready_ahead] --- misc.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index b15ca7e1b..dcaf494db 100644 --- a/misc.c +++ b/misc.c @@ -8,8 +8,6 @@ extern void StartupEconomy(); extern void InitNewsItemStructs(); -static uint32 _random_seed_3, _random_seed_4; - byte _name_array[512][32]; static INLINE uint32 ROR(uint32 x, int n) @@ -20,10 +18,17 @@ static INLINE uint32 ROR(uint32 x, int n) uint32 Random() { - uint32 t = _random_seed_2; - uint32 s = _random_seed_1; - _random_seed_1 = s + ROR(t ^ 0x1234567F, 7); - return _random_seed_2 = ROR(s, 3); + if (_current_player>=MAX_PLAYERS) { + uint32 s = _random_seeds[0][0]; + uint32 t = _random_seeds[0][1]; + _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); + return _random_seeds[0][1] = ROR(s, 3); + } else { + uint32 s = _player_seeds[_current_player][0]; + uint32 t = _player_seeds[_current_player][1]; + _player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7); + return _player_seeds[_current_player][1] = ROR(s, 3); + } } uint RandomRange(uint max) @@ -33,10 +38,19 @@ uint RandomRange(uint max) uint32 InteractiveRandom() { - uint32 t = _random_seed_4; - uint32 s = _random_seed_3; - _random_seed_3 = s + ROR(t ^ 0x1234567F, 7); - return _random_seed_4 = ROR(s, 3); + uint32 t = _random_seeds[1][1]; + uint32 s = _random_seeds[1][0]; + _random_seeds[1][0] = s + ROR(t ^ 0x1234567F, 7); + return _random_seeds[1][1] = ROR(s, 3); +} + +void InitPlayerRandoms() +{ + int i; + for (i=0; i