Ticket #3578: DeterministicSound.patch
File DeterministicSound.patch, 1.8 KB (added by , 8 years ago) |
---|
-
source/soundmanager/scripting/SoundGroup.cpp
38 38 #include "ps/XML/Xeromyces.h" 39 39 #include "soundmanager/items/ISoundItem.h" 40 40 #include "soundmanager/SoundManager.h" 41 #include "simulation2/system/Component.h" 42 #include "simulation2/components/ICmpVisual.h" 41 43 44 #include <boost/random/mersenne_twister.hpp> 45 #include <boost/random/uniform_real.hpp> 46 42 47 #include <algorithm> 43 48 44 49 … … 46 51 47 52 #define PI 3.14126f 48 53 54 typedef boost::mt19937 rng_t; 49 55 50 56 static const bool DISABLE_INTENSITY = true; // disable for now since it's broken 51 57 … … 96 102 } 97 103 98 104 #if CONFIG2_AUDIO 99 static float RandFloat( float min, float max)100 { 101 return float( rand(min*100.0f, max*100.0f) / 100.0f);105 static float RandFloat(rng_t& rng, float min, float max) { 106 boost::uniform_real<> uni_dist(min, max); 107 return float(uni_dist(rng)); 102 108 } 103 109 #endif // CONFIG2_AUDIO 104 110 … … 203 209 hSound->SetRollOff(itemRollOff); 204 210 } 205 211 212 213 rng_t rng; 214 if (TestFlag(eRandPitch) || TestFlag(eRandGain)) { 215 // Seed random number generator 216 CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source); 217 rng.seed(cmpVisual ? cmpVisual->GetActorSeed() : rand(0, 1000)); 218 } 219 206 220 if (TestFlag(eRandPitch)) 207 hSound->SetPitch(RandFloat( m_PitchLower, m_PitchUpper));221 hSound->SetPitch(RandFloat(rng, m_PitchLower, m_PitchUpper)); 208 222 else 209 223 hSound->SetPitch(m_Pitch); 210 224 211 225 ALfloat theGain = m_Gain; 212 226 if (TestFlag(eRandGain)) 213 theGain = RandFloat( m_GainLower, m_GainUpper);227 theGain = RandFloat(rng, m_GainLower, m_GainUpper); 214 228 215 229 hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); 216 230 ((CSoundManager*)g_SoundManager)->PlayGroupItem(hSound, theGain);