1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Audio/BsAudio.h"
4#include "Audio/BsAudioSource.h"
5
6namespace bs
7{
8 void Audio::play(const HAudioClip& clip, const Vector3& position, float volume)
9 {
10 Transform transform;
11 transform.setPosition(position);
12
13 SPtr<AudioSource> source = createSource();
14 source->setClip(clip);
15 source->setTransform(transform);
16 source->setVolume(volume);
17 source->play();
18
19 mManualSources.push_back(source);
20 }
21
22 void Audio::stopManualSources()
23 {
24 for (auto& source : mManualSources)
25 source->stop();
26
27 mManualSources.clear();
28 }
29
30 void Audio::_update()
31 {
32 const UINT32 numSources = (UINT32)mManualSources.size();
33 for(UINT32 i = 0; i < numSources; i++)
34 {
35 if (mManualSources[i]->getState() != AudioSourceState::Stopped)
36 mTempSources.push_back(mManualSources[i]);
37 }
38
39 std::swap(mTempSources, mManualSources);
40 mTempSources.clear();
41 }
42
43 Audio& gAudio()
44 {
45 return Audio::instance();
46 }
47}