-
Notifications
You must be signed in to change notification settings - Fork 793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add alternate RNG and proposed API for versioning Random Number Generators #2261
base: master
Are you sure you want to change the base?
Conversation
6fb3d29
to
513a1f0
Compare
The main changes in this PR are the addition of RandomEngine as a class in engine/random.hpp (and implementation of global functions in random.cpp), versioning namespaces, and updated test cases showing usages. I have updated all uses of RNG functions to refer to the vanilla:: namespaced versions because I don't like having unbuildable commits. I can split that if desired. @qndel would I be able to add you as a co-author for this PR? I didn't want to imply you had signed off on this but I do want to acknowledge your work in this space. |
3388aa9
to
fe981d6
Compare
Added an example of how this could be used to make it easier to ensure code which relies on pseudo-random sequences is functioning correctly. This PR is already massive so I didn't want to make it worse by actually using the new API, but hopefully this gives context for why I think this change is worthwhile. |
4e8f508
to
54a290a
Compare
9764d6f
to
2c61e7a
Compare
2c61e7a
to
8105be5
Compare
…ators This builds on the work done by qndel in diasurgical#2084. I have not updated any of the call sites identified in that PR as I wanted to make it obvious that this does not change existing code. This is more of a discussion point at the moment. I was thinking that namespaces would be a good way to delineate behaviour. I've implemented "vanilla" to cover the base game logic and bugs. "randomV1" is based on diasurgical#2084 and uses STL concepts to add convenience functions as discussed in diasurgical#2193. The API design is intended to be common between versions. The next step would be to update the vanilla namespace functions to align with member functions of vanilla::RandomEngine. The reason for having this class is to allow creating a RandomEngine object and passing it in to the level/item generation code (for example) to make it clearer how a given object/dungeon layout is generated. Looking at code such as quests.cpp:165 makes me think a "vanillaSafe" namespace which fixes the negative number bug would be useful, but this would be a future enhancement iff this proposal is acceptable. Add libgmock-dev to the install script for linux_x86_64_test to use EXPECT_THAT and ::testing::AnyOf
This is to further discourage the use of buggy RNG functions. The V1 engine class should make it much easier to do repeatable generated logic for mods adding additional items, dungeons, etc.
…la::RandomEngine This shows how the RandomEngine classes can be used to isolate pseudo-random generation logic.
8105be5
to
495666b
Compare
The monster direction is synced even if the receiving player is not on the same dungeon level as the player killing the monster. Note, this happens, even if one player is in town, and the other kills a monster at e.g. dlvl=1. Then the code will check the monster at index mi even for the player in town, so it will just read garbage data from memory.
This builds on the work done by @qndel in #2084. I have not updated any of the call sites identified in that PR as I wanted to make it obvious that this does not change existing code.
This is more of a discussion point at the moment. I was thinking that namespaces would be a good way to delineate behaviour. I've implemented "vanilla" to cover the base game logic and bugs. "randomV1" is based on #2084 and uses STL concepts to add convenience functions as discussed in #2193 and #2206.
The API design is intended to be common between versions. The next step would be to update the vanilla namespace functions to align member functions of vanilla::RandomEngine. The reason for having this class is to allow creating a RandomEngine object and passing it in to the level/item generation code (for example) to make it clearer how a given object/dungeon layout is generated.
Looking at code such as quests.cpp:InitQuests() makes me think a "vanillaSafe" namespace which fixes the negative number bug would be useful, but this would be a future enhancement iff this proposal is acceptable.