----------------------------------- AudioSourceSystem::OnComponentAdded Register transform components in the render scene when they are added to the ECS
| 26 | // Register transform components in the render scene when they are added to the ECS |
| 27 | // |
| 28 | void AudioSourceSystem::OnComponentAdded(EcsController& controller, AudioSourceComponent& component, T_EntityId const entity) |
| 29 | { |
| 30 | // generate the source handle |
| 31 | alGenSources((ALuint)1, &component.m_Source); |
| 32 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL gen sources error")); |
| 33 | |
| 34 | // are we 3D ? |
| 35 | if (controller.HasComponent<TransformComponent>(entity)) |
| 36 | { |
| 37 | controller.AddComponents(entity, AudioSource3DComponent()); |
| 38 | } |
| 39 | else // make our component play audio globally |
| 40 | { |
| 41 | alSourcei(component.m_Source, AL_SOURCE_RELATIVE, AL_TRUE); |
| 42 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source relative error")); |
| 43 | |
| 44 | // set the source dist to be the ref dist in front of the listener, so it will always be at default volume |
| 45 | alSource3f(component.m_Source, AL_POSITION, 0.f, 0.f, -1.f); |
| 46 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source position error")); |
| 47 | } |
| 48 | |
| 49 | // set source params |
| 50 | alSourcef(component.m_Source, AL_GAIN, component.m_Gain); |
| 51 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source gain error")); |
| 52 | |
| 53 | alSourcef(component.m_Source, AL_MIN_GAIN, component.m_MinGain); |
| 54 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source min gain error")); |
| 55 | |
| 56 | alSourcef(component.m_Source, AL_MAX_GAIN, component.m_MaxGain); |
| 57 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source max gain error")); |
| 58 | |
| 59 | alSourcef(component.m_Source, AL_PITCH, component.m_Pitch); |
| 60 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source pitch error")); |
| 61 | |
| 62 | alSourcei(component.m_Source, AL_LOOPING, (component.m_IsLooping ? AL_TRUE : AL_FALSE)); |
| 63 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source looping error")); |
| 64 | |
| 65 | // set the audio track |
| 66 | //--------------------- |
| 67 | if (component.m_NextTrack != 0u) |
| 68 | { |
| 69 | component.m_AudioData = core::ResourceManager::Instance()->GetAssetData<AudioData>(component.m_NextTrack); |
| 70 | alSourcei(component.m_Source, AL_BUFFER, component.m_AudioData->GetHandle()); |
| 71 | ET_ASSERT(!AudioManager::GetInstance()->TestALError("AL source buffer error")); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | //------------------------------------- |
| 76 | // AudioSourceSystem::OnComponentRemoved |
nothing calls this directly
no test coverage detected