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 <rhhong@amazon.com>

* use actor instance id as the seed of the lcg random in anim graph instance

Signed-off-by: rhhong <rhhong@amazon.com>

* add const

Signed-off-by: rhhong <rhhong@amazon.com>
monroegm-disable-blank-issue-2
Roman 4 years ago committed by GitHub
parent 99764df120
commit 8766de21cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
}

@ -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
{

@ -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.

Loading…
Cancel
Save