Changeset View
Changeset View
Standalone View
Standalone View
source/soundmanager/scripting/SoundGroup.cpp
Show All 30 Lines | |||||
#include "simulation2/system/Component.h" | #include "simulation2/system/Component.h" | ||||
#include "soundmanager/items/ISoundItem.h" | #include "soundmanager/items/ISoundItem.h" | ||||
#include "soundmanager/SoundManager.h" | #include "soundmanager/SoundManager.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
extern CGame *g_Game; | extern CGame *g_Game; | ||||
#if CONFIG2_AUDIO | |||||
inline u32 CSoundGroup::FastRand() | |||||
{ | |||||
// This is a mixed linear congruential random number generator. | |||||
// The magic numbers are chosen so that they generate pseudo random numbers over a big enough period (0xFFFF). | |||||
m_Seed = 214013 * m_Seed + 2531011; | |||||
return (m_Seed >> 16) & 0xFFFF; | |||||
} | |||||
float CSoundGroup::RandFloat(float min, float max) | |||||
{ | |||||
return (static_cast<float>(FastRand()) / (0xFFFF)) * (max - min) + min; | |||||
} | |||||
#endif | |||||
void CSoundGroup::SetGain(float gain) | void CSoundGroup::SetGain(float gain) | ||||
{ | { | ||||
m_Gain = std::min(gain, 1.0f); | m_Gain = std::min(gain, 1.0f); | ||||
} | } | ||||
void CSoundGroup::SetDefaultValues() | void CSoundGroup::SetDefaultValues() | ||||
{ | { | ||||
m_CurrentSoundIndex = 0; | m_CurrentSoundIndex = 0; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | if (!TestFlag(eOmnipresent)) | ||||
hSound->SetLocation(CVector3D(sndDist * sin(offset), 0, -sndDist * cos(offset))); | hSound->SetLocation(CVector3D(sndDist * sin(offset), 0, -sndDist * cos(offset))); | ||||
hSound->SetRollOff(itemRollOff); | hSound->SetRollOff(itemRollOff); | ||||
} | } | ||||
CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source); | CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), source); | ||||
if (cmpVisual) | if (cmpVisual) | ||||
m_Seed = cmpVisual->GetActorSeed(); | m_Seed = cmpVisual->GetActorSeed(); | ||||
hSound->SetPitch(TestFlag(eRandPitch) ? RandFloat(m_PitchLower, m_PitchUpper) : m_Pitch); | hSound->SetPitch(TestFlag(eRandPitch) ? CFastRand::RandFloat(m_Seed, m_PitchLower, m_PitchUpper) : m_Pitch); | ||||
if (TestFlag(eRandGain)) | if (TestFlag(eRandGain)) | ||||
m_Gain = RandFloat(m_GainLower, m_GainUpper); | m_Gain = CFastRand::RandFloat(m_Seed, m_GainLower, m_GainUpper); | ||||
hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); | hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain); | ||||
static_cast<CSoundManager*>(g_SoundManager)->PlayGroupItem(hSound, m_Gain); | static_cast<CSoundManager*>(g_SoundManager)->PlayGroupItem(hSound, m_Gain); | ||||
#endif // !CONFIG2_AUDIO | #endif // !CONFIG2_AUDIO | ||||
} | } | ||||
static void HandleError(const std::wstring& message, const VfsPath& pathname, Status err) | static void HandleError(const std::wstring& message, const VfsPath& pathname, Status err) | ||||
{ | { | ||||
Show All 28 Lines | for (const std::wstring& filename : m_Filenames) | ||||
CSoundData* itemData = CSoundData::SoundDataFromFile(absolutePath); | CSoundData* itemData = CSoundData::SoundDataFromFile(absolutePath); | ||||
if (!itemData) | if (!itemData) | ||||
HandleError(L"error loading sound", absolutePath, ERR::FAIL); | HandleError(L"error loading sound", absolutePath, ERR::FAIL); | ||||
else | else | ||||
m_SoundGroups.push_back(itemData->IncrementCount()); | m_SoundGroups.push_back(itemData->IncrementCount()); | ||||
} | } | ||||
if (TestFlag(eRandOrder)) | if (TestFlag(eRandOrder)) | ||||
random_shuffle(m_SoundGroups.begin(), m_SoundGroups.end()); | std::shuffle(m_SoundGroups.begin(), m_SoundGroups.end(), CFastRand(m_Seed)); | ||||
#endif | #endif | ||||
} | } | ||||
void CSoundGroup::ReleaseGroup() | void CSoundGroup::ReleaseGroup() | ||||
{ | { | ||||
#if CONFIG2_AUDIO | #if CONFIG2_AUDIO | ||||
for (CSoundData* soundGroup : m_SoundGroups) | for (CSoundData* soundGroup : m_SoundGroups) | ||||
CSoundData::ReleaseSoundData(soundGroup); | CSoundData::ReleaseSoundData(soundGroup); | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator