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

Support conditional events and fallback for random_event_player #1536

Merged

Conversation

avanwinkle
Copy link
Collaborator

This PR adds support for conditional events in random_event_player event lists.

For starters, the Randomizer class now accepts machine and template_type as constructor arguments, and if provided, will generate conditional templates for the items in its randomization list. When fetching the next random item, if the items are conditional template instances, they will all be evaluated and only those that are true will be returned.

For flexibility, the Randomizer class also gets a new config setting: fallback_value. If all the conditions failed and no items will be returned, the Randomizer will return its fallback value if one is defined. If not, it will return None.

The RandomEventPlayer is likewise updated to pass in the new constructor arguments and set a fallback event.

Tests forthcoming!

@avanwinkle
Copy link
Collaborator Author

@jabdoa2 Curious about your thoughts on performance. I had the idea to, after the items list is built, check all the conditional template instances to see if they have conditions. If all conditions are None, i.e. none of the events are conditional, replace all the templates with the original strings and remove the self._template_type value.

In such a situation, we'd save the iteration to check for conditions when the random events played, at the cost of doing another iteration on construction. Not sure if that's worth it?

@jabdoa2
Copy link
Collaborator

jabdoa2 commented Oct 24, 2020

Our template code will only construct templates if there are conditions. Otherwise, it will emit Native types which do not perform any evaluation.

In general, I like to heavy lifting to startup time. That pays off most of the time. Also provides earlier error which is generally nice. Guess we could write a benchmark to see if this is worth the effort or not. There are some benchmarks for events already. If you want give them a try. Otherwise I would not worry too much. We can tune that once it becomes an issue.

@avanwinkle
Copy link
Collaborator Author

Started down the path of reverting conditions if no events have them, but then decided it's probably not worth it. Random_event_players are most likely not spamming tons of events constantly and the conditional lookup for None is real fast. Seems good as it is.

@jabdoa2 jabdoa2 merged commit b5e1e57 into missionpinball:dev Oct 25, 2020
@avanwinkle avanwinkle mentioned this pull request Oct 26, 2020
@avanwinkle avanwinkle deleted the conditional-random-event-player branch December 4, 2023 23:32
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