godarklight / DarkMultiPlayer

DarkMultiPlayer - A multiplayer mod for Kerbal Space Program
MIT License
280 stars 120 forks source link

Asteroids in 1.3 #423

Closed 81ninja closed 6 years ago

81ninja commented 7 years ago

This is meant to temporarily solve the following issues

1) Squad has borked ProtoScenarioModule.moduleRef (intentionally or not), breaking the previous scenario detection / asteroid spawn inhibition. The old scenarios still exist, though asteroids are now generated by the SentinelModule.

2) AsteroidWorker.Update() is called multiple times during load and all the time while the game is running. Existing asteroids were being recounted very inefficiently during every Update() cycle, by iterating through all vessels and protovessels, checking if every one of them is an asteroid. Then adding every one of them to a List<>, instead of just generating the list once, and getting the total number of items from it (or just using a counter).

3) All remaining asteroids up to the numberOfAsteroids set in Settings.txt were being generated at once by the first player that acquired the lock asteroid-spawning. On servers with asteroid generation increased and/or a high number of vessels, clients got stalled when loading the game while asteroids were being spawned; this along with (1) and (2) was causing apparent freezes on Syncing Vessels or the load screen, making players think the game froze (because it actually almost did, since the loop was running astray).

The current logic is just to keep the system working as it were pre-1.3 in DMP. Full compatibility with the new Sentinel scenario (esp. for career mode) will require a more complete refactoring of the Asteroid module to work with the fact asteroids in KSP are now generated in order to fulfill Sentinel contracts, and not just randomly.

Xinayder commented 7 years ago

What's the state on this?

81ninja commented 7 years ago

As far as I've tested, it's working as intended.

If existing asteroids < server setting, new asteroids are created, one per minute, until the count reaches the setting. The new asteroids are created with lifetime = Infinity, so they aren't expired by other players registering or warping ahead into the future.