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

force UnityEngine.Random reseeding when parsing quests #1702

Merged
merged 3 commits into from Feb 20, 2020

Conversation

petchema
Copy link
Collaborator

@petchema petchema commented Feb 10, 2020

No optimisation attempt, QuestMachine.ParseQuest can be called several times during the same frame and is not in a hot path so I'm using System.Random as randomness source.
Generating a list of quests feels just as fast as before.

Forums: https://forums.dfworkshop.net/viewtopic.php?f=5&t=3399
https://forums.dfworkshop.net/viewtopic.php?f=27&t=924&p=39061#p39056

No optimisation attempt, QuestMachine.ParseQuest can be called several
times during the same frame and is not in a hot path so I'm using
System.Random as randomness source.
Generating a list of quests feels just as fast as before.

Forums: https://forums.dfworkshop.net/viewtopic.php?f=5&t=3399
@ajrb
Copy link
Collaborator

ajrb commented Feb 11, 2020

This will not help with PickOneOf action as that is not selecting until runtime as far as I can see, although I may be mistaken. There is a commented out seed line in there commented out by Interkarma in 2017.

@Interkarma
Copy link
Owner

If PickOneOf is compiled multiple times in a row, can more than one compile within 1ms of each other? That would result in them ending up with the same seed. I can't recall now, but I think that's why I commented out that InitState in 2017. I don't have a problem with seeding random here, just that TickCount might not have enough time resolution.

I do like the clever approach of using an internal seed and Next() in QuestMachine. If we expose that at a property then PickOneOf could just use QuestMachine.Instance.InternalSeed when seeding InitState. Would just need to make sure the property called internalSeed.Next() when returning result, and we'll have a constantly rolling seed value anyone can use.

@petchema
Copy link
Collaborator Author

I do like the clever approach of using an internal seed and Next() in QuestMachine. If we expose that at a property then PickOneOf could just use QuestMachine.Instance.InternalSeed when seeding InitState. Would just need to make sure the property called internalSeed.Next() when returning result, and we'll have a constantly rolling seed value anyone can use.

As the King of Worms would say, "Done."

@Interkarma
Copy link
Owner

Nice one, cheers! :)

@Interkarma Interkarma merged commit 9809aec into Interkarma:master Feb 20, 2020
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

3 participants