Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ephphatha
Copy link
Contributor

@ephphatha ephphatha commented Jun 28, 2021

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.

@ephphatha
Copy link
Contributor Author

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.

@ephphatha ephphatha force-pushed the random-refactor branch 5 times, most recently from 3388aa9 to fe981d6 Compare June 29, 2021 13:24
@ephphatha ephphatha marked this pull request as ready for review June 29, 2021 13:52
@ephphatha
Copy link
Contributor Author

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.

@ephphatha ephphatha force-pushed the random-refactor branch 3 times, most recently from 4e8f508 to 54a290a Compare July 1, 2021 09:56
@AJenbo
Copy link
Member

AJenbo commented Jul 2, 2021

The coverage result is pretty amazing for this PR :)
image
(All changed code is tested, and total increased by 0.12%)

…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.
AJenbo pushed a commit that referenced this pull request Aug 27, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants