Ticket #3578: sound.patch
File sound.patch, 1.9 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 56 50 57 static const bool DISABLE_INTENSITY = true; // disable for now since it's broken 51 58 52 59 void CSoundGroup::SetGain(float gain) … … 96 103 } 97 104 98 105 #if CONFIG2_AUDIO 99 static float RandFloat( float min, float max)100 { 101 return float( rand(min*100.0f, max*100.0f) / 100.0f);106 static float RandFloat(rng_t* rng, float min, float max) { 107 boost::uniform_real<> uni_dist(min, max); 108 return float(uni_dist(rng)); 102 109 } 103 110 #endif // CONFIG2_AUDIO 104 111 … … 203 210 hSound->SetRollOff(itemRollOff); 204 211 } 205 212 213 214 rng_t rng; 215 if (TestFlag(eRandPitch) || TestFlag(eRandGain)) { 216 // Seed random number generator 217 CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source); 218 rng.seed(cmpVisual ? cmpVisual->GetActorSeed() : rand(0, 1000)); 219 } 220 206 221 if (TestFlag(eRandPitch)) 207 hSound->SetPitch(RandFloat( m_PitchLower, m_PitchUpper));222 hSound->SetPitch(RandFloat(&rng, m_PitchLower, m_PitchUpper)); 208 223 else 209 224 hSound->SetPitch(m_Pitch); 210 225 211 226 ALfloat theGain = m_Gain; 212 227 if (TestFlag(eRandGain)) 213 theGain = RandFloat( m_GainLower, m_GainUpper);228 theGain = RandFloat(&rng, m_GainLower, m_GainUpper); 214 229 215 230 hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); 216 231 ((CSoundManager*)g_SoundManager)->PlayGroupItem(hSound, theGain);