Deleting an entity now tells openal to behave accordingly.
This commit is contained in:
@@ -65,7 +65,7 @@ void SoundSystem::stopEmitters()
|
||||
|
||||
void SoundSystem::Update()
|
||||
{
|
||||
//deleteInactiveEmitters(); // Not tested
|
||||
deleteInactiveEmitters();
|
||||
addNewEmitters();
|
||||
updateEmitters();
|
||||
updateListener();
|
||||
@@ -73,19 +73,33 @@ void SoundSystem::Update()
|
||||
|
||||
void SoundSystem::deleteInactiveEmitters()
|
||||
{
|
||||
auto emitterComponents = m_World->GetComponents("SoundEmitter");
|
||||
for (auto it = emitterComponents->begin(); it != emitterComponents->end();) {
|
||||
EntityID emitter = (*it).EntityID;
|
||||
if (isPlaying(m_Sources[emitter]->ALsource)) { // The sound is still playing, do not remove
|
||||
//auto emitterComponents = m_World->GetComponents("SoundEmitter");
|
||||
//for (auto it = emitterComponents->begin(); it != emitterComponents->end();) {
|
||||
// EntityID emitter = (*it).EntityID;
|
||||
// if (isPlaying(m_Sources[emitter]->ALsource)) { // The sound is still playing, do not remove
|
||||
// it++;
|
||||
// continue;
|
||||
// } else {
|
||||
// alDeleteBuffers(1, &m_Sources[emitter]->ALsource);
|
||||
// alDeleteSources(1, &m_Sources[emitter]->ALsource);
|
||||
// //delete m_Sources[emitter]->SoundResource;
|
||||
// m_Sources.erase(emitter);
|
||||
// m_World->DeleteEntity(emitter);
|
||||
// }
|
||||
//}
|
||||
|
||||
std::unordered_map<EntityID, Source*>::iterator it;
|
||||
for (it = m_Sources.begin(); it != m_Sources.end();) {
|
||||
if (m_World->ValidEntity((*it).first)) {
|
||||
// Entity is valid, move on.
|
||||
it++;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
alDeleteBuffers(1, &m_Sources[emitter]->ALsource);
|
||||
alDeleteSources(1, &m_Sources[emitter]->ALsource);
|
||||
} else {
|
||||
stopSound((*it).second);
|
||||
alDeleteBuffers(1, &m_Sources[(*it).first]->ALsource);
|
||||
alDeleteSources(1, &m_Sources[(*it).first]->ALsource);
|
||||
//delete m_Sources[emitter]->SoundResource;
|
||||
m_Sources.erase(emitter);
|
||||
m_World->DeleteEntity(emitter);
|
||||
it = m_Sources.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,8 +130,11 @@ void SoundSystem::addNewEmitters()
|
||||
void SoundSystem::updateEmitters()
|
||||
{
|
||||
auto emitterComponents = m_World->GetComponents("SoundEmitter");
|
||||
for (auto it = emitterComponents->begin(); it != emitterComponents->end(); it++) {
|
||||
for (auto it = emitterComponents->begin(); it != emitterComponents->end();) {
|
||||
EntityID emitter = (*it).EntityID;
|
||||
if (!m_World->ValidEntity(emitter)) { // Entity has been deleted
|
||||
// Delete
|
||||
} else {
|
||||
std::unordered_map<EntityID, Source*>::iterator i;
|
||||
i = m_Sources.find(emitter);
|
||||
if (i != m_Sources.end()) {
|
||||
@@ -148,6 +165,8 @@ void SoundSystem::updateEmitters()
|
||||
playSound(m_Sources[emitter]);
|
||||
}
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user