Starstrider42 / Custom-Asteroids

A KSP mod that lets users control where asteroids appear
http://starstrider42.github.io/Custom-Asteroids/
MIT License
13 stars 10 forks source link

FixedRateSpawner initialization problems #41

Closed Starstrider42 closed 4 years ago

Starstrider42 commented 5 years ago

Background Info

Issue Description

When a save game is first loaded and the FixedRateSpawner boots up, it thinks it is UT 0. This causes the spawner to quickly recreate all asteroids that would have spawned between UT 0 and the true in-game date. While these asteroids get cleaned up (they're mistaken for stock-spawned asteroids), this slows down game loading. Note that this bug only happens when a save game is loaded, not during scene changes.

Unfortunately, a naive fix to this problem runs into a much worse bug, where each scene change resets the Unity random number generator to a fixed value (related to #1?). The result is that identical asteroids are produced after each scene change. This doesn't seem to happen when Custom Asteroids is not installed or when FixedRateSpawner is allowed to spam asteroids, for reasons unknown.

Starstrider42 commented 4 years ago

The fix to #45 involved rewriting FixedRateSpawner almost from scratch. While the new implementation might also be initialized with UT 0, it cannot spawn more than one asteroid per tick, causing minimal slowdown. I've also confirmed that this fix does not create duplicate asteroids in the sense described here or in #39.