Index: source/soundmanager/scripting/SoundGroup.h =================================================================== --- source/soundmanager/scripting/SoundGroup.h +++ source/soundmanager/scripting/SoundGroup.h @@ -80,6 +80,10 @@ void SetDefaultValues(); #if CONFIG2_AUDIO + inline int FastRand(); + // Contains the current sound seed for the generator + unsigned int m_Seed; + float RandFloat(float min, float max); // We store the handles so we can load now and play later std::vector m_SoundGroups; #endif Index: source/soundmanager/scripting/SoundGroup.cpp =================================================================== --- source/soundmanager/scripting/SoundGroup.cpp +++ source/soundmanager/scripting/SoundGroup.cpp @@ -21,12 +21,14 @@ #include "graphics/Camera.h" #include "graphics/GameView.h" #include "lib/rand.h" -#include "ps/Game.h" #include "ps/CLogger.h" #include "ps/CStr.h" #include "ps/Filesystem.h" +#include "ps/Game.h" #include "ps/Util.h" #include "ps/XML/Xeromyces.h" +#include "simulation2/components/ICmpVisual.h" +#include "simulation2/system/Component.h" #include "soundmanager/items/ISoundItem.h" #include "soundmanager/SoundManager.h" @@ -35,9 +37,15 @@ extern CGame *g_Game; #if CONFIG2_AUDIO -static float RandFloat(float min, float max) +inline int CSoundGroup::FastRand() { - return rand(min * 100.f, max * 100.f) / 100.f; + m_Seed = (214013 * m_Seed + 2531011); + return (m_Seed >> 16) & 0x7FFF; +} + +float CSoundGroup::RandFloat(float min, float max) +{ + return (static_cast(FastRand()) / (0x7FFF)) * (max - min) + min; } #endif @@ -62,6 +70,7 @@ m_ConeInnerAngle = 360.f; m_ConeOuterAngle = 360.f; m_Decay = 3.f; + m_Seed = 0; m_IntensityThreshold = 3.f; } @@ -179,10 +188,11 @@ hSound->SetRollOff(itemRollOff); } - if (TestFlag(eRandPitch)) - hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); - else - hSound->SetPitch(m_Pitch); + CmpPtr cmpVisual(*g_Game->GetSimulation2(), source); + if (cmpVisual) + m_Seed = cmpVisual->GetActorSeed(); + + hSound->SetPitch(TestFlag(eRandPitch) ? RandFloat(m_PitchLower, m_PitchUpper) : m_Pitch); if (TestFlag(eRandGain)) m_Gain = RandFloat(m_GainLower, m_GainUpper);