MovingBlocks / DestinationSol

Official continuation of Destination Sol, the great fun little arcade space shooter from http://sourceforge.net/projects/destinationsol/ Modules live at https://github.com/DestinationSol/
Apache License 2.0
326 stars 123 forks source link

fix(world): make new world generation deterministic #647

Closed BenjaminAmos closed 1 year ago

BenjaminAmos commented 2 years ago

Description

When #607 was merged, it broke the determinism of world generation. This means that continuing an existing save would often end-up generating a completely different system than the one that was present when the game was saved. The precise reason for this issue is because the ordering of types returned by ModuleEnvionment::getSubtypesOf is undefined. I often found that the exact ordering of types in the returned list changed every time the game was run. The galaxy generation code is very sensitive to the ordering of these lists.

A simple solution to this problem would be to sort the lists by type name. This would not help though if additional feature generators were added later-on, since they could change the list ordering and size again. Because of this, I decided to save the generators used with the world configuration instead. This does mean that you will have to start a new game to see any new system/feature generators in use though.

I also updated some occurences of publicly-facing ArrayList<T> methods to the more generic List<T> in GalaxyBuilder, since I was modifying that code anyway.

It appears that some world generation tests were commented-out in #622. This pull request also restores those stubbed tests with working implementations again.

Testing

Notes

BenjaminAmos commented 2 years ago

@IsaiahBlanks, would you be interested in verifying this change? I'm not very familiar with the new world generation, so I might have made some mistakes somewhere.

BenjaminAmos commented 1 year ago

These changes appear to work and are an improvement over the previous behaviour, so I see no issues in merging this right away.