Index: source/soundmanager/scripting/SoundGroup.h =================================================================== --- source/soundmanager/scripting/SoundGroup.h +++ source/soundmanager/scripting/SoundGroup.h @@ -20,6 +20,7 @@ #include "lib/config2.h" #include "lib/file/vfs/vfs_path.h" +#include "lib/types.h" #include "simulation2/system/Entity.h" #include "soundmanager/data/SoundData.h" @@ -80,6 +81,10 @@ void SetDefaultValues(); #if CONFIG2_AUDIO + inline u32 FastRand(); + // Contains the current sound seed for the generator + u32 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 @@ -104,7 +109,7 @@ float m_PitchUpper; float m_Priority; // Up to eight individual parameters, use with eSndGrpFlags. - uint8_t m_Flags; + u8 m_Flags; }; #endif //#ifndef INCLUDED_SOUNDGROUP_H 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,10 +37,16 @@ extern CGame *g_Game; #if CONFIG2_AUDIO -static float RandFloat(float min, float max) +inline u32 CSoundGroup::FastRand() { - return rand(min * 100.f, max * 100.f) / 100.f; + m_Seed = 214013 * m_Seed + 2531011; + return (m_Seed >> 16) & 0xFFFF; } + +float CSoundGroup::RandFloat(float min, float max) +{ + return (static_cast(FastRand()) / (0xFFFF)) * (max - min) + min; +} #endif void CSoundGroup::SetGain(float gain) @@ -62,6 +70,7 @@ m_ConeInnerAngle = 360.f; m_ConeOuterAngle = 360.f; m_Decay = 3.f; + m_Seed = 0; m_IntensityThreshold = 3.f; } @@ -179,11 +188,12 @@ 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);