From 8766de21cc0b7cf9e46fdd01656fb770dcfa2122 Mon Sep 17 00:00:00 2001 From: Roman <69218254+amzn-rhhong@users.noreply.github.com> Date: Tue, 25 Jan 2022 14:53:16 -0800 Subject: [PATCH] Only use a deterministic random when network option is enabled. (#7126) * Only use a deterministic random when network option is enabled. Signed-off-by: rhhong * use actor instance id as the seed of the lcg random in anim graph instance Signed-off-by: rhhong * add const Signed-off-by: rhhong --- .../Code/EMotionFX/Source/AnimGraphInstance.cpp | 3 +++ .../EMotionFX/Source/AnimGraphTimeCondition.cpp | 11 ++--------- Gems/EMotionFX/Code/MCore/Source/Random.h | 16 ---------------- 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphInstance.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphInstance.cpp index 7f9e8ba6fc..61a366f298 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphInstance.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphInstance.cpp @@ -71,6 +71,9 @@ namespace EMotionFX // create the parameter value objects CreateParameterValues(); + // Assign a unique seed for the lcg random number. Here we use the actorInstanceId because it guaranteed to be unique and available on actor instances. + m_lcgRandom.SetSeed(actorInstance->GetID()); + m_animGraph->Unlock(); GetEventManager().OnCreateAnimGraphInstance(this); } diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphTimeCondition.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphTimeCondition.cpp index 3da55ced3e..e6e9c529df 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphTimeCondition.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/AnimGraphTimeCondition.cpp @@ -90,15 +90,8 @@ namespace EMotionFX if (m_useRandomization) { // create a randomized count down value - if (animGraphInstance->IsNetworkEnabled()) - { - // using a seeded random in order to generate predictable result in network. - uniqueData->m_countDownTime = MCore::Random::RandF(m_minRandomTime, m_maxRandomTime, animGraphInstance->GetLcgRandom()); - } - else - { - uniqueData->m_countDownTime = MCore::Random::RandF(m_minRandomTime, m_maxRandomTime); - } + uniqueData->m_countDownTime = + m_minRandomTime + (m_maxRandomTime - m_minRandomTime) * animGraphInstance->GetLcgRandom().GetRandomFloat(); } else { diff --git a/Gems/EMotionFX/Code/MCore/Source/Random.h b/Gems/EMotionFX/Code/MCore/Source/Random.h index 55576bb958..d2454af38b 100644 --- a/Gems/EMotionFX/Code/MCore/Source/Random.h +++ b/Gems/EMotionFX/Code/MCore/Source/Random.h @@ -64,22 +64,6 @@ namespace MCore */ static MCORE_INLINE float RandF(float minVal, float maxVal) { return minVal + (maxVal - minVal) * rand() / (float)RAND_MAX; } - /** - * Generate a uniform random float in a range of a given minimum and maximum. - * @param minVal The minimum value of the range. - * @param maxVal The maximum value of the range. - * @result A uniform random floating point number in range of [min..max]. - */ - static MCORE_INLINE float RandF(float minVal, float maxVal, unsigned int seed) { AZ_UNUSED(seed); return minVal + (maxVal - minVal) * rand() / (float)RAND_MAX; } - - /** - * Generate a uniform random float in a range of a given minimum and maximum. - * @param minVal The minimum value of the range. - * @param maxVal The maximum value of the range. - * @result A uniform random floating point number in range of [min..max]. - */ - static MCORE_INLINE float RandF(float minVal, float maxVal, LcgRandom& rand) { return minVal + (maxVal - minVal) * rand.GetRandomFloat(); } - /** * Generates a uniform random normalized direction vector, using floats. * @result A uniform random direction vector with a length of 1.