Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Duelers were alarmed by an apparent lack of randomness in starting spawns.
Some kind of seeding problem was suspected.
Investigation
phylter and Zorak discovered the following:
Sys_DoubleTime
returns approximate seconds since MVDSV launch.RNG is seeded with
randomSeed = (int)(Sys_DoubleTime() * 100000)
.Maximum value
randomSeed
can hold is 2147483647.(int)(Sys_DoubleTime() * 100000)
exceeds 2147483647 in just under 6 hours, after which the value stops increasing (or potentially behaves in an undefined way).The code in question was introduced in 2021 (commit 837bdfc).
On affected servers, after 6 hours of uptime, it is possible to lock the starting spawns entirely by minimizing player activity (which can trigger RNG calls) during pre-war.
Solution
Seed the RNG directly with elapsed seconds since epoch.
Replace
with
This provides a source of unique seeds for a very long time.
Notes
There is some concern that epoch functions might behave badly in the year 2038 on some old 32-bit machines... the so-called "2038 problem".
We figure such systems, already in the extreme minority, will face much bigger problems than running quakeworld.
Most MVDSV instances are already 64-bit, and are therefore unaffected.
There is a non-epoch alternative worthy of mention (suggested by foobar):
Replace
with something like
This is elegant but cannot make any guarantees about seeds being unique. Presumably the repeats would be far apart.