Changeset View
Changeset View
Standalone View
Standalone View
source/soundmanager/scripting/SoundGroup.cpp
Show All 36 Lines | |||||
#include "ps/Util.h" | #include "ps/Util.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.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; | |||||
#define PI 3.14126f | #define PI 3.14126f | ||||
static const bool DISABLE_INTENSITY = true; // disable for now since it's broken | static const bool DISABLE_INTENSITY = true; // disable for now since it's broken | ||||
void CSoundGroup::SetGain(float gain) | void CSoundGroup::SetGain(float gain) | ||||
{ | { | ||||
gain = std::min(gain, 1.0f); | gain = std::min(gain, 1.0f); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static float RandFloat(float min, float max) | ||||
return float(rand(min*100.0f, max*100.0f) / 100.0f); | return float(rand(min*100.0f, max*100.0f) / 100.0f); | ||||
} | } | ||||
#endif // CONFIG2_AUDIO | #endif // CONFIG2_AUDIO | ||||
float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff) | float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff) | ||||
{ | { | ||||
float x, y; | float x, y; | ||||
float answer = 0.0; | float answer = 0.0; | ||||
const size_t screenWidth = g_Game->GetView()->GetCamera()->GetViewPort().m_Width; | const size_t screenWidth = CGame::getGame()->GetView()->GetCamera()->GetViewPort().m_Width; | ||||
const size_t screenHeight = g_Game->GetView()->GetCamera()->GetViewPort().m_Height; | const size_t screenHeight = CGame::getGame()->GetView()->GetCamera()->GetViewPort().m_Height; | ||||
float bufferSize = screenWidth * 0.10; | float bufferSize = screenWidth * 0.10; | ||||
float yBufferSize = 15; | float yBufferSize = 15; | ||||
const size_t audioWidth = screenWidth; | const size_t audioWidth = screenWidth; | ||||
float radianCap = PI / 3; | float radianCap = PI / 3; | ||||
g_Game->GetView()->GetCamera()->GetScreenCoordinates(position, x, y); | CGame::getGame()->GetView()->GetCamera()->GetScreenCoordinates(position, x, y); | ||||
onScreen = true; | onScreen = true; | ||||
if (x < -bufferSize) | if (x < -bufferSize) | ||||
{ | { | ||||
onScreen = false; | onScreen = false; | ||||
answer = -radianCap; | answer = -radianCap; | ||||
} | } | ||||
Show All 26 Lines | float CSoundGroup::RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff) | ||||
} | } | ||||
return answer; | return answer; | ||||
} | } | ||||
void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source) | void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source) | ||||
{ | { | ||||
#if CONFIG2_AUDIO | #if CONFIG2_AUDIO | ||||
if (!g_SoundManager) | if (!ISoundManager::IsCreated()) | ||||
return; | return; | ||||
bool isOnscreen = false; | bool isOnscreen = false; | ||||
ALfloat itemRollOff = 0.1f; | ALfloat itemRollOff = 0.1f; | ||||
float offset = RadiansOffCenter(position, isOnscreen, itemRollOff); | float offset = RadiansOffCenter(position, isOnscreen, itemRollOff); | ||||
if (!isOnscreen && !TestFlag(eDistanceless) && !TestFlag(eOmnipresent)) | if (!isOnscreen && !TestFlag(eDistanceless) && !TestFlag(eOmnipresent)) | ||||
return; | return; | ||||
if (snd_group.size() == 0) | if (snd_group.size() == 0) | ||||
Reload(); | Reload(); | ||||
if (snd_group.size() <= theIndex) | if (snd_group.size() <= theIndex) | ||||
return; | return; | ||||
CSoundData* sndData = snd_group[theIndex]; | CSoundData* sndData = snd_group[theIndex]; | ||||
if (sndData == nullptr) | if (sndData == nullptr) | ||||
return; | return; | ||||
ISoundItem* hSound = static_cast<CSoundManager*>(g_SoundManager)->ItemForEntity(source, sndData); | ISoundItem* hSound = static_cast<CSoundManager*>(ISoundManager::GetSoundManager())->ItemForEntity(source, sndData); | ||||
if (hSound == nullptr) | if (hSound == nullptr) | ||||
return; | return; | ||||
if (!TestFlag(eOmnipresent)) | if (!TestFlag(eOmnipresent)) | ||||
{ | { | ||||
CVector3D origin = g_Game->GetView()->GetCamera()->GetOrientation().GetTranslation(); | CVector3D origin = CGame::getGame()->GetView()->GetCamera()->GetOrientation().GetTranslation(); | ||||
float sndDist = origin.Y; | float sndDist = origin.Y; | ||||
float itemDist = (position - origin).Length(); | float itemDist = (position - origin).Length(); | ||||
if ((sndDist * 2) < itemDist) | if ((sndDist * 2) < itemDist) | ||||
sndDist = itemDist; | sndDist = itemDist; | ||||
if (TestFlag(eDistanceless)) | if (TestFlag(eDistanceless)) | ||||
itemRollOff = 0; | itemRollOff = 0; | ||||
Show All 9 Lines | if (TestFlag(eRandPitch)) | ||||
hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); | hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper)); | ||||
else | else | ||||
hSound->SetPitch(m_Pitch); | hSound->SetPitch(m_Pitch); | ||||
if (TestFlag(eRandGain)) | if (TestFlag(eRandGain)) | ||||
m_Gain = RandFloat(m_GainLower, m_GainUpper); | m_Gain = RandFloat(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*>(ISoundManager::GetSoundManager())->PlayGroupItem(hSound, m_Gain); | ||||
#else // !CONFIG2_AUDIO | #else // !CONFIG2_AUDIO | ||||
UNUSED2(theIndex); | UNUSED2(theIndex); | ||||
UNUSED2(position); | UNUSED2(position); | ||||
UNUSED2(source); | UNUSED2(source); | ||||
#endif // !CONFIG2_AUDIO | #endif // !CONFIG2_AUDIO | ||||
} | } | ||||
Show All 17 Lines | |||||
void CSoundGroup::Reload() | void CSoundGroup::Reload() | ||||
{ | { | ||||
m_index = 0; // reset our index | m_index = 0; // reset our index | ||||
#if CONFIG2_AUDIO | #if CONFIG2_AUDIO | ||||
ReleaseGroup(); | ReleaseGroup(); | ||||
if ( g_SoundManager ) { | if (ISoundManager::IsCreated()) { | ||||
for (size_t i = 0; i < filenames.size(); i++) | for (size_t i = 0; i < filenames.size(); i++) | ||||
{ | { | ||||
VfsPath thePath = m_filepath/filenames[i]; | VfsPath thePath = m_filepath/filenames[i]; | ||||
CSoundData* itemData = CSoundData::SoundDataFromFile(thePath); | CSoundData* itemData = CSoundData::SoundDataFromFile(thePath); | ||||
if (itemData == NULL) | if (itemData == NULL) | ||||
HandleError(L"error loading sound", thePath, ERR::FAIL); | HandleError(L"error loading sound", thePath, ERR::FAIL); | ||||
else | else | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator