Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -36,16 +36,21 @@ #include "ps/Filesystem.h" #include "ps/Util.h" #include "ps/XML/Xeromyces.h" +#include "simulation2/system/Component.h" +#include "simulation2/components/ICmpVisual.h" #include "soundmanager/items/ISoundItem.h" #include "soundmanager/SoundManager.h" #include +#include +#include extern CGame *g_Game; #define PI 3.14126f +typedef boost::mt19937 rng_t; static const bool DISABLE_INTENSITY = true; // disable for now since it's broken @@ -96,9 +101,10 @@ } #if CONFIG2_AUDIO -static float RandFloat(float min, float max) +static float RandFloat(rng_t& rng, float min, float max) { - return float(rand(min*100.0f, max*100.0f) / 100.0f); + boost::uniform_real<> uni_dist(min, max); + return float(uni_dist(rng)); } #endif // CONFIG2_AUDIO @@ -199,13 +205,21 @@ hSound->SetRollOff(itemRollOff); } + rng_t rng; + if (TestFlag(eRandPitch) || TestFlag(eRandGain)) + { + // Seed random number generator + CmpPtr cmpVisual(*g_Game->GetSimulation2(), source); + rng.seed(cmpVisual ? cmpVisual->GetActorSeed() : rand(0, 1000)); + } + if (TestFlag(eRandPitch)) - hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); + hSound->SetPitch(RandFloat(rng, m_PitchLower, m_PitchUpper)); else hSound->SetPitch(m_Pitch); if (TestFlag(eRandGain)) - m_Gain = RandFloat(m_GainLower, m_GainUpper); + m_Gain = RandFloat(rng, m_GainLower, m_GainUpper); hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); static_cast(g_SoundManager)->PlayGroupItem(hSound, m_Gain);